Skip to content

Commit 1c3612c

Browse files
jamesshaw1987burkel24
andauthoredJan 13, 2023
fix: use recursive rm in ci command (#6054)
* fix: use recursive rm in ci command * fix: add test for repeat uses of ci command Co-authored-by: Burke Livingston <burkel24@gmail.com>
1 parent 4d27592 commit 1c3612c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

‎lib/commands/ci.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CI extends ArboristWorkspaceCmd {
6767
const path = `${where}/node_modules`
6868
// get the list of entries so we can skip the glob for performance
6969
const entries = await fs.readdir(path, null).catch(er => [])
70-
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`, { force: true })))
70+
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`, { force: true, recursive: true })))
7171
})
7272

7373
await arb.reify(opts)

‎test/lib/commands/ci.js

+24
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ t.test('reifies, audits, removes node_modules', async t => {
7979
t.equal(fs.existsSync(nmAbbrev), true, 'installs abbrev')
8080
})
8181

82+
t.test('reifies, audits, removes node_modules on repeat run', async t => {
83+
const { npm, joinedOutput, registry } = await loadMockNpm(t, {
84+
prefixDir: {
85+
abbrev: abbrev,
86+
'package.json': JSON.stringify(packageJson),
87+
'package-lock.json': JSON.stringify(packageLock),
88+
node_modules: { test: 'test file that will be removed' },
89+
},
90+
})
91+
const manifest = registry.manifest({ name: 'abbrev' })
92+
await registry.tarball({
93+
manifest: manifest.versions['1.0.0'],
94+
tarball: path.join(npm.prefix, 'abbrev'),
95+
})
96+
registry.nock.post('/-/npm/v1/security/advisories/bulk').reply(200, {})
97+
await npm.exec('ci', [])
98+
await npm.exec('ci', [])
99+
t.match(joinedOutput(), 'added 1 package, and audited 2 packages in')
100+
const nmTest = path.join(npm.prefix, 'node_modules', 'test')
101+
t.equal(fs.existsSync(nmTest), false, 'existing node_modules is removed')
102+
const nmAbbrev = path.join(npm.prefix, 'node_modules', 'abbrev')
103+
t.equal(fs.existsSync(nmAbbrev), true, 'installs abbrev')
104+
})
105+
82106
t.test('--no-audit and --ignore-scripts', async t => {
83107
const { npm, joinedOutput, registry } = await loadMockNpm(t, {
84108
config: {

0 commit comments

Comments
 (0)
Please sign in to comment.