Skip to content

Commit 87ea736

Browse files
committed
fix(build): remove get-local-package-aliases from esbuild config
Remove unused get-local-package-aliases import and related functions from esbuild configuration. Update build.mjs to call clean.mjs directly instead of through load.cjs wrapper. These changes fix build errors after removing the loader infrastructure.
1 parent 2337eec commit 87ea736

File tree

2 files changed

+5
-63
lines changed

2 files changed

+5
-63
lines changed

.config/esbuild.config.mjs

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { builtinModules } from 'node:module'
66
import path from 'node:path'
77
import { fileURLToPath } from 'node:url'
88

9-
import { getLocalPackageAliases } from '../scripts/utils/get-local-package-aliases.mjs'
10-
119
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1210
const rootPath = path.join(__dirname, '..')
1311
const srcPath = path.join(rootPath, 'src')
@@ -181,59 +179,6 @@ function createPathShorteningPlugin() {
181179
}
182180
}
183181

184-
/**
185-
* Plugin to handle local package aliases.
186-
* Provides consistent alias resolution across all Socket repos.
187-
* Note: Does not externalize @socketsecurity/lib - that should be bundled.
188-
*/
189-
function createAliasPlugin() {
190-
const aliases = getLocalPackageAliases(rootPath)
191-
192-
// Only create plugin if we have local aliases
193-
if (Object.keys(aliases).length === 0) {
194-
return null
195-
}
196-
197-
// Packages that should always be bundled (even when using local aliases)
198-
const ALWAYS_BUNDLED = new Set(['@socketsecurity/lib'])
199-
200-
return {
201-
name: 'local-package-aliases',
202-
setup(build) {
203-
// Intercept imports for aliased packages (except @socketsecurity/lib which should be bundled)
204-
for (const [packageName, _aliasPath] of Object.entries(aliases)) {
205-
// Skip packages that should always be bundled - let esbuild bundle them naturally
206-
if (ALWAYS_BUNDLED.has(packageName)) {
207-
continue
208-
}
209-
210-
// Match both exact package name and subpath imports
211-
build.onResolve(
212-
{ filter: new RegExp(`^${packageName}(/|$)`) },
213-
args => {
214-
// Mark as external using the original package name to avoid absolute paths in output.
215-
// This ensures require('@socketsecurity/lib') instead of require('/absolute/path/to/socket-lib/dist').
216-
return { path: args.path, external: true }
217-
},
218-
)
219-
}
220-
},
221-
}
222-
}
223-
224-
// Get local package aliases for bundled packages
225-
function getBundledPackageAliases() {
226-
const aliases = getLocalPackageAliases(rootPath)
227-
const bundledAliases = {}
228-
229-
// @socketsecurity/lib should always be bundled (not external)
230-
if (aliases['@socketsecurity/lib']) {
231-
bundledAliases['@socketsecurity/lib'] = aliases['@socketsecurity/lib']
232-
}
233-
234-
return bundledAliases
235-
}
236-
237182
// Build configuration for CommonJS output
238183
export const buildConfig = {
239184
entryPoints: [`${srcPath}/index.ts`],
@@ -254,11 +199,8 @@ export const buildConfig = {
254199
// Preserve module structure for better tree-shaking
255200
splitting: false,
256201

257-
// Alias local packages that should be bundled (not external)
258-
alias: getBundledPackageAliases(),
259-
260-
// Use plugins for local package aliases and path shortening
261-
plugins: [createPathShorteningPlugin(), createAliasPlugin()].filter(Boolean),
202+
// Use plugins for path shortening
203+
plugins: [createPathShorteningPlugin()],
262204

263205
// External dependencies
264206
external: [

scripts/build.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function buildSource(options = {}) {
4343
if (!skipClean) {
4444
const exitCode = await runSequence([
4545
{
46-
args: ['scripts/load.cjs', 'clean', '--dist', '--quiet'],
46+
args: ['scripts/clean.mjs', '--dist', '--quiet'],
4747
command: 'node',
4848
},
4949
])
@@ -94,7 +94,7 @@ async function buildTypes(options = {}) {
9494

9595
if (!skipClean) {
9696
commands.push({
97-
args: ['scripts/load.cjs', 'clean', '--types', '--quiet'],
97+
args: ['scripts/clean.mjs', '--types', '--quiet'],
9898
command: 'node',
9999
})
100100
}
@@ -338,7 +338,7 @@ async function main() {
338338
}
339339
exitCode = await runSequence([
340340
{
341-
args: ['scripts/load.cjs', 'clean', '--dist', '--types', '--quiet'],
341+
args: ['scripts/clean.mjs', '--dist', '--types', '--quiet'],
342342
command: 'node',
343343
},
344344
])

0 commit comments

Comments
 (0)