Skip to content

Commit 1ca37f5

Browse files
authored
Expose esbuild keepNames and minify options (experimental) (#2091)
* Expose esbuild `keepNames` option (experimental) * Expose esbuild `minify` option (experimental) * test new experimental options
1 parent 8112c12 commit 1ca37f5

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

.changeset/gold-insects-invite.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Expose esbuild `keepNames` option (experimental)

.changeset/wild-mirrors-return.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Expose esbuild `minify` option (experimental)

packages/cli-v3/src/build/bundle.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ async function createBuildOptions(
174174
options: BundleOptions & { entryPoints: string[]; buildResultPlugin?: esbuild.Plugin }
175175
): Promise<esbuild.BuildOptions & { metafile: true }> {
176176
const customConditions = options.resolvedConfig.build?.conditions ?? [];
177-
178177
const conditions = [...customConditions, "trigger.dev", "module", "node"];
179178

179+
const keepNames = options.resolvedConfig.build?.experimental_keepNames ?? false;
180+
const minify = options.resolvedConfig.build?.experimental_minify ?? false;
181+
180182
const $buildPlugins = await buildPlugins(options.target, options.resolvedConfig);
181183

182184
return {
@@ -186,13 +188,14 @@ async function createBuildOptions(
186188
bundle: true,
187189
metafile: true,
188190
write: false,
189-
minify: false,
191+
minify,
190192
splitting: true,
191193
charset: "utf8",
192194
platform: "node",
193195
sourcemap: true,
194196
sourcesContent: options.target === "dev",
195197
conditions,
198+
keepNames,
196199
format: "esm",
197200
target: ["node20", "es2022"],
198201
loader: {

packages/core/src/v3/config.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ export type TriggerConfig = {
183183
*/
184184
experimental_autoDetectExternal?: boolean;
185185

186+
/**
187+
* **WARNING: This is an experimental feature and might be removed in a future version.**
188+
*
189+
* Preserve the original names of functions and classes in the bundle. This can fix issues with frameworks that rely on the original names for registration and binding, for example MikroORM.
190+
*
191+
* @link https://esbuild.github.io/api/#keep-names
192+
*
193+
* @default false
194+
*
195+
* @deprecated (experimental)
196+
*/
197+
experimental_keepNames?: boolean;
198+
199+
/**
200+
* **WARNING: This is an experimental feature and might be removed in a future version.**
201+
*
202+
* "Minification is not safe for 100% of all JavaScript code" - esbuild docs
203+
*
204+
* Minify the generated code to help decrease bundle size. This may break stuff.
205+
*
206+
* @link https://esbuild.github.io/api/#minify
207+
*
208+
* @default false
209+
*
210+
* @deprecated (experimental)
211+
*/
212+
experimental_minify?: boolean;
213+
186214
jsx?: {
187215
/**
188216
* @default "React.createElement"

references/v3-catalog/src/trigger/binaries.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ function unzip(inputPath: string, outputPath: string) {
4343

4444
import { createClient } from "@1password/sdk";
4545

46-
// Creates an authenticated client.
47-
const client = await createClient({
48-
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN ?? "",
49-
// Set the following to your own integration name and version.
50-
integrationName: "My 1Password Integration",
51-
integrationVersion: "v1.0.0",
52-
});
46+
function create1PasswordClient() {
47+
return createClient({
48+
auth: process.env.OP_SERVICE_ACCOUNT_TOKEN ?? "",
49+
// Set the following to your own integration name and version.
50+
integrationName: "My 1Password Integration",
51+
integrationVersion: "v1.0.0",
52+
});
53+
}
5354

5455
// Fetches a secret.
5556
// const secret = await client.secrets.resolve("op://vault/item/field");

references/v3-catalog/trigger.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export default defineConfig({
3232
build: {
3333
conditions: ["react-server"],
3434
experimental_autoDetectExternal: true,
35+
experimental_keepNames: true,
36+
experimental_minify: true,
3537
extensions: [
3638
additionalFiles({
3739
files: ["./wrangler/wrangler.toml"],

0 commit comments

Comments
 (0)