-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Set up TypeScript #19559
Set up TypeScript #19559
Conversation
Not an expert, but I would love to start contributing to jhipster in typescript! |
2fe6184
to
99f7512
Compare
At this point running Running it does not work yet though. First linking with @mshima Could you help me understand what the error exactly means and what the issue is? |
Why copy every js file to dist?
This is related to the generators lookup process. |
TypeScript compiles all source files, JavaScript and TypeScript ones. It's not just copying the files. Not sure what the migration to TS could look like if we only compile a selected part of the program and leave the rest uncompiled. I was thinking about letting TypeScript compile the whole program and then piece after piece migrate the JavaScript files to TypeScript. What exactly did you have in mind?
I am still not sure what the code does but I just naively replace generator-jhipster/cli/environment-builder.js Line 119 in b741f65
If there is a way to only compile parts of the programm and we decide we prefer that over letting TypeScript compile all source files we could do this. Otherwise this is needed to be done within the scope of this PR. |
Might be relevant to this conversation: https://blog.jim-nielsen.com/2018/installing-and-building-an-npm-package-from-github/ |
I was thinking to migrate jdl first to reduce the complexity of the migration.
The lookups should be changed to
IFAIK jdl doesn't uses other folder, so compiling the jdl folder and moving it to src/jdl should be enough. generator-jhipster/cli/import-jdl.js Line 28 in b741f65
Anyway, feel free to compile everything if it works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will support node >=16, target and module can be bumped.
If we copy tests to dist, how do we update snapshots? |
I haven't yet looked into how snapshots work, so I don't know.
You mean to move
Yes, I also looked into that but wasn't sure if that's the right approach. The generator lookup seems to not work correctly yet. At least that's my guess based on the error message in the failed tests. So just changing the paths did not work. I am still looking into that. |
That's not the only reason, having more than one root source folder can be confusing.
The lookup is working fine, all integration tests are working. Moving sources to |
6136ea8
to
c44818b
Compare
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.
e9640be
to
931bc39
Compare
All the tests were passing. While rebasing I made a mistake but now I restored it to the pre-rebase mistake state. @mshima You could force push your local branch if commits are missing but I think it's good now. I also started to work on moving the source files to an In both PRs the pipelines don't seem to start anymore though. Any idea why? |
Due to conflicts, since this tests of this PR is succeeding, we can finish it and merge. |
I thought that also the pipeline in this PR was not starting but it just took a very long time. Adapting the package.json exports to the new build output was not yet done. I changed the paths and then some tests broke. Currently, I am working on that. Other than that I think this PR is done. |
"./esm/cli": "./cli/index.mjs", | ||
"./esm/generators/*": "./generators/*/esm.mjs", | ||
"./esm/generators": "./lib/constants/generators.mjs", | ||
"./esm/priorities": "./lib/constants/priorities.mjs", | ||
"./esm/support": "./lib/support/index.cjs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for not update?
"./esm/cli": "./cli/index.mjs", | |
"./esm/generators/*": "./generators/*/esm.mjs", | |
"./esm/generators": "./lib/constants/generators.mjs", | |
"./esm/priorities": "./lib/constants/priorities.mjs", | |
"./esm/support": "./lib/support/index.cjs" | |
"./esm/cli": "./dist/cli/index.mjs", | |
"./esm/generators/*": "./dist/generators/*/esm.mjs", | |
"./esm/generators": "./dist/lib/constants/generators.mjs", | |
"./esm/priorities": "./dist/lib/constants/priorities.mjs", | |
"./esm/support": "./dist/lib/support/index.cjs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I explained it in the commit: 5263183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at prepare
script and it seems to work for this case:
Adding "prepare": "npm run build",
script to package.json and build should be executed every time npm install is executed.
Can you check please?
npm ci --prod | ||
npm run build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm ci --prod | |
npm run build | |
npm install |
npm ci --prod | ||
npm run build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm ci --prod | |
npm run build | |
npm install |
tsconfig.json
Outdated
"include": ["cli/**/*", "generators/**/*", "jdl/**/*", "lib/**/*", "test/**/*"], | ||
"exclude": ["**/*.spec.*"], | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig to read more about this file */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove commented configs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
This will build the project when it's installed.
This should be done by the prepare npm script now.
5263183
to
0af077b
Compare
Initial set up of TypeScript.
Please make sure the below checklist is followed for Pull Requests.
When you are still working on the PR, consider converting it to Draft (below reviewers) and adding
skip-ci
label, you can still see CI build result at your branch.