From dc38ab96fca99069449e6c5e492062b94a1264b6 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 19 May 2022 14:18:29 -0700 Subject: [PATCH] deps: npm-packlist@5.0.4 (#4919) --- node_modules/npm-packlist/lib/index.js | 51 +++++++++++++++++++++++++- node_modules/npm-packlist/package.json | 6 +-- package-lock.json | 12 +++--- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/node_modules/npm-packlist/lib/index.js b/node_modules/npm-packlist/lib/index.js index c7b0db5f60847..e4a2e76c545f6 100644 --- a/node_modules/npm-packlist/lib/index.js +++ b/node_modules/npm-packlist/lib/index.js @@ -33,6 +33,33 @@ const fs = require('fs') const glob = require('glob') const globify = pattern => pattern.split('\\').join('/') +const readOutOfTreeIgnoreFiles = (root, rel, result = '') => { + for (const file of ['.gitignore', '.npmignore']) { + try { + const ignoreContent = fs.readFileSync(path.join(root, file), { encoding: 'utf8' }) + result += ignoreContent + '\n' + } catch (err) { + // we ignore ENOENT errors completely because we don't care if the file doesn't exist + // but we throw everything else because failing to read a file that does exist is + // something that the user likely wants to know about. we don't need to test this. + /* istanbul ignore next */ + if (err.code !== 'ENOENT') { + throw err + } + } + } + + if (!rel) { + return result + } + + const firstRel = rel.split(path.sep)[0] + const newRoot = path.join(root, firstRel) + const newRel = path.relative(newRoot, path.join(root, rel)) + + return readOutOfTreeIgnoreFiles(newRoot, newRel, result) +} + const pathHasPkg = (input) => { if (!input.startsWith('node_modules/')) { return false @@ -119,9 +146,31 @@ class Walker extends IgnoreWalker { this.bundledScopes = Array.from(new Set( this.bundled.filter(f => /^@/.test(f)) .map(f => f.split('/')[0]))) - const rules = defaultRules.join('\n') + '\n' this.packageJsonCache = this.parent ? this.parent.packageJsonCache : (opt.packageJsonCache || new Map()) + let rules = defaultRules.join('\n') + '\n' + + if (opt.prefix && opt.workspaces) { + const gPath = globify(opt.path) + const gPrefix = globify(opt.prefix) + const gWorkspaces = opt.workspaces.map((ws) => globify(ws)) + // if opt.path and opt.prefix are not the same directory, and opt.workspaces has opt.path + // in it, then we know that opt.path is a workspace directory. in order to not drop ignore + // rules from directories between the workspace root (opt.prefix) and the workspace itself + // (opt.path), we need to find and read those now + /* istanbul ignore else */ + if (gPath !== gPrefix && gWorkspaces.includes(gPath)) { + // relpath is the relative path between the prefix and the parent of opt.path + // we use the parent because ignore-walk will read the files in opt.path already + const relpath = path.relative(opt.prefix, path.dirname(opt.path)) + rules += readOutOfTreeIgnoreFiles(opt.prefix, relpath) + } else if (gPath === gPrefix) { + // on the other hand, if the path and the prefix are the same, then we ignore workspaces + // so that we don't pack workspaces inside of a root project + rules += opt.workspaces.map((ws) => globify(path.relative(opt.path, ws))).join('\n') + } + } + super.onReadIgnoreFile(rootBuiltinRules, rules, _ => _) } else { this.bundled = [] diff --git a/node_modules/npm-packlist/package.json b/node_modules/npm-packlist/package.json index e79d1d4b82d86..e7622d735458c 100644 --- a/node_modules/npm-packlist/package.json +++ b/node_modules/npm-packlist/package.json @@ -1,6 +1,6 @@ { "name": "npm-packlist", - "version": "5.0.3", + "version": "5.0.4", "description": "Get a list of the files to add from a folder into an npm package", "directories": { "test": "test" @@ -20,7 +20,7 @@ ], "devDependencies": { "@npmcli/eslint-config": "^3.0.1", - "@npmcli/template-oss": "3.4.2", + "@npmcli/template-oss": "3.5.0", "mutate-fs": "^2.1.1", "tap": "^16.0.1" }, @@ -56,6 +56,6 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "version": "3.4.2" + "version": "3.5.0" } } diff --git a/package-lock.json b/package-lock.json index a06dbc49ea5a9..f982b3bf050d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5136,9 +5136,9 @@ } }, "node_modules/npm-packlist": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-5.0.3.tgz", - "integrity": "sha512-KuSbzgejxdsAWbNNyEs8EsyDHsO+nJF6k+9WuWzFbSNh5tFHs4lDApXw7kntKpuehfp8lKRzJkMtz0+WmGvTIw==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-5.0.4.tgz", + "integrity": "sha512-G4sCWzzHokHC5oxGD46Q9vCe+eN2tFb+3RfADD/eZbx4nKa7Y1eku1xvIWrw5R3F3hWX7IM2BgdqbQsyBUa3IA==", "inBundle": true, "dependencies": { "glob": "^8.0.1", @@ -13604,9 +13604,9 @@ } }, "npm-packlist": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-5.0.3.tgz", - "integrity": "sha512-KuSbzgejxdsAWbNNyEs8EsyDHsO+nJF6k+9WuWzFbSNh5tFHs4lDApXw7kntKpuehfp8lKRzJkMtz0+WmGvTIw==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-5.0.4.tgz", + "integrity": "sha512-G4sCWzzHokHC5oxGD46Q9vCe+eN2tFb+3RfADD/eZbx4nKa7Y1eku1xvIWrw5R3F3hWX7IM2BgdqbQsyBUa3IA==", "requires": { "glob": "^8.0.1", "ignore-walk": "^5.0.1",