From 303d8c8fca8858e98a69e84ab7d7574441f52988 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 14:56:05 +0100 Subject: [PATCH 1/7] keepNames default true, not experimental now --- packages/cli-v3/src/build/bundle.ts | 5 ++++- packages/core/src/v3/config.ts | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/cli-v3/src/build/bundle.ts b/packages/cli-v3/src/build/bundle.ts index d8687922d1..d29c696084 100644 --- a/packages/cli-v3/src/build/bundle.ts +++ b/packages/cli-v3/src/build/bundle.ts @@ -176,7 +176,10 @@ async function createBuildOptions( const customConditions = options.resolvedConfig.build?.conditions ?? []; const conditions = [...customConditions, "trigger.dev", "module", "node"]; - const keepNames = options.resolvedConfig.build?.experimental_keepNames ?? false; + const keepNames = + options.resolvedConfig.build?.keepNames ?? + options.resolvedConfig.build?.experimental_keepNames ?? + true; const minify = options.resolvedConfig.build?.experimental_minify ?? false; const $buildPlugins = await buildPlugins(options.target, options.resolvedConfig); diff --git a/packages/core/src/v3/config.ts b/packages/core/src/v3/config.ts index 838a464dcf..949b776599 100644 --- a/packages/core/src/v3/config.ts +++ b/packages/core/src/v3/config.ts @@ -184,17 +184,22 @@ export type TriggerConfig = { experimental_autoDetectExternal?: boolean; /** - * **WARNING: This is an experimental feature and might be removed in a future version.** + * This still works but use `keepNames` instead. * - * 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. + * @default true * - * @link https://esbuild.github.io/api/#keep-names + * @deprecated (use keepNames instead) + */ + experimental_keepNames?: boolean; + + /* Set to false to minify the original names of functions and classes in the bundle. + * This can make bundles smaller at the cost of compatibility with frameworks that rely on function/class/variable names. * - * @default false + * @link https://esbuild.github.io/api/#keep-names * - * @deprecated (experimental) + * @default true */ - experimental_keepNames?: boolean; + keepNames?: boolean; /** * **WARNING: This is an experimental feature and might be removed in a future version.** From 2c56607f1ab3fdd8e79692e4d1388d44ce0844cf Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 15:06:50 +0100 Subject: [PATCH 2/7] Added docs for the `environments` declarative schedules feature --- docs/tasks/scheduled.mdx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/tasks/scheduled.mdx b/docs/tasks/scheduled.mdx index aea6efb9db..47c7854373 100644 --- a/docs/tasks/scheduled.mdx +++ b/docs/tasks/scheduled.mdx @@ -3,7 +3,10 @@ title: "Scheduled tasks (cron)" description: "A task that is triggered on a recurring schedule using cron syntax." --- -Scheduled tasks are only for recurring tasks. If you want to trigger a one-off task at a future time, you should [use the delay option](/triggering#delay). + + Scheduled tasks are only for recurring tasks. If you want to trigger a one-off task at a future + time, you should [use the delay option](/triggering#delay). + ## Defining a scheduled task @@ -104,6 +107,9 @@ export const secondScheduledTask = schedules.task({ //5am every day Tokyo time pattern: "0 5 * * *", timezone: "Asia/Tokyo", + //optional, defaults to all environments + //possible values are "PRODUCTION", "STAGING", "PREVIEW" and "DEVELOPMENT" + environments: ["PRODUCTION", "STAGING"], }, run: async (payload) => {}, }); From a07d66151e016efe56d90fb762159d1075da7259 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 15:42:11 +0100 Subject: [PATCH 3/7] minify and autoDetectExternal (true now) --- packages/cli-v3/src/build/bundle.ts | 5 ++++- packages/cli-v3/src/build/externals.ts | 9 +++++++-- packages/core/src/v3/config.ts | 28 ++++++++++++++++---------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/cli-v3/src/build/bundle.ts b/packages/cli-v3/src/build/bundle.ts index d29c696084..597b46854a 100644 --- a/packages/cli-v3/src/build/bundle.ts +++ b/packages/cli-v3/src/build/bundle.ts @@ -180,7 +180,10 @@ async function createBuildOptions( options.resolvedConfig.build?.keepNames ?? options.resolvedConfig.build?.experimental_keepNames ?? true; - const minify = options.resolvedConfig.build?.experimental_minify ?? false; + const minify = + options.resolvedConfig.build?.minify ?? + options.resolvedConfig.build?.experimental_minify ?? + false; const $buildPlugins = await buildPlugins(options.target, options.resolvedConfig); diff --git a/packages/cli-v3/src/build/externals.ts b/packages/cli-v3/src/build/externals.ts index 90a2e07514..c35f90cf18 100644 --- a/packages/cli-v3/src/build/externals.ts +++ b/packages/cli-v3/src/build/externals.ts @@ -159,11 +159,16 @@ function createExternalsCollector( isExternalCache.clear(); }); + const autoDetectExternal = + resolvedConfig.build?.autoDetectExternal ?? + resolvedConfig.build?.experimental_autoDetectExternal ?? + true; + build.onEnd(async () => { logger.debug("[externals][onEnd] Collected externals", { externals, maybeExternals, - autoDetectExternal: !!resolvedConfig.build?.experimental_autoDetectExternal, + autoDetectExternal, packageJsonCache: packageJsonCache.size, isExternalCache: isExternalCache.size, }); @@ -265,7 +270,7 @@ function createExternalsCollector( }); }); - if (resolvedConfig.build?.experimental_autoDetectExternal) { + if (autoDetectExternal) { build.onResolve( { filter: /.*/, namespace: "file" }, async (args: esbuild.OnResolveArgs): Promise => { diff --git a/packages/core/src/v3/config.ts b/packages/core/src/v3/config.ts index 949b776599..b0acbba375 100644 --- a/packages/core/src/v3/config.ts +++ b/packages/core/src/v3/config.ts @@ -171,23 +171,24 @@ export type TriggerConfig = { external?: string[]; /** - * **WARNING: This is an experimental feature and might be removed in a future version.** + * This still works but use `autoDetectExternal` instead. * + * @deprecated (use autoDetectExternal instead) + */ + experimental_autoDetectExternal?: boolean; + + /** * Automatically detect dependencies that shouldn't be bundled and mark them as external. For example, native modules. * - * Turning this on will not affect dependencies that were manually added to the `external` array. + * Turn this off if you are having issues and want to manually specify all `external` dependencies. * - * @default false - * - * @deprecated (experimental) + * @default true */ - experimental_autoDetectExternal?: boolean; + autoDetectExternal?: boolean; /** * This still works but use `keepNames` instead. * - * @default true - * * @deprecated (use keepNames instead) */ experimental_keepNames?: boolean; @@ -201,6 +202,13 @@ export type TriggerConfig = { */ keepNames?: boolean; + /** + * This still works but use `minify` instead. + * + * @deprecated (use minify instead) + */ + experimental_minify?: boolean; + /** * **WARNING: This is an experimental feature and might be removed in a future version.** * @@ -211,10 +219,8 @@ export type TriggerConfig = { * @link https://esbuild.github.io/api/#minify * * @default false - * - * @deprecated (experimental) */ - experimental_minify?: boolean; + minify?: boolean; jsx?: { /** From 92fa40f15570b42e726236555a1aa6e725ad0250 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 15:53:52 +0100 Subject: [PATCH 4/7] processKeepAlive --- packages/cli-v3/src/dev/devSupervisor.ts | 19 ++++---- .../src/entryPoints/managed-index-worker.ts | 10 +++-- packages/core/src/v3/config.ts | 45 +++++++++++-------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/packages/cli-v3/src/dev/devSupervisor.ts b/packages/cli-v3/src/dev/devSupervisor.ts index e86ea4eb45..5b070e0eac 100644 --- a/packages/cli-v3/src/dev/devSupervisor.ts +++ b/packages/cli-v3/src/dev/devSupervisor.ts @@ -101,22 +101,21 @@ class DevSupervisor implements WorkerRuntime { // Initialize the task run process pool const env = await this.#getEnvVars(); + const processKeepAlive = + this.options.config.processKeepAlive ?? this.options.config.experimental_processKeepAlive; + const enableProcessReuse = - typeof this.options.config.experimental_processKeepAlive === "boolean" - ? this.options.config.experimental_processKeepAlive - : typeof this.options.config.experimental_processKeepAlive === "object" - ? this.options.config.experimental_processKeepAlive.enabled + typeof processKeepAlive === "boolean" + ? processKeepAlive + : typeof processKeepAlive === "object" + ? processKeepAlive.enabled : false; const maxPoolSize = - typeof this.options.config.experimental_processKeepAlive === "object" - ? this.options.config.experimental_processKeepAlive.devMaxPoolSize ?? 25 - : 25; + typeof processKeepAlive === "object" ? processKeepAlive.devMaxPoolSize ?? 25 : 25; const maxExecutionsPerProcess = - typeof this.options.config.experimental_processKeepAlive === "object" - ? this.options.config.experimental_processKeepAlive.maxExecutionsPerProcess ?? 50 - : 50; + typeof processKeepAlive === "object" ? processKeepAlive.maxExecutionsPerProcess ?? 50 : 50; if (enableProcessReuse) { logger.debug("[DevSupervisor] Enabling process reuse", { diff --git a/packages/cli-v3/src/entryPoints/managed-index-worker.ts b/packages/cli-v3/src/entryPoints/managed-index-worker.ts index 03c4ff4b14..98593cfc6e 100644 --- a/packages/cli-v3/src/entryPoints/managed-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-index-worker.ts @@ -147,6 +147,8 @@ if (typeof config.machine === "string") { }); } +const processKeepAlive = config.processKeepAlive ?? config.experimental_processKeepAlive; + await sendMessageInCatalog( indexerToWorkerMessages, "INDEX_COMPLETE", @@ -163,10 +165,10 @@ await sendMessageInCatalog( customConditions: buildManifest.customConditions, initEntryPoint: buildManifest.initEntryPoint, processKeepAlive: - typeof config.experimental_processKeepAlive === "object" - ? config.experimental_processKeepAlive - : typeof config.experimental_processKeepAlive === "boolean" - ? { enabled: config.experimental_processKeepAlive } + typeof processKeepAlive === "object" + ? processKeepAlive + : typeof processKeepAlive === "boolean" + ? { enabled: processKeepAlive } : undefined, timings, }, diff --git a/packages/core/src/v3/config.ts b/packages/core/src/v3/config.ts index b0acbba375..440d207b40 100644 --- a/packages/core/src/v3/config.ts +++ b/packages/core/src/v3/config.ts @@ -19,6 +19,25 @@ export type CompatibilityFlagFeatures = { [key in CompatibilityFlag]: boolean; }; +type ProcessKeepAlive = + | boolean + | { + enabled: boolean; + /** + * The maximum number of executions per process. If the process has run more than this number of times, it will be killed. + * + * @default 50 + */ + maxExecutionsPerProcess?: number; + + /** + * The maximum number of processes to keep alive in dev. + * + * @default 25 + */ + devMaxPoolSize?: number; + }; + export type TriggerConfig = { /** * @default "node" @@ -245,30 +264,20 @@ export type TriggerConfig = { env?: Record; }; + /** + * This still works but use `processKeepAlive` instead. + * + * @deprecated (use processKeepAlive instead) + */ + experimental_processKeepAlive?: ProcessKeepAlive; + /** * @default false * @description Keep the process alive after the task has finished running so the next task doesn't have to wait for the process to start up again. * * Note that the process could be killed at any time, and we don't make any guarantees about the process being alive for a certain amount of time */ - experimental_processKeepAlive?: - | boolean - | { - enabled: boolean; - /** - * The maximum number of executions per process. If the process has run more than this number of times, it will be killed. - * - * @default 50 - */ - maxExecutionsPerProcess?: number; - - /** - * The maximum number of processes to keep alive in dev. - * - * @default 25 - */ - devMaxPoolSize?: number; - }; + processKeepAlive?: ProcessKeepAlive; /** * @default false From a399d1440a8ab3e33cb261d0d06ec130a8c58b5d Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 16:04:09 +0100 Subject: [PATCH 5/7] devProcessCwdInBuildDir --- packages/cli-v3/src/dev/devSupervisor.ts | 8 +++++--- packages/core/src/v3/config.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/cli-v3/src/dev/devSupervisor.ts b/packages/cli-v3/src/dev/devSupervisor.ts index 5b070e0eac..55bb15e97a 100644 --- a/packages/cli-v3/src/dev/devSupervisor.ts +++ b/packages/cli-v3/src/dev/devSupervisor.ts @@ -358,9 +358,11 @@ class DevSupervisor implements WorkerRuntime { config: this.options.config, }); - const cwd = this.options.config.experimental_devProcessCwdInBuildDir - ? worker.build.outputPath - : undefined; + const cwd = + this.options.config.devProcessCwdInBuildDir ?? + this.options.config.experimental_devProcessCwdInBuildDir + ? worker.build.outputPath + : undefined; //new run runController = new DevRunController({ diff --git a/packages/core/src/v3/config.ts b/packages/core/src/v3/config.ts index 440d207b40..a452dbdd20 100644 --- a/packages/core/src/v3/config.ts +++ b/packages/core/src/v3/config.ts @@ -279,13 +279,20 @@ export type TriggerConfig = { */ processKeepAlive?: ProcessKeepAlive; + /** + * This still works but use `devProcessCwdInBuildDir` instead. + * + * @deprecated (use devProcessCwdInBuildDir instead) + */ + experimental_devProcessCwdInBuildDir?: boolean; + /** * @default false * @description When running the dev CLI, set the current working directory to the build directory. * * Currently, the process.cwd() is set to the root of the project. */ - experimental_devProcessCwdInBuildDir?: boolean; + devProcessCwdInBuildDir?: boolean; /** * @deprecated Use `dirs` instead From 2e7b197bab439eebc7f9041fa7ff4aa928b56a4d Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 16:05:10 +0100 Subject: [PATCH 6/7] Changeset --- .changeset/little-lemons-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/little-lemons-grab.md diff --git a/.changeset/little-lemons-grab.md b/.changeset/little-lemons-grab.md new file mode 100644 index 0000000000..71041f1385 --- /dev/null +++ b/.changeset/little-lemons-grab.md @@ -0,0 +1,5 @@ +--- +"trigger.dev": patch +--- + +All experimental flags have been promoted to non-experimental, but the experimental ones still work (for now). keepNames and autoDetectExternal now default to true. From b33cbc4c39fc967794707005c44561924ef42a31 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Thu, 7 Aug 2025 16:37:26 +0100 Subject: [PATCH 7/7] Switch to legacyDevProcessCwdBehaviour --- packages/cli-v3/src/dev/devSupervisor.ts | 7 +++---- packages/core/src/v3/config.ts | 16 ++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/cli-v3/src/dev/devSupervisor.ts b/packages/cli-v3/src/dev/devSupervisor.ts index 55bb15e97a..a445748473 100644 --- a/packages/cli-v3/src/dev/devSupervisor.ts +++ b/packages/cli-v3/src/dev/devSupervisor.ts @@ -359,10 +359,9 @@ class DevSupervisor implements WorkerRuntime { }); const cwd = - this.options.config.devProcessCwdInBuildDir ?? - this.options.config.experimental_devProcessCwdInBuildDir - ? worker.build.outputPath - : undefined; + this.options.config.legacyDevProcessCwdBehaviour === true + ? undefined + : worker.build.outputPath; //new run runController = new DevRunController({ diff --git a/packages/core/src/v3/config.ts b/packages/core/src/v3/config.ts index a452dbdd20..08d1e90359 100644 --- a/packages/core/src/v3/config.ts +++ b/packages/core/src/v3/config.ts @@ -279,20 +279,16 @@ export type TriggerConfig = { */ processKeepAlive?: ProcessKeepAlive; - /** - * This still works but use `devProcessCwdInBuildDir` instead. - * - * @deprecated (use devProcessCwdInBuildDir instead) - */ - experimental_devProcessCwdInBuildDir?: boolean; - /** * @default false - * @description When running the dev CLI, set the current working directory to the build directory. + * @description If set to true when running the dev CLI, the current working directory will be set to where the command is run from. + * + * The new default (when this flag isn't passed) is to set the current working directory to the build directory. + * This more closely matches the behavior of the CLI when running in production and is highly recommended. * - * Currently, the process.cwd() is set to the root of the project. + * This impacts the value of process.cwd() in your task code. */ - devProcessCwdInBuildDir?: boolean; + legacyDevProcessCwdBehaviour?: boolean; /** * @deprecated Use `dirs` instead