Skip to content

Commit a6b8444

Browse files
committed
refactor(build): auto-detect external dependencies from package.json
Change esbuild configuration to dynamically read runtime dependencies from package.json instead of manually listing them. Changes: - Read package.json at build time to get dependencies object - Use Object.keys(dependencies) to populate external array - Remove hardcoded list of external dependencies Benefits: - Automatically keeps external dependencies in sync with package.json - Prevents mistakes where dependencies are added but not marked external - Clearer intent: all dependencies are external, devDependencies bundled - Eliminates manual maintenance of external array Verification: - form-data correctly marked as external (not bundled inline) - Bundle only contains require("form-data") statement - All bundle validation tests pass
1 parent 0911748 commit a6b8444

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

.config/esbuild.config.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const distPath = path.join(rootPath, 'dist')
2222

2323
const logger = getDefaultLogger()
2424

25+
// Read package.json to get runtime dependencies
26+
const packageJsonPath = path.join(rootPath, 'package.json')
27+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))
28+
const externalDependencies = Object.keys(packageJson.dependencies || {})
29+
2530
/**
2631
* Plugin to shorten module paths in bundled output with conflict detection.
2732
* Uses @babel/parser and magic-string for precise AST-based modifications.
@@ -225,12 +230,8 @@ export const buildConfig = {
225230
),
226231

227232
// External dependencies.
228-
// @socketsecurity/lib, form-data, and @socketregistry/packageurl-js are external (not bundled) - consumers must install them.
229-
external: [
230-
'@socketsecurity/lib',
231-
'@socketregistry/packageurl-js',
232-
'form-data',
233-
],
233+
// All runtime dependencies from package.json are external (not bundled) - consumers must install them.
234+
external: externalDependencies,
234235

235236
// TypeScript configuration
236237
tsconfig: path.join(rootPath, 'tsconfig.json'),

0 commit comments

Comments
 (0)