@@ -9,7 +9,7 @@ import type {
99 BaseEnvironment ,
1010 BaseEnvironmentOptions ,
1111 BaseGenerator ,
12- BaseGeneratorConstructor ,
12+ BaseGeneratorConstructorMeta ,
1313 BaseGeneratorMeta ,
1414 ComposeOptions ,
1515 GeneratorMeta ,
@@ -293,11 +293,12 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
293293 * @param namespaceOrPath
294294 * @return the generator registered under the namespace
295295 */
296- async get < C extends BaseGeneratorConstructor = BaseGeneratorConstructor > (
296+ get < G extends BaseGenerator = BaseGenerator > (
297297 namespaceOrPath : string | YeomanNamespace ,
298- ) : Promise < C | undefined > {
299- const meta = await this . findMeta ( namespaceOrPath ) ;
300- return meta ?. importGenerator ( ) as Promise < C > ;
298+ ) :
299+ | Promise < ( GetGeneratorConstructor < G > & BaseGeneratorConstructorMeta ) | undefined >
300+ | ( ( GetGeneratorConstructor < G > & BaseGeneratorConstructorMeta ) | undefined ) {
301+ return this . findMeta ( namespaceOrPath ) ?. importGenerator ( ) ;
301302 }
302303
303304 /**
@@ -312,22 +313,21 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
312313 * @return The instantiated generator
313314 */
314315 async create < G extends BaseGenerator = BaseGenerator > (
315- namespaceOrPath : string | GetGeneratorConstructor < G > ,
316+ namespaceOrPath : string | ( GetGeneratorConstructor < G > & Partial < BaseGeneratorConstructorMeta > ) ,
316317 instantiateOptions ?: InstantiateOptions < G > ,
317318 ) : Promise < G > ;
318319 create < G extends BaseGenerator = BaseGenerator > (
319- namespaceOrPath : string | GetGeneratorConstructor < G > ,
320+ namespaceOrPath : string | ( GetGeneratorConstructor < G > & Partial < BaseGeneratorConstructorMeta > ) ,
320321 ...arguments_ : any [ ]
321322 ) : Promise < G > | G {
322- let constructor ;
323323 const namespace = typeof namespaceOrPath === 'string' ? toNamespace ( namespaceOrPath ) : undefined ;
324324
325- const checkGenerator = ( Generator : any ) => {
325+ const checkGenerator = < const T extends Partial < BaseGeneratorConstructorMeta > > ( Generator ?: T ) : T => {
326326 const generatorNamespace = Generator ?. namespace ;
327- if ( namespace && generatorNamespace !== namespace . namespace && generatorNamespace !== UNKNOWN_NAMESPACE ) {
327+ if ( namespace && generatorNamespace && generatorNamespace !== namespace . namespace && generatorNamespace !== UNKNOWN_NAMESPACE ) {
328328 // Update namespace object in case of aliased namespace.
329329 try {
330- namespace . namespace = Generator . namespace ;
330+ namespace . namespace = generatorNamespace ;
331331 } catch {
332332 // Invalid namespace can be aliased to a valid one.
333333 }
@@ -350,32 +350,23 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
350350 return Generator ;
351351 } ;
352352
353- if ( typeof namespaceOrPath !== 'string' ) {
354- return this . instantiate ( checkGenerator ( namespaceOrPath ) , ...arguments_ ) ;
355- }
356-
357353 if ( typeof namespaceOrPath === 'string' ) {
358354 const meta = this . findMeta ( namespaceOrPath ) ;
359- constructor = meta ?. importGenerator ( ) ;
355+ const constructor = meta ?. importGenerator ( ) ;
360356 if ( namespace && ! constructor ) {
361357 // Await this.lookupLocalNamespaces(namespace);
362358 // constructor = await this.get(namespace);
363359 }
364360
365- if ( constructor ) {
366- if ( ( constructor as any ) . then ) {
367- return constructor . then ( g => {
368- ( g as any ) . _meta = meta ;
369- return this . instantiate ( checkGenerator ( g ) , ...arguments_ ) ;
370- } ) ;
371- }
372- ( constructor as any ) . _meta = meta ;
361+ if ( constructor && 'then' in constructor ) {
362+ return constructor . then ( g => {
363+ return this . instantiate ( checkGenerator ( g ) , ...arguments_ ) ;
364+ } ) ;
373365 }
366+ return this . instantiate ( checkGenerator ( constructor ) , ...arguments_ ) ;
374367 } else {
375- constructor = namespaceOrPath ;
368+ return this . instantiate ( checkGenerator ( namespaceOrPath ) , ... arguments_ ) ;
376369 }
377-
378- return this . instantiate ( checkGenerator ( constructor ) , ...arguments_ ) ;
379370 }
380371
381372 /**
@@ -389,9 +380,12 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
389380 generator : GetGeneratorConstructor < G > ,
390381 instantiateOptions ?: InstantiateOptions < G > ,
391382 ) : Promise < G > ;
392- instantiate < G extends BaseGenerator = BaseGenerator > ( constructor : GetGeneratorConstructor < G > , ...arguments_ : any [ ] ) : Promise < G > | G {
383+ instantiate < G extends BaseGenerator = BaseGenerator > (
384+ constructor : GetGeneratorConstructor < G > & Partial < BaseGeneratorConstructorMeta > ,
385+ ...arguments_ : any [ ]
386+ ) : Promise < G > | G {
393387 const composeOptions = arguments_ . length > 0 ? ( getInstantiateOptions ( ...arguments_ ) as InstantiateOptions < G > ) : { } ;
394- const { namespace = UNKNOWN_NAMESPACE , resolved = UNKNOWN_RESOLVED , _meta } = constructor as any ;
388+ const { namespace = UNKNOWN_NAMESPACE , resolved = UNKNOWN_RESOLVED , _meta } = constructor ;
395389 const environmentOptions = { env : this , resolved, namespace } ;
396390 const generator = new constructor ( composeOptions . generatorArgs ?? [ ] , {
397391 ...this . sharedOptions ,
@@ -836,7 +830,8 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
836830 return new Promise < void > ( ( resolve , reject ) => {
837831 Object . assign ( this . options , removePropertiesWithNullishValues ( pick ( options , [ 'skipInstall' , 'nodePackageManager' ] ) ) ) ;
838832 this . logCwd = options . logCwd ?? this . logCwd ;
839- this . conflicterOptions = pick ( defaults ( { } , this . options , options ) , [ 'force' , 'bail' , 'ignoreWhitespace' , 'dryRun' , 'skipYoResolve' ] ) ;
833+ const conflicterOptionsProperties = [ 'force' , 'bail' , 'ignoreWhitespace' , 'dryRun' , 'skipYoResolve' ] ;
834+ this . conflicterOptions = defaults ( { } , pick ( this . options , conflicterOptionsProperties ) , pick ( options , conflicterOptionsProperties ) ) ;
840835 this . conflicterOptions . cwd = this . logCwd ;
841836
842837 this . queueCommit ( ) ;
0 commit comments