do not fetch packageJson if version is specified

pull/3622/head
yann300 2 years ago
parent 44ef80bb05
commit dae0708a90
  1. 10
      libs/remix-url-resolver/src/resolve.ts

@ -137,7 +137,9 @@ export class RemixURLResolver {
*/
async handleNpmImport(url: string): Promise<HandlerResponse> {
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;
}

Loading…
Cancel
Save