Skip to content

Commit 4bf15d6

Browse files
authored
fix bug for file paths in windows during componentization (#213)
Also changes CI to run tests on Windows and macOS in addition to Linux.
1 parent 246e4da commit 4bf15d6

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
########
133133

134134
test:
135-
runs-on: ubuntu-latest
135+
runs-on: ${{ matrix.os }}
136136
needs:
137137
- build
138138
strategy:
@@ -141,6 +141,10 @@ jobs:
141141
node-version:
142142
- '23.10.0'
143143
# - latest reenable when https://github.com/nodejs/node/issues/57172 is fixed
144+
os:
145+
- ubuntu-latest
146+
- windows-latest
147+
- macos-latest
144148
build-type:
145149
- 'release'
146150
- 'debug'
@@ -156,6 +160,7 @@ jobs:
156160
uses: actions/cache/restore@v4
157161
id: restore-starlingmonkey-jit-build
158162
with:
163+
enableCrossOsArchive: true
159164
key: starlingmonkey-${{matrix.build-type}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
160165
path: lib
161166

package-lock.json

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@bytecodealliance/preview2-shim": "^0.17.1",
16+
"cross-env": "^7.0.3",
1617
"mocha": "^11.1.0"
1718
},
1819
"dependencies": {
@@ -31,8 +32,8 @@
3132
"build:debug": "make debug",
3233
"test": "mocha -u tdd test/test.js --timeout 120000",
3334
"test:release": "mocha -u tdd test/test.js --timeout 120000",
34-
"test:weval": "WEVAL_TEST=1 mocha -u tdd test/test.js --timeout 120000",
35-
"test:debug": "DEBUG_TEST=1 mocha -u tdd test/test.js --timeout 120000",
35+
"test:weval": "cross-env WEVAL_TEST=1 mocha -u tdd test/test.js --timeout 120000",
36+
"test:debug": "cross-env DEBUG_TEST=1 mocha -u tdd test/test.js --timeout 120000",
3637
"prepublishOnly": "npm run build"
3738
},
3839
"files": [
@@ -48,4 +49,4 @@
4849
"workspaces": [
4950
"."
5051
]
51-
}
52+
}

src/componentize.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ const isWindows = platform === 'win32';
2525

2626
function maybeWindowsPath(path) {
2727
if (!path) return path;
28-
if (!isWindows) return resolve(path);
29-
return '//?/' + resolve(path).replace(/\\/g, '/');
28+
const resolvedPath = resolve(path);
29+
if (!isWindows) return resolvedPath;
30+
31+
// Strip any existing UNC prefix check both the format we add as well as what
32+
// the windows API returns when using path.resolve
33+
let cleanPath = resolvedPath;
34+
while (cleanPath.startsWith('\\\\?\\') || cleanPath.startsWith('//?/')) {
35+
cleanPath = cleanPath.substring(4);
36+
}
37+
38+
return '//?/' + cleanPath.replace(/\\/g, '/');
3039
}
3140

3241
/**
@@ -108,7 +117,7 @@ export async function componentize(opts,
108117
.slice(0, 12)
109118
);
110119
await mkdir(tmpDir);
111-
const sourceDir = join(tmpDir, 'sources');
120+
const sourceDir = maybeWindowsPath(join(tmpDir, 'sources'));
112121
await mkdir(sourceDir);
113122

114123
let {
@@ -223,7 +232,7 @@ export async function componentize(opts,
223232
console.log(env);
224233
}
225234

226-
let initializerPath = join(sourceDir, 'initializer.js');
235+
let initializerPath = maybeWindowsPath(join(sourceDir, 'initializer.js'));
227236
sourcePath = maybeWindowsPath(sourcePath);
228237
let workspacePrefix = dirname(sourcePath);
229238

test/cases/missing-export/test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { strictEqual } from 'node:assert';
1+
import { match } from 'node:assert';
22

3+
// use match instead of strictEqual to enable testing between linux and windows
4+
// Windows errors prefix the error with file path
35
export function err(e) {
4-
strictEqual(e.message, `Unable to extract expected exports list
5-
Error: "missing-export.js" does not export a "expected" function as expected by the world.
6-
Try defining it:
7-
export function expected() {};`);
6+
match(e.message, /Error: "missing-export.js" does not export a "expected" function/);
7+
match(e.message, /Try defining it:/);
8+
match(e.message, /export function expected\(\) {};/);
89
}

0 commit comments

Comments
 (0)