Skip to content

feat: Support import.meta.filename/dirname/resolve #10573

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

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

Conversation

magic-akari
Copy link
Contributor

@magic-akari magic-akari commented Jun 5, 2025

Summary

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for rspack ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 561581e
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6842528a9e59f900083045f4
😎 Deploy Preview https://deploy-preview-10573--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Jun 5, 2025
Copy link

codspeed-hq bot commented Jun 5, 2025

CodSpeed Performance Report

Merging #10573 will not alter performance

Comparing magic-akari:fix/issue-8008 (561581e) with main (40f964e)

Summary

✅ 12 untouched benchmarks

@magic-akari
Copy link
Contributor Author

magic-akari commented Jun 5, 2025

I haven't yet implemented import.meta.resolve, which provides functionality similar to require.resolve but follows ESM resolution rules.
Since we're currently unsure about the best approach to implement this (and would welcome insights if you have them), I've decided to hold off on implementation for now.

done.

@magic-akari
Copy link
Contributor Author

magic-akari commented Jun 5, 2025

On Windows CI, import.meta.url handles file paths differently (using three slashes versus two). Since this PR doesn't address that specific behavior, we'll defer fixing it for now.

- 	expect('file://<TEST_TOOLS_ROOT>/tests/builtinCases/plugin-javascript/import-meta/index.js').toBe(url);
- 	expect('file://<TEST_TOOLS_ROOT>/tests/builtinCases/plugin-javascript/import-meta/index.js').toBe(url);
- 	expect("my" + 'file://<TEST_TOOLS_ROOT>/tests/builtinCases/plugin-javascript/import-meta/index.js').toBe("my" + url);
+ 	expect('file:///<TEST_TOOLS_ROOT>/tests/builtinCases/plugin-javascript/import-meta/index.js').toBe(url);
+ 	expect('file:///<TEST_TOOLS_ROOT>/tests/builtinCases/plugin-javascript/import-meta/index.js').toBe(url);
+ 	expect("my" + 'file:///<TEST_TOOLS_ROOT>/tests/builtinCases/plugin-javascript/import-meta/index.js').toBe("my" + url);

@magic-akari magic-akari changed the title feat: Support import.meta.filename and import.meta.dirname feat: Support import.meta.filename/dirname/resolve Jun 5, 2025
@magic-akari magic-akari marked this pull request as ready for review June 5, 2025 08:47
@magic-akari magic-akari marked this pull request as draft June 6, 2025 02:18
"./tests/builtinCases/plugin-javascript/import-meta/index.js",
).toString();

const filename = "/index.js";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears that __filename is handled by crates/rspack_plugin_rstest/src/parser_plugin.rs using a different strategy.

@magic-akari magic-akari marked this pull request as ready for review June 6, 2025 02:57
.to_string()
}

// This is the same as the url.fileURLToPath() of the import.meta.url
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using PathBuf::from directly might be more efficient. However, considering that the Resource might contain a query string – which can introduce various edge cases like ./x.js?foo=/../y.js – processing it through a URL parser is safer.

/// Resource with absolute path, query and fragment
pub resource: String,

@chenjiahan chenjiahan requested review from LingyuCoder and h-a-n-a and removed request for LingyuCoder June 11, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support import.meta.resolve + Node Specific Meta Values
1 participant