Skip to content

Commit fd58c58

Browse files
committed
fix(deps): update recursive-fs to v2
1 parent 266b992 commit fd58c58

File tree

5 files changed

+54
-85
lines changed

5 files changed

+54
-85
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"progress": "2.0.3",
4646
"prompt": "1.2.1",
4747
"properties": "1.2.1",
48-
"recursive-fs": "0.1.4",
48+
"recursive-fs": "2.1.0",
4949
"rimraf": "3.0.2",
5050
"semver": "7.3.5",
5151
"simctl": "2.0.0",

src/definitions/recursive-fs.d.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
declare module 'recursive-fs' {
2-
export interface ICopyDirCallback {
3-
(error?: any): void;
4-
}
5-
6-
export interface IReadDirCallback {
7-
(error?: any, directories?: string[], files?: string[]): void;
8-
}
9-
10-
export interface IRemoveDirCallback {
11-
(error?: any): void;
12-
}
13-
14-
export function cpdirr(
15-
sourceDirectoryPath: string,
16-
targetDirectoryPath: string,
17-
callback: ICopyDirCallback,
18-
): void;
19-
export function readdirr(directoryPath: string, callback: IReadDirCallback): void;
20-
export function rmdirr(directoryPath: string, callback: IRemoveDirCallback): void;
2+
export function read(directoryPath: string): Promise<{
3+
dirs?: string[];
4+
files?: string[];
5+
}>;
216
}

src/lib/hash-utils.ts

+31-42
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
import crypto from 'crypto';
77
import fs from 'fs';
88
import path from 'path';
9+
import recursiveFs from 'recursive-fs';
910
import stream from 'stream';
1011

11-
// Do not throw an exception if either of these modules are missing, as they may not be needed by the
12-
// consumer of this file.
13-
// - recursiveFs: Only required for hashing of directories
14-
try {
15-
var recursiveFs = require('recursive-fs');
16-
} catch (e) {}
17-
1812
const HASH_ALGORITHM = 'sha256';
1913

2014
export function generatePackageHashFromDirectory(
@@ -36,44 +30,39 @@ export function generatePackageManifestFromDirectory(
3630
directoryPath: string,
3731
basePath: string,
3832
): Promise<PackageManifest> {
39-
return new Promise<PackageManifest>((resolve, reject) => {
33+
return new Promise<PackageManifest>(async (resolve, reject) => {
4034
var fileHashesMap = new Map<string, string>();
4135

42-
recursiveFs.readdirr(
43-
directoryPath,
44-
(error?: any, directories?: string[], files?: string[]): void => {
45-
if (error) {
46-
reject(error);
47-
return;
48-
}
49-
50-
if (!files || files.length === 0) {
51-
reject("Error: Can't sign the release because no files were found.");
52-
return;
53-
}
36+
try {
37+
const { files } = await recursiveFs.read(directoryPath);
38+
if (!files || files.length === 0) {
39+
reject("Error: Can't sign the release because no files were found.");
40+
return;
41+
}
5442

55-
// Hash the files sequentially, because streaming them in parallel is not necessarily faster
56-
var generateManifestPromise: Promise<void> = files.reduce(
57-
(soFar: Promise<void>, filePath: string) => {
58-
return soFar.then(() => {
59-
var relativePath: string = PackageManifest.normalizePath(
60-
path.relative(basePath, filePath),
61-
);
62-
if (!PackageManifest.isIgnored(relativePath)) {
63-
return hashFile(filePath).then((hash: string) => {
64-
fileHashesMap.set(relativePath, hash);
65-
});
66-
}
67-
});
68-
},
69-
Promise.resolve(null as void),
70-
);
71-
72-
generateManifestPromise.then(() => {
73-
resolve(new PackageManifest(fileHashesMap));
74-
}, reject);
75-
},
76-
);
43+
// Hash the files sequentially, because streaming them in parallel is not necessarily faster
44+
var generateManifestPromise: Promise<void> = files.reduce(
45+
(soFar: Promise<void>, filePath: string) => {
46+
return soFar.then(() => {
47+
var relativePath: string = PackageManifest.normalizePath(
48+
path.relative(basePath, filePath),
49+
);
50+
if (!PackageManifest.isIgnored(relativePath)) {
51+
return hashFile(filePath).then((hash: string) => {
52+
fileHashesMap.set(relativePath, hash);
53+
});
54+
}
55+
});
56+
},
57+
Promise.resolve(null as void),
58+
);
59+
60+
generateManifestPromise.then(() => {
61+
resolve(new PackageManifest(fileHashesMap));
62+
}, reject);
63+
} catch (error) {
64+
reject(error);
65+
}
7766
});
7867
}
7968

src/release-hooks/core-release.ts

+15-20
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,26 @@ var coreReleaseHook: cli.ReleaseHook = (
3030
return Promise.resolve(releaseFiles);
3131
}
3232

33-
return new Promise<cli.ReleaseFile[]>((resolve, reject) => {
33+
return new Promise<cli.ReleaseFile[]>(async (resolve, reject) => {
3434
var directoryPath: string = currentCommand.package;
3535
var baseDirectoryPath = path.join(directoryPath, '..'); // For legacy reasons, put the root directory in the zip
3636

37-
recursiveFs.readdirr(
38-
currentCommand.package,
39-
(error?: any, directories?: string[], files?: string[]): void => {
40-
if (error) {
41-
reject(error);
42-
return;
43-
}
44-
45-
files.forEach((filePath: string) => {
46-
var relativePath: string = path.relative(baseDirectoryPath, filePath);
47-
// yazl does not like backslash (\) in the metadata path.
48-
relativePath = slash(relativePath);
49-
releaseFiles.push({
50-
sourceLocation: filePath,
51-
targetLocation: relativePath,
52-
});
37+
try {
38+
var { files } = await recursiveFs.read(currentCommand.package);
39+
files.forEach((filePath: string) => {
40+
var relativePath: string = path.relative(baseDirectoryPath, filePath);
41+
// yazl does not like backslash (\) in the metadata path.
42+
relativePath = slash(relativePath);
43+
releaseFiles.push({
44+
sourceLocation: filePath,
45+
targetLocation: relativePath,
5346
});
47+
});
5448

55-
resolve(releaseFiles);
56-
},
57-
);
49+
resolve(releaseFiles);
50+
} catch (error) {
51+
reject(error);
52+
}
5853
});
5954
})
6055
.then((releaseFiles: cli.ReleaseFile[]) => {

0 commit comments

Comments
 (0)