-
-
Notifications
You must be signed in to change notification settings - Fork 247
feat: support for noEmitOnErrors property in webpack.config #337
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
Conversation
Webpack doesn't notify NativeScript CLI when there is a compilation error. So, NativeScript CLI build the app, install it on device and start it. In most cases the application crashes runtime as the webpack compilcation is not successful. Most probably there would be a red/yellow message in the console printed during the compilation. The users don't see the error message as there is too much log outputed in the console. They don't understand the exact reason why their app crashes runtime. Webpack has a mechanism to skip the emitting phase whenever there are errors while compiling. This can be achieved using `optimization.noEmitOnErrors` property as it is described [here](https://webpack.js.org/configuration/optimization/#optimizationnoemitonerrors). This PR adds `noEmitOnErrors` property in all webpack.config files: * The default value is based on `noEmitOnError` property from `tsconfig.json` for `angular` and `typescript` projects * The default value is `true` for `javascript` and `vue` projects. Also this PR fixes the following problems: 1. Check for syntactic errors when running webpack compilation in ts projects Currently `ts-loader` is started in `transpileOnly` mode and webpack plugin (`ForkTsCheckerWebpackPlugin`) runs TypeScript type checker on a separate process in order to report for compilation errors. By default the plugin only checks for semantic errors and adds them to `compilation.errors` as can be seen [here](). On the other side, webpack relies on [compilation.errors]() array when deciding if should skip emitting phase. However, `ts-loader` used in `transpileOnly` mode still reports syntactic errors but adds them to `compilation.warnings`. This is a problem, as actually the compilation is not stopped when there is a syntactic error. Setting `checkSyntacticErrors: true` will ensure that `ForkTsCheckerWebpackPlugin` will check for both syntactic and semantic errors and after that will be added to `compilation.errors`. 2. Respect `noEmitOnError` from `tsconfig.json` when compiling in `ts` projects The problem is in `ForkTsCheckerWebpackPlugin` and in the way it is integrated with webpack hooks - TypeStrong/fork-ts-checker-webpack-plugin#337. 3. Send the hash of compilation to NativeScript CLI The `hmr` generates new hot-update files on every change and the hash of the next hmr update is written inside hot-update.json file. Although webpack doesn't emit any files, hmr hash is still generated. The hash is generated per compilation no matter if files will be emitted or not. This way, the first successful compilation after fixing the compilation error generates a hash that is not the same as the one expected in the latest emitted hot-update.json file. As a result, the hmr chain is broken and the changes are not applied. Rel to: NativeScript/nativescript-cli#3785
Thank you for your findings and for the PR :) I know that it can be frustrating that we cannot just fix this bug and change the hook, but our responsibility is to introduce breaking changes gracefully :) |
Hey @piotr-oles, Thank you very much for taking a look at this PR.
I totally agree that we have to ensure seamless transition for the users.
Yep, maybe introducing a new configuration option is a good solution. Having that option with default value false will ensure the new version of the plugin will not break existing users and applications. So we need a name for the new option 😸 - maybe As this PR is really important for us and our error handling story, I'll prepare the needed changes once we have an agreement about the name of the new option. |
I would suggest |
We could do... I'm just wondering if it might make more sense to do a breaking changes version? After all, do we want to maintain two behaviours in the long term? If we all agree this is a more sensible behaviour then having a breaking changes version seems like a way to not break existing users and move the plugin in the direction we want to go... Thoughts? |
Hey @piotr-oles, @johnnyreilly It seems we have 2 options:
The both solutions will work for us and will address our problem. However, personally to me, I prefer releasing a major version and introducing it as a breaking change. That will be the most beneficial solution in the long term. Let me know about your decision, so I can apply the required changes on the PR. |
Ok, maybe breaking change is a better option - it will probably not break anything for 99% of users. Please update the documentation (Plugin hooks section) and add BREAKING CHANGE section to the commit message :) |
10273e7
to
83112ba
Compare
I changed the commit message with BREAKING CHANGE: footer and updated the plugin section in the documentation. Let me know if I've missed something or there is something else that I can do. |
Could you catch up this branch with master please? |
83112ba
to
a685243
Compare
I've rebased the PR on the latest master branch. |
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.
Looks good to me!
It seems there are failing CI builds https://travis-ci.org/TypeStrong/fork-ts-checker-webpack-plugin/jobs/602424646?utm_medium=notification&utm_source=github_status:
Maybe we should rerun the travis builds. |
Retriggered. Travis has been pretty flaky this week |
We have a green build! 🎉 Do I need to rebase it again on master as there are additional commits merged into master or you can merge the PR directly? |
Yes please - update the branch! |
The afterCompile hook should be blocked instead of emit in order to handle correctly noEmitOnErrors property from webpack.config.js BREAKING CHANGE: The emit hook is replaced with afterCompile hook.
a685243
to
4562102
Compare
Thank you very much for merging the PR! |
It will be released automatically by |
What about the version - will it be updated to |
🎉 This PR is included in version 2.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
The CI is performing very badly last time - I had to re-run the release job. And yes - as you can see semantic-release do all the magic ✨ 😃 |
Yeep, it's really cool magic! 😃 |
We have a limitation that webpack compilation doesn't stop on error in typescript applications. That was due to the issue in fork-ts-checker-webpack-plugin. After merging [the PR that fixes the issue](TypeStrong/fork-ts-checker-webpack-plugin#337) and releasing 2.0.0 version of the plugin, we can update it on our side and that way webpack compilation will stop on syntax/semantic errors within the application. Rel to: NativeScript/nativescript-cli#3785
Currently noEmitOnErrors property is not respected from webpack compilation in case it is set in
webpack.config.js
. As a result, the files are emitted even when there is an error in the source code. However, it turns out thatts-loader
is working correctly intranspileOnly: false
mode and the problem is only in case whents-loader
is started intranspileOnly: true
+ForkTsCheckerWebpackPlugin
.After investigating the issue, it turns out that the problem is here. Webpack has a logic that checks if the files should be emitted based on
compilation.errors
array. This logic is executed onshouldEmit
hook as can be seen here. So, we need to put our reporteddiagnostics
andlints
incompilation.errors
beforeshouldEmit
.The
afterCompile
hook seems as a perfect solution as it is executed beforeshouldEmit
and is anasync
hook. As supporting this feature is important for our error handling story, we implemented the change, spent a little time testing it and it works for our cases.However, we're not absolutely sure for the impact of the mentioned change so we'd be glad to hear your opinion and suggestions.
Rel to: #57