Skip to content

Commit f07dd91

Browse files
author
Guy Bedford
committed
fixup error
1 parent e30222c commit f07dd91

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/componentize.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,23 @@ export async function componentize(jsSource, witWorld, opts) {
4646
worldName,
4747
disableFeatures = [],
4848
enableFeatures = [],
49-
aotCache = fileURLToPath(new URL(`../lib/starlingmonkey_ics.wevalcache`, import.meta.url))
49+
aotCache = fileURLToPath(
50+
new URL(`../lib/starlingmonkey_ics.wevalcache`, import.meta.url)
51+
),
5052
} = opts;
5153

52-
const engine = opts.engine || fileURLToPath(
53-
new URL(opts.enableAot ? `../lib/starlingmonkey_embedding_weval.wasm` : `../lib/starlingmonkey_embedding${DEBUG_BUILD ? '.debug' : ''}.wasm`, import.meta.url));
54+
const engine =
55+
opts.engine ||
56+
fileURLToPath(
57+
new URL(
58+
opts.enableAot
59+
? `../lib/starlingmonkey_embedding_weval.wasm`
60+
: `../lib/starlingmonkey_embedding${
61+
DEBUG_BUILD ? '.debug' : ''
62+
}.wasm`,
63+
import.meta.url
64+
)
65+
);
5466

5567
await lexerInit;
5668
let jsImports = [];
@@ -132,11 +144,22 @@ export async function componentize(jsSource, witWorld, opts) {
132144
// rewrite the JS source import specifiers to reference import wrappers
133145
let source = '',
134146
curIdx = 0;
147+
const importSpecifiers = new Set([...imports.map(([impt]) => impt)]);
135148
for (const jsImpt of jsImports) {
136149
if (jsImpt.t !== 1 && jsImpt.t !== 2) continue;
137150
if (!jsImpt.n) continue;
138-
if (!imports.some(([impt]) => jsImpt.n === impt)) {
139-
throw new Error(`Import '${jsImpt.n}' is not defined by the WIT world. Make sure to use a bundler for JS dependencies such as esbuild or RollupJS. Future ComponentizeJS versions may include Node.js builtins and bundling.`);
151+
if (!importSpecifiers.has(jsImpt.n)) {
152+
throw new Error(
153+
`Import '${
154+
jsImpt.n
155+
}' is not defined by the WIT world. Available imports are: ${[
156+
...importSpecifiers,
157+
]
158+
.map((impt) => `'${impt}'`)
159+
.join(
160+
', '
161+
)}.\nMake sure to use a bundler for JS dependencies such as esbuild or RollupJS.`
162+
);
140163
}
141164
const specifier = jsSource.slice(jsImpt.s, jsImpt.e);
142165
source += jsSource.slice(curIdx, jsImpt.s);
@@ -169,10 +192,8 @@ export async function componentize(jsSource, witWorld, opts) {
169192
let hostenv = {};
170193

171194
if (opts.env) {
172-
hostenv = (typeof opts.env === 'object')
173-
? opts.env
174-
: process.env;
175-
};
195+
hostenv = typeof opts.env === 'object' ? opts.env : process.env;
196+
}
176197

177198
const env = {
178199
...hostenv,
@@ -221,7 +242,7 @@ export async function componentize(jsSource, witWorld, opts) {
221242
'--init-func',
222243
'componentize.wizer',
223244
`-i ${input}`,
224-
`-o ${output}`
245+
`-o ${output}`,
225246
],
226247
{
227248
stdio: [null, stdout, stderr],

test/cases/bad-binding/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { strictEqual } from 'node:assert';
22

33
export function err (error) {
4-
strictEqual(error.message, "Import 'not:world-defined' is not defined by the WIT world. Make sure to use a bundler for JS dependencies such as esbuild or RollupJS. Future ComponentizeJS versions may include Node.js builtins and bundling.");
4+
strictEqual(error.message, "Import 'not:world-defined' is not defined by the WIT world. Available imports are: 'local:char/chars'.\nMake sure to use a bundler for JS dependencies such as esbuild or RollupJS.");
55
}

0 commit comments

Comments
 (0)