Skip to content

Commit

Permalink
fix: specifier mappings in componentizeJS
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Dec 11, 2024
1 parent 423117c commit f172488
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/componentize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const isWindows = platform === 'win32';
const DEBUG_BINDINGS = false;
const DEBUG_CALLS = false;
const DEBUG_BUILD = false;
const DEBUG_BINARY = false;

function maybeWindowsPath(path) {
if (!path) return path;
Expand Down Expand Up @@ -61,13 +62,13 @@ export async function componentize(jsSource, witWorld, opts) {
}

let guestImports = [];
jsImports.map((k) => {
guestImports.push(k.n);
jsImports.map(({ t, n }) => {
if (typeof n === 'string' && (t === 1 || t === 2)) guestImports.push(n);
});

let guestExports = [];
jsExports.map((k) => {
guestExports.push(k.n);
if (k.n) guestExports.push(k.n);
});

// we never disable a feature that is already in the target world usage
Expand Down Expand Up @@ -132,6 +133,7 @@ export async function componentize(jsSource, witWorld, opts) {
let source = '',
curIdx = 0;
for (const jsImpt of jsImports) {
if (jsImpt.t !== 1 && jsImpt.t !== 2) continue;
const specifier = jsSource.slice(jsImpt.s, jsImpt.e);
source += jsSource.slice(curIdx, jsImpt.s);
source += `./${specifier.replace(':', '__').replace('/', '$')}.js`;
Expand Down Expand Up @@ -378,6 +380,10 @@ export async function componentize(jsSource, witWorld, opts) {
worldName
);

if (DEBUG_BINARY) {
await writeFile('binary.wasm', finalBin);
}

const component = await metadataAdd(
await componentNew(
finalBin,
Expand Down

0 comments on commit f172488

Please sign in to comment.