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

Core: Async load presets, replace interpret with esbuild-register #18619

Merged
merged 3 commits into from
Jul 8, 2022

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Jul 1, 2022

@tmeasday this kinda replaces your PR: #18025

It does not preserve the import(), but that's because there's no way to make that work with TypeScript AFAICS.

This adds an esbuild-register as soon as it's needed, but only once; this mutates the require method in Node to run code through esbuild (which does support TypeScript and other stuff.

I need to experiment more, but this also seems much faster!

@shilman the removes the interpreter "nonsense", too..

@nx-cloud
Copy link

nx-cloud bot commented Jul 1, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 645e1b8. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@ndelangen ndelangen changed the base branch from next to future/base July 1, 2022 16:45
@ndelangen ndelangen self-assigned this Jul 1, 2022
@ndelangen ndelangen requested review from shilman, tmeasday and IanVS and removed request for shilman July 1, 2022 16:45
@ndelangen ndelangen added the maintenance User-facing maintenance tasks label Jul 1, 2022
@ndelangen ndelangen changed the base branch from future/base to future/pbm/stage0 July 1, 2022 19:27
@tmeasday
Copy link
Member

tmeasday commented Jul 4, 2022

@ndelangen so does this mean at the point we first require a user file we register esbuild and then from then on everything that gets required (including our own code) gets passed through it?

I guess in node, everything of our own will have already been required before this point (no code splitting or async imports). I guess I am just a tiny bit concerned about inconsistencies of in some circumstances importing our code through esbuild and in others not. What's your thinking here @ndelangen?

@ndelangen
Copy link
Member Author

Every time a user's file get loaded I register the esbuild-register, then when it's loaded I unload it.

@tmeasday
Copy link
Member

tmeasday commented Jul 4, 2022

then when it's loaded I unload it.

How are you doing that? I'm not seeing it..?

@ndelangen
Copy link
Member Author

Hmm, I must have undone that work for some reason @tmeasday I'll change it to what I had.

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

LGTM!

@IanVS
Copy link
Member

IanVS commented Jul 6, 2022

I'd love to test this out in my vite project, but as far as I know, the future branch is not compatible with the vite-builder, right?

Base automatically changed from future/pbm/stage0 to future/base July 6, 2022 10:48
@ndelangen ndelangen changed the base branch from future/base to future/prep-for-esbuild-register July 6, 2022 12:22
@ndelangen ndelangen force-pushed the future/async-load-presets-esbuild-register branch from 2c04a75 to fba9296 Compare July 6, 2022 12:52
…d-presets-esbuild-register

# Conflicts:
#	lib/core-common/src/presets.ts
#	lib/core-common/src/utils/interpret-require.ts
@ndelangen
Copy link
Member Author

@tmeasday I think there's race conditions when registering and unregistering the esbuild loader in storyshots.

😢

@ndelangen
Copy link
Member Author

the interpret package didn't unregister either btw

Base automatically changed from future/prep-for-esbuild-register to future/base July 6, 2022 13:21
ndelangen added a commit that referenced this pull request Jul 6, 2022
@ndelangen
Copy link
Member Author

@tmeasday I agree with you that registering and then unregistering is better, and safer. But somehow storyshots is dependent on the registering happening globally and staying registered.
This is also what happened with the interpret package.

I do not want to invest any time into storyshots, mainly because I'd rather work on improving testing library to replace it.
But also I'm getting absolutely NO, ZERO indication where the problem is from storyshots. Pinning it down is going to eat away my time and energy.

I propose we merge as is.

@ndelangen ndelangen requested a review from tmeasday July 6, 2022 13:43
@ndelangen ndelangen added the core label Jul 6, 2022
@tmeasday
Copy link
Member

tmeasday commented Jul 7, 2022

@ndelangen I would be happy to spend some time investigating, I've seen errors like this from SS before and I generally have figured them out.

However, I did:

git checkout 18064b2
yarn bootstrap --core
yarn test

and all the tests passed 🤷

I'll rerun the job in CI.

@ndelangen
Copy link
Member Author

I also could not reproduce locally, at first, then after some trial and error I could get some story shots test to fail, but when running them in isolation they'd succeed.

@tmeasday
Copy link
Member

tmeasday commented Jul 8, 2022

As discussed I think the register-once approach is probably better anyway. I would consider registering right at the start, rather than when we load our first user file; but if that's what we were doing before it's probably fine.

@shilman shilman changed the title Future - async load presets esbuild register Core: Async load presets, replace interpret with esbuild-register Jul 8, 2022
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Super excited about this @ndelangen 🚀

@shilman shilman merged commit b9efb25 into future/base Jul 8, 2022
@shilman shilman deleted the future/async-load-presets-esbuild-register branch July 8, 2022 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants