Skip to content

Commit

Permalink
[Refactor] use array.prototype.flat instead of relying on .concat
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 8, 2022
1 parent b52e661 commit 1d63028
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Arborist = require('@npmcli/arborist');
const colors = require('colors/safe');
const { manifest } = require('pacote');
const lockfileInfo = require('lockfile-info');
const flat = require('array.prototype.flat');

function prune(tree, {
dev: keepDev,
Expand Down Expand Up @@ -35,10 +36,10 @@ async function getBaseTree({
} = await lockfileInfo();

if (mode === 'actual' || (mode === 'auto' && hasNodeModulesDir)) {
const messages = [].concat(
const messages = flat([
hasNodeModulesDir ? `\`${colors.gray('node_modules')}\` found` : [],
mode === 'actual' ? 'mode is “actual”' : [],
);
]);
logger(colors.green(`${messages.join(', ')}; loading tree from disk...`));
return arb.loadActual({ fullMetadata: true, packumentCache });
}
Expand All @@ -57,18 +58,18 @@ async function getBaseTree({
));
return tree;
}
const messages = [].concat(
const messages = flat([
hasLockfile ? 'Lockfile found' : [],
mode === 'virtual' ? 'mode is “virtual”' : [],
);
]);
logger(colors.green(`${messages.join(', ')}; loading virtual tree from lockfile...`));
return arb.loadVirtual({ fullMetadata: true, packumentCache });
}

const messages = [].concat(
const messages = flat([
`\`${colors.gray('package.json')}\` ${hasPackageJSON ? '' : 'not '}found`,
mode === 'ideal' ? 'mode is “ideal”' : [],
);
]);
logger(colors.green(`${messages.join(', ')}; building ideal tree from \`${colors.gray('package.json')}\`...`));
return arb.buildIdealTree({ fullMetadata, packumentCache, update: true });
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"homepage": "https://github.com/ljharb/get-dep-tree#readme",
"dependencies": {
"@npmcli/arborist": "^4.2.0",
"array.prototype.flat": "^1.2.5",
"colors": "^1.4.0",
"lockfile-info": "^1.0.0",
"pacote": "^12.0.2"
Expand Down

0 comments on commit 1d63028

Please sign in to comment.