From 8184cf1af2317dc1de028ff0cfbc57c7f151ccb9 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 2 Apr 2025 14:41:46 +0200 Subject: [PATCH 1/5] fix bug for file paths in windows during componentization Signed-off-by: karthik2804 --- .github/workflows/main.yml | 5 ++++- src/componentize.js | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42cd5ef9..74b42e8d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -132,7 +132,7 @@ jobs: ######## test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} needs: - build strategy: @@ -141,6 +141,9 @@ jobs: node-version: - '23.10.0' # - latest reenable when https://github.com/nodejs/node/issues/57172 is fixed + os: + - ubuntu-latest + - windows-latest build-type: - 'release' - 'debug' diff --git a/src/componentize.js b/src/componentize.js index 89ac6576..c3954aed 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -25,8 +25,17 @@ const isWindows = platform === 'win32'; function maybeWindowsPath(path) { if (!path) return path; - if (!isWindows) return resolve(path); - return '//?/' + resolve(path).replace(/\\/g, '/'); + const resolvedPath = resolve(path); + if (!isWindows) return resolvedPath; + + // Strip any existing UNC prefix check both the format we add as well as what + // the windows API returns when using path.resolve + let cleanPath = resolvedPath; + while (cleanPath.startsWith('\\\\?\\') || cleanPath.startsWith('//?/')) { + cleanPath = cleanPath.substring(4); + } + + return '//?/' + cleanPath.replace(/\\/g, '/'); } /** @@ -108,7 +117,7 @@ export async function componentize(opts, .slice(0, 12) ); await mkdir(tmpDir); - const sourceDir = join(tmpDir, 'sources'); + const sourceDir = maybeWindowsPath(join(tmpDir, 'sources')); await mkdir(sourceDir); let { @@ -223,7 +232,7 @@ export async function componentize(opts, console.log(env); } - let initializerPath = join(sourceDir, 'initializer.js'); + let initializerPath = maybeWindowsPath(join(sourceDir, 'initializer.js')); sourcePath = maybeWindowsPath(sourcePath); let workspacePrefix = dirname(sourcePath); From 6179b4a29631c845562b0652a5d1848d2d647c7e Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 2 Apr 2025 14:55:19 +0200 Subject: [PATCH 2/5] enable cross OS cache restore for test Signed-off-by: karthik2804 --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 74b42e8d..9af9d72a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -159,6 +159,7 @@ jobs: uses: actions/cache/restore@v4 id: restore-starlingmonkey-jit-build with: + enableCrossOsArchive: true key: starlingmonkey-${{matrix.build-type}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }} path: lib From dbda420ad2d2b90cd190398497b97ede57803575 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 2 Apr 2025 14:59:21 +0200 Subject: [PATCH 3/5] Add cross env as dev dependency The npm tests depend on environment variables and `cross-env` helps us perform it easily.env Signed-off-by: karthik2804 --- package-lock.json | 24 ++++++++++++++++++++++-- package.json | 7 ++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6f418f59..e919e466 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bytecodealliance/componentize-js", - "version": "0.17.0", + "version": "0.18.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@bytecodealliance/componentize-js", - "version": "0.17.0", + "version": "0.18.0", "workspaces": [ "." ], @@ -21,6 +21,7 @@ }, "devDependencies": { "@bytecodealliance/preview2-shim": "^0.17.1", + "cross-env": "^7.0.3", "mocha": "^11.1.0" } }, @@ -1092,6 +1093,25 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "license": "MIT" }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", diff --git a/package.json b/package.json index 2b50b7ea..788f6866 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "devDependencies": { "@bytecodealliance/preview2-shim": "^0.17.1", + "cross-env": "^7.0.3", "mocha": "^11.1.0" }, "dependencies": { @@ -31,8 +32,8 @@ "build:debug": "make debug", "test": "mocha -u tdd test/test.js --timeout 120000", "test:release": "mocha -u tdd test/test.js --timeout 120000", - "test:weval": "WEVAL_TEST=1 mocha -u tdd test/test.js --timeout 120000", - "test:debug": "DEBUG_TEST=1 mocha -u tdd test/test.js --timeout 120000", + "test:weval": "cross-env WEVAL_TEST=1 mocha -u tdd test/test.js --timeout 120000", + "test:debug": "cross-env DEBUG_TEST=1 mocha -u tdd test/test.js --timeout 120000", "prepublishOnly": "npm run build" }, "files": [ @@ -48,4 +49,4 @@ "workspaces": [ "." ] -} +} \ No newline at end of file From dc53f53ca50244287f97fa939a8d71fcca0611f9 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 2 Apr 2025 15:20:10 +0200 Subject: [PATCH 4/5] fix windows test Signed-off-by: karthik2804 --- test/cases/missing-export/test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/cases/missing-export/test.js b/test/cases/missing-export/test.js index 3222bed6..59180b56 100644 --- a/test/cases/missing-export/test.js +++ b/test/cases/missing-export/test.js @@ -1,8 +1,9 @@ -import { strictEqual } from 'node:assert'; +import { match } from 'node:assert'; +// use match instead of strictEqual to enable testing between linux and windows +// Windows errors prefix the error with file path export function err(e) { - strictEqual(e.message, `Unable to extract expected exports list -Error: "missing-export.js" does not export a "expected" function as expected by the world. - Try defining it: - export function expected() {};`); + match(e.message, /Error: "missing-export.js" does not export a "expected" function/); + match(e.message, /Try defining it:/); + match(e.message, /export function expected\(\) {};/); } From 47ed722f85b0ac8f617c7253335ef3fed5fd4338 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 2 Apr 2025 17:24:23 +0200 Subject: [PATCH 5/5] start testing on macos as well Signed-off-by: karthik2804 --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9af9d72a..2837289b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -144,6 +144,7 @@ jobs: os: - ubuntu-latest - windows-latest + - macos-latest build-type: - 'release' - 'debug'