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(runtime): align import.meta.resolve with node.js's implementation #5827

Merged
merged 29 commits into from
Apr 1, 2024

Conversation

paperdave
Copy link
Member

What does this PR do?

Closes #2472

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

@paperdave paperdave changed the title Dave/import.meta.resolve feat(runtime): align import.meta.resolve with node.js's implementation Sep 20, 2023

/**
* Resolve a module ID the same as if you imported it
*
* The `parent` argument is optional, and defaults to the current module's path.
*
* Will throw if the module does not exist.

Choose a reason for hiding this comment

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

Erm... it should not throw an error if you do:

import.meta.resolve('./this-file-dose-not-exist.md') // or
import.meta.resolve('./this-dir-dose-not-exist')

That is not how Deno, browser or NodeJS works right now.
if the module can't be resolved by looking at some import-map or some package.json
then it should just return the relative string.

Copy link
Member Author

Choose a reason for hiding this comment

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

this documentation is for resolveSync not resolve

auto specifier = specifierValue.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(JSC::JSValue {}));

// Node.js allows a second argument for parent

Choose a reason for hiding this comment

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

only behind a flag. it's likely that NodeJS will not support a 2nd argument for import.meta.resolve as they want to align with Deno and Browser that dose not support a 2nd argument.

Copy link

Choose a reason for hiding this comment

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

I think as of v20.11.1, import.meta.resolve supports second argument (also for what is worth, if it is not supported, tooling support would be hell considering a module cannot resolve on behalf of another)

Copy link
Member Author

@paperdave paperdave Feb 21, 2024

Choose a reason for hiding this comment

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

it is still behind a flag: --experimental-import-meta-resolve

since we do not have node's feature flags, i think this is ok to just have, but it can just not be present in the typescript definitions

Copy link
Contributor

github-actions bot commented Feb 22, 2024

Copy link
Contributor

github-actions bot commented Feb 22, 2024

@paperdave paperdave marked this pull request as ready for review March 11, 2024 20:38
autofix-ci bot and others added 2 commits March 30, 2024 00:01
* fix canceled onFileRead

* report continue errors and fix closing

* also fix pipe writer

* avoid possible memory leaks

* Propagate errors in open

---------

Co-authored-by: Jarred Sumner <[email protected]>
@paperdave
Copy link
Member Author

posix test failrues

test/bundler/bundler_compile.test.ts
test/js/bun/plugin/plugins.test.ts
test/transpiler/macro-test.test.ts

window test failure

test\js\bun\resolve\import-meta-resolve.test.mjs

@paperdave
Copy link
Member Author

test\bundler\bundler_compile.test.ts panics on windows

@Jarred-Sumner Jarred-Sumner merged commit 9e6e8b0 into main Apr 1, 2024
26 of 32 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dave/import.meta.resolve branch April 1, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement synchronous import.meta.resolve(…)
6 participants