fix(nitro): allow inlining subpath of externals (#2759)

This commit is contained in:
Ahad Birang 2022-01-17 20:55:26 +03:30 committed by GitHub
parent fb0a27aa98
commit eb14eca702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,8 +39,9 @@ export function externals (opts: NodeExternalsOptions): Plugin {
// Normalize from node_modules // Normalize from node_modules
const _id = id.split('node_modules/').pop() const _id = id.split('node_modules/').pop()
const externalPath = opts.external.find(i => _id.startsWith(i) || id.startsWith(i))
// Skip checks if is an explicit external // Skip checks if is an explicit external
if (!opts.external.find(i => _id.startsWith(i) || id.startsWith(i))) { if (!externalPath) {
// Resolve relative paths and exceptions // Resolve relative paths and exceptions
// Ensure to take absolute and relative id // Ensure to take absolute and relative id
if (_id.startsWith('.') || opts.inline.find(i => _id.startsWith(i) || id.startsWith(i))) { if (_id.startsWith('.') || opts.inline.find(i => _id.startsWith(i) || id.startsWith(i))) {
@ -50,6 +51,9 @@ export function externals (opts: NodeExternalsOptions): Plugin {
if (/\.(ts|wasm|json)$/.test(_id)) { if (/\.(ts|wasm|json)$/.test(_id)) {
return null return null
} }
// Check for subpaths
} else if (opts.inline.find(i => i.startsWith(externalPath) && (_id.startsWith(i) || id.startsWith(i)))) {
return null
} }
// Track externals // Track externals