Skip to content

Commit

Permalink
fix: use recursive rm in ci command (#6054)
Browse files Browse the repository at this point in the history
* fix: use recursive rm in ci command

* fix: add test for repeat uses of ci command

Co-authored-by: Burke Livingston <[email protected]>
  • Loading branch information
jamesshaw1987 and burkel24 authored Jan 13, 2023
1 parent 4d27592 commit 1c3612c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CI extends ArboristWorkspaceCmd {
const path = `${where}/node_modules`
// get the list of entries so we can skip the glob for performance
const entries = await fs.readdir(path, null).catch(er => [])
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`, { force: true })))
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`, { force: true, recursive: true })))
})

await arb.reify(opts)
Expand Down
24 changes: 24 additions & 0 deletions test/lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ t.test('reifies, audits, removes node_modules', async t => {
t.equal(fs.existsSync(nmAbbrev), true, 'installs abbrev')
})

t.test('reifies, audits, removes node_modules on repeat run', async t => {
const { npm, joinedOutput, registry } = await loadMockNpm(t, {
prefixDir: {
abbrev: abbrev,
'package.json': JSON.stringify(packageJson),
'package-lock.json': JSON.stringify(packageLock),
node_modules: { test: 'test file that will be removed' },
},
})
const manifest = registry.manifest({ name: 'abbrev' })
await registry.tarball({
manifest: manifest.versions['1.0.0'],
tarball: path.join(npm.prefix, 'abbrev'),
})
registry.nock.post('/-/npm/v1/security/advisories/bulk').reply(200, {})
await npm.exec('ci', [])
await npm.exec('ci', [])
t.match(joinedOutput(), 'added 1 package, and audited 2 packages in')
const nmTest = path.join(npm.prefix, 'node_modules', 'test')
t.equal(fs.existsSync(nmTest), false, 'existing node_modules is removed')
const nmAbbrev = path.join(npm.prefix, 'node_modules', 'abbrev')
t.equal(fs.existsSync(nmAbbrev), true, 'installs abbrev')
})

t.test('--no-audit and --ignore-scripts', async t => {
const { npm, joinedOutput, registry } = await loadMockNpm(t, {
config: {
Expand Down

0 comments on commit 1c3612c

Please sign in to comment.