Skip to content

Commit

Permalink
🫓: update faltn
Browse files Browse the repository at this point in the history
  • Loading branch information
merryman committed Feb 5, 2025
1 parent 15afd2d commit c0b3586
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions flatn/flatn-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15493,7 +15493,7 @@ const requestMap = {};

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

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

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


if (pathStructure[pathStructure.length - 1].endsWith('+esm')) {
pathStructure[pathStructure.length - 1] = pathStructure[pathStructure.length - 1].replace('+esm', 'esm.js');
}
Expand All @@ -15527,13 +15526,22 @@ class ESMResource extends Resource {
return pathStructure;
}

async read () {
let module;

const id = this.url.replace(/esm:\/\/(run|cache)\//g, '');
let baseUrl = 'https://jspm.dev/';
getEsmURL () {
let baseUrl;
if (this.url.startsWith('esm://run/npm/')) baseUrl = 'https://cdn.jsdelivr.net/';
else if (this.url.startsWith('esm://run/')) baseUrl = 'https://esm.run/';
else if (this.url.startsWith('esm://cache/')) baseUrl = 'https://jspm.dev/';
else {
const domain = this.url.match(/esm:\/\/([^\/]*)\//)?.[1];
baseUrl = `https://${domain}/`;
}
return baseUrl;
}

async read () {
let module;
const id = this.url.replace(/esm:\/\/([^\/]*)\//g, '');
const esmURL = this.getEsmURL();

let pathStructure = ESMResource.normalize(id);

Expand All @@ -15544,7 +15552,7 @@ class ESMResource extends Resource {
if (typeof lively !== 'undefined' && (hit = lively.memory_esm?.get(shortName))) return await hit.blob.text();
module = await res.read();
} else {
module = await resource((baseUrl + id)).read();
module = await resource((esmURL + id)).read();
res.write(module);
}
return module;
Expand Down Expand Up @@ -15627,7 +15635,9 @@ class ESMResource extends Resource {
}

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

async remove () {
Expand Down

0 comments on commit c0b3586

Please sign in to comment.