Repository: ember-cli/ember-try
Pull request #964 (2023-09-05 19:35:00)

Drop support for npm v4
Closes https://github.com/ember-cli/ember-try/pull/961.


Patch:
diff --git a/README.md b/README.md
index 38373b5..e8feba7 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,7 @@ module.exports = async function() {
     /*
       `npmOptions` - options to be passed to `npm`.
     */
-    npmOptions: ['--loglevel=silent', '--no-shrinkwrap=true'],
+    npmOptions: ['--loglevel=silent'],
     /*
       If set to true, the `versionCompatibility` key under `ember-addon` in `package.json` will be used to
       automatically generate scenarios that will deep merge with any in this configuration file.
@@ -218,7 +218,7 @@ If you include `usePnpm: true` in your `ember-try` config, all npm scenarios wil
 
 ##### A note on npm scenarios with lockfiles
 
-Lockfiles are ignored by `ember-try`. (`yarn` will run with `--no-lockfile` and `npm` will be run with `--no-shrinkwrap` and `pnpm` will be run with `--no-lockfile`).
+Lockfiles are ignored by `ember-try`. (`yarn` will run with `--no-lockfile` and `npm` will be run with `--no-package-lock` and `pnpm` will be run with `--no-lockfile`).
 When testing various scenarios, it's important to "float" dependencies so that the scenarios are run with the latest satisfying versions of dependencies a user of the project would get.
 
 ##### Workspaces
diff --git a/lib/dependency-manager-adapters/npm.js b/lib/dependency-manager-adapters/npm.js
index cbe6f74..de51bbb 100644
--- a/lib/dependency-manager-adapters/npm.js
+++ b/lib/dependency-manager-adapters/npm.js
@@ -21,8 +21,6 @@ module.exports = CoreObject.extend({
   configKey: 'npm',
   packageJSON: 'package.json',
   packageJSONBackupFileName: 'package.json.ember-try',
-  npmShrinkWrap: 'npm-shrinkwrap.json',
-  npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try',
   packageLock: 'package-lock.json',
   packageLockBackupFileName: 'package-lock.json.ember-try',
 
@@ -68,10 +66,6 @@ module.exports = CoreObject.extend({
         cleanupTasks.push(rimraf(path.join(this.cwd, this.yarnLockBackupFileName)));
       }
 
-      if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) {
-        cleanupTasks.push(rimraf(path.join(this.cwd, this.npmShrinkWrapBackupFileName)));
-      }
-
       if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) {
         cleanupTasks.push(rimraf(path.join(this.cwd, this.packageLockBackupFileName)));
       }
@@ -128,25 +122,14 @@ module.exports = CoreObject.extend({
         if (mgrOptions.indexOf('--ignore-engines') === -1) {
           mgrOptions = mgrOptions.concat(['--ignore-engines']);
         }
-      } else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) {
-        mgrOptions = mgrOptions.concat(['--no-shrinkwrap']);
+      } else if (mgrOptions.indexOf('--no-package-lock') === -1) {
+        mgrOptions = mgrOptions.concat(['--no-package-lock']);
       }
     }
 
     debug('Run npm/yarn install with options %s', mgrOptions);
 
     await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
-
-    if (!this.useYarnCommand) {
-      let res = await this.run('npm', ['--version'], { cwd: this.cwd, stdio: 'pipe' });
-      let version = res.stdout;
-      if (version.match(/^4./)) {
-        debug('Running npm prune because version is %s', version);
-        return await this.run(this.configKey, ['prune'], { cwd: this.cwd });
-      }
-
-      debug('Not running npm prune because version is %s', version);
-    }
   },
 
   applyDependencySet(depSet) {
@@ -229,11 +212,6 @@ module.exports = CoreObject.extend({
       restoreTasks.push(copy(yarnLockBackupFileName, path.join(this.cwd, this.yarnLock)));
     }
 
-    let npmShrinkWrapBackupFileName = path.join(this.cwd, this.npmShrinkWrapBackupFileName);
-    if (fs.existsSync(npmShrinkWrapBackupFileName)) {
-      restoreTasks.push(copy(npmShrinkWrapBackupFileName, path.join(this.cwd, this.npmShrinkWrap)));
-    }
-
     let packageLockBackupFileName = path.join(this.cwd, this.packageLockBackupFileName);
     if (fs.existsSync(packageLockBackupFileName)) {
       restoreTasks.push(copy(packageLockBackupFileName, path.join(this.cwd, this.packageLock)));
@@ -257,13 +235,6 @@ module.exports = CoreObject.extend({
       backupTasks.push(copy(yarnLockPath, path.join(this.cwd, this.yarnLockBackupFileName)));
     }
 
-    let npmShrinkWrapPath = path.join(this.cwd, this.npmShrinkWrap);
-    if (fs.existsSync(npmShrinkWrapPath)) {
-      backupTasks.push(
-        copy(npmShrinkWrapPath, path.join(this.cwd, this.npmShrinkWrapBackupFileName))
-      );
-    }
-
     let packageLockPath = path.join(this.cwd, this.packageLock);
     if (fs.existsSync(packageLockPath)) {
       backupTasks.push(copy(packageLockPath, path.join(this.cwd, this.packageLockBackupFileName)));


Test patch:
diff --git a/smoke-test-app/.eslintignore b/smoke-test-app/.eslintignore
index 5975725..4cd2927 100644
--- a/smoke-test-app/.eslintignore
+++ b/smoke-test-app/.eslintignore
@@ -18,7 +18,6 @@
 
 # ember-try
 /bower.json.ember-try
-/npm-shrinkwrap.json.ember-try
 /package.json.ember-try
 /package-lock.json.ember-try
 /yarn.lock.ember-try
diff --git a/smoke-test-app/.gitignore b/smoke-test-app/.gitignore
index db375fe..6c714c8 100644
--- a/smoke-test-app/.gitignore
+++ b/smoke-test-app/.gitignore
@@ -22,7 +22,6 @@
 
 # ember-try
 /bower.json.ember-try
-/npm-shrinkwrap.json.ember-try
 /package.json.ember-try
 /package-lock.json.ember-try
 /yarn.lock.ember-try
diff --git a/smoke-test-app/.npmignore b/smoke-test-app/.npmignore
index 9c4b731..75fc998 100644
--- a/smoke-test-app/.npmignore
+++ b/smoke-test-app/.npmignore
@@ -32,7 +32,6 @@
 
 # ember-try
 /bower.json.ember-try
-/npm-shrinkwrap.json.ember-try
 /package.json.ember-try
 /package-lock.json.ember-try
 /yarn.lock.ember-try
diff --git a/smoke-test-app/.prettierignore b/smoke-test-app/.prettierignore
index b9caf68..e4c1d8a 100644
--- a/smoke-test-app/.prettierignore
+++ b/smoke-test-app/.prettierignore
@@ -18,7 +18,6 @@
 
 # ember-try
 /bower.json.ember-try
-/npm-shrinkwrap.json.ember-try
 /package.json.ember-try
 /package-lock.json.ember-try
 /yarn.lock.ember-try
diff --git a/test/dependency-manager-adapters/npm-adapter-test.js b/test/dependency-manager-adapters/npm-adapter-test.js
index 87ad398..d91d920 100644
--- a/test/dependency-manager-adapters/npm-adapter-test.js
+++ b/test/dependency-manager-adapters/npm-adapter-test.js
@@ -40,11 +40,10 @@ describe('npmAdapter', () => {
       });
     });
 
-    it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', async () => {
+    it('backs up the yarn.lock file and package-lock.json if they exist', async () => {
       fs.mkdirSync('node_modules');
       writeJSONFile('package.json', { originalPackageJSON: true });
       writeJSONFile('yarn.lock', { originalYarnLock: true });
-      writeJSONFile('npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
       writeJSONFile('package-lock.json', { originalPackageLock: true });
 
       let adapter = new NpmAdapter({ cwd: tmpdir });
@@ -56,9 +55,6 @@ describe('npmAdapter', () => {
       assertFileContainsJSON(path.join(tmpdir, 'yarn.lock.ember-try'), {
         originalYarnLock: true,
       });
-      assertFileContainsJSON(path.join(tmpdir, 'npm-shrinkwrap.json.ember-try'), {
-        originalNpmShrinkWrap: true,
-      });
       assertFileContainsJSON(path.join(tmpdir, 'package-lock.json.ember-try'), {
         originalPackageLock: true,
       });
@@ -67,26 +63,19 @@ describe('npmAdapter', () => {
 
   describe('#_install', () => {
     describe('without yarn', () => {
-      it('only runs npm install with npm 5', async () => {
+      it('runs npm install', async () => {
         writeJSONFile('package.json', fixturePackage);
         let runCount = 0;
         let stubbedRun = generateMockRun(
           [
             {
-              command: 'npm install --no-shrinkwrap',
+              command: 'npm install --no-package-lock',
               callback(command, args, opts) {
                 runCount++;
                 expect(opts).to.have.property('cwd', tmpdir);
                 return RSVP.resolve();
               },
             },
-            {
-              command: 'npm --version',
-              callback() {
-                runCount++;
-                return RSVP.resolve({ stdout: '5.7.1' });
-              },
-            },
           ],
           { allowPassthrough: false }
         );
@@ -97,48 +86,7 @@ describe('npmAdapter', () => {
         });
 
         await adapter._install();
-        expect(runCount).to.equal(2);
-      });
-
-      it('runs npm prune and npm install with npm 4', async () => {
-        writeJSONFile('package.json', fixturePackage);
-        let runCount = 0;
-        let stubbedRun = generateMockRun(
-          [
-            {
-              command: 'npm install --no-shrinkwrap',
-              callback(command, args, opts) {
-                runCount++;
-                expect(opts).to.have.property('cwd', tmpdir);
-                return RSVP.resolve();
-              },
-            },
-            {
-              command: 'npm prune',
-              callback(command, args, opts) {
-                runCount++;
-                expect(opts).to.have.property('cwd', tmpdir);
-                return RSVP.resolve();
-              },
-            },
-            {
-              command: 'npm --version',
-              callback() {
-                runCount++;
-                return RSVP.resolve({ stdout: '4.7.1' });
-              },
-            },
-          ],
-          { allowPassthrough: false }
-        );
-
-        let adapter = new NpmAdapter({
-          cwd: tmpdir,
-          run: stubbedRun,
-        });
-
-        await adapter._install();
-        expect(runCount).to.equal(3, 'All three commands should run');
+        expect(runCount).to.equal(1);
       });
 
       it('uses managerOptions for npm commands', async () => {
@@ -147,19 +95,12 @@ describe('npmAdapter', () => {
         let stubbedRun = generateMockRun(
           [
             {
-              command: 'npm install --no-optional --no-shrinkwrap',
+              command: 'npm install --no-optional --no-package-lock',
               callback() {
                 runCount++;
                 return RSVP.resolve();
               },
             },
-            {
-              command: 'npm --version',
-              callback() {
-                runCount++;
-                return RSVP.resolve({ stdout: '5.7.1' });
-              },
-            },
           ],
           { allowPassthrough: false }
         );
@@ -171,7 +112,7 @@ describe('npmAdapter', () => {
         });
 
         await adapter._install();
-        expect(runCount).to.equal(2);
+        expect(runCount).to.equal(1);
       });
 
       it('uses buildManagerOptions for npm commands', async () => {
@@ -186,13 +127,6 @@ describe('npmAdapter', () => {
                 return RSVP.resolve();
               },
             },
-            {
-              command: 'npm --version',
-              callback() {
-                runCount++;
-                return RSVP.resolve({ stdout: '5.7.1' });
-              },
-            },
           ],
           { allowPassthrough: false }
         );
@@ -206,7 +140,7 @@ describe('npmAdapter', () => {
         });
 
         await adapter._install();
-        expect(runCount).to.equal(2, 'npm install should run with buildManagerOptions');
+        expect(runCount).to.equal(1, 'npm install should run with buildManagerOptions');
       });
 
       it('throws an error if buildManagerOptions does not return an array', async () => {
@@ -346,13 +280,11 @@ describe('npmAdapter', () => {
       assertFileContainsJSON(path.join(tmpdir, 'package.json'), { originalPackageJSON: true });
     });
 
-    it('replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist', async () => {
+    it('replaces the yarn.lock and package-lock.json with the backed up version if they exist', async () => {
       writeJSONFile('package.json.ember-try', { originalPackageJSON: true });
       writeJSONFile('package.json', { originalPackageJSON: false });
       writeJSONFile('yarn.lock.ember-try', { originalYarnLock: true });
       writeJSONFile('yarn.lock', { originalYarnLock: false });
-      writeJSONFile('npm-shrinkwrap.json.ember-try', { originalNpmShrinkWrap: true });
-      writeJSONFile('npm-shrinkwrap.json', { originalNpmShrinkWrap: false });
       writeJSONFile('package-lock.json.ember-try', { originalPackageLock: true });
       writeJSONFile('package-lock.json', { originalPackageLock: false });
 
@@ -361,9 +293,6 @@ describe('npmAdapter', () => {
 
       assertFileContainsJSON(path.join(tmpdir, 'package.json'), { originalPackageJSON: true });
       assertFileContainsJSON(path.join(tmpdir, 'yarn.lock'), { originalYarnLock: true });
-      assertFileContainsJSON(path.join(tmpdir, 'npm-shrinkwrap.json'), {
-        originalNpmShrinkWrap: true,
-      });
       assertFileContainsJSON(path.join(tmpdir, 'package-lock.json'), {
         originalPackageLock: true,
       });
@@ -376,19 +305,12 @@ describe('npmAdapter', () => {
       let stubbedRun = generateMockRun(
         [
           {
-            command: 'npm install --no-shrinkwrap',
+            command: 'npm install --no-package-lock',
             callback() {
               runCount++;
               return Promise.resolve();
             },
           },
-          {
-            command: 'npm --version',
-            callback() {
-              runCount++;
-              return RSVP.resolve({ stdout: '10.0.0' });
-            },
-          },
         ],
         { allowPassthrough: false }
       );
@@ -400,7 +322,7 @@ describe('npmAdapter', () => {
 
       await adapter._restoreOriginalDependencies();
 
-      expect(runCount).to.equal(2);
+      expect(runCount).to.equal(1);
     });
   });
 
diff --git a/test/dependency-manager-adapters/workspace-adapter-test.js b/test/dependency-manager-adapters/workspace-adapter-test.js
index e411447..51b8c45 100644
--- a/test/dependency-manager-adapters/workspace-adapter-test.js
+++ b/test/dependency-manager-adapters/workspace-adapter-test.js
@@ -71,12 +71,11 @@ describe('workspaceAdapter', () => {
         });
     });
 
-    it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', () => {
+    it('backs up the yarn.lock file and package-lock.json if they exist', () => {
       fs.ensureDirSync('packages/test/node_modules');
 
       writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
       writeJSONFile('packages/test/yarn.lock', { originalYarnLock: true });
-      writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
       writeJSONFile('packages/test/package-lock.json', { originalPackageLock: true });
       return new WorkspaceAdapter({
         cwd: tmpdir,
@@ -90,9 +89,6 @@ describe('workspaceAdapter', () => {
           assertFileContainsJSON(path.join(tmpdir, 'packages/test/yarn.lock.ember-try'), {
             originalYarnLock: true,
           });
-          assertFileContainsJSON(path.join(tmpdir, 'packages/test/npm-shrinkwrap.json.ember-try'), {
-            originalNpmShrinkWrap: true,
-          });
           assertFileContainsJSON(path.join(tmpdir, 'packages/test/package-lock.json.ember-try'), {
             originalPackageLock: true,
           });
@@ -273,12 +269,11 @@ describe('workspaceAdapter', () => {
         });
     });
 
-    it('replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist', () => {
+    it('replaces the yarn.lock and package-lock.json with the backed up version if they exist', () => {
       fs.ensureDirSync('packages/test/node_modules');
 
       writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
       writeJSONFile('packages/test/yarn.lock', { originalYarnLock: true });
-      writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
       writeJSONFile('packages/test/package-lock.json', { originalPackageLock: true });
 
       let workspaceAdapter = new WorkspaceAdapter({
@@ -292,7 +287,6 @@ describe('workspaceAdapter', () => {
         .then(() => {
           writeJSONFile('packages/test/package.json', { originalPackageJSON: false });
           writeJSONFile('packages/test/yarn.lock', { originalYarnLock: false });
-          writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: false });
           writeJSONFile('packages/test/package-lock.json', { originalPackageLock: false });
 
           return workspaceAdapter.cleanup();
@@ -304,9 +298,6 @@ describe('workspaceAdapter', () => {
           assertFileContainsJSON(path.join(tmpdir, 'packages/test/yarn.lock'), {
             originalYarnLock: true,
           });
-          assertFileContainsJSON(path.join(tmpdir, 'packages/test/npm-shrinkwrap.json'), {
-            originalNpmShrinkWrap: true,
-          });
           assertFileContainsJSON(path.join(tmpdir, 'packages/test/package-lock.json'), {
             originalPackageLock: true,
           });