Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Nov 25, 2024
1 parent b098738 commit 6a77df1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/repl-sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class Compiler {
if (this.#options.logging) {
console.debug('[resolve]', id);
}

if (id.startsWith('blob:')) return id;
if (id.startsWith('https://')) return id;
if (id.startsWith('.')) return id;
Expand All @@ -52,6 +53,7 @@ export class Compiler {
if (this.#options.logging) {
console.debug(`[resolve] ${id} found in manually specified resolver`);
}

return `manual:${id}`;
}

Expand All @@ -66,6 +68,7 @@ export class Compiler {
if (this.#options.resolve) {
if (url.startsWith('manual:')) {
let name = url.replace(/^manual:/, '');

if (this.#options.logging) {
console.debug('[fetch] resolved url in manually specified resolver', url);
}
Expand All @@ -86,13 +89,15 @@ export class Compiler {

window[secret].resolves ||= {};
window[secret].resolves[name] ||= result;

let blobContent =
`const mod = window[Symbol.for('${secretKey}')].resolves?.['${name}'];\n` +
`${Object.keys(result)
.map((exportName) => {
if (exportName === 'default') {
return `export default mod.default;`;
}
return `export const ${exportName} = mod.${exportName};`;
})
.join('\n')}
Expand All @@ -107,13 +112,15 @@ export class Compiler {
);
// console.debug(await blob.text());
}

return new Response(blob);
}
}

if (this.#options.logging) {
console.debug('[fetch] fetching url', url, options);
}

const response = await fetch(url, options);

return response;
Expand Down Expand Up @@ -249,6 +256,7 @@ export class Compiler {
if (this.#options.logging) {
console.warn(`Could not load ${name}. Trying fallback.`);
}

morePromises[i] = fallback(name);
}
}
Expand Down

0 comments on commit 6a77df1

Please sign in to comment.