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

tests: fix loading wasm when targeting external deps #94

Merged
merged 2 commits into from Apr 28, 2024

Conversation

mochaaP
Copy link
Contributor

@mochaaP mochaaP commented Apr 28, 2024

  • tests: fix loading wasm when targeting external deps
  • Revert "fix: cannot resolve path when build with EXTERNAL_PATH"

Follow up of #91 and #93.

@mochaaP
Copy link
Contributor Author

mochaaP commented Apr 28, 2024

I'm sincerely sorry for the noise this caused 😅

@guybedford guybedford merged commit bcc6ce4 into nodejs:main Apr 28, 2024
1 check passed
guybedford added a commit that referenced this pull request Apr 28, 2024
@guybedford
Copy link
Collaborator

Actually I'm just very confused about what is going on here now - EXTERNAL_PATH is no longer being used as a runtime variable, but instead is being used as a define variable that is a string that is only used as a boolean check and not as a string.

But it is both a build environment variable and a define variable by name.

And in the build, we inline that path as an absolute path, while in the runtime the assumption is that lib/lexer.wasm is available relative to the build file?

And then we also wrap the entry point for the package for some kind of lazy wrapping as well as altering the main distribution file?

This is all just very very very convoluted, and I trusted that it would work but it clearly doesn't.

I've put together a revert PR in #95, to remove these build changes entirely.

guybedford added a commit that referenced this pull request Apr 28, 2024
* Revert "tests: fix loading wasm when targeting external deps (#94)"

This reverts commit bcc6ce4.

* Revert "fix: cannot resolve path when build with EXTERNAL_PATH (#93)"

This reverts commit 8ea767a.

* Revert "Support building for externally shared js builtins (#91)"

This reverts commit 1c5072c.
@mochaaP
Copy link
Contributor Author

mochaaP commented Apr 28, 2024

EXTERNAL_PATH is no longer being used as a runtime variable, but instead is being used as a define variable that is a string that is only used as a boolean check and not as a string.

It was never a runtime variable. The purpose of this is to enable externalized build, and build dist/lexer.js as a loader of EXTERNAL_PATH/dist/lexer.mjs, since node could not resolve filesystem paths with external builtins. It was not exported by package.json nor imported by tests. It's only accessed when referenced from node's build process.

while in the runtime the assumption is that lib/lexer.wasm is available relative to the build file?

The relative path change was done to make sure a single external build can handle the reading of lexer.wasm both in-tree and installed to EXTERNAL_PATH.

I understand the efforts you put into this, and the necessity to make things simpler. But based on the reasons above, #95 is, unfortunately, not a choice here.

@guybedford
Copy link
Collaborator

The relative path change was done to make sure a single external build can handle the reading of lexer.wasm both in-tree and installed to EXTERNAL_PATH.

There is no variable in https://github.com/nodejs/cjs-module-lexer/pull/94/files#diff-7d867ca4df223e0c07d997702e598243e0644cb647e57d8363a6652a8888cf1fR97, so how is this the case in the code?

@mochaaP
Copy link
Contributor Author

mochaaP commented Apr 28, 2024

A step by step breakdown:

  • when required in-tree (e.g., from test/_unit.js)

    • await import('../dist/lexer.mjs');
    • (in dist/lexer.mjs) import.meta.resolve('.') == "file:///path/to/your/repo/dist/lexer.mjs"
    • import.meta.resolve('../lib/lexer.wasm')
    • "file:///path/to/your/repo/lib/lexer.wasm"
  • when required as an externalized builtin (from node)

    • require('internal/deps/cjs-module-lexer/dist/lexer');
    • (in EXTERNAL_PATH/dist/lexer.js) node:module magic

      ℹ️ to let dist/lexer.js believe it's loaded as EXTERNAL_PATH/dist/lexer.js instead of as an external, in order not to lose the path context. [this is the only difference]

    • import('./lexer.mjs') (import.meta is already setup correctly here, so we can do relative path stuff safely)
    • import.meta.resolve('../lib/lexer.wasm')
    • "file:///EXTERNAL_PATH/lib/lexer.wasm"

@guybedford
Copy link
Collaborator

Thanks for clarifying, if you're doing internal module hooks to alter internal resolution rules, then this pattern needs to be clearly identified and described as part of this work.

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.

None yet

2 participants