Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Delay the warning ExperimentalWarning: WASI is ... for prism/wasm until the actual moment prism is used. #404

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/blue-worms-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/db-structure": patch
"@liam-hq/cli": patch
---

:children_crossing: Delay the warning `ExperimentalWarning: WASI is an experimental feature and might change at any time` for prism/wasm until the actual moment prism is used.
1 change: 1 addition & 0 deletions frontend/packages/cli/vite-plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './remove-import-wasi.js'
export * from './set-env.js'
19 changes: 19 additions & 0 deletions frontend/packages/cli/vite-plugins/remove-import-wasi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'node:fs'
import type { Plugin } from 'vite'

// The `import 'wasi'` statement is dynamically imported within the db-structure package.
// However, `import 'wasi';` gets included in the build output.
// To address this, the buildEnd hook removes it from the build artifact.
export function renameImportWasi(): Plugin {
return {
name: 'remove-import-wasi',
buildEnd() {
const filePath = 'dist-cli/bin/cli.js'
const originalContent = fs.readFileSync(filePath, 'utf8')
const content = originalContent.replace(/import 'wasi';\s*/g, '')
fs.writeFileSync(filePath, content, 'utf8')
},
}
}

export default renameImportWasi
4 changes: 2 additions & 2 deletions frontend/packages/cli/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { rmSync } from 'node:fs'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import { defineConfig } from 'vitest/config'
import { setEnvPlugin } from './vite-plugins/index.js'
import { renameImportWasi, setEnvPlugin } from './vite-plugins/index.js'

const outDir = 'dist-cli/html'

Expand All @@ -26,7 +26,7 @@ export default defineConfig({
],
},
},
plugins: [react(), tsconfigPaths(), setEnvPlugin()],
plugins: [react(), tsconfigPaths(), renameImportWasi(), setEnvPlugin()],
test: {
globals: true,
environment: 'node',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Consider removing this patch once support for Node.js v18 is no longer necessary
import { readFile } from 'node:fs/promises'
// biome-ignore lint/correctness/noNodejsModules: This import is server-side specific because loadPrism() is exclusively invoked in server environments.
import { fileURLToPath } from 'node:url'
// biome-ignore lint/correctness/noNodejsModules: This import is server-side specific because loadPrism() is exclusively invoked in server environments.
import { WASI } from 'node:wasi'

import type { ParseResult } from '@ruby/prism/src/deserialize.js'
import { parsePrism } from '@ruby/prism/src/parsePrism.js'

Expand All @@ -32,6 +31,9 @@ export async function loadPrism(): Promise<(source: string) => ParseResult> {
overrideWasmUrl ?? fileURLToPath(new URL('prism.wasm', import.meta.url))
const wasm = await WebAssembly.compile(await readFile(path))

// Dynamic import for WASI to avoid warnings unless necessary
// biome-ignore lint/correctness/noNodejsModules: This import is server-side specific because loadPrism() is exclusively invoked in server environments.
const { WASI } = await import('node:wasi')
const wasi = new WASI({ version: 'preview1' })

// Patch applied for compatibility
Expand Down
Loading