Skip to content

Commit 3d04a1f

Browse files
feat: add config.keep_names option
1 parent 4c6873d commit 3d04a1f

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(
@@ -248,6 +249,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
248249
rules: config.build.moduleRules,
249250
tsconfig: config.build?.tsconfig,
250251
minify: config.build?.minify,
252+
keepNames: config.build?.keepNames ?? true,
251253
nodejsCompatMode: config.build.nodejsCompatMode,
252254
define: config.build.define,
253255
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
@@ -107,6 +107,8 @@ export interface StartDevWorkerInput {
107107
alias?: Record<string, string>;
108108
/** Whether the bundled worker is minified. Only takes effect if bundle: true. */
109109
minify?: boolean;
110+
/** Whether to keep function names after JavaScript transpilations. */
111+
keepNames?: boolean;
110112
/** Options controlling a custom build step. */
111113
custom?: {
112114
/** 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
@@ -331,6 +331,7 @@ export const defaultWranglerConfig: Config = {
331331
build: { command: undefined, watch_dir: "./src", cwd: undefined },
332332
no_bundle: undefined,
333333
minify: undefined,
334+
keep_names: undefined,
334335
dispatch_namespaces: [],
335336
first_party_worker: undefined,
336337
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
@@ -1376,6 +1376,14 @@ function normalizeAndValidateEnvironment(
13761376
isBoolean,
13771377
undefined
13781378
),
1379+
keep_names: inheritable(
1380+
diagnostics,
1381+
topLevelEnv,
1382+
rawEnv,
1383+
"keep_names",
1384+
isBoolean,
1385+
undefined
1386+
),
13791387
first_party_worker: inheritable(
13801388
diagnostics,
13811389
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"];
@@ -155,6 +156,7 @@ export async function bundleWorker(
155156
watch,
156157
tsconfig,
157158
minify,
159+
keepNames,
158160
nodejsCompatMode,
159161
alias,
160162
define,
@@ -370,7 +372,7 @@ export async function bundleWorker(
370372
bundle,
371373
absWorkingDir: entry.projectRoot,
372374
outdir: destination,
373-
keepNames: true,
375+
keepNames,
374376
entryNames: entryName || path.parse(entryFile).name,
375377
...(isOutfile
376378
? {

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,
@@ -69,6 +70,7 @@ export function runBuild(
6970
alias: Config["alias"];
7071
tsconfig: string | undefined;
7172
minify: boolean | undefined;
73+
keepNames: boolean;
7274
nodejsCompatMode: NodeJSCompatMode | undefined;
7375
noBundle: boolean;
7476
findAdditionalModules: boolean | undefined;
@@ -150,6 +152,7 @@ export function runBuild(
150152
watch: true,
151153
tsconfig,
152154
minify,
155+
keepNames,
153156
nodejsCompatMode,
154157
doBindings: durableObjects.bindings,
155158
workflowBindings: workflows,

0 commit comments

Comments
 (0)