From 7874daa96fcbfda9ab26d9eb4e3d6158d76ce519 Mon Sep 17 00:00:00 2001 From: kunlinglio <142668432+kunlinglio@users.noreply.github.com> Date: Wed, 22 Jul 2026 16:39:52 +0800 Subject: [PATCH 1/4] refactor(wasm): make vide-lsp-wasm own build script and artifacts --- .github/ci-modules.yml | 4 +- .github/workflows/build-artifacts.yml | 30 ++++++------ .github/workflows/ci.yml | 46 +++++++++---------- .github/workflows/deploy-docs.yml | 43 +++++++++-------- .github/workflows/docs-preview.yml | 43 +++++++++-------- crates/vide-lsp-wasm/.gitignore | 1 + .../vide-lsp-wasm/scripts/build.mjs | 26 +++++++++-- editors/vscode/scripts/copy-web-assets.ts | 2 +- website/playground/package.json | 2 +- .../playground/scripts/copy-docs-assets.mjs | 4 +- .../playground/scripts/copy-wasm-assets.mjs | 19 ++++++++ .../advanced-guide/advanced-installation.md | 2 +- .../advanced-guide/advanced-installation.md | 2 +- 13 files changed, 131 insertions(+), 93 deletions(-) create mode 100644 crates/vide-lsp-wasm/.gitignore rename website/playground/scripts/build-vide-wasm.mjs => crates/vide-lsp-wasm/scripts/build.mjs (85%) create mode 100644 website/playground/scripts/copy-wasm-assets.mjs diff --git a/.github/ci-modules.yml b/.github/ci-modules.yml index 5c34ceb36..07f2842af 100644 --- a/.github/ci-modules.yml +++ b/.github/ci-modules.yml @@ -43,8 +43,8 @@ package: - "website/package.json" - "website/playground/package.json" - "website/package-lock.json" - - "website/playground/scripts/build-vide-wasm.mjs" - - "website/playground/scripts/script-utils.mjs" + - "crates/vide-lsp-wasm/scripts/**" + - "crates/vide-lsp-wasm/js/**" - ".github/actions/setup-rust/**" - ".github/actions/setup-sccache/**" - ".github/actions/setup-emscripten/**" diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml index 4576a8571..08bd764bd 100644 --- a/.github/workflows/build-artifacts.yml +++ b/.github/workflows/build-artifacts.yml @@ -186,25 +186,25 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Restore playground WASM cache - id: playground-wasm-cache + - name: Restore Vide LSP WASM cache + id: vide-lsp-wasm-cache uses: actions/cache/restore@v4 with: - path: website/playground/public/wasm - key: playground-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + path: crates/vide-lsp-wasm/dist + key: vide-lsp-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} - name: Setup Rust - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-rust - name: Setup sccache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-sccache with: cmake-launcher: "true" - name: Install Emscripten SDK - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-emscripten with: version: ${{ env.EMSDK_VERSION }} @@ -219,20 +219,20 @@ jobs: - name: Install JS dependencies run: npm ci - - name: Build playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' - working-directory: website + - name: Build Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' + working-directory: ${{ github.workspace }} run: | source "${EMSDK}/emsdk_env.sh" - npm --workspace playground run build:wasm + node crates/vide-lsp-wasm/scripts/build.mjs - - name: Save playground WASM cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + - name: Save Vide LSP WASM cache + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 continue-on-error: true with: - path: website/playground/public/wasm - key: ${{ steps.playground-wasm-cache.outputs.cache-primary-key }} + path: crates/vide-lsp-wasm/dist + key: ${{ steps.vide-lsp-wasm-cache.outputs.cache-primary-key }} - name: Set VSIX build metadata working-directory: . diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb038d295..b37d8de3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -147,38 +147,38 @@ jobs: working-directory: editors/vscode steps: - uses: actions/checkout@v4 - - name: Restore playground WASM cache - id: playground-wasm-cache + - name: Restore Vide LSP WASM cache + id: vide-lsp-wasm-cache uses: actions/cache/restore@v4 with: - path: website/playground/public/wasm - key: playground-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} - - name: Verify cached playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit == 'true' - working-directory: . + path: crates/vide-lsp-wasm/dist + key: vide-lsp-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + - name: Verify cached Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit == 'true' + working-directory: ${{ github.workspace }} run: | - test -s website/playground/public/wasm/vide-lsp.js - test -s website/playground/public/wasm/vide-core.js - test -s website/playground/public/wasm/vide-core.wasm + test -s crates/vide-lsp-wasm/dist/vide-lsp.js + test -s crates/vide-lsp-wasm/dist/vide-core.js + test -s crates/vide-lsp-wasm/dist/vide-core.wasm - name: Install Rust - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-rust - name: Setup sccache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-sccache with: cmake-launcher: "true" - name: Rust Cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: Swatinem/rust-cache@v2 continue-on-error: true with: shared-key: vscode-web-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }} - key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} cache-workspace-crates: true cache-on-failure: true - name: Install Emscripten SDK - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-emscripten with: version: ${{ env.EMSDK_VERSION }} @@ -195,19 +195,19 @@ jobs: - name: Install web smoke dependencies working-directory: editors/vscode/test-web run: npm ci - - name: Build playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' - working-directory: website + - name: Build Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' + working-directory: ${{ github.workspace }} run: | source "${EMSDK}/emsdk_env.sh" - npm --workspace playground run build:wasm - - name: Save playground WASM cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + node crates/vide-lsp-wasm/scripts/build.mjs + - name: Save Vide LSP WASM cache + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 continue-on-error: true with: - path: website/playground/public/wasm - key: ${{ steps.playground-wasm-cache.outputs.cache-primary-key }} + path: crates/vide-lsp-wasm/dist + key: ${{ steps.vide-lsp-wasm-cache.outputs.cache-primary-key }} - name: Web smoke test run: npm run test:web diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index e597f633e..98a4bce10 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -328,42 +328,42 @@ jobs: with: ref: ${{ github.event.workflow_run.head_sha || github.event.release.tag_name || github.ref }} - - name: Restore playground WASM cache - id: playground-wasm-cache + - name: Restore Vide LSP WASM cache + id: vide-lsp-wasm-cache uses: actions/cache/restore@v4 with: - path: website/playground/public/wasm - key: playground-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + path: crates/vide-lsp-wasm/dist + key: vide-lsp-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} - - name: Verify cached playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit == 'true' + - name: Verify cached Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit == 'true' run: | - test -s website/playground/public/wasm/vide-lsp.js - test -s website/playground/public/wasm/vide-core.js - test -s website/playground/public/wasm/vide-core.wasm + test -s crates/vide-lsp-wasm/dist/vide-lsp.js + test -s crates/vide-lsp-wasm/dist/vide-core.js + test -s crates/vide-lsp-wasm/dist/vide-core.wasm - name: Install Rust - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-rust - name: Setup sccache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-sccache with: cmake-launcher: "true" - name: Rust Cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: Swatinem/rust-cache@v2 continue-on-error: true with: shared-key: docs-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }} - key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} cache-workspace-crates: true cache-on-failure: true - name: Install Emscripten SDK - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-emscripten with: version: ${{ env.EMSDK_VERSION }} @@ -383,20 +383,19 @@ jobs: npm install --no-save working-directory: website - - name: Build playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + - name: Build Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' run: | source "${EMSDK}/emsdk_env.sh" - npm --workspace playground run build:wasm - working-directory: website + node crates/vide-lsp-wasm/scripts/build.mjs - - name: Save playground WASM cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + - name: Save Vide LSP WASM cache + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 continue-on-error: true with: - path: website/playground/public/wasm - key: ${{ steps.playground-wasm-cache.outputs.cache-primary-key }} + path: crates/vide-lsp-wasm/dist + key: ${{ steps.vide-lsp-wasm-cache.outputs.cache-primary-key }} - name: Build docs run: npm run build diff --git a/.github/workflows/docs-preview.yml b/.github/workflows/docs-preview.yml index 3ef97ae2e..b5752004f 100644 --- a/.github/workflows/docs-preview.yml +++ b/.github/workflows/docs-preview.yml @@ -75,42 +75,42 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Restore playground WASM cache - id: playground-wasm-cache + - name: Restore Vide LSP WASM cache + id: vide-lsp-wasm-cache uses: actions/cache/restore@v4 with: - path: website/playground/public/wasm - key: playground-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + path: crates/vide-lsp-wasm/dist + key: vide-lsp-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }}-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} - - name: Verify cached playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit == 'true' + - name: Verify cached Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit == 'true' run: | - test -s website/playground/public/wasm/vide-lsp.js - test -s website/playground/public/wasm/vide-core.js - test -s website/playground/public/wasm/vide-core.wasm + test -s crates/vide-lsp-wasm/dist/vide-lsp.js + test -s crates/vide-lsp-wasm/dist/vide-core.js + test -s crates/vide-lsp-wasm/dist/vide-core.wasm - name: Install Rust - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-rust - name: Setup sccache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-sccache with: cmake-launcher: "true" - name: Rust Cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: Swatinem/rust-cache@v2 continue-on-error: true with: shared-key: docs-wasm-${{ runner.os }}-${{ env.EMSDK_VERSION }} - key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', 'website/playground/scripts/build-vide-wasm.mjs', 'website/playground/scripts/script-utils.mjs', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} + key: wasm-src-${{ hashFiles('Cargo.toml', 'Cargo.lock', 'build.rs', 'rust-toolchain.toml', 'src/**', 'crates/**', '.github/actions/setup-emscripten/**', '.github/actions/setup-rust/**') }} cache-workspace-crates: true cache-on-failure: true - name: Install Emscripten SDK - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/setup-emscripten with: version: ${{ env.EMSDK_VERSION }} @@ -129,20 +129,19 @@ jobs: npm install --no-save working-directory: website - - name: Build playground WASM - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + - name: Build Vide LSP WASM + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' run: | source "${EMSDK}/emsdk_env.sh" - npm --workspace playground run build:wasm - working-directory: website + node crates/vide-lsp-wasm/scripts/build.mjs - - name: Save playground WASM cache - if: steps.playground-wasm-cache.outputs.cache-hit != 'true' + - name: Save Vide LSP WASM cache + if: steps.vide-lsp-wasm-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 continue-on-error: true with: - path: website/playground/public/wasm - key: ${{ steps.playground-wasm-cache.outputs.cache-primary-key }} + path: crates/vide-lsp-wasm/dist + key: ${{ steps.vide-lsp-wasm-cache.outputs.cache-primary-key }} - name: Build docs run: npm run build diff --git a/crates/vide-lsp-wasm/.gitignore b/crates/vide-lsp-wasm/.gitignore new file mode 100644 index 000000000..849ddff3b --- /dev/null +++ b/crates/vide-lsp-wasm/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/website/playground/scripts/build-vide-wasm.mjs b/crates/vide-lsp-wasm/scripts/build.mjs similarity index 85% rename from website/playground/scripts/build-vide-wasm.mjs rename to crates/vide-lsp-wasm/scripts/build.mjs index 0f0e19745..d07af9b29 100644 --- a/website/playground/scripts/build-vide-wasm.mjs +++ b/crates/vide-lsp-wasm/scripts/build.mjs @@ -1,6 +1,10 @@ import { copyFileSync, existsSync, mkdirSync } from "node:fs"; import { delimiter, dirname, resolve } from "node:path"; -import { repoRoot, run, workspaceRoot } from "./script-utils.mjs"; +import { spawnSync } from "node:child_process"; +import { fileURLToPath } from "node:url"; + +const crateRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const workspaceRoot = resolve(crateRoot, "..", ".."); if (process.argv.slice(2).some((arg) => arg !== "--")) { throw new Error(`build:wasm does not accept arguments.`); @@ -53,7 +57,7 @@ const coreWasm = resolve(targetRoot, "vide_lsp_wasm.wasm"); assertFile(coreJs, "Emscripten JavaScript output"); assertFile(coreWasm, "Emscripten WASM output"); -const outWasmRoot = resolve(repoRoot, "public", "wasm"); +const outWasmRoot = resolve(crateRoot, "dist"); mkdirSync(outWasmRoot, { recursive: true }); copyFileSync(coreJs, resolve(outWasmRoot, "vide-core.js")); copyFileSync(coreWasm, resolve(outWasmRoot, "vide-core.wasm")); @@ -67,6 +71,22 @@ function assertFile(path, label) { } } +function run(command, args, options = {}) { + const result = spawnSync(command, args, { + cwd: workspaceRoot, + env: process.env, + stdio: "inherit", + shell: false, + ...options, + }); + if (result.error) { + throw result.error; + } + if (result.status !== 0) { + throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status}`); + } +} + function findEmscriptenRoot() { if (process.env.EMSDK) { const root = resolve(process.env.EMSDK, "upstream", "emscripten"); @@ -81,7 +101,7 @@ function findEmscriptenRoot() { } throw new Error( - "Emscripten SDK is not configured. Activate emsdk_env first or set EMSDK before running npm run build:wasm.", + "Emscripten SDK is not configured. Activate emsdk_env first or set EMSDK before building vide-lsp-wasm.", ); } diff --git a/editors/vscode/scripts/copy-web-assets.ts b/editors/vscode/scripts/copy-web-assets.ts index 5f290e7f7..b2089b743 100644 --- a/editors/vscode/scripts/copy-web-assets.ts +++ b/editors/vscode/scripts/copy-web-assets.ts @@ -3,7 +3,7 @@ import * as path from "node:path"; const vscodeDir = path.resolve(__dirname, ".."); const repoRoot = path.resolve(vscodeDir, "..", ".."); -const sourceDir = path.join(repoRoot, "website", "playground", "public", "wasm"); +const sourceDir = path.join(repoRoot, "crates", "vide-lsp-wasm", "dist"); const targetDir = path.join(vscodeDir, "dist", "browser", "wasm"); const requiredFiles = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; const buildWasmCommand = "npm --prefix website --workspace playground run build:wasm"; diff --git a/website/playground/package.json b/website/playground/package.json index f94234fb1..1183b072a 100644 --- a/website/playground/package.json +++ b/website/playground/package.json @@ -11,7 +11,7 @@ "build": "astro check && astro build", "build:embed": "vite build --config vite.embed.config.ts", "preview": "astro preview --host 127.0.0.1 --port 4177", - "build:wasm": "node scripts/build-vide-wasm.mjs", + "build:wasm": "node ../../crates/vide-lsp-wasm/scripts/build.mjs && node scripts/copy-wasm-assets.mjs", "copy:docs-assets": "node scripts/copy-docs-assets.mjs", "copy:docs-wasm": "node scripts/copy-docs-wasm-assets.mjs" }, diff --git a/website/playground/scripts/copy-docs-assets.mjs b/website/playground/scripts/copy-docs-assets.mjs index 7fc34251e..804acd96b 100644 --- a/website/playground/scripts/copy-docs-assets.mjs +++ b/website/playground/scripts/copy-docs-assets.mjs @@ -4,7 +4,7 @@ import { playgroundRoot, websiteRoot } from "./script-utils.mjs"; const docsAssetRoot = resolve(websiteRoot, "site", "public", "vide-lab"); const embedSource = resolve(playgroundRoot, "dist", "embed"); -const wasmSource = resolve(playgroundRoot, "public", "wasm"); +const wasmSource = resolve(websiteRoot, "..", "crates", "vide-lsp-wasm", "dist"); const wasmTarget = resolve(docsAssetRoot, "wasm"); const requiredEmbedFiles = ["vide-lab.es.js", "locale-zh-hans.es.js", "vide-playground.css"]; @@ -26,7 +26,7 @@ mkdirSync(docsAssetRoot, { recursive: true }); cpSync(embedSource, docsAssetRoot, { recursive: true }); console.log(`Copied Vide Lab embed assets to ${docsAssetRoot}`); -requireFiles(wasmSource, requiredWasmFiles, "Run npm run build:wasm in the playground package first."); +requireFiles(wasmSource, requiredWasmFiles, "Run the vide-lsp-wasm build first."); rmSync(wasmTarget, { recursive: true, force: true }); cpSync(wasmSource, wasmTarget, { recursive: true }); console.log(`Copied Vide WASM docs assets to ${wasmTarget}`); diff --git a/website/playground/scripts/copy-wasm-assets.mjs b/website/playground/scripts/copy-wasm-assets.mjs new file mode 100644 index 000000000..585d12312 --- /dev/null +++ b/website/playground/scripts/copy-wasm-assets.mjs @@ -0,0 +1,19 @@ +import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs"; +import { resolve } from "node:path"; +import { playgroundRoot, workspaceRoot } from "./script-utils.mjs"; + +const wasmSource = resolve(workspaceRoot, "crates", "vide-lsp-wasm", "dist"); +const wasmTarget = resolve(playgroundRoot, "public", "wasm"); +const requiredWasmFiles = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; + +for (const file of requiredWasmFiles) { + const path = resolve(wasmSource, file); + if (!existsSync(path)) { + throw new Error(`Missing ${path}. Run the vide-lsp-wasm build first.`); + } +} + +rmSync(wasmTarget, { recursive: true, force: true }); +mkdirSync(wasmTarget, { recursive: true }); +cpSync(wasmSource, wasmTarget, { recursive: true }); +console.log(`Copied Vide WASM playground assets to ${wasmTarget}`); diff --git a/website/site/src/content/docs/advanced-guide/advanced-installation.md b/website/site/src/content/docs/advanced-guide/advanced-installation.md index 55eee2035..a9055e65b 100644 --- a/website/site/src/content/docs/advanced-guide/advanced-installation.md +++ b/website/site/src/content/docs/advanced-guide/advanced-installation.md @@ -38,7 +38,7 @@ description: 从源码构建 Vide、打包本地 VSIX,或安装预发布 VS Co - Emscripten SDK 5.0.2 - `ninja` - Rust `wasm32-unknown-emscripten` target - - `website/playground/scripts/build-vide-wasm.mjs` 会自动执行 `rustup target add wasm32-unknown-emscripten` + - `crates/vide-lsp-wasm/scripts/build.mjs` 会自动执行 `rustup target add wasm32-unknown-emscripten` ### 构建 Vide 语言服务器 diff --git a/website/site/src/content/docs/en/advanced-guide/advanced-installation.md b/website/site/src/content/docs/en/advanced-guide/advanced-installation.md index 719afd93e..131998cf2 100644 --- a/website/site/src/content/docs/en/advanced-guide/advanced-installation.md +++ b/website/site/src/content/docs/en/advanced-guide/advanced-installation.md @@ -40,7 +40,7 @@ If you also want to build the Playground WASM version, additionally install: - Emscripten SDK 5.0.2 - `ninja` - The Rust `wasm32-unknown-emscripten` target - - `website/playground/scripts/build-vide-wasm.mjs` automatically runs `rustup target add wasm32-unknown-emscripten` + - `crates/vide-lsp-wasm/scripts/build.mjs` automatically runs `rustup target add wasm32-unknown-emscripten` If you want to package a local VSIX, you need both sets of tools above. If you also want to build the Playground WASM version, you need all three sets. From a7d51efd86c6788caf0ff564d046d61cdb4bb928 Mon Sep 17 00:00:00 2001 From: Hong Jiarong Date: Thu, 23 Jul 2026 15:41:39 +0800 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- editors/vscode/scripts/copy-web-assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/vscode/scripts/copy-web-assets.ts b/editors/vscode/scripts/copy-web-assets.ts index b2089b743..051f5da96 100644 --- a/editors/vscode/scripts/copy-web-assets.ts +++ b/editors/vscode/scripts/copy-web-assets.ts @@ -6,7 +6,7 @@ const repoRoot = path.resolve(vscodeDir, "..", ".."); const sourceDir = path.join(repoRoot, "crates", "vide-lsp-wasm", "dist"); const targetDir = path.join(vscodeDir, "dist", "browser", "wasm"); const requiredFiles = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; -const buildWasmCommand = "npm --prefix website --workspace playground run build:wasm"; +const buildWasmCommand = `node "${path.join(repoRoot, "crates", "vide-lsp-wasm", "scripts", "build.mjs")}"`; if (!fs.existsSync(sourceDir)) { throw new Error( From 0fbfc275d7df8ee8da3f8ffffeadf85d08dc827b Mon Sep 17 00:00:00 2001 From: Hong Jiarong Date: Thu, 23 Jul 2026 16:23:57 +0800 Subject: [PATCH 3/4] Revert "Apply suggestions from code review" This reverts commit a7d51efd86c6788caf0ff564d046d61cdb4bb928. --- editors/vscode/scripts/copy-web-assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/vscode/scripts/copy-web-assets.ts b/editors/vscode/scripts/copy-web-assets.ts index 051f5da96..b2089b743 100644 --- a/editors/vscode/scripts/copy-web-assets.ts +++ b/editors/vscode/scripts/copy-web-assets.ts @@ -6,7 +6,7 @@ const repoRoot = path.resolve(vscodeDir, "..", ".."); const sourceDir = path.join(repoRoot, "crates", "vide-lsp-wasm", "dist"); const targetDir = path.join(vscodeDir, "dist", "browser", "wasm"); const requiredFiles = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; -const buildWasmCommand = `node "${path.join(repoRoot, "crates", "vide-lsp-wasm", "scripts", "build.mjs")}"`; +const buildWasmCommand = "npm --prefix website --workspace playground run build:wasm"; if (!fs.existsSync(sourceDir)) { throw new Error( From 4548338ebe254d67092ca180453440ce759f5cef Mon Sep 17 00:00:00 2001 From: Hong Jiarong Date: Thu, 23 Jul 2026 16:41:00 +0800 Subject: [PATCH 4/4] chore: simplify a bit --- crates/vide-lsp-wasm/scripts/build.mjs | 24 ++++--------------- .../playground/scripts/copy-docs-assets.mjs | 16 +++---------- .../playground/scripts/copy-wasm-assets.mjs | 12 +++------- website/playground/scripts/script-utils.mjs | 11 +++++++++ 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/crates/vide-lsp-wasm/scripts/build.mjs b/crates/vide-lsp-wasm/scripts/build.mjs index d07af9b29..d34af0960 100644 --- a/crates/vide-lsp-wasm/scripts/build.mjs +++ b/crates/vide-lsp-wasm/scripts/build.mjs @@ -1,7 +1,7 @@ import { copyFileSync, existsSync, mkdirSync } from "node:fs"; import { delimiter, dirname, resolve } from "node:path"; -import { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; +import { run } from "../../website/playground/scripts/script-utils.mjs"; const crateRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const workspaceRoot = resolve(crateRoot, "..", ".."); @@ -22,8 +22,8 @@ if (!buildEnv.EM_CONFIG && existsSync(emConfig)) { buildEnv.EM_CONFIG = emConfig; } -run("rustup", ["target", "add", "wasm32-unknown-emscripten"], { env: buildEnv }); -run("ninja", ["--version"], { env: buildEnv }); +run("rustup", ["target", "add", "wasm32-unknown-emscripten"], { cwd: workspaceRoot, env: buildEnv }); +run("ninja", ["--version"], { cwd: workspaceRoot, env: buildEnv }); const linkArgs = [ "-C", "link-arg=-sENVIRONMENT=web,worker", @@ -48,6 +48,7 @@ Object.assign(buildEnv, { const crateManifest = resolve(workspaceRoot, "crates", "vide-lsp-wasm", "Cargo.toml"); run("cargo", ["build", "--manifest-path", crateManifest, "--target", "wasm32-unknown-emscripten", "--release"], { + cwd: workspaceRoot, env: buildEnv, }); @@ -70,23 +71,6 @@ function assertFile(path, label) { throw new Error(`${label} not found at ${path}`); } } - -function run(command, args, options = {}) { - const result = spawnSync(command, args, { - cwd: workspaceRoot, - env: process.env, - stdio: "inherit", - shell: false, - ...options, - }); - if (result.error) { - throw result.error; - } - if (result.status !== 0) { - throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status}`); - } -} - function findEmscriptenRoot() { if (process.env.EMSDK) { const root = resolve(process.env.EMSDK, "upstream", "emscripten"); diff --git a/website/playground/scripts/copy-docs-assets.mjs b/website/playground/scripts/copy-docs-assets.mjs index 804acd96b..a75c4e82a 100644 --- a/website/playground/scripts/copy-docs-assets.mjs +++ b/website/playground/scripts/copy-docs-assets.mjs @@ -1,6 +1,6 @@ -import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs"; +import { cpSync, mkdirSync, rmSync } from "node:fs"; import { resolve } from "node:path"; -import { playgroundRoot, websiteRoot } from "./script-utils.mjs"; +import { playgroundRoot, requireFiles, WASM_FILES, websiteRoot } from "./script-utils.mjs"; const docsAssetRoot = resolve(websiteRoot, "site", "public", "vide-lab"); const embedSource = resolve(playgroundRoot, "dist", "embed"); @@ -8,16 +8,6 @@ const wasmSource = resolve(websiteRoot, "..", "crates", "vide-lsp-wasm", "dist") const wasmTarget = resolve(docsAssetRoot, "wasm"); const requiredEmbedFiles = ["vide-lab.es.js", "locale-zh-hans.es.js", "vide-playground.css"]; -const requiredWasmFiles = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; - -function requireFiles(root, files, hint) { - for (const file of files) { - const path = resolve(root, file); - if (!existsSync(path)) { - throw new Error(`Missing ${path}. ${hint}`); - } - } -} requireFiles(embedSource, requiredEmbedFiles, "Run npm run build:embed in the playground package first."); @@ -26,7 +16,7 @@ mkdirSync(docsAssetRoot, { recursive: true }); cpSync(embedSource, docsAssetRoot, { recursive: true }); console.log(`Copied Vide Lab embed assets to ${docsAssetRoot}`); -requireFiles(wasmSource, requiredWasmFiles, "Run the vide-lsp-wasm build first."); +requireFiles(wasmSource, WASM_FILES, "Run the vide-lsp-wasm build first."); rmSync(wasmTarget, { recursive: true, force: true }); cpSync(wasmSource, wasmTarget, { recursive: true }); console.log(`Copied Vide WASM docs assets to ${wasmTarget}`); diff --git a/website/playground/scripts/copy-wasm-assets.mjs b/website/playground/scripts/copy-wasm-assets.mjs index 585d12312..59d9ddfec 100644 --- a/website/playground/scripts/copy-wasm-assets.mjs +++ b/website/playground/scripts/copy-wasm-assets.mjs @@ -1,17 +1,11 @@ -import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs"; +import { cpSync, mkdirSync, rmSync } from "node:fs"; import { resolve } from "node:path"; -import { playgroundRoot, workspaceRoot } from "./script-utils.mjs"; +import { playgroundRoot, requireFiles, WASM_FILES, workspaceRoot } from "./script-utils.mjs"; const wasmSource = resolve(workspaceRoot, "crates", "vide-lsp-wasm", "dist"); const wasmTarget = resolve(playgroundRoot, "public", "wasm"); -const requiredWasmFiles = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; -for (const file of requiredWasmFiles) { - const path = resolve(wasmSource, file); - if (!existsSync(path)) { - throw new Error(`Missing ${path}. Run the vide-lsp-wasm build first.`); - } -} +requireFiles(wasmSource, WASM_FILES, "Run the vide-lsp-wasm build first."); rmSync(wasmTarget, { recursive: true, force: true }); mkdirSync(wasmTarget, { recursive: true }); diff --git a/website/playground/scripts/script-utils.mjs b/website/playground/scripts/script-utils.mjs index d3156058b..3f1dbdf54 100644 --- a/website/playground/scripts/script-utils.mjs +++ b/website/playground/scripts/script-utils.mjs @@ -8,6 +8,8 @@ export const websiteRoot = resolve(playgroundRoot, ".."); export const workspaceRoot = resolve(websiteRoot, ".."); export const repoRoot = playgroundRoot; +export const WASM_FILES = ["vide-lsp.js", "vide-core.js", "vide-core.wasm"]; + export function readJson(path) { return JSON.parse(readFileSync(path, "utf8")); } @@ -93,3 +95,12 @@ export function findFirstFile(root, extension) { export function directoryExists(path) { return existsSync(path) && statSync(path).isDirectory(); } + +export function requireFiles(root, files, hint) { + for (const file of files) { + const path = resolve(root, file); + if (!existsSync(path)) { + throw new Error(`Missing ${path}. ${hint}`); + } + } +}