Skip to content

Commit f68085c

Browse files
authored
Merge pull request #964 from bertdeblock/drop-support-for-npm-v4
Drop support for npm v4
2 parents b0f477b + 80587e6 commit f68085c

8 files changed

Lines changed: 16 additions & 136 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports = async function() {
109109
/*
110110
`npmOptions` - options to be passed to `npm`.
111111
*/
112-
npmOptions: ['--loglevel=silent', '--no-shrinkwrap=true'],
112+
npmOptions: ['--loglevel=silent'],
113113
/*
114114
If set to true, the `versionCompatibility` key under `ember-addon` in `package.json` will be used to
115115
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
218218

219219
##### A note on npm scenarios with lockfiles
220220

221-
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`).
221+
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`).
222222
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.
223223

224224
##### Workspaces

lib/dependency-manager-adapters/npm.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ module.exports = CoreObject.extend({
2121
configKey: 'npm',
2222
packageJSON: 'package.json',
2323
packageJSONBackupFileName: 'package.json.ember-try',
24-
npmShrinkWrap: 'npm-shrinkwrap.json',
25-
npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try',
2624
packageLock: 'package-lock.json',
2725
packageLockBackupFileName: 'package-lock.json.ember-try',
2826

@@ -68,10 +66,6 @@ module.exports = CoreObject.extend({
6866
cleanupTasks.push(rimraf(path.join(this.cwd, this.yarnLockBackupFileName)));
6967
}
7068

71-
if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) {
72-
cleanupTasks.push(rimraf(path.join(this.cwd, this.npmShrinkWrapBackupFileName)));
73-
}
74-
7569
if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) {
7670
cleanupTasks.push(rimraf(path.join(this.cwd, this.packageLockBackupFileName)));
7771
}
@@ -128,25 +122,14 @@ module.exports = CoreObject.extend({
128122
if (mgrOptions.indexOf('--ignore-engines') === -1) {
129123
mgrOptions = mgrOptions.concat(['--ignore-engines']);
130124
}
131-
} else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) {
132-
mgrOptions = mgrOptions.concat(['--no-shrinkwrap']);
125+
} else if (mgrOptions.indexOf('--no-package-lock') === -1) {
126+
mgrOptions = mgrOptions.concat(['--no-package-lock']);
133127
}
134128
}
135129

136130
debug('Run npm/yarn install with options %s', mgrOptions);
137131

138132
await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
139-
140-
if (!this.useYarnCommand) {
141-
let res = await this.run('npm', ['--version'], { cwd: this.cwd, stdio: 'pipe' });
142-
let version = res.stdout;
143-
if (version.match(/^4./)) {
144-
debug('Running npm prune because version is %s', version);
145-
return await this.run(this.configKey, ['prune'], { cwd: this.cwd });
146-
}
147-
148-
debug('Not running npm prune because version is %s', version);
149-
}
150133
},
151134

152135
applyDependencySet(depSet) {
@@ -229,11 +212,6 @@ module.exports = CoreObject.extend({
229212
restoreTasks.push(copy(yarnLockBackupFileName, path.join(this.cwd, this.yarnLock)));
230213
}
231214

232-
let npmShrinkWrapBackupFileName = path.join(this.cwd, this.npmShrinkWrapBackupFileName);
233-
if (fs.existsSync(npmShrinkWrapBackupFileName)) {
234-
restoreTasks.push(copy(npmShrinkWrapBackupFileName, path.join(this.cwd, this.npmShrinkWrap)));
235-
}
236-
237215
let packageLockBackupFileName = path.join(this.cwd, this.packageLockBackupFileName);
238216
if (fs.existsSync(packageLockBackupFileName)) {
239217
restoreTasks.push(copy(packageLockBackupFileName, path.join(this.cwd, this.packageLock)));
@@ -257,13 +235,6 @@ module.exports = CoreObject.extend({
257235
backupTasks.push(copy(yarnLockPath, path.join(this.cwd, this.yarnLockBackupFileName)));
258236
}
259237

260-
let npmShrinkWrapPath = path.join(this.cwd, this.npmShrinkWrap);
261-
if (fs.existsSync(npmShrinkWrapPath)) {
262-
backupTasks.push(
263-
copy(npmShrinkWrapPath, path.join(this.cwd, this.npmShrinkWrapBackupFileName))
264-
);
265-
}
266-
267238
let packageLockPath = path.join(this.cwd, this.packageLock);
268239
if (fs.existsSync(packageLockPath)) {
269240
backupTasks.push(copy(packageLockPath, path.join(this.cwd, this.packageLockBackupFileName)));

smoke-test-app/.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# ember-try
2020
/bower.json.ember-try
21-
/npm-shrinkwrap.json.ember-try
2221
/package.json.ember-try
2322
/package-lock.json.ember-try
2423
/yarn.lock.ember-try

smoke-test-app/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
# ember-try
2424
/bower.json.ember-try
25-
/npm-shrinkwrap.json.ember-try
2625
/package.json.ember-try
2726
/package-lock.json.ember-try
2827
/yarn.lock.ember-try

smoke-test-app/.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
# ember-try
3434
/bower.json.ember-try
35-
/npm-shrinkwrap.json.ember-try
3635
/package.json.ember-try
3736
/package-lock.json.ember-try
3837
/yarn.lock.ember-try

smoke-test-app/.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# ember-try
2020
/bower.json.ember-try
21-
/npm-shrinkwrap.json.ember-try
2221
/package.json.ember-try
2322
/package-lock.json.ember-try
2423
/yarn.lock.ember-try

test/dependency-manager-adapters/npm-adapter-test.js

Lines changed: 10 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ describe('npmAdapter', () => {
4040
});
4141
});
4242

43-
it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', async () => {
43+
it('backs up the yarn.lock file and package-lock.json if they exist', async () => {
4444
fs.mkdirSync('node_modules');
4545
writeJSONFile('package.json', { originalPackageJSON: true });
4646
writeJSONFile('yarn.lock', { originalYarnLock: true });
47-
writeJSONFile('npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
4847
writeJSONFile('package-lock.json', { originalPackageLock: true });
4948

5049
let adapter = new NpmAdapter({ cwd: tmpdir });
@@ -56,9 +55,6 @@ describe('npmAdapter', () => {
5655
assertFileContainsJSON(path.join(tmpdir, 'yarn.lock.ember-try'), {
5756
originalYarnLock: true,
5857
});
59-
assertFileContainsJSON(path.join(tmpdir, 'npm-shrinkwrap.json.ember-try'), {
60-
originalNpmShrinkWrap: true,
61-
});
6258
assertFileContainsJSON(path.join(tmpdir, 'package-lock.json.ember-try'), {
6359
originalPackageLock: true,
6460
});
@@ -67,26 +63,19 @@ describe('npmAdapter', () => {
6763

6864
describe('#_install', () => {
6965
describe('without yarn', () => {
70-
it('only runs npm install with npm 5', async () => {
66+
it('runs npm install', async () => {
7167
writeJSONFile('package.json', fixturePackage);
7268
let runCount = 0;
7369
let stubbedRun = generateMockRun(
7470
[
7571
{
76-
command: 'npm install --no-shrinkwrap',
72+
command: 'npm install --no-package-lock',
7773
callback(command, args, opts) {
7874
runCount++;
7975
expect(opts).to.have.property('cwd', tmpdir);
8076
return RSVP.resolve();
8177
},
8278
},
83-
{
84-
command: 'npm --version',
85-
callback() {
86-
runCount++;
87-
return RSVP.resolve({ stdout: '5.7.1' });
88-
},
89-
},
9079
],
9180
{ allowPassthrough: false }
9281
);
@@ -97,48 +86,7 @@ describe('npmAdapter', () => {
9786
});
9887

9988
await adapter._install();
100-
expect(runCount).to.equal(2);
101-
});
102-
103-
it('runs npm prune and npm install with npm 4', async () => {
104-
writeJSONFile('package.json', fixturePackage);
105-
let runCount = 0;
106-
let stubbedRun = generateMockRun(
107-
[
108-
{
109-
command: 'npm install --no-shrinkwrap',
110-
callback(command, args, opts) {
111-
runCount++;
112-
expect(opts).to.have.property('cwd', tmpdir);
113-
return RSVP.resolve();
114-
},
115-
},
116-
{
117-
command: 'npm prune',
118-
callback(command, args, opts) {
119-
runCount++;
120-
expect(opts).to.have.property('cwd', tmpdir);
121-
return RSVP.resolve();
122-
},
123-
},
124-
{
125-
command: 'npm --version',
126-
callback() {
127-
runCount++;
128-
return RSVP.resolve({ stdout: '4.7.1' });
129-
},
130-
},
131-
],
132-
{ allowPassthrough: false }
133-
);
134-
135-
let adapter = new NpmAdapter({
136-
cwd: tmpdir,
137-
run: stubbedRun,
138-
});
139-
140-
await adapter._install();
141-
expect(runCount).to.equal(3, 'All three commands should run');
89+
expect(runCount).to.equal(1);
14290
});
14391

14492
it('uses managerOptions for npm commands', async () => {
@@ -147,19 +95,12 @@ describe('npmAdapter', () => {
14795
let stubbedRun = generateMockRun(
14896
[
14997
{
150-
command: 'npm install --no-optional --no-shrinkwrap',
98+
command: 'npm install --no-optional --no-package-lock',
15199
callback() {
152100
runCount++;
153101
return RSVP.resolve();
154102
},
155103
},
156-
{
157-
command: 'npm --version',
158-
callback() {
159-
runCount++;
160-
return RSVP.resolve({ stdout: '5.7.1' });
161-
},
162-
},
163104
],
164105
{ allowPassthrough: false }
165106
);
@@ -171,7 +112,7 @@ describe('npmAdapter', () => {
171112
});
172113

173114
await adapter._install();
174-
expect(runCount).to.equal(2);
115+
expect(runCount).to.equal(1);
175116
});
176117

177118
it('uses buildManagerOptions for npm commands', async () => {
@@ -186,13 +127,6 @@ describe('npmAdapter', () => {
186127
return RSVP.resolve();
187128
},
188129
},
189-
{
190-
command: 'npm --version',
191-
callback() {
192-
runCount++;
193-
return RSVP.resolve({ stdout: '5.7.1' });
194-
},
195-
},
196130
],
197131
{ allowPassthrough: false }
198132
);
@@ -206,7 +140,7 @@ describe('npmAdapter', () => {
206140
});
207141

208142
await adapter._install();
209-
expect(runCount).to.equal(2, 'npm install should run with buildManagerOptions');
143+
expect(runCount).to.equal(1, 'npm install should run with buildManagerOptions');
210144
});
211145

212146
it('throws an error if buildManagerOptions does not return an array', async () => {
@@ -346,13 +280,11 @@ describe('npmAdapter', () => {
346280
assertFileContainsJSON(path.join(tmpdir, 'package.json'), { originalPackageJSON: true });
347281
});
348282

349-
it('replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist', async () => {
283+
it('replaces the yarn.lock and package-lock.json with the backed up version if they exist', async () => {
350284
writeJSONFile('package.json.ember-try', { originalPackageJSON: true });
351285
writeJSONFile('package.json', { originalPackageJSON: false });
352286
writeJSONFile('yarn.lock.ember-try', { originalYarnLock: true });
353287
writeJSONFile('yarn.lock', { originalYarnLock: false });
354-
writeJSONFile('npm-shrinkwrap.json.ember-try', { originalNpmShrinkWrap: true });
355-
writeJSONFile('npm-shrinkwrap.json', { originalNpmShrinkWrap: false });
356288
writeJSONFile('package-lock.json.ember-try', { originalPackageLock: true });
357289
writeJSONFile('package-lock.json', { originalPackageLock: false });
358290

@@ -361,9 +293,6 @@ describe('npmAdapter', () => {
361293

362294
assertFileContainsJSON(path.join(tmpdir, 'package.json'), { originalPackageJSON: true });
363295
assertFileContainsJSON(path.join(tmpdir, 'yarn.lock'), { originalYarnLock: true });
364-
assertFileContainsJSON(path.join(tmpdir, 'npm-shrinkwrap.json'), {
365-
originalNpmShrinkWrap: true,
366-
});
367296
assertFileContainsJSON(path.join(tmpdir, 'package-lock.json'), {
368297
originalPackageLock: true,
369298
});
@@ -376,19 +305,12 @@ describe('npmAdapter', () => {
376305
let stubbedRun = generateMockRun(
377306
[
378307
{
379-
command: 'npm install --no-shrinkwrap',
308+
command: 'npm install --no-package-lock',
380309
callback() {
381310
runCount++;
382311
return Promise.resolve();
383312
},
384313
},
385-
{
386-
command: 'npm --version',
387-
callback() {
388-
runCount++;
389-
return RSVP.resolve({ stdout: '10.0.0' });
390-
},
391-
},
392314
],
393315
{ allowPassthrough: false }
394316
);
@@ -400,7 +322,7 @@ describe('npmAdapter', () => {
400322

401323
await adapter._restoreOriginalDependencies();
402324

403-
expect(runCount).to.equal(2);
325+
expect(runCount).to.equal(1);
404326
});
405327
});
406328

test/dependency-manager-adapters/workspace-adapter-test.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ describe('workspaceAdapter', () => {
7171
});
7272
});
7373

74-
it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', () => {
74+
it('backs up the yarn.lock file and package-lock.json if they exist', () => {
7575
fs.ensureDirSync('packages/test/node_modules');
7676

7777
writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
7878
writeJSONFile('packages/test/yarn.lock', { originalYarnLock: true });
79-
writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
8079
writeJSONFile('packages/test/package-lock.json', { originalPackageLock: true });
8180
return new WorkspaceAdapter({
8281
cwd: tmpdir,
@@ -90,9 +89,6 @@ describe('workspaceAdapter', () => {
9089
assertFileContainsJSON(path.join(tmpdir, 'packages/test/yarn.lock.ember-try'), {
9190
originalYarnLock: true,
9291
});
93-
assertFileContainsJSON(path.join(tmpdir, 'packages/test/npm-shrinkwrap.json.ember-try'), {
94-
originalNpmShrinkWrap: true,
95-
});
9692
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package-lock.json.ember-try'), {
9793
originalPackageLock: true,
9894
});
@@ -273,12 +269,11 @@ describe('workspaceAdapter', () => {
273269
});
274270
});
275271

276-
it('replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist', () => {
272+
it('replaces the yarn.lock and package-lock.json with the backed up version if they exist', () => {
277273
fs.ensureDirSync('packages/test/node_modules');
278274

279275
writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
280276
writeJSONFile('packages/test/yarn.lock', { originalYarnLock: true });
281-
writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
282277
writeJSONFile('packages/test/package-lock.json', { originalPackageLock: true });
283278

284279
let workspaceAdapter = new WorkspaceAdapter({
@@ -292,7 +287,6 @@ describe('workspaceAdapter', () => {
292287
.then(() => {
293288
writeJSONFile('packages/test/package.json', { originalPackageJSON: false });
294289
writeJSONFile('packages/test/yarn.lock', { originalYarnLock: false });
295-
writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: false });
296290
writeJSONFile('packages/test/package-lock.json', { originalPackageLock: false });
297291

298292
return workspaceAdapter.cleanup();
@@ -304,9 +298,6 @@ describe('workspaceAdapter', () => {
304298
assertFileContainsJSON(path.join(tmpdir, 'packages/test/yarn.lock'), {
305299
originalYarnLock: true,
306300
});
307-
assertFileContainsJSON(path.join(tmpdir, 'packages/test/npm-shrinkwrap.json'), {
308-
originalNpmShrinkWrap: true,
309-
});
310301
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package-lock.json'), {
311302
originalPackageLock: true,
312303
});

0 commit comments

Comments
 (0)