Skip to content

Commit 7e10e03

Browse files
authored
Merge pull request #1143 from nojaf/oxc-parser-wasm
Include bindings of oxc-parser
2 parents 82c0d49 + 4c298f3 commit 7e10e03

File tree

4 files changed

+153
-6
lines changed

4 files changed

+153
-6
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
registry-url: "https://registry.npmjs.org"
7878

7979
- run: npm ci
80+
- run: npm install --include=optional
8081
- run: opam install dune cppo
8182
- run: npm run compile
8283
- run: npm run bundle
@@ -114,11 +115,20 @@ jobs:
114115
mv rescript-tools.exe ${{matrix.artifact-folder}}
115116
tar -cvf binary.tar ${{matrix.artifact-folder}}
116117
117-
- uses: actions/upload-artifact@v4
118+
- name: Upload binaries
119+
uses: actions/upload-artifact@v4
118120
with:
119121
name: ${{matrix.artifact-folder}}
120122
path: binary.tar
121123

124+
- name: Upload platform bindings
125+
if: always()
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: bindings-${{matrix.artifact-folder}}
129+
path: node_modules/@oxc-parser/
130+
retention-days: 1
131+
122132
package:
123133
needs:
124134
- build
@@ -134,6 +144,7 @@ jobs:
134144
registry-url: "https://registry.npmjs.org"
135145

136146
- run: npm ci
147+
- run: npm install --include=optional
137148
- run: npm run compile
138149

139150
- name: Download MacOS binaries
@@ -180,6 +191,13 @@ jobs:
180191
run: rm binary.tar
181192
working-directory: binaries
182193

194+
- name: Download platform bindings from all platforms
195+
uses: actions/download-artifact@v4
196+
with:
197+
pattern: bindings-*
198+
path: bindings
199+
merge-multiple: true
200+
183201
- name: Move binaries to folders
184202
run: |
185203
declare -a platforms=("darwin" "darwinarm64" "linux" "linuxarm64" "win32")
@@ -194,6 +212,16 @@ jobs:
194212
mv binaries/"$platform"/rescript-tools.exe tools/binaries/"$platform"
195213
done
196214
215+
- name: Merge platform bindings into node_modules
216+
run: |
217+
mkdir -p node_modules/@oxc-parser
218+
# Copy all bindings from downloaded artifacts
219+
if [ -d "bindings" ]; then
220+
find bindings -type d -name "binding-*" -exec cp -r {} node_modules/@oxc-parser/ \;
221+
fi
222+
# Ensure we have the Linux binding from current platform
223+
npm install --include=optional || true
224+
197225
- name: Store short commit SHA for filename
198226
id: vars
199227
env:
@@ -215,15 +243,18 @@ jobs:
215243
216244
- name: Package Extension
217245
if: github.ref != 'refs/heads/master'
218-
run: npx vsce package -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
246+
run: npx vsce package --no-yarn -o rescript-vscode-${{ steps.vars.outputs.sha_short }}.vsix
219247

220248
- name: Package Extension pre-release version
221249
if: github.ref == 'refs/heads/master'
222-
run: npx vsce package -o rescript-vscode-latest-master.vsix ${{ steps.increment_pre_release.outputs.new_version }} --no-git-tag-version
250+
run: npx vsce package --no-yarn -o rescript-vscode-latest-master.vsix ${{ steps.increment_pre_release.outputs.new_version }} --no-git-tag-version
223251

224252
- name: Package Extension release version
225253
if: startsWith(github.ref, 'refs/tags/')
226-
run: npx vsce package -o rescript-vscode-${{ steps.tag_name.outputs.tag }}.vsix ${{ steps.tag_name.outputs.tag }} --no-git-tag-version
254+
run: npx vsce package --no-yarn -o rescript-vscode-${{ steps.tag_name.outputs.tag }}.vsix ${{ steps.tag_name.outputs.tag }} --no-git-tag-version
255+
256+
- name: Verify Package Contents
257+
run: npm run verify-package
227258

228259
- uses: actions/upload-artifact@v4
229260
if: github.ref != 'refs/heads/master'

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
"scripts": {
264264
"clean": "rm -rf client/out server/out",
265265
"vscode:prepublish": "npm run clean && npm run bundle",
266+
"verify-package": "node scripts/verify-package.mjs",
266267
"compile": "tsc -b",
267268
"watch": "tsc -b -w",
268269
"postinstall": "cd server && npm i && cd ../client && npm i && cd ../tools && npm i && cd ../tools/tests && npm i && cd ../../analysis/tests && npm i && cd ../reanalyze/examples/deadcode && npm i && cd ../termination && npm i",
@@ -280,7 +281,7 @@
280281
},
281282
"dependencies": {
282283
"magic-string": "^0.30.21",
283-
"oxc-parser": "^0.97.0",
284+
"oxc-parser": "0.97.0",
284285
"oxc-walker": "^0.5.2",
285286
"semver": "^7.7.2"
286287
},

scripts/verify-package.mjs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Script to verify that platform-specific native bindings and required dependencies
5+
* are included in the packaged .vsix file
6+
*/
7+
8+
import fs from "fs";
9+
import path from "path";
10+
import { fileURLToPath } from "url";
11+
import { execSync } from "child_process";
12+
13+
const __filename = fileURLToPath(import.meta.url);
14+
const __dirname = path.dirname(__filename);
15+
const ROOT_DIR = path.join(__dirname, "..");
16+
17+
// Find .vsix file
18+
const vsixFiles = fs
19+
.readdirSync(ROOT_DIR)
20+
.filter((f) => f.endsWith(".vsix"))
21+
.sort((a, b) => {
22+
const statA = fs.statSync(path.join(ROOT_DIR, a));
23+
const statB = fs.statSync(path.join(ROOT_DIR, b));
24+
return statB.mtimeMs - statA.mtimeMs; // Most recent first
25+
});
26+
27+
if (vsixFiles.length === 0) {
28+
console.error('No .vsix file found. Run "npx vsce package" first.');
29+
process.exit(1);
30+
}
31+
32+
const vsixFile = vsixFiles[0];
33+
console.log(`Checking ${vsixFile}...\n`);
34+
35+
// Extract and check contents
36+
const tempDir = path.join(ROOT_DIR, ".vsix-check");
37+
try {
38+
fs.mkdirSync(tempDir, { recursive: true });
39+
40+
// .vsix is just a zip file
41+
execSync(`unzip -q "${path.join(ROOT_DIR, vsixFile)}" -d "${tempDir}"`, {
42+
stdio: "inherit",
43+
});
44+
45+
const extensionDir = path.join(tempDir, "extension");
46+
const oxcParserDir = path.join(extensionDir, "node_modules", "@oxc-parser");
47+
48+
// Platform-specific bindings that should be included
49+
const platformBindings = [
50+
"@oxc-parser/binding-darwin-arm64",
51+
"@oxc-parser/binding-darwin-x64",
52+
"@oxc-parser/binding-linux-x64-gnu",
53+
"@oxc-parser/binding-win32-x64-msvc",
54+
];
55+
56+
const checks = [
57+
{
58+
name: "oxc-parser",
59+
path: path.join(extensionDir, "node_modules", "oxc-parser"),
60+
required: true,
61+
},
62+
...platformBindings.map((binding) => ({
63+
name: binding,
64+
path: path.join(oxcParserDir, binding.replace("@oxc-parser/", "")),
65+
required: true,
66+
})),
67+
];
68+
69+
let allGood = true;
70+
let foundCount = 0;
71+
72+
for (const check of checks) {
73+
const exists = fs.existsSync(check.path);
74+
const status = exists ? "✓" : "✗";
75+
console.log(`${status} ${check.name}: ${exists ? "FOUND" : "MISSING"}`);
76+
77+
if (exists) {
78+
foundCount++;
79+
// Check for key files in bindings
80+
if (check.name.startsWith("@oxc-parser/binding-")) {
81+
// Look for .node files (native bindings) or package.json
82+
const packageJson = path.join(check.path, "package.json");
83+
if (fs.existsSync(packageJson)) {
84+
console.log(` ✓ package.json found`);
85+
} else {
86+
console.log(` ✗ package.json missing`);
87+
allGood = false;
88+
}
89+
}
90+
} else if (check.required) {
91+
allGood = false;
92+
}
93+
}
94+
95+
console.log("");
96+
console.log(`Found ${foundCount}/${checks.length} required packages`);
97+
98+
if (allGood && foundCount === checks.length) {
99+
console.log("✓ All required files are included in the package!");
100+
} else {
101+
console.log("✗ Some required files are missing!");
102+
if (foundCount < platformBindings.length) {
103+
console.log(
104+
` Warning: Only ${foundCount - 1} platform bindings found, expected ${platformBindings.length}`,
105+
);
106+
console.log(" The extension may not work on all platforms.");
107+
}
108+
process.exit(1);
109+
}
110+
} finally {
111+
// Cleanup
112+
if (fs.existsSync(tempDir)) {
113+
fs.rmSync(tempDir, { recursive: true, force: true });
114+
}
115+
}

0 commit comments

Comments
 (0)