|
|
@ -1,5 +1,6 @@ |
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
|
|
|
|
import semver from 'semver' |
|
|
|
import { BzzNode as Bzz } from '@erebos/bzz-node' |
|
|
|
import { BzzNode as Bzz } from '@erebos/bzz-node' |
|
|
|
|
|
|
|
|
|
|
|
export interface Imported { |
|
|
|
export interface Imported { |
|
|
@ -137,14 +138,16 @@ export class RemixURLResolver { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
async handleNpmImport(url: string): Promise<HandlerResponse> { |
|
|
|
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 { |
|
|
|
try { |
|
|
|
const { deps, yarnLock, packageLock } = await this.getDependencies() |
|
|
|
const { deps, yarnLock, packageLock } = await this.getDependencies() |
|
|
|
let matchLength = 0 |
|
|
|
let matchLength = 0 |
|
|
|
let pkg |
|
|
|
let pkg |
|
|
|
if (deps) { |
|
|
|
if (deps) { |
|
|
|
Object.keys(deps).map((dep) => { |
|
|
|
Object.keys(deps).map((dep) => { |
|
|
|
const reg = new RegExp(dep, 'g') |
|
|
|
const reg = new RegExp(dep + '/', 'g') |
|
|
|
const match = url.match(reg) |
|
|
|
const match = url.match(reg) |
|
|
|
if (match && match.length > 0 && matchLength < match[0].length) { |
|
|
|
if (match && match.length > 0 && matchLength < match[0].length) { |
|
|
|
matchLength = match[0].length |
|
|
|
matchLength = match[0].length |
|
|
@ -169,7 +172,10 @@ export class RemixURLResolver { |
|
|
|
// package.json
|
|
|
|
// package.json
|
|
|
|
version = deps[pkg] |
|
|
|
version = deps[pkg] |
|
|
|
} |
|
|
|
} |
|
|
|
if (version) url = url.replace(pkg, `${pkg}@${version}`) |
|
|
|
if (version) { |
|
|
|
|
|
|
|
const versionSemver = semver.minVersion(version) |
|
|
|
|
|
|
|
url = url.replace(pkg, `${pkg}@${versionSemver.version}`) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -177,7 +183,6 @@ export class RemixURLResolver { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const npm_urls = ["https://cdn.jsdelivr.net/npm/", "https://unpkg.com/"] |
|
|
|
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']) |
|
|
|
process && process.env && process.env['NPM_URL'] && npm_urls.unshift(process.env['NPM_URL']) |
|
|
|
let content = null |
|
|
|
let content = null |
|
|
@ -253,3 +258,8 @@ export class RemixURLResolver { |
|
|
|
return imported |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|