Skip to content
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

all: change approach to extensions on imports #716

Merged

Conversation

allisonkarlitskaya
Copy link
Member

It's currently not possible to run ./build.js under node-22, which is a shame, because we'll want to be able to do that soon (due to upcoming TypeScript support, which will let us stop using tsx and its bundled copy of esbuild, simplifying builds on arm64).

Reading the developments on the addition of TypeScript support to Node, it seems to be the case that TypeScript is somewhat isolated in their opinion on the correct approach for handling extensions on import statements. Indeed, node-22 will outright break if we don't use extensions correctly.

Add back the extensions that we removed from the files in our build process. Change our use of the eslint rule to require extensions, rather than forbid them, and update our code accordingly. Updating our bundled code is not strictly necessary (and we could just drop the eslint rule entirely) but let's be consistent.

Add an option to our tsconfig to tell TypeScript that we want to do things node's way.

@allisonkarlitskaya allisonkarlitskaya force-pushed the revisit-extensions branch 2 times, most recently from 7c2bd1b to 5f6ad52 Compare August 20, 2024 12:43
It's currently not possible to run ./build.js under node-22, which is a
shame, because we'll want to be able to do that soon (due to upcoming
TypeScript support, which will let us stop using tsx and its bundled
copy of esbuild, simplifying builds on arm64).

Reading the developments on the addition of TypeScript support to Node,
it seems to be the case that TypeScript is somewhat isolated in their
opinion on the correct approach for handling extensions on import
statements.  Indeed, node-22 will outright break if we don't use
extensions correctly.

Add back the extensions that we removed from the files in our build
process.  Change our use of the eslint rule to *require* extensions,
rather than forbid them, and update our code accordingly.  Updating our
bundled code is not strictly necessary (and we could just drop the
eslint rule entirely) but let's be consistent.

Add an option to our tsconfig to tell TypeScript that we want to do
things node's way.
Modern versions of node require `with { type: 'json' };` on JSON
imports.  `tsc` doesn't like this with its default module system (which
is commonjs) so use "preserve", which is the recommended setting for
bundler setups, anyway.

Also add some `import type` vs. `import` cleanups: I used to think this
was excessively pedantic, but getting this right is necessary for using
`--experimental-transform-types`.

With these changes it's possible to run the build system under nodejs-22
as is currently available in Fedora.  It's also possible to run it with
a currently nightly build of nodejs, without tsx:

    node-22 --experimental-transform-types ./build.js
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to make an intelligent face

Thanks!

@allisonkarlitskaya
Copy link
Member Author

Copr is currently experiencing issues. We are working on the fix.

I guess that explains why the builds haven't been picked up for over an hour...

@allisonkarlitskaya allisonkarlitskaya merged commit 093d865 into cockpit-project:main Aug 20, 2024
13 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants