Skip to content

Commit

Permalink
Set up TypeScript (#19559)
Browse files Browse the repository at this point in the history
* Init tsconfig.json

* Initial config of build npm script

* Configure TS support in eslint

* Add include field to tsconfig.json

* Set allowSyntheticDefaultImports to true

* Fix quotation in .eslintrc.json

* Add dist folder to .prettierignore

* Add dist folder to .eslintignore

* Ignore some eslint rules

Ignore some of the @typescript-eslint rules on existing
JavaScript files.

* Add npm script to copy files

This script copies all files which are not source files from `generators/` to the build
output folder `dist`. This is needed since TypeScript only places the generated
JavaScript files in the `dist` folder but other files from
`generators/` are also needed in the output.

* Add copy-files to build script

* Configure package.json "main" to use build output

* Configure package.json "bin" to use build output

* Configure package.json "files" to use build output

* Copy package.json to dist in build script

* Also copy .ejs files to build output

* Adapt JHipster generator lookup paths

* Build before installing in install script

* Set module system in tsconfig.json to node16

* Pin dependencies

* Set build target to ES2022

* Ignore more files in copy-files script

Don't copy files ending with .snap and folders starting with __ (currently __snapshots__ & __workflow)  to build output. These are files needed for tests or CI which have no use in the build output.

* Add test files to exclude in tsconfig.json

* Update cli/environment-builder.js

* Adapt paths in exports to build output

* Don't build when installing from package

* Don't use build output for `/esm/*` exports

When using the build output for these exports the tests which import
these modules as part of the test case fail.

This has two reasons:
1. In CI/CD npm run build is not run before the tests so the
   modules fail to be imported. This could be solved by first building
   the package.
2. In the tests the modules are imported via ES Modules syntax and the
   import function and the result is compared for referential equality.
   When the built file is imported through the import function and
   it's compared to the source file the reference is always
   not the same.

When this part of the code is converted to TypeScript these issues must
be addressed.

* Build project in prepare npm script

This will build the project when it's installed.

* Don't build before installing

This should be done by the prepare npm script now.

* Remove commented out tsconfig options

Co-authored-by: Marcelo Shima <marceloshima@gmail.com>
  • Loading branch information
emilpaw and mshima committed Sep 16, 2022
1 parent 9e561b1 commit 71b7e73
Show file tree
Hide file tree
Showing 8 changed files with 1,418 additions and 26 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ docs
test/templates
jdl/bundling
test/fixtures/**
dist
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"node": true,
"es2022": true
},
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"plugins": ["mocha", "prettier", "chai-friendly"],
"extends": ["airbnb-base", "plugin:prettier/recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["mocha", "prettier", "chai-friendly", "@typescript-eslint"],
"settings": {
"import/core-modules": ["generator-jhipster", "generator-jhipster/support"]
},
Expand All @@ -23,6 +24,15 @@
"env": {
"mocha": true
}
},
{
"files": ["**/*.{c,m,}js", "**/*.{c,m,}js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-this-alias": "off"
}
}
],
"rules": {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ test/temp/
.project
.settings
test/**/*.png
dist
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test/jdl/**/.jhipster/**
**/jdl-core.min.js
**/generated-serialized-grammar.js
test/fixtures/**
dist
12 changes: 11 additions & 1 deletion cli/environment-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ module.exports = class EnvironmentBuilder {
*/
_lookupJHipster() {
// Register jhipster generators.
this.env.lookup({ packagePaths: [path.join(__dirname, '..')], lookups: ['generators'] }).forEach(generator => {
const sourceRoot = path.basename(path.join(__dirname, '..'));
let packagePath;
let lookup;
if (sourceRoot === 'generator-jhipster') {
packagePath = path.join(__dirname, '..');
lookup = 'generators';
} else {
packagePath = path.join(__dirname, '../..');
lookup = `${sourceRoot}/generators`;
}
this.env.lookup({ packagePaths: [packagePath], lookups: [lookup] }).forEach(generator => {
// Verify jhipster generators namespace.
assert(
generator.namespace.startsWith(`${CLI_NAME}:`),
Expand Down
Loading

0 comments on commit 71b7e73

Please sign in to comment.