yeoman-environment 3.15.1 → 3.16.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.
Files changed (2) hide show
  1. package/lib/environment.js +48 -23
  2. package/package.json +1 -5
@@ -979,17 +979,7 @@ class Environment extends Base {
979
979
  };
980
980
 
981
981
  if (schedule) {
982
- this.runLoop.add(
983
- 'environment:run',
984
- async (done, stop) => {
985
- try {
986
- await runGenerator();
987
- done();
988
- } catch (error) {
989
- stop(error);
990
- }
991
- }
992
- );
982
+ this.queueTask('environment:run', () => runGenerator());
993
983
  } else {
994
984
  const maybePromise = runGenerator();
995
985
  if (maybePromise && maybePromise.then) {
@@ -1314,11 +1304,10 @@ class Environment extends Base {
1314
1304
  queueConflicter() {
1315
1305
  const queueCommit = () => {
1316
1306
  debug('Queueing conflicts task');
1317
- this.runLoop.add('environment:conflicts', (done, stop) => {
1307
+ this.queueTask('environment:conflicts', async () => {
1318
1308
  let customCommitTask = this.findGeneratorCustomCommitTask();
1319
1309
  if (customCommitTask !== undefined && customCommitTask) {
1320
1310
  if (typeof customCommitTask !== 'function') {
1321
- done();
1322
1311
  return;
1323
1312
  }
1324
1313
  } else {
@@ -1331,17 +1320,13 @@ class Environment extends Base {
1331
1320
  }
1332
1321
  const result = customCommitTask();
1333
1322
  if (!result || !result.then) {
1334
- done();
1335
1323
  return;
1336
1324
  }
1337
- return result.then(() => {
1338
- if (!this.enableConflicterIgnore) {
1339
- debug('Adding queueCommit event listener');
1340
- this.sharedFs.once('change', queueCommit);
1341
- }
1342
- done();
1325
+ await result;
1326
+ if (!this.enableConflicterIgnore) {
1327
+ debug('Adding queueCommit event listener');
1328
+ this.sharedFs.once('change', queueCommit);
1343
1329
  }
1344
- , stop);
1345
1330
  }
1346
1331
  , {
1347
1332
  once: 'write memory fs to disk'
@@ -1355,12 +1340,52 @@ class Environment extends Base {
1355
1340
  * Queue environment's package manager install task.
1356
1341
  */
1357
1342
  queuePackageManagerInstall() {
1358
- this.runLoop.add(
1343
+ this.queueTask(
1359
1344
  'install',
1360
- (done, stop) => this.packageManagerInstallTask().then(done, stop),
1345
+ () => this.packageManagerInstallTask(),
1361
1346
  {once: 'package manager install'}
1362
1347
  );
1363
1348
  }
1349
+
1350
+ /**
1351
+ * Queue tasks
1352
+ * @param {string} priority
1353
+ * @param {(...args: any[]) => void | Promise<void>} task
1354
+ * @param {{ once?: string, startQueue?: boolean }} [options]
1355
+ */
1356
+ queueTask(priority, task, options) {
1357
+ return new Promise((resolve, reject) => {
1358
+ this.runLoop.add(
1359
+ priority,
1360
+ async (done, stop) => {
1361
+ try {
1362
+ const result = await task();
1363
+ done(result);
1364
+ resolve(result);
1365
+ } catch (error) {
1366
+ stop(error);
1367
+ reject(error);
1368
+ }
1369
+ },
1370
+ {
1371
+ once: options.once,
1372
+ run: options.startQueue || false
1373
+ }
1374
+ );
1375
+ });
1376
+ }
1377
+
1378
+ /**
1379
+ * Add priority
1380
+ * @param {string} priority
1381
+ * @param {string} [before]
1382
+ */
1383
+ addPriority(priority, before) {
1384
+ if (this.runLoop.queueNames.includes(priority)) {
1385
+ return;
1386
+ }
1387
+ this.runLoop.addSubQueue(priority, before);
1388
+ }
1364
1389
  }
1365
1390
 
1366
1391
  Object.assign(Environment.prototype, resolver);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "3.15.1",
3
+ "version": "3.16.0",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "homepage": "http://yeoman.io",
6
6
  "author": "Yeoman",
@@ -98,10 +98,6 @@
98
98
  "textextensions": "^5.12.0",
99
99
  "untildify": "^4.0.0"
100
100
  },
101
- "peerDependencies": {
102
- "mem-fs": "^1.2.0 || ^2.0.0",
103
- "mem-fs-editor": "^8.1.2 || ^9.0.0"
104
- },
105
101
  "devDependencies": {
106
102
  "coveralls": "^3.0.2",
107
103
  "cross-spawn": "^7.0.1",