Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"git-tag-version": true,
"global": false,
"globalconfig": "{CWD}/global/etc/npmrc",
"global-ignore-file": "{CWD}/global/etc/npmignore",
"global-style": false,
"heading": "npm",
"https-proxy": null,
Expand Down Expand Up @@ -247,6 +248,7 @@ fund = true
git = "git"
git-tag-version = true
global = false
global-ignore-file = "{CWD}/global/etc/npmignore"
global-style = false
globalconfig = "{CWD}/global/etc/npmrc"
heading = "npm"
Expand Down
22 changes: 22 additions & 0 deletions tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,25 @@ folder instead of the current working directory. See



#### \`global-ignore-file\`

* Default: The global --prefix setting plus 'etc/npmignore'. For example,
'/usr/local/etc/npmignore'
* Type: Path

An additional ignore file applied during \`npm pack\` and \`npm publish\`, owned
by the current user rather than the package. Patterns follow the same syntax
as a package's local \`.npmignore\` file. Useful for keeping editor metadata
(such as \`.idea/\` or \`*.iml\`) and scratch directories out of every package
you publish, without adding them to each package's own ignore rules.

The global rules apply in addition to a package's local \`.npmignore\`. When a
package uses a \`files\` field in its \`package.json\`, an entry in \`files\` that
contradicts a global rule (i.e., explicitly includes a path the global rule
would exclude) still wins.



#### \`globalconfig\`

* Default: The global --prefix setting plus 'etc/npmrc'. For example,
Expand Down Expand Up @@ -2349,6 +2368,7 @@ Array [
"git-tag-version",
"global",
"globalconfig",
"global-ignore-file",
"global-style",
"heading",
"https-proxy",
Expand Down Expand Up @@ -2526,6 +2546,7 @@ Array [
"git-tag-version",
"global",
"globalconfig",
"global-ignore-file",
"global-style",
"heading",
"https-proxy",
Expand Down Expand Up @@ -2700,6 +2721,7 @@ Object {
"gitTagVersion": true,
"global": false,
"globalconfig": "{CWD}/global/etc/npmrc",
"globalIgnoreFile": "{CWD}/global/etc/npmignore",
"heading": "npm",
"httpsProxy": null,
"ifPresent": false,
Expand Down
23 changes: 23 additions & 0 deletions workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,29 @@ const definitions = {
`,
flatten,
}),
// the global-ignore-file has its default defined outside of this module
'global-ignore-file': new Definition('global-ignore-file', {
type: path,
default: '',
defaultDescription: `
The global --prefix setting plus 'etc/npmignore'. For example,
'/usr/local/etc/npmignore'
`,
description: `
An additional ignore file applied during \`npm pack\` and \`npm
publish\`, owned by the current user rather than the package. Patterns
follow the same syntax as a package's local \`.npmignore\` file.
Useful for keeping editor metadata (such as \`.idea/\` or \`*.iml\`)
and scratch directories out of every package you publish, without
adding them to each package's own ignore rules.

The global rules apply in addition to a package's local \`.npmignore\`.
When a package uses a \`files\` field in its \`package.json\`, an entry
in \`files\` that contradicts a global rule (i.e., explicitly includes
a path the global rule would exclude) still wins.
`,
flatten,
}),
'global-style': new Definition('global-style', {
default: false,
type: Boolean,
Expand Down
18 changes: 18 additions & 0 deletions workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ class Config {
configurable: true,
enumerable: true,
})

// like globalconfig, the global-ignore-file default is computed from
// the current prefix. since prefix may be overridden after defaults
// load (via cli, env, or userconfig), expose a getter and only freeze
// to a value once explicitly set.
Object.defineProperty(data, 'global-ignore-file', {
get: () => resolve(this.#get('prefix'), 'etc/npmignore'),
set (value) {
Object.defineProperty(data, 'global-ignore-file', {
value,
configurable: true,
writable: true,
enumerable: true,
})
},
configurable: true,
enumerable: true,
})
}

loadHome () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ Object {
"global": Array [
"boolean value (true or false)",
],
"global-ignore-file": Array [
"valid filesystem path",
],
"global-style": Array [
"boolean value (true or false)",
],
Expand Down
16 changes: 16 additions & 0 deletions workspaces/config/test/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1050,3 +1050,19 @@ t.test('node-gyp', t => {

t.end()
})

t.test('global-ignore-file', t => {
const defs = mockDefs()
const def = defs['global-ignore-file']

t.ok(def, 'global-ignore-file definition is exported')
t.equal(def.type, require('../../lib/type-defs.js').path.type, 'is a path typed config')
t.equal(def.default, '', 'default value is empty (computed at load time)')
t.ok(/ignore/i.test(def.description), 'has a descriptive entry')

const flat = {}
def.flatten('global-ignore-file', { 'global-ignore-file': '/path/to/npmignore' }, flat)
t.strictSame(flat, { globalIgnoreFile: '/path/to/npmignore' }, 'flattens to camelCase')

t.end()
})
43 changes: 43 additions & 0 deletions workspaces/config/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1869,3 +1869,46 @@ t.test('before and min-release-age', async t => {
t.ok(config.flat.before < Date.now(), 'before date is in the past not the future')
t.equal(config.get('min-release-age'), 30, 'min-release-age config remains readable after flattening')
})

t.test('global-ignore-file defaults to ${prefix}/etc/npmignore', async t => {
const path = t.testdir()
const config = new Config({
npmPath: `${path}/npm`,
env: {},
argv: [process.execPath, __filename, '--prefix', `${path}/global`],
cwd: path,
definitions,
shorthands,
flatten,
})
await config.load()
t.equal(
config.get('global-ignore-file'),
resolve(`${path}/global/etc/npmignore`),
'computed from --prefix, mirrors globalconfig'
)
t.equal(config.flat.globalIgnoreFile, resolve(`${path}/global/etc/npmignore`), 'flattens to camelCase')
})

t.test('global-ignore-file follows an explicit override', async t => {
const path = t.testdir()
const config = new Config({
npmPath: `${path}/npm`,
env: {},
argv: [
process.execPath, __filename,
'--prefix', `${path}/global`,
'--global-ignore-file', `${path}/custom/.npmignore`,
],
cwd: path,
definitions,
shorthands,
flatten,
})
await config.load()
t.equal(
config.get('global-ignore-file'),
resolve(`${path}/custom/.npmignore`),
'cli override wins over computed default'
)
})
Loading