Skip to content

Commit

Permalink
WIP of streaming Oniguruma WASM compilation (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
zm-cttae authored Nov 5, 2024
1 parent c748431 commit 101a449
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/util/oniguruma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
import * as vscodeOniguruma from 'vscode-oniguruma';
import type * as vscodeTextmate from 'vscode-textmate';

// Use webpack + encoded-uint8array-loader to generate a `Uint8Array` WASM module.
// This is not streaming :[ but vscode libs must bundle WASM deps to support web ecosystem.
// Extension alternative is using copy-webpack-plugin + fetch to include the WASM file.
// TODO: use data URI and native node 18.x fetch for streaming compilation.
import * as data from '../../node_modules/vscode-oniguruma/release/onig.wasm';
// Use webpack + asset inlining to generate a streaming compilation WASM module.
import * as dataUri from '../../node_modules/vscode-oniguruma/release/onig.wasm';

let onigurumaLib: vscodeTextmate.IOnigLib | null = null;

export async function getOniguruma(): Promise<vscodeTextmate.IOnigLib> {
if (onigurumaLib) {
return onigurumaLib;
}
await vscodeOniguruma.loadWASM({ data });
await vscodeOniguruma.loadWASM({ data: await fetch(dataUri) });
onigurumaLib = {
createOnigScanner(patterns: string[]) {
return new vscodeOniguruma.OnigScanner(patterns);
Expand Down
2 changes: 1 addition & 1 deletion typings/imports.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// wiring from webpack `encoded-uint8array-loader` to inline WASM buffer view
declare module '*.wasm' {
const bufview: Uint8Array;
const bufview: string;
export = bufview;
}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const configuration = {
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{ test: /\.wasm$/, type: 'javascript/auto', loader: 'encoded-uint8array-loader' }
{ test: /\.wasm$/, type: 'asset/inline' }
]
},
externals: {
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const configuration = {
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader', options: { configFile: 'test/tsconfig.json' } },
{ test: /\.wasm$/, type: 'javascript/auto', loader: 'encoded-uint8array-loader' }
{ test: /\.wasm$/, type: 'asset/inline' }
]
},
plugins: [
Expand Down

0 comments on commit 101a449

Please sign in to comment.