Skip to content

Commit 45421f5

Browse files
merrymanlinusha
authored andcommitted
🫓: rebuild flatn
1 parent 1426c46 commit 45421f5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

flatn/flatn-cjs.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15493,7 +15493,7 @@ const requestMap = {};
1549315493

1549415494
class ESMResource extends Resource {
1549515495
static normalize (esmUrl) {
15496-
const id = esmUrl.replaceAll(/esm:\/\/(run|cache)\//g, '');
15496+
const id = esmUrl.replaceAll(/esm:\/\/([^\/]*)\//g, '');
1549715497

1549815498
let pathStructure = id.split('/').filter(Boolean);
1549915499

@@ -15511,7 +15511,6 @@ class ESMResource extends Resource {
1551115511
pathStructure.push(fileName);
1551215512
}
1551315513

15514-
1551515514
if (pathStructure[pathStructure.length - 1].endsWith('+esm')) {
1551615515
pathStructure[pathStructure.length - 1] = pathStructure[pathStructure.length - 1].replace('+esm', 'esm.js');
1551715516
}
@@ -15527,13 +15526,22 @@ class ESMResource extends Resource {
1552715526
return pathStructure;
1552815527
}
1552915528

15530-
async read () {
15531-
let module;
15532-
15533-
const id = this.url.replace(/esm:\/\/(run|cache)\//g, '');
15534-
let baseUrl = 'https://jspm.dev/';
15529+
getEsmURL () {
15530+
let baseUrl;
1553515531
if (this.url.startsWith('esm://run/npm/')) baseUrl = 'https://cdn.jsdelivr.net/';
1553615532
else if (this.url.startsWith('esm://run/')) baseUrl = 'https://esm.run/';
15533+
else if (this.url.startsWith('esm://cache/')) baseUrl = 'https://jspm.dev/';
15534+
else {
15535+
const domain = this.url.match(/esm:\/\/([^\/]*)\//)?.[1];
15536+
baseUrl = `https://${domain}/`;
15537+
}
15538+
return baseUrl;
15539+
}
15540+
15541+
async read () {
15542+
let module;
15543+
const id = this.url.replace(/esm:\/\/([^\/]*)\//g, '');
15544+
const esmURL = this.getEsmURL();
1553715545

1553815546
let pathStructure = ESMResource.normalize(id);
1553915547

@@ -15544,7 +15552,7 @@ class ESMResource extends Resource {
1554415552
if (typeof lively !== 'undefined' && (hit = lively.memory_esm?.get(shortName))) return await hit.blob.text();
1554515553
module = await res.read();
1554615554
} else {
15547-
module = await resource((baseUrl + id)).read();
15555+
module = await resource((esmURL + id)).read();
1554815556
res.write(module);
1554915557
}
1555015558
return module;
@@ -15627,7 +15635,9 @@ class ESMResource extends Resource {
1562715635
}
1562815636

1562915637
async exists () {
15630-
// stub that needs to exist
15638+
const id = this.url.replace(/esm:\/\/([^\/]*)\//g, '');
15639+
const baseUrl = this.getEsmURL();
15640+
return await resource(baseUrl).join(id).exists();
1563115641
}
1563215642

1563315643
async remove () {

0 commit comments

Comments
 (0)