Skip to content

Commit

Permalink
fix(deps): update recursive-fs to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
rocwind committed Jan 28, 2022
1 parent 266b992 commit fd58c58
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 85 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"progress": "2.0.3",
"prompt": "1.2.1",
"properties": "1.2.1",
"recursive-fs": "0.1.4",
"recursive-fs": "2.1.0",
"rimraf": "3.0.2",
"semver": "7.3.5",
"simctl": "2.0.0",
Expand Down
23 changes: 4 additions & 19 deletions src/definitions/recursive-fs.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
declare module 'recursive-fs' {
export interface ICopyDirCallback {
(error?: any): void;
}

export interface IReadDirCallback {
(error?: any, directories?: string[], files?: string[]): void;
}

export interface IRemoveDirCallback {
(error?: any): void;
}

export function cpdirr(
sourceDirectoryPath: string,
targetDirectoryPath: string,
callback: ICopyDirCallback,
): void;
export function readdirr(directoryPath: string, callback: IReadDirCallback): void;
export function rmdirr(directoryPath: string, callback: IRemoveDirCallback): void;
export function read(directoryPath: string): Promise<{
dirs?: string[];
files?: string[];
}>;
}
73 changes: 31 additions & 42 deletions src/lib/hash-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import recursiveFs from 'recursive-fs';
import stream from 'stream';

// Do not throw an exception if either of these modules are missing, as they may not be needed by the
// consumer of this file.
// - recursiveFs: Only required for hashing of directories
try {
var recursiveFs = require('recursive-fs');
} catch (e) {}

const HASH_ALGORITHM = 'sha256';

export function generatePackageHashFromDirectory(
Expand All @@ -36,44 +30,39 @@ export function generatePackageManifestFromDirectory(
directoryPath: string,
basePath: string,
): Promise<PackageManifest> {
return new Promise<PackageManifest>((resolve, reject) => {
return new Promise<PackageManifest>(async (resolve, reject) => {
var fileHashesMap = new Map<string, string>();

recursiveFs.readdirr(
directoryPath,
(error?: any, directories?: string[], files?: string[]): void => {
if (error) {
reject(error);
return;
}

if (!files || files.length === 0) {
reject("Error: Can't sign the release because no files were found.");
return;
}
try {
const { files } = await recursiveFs.read(directoryPath);
if (!files || files.length === 0) {
reject("Error: Can't sign the release because no files were found.");
return;
}

// Hash the files sequentially, because streaming them in parallel is not necessarily faster
var generateManifestPromise: Promise<void> = files.reduce(
(soFar: Promise<void>, filePath: string) => {
return soFar.then(() => {
var relativePath: string = PackageManifest.normalizePath(
path.relative(basePath, filePath),
);
if (!PackageManifest.isIgnored(relativePath)) {
return hashFile(filePath).then((hash: string) => {
fileHashesMap.set(relativePath, hash);
});
}
});
},
Promise.resolve(null as void),
);

generateManifestPromise.then(() => {
resolve(new PackageManifest(fileHashesMap));
}, reject);
},
);
// Hash the files sequentially, because streaming them in parallel is not necessarily faster
var generateManifestPromise: Promise<void> = files.reduce(
(soFar: Promise<void>, filePath: string) => {
return soFar.then(() => {
var relativePath: string = PackageManifest.normalizePath(
path.relative(basePath, filePath),
);
if (!PackageManifest.isIgnored(relativePath)) {
return hashFile(filePath).then((hash: string) => {
fileHashesMap.set(relativePath, hash);
});
}
});
},
Promise.resolve(null as void),
);

generateManifestPromise.then(() => {
resolve(new PackageManifest(fileHashesMap));
}, reject);
} catch (error) {
reject(error);
}
});
}

Expand Down
35 changes: 15 additions & 20 deletions src/release-hooks/core-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,26 @@ var coreReleaseHook: cli.ReleaseHook = (
return Promise.resolve(releaseFiles);
}

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

recursiveFs.readdirr(
currentCommand.package,
(error?: any, directories?: string[], files?: string[]): void => {
if (error) {
reject(error);
return;
}

files.forEach((filePath: string) => {
var relativePath: string = path.relative(baseDirectoryPath, filePath);
// yazl does not like backslash (\) in the metadata path.
relativePath = slash(relativePath);
releaseFiles.push({
sourceLocation: filePath,
targetLocation: relativePath,
});
try {
var { files } = await recursiveFs.read(currentCommand.package);
files.forEach((filePath: string) => {
var relativePath: string = path.relative(baseDirectoryPath, filePath);
// yazl does not like backslash (\) in the metadata path.
relativePath = slash(relativePath);
releaseFiles.push({
sourceLocation: filePath,
targetLocation: relativePath,
});
});

resolve(releaseFiles);
},
);
resolve(releaseFiles);
} catch (error) {
reject(error);
}
});
})
.then((releaseFiles: cli.ReleaseFile[]) => {
Expand Down

0 comments on commit fd58c58

Please sign in to comment.