Skip to content

Commit cc20963

Browse files
committed
optimize rollup external checks ordering
1 parent ad64708 commit cc20963

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

.config/rollup.base.config.mjs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,32 @@ export default function baseConfig(extendConfig = {}) {
140140
// but is actually accessed dynamically or through other means.
141141
treeshake: false,
142142
external(rawId) {
143+
// Order checks by likelihood for better performance.
144+
// Externalize Node.js built-ins (most common case).
145+
if (isBuiltin(rawId)) {
146+
return true
147+
}
148+
// Externalize special rollup external suffix.
149+
if (rawId.endsWith(ROLLUP_EXTERNAL_SUFFIX)) {
150+
return true
151+
}
143152
const id = normalizeId(rawId)
153+
// Externalize anything from the external directory.
154+
if (id.includes('/external/')) {
155+
return true
156+
}
157+
// Externalize TypeScript declaration files.
158+
if (
159+
id.endsWith('.d.ts') ||
160+
id.endsWith('.d.mts') ||
161+
id.endsWith('.d.cts')
162+
) {
163+
return true
164+
}
144165
const pkgName = getPackageName(
145166
id,
146167
path.isAbsolute(id) ? nmPath.length + 1 : 0,
147168
)
148-
// Externalize anything from the external directory.
149-
if (id.includes('/external/') || id.startsWith('../external/')) {
150-
return true
151-
}
152169
// Externalize @socketsecurity/registry and all its internal paths.
153170
if (
154171
pkgName === '@socketsecurity/registry' ||
@@ -164,14 +181,8 @@ export default function baseConfig(extendConfig = {}) {
164181
) {
165182
return true
166183
}
167-
return (
168-
id.endsWith('.d.cts') ||
169-
id.endsWith('.d.mts') ||
170-
id.endsWith('.d.ts') ||
171-
EXTERNAL_PACKAGES.includes(pkgName) ||
172-
rawId.endsWith(ROLLUP_EXTERNAL_SUFFIX) ||
173-
isBuiltin(rawId)
174-
)
184+
// Externalize other specific external packages.
185+
return EXTERNAL_PACKAGES.includes(pkgName)
175186
},
176187
onwarn(warning, warn) {
177188
// Suppress warnings.

0 commit comments

Comments
 (0)