Skip to content

Commit 691cc07

Browse files
authored
chore(build): bump esbuild target to node25 (#1216)
* chore(build): bump esbuild target to node25 Updates the hardcoded esbuild `target` in the two prod build configs (cli.mts and esbuild-utils.mts) from 'node18' to 'node25' so the output matches what we actually ship and run (see .node-version). No runtime behavior change; just unlocks the newer syntax lowering defaults in esbuild so the bundle doesn't carry transforms for language features that are already native in node 18+. * chore(build): extract shared esbuild base config (DRY) Introduces `createBaseConfig(inlinedEnvVars)` in esbuild-utils.mts that returns the settings every Socket CLI esbuild config needs to agree on: bundle, format, minify, platform, sourcemap, target, write, define: { 'process.env.NODE_ENV': '"production"', ...inlined } Both callers spread it and add their variant-specific fields: * `createIndexConfig` (index loader): banner + entry + output + env-var replacement plugin. * `esbuild.cli.mts` (main bundle): shebang+importMeta banner, extra `import.meta.url` define, `keepNames`, `loader`, `logOverride`, `metafile`, plugin stack. Before: the Node target and six other shared settings were duplicated between the two configs, so bumping something like `target: 'node25'` meant remembering to touch both files (and earlier PRs did miss exactly that pattern). No behavior change — diffed the build output before/after.
1 parent 1e443ae commit 691cc07

File tree

2 files changed

+53
-45
lines changed

2 files changed

+53
-45
lines changed

packages/cli/.config/esbuild.cli.mts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IMPORT_META_URL_BANNER } from 'build-infra/lib/esbuild-helpers'
1414
import { unicodeTransformPlugin } from 'build-infra/lib/esbuild-plugin-unicode-transform'
1515

1616
import {
17-
createDefineEntries,
17+
createBaseConfig,
1818
envVarReplacementPlugin,
1919
getInlinedEnvVars,
2020
runBuild,
@@ -58,33 +58,27 @@ function resolveSocketLibExternal(socketLibPath: string, packageName: string) {
5858
}
5959

6060

61+
const baseConfig = createBaseConfig(inlinedEnvVars)
62+
6163
const config: BuildOptions = {
64+
...baseConfig,
65+
banner: {
66+
js: `#!/usr/bin/env node\n"use strict";\n${IMPORT_META_URL_BANNER.js}`,
67+
},
68+
define: {
69+
...baseConfig.define,
70+
'import.meta.url': '__importMetaUrl',
71+
},
6272
entryPoints: [path.join(rootPath, 'src/cli-dispatch.mts')],
63-
bundle: true,
64-
outfile: path.join(rootPath, 'build/cli.js'),
65-
platform: 'node',
66-
target: 'node18',
67-
format: 'cjs',
73+
keepNames: true,
74+
// .cs files used by node-gyp on Windows.
75+
loader: { '.cs': 'empty' },
6876
logOverride: {
6977
'commonjs-variable-in-esm': 'silent',
7078
'require-resolve-not-external': 'silent',
7179
},
72-
// .cs files used by node-gyp on Windows.
73-
loader: { '.cs': 'empty' },
74-
sourcemap: false,
75-
minify: false,
76-
keepNames: true,
77-
write: false,
7880
metafile: true,
79-
define: {
80-
'process.env.NODE_ENV': '"production"',
81-
'import.meta.url': '__importMetaUrl',
82-
...createDefineEntries(inlinedEnvVars),
83-
},
84-
banner: {
85-
js: `#!/usr/bin/env node\n"use strict";\n${IMPORT_META_URL_BANNER.js}`,
86-
},
87-
81+
outfile: path.join(rootPath, 'build/cli.js'),
8882
plugins: [
8983
unicodeTransformPlugin(),
9084
// Environment variable replacement must run AFTER unicode transform.

packages/cli/scripts/esbuild-utils.mts

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,56 @@ import { EnvironmentVariables } from './environment-variables.mts'
1515

1616
const logger = getDefaultLogger()
1717

18+
/**
19+
* Settings every Socket CLI esbuild config shares.
20+
*
21+
* Kept in one place so the target Node version, module format, minify
22+
* default, etc. can't drift between the index loader and the main CLI
23+
* bundle. Callers spread this and add variant-specific fields
24+
* (entry points, output, banner, plugins, extra defines).
25+
*/
26+
export function createBaseConfig(
27+
inlinedEnvVars: Record<string, string>,
28+
): BuildOptions {
29+
return {
30+
bundle: true,
31+
define: {
32+
'process.env.NODE_ENV': '"production"',
33+
...createDefineEntries(inlinedEnvVars),
34+
},
35+
format: 'cjs',
36+
minify: false,
37+
platform: 'node',
38+
// We don't ship minified bundles and we don't ship sourcemaps for prod.
39+
sourcemap: false,
40+
target: 'node25',
41+
// Plugin writes are handled by `runBuild` so every caller's env-var
42+
// replacement can mutate output buffers before they hit disk.
43+
write: false,
44+
}
45+
}
46+
1847
/**
1948
* Create a standard index loader config.
20-
* @param {Object} options - Configuration options
21-
* @param {string} options.entryPoint - Path to entry point file
22-
* @param {string} options.outfile - Path to output file
23-
* @returns {Object} esbuild configuration object
2449
*/
25-
export function createIndexConfig({ entryPoint, outfile }: { entryPoint: string; outfile: string }) {
26-
// Get inlined environment variables for build-time constant replacement.
50+
export function createIndexConfig({
51+
entryPoint,
52+
outfile,
53+
}: {
54+
entryPoint: string
55+
outfile: string
56+
}): BuildOptions {
2757
const inlinedEnvVars = getInlinedEnvVars()
2858

29-
const config: BuildOptions = {
59+
return {
60+
...createBaseConfig(inlinedEnvVars),
3061
banner: {
3162
js: '#!/usr/bin/env node',
3263
},
33-
bundle: true,
3464
entryPoints: [entryPoint],
35-
format: 'cjs',
36-
minify: false,
3765
outfile,
38-
platform: 'node',
39-
// Source maps off for entry point production build.
40-
sourcemap: false,
41-
target: 'node18',
42-
// Define environment variables for inlining.
43-
define: {
44-
'process.env.NODE_ENV': '"production"',
45-
...createDefineEntries(inlinedEnvVars),
46-
},
47-
// Add plugin for post-bundle env var replacement.
4866
plugins: [envVarReplacementPlugin(inlinedEnvVars)],
49-
// Plugin needs to transform output.
50-
write: false,
5167
}
52-
53-
return config
5468
}
5569

5670
/**

0 commit comments

Comments
 (0)