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

Compile to JavaScript and drop runtime dependency on tsx #850

Closed
mbostock opened this issue Feb 17, 2024 · 2 comments · Fixed by #963
Closed

Compile to JavaScript and drop runtime dependency on tsx #850

mbostock opened this issue Feb 17, 2024 · 2 comments · Fixed by #963
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

I love tsx during development, but I think we should compile to JavaScript on publish and drop the runtime dependency. This would allow us to support Node 18+ instead of requiring Node 20.6+, and it would fix confusing errors such as #847. It would just be “fewer moving parts” and more robust, and it shouldn’t be too technically challenging to run esbuild or tsc or whatever on publish.

@mbostock mbostock added the enhancement New feature or request label Feb 17, 2024
@Fil
Copy link
Contributor

Fil commented Feb 23, 2024

This seems like it would help a lot of people. I've experimented a bit with esbuild:

yarn esbuild --target=esnext --outdir=build/ bin/observable.ts src/**/*{js,ts,css} && cp package.json build`

(You can also add --minify and --sourcemap).

I had to specify, in tsconfig.json:

"module": "nodenext",

so that it would compile with top-level await.

But then when I then run:

node build/bin/observable.js preview

I get errors related to package.json [1]. If I force my way around this problem [2], it then fails on observablehq.config.ts (as it only accepts a js config file). If I rename the config file, I then get another error about package.json [3].

It doesn't seem complicated, it's just that I don't really know ho this is supposed to work. Maybe someone with a better knowledge of esbuild will come up with the best approach.

[1] Unexpected error: The requested module '../package.json' does not provide an export named 'version'
[2] for example, with const {version} = (await import("../package.json", {with: {type: "json"}})).default;
[3] Unexpected error: The requested module './package.json' does not provide an export named 'version'

@mbostock
Copy link
Member Author

mbostock commented Mar 3, 2024

Some things I learned so far in #963:

In general it seems to work well, but the fact that the generated sources live in a different directory I think are going to cause problems for methods such as getClientPath which assume they are in src/client/. I also would like our testing and local development environment to be as close as possible to what we publish, so that we are less likely to have issues that only affect the published distribution. esbuild has some lovely built-in watch and serving features for local development, which makes me wonder if we couldn’t just drop tsx entirely? But I also want to minimize churn, so my primary goal for this week is to get a no-tsx distribution working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants