Skip to content

Commit b0ad1df

Browse files
ryansolidclaude
andauthored
fix(compiler): WASI loc paths and directive hashes ignore the binding's cwd (#4173)
A WASI binding starts at `/`, so `relative_id` resolved an absolute filename with no `root` against the wrong directory: `loc` paths came out as `home/runner/.../src/store.ts`, and the release's WASI test failed (source-names.test.js, "the path is relative to `root`"). The JS entry now hands transform, transformDirectives and transformSourceNames a `root` that needs no working directory: absolute beside an absolute filename, relative beside a relative one. Native results are unchanged. Claude-Session: https://claude.ai/code/session_018LY7F9czoRqdMEvk2QwPr1 Co-authored-by: Claude <[email protected]>
1 parent 47c745c commit b0ad1df

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎packages/compiler/index.js‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function transform(code, options) {
1010
throw new TypeError("@solidjs/compiler transform() expects source code as a string");
1111
}
1212

13-
const nativeOptions = validateOptions(code, options);
13+
const nativeOptions = hostRoot(validateOptions(code, options));
1414
const result = native.transform(code, nativeOptions);
1515
const output = {
1616
code: result.code,
@@ -71,7 +71,7 @@ function transformDirectives(code, options) {
7171
throw new TypeError("@solidjs/compiler transformDirectives() expects source code as a string");
7272
}
7373

74-
const nativeOptions = validateDirectivesOptions(options);
74+
const nativeOptions = hostRoot(validateDirectivesOptions(options));
7575
const result = native.transformDirectives(code, nativeOptions);
7676
return {
7777
code: result.code,
@@ -124,7 +124,7 @@ function transformSourceNames(code, options) {
124124
throw new TypeError("@solidjs/compiler transformSourceNames() expects source code as a string");
125125
}
126126

127-
const nativeOptions = validateSourceNamesOptions(options);
127+
const nativeOptions = hostRoot(validateSourceNamesOptions(options));
128128
const result = native.transformSourceNames(code, nativeOptions);
129129
return {
130130
code: result.code,
@@ -445,6 +445,23 @@ function tryPackage(packageName) {
445445
}
446446
}
447447

448+
// The binding makes `filename` relative to `root` (`loc` paths, directive
449+
// hashes), resolving both against its own working directory. A WASI binding
450+
// cannot see the host's (it starts at `/`), so hand it a `root` that needs
451+
// none: absolute beside an absolute filename (the working directory when
452+
// unset), relative beside a relative one. The result is unchanged on a native
453+
// binding.
454+
function hostRoot(nativeOptions) {
455+
if (nativeOptions == null || typeof nativeOptions.filename !== "string") return nativeOptions;
456+
const { filename, root } = nativeOptions;
457+
if (path.isAbsolute(filename)) {
458+
nativeOptions.root = path.resolve(root ?? ".");
459+
} else if (root !== undefined && path.isAbsolute(root)) {
460+
nativeOptions.root = path.relative(process.cwd(), root) || ".";
461+
}
462+
return nativeOptions;
463+
}
464+
448465
function requireBinding() {
449466
const explicit = process.env.SOLID_COMPILER_NATIVE;
450467
if (explicit) return require(explicit);

0 commit comments

Comments
 (0)