From 2a680e91a2be1f3f03a6fbd946f74628ee1cb370 Mon Sep 17 00:00:00 2001 From: nlf Date: Thu, 29 Oct 2020 13:30:25 -0700 Subject: [PATCH] delete the contents of node_modules only PR-URL: https://github.com/npm/cli/pull/2083 Credit: @nlf Close: #2083 Reviewed-by: @darcyclarke --- lib/ci.js | 2 +- test/lib/ci.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ci.js b/lib/ci.js index a0728f8a46467..a72e1c0cffba6 100644 --- a/lib/ci.js +++ b/lib/ci.js @@ -31,7 +31,7 @@ const ci = async () => { 'later to generate a package-lock.json file, then try again.' throw new Error(msg) }), - rimraf(`${where}/node_modules/`), + rimraf(`${where}/node_modules/*`, { glob: { dot: true, nosort: true, silent: true } }), ]) // npm ci should never modify the lockfile or package.json await arb.reify({ save: false }) diff --git a/test/lib/ci.js b/test/lib/ci.js index 3c642ba930135..645fc6aed97e4 100644 --- a/test/lib/ci.js +++ b/test/lib/ci.js @@ -104,7 +104,8 @@ test('should remove existing node_modules before installing', (t) => { t.equal(options.save, false, 'npm ci should never save') // check if node_modules was removed before reifying const contents = await readdir(testDir) - t.equals(contents.indexOf('node_modules'), -1, 'node_modules does not exist') + const nodeModules = contents.filter((path) => path.startsWith('node_modules')) + t.same(nodeModules, ['node_modules'], 'should only have the node_modules directory') t.end() } }