Skip to content

Commit

Permalink
Update npmInstallCmd, run prepare scripts properly
Browse files Browse the repository at this point in the history
Fix: #53
Fix: npm/cli#1865
  • Loading branch information
isaacs committed Nov 5, 2020
1 parent fd9401b commit f536ec0
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,11 @@ class FetcherBase {

// command to run 'prepare' scripts on directories and git dirs
// To use pacote with yarn, for example, set npmBin to 'yarn'
// and npmInstallCmd to ['add'], and npmCliConfig with yarn's equivalents.
// and npmCliConfig with yarn's equivalents.
this.npmBin = opts.npmBin || 'npm'

// command to install deps for preparing
this.npmInstallCmd = opts.npmInstallCmd || [
'install',
'--only=dev',
'--prod',
'--ignore-prepublish',
'--no-progress',
'--no-save',
]
this.npmInstallCmd = opts.npmInstallCmd || [ 'install' ]

// XXX fill more of this in based on what we know from this.opts
// we explicitly DO NOT fill in --tag, though, since we are often
Expand All @@ -113,7 +106,10 @@ class FetcherBase {
`--prefer-offline=${!!this.preferOffline}`,
`--prefer-online=${!!this.preferOnline}`,
`--offline=${!!this.offline}`,
`--before=${this.before ? this.before.toISOString() : ''}`,
...(this.before ? [`--before=${this.before.toISOString()}`] : []),
'--no-progress',
'--no-save',
'--no-audit',
]
}

Expand Down
52 changes: 52 additions & 0 deletions tap-snapshots/test-fetcher.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,55 @@ Object {
"resolved": "{CWD}/test/fixtures/bin-object.tgz",
}
`

exports[`test/fetcher.js TAP snapshot the npmInstallCmd and npmInstallConfig > customized npmInstallCmd 1`] = `
Array [
"install",
"blerg",
]
`

exports[`test/fetcher.js TAP snapshot the npmInstallCmd and npmInstallConfig > default install cmd 1`] = `
Array [
"install",
]
`

exports[`test/fetcher.js TAP snapshot the npmInstallCmd and npmInstallConfig > default install cmd with before 1`] = `
Array [
"install",
]
`

exports[`test/fetcher.js TAP snapshot the npmInstallCmd and npmInstallConfig > default install config 1`] = `
Array [
"--cache={CACHE}",
"--prefer-offline=false",
"--prefer-online=false",
"--offline=false",
"--no-progress",
"--no-save",
"--no-audit",
]
`

exports[`test/fetcher.js TAP snapshot the npmInstallCmd and npmInstallConfig > default install config with before 1`] = `
Array [
"--cache={CACHE}",
"--prefer-offline=false",
"--prefer-online=false",
"--offline=false",
"--before=1979-07-01T19:10:00.000Z",
"--no-progress",
"--no-save",
"--no-audit",
]
`

exports[`test/fetcher.js TAP snapshot the npmInstallCmd and npmInstallConfig > yarn style cli config stuff 1`] = `
Array [
"--some",
"--yarn",
"--stuff",
]
`
52 changes: 52 additions & 0 deletions tap-snapshots/test-fetcher.js-fake-sudo-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,55 @@ Object {
"resolved": "{CWD}/test/fixtures/bin-object.tgz",
}
`

exports[`test/fetcher.js fake-sudo TAP snapshot the npmInstallCmd and npmInstallConfig > customized npmInstallCmd 1`] = `
Array [
"install",
"blerg",
]
`

exports[`test/fetcher.js fake-sudo TAP snapshot the npmInstallCmd and npmInstallConfig > default install cmd 1`] = `
Array [
"install",
]
`

exports[`test/fetcher.js fake-sudo TAP snapshot the npmInstallCmd and npmInstallConfig > default install cmd with before 1`] = `
Array [
"install",
]
`

exports[`test/fetcher.js fake-sudo TAP snapshot the npmInstallCmd and npmInstallConfig > default install config 1`] = `
Array [
"--cache={CACHE}",
"--prefer-offline=false",
"--prefer-online=false",
"--offline=false",
"--no-progress",
"--no-save",
"--no-audit",
]
`

exports[`test/fetcher.js fake-sudo TAP snapshot the npmInstallCmd and npmInstallConfig > default install config with before 1`] = `
Array [
"--cache={CACHE}",
"--prefer-offline=false",
"--prefer-online=false",
"--offline=false",
"--before=1979-07-01T19:10:00.000Z",
"--no-progress",
"--no-save",
"--no-audit",
]
`

exports[`test/fetcher.js fake-sudo TAP snapshot the npmInstallCmd and npmInstallConfig > yarn style cli config stuff 1`] = `
Array [
"--some",
"--yarn",
"--stuff",
]
`
23 changes: 23 additions & 0 deletions test/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ t.test('do not mutate opts object passed in', t => {
t.end()
})

t.test('snapshot the npmInstallCmd and npmInstallConfig', async t => {
t.formatSnapshot = o => !Array.isArray(o) ? ou
: o.map(s => s.replace(/^--cache=.*/, '--cache={CACHE}'))
const def = new FileFetcher(abbrevspec, {})
t.equal(def.npmBin, 'npm', 'use default npm bin')
t.matchSnapshot(def.npmInstallCmd, 'default install cmd')
t.matchSnapshot(def.npmCliConfig, 'default install config')
const bef = new FileFetcher(abbrevspec, {
before: new Date('1979-07-01T19:10:00.000Z'),
})
t.equal(bef.npmBin, 'npm', 'use default npm bin')
t.matchSnapshot(bef.npmInstallCmd, 'default install cmd with before')
t.matchSnapshot(bef.npmCliConfig, 'default install config with before')
const yarn = new FileFetcher(abbrevspec, {
npmBin: 'yarn',
npmInstallCmd: ['install', 'blerg'],
npmCliConfig: ['--some', '--yarn', '--stuff'],
})
t.equal(yarn.npmBin, 'yarn', 'use default yarn bin')
t.matchSnapshot(yarn.npmInstallCmd, 'customized npmInstallCmd')
t.matchSnapshot(yarn.npmCliConfig, 'yarn style cli config stuff')
})

t.test('tarball data', t =>
new FileFetcher(abbrevspec, { cache }).tarball()
.then(data => {
Expand Down

0 comments on commit f536ec0

Please sign in to comment.