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

feat(sync): Add a sync and CJS entrypoint for editor tooling #772

Merged
merged 6 commits into from
Apr 18, 2023

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Apr 9, 2023

Changes

TypeScript unfortunately does not support running async methods inside its LanguageService API, so our language server needs a sync version of the compiler. Since WASM instantiation is async only, you still need at least one async init call, but then you can use all the methods sync. It's not perfect, but it at leasts allows us to not rely on synckit, which makes things slow

Why the separate file? index.ts has a call to import.meta.url, which prevented my CJS-based application to even import the file. Annoying. ESM in VS Code extensions when 😠

Testing

Tested manually

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Apr 9, 2023

🦋 Changeset detected

Latest commit: be6c3b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Princesseuh
Copy link
Member Author

!preview sync

@github-actions
Copy link
Contributor

github-actions bot commented Apr 9, 2023

 > root@0.0.0 release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--sync" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--sync tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 warn @astrojs/compiler is not being published because version 1.3.1 is already published on npm 🦋 warn No unpublished projects to publish

@Princesseuh
Copy link
Member Author

!preview sync

@github-actions
Copy link
Contributor

github-actions bot commented Apr 9, 2023

 > root@0.0.0 release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--sync" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--sync tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-sync-20230409173822) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-sync-20230409173822" 🦋 success packages published successfully: 🦋 @astrojs/compiler@0.0.0-sync-20230409173822 🦋 Creating git tag... 🦋 New tag: @astrojs/compiler@0.0.0-sync-20230409173822

@bluwy
Copy link
Member

bluwy commented Apr 10, 2023

I believe es-module-lexer has this pattern too, where you can call await init so that the rest of the functions are sync. If init isn't called before, the first function call would return a promise as fallback. Maybe we can also have this same flow for both ESM and CJS.

@Princesseuh
Copy link
Member Author

!preview sync

@Princesseuh Princesseuh changed the title feat(sync): Add a sync version of transform, parse, convertToTSX etc feat(sync): Add a sync and CJS entrypoint for editor tooling Apr 18, 2023
@github-actions
Copy link
Contributor

 > root@0.0.0 release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--sync" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--sync tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-sync-20230418112509) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-sync-20230418112509" 🦋 success packages published successfully: 🦋 @astrojs/compiler@0.0.0-sync-20230418112509 🦋 Creating git tag... 🦋 New tag: @astrojs/compiler@0.0.0-sync-20230418112509

@Princesseuh
Copy link
Member Author

!preview sync

@github-actions
Copy link
Contributor

 > root@0.0.0 release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--sync" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--sync tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-sync-20230418114635) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-sync-20230418114635" 🦋 success packages published successfully: 🦋 @astrojs/compiler@0.0.0-sync-20230418114635 🦋 Creating git tag... 🦋 New tag: @astrojs/compiler@0.0.0-sync-20230418114635

packages/compiler/node/sync.cts Show resolved Hide resolved
packages/compiler/node/sync.cts Outdated Show resolved Hide resolved
@Princesseuh
Copy link
Member Author

!preview sync

@github-actions
Copy link
Contributor

 > root@0.0.0 release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--sync" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--sync tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-sync-20230418131144) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-sync-20230418131144" 🦋 success packages published successfully: 🦋 @astrojs/compiler@0.0.0-sync-20230418131144 🦋 Creating git tag... 🦋 New tag: @astrojs/compiler@0.0.0-sync-20230418131144

@Princesseuh Princesseuh merged commit b0e0cfd into main Apr 18, 2023
@Princesseuh Princesseuh deleted the feat/sync branch April 18, 2023 13:37
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