npm-packlist 11.0.0 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +40 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const { log } = require('proc-log')
|
|
|
8
8
|
|
|
9
9
|
// symbols used to represent synthetic rule sets
|
|
10
10
|
const defaultRules = Symbol('npm-packlist.rules.default')
|
|
11
|
+
const globalRules = Symbol('npm-packlist.rules.global')
|
|
11
12
|
const strictRules = Symbol('npm-packlist.rules.strict')
|
|
12
13
|
|
|
13
14
|
// There may be others, but :?|<> are handled by node-tar
|
|
@@ -84,13 +85,23 @@ class PackWalker extends IgnoreWalker {
|
|
|
84
85
|
follow: false,
|
|
85
86
|
// we path.resolve() here because ignore-walk doesn't do it and we want full paths
|
|
86
87
|
path: resolve(opts?.path || tree.path).replace(/\\/g, '/'),
|
|
87
|
-
|
|
88
|
+
// globalRules belongs on the root walker only. Child walkers reach it through
|
|
89
|
+
// parent.filterEntry, where package.json rules can still override it; reapplying
|
|
90
|
+
// globalRules at the child level would defeat that override.
|
|
91
|
+
ignoreFiles: opts?.ignoreFiles || (opts?.parent ? [
|
|
88
92
|
defaultRules,
|
|
89
93
|
'package.json',
|
|
90
94
|
'.npmignore',
|
|
91
95
|
'.gitignore',
|
|
92
96
|
strictRules,
|
|
93
|
-
]
|
|
97
|
+
] : [
|
|
98
|
+
defaultRules,
|
|
99
|
+
globalRules,
|
|
100
|
+
'package.json',
|
|
101
|
+
'.npmignore',
|
|
102
|
+
'.gitignore',
|
|
103
|
+
strictRules,
|
|
104
|
+
]),
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
super(options)
|
|
@@ -98,6 +109,8 @@ class PackWalker extends IgnoreWalker {
|
|
|
98
109
|
this.isPackage = options.isPackage
|
|
99
110
|
this.seen = options.seen || new Set()
|
|
100
111
|
this.tree = tree
|
|
112
|
+
this.globalIgnoreFile = options.globalIgnoreFile || null
|
|
113
|
+
this.globalIgnoreRules = options.globalIgnoreRules || null
|
|
101
114
|
|
|
102
115
|
const additionalDefaults = []
|
|
103
116
|
if (options.prefix && options.workspaces) {
|
|
@@ -124,6 +137,31 @@ class PackWalker extends IgnoreWalker {
|
|
|
124
137
|
// go ahead and inject the default rules now
|
|
125
138
|
this.injectRules(defaultRules, [...defaults, ...additionalDefaults])
|
|
126
139
|
|
|
140
|
+
// inject the global rules from the user's ignore file. positioned between
|
|
141
|
+
// defaultRules and package.json so an explicit entry in the package "files"
|
|
142
|
+
// field can still override. only the root walker carries globalRules in its
|
|
143
|
+
// ignoreFiles list; child walkers see global exclusions via parent.filterEntry,
|
|
144
|
+
// which is what lets the package.json `!/path/**` override win.
|
|
145
|
+
if (this.globalIgnoreRules === null && this.globalIgnoreFile) {
|
|
146
|
+
try {
|
|
147
|
+
this.globalIgnoreRules = readFile(this.globalIgnoreFile, { encoding: 'utf8' })
|
|
148
|
+
} catch (err) {
|
|
149
|
+
// istanbul ignore next -- only ENOENT is expected here
|
|
150
|
+
if (err.code !== 'ENOENT') {
|
|
151
|
+
throw err
|
|
152
|
+
}
|
|
153
|
+
this.globalIgnoreRules = ''
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (this.globalIgnoreRules) {
|
|
157
|
+
this.injectRules(globalRules, [this.globalIgnoreRules])
|
|
158
|
+
// istanbul ignore else -- globalIgnoreRules without a filename only happens when
|
|
159
|
+
// a caller pre-populates rules directly instead of going through globalIgnoreFile
|
|
160
|
+
if (this.globalIgnoreFile) {
|
|
161
|
+
log.silly('global-ignore-file', `applied rules from ${this.globalIgnoreFile}`)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
127
165
|
if (!this.isPackage) {
|
|
128
166
|
// if this instance is not a package, then place some strict default rules
|
|
129
167
|
this.injectRules(strictRules, [...strictDefaults])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-packlist",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "Get a list of the files to add from a folder into an npm package",
|
|
5
5
|
"directories": {
|
|
6
6
|
"test": "test"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@npmcli/arborist": "^9.0.0",
|
|
22
|
-
"@npmcli/eslint-config": "^
|
|
22
|
+
"@npmcli/eslint-config": "^7.0.0",
|
|
23
23
|
"@npmcli/template-oss": "5.1.0",
|
|
24
24
|
"mutate-fs": "^2.1.1",
|
|
25
25
|
"tap": "^16.0.1"
|