15 lines
664 B
JavaScript
15 lines
664 B
JavaScript
import { readFile } from 'node:fs/promises';
|
|
import { join } from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
|
|
/** Loader for Node: reads build/ produced by scripts/build.sh. */
|
|
export function nodeLoader(buildDir) {
|
|
return async (name) => {
|
|
const meta = JSON.parse(await readFile(join(buildDir, 'components', `${name}.meta.json`), 'utf8'));
|
|
const dir = join(buildDir, 'jco', name);
|
|
const mod = await import(pathToFileURL(join(dir, `${name}.js`)).href);
|
|
const getCoreModule = async (p) => WebAssembly.compile(await readFile(join(dir, p)));
|
|
return { meta, instantiate: (imports) => mod.instantiate(getCoreModule, imports) };
|
|
};
|
|
}
|