|
|
|
@ -137,29 +137,36 @@ 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 version |
|
|
|
|
if (yarnLock) { |
|
|
|
|
// yarn.lock
|
|
|
|
|
const regex = new RegExp(`"${pkg}@(.*)"`, 'g') |
|
|
|
|
const yarnVersion = regex.exec(yarnLock) |
|
|
|
|
if (yarnVersion && yarnVersion.length > 1) { |
|
|
|
|
version = yarnVersion[1] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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] |
|
|
|
|
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
|
|
|
|
|
const regex = new RegExp(`"${pkg}@(.*)"`, 'g') |
|
|
|
|
const yarnVersion = regex.exec(yarnLock) |
|
|
|
|
if (yarnVersion && yarnVersion.length > 1) { |
|
|
|
|
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) { |
|
|
|
|
console.log(e) |
|
|
|
|
} |
|
|
|
|