@@ -245,18 +245,10 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
245245 }
246246
247247 /**
248- * Get a single generator from the registered list of generators. The lookup is
249- * based on generator's namespace, "walking up" the namespaces until a matching
250- * is found. Eg. if an `angular:common` namespace is registered, and we try to
251- * get `angular:common:all` then we get `angular:common` as a fallback (unless
252- * an `angular:common:all` generator is registered).
253- *
254248 * @param namespaceOrPath
255- * @return the generator registered under the namespace
249+ * @return the generator meta registered under the namespace
256250 */
257- async get < C extends BaseGeneratorConstructor = BaseGeneratorConstructor > (
258- namespaceOrPath : string | YeomanNamespace ,
259- ) : Promise < C | undefined > {
251+ async findMeta ( namespaceOrPath : string | YeomanNamespace ) : Promise < GeneratorMeta | undefined > {
260252 // Stop the recursive search if nothing is left
261253 if ( ! namespaceOrPath ) {
262254 return ;
@@ -265,27 +257,41 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
265257 const parsed = toNamespace ( namespaceOrPath ) ;
266258 if ( typeof namespaceOrPath !== 'string' || parsed ) {
267259 const ns = parsed ! . namespace ;
268- const maybeGenerator = ( await this . store . get ( ns ) ) ?? this . store . get ( this . alias ( ns ) ) ;
269- return maybeGenerator as C ;
260+ return this . store . getMeta ( ns ) ?? this . store . getMeta ( this . alias ( ns ) ) ;
270261 }
271262
272- const maybeGenerator = ( await this . store . get ( namespaceOrPath ) ) ?? ( await this . store . get ( this . alias ( namespaceOrPath ) ) ) ;
273- if ( maybeGenerator ) {
274- return maybeGenerator as C ;
263+ const maybeMeta = this . store . getMeta ( namespaceOrPath ) ?? this . store . getMeta ( this . alias ( namespaceOrPath ) ) ;
264+ if ( maybeMeta ) {
265+ return maybeMeta ;
275266 }
276267
277268 try {
278269 const resolved = await resolveModulePath ( namespaceOrPath ) ;
279270 if ( resolved ) {
280- const namespace = this . namespace ( resolved ) ;
281- this . store . add ( { resolved, namespace } ) ;
282- return ( await this . store . get ( namespace ) ) as C ;
271+ return this . store . add ( { resolved, namespace : this . namespace ( resolved ) } ) ;
283272 }
284273 } catch { }
285274
286275 return undefined ;
287276 }
288277
278+ /**
279+ * Get a single generator from the registered list of generators. The lookup is
280+ * based on generator's namespace, "walking up" the namespaces until a matching
281+ * is found. Eg. if an `angular:common` namespace is registered, and we try to
282+ * get `angular:common:all` then we get `angular:common` as a fallback (unless
283+ * an `angular:common:all` generator is registered).
284+ *
285+ * @param namespaceOrPath
286+ * @return the generator registered under the namespace
287+ */
288+ async get < C extends BaseGeneratorConstructor = BaseGeneratorConstructor > (
289+ namespaceOrPath : string | YeomanNamespace ,
290+ ) : Promise < C | undefined > {
291+ const meta = await this . findMeta ( namespaceOrPath ) ;
292+ return meta ?. importGenerator ( ) as Promise < C > ;
293+ }
294+
289295 /**
290296 * Create is the Generator factory. It takes a namespace to lookup and optional
291297 * hash of options, that lets you define `arguments` and `options` to
@@ -351,11 +357,16 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
351357 }
352358
353359 if ( typeof namespaceOrPath === 'string' ) {
354- constructor = await this . get ( namespaceOrPath ) ;
360+ const meta = await this . findMeta ( namespaceOrPath ) ;
361+ constructor = await meta ?. importGenerator ( ) ;
355362 if ( namespace && ! constructor ) {
356363 // Await this.lookupLocalNamespaces(namespace);
357364 // constructor = await this.get(namespace);
358365 }
366+
367+ if ( constructor ) {
368+ ( constructor as any ) . _meta = meta ;
369+ }
359370 } else {
360371 constructor = namespaceOrPath ;
361372 }
@@ -376,14 +387,15 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
376387 ) : Promise < G > ;
377388 async instantiate < G extends BaseGenerator = BaseGenerator > ( constructor : GetGeneratorConstructor < G > , ...args : any [ ] ) : Promise < G > {
378389 const composeOptions = args . length > 0 ? ( getInstantiateOptions ( ...args ) as InstantiateOptions < G > ) : { } ;
379- const { namespace = UNKNOWN_NAMESPACE , resolved = UNKNOWN_RESOLVED } = constructor as any ;
390+ const { namespace = UNKNOWN_NAMESPACE , resolved = UNKNOWN_RESOLVED , _meta } = constructor as any ;
380391 const environmentOptions = { env : this , resolved, namespace } ;
381392 const generator = new constructor ( composeOptions . generatorArgs ?? [ ] , {
382393 ...this . sharedOptions ,
383394 ...composeOptions . generatorOptions ,
384395 ...environmentOptions ,
385396 } as unknown as GetGeneratorOptions < G > ) ;
386397
398+ ( generator as any ) . _meta = _meta ;
387399 ( generator as any ) . _environmentOptions = {
388400 ...this . options ,
389401 ...this . sharedOptions ,
@@ -689,7 +701,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
689701 * @param namespace
690702 */
691703 getGeneratorMeta ( namespace : string ) : GeneratorMeta | undefined {
692- const meta : GeneratorMeta = this . store . getMeta ( namespace ) ?? this . store . getMeta ( this . alias ( namespace ) ) ;
704+ const meta = this . store . getMeta ( namespace ) ?? this . store . getMeta ( this . alias ( namespace ) ) ;
693705 if ( ! meta ) {
694706 return ;
695707 }
0 commit comments