Skip to content

Commit fc1552b

Browse files
committed
fix(build): add 'use strict' to all CJS files
- Add 'use strict' banner to esbuild config for dist/*.js files - Add 'use strict' banner to external bundler config - Add 'use strict' to all src/external/*.js wrapper files - Ensures strict mode enforcement across all CommonJS modules
1 parent 47e3707 commit fc1552b

39 files changed

Lines changed: 82 additions & 3 deletions

.config/esbuild.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export const buildConfig = {
260260

261261
// Banner for generated code
262262
banner: {
263-
js: '/* Socket Lib - Built with esbuild */',
263+
js: '"use strict";\n/* Socket Lib - Built with esbuild */',
264264
},
265265
}
266266

scripts/build-externals/bundler.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ export async function bundlePackage(packageName, outputPath, options = {}) {
8989

9090
// Add a header comment to the bundled file.
9191
const bundleContent = await fs.readFile(outputPath, 'utf8')
92-
const finalContent = `/**
92+
// Strip 'use strict' from bundle content if present (will be re-added at top)
93+
const contentWithoutStrict = bundleContent.replace(/^"use strict";\n/, '')
94+
const finalContent = `"use strict";
95+
/**
9396
* Bundled from ${packageName}
9497
* This is a zero-dependency bundle created by esbuild.
9598
*/
96-
${bundleContent}`
99+
${contentWithoutStrict}`
97100
await fs.writeFile(outputPath, finalContent)
98101

99102
// Get file size for logging.

scripts/build-externals/esbuild-config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,9 @@ export function getEsbuildConfig(entryPoint, outfile, packageOpts = {}) {
174174
...packageOpts.define,
175175
},
176176
charset: 'utf8',
177+
// Banner for generated code
178+
banner: {
179+
js: '"use strict";',
180+
},
177181
}
178182
}

src/external/@inquirer/confirm.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@inquirer/confirm')

src/external/@inquirer/input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@inquirer/input')

src/external/@inquirer/password.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@inquirer/password')

src/external/@inquirer/search.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@inquirer/search')

src/external/@inquirer/select.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@inquirer/select')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@npmcli/package-json')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict'
2+
13
module.exports = require('@npmcli/package-json')

0 commit comments

Comments
 (0)