yeoman-environment 6.0.1 → 6.1.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.
@@ -1,5 +1,5 @@
1
1
  import type { BaseGenerator, Logger } from '@yeoman/types';
2
- import type { InstallTask } from './package-manager.ts';
2
+ import type { PackageManagerInstallTaskOptions } from './package-manager.ts';
3
3
  export declare class ComposedStore {
4
4
  private readonly log?;
5
5
  private readonly generators;
@@ -9,15 +9,15 @@ export declare class ComposedStore {
9
9
  log?: Logger;
10
10
  });
11
11
  get customCommitTask(): (() => Promise<void> | void) | undefined;
12
- get customInstallTask(): InstallTask | undefined;
12
+ get customInstallTask(): PackageManagerInstallTaskOptions['customInstallTask'] | undefined;
13
13
  getGenerators(): Record<string, BaseGenerator>;
14
14
  addGenerator(generator: BaseGenerator): {
15
- uniqueBy: any;
16
- identifier: any;
15
+ uniqueBy: string;
16
+ identifier: string | undefined;
17
17
  added: boolean;
18
18
  generator: BaseGenerator | undefined;
19
19
  } | {
20
- identifier: any;
20
+ identifier: string | undefined;
21
21
  added: boolean;
22
22
  generator: BaseGenerator;
23
23
  uniqueBy?: undefined;
@@ -2,6 +2,9 @@ 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 getFeaturesFromGenerator = (generator) => {
6
+ return generator.features ?? generator.getFeatures?.() ?? {};
7
+ };
5
8
  export class ComposedStore {
6
9
  log;
7
10
  generators = {};
@@ -20,7 +23,7 @@ export class ComposedStore {
20
23
  return { ...this.generators };
21
24
  }
22
25
  addGenerator(generator) {
23
- const { features = generator.getFeatures?.() ?? {} } = generator;
26
+ const features = getFeaturesFromGenerator(generator);
24
27
  let { uniqueBy } = features;
25
28
  const { uniqueGlobally } = features;
26
29
  let identifier = uniqueBy;
@@ -56,8 +59,8 @@ export class ComposedStore {
56
59
  findFeature(featureName) {
57
60
  return Object.entries(this.generators)
58
61
  .map(([generatorId, generator]) => {
59
- const { features = generator.getFeatures?.() } = generator;
60
- const feature = features?.[featureName];
62
+ const features = getFeaturesFromGenerator(generator);
63
+ const feature = features[featureName];
61
64
  return feature ? { generatorId, feature: feature } : undefined;
62
65
  })
63
66
  .filter(Boolean);
@@ -74,7 +74,7 @@ class FullEnvironment extends EnvironmentBase {
74
74
  }
75
75
  groups[base].push(namespace);
76
76
  }
77
- for (const key of Object.keys(groups).sort()) {
77
+ for (const key of Object.keys(groups).toSorted()) {
78
78
  const group = groups[key];
79
79
  if (group.length > 0) {
80
80
  out.push('', key.charAt(0).toUpperCase() + key.slice(1));
@@ -39,7 +39,7 @@ export async function lookupGenerators(options = {}, register) {
39
39
  ...options,
40
40
  };
41
41
  return moduleLookupSync(options, ({ packagePath, files }) => {
42
- files = [...files].sort((a, b) => {
42
+ files = [...files].toSorted((a, b) => {
43
43
  return defaultExtensions.indexOf(extname(a)) - defaultExtensions.indexOf(extname(b));
44
44
  });
45
45
  for (const filePath of files) {
@@ -7,7 +7,7 @@ export type PackageManagerInstallTaskOptions = {
7
7
  packageJsonLocation: string;
8
8
  adapter: InputOutputAdapter;
9
9
  nodePackageManager?: string;
10
- customInstallTask?: boolean | InstallTask;
10
+ customInstallTask?: boolean | InstallTask | 'ask';
11
11
  skipInstall?: boolean;
12
12
  };
13
13
  /**
@@ -23,7 +23,10 @@ export async function packageManagerInstallTask({ memFs, packageJsonLocation, cu
23
23
  * @return {Vinyl | undefined} a Vinyl file.
24
24
  */
25
25
  function getDestinationPackageJson() {
26
- return memFs.get(join(packageJsonLocation, 'package.json'));
26
+ const packageJsonFile = join(packageJsonLocation, 'package.json');
27
+ if (memFs.existsInMemory(packageJsonFile)) {
28
+ return memFs.get(packageJsonFile);
29
+ }
27
30
  }
28
31
  /**
29
32
  * @private
@@ -32,12 +35,12 @@ export async function packageManagerInstallTask({ memFs, packageJsonLocation, cu
32
35
  */
33
36
  function isDestinationPackageJsonCommitted() {
34
37
  const file = getDestinationPackageJson();
35
- return file.committed;
38
+ return file?.committed;
36
39
  }
37
40
  if (!getDestinationPackageJson()) {
38
41
  return false;
39
42
  }
40
- if (customInstallTask && typeof customInstallTask !== 'function') {
43
+ if (customInstallTask && typeof customInstallTask !== 'function' && customInstallTask !== 'ask') {
41
44
  debug('Install disabled by customInstallTask');
42
45
  return false;
43
46
  }
@@ -68,8 +71,18 @@ Running ${packageManagerName} install for you to install the required dependenci
68
71
  await execa(packageManagerName, ['install'], { stdio: 'inherit', cwd: packageJsonLocation });
69
72
  return true;
70
73
  };
71
- if (customInstallTask) {
74
+ if (typeof customInstallTask === 'function') {
72
75
  return customInstallTask(packageManagerName, execPackageManager);
73
76
  }
77
+ if (customInstallTask === 'ask') {
78
+ const { runInstall } = await adapter.prompt({
79
+ type: 'confirm',
80
+ name: 'runInstall',
81
+ message: `Do you want to run ${packageManagerName} install now?`,
82
+ });
83
+ if (!runInstall) {
84
+ return false;
85
+ }
86
+ }
74
87
  return execPackageManager();
75
88
  }
@@ -39,7 +39,7 @@ export const asNamespace = (filepath, { lookups = defaultLookups }) => {
39
39
  // Sort lookups by length so biggest are removed first
40
40
  const nsLookups = [...lookups, '..']
41
41
  .map(found => slash(found))
42
- .sort((a, b) => a.split('/').length - b.split('/').length)
42
+ .toSorted((a, b) => a.split('/').length - b.split('/').length)
43
43
  .toReversed();
44
44
  // If `ns` contains a lookup dir in its path, remove it.
45
45
  for (const lookup of nsLookups) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "keywords": [
6
6
  "development",
@@ -16,7 +16,10 @@
16
16
  "app"
17
17
  ],
18
18
  "homepage": "http://yeoman.io",
19
- "repository": "yeoman/environment",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/yeoman/environment.git"
22
+ },
20
23
  "license": "BSD-2-Clause",
21
24
  "author": "Yeoman",
22
25
  "type": "module",
@@ -57,10 +60,10 @@
57
60
  },
58
61
  "dependencies": {
59
62
  "@yeoman/adapter": "^4.0.2",
60
- "@yeoman/conflicter": "^4.0.1",
61
- "@yeoman/namespace": "^1.0.1",
62
- "@yeoman/transform": "^2.1.0",
63
- "@yeoman/types": "^1.10.3",
63
+ "@yeoman/conflicter": "^4.1.0",
64
+ "@yeoman/namespace": "^2.1.0",
65
+ "@yeoman/transform": "^2.1.1",
66
+ "@yeoman/types": "^1.11.0",
64
67
  "arrify": "^3.0.0",
65
68
  "chalk": "^5.6.2",
66
69
  "commander": "^14.0.3",
@@ -72,7 +75,7 @@
72
75
  "locate-path": "^8.0.0",
73
76
  "lodash-es": "^4.18.1",
74
77
  "mem-fs": "^4.1.4",
75
- "mem-fs-editor": "^12.0.3",
78
+ "mem-fs-editor": "^12.0.4",
76
79
  "semver": "^7.7.4",
77
80
  "slash": "^5.1.0",
78
81
  "untildify": "^6.0.0",
@@ -84,19 +87,19 @@
84
87
  "@types/lodash-es": "^4.17.12",
85
88
  "@types/node": "^20.19.35",
86
89
  "@types/semver": "^7.7.1",
87
- "@yeoman/eslint": "1.0.0",
90
+ "@yeoman/eslint": "1.1.0",
88
91
  "c8": "^11.0.0",
89
- "eslint": "9.39.3",
92
+ "eslint": "10.2.1",
90
93
  "esmocha": "^5.0.0",
91
94
  "fs-extra": "^11.3.4",
92
95
  "jsdoc": "^4.0.5",
93
- "prettier": "3.8.1",
96
+ "prettier": "3.8.3",
94
97
  "prettier-plugin-packagejson": "^3.0.2",
95
98
  "rimraf": "^6.1.3",
96
- "sinon": "^21.1.0",
99
+ "sinon": "^21.1.2",
97
100
  "sinon-test": "^3.1.6",
98
101
  "strip-ansi": "^7.2.0",
99
- "typescript": "5.9.3",
102
+ "typescript": "6.0.3",
100
103
  "yeoman-assert": "^3.1.1",
101
104
  "yeoman-environment": "file:./",
102
105
  "yeoman-generator-2": "npm:yeoman-generator@^2.0.5",