diff --git a/lib/dependency-manager-adapters/npm.js b/lib/dependency-manager-adapters/npm.js index 8ecbc73d..acc58406 100644 --- a/lib/dependency-manager-adapters/npm.js +++ b/lib/dependency-manager-adapters/npm.js @@ -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:npm'); @@ -8,17 +7,22 @@ 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) { @@ -28,7 +32,7 @@ module.exports = CoreObject.extend({ this._runYarnCheck(options.ui); return await this._backupOriginalDependencies(); - }, + } async changeToDependencySet(depSet) { this.applyDependencySet(depSet); @@ -48,7 +52,7 @@ module.exports = CoreObject.extend({ debug('Switched to dependencies: \n', currentDeps); return currentDeps; - }, + } async cleanup() { try { @@ -56,7 +60,7 @@ module.exports = CoreObject.extend({ } catch (e) { console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console } - }, + } _runYarnCheck(ui) { if (!this.useYarnCommand) { @@ -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); @@ -81,7 +85,7 @@ module.exports = CoreObject.extend({ } else { return null; } - }, + } async _install(depSet) { let mgrOptions = this.managerOptions || []; @@ -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)); @@ -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'); @@ -144,7 +148,7 @@ module.exports = CoreObject.extend({ } return packageJSON; - }, + } _overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) { if (!depSet[kindOfDependency]) { @@ -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]); - }, -}); + } +}; diff --git a/lib/dependency-manager-adapters/pnpm.js b/lib/dependency-manager-adapters/pnpm.js index a854b306..81517150 100644 --- a/lib/dependency-manager-adapters/pnpm.js +++ b/lib/dependency-manager-adapters/pnpm.js @@ -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'); @@ -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); @@ -44,7 +46,7 @@ module.exports = CoreObject.extend({ debug('Switched to dependencies: \n', currentDeps); return currentDeps; - }, + } async cleanup() { try { @@ -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); @@ -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 @@ -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'], { @@ -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 @@ -106,7 +108,7 @@ module.exports = CoreObject.extend({ } return false; - }, + } async _install(depSet) { let mgrOptions = this.managerOptions || []; @@ -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)); @@ -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'); @@ -167,7 +169,7 @@ module.exports = CoreObject.extend({ this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides'); return packageJSON; - }, + } _overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) { if (!depSet[kindOfDependency]) { @@ -188,5 +190,5 @@ module.exports = CoreObject.extend({ packageJSON[kindOfDependency][packageName] = version; } } - }, -}); + } +}; diff --git a/lib/dependency-manager-adapters/workspace.js b/lib/dependency-manager-adapters/workspace.js index e56d7e9c..d1c5ab2f 100644 --- a/lib/dependency-manager-adapters/workspace.js +++ b/lib/dependency-manager-adapters/workspace.js @@ -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:workspaces'); @@ -8,10 +7,15 @@ 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( @@ -51,9 +55,7 @@ module.exports = CoreObject.extend({ buildManagerOptions: this.buildManagerOptions, }); }); - }, - - packageJSON: 'package.json', + } setup(options) { if (!options) { @@ -61,7 +63,7 @@ module.exports = CoreObject.extend({ } return Promise.all(this._packageAdapters.map((adapter) => adapter.setup(options))); - }, + } async changeToDependencySet(depSet) { // TODO: What should this do for tables? Nesting? Needs different output @@ -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 || []; @@ -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); - }, -}); + } +}; diff --git a/package.json b/package.json index b5e9a3c6..7b3b6817 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/helpers/stub-dependency-manager-adapter.js b/test/helpers/stub-dependency-manager-adapter.js index 0d4bd081..724a3fb2 100644 --- a/test/helpers/stub-dependency-manager-adapter.js +++ b/test/helpers/stub-dependency-manager-adapter.js @@ -1,22 +1,21 @@ 'use strict'; -const CoreObject = require('core-object'); -const RSVP = require('rsvp'); - -module.exports = CoreObject.extend({ +module.exports = class { setup() { - return RSVP.resolve(); - }, + return Promise.resolve(); + } + changeToDependencySet() { - return RSVP.resolve([ + return Promise.resolve([ { name: 'testDep', versionExpected: '2.0.0', versionSeen: '2.1.0', }, ]); - }, + } + cleanup() { - return RSVP.resolve(); - }, -}); + return Promise.resolve(); + } +}; diff --git a/test/utils/scenario-manager-test.js b/test/utils/scenario-manager-test.js index 8e23dac5..cd3bc7a9 100644 --- a/test/utils/scenario-manager-test.js +++ b/test/utils/scenario-manager-test.js @@ -2,7 +2,6 @@ const expect = require('chai').expect; const ScenarioManager = require('../../lib/utils/scenario-manager'); -const CoreObject = require('core-object'); const RSVP = require('rsvp'); describe('scenarioManager', () => { @@ -15,16 +14,16 @@ describe('scenarioManager', () => { let calledFirstAdapter = false; let calledSecondAdapter = false; let fakeAdapters = [ - new CoreObject({ + new (class { setup() { calledFirstAdapter = true; - }, - }), - new CoreObject({ + } + })(), + new (class { setup() { calledSecondAdapter = true; - }, - }), + } + })(), ]; return new ScenarioManager({ dependencyManagerAdapters: fakeAdapters }).setup().then(() => { @@ -37,18 +36,18 @@ describe('scenarioManager', () => { describe('#changeTo', () => { it('changes dependency sets on each of the managers, in order, and concats results', () => { let fakeAdapters = [ - new CoreObject({ - configKey: 'adapterA', + new (class { + configKey = 'adapterA'; changeToDependencySet() { return RSVP.resolve(['a', 'b', 'r']); - }, - }), - new CoreObject({ - configKey: 'adapterB', + } + })(), + new (class { + configKey = 'adapterB'; changeToDependencySet() { return RSVP.resolve(['u', 'q', 'a']); - }, - }), + } + })(), ]; let manager = new ScenarioManager({ dependencyManagerAdapters: fakeAdapters }); @@ -63,16 +62,16 @@ describe('scenarioManager', () => { let calledFirstAdapter = false; let calledSecondAdapter = false; let fakeAdapters = [ - new CoreObject({ + new (class { cleanup() { calledFirstAdapter = true; - }, - }), - new CoreObject({ + } + })(), + new (class { cleanup() { calledSecondAdapter = true; - }, - }), + } + })(), ]; return new ScenarioManager({ dependencyManagerAdapters: fakeAdapters }).cleanup().then(() => {