Skip to content

Commit

Permalink
fix(externals): improve fallback error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 7, 2022
1 parent b4ced48 commit 6b355ca
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/rollup/plugins/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,17 @@ export function externals (opts: NodeExternalsOptions): Plugin {
return { id, external: true }
}

// Resolve id (rollup > esm)
// Resolve id using rollup resolver
const resolved = await this.resolve(originalId, importer, { ...options, skipSelf: true }) || { id }

// Try resolving with mlly as fallback
if (!existsSync(resolved.id)) {
resolved.id = await _resolve(resolved.id)
resolved.id = await _resolve(resolved.id).catch(() => resolved.id)
}

// Inline invalid node imports
if (!await isValidNodeImport(resolved.id)) {
return {
...resolved,
external: false
}
if (!await isValidNodeImport(resolved.id).catch(() => false)) {
return null
}

// Externalize with full path if trace is disabled
Expand Down

0 comments on commit 6b355ca

Please sign in to comment.