yeoman-environment 4.0.0-alpha.8 → 4.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.
package/dist/commit.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { createConflicterTransform, createYoResolveTransform, forceYoFiles } from '@yeoman/conflicter';
2
+ import createdLogger from 'debug';
2
3
  import { create as createMemFsEditor } from 'mem-fs-editor';
3
4
  // eslint-disable-next-line n/file-extension-in-import
4
5
  import { isFilePending } from 'mem-fs-editor/state';
5
6
  // eslint-disable-next-line n/file-extension-in-import
6
7
  import { createCommitTransform } from 'mem-fs-editor/transform';
8
+ const debug = createdLogger('yeoman:environment:commit');
7
9
  /**
8
10
  * Commits the MemFs to the disc.
9
11
  * @param {Stream} [stream] - files stream, defaults to this.sharedFs.stream().
10
12
  * @return {Promise}
11
13
  */
12
14
  export const commitSharedFsTask = ({ adapter, conflicterOptions, sharedFs, stream, }) => {
15
+ debug('Running commitSharedFsTask');
13
16
  const fs = createMemFsEditor(sharedFs);
14
17
  stream = stream ?? fs.store.stream({ filter: file => isFilePending(file) });
15
18
  return fs.commit([
@@ -13,9 +13,9 @@ export declare class ComposedStore {
13
13
  getGenerators(): Record<string, BaseGenerator>;
14
14
  addGenerator(generator: any): {
15
15
  uniqueBy: any;
16
+ identifier: any;
16
17
  added: boolean;
17
18
  generator: BaseGenerator | undefined;
18
- identifier?: undefined;
19
19
  } | {
20
20
  identifier: any;
21
21
  added: boolean;
@@ -1,5 +1,7 @@
1
1
  import crypto from 'node:crypto';
2
2
  import { toNamespace } from '@yeoman/namespace';
3
+ import createdLogger from 'debug';
4
+ const debug = createdLogger('yeoman:environment:composed-store');
3
5
  const uniqueFeatureValues = ['customCommitTask', 'customInstallTask'];
4
6
  export class ComposedStore {
5
7
  log;
@@ -41,7 +43,7 @@ export class ComposedStore {
41
43
  const generatorRoot = generator.destinationRoot();
42
44
  const uniqueByMap = uniqueGlobally ? this.uniqueGloballyMap : this.getUniqueByPathMap(generatorRoot);
43
45
  if (uniqueByMap.has(uniqueBy)) {
44
- return { uniqueBy, added: false, generator: uniqueByMap.get(uniqueBy) };
46
+ return { uniqueBy, identifier, added: false, generator: uniqueByMap.get(uniqueBy) };
45
47
  }
46
48
  uniqueByMap.set(uniqueBy, generator);
47
49
  for (const featureName of uniqueFeatureValues) {
@@ -49,6 +51,7 @@ export class ComposedStore {
49
51
  if (feature) {
50
52
  const existingFeature = this.uniqueFeatures.get(feature);
51
53
  if (typeof existingFeature !== 'function') {
54
+ debug(`Feature ${featureName} provided by ${uniqueBy}`);
52
55
  this.uniqueFeatures.set(featureName, feature);
53
56
  }
54
57
  else if (typeof feature === 'function') {
@@ -526,11 +526,14 @@ export default class EnvironmentBase extends EventEmitter {
526
526
  * would be killed if an error is thrown to environment.
527
527
  * Make sure to not rely on that behavior.
528
528
  */
529
- this.on('error', error => {
529
+ this.on('error', async (error) => {
530
+ this.runLoop.pause();
531
+ await this.adapter.onIdle?.();
530
532
  reject(error);
531
533
  this.adapter.close();
532
534
  });
533
- this.once('end', () => {
535
+ this.once('end', async () => {
536
+ await this.adapter.onIdle?.();
534
537
  resolve();
535
538
  this.adapter.close();
536
539
  });
@@ -567,13 +570,15 @@ export default class EnvironmentBase extends EventEmitter {
567
570
  const queueCommit = () => {
568
571
  debug('Queueing conflicts task');
569
572
  this.queueTask('environment:conflicts', async () => {
573
+ debug('Running conflicts');
570
574
  const { customCommitTask = () => commitSharedFsTask(this) } = this.composedStore;
571
- if (typeof customCommitTask !== 'function') {
572
- // There is a custom commit task or just disabled
573
- return;
575
+ if (typeof customCommitTask === 'function') {
576
+ await customCommitTask();
574
577
  }
575
- await customCommitTask();
576
- debug('Adding queueCommit event listener');
578
+ else {
579
+ debug('Ignoring commit, custom commit was provided');
580
+ }
581
+ debug('Adding queueCommit listener');
577
582
  this.sharedFs.once('change', queueCommit);
578
583
  }, {
579
584
  once: 'write memory fs to disk',
@@ -601,6 +606,10 @@ export default class EnvironmentBase extends EventEmitter {
601
606
  nodePackageManager,
602
607
  customInstallTask,
603
608
  });
609
+ memFs.once('change', file => {
610
+ if (file === join(this.cwd, 'package.json'))
611
+ this.queuePackageManagerInstall();
612
+ });
604
613
  }, { once: 'package manager install' });
605
614
  }
606
615
  /**
@@ -15,6 +15,7 @@ const debug = createdLogger('yeoman:environment:package-manager');
15
15
 
16
16
  */
17
17
  export async function packageManagerInstallTask({ memFs, packageJsonLocation, customInstallTask, adapter, nodePackageManager, skipInstall, }) {
18
+ debug('Running packageManagerInstallTask');
18
19
  packageJsonLocation = resolve(packageJsonLocation);
19
20
  /**
20
21
  * @private
@@ -1,7 +1,6 @@
1
1
  import { parse } from 'node:path';
2
2
  import slash from 'slash';
3
- import { findLast } from 'lodash-es';
4
- import escapeStringRegexp from 'escape-string-regexp';
3
+ import { findLast, escapeRegExp } from 'lodash-es';
5
4
  export const defaultLookups = ['.', 'generators', 'lib/generators', 'dist/generators'];
6
5
  /**
7
6
  * Given a String `filepath`, tries to figure out the relative namespace.
@@ -45,7 +44,7 @@ export const asNamespace = (filepath, { lookups = defaultLookups }) => {
45
44
  // If `ns` contains a lookup dir in its path, remove it.
46
45
  for (const lookup of nsLookups) {
47
46
  // Only match full directory (begin with leading slash or start of input, end with trailing slash)
48
- ns = ns.replace(new RegExp(`(?:/|^)${escapeStringRegexp(lookup)}(?=/)`, 'g'), '');
47
+ ns = ns.replace(new RegExp(`(?:/|^)${escapeRegExp(lookup)}(?=/)`, 'g'), '');
49
48
  }
50
49
  const folders = ns.split('/');
51
50
  const scope = findLast(folders, folder => folder.startsWith('@'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "keywords": [
6
6
  "development",
@@ -65,21 +65,18 @@
65
65
  "chalk": "^5.2.0",
66
66
  "commander": "^10.0.1",
67
67
  "debug": "^4.3.4",
68
- "escape-string-regexp": "^5.0.0",
69
68
  "execa": "^7.1.1",
70
- "fly-import": "^0.2.0",
69
+ "fly-import": "^0.3.0",
71
70
  "globby": "^13.1.4",
72
71
  "grouped-queue": "^2.0.0",
73
72
  "locate-path": "^7.2.0",
74
73
  "lodash-es": "^4.17.21",
75
- "log-symbols": "^5.1.0",
76
74
  "mem-fs": "^3.0.0",
77
75
  "mem-fs-editor": "^10.0.1",
78
- "npmlog": "^7.0.1",
79
76
  "preferred-pm": "^3.0.3",
80
77
  "semver": "^7.5.0",
81
78
  "slash": "^5.0.1",
82
- "untildify": "^4.0.0"
79
+ "untildify": "^5.0.0"
83
80
  },
84
81
  "devDependencies": {
85
82
  "@types/debug": "^4.1.8",
@@ -102,7 +99,7 @@
102
99
  "xo": "0.54.2",
103
100
  "yeoman-assert": "^3.1.1",
104
101
  "yeoman-generator": "^5.9.0",
105
- "yeoman-test": "^8.0.0-rc.0"
102
+ "yeoman-test": "^8.0.0-rc.1"
106
103
  },
107
104
  "peerDependencies": {
108
105
  "@yeoman/types": "^1.0.1",