ember-try 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-plan.json +33 -0
- package/CHANGELOG.md +66 -0
- package/README.md +23 -24
- package/lib/commands/config.js +4 -2
- package/lib/commands/reset.js +3 -3
- package/lib/commands/try-each.js +3 -3
- package/lib/commands/try-ember.js +3 -3
- package/lib/commands/try-one.js +6 -7
- package/lib/dependency-manager-adapters/base.js +175 -0
- package/lib/dependency-manager-adapters/npm.js +9 -293
- package/lib/dependency-manager-adapters/pnpm.js +52 -160
- package/lib/dependency-manager-adapters/workspace.js +23 -28
- package/lib/dependency-manager-adapters/yarn.js +11 -0
- package/lib/tasks/reset.js +13 -8
- package/lib/tasks/try-each.js +37 -31
- package/lib/utils/backup.js +95 -0
- package/lib/utils/config.js +40 -18
- package/lib/utils/console.js +51 -0
- package/lib/utils/dependency-manager-adapter-factory.js +18 -18
- package/lib/utils/package-managers.js +9 -0
- package/lib/utils/result-summary.js +27 -23
- package/lib/utils/run.js +22 -2
- package/lib/utils/scenario-manager.js +11 -10
- package/package.json +34 -47
- package/lib/utils/find-by-name.js +0 -10
|
@@ -1,295 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
module.exports = CoreObject.extend({
|
|
14
|
-
init() {
|
|
15
|
-
this._super.apply(this, arguments);
|
|
16
|
-
this.run = this.run || require('../utils/run');
|
|
17
|
-
},
|
|
18
|
-
useYarnCommand: false,
|
|
19
|
-
yarnLock: 'yarn.lock',
|
|
20
|
-
yarnLockBackupFileName: 'yarn.lock.ember-try',
|
|
21
|
-
configKey: 'npm',
|
|
22
|
-
packageJSON: 'package.json',
|
|
23
|
-
packageJSONBackupFileName: 'package.json.ember-try',
|
|
24
|
-
nodeModules: 'node_modules',
|
|
25
|
-
nodeModulesBackupLocation: '.node_modules.ember-try',
|
|
26
|
-
npmShrinkWrap: 'npm-shrinkwrap.json',
|
|
27
|
-
npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try',
|
|
28
|
-
packageLock: 'package-lock.json',
|
|
29
|
-
packageLockBackupFileName: 'package-lock.json.ember-try',
|
|
30
|
-
|
|
31
|
-
async setup(options) {
|
|
32
|
-
if (!options) {
|
|
33
|
-
options = {};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this._runYarnCheck(options.ui);
|
|
37
|
-
|
|
38
|
-
return await this._backupOriginalDependencies();
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
async changeToDependencySet(depSet) {
|
|
42
|
-
this.applyDependencySet(depSet);
|
|
43
|
-
|
|
44
|
-
await this._install(depSet);
|
|
45
|
-
|
|
46
|
-
let deps = Object.assign({}, depSet.dependencies, depSet.devDependencies);
|
|
47
|
-
let currentDeps = Object.keys(deps).map((dep) => {
|
|
48
|
-
return {
|
|
49
|
-
name: dep,
|
|
50
|
-
versionExpected: deps[dep],
|
|
51
|
-
versionSeen: this._findCurrentVersionOf(dep),
|
|
52
|
-
packageManager: this.useYarnCommand ? 'yarn' : 'npm',
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
debug('Switched to dependencies: \n', currentDeps);
|
|
57
|
-
|
|
58
|
-
return currentDeps;
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
async cleanup() {
|
|
62
|
-
try {
|
|
63
|
-
await this._restoreOriginalDependencies();
|
|
64
|
-
|
|
65
|
-
debug('Remove backup package.json and node_modules');
|
|
66
|
-
|
|
67
|
-
let cleanupTasks = [
|
|
68
|
-
rimraf(path.join(this.cwd, this.packageJSONBackupFileName)),
|
|
69
|
-
rimraf(path.join(this.cwd, this.nodeModulesBackupLocation)),
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) {
|
|
73
|
-
cleanupTasks.push(rimraf(path.join(this.cwd, this.yarnLockBackupFileName)));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) {
|
|
77
|
-
cleanupTasks.push(rimraf(path.join(this.cwd, this.npmShrinkWrapBackupFileName)));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) {
|
|
81
|
-
cleanupTasks.push(rimraf(path.join(this.cwd, this.packageLockBackupFileName)));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return await Promise.all(cleanupTasks);
|
|
85
|
-
} catch (e) {
|
|
86
|
-
console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
_runYarnCheck(ui) {
|
|
91
|
-
if (!this.useYarnCommand) {
|
|
92
|
-
try {
|
|
93
|
-
if (fs.statSync(path.join(this.cwd, this.yarnLock)).isFile()) {
|
|
94
|
-
ui.writeLine(
|
|
95
|
-
chalk.yellow(
|
|
96
|
-
'Detected a yarn.lock file. Add `useYarn: true` to your `config/ember-try.js` configuration file if you want to use Yarn to install npm dependencies.'
|
|
97
|
-
)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
} catch (e) {
|
|
101
|
-
// If no yarn.lock is found, no need to warn.
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
_findCurrentVersionOf(packageName) {
|
|
107
|
-
let filename = path.join(this.cwd, this.nodeModules, packageName, this.packageJSON);
|
|
108
|
-
if (fs.existsSync(filename)) {
|
|
109
|
-
return JSON.parse(fs.readFileSync(filename)).version;
|
|
110
|
-
} else {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
async _install(depSet) {
|
|
116
|
-
let mgrOptions = this.managerOptions || [];
|
|
117
|
-
let cmd = this.useYarnCommand ? 'yarn' : 'npm';
|
|
118
|
-
|
|
119
|
-
// buildManagerOptions overrides all default
|
|
120
|
-
if (typeof this.buildManagerOptions === 'function') {
|
|
121
|
-
mgrOptions = this.buildManagerOptions(depSet);
|
|
122
|
-
|
|
123
|
-
if (!Array.isArray(mgrOptions)) {
|
|
124
|
-
throw new Error('buildManagerOptions must return an array of options');
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
if (this.useYarnCommand) {
|
|
128
|
-
if (mgrOptions.indexOf('--no-lockfile') === -1) {
|
|
129
|
-
mgrOptions = mgrOptions.concat(['--no-lockfile']);
|
|
130
|
-
}
|
|
131
|
-
// npm warns on incompatible engines
|
|
132
|
-
// yarn errors, not a good experience
|
|
133
|
-
if (mgrOptions.indexOf('--ignore-engines') === -1) {
|
|
134
|
-
mgrOptions = mgrOptions.concat(['--ignore-engines']);
|
|
135
|
-
}
|
|
136
|
-
} else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) {
|
|
137
|
-
mgrOptions = mgrOptions.concat(['--no-shrinkwrap']);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
debug('Run npm/yarn install with options %s', mgrOptions);
|
|
142
|
-
|
|
143
|
-
await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
|
|
144
|
-
|
|
145
|
-
if (!this.useYarnCommand) {
|
|
146
|
-
let res = await this.run('npm', ['--version'], { cwd: this.cwd, stdio: 'pipe' });
|
|
147
|
-
let version = res.stdout;
|
|
148
|
-
if (version.match(/^4./)) {
|
|
149
|
-
debug('Running npm prune because version is %s', version);
|
|
150
|
-
return await this.run(this.configKey, ['prune'], { cwd: this.cwd });
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
debug('Not running npm prune because version is %s', version);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
applyDependencySet(depSet) {
|
|
158
|
-
debug('Changing to dependency set: %s', JSON.stringify(depSet));
|
|
159
|
-
|
|
160
|
-
if (!depSet) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let backupPackageJSON = path.join(this.cwd, this.packageJSONBackupFileName);
|
|
165
|
-
let packageJSONFile = path.join(this.cwd, this.packageJSON);
|
|
166
|
-
let packageJSON = JSON.parse(fs.readFileSync(backupPackageJSON));
|
|
167
|
-
let newPackageJSON = this._packageJSONForDependencySet(packageJSON, depSet);
|
|
168
|
-
|
|
169
|
-
debug('Write package.json with: \n', JSON.stringify(newPackageJSON));
|
|
170
|
-
|
|
171
|
-
fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
_packageJSONForDependencySet(packageJSON, depSet) {
|
|
175
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
|
|
176
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'devDependencies');
|
|
177
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
|
|
178
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'ember');
|
|
179
|
-
|
|
180
|
-
if (this.useYarnCommand) {
|
|
181
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'resolutions');
|
|
182
|
-
} else {
|
|
183
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return packageJSON;
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
_overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
|
|
190
|
-
if (!depSet[kindOfDependency]) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
let packageNames = Object.keys(depSet[kindOfDependency]);
|
|
195
|
-
|
|
196
|
-
packageNames.forEach((packageName) => {
|
|
197
|
-
if (!packageJSON[kindOfDependency]) {
|
|
198
|
-
packageJSON[kindOfDependency] = {};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let version = depSet[kindOfDependency][packageName];
|
|
202
|
-
if (version === null) {
|
|
203
|
-
delete packageJSON[kindOfDependency][packageName];
|
|
204
|
-
} else {
|
|
205
|
-
packageJSON[kindOfDependency][packageName] = version;
|
|
206
|
-
|
|
207
|
-
// in npm we need to always add an override if the version is a pre-release
|
|
208
|
-
if (
|
|
209
|
-
!this.useYarnCommand &&
|
|
210
|
-
(semver.prerelease(version) || /^https*:\/\/.*\.tg*z/.test(version))
|
|
211
|
-
) {
|
|
212
|
-
if (!packageJSON.overrides) {
|
|
213
|
-
packageJSON.overrides = {};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
packageJSON.overrides[packageName] = `$${packageName}`;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
_restoreOriginalDependencies() {
|
|
223
|
-
debug('Restoring original package.json and node_modules');
|
|
224
|
-
|
|
225
|
-
let restoreTasks = [
|
|
226
|
-
copy(
|
|
227
|
-
path.join(this.cwd, this.packageJSONBackupFileName),
|
|
228
|
-
path.join(this.cwd, this.packageJSON)
|
|
229
|
-
),
|
|
230
|
-
];
|
|
231
|
-
|
|
232
|
-
let nodeModulesBackupLocation = path.join(this.cwd, this.nodeModulesBackupLocation);
|
|
233
|
-
if (fs.existsSync(nodeModulesBackupLocation)) {
|
|
234
|
-
restoreTasks.push(
|
|
235
|
-
copy(nodeModulesBackupLocation, path.join(this.cwd, this.nodeModules), { clobber: true })
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
let yarnLockBackupFileName = path.join(this.cwd, this.yarnLockBackupFileName);
|
|
240
|
-
if (fs.existsSync(yarnLockBackupFileName)) {
|
|
241
|
-
restoreTasks.push(copy(yarnLockBackupFileName, path.join(this.cwd, this.yarnLock)));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
let npmShrinkWrapBackupFileName = path.join(this.cwd, this.npmShrinkWrapBackupFileName);
|
|
245
|
-
if (fs.existsSync(npmShrinkWrapBackupFileName)) {
|
|
246
|
-
restoreTasks.push(copy(npmShrinkWrapBackupFileName, path.join(this.cwd, this.npmShrinkWrap)));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
let packageLockBackupFileName = path.join(this.cwd, this.packageLockBackupFileName);
|
|
250
|
-
if (fs.existsSync(packageLockBackupFileName)) {
|
|
251
|
-
restoreTasks.push(copy(packageLockBackupFileName, path.join(this.cwd, this.packageLock)));
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return Promise.all(restoreTasks);
|
|
255
|
-
},
|
|
256
|
-
|
|
257
|
-
_backupOriginalDependencies() {
|
|
258
|
-
debug('Backing up package.json and node_modules');
|
|
259
|
-
|
|
260
|
-
let backupTasks = [
|
|
261
|
-
copy(
|
|
262
|
-
path.join(this.cwd, this.packageJSON),
|
|
263
|
-
path.join(this.cwd, this.packageJSONBackupFileName)
|
|
264
|
-
),
|
|
265
|
-
];
|
|
266
|
-
|
|
267
|
-
let nodeModulesPath = path.join(this.cwd, this.nodeModules);
|
|
268
|
-
if (fs.existsSync(nodeModulesPath)) {
|
|
269
|
-
backupTasks.push(
|
|
270
|
-
copy(nodeModulesPath, path.join(this.cwd, this.nodeModulesBackupLocation), {
|
|
271
|
-
clobber: true,
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let yarnLockPath = path.join(this.cwd, this.yarnLock);
|
|
277
|
-
if (fs.existsSync(yarnLockPath)) {
|
|
278
|
-
backupTasks.push(copy(yarnLockPath, path.join(this.cwd, this.yarnLockBackupFileName)));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
let npmShrinkWrapPath = path.join(this.cwd, this.npmShrinkWrap);
|
|
282
|
-
if (fs.existsSync(npmShrinkWrapPath)) {
|
|
283
|
-
backupTasks.push(
|
|
284
|
-
copy(npmShrinkWrapPath, path.join(this.cwd, this.npmShrinkWrapBackupFileName))
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
let packageLockPath = path.join(this.cwd, this.packageLock);
|
|
289
|
-
if (fs.existsSync(packageLockPath)) {
|
|
290
|
-
backupTasks.push(copy(packageLockPath, path.join(this.cwd, this.packageLockBackupFileName)));
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return Promise.all(backupTasks);
|
|
294
|
-
},
|
|
295
|
-
});
|
|
3
|
+
const { LOCKFILE } = require('../utils/package-managers');
|
|
4
|
+
const { BaseAdapter } = require('./base');
|
|
5
|
+
|
|
6
|
+
module.exports = class NpmAdapter extends BaseAdapter {
|
|
7
|
+
defaultInstallOptions = ['--no-package-lock'];
|
|
8
|
+
lockfile = LOCKFILE.npm;
|
|
9
|
+
name = 'npm';
|
|
10
|
+
overridesKey = 'overrides';
|
|
11
|
+
};
|
|
@@ -1,172 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const debug = require('debug')('ember-try:dependency-manager-adapter:pnpm');
|
|
3
|
+
const semver = require('semver');
|
|
4
|
+
const { LOCKFILE } = require('../utils/package-managers');
|
|
5
|
+
const { BaseAdapter } = require('./base');
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// extension, however this breaks syntax highlighting, so I've chosen to
|
|
14
|
-
// insert it right before the file extension.
|
|
15
|
-
const PNPM_LOCKFILE_BACKUP = 'pnpm-lock.ember-try.yaml';
|
|
16
|
-
|
|
17
|
-
module.exports = CoreObject.extend({
|
|
18
|
-
// This still needs to be `npm` because we're still reading the dependencies
|
|
19
|
-
// from the `npm` key of the ember-try config.
|
|
20
|
-
configKey: 'npm',
|
|
21
|
-
|
|
22
|
-
init() {
|
|
23
|
-
this._super.apply(this, arguments);
|
|
24
|
-
this.run = this.run || require('../utils/run');
|
|
25
|
-
},
|
|
7
|
+
module.exports = class PnpmAdapter extends BaseAdapter {
|
|
8
|
+
defaultInstallOptions = ['--no-lockfile', '--ignore-scripts'];
|
|
9
|
+
lockfile = LOCKFILE.pnpm;
|
|
10
|
+
name = 'pnpm';
|
|
11
|
+
overridesKey = 'pnpm.overrides';
|
|
26
12
|
|
|
27
13
|
async setup() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
await this._throwOnResolutionMode();
|
|
15
|
+
await super.setup();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* pnpm versions 8.0.0 through 8.6.* have the `resolution-mode` setting inverted to
|
|
20
|
+
* `lowest-direct`, which breaks ember-try. This method throws a helpful error in the following
|
|
21
|
+
* case: pnpm version is within dangerous range and `pnpm config get resolution-mode` reports an
|
|
22
|
+
* empty value.
|
|
23
|
+
*
|
|
24
|
+
* @returns Promise<void>
|
|
25
|
+
*/
|
|
26
|
+
async _throwOnResolutionMode() {
|
|
27
|
+
let version = await this._getPnpmVersion();
|
|
28
|
+
let resolutionMode = await this._getResolutionMode();
|
|
29
|
+
|
|
30
|
+
if (this._isResolutionModeWrong(version, resolutionMode)) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
'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`.',
|
|
33
|
+
);
|
|
38
34
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async changeToDependencySet(depSet) {
|
|
42
|
-
await this.applyDependencySet(depSet);
|
|
35
|
+
}
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
async _getPnpmVersion() {
|
|
38
|
+
let result = await this.run('pnpm', ['--version'], { cwd: this.cwd, stdio: 'pipe' });
|
|
39
|
+
return result.stdout.split('\n')[0];
|
|
40
|
+
}
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
versionExpected: deps[dep],
|
|
51
|
-
versionSeen: this._findCurrentVersionOf(dep),
|
|
52
|
-
packageManager: 'pnpm',
|
|
53
|
-
};
|
|
42
|
+
async _getResolutionMode() {
|
|
43
|
+
let result = await this.run('pnpm', ['config', 'get', 'resolution-mode'], {
|
|
44
|
+
cwd: this.cwd,
|
|
45
|
+
stdio: 'pipe',
|
|
54
46
|
});
|
|
55
47
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
debug(`Restoring original ${PNPM_LOCKFILE}`);
|
|
70
|
-
let lockFile = path.join(this.cwd, PNPM_LOCKFILE);
|
|
71
|
-
let lockFileBackup = path.join(this.cwd, PNPM_LOCKFILE_BACKUP);
|
|
72
|
-
await fs.copy(lockFileBackup, lockFile);
|
|
73
|
-
await fs.remove(lockFileBackup);
|
|
74
|
-
|
|
75
|
-
await this._install();
|
|
76
|
-
} catch (e) {
|
|
77
|
-
console.log('Error cleaning up scenario:', e); // eslint-disable-line no-console
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
_findCurrentVersionOf(packageName) {
|
|
82
|
-
let filename = path.join(this.cwd, 'node_modules', packageName, PACKAGE_JSON);
|
|
83
|
-
if (fs.existsSync(filename)) {
|
|
84
|
-
return JSON.parse(fs.readFileSync(filename)).version;
|
|
85
|
-
} else {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
async _install(depSet) {
|
|
91
|
-
let mgrOptions = this.managerOptions || [];
|
|
92
|
-
|
|
93
|
-
// buildManagerOptions overrides all default
|
|
94
|
-
if (typeof this.buildManagerOptions === 'function') {
|
|
95
|
-
mgrOptions = this.buildManagerOptions(depSet);
|
|
96
|
-
|
|
97
|
-
if (!Array.isArray(mgrOptions)) {
|
|
98
|
-
throw new Error('buildManagerOptions must return an array of options');
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
if (!mgrOptions.includes('--no-lockfile')) {
|
|
102
|
-
mgrOptions.push('--no-lockfile');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Note: We are explicitly *not* using `--no-lockfile` here, so that we
|
|
107
|
-
// only have to resolve the dependencies that have actually changed.
|
|
108
|
-
|
|
109
|
-
debug('Run pnpm install with options %s', mgrOptions);
|
|
110
|
-
|
|
111
|
-
await this.run('pnpm', [].concat(['install'], mgrOptions), { cwd: this.cwd });
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
async applyDependencySet(depSet) {
|
|
115
|
-
debug('Changing to dependency set: %s', JSON.stringify(depSet));
|
|
116
|
-
|
|
117
|
-
if (!depSet) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
let backupPackageJSON = path.join(this.cwd, PACKAGE_JSON_BACKUP);
|
|
122
|
-
let packageJSONFile = path.join(this.cwd, PACKAGE_JSON);
|
|
123
|
-
let packageJSON = JSON.parse(fs.readFileSync(backupPackageJSON));
|
|
124
|
-
let newPackageJSON = this._packageJSONForDependencySet(packageJSON, depSet);
|
|
125
|
-
|
|
126
|
-
debug('Write package.json with: \n', JSON.stringify(newPackageJSON));
|
|
127
|
-
fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
|
|
128
|
-
|
|
129
|
-
// We restore the original lockfile here, so that we always create a minimal
|
|
130
|
-
// diff compared to the original locked dependency set.
|
|
131
|
-
|
|
132
|
-
let lockFile = path.join(this.cwd, PNPM_LOCKFILE);
|
|
133
|
-
let lockFileBackup = path.join(this.cwd, PNPM_LOCKFILE_BACKUP);
|
|
134
|
-
if (fs.existsSync(lockFileBackup)) {
|
|
135
|
-
debug(`Restoring original ${PNPM_LOCKFILE}`);
|
|
136
|
-
await fs.copy(lockFileBackup, lockFile);
|
|
48
|
+
return result.stdout.split('\n')[0];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_isResolutionModeWrong(versionStr, resolutionMode) {
|
|
52
|
+
// The `resolution-mode` is not set explicitly, and the current pnpm version makes it default
|
|
53
|
+
// to `lowest-direct`
|
|
54
|
+
if (
|
|
55
|
+
!resolutionMode.length &&
|
|
56
|
+
semver.gte(versionStr, '8.0.0') &&
|
|
57
|
+
semver.lt(versionStr, '8.7.0')
|
|
58
|
+
) {
|
|
59
|
+
return true;
|
|
137
60
|
}
|
|
138
|
-
},
|
|
139
61
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
|
|
144
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'ember');
|
|
145
|
-
|
|
146
|
-
// see https://pnpm.io/package_json#pnpmoverrides
|
|
147
|
-
this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides');
|
|
148
|
-
|
|
149
|
-
return packageJSON;
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
_overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
|
|
153
|
-
if (!depSet[kindOfDependency]) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
let packageNames = Object.keys(depSet[kindOfDependency]);
|
|
158
|
-
|
|
159
|
-
for (let packageName of packageNames) {
|
|
160
|
-
if (!packageJSON[kindOfDependency]) {
|
|
161
|
-
packageJSON[kindOfDependency] = {};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let version = depSet[kindOfDependency][packageName];
|
|
165
|
-
if (version === null) {
|
|
166
|
-
delete packageJSON[kindOfDependency][packageName];
|
|
167
|
-
} else {
|
|
168
|
-
packageJSON[kindOfDependency][packageName] = version;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
});
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const CoreObject = require('core-object');
|
|
4
3
|
const fs = require('fs-extra');
|
|
5
4
|
const path = require('path');
|
|
6
5
|
const debug = require('debug')('ember-try:dependency-manager-adapter:workspaces');
|
|
7
6
|
const walkSync = require('walk-sync');
|
|
7
|
+
const { PACKAGE_JSON } = require('../utils/package-managers');
|
|
8
|
+
const YarnAdapter = require('./yarn');
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
module.exports = class {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.buildManagerOptions = options.buildManagerOptions;
|
|
13
|
+
this.cwd = options.cwd;
|
|
14
|
+
this.managerOptions = options.managerOptions;
|
|
15
|
+
this.run = options.run || require('../utils/run');
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
init() {
|
|
13
|
-
this._super.apply(this, arguments);
|
|
14
|
-
this.run = this.run || require('../utils/run');
|
|
15
|
-
|
|
16
|
-
if (!this.useYarnCommand) {
|
|
17
|
+
if (options.packageManager !== 'yarn') {
|
|
17
18
|
throw new Error(
|
|
18
|
-
'workspaces are currently only supported by Yarn, you must set `
|
|
19
|
+
'workspaces are currently only supported by Yarn, you must set `packageManager` to `yarn`',
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
let packageJSON = JSON.parse(fs.readFileSync(PACKAGE_JSON));
|
|
22
24
|
let workspaceGlobs;
|
|
23
25
|
|
|
24
26
|
if (Array.isArray(packageJSON.workspaces)) {
|
|
@@ -31,7 +33,7 @@ module.exports = CoreObject.extend({
|
|
|
31
33
|
|
|
32
34
|
if (!workspaceGlobs || !workspaceGlobs.length) {
|
|
33
35
|
throw new Error(
|
|
34
|
-
'you must define the `workspaces` property in package.json with at least one workspace to use workspaces with ember-try'
|
|
36
|
+
'you must define the `workspaces` property in package.json with at least one workspace to use workspaces with ember-try',
|
|
35
37
|
);
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -43,25 +45,18 @@ module.exports = CoreObject.extend({
|
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
this._packageAdapters = workspacePaths.map((workspacePath) => {
|
|
46
|
-
return new
|
|
48
|
+
return new YarnAdapter({
|
|
47
49
|
cwd: workspacePath,
|
|
48
50
|
run: this.run,
|
|
49
51
|
managerOptions: this.managerOptions,
|
|
50
|
-
useYarnCommand: true,
|
|
51
52
|
buildManagerOptions: this.buildManagerOptions,
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
packageJSON: 'package.json',
|
|
57
|
-
|
|
58
|
-
setup(options) {
|
|
59
|
-
if (!options) {
|
|
60
|
-
options = {};
|
|
61
|
-
}
|
|
55
|
+
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
setup() {
|
|
58
|
+
return Promise.all(this._packageAdapters.map((adapter) => adapter.setup()));
|
|
59
|
+
}
|
|
65
60
|
|
|
66
61
|
async changeToDependencySet(depSet) {
|
|
67
62
|
// TODO: What should this do for tables? Nesting? Needs different output
|
|
@@ -83,11 +78,11 @@ module.exports = CoreObject.extend({
|
|
|
83
78
|
debug('Switched to dependencies: \n', currentDeps);
|
|
84
79
|
|
|
85
80
|
return currentDeps;
|
|
86
|
-
}
|
|
81
|
+
}
|
|
87
82
|
|
|
88
83
|
cleanup() {
|
|
89
84
|
return Promise.all(this._packageAdapters.map((adapter) => adapter.cleanup()));
|
|
90
|
-
}
|
|
85
|
+
}
|
|
91
86
|
|
|
92
87
|
_install(depSet) {
|
|
93
88
|
let mgrOptions = this.managerOptions || [];
|
|
@@ -113,9 +108,9 @@ module.exports = CoreObject.extend({
|
|
|
113
108
|
debug('Run yarn install with options %s', mgrOptions);
|
|
114
109
|
|
|
115
110
|
return this.run('yarn', ['install', ...mgrOptions], { cwd: this.cwd });
|
|
116
|
-
}
|
|
111
|
+
}
|
|
117
112
|
|
|
118
113
|
_findCurrentVersionOf(dep) {
|
|
119
114
|
return this._packageAdapters[0]._findCurrentVersionOf(dep);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { LOCKFILE } = require('../utils/package-managers');
|
|
4
|
+
const { BaseAdapter } = require('./base');
|
|
5
|
+
|
|
6
|
+
module.exports = class YarnAdapter extends BaseAdapter {
|
|
7
|
+
defaultInstallOptions = ['--no-lockfile', '--ignore-engines'];
|
|
8
|
+
lockfile = LOCKFILE.yarn;
|
|
9
|
+
name = 'yarn';
|
|
10
|
+
overridesKey = 'resolutions';
|
|
11
|
+
};
|
package/lib/tasks/reset.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const CoreObject = require('core-object');
|
|
4
3
|
const debug = require('debug')('ember-try:commands:reset');
|
|
5
4
|
const ScenarioManager = require('../utils/scenario-manager');
|
|
6
5
|
const DependencyManagerAdapterFactory = require('./../utils/dependency-manager-adapter-factory');
|
|
7
6
|
|
|
8
|
-
module.exports =
|
|
7
|
+
module.exports = class ResetTask {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.config = options.config;
|
|
10
|
+
this.cwd = options.cwd;
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
run() {
|
|
10
|
-
let dependencyAdapters =
|
|
11
|
-
this.
|
|
12
|
-
|
|
14
|
+
let dependencyAdapters = DependencyManagerAdapterFactory.generateFromConfig(
|
|
15
|
+
this.config,
|
|
16
|
+
this.cwd,
|
|
17
|
+
);
|
|
13
18
|
debug(
|
|
14
19
|
'DependencyManagerAdapters: %s',
|
|
15
20
|
dependencyAdapters.map((item) => {
|
|
16
21
|
return item.configKey;
|
|
17
|
-
})
|
|
22
|
+
}),
|
|
18
23
|
);
|
|
19
24
|
return new ScenarioManager({ dependencyManagerAdapters: dependencyAdapters }).cleanup();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
25
|
+
}
|
|
26
|
+
};
|