From a2c7d69e1b06dee5fb4bb3f19321d63c1d1125c4 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 8 Feb 2022 11:13:51 -0500 Subject: [PATCH] fix: remove extraneous devDependencies on package merge /cc @pitaj --- src/cli/package-install.js | 5 +++-- test/package-install.js | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cli/package-install.js b/src/cli/package-install.js index 76f5218679..f2e4e94913 100644 --- a/src/cli/package-install.js +++ b/src/cli/package-install.js @@ -38,11 +38,12 @@ pkgInstall.updatePackageFile = () => { } }); + const { devDependencies } = defaultPackageContents; + // Sort dependencies alphabetically dependencies = sortDependencies({ ...dependencies, ...defaultPackageContents.dependencies }); - const packageContents = { ..._.merge(oldPackageContents, defaultPackageContents), dependencies }; - + const packageContents = { ..._.merge(oldPackageContents, defaultPackageContents), dependencies, devDependencies }; fs.writeFileSync(paths.currentPackage, JSON.stringify(packageContents, null, 2)); }; diff --git a/test/package-install.js b/test/package-install.js index 0e15e145db..0d31387df1 100644 --- a/test/package-install.js +++ b/test/package-install.js @@ -86,6 +86,15 @@ describe('Package install lib', () => { assert.strictEqual(updated.scripts.preinstall, 'echo "What are you?";'); }); + it('should remove extraneous devDependencies', async () => { + current.devDependencies.expect = '27.5.1'; + await fs.writeFile(packageFilePath, JSON.stringify(current, null, 4)); + + pkgInstall.updatePackageFile(); + const updated = JSON.parse(await fs.readFile(packageFilePath, 'utf8')); + assert.strictEqual(updated.devDependencies.hasOwnProperty('expect'), false); + }); + after(async () => { // Clean up await fs.rename(path.resolve(__dirname, '../install/package.json.bak'), sourcePackagePath);