1
1
import EventEmitter from 'node:events' ;
2
2
import path , { isAbsolute } from 'node:path' ;
3
3
import { pathToFileURL } from 'node:url' ;
4
- import { toNamespace } from '@yeoman/namespace' ;
4
+ import { requireNamespace , toNamespace } from '@yeoman/namespace' ;
5
5
import { defaults , pick , uniq } from 'lodash-es' ;
6
6
import createdLogger from 'debug' ;
7
7
import { findPackagesIn , getNpmPaths , moduleLookupSync } from './module-lookup.js' ;
@@ -31,32 +31,22 @@ function splitArgsFromString(argsString) {
31
31
return result ;
32
32
}
33
33
34
- /**
35
- * @classdesc `Environment` object is responsible of handling the lifecyle and bootstrap
36
- * of generators in a specific environment (your app).
37
- *
38
- * It provides a high-level API to create and run generators, as well as further
39
- * tuning where and how a generator is resolved.
40
- *
41
- * An environment is created using a list of `arguments` and a Hash of
42
- * `options`. Usually, this is the list of arguments you get back from your CLI
43
- * options parser.
44
- *
45
- * An optional adapter can be passed to provide interaction in non-CLI environment
46
- * (e.g. IDE plugins), otherwise a `QueuedAdapter` is instantiated by default
47
- *
48
- */
49
- export default class Environment extends EventEmitter {
50
- /**
51
- * Convert a generators namespace to its name
52
- *
53
- * @param {String } namespace
54
- * @return {String }
55
- */
56
- static namespaceToName ( namespace ) {
57
- return namespace . split ( ':' ) [ 0 ] ;
58
- }
59
-
34
+ /**
35
+ * @classdesc `Environment` object is responsible of handling the lifecyle and bootstrap
36
+ * of generators in a specific environment (your app).
37
+ *
38
+ * It provides a high-level API to create and run generators, as well as further
39
+ * tuning where and how a generator is resolved.
40
+ *
41
+ * An environment is created using a list of `arguments` and a Hash of
42
+ * `options`. Usually, this is the list of arguments you get back from your CLI
43
+ * options parser.
44
+ *
45
+ * An optional adapter can be passed to provide interaction in non-CLI environment
46
+ * (e.g. IDE plugins), otherwise a `QueuedAdapter` is instantiated by default
47
+ *
48
+ */
49
+ export default class Environment extends EventEmitter {
60
50
/**
61
51
* Lookup for a specific generator.
62
52
*
@@ -76,9 +66,7 @@ function splitArgsFromString(argsString) {
76
66
: { singleResult : ! ( options && options . multiple ) , ...options } ;
77
67
78
68
options . filePatterns = options . filePatterns || defaultLookups . map ( prefix => path . join ( prefix , '*/index.{js,ts}' ) ) ;
79
-
80
- const name = Environment . namespaceToName ( namespace ) ;
81
- options . packagePatterns = options . packagePatterns || toNamespace ( name ) ?. generatorHint ;
69
+ options . packagePatterns = options . packagePatterns || toNamespace ( namespace ) ?. generatorHint ;
82
70
83
71
options . npmPaths = options . npmPaths || getNpmPaths ( { localOnly : options . localOnly , filePaths : false } ) . reverse ( ) ;
84
72
options . packagePatterns = options . packagePatterns || 'generator-*' ;
@@ -88,7 +76,8 @@ function splitArgsFromString(argsString) {
88
76
moduleLookupSync ( options , ( { files, packagePath } ) => {
89
77
for ( const filename of files ) {
90
78
const fileNS = asNamespace ( filename , { lookups : defaultLookups } ) ;
91
- if ( namespace === fileNS || ( options . packagePath && namespace === Environment . namespaceToName ( fileNS ) ) ) {
79
+ const ns = toNamespace ( fileNS ) ;
80
+ if ( namespace === fileNS || ( options . packagePath && namespace === ns ?. packageNamespace ) ) {
92
81
// Version 2.6.0 returned pattern instead of modulePath for options.packagePath
93
82
const returnPath = options . packagePath ? packagePath : options . generatorPath ? path . posix . join ( filename , '../../' ) : filename ;
94
83
if ( options . singleResult ) {
@@ -213,7 +202,7 @@ function splitArgsFromString(argsString) {
213
202
* @return {Array }
214
203
*/
215
204
getGeneratorNames ( ) {
216
- return uniq ( Object . keys ( this . getGeneratorsMeta ( ) ) . map ( namespace => Environment . namespaceToName ( namespace ) ) ) ;
205
+ return uniq ( Object . keys ( this . getGeneratorsMeta ( ) ) . map ( namespace => toNamespace ( namespace ) ?. packageNamespace ) ) ;
217
206
}
218
207
219
208
/**
@@ -241,7 +230,9 @@ function splitArgsFromString(argsString) {
241
230
* @return {Array } - array of paths.
242
231
*/
243
232
getPackagePaths ( namespace ) {
244
- return this . store . getPackagesPaths ( ) [ namespace ] || this . store . getPackagesPaths ( ) [ Environment . namespaceToName ( this . alias ( namespace ) ) ] ;
233
+ return (
234
+ this . store . getPackagesPaths ( ) [ namespace ] || this . store . getPackagesPaths ( ) [ requireNamespace ( this . alias ( namespace ) ) . packageNamespace ]
235
+ ) ;
245
236
}
246
237
247
238
/**
0 commit comments