Compare commits
3 Commits
5590b86c04
...
2cca297bcc
Author | SHA1 | Date | |
---|---|---|---|
2cca297bcc | |||
d385630499 | |||
29c5be137a |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@unlock-music/crypto",
|
||||
"version": "0.0.0-alpha.3",
|
||||
"version": "0.0.0-alpha.5",
|
||||
"description": "Project Unlock Music: 加解密支持库",
|
||||
"scripts": {
|
||||
"build": "node build.js",
|
||||
|
@ -257,11 +257,13 @@ snapshots:
|
||||
dependencies:
|
||||
'@rollup/pluginutils': 5.1.0(rollup@4.21.2)
|
||||
magic-string: 0.30.11
|
||||
optionalDependencies:
|
||||
rollup: 4.21.2
|
||||
|
||||
'@rollup/plugin-wasm@6.2.2(rollup@4.21.2)':
|
||||
dependencies:
|
||||
'@rollup/pluginutils': 5.1.0(rollup@4.21.2)
|
||||
optionalDependencies:
|
||||
rollup: 4.21.2
|
||||
|
||||
'@rollup/pluginutils@5.1.0(rollup@4.21.2)':
|
||||
@ -269,6 +271,7 @@ snapshots:
|
||||
'@types/estree': 1.0.5
|
||||
estree-walker: 2.0.2
|
||||
picomatch: 2.3.1
|
||||
optionalDependencies:
|
||||
rollup: 4.21.2
|
||||
|
||||
'@rollup/rollup-android-arm-eabi@4.21.2':
|
||||
|
@ -5,7 +5,12 @@ import { dts } from 'rollup-plugin-dts';
|
||||
|
||||
function makePlugins({ sync }) {
|
||||
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(
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
|
@ -1,15 +1,22 @@
|
||||
import umWasm from '../pkg/um_wasm_bg.wasm';
|
||||
import { __wbg_init, initSync } from '../pkg/um_wasm.js';
|
||||
|
||||
export * from '../pkg/um_wasm.js';
|
||||
|
||||
function loader() {
|
||||
if (process.env.UMC_INLINE_BUILD === '1') {
|
||||
initSync({ module: umWasm() });
|
||||
return Promise.resolve(undefined);
|
||||
return Promise.resolve(true);
|
||||
} else {
|
||||
return umWasm().then(async (wasm) => {
|
||||
await __wbg_init({ module_or_path: wasm });
|
||||
});
|
||||
/** @type {Promise<Buffer>|undefined} */
|
||||
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