Skip to content

Commit 3614828

Browse files
MishaKavclaude
andauthored
fix: bundle WASM dependency for Python formatting support (#426)
- Add @wasm-fmt/ruff_fmt as devDependency for build-time bundling - Add static import hint in main.ts so ncc can detect the package - Bundle WASM binary (ruff_fmt_bg.wasm) to dist for runtime usage - Add Jest mock to prevent test failures with ESM-only package This fixes the "Cannot find package '@wasm-fmt/ruff_fmt'" error that occurred when gitstream-core 2.1.216+ tried to initialize Python formatting. The solution works for both environments: - GitHub Actions: WASM bundled by ncc, loaded via dynamic import - Lambda: WASM loaded from node_modules via dynamic import 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent b04bf7e commit 3614828

File tree

7 files changed

+55
-10
lines changed

7 files changed

+55
-10
lines changed

__mocks__/@wasm-fmt/ruff_fmt.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Mock for @wasm-fmt/ruff_fmt (used only for ncc bundling hint)
2+
module.exports = {}

dist/index.js

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

dist/licenses.txt

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

dist/ruff_fmt_bg.wasm

1.65 MB
Binary file not shown.

package-lock.json

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

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"license": "Apache-2.0",
3939
"dependencies": {
4040
"@actions/core": "^1.11.1",
41-
"@linearb/gitstream-core": "2.1.216"
41+
"@linearb/gitstream-core": "2.1.217"
4242
},
4343
"devDependencies": {
4444
"@jest/globals": "^30.2.0",
@@ -47,6 +47,7 @@
4747
"@typescript-eslint/eslint-plugin": "^8.46.3",
4848
"@typescript-eslint/parser": "^8.39.1",
4949
"@vercel/ncc": "^0.38.4",
50+
"@wasm-fmt/ruff_fmt": "^0.10.0",
5051
"eslint": "^9.39.1",
5152
"eslint-plugin-github": "^5.1.8",
5253
"eslint-plugin-jest": "^28.13.0",
@@ -85,6 +86,9 @@
8586
"collectCoverage": true,
8687
"collectCoverageFrom": [
8788
"./src/**"
88-
]
89+
],
90+
"moduleNameMapper": {
91+
"@wasm-fmt/ruff_fmt": "<rootDir>/__mocks__/@wasm-fmt/ruff_fmt.js"
92+
}
8993
}
9094
}

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { RulesEngine } from '@linearb/gitstream-core'
33
import { version } from '@linearb/gitstream-core/package.json'
44
import { installBlack } from './support-python'
55

6+
// Hint for ncc to bundle WASM package (used dynamically in gitstream-core)
7+
import '@wasm-fmt/ruff_fmt'
8+
69
export async function run(): Promise<void> {
710
await installBlack()
811

0 commit comments

Comments
 (0)