From 0728fb7f1c8942fc6cd362428c7417e171852ace Mon Sep 17 00:00:00 2001 From: dwarakaprasad Date: Fri, 8 Mar 2024 23:55:26 -0500 Subject: [PATCH 1/9] add callback function support for generator scheduling depends on yeoman/yeoman-api#6 required by jhipster/generator-jhipster#25445 fixes jhipster/generator-jhipster#25444 --- src/environment-base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/environment-base.ts b/src/environment-base.ts index f92f9d22..245ec175 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -425,7 +425,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron const { schedule = true, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); - return this.queueGenerator(generatorInstance, { schedule }); + return this.queueGenerator(generatorInstance, { schedule: typeof schedule === 'function' ? schedule(generatorInstance) : schedule }); } /** From ae4929a44efef664edadef7b318e7cf79d7327c7 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 09:45:55 -0300 Subject: [PATCH 2/9] add backward compatibility --- src/environment-base.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/environment-base.ts b/src/environment-base.ts index 245ec175..79daa243 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -425,6 +425,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron const { schedule = true, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); + // @ts-ignore: keep type compatibility with old @yeoman/types return this.queueGenerator(generatorInstance, { schedule: typeof schedule === 'function' ? schedule(generatorInstance) : schedule }); } From 0e7d50377ca18e16f763f04a847ea2efcff164e6 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 09:50:09 -0300 Subject: [PATCH 3/9] Update src/environment-base.ts --- src/environment-base.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/environment-base.ts b/src/environment-base.ts index 79daa243..1154cfad 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -425,6 +425,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron const { schedule = true, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error // @ts-ignore: keep type compatibility with old @yeoman/types return this.queueGenerator(generatorInstance, { schedule: typeof schedule === 'function' ? schedule(generatorInstance) : schedule }); } From 702022fd469036f799e6f84e9e0f5abc982538a6 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 11:33:28 -0300 Subject: [PATCH 4/9] try to keep type compatible with old @yeoman/types --- src/environment-base.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/environment-base.ts b/src/environment-base.ts index 1154cfad..77f9eaad 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -422,12 +422,12 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron ): Promise; async composeWith(generator: string | GetGeneratorConstructor, ...args: any[]): Promise { const options = getComposeOptions(...args) as ComposeOptions; - const { schedule = true, ...instantiateOptions } = options; + const { schedule = true: passedSchedule, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error - // @ts-ignore: keep type compatibility with old @yeoman/types - return this.queueGenerator(generatorInstance, { schedule: typeof schedule === 'function' ? schedule(generatorInstance) : schedule }); + // Keep type compatibility with old @yeoman/types + const schedule: (G) => boolean = typeof schedule === 'function' ? schedule : () => schedule; + return this.queueGenerator(generatorInstance, { schedule: schedule(generatorInstance) }); } /** From c4864839a987152e79804a1b9250e5aa9e22b1d8 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 11:35:20 -0300 Subject: [PATCH 5/9] Update environment-base.ts --- src/environment-base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/environment-base.ts b/src/environment-base.ts index 77f9eaad..fc47fe96 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -422,7 +422,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron ): Promise; async composeWith(generator: string | GetGeneratorConstructor, ...args: any[]): Promise { const options = getComposeOptions(...args) as ComposeOptions; - const { schedule = true: passedSchedule, ...instantiateOptions } = options; + const { schedule: passedSchedule = true, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); // Keep type compatibility with old @yeoman/types From d60d4ee52340d2adb786994fc9263cb4dd3d9e03 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 11:36:04 -0300 Subject: [PATCH 6/9] Update environment-base.ts --- src/environment-base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/environment-base.ts b/src/environment-base.ts index fc47fe96..b1343027 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -426,7 +426,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron const generatorInstance = await this.create(generator, instantiateOptions); // Keep type compatibility with old @yeoman/types - const schedule: (G) => boolean = typeof schedule === 'function' ? schedule : () => schedule; + const schedule: (G) => boolean = typeof passedSchedule === 'function' ? passedSchedule : () => passedSchedule; return this.queueGenerator(generatorInstance, { schedule: schedule(generatorInstance) }); } From 64dc6daf465d898e8dc17271cb914e6eee060ea7 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 11:37:34 -0300 Subject: [PATCH 7/9] Update environment-base.ts --- src/environment-base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/environment-base.ts b/src/environment-base.ts index b1343027..ffa38dae 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -426,7 +426,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron const generatorInstance = await this.create(generator, instantiateOptions); // Keep type compatibility with old @yeoman/types - const schedule: (G) => boolean = typeof passedSchedule === 'function' ? passedSchedule : () => passedSchedule; + const schedule: (gen: G) => boolean = typeof passedSchedule === 'function' ? passedSchedule : () => passedSchedule; return this.queueGenerator(generatorInstance, { schedule: schedule(generatorInstance) }); } From d85d5fa387c0d2cf2434784b73dae6c2d2fdbd1f Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 11:41:16 -0300 Subject: [PATCH 8/9] Update environment-base.ts --- src/environment-base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/environment-base.ts b/src/environment-base.ts index ffa38dae..4466afdc 100644 --- a/src/environment-base.ts +++ b/src/environment-base.ts @@ -425,7 +425,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron const { schedule: passedSchedule = true, ...instantiateOptions } = options; const generatorInstance = await this.create(generator, instantiateOptions); - // Keep type compatibility with old @yeoman/types + // Convert to function to keep type compatibility with old @yeoman/types where schedule is boolean only const schedule: (gen: G) => boolean = typeof passedSchedule === 'function' ? passedSchedule : () => passedSchedule; return this.queueGenerator(generatorInstance, { schedule: schedule(generatorInstance) }); } From 3b29812d43112c3e1b7fb8779f260aff229d5a70 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 9 Mar 2024 13:43:05 -0300 Subject: [PATCH 9/9] add test --- test/environment.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/environment.js b/test/environment.js index a1bafc14..e7778214 100644 --- a/test/environment.js +++ b/test/environment.js @@ -272,6 +272,18 @@ for (const generatorVersion of allVersions) { } }); }); + describe('passing function schedule parameter', () => { + it('returning false should not schedule generator', async function () { + this.env.queueTask = sinon.spy(); + await this.env.composeWith('stub', { generatorArgs: [], schedule: () => false }); + if (isGreaterThan6(generatorVersion)) { + assert(this.env.queueTask.calledOnce); + assert(this.env.queueTask.getCall(0).firstArg !== 'environment:run'); + } else { + assert(this.env.queueTask.notCalled); + } + }); + }); it('should emit a compose event', function (done) { this.env.once('compose', (namespace, generator) => {