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

Native: Initialize AtlaspackNative async #402

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alshdavid
Copy link
Contributor

@alshdavid alshdavid commented Mar 28, 2025

Motivation

Lazy initialization of AtlaspackNapi was hiding errors occuring asynchronously. This fixes the watcher hanging, but also Matt's PR bumping the watcher version fixes it too. Por que no los dos?

Changes

  • Updated AtlaspackNapi to have an async constructor
  • Updated AtlaspackNapi to use functions rather than napi methods
  • Re-enabled napi macros (cannot use napi classes until we migrate to napi v3)

Checklist

  • Existing or new tests cover this change
  • There is a changeset for this change, or one is not required

@alshdavid alshdavid requested a review from a team as a code owner March 28, 2025 05:30
Copy link

changeset-bot bot commented Mar 28, 2025

🦋 Changeset detected

Latest commit: dc9c912

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

This PR includes changesets to release 100 packages
Name Type
@atlaspack/rust Major
@atlaspack/integration-tests Patch
@atlaspack/core Patch
@atlaspack/bundler-experimental Patch
@atlaspack/bundler-default Patch
@atlaspack/cache Patch
@atlaspack/fs Patch
@atlaspack/logger Patch
@atlaspack/utils Patch
@atlaspack/optimizer-image Patch
@atlaspack/optimizer-inline-requires Patch
@atlaspack/packager-js Patch
@atlaspack/transformer-html Patch
@atlaspack/transformer-js Patch
@atlaspack/transformer-postcss Patch
@atlaspack/transformer-svg Patch
@atlaspack/node-resolver-core Patch
@atlaspack/cli Patch
@atlaspack/register Patch
@atlaspack/test-utils Patch
@atlaspack/bundle-stats Patch
@atlaspack/query Patch
@atlaspack/reporter-bundle-stats Patch
@atlaspack/config-default Patch
@atlaspack/config-repl Patch
@atlaspack/package-manager Patch
@atlaspack/link Patch
@atlaspack/workers Patch
@atlaspack/watcher-watchman-js Patch
@atlaspack/optimizer-blob-url Patch
@atlaspack/optimizer-css Patch
@atlaspack/optimizer-data-url Patch
@atlaspack/optimizer-svgo Patch
@atlaspack/optimizer-swc Patch
@atlaspack/optimizer-terser Patch
@atlaspack/packager-css Patch
@atlaspack/packager-html Patch
@atlaspack/packager-raw-url Patch
@atlaspack/packager-svg Patch
@atlaspack/packager-webextension Patch
@atlaspack/packager-xml Patch
@atlaspack/reporter-build-metrics Patch
@atlaspack/reporter-bundle-analyzer Patch
@atlaspack/reporter-cli Patch
@atlaspack/reporter-dev-server-sw Patch
@atlaspack/reporter-dev-server Patch
@atlaspack/reporter-json Patch
@atlaspack/reporter-lsp Patch
@atlaspack/reporter-sourcemap-visualiser Patch
@atlaspack/reporter-tracer Patch
@atlaspack/resolver-glob Patch
@atlaspack/runtime-browser-hmr Patch
@atlaspack/runtime-js Patch
@atlaspack/runtime-react-refresh Patch
@atlaspack/runtime-service-worker Patch
@atlaspack/runtime-webextension Patch
@atlaspack/transformer-babel Patch
@atlaspack/transformer-css Patch
@atlaspack/transformer-image Patch
@atlaspack/transformer-posthtml Patch
@atlaspack/transformer-react-refresh-wrap Patch
@atlaspack/transformer-typescript-types Patch
@atlaspack/transformer-webextension Patch
@atlaspack/transformer-webmanifest Patch
@atlaspack/validator-eslint Patch
@atlaspack/validator-typescript Patch
@atlaspack/resolver-default Patch
@atlaspack/config-webextension Patch
@atlaspack/types Patch
@atlaspack/plugin Patch
@atlaspack/transformer-jsonld Patch
@atlaspack/bundler-library Patch
@atlaspack/compressor-brotli Patch
@atlaspack/compressor-gzip Patch
@atlaspack/compressor-raw Patch
@atlaspack/namer-default Patch
@atlaspack/optimizer-cssnano Patch
@atlaspack/optimizer-htmlnano Patch
@atlaspack/packager-raw Patch
@atlaspack/packager-ts Patch
@atlaspack/packager-wasm Patch
@atlaspack/reporter-bundle-buddy Patch
@atlaspack/reporter-conditional-manifest Patch
@atlaspack/resolver-repl-runtimes Patch
@atlaspack/transformer-glsl Patch
@atlaspack/transformer-graphql Patch
@atlaspack/transformer-inline-string Patch
@atlaspack/transformer-inline Patch
@atlaspack/transformer-json Patch
@atlaspack/transformer-less Patch
@atlaspack/transformer-mdx Patch
@atlaspack/transformer-pug Patch
@atlaspack/transformer-raw Patch
@atlaspack/transformer-sass Patch
@atlaspack/transformer-svg-react Patch
@atlaspack/transformer-toml Patch
@atlaspack/transformer-typescript-tsc Patch
@atlaspack/transformer-worklet Patch
@atlaspack/transformer-xml Patch
@atlaspack/transformer-yaml 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

@alshdavid alshdavid force-pushed the alsh/async-native-constructor branch from 65c565b to b9fdede Compare March 28, 2025 05:30
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be initialized synchronously now, no need for any channel shenanigans

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪦

@@ -66,6 +82,6 @@ export class AtlaspackV3 {
}

respondToFsEvents(events: Array<Event>): boolean {
return this._internal.respondToFsEvents(events);
return atlaspackNapiRespondToFsEvents(this._atlaspack_napi, events);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you opt for functions instead of adding to the _atlaspack_napi instance like before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

napi-rs V2 has broken macros for napi classes requring us to disable macro expansion in our LSPs. This results in incorrect intelisense and limits the napi features we can use. For instance; the boilerplate in this section of code could all be handled by the macro but without macro expansion we cannot use it.

I'd like to turn macro expansion back on and to do that we either need to:

  • Migrate to napi-rs v3 (which is still in alpha)
  • Avoid the use of napi-rs classes (recreating them in the JS layer)

Personally, I'm okay with migrating to v3, even if it's in alpha, but I am not sure how much work is needed for the migration and if the team is comfortable with pre-release software.

@alshdavid alshdavid force-pushed the alsh/async-native-constructor branch from db6c2ee to e5d870a Compare March 30, 2025 21:26
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.

3 participants