diff --git a/src/componentize.js b/src/componentize.js index c3954aed..cb50f527 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -85,8 +85,8 @@ function isNumeric(n) { } export async function componentize(opts, - _deprecatedWitWorldOrOpts = undefined, - _deprecatedOpts = undefined) { + _deprecatedWitWorldOrOpts = undefined, + _deprecatedOpts = undefined) { let useOriginalSourceFile = true; let jsSource; @@ -246,8 +246,9 @@ export async function componentize(opts, workspacePrefix = sourceDir; sourcePath = sourceName; } - if (workspacePrefix.startsWith(cwd())) { - workspacePrefix = cwd(); + let currentDir = maybeWindowsPath(cwd()); + if (workspacePrefix.startsWith(currentDir)) { + workspacePrefix = currentDir; sourcePath = sourcePath.slice(workspacePrefix.length + 1); } } diff --git a/test/api/index.js b/test/api/index.js new file mode 100644 index 00000000..d0c6cf87 --- /dev/null +++ b/test/api/index.js @@ -0,0 +1,11 @@ +import { now } from 'wasi:clocks/wall-clock@0.2.3'; +import { getRandomBytes } from 'wasi:random/random@0.2.3'; + +let result; +export const run = { + run() { + result = `NOW: ${now().seconds}, RANDOM: ${getRandomBytes(2n)}`; + } +}; + +export const getResult = () => result; \ No newline at end of file diff --git a/test/test.js b/test/test.js index 928b9fdf..df4e45d8 100644 --- a/test/test.js +++ b/test/test.js @@ -109,9 +109,9 @@ suite('Builtins', () => { reject( new Error( 'test timed out with output:\n' + - stdout + - '\n\nstderr:\n' + - stderr + stdout + + '\n\nstderr:\n' + + stderr ) ); }, 10_000); @@ -254,7 +254,7 @@ suite('Bindings', () => { }); suite('WASI', () => { - test('basic app', async () => { + test('basic app (old API)', async () => { const { component } = await componentize( ` import { now } from 'wasi:clocks/wall-clock@0.2.3'; @@ -301,4 +301,40 @@ suite('WASI', () => { strictEqual(result.slice(0, 10), `NOW: ${String(Date.now()).slice(0, 5)}`); strictEqual(result.split(',').length, 3); }); + + test('basic app (OriginalSourceFile API)', async () => { + const { component } = await componentize( + { + sourcePath: "./test/api/index.js", + witPath: fileURLToPath(new URL('./wit', import.meta.url)), + worldName: 'test1', + enableAot, + debugBuild, + } + ); + + await writeFile( + new URL(`./output/wasi.component.wasm`, import.meta.url), + component + ); + + const { files } = await transpile(component, { tracing: DEBUG_TRACING }); + + await mkdir(new URL(`./output/wasi/interfaces`, import.meta.url), { + recursive: true, + }); + + for (const file of Object.keys(files)) { + await writeFile( + new URL(`./output/wasi/${file}`, import.meta.url), + files[file] + ); + } + + var instance = await import(`./output/wasi/component.js`); + instance.run.run(); + const result = instance.getResult(); + strictEqual(result.slice(0, 10), `NOW: ${String(Date.now()).slice(0, 5)}`); + strictEqual(result.split(',').length, 3); + }); });