ember-try 1.2.0 → 2.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.
@@ -2,11 +2,11 @@
2
2
 
3
3
  const CoreObject = require('core-object');
4
4
  const fs = require('fs-extra');
5
- const RSVP = require('rsvp');
5
+ const util = require('util');
6
+ const copy = util.promisify(fs.copy);
6
7
  const path = require('path');
7
- const extend = require('extend');
8
8
  const debug = require('debug')('ember-try:dependency-manager-adapter:npm');
9
- const rimraf = RSVP.denodeify(require('rimraf'));
9
+ const rimraf = util.promisify(require('rimraf'));
10
10
  const chalk = require('chalk');
11
11
 
12
12
  module.exports = CoreObject.extend({
@@ -16,64 +16,92 @@ module.exports = CoreObject.extend({
16
16
  },
17
17
  useYarnCommand: false,
18
18
  yarnLock: 'yarn.lock',
19
+ yarnLockBackupFileName: 'yarn.lock.ember-try',
19
20
  configKey: 'npm',
20
21
  packageJSON: 'package.json',
21
22
  packageJSONBackupFileName: 'package.json.ember-try',
22
23
  nodeModules: 'node_modules',
23
24
  nodeModulesBackupLocation: '.node_modules.ember-try',
24
- setup(options) {
25
+ npmShrinkWrap: 'npm-shrinkwrap.json',
26
+ npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try',
27
+ packageLock: 'package-lock.json',
28
+ packageLockBackupFileName: 'package-lock.json.ember-try',
29
+
30
+ async setup(options) {
25
31
  if (!options) {
26
32
  options = {};
27
33
  }
34
+
28
35
  this._runYarnCheck(options.ui);
29
- return this._backupOriginalDependencies();
30
- },
31
- changeToDependencySet(depSet) {
32
- let adapter = this;
33
36
 
34
- adapter.applyDependencySet(depSet);
37
+ return await this._backupOriginalDependencies();
38
+ },
35
39
 
36
- return adapter._install().then(() => {
37
- let deps = extend({}, depSet.dependencies || {}, depSet.devDependencies || {});
38
- let currentDeps = Object.keys(deps).map((dep) => {
39
- return {
40
- name: dep,
41
- versionExpected: deps[dep],
42
- versionSeen: adapter._findCurrentVersionOf(dep),
43
- packageManager: adapter.useYarnCommand ? 'yarn' : 'npm',
44
- };
45
- });
40
+ async changeToDependencySet(depSet) {
41
+ this.applyDependencySet(depSet);
46
42
 
47
- debug('Switched to dependencies: \n', currentDeps);
43
+ await this._install(depSet);
48
44
 
49
- return RSVP.Promise.resolve(currentDeps);
45
+ let deps = Object.assign({}, depSet.dependencies, depSet.devDependencies);
46
+ let currentDeps = Object.keys(deps).map((dep) => {
47
+ return {
48
+ name: dep,
49
+ versionExpected: deps[dep],
50
+ versionSeen: this._findCurrentVersionOf(dep),
51
+ packageManager: this.useYarnCommand ? 'yarn' : 'npm',
52
+ };
50
53
  });
54
+
55
+ debug('Switched to dependencies: \n', currentDeps);
56
+
57
+ return currentDeps;
51
58
  },
52
- cleanup() {
53
- let adapter = this;
54
59
 
55
- return this._restoreOriginalDependencies().then(() => {
60
+ async cleanup() {
61
+ try {
62
+ await this._restoreOriginalDependencies();
63
+
56
64
  debug('Remove backup package.json and node_modules');
57
65
 
58
- let cleanupTasks = [rimraf(path.join(adapter.cwd, adapter.packageJSONBackupFileName)),
59
- rimraf(path.join(adapter.cwd, adapter.nodeModulesBackupLocation))];
66
+ let cleanupTasks = [
67
+ rimraf(path.join(this.cwd, this.packageJSONBackupFileName)),
68
+ rimraf(path.join(this.cwd, this.nodeModulesBackupLocation)),
69
+ ];
60
70
 
61
- return RSVP.all(cleanupTasks);
62
- }).catch((e) => {
71
+ if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) {
72
+ cleanupTasks.push(rimraf(path.join(this.cwd, this.yarnLockBackupFileName)));
73
+ }
74
+
75
+ if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) {
76
+ cleanupTasks.push(rimraf(path.join(this.cwd, this.npmShrinkWrapBackupFileName)));
77
+ }
78
+
79
+ if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) {
80
+ cleanupTasks.push(rimraf(path.join(this.cwd, this.packageLockBackupFileName)));
81
+ }
82
+
83
+ return await Promise.all(cleanupTasks);
84
+ } catch (e) {
63
85
  console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console
64
- });
86
+ }
65
87
  },
88
+
66
89
  _runYarnCheck(ui) {
67
90
  if (!this.useYarnCommand) {
68
91
  try {
69
92
  if (fs.statSync(path.join(this.cwd, this.yarnLock)).isFile()) {
70
- ui.writeLine(chalk.yellow('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.'));
93
+ ui.writeLine(
94
+ chalk.yellow(
95
+ '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.'
96
+ )
97
+ );
71
98
  }
72
99
  } catch (e) {
73
100
  // If no yarn.lock is found, no need to warn.
74
101
  }
75
102
  }
76
103
  },
104
+
77
105
  _findCurrentVersionOf(packageName) {
78
106
  let filename = path.join(this.cwd, this.nodeModules, packageName, this.packageJSON);
79
107
  if (fs.existsSync(filename)) {
@@ -82,37 +110,56 @@ module.exports = CoreObject.extend({
82
110
  return null;
83
111
  }
84
112
  },
85
- _install() {
86
- let adapter = this;
113
+
114
+ async _install(depSet) {
87
115
  let mgrOptions = this.managerOptions || [];
116
+ let cmd = this.useYarnCommand ? 'yarn' : 'npm';
88
117
 
89
- debug('Run npm install with options %s', mgrOptions);
118
+ // buildManagerOptions overrides all default
119
+ if (typeof this.buildManagerOptions === 'function') {
120
+ mgrOptions = this.buildManagerOptions(depSet);
90
121
 
91
- let cmd = this.useYarnCommand ? 'yarn' : 'npm';
92
- if (this.useYarnCommand) {
93
- if (mgrOptions.indexOf('--no-lockfile') === -1) {
94
- mgrOptions = mgrOptions.concat(['--no-lockfile']);
122
+ if (!Array.isArray(mgrOptions)) {
123
+ throw new Error('buildManagerOptions must return an array of options');
95
124
  }
96
- // npm warns on incompatible engines
97
- // yarn errors, not a good experience
98
- if (mgrOptions.indexOf('--ignore-engines') === -1) {
99
- mgrOptions = mgrOptions.concat(['--ignore-engines']);
125
+ } else {
126
+ if (this.useYarnCommand) {
127
+ if (mgrOptions.indexOf('--no-lockfile') === -1) {
128
+ mgrOptions = mgrOptions.concat(['--no-lockfile']);
129
+ }
130
+ // npm warns on incompatible engines
131
+ // yarn errors, not a good experience
132
+ if (mgrOptions.indexOf('--ignore-engines') === -1) {
133
+ mgrOptions = mgrOptions.concat(['--ignore-engines']);
134
+ }
135
+ } else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) {
136
+ mgrOptions = mgrOptions.concat(['--no-shrinkwrap']);
100
137
  }
101
- } else if (mgrOptions.indexOf('--no-shrinkwrap') === -1) {
102
- mgrOptions = mgrOptions.concat(['--no-shrinkwrap']);
103
138
  }
104
139
 
105
- return this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd }).then(() => {
106
- if (!adapter.useYarnCommand) {
107
- return adapter.run(adapter.configKey, ['prune'], { cwd: adapter.cwd });
140
+ debug('Run npm/yarn install with options %s', mgrOptions);
141
+
142
+ await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
143
+
144
+ if (!this.useYarnCommand) {
145
+ let res = await this.run('npm', ['--version'], { cwd: this.cwd, stdio: 'pipe' });
146
+ let version = res.stdout;
147
+ if (version.match(/^4./)) {
148
+ debug('Running npm prune because version is %s', version);
149
+ return await this.run(this.configKey, ['prune'], { cwd: this.cwd });
108
150
  }
109
- });
151
+
152
+ debug('Not running npm prune because version is %s', version);
153
+ }
110
154
  },
111
- applyDependencySet(depSet) {
112
155
 
156
+ applyDependencySet(depSet) {
113
157
  debug('Changing to dependency set: %s', JSON.stringify(depSet));
114
158
 
115
- if (!depSet) { return RSVP.resolve([]); }
159
+ if (!depSet) {
160
+ return;
161
+ }
162
+
116
163
  let backupPackageJSON = path.join(this.cwd, this.packageJSONBackupFileName);
117
164
  let packageJSONFile = path.join(this.cwd, this.packageJSON);
118
165
  let packageJSON = JSON.parse(fs.readFileSync(backupPackageJSON));
@@ -122,11 +169,12 @@ module.exports = CoreObject.extend({
122
169
 
123
170
  fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
124
171
  },
125
- _packageJSONForDependencySet(packageJSON, depSet) {
126
172
 
173
+ _packageJSONForDependencySet(packageJSON, depSet) {
127
174
  this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
128
175
  this._overridePackageJSONDependencies(packageJSON, depSet, 'devDependencies');
129
176
  this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
177
+ this._overridePackageJSONDependencies(packageJSON, depSet, 'ember');
130
178
 
131
179
  if (this.useYarnCommand) {
132
180
  this._overridePackageJSONDependencies(packageJSON, depSet, 'resolutions');
@@ -134,48 +182,99 @@ module.exports = CoreObject.extend({
134
182
 
135
183
  return packageJSON;
136
184
  },
185
+
137
186
  _overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
138
- if (!depSet[kindOfDependency]) { return; }
139
- let pkgs = Object.keys(depSet[kindOfDependency]);
187
+ if (!depSet[kindOfDependency]) {
188
+ return;
189
+ }
140
190
 
141
- pkgs.forEach((pkg) => {
191
+ let packageNames = Object.keys(depSet[kindOfDependency]);
192
+
193
+ packageNames.forEach((packageName) => {
142
194
  if (!packageJSON[kindOfDependency]) {
143
195
  packageJSON[kindOfDependency] = {};
144
196
  }
145
197
 
146
- let version = depSet[kindOfDependency][pkg];
198
+ let version = depSet[kindOfDependency][packageName];
147
199
  if (version === null) {
148
- delete packageJSON[kindOfDependency][pkg];
200
+ delete packageJSON[kindOfDependency][packageName];
149
201
  } else {
150
- packageJSON[kindOfDependency][pkg] = version;
202
+ packageJSON[kindOfDependency][packageName] = version;
151
203
  }
152
204
  });
153
205
  },
154
- _restoreOriginalDependencies() {
155
- let copy = RSVP.denodeify(fs.copy);
156
206
 
207
+ _restoreOriginalDependencies() {
157
208
  debug('Restoring original package.json and node_modules');
158
209
 
159
210
  let restoreTasks = [
160
- copy(path.join(this.cwd, this.packageJSONBackupFileName),
161
- path.join(this.cwd, this.packageJSON)),
162
- copy(path.join(this.cwd, this.nodeModulesBackupLocation),
163
- path.join(this.cwd, this.nodeModules), { clobber: true }),
211
+ copy(
212
+ path.join(this.cwd, this.packageJSONBackupFileName),
213
+ path.join(this.cwd, this.packageJSON)
214
+ ),
164
215
  ];
165
216
 
166
- return RSVP.all(restoreTasks);
217
+ let nodeModulesBackupLocation = path.join(this.cwd, this.nodeModulesBackupLocation);
218
+ if (fs.existsSync(nodeModulesBackupLocation)) {
219
+ restoreTasks.push(
220
+ copy(nodeModulesBackupLocation, path.join(this.cwd, this.nodeModules), { clobber: true })
221
+ );
222
+ }
223
+
224
+ let yarnLockBackupFileName = path.join(this.cwd, this.yarnLockBackupFileName);
225
+ if (fs.existsSync(yarnLockBackupFileName)) {
226
+ restoreTasks.push(copy(yarnLockBackupFileName, path.join(this.cwd, this.yarnLock)));
227
+ }
228
+
229
+ let npmShrinkWrapBackupFileName = path.join(this.cwd, this.npmShrinkWrapBackupFileName);
230
+ if (fs.existsSync(npmShrinkWrapBackupFileName)) {
231
+ restoreTasks.push(copy(npmShrinkWrapBackupFileName, path.join(this.cwd, this.npmShrinkWrap)));
232
+ }
233
+
234
+ let packageLockBackupFileName = path.join(this.cwd, this.packageLockBackupFileName);
235
+ if (fs.existsSync(packageLockBackupFileName)) {
236
+ restoreTasks.push(copy(packageLockBackupFileName, path.join(this.cwd, this.packageLock)));
237
+ }
238
+
239
+ return Promise.all(restoreTasks);
167
240
  },
168
- _backupOriginalDependencies() {
169
- let copy = RSVP.denodeify(fs.copy);
170
241
 
242
+ _backupOriginalDependencies() {
171
243
  debug('Backing up package.json and node_modules');
172
244
 
173
245
  let backupTasks = [
174
- copy(path.join(this.cwd, this.packageJSON),
175
- path.join(this.cwd, this.packageJSONBackupFileName)),
176
- copy(path.join(this.cwd, this.nodeModules),
177
- path.join(this.cwd, this.nodeModulesBackupLocation), { clobber: true })];
246
+ copy(
247
+ path.join(this.cwd, this.packageJSON),
248
+ path.join(this.cwd, this.packageJSONBackupFileName)
249
+ ),
250
+ ];
251
+
252
+ let nodeModulesPath = path.join(this.cwd, this.nodeModules);
253
+ if (fs.existsSync(nodeModulesPath)) {
254
+ backupTasks.push(
255
+ copy(nodeModulesPath, path.join(this.cwd, this.nodeModulesBackupLocation), {
256
+ clobber: true,
257
+ })
258
+ );
259
+ }
260
+
261
+ let yarnLockPath = path.join(this.cwd, this.yarnLock);
262
+ if (fs.existsSync(yarnLockPath)) {
263
+ backupTasks.push(copy(yarnLockPath, path.join(this.cwd, this.yarnLockBackupFileName)));
264
+ }
265
+
266
+ let npmShrinkWrapPath = path.join(this.cwd, this.npmShrinkWrap);
267
+ if (fs.existsSync(npmShrinkWrapPath)) {
268
+ backupTasks.push(
269
+ copy(npmShrinkWrapPath, path.join(this.cwd, this.npmShrinkWrapBackupFileName))
270
+ );
271
+ }
272
+
273
+ let packageLockPath = path.join(this.cwd, this.packageLock);
274
+ if (fs.existsSync(packageLockPath)) {
275
+ backupTasks.push(copy(packageLockPath, path.join(this.cwd, this.packageLockBackupFileName)));
276
+ }
178
277
 
179
- return RSVP.all(backupTasks);
278
+ return Promise.all(backupTasks);
180
279
  },
181
280
  });
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ const CoreObject = require('core-object');
4
+ const fs = require('fs-extra');
5
+ const path = require('path');
6
+ const debug = require('debug')('ember-try:dependency-manager-adapter:pnpm');
7
+
8
+ const PACKAGE_JSON = 'package.json';
9
+ const PACKAGE_JSON_BACKUP = 'package.json.ember-try';
10
+ const PNPM_LOCKFILE = 'pnpm-lock.yaml';
11
+
12
+ // Note: the upstream convention is to append `.ember-try` _after_ the file
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
+ },
26
+
27
+ async setup() {
28
+ let pkg = path.join(this.cwd, PACKAGE_JSON);
29
+ let pkgBackup = path.join(this.cwd, PACKAGE_JSON_BACKUP);
30
+ debug(`Copying ${PACKAGE_JSON}`);
31
+ await fs.copy(pkg, pkgBackup);
32
+
33
+ let lockFile = path.join(this.cwd, PNPM_LOCKFILE);
34
+ let lockFileBackup = path.join(this.cwd, PNPM_LOCKFILE_BACKUP);
35
+ if (fs.existsSync(lockFile)) {
36
+ debug(`Copying ${PNPM_LOCKFILE}`);
37
+ await fs.copy(lockFile, lockFileBackup);
38
+ }
39
+ },
40
+
41
+ async changeToDependencySet(depSet) {
42
+ await 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: 'pnpm',
53
+ };
54
+ });
55
+
56
+ debug('Switched to dependencies: \n', currentDeps);
57
+
58
+ return currentDeps;
59
+ },
60
+
61
+ async cleanup() {
62
+ try {
63
+ debug(`Restoring original ${PACKAGE_JSON}`);
64
+ let pkg = path.join(this.cwd, PACKAGE_JSON);
65
+ let pkgBackup = path.join(this.cwd, PACKAGE_JSON_BACKUP);
66
+ await fs.copy(pkgBackup, pkg);
67
+ await fs.remove(pkgBackup);
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 if (!mgrOptions.includes('--frozen-lockfile=false')) {
101
+ mgrOptions.push('--frozen-lockfile=false');
102
+ }
103
+
104
+ // Note: We are explicitly *not* using `--no-lockfile` here, so that we
105
+ // only have to resolve the dependencies that have actually changed.
106
+
107
+ debug('Run pnpm install with options %s', mgrOptions);
108
+
109
+ await this.run('pnpm', [].concat(['install'], mgrOptions), { cwd: this.cwd });
110
+ },
111
+
112
+ async applyDependencySet(depSet) {
113
+ debug('Changing to dependency set: %s', JSON.stringify(depSet));
114
+
115
+ if (!depSet) {
116
+ return;
117
+ }
118
+
119
+ let backupPackageJSON = path.join(this.cwd, PACKAGE_JSON_BACKUP);
120
+ let packageJSONFile = path.join(this.cwd, PACKAGE_JSON);
121
+ let packageJSON = JSON.parse(fs.readFileSync(backupPackageJSON));
122
+ let newPackageJSON = this._packageJSONForDependencySet(packageJSON, depSet);
123
+
124
+ debug('Write package.json with: \n', JSON.stringify(newPackageJSON));
125
+ fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
126
+
127
+ // We restore the original lockfile here, so that we always create a minimal
128
+ // diff compared to the original locked dependency set.
129
+
130
+ let lockFile = path.join(this.cwd, PNPM_LOCKFILE);
131
+ let lockFileBackup = path.join(this.cwd, PNPM_LOCKFILE_BACKUP);
132
+ if (fs.existsSync(lockFileBackup)) {
133
+ debug(`Restoring original ${PNPM_LOCKFILE}`);
134
+ await fs.copy(lockFileBackup, lockFile);
135
+ }
136
+ },
137
+
138
+ _packageJSONForDependencySet(packageJSON, depSet) {
139
+ this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
140
+ this._overridePackageJSONDependencies(packageJSON, depSet, 'devDependencies');
141
+ this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
142
+ this._overridePackageJSONDependencies(packageJSON, depSet, 'ember');
143
+
144
+ // see https://pnpm.io/package_json#pnpmoverrides
145
+ this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides');
146
+
147
+ return packageJSON;
148
+ },
149
+
150
+ _overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
151
+ if (!depSet[kindOfDependency]) {
152
+ return;
153
+ }
154
+
155
+ let packageNames = Object.keys(depSet[kindOfDependency]);
156
+
157
+ for (let packageName of packageNames) {
158
+ if (!packageJSON[kindOfDependency]) {
159
+ packageJSON[kindOfDependency] = {};
160
+ }
161
+
162
+ let version = depSet[kindOfDependency][packageName];
163
+ if (version === null) {
164
+ delete packageJSON[kindOfDependency][packageName];
165
+ } else {
166
+ packageJSON[kindOfDependency][packageName] = version;
167
+ }
168
+ }
169
+ },
170
+ });
@@ -2,9 +2,7 @@
2
2
 
3
3
  const CoreObject = require('core-object');
4
4
  const fs = require('fs-extra');
5
- const RSVP = require('rsvp');
6
5
  const path = require('path');
7
- const extend = require('extend');
8
6
  const debug = require('debug')('ember-try:dependency-manager-adapter:workspaces');
9
7
  const walkSync = require('walk-sync');
10
8
 
@@ -16,85 +14,105 @@ module.exports = CoreObject.extend({
16
14
  this.run = this.run || require('../utils/run');
17
15
 
18
16
  if (!this.useYarnCommand) {
19
- throw new Error('workspaces are currently only supported by Yarn, you must set `useYarn` to true');
17
+ throw new Error(
18
+ 'workspaces are currently only supported by Yarn, you must set `useYarn` to true'
19
+ );
20
20
  }
21
- },
22
-
23
- packageJSON: 'package.json',
21
+ let packageJSON = JSON.parse(fs.readFileSync(this.packageJSON));
22
+ let workspaceGlobs;
24
23
 
25
- setup(options) {
26
- if (!options) {
27
- options = {};
24
+ if (Array.isArray(packageJSON.workspaces)) {
25
+ workspaceGlobs = packageJSON.workspaces;
28
26
  }
29
27
 
30
- let packageJSON = JSON.parse(fs.readFileSync(this.packageJSON));
31
- let workspaceGlobs = packageJSON.workspaces;
28
+ if (packageJSON.workspaces && Array.isArray(packageJSON.workspaces.packages)) {
29
+ workspaceGlobs = packageJSON.workspaces.packages;
30
+ }
32
31
 
33
32
  if (!workspaceGlobs || !workspaceGlobs.length) {
34
- throw new Error('you must define the `workspaces` property in package.json with at least one workspace to use workspaces with ember-try');
33
+ throw new Error(
34
+ 'you must define the `workspaces` property in package.json with at least one workspace to use workspaces with ember-try'
35
+ );
35
36
  }
36
37
 
37
38
  // workspaces is a list of globs, loop over the list and find
38
39
  // all paths that contain a `package.json` file
39
- let workspacePaths = walkSync('.', { globs: workspaceGlobs }).filter(workspacePath => {
40
+ let workspacePaths = walkSync('.', { globs: workspaceGlobs }).filter((workspacePath) => {
40
41
  let packageJSONPath = path.join(this.cwd, workspacePath, 'package.json');
41
42
  return fs.existsSync(packageJSONPath);
42
43
  });
43
44
 
44
- this._packageAdapters = workspacePaths.map(workspacePath => {
45
+ this._packageAdapters = workspacePaths.map((workspacePath) => {
45
46
  return new NpmAdapter({
46
47
  cwd: workspacePath,
47
48
  run: this.run,
48
49
  managerOptions: this.managerOptions,
49
50
  useYarnCommand: true,
51
+ buildManagerOptions: this.buildManagerOptions,
50
52
  });
51
53
  });
54
+ },
52
55
 
53
- return RSVP.all(this._packageAdapters.map(adapter => adapter.setup(options)));
56
+ packageJSON: 'package.json',
57
+
58
+ setup(options) {
59
+ if (!options) {
60
+ options = {};
61
+ }
62
+
63
+ return Promise.all(this._packageAdapters.map((adapter) => adapter.setup(options)));
54
64
  },
55
65
 
56
- changeToDependencySet(depSet) {
66
+ async changeToDependencySet(depSet) {
57
67
  // TODO: What should this do for tables? Nesting? Needs different output
58
- this._packageAdapters.forEach(adapter => {
68
+ this._packageAdapters.forEach((adapter) => {
59
69
  adapter.applyDependencySet(depSet);
60
70
  });
61
71
 
62
- return this._install().then(() => {
63
- let deps = extend({}, depSet.dependencies || {}, depSet.devDependencies || {});
64
- let currentDeps = Object.keys(deps).map((dep) => {
65
- return {
66
- name: dep,
67
- versionExpected: deps[dep],
68
- versionSeen: this._findCurrentVersionOf(dep),
69
- packageManager: 'yarn',
70
- };
71
- });
72
+ await this._install(depSet);
73
+ let deps = Object.assign({}, depSet.dependencies, depSet.devDependencies);
74
+ let currentDeps = Object.keys(deps).map((dep) => {
75
+ return {
76
+ name: dep,
77
+ versionExpected: deps[dep],
78
+ versionSeen: this._findCurrentVersionOf(dep),
79
+ packageManager: 'yarn',
80
+ };
81
+ });
72
82
 
73
- debug('Switched to dependencies: \n', currentDeps);
83
+ debug('Switched to dependencies: \n', currentDeps);
74
84
 
75
- return RSVP.Promise.resolve(currentDeps);
76
- });
85
+ return currentDeps;
77
86
  },
78
87
 
79
88
  cleanup() {
80
- return RSVP.all(this._packageAdapters.map(adapter => adapter.cleanup()));
89
+ return Promise.all(this._packageAdapters.map((adapter) => adapter.cleanup()));
81
90
  },
82
91
 
83
- _install() {
92
+ _install(depSet) {
84
93
  let mgrOptions = this.managerOptions || [];
85
94
 
86
- debug('Run yarn install with options %s', mgrOptions);
87
-
88
- if (mgrOptions.indexOf('--no-lockfile') === -1) {
89
- mgrOptions = mgrOptions.concat(['--no-lockfile']);
90
- }
91
- // npm warns on incompatible engines
92
- // yarn errors, not a good experience
93
- if (mgrOptions.indexOf('--ignore-engines') === -1) {
94
- mgrOptions = mgrOptions.concat(['--ignore-engines']);
95
+ // buildManagerOptions overrides all default
96
+ if (typeof this.buildManagerOptions === 'function') {
97
+ mgrOptions = this.buildManagerOptions(depSet);
98
+
99
+ if (!Array.isArray(mgrOptions)) {
100
+ throw new Error('buildManagerOptions must return an array of options');
101
+ }
102
+ } else {
103
+ if (mgrOptions.indexOf('--no-lockfile') === -1) {
104
+ mgrOptions = mgrOptions.concat(['--no-lockfile']);
105
+ }
106
+ // npm warns on incompatible engines
107
+ // yarn errors, not a good experience
108
+ if (mgrOptions.indexOf('--ignore-engines') === -1) {
109
+ mgrOptions = mgrOptions.concat(['--ignore-engines']);
110
+ }
95
111
  }
96
112
 
97
- return this.run('yarn', [].concat(['install'], mgrOptions), { cwd: this.cwd });
113
+ debug('Run yarn install with options %s', mgrOptions);
114
+
115
+ return this.run('yarn', ['install', ...mgrOptions], { cwd: this.cwd });
98
116
  },
99
117
 
100
118
  _findCurrentVersionOf(dep) {