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

fix(turbopack-node) postcss.config.js path resolution on Windows #7995

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/turbopack-node/src/transforms/postcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,18 @@ pub(crate) async fn config_loader_source(
// Bundling would break the ability to use `require.resolve` in the config file.
let code = formatdoc! {
r#"
const configPath = `${{process.cwd()}}/{config_path}`;
import {{ pathToFileURL }} from 'url';
const mod = await __turbopack_external_import__(configPath);
const configPath = `${{process.cwd()}}/${{{config_path}}}`;
Copy link
Member

Choose a reason for hiding this comment

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

This would better use path.join since the / is technically not the correct path separator on windows.

Copy link
Member Author

@bgw bgw Apr 19, 2024

Choose a reason for hiding this comment

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

@sokra I was trying to keep the change small, and I saw in the node documentation that:

On Windows, both the forward slash (/) and backward slash () are accepted as path segment separators; however, the path methods only add backward slashes ().

If you'd like, I can submit a follow-up PR.

Edit: #8105

// Absolute paths don't work with ESM imports on Windows:
// https://github.com/nodejs/node/issues/31710
// convert it to a file:// URL, which works on all platforms
const configUrl = pathToFileURL(configPath).toString();
const mod = await __turbopack_external_import__(configUrl);
export default mod.default ?? mod;
"#,
config_path = config_path,
config_path = serde_json::to_string(&config_path).expect("a string should be serializable"),
};

Ok(Vc::upcast(VirtualSource::new(
Expand Down
Loading