diff --git a/src/pack-individually.ts b/src/pack-individually.ts index dee79780..2ed7df8f 100644 --- a/src/pack-individually.ts +++ b/src/pack-individually.ts @@ -52,8 +52,8 @@ export async function packIndividually() { // get a list of external dependencies already listed in package.json const externals = Object.keys(require(path.join(buildDir, 'package.json')).dependencies); - // get a list of all production dependencies - const { dependencies } = await packager.getProdDependencies(buildDir, 10); + // get a tree of all production dependencies + const { dependencies } = await packager.getProdDependencies(buildDir); // package each function await Promise.all( diff --git a/src/packagers/npm.ts b/src/packagers/npm.ts index eca0ebbc..27ef1adb 100644 --- a/src/packagers/npm.ts +++ b/src/packagers/npm.ts @@ -20,20 +20,20 @@ export class NPM implements Packager { return true; } - async getProdDependencies(cwd: string, depth: number) { + async getProdDependencies(cwd: string, depth?: number) { // Get first level dependency graph const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; const args = [ 'ls', '-prod', // Only prod dependencies '-json', - `-depth=${depth || 1}` - ]; + depth ? `-depth=${depth}` : null, + ].filter(Boolean); const ignoredNpmErrors = [ { npmError: 'extraneous', log: false }, { npmError: 'missing', log: false }, - { npmError: 'peer dep missing', log: true } + { npmError: 'peer dep missing', log: true }, ]; try { @@ -45,15 +45,22 @@ export class NPM implements Packager { if (err instanceof SpawnError) { // Only exit with an error if we have critical npm errors for 2nd level inside const errors = split('\n', err.stderr); - const failed = reduce((f, error) => { - if (f) { - return true; - } - return ( - !isEmpty(error) && - !any(ignoredError => startsWith(`npm ERR! ${ignoredError.npmError}`, error), ignoredNpmErrors) - ); - }, false, errors); + const failed = reduce( + (f, error) => { + if (f) { + return true; + } + return ( + !isEmpty(error) && + !any( + ignoredError => startsWith(`npm ERR! ${ignoredError.npmError}`, error), + ignoredNpmErrors + ) + ); + }, + false, + errors + ); if (!failed && !isEmpty(err.stdout)) { return { stdout: err.stdout }; @@ -111,10 +118,12 @@ export class NPM implements Packager { async runScripts(cwd, scriptNames) { const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; - await Promise.all(scriptNames.map(scriptName => { - const args = ['run', scriptName]; + await Promise.all( + scriptNames.map(scriptName => { + const args = ['run', scriptName]; - return spawnProcess(command, args, { cwd }); - })); + return spawnProcess(command, args, { cwd }); + }) + ); } } diff --git a/src/packagers/packager.ts b/src/packagers/packager.ts index dcca25b7..b4b8a469 100644 --- a/src/packagers/packager.ts +++ b/src/packagers/packager.ts @@ -4,7 +4,7 @@ export interface Packager { lockfileName: string; copyPackageSectionNames: Array; mustCopyModules: boolean; - getProdDependencies(cwd: string, depth: number): Promise; + getProdDependencies(cwd: string, depth?: number): Promise; rebaseLockfile(pathToPackageRoot: string, lockfile: JSONObject): JSONObject; install(cwd: string): Promise; prune(cwd: string): Promise; diff --git a/src/packagers/yarn.ts b/src/packagers/yarn.ts index a85cba14..cb1a66bd 100644 --- a/src/packagers/yarn.ts +++ b/src/packagers/yarn.ts @@ -24,9 +24,11 @@ export class Yarn implements Packager { return false; } - async getProdDependencies(cwd, depth) { + async getProdDependencies(cwd: string, depth?: number) { const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn'; - const args = ['list', `--depth=${depth || 1}`, '--json', '--production']; + const args = ['list', depth ? `--depth=${depth}` : null, '--json', '--production'].filter( + Boolean + ); // If we need to ignore some errors add them here const ignoredYarnErrors = []; @@ -38,15 +40,22 @@ export class Yarn implements Packager { if (err instanceof SpawnError) { // Only exit with an error if we have critical npm errors for 2nd level inside const errors = split('\n', err.stderr); - const failed = reduce((f, error) => { - if (f) { - return true; - } - return ( - !isEmpty(error) && - !any(ignoredError => startsWith(`npm ERR! ${ignoredError.npmError}`, error), ignoredYarnErrors) - ); - }, false, errors); + const failed = reduce( + (f, error) => { + if (f) { + return true; + } + return ( + !isEmpty(error) && + !any( + ignoredError => startsWith(`npm ERR! ${ignoredError.npmError}`, error), + ignoredYarnErrors + ) + ); + }, + false, + errors + ); if (!failed && !isEmpty(err.stdout)) { return { stdout: err.stdout }; @@ -67,7 +76,7 @@ export class Yarn implements Packager { } __[head(splitModule)] = { version: join('@', tail(splitModule)), - dependencies: convertTrees(tree.children) + dependencies: convertTrees(tree.children), }; return __; }, {}); @@ -75,7 +84,7 @@ export class Yarn implements Packager { const trees = pathOr([], ['data', 'trees'], parsedTree); const result = { problems: [], - dependencies: convertTrees(trees) + dependencies: convertTrees(trees), }; return result; } @@ -89,12 +98,16 @@ export class Yarn implements Packager { while ((match = fileVersionMatcher.exec(lockfile)) !== null) { replacements.push({ oldRef: match[1], - newRef: replace(/\\/g, '/', `${pathToPackageRoot}/${match[1]}`) + newRef: replace(/\\/g, '/', `${pathToPackageRoot}/${match[1]}`), }); } // Replace all lines in lockfile - return reduce((__, replacement) => replace(__, replacement.oldRef, replacement.newRef), lockfile, replacements); + return reduce( + (__, replacement) => replace(__, replacement.oldRef, replacement.newRef), + lockfile, + replacements + ); } async install(cwd) { @@ -111,6 +124,8 @@ export class Yarn implements Packager { async runScripts(cwd, scriptNames: string[]) { const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn'; - await Promise.all(scriptNames.map(scriptName => spawnProcess(command, ['run', scriptName], { cwd }))); + await Promise.all( + scriptNames.map(scriptName => spawnProcess(command, ['run', scriptName], { cwd })) + ); } }