Skip to content

Commit b4bc68f

Browse files
authored
Merge pull request #1020 from bertdeblock/remove-use-of-core-object-for-adapters
Remove use of `core-object` for adapters
2 parents ced2d08 + 15b5f65 commit b4bc68f

6 files changed

Lines changed: 95 additions & 90 deletions

File tree

lib/dependency-manager-adapters/npm.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
'use strict';
22

3-
const CoreObject = require('core-object');
43
const fs = require('fs-extra');
54
const path = require('path');
65
const debug = require('debug')('ember-try:dependency-manager-adapter:npm');
76
const chalk = require('chalk');
87
const semver = require('semver');
98
const Backup = require('../utils/backup');
109

11-
module.exports = CoreObject.extend({
12-
init() {
13-
this._super.apply(this, arguments);
10+
module.exports = class {
11+
configKey = 'npm';
12+
packageJSON = 'package.json';
13+
packageLock = 'package-lock.json';
14+
useYarnCommand = false;
15+
yarnLock = 'yarn.lock';
16+
17+
constructor(options) {
18+
this.buildManagerOptions = options.buildManagerOptions;
19+
this.cwd = options.cwd;
20+
this.managerOptions = options.managerOptions;
21+
this.run = options.run || require('../utils/run');
22+
this.useYarnCommand = options.useYarnCommand ?? false;
23+
1424
this.backup = new Backup({ cwd: this.cwd });
15-
this.run = this.run || require('../utils/run');
16-
},
17-
useYarnCommand: false,
18-
yarnLock: 'yarn.lock',
19-
configKey: 'npm',
20-
packageJSON: 'package.json',
21-
packageLock: 'package-lock.json',
25+
}
2226

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

3034
return await this._backupOriginalDependencies();
31-
},
35+
}
3236

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

5054
return currentDeps;
51-
},
55+
}
5256

5357
async cleanup() {
5458
try {
5559
await this._restoreOriginalDependencies();
5660
} catch (e) {
5761
console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console
5862
}
59-
},
63+
}
6064

6165
_runYarnCheck(ui) {
6266
if (!this.useYarnCommand) {
@@ -72,7 +76,7 @@ module.exports = CoreObject.extend({
7276
// If no yarn.lock is found, no need to warn.
7377
}
7478
}
75-
},
79+
}
7680

7781
_findCurrentVersionOf(packageName) {
7882
let filename = path.join(this.cwd, 'node_modules', packageName, this.packageJSON);
@@ -81,7 +85,7 @@ module.exports = CoreObject.extend({
8185
} else {
8286
return null;
8387
}
84-
},
88+
}
8589

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

114118
await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
115-
},
119+
}
116120

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

131135
fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
132-
},
136+
}
133137

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

146150
return packageJSON;
147-
},
151+
}
148152

149153
_overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
150154
if (!depSet[kindOfDependency]) {
@@ -177,15 +181,15 @@ module.exports = CoreObject.extend({
177181
}
178182
}
179183
});
180-
},
184+
}
181185

182186
async _restoreOriginalDependencies() {
183187
await this.backup.restoreFiles([this.packageJSON, this.packageLock, this.yarnLock]);
184188
await this.backup.cleanUp();
185189
await this._install();
186-
},
190+
}
187191

188192
async _backupOriginalDependencies() {
189193
await this.backup.addFiles([this.packageJSON, this.packageLock, this.yarnLock]);
190-
},
191-
});
194+
}
195+
};

lib/dependency-manager-adapters/pnpm.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

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

14-
module.exports = CoreObject.extend({
13+
module.exports = class {
1514
// This still needs to be `npm` because we're still reading the dependencies
1615
// from the `npm` key of the ember-try config.
17-
configKey: 'npm',
16+
configKey = 'npm';
17+
18+
constructor(options) {
19+
this.buildManagerOptions = options.buildManagerOptions;
20+
this.cwd = options.cwd;
21+
this.managerOptions = options.managerOptions;
22+
this.run = options.run || require('../utils/run');
1823

19-
init() {
20-
this._super.apply(this, arguments);
2124
this.backup = new Backup({ cwd: this.cwd });
22-
this.run = this.run || require('../utils/run');
23-
},
25+
}
2426

2527
async setup() {
2628
await this._throwOnResolutionMode();
2729
await this.backup.addFiles([PACKAGE_JSON, PNPM_LOCKFILE]);
28-
},
30+
}
2931

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

4648
return currentDeps;
47-
},
49+
}
4850

4951
async cleanup() {
5052
try {
@@ -54,7 +56,7 @@ module.exports = CoreObject.extend({
5456
} catch (e) {
5557
console.log('Error cleaning up scenario:', e); // eslint-disable-line no-console
5658
}
57-
},
59+
}
5860

5961
_findCurrentVersionOf(packageName) {
6062
let filename = path.join(this.cwd, 'node_modules', packageName, PACKAGE_JSON);
@@ -63,7 +65,7 @@ module.exports = CoreObject.extend({
6365
} else {
6466
return null;
6567
}
66-
},
68+
}
6769

6870
/**
6971
* pnpm versions 8.0.0 through 8.6.* have the `resolution-mode` setting inverted to
@@ -82,12 +84,12 @@ module.exports = CoreObject.extend({
8284
'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`.',
8385
);
8486
}
85-
},
87+
}
8688

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

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

98100
return result.stdout.split('\n')[0];
99-
},
101+
}
100102

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

108110
return false;
109-
},
111+
}
110112

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

136138
await this.run('pnpm', [].concat(['install'], mgrOptions), { cwd: this.cwd });
137-
},
139+
}
138140

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

157159
await this.backup.restoreFile(PNPM_LOCKFILE);
158-
},
160+
}
159161

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

169171
return packageJSON;
170-
},
172+
}
171173

172174
_overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
173175
if (!depSet[kindOfDependency]) {
@@ -188,5 +190,5 @@ module.exports = CoreObject.extend({
188190
packageJSON[kindOfDependency][packageName] = version;
189191
}
190192
}
191-
},
192-
});
193+
}
194+
};

lib/dependency-manager-adapters/workspace.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
'use strict';
22

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

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

11-
module.exports = CoreObject.extend({
12-
init() {
13-
this._super.apply(this, arguments);
14-
this.run = this.run || require('../utils/run');
10+
module.exports = class {
11+
packageJSON = 'package.json';
12+
13+
constructor(options) {
14+
this.buildManagerOptions = options.buildManagerOptions;
15+
this.cwd = options.cwd;
16+
this.managerOptions = options.managerOptions;
17+
this.run = options.run || require('../utils/run');
18+
this.useYarnCommand = options.useYarnCommand ?? false;
1519

1620
if (!this.useYarnCommand) {
1721
throw new Error(
@@ -51,17 +55,15 @@ module.exports = CoreObject.extend({
5155
buildManagerOptions: this.buildManagerOptions,
5256
});
5357
});
54-
},
55-
56-
packageJSON: 'package.json',
58+
}
5759

5860
setup(options) {
5961
if (!options) {
6062
options = {};
6163
}
6264

6365
return Promise.all(this._packageAdapters.map((adapter) => adapter.setup(options)));
64-
},
66+
}
6567

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

8587
return currentDeps;
86-
},
88+
}
8789

8890
cleanup() {
8991
return Promise.all(this._packageAdapters.map((adapter) => adapter.cleanup()));
90-
},
92+
}
9193

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

115117
return this.run('yarn', ['install', ...mgrOptions], { cwd: this.cwd });
116-
},
118+
}
117119

118120
_findCurrentVersionOf(dep) {
119121
return this._packageAdapters[0]._findCurrentVersionOf(dep);
120-
},
121-
});
122+
}
123+
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"dependencies": {
3232
"chalk": "^4.1.2",
3333
"cli-table3": "^0.6.0",
34-
"core-object": "^3.1.5",
3534
"debug": "^4.3.2",
3635
"ember-try-config": "^4.0.0",
3736
"execa": "^4.1.0",
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
'use strict';
22

3-
const CoreObject = require('core-object');
4-
const RSVP = require('rsvp');
5-
6-
module.exports = CoreObject.extend({
3+
module.exports = class {
74
setup() {
8-
return RSVP.resolve();
9-
},
5+
return Promise.resolve();
6+
}
7+
108
changeToDependencySet() {
11-
return RSVP.resolve([
9+
return Promise.resolve([
1210
{
1311
name: 'testDep',
1412
versionExpected: '2.0.0',
1513
versionSeen: '2.1.0',
1614
},
1715
]);
18-
},
16+
}
17+
1918
cleanup() {
20-
return RSVP.resolve();
21-
},
22-
});
19+
return Promise.resolve();
20+
}
21+
};

0 commit comments

Comments
 (0)