From f9c6c0e2fda6a59608492a06b0a088e921b74718 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 23 Sep 2024 00:25:04 -0300 Subject: [PATCH 1/6] generate-blueprint: run prettier-format and lint-fix in case of upgrades --- generators/generate-blueprint/generator.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/generators/generate-blueprint/generator.ts b/generators/generate-blueprint/generator.ts index 389123b2195c..7c98c64c5614 100644 --- a/generators/generate-blueprint/generator.ts +++ b/generators/generate-blueprint/generator.ts @@ -344,7 +344,7 @@ export default class extends BaseGenerator { get postInstall() { return this.asPostInstallTaskGroup({ - async addSnapshot() { + async addSnapshot({ control }) { const { [LOCAL_BLUEPRINT_OPTION]: localBlueprint } = this.jhipsterConfig; const { skipInstall, @@ -377,6 +377,21 @@ This is a new blueprint, executing '${chalk.yellow('npm run update-snapshot')}' } this.log.warn('Fail to generate snapshots'); } + + if (control.jhipsterOldVersion) { + // Apply prettier and eslint to fix non generated files on upgrade. + try { + await this.spawnCommand('npm', ['run', 'prettier-format']); + } catch { + // Ignore error + } + + try { + await this.spawnCommand('npm', ['run', 'lint-fix']); + } catch { + // Ignore error + } + } }, }); } From a4373f4cd8bafbead4368c9130001c9c3c6cd050 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sun, 22 Sep 2024 19:06:03 -0300 Subject: [PATCH 2/6] generate-generator: use `as const satisfies` --- .blueprint/generate-generator/templates/command.ts.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.blueprint/generate-generator/templates/command.ts.ejs b/.blueprint/generate-generator/templates/command.ts.ejs index 2dbdefa750df..b014bcbaa807 100644 --- a/.blueprint/generate-generator/templates/command.ts.ejs +++ b/.blueprint/generate-generator/templates/command.ts.ejs @@ -18,9 +18,9 @@ */ import type { JHipsterCommandDefinition } from '<%- generatorRelativePath %>base/api.js'; -const command: JHipsterCommandDefinition = { +const command = { configs: {}, import: [], -}; +} as const satisfies JHipsterCommandDefinition; export default command; From 401662af14c482f32e81751999d0bda284bc7d79 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sun, 22 Sep 2024 19:06:45 -0300 Subject: [PATCH 3/6] generate-blueprint: use `as const satisfies` --- generators/generate-blueprint/command.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/generate-blueprint/command.ts b/generators/generate-blueprint/command.ts index 4d6ae7721a0e..4973b0446df6 100644 --- a/generators/generate-blueprint/command.ts +++ b/generators/generate-blueprint/command.ts @@ -31,7 +31,7 @@ import { SUB_GENERATORS, } from './constants.js'; -const command: JHipsterCommandDefinition = { +const command = { configs: { recreatePackageLock: { description: 'Recreate package lock', @@ -106,6 +106,6 @@ const command: JHipsterCommandDefinition = { }, }, import: [GENERATOR_INIT], -}; +} as const satisfies JHipsterCommandDefinition; export default command; From 955ba29df8dc5ac620094f064ae5d19ba636c5ef Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sun, 22 Sep 2024 23:50:18 -0300 Subject: [PATCH 4/6] enable `@typescript-eslint/no-floating-promises` rule --- eslint.config.js | 1 + generators/angular/generator.ts | 4 ++-- generators/bootstrap/support/eslint-transform.ts | 4 ++-- generators/bootstrap/support/java-unused-imports-transform.ts | 4 ++-- generators/bootstrap/support/prettier-support.ts | 4 ++-- generators/common/generator.ts | 4 ++-- generators/docker-compose/generator.ts | 4 ++-- generators/java/generators/openapi-generator/generator.ts | 4 ++-- generators/react/generator.ts | 4 ++-- generators/spring-boot/cleanup.ts | 4 ++-- generators/spring-cloud/generators/gateway/generator.ts | 4 ++-- generators/vue/generator.ts | 4 ++-- 12 files changed, 23 insertions(+), 22 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 6d01d6c24ac2..906b9c489982 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -29,6 +29,7 @@ export default ts.config( }, rules: { '@typescript-eslint/consistent-type-imports': 'error', + '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/ban-ts-comment': ['off', { 'ts-nocheck': true }], '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/no-empty-function': 'off', diff --git a/generators/angular/generator.ts b/generators/angular/generator.ts index b3ea7497a819..5e8cd9047611 100644 --- a/generators/angular/generator.ts +++ b/generators/angular/generator.ts @@ -234,8 +234,8 @@ export default class AngularGenerator extends BaseApplicationGenerator { get writing() { return this.asWritingTaskGroup({ - cleanup({ control }) { - control.cleanupFiles({ + async cleanup({ control }) { + await control.cleanupFiles({ '8.6.1': ['.eslintrc.json', '.eslintignore'], }); }, diff --git a/generators/bootstrap/support/eslint-transform.ts b/generators/bootstrap/support/eslint-transform.ts index 7982f8930012..ed22891e1bb9 100644 --- a/generators/bootstrap/support/eslint-transform.ts +++ b/generators/bootstrap/support/eslint-transform.ts @@ -75,8 +75,8 @@ export const createESLintTransform = function ( this?.log?.warn?.(errorMessage); } }, - () => { - pool.destroy(); + async () => { + await pool.destroy(); }, ); }; diff --git a/generators/bootstrap/support/java-unused-imports-transform.ts b/generators/bootstrap/support/java-unused-imports-transform.ts index a3a240b0f7e3..b7c1352e34cf 100644 --- a/generators/bootstrap/support/java-unused-imports-transform.ts +++ b/generators/bootstrap/support/java-unused-imports-transform.ts @@ -44,8 +44,8 @@ export const createRemoveUnusedImportsTransform = function ( } } }, - () => { - pool.destroy(); + async () => { + await pool.destroy(); }, ); }; diff --git a/generators/bootstrap/support/prettier-support.ts b/generators/bootstrap/support/prettier-support.ts index 945c97c33e8a..3ff4947130bd 100644 --- a/generators/bootstrap/support/prettier-support.ts +++ b/generators/bootstrap/support/prettier-support.ts @@ -92,8 +92,8 @@ export const createPrettierTransform = async function ( this?.log?.warn?.(errorMessage); } }, - () => { - pool?.destroy(); + async () => { + await pool?.destroy(); }, ); }; diff --git a/generators/common/generator.ts b/generators/common/generator.ts index 32c10acbed31..6bda63fd4519 100644 --- a/generators/common/generator.ts +++ b/generators/common/generator.ts @@ -196,8 +196,8 @@ export default class CommonGenerator extends BaseApplicationGenerator { // Public API method used by the getter and also by Blueprints get writing() { return this.asWritingTaskGroup({ - cleanup({ application, control }) { - control.cleanupFiles({ + async cleanup({ application, control }) { + await control.cleanupFiles({ '7.1.1': [[!application.skipCommitHook, '.huskyrc']], '7.6.1': [[application.skipClient, 'npmw', 'npmw.cmd']], '8.0.0-rc.2': [[!application.skipCommitHook, '.lintstagedrc.js']], diff --git a/generators/docker-compose/generator.ts b/generators/docker-compose/generator.ts index 1d767c02ef2b..3d73977b185e 100644 --- a/generators/docker-compose/generator.ts +++ b/generators/docker-compose/generator.ts @@ -135,10 +135,10 @@ export default class DockerComposeGenerator extends BaseWorkspacesGenerator { get loadingWorkspaces() { return { - loadBaseDeployment({ deployment }) { + async loadBaseDeployment({ deployment }) { deployment.jwtSecretKey = this.jhipsterConfig.jwtSecretKey; - loadDockerDependenciesTask.call(this, { context: deployment }); + await loadDockerDependenciesTask.call(this, { context: deployment }); }, loadPlatformConfig({ deployment }) { this.loadDeploymentConfig({ deployment }); diff --git a/generators/java/generators/openapi-generator/generator.ts b/generators/java/generators/openapi-generator/generator.ts index b98a3d3c35d8..752d70a9d304 100644 --- a/generators/java/generators/openapi-generator/generator.ts +++ b/generators/java/generators/openapi-generator/generator.ts @@ -34,8 +34,8 @@ export default class OpenapiGeneratorGenerator extends BaseApplicationGenerator get writing() { return this.asWritingTaskGroup({ - cleanup({ application, control }) { - control.cleanupFiles({ + async cleanup({ application, control }) { + await control.cleanupFiles({ '8.6.1': [[application.buildToolGradle!, 'gradle/swagger.gradle']], }); }, diff --git a/generators/react/generator.ts b/generators/react/generator.ts index 24d041e48de8..ebf61fb5a8bc 100644 --- a/generators/react/generator.ts +++ b/generators/react/generator.ts @@ -155,8 +155,8 @@ export default class ReactGenerator extends BaseApplicationGenerator { get writing() { return this.asWritingTaskGroup({ - cleanup({ control }) { - control.cleanupFiles({ + async cleanup({ control }) { + await control.cleanupFiles({ '8.6.1': ['.eslintrc.json', '.eslintignore'], }); }, diff --git a/generators/spring-boot/cleanup.ts b/generators/spring-boot/cleanup.ts index 846cdcf7b078..9303515105f3 100644 --- a/generators/spring-boot/cleanup.ts +++ b/generators/spring-boot/cleanup.ts @@ -25,7 +25,7 @@ import cleanupOauth2 from './cleanup-oauth2.js'; * Removes server files that where generated in previous JHipster versions and therefore * need to be removed. */ -export default asWritingTask(function cleanupTask(this, taskParam) { +export default asWritingTask(async function cleanupTask(this, taskParam) { const { application, control } = taskParam; if (application.authenticationTypeOauth2) { cleanupOauth2.call(this, taskParam); @@ -209,7 +209,7 @@ export default asWritingTask(function cleanupTask(this, taskParam) { this.removeFile(`${application.javaPackageSrcDir}config/LocaleConfiguration.java`); } - control.cleanupFiles({ + await control.cleanupFiles({ '8.6.1': [[application.authenticationTypeOauth2!, `${application.javaPackageSrcDir}security/oauth2/JwtGrantedAuthorityConverter.java`]], }); }); diff --git a/generators/spring-cloud/generators/gateway/generator.ts b/generators/spring-cloud/generators/gateway/generator.ts index d95dbac395c1..285692171d29 100644 --- a/generators/spring-cloud/generators/gateway/generator.ts +++ b/generators/spring-cloud/generators/gateway/generator.ts @@ -70,8 +70,8 @@ export default class GatewayGenerator extends BaseApplicationGenerator { get writing() { return this.asWritingTaskGroup({ - cleanup({ control, application }) { - control.cleanupFiles({ + async cleanup({ control, application }) { + await control.cleanupFiles({ '8.6.1': [ [ application.reactive && (application as any).serviceDiscoveryAny, diff --git a/generators/vue/generator.ts b/generators/vue/generator.ts index e2d65daa2091..8e174c41bdf0 100644 --- a/generators/vue/generator.ts +++ b/generators/vue/generator.ts @@ -145,8 +145,8 @@ export default class VueGenerator extends BaseApplicationGenerator { get writing() { return this.asWritingTaskGroup({ - cleanup({ control }) { - control.cleanupFiles({ + async cleanup({ control }) { + await control.cleanupFiles({ '8.6.1': ['.eslintrc.json', '.eslintignore'], }); }, From 8bbf27da3f37346fdb0011b936a2dc3d8c07eb1d Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 23 Sep 2024 00:15:21 -0300 Subject: [PATCH 5/6] generate-blueprint: store current jhipsterVersion --- generators/base-core/generator.ts | 6 +++++- generators/generate-blueprint/generator.ts | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index b6e8226729b2..f44adcd8fb83 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -196,7 +196,7 @@ export default class CoreGenerator extends YeomanGenerator Date: Mon, 23 Sep 2024 11:58:05 -0300 Subject: [PATCH 6/6] apply javascript:bootstrap command types --- generators/javascript/generators/bootstrap/command.ts | 4 ++-- generators/javascript/types.d.ts | 8 ++++++-- lib/types/application/options.d.ts | 1 + lib/types/application/yo-rc.d.ts | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/generators/javascript/generators/bootstrap/command.ts b/generators/javascript/generators/bootstrap/command.ts index 28de8ab124fc..cfdbedb71364 100644 --- a/generators/javascript/generators/bootstrap/command.ts +++ b/generators/javascript/generators/bootstrap/command.ts @@ -18,7 +18,7 @@ */ import type { JHipsterCommandDefinition } from '../../../../lib/command/index.js'; -const command: JHipsterCommandDefinition = { +const command = { configs: { packageJsonNodeEngine: { cli: { @@ -39,6 +39,6 @@ const command: JHipsterCommandDefinition = { }, }, import: [], -}; +} as const satisfies JHipsterCommandDefinition; export default command; diff --git a/generators/javascript/types.d.ts b/generators/javascript/types.d.ts index ddddcd46d69f..190c9ca53965 100644 --- a/generators/javascript/types.d.ts +++ b/generators/javascript/types.d.ts @@ -1,3 +1,8 @@ +import type { ExportApplicationPropertiesFromCommand } from '../../lib/command/types.js'; +import type JavascriptBootstrapCommand from './generators/bootstrap/command.ts'; + +type JavascriptBootstrapProperties = ExportApplicationPropertiesFromCommand; + export type JavaScriptSourceType = { mergePrettierConfig?: (config: Record) => void; addPrettierIgnore?: (newContent: string) => void; @@ -6,9 +11,8 @@ export type JavaScriptSourceType = { addEslintConfig?: (opts: { import?: string | string[]; config?: string | string[] }) => void; }; -export type JavaScriptApplication = { +export type JavaScriptApplication = JavascriptBootstrapProperties & { packageJsonNodeEngine?: boolean | string; - packageJsonType?: string; eslintConfigFile?: string; addPrettierExtensions?: (extensions: string[]) => void; diff --git a/lib/types/application/options.d.ts b/lib/types/application/options.d.ts index f65aeab19a61..a089c1ed9a1d 100644 --- a/lib/types/application/options.d.ts +++ b/lib/types/application/options.d.ts @@ -9,6 +9,7 @@ export type ApplicationOptions = Simplify< ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & + ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & diff --git a/lib/types/application/yo-rc.d.ts b/lib/types/application/yo-rc.d.ts index 9f67e2ee4604..909ba4e572e4 100644 --- a/lib/types/application/yo-rc.d.ts +++ b/lib/types/application/yo-rc.d.ts @@ -18,6 +18,7 @@ export type ApplicationConfiguration = Simplify< ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & + ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand &