Skip to content

Commit

Permalink
Merge pull request #964 from bertdeblock/drop-support-for-npm-v4
Browse files Browse the repository at this point in the history
Drop support for npm v4
  • Loading branch information
Bert De Block committed Sep 6, 2023
2 parents b0f477b + 80587e6 commit f68085c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 136 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
33 changes: 2 additions & 31 deletions lib/dependency-manager-adapters/npm.js
Expand Up @@ -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',

Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)));
Expand All @@ -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)));
Expand Down
1 change: 0 additions & 1 deletion smoke-test-app/.eslintignore
Expand Up @@ -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
1 change: 0 additions & 1 deletion smoke-test-app/.gitignore
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion smoke-test-app/.npmignore
Expand Up @@ -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
1 change: 0 additions & 1 deletion smoke-test-app/.prettierignore
Expand Up @@ -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
98 changes: 10 additions & 88 deletions test/dependency-manager-adapters/npm-adapter-test.js
Expand Up @@ -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 });
Expand All @@ -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,
});
Expand All @@ -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 }
);
Expand All @@ -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 () => {
Expand All @@ -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 }
);
Expand All @@ -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 () => {
Expand All @@ -186,13 +127,6 @@ describe('npmAdapter', () => {
return RSVP.resolve();
},
},
{
command: 'npm --version',
callback() {
runCount++;
return RSVP.resolve({ stdout: '5.7.1' });
},
},
],
{ allowPassthrough: false }
);
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 });

Expand All @@ -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,
});
Expand All @@ -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 }
);
Expand All @@ -400,7 +322,7 @@ describe('npmAdapter', () => {

await adapter._restoreOriginalDependencies();

expect(runCount).to.equal(2);
expect(runCount).to.equal(1);
});
});

Expand Down
13 changes: 2 additions & 11 deletions test/dependency-manager-adapters/workspace-adapter-test.js
Expand Up @@ -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,
Expand All @@ -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,
});
Expand Down Expand Up @@ -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({
Expand All @@ -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();
Expand All @@ -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,
});
Expand Down

0 comments on commit f68085c

Please sign in to comment.