Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/little-lemons-grab.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 7 additions & 1 deletion docs/tasks/scheduled.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ title: "Scheduled tasks (cron)"
description: "A task that is triggered on a recurring schedule using cron syntax."
---

<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>
<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>

## Defining a scheduled task

Expand Down Expand Up @@ -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) => {},
});
Expand Down
10 changes: 8 additions & 2 deletions packages/cli-v3/src/build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,14 @@ 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 minify = options.resolvedConfig.build?.experimental_minify ?? false;
const keepNames =
options.resolvedConfig.build?.keepNames ??
options.resolvedConfig.build?.experimental_keepNames ??
true;
const minify =
options.resolvedConfig.build?.minify ??
options.resolvedConfig.build?.experimental_minify ??
false;

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

Expand Down
9 changes: 7 additions & 2 deletions packages/cli-v3/src/build/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -265,7 +270,7 @@ function createExternalsCollector(
});
});

if (resolvedConfig.build?.experimental_autoDetectExternal) {
if (autoDetectExternal) {
build.onResolve(
{ filter: /.*/, namespace: "file" },
async (args: esbuild.OnResolveArgs): Promise<esbuild.OnResolveResult | undefined> => {
Expand Down
26 changes: 13 additions & 13 deletions packages/cli-v3/src/dev/devSupervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -359,9 +358,10 @@ class DevSupervisor implements WorkerRuntime {
config: this.options.config,
});

const cwd = this.options.config.experimental_devProcessCwdInBuildDir
? worker.build.outputPath
: undefined;
const cwd =
this.options.config.legacyDevProcessCwdBehaviour === true
? undefined
: worker.build.outputPath;

//new run
runController = new DevRunController({
Expand Down
10 changes: 6 additions & 4 deletions packages/cli-v3/src/entryPoints/managed-index-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ if (typeof config.machine === "string") {
});
}

const processKeepAlive = config.processKeepAlive ?? config.experimental_processKeepAlive;

await sendMessageInCatalog(
indexerToWorkerMessages,
"INDEX_COMPLETE",
Expand All @@ -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,
},
Expand Down
93 changes: 58 additions & 35 deletions packages/core/src/v3/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -171,30 +190,43 @@ 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;

/**
* **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.
* @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.
*
* @link https://esbuild.github.io/api/#keep-names
*
* @default false
* @default true
*/
keepNames?: boolean;

/**
* This still works but use `minify` instead.
*
* @deprecated (experimental)
* @deprecated (use minify instead)
*/
experimental_keepNames?: boolean;
experimental_minify?: boolean;

/**
* **WARNING: This is an experimental feature and might be removed in a future version.**
Expand All @@ -206,10 +238,8 @@ export type TriggerConfig = {
* @link https://esbuild.github.io/api/#minify
*
* @default false
*
* @deprecated (experimental)
*/
experimental_minify?: boolean;
minify?: boolean;

jsx?: {
/**
Expand All @@ -234,38 +264,31 @@ export type TriggerConfig = {
env?: Record<string, string>;
};

/**
* 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
* @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.
*/
experimental_devProcessCwdInBuildDir?: boolean;
legacyDevProcessCwdBehaviour?: boolean;

/**
* @deprecated Use `dirs` instead
Expand Down
Loading