[wasm] build: fix build with node/browser
This commit is contained in:
parent
29c5be137a
commit
d385630499
@ -257,11 +257,13 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@rollup/pluginutils': 5.1.0(rollup@4.21.2)
|
'@rollup/pluginutils': 5.1.0(rollup@4.21.2)
|
||||||
magic-string: 0.30.11
|
magic-string: 0.30.11
|
||||||
|
optionalDependencies:
|
||||||
rollup: 4.21.2
|
rollup: 4.21.2
|
||||||
|
|
||||||
'@rollup/plugin-wasm@6.2.2(rollup@4.21.2)':
|
'@rollup/plugin-wasm@6.2.2(rollup@4.21.2)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@rollup/pluginutils': 5.1.0(rollup@4.21.2)
|
'@rollup/pluginutils': 5.1.0(rollup@4.21.2)
|
||||||
|
optionalDependencies:
|
||||||
rollup: 4.21.2
|
rollup: 4.21.2
|
||||||
|
|
||||||
'@rollup/pluginutils@5.1.0(rollup@4.21.2)':
|
'@rollup/pluginutils@5.1.0(rollup@4.21.2)':
|
||||||
@ -269,6 +271,7 @@ snapshots:
|
|||||||
'@types/estree': 1.0.5
|
'@types/estree': 1.0.5
|
||||||
estree-walker: 2.0.2
|
estree-walker: 2.0.2
|
||||||
picomatch: 2.3.1
|
picomatch: 2.3.1
|
||||||
|
optionalDependencies:
|
||||||
rollup: 4.21.2
|
rollup: 4.21.2
|
||||||
|
|
||||||
'@rollup/rollup-android-arm-eabi@4.21.2':
|
'@rollup/rollup-android-arm-eabi@4.21.2':
|
||||||
|
@ -5,7 +5,12 @@ import { dts } from 'rollup-plugin-dts';
|
|||||||
|
|
||||||
function makePlugins({ sync }) {
|
function makePlugins({ sync }) {
|
||||||
const plugins = [];
|
const plugins = [];
|
||||||
plugins.push(wasm({ sync: sync ? ['pkg/um_wasm_bg.wasm'] : [] }));
|
plugins.push(
|
||||||
|
wasm({
|
||||||
|
sync: sync ? ['pkg/um_wasm_bg.wasm'] : [],
|
||||||
|
fileName: 'um_wasm_bg.wasm',
|
||||||
|
}),
|
||||||
|
);
|
||||||
plugins.push(
|
plugins.push(
|
||||||
replace({
|
replace({
|
||||||
preventAssignment: true,
|
preventAssignment: true,
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
import umWasm from '../pkg/um_wasm_bg.wasm';
|
import umWasm from '../pkg/um_wasm_bg.wasm';
|
||||||
import { __wbg_init, initSync } from '../pkg/um_wasm.js';
|
import { __wbg_init, initSync } from '../pkg/um_wasm.js';
|
||||||
|
|
||||||
export * from '../pkg/um_wasm.js';
|
export * from '../pkg/um_wasm.js';
|
||||||
|
|
||||||
function loader() {
|
function loader() {
|
||||||
if (process.env.UMC_INLINE_BUILD === '1') {
|
if (process.env.UMC_INLINE_BUILD === '1') {
|
||||||
initSync({ module: umWasm() });
|
initSync({ module: umWasm() });
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(true);
|
||||||
} else {
|
} else {
|
||||||
return umWasm().then(async (wasm) => {
|
/** @type {Promise<Buffer>|undefined} */
|
||||||
await __wbg_init({ module_or_path: wasm });
|
let wasm = undefined;
|
||||||
});
|
if (typeof document === 'undefined') {
|
||||||
|
// node
|
||||||
|
wasm = import('node:f' + 's/promises').then((fs) =>
|
||||||
|
fs.readFile(new URL('../pkg/um_wasm_bg.wasm', import.meta.url)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return __wbg_init({ module_or_path: wasm }).then(() => true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
um_wasm_loader/test.cjs
Normal file
8
um_wasm_loader/test.cjs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const { NCMFile, ready } = require('./dist/loader.js');
|
||||||
|
|
||||||
|
ready.then(() => {
|
||||||
|
const ncm = new NCMFile();
|
||||||
|
let n = ncm.open(new Uint8Array([]));
|
||||||
|
console.assert(n !== 0, 'n should not be 0', { n });
|
||||||
|
console.log('cjs test ok');
|
||||||
|
});
|
8
um_wasm_loader/test.mjs
Normal file
8
um_wasm_loader/test.mjs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { NCMFile, ready } from './dist/loader.mjs';
|
||||||
|
|
||||||
|
ready.then(() => {
|
||||||
|
const ncm = new NCMFile();
|
||||||
|
let n = ncm.open(new Uint8Array([]));
|
||||||
|
console.assert(n !== 0, 'n should not be 0', { n });
|
||||||
|
console.log('mjs test ok');
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user