fix using package json dependencies

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

@ -137,29 +137,36 @@ export class RemixURLResolver {
if (this.getDependencies) { if (this.getDependencies) {
try { try {
const { deps, yarnLock, packageLock } = await this.getDependencies() const { deps, yarnLock, packageLock } = await this.getDependencies()
for (const pkg of Object.keys(deps)) { let matchLength = 0
if (url.startsWith(pkg)) { let pkg
let version Object.keys(deps).map((dep) => {
if (yarnLock) { const reg = new RegExp(dep, 'g')
// yarn.lock const match = url.match(reg)
const regex = new RegExp(`"${pkg}@(.*)"`, 'g') if (match && match.length > 0 && matchLength < match[0].length) {
const yarnVersion = regex.exec(yarnLock) matchLength = match[0].length
if (yarnVersion && yarnVersion.length > 1) { pkg = dep
version = yarnVersion[1] }
} })
} if (pkg) {
if (!version && packageLock['dependencies'] && packageLock['dependencies'][pkg] && packageLock['dependencies'][pkg]['version']) { let version
// package-lock.json if (yarnLock) {
version = packageLock['dependencies'][pkg]['version'] // yarn.lock
} const regex = new RegExp(`"${pkg}@(.*)"`, 'g')
if (!version) { const yarnVersion = regex.exec(yarnLock)
// package.json if (yarnVersion && yarnVersion.length > 1) {
version = deps[pkg] version = yarnVersion[1]
} }
if (version) url = url.replace(pkg, `${pkg}@${version}`)
break
} }
} if (!version && packageLock['dependencies'] && packageLock['dependencies'][pkg] && packageLock['dependencies'][pkg]['version']) {
// package-lock.json
version = packageLock['dependencies'][pkg]['version']
}
if (!version) {
// package.json
version = deps[pkg]
}
if (version) url = url.replace(pkg, `${pkg}@${version}`)
}
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }

Loading…
Cancel
Save