ember-try 1.4.0 → 3.0.0-beta.1

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({
@@ -26,71 +26,82 @@ module.exports = CoreObject.extend({
26
26
  npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try',
27
27
  packageLock: 'package-lock.json',
28
28
  packageLockBackupFileName: 'package-lock.json.ember-try',
29
- setup(options) {
29
+
30
+ async setup(options) {
30
31
  if (!options) {
31
32
  options = {};
32
33
  }
34
+
33
35
  this._runYarnCheck(options.ui);
34
- return this._backupOriginalDependencies();
35
- },
36
- changeToDependencySet(depSet) {
37
- let adapter = this;
38
36
 
39
- adapter.applyDependencySet(depSet);
37
+ return await this._backupOriginalDependencies();
38
+ },
40
39
 
41
- return adapter._install(depSet).then(() => {
42
- let deps = extend({}, depSet.dependencies || {}, depSet.devDependencies || {});
43
- let currentDeps = Object.keys(deps).map((dep) => {
44
- return {
45
- name: dep,
46
- versionExpected: deps[dep],
47
- versionSeen: adapter._findCurrentVersionOf(dep),
48
- packageManager: adapter.useYarnCommand ? 'yarn' : 'npm',
49
- };
50
- });
40
+ async changeToDependencySet(depSet) {
41
+ this.applyDependencySet(depSet);
51
42
 
52
- debug('Switched to dependencies: \n', currentDeps);
43
+ await this._install(depSet);
53
44
 
54
- 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
+ };
55
53
  });
54
+
55
+ debug('Switched to dependencies: \n', currentDeps);
56
+
57
+ return currentDeps;
56
58
  },
57
- cleanup() {
58
- let adapter = this;
59
59
 
60
- return this._restoreOriginalDependencies().then(() => {
60
+ async cleanup() {
61
+ try {
62
+ await this._restoreOriginalDependencies();
63
+
61
64
  debug('Remove backup package.json and node_modules');
62
65
 
63
- let cleanupTasks = [rimraf(path.join(adapter.cwd, adapter.packageJSONBackupFileName)),
64
- 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
+ ];
65
70
 
66
71
  if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) {
67
- cleanupTasks.push(rimraf(path.join(adapter.cwd, adapter.yarnLockBackupFileName)));
72
+ cleanupTasks.push(rimraf(path.join(this.cwd, this.yarnLockBackupFileName)));
68
73
  }
69
74
 
70
75
  if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) {
71
- cleanupTasks.push(rimraf(path.join(adapter.cwd, adapter.npmShrinkWrapBackupFileName)));
76
+ cleanupTasks.push(rimraf(path.join(this.cwd, this.npmShrinkWrapBackupFileName)));
72
77
  }
73
78
 
74
79
  if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) {
75
- cleanupTasks.push(rimraf(path.join(adapter.cwd, adapter.packageLockBackupFileName)));
80
+ cleanupTasks.push(rimraf(path.join(this.cwd, this.packageLockBackupFileName)));
76
81
  }
77
82
 
78
- return RSVP.all(cleanupTasks);
79
- }).catch((e) => {
83
+ return await Promise.all(cleanupTasks);
84
+ } catch (e) {
80
85
  console.log('Error cleaning up npm scenario:', e); // eslint-disable-line no-console
81
- });
86
+ }
82
87
  },
88
+
83
89
  _runYarnCheck(ui) {
84
90
  if (!this.useYarnCommand) {
85
91
  try {
86
92
  if (fs.statSync(path.join(this.cwd, this.yarnLock)).isFile()) {
87
- 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
+ );
88
98
  }
89
99
  } catch (e) {
90
100
  // If no yarn.lock is found, no need to warn.
91
101
  }
92
102
  }
93
103
  },
104
+
94
105
  _findCurrentVersionOf(packageName) {
95
106
  let filename = path.join(this.cwd, this.nodeModules, packageName, this.packageJSON);
96
107
  if (fs.existsSync(filename)) {
@@ -99,8 +110,8 @@ module.exports = CoreObject.extend({
99
110
  return null;
100
111
  }
101
112
  },
102
- _install(depSet) {
103
- let adapter = this;
113
+
114
+ async _install(depSet) {
104
115
  let mgrOptions = this.managerOptions || [];
105
116
  let cmd = this.useYarnCommand ? 'yarn' : 'npm';
106
117
 
@@ -128,25 +139,27 @@ module.exports = CoreObject.extend({
128
139
 
129
140
  debug('Run npm/yarn install with options %s', mgrOptions);
130
141
 
131
- return this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd }).then(() => {
132
- if (!adapter.useYarnCommand) {
133
- return adapter.run('npm', ['--version'], { cwd: this.cwd, stdio: 'pipe' }).then((res) => {
134
- let version = res.stdout;
135
- if (version.match(/^4./)) {
136
- debug('Running npm prune because version is %s', version);
137
- return adapter.run(adapter.configKey, ['prune'], { cwd: adapter.cwd });
138
- }
142
+ await this.run(cmd, [].concat(['install'], mgrOptions), { cwd: this.cwd });
139
143
 
140
- debug('Not running npm prune because version is %s', version);
141
- })
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 });
142
150
  }
143
- });
151
+
152
+ debug('Not running npm prune because version is %s', version);
153
+ }
144
154
  },
145
- applyDependencySet(depSet) {
146
155
 
156
+ applyDependencySet(depSet) {
147
157
  debug('Changing to dependency set: %s', JSON.stringify(depSet));
148
158
 
149
- if (!depSet) { return RSVP.resolve([]); }
159
+ if (!depSet) {
160
+ return;
161
+ }
162
+
150
163
  let backupPackageJSON = path.join(this.cwd, this.packageJSONBackupFileName);
151
164
  let packageJSONFile = path.join(this.cwd, this.packageJSON);
152
165
  let packageJSON = JSON.parse(fs.readFileSync(backupPackageJSON));
@@ -156,8 +169,8 @@ module.exports = CoreObject.extend({
156
169
 
157
170
  fs.writeFileSync(packageJSONFile, JSON.stringify(newPackageJSON, null, 2));
158
171
  },
159
- _packageJSONForDependencySet(packageJSON, depSet) {
160
172
 
173
+ _packageJSONForDependencySet(packageJSON, depSet) {
161
174
  this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
162
175
  this._overridePackageJSONDependencies(packageJSON, depSet, 'devDependencies');
163
176
  this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
@@ -169,78 +182,99 @@ module.exports = CoreObject.extend({
169
182
 
170
183
  return packageJSON;
171
184
  },
185
+
172
186
  _overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {
173
- if (!depSet[kindOfDependency]) { return; }
174
- let pkgs = Object.keys(depSet[kindOfDependency]);
187
+ if (!depSet[kindOfDependency]) {
188
+ return;
189
+ }
175
190
 
176
- pkgs.forEach((pkg) => {
191
+ let packageNames = Object.keys(depSet[kindOfDependency]);
192
+
193
+ packageNames.forEach((packageName) => {
177
194
  if (!packageJSON[kindOfDependency]) {
178
195
  packageJSON[kindOfDependency] = {};
179
196
  }
180
197
 
181
- let version = depSet[kindOfDependency][pkg];
198
+ let version = depSet[kindOfDependency][packageName];
182
199
  if (version === null) {
183
- delete packageJSON[kindOfDependency][pkg];
200
+ delete packageJSON[kindOfDependency][packageName];
184
201
  } else {
185
- packageJSON[kindOfDependency][pkg] = version;
202
+ packageJSON[kindOfDependency][packageName] = version;
186
203
  }
187
204
  });
188
205
  },
189
- _restoreOriginalDependencies() {
190
- let copy = RSVP.denodeify(fs.copy);
191
206
 
207
+ _restoreOriginalDependencies() {
192
208
  debug('Restoring original package.json and node_modules');
193
209
 
194
210
  let restoreTasks = [
195
- copy(path.join(this.cwd, this.packageJSONBackupFileName),
196
- path.join(this.cwd, this.packageJSON)),
197
- copy(path.join(this.cwd, this.nodeModulesBackupLocation),
198
- 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
+ ),
199
215
  ];
200
216
 
201
- if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) {
202
- restoreTasks.push(copy(path.join(this.cwd, this.yarnLockBackupFileName),
203
- path.join(this.cwd, this.yarnLock)));
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)));
204
227
  }
205
228
 
206
- if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrapBackupFileName))) {
207
- restoreTasks.push(copy(path.join(this.cwd, this.npmShrinkWrapBackupFileName),
208
- path.join(this.cwd, this.npmShrinkWrap)));
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)));
209
232
  }
210
233
 
211
- if (fs.existsSync(path.join(this.cwd, this.packageLockBackupFileName))) {
212
- restoreTasks.push(copy(path.join(this.cwd, this.packageLockBackupFileName),
213
- path.join(this.cwd, this.packageLock)));
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)));
214
237
  }
215
238
 
216
- return RSVP.all(restoreTasks);
239
+ return Promise.all(restoreTasks);
217
240
  },
218
- _backupOriginalDependencies() {
219
- let copy = RSVP.denodeify(fs.copy);
220
241
 
242
+ _backupOriginalDependencies() {
221
243
  debug('Backing up package.json and node_modules');
222
244
 
223
245
  let backupTasks = [
224
- copy(path.join(this.cwd, this.packageJSON),
225
- path.join(this.cwd, this.packageJSONBackupFileName)),
226
- copy(path.join(this.cwd, this.nodeModules),
227
- 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
+ }
228
260
 
229
- if (fs.existsSync(path.join(this.cwd, this.yarnLock))) {
230
- backupTasks.push(copy(path.join(this.cwd, this.yarnLock),
231
- path.join(this.cwd, this.yarnLockBackupFileName)));
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)));
232
264
  }
233
265
 
234
- if (fs.existsSync(path.join(this.cwd, this.npmShrinkWrap))) {
235
- backupTasks.push(copy(path.join(this.cwd, this.npmShrinkWrap),
236
- path.join(this.cwd, this.npmShrinkWrapBackupFileName)));
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
+ );
237
271
  }
238
272
 
239
- if (fs.existsSync(path.join(this.cwd, this.packageLock))) {
240
- backupTasks.push(copy(path.join(this.cwd, this.packageLock),
241
- path.join(this.cwd, this.packageLockBackupFileName)));
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)));
242
276
  }
243
277
 
244
- return RSVP.all(backupTasks);
278
+ return Promise.all(backupTasks);
245
279
  },
246
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,32 +14,35 @@ 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,
@@ -50,35 +51,42 @@ module.exports = CoreObject.extend({
50
51
  buildManagerOptions: this.buildManagerOptions,
51
52
  });
52
53
  });
54
+ },
53
55
 
54
- 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)));
55
64
  },
56
65
 
57
- changeToDependencySet(depSet) {
66
+ async changeToDependencySet(depSet) {
58
67
  // TODO: What should this do for tables? Nesting? Needs different output
59
- this._packageAdapters.forEach(adapter => {
68
+ this._packageAdapters.forEach((adapter) => {
60
69
  adapter.applyDependencySet(depSet);
61
70
  });
62
71
 
63
- return this._install(depSet).then(() => {
64
- let deps = extend({}, depSet.dependencies || {}, depSet.devDependencies || {});
65
- let currentDeps = Object.keys(deps).map((dep) => {
66
- return {
67
- name: dep,
68
- versionExpected: deps[dep],
69
- versionSeen: this._findCurrentVersionOf(dep),
70
- packageManager: 'yarn',
71
- };
72
- });
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
+ });
73
82
 
74
- debug('Switched to dependencies: \n', currentDeps);
83
+ debug('Switched to dependencies: \n', currentDeps);
75
84
 
76
- return RSVP.Promise.resolve(currentDeps);
77
- });
85
+ return currentDeps;
78
86
  },
79
87
 
80
88
  cleanup() {
81
- return RSVP.all(this._packageAdapters.map(adapter => adapter.cleanup()));
89
+ return Promise.all(this._packageAdapters.map((adapter) => adapter.cleanup()));
82
90
  },
83
91
 
84
92
  _install(depSet) {
@@ -104,7 +112,7 @@ module.exports = CoreObject.extend({
104
112
 
105
113
  debug('Run yarn install with options %s', mgrOptions);
106
114
 
107
- return this.run('yarn', [].concat(['install'], mgrOptions), { cwd: this.cwd });
115
+ return this.run('yarn', ['install', ...mgrOptions], { cwd: this.cwd });
108
116
  },
109
117
 
110
118
  _findCurrentVersionOf(dep) {
@@ -7,8 +7,15 @@ const DependencyManagerAdapterFactory = require('./../utils/dependency-manager-a
7
7
 
8
8
  module.exports = CoreObject.extend({
9
9
  run() {
10
- let dependencyAdapters = this.dependencyManagerAdapters || DependencyManagerAdapterFactory.generateFromConfig(this.config, this.project.root);
11
- debug('DependencyManagerAdapters: %s', dependencyAdapters.map((item) => { return item.configKey; }));
10
+ let dependencyAdapters =
11
+ this.dependencyManagerAdapters ||
12
+ DependencyManagerAdapterFactory.generateFromConfig(this.config, this.project.root);
13
+ debug(
14
+ 'DependencyManagerAdapters: %s',
15
+ dependencyAdapters.map((item) => {
16
+ return item.configKey;
17
+ })
18
+ );
12
19
  return new ScenarioManager({ dependencyManagerAdapters: dependencyAdapters }).cleanup();
13
20
  },
14
21
  });