-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
42 lines (37 loc) · 1.07 KB
/
build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { build } from 'esbuild';
import { componentize } from '@bytecodealliance/componentize-js';
import { readFile, writeFile } from 'node:fs/promises';
// Bundle, for npm
await build({
logLevel: 'info',
entryPoints: ['lib/api.js'],
bundle: true,
format: 'esm',
outfile: 'out/bundle.js',
});
// Componentize, for PyPI
// This isn't currently used pending https://github.com/bytecodealliance/wasmtime-py/pull/224,
// but is planned for later use and kept tested in the meantime.
const { component } = await componentize(`\
${await readFile('out/bundle.js', 'utf8')}
export function renderJson(sourceJSON) {
return render(JSON.parse(sourceJSON));
}
`, `\
package local:wavedrom;
world wavedrom {
export render-json: func(json: string) -> string;
}
`, {
disableFeatures: ['random', 'stdio', 'clocks']
});
await writeFile('out/wavedrom.component.wasm', component);
// Bundle, for PyPI
// This is what's actually used right now.
await build({
logLevel: 'info',
entryPoints: ['lib/api.js'],
bundle: true,
format: 'cjs',
outfile: 'pypi/yowasp_wavedrom/bundle.js',
});