Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of rsvp #1021

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions lib/dependency-manager-adapters/npm.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
'use strict';

const CoreObject = require('core-object');
const fs = require('fs-extra');
const path = require('path');
const debug = require('debug')('ember-try:dependency-manager-adapter:npm');
const chalk = require('chalk');
const semver = require('semver');
const Backup = require('../utils/backup');

module.exports = CoreObject.extend({
init() {
this._super.apply(this, arguments);
module.exports = class {
configKey = 'npm';
packageJSON = 'package.json';
packageLock = 'package-lock.json';
useYarnCommand = false;
yarnLock = 'yarn.lock';

constructor(options) {
this.buildManagerOptions = options.buildManagerOptions;
this.cwd = options.cwd;
this.managerOptions = options.managerOptions;
this.run = options.run || require('../utils/run');
this.useYarnCommand = options.useYarnCommand ?? false;

this.backup = new Backup({ cwd: this.cwd });
this.run = this.run || require('../utils/run');
},
useYarnCommand: false,
yarnLock: 'yarn.lock',
configKey: 'npm',
packageJSON: 'package.json',
packageLock: 'package-lock.json',
}

async setup(options) {
if (!options) {
Expand All @@ -28,7 +32,7 @@ module.exports = CoreObject.extend({
this._runYarnCheck(options.ui);

return await this._backupOriginalDependencies();
},
}

async changeToDependencySet(depSet) {
this.applyDependencySet(depSet);
Expand All @@ -48,15 +52,15 @@ module.exports = CoreObject.extend({
debug('Switched to dependencies: \n', currentDeps);

return currentDeps;
},
}

async cleanup() {
try {
await this._restoreOriginalDependencies();
} catch (e) {
console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console
}
},
}

_runYarnCheck(ui) {
if (!this.useYarnCommand) {
Expand All @@ -72,7 +76,7 @@ module.exports = CoreObject.extend({
// If no yarn.lock is found, no need to warn.
}
}
},
}

_findCurrentVersionOf(packageName) {
let filename = path.join(this.cwd, 'node_modules', packageName, this.packageJSON);
Expand All @@ -81,7 +85,7 @@ module.exports = CoreObject.extend({
} else {
return null;
}
},
}

async _install(depSet) {
let mgrOptions = this.managerOptions || [];
Expand Down Expand Up @@ -112,7 +116,7 @@ module.exports = CoreObject.extend({
debug('Run npm/yarn install with options %s', mgrOptions);

await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
},
}

applyDependencySet(depSet) {
debug('Changing to dependency set: %s', JSON.stringify(depSet));
Expand All @@ -129,7 +133,7 @@ module.exports = CoreObject.extend({
debug('Write package.json with: \n', JSON.stringify(newPackageJSON));

fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
},
}

_packageJSONForDependencySet(packageJSON, depSet) {
this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
Expand All @@ -144,7 +148,7 @@ module.exports = CoreObject.extend({
}

return packageJSON;
},
}

_overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
if (!depSet[kindOfDependency]) {
Expand Down Expand Up @@ -177,15 +181,15 @@ module.exports = CoreObject.extend({
}
}
});
},
}

async _restoreOriginalDependencies() {
await this.backup.restoreFiles([this.packageJSON, this.packageLock, this.yarnLock]);
await this.backup.cleanUp();
await this._install();
},
}

async _backupOriginalDependencies() {
await this.backup.addFiles([this.packageJSON, this.packageLock, this.yarnLock]);
},
});
}
};
42 changes: 22 additions & 20 deletions lib/dependency-manager-adapters/pnpm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const CoreObject = require('core-object');
const fs = require('fs-extra');
const path = require('path');
const debug = require('debug')('ember-try:dependency-manager-adapter:pnpm');
Expand All @@ -11,21 +10,24 @@ const semverGte = require('semver/functions/gte');
const PACKAGE_JSON = 'package.json';
const PNPM_LOCKFILE = 'pnpm-lock.yaml';

module.exports = CoreObject.extend({
module.exports = class {
// This still needs to be `npm` because we're still reading the dependencies
// from the `npm` key of the ember-try config.
configKey: 'npm',
configKey = 'npm';

constructor(options) {
this.buildManagerOptions = options.buildManagerOptions;
this.cwd = options.cwd;
this.managerOptions = options.managerOptions;
this.run = options.run || require('../utils/run');

init() {
this._super.apply(this, arguments);
this.backup = new Backup({ cwd: this.cwd });
this.run = this.run || require('../utils/run');
},
}

async setup() {
await this._throwOnResolutionMode();
await this.backup.addFiles([PACKAGE_JSON, PNPM_LOCKFILE]);
},
}

async changeToDependencySet(depSet) {
await this.applyDependencySet(depSet);
Expand All @@ -44,7 +46,7 @@ module.exports = CoreObject.extend({
debug('Switched to dependencies: \n', currentDeps);

return currentDeps;
},
}

async cleanup() {
try {
Expand All @@ -54,7 +56,7 @@ module.exports = CoreObject.extend({
} catch (e) {
console.log('Error cleaning up scenario:', e); // eslint-disable-line no-console
}
},
}

_findCurrentVersionOf(packageName) {
let filename = path.join(this.cwd, 'node_modules', packageName, PACKAGE_JSON);
Expand All @@ -63,7 +65,7 @@ module.exports = CoreObject.extend({
} else {
return null;
}
},
}

/**
* pnpm versions 8.0.0 through 8.6.* have the `resolution-mode` setting inverted to
Expand All @@ -82,12 +84,12 @@ module.exports = CoreObject.extend({
'You are using an old version of pnpm that uses wrong resolution mode that violates ember-try expectations. Please either upgrade pnpm or set `resolution-mode` to `highest` in `.npmrc`.',
);
}
},
}

async _getPnpmVersion() {
let result = await this.run('pnpm', ['--version'], { cwd: this.cwd, stdio: 'pipe' });
return result.stdout.split('\n')[0];
},
}

async _getResolutionMode() {
let result = await this.run('pnpm', ['config', 'get', 'resolution-mode'], {
Expand All @@ -96,7 +98,7 @@ module.exports = CoreObject.extend({
});

return result.stdout.split('\n')[0];
},
}

_isResolutionModeWrong(versionStr, resolutionMode) {
// The `resolution-mode` is not set explicitly, and the current pnpm version makes it default
Expand All @@ -106,7 +108,7 @@ module.exports = CoreObject.extend({
}

return false;
},
}

async _install(depSet) {
let mgrOptions = this.managerOptions || [];
Expand Down Expand Up @@ -134,7 +136,7 @@ module.exports = CoreObject.extend({
debug('Run pnpm install with options %s', mgrOptions);

await this.run('pnpm', [].concat(['install'], mgrOptions), { cwd: this.cwd });
},
}

async applyDependencySet(depSet) {
debug('Changing to dependency set: %s', JSON.stringify(depSet));
Expand All @@ -155,7 +157,7 @@ module.exports = CoreObject.extend({
// diff compared to the original locked dependency set.

await this.backup.restoreFile(PNPM_LOCKFILE);
},
}

_packageJSONForDependencySet(packageJSON, depSet) {
this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
Expand All @@ -167,7 +169,7 @@ module.exports = CoreObject.extend({
this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides');

return packageJSON;
},
}

_overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
if (!depSet[kindOfDependency]) {
Expand All @@ -188,5 +190,5 @@ module.exports = CoreObject.extend({
packageJSON[kindOfDependency][packageName] = version;
}
}
},
});
}
};
30 changes: 16 additions & 14 deletions lib/dependency-manager-adapters/workspace.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
'use strict';

const CoreObject = require('core-object');
const fs = require('fs-extra');
const path = require('path');
const debug = require('debug')('ember-try:dependency-manager-adapter:workspaces');
const walkSync = require('walk-sync');

const NpmAdapter = require('./npm');

module.exports = CoreObject.extend({
init() {
this._super.apply(this, arguments);
this.run = this.run || require('../utils/run');
module.exports = class {
packageJSON = 'package.json';

constructor(options) {
this.buildManagerOptions = options.buildManagerOptions;
this.cwd = options.cwd;
this.managerOptions = options.managerOptions;
this.run = options.run || require('../utils/run');
this.useYarnCommand = options.useYarnCommand ?? false;

if (!this.useYarnCommand) {
throw new Error(
Expand Down Expand Up @@ -51,17 +55,15 @@ module.exports = CoreObject.extend({
buildManagerOptions: this.buildManagerOptions,
});
});
},

packageJSON: 'package.json',
}

setup(options) {
if (!options) {
options = {};
}

return Promise.all(this._packageAdapters.map((adapter) => adapter.setup(options)));
},
}

async changeToDependencySet(depSet) {
// TODO: What should this do for tables? Nesting? Needs different output
Expand All @@ -83,11 +85,11 @@ module.exports = CoreObject.extend({
debug('Switched to dependencies: \n', currentDeps);

return currentDeps;
},
}

cleanup() {
return Promise.all(this._packageAdapters.map((adapter) => adapter.cleanup()));
},
}

_install(depSet) {
let mgrOptions = this.managerOptions || [];
Expand All @@ -113,9 +115,9 @@ module.exports = CoreObject.extend({
debug('Run yarn install with options %s', mgrOptions);

return this.run('yarn', ['install', ...mgrOptions], { cwd: this.cwd });
},
}

_findCurrentVersionOf(dep) {
return this._packageAdapters[0]._findCurrentVersionOf(dep);
},
});
}
};
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"dependencies": {
"chalk": "^4.1.2",
"cli-table3": "^0.6.0",
"core-object": "^3.1.5",
"debug": "^4.3.2",
"ember-try-config": "^4.0.0",
"execa": "^4.1.0",
Expand All @@ -58,7 +57,6 @@
"nyc": "^17.1.0",
"prettier": "^3.3.3",
"release-it": "^17.10.0",
"rsvp": "^4.7.0",
"sinon": "^19.0.2",
"tmp-sync": "^1.1.0"
},
Expand Down
5 changes: 2 additions & 3 deletions test/commands/try-each-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const expect = require('chai').expect;
const RSVP = require('rsvp');
const TryEachCommand = require('../../lib/commands/try-each');

const origTryEachTask = TryEachCommand._TryEachTask;
Expand All @@ -16,7 +15,7 @@ describe('commands/try-each', () => {

beforeEach(() => {
TryEachCommand._getConfig = function () {
return RSVP.resolve(mockConfig || { scenarios: [] });
return Promise.resolve(mockConfig || { scenarios: [] });
};

TryEachCommand._TryEachTask = MockTryEachTask;
Expand All @@ -33,7 +32,7 @@ describe('commands/try-each', () => {
TryEachCommand._getConfig = function (options) {
configPath = options.configPath;

return RSVP.resolve({ scenarios: [{ name: 'foo' }] });
return Promise.resolve({ scenarios: [{ name: 'foo' }] });
};

TryEachCommand.run({ configPath: 'foo/bar/widget.js' }, ['foo']);
Expand Down
Loading
Loading