Skip to content

Commit ce8669e

Browse files
feat: add config.keep_names option
1 parent cf2a343 commit ce8669e

File tree

13 files changed

+63
-1
lines changed

13 files changed

+63
-1
lines changed

.changeset/long-mugs-pull.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
feat: add `config.keep_names` option
6+
7+
adds a new option so that developers can opt out of esbuild's `keep_names` option
8+
(see: https://esbuild.github.io/api/#keep-names) which wrangler otherwise sets
9+
to `true`
10+
11+
this is something developers should not usually need to care about, but sometimes
12+
`keep_names` can create issues, in such cases they will be now able to set opt
13+
out of it
14+
15+
example `wrangler.jsonc`:
16+
17+
```json
18+
{
19+
"name": "my-worker",
20+
"main": "src/worker.ts",
21+
"compatibility_flags": ["nodejs_compat"],
22+
23+
"minify": false
24+
}
25+
```

packages/wrangler/src/api/startDevWorker/BundlerController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
117117
jsxFragment: config.build.jsxFactory,
118118
tsconfig: config.build.tsconfig,
119119
minify: config.build.minify,
120+
keepNames: config.build.keepNames ?? true,
120121
nodejsCompatMode: config.build.nodejsCompatMode,
121122
define: config.build.define,
122123
checkFetch: shouldCheckFetch(
@@ -246,6 +247,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
246247
rules: config.build.moduleRules,
247248
tsconfig: config.build?.tsconfig,
248249
minify: config.build?.minify,
250+
keepNames: config.build?.keepNames ?? true,
249251
nodejsCompatMode: config.build.nodejsCompatMode,
250252
define: config.build.define,
251253
alias: config.build.alias,

packages/wrangler/src/api/startDevWorker/ConfigController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ async function resolveConfig(
289289
moduleRules: input.build?.moduleRules ?? getRules(config),
290290

291291
minify: input.build?.minify ?? config.minify,
292+
keepNames: input.build?.keepNames ?? config.keep_names,
292293
define: { ...config.define, ...input.build?.define },
293294
custom: {
294295
command: input.build?.custom?.command ?? config.build?.command,

packages/wrangler/src/api/startDevWorker/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export interface StartDevWorkerInput {
108108
alias?: Record<string, string>;
109109
/** Whether the bundled worker is minified. Only takes effect if bundle: true. */
110110
minify?: boolean;
111+
/** Whether to keep function names after JavaScript transpilations. */
112+
keepNames?: boolean;
111113
/** Options controlling a custom build step. */
112114
custom?: {
113115
/** Custom shell command to run before bundling. Runs even if bundle. */

packages/wrangler/src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export const defaultWranglerConfig: Config = {
332332
build: { command: undefined, watch_dir: "./src", cwd: undefined },
333333
no_bundle: undefined,
334334
minify: undefined,
335+
keep_names: undefined,
335336
dispatch_namespaces: [],
336337
first_party_worker: undefined,
337338
logfwdr: { bindings: [] },

packages/wrangler/src/config/environment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ interface EnvironmentInheritable {
306306
*/
307307
minify: boolean | undefined;
308308

309+
/**
310+
* Keep function names after javascript transpilations.
311+
*
312+
* @default {true}
313+
* @inheritable
314+
*/
315+
keep_names: boolean | undefined;
316+
309317
/**
310318
* Designates this Worker as an internal-only "first-party" Worker.
311319
*

packages/wrangler/src/config/validation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,14 @@ function normalizeAndValidateEnvironment(
14171417
isBoolean,
14181418
undefined
14191419
),
1420+
keep_names: inheritable(
1421+
diagnostics,
1422+
topLevelEnv,
1423+
rawEnv,
1424+
"keep_names",
1425+
isBoolean,
1426+
undefined
1427+
),
14201428
first_party_worker: inheritable(
14211429
diagnostics,
14221430
topLevelEnv,

packages/wrangler/src/deploy/deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
558558
jsxFragment,
559559
tsconfig: props.tsconfig ?? config.tsconfig,
560560
minify,
561+
keepNames: config.keep_names ?? true,
561562
sourcemap: uploadSourceMaps,
562563
nodejsCompatMode,
563564
define: { ...config.define, ...props.defines },

packages/wrangler/src/deployment-bundle/bundle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export type BundleOptions = {
120120
watch: boolean | undefined;
121121
tsconfig: string | undefined;
122122
minify: boolean | undefined;
123+
keepNames: boolean;
123124
nodejsCompatMode: NodeJSCompatMode | undefined;
124125
define: Config["define"];
125126
alias: Config["alias"];
@@ -154,6 +155,7 @@ export async function bundleWorker(
154155
watch,
155156
tsconfig,
156157
minify,
158+
keepNames,
157159
nodejsCompatMode,
158160
alias,
159161
define,
@@ -353,7 +355,7 @@ export async function bundleWorker(
353355
bundle,
354356
absWorkingDir: entry.projectRoot,
355357
outdir: destination,
356-
keepNames: true,
358+
keepNames,
357359
entryNames: entryName || path.parse(entryFile).name,
358360
...(isOutfile
359361
? {

packages/wrangler/src/dev/use-esbuild.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function runBuild(
4242
rules,
4343
tsconfig,
4444
minify,
45+
keepNames,
4546
nodejsCompatMode,
4647
define,
4748
alias,
@@ -68,6 +69,7 @@ export function runBuild(
6869
alias: Config["alias"];
6970
tsconfig: string | undefined;
7071
minify: boolean | undefined;
72+
keepNames: boolean;
7173
nodejsCompatMode: NodeJSCompatMode | undefined;
7274
noBundle: boolean;
7375
findAdditionalModules: boolean | undefined;
@@ -148,6 +150,7 @@ export function runBuild(
148150
watch: true,
149151
tsconfig,
150152
minify,
153+
keepNames,
151154
nodejsCompatMode,
152155
doBindings: durableObjects.bindings,
153156
workflowBindings: workflows,

0 commit comments

Comments
 (0)