yeoman-environment 4.0.0-beta.1 → 4.0.0-beta.3

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.
@@ -4,14 +4,13 @@ export declare class ComposedStore {
4
4
  private readonly generators;
5
5
  private readonly uniqueByPathMap;
6
6
  private readonly uniqueGloballyMap;
7
- private readonly uniqueFeatures;
8
7
  constructor({ log }?: {
9
8
  log?: Logger;
10
9
  });
11
- get customCommitTask(): true | (() => Promise<void>) | undefined;
12
- get customInstallTask(): true | (() => Promise<void>) | undefined;
10
+ get customCommitTask(): any;
11
+ get customInstallTask(): any;
13
12
  getGenerators(): Record<string, BaseGenerator>;
14
- addGenerator(generator: any): {
13
+ addGenerator(generator: BaseGenerator): {
15
14
  uniqueBy: any;
16
15
  identifier: any;
17
16
  added: boolean;
@@ -19,8 +18,9 @@ export declare class ComposedStore {
19
18
  } | {
20
19
  identifier: any;
21
20
  added: boolean;
22
- generator: any;
21
+ generator: BaseGenerator;
23
22
  uniqueBy?: undefined;
24
23
  };
25
24
  getUniqueByPathMap(root: string): Map<string, BaseGenerator>;
25
+ private getFeature;
26
26
  }
@@ -2,27 +2,25 @@ import crypto from 'node:crypto';
2
2
  import { toNamespace } from '@yeoman/namespace';
3
3
  import createdLogger from 'debug';
4
4
  const debug = createdLogger('yeoman:environment:composed-store');
5
- const uniqueFeatureValues = ['customCommitTask', 'customInstallTask'];
6
5
  export class ComposedStore {
7
6
  log;
8
7
  generators = {};
9
8
  uniqueByPathMap = new Map();
10
9
  uniqueGloballyMap = new Map();
11
- uniqueFeatures = new Map();
12
10
  constructor({ log } = {}) {
13
11
  this.log = log;
14
12
  }
15
13
  get customCommitTask() {
16
- return this.uniqueFeatures.get('customCommitTask');
14
+ return this.getFeature('customCommitTask');
17
15
  }
18
16
  get customInstallTask() {
19
- return this.uniqueFeatures.get('customInstallTask');
17
+ return this.getFeature('customInstallTask');
20
18
  }
21
19
  getGenerators() {
22
20
  return { ...this.generators };
23
21
  }
24
22
  addGenerator(generator) {
25
- const features = generator.getFeatures?.() ?? {};
23
+ const { features = generator.getFeatures?.() ?? {} } = generator;
26
24
  let { uniqueBy } = features;
27
25
  const { uniqueGlobally } = features;
28
26
  let identifier = uniqueBy;
@@ -46,19 +44,6 @@ export class ComposedStore {
46
44
  return { uniqueBy, identifier, added: false, generator: uniqueByMap.get(uniqueBy) };
47
45
  }
48
46
  uniqueByMap.set(uniqueBy, generator);
49
- for (const featureName of uniqueFeatureValues) {
50
- const feature = features[featureName];
51
- if (feature) {
52
- const existingFeature = this.uniqueFeatures.get(feature);
53
- if (typeof existingFeature !== 'function') {
54
- debug(`Feature ${featureName} provided by ${uniqueBy}`);
55
- this.uniqueFeatures.set(featureName, feature);
56
- }
57
- else if (typeof feature === 'function') {
58
- this.log?.info?.(`Multiple ${featureName} tasks found. Using the first.`);
59
- }
60
- }
61
- }
62
47
  this.generators[uniqueGlobally ? uniqueBy : `${generatorRoot}#${uniqueBy}`] = generator;
63
48
  return { identifier, added: true, generator };
64
49
  }
@@ -68,4 +53,22 @@ export class ComposedStore {
68
53
  }
69
54
  return this.uniqueByPathMap.get(root);
70
55
  }
56
+ getFeature(featureName) {
57
+ const providedFeatures = Object.entries(this.generators)
58
+ .map(([generatorId, generator]) => {
59
+ const { features = generator.getFeatures?.() } = generator;
60
+ const feature = features?.[featureName];
61
+ return feature ? [generatorId, feature] : undefined;
62
+ })
63
+ .filter(Boolean);
64
+ if (providedFeatures.length > 0) {
65
+ if (providedFeatures.length > 1) {
66
+ this.log?.info?.(`Multiple ${featureName} tasks found (${providedFeatures.map(([generatorId]) => generatorId).join(', ')}). Using the first.`);
67
+ }
68
+ const [generatorId, feature] = providedFeatures[0];
69
+ debug(`Feature ${featureName} provided by ${generatorId}`);
70
+ return feature;
71
+ }
72
+ return undefined;
73
+ }
71
74
  }
@@ -590,14 +590,14 @@ export default class EnvironmentBase extends EventEmitter {
590
590
  * Queue environment's package manager install task.
591
591
  */
592
592
  queuePackageManagerInstall() {
593
- const { adapter, sharedFs: memFs } = this;
594
- const { skipInstall, nodePackageManager } = this.options;
595
- const { customInstallTask } = this.composedStore;
596
593
  this.queueTask('install', async () => {
597
594
  if (this.compatibilityMode === 'v4') {
598
595
  debug('Running in generator < 5 compatibility. Package manager install is done by the generator.');
599
596
  return;
600
597
  }
598
+ const { adapter, sharedFs: memFs } = this;
599
+ const { skipInstall, nodePackageManager } = this.options;
600
+ const { customInstallTask } = this.composedStore;
601
601
  await packageManagerInstallTask({
602
602
  adapter,
603
603
  memFs,
@@ -1,6 +1,6 @@
1
1
  import { join, resolve } from 'node:path';
2
2
  import createdLogger from 'debug';
3
- import preferredPm from 'preferred-pm';
3
+ import { whichPackageManager } from 'which-package-manager';
4
4
  import { execa } from 'execa';
5
5
  const debug = createdLogger('yeoman:environment:package-manager');
6
6
  /**
@@ -53,8 +53,7 @@ Changes to package.json were detected.`);
53
53
  `);
54
54
  return false;
55
55
  }
56
- // eslint-disable-next-line unicorn/no-await-expression-member
57
- let packageManagerName = nodePackageManager ?? (await preferredPm(packageJsonLocation))?.name;
56
+ let packageManagerName = nodePackageManager ?? (await whichPackageManager({ cwd: packageJsonLocation }));
58
57
  const execPackageManager = async () => {
59
58
  if (!packageManagerName) {
60
59
  packageManagerName = 'npm';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.3",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "keywords": [
6
6
  "development",
@@ -73,10 +73,10 @@
73
73
  "lodash-es": "^4.17.21",
74
74
  "mem-fs": "^3.0.0",
75
75
  "mem-fs-editor": "^10.0.1",
76
- "preferred-pm": "^3.0.3",
77
76
  "semver": "^7.5.0",
78
77
  "slash": "^5.0.1",
79
- "untildify": "^5.0.0"
78
+ "untildify": "^5.0.0",
79
+ "which-package-manager": "^0.0.1"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@types/debug": "^4.1.8",