From cf188b577aae025baa69bd43e4ed7815ae7bc33e Mon Sep 17 00:00:00 2001 From: Robin Schreiber Date: Fri, 26 Jul 2024 17:53:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A8:=20fix=20+esm=20url=20handling=20w?= =?UTF-8?q?hen=20fetching=20via=20esm.run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lively.resources/src/esm-resource.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lively.resources/src/esm-resource.js b/lively.resources/src/esm-resource.js index 9be075a547..6846d92925 100644 --- a/lively.resources/src/esm-resource.js +++ b/lively.resources/src/esm-resource.js @@ -14,6 +14,7 @@ export class ESMResource extends Resource { // jspm servers both the entry point into a package as well as subcontent from package@version/ // differentiate these cases by introducing an index.js which will automatically be served by systemJS if (pathStructure.length === 1 || + !pathStructure[pathStructure.length - 1].endsWith('+esm') && !pathStructure[pathStructure.length - 1].endsWith('js') && !pathStructure[pathStructure.length - 1].endsWith('!cjs')) { let fileName = 'index.js'; @@ -24,6 +25,11 @@ export 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'); + } + if (pathStructure[pathStructure.length - 1].endsWith('.js!cjs')) { pathStructure[pathStructure.length - 1] = pathStructure[pathStructure.length - 1].replace('.js!cjs', '.cjs'); } @@ -40,7 +46,8 @@ export class ESMResource extends Resource { const id = this.url.replace(/esm:\/\/(run|cache)\//g, ''); let baseUrl = 'https://jspm.dev/'; - if (this.url.startsWith('esm://run/')) baseUrl = 'https://esm.run/'; + if (this.url.startsWith('esm://run/npm/')) baseUrl = 'https://cdn.jsdelivr.net/'; + else if (this.url.startsWith('esm://run/')) baseUrl = 'https://esm.run/'; let pathStructure = ESMResource.normalize(id); @@ -69,7 +76,9 @@ export class ESMResource extends Resource { // pathElements can together either describe a directory or a file // in the case that it is not a file (will be either js or !cjs) we need to fixup the last part of the path - if (!pathElements[pathElements.length - 1].endsWith('js') && !pathElements[pathElements.length - 1].endsWith('!cjs')) { + if (!pathElements[pathElements.length - 1].endsWith('js') && + !pathElements[pathElements.length - 1].endsWith('!cjs') && + !pathElements[pathElements.length - 1].endsWith('+esm')) { pathElements[pathElements.length - 1] = pathElements[pathElements.length - 1] + '/'; }