fix using package json dependencies

pull/3311/head
yann300 2 years ago
parent ec968ee67b
commit fb4989fa37
  1. 15
      libs/remix-url-resolver/src/resolve.ts

@ -137,8 +137,17 @@ export class RemixURLResolver {
if (this.getDependencies) {
try {
const { deps, yarnLock, packageLock } = await this.getDependencies()
for (const pkg of Object.keys(deps)) {
if (url.startsWith(pkg)) {
let matchLength = 0
let pkg
Object.keys(deps).map((dep) => {
const reg = new RegExp(dep, 'g')
const match = url.match(reg)
if (match && match.length > 0 && matchLength < match[0].length) {
matchLength = match[0].length
pkg = dep
}
})
if (pkg) {
let version
if (yarnLock) {
// yarn.lock
@ -157,8 +166,6 @@ export class RemixURLResolver {
version = deps[pkg]
}
if (version) url = url.replace(pkg, `${pkg}@${version}`)
break
}
}
} catch (e) {
console.log(e)

Loading…
Cancel
Save