Skip to content

Commit 576adaa

Browse files
committed
refactor(build): simplify alias plugin to single regexp handler
Consolidated two separate onResolve handlers into one using a unified regexp pattern that matches both exact package imports and subpath imports with (/|$). This reduces code complexity while maintaining the same functionality for local package alias resolution.
1 parent f43cd86 commit 576adaa

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

.config/esbuild.config.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ function createAliasPlugin() {
3939
setup(build) {
4040
// Intercept imports for aliased packages
4141
for (const [packageName, aliasPath] of Object.entries(aliases)) {
42-
build.onResolve({ filter: new RegExp(`^${packageName}$`) }, () => {
43-
// Return the path to the local package dist
44-
return { path: aliasPath, external: true }
45-
})
46-
47-
// Handle subpath imports like '@socketsecurity/lib/spinner'
48-
build.onResolve({ filter: new RegExp(`^${packageName}/`) }, args => {
42+
// Match both exact package name and subpath imports
43+
build.onResolve({ filter: new RegExp(`^${packageName}(/|$)`) }, args => {
44+
// Handle subpath imports like '@socketsecurity/lib/spinner'
4945
const subpath = args.path.slice(packageName.length + 1)
50-
return { path: path.join(aliasPath, subpath), external: true }
46+
const resolvedPath = subpath ? path.join(aliasPath, subpath) : aliasPath
47+
return { path: resolvedPath, external: true }
5148
})
5249
}
5350
},

0 commit comments

Comments
 (0)