Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to type modules. #19941

Merged
merged 36 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
914c771
Move generator-base* to base folder
mshima Oct 4, 2022
1441f9e
move docker-* to base-docker
mshima Oct 4, 2022
4aa606c
move kubernetes-base to kubernetes folder
mshima Oct 4, 2022
cace015
rename generator-list.js to generator-list.cjs
mshima Oct 5, 2022
082f26d
rename options.js to options.cjs
mshima Oct 5, 2022
bf73505
rename needle-api.js to needle-api.cjs
mshima Oct 5, 2022
adc45eb
change cleanup extension to cjs
mshima Oct 5, 2022
221bd8b
change needle-* extension to cjs
mshima Oct 5, 2022
cafbdaa
change generator-constants extension to cjs
mshima Oct 5, 2022
2ac743a
change generator-defaults extension to cjs
mshima Oct 5, 2022
b6833ef
change sql-constants extension to cjs
mshima Oct 5, 2022
c3d1cef
change statistics extension to cjs
mshima Oct 5, 2022
de26779
change utils extension to cjs
mshima Oct 5, 2022
45eed9c
change lib/index extension to cjs
mshima Oct 5, 2022
48876f9
change generators extension to cjs
mshima Oct 5, 2022
304efaa
stop relaying on commonjs features
mshima Oct 5, 2022
4435802
generators
mshima Oct 5, 2022
b2e7b85
generators
mshima Oct 5, 2022
6af443f
rename test files to cjs
mshima Oct 5, 2022
d4b8698
generators
mshima Oct 5, 2022
48b2923
use ejslint cli
mshima Oct 5, 2022
d565217
test utils
mshima Oct 5, 2022
9e228ca
generators
mshima Oct 5, 2022
517b294
change .mocharc extension to cjs
mshima Oct 5, 2022
2b85c03
expected-files
mshima Oct 5, 2022
6e429d5
change to type: module
mshima Oct 5, 2022
fb372fd
convert files to mjs
mshima Oct 5, 2022
8c759d0
add jsdoc
mshima Oct 6, 2022
7ee97fa
don't generate User at bootstrap
mshima Oct 6, 2022
917e271
make most of generator-(base/private) apis private
mshima Oct 6, 2022
11f8357
type module
mshima Oct 6, 2022
a190c69
convert tests to mts
mshima Oct 6, 2022
ad88d80
convert tests to mts
mshima Oct 6, 2022
eddffe6
migrate tests to mts.
mshima Oct 6, 2022
627c739
change print-matrix to esm
mshima Oct 6, 2022
6d3906e
fix init-env
mshima Oct 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"prefer-destructuring": "off",
"no-multi-assign": "off",
"no-param-reassign": "off",
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"import/no-extraneous-dependencies": "off",
"no-await-in-loop": "off",
"no-restricted-syntax": [
"error",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
${{ runner.os }}-node-${{ steps.get-date.outputs.date }}-
${{ runner.os }}-node-${{ steps.get-date.outputs.date }}
- name: 'install required npm version'
run: npm install -g npm@$(node -e "console.log(require('./generators/generator-constants').NPM_VERSION);")
run: npm install -g npm@$(node -e "console.log(require('./generators/generator-constants.cjs').NPM_VERSION);")
- run: git --no-pager log -n 10 --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue) <%an>%Creset' --abbrev-commit
shell: bash
- name: Config git variables
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.js → .mocharc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
timeout: 30000,
ui: 'bdd',
extension: ['js', 'spec.cjs', 'spec.mjs', 'spec.ts', 'spec.mts'],
require: ['mocha-expect-snapshot/old-format', 'test/mocha.config.js'],
require: ['mocha-expect-snapshot/old-format', 'test/mocha.config.cjs'],
// Resolve absolute path for test with fork and different cwd.
loader: require.resolve('@esbuild-kit/esm-loader'),
parallel: true,
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.js → cli/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/

const { runJHipster } = require('./program');
const { done, logger } = require('./utils');
const { runJHipster } = require('./program.cjs');
const { done, logger } = require('./utils.cjs');

module.exports = runJHipster().catch(done);

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cli/download.js → cli/download.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
const fs = require('fs');
const https = require('https');
const path = require('path');
const cliUtils = require('./utils');
const { packageJson } = require('../lib/index.js');
const cliUtils = require('./utils.cjs');
const { packageJson } = require('../lib/index.cjs');

const { logger, toString } = cliUtils;

Expand Down
6 changes: 3 additions & 3 deletions cli/environment-builder.js → cli/environment-builder.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const _ = require('lodash');
const path = require('path');
const { existsSync } = require('fs');
const Environment = require('yeoman-environment');
const { CLI_NAME, logger } = require('./utils');
const { loadYoRc, packageNameToNamespace } = require('../generators/utils');
const { parseBlueprintInfo, loadBlueprintsFromConfiguration, mergeBlueprints } = require('../utils/blueprint');
const { CLI_NAME, logger } = require('./utils.cjs');
const { loadYoRc, packageNameToNamespace } = require('../generators/utils.cjs');
const { parseBlueprintInfo, loadBlueprintsFromConfiguration, mergeBlueprints } = require('../utils/blueprint.cjs');

const createEnvironment = (args, options = {}, adapter) => {
// Remove after migration to environment 3.
Expand Down
12 changes: 6 additions & 6 deletions cli/import-jdl.js → cli/import-jdl.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const path = require('path');
const pluralize = require('pluralize');
const { fork: forkProcess } = require('child_process');

const EnvironmentBuilder = require('./environment-builder');
const { CLI_NAME, GENERATOR_NAME, logger, toString, printSuccess, getOptionAsArgs } = require('./utils');
const EnvironmentBuilder = require('./environment-builder.cjs');
const { CLI_NAME, GENERATOR_NAME, logger, toString, printSuccess, getOptionAsArgs } = require('./utils.cjs');
const { createImporterFromContent, createImporterFromFiles } = require('../jdl/jdl-importer');

const { packageJson: packagejs } = require('../lib/index.js');
const statistics = require('../generators/statistics');
const { JHIPSTER_CONFIG_DIR } = require('../generators/generator-constants');
const { packageJson: packagejs } = require('../lib/index.cjs');
const statistics = require('../generators/statistics.cjs');
const { JHIPSTER_CONFIG_DIR } = require('../generators/generator-constants.cjs');

const jhipsterCli = require.resolve('./cli.js');
const jhipsterCli = require.resolve('./cli.cjs');
const { writeConfigFile } = require('../jdl/exporters/export-utils');
const { createFolderIfItDoesNotExist } = require('../jdl/utils/file-utils');

Expand Down
4 changes: 2 additions & 2 deletions cli/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { createProgram, buildCommands, buildJHipster, runJHipster, printJHipsterLogo, done, logger } from './program.js';
export { default as EnvironmentBuilder } from './environment-builder.js';
export { createProgram, buildCommands, buildJHipster, runJHipster, printJHipsterLogo, done, logger } from './program.cjs';
export { default as EnvironmentBuilder } from './environment-builder.cjs';
6 changes: 3 additions & 3 deletions cli/jdl.js → cli/jdl.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const cliUtils = require('./utils');
const importJdl = require('./import-jdl');
const download = require('./download');
const cliUtils = require('./utils.cjs');
const importJdl = require('./import-jdl.cjs');
const download = require('./download.cjs');

const { logger } = cliUtils;

Expand Down
File renamed without changes.
20 changes: 11 additions & 9 deletions cli/jhipster.js → cli/jhipster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const semver = require('semver');
const path = require('path');
const { logger } = require('./utils');
const { packageJson } = require('../lib/index.js');
import semver from 'semver';
import path from 'path';
import cliUtils from './utils.cjs';
import { packageJson } from '../lib/index.mjs';

const { logger } = cliUtils;

const currentNodeVersion = process.versions.node;
const minimumNodeVersion = packageJson.engines.node;
Expand All @@ -45,24 +47,24 @@ if (preferLocalArg && preferGlobalArg) {
// --prefer-local: Always resolve node modules locally (useful when using linked module)
const preferLocal = preferLocalArg || (!preferGlobalArg && !process.argv.includes('upgrade'));

requireCLI(preferLocal);
await requireCLI(preferLocal);

/*
* Require cli.js giving priority to local version over bundled one if it exists.
*/
function requireCLI(preferLocal) {
async function requireCLI(preferLocal) {
let message = BUNDLED_VERSION_MESSAGE;
/* eslint-disable global-require */
if (preferLocal) {
try {
const localCLI = require.resolve(path.join(process.cwd(), 'node_modules', 'generator-jhipster', 'cli', 'cli.js'));
const localCLI = require.resolve(path.join(process.cwd(), 'node_modules', 'generator-jhipster', 'cli', 'cli.mjs'));
if (__dirname === path.dirname(localCLI)) {
message = LOCAL_VERSION_MESSAGE;
} else {
// load local version
/* eslint-disable import/no-dynamic-require */
logger.info(LOCAL_VERSION_MESSAGE);
require(localCLI);
await import(localCLI);
return;
}
} catch (e) {
Expand All @@ -71,6 +73,6 @@ function requireCLI(preferLocal) {
}
// load current jhipster
logger.info(message);
require('./cli');
await import('./cli.cjs');
/* eslint-enable */
}
2 changes: 1 addition & 1 deletion cli/logo.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/
const chalk = require('chalk');
const { packageJson: packagejs } = require('../lib/index.js');
const { packageJson: packagejs } = require('../lib/index.cjs');

module.exports.logo = `${chalk.green(' ██╗')}${chalk.red(' ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗')}
${chalk.green(' ██║')}${chalk.red(' ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗')}
Expand Down
18 changes: 11 additions & 7 deletions cli/program.js → cli/program.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
/**
* Copyright 2013-2022 the original author or authors from the JHipster project.
*
Expand All @@ -23,12 +25,12 @@ const didYouMean = require('didyoumean');
const fs = require('fs');
const path = require('path');

const EnvironmentBuilder = require('./environment-builder');
const SUB_GENERATORS = require('./commands');
const JHipsterCommand = require('./jhipster-command');
const { CLI_NAME, logger, getCommand, done } = require('./utils');
const { packageJson } = require('../lib/index.js');
const { packageNameToNamespace } = require('../generators/utils');
const EnvironmentBuilder = require('./environment-builder.cjs');
const SUB_GENERATORS = require('./commands.cjs');
const JHipsterCommand = require('./jhipster-command.cjs');
const { CLI_NAME, logger, getCommand, done } = require('./utils.cjs');
const { packageJson } = require('../lib/index.cjs');
const { packageNameToNamespace } = require('../generators/utils.cjs');
const { logo } = require('./logo.cjs');

const { version: JHIPSTER_VERSION } = packageJson;
Expand Down Expand Up @@ -256,7 +258,9 @@ const buildJHipster = ({
printBlueprintLogo,
env = envBuilder.getEnvironment(),
/* eslint-disable-next-line global-require, import/no-dynamic-require */
loadCommand = key => require(`./${key}`),
loadCommand = key => {
return require(`./${key}.cjs`);
},
defaultCommand,
} = {}) => {
/* setup debugging */
Expand Down
File renamed without changes.
11 changes: 4 additions & 7 deletions generators/add/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {
Priorities: { INITIALIZING_PRIORITY, COMPOSING_PRIORITY },
} = require('generator-jhipster/support');
const BaseBlueprintGenerator = require('../generator-base-blueprint');
const { GENERATOR_ADD } = require('../generator-list');
const BaseBlueprintGenerator = require('../base/generator-base-blueprint.cjs');
const { GENERATOR_ADD } = require('../generator-list.cjs');

/**
* @experimental
Expand Down Expand Up @@ -56,7 +53,7 @@ module.exports = class extends BaseBlueprintGenerator {
};
}

get [INITIALIZING_PRIORITY]() {
get [BaseBlueprintGenerator.INITIALIZING]() {
if (this.delegateToBlueprint) return {};
return this._initializing();
}
Expand All @@ -71,7 +68,7 @@ module.exports = class extends BaseBlueprintGenerator {
};
}

get [COMPOSING_PRIORITY]() {
get [BaseBlueprintGenerator.COMPOSING]() {
if (this.fromBlueprint) return {};
return this._composing();
}
Expand Down
58 changes: 18 additions & 40 deletions generators/app/index.js → generators/app/generator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,21 @@
/* eslint-disable consistent-return */
const chalk = require('chalk');
const _ = require('lodash');
const BaseBlueprintGenerator = require('../generator-base-blueprint');
const {
INITIALIZING_PRIORITY,
PROMPTING_PRIORITY,
CONFIGURING_PRIORITY,
COMPOSING_PRIORITY,
DEFAULT_PRIORITY,
WRITING_PRIORITY,
INSTALL_PRIORITY,
END_PRIORITY,
} = require('../../lib/constants/priorities.cjs').compat;

const cleanup = require('../cleanup');
const prompts = require('./prompts');
const { packageJson: packagejs } = require('../../lib/index.js');
const statistics = require('../statistics');
const { appDefaultConfig } = require('../generator-defaults');
const { GENERATOR_APP } = require('../generator-list');
const { GENERATOR_JHIPSTER } = require('../generator-constants');
const BaseBlueprintGenerator = require('../base/generator-base-blueprint.cjs');

const cleanup = require('../cleanup.cjs');
const prompts = require('./prompts.cjs');
const { packageJson: packagejs } = require('../../lib/index.cjs');
const statistics = require('../statistics.cjs');
const { appDefaultConfig } = require('../generator-defaults.cjs');
const { GENERATOR_APP } = require('../generator-list.cjs');
const { GENERATOR_JHIPSTER } = require('../generator-constants.cjs');
const { MICROSERVICE } = require('../../jdl/jhipster/application-types');
const { OptionNames } = require('../../jdl/jhipster/application-options');
const { NO: CLIENT_FRAMEWORK_NO } = require('../../jdl/jhipster/client-framework-types');

const { JHI_PREFIX, BASE_NAME, JWT_SECRET_KEY, PACKAGE_NAME, PACKAGE_FOLDER, REMEMBER_ME_KEY } = OptionNames;
const {
GENERATOR_COMMON,
GENERATOR_ENTITIES,
GENERATOR_LANGUAGES,
GENERATOR_CLIENT,
GENERATOR_PAGE,
GENERATOR_SERVER,
} = require('../generator-list');
const { GENERATOR_COMMON, GENERATOR_LANGUAGES, GENERATOR_CLIENT, GENERATOR_PAGE, GENERATOR_SERVER } = require('../generator-list.cjs');

module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
constructor(args, options, features) {
Expand Down Expand Up @@ -378,7 +361,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [INITIALIZING_PRIORITY]() {
get [BaseBlueprintGenerator.INITIALIZING]() {
if (this.delegateToBlueprint) {
return;
}
Expand All @@ -393,7 +376,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [PROMPTING_PRIORITY]() {
get [BaseBlueprintGenerator.PROMPTING]() {
if (this.delegateToBlueprint) return;
return this._prompting();
}
Expand Down Expand Up @@ -429,7 +412,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [CONFIGURING_PRIORITY]() {
get [BaseBlueprintGenerator.CONFIGURING]() {
if (this.delegateToBlueprint) return;
return this._configuring();
}
Expand Down Expand Up @@ -486,11 +469,6 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
this.config.set(config);
},

async composeEntities() {
if (!this.options.withEntities) return;
await this.composeWithJHipster(GENERATOR_ENTITIES, { skipInstall: true }, true);
},

async composePages() {
if (!this.jhipsterConfig.pages || this.jhipsterConfig.pages.length === 0 || this.configOptions.skipComposePage) return;
this.configOptions.skipComposePage = true;
Expand All @@ -506,7 +484,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [COMPOSING_PRIORITY]() {
get [BaseBlueprintGenerator.COMPOSING]() {
if (this.delegateToBlueprint) return;
return this._composing();
}
Expand All @@ -523,7 +501,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [DEFAULT_PRIORITY]() {
get [BaseBlueprintGenerator.DEFAULT]() {
if (this.delegateToBlueprint) return;
return this._default();
}
Expand All @@ -537,7 +515,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [WRITING_PRIORITY]() {
get [BaseBlueprintGenerator.WRITING]() {
if (this.delegateToBlueprint) return;
return this._writing();
}
Expand All @@ -554,7 +532,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [INSTALL_PRIORITY]() {
get [BaseBlueprintGenerator.INSTALL]() {
if (this.delegateToBlueprint) return;
return this._install();
}
Expand Down Expand Up @@ -598,7 +576,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
};
}

get [END_PRIORITY]() {
get [BaseBlueprintGenerator.END]() {
if (this.delegateToBlueprint) return;
return this._end();
}
Expand Down
4 changes: 2 additions & 2 deletions generators/app/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { fileURLToPath } from 'url';

import testSupport from '../../test/support/index.cjs';
import { defaultHelpers as helpers } from '../../test/utils/utils.mjs';
import Generator from './index.js';
import Generator from './index.mjs';

const { snakeCase } = lodash;
const { testBlueprintSupport } = testSupport;
Expand All @@ -36,7 +36,7 @@ const generatorPath = join(__dirname, 'index.mjs');

describe(`JHipster ${generator} generator`, () => {
it('generator-list constant matches folder name', async () => {
await expect((await import('../generator-list.js')).default[`GENERATOR_${snakeCase(generator).toUpperCase()}`]).toBe(generator);
await expect((await import('../generator-list.cjs')).default[`GENERATOR_${snakeCase(generator).toUpperCase()}`]).toBe(generator);
});
it('should support features parameter', () => {
const instance = new Generator([], { help: true }, { bar: true });
Expand Down
Loading