Skip to content

Commit 915f95e

Browse files
committed
fix: inject __MIN_NODE_VERSION__ in bootstrap esbuild configs
Add define property to both esbuild configs to inject __MIN_NODE_VERSION__ from node-version.json. This fixes "is not defined" error when running built bootstrap via pnpm link.
1 parent 4150ee8 commit 915f95e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/socket/scripts/esbuild.bootstrap-smol.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* with Node.js internal bootstrap context.
66
*/
77

8+
import { readFileSync } from 'node:fs'
89
import path from 'node:path'
910
import { fileURLToPath } from 'node:url'
1011

@@ -15,11 +16,19 @@ const packageRoot = path.resolve(__dirname, '..')
1516
const monorepoRoot = path.resolve(packageRoot, '../..')
1617
const bootstrapPackage = path.join(monorepoRoot, 'packages/bootstrap')
1718

19+
// Read Node.js version from config.
20+
const nodeVersionPath = path.join(bootstrapPackage, 'node-version.json')
21+
const nodeVersionConfig = JSON.parse(readFileSync(nodeVersionPath, 'utf8'))
22+
const minNodeVersion = nodeVersionConfig.versionSemver
23+
1824
export default {
1925
banner: {
2026
js: '#!/usr/bin/env node',
2127
},
2228
bundle: true,
29+
define: {
30+
__MIN_NODE_VERSION__: JSON.stringify(minNodeVersion),
31+
},
2332
entryPoints: [path.join(bootstrapPackage, 'src', 'bootstrap-smol.mts')],
2433
external: [],
2534
format: 'cjs',

packages/socket/scripts/esbuild.bootstrap.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* esbuild configuration for Socket npm wrapper bootstrap.
33
*/
44

5+
import { readFileSync } from 'node:fs'
56
import path from 'node:path'
67
import { fileURLToPath } from 'node:url'
78

@@ -10,11 +11,19 @@ const packageRoot = path.resolve(__dirname, '..')
1011
const monorepoRoot = path.resolve(packageRoot, '../..')
1112
const bootstrapPackage = path.join(monorepoRoot, 'packages/bootstrap')
1213

14+
// Read Node.js version from config.
15+
const nodeVersionPath = path.join(bootstrapPackage, 'node-version.json')
16+
const nodeVersionConfig = JSON.parse(readFileSync(nodeVersionPath, 'utf8'))
17+
const minNodeVersion = nodeVersionConfig.versionSemver
18+
1319
export default {
1420
banner: {
1521
js: '#!/usr/bin/env node',
1622
},
1723
bundle: true,
24+
define: {
25+
__MIN_NODE_VERSION__: JSON.stringify(minNodeVersion),
26+
},
1827
entryPoints: [path.join(bootstrapPackage, 'src', 'bootstrap-npm.mts')],
1928
external: [],
2029
format: 'cjs',

0 commit comments

Comments
 (0)