|
|
|
@ -135,14 +135,16 @@ export class RemixURLResolver { |
|
|
|
|
* Handle an import statement based on NPM |
|
|
|
|
* @param url The url of the NPM import statement |
|
|
|
|
*/ |
|
|
|
|
async handleNpmImport (url: string): Promise<HandlerResponse> { |
|
|
|
|
async handleNpmImport(url: string): Promise<HandlerResponse> { |
|
|
|
|
// eslint-disable-next-line no-useless-catch
|
|
|
|
|
try { |
|
|
|
|
if (this.getDependencies) { |
|
|
|
|
try { |
|
|
|
|
const { deps, yarnLock, packageLock } = await this.getDependencies() |
|
|
|
|
console.log('deps', deps, yarnLock, packageLock) |
|
|
|
|
let matchLength = 0 |
|
|
|
|
let pkg |
|
|
|
|
if (deps) { |
|
|
|
|
Object.keys(deps).map((dep) => { |
|
|
|
|
const reg = new RegExp(dep, 'g') |
|
|
|
|
const match = url.match(reg) |
|
|
|
@ -171,12 +173,14 @@ export class RemixURLResolver { |
|
|
|
|
} |
|
|
|
|
if (version) url = url.replace(pkg, `${pkg}@${version}`) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const req = 'https://unpkg.com/' + url |
|
|
|
|
const response: AxiosResponse = await axios.get(req, { transformResponse: [] }) |
|
|
|
|
console.log('handleNpmImport', url, response.data, req) |
|
|
|
|
return { content: response.data, cleanUrl: url } |
|
|
|
|
} catch (e) { |
|
|
|
|
throw e |
|
|
|
|