Repository navigation
NXT-20659: Adapt ui and ss tests jobs to work with typescript - #403
Closed
alexandrumorariu wants to merge 3 commits into
Closed
alexandrumorariu wants to merge 3 commits into
alexandrumorariu wants to merge 3 commits into
Conversation
…g a build
* Skip fork-ts-checker (in-build type checking) when TypeScript >= 7 is installed. TypeScript 7
no longer provides the classic JavaScript API it needs, and has no `main` entry for `resolve`,
so `resolve.sync('typescript')` threw "Cannot find module 'typescript'" whenever a project had
a tsconfig.json.
* Run `api()` inside the promise chain in `pack` and `serve` so errors thrown synchronously while
preparing the build are reported and exit non-zero. Previously they became an uncaught
exception that bin/enact.js logs and swallows, so `enact pack` exited 0 without writing any
output and callers saw only a confusing follow-on failure (e.g. ENOENT on the output folder).
Contributor
|
closing as duplicate of #401 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Issue Resolved / Feature Added
enact pack does not work in a project that has a tsconfig.json and TypeScript 7 installed. Instead of failing, it exits with status 0 and writes no output at all, so the failure only shows up later in whatever called it.
Seen in @enact/ui-test-utils (start-tests), which builds an Enact framework bundle with enact pack --framework and then creates dist/framework/ilib:
Enact framework bundle... DONE
Build failed: ENOENT: no such file or directory, mkdir 'tests/screenshot/dist/framework/ilib'
There are two separate causes:
TypeScript 7 is not supported. When tsconfig.json exists, config/webpack.config.js enables in-build type checking (fork-ts-checker) and locates TypeScript with resolve.sync('typescript', {basedir: 'node_modules'}). That throws Cannot find module 'typescript' for TypeScript 7, because its package has no main entry. It would not help to fix the lookup alone: the root export of TypeScript 7 no longer exposes the classic JavaScript API (ts.createProgram, etc.) that fork-ts-checker is built on.
The error is swallowed. pack/serve call api(opts) inside a .then() callback. A synchronous throw while creating the webpack config rejects that outer promise, which nothing handles. bin/enact.js registers an uncaughtException handler that only logs the stack, so the process then exits with status 0. Callers that only check the exit code (and discard stderr when it is 0, as ui-test-utils does) see a successful build.
Resolution
config/webpack.config.js: added hasTypeScriptJsApi(). The ForkTsCheckerWebpackPlugin is only created when the installed TypeScript is older than 7. For TypeScript 7+ a one-line notice is printed and in-build type checking is skipped. Source files are still transpiled by Babel as before. If TypeScript is not installed at all, the existing Cannot find module 'typescript' error is still raised instead of being skipped.
commands/pack.js, commands/serve.js: api(opts) now runs inside the promise chain (Promise.resolve().then(() => api(opts)).catch(...)), so errors thrown while preparing the build are reported through the existing error handling and exit with status 1.
CHANGELOG.md: entries added under unreleased (pack, serve).
No dependency changes; package.json and npm-shrinkwrap.json are unchanged.
Additional Considerations
Behavior changes to be aware of
With TypeScript 7+, type errors are no longer reported during enact pack. They need to be caught by running tsc separately. With TypeScript < 7 nothing changes.
Errors thrown while preparing a build now cause a non-zero exit status. Setups that previously "passed" because of the swallowed error were not producing any output, but they will now fail visibly.
How to test
Create a project with a tsconfig.json and typescript@7 installed (for example npm install -D typescript@7) and run enact pack --framework --output dist/framework --externals-polyfill (or enact pack on a normal app).
Before: exit status 0, no dist folder, error only on stderr.
After: the build runs, prints TypeScript 7.x detected: skipping in-build type checking, and writes enact.js/enact.css.
Remove typescript from node_modules and run enact pack again. It should print Failed to compile. Cannot find module 'typescript' from 'node_modules' and exit with status 1.
With typescript@6, put a deliberate type error in a file under src/ and run enact pack --production. It should still fail with TS2322, as before.
Links
NXT-20659
Comments
Type checking under TypeScript 7 would need a different checker than fork-ts-checker. That is not part of this change, which only stops the build from failing.