From dae0708a90c2d181cb5d4f99ec7c1f8952229960 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 17 Apr 2023 13:40:18 +0200 Subject: [PATCH] do not fetch packageJson if version is specified --- libs/remix-url-resolver/src/resolve.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/remix-url-resolver/src/resolve.ts b/libs/remix-url-resolver/src/resolve.ts index dbe1d09167..96ced4dd64 100644 --- a/libs/remix-url-resolver/src/resolve.ts +++ b/libs/remix-url-resolver/src/resolve.ts @@ -137,7 +137,9 @@ export class RemixURLResolver { */ async handleNpmImport(url: string): Promise { - if (this.getDependencies) { + if (!url) throw new Error('url is empty') + const isVersionned = semverRegex().exec(url.replace(/@/g, '@ ').replace(/\//g, ' /')) + if (this.getDependencies && !isVersionned) { try { const { deps, yarnLock, packageLock } = await this.getDependencies() let matchLength = 0 @@ -177,7 +179,6 @@ export class RemixURLResolver { } } - const npm_urls = ["https://cdn.jsdelivr.net/npm/", "https://unpkg.com/"] process && process.env && process.env['NPM_URL'] && npm_urls.unshift(process.env['NPM_URL']) let content = null @@ -253,3 +254,8 @@ export class RemixURLResolver { return imported } } + +// see npm semver-regex +function semverRegex() { + return /(?<=^v?|\sv?)(?:(?:0|[1-9]\d{0,9}?)\.){2}(?:0|[1-9]\d{0,9})(?:-(?:--+)?(?:0|[1-9]\d*|\d*[a-z]+\d*)){0,100}(?=$| |\+|\.)(?:(?<=-\S+)(?:\.(?:--?|[\da-z-]*[a-z-]\d*|0|[1-9]\d*)){1,100}?)?(?!\.)(?:\+(?:[\da-z]\.?-?){1,100}?(?!\w))?(?!\+)/gi; +}