Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

delete contents of node_modules but keep the dir itself #1

Merged
merged 2 commits into from
Oct 8, 2019
Merged
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: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Installer {
)
return BB.join(
this.checkLock(),
stat && rimraf(path.join(this.prefix, 'node_modules'))
stat && rimraf(path.join(this.prefix, 'node_modules/*'))
)
}).then(() => {
// This needs to happen -after- we've done checkLock()
Expand Down
39 changes: 39 additions & 0 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,45 @@ test('handles dependency list with only shallow subdeps', t => {
})
})

test('deletes node_modules/ contents, without deleting node_modules/ itself', t => {
const fixture = new Tacks(Dir({
'node_modules': Dir({
'stale-dependency': Dir({
'package.json': File({
name: 'stale-dependency',
version: '1.0.0'
})
})
}),
'package.json': File({
name: pkgName,
version: pkgVersion
}),
'package-lock.json': File({
dependencies: {},
lockfileVersion: 1
})
}))
fixture.create(prefix)

let notNodeModulesDeleted = true
const nodeModulesDir = path.join(prefix, 'node_modules')
const watcher = fs.watch(nodeModulesDir, () => {
if (!fs.existsSync(nodeModulesDir)) {
notNodeModulesDeleted = false
}
})

return run().then(() => {
t.ok(
!fs.existsSync(path.join(nodeModulesDir, 'stale-dependency')),
'node_modules/ contents were deleted'
)
watcher.close()
t.ok(notNodeModulesDeleted, 'node_modules/ itself was not deleted')
})
})

test('handles dependency list with only deep subdeps', t => {
const fixture = new Tacks(Dir({
'package.json': File({
Expand Down