Unverified Commit f6557ffc authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: fix `sideEffects` matching for non-relative globs (#77693)

Previously, `"sideEffects": ["lib/common.js"]` never matched.

Closes #66348
Closes PACK-4241
parent a14d0137
......@@ -50,7 +50,9 @@ async fn side_effects_from_package_json(
.filter_map(|side_effect| {
if let Some(side_effect) = side_effect.as_str() {
if side_effect.contains('/') {
Some(Glob::new(side_effect.into()))
Some(Glob::new(
side_effect.strip_prefix("./").unwrap_or(side_effect).into(),
))
} else {
Some(Glob::new(format!("**/{side_effect}").into()))
}
......@@ -179,7 +181,8 @@ pub async fn is_marked_as_side_effect_free(
.await?
.get_relative_path_to(&*path.await?)
{
return Ok(Vc::cell(!glob.await?.execute(&rel_path)));
let rel_path = rel_path.strip_prefix("./").unwrap_or(&rel_path);
return Ok(Vc::cell(!glob.await?.execute(rel_path)));
}
}
}
......
......@@ -102,7 +102,12 @@ import { effects } from "package-partial/effect";
it("should handle globs in sideEffects field", () => {
expect(a9).toBe("a");
expect(b9).toBe("b");
expect(effects).toEqual(["file.side.js", "dir/file.js"]);
expect(effects).toEqual([
"file.side.js",
"sub/file.side.js",
"sub/bare.js",
"dir/file.js"
]);
});
it("should generate a correct facade from async modules", async () => {
......
......@@ -5,6 +5,9 @@ export * from "./not-compiled.js";
// export * from "./not-existing.js";
export * from "./not-executed.js";
export * from "./file.side.js";
export * from "./sub/file.side.js";
export * from "./sub/bare.js";
export { named } from "./dir/file.js";
export { a } from "./a.js";
export { b } from "./b.js";
import { effects } from "../effect.js";
export const bare = "bare";
effects.push("sub/bare.js");
import { effects } from "../effect.js";
export const namedDir = "named-dir";
effects.push("sub/file.side.js");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment