-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
Build: create a tsc prepare script, use it for angular framework, add ESM to angular dist #20516
Conversation
ts.createProgram({ | ||
rootNames: out.fileNames, | ||
options: { ...compilerOptions, module: ts.ModuleKind.ES2020, declaration: false }, | ||
}).emit(); | ||
|
||
const files = glob.sync(join(process.cwd(), 'dist', '*.js')); | ||
await Promise.all(files.map((file) => move(file, file.replace('.js', '.mjs'), {}))); |
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'm planning on improving this, the compiler host has the ability to override the writeFile method, which would allow me to write the file with a different extension than the one tsc wants to write... this would also be the way to get the watch-mode to work, most likely.
); | ||
|
||
const compilerOptions = out.options; | ||
|
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 know what you're thinking: why not simply use a child_process and spawn tsc
CLI? That's going to be about a second slower, starting node.
But I'm considering doing it anyway, because typescript's API are all sync and blocking, thus generating both CJS and ESM, can only be done 1 after the other, not in parallel. So perhaps it balances out, and spawning 2 subprocesses is actually faster... :(
|
||
const reset = hasFlag(flags, 'reset'); | ||
const watch = hasFlag(flags, 'watch'); | ||
// const optimized = hasFlag(flags, 'optimized'); |
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.
tsc has no concept/feature of minification, so we'd have to use another tool on top, which might break stuff.. so I'm going to say let's just skip it for now, not take the risk.
I found the documentation for how to use this here: |
What I did
I created a script that mimicks the bundle script, but using tsc directly.
This is useful to have more control over the build process for packages that need to be compiled using tsc (angular).
This adds some improvements, such as:
Known issues:
I converted the angular framework to use this new script.