Skip to content

Commit

Permalink
fix 1. bug with compound extensions, such as .tar.gz.bin (add test?) …
Browse files Browse the repository at this point in the history
…2. regex non-match issue with chunks that include "_" in their id
  • Loading branch information
adrianlyjak committed Apr 27, 2024
1 parent 4aa4241 commit b9e541c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/cloudflare/src/utils/wasm-module-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ export function cloudflareModuleLoader(
},

async load(id, _) {
const suffix = id.split('.').at(-1);
const importAdapter = cloudflareImportAdapters.find((x) => x.qualifiedExtension === suffix);
const importAdapter = cloudflareImportAdapters.find((x) => id.endsWith(x.qualifiedExtension));
if (!importAdapter) {
return;
}
if (!enabled) {
throw new Error(
`Cloudflare module loading is experimental. The ${suffix} module cannot be loaded unless you add \`wasmModuleImports: true\` to your astro config.`
`Cloudflare module loading is experimental. The ${importAdapter.qualifiedExtension} module cannot be loaded unless you add \`wasmModuleImports: true\` to your astro config.`
);
}

Expand Down Expand Up @@ -106,7 +105,8 @@ export function cloudflareModuleLoader(
let replaced = code;
for (const loader of enabledAdapters) {
replaced = replaced.replaceAll(
new RegExp(`${MAGIC_STRING}([A-Za-z\\d]+)\\.${loader.extension}\\.mjs`, 'g'),
// chunk id can be many things, (alpha numeric, dollars, or underscores, maybe more)
new RegExp(`${MAGIC_STRING}([^\\s]+?)\\.${loader.extension}\\.mjs`, 'g'),
(s, assetId) => {
const fileName = this.getFileName(assetId);
const relativePath = path
Expand Down

0 comments on commit b9e541c

Please sign in to comment.