trigger.dev 3.0.0-beta.33 → 3.0.0-beta.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -799,7 +799,7 @@ import invariant from "tiny-invariant";
|
|
|
799
799
|
import { z as z4 } from "zod";
|
|
800
800
|
|
|
801
801
|
// package.json
|
|
802
|
-
var version = "3.0.0-beta.
|
|
802
|
+
var version = "3.0.0-beta.34";
|
|
803
803
|
var dependencies = {
|
|
804
804
|
"@anatine/esbuild-decorators": "^0.2.19",
|
|
805
805
|
"@clack/prompts": "^0.7.0",
|
|
@@ -816,7 +816,7 @@ var dependencies = {
|
|
|
816
816
|
"@opentelemetry/sdk-trace-base": "^1.22.0",
|
|
817
817
|
"@opentelemetry/sdk-trace-node": "^1.22.0",
|
|
818
818
|
"@opentelemetry/semantic-conventions": "^1.22.0",
|
|
819
|
-
"@trigger.dev/core": "workspace:3.0.0-beta.
|
|
819
|
+
"@trigger.dev/core": "workspace:3.0.0-beta.34",
|
|
820
820
|
"@types/degit": "^2.8.3",
|
|
821
821
|
chalk: "^5.2.0",
|
|
822
822
|
chokidar: "^3.5.3",
|
|
@@ -948,7 +948,8 @@ import {
|
|
|
948
948
|
InitializeDeploymentResponseBody,
|
|
949
949
|
GetDeploymentResponseBody,
|
|
950
950
|
GetProjectsResponseBody,
|
|
951
|
-
GetProjectResponseBody
|
|
951
|
+
GetProjectResponseBody,
|
|
952
|
+
EnvironmentVariableResponseBody
|
|
952
953
|
} from "@trigger.dev/core/v3";
|
|
953
954
|
var CliApiClient = class {
|
|
954
955
|
constructor(apiURL, accessToken) {
|
|
@@ -1052,6 +1053,23 @@ var CliApiClient = class {
|
|
|
1052
1053
|
}
|
|
1053
1054
|
);
|
|
1054
1055
|
}
|
|
1056
|
+
async importEnvVars(projectRef, slug, params) {
|
|
1057
|
+
if (!this.accessToken) {
|
|
1058
|
+
throw new Error("importEnvVars: No access token");
|
|
1059
|
+
}
|
|
1060
|
+
return zodfetch(
|
|
1061
|
+
EnvironmentVariableResponseBody,
|
|
1062
|
+
`${this.apiURL}/api/v1/projects/${projectRef}/envvars/${slug}/import`,
|
|
1063
|
+
{
|
|
1064
|
+
method: "POST",
|
|
1065
|
+
headers: {
|
|
1066
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1067
|
+
"Content-Type": "application/json"
|
|
1068
|
+
},
|
|
1069
|
+
body: JSON.stringify(params)
|
|
1070
|
+
}
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1055
1073
|
async initializeDeployment(body) {
|
|
1056
1074
|
if (!this.accessToken) {
|
|
1057
1075
|
throw new Error("initializeDeployment: No access token");
|
|
@@ -1710,7 +1728,15 @@ async function readConfig(dir, options) {
|
|
|
1710
1728
|
cwd: absoluteDir,
|
|
1711
1729
|
tsx: false,
|
|
1712
1730
|
force: false
|
|
1713
|
-
})
|
|
1731
|
+
}),
|
|
1732
|
+
{
|
|
1733
|
+
name: "native-node-modules",
|
|
1734
|
+
setup(build3) {
|
|
1735
|
+
const opts = build3.initialOptions;
|
|
1736
|
+
opts.loader = opts.loader || {};
|
|
1737
|
+
opts.loader[".node"] = "copy";
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1714
1740
|
]
|
|
1715
1741
|
});
|
|
1716
1742
|
try {
|
|
@@ -1723,7 +1749,8 @@ async function readConfig(dir, options) {
|
|
|
1723
1749
|
return {
|
|
1724
1750
|
status: "file",
|
|
1725
1751
|
config: await resolveConfig(absoluteDir, config),
|
|
1726
|
-
path: configPath
|
|
1752
|
+
path: configPath,
|
|
1753
|
+
module: userConfigModule
|
|
1727
1754
|
};
|
|
1728
1755
|
} catch (error) {
|
|
1729
1756
|
return {
|
|
@@ -2302,14 +2329,14 @@ var baseOpen = async (options) => {
|
|
|
2302
2329
|
}
|
|
2303
2330
|
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
2304
2331
|
if (options.wait) {
|
|
2305
|
-
return new Promise((
|
|
2332
|
+
return new Promise((resolve6, reject) => {
|
|
2306
2333
|
subprocess.once("error", reject);
|
|
2307
2334
|
subprocess.once("close", (exitCode) => {
|
|
2308
2335
|
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
2309
2336
|
reject(new Error(`Exited with code ${exitCode}`));
|
|
2310
2337
|
return;
|
|
2311
2338
|
}
|
|
2312
|
-
|
|
2339
|
+
resolve6(subprocess);
|
|
2313
2340
|
});
|
|
2314
2341
|
});
|
|
2315
2342
|
}
|
|
@@ -2426,7 +2453,7 @@ var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
|
2426
2453
|
return error;
|
|
2427
2454
|
};
|
|
2428
2455
|
async function pRetry(input, options) {
|
|
2429
|
-
return new Promise((
|
|
2456
|
+
return new Promise((resolve6, reject) => {
|
|
2430
2457
|
options = {
|
|
2431
2458
|
onFailedAttempt() {
|
|
2432
2459
|
},
|
|
@@ -2449,7 +2476,7 @@ async function pRetry(input, options) {
|
|
|
2449
2476
|
try {
|
|
2450
2477
|
const result = await input(attemptNumber);
|
|
2451
2478
|
cleanUp();
|
|
2452
|
-
|
|
2479
|
+
resolve6(result);
|
|
2453
2480
|
} catch (error) {
|
|
2454
2481
|
try {
|
|
2455
2482
|
if (!(error instanceof Error)) {
|
|
@@ -3832,6 +3859,46 @@ async function getPackageJson(absoluteProjectPath) {
|
|
|
3832
3859
|
return { packageJson, readonlyPackageJson, packageJsonPath };
|
|
3833
3860
|
}
|
|
3834
3861
|
|
|
3862
|
+
// src/utilities/resolveEnvVars.ts
|
|
3863
|
+
async function callResolveEnvVars(configModule, env, environment, projectRef) {
|
|
3864
|
+
if (configModule && configModule.resolveEnvVars && typeof configModule.resolveEnvVars === "function") {
|
|
3865
|
+
let resolvedEnvVars2 = {};
|
|
3866
|
+
try {
|
|
3867
|
+
let result = await configModule.resolveEnvVars({
|
|
3868
|
+
projectRef,
|
|
3869
|
+
environment,
|
|
3870
|
+
env
|
|
3871
|
+
});
|
|
3872
|
+
if (!result) {
|
|
3873
|
+
return;
|
|
3874
|
+
}
|
|
3875
|
+
result = await result;
|
|
3876
|
+
if (typeof result === "object" && result !== null && "variables" in result) {
|
|
3877
|
+
const variables = result.variables;
|
|
3878
|
+
if (Array.isArray(variables)) {
|
|
3879
|
+
for (const item of variables) {
|
|
3880
|
+
if (typeof item === "object" && item !== null && "name" in item && "value" in item && typeof item.name === "string" && typeof item.value === "string") {
|
|
3881
|
+
resolvedEnvVars2[item.name] = item.value;
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
} else if (typeof variables === "object") {
|
|
3885
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
3886
|
+
if (typeof key === "string" && typeof value === "string") {
|
|
3887
|
+
resolvedEnvVars2[key] = value;
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
return {
|
|
3893
|
+
variables: resolvedEnvVars2,
|
|
3894
|
+
override: result.override
|
|
3895
|
+
};
|
|
3896
|
+
} catch (error) {
|
|
3897
|
+
logger.error(error);
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
|
|
3835
3902
|
// src/commands/deploy.ts
|
|
3836
3903
|
var DeployCommandOptions = CommonCommandOptions.extend({
|
|
3837
3904
|
skipTypecheck: z4.boolean().default(false),
|
|
@@ -3981,6 +4048,7 @@ async function _deployCommand(dir, options) {
|
|
|
3981
4048
|
resolvedConfig.status === "file" ? resolvedConfig.path : void 0
|
|
3982
4049
|
);
|
|
3983
4050
|
logger.debug("Compilation result", { compilation });
|
|
4051
|
+
await resolveEnvironmentVariables(resolvedConfig, environmentClient, options);
|
|
3984
4052
|
const deploymentResponse = await environmentClient.initializeDeployment({
|
|
3985
4053
|
contentHash: compilation.contentHash,
|
|
3986
4054
|
userId: authorization.userId
|
|
@@ -4579,7 +4647,9 @@ async function compileProject(config, options, configPath) {
|
|
|
4579
4647
|
const workerSetupPath = join6(cliRootPath(), "workers", "prod", "worker-setup.js");
|
|
4580
4648
|
let workerContents = workerFacade.replace("__TASKS__", createTaskFileImports(taskFiles)).replace(
|
|
4581
4649
|
"__WORKER_SETUP__",
|
|
4582
|
-
`import { tracingSDK } from "${escapeImportPath(
|
|
4650
|
+
`import { tracingSDK, otelTracer, otelLogger } from "${escapeImportPath(
|
|
4651
|
+
workerSetupPath
|
|
4652
|
+
)}";`
|
|
4583
4653
|
);
|
|
4584
4654
|
if (configPath) {
|
|
4585
4655
|
logger.debug("Importing project config from", { configPath });
|
|
@@ -4794,6 +4864,68 @@ If this is unexpected you should check your ${terminalLink2(
|
|
|
4794
4864
|
}
|
|
4795
4865
|
});
|
|
4796
4866
|
}
|
|
4867
|
+
async function resolveEnvironmentVariables(config, apiClient2, options) {
|
|
4868
|
+
if (config.status !== "file") {
|
|
4869
|
+
return;
|
|
4870
|
+
}
|
|
4871
|
+
if (!config.module || typeof config.module.resolveEnvVars !== "function") {
|
|
4872
|
+
return;
|
|
4873
|
+
}
|
|
4874
|
+
const projectConfig = config.config;
|
|
4875
|
+
return await tracer.startActiveSpan("resolveEnvironmentVariables", async (span) => {
|
|
4876
|
+
try {
|
|
4877
|
+
const $spinner = spinner();
|
|
4878
|
+
$spinner.start("Resolving environment variables");
|
|
4879
|
+
let processEnv = {
|
|
4880
|
+
...process.env
|
|
4881
|
+
};
|
|
4882
|
+
const environmentVariables = await apiClient2.getEnvironmentVariables(projectConfig.project);
|
|
4883
|
+
if (environmentVariables.success) {
|
|
4884
|
+
processEnv = {
|
|
4885
|
+
...processEnv,
|
|
4886
|
+
...environmentVariables.data.variables
|
|
4887
|
+
};
|
|
4888
|
+
}
|
|
4889
|
+
logger.debug("Existing environment variables", {
|
|
4890
|
+
keys: Object.keys(processEnv)
|
|
4891
|
+
});
|
|
4892
|
+
const resolvedEnvVars2 = await callResolveEnvVars(
|
|
4893
|
+
config.module,
|
|
4894
|
+
processEnv,
|
|
4895
|
+
options.env,
|
|
4896
|
+
projectConfig.project
|
|
4897
|
+
);
|
|
4898
|
+
if (resolvedEnvVars2) {
|
|
4899
|
+
const total = Object.keys(resolvedEnvVars2.variables).length;
|
|
4900
|
+
logger.debug("Resolved env vars", {
|
|
4901
|
+
keys: Object.keys(resolvedEnvVars2.variables)
|
|
4902
|
+
});
|
|
4903
|
+
if (total > 0) {
|
|
4904
|
+
$spinner.message(
|
|
4905
|
+
`Syncing ${total} environment variable${total > 1 ? "s" : ""} with the server`
|
|
4906
|
+
);
|
|
4907
|
+
const uploadResult = await apiClient2.importEnvVars(projectConfig.project, options.env, {
|
|
4908
|
+
variables: resolvedEnvVars2.variables,
|
|
4909
|
+
override: typeof resolvedEnvVars2.override === "boolean" ? resolvedEnvVars2.override : true
|
|
4910
|
+
});
|
|
4911
|
+
if (uploadResult.success) {
|
|
4912
|
+
$spinner.stop(`${total} environment variable${total > 1 ? "s" : ""} synced`);
|
|
4913
|
+
} else {
|
|
4914
|
+
$spinner.stop("Failed to sync environment variables");
|
|
4915
|
+
throw new Error(uploadResult.error);
|
|
4916
|
+
}
|
|
4917
|
+
} else {
|
|
4918
|
+
$spinner.stop("No environment variables to sync");
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4921
|
+
} catch (e) {
|
|
4922
|
+
recordSpanException5(span, e);
|
|
4923
|
+
throw e;
|
|
4924
|
+
} finally {
|
|
4925
|
+
span.end();
|
|
4926
|
+
}
|
|
4927
|
+
});
|
|
4928
|
+
}
|
|
4797
4929
|
async function resolveDependencies(projectDir, packageJsonContents, config, options) {
|
|
4798
4930
|
return await tracer.startActiveSpan("resolveDependencies", async (span) => {
|
|
4799
4931
|
const resolvingDepsSpinner = spinner();
|
|
@@ -4830,10 +4962,29 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
|
|
|
4830
4962
|
});
|
|
4831
4963
|
logger.debug(`No cached package-lock.json found for ${digest}`);
|
|
4832
4964
|
try {
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4965
|
+
if (logger.loggerLevel === "debug") {
|
|
4966
|
+
const childProcess2 = await execa2("npm", ["config", "list"], {
|
|
4967
|
+
cwd: projectDir,
|
|
4968
|
+
stdio: "inherit"
|
|
4969
|
+
});
|
|
4970
|
+
logger.debug("npm config list");
|
|
4971
|
+
console.log(childProcess2.stdout);
|
|
4972
|
+
}
|
|
4973
|
+
await execa2(
|
|
4974
|
+
"npm",
|
|
4975
|
+
[
|
|
4976
|
+
"install",
|
|
4977
|
+
"--package-lock-only",
|
|
4978
|
+
"--ignore-scripts",
|
|
4979
|
+
"--no-audit",
|
|
4980
|
+
"--legacy-peer-deps=false",
|
|
4981
|
+
"--strict-peer-deps=false"
|
|
4982
|
+
],
|
|
4983
|
+
{
|
|
4984
|
+
cwd: projectDir,
|
|
4985
|
+
stdio: logger.loggerLevel === "debug" ? "inherit" : "pipe"
|
|
4986
|
+
}
|
|
4987
|
+
);
|
|
4837
4988
|
const packageLockContents = await readFile2(join6(projectDir, "package-lock.json"), "utf-8");
|
|
4838
4989
|
logger.debug(`Writing package-lock.json to cache for ${digest}`);
|
|
4839
4990
|
await mkdir(cacheDir, { recursive: true });
|
|
@@ -4890,8 +5041,8 @@ async function typecheckProject(config, options) {
|
|
|
4890
5041
|
tscTypecheck.stdout?.on("data", (chunk) => stdouts.push(chunk.toString()));
|
|
4891
5042
|
tscTypecheck.stderr?.on("data", (chunk) => stderrs.push(chunk.toString()));
|
|
4892
5043
|
try {
|
|
4893
|
-
await new Promise((
|
|
4894
|
-
tscTypecheck.addListener("exit", (code) => code === 0 ?
|
|
5044
|
+
await new Promise((resolve6, reject) => {
|
|
5045
|
+
tscTypecheck.addListener("exit", (code) => code === 0 ? resolve6(code) : reject(code));
|
|
4895
5046
|
});
|
|
4896
5047
|
} catch (error) {
|
|
4897
5048
|
typecheckSpinner.stop(
|
|
@@ -5137,7 +5288,7 @@ import { ZodMessageHandler, ZodMessageSender } from "@trigger.dev/core/v3/zodMes
|
|
|
5137
5288
|
import dotenv from "dotenv";
|
|
5138
5289
|
import { Evt } from "evt";
|
|
5139
5290
|
import { fork } from "node:child_process";
|
|
5140
|
-
import { dirname as dirname2, resolve as
|
|
5291
|
+
import { dirname as dirname2, resolve as resolve4 } from "node:path";
|
|
5141
5292
|
import terminalLink3 from "terminal-link";
|
|
5142
5293
|
var BackgroundWorkerCoordinator = class {
|
|
5143
5294
|
constructor(baseURL) {
|
|
@@ -5310,6 +5461,7 @@ var BackgroundWorker = class {
|
|
|
5310
5461
|
metadata;
|
|
5311
5462
|
_taskRunProcesses = /* @__PURE__ */ new Map();
|
|
5312
5463
|
_closed = false;
|
|
5464
|
+
_fullEnv = {};
|
|
5313
5465
|
close() {
|
|
5314
5466
|
if (this._closed) {
|
|
5315
5467
|
return;
|
|
@@ -5332,12 +5484,24 @@ var BackgroundWorker = class {
|
|
|
5332
5484
|
}
|
|
5333
5485
|
let resolved = false;
|
|
5334
5486
|
const cwd = dirname2(this.path);
|
|
5335
|
-
|
|
5487
|
+
this._fullEnv = {
|
|
5336
5488
|
...this.params.env,
|
|
5337
|
-
...this.#readEnvVars()
|
|
5489
|
+
...this.#readEnvVars(),
|
|
5490
|
+
...this.params.debugOtel ? { OTEL_LOG_LEVEL: "debug" } : {}
|
|
5338
5491
|
};
|
|
5339
|
-
|
|
5340
|
-
this.
|
|
5492
|
+
let resolvedEnvVars2 = {};
|
|
5493
|
+
if (this.params.resolveEnvVariables) {
|
|
5494
|
+
const resolvedEnv = await this.params.resolveEnvVariables(this._fullEnv, this);
|
|
5495
|
+
if (resolvedEnv) {
|
|
5496
|
+
resolvedEnvVars2 = resolvedEnv;
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
this._fullEnv = {
|
|
5500
|
+
...this._fullEnv,
|
|
5501
|
+
...resolvedEnvVars2
|
|
5502
|
+
};
|
|
5503
|
+
logger.debug("Initializing worker", { path: this.path, cwd, fullEnv: this._fullEnv });
|
|
5504
|
+
this.tasks = await new Promise((resolve6, reject) => {
|
|
5341
5505
|
const child = fork(this.path, {
|
|
5342
5506
|
stdio: [
|
|
5343
5507
|
/*stdin*/
|
|
@@ -5349,7 +5513,7 @@ var BackgroundWorker = class {
|
|
|
5349
5513
|
"ipc"
|
|
5350
5514
|
],
|
|
5351
5515
|
cwd,
|
|
5352
|
-
env:
|
|
5516
|
+
env: this._fullEnv
|
|
5353
5517
|
});
|
|
5354
5518
|
const timeout = setTimeout(() => {
|
|
5355
5519
|
if (resolved) {
|
|
@@ -5364,7 +5528,7 @@ var BackgroundWorker = class {
|
|
|
5364
5528
|
if (message.type === "TASKS_READY" && !resolved) {
|
|
5365
5529
|
clearTimeout(timeout);
|
|
5366
5530
|
resolved = true;
|
|
5367
|
-
|
|
5531
|
+
resolve6(message.payload.tasks);
|
|
5368
5532
|
child.kill();
|
|
5369
5533
|
} else if (message.type === "UNCAUGHT_EXCEPTION") {
|
|
5370
5534
|
clearTimeout(timeout);
|
|
@@ -5407,9 +5571,8 @@ var BackgroundWorker = class {
|
|
|
5407
5571
|
payload.execution,
|
|
5408
5572
|
this.path,
|
|
5409
5573
|
{
|
|
5410
|
-
...this.
|
|
5411
|
-
...payload.environment ?? {}
|
|
5412
|
-
...this.#readEnvVars()
|
|
5574
|
+
...this._fullEnv,
|
|
5575
|
+
...payload.environment ?? {}
|
|
5413
5576
|
},
|
|
5414
5577
|
this.metadata,
|
|
5415
5578
|
this.params
|
|
@@ -5499,7 +5662,7 @@ var BackgroundWorker = class {
|
|
|
5499
5662
|
const result = {};
|
|
5500
5663
|
dotenv.config({
|
|
5501
5664
|
processEnv: result,
|
|
5502
|
-
path: [".env", ".env.local", ".env.development.local"].map((p) =>
|
|
5665
|
+
path: [".env", ".env.local", ".env.development.local"].map((p) => resolve4(process.cwd(), p))
|
|
5503
5666
|
});
|
|
5504
5667
|
process.env.TRIGGER_API_URL && (result.TRIGGER_API_URL = process.env.TRIGGER_API_URL);
|
|
5505
5668
|
delete result.TRIGGER_API_URL;
|
|
@@ -5600,8 +5763,8 @@ var TaskRunProcess = class {
|
|
|
5600
5763
|
async executeTaskRun(payload) {
|
|
5601
5764
|
let resolver;
|
|
5602
5765
|
let rejecter;
|
|
5603
|
-
const promise = new Promise((
|
|
5604
|
-
resolver =
|
|
5766
|
+
const promise = new Promise((resolve6, reject) => {
|
|
5767
|
+
resolver = resolve6;
|
|
5605
5768
|
rejecter = reject;
|
|
5606
5769
|
});
|
|
5607
5770
|
this._attemptStatuses.set(payload.execution.attempt.id, "PENDING");
|
|
@@ -5813,7 +5976,7 @@ async function startDev(dir, options, authorization, dashboardUrl) {
|
|
|
5813
5976
|
logger.error("Failed to read config", config.error);
|
|
5814
5977
|
process.exit(1);
|
|
5815
5978
|
}
|
|
5816
|
-
async function getDevReactElement(configParam, authorization2, configPath) {
|
|
5979
|
+
async function getDevReactElement(configParam, authorization2, configPath, configModule) {
|
|
5817
5980
|
const accessToken = authorization2.accessToken;
|
|
5818
5981
|
const apiUrl = authorization2.apiUrl;
|
|
5819
5982
|
apiClient = new CliApiClient(apiUrl, accessToken);
|
|
@@ -5845,7 +6008,8 @@ async function startDev(dir, options, authorization, dashboardUrl) {
|
|
|
5845
6008
|
projectName: devEnv.data.name,
|
|
5846
6009
|
debuggerOn: options.debugger,
|
|
5847
6010
|
debugOtel: options.debugOtel,
|
|
5848
|
-
configPath
|
|
6011
|
+
configPath,
|
|
6012
|
+
configModule
|
|
5849
6013
|
}
|
|
5850
6014
|
);
|
|
5851
6015
|
}
|
|
@@ -5853,7 +6017,8 @@ async function startDev(dir, options, authorization, dashboardUrl) {
|
|
|
5853
6017
|
await getDevReactElement(
|
|
5854
6018
|
config.config,
|
|
5855
6019
|
authorization,
|
|
5856
|
-
config.status === "file" ? config.path : void 0
|
|
6020
|
+
config.status === "file" ? config.path : void 0,
|
|
6021
|
+
config.status === "file" ? config.module : void 0
|
|
5857
6022
|
)
|
|
5858
6023
|
);
|
|
5859
6024
|
rerender = devReactElement.rerender;
|
|
@@ -5876,7 +6041,8 @@ function useDev({
|
|
|
5876
6041
|
projectName,
|
|
5877
6042
|
debuggerOn,
|
|
5878
6043
|
debugOtel,
|
|
5879
|
-
configPath
|
|
6044
|
+
configPath,
|
|
6045
|
+
configModule
|
|
5880
6046
|
}) {
|
|
5881
6047
|
useEffect(() => {
|
|
5882
6048
|
const websocketUrl = new URL(apiUrl);
|
|
@@ -5965,6 +6131,7 @@ function useDev({
|
|
|
5965
6131
|
await messageHandler.handleMessage(data);
|
|
5966
6132
|
});
|
|
5967
6133
|
let ctx;
|
|
6134
|
+
let firstBuild = true;
|
|
5968
6135
|
async function runBuild() {
|
|
5969
6136
|
if (ctx) {
|
|
5970
6137
|
await ctx.dispose();
|
|
@@ -5976,7 +6143,9 @@ function useDev({
|
|
|
5976
6143
|
const workerSetupPath = join7(cliRootPath(), "workers", "dev", "worker-setup.js");
|
|
5977
6144
|
let entryPointContents = workerFacade.replace("__TASKS__", createTaskFileImports(taskFiles)).replace(
|
|
5978
6145
|
"__WORKER_SETUP__",
|
|
5979
|
-
`import { tracingSDK, sender } from "${escapeImportPath(
|
|
6146
|
+
`import { tracingSDK, otelTracer, otelLogger, sender } from "${escapeImportPath(
|
|
6147
|
+
workerSetupPath
|
|
6148
|
+
)}";`
|
|
5980
6149
|
);
|
|
5981
6150
|
if (configPath) {
|
|
5982
6151
|
configPath = normalize(configPath);
|
|
@@ -5993,7 +6162,6 @@ function useDev({
|
|
|
5993
6162
|
`const importedConfig = undefined; const handleError = undefined;`
|
|
5994
6163
|
);
|
|
5995
6164
|
}
|
|
5996
|
-
let firstBuild = true;
|
|
5997
6165
|
logger.log(chalkGrey("\u25CB Building background worker\u2026"));
|
|
5998
6166
|
ctx = await context2({
|
|
5999
6167
|
stdin: {
|
|
@@ -6094,7 +6262,8 @@ function useDev({
|
|
|
6094
6262
|
...environmentVariablesResponse.success ? environmentVariablesResponse.data.variables : {}
|
|
6095
6263
|
},
|
|
6096
6264
|
debuggerOn,
|
|
6097
|
-
debugOtel
|
|
6265
|
+
debugOtel,
|
|
6266
|
+
resolveEnvVariables: createResolveEnvironmentVariablesFunction(configModule)
|
|
6098
6267
|
});
|
|
6099
6268
|
try {
|
|
6100
6269
|
await backgroundWorker.initialize();
|
|
@@ -6366,6 +6535,26 @@ async function findPnpmNodeModulesPath() {
|
|
|
6366
6535
|
{ type: "directory" }
|
|
6367
6536
|
);
|
|
6368
6537
|
}
|
|
6538
|
+
var hasResolvedEnvVars = false;
|
|
6539
|
+
var resolvedEnvVars = {};
|
|
6540
|
+
function createResolveEnvironmentVariablesFunction(configModule) {
|
|
6541
|
+
return async (env, worker) => {
|
|
6542
|
+
if (hasResolvedEnvVars) {
|
|
6543
|
+
return resolvedEnvVars;
|
|
6544
|
+
}
|
|
6545
|
+
const $resolvedEnvVars = await callResolveEnvVars(
|
|
6546
|
+
configModule,
|
|
6547
|
+
env,
|
|
6548
|
+
"dev",
|
|
6549
|
+
worker.params.projectConfig.project
|
|
6550
|
+
);
|
|
6551
|
+
if ($resolvedEnvVars) {
|
|
6552
|
+
resolvedEnvVars = $resolvedEnvVars.variables;
|
|
6553
|
+
hasResolvedEnvVars = true;
|
|
6554
|
+
}
|
|
6555
|
+
return resolvedEnvVars;
|
|
6556
|
+
};
|
|
6557
|
+
}
|
|
6369
6558
|
|
|
6370
6559
|
// src/commands/init.ts
|
|
6371
6560
|
import { intro as intro5, isCancel as isCancel2, log as log6, outro as outro6, select as select2, text } from "@clack/prompts";
|
|
@@ -6374,9 +6563,9 @@ import { flattenAttributes as flattenAttributes4 } from "@trigger.dev/core/v3";
|
|
|
6374
6563
|
import { recordSpanException as recordSpanException6 } from "@trigger.dev/core/v3/workers";
|
|
6375
6564
|
import chalk5 from "chalk";
|
|
6376
6565
|
import { execa as execa3 } from "execa";
|
|
6377
|
-
import { applyEdits, modify } from "jsonc-parser";
|
|
6566
|
+
import { applyEdits, modify, findNodeAtLocation, parseTree, getNodeValue } from "jsonc-parser";
|
|
6378
6567
|
import { writeFile as writeFile3 } from "node:fs/promises";
|
|
6379
|
-
import { join as join8, relative as relative4, resolve as
|
|
6568
|
+
import { join as join8, relative as relative4, resolve as resolve5 } from "node:path";
|
|
6380
6569
|
import terminalLink4 from "terminal-link";
|
|
6381
6570
|
import { z as z6 } from "zod";
|
|
6382
6571
|
|
|
@@ -6541,7 +6730,7 @@ async function createTriggerDir(dir, options) {
|
|
|
6541
6730
|
if (isCancel2(location)) {
|
|
6542
6731
|
throw new OutroCommandError();
|
|
6543
6732
|
}
|
|
6544
|
-
const triggerDir =
|
|
6733
|
+
const triggerDir = resolve5(process.cwd(), location);
|
|
6545
6734
|
logger.debug({ triggerDir });
|
|
6546
6735
|
span.setAttributes({
|
|
6547
6736
|
"cli.triggerDir": triggerDir
|
|
@@ -6596,7 +6785,7 @@ async function createTriggerDir(dir, options) {
|
|
|
6596
6785
|
async function gitIgnoreDotTriggerDir(dir, options) {
|
|
6597
6786
|
return await tracer.startActiveSpan("gitIgnoreDotTriggerDir", async (span) => {
|
|
6598
6787
|
try {
|
|
6599
|
-
const projectDir =
|
|
6788
|
+
const projectDir = resolve5(process.cwd(), dir);
|
|
6600
6789
|
const gitIgnorePath = join8(projectDir, ".gitignore");
|
|
6601
6790
|
span.setAttributes({
|
|
6602
6791
|
"cli.projectDir": projectDir,
|
|
@@ -6630,14 +6819,30 @@ async function gitIgnoreDotTriggerDir(dir, options) {
|
|
|
6630
6819
|
async function addConfigFileToTsConfig(dir, options) {
|
|
6631
6820
|
return await tracer.startActiveSpan("createTriggerDir", async (span) => {
|
|
6632
6821
|
try {
|
|
6633
|
-
const projectDir =
|
|
6822
|
+
const projectDir = resolve5(process.cwd(), dir);
|
|
6634
6823
|
const tsconfigPath = join8(projectDir, "tsconfig.json");
|
|
6635
6824
|
span.setAttributes({
|
|
6636
6825
|
"cli.projectDir": projectDir,
|
|
6637
6826
|
"cli.tsconfigPath": tsconfigPath
|
|
6638
6827
|
});
|
|
6639
6828
|
const tsconfigContent = await readFile(tsconfigPath);
|
|
6640
|
-
const
|
|
6829
|
+
const tsconfigContentTree = parseTree(tsconfigContent, void 0);
|
|
6830
|
+
if (!tsconfigContentTree) {
|
|
6831
|
+
span.end();
|
|
6832
|
+
return;
|
|
6833
|
+
}
|
|
6834
|
+
const tsconfigIncludeOption = findNodeAtLocation(tsconfigContentTree, ["include"]);
|
|
6835
|
+
if (!tsconfigIncludeOption) {
|
|
6836
|
+
span.end();
|
|
6837
|
+
return;
|
|
6838
|
+
}
|
|
6839
|
+
const tsConfigFileName = "trigger.config.ts";
|
|
6840
|
+
const tsconfigIncludeOptionValue = getNodeValue(tsconfigIncludeOption);
|
|
6841
|
+
if (tsconfigIncludeOptionValue.includes(tsConfigFileName)) {
|
|
6842
|
+
span.end();
|
|
6843
|
+
return;
|
|
6844
|
+
}
|
|
6845
|
+
const edits = modify(tsconfigContent, ["include", -1], tsConfigFileName, {
|
|
6641
6846
|
isArrayInsertion: true,
|
|
6642
6847
|
formattingOptions: {
|
|
6643
6848
|
tabSize: 2,
|
|
@@ -6664,7 +6869,7 @@ async function installPackages2(dir, options) {
|
|
|
6664
6869
|
return await tracer.startActiveSpan("installPackages", async (span) => {
|
|
6665
6870
|
const installSpinner = spinner();
|
|
6666
6871
|
try {
|
|
6667
|
-
const projectDir =
|
|
6872
|
+
const projectDir = resolve5(process.cwd(), dir);
|
|
6668
6873
|
const pkgManager = await getUserPackageManager(projectDir);
|
|
6669
6874
|
span.setAttributes({
|
|
6670
6875
|
"cli.projectDir": projectDir,
|
|
@@ -6716,7 +6921,7 @@ async function writeConfigFile(dir, project, options, triggerDir) {
|
|
|
6716
6921
|
try {
|
|
6717
6922
|
const spnnr = spinner();
|
|
6718
6923
|
spnnr.start("Creating config file");
|
|
6719
|
-
const projectDir =
|
|
6924
|
+
const projectDir = resolve5(process.cwd(), dir);
|
|
6720
6925
|
const templatePath = join8(cliRootPath(), "templates", "trigger.config.ts.template");
|
|
6721
6926
|
const outputPath = join8(projectDir, "trigger.config.ts");
|
|
6722
6927
|
span.setAttributes({
|