npm-packlist
Advanced tools
Comparing version 5.0.3 to 5.0.4
@@ -36,2 +36,29 @@ 'use strict' | ||
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) => { | ||
@@ -123,5 +150,27 @@ if (!input.startsWith('node_modules/')) { | ||
.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, _ => _) | ||
@@ -128,0 +177,0 @@ } else { |
{ | ||
"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", | ||
@@ -23,3 +23,3 @@ "directories": { | ||
"@npmcli/eslint-config": "^3.0.1", | ||
"@npmcli/template-oss": "3.4.2", | ||
"@npmcli/template-oss": "3.5.0", | ||
"mutate-fs": "^2.1.1", | ||
@@ -60,4 +60,4 @@ "tap": "^16.0.1" | ||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", | ||
"version": "3.4.2" | ||
"version": "3.5.0" | ||
} | ||
} |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
26329
475
1