diff --git a/generators/angular/__snapshots__/generator.spec.ts.snap b/generators/angular/__snapshots__/generator.spec.ts.snap index c2a21060cea3..0e9253e67b07 100644 --- a/generators/angular/__snapshots__/generator.spec.ts.snap +++ b/generators/angular/__snapshots__/generator.spec.ts.snap @@ -35,7 +35,7 @@ exports[`generator - angular gateway-jwt-skipUserManagement(true)-withAdminUi(fa "clientRoot/package.json": { "stateCleared": "modified", }, - "clientRoot/proxy.config.mjs": { + "clientRoot/proxy.config.js": { "stateCleared": "modified", }, "clientRoot/src/404.html": { @@ -763,7 +763,7 @@ exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDepend "clientRoot/package.json": { "stateCleared": "modified", }, - "clientRoot/proxy.config.mjs": { + "clientRoot/proxy.config.js": { "stateCleared": "modified", }, "clientRoot/src/404.html": { @@ -3176,7 +3176,7 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi( "package.json": { "stateCleared": "modified", }, - "proxy.config.mjs": { + "proxy.config.js": { "stateCleared": "modified", }, "src/main/webapp/404.html": { @@ -4298,7 +4298,7 @@ exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDepe "package.json": { "stateCleared": "modified", }, - "proxy.config.mjs": { + "proxy.config.js": { "stateCleared": "modified", }, "src/main/webapp/404.html": { @@ -4993,7 +4993,7 @@ exports[`generator - angular monolith-session-skipUserManagement(true)-withAdmin "package.json": { "stateCleared": "modified", }, - "proxy.config.mjs": { + "proxy.config.js": { "stateCleared": "modified", }, "src/main/webapp/404.html": { diff --git a/generators/angular/files-angular.ts b/generators/angular/files-angular.ts index 111a7c821d65..2873746818b8 100644 --- a/generators/angular/files-angular.ts +++ b/generators/angular/files-angular.ts @@ -61,7 +61,7 @@ export const files = asWriteFilesSection({ condition: ctx => ctx.clientBundlerEsbuild, templates: [ { sourceFile: 'angular.json.esbuild', destinationFile: 'angular.json' }, - 'proxy.config.mjs', + 'proxy.config.js', 'build-plugins/define-esbuild.ts', ], }), diff --git a/generators/angular/resources/package.json b/generators/angular/resources/package.json index 3bfc3ff9a5a0..9ed9ba37bad2 100644 --- a/generators/angular/resources/package.json +++ b/generators/angular/resources/package.json @@ -1,4 +1,5 @@ { + "type": "module", "dependencies": { "@angular/common": "20.3.0", "@fortawesome/angular-fontawesome": "3.0.0", diff --git a/generators/angular/templates/angular.json.esbuild.ejs b/generators/angular/templates/angular.json.esbuild.ejs index fff3e050ea95..603dfec160bf 100644 --- a/generators/angular/templates/angular.json.esbuild.ejs +++ b/generators/angular/templates/angular.json.esbuild.ejs @@ -126,7 +126,7 @@ "options": { "buildTarget": "<%= dasherizedBaseName %>:build:development", "open": true, - "proxyConfig": "proxy.config.mjs", + "proxyConfig": "proxy.config.js", "port": <%= devServerPort %> }, "configurations": { diff --git a/generators/angular/templates/jest.conf.js.ejs b/generators/angular/templates/jest.conf.js.ejs index 00cc28b83065..2bd1f2a2f2e7 100644 --- a/generators/angular/templates/jest.conf.js.ejs +++ b/generators/angular/templates/jest.conf.js.ejs @@ -16,13 +16,18 @@ See the License for the specific language governing permissions and limitations under the License. -%> -const { pathsToModuleNameMapper } = require('ts-jest'); +import { pathsToModuleNameMapper } from 'ts-jest'; +import { createRequire } from 'module'; + +const require = createRequire(import.meta.url); +const tsconfig = require('./tsconfig.json'); const { compilerOptions: { paths = {}, baseUrl = './' }, -} = require('./tsconfig.json'); +} = tsconfig; + -module.exports = { +export default { transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$|dayjs/esm<% if (applicationTypeGateway && microfrontend) { %>|@angular-architects/module-federation-runtime<% } %>)'], resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js', globals: { diff --git a/generators/angular/templates/package.json.ejs b/generators/angular/templates/package.json.ejs index a32d4f0916f8..731df04713c5 100644 --- a/generators/angular/templates/package.json.ejs +++ b/generators/angular/templates/package.json.ejs @@ -21,6 +21,7 @@ "name": "<%= dasherizedBaseName %>", "version": "0.0.1-SNAPSHOT", "description": "<%= projectDescription %>", + "type": "module", "private": true, "license": "UNLICENSED", "cacheDirectories": [ diff --git a/generators/angular/templates/proxy.config.mjs.ejs b/generators/angular/templates/proxy.config.js.ejs similarity index 100% rename from generators/angular/templates/proxy.config.mjs.ejs rename to generators/angular/templates/proxy.config.js.ejs diff --git a/generators/angular/templates/webpack/environment.js.ejs b/generators/angular/templates/webpack/environment.js.ejs index 953d480f8a6e..02cedbd8e080 100644 --- a/generators/angular/templates/webpack/environment.js.ejs +++ b/generators/angular/templates/webpack/environment.js.ejs @@ -1,4 +1,4 @@ -module.exports = { +export default { I18N_HASH: 'generated_hash', SERVER_API_URL: '', __VERSION__: process.env.APP_VERSION || 'DEV', diff --git a/generators/angular/templates/webpack/proxy.conf.js.ejs b/generators/angular/templates/webpack/proxy.conf.js.ejs index ab8536cd2955..09a35985523c 100644 --- a/generators/angular/templates/webpack/proxy.conf.js.ejs +++ b/generators/angular/templates/webpack/proxy.conf.js.ejs @@ -47,4 +47,4 @@ function setupProxy({ tls }) { ]; } -module.exports = setupProxy; +export default setupProxy; \ No newline at end of file diff --git a/generators/angular/templates/webpack/webpack.custom.js.ejs b/generators/angular/templates/webpack/webpack.custom.js.ejs index cb169312bf21..aa05bfe9c160 100644 --- a/generators/angular/templates/webpack/webpack.custom.js.ejs +++ b/generators/angular/templates/webpack/webpack.custom.js.ejs @@ -16,22 +16,27 @@ See the License for the specific language governing permissions and limitations under the License. -%> -const webpack = require('webpack'); -const { merge } = require('webpack-merge'); -const path = require('path'); +import webpack from 'webpack'; +import { merge } from 'webpack-merge'; +import path, { dirname } from 'path'; +import { fileURLToPath } from 'url'; <%_ if (enableTranslation) { _%> -const { hashElement } = require('folder-hash'); -const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin'); +import { hashElement } from 'folder-hash'; +import MergeJsonWebpackPlugin from 'merge-jsons-webpack-plugin'; <%_ } _%> -const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); +import BrowserSyncPlugin from 'browser-sync-webpack-plugin'; +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; +import CopyWebpackPlugin from 'copy-webpack-plugin'; +import environment from './environment.js'; +import proxyConfig from './proxy.conf.js'; const WebpackNotifierPlugin = require('webpack-notifier'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const environment = require('./environment'); -const proxyConfig = require('./proxy.conf'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); -module.exports = async (config, options, targetOptions) => { +export default async (config, options, targetOptions) => { <%_ if (enableTranslation) { _%> const languagesHash = await hashElement(path.resolve(__dirname, '<%= this.relativeDir(clientRootDir + 'webpack/', clientSrcDir) %>i18n'), { algo: 'md5', diff --git a/generators/angular/templates/webpack/webpack.microfrontend.js.ejs b/generators/angular/templates/webpack/webpack.microfrontend.js.ejs index 4f4ab08f21ae..5229a4304d8e 100644 --- a/generators/angular/templates/webpack/webpack.microfrontend.js.ejs +++ b/generators/angular/templates/webpack/webpack.microfrontend.js.ejs @@ -16,8 +16,8 @@ See the License for the specific language governing permissions and limitations under the License. -%> -const { withModuleFederationPlugin } = require('@angular-architects/module-federation/webpack'); -const packageJson = require('../package.json'); +import { withModuleFederationPlugin } from '@angular-architects/module-federation/webpack'; +import packageJson from '../package.json' assert { type: 'json' }; // Microfrontend api, should match across gateway and microservices. const apiVersion = '0.0.1'; @@ -39,7 +39,7 @@ sharedDependencies = { }; // eslint-disable-next-line no-unused-vars -module.exports = (config, options, targetOptions) => { +export default (config, options, targetOptions) => { return withModuleFederationPlugin({ name: '<%= lowercaseBaseName %>', <%_ if (applicationTypeMicroservice) { _%> diff --git a/generators/generate-blueprint/__snapshots__/generator.spec.ts.snap b/generators/generate-blueprint/__snapshots__/generator.spec.ts.snap index dea89ce49208..fb87bf48c00a 100644 --- a/generators/generate-blueprint/__snapshots__/generator.spec.ts.snap +++ b/generators/generate-blueprint/__snapshots__/generator.spec.ts.snap @@ -2,16 +2,16 @@ exports[`generator - generate-blueprint with all option should match snapshot 1`] = ` { - ".blueprint/cli/commands.mjs": { + ".blueprint/cli/commands.js": { "stateCleared": "modified", }, - ".blueprint/generate-sample/command.mjs": { + ".blueprint/generate-sample/command.js": { "stateCleared": "modified", }, - ".blueprint/generate-sample/generator.mjs": { + ".blueprint/generate-sample/generator.js": { "stateCleared": "modified", }, - ".blueprint/generate-sample/index.mjs": { + ".blueprint/generate-sample/index.js": { "stateCleared": "modified", }, ".blueprint/generate-sample/templates/samples/sample.jdl": { @@ -26,10 +26,10 @@ exports[`generator - generate-blueprint with all option should match snapshot 1` "README.md": { "stateCleared": "modified", }, - "cli/cli-customizations.cjs": { + "cli/cli-customizations.js": { "stateCleared": "modified", }, - "cli/cli.cjs": { + "cli/cli.js": { "stateCleared": "modified", }, "generators/angular/command.js": { @@ -1576,16 +1576,16 @@ exports[`generator - generate-blueprint with all option should match snapshot 1` exports[`generator - generate-blueprint with default config should write files and match snapshot 1`] = ` { - ".blueprint/cli/commands.mjs": { + ".blueprint/cli/commands.js": { "stateCleared": "modified", }, - ".blueprint/generate-sample/command.mjs": { + ".blueprint/generate-sample/command.js": { "stateCleared": "modified", }, - ".blueprint/generate-sample/generator.mjs": { + ".blueprint/generate-sample/generator.js": { "stateCleared": "modified", }, - ".blueprint/generate-sample/index.mjs": { + ".blueprint/generate-sample/index.js": { "stateCleared": "modified", }, ".blueprint/generate-sample/templates/samples/sample.jdl": { @@ -1600,10 +1600,10 @@ exports[`generator - generate-blueprint with default config should write files a "README.md": { "stateCleared": "modified", }, - "cli/cli-customizations.cjs": { + "cli/cli-customizations.js": { "stateCleared": "modified", }, - "cli/cli.cjs": { + "cli/cli.js": { "stateCleared": "modified", }, "package.json": { diff --git a/generators/generate-blueprint/files.ts b/generators/generate-blueprint/files.ts index 9c2bf7b87e22..ec848241d327 100644 --- a/generators/generate-blueprint/files.ts +++ b/generators/generate-blueprint/files.ts @@ -34,22 +34,22 @@ export const files = asWriteFilesSection({ 'tsconfig.json', 'vitest.config.ts', 'vitest.test-setup.ts', - '.blueprint/cli/commands.mjs', - '.blueprint/generate-sample/command.mjs', - '.blueprint/generate-sample/generator.mjs', - '.blueprint/generate-sample/index.mjs', + '.blueprint/cli/commands.js', + '.blueprint/generate-sample/command.js', + '.blueprint/generate-sample/generator.js', + '.blueprint/generate-sample/index.js', // Always write cli for devBlueprint usage - 'cli/cli.cjs', - { sourceFile: 'cli/cli-customizations.cjs', override: false }, + 'cli/cli.js', + { sourceFile: 'cli/cli-customizations.js', override: false }, ], }, { condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && ctx.githubWorkflows, templates: [ - '.blueprint/github-build-matrix/command.mjs', - '.blueprint/github-build-matrix/generator.mjs', - '.blueprint/github-build-matrix/generator.spec.mjs', - '.blueprint/github-build-matrix/index.mjs', + '.blueprint/github-build-matrix/command.js', + '.blueprint/github-build-matrix/generator.js', + '.blueprint/github-build-matrix/generator.spec.js', + '.blueprint/github-build-matrix/index.js', ], }, { @@ -62,7 +62,7 @@ export const files = asWriteFilesSection({ }, { condition: ctx => ctx.commands.length > 0, - templates: ['cli/commands.cjs'], + templates: ['cli/commands.js'], }, ], }); @@ -73,20 +73,20 @@ export const generatorFiles = asWriteFilesSection({ path: 'generators/generator', to: ctx => `${ctx.application.blueprintsPath}${ctx.generator.replaceAll(':', '/generators/')}`, templates: [ - { sourceFile: 'index.mjs', destinationFile: ctx => `index.${ctx.blueprintMjsExtension}` }, + { sourceFile: 'index.js', destinationFile: ctx => `index.${ctx.blueprintMjsExtension}` }, { - sourceFile: 'command.mjs', + sourceFile: 'command.js', destinationFile: ctx => `command.${ctx.blueprintMjsExtension}`, override: data => !data.ignoreExistingGenerators, }, { - sourceFile: 'generator.mjs.jhi', + sourceFile: 'generator.js.jhi', destinationFile: ctx => `generator.${ctx.blueprintMjsExtension}.jhi`, override: data => !data.ignoreExistingGenerators, }, { condition: data => !data.generator.startsWith('entity') && !data.application[LOCAL_BLUEPRINT_OPTION], - sourceFile: 'generator.spec.mjs', + sourceFile: 'generator.spec.js', destinationFile: data => `generator.spec.${data.blueprintMjsExtension}`, override: data => !data.ignoreExistingGenerators, }, diff --git a/generators/generate-blueprint/templates/.blueprint/cli/commands.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/cli/commands.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/cli/commands.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/cli/commands.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/generate-sample/command.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/generate-sample/command.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/generate-sample/command.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/generate-sample/command.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/generate-sample/generator.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/generate-sample/index.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/generate-sample/index.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/generate-sample/index.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/generate-sample/index.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/github-build-matrix/command.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/github-build-matrix/command.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/github-build-matrix/command.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/github-build-matrix/command.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.spec.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.spec.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.spec.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/github-build-matrix/generator.spec.js.ejs diff --git a/generators/generate-blueprint/templates/.blueprint/github-build-matrix/index.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/github-build-matrix/index.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/.blueprint/github-build-matrix/index.mjs.ejs rename to generators/generate-blueprint/templates/.blueprint/github-build-matrix/index.js.ejs diff --git a/generators/generate-blueprint/templates/cli/cli-customizations.cjs.ejs b/generators/generate-blueprint/templates/cli/cli-customizations.js.ejs similarity index 73% rename from generators/generate-blueprint/templates/cli/cli-customizations.cjs.ejs rename to generators/generate-blueprint/templates/cli/cli-customizations.js.ejs index 20a8a77ad8b9..6db49670e0d9 100644 --- a/generators/generate-blueprint/templates/cli/cli-customizations.cjs.ejs +++ b/generators/generate-blueprint/templates/cli/cli-customizations.js.ejs @@ -1,2 +1,2 @@ // This file will not be overwritten by generate-blueprint -module.exports = {}; +export default {}; diff --git a/generators/generate-blueprint/templates/cli/cli.cjs.ejs b/generators/generate-blueprint/templates/cli/cli.js.ejs similarity index 81% rename from generators/generate-blueprint/templates/cli/cli.cjs.ejs rename to generators/generate-blueprint/templates/cli/cli.js.ejs index 9f06eee6e866..264f1401422b 100755 --- a/generators/generate-blueprint/templates/cli/cli.cjs.ejs +++ b/generators/generate-blueprint/templates/cli/cli.js.ejs @@ -1,8 +1,15 @@ #!/usr/bin/env node -const { dirname, basename, join } = require('path'); +import { dirname, basename, join } from 'path'; +import { fileURLToPath } from 'url'; +import { createRequire } from 'module'; + +const require = createRequire(import.meta.url); const { version, bin } = require('../package.json'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + // Get package name to use as namespace. // Allows blueprints to be aliased. const packagePath = dirname(__dirname); diff --git a/generators/generate-blueprint/templates/cli/commands.cjs.ejs b/generators/generate-blueprint/templates/cli/commands.js.ejs similarity index 97% rename from generators/generate-blueprint/templates/cli/commands.cjs.ejs rename to generators/generate-blueprint/templates/cli/commands.js.ejs index 6d3cd374debf..66b6eb5ea2fb 100644 --- a/generators/generate-blueprint/templates/cli/commands.cjs.ejs +++ b/generators/generate-blueprint/templates/cli/commands.js.ejs @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. -%> -module.exports = { +export default { <% for (const command of commands) { %> '<%= command %>': { desc: 'Run <%= command %> sub-generator (<%= baseName %> blueprint)', diff --git a/generators/generate-blueprint/templates/generators/generator/command.mjs.ejs b/generators/generate-blueprint/templates/generators/generator/command.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/generators/generator/command.mjs.ejs rename to generators/generate-blueprint/templates/generators/generator/command.js.ejs diff --git a/generators/generate-blueprint/templates/generators/generator/generator.mjs.jhi.ejs b/generators/generate-blueprint/templates/generators/generator/generator.js.jhi.ejs similarity index 100% rename from generators/generate-blueprint/templates/generators/generator/generator.mjs.jhi.ejs rename to generators/generate-blueprint/templates/generators/generator/generator.js.jhi.ejs diff --git a/generators/generate-blueprint/templates/generators/generator/generator.spec.mjs.ejs b/generators/generate-blueprint/templates/generators/generator/generator.spec.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/generators/generator/generator.spec.mjs.ejs rename to generators/generate-blueprint/templates/generators/generator/generator.spec.js.ejs diff --git a/generators/generate-blueprint/templates/generators/generator/index.mjs.ejs b/generators/generate-blueprint/templates/generators/generator/index.js.ejs similarity index 100% rename from generators/generate-blueprint/templates/generators/generator/index.mjs.ejs rename to generators/generate-blueprint/templates/generators/generator/index.js.ejs diff --git a/generators/react/resources/package.json b/generators/react/resources/package.json index 3ef1cde9d20b..11d653cf83a6 100644 --- a/generators/react/resources/package.json +++ b/generators/react/resources/package.json @@ -1,4 +1,5 @@ { + "type": "module", "dependencies": { "@fortawesome/fontawesome-svg-core": "7.0.1", "@fortawesome/free-solid-svg-icons": "7.0.1", diff --git a/generators/react/templates/jest.conf.js.ejs b/generators/react/templates/jest.conf.js.ejs index 3c0b4385391c..c100c738b786 100644 --- a/generators/react/templates/jest.conf.js.ejs +++ b/generators/react/templates/jest.conf.js.ejs @@ -1,44 +1,9 @@ +import { createRequire } from 'module'; + +const require = createRequire(import.meta.url); const tsconfig = require('./tsconfig.test.json'); +import environment from './webpack/environment.js'; -module.exports = { - testEnvironment: 'jest-fixed-jsdom', - transform: { - '^.+\\.tsx?$': [ - 'ts-jest', - { - tsconfig: './tsconfig.test.json', - compiler: 'typescript', - diagnostics: false, - }, - ], - }, - testEnvironmentOptions: { - url: 'http://localhost/', - }, - cacheDirectory: '/<%= this.relativeDir(clientRootDir, temporaryDir) %>jest-cache', - coverageDirectory: '/<%= this.relativeDir(clientRootDir, temporaryDir) %>test-results/', - testMatch: ['/<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/**/@(*.)@(spec.ts?(x))'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coveragePathIgnorePatterns: ['/<%= this.relativeDir(clientRootDir, clientTestDir) %>'], - moduleNameMapper: mapTypescriptAliasToJestAlias({ - '\\.(css|scss)$': 'identity-obj-proxy', - sinon: require.resolve('sinon/pkg/sinon.js'), - }), - reporters: [ - 'default', - ['jest-junit', { outputDirectory: './<%= this.relativeDir(clientRootDir, temporaryDir) %>test-results/', outputName: 'TESTS-results-jest.xml' }], - ['jest-sonar', { outputDirectory: './<%= this.relativeDir(clientRootDir, temporaryDir) %>test-results/jest', outputName: 'TESTS-results-sonar.xml' }], - ], - testPathIgnorePatterns: ['/node_modules/'], - setupFiles: ['/<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/setup-tests.ts'], - globals: { -<%_ if (enableTranslation) { _%> - I18N_HASH: 'generated_hash', -<%_ } _%> - ...require('./webpack/environment'), - DEVELOPMENT: false, - }, -}; function mapTypescriptAliasToJestAlias(alias = {}) { const jestAliases = { ...alias }; @@ -65,3 +30,43 @@ function mapTypescriptAliasToJestAlias(alias = {}) { }, jestAliases); return jestAliases; } + + export default { + testEnvironment: 'jest-fixed-jsdom', + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + tsconfig: './tsconfig.test.json', + compiler: 'typescript', + diagnostics: false, + }, + ], + }, + testEnvironmentOptions: { + url: 'http://localhost/', + }, + cacheDirectory: '/<%= this.relativeDir(clientRootDir, temporaryDir) %>jest-cache', + coverageDirectory: '/<%= this.relativeDir(clientRootDir, temporaryDir) %>test-results/', + testMatch: ['/<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/**/@(*.)@(spec.ts?(x))'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + coveragePathIgnorePatterns: ['/<%= this.relativeDir(clientRootDir, clientTestDir) %>'], + moduleNameMapper: mapTypescriptAliasToJestAlias({ + '\\.(css|scss)$': 'identity-obj-proxy', + sinon: require.resolve('sinon/pkg/sinon.js'), + }), + reporters: [ + 'default', + ['jest-junit', { outputDirectory: './<%= this.relativeDir(clientRootDir, temporaryDir) %>test-results/', outputName: 'TESTS-results-jest.xml' }], + ['jest-sonar', { outputDirectory: './<%= this.relativeDir(clientRootDir, temporaryDir) %>test-results/jest', outputName: 'TESTS-results-sonar.xml' }], + ], + testPathIgnorePatterns: ['/node_modules/'], + setupFiles: ['/<%= this.relativeDir(clientRootDir, clientSrcDir) %>app/setup-tests.ts'], + globals: { + <%_ if (enableTranslation) { _%> + I18N_HASH: 'generated_hash', + <%_ } _%> + ...require('./webpack/environment'), + DEVELOPMENT: false, + }, + }; \ No newline at end of file diff --git a/generators/react/templates/package.json.ejs b/generators/react/templates/package.json.ejs index 7b22c1744ee0..51c5b8a7da94 100644 --- a/generators/react/templates/package.json.ejs +++ b/generators/react/templates/package.json.ejs @@ -20,6 +20,7 @@ "name": "<%= dasherizedBaseName %>", "version": "0.0.1-SNAPSHOT", "description": "<%= projectDescription %>", + "type": "module", "private": true, "license": "UNLICENSED", "cacheDirectories": [ diff --git a/generators/react/templates/postcss.config.js.ejs b/generators/react/templates/postcss.config.js.ejs index 9532ea140f28..f9bb74c2624d 100644 --- a/generators/react/templates/postcss.config.js.ejs +++ b/generators/react/templates/postcss.config.js.ejs @@ -16,6 +16,8 @@ See the License for the specific language governing permissions and limitations under the License. -%> -module.exports = { +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +export default { plugins: [require('autoprefixer')], }; diff --git a/generators/react/templates/webpack/environment.js.ejs b/generators/react/templates/webpack/environment.js.ejs index d1f598c74be2..32fb3df9e2cb 100644 --- a/generators/react/templates/webpack/environment.js.ejs +++ b/generators/react/templates/webpack/environment.js.ejs @@ -17,10 +17,12 @@ limitations under the License. -%> <%_ if (buildToolUnknown) { _%> +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); const packageJson = require('./../package.json'); <%_ } _%> -module.exports = { +export default { <%_ if (buildToolUnknown) { _%> VERSION: packageJson.version, <%_ } else { _%> diff --git a/generators/react/templates/webpack/utils.js.ejs b/generators/react/templates/webpack/utils.js.ejs index cc2a35b8ff82..08f35fb8fb70 100644 --- a/generators/react/templates/webpack/utils.js.ejs +++ b/generators/react/templates/webpack/utils.js.ejs @@ -16,14 +16,15 @@ See the License for the specific language governing permissions and limitations under the License. -%> +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; const path = require('path'); - const tsconfig = require('../tsconfig.json'); -module.exports = { - root, - mapTypescriptAliasToWebpackAlias, -}; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const _root = path.resolve(__dirname, '..'); @@ -55,3 +56,8 @@ function mapTypescriptAliasToWebpackAlias(alias = {}) { }, webpackAliases); return webpackAliases; } + +export default { + root, + mapTypescriptAliasToWebpackAlias, +}; \ No newline at end of file diff --git a/generators/react/templates/webpack/webpack.common.js.ejs b/generators/react/templates/webpack/webpack.common.js.ejs index 780033d0b745..6483c8e72ee6 100644 --- a/generators/react/templates/webpack/webpack.common.js.ejs +++ b/generators/react/templates/webpack/webpack.common.js.ejs @@ -16,19 +16,26 @@ See the License for the specific language governing permissions and limitations under the License. -%> -const path = require('path'); -const webpack = require('webpack'); -const { merge } = require('webpack-merge'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); -const ESLintPlugin = require('eslint-webpack-plugin'); +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +import path from 'path'; +import {dirname} from 'path'; +import {fileURLToPath} from 'url'; +import webpack from 'webpack'; +import { merge } from 'webpack-merge'; +import CopyWebpackPlugin from 'copy-webpack-plugin'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; +import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; +import ESLintPlugin from 'eslint-webpack-plugin'; <%_ if (enableTranslation) { _%> const { hashElement } = require('folder-hash'); -const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin'); +import MergeJsonWebpackPlugin from 'merge-jsons-webpack-plugin'; <%_ } _%> -const utils = require('./utils.js'); -const environment = require('./environment'); +import utils from './utils.js'; +import environment from './environment.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const getTsLoaderRule = () => { return [ @@ -51,7 +58,7 @@ const getTsLoaderRule = () => { ]; }; -module.exports = async options => { +export default async options => { const development = options.env === 'development'; <%_ if (enableTranslation) { _%> const languagesHash = await hashElement(path.resolve(__dirname, '../<%= this.relativeDir(clientRootDir, clientSrcDir) %>i18n'), { diff --git a/generators/react/templates/webpack/webpack.dev.js.ejs b/generators/react/templates/webpack/webpack.dev.js.ejs index 2e9c2b809370..f126db3efa2c 100644 --- a/generators/react/templates/webpack/webpack.dev.js.ejs +++ b/generators/react/templates/webpack/webpack.dev.js.ejs @@ -16,7 +16,12 @@ See the License for the specific language governing permissions and limitations under the License. -%> -const webpackMerge = require('webpack-merge').merge; +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const require = createRequire(import.meta.url); +const { merge: webpackMerge } = require('webpack-merge'); const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin'); const WebpackNotifierPlugin = require('webpack-notifier'); @@ -25,13 +30,16 @@ const sass = require('sass'); <%_ if (enableI18nRTL) { _%> const postcssRTLCSS = require('postcss-rtlcss'); <%_ } _%> +import utils from './utils.js'; +import commonConfig from './webpack.common.js'; -const utils = require('./utils.js'); -const commonConfig = require('./webpack.common.js'); +// ESM equivalent of __dirname +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const ENV = 'development'; -module.exports = async (options) => webpackMerge(await commonConfig({ env: ENV }), { +export default async (options) => webpackMerge(await commonConfig({ env: ENV }), { devtool: 'cheap-module-source-map', // https://reactjs.org/docs/cross-origin-errors.html mode: ENV, entry: [ diff --git a/generators/react/templates/webpack/webpack.prod.js.ejs b/generators/react/templates/webpack/webpack.prod.js.ejs index 1185d702fb25..01f5ec54812e 100644 --- a/generators/react/templates/webpack/webpack.prod.js.ejs +++ b/generators/react/templates/webpack/webpack.prod.js.ejs @@ -16,23 +16,23 @@ See the License for the specific language governing permissions and limitations under the License. -%> -const webpack = require('webpack'); -const webpackMerge = require('webpack-merge').merge; -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const WorkboxPlugin = require('workbox-webpack-plugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); -const sass = require('sass'); +import webpack from 'webpack'; +import { merge as webpackMerge } from 'webpack-merge'; +import MiniCssExtractPlugin from 'mini-css-extract-plugin'; +import WorkboxPlugin from 'workbox-webpack-plugin'; +import TerserPlugin from 'terser-webpack-plugin'; +import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; +import sass from 'sass'; <%_ if (enableI18nRTL) { _%> -const postcssRTLCSS = require('postcss-rtlcss'); +import postcssRTLCSS from 'postcss-rtlcss'; <%_ } _%> -const utils = require('./utils.js'); -const commonConfig = require('./webpack.common.js'); +import * as utils from './utils.js'; +import commonConfig from './webpack.common.js'; const ENV = 'production'; -module.exports = async () => webpackMerge(await commonConfig({ env: ENV }), { +export default async () => webpackMerge(await commonConfig({ env: ENV }), { // devtool: 'source-map', // Enable source maps. Please note that this will slow down the build mode: ENV, entry: { diff --git a/generators/vue/__snapshots__/generator.spec.ts.snap b/generators/vue/__snapshots__/generator.spec.ts.snap index 7839f05e7b03..18d832de90af 100644 --- a/generators/vue/__snapshots__/generator.spec.ts.snap +++ b/generators/vue/__snapshots__/generator.spec.ts.snap @@ -1117,7 +1117,7 @@ exports[`generator - vue microservice-jwt-skipUserManagement(false)-withAdminUi( "clientRoot/eslint.config.mjs": { "stateCleared": "modified", }, - "clientRoot/module-federation.config.cjs": { + "clientRoot/module-federation.config.js": { "stateCleared": "modified", }, "clientRoot/package.json": { @@ -1663,7 +1663,7 @@ exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDepen "eslint.config.mjs": { "stateCleared": "modified", }, - "module-federation.config.cjs": { + "module-federation.config.js": { "stateCleared": "modified", }, "package.json": { diff --git a/generators/vue/files-vue.ts b/generators/vue/files-vue.ts index 978531a0565f..c2bbfb0173da 100644 --- a/generators/vue/files-vue.ts +++ b/generators/vue/files-vue.ts @@ -40,7 +40,7 @@ export const vueFiles = asWriteFilesSection({ microfrontend: [ clientRootTemplatesBlock({ condition: generator => generator.microfrontend, - templates: ['module-federation.config.cjs'], + templates: ['module-federation.config.js'], }), clientRootTemplatesBlock({ condition: ctx => ctx.microfrontend && ctx.clientBundlerWebpack, diff --git a/generators/vue/generator.ts b/generators/vue/generator.ts index 6c6b0d1411ff..ab2aa420e91e 100644 --- a/generators/vue/generator.ts +++ b/generators/vue/generator.ts @@ -117,7 +117,7 @@ export default class VueGenerator extends ClientApplicationGenerator { javaNodeBuildPaths?.push('.postcssrc.js', 'tsconfig.json', 'tsconfig.app.json'); if (microfrontend) { - javaNodeBuildPaths?.push('module-federation.config.cjs'); + javaNodeBuildPaths?.push('module-federation.config.js'); } if (clientBundlerWebpack) { javaNodeBuildPaths?.push('webpack/'); diff --git a/generators/vue/resources/package.json b/generators/vue/resources/package.json index 2e165806623a..cba48c516781 100644 --- a/generators/vue/resources/package.json +++ b/generators/vue/resources/package.json @@ -1,4 +1,5 @@ { + "type": "module", "dependencies": { "@fortawesome/fontawesome-svg-core": "7.0.1", "@fortawesome/free-solid-svg-icons": "7.0.1", diff --git a/generators/vue/templates/.postcssrc.js.ejs b/generators/vue/templates/.postcssrc.js.ejs index 39ebf318ccd6..9c9a43b8acd8 100644 --- a/generators/vue/templates/.postcssrc.js.ejs +++ b/generators/vue/templates/.postcssrc.js.ejs @@ -1,6 +1,6 @@ // https://github.com/michael-ciniawsky/postcss-load-config -module.exports = { +export default { plugins: { 'postcss-import': {}, 'postcss-url': {}, diff --git a/generators/vue/templates/module-federation.config.cjs.ejs b/generators/vue/templates/module-federation.config.js.ejs similarity index 88% rename from generators/vue/templates/module-federation.config.cjs.ejs rename to generators/vue/templates/module-federation.config.js.ejs index 83734f36ccd9..b0191bdc4ef2 100644 --- a/generators/vue/templates/module-federation.config.cjs.ejs +++ b/generators/vue/templates/module-federation.config.js.ejs @@ -16,8 +16,16 @@ See the License for the specific language governing permissions and limitations under the License. -%> +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const require = createRequire(import.meta.url); const packageJson = require('./package.json'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + // Microfrontend api, should match across gateway and microservices. const apiVersion = '0.0.1'; @@ -32,7 +40,7 @@ const shareDependencies = ({ skipList = [] } = {}) => ); /** @type {import('@module-federation/runtime').Options} */ -module.exports = { +export default { name: '<%= lowercaseBaseName %>', <%_ if (applicationTypeMicroservice) { _%> exposes: { diff --git a/generators/vue/templates/package.json.ejs b/generators/vue/templates/package.json.ejs index 3eda6904ba6d..77b46ca6e91f 100644 --- a/generators/vue/templates/package.json.ejs +++ b/generators/vue/templates/package.json.ejs @@ -20,6 +20,7 @@ "name": "<%= dasherizedBaseName %>", "version": "0.0.0", "description": "<%= projectDescription %>", + "type": "module", "private": true, "license": "UNLICENSED", "cacheDirectories": [ diff --git a/generators/vue/templates/vitest.config.mts.ejs b/generators/vue/templates/vitest.config.mts.ejs index 141ffb3aa73f..c219312fb7a9 100644 --- a/generators/vue/templates/vitest.config.mts.ejs +++ b/generators/vue/templates/vitest.config.mts.ejs @@ -18,7 +18,7 @@ -%> import { fileURLToPath } from 'node:url' import { mergeConfig, defineConfig } from 'vitest/config'; -import viteConfig from './vite.config.mjs' +import viteConfig from './vite.config.mts' export default mergeConfig( viteConfig, diff --git a/generators/vue/templates/webpack/config.js.ejs b/generators/vue/templates/webpack/config.js.ejs index fe10699613d9..baabc78d1acf 100644 --- a/generators/vue/templates/webpack/config.js.ejs +++ b/generators/vue/templates/webpack/config.js.ejs @@ -1,10 +1,17 @@ -'use strict'; +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const require = createRequire(import.meta.url); + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); <%_ if (buildToolUnknown) { _%> const packageJson = require('./../package.json'); <%_ } _%> -module.exports = { +export default { serverApiUrl: '', <%_ if (buildToolUnknown) { _%> version: packageJson.version, diff --git a/generators/vue/templates/webpack/vue.utils.js.ejs b/generators/vue/templates/webpack/vue.utils.js.ejs index 6552b8c4165e..286f326be65f 100644 --- a/generators/vue/templates/webpack/vue.utils.js.ejs +++ b/generators/vue/templates/webpack/vue.utils.js.ejs @@ -1,4 +1,5 @@ -'use strict'; +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const sass = require('sass'); @@ -85,7 +86,7 @@ const vueLoaderConfig = production => ({ hotReload: config.dev.hotReload, }); -module.exports = { +export default { cssLoaders, styleLoaders, vueLoaderConfig, diff --git a/generators/vue/templates/webpack/webpack.common.js.ejs b/generators/vue/templates/webpack/webpack.common.js.ejs index 8b24543ed05d..1ae950f1f716 100644 --- a/generators/vue/templates/webpack/webpack.common.js.ejs +++ b/generators/vue/templates/webpack/webpack.common.js.ejs @@ -1,4 +1,7 @@ -'use strict'; +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +const require = createRequire(import.meta.url); const path = require('path'); const { merge } = require('webpack-merge'); const { VueLoaderPlugin } = require('vue-loader'); @@ -10,14 +13,17 @@ const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin'); <%_ } _%> const { DefinePlugin } = require('webpack'); -const { vueLoaderConfig } = require('./vue.utils'); -const config = require('./config'); +const { vueLoaderConfig } = require('./vue.utils.js'); +const config = require('./config.js'); + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); function resolve(dir = '') { return path.join(__dirname, '..', dir); } -module.exports = async (env, options) => { +export default async (env, options) => { const development = options.mode === 'development'; <%_ if (enableTranslation) { _%> const languagesHash = await hashElement(resolve('<%= this.relativeDir(clientRootDir, clientSrcDir) %>i18n'), { @@ -51,7 +57,7 @@ module.exports = async (env, options) => { }, devServer: { <%_ if (microfrontend) { _%> - hot: config.dev.hotReload, + hot: config.dev?.hotReload ?? false, <%_ } _%> static: { directory: './<%= this.relativeDir(clientRootDir, clientDistDir) %>', diff --git a/generators/vue/templates/webpack/webpack.dev.js.ejs b/generators/vue/templates/webpack/webpack.dev.js.ejs index 8ff63e69b28d..c80624e17a55 100644 --- a/generators/vue/templates/webpack/webpack.dev.js.ejs +++ b/generators/vue/templates/webpack/webpack.dev.js.ejs @@ -16,18 +16,22 @@ See the License for the specific language governing permissions and limitations under the License. -%> -'use strict'; +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import config from './config.js'; +import { styleLoaders } from './vue.utils.js'; + +const require = createRequire(import.meta.url); const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); -const { styleLoaders } = require('./vue.utils'); -const config = require('./config'); -module.exports = (env, options) => { +export default (env, options) => { const devConfig = { module: { rules: styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }), }, - // cheap-module-eval-source-map is faster for development + // cheap-module-eval-source-map is faster for developmenst devtool: config.dev.devtool, output: { filename: 'app/[name].[contenthash].bundle.js', diff --git a/generators/vue/templates/webpack/webpack.prod.js.ejs b/generators/vue/templates/webpack/webpack.prod.js.ejs index a8d6afd96db1..a688d4c4785d 100644 --- a/generators/vue/templates/webpack/webpack.prod.js.ejs +++ b/generators/vue/templates/webpack/webpack.prod.js.ejs @@ -16,14 +16,20 @@ See the License for the specific language governing permissions and limitations under the License. -%> -'use strict'; +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import { styleLoaders } from './vue.utils.js'; +import config from './config.js'; + +const require = createRequire(import.meta.url); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); const WorkboxPlugin = require('workbox-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin'); -const { styleLoaders } = require('./vue.utils'); -const config = require('./config'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const webpackConfig = { module: { @@ -123,4 +129,4 @@ if (config.build.bundleAnalyzerReport) { webpackConfig.plugins.push(new BundleAnalyzerPlugin()); } -module.exports = async () => webpackConfig; +export default async () => webpackConfig;