diff options
Diffstat (limited to 'scripts/bundle-and-gitignore-deps.js')
-rw-r--r-- | scripts/bundle-and-gitignore-deps.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/bundle-and-gitignore-deps.js b/scripts/bundle-and-gitignore-deps.js new file mode 100644 index 000000000..c264b1c3c --- /dev/null +++ b/scripts/bundle-and-gitignore-deps.js @@ -0,0 +1,32 @@ +const Arborist = require('@npmcli/arborist') +const { resolve } = require('path') +const ignore = resolve(__dirname, '../node_modules/.gitignore') +const { writeFileSync } = require('fs') +const pj = resolve(__dirname, '../package.json') +const pkg = require(pj) +const bundle = [] +const arb = new Arborist({ path: resolve(__dirname, '..') }) +const shouldIgnore = [] + +arb.loadVirtual().then(tree => { + for (const [name, node] of tree.children.entries()) { + if (node.dev) { + console.error('ignore', node.name) + shouldIgnore.push(node.name) + } else if (tree.edgesOut.has(node.name)) { + console.error('BUNDLE', node.name) + bundle.push(node.name) + } + } + pkg.bundleDependencies = bundle.sort((a, b) => a.localeCompare(b)) + + const ignores = shouldIgnore.sort((a, b) => a.localeCompare(b)) + .map(i => `/${i}`) + .join('\n') + const ignoreData = `# Automatically generated to ignore dev deps +/.package-lock.json +${ignores} +` + writeFileSync(ignore, ignoreData) + writeFileSync(pj, JSON.stringify(pkg, 0, 2) + '\n') +}) |