Skip to content

Commit 9ce4f57

Browse files
authored
Upgraded v4 experimental flags. keepNames and autoDetectExternal now default to true. (#2371)
* keepNames default true, not experimental now * Added docs for the `environments` declarative schedules feature * minify and autoDetectExternal (true now) * processKeepAlive * devProcessCwdInBuildDir * Changeset * Switch to legacyDevProcessCwdBehaviour
1 parent 363b9b1 commit 9ce4f57

File tree

7 files changed

+104
-57
lines changed

7 files changed

+104
-57
lines changed

.changeset/little-lemons-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
All experimental flags have been promoted to non-experimental, but the experimental ones still work (for now). keepNames and autoDetectExternal now default to true.

docs/tasks/scheduled.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ title: "Scheduled tasks (cron)"
33
description: "A task that is triggered on a recurring schedule using cron syntax."
44
---
55

6-
<Note>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).</Note>
6+
<Note>
7+
Scheduled tasks are only for recurring tasks. If you want to trigger a one-off task at a future
8+
time, you should [use the delay option](/triggering#delay).
9+
</Note>
710

811
## Defining a scheduled task
912

@@ -104,6 +107,9 @@ export const secondScheduledTask = schedules.task({
104107
//5am every day Tokyo time
105108
pattern: "0 5 * * *",
106109
timezone: "Asia/Tokyo",
110+
//optional, defaults to all environments
111+
//possible values are "PRODUCTION", "STAGING", "PREVIEW" and "DEVELOPMENT"
112+
environments: ["PRODUCTION", "STAGING"],
107113
},
108114
run: async (payload) => {},
109115
});

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ async function createBuildOptions(
176176
const customConditions = options.resolvedConfig.build?.conditions ?? [];
177177
const conditions = [...customConditions, "trigger.dev", "module", "node"];
178178

179-
const keepNames = options.resolvedConfig.build?.experimental_keepNames ?? false;
180-
const minify = options.resolvedConfig.build?.experimental_minify ?? false;
179+
const keepNames =
180+
options.resolvedConfig.build?.keepNames ??
181+
options.resolvedConfig.build?.experimental_keepNames ??
182+
true;
183+
const minify =
184+
options.resolvedConfig.build?.minify ??
185+
options.resolvedConfig.build?.experimental_minify ??
186+
false;
181187

182188
const $buildPlugins = await buildPlugins(options.target, options.resolvedConfig);
183189

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,16 @@ function createExternalsCollector(
159159
isExternalCache.clear();
160160
});
161161

162+
const autoDetectExternal =
163+
resolvedConfig.build?.autoDetectExternal ??
164+
resolvedConfig.build?.experimental_autoDetectExternal ??
165+
true;
166+
162167
build.onEnd(async () => {
163168
logger.debug("[externals][onEnd] Collected externals", {
164169
externals,
165170
maybeExternals,
166-
autoDetectExternal: !!resolvedConfig.build?.experimental_autoDetectExternal,
171+
autoDetectExternal,
167172
packageJsonCache: packageJsonCache.size,
168173
isExternalCache: isExternalCache.size,
169174
});
@@ -265,7 +270,7 @@ function createExternalsCollector(
265270
});
266271
});
267272

268-
if (resolvedConfig.build?.experimental_autoDetectExternal) {
273+
if (autoDetectExternal) {
269274
build.onResolve(
270275
{ filter: /.*/, namespace: "file" },
271276
async (args: esbuild.OnResolveArgs): Promise<esbuild.OnResolveResult | undefined> => {

packages/cli-v3/src/dev/devSupervisor.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,21 @@ class DevSupervisor implements WorkerRuntime {
101101
// Initialize the task run process pool
102102
const env = await this.#getEnvVars();
103103

104+
const processKeepAlive =
105+
this.options.config.processKeepAlive ?? this.options.config.experimental_processKeepAlive;
106+
104107
const enableProcessReuse =
105-
typeof this.options.config.experimental_processKeepAlive === "boolean"
106-
? this.options.config.experimental_processKeepAlive
107-
: typeof this.options.config.experimental_processKeepAlive === "object"
108-
? this.options.config.experimental_processKeepAlive.enabled
108+
typeof processKeepAlive === "boolean"
109+
? processKeepAlive
110+
: typeof processKeepAlive === "object"
111+
? processKeepAlive.enabled
109112
: false;
110113

111114
const maxPoolSize =
112-
typeof this.options.config.experimental_processKeepAlive === "object"
113-
? this.options.config.experimental_processKeepAlive.devMaxPoolSize ?? 25
114-
: 25;
115+
typeof processKeepAlive === "object" ? processKeepAlive.devMaxPoolSize ?? 25 : 25;
115116

116117
const maxExecutionsPerProcess =
117-
typeof this.options.config.experimental_processKeepAlive === "object"
118-
? this.options.config.experimental_processKeepAlive.maxExecutionsPerProcess ?? 50
119-
: 50;
118+
typeof processKeepAlive === "object" ? processKeepAlive.maxExecutionsPerProcess ?? 50 : 50;
120119

121120
if (enableProcessReuse) {
122121
logger.debug("[DevSupervisor] Enabling process reuse", {
@@ -359,9 +358,10 @@ class DevSupervisor implements WorkerRuntime {
359358
config: this.options.config,
360359
});
361360

362-
const cwd = this.options.config.experimental_devProcessCwdInBuildDir
363-
? worker.build.outputPath
364-
: undefined;
361+
const cwd =
362+
this.options.config.legacyDevProcessCwdBehaviour === true
363+
? undefined
364+
: worker.build.outputPath;
365365

366366
//new run
367367
runController = new DevRunController({

packages/cli-v3/src/entryPoints/managed-index-worker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ if (typeof config.machine === "string") {
147147
});
148148
}
149149

150+
const processKeepAlive = config.processKeepAlive ?? config.experimental_processKeepAlive;
151+
150152
await sendMessageInCatalog(
151153
indexerToWorkerMessages,
152154
"INDEX_COMPLETE",
@@ -163,10 +165,10 @@ await sendMessageInCatalog(
163165
customConditions: buildManifest.customConditions,
164166
initEntryPoint: buildManifest.initEntryPoint,
165167
processKeepAlive:
166-
typeof config.experimental_processKeepAlive === "object"
167-
? config.experimental_processKeepAlive
168-
: typeof config.experimental_processKeepAlive === "boolean"
169-
? { enabled: config.experimental_processKeepAlive }
168+
typeof processKeepAlive === "object"
169+
? processKeepAlive
170+
: typeof processKeepAlive === "boolean"
171+
? { enabled: processKeepAlive }
170172
: undefined,
171173
timings,
172174
},

packages/core/src/v3/config.ts

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ export type CompatibilityFlagFeatures = {
1919
[key in CompatibilityFlag]: boolean;
2020
};
2121

22+
type ProcessKeepAlive =
23+
| boolean
24+
| {
25+
enabled: boolean;
26+
/**
27+
* The maximum number of executions per process. If the process has run more than this number of times, it will be killed.
28+
*
29+
* @default 50
30+
*/
31+
maxExecutionsPerProcess?: number;
32+
33+
/**
34+
* The maximum number of processes to keep alive in dev.
35+
*
36+
* @default 25
37+
*/
38+
devMaxPoolSize?: number;
39+
};
40+
2241
export type TriggerConfig = {
2342
/**
2443
* @default "node"
@@ -171,30 +190,43 @@ export type TriggerConfig = {
171190
external?: string[];
172191

173192
/**
174-
* **WARNING: This is an experimental feature and might be removed in a future version.**
193+
* This still works but use `autoDetectExternal` instead.
175194
*
195+
* @deprecated (use autoDetectExternal instead)
196+
*/
197+
experimental_autoDetectExternal?: boolean;
198+
199+
/**
176200
* Automatically detect dependencies that shouldn't be bundled and mark them as external. For example, native modules.
177201
*
178-
* Turning this on will not affect dependencies that were manually added to the `external` array.
202+
* Turn this off if you are having issues and want to manually specify all `external` dependencies.
179203
*
180-
* @default false
181-
*
182-
* @deprecated (experimental)
204+
* @default true
183205
*/
184-
experimental_autoDetectExternal?: boolean;
206+
autoDetectExternal?: boolean;
185207

186208
/**
187-
* **WARNING: This is an experimental feature and might be removed in a future version.**
209+
* This still works but use `keepNames` instead.
188210
*
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.
211+
* @deprecated (use keepNames instead)
212+
*/
213+
experimental_keepNames?: boolean;
214+
215+
/* Set to false to minify the original names of functions and classes in the bundle.
216+
* This can make bundles smaller at the cost of compatibility with frameworks that rely on function/class/variable names.
190217
*
191218
* @link https://esbuild.github.io/api/#keep-names
192219
*
193-
* @default false
220+
* @default true
221+
*/
222+
keepNames?: boolean;
223+
224+
/**
225+
* This still works but use `minify` instead.
194226
*
195-
* @deprecated (experimental)
227+
* @deprecated (use minify instead)
196228
*/
197-
experimental_keepNames?: boolean;
229+
experimental_minify?: boolean;
198230

199231
/**
200232
* **WARNING: This is an experimental feature and might be removed in a future version.**
@@ -206,10 +238,8 @@ export type TriggerConfig = {
206238
* @link https://esbuild.github.io/api/#minify
207239
*
208240
* @default false
209-
*
210-
* @deprecated (experimental)
211241
*/
212-
experimental_minify?: boolean;
242+
minify?: boolean;
213243

214244
jsx?: {
215245
/**
@@ -234,38 +264,31 @@ export type TriggerConfig = {
234264
env?: Record<string, string>;
235265
};
236266

267+
/**
268+
* This still works but use `processKeepAlive` instead.
269+
*
270+
* @deprecated (use processKeepAlive instead)
271+
*/
272+
experimental_processKeepAlive?: ProcessKeepAlive;
273+
237274
/**
238275
* @default false
239276
* @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.
240277
*
241278
* 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
242279
*/
243-
experimental_processKeepAlive?:
244-
| boolean
245-
| {
246-
enabled: boolean;
247-
/**
248-
* The maximum number of executions per process. If the process has run more than this number of times, it will be killed.
249-
*
250-
* @default 50
251-
*/
252-
maxExecutionsPerProcess?: number;
253-
254-
/**
255-
* The maximum number of processes to keep alive in dev.
256-
*
257-
* @default 25
258-
*/
259-
devMaxPoolSize?: number;
260-
};
280+
processKeepAlive?: ProcessKeepAlive;
261281

262282
/**
263283
* @default false
264-
* @description When running the dev CLI, set the current working directory to the build directory.
284+
* @description If set to true when running the dev CLI, the current working directory will be set to where the command is run from.
285+
*
286+
* The new default (when this flag isn't passed) is to set the current working directory to the build directory.
287+
* This more closely matches the behavior of the CLI when running in production and is highly recommended.
265288
*
266-
* Currently, the process.cwd() is set to the root of the project.
289+
* This impacts the value of process.cwd() in your task code.
267290
*/
268-
experimental_devProcessCwdInBuildDir?: boolean;
291+
legacyDevProcessCwdBehaviour?: boolean;
269292

270293
/**
271294
* @deprecated Use `dirs` instead

0 commit comments

Comments
 (0)