trigger.dev 3.0.0-beta.16 → 3.0.0-beta.18

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
@@ -777,30 +777,29 @@ var require_retry2 = __commonJS({
777
777
  import { Command as Command2 } from "commander";
778
778
 
779
779
  // src/commands/deploy.ts
780
- import { intro as intro3, log as log3, outro as outro3 } from "@clack/prompts";
780
+ import { intro as intro4, log as log5, outro as outro5 } from "@clack/prompts";
781
781
  import { depot } from "@depot/cli";
782
782
  import { context, trace as trace2 } from "@opentelemetry/api";
783
783
  import {
784
784
  TaskMetadataFailedToParseData,
785
785
  detectDependencyVersion,
786
- flattenAttributes as flattenAttributes2,
787
- recordSpanException as recordSpanException4
786
+ flattenAttributes as flattenAttributes2
788
787
  } from "@trigger.dev/core/v3";
789
- import chalk5 from "chalk";
788
+ import { recordSpanException as recordSpanException4 } from "@trigger.dev/core/v3/workers";
790
789
  import { Option as CommandOption } from "commander";
791
790
  import { build as build2 } from "esbuild";
792
791
  import { execa as execa2 } from "execa";
793
792
  import { createHash } from "node:crypto";
794
793
  import { readFileSync as readFileSync2 } from "node:fs";
795
794
  import { copyFile, mkdir, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
796
- import { dirname, join as join5, relative as relative3, posix } from "node:path";
795
+ import { dirname, join as join6, relative as relative3, posix } from "node:path";
797
796
  import { setTimeout as setTimeout2 } from "node:timers/promises";
798
797
  import terminalLink2 from "terminal-link";
799
798
  import invariant from "tiny-invariant";
800
799
  import { z as z4 } from "zod";
801
800
 
802
801
  // package.json
803
- var version = "3.0.0-beta.16";
802
+ var version = "3.0.0-beta.18";
804
803
  var dependencies = {
805
804
  "@clack/prompts": "^0.7.0",
806
805
  "@depot/cli": "0.0.1-cli.2.55.0",
@@ -816,7 +815,7 @@ var dependencies = {
816
815
  "@opentelemetry/sdk-trace-base": "^1.22.0",
817
816
  "@opentelemetry/sdk-trace-node": "^1.22.0",
818
817
  "@opentelemetry/semantic-conventions": "^1.22.0",
819
- "@trigger.dev/core": "workspace:^3.0.0-beta.16",
818
+ "@trigger.dev/core": "workspace:^3.0.0-beta.18",
820
819
  "@types/degit": "^2.8.3",
821
820
  chalk: "^5.2.0",
822
821
  chokidar: "^3.5.3",
@@ -837,7 +836,6 @@ var dependencies = {
837
836
  "mock-fs": "^5.2.0",
838
837
  nanoid: "^4.0.2",
839
838
  "node-fetch": "^3.3.0",
840
- "npm-check-updates": "^16.12.2",
841
839
  "object-hash": "^3.0.0",
842
840
  "p-debounce": "^4.0.0",
843
841
  "p-throttle": "^6.1.0",
@@ -1141,7 +1139,8 @@ async function zodfetch(schema, url, requestInit) {
1141
1139
  }
1142
1140
 
1143
1141
  // src/cli/common.ts
1144
- import { flattenAttributes, recordSpanException } from "@trigger.dev/core/v3";
1142
+ import { flattenAttributes } from "@trigger.dev/core/v3";
1143
+ import { recordSpanException } from "@trigger.dev/core/v3/workers";
1145
1144
  import { z } from "zod";
1146
1145
 
1147
1146
  // src/telemetry/tracing.ts
@@ -1151,6 +1150,10 @@ import { Resource, detectResourcesSync, processDetectorSync } from "@opentelemet
1151
1150
  import { NodeTracerProvider, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
1152
1151
  import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch";
1153
1152
  import { DiagConsoleLogger, DiagLogLevel, diag, trace } from "@opentelemetry/api";
1153
+ import {
1154
+ SEMRESATTRS_SERVICE_NAME,
1155
+ SEMRESATTRS_SERVICE_VERSION
1156
+ } from "@opentelemetry/semantic-conventions";
1154
1157
  function initializeTracing() {
1155
1158
  if (process.argv.includes("--skip-telemetry") || process.env.TRIGGER_DEV_SKIP_TELEMETRY) {
1156
1159
  return;
@@ -1162,7 +1165,8 @@ function initializeTracing() {
1162
1165
  detectors: [processDetectorSync]
1163
1166
  }).merge(
1164
1167
  new Resource({
1165
- service: "trigger.dev cli v3"
1168
+ [SEMRESATTRS_SERVICE_NAME]: "trigger.dev cli v3",
1169
+ [SEMRESATTRS_SERVICE_VERSION]: version
1166
1170
  })
1167
1171
  );
1168
1172
  const traceProvider = new NodeTracerProvider({
@@ -1179,10 +1183,9 @@ function initializeTracing() {
1179
1183
  });
1180
1184
  const spanExporter = new OTLPTraceExporter({
1181
1185
  url: "https://otel.baselime.io/v1",
1182
- timeoutMillis: 500,
1186
+ timeoutMillis: 5e3,
1183
1187
  headers: {
1184
- "x-api-key": "e9f963244f8b092850d42e34a5339b2d5e68070b".split("").reverse().join("")
1185
- // this is a joke
1188
+ "x-api-key": "b6e0fbbaf8dc2524773d2152ae2e9eb5c7fbaa52"
1186
1189
  }
1187
1190
  });
1188
1191
  const spanProcessor = new SimpleSpanProcessor(spanExporter);
@@ -1195,7 +1198,7 @@ function initializeTracing() {
1195
1198
  }
1196
1199
  var provider = initializeTracing();
1197
1200
  function getTracer() {
1198
- return trace.getTracer("trigger.dev cli", version);
1201
+ return trace.getTracer("trigger.dev cli v3", version);
1199
1202
  }
1200
1203
 
1201
1204
  // src/cli/common.ts
@@ -1318,6 +1321,7 @@ var logger = new Logger();
1318
1321
  import { outro } from "@clack/prompts";
1319
1322
 
1320
1323
  // src/utilities/cliOutput.ts
1324
+ import { log } from "@clack/prompts";
1321
1325
  import chalk2 from "chalk";
1322
1326
  var green = "#4FFF54";
1323
1327
  var purple = "#735BF3";
@@ -1366,6 +1370,30 @@ function prettyPrintDate(date = /* @__PURE__ */ new Date()) {
1366
1370
  formattedDate += "." + ("00" + date.getMilliseconds()).slice(-3);
1367
1371
  return formattedDate;
1368
1372
  }
1373
+ function prettyError(header, body, footer) {
1374
+ const prefix = "Error: ";
1375
+ const indent = Array(prefix.length).fill(" ").join("");
1376
+ const spacing = "\n\n";
1377
+ const prettyPrefix = chalkError(prefix);
1378
+ const withIndents = (text3) => text3?.split("\n").map((line) => `${indent}${line}`).join("\n");
1379
+ const prettyBody = withIndents(body);
1380
+ const prettyFooter = withIndents(footer);
1381
+ log.error(
1382
+ `${prettyPrefix}${header}${prettyBody ? `${spacing}${prettyBody}` : ""}${prettyFooter ? `${spacing}${prettyFooter}` : ""}`
1383
+ );
1384
+ }
1385
+ function prettyWarning(header, body, footer) {
1386
+ const prefix = "Warning: ";
1387
+ const indent = Array(prefix.length).fill(" ").join("");
1388
+ const spacing = "\n\n";
1389
+ const prettyPrefix = chalkWarning(prefix);
1390
+ const withIndents = (text3) => text3?.split("\n").map((line) => `${indent}${line}`).join("\n");
1391
+ const prettyBody = withIndents(body);
1392
+ const prettyFooter = withIndents(footer);
1393
+ log.warn(
1394
+ `${prettyPrefix}${header}${prettyBody ? `${spacing}${prettyBody}` : ""}${prettyFooter ? `${spacing}${prettyFooter}` : ""}`
1395
+ );
1396
+ }
1369
1397
 
1370
1398
  // src/cli/common.ts
1371
1399
  var CommonCommandOptions = z.object({
@@ -1474,6 +1502,9 @@ async function createFile(path7, contents) {
1474
1502
  async function pathExists(path7) {
1475
1503
  return fsSync.existsSync(path7);
1476
1504
  }
1505
+ async function removeFile(path7) {
1506
+ await fsModule.unlink(path7);
1507
+ }
1477
1508
  async function readFile(path7) {
1478
1509
  return await fsModule.readFile(path7, "utf8");
1479
1510
  }
@@ -1481,8 +1512,8 @@ async function readJSONFile(path7) {
1481
1512
  const fileContents = await fsModule.readFile(path7, "utf8");
1482
1513
  return JSON.parse(fileContents);
1483
1514
  }
1484
- async function writeJSONFile(path7, json) {
1485
- await writeFile(path7, JSON.stringify(json), "utf8");
1515
+ async function writeJSONFile(path7, json, pretty = false) {
1516
+ await writeFile(path7, JSON.stringify(json, void 0, pretty ? 2 : void 0), "utf8");
1486
1517
  }
1487
1518
  function readJSONFileSync(path7) {
1488
1519
  const fileContents = fsSync.readFileSync(path7, "utf8");
@@ -1513,14 +1544,23 @@ function createTaskFileImports(taskFiles) {
1513
1544
  async function gatherTaskFiles(config) {
1514
1545
  const taskFiles = [];
1515
1546
  for (const triggerDir of config.triggerDirectories) {
1516
- const files = await fs2.promises.readdir(triggerDir, { withFileTypes: true });
1517
- for (const file of files) {
1518
- if (!file.isFile())
1519
- continue;
1547
+ const files = await gatherTaskFilesFromDir(triggerDir, triggerDir, config);
1548
+ taskFiles.push(...files);
1549
+ }
1550
+ return taskFiles;
1551
+ }
1552
+ async function gatherTaskFilesFromDir(dirPath, triggerDir, config) {
1553
+ const taskFiles = [];
1554
+ const files = await fs2.promises.readdir(dirPath, { withFileTypes: true });
1555
+ for (const file of files) {
1556
+ if (!file.isFile()) {
1557
+ const fullPath = join(dirPath, file.name);
1558
+ taskFiles.push(...await gatherTaskFilesFromDir(fullPath, triggerDir, config));
1559
+ } else {
1520
1560
  if (!file.name.endsWith(".js") && !file.name.endsWith(".ts") && !file.name.endsWith(".jsx") && !file.name.endsWith(".tsx")) {
1521
1561
  continue;
1522
1562
  }
1523
- const fullPath = join(triggerDir, file.name);
1563
+ const fullPath = join(dirPath, file.name);
1524
1564
  const filePath = relative(config.projectDir, fullPath);
1525
1565
  const importName = filePath.replace(/\..+$/, "").replace(/[^a-zA-Z0-9_$]/g, "_");
1526
1566
  const importPath = filePath.replace(/\\/g, "/");
@@ -1540,9 +1580,12 @@ async function getTriggerDirectories(dirPath) {
1540
1580
  const entries = await fs2.promises.readdir(dirPath, { withFileTypes: true });
1541
1581
  const triggerDirectories = [];
1542
1582
  for (const entry of entries) {
1543
- if (!entry.isDirectory() || IGNORED_DIRS.includes(entry.name))
1583
+ if (!entry.isDirectory() || IGNORED_DIRS.includes(entry.name) || entry.name.startsWith("."))
1544
1584
  continue;
1545
1585
  const fullPath = join(dirPath, entry.name);
1586
+ if (fullPath.endsWith("app/api/trigger")) {
1587
+ continue;
1588
+ }
1546
1589
  if (entry.name === "trigger") {
1547
1590
  triggerDirectories.push(fullPath);
1548
1591
  }
@@ -1616,6 +1659,15 @@ async function getConfigPath(dir, fileName) {
1616
1659
  });
1617
1660
  return await findUp(fileName ? [fileName] : CONFIG_FILES, { cwd: dir });
1618
1661
  }
1662
+ async function findFilePath(dir, fileName) {
1663
+ const result = await findUp([fileName], { cwd: dir });
1664
+ logger.debug("Searched for the file", {
1665
+ dir,
1666
+ fileName,
1667
+ result
1668
+ });
1669
+ return result;
1670
+ }
1619
1671
  async function readConfig(dir, options) {
1620
1672
  const absoluteDir = path2.resolve(process.cwd(), dir);
1621
1673
  const configPath = await getConfigPath(dir, options?.configFile);
@@ -1668,6 +1720,7 @@ async function resolveConfig(path7, config) {
1668
1720
  config.triggerDirectories = await findTriggerDirectories(path7);
1669
1721
  }
1670
1722
  config.triggerDirectories = resolveTriggerDirectories(config.triggerDirectories);
1723
+ logger.debug("Resolved trigger directories", { triggerDirectories: config.triggerDirectories });
1671
1724
  if (!config.triggerUrl) {
1672
1725
  config.triggerUrl = CLOUD_API_URL;
1673
1726
  }
@@ -1675,7 +1728,7 @@ async function resolveConfig(path7, config) {
1675
1728
  config.projectDir = path7;
1676
1729
  }
1677
1730
  if (!config.tsconfigPath) {
1678
- config.tsconfigPath = await getConfigPath(path7, "tsconfig.json");
1731
+ config.tsconfigPath = await findFilePath(path7, "tsconfig.json");
1679
1732
  }
1680
1733
  return config;
1681
1734
  }
@@ -1701,29 +1754,29 @@ function getVersion() {
1701
1754
  }
1702
1755
 
1703
1756
  // src/utilities/windows.ts
1704
- import { log, spinner as clackSpinner } from "@clack/prompts";
1757
+ import { log as log2, spinner as clackSpinner } from "@clack/prompts";
1705
1758
  var isWindows = process.platform === "win32";
1706
1759
  function escapeImportPath(path7) {
1707
1760
  return isWindows ? path7.replaceAll("\\", "\\\\") : path7;
1708
1761
  }
1709
1762
  var ballmerSpinner = () => ({
1710
1763
  start: (msg) => {
1711
- log.step(msg ?? "");
1764
+ log2.step(msg ?? "");
1712
1765
  },
1713
1766
  stop: (msg, code) => {
1714
- log.message(msg ?? "");
1767
+ log2.message(msg ?? "");
1715
1768
  },
1716
1769
  message: (msg) => {
1717
- log.message(msg ?? "");
1770
+ log2.message(msg ?? "");
1718
1771
  }
1719
1772
  });
1720
1773
  var spinner = () => isWindows ? ballmerSpinner() : clackSpinner();
1721
1774
 
1722
1775
  // src/utilities/initialBanner.ts
1723
1776
  async function printInitialBanner(performUpdateCheck = true) {
1724
- const packageVersion = getVersion();
1777
+ const cliVersion = getVersion();
1725
1778
  const text3 = `
1726
- ${logo()} ${chalkGrey(`(${packageVersion})`)}
1779
+ ${logo()} ${chalkGrey(`(${cliVersion})`)}
1727
1780
  `;
1728
1781
  logger.info(text3);
1729
1782
  let maybeNewVersion;
@@ -1733,7 +1786,7 @@ ${logo()} ${chalkGrey(`(${packageVersion})`)}
1733
1786
  maybeNewVersion = await updateCheck();
1734
1787
  if (maybeNewVersion !== void 0) {
1735
1788
  loadingSpinner.stop(`Update available ${chalk3.green(maybeNewVersion)}`);
1736
- const currentMajor = parseInt(packageVersion.split(".")[0]);
1789
+ const currentMajor = parseInt(cliVersion.split(".")[0]);
1737
1790
  const newMajor = parseInt(maybeNewVersion.split(".")[0]);
1738
1791
  if (newMajor > currentMajor) {
1739
1792
  logger.warn(
@@ -1748,9 +1801,10 @@ After installation, run Trigger.dev with \`npx trigger.dev\`.`
1748
1801
  }
1749
1802
  }
1750
1803
  async function printStandloneInitialBanner(performUpdateCheck = true) {
1751
- const packageVersion = getVersion();
1804
+ const cliVersion = getVersion();
1752
1805
  logger.log(`
1753
- ${logo()} ${chalkGrey("(v3 Developer Preview)")}`);
1806
+ ${logo()} ${chalkGrey(`(${cliVersion})`)}
1807
+ `);
1754
1808
  if (performUpdateCheck) {
1755
1809
  const maybeNewVersion = await updateCheck();
1756
1810
  if (maybeNewVersion !== void 0) {
@@ -1759,7 +1813,10 @@ ${logo()} ${chalkGrey("(v3 Developer Preview)")}`);
1759
1813
  }
1760
1814
  logger.log(`${chalkGrey("-".repeat(54))}`);
1761
1815
  }
1762
- function printDevBanner() {
1816
+ function printDevBanner(printTopBorder = true) {
1817
+ if (printTopBorder) {
1818
+ logger.log(chalkGrey("-".repeat(54)));
1819
+ }
1763
1820
  logger.log(
1764
1821
  `${chalkGrey("Key:")} ${chalkWorker("Version")} ${chalkGrey("|")} ${chalkTask(
1765
1822
  "Task"
@@ -1771,7 +1828,7 @@ async function doUpdateCheck() {
1771
1828
  let update = null;
1772
1829
  try {
1773
1830
  update = await checkForUpdate(package_default, {
1774
- distTag: package_default.version.startsWith("0.0.0") ? "beta" : "latest"
1831
+ distTag: package_default.version.startsWith("3.0.0-beta") ? "beta" : "latest"
1775
1832
  });
1776
1833
  } catch (err) {
1777
1834
  }
@@ -1840,8 +1897,8 @@ async function setPackageJsonDeps(path7, deps) {
1840
1897
  }
1841
1898
 
1842
1899
  // src/commands/login.ts
1843
- import { intro as intro2, log as log2, outro as outro2, select } from "@clack/prompts";
1844
- import { recordSpanException as recordSpanException3 } from "@trigger.dev/core/v3";
1900
+ import { intro as intro2, log as log3, outro as outro3, select } from "@clack/prompts";
1901
+ import { recordSpanException as recordSpanException3 } from "@trigger.dev/core/v3/workers";
1845
1902
 
1846
1903
  // ../../node_modules/.pnpm/open@10.0.3/node_modules/open/index.js
1847
1904
  import process6 from "node:process";
@@ -2211,14 +2268,14 @@ var baseOpen = async (options) => {
2211
2268
  }
2212
2269
  const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
2213
2270
  if (options.wait) {
2214
- return new Promise((resolve4, reject) => {
2271
+ return new Promise((resolve5, reject) => {
2215
2272
  subprocess.once("error", reject);
2216
2273
  subprocess.once("close", (exitCode) => {
2217
2274
  if (!options.allowNonzeroExitCode && exitCode > 0) {
2218
2275
  reject(new Error(`Exited with code ${exitCode}`));
2219
2276
  return;
2220
2277
  }
2221
- resolve4(subprocess);
2278
+ resolve5(subprocess);
2222
2279
  });
2223
2280
  });
2224
2281
  }
@@ -2335,7 +2392,7 @@ var decorateErrorWithCounts = (error, attemptNumber, options) => {
2335
2392
  return error;
2336
2393
  };
2337
2394
  async function pRetry(input, options) {
2338
- return new Promise((resolve4, reject) => {
2395
+ return new Promise((resolve5, reject) => {
2339
2396
  options = {
2340
2397
  onFailedAttempt() {
2341
2398
  },
@@ -2358,7 +2415,7 @@ async function pRetry(input, options) {
2358
2415
  try {
2359
2416
  const result = await input(attemptNumber);
2360
2417
  cleanUp();
2361
- resolve4(result);
2418
+ resolve5(result);
2362
2419
  } catch (error) {
2363
2420
  try {
2364
2421
  if (!(error instanceof Error)) {
@@ -2388,10 +2445,10 @@ async function pRetry(input, options) {
2388
2445
  import { z as z3 } from "zod";
2389
2446
 
2390
2447
  // src/commands/whoami.ts
2391
- import { intro, note } from "@clack/prompts";
2448
+ import { intro, note, outro as outro2 } from "@clack/prompts";
2392
2449
 
2393
2450
  // src/utilities/session.ts
2394
- import { recordSpanException as recordSpanException2 } from "@trigger.dev/core/v3";
2451
+ import { recordSpanException as recordSpanException2 } from "@trigger.dev/core/v3/workers";
2395
2452
  var tracer2 = getTracer();
2396
2453
  async function isLoggedIn(profile = "default") {
2397
2454
  return await tracer2.startActiveSpan("isLoggedIn", async (span) => {
@@ -2473,9 +2530,16 @@ async function whoAmI(options, embedded = false) {
2473
2530
  if (authentication.error === "fetch failed") {
2474
2531
  loadingSpinner.stop("Fetch failed. Platform down?");
2475
2532
  } else {
2476
- loadingSpinner.stop(
2477
- `You must login first. Use \`trigger.dev login --profile ${options?.profile ?? "default"}\` to login.`
2478
- );
2533
+ if (embedded) {
2534
+ loadingSpinner.stop(
2535
+ `Failed to check account details. You may want to run \`trigger.dev logout --profile ${options?.profile ?? "default"}\` and try again.`
2536
+ );
2537
+ } else {
2538
+ loadingSpinner.stop(
2539
+ `You must login first. Use \`trigger.dev login --profile ${options?.profile ?? "default"}\` to login.`
2540
+ );
2541
+ outro2("Whoami failed");
2542
+ }
2479
2543
  }
2480
2544
  return {
2481
2545
  success: false,
@@ -2571,10 +2635,18 @@ async function login(options) {
2571
2635
  skipTelemetry: !span.isRecording(),
2572
2636
  logLevel: logger.loggerLevel
2573
2637
  },
2574
- opts.embedded
2638
+ true
2575
2639
  );
2576
2640
  if (!whoAmIResult.success) {
2577
- throw new Error(whoAmIResult.error);
2641
+ prettyError("Unable to validate existing personal access token", whoAmIResult.error);
2642
+ if (!opts.embedded) {
2643
+ outro3(
2644
+ `Login failed using stored token. To fix, first logout using \`trigger.dev logout${options?.profile ? ` --profile ${options.profile}` : ""}\` and then try again.`
2645
+ );
2646
+ throw new SkipLoggingError(whoAmIResult.error);
2647
+ } else {
2648
+ throw new Error(whoAmIResult.error);
2649
+ }
2578
2650
  } else {
2579
2651
  if (!opts.embedded) {
2580
2652
  const continueOption = await select({
@@ -2592,7 +2664,7 @@ async function login(options) {
2592
2664
  initialValue: false
2593
2665
  });
2594
2666
  if (continueOption !== true) {
2595
- outro2("Already logged in");
2667
+ outro3("Already logged in");
2596
2668
  span.setAttributes({
2597
2669
  "cli.userId": whoAmIResult.data.userId,
2598
2670
  "cli.email": whoAmIResult.data.email,
@@ -2633,11 +2705,11 @@ async function login(options) {
2633
2705
  }
2634
2706
  }
2635
2707
  if (opts.embedded) {
2636
- log2.step("You must login to continue.");
2708
+ log3.step("You must login to continue.");
2637
2709
  }
2638
2710
  const apiClient2 = new CliApiClient(authConfig?.apiUrl ?? opts.defaultApiUrl);
2639
2711
  const authorizationCodeResult = await createAuthorizationCode(apiClient2);
2640
- log2.step(
2712
+ log3.step(
2641
2713
  `Please visit the following URL to login:
2642
2714
  ${chalkLink(authorizationCodeResult.url)}`
2643
2715
  );
@@ -2671,9 +2743,9 @@ ${chalkLink(authorizationCodeResult.url)}`
2671
2743
  throw new Error(whoAmIResult.error);
2672
2744
  }
2673
2745
  if (opts.embedded) {
2674
- log2.step("Logged in successfully");
2746
+ log3.step("Logged in successfully");
2675
2747
  } else {
2676
- outro2("Logged in successfully");
2748
+ outro3("Logged in successfully");
2677
2749
  }
2678
2750
  span.end();
2679
2751
  return {
@@ -2690,7 +2762,7 @@ ${chalkLink(authorizationCodeResult.url)}`
2690
2762
  } catch (e) {
2691
2763
  getPersonalAccessTokenSpinner.stop(`Failed to get access token`);
2692
2764
  if (e instanceof AbortError) {
2693
- log2.error(e.message);
2765
+ log3.error(e.message);
2694
2766
  }
2695
2767
  recordSpanException3(span, e);
2696
2768
  span.end();
@@ -2775,7 +2847,7 @@ function bundleTriggerDevCore(buildIdentifier, tsconfigPath) {
2775
2847
  name: "trigger-bundle-core",
2776
2848
  setup(build3) {
2777
2849
  build3.onResolve({ filter: /.*/ }, (args) => {
2778
- if (args.path !== "@trigger.dev/core/v3") {
2850
+ if (!args.path.startsWith("@trigger.dev/core/v3")) {
2779
2851
  return void 0;
2780
2852
  }
2781
2853
  const triggerSdkPath = __require.resolve("@trigger.dev/sdk/v3", { paths: [process.cwd()] });
@@ -2783,17 +2855,14 @@ function bundleTriggerDevCore(buildIdentifier, tsconfigPath) {
2783
2855
  ...args,
2784
2856
  triggerSdkPath
2785
2857
  });
2786
- const resolvedPath = __require.resolve("@trigger.dev/core/v3", {
2858
+ const resolvedPath = __require.resolve(args.path, {
2787
2859
  paths: [triggerSdkPath]
2788
2860
  });
2789
- logger.debug(
2790
- `[${buildIdentifier}][trigger-bundle-core] Externalizing @trigger.dev/core/v3`,
2791
- {
2792
- ...args,
2793
- triggerSdkPath,
2794
- resolvedPath
2795
- }
2796
- );
2861
+ logger.debug(`[${buildIdentifier}][trigger-bundle-core] Externalizing ${args.path}`, {
2862
+ ...args,
2863
+ triggerSdkPath,
2864
+ resolvedPath
2865
+ });
2797
2866
  return {
2798
2867
  path: resolvedPath,
2799
2868
  external: false
@@ -3117,7 +3186,13 @@ import { join as join4 } from "node:path";
3117
3186
 
3118
3187
  // src/utilities/getUserPackageManager.ts
3119
3188
  import { findUp as findUp2 } from "find-up";
3189
+ import { basename } from "path";
3120
3190
  async function getUserPackageManager(path7) {
3191
+ const packageManager = await detectPackageManager(path7);
3192
+ logger.debug("Detected package manager", { packageManager });
3193
+ return packageManager;
3194
+ }
3195
+ async function detectPackageManager(path7) {
3121
3196
  try {
3122
3197
  return await detectPackageManagerFromArtifacts(path7);
3123
3198
  } catch (error) {
@@ -3139,19 +3214,33 @@ function detectPackageManagerFromCurrentCommand() {
3139
3214
  }
3140
3215
  }
3141
3216
  async function detectPackageManagerFromArtifacts(path7) {
3142
- const packageFiles = [
3143
- { name: "yarn.lock", pm: "yarn" },
3144
- { name: "pnpm-lock.yaml", pm: "pnpm" },
3145
- { name: "package-lock.json", pm: "npm" },
3146
- { name: "npm-shrinkwrap.json", pm: "npm" }
3147
- ];
3148
- for (const { name, pm } of packageFiles) {
3149
- const foundPath = await findUp2(name, { cwd: path7 });
3150
- if (typeof foundPath === "string") {
3151
- return pm;
3152
- }
3217
+ const artifacts = {
3218
+ yarn: "yarn.lock",
3219
+ pnpm: "pnpm-lock.yaml",
3220
+ npm: "package-lock.json",
3221
+ npmShrinkwrap: "npm-shrinkwrap.json"
3222
+ };
3223
+ const foundPath = await findUp2(Object.values(artifacts), { cwd: path7 });
3224
+ if (!foundPath) {
3225
+ throw new Error("Could not detect package manager from artifacts");
3226
+ }
3227
+ logger.debug("Found path from package manager artifacts", { foundPath });
3228
+ switch (basename(foundPath)) {
3229
+ case artifacts.yarn:
3230
+ return "yarn";
3231
+ case artifacts.pnpm:
3232
+ return "pnpm";
3233
+ case artifacts.npm:
3234
+ case artifacts.npmShrinkwrap:
3235
+ return "npm";
3236
+ default:
3237
+ throw new Error(`Unhandled package manager detection path: ${foundPath}`);
3153
3238
  }
3154
- throw new Error("Could not detect package manager from artifacts");
3239
+ }
3240
+
3241
+ // src/utilities/assertExhaustive.ts
3242
+ function assertExhaustive(x) {
3243
+ throw new Error("Unexpected object: " + x);
3155
3244
  }
3156
3245
 
3157
3246
  // src/utilities/javascriptProject.ts
@@ -3210,17 +3299,25 @@ var JavascriptProject = class {
3210
3299
  }
3211
3300
  get scripts() {
3212
3301
  return {
3213
- postinstall: this.packageJson.scripts?.postinstall
3302
+ postinstall: this.packageJson.scripts?.postinstall ?? ""
3214
3303
  };
3215
3304
  }
3305
+ async install() {
3306
+ const command = await this.#getCommand();
3307
+ try {
3308
+ await command.installDependencies({
3309
+ cwd: this.projectPath
3310
+ });
3311
+ } catch (error) {
3312
+ logger.debug(`Failed to install dependencies using ${command.name}`, {
3313
+ error
3314
+ });
3315
+ }
3316
+ }
3216
3317
  async resolve(packageName, options) {
3217
3318
  if (BuiltInModules.has(packageName)) {
3218
3319
  return void 0;
3219
3320
  }
3220
- if (!this._packageManager) {
3221
- this._packageManager = await getUserPackageManager(this.projectPath);
3222
- }
3223
- const packageManager = this._packageManager;
3224
3321
  const opts = { allowDev: false, ...options };
3225
3322
  const packageJsonVersion = this.packageJson.dependencies?.[packageName];
3226
3323
  if (typeof packageJsonVersion === "string") {
@@ -3232,7 +3329,7 @@ var JavascriptProject = class {
3232
3329
  return devPackageJsonVersion;
3233
3330
  }
3234
3331
  }
3235
- const command = packageManager === "npm" ? new NPMCommands() : packageManager === "pnpm" ? new PNPMCommands() : new YarnCommands();
3332
+ const command = await this.#getCommand();
3236
3333
  try {
3237
3334
  const version2 = await command.resolveDependencyVersion(packageName, {
3238
3335
  cwd: this.projectPath
@@ -3247,16 +3344,41 @@ var JavascriptProject = class {
3247
3344
  });
3248
3345
  }
3249
3346
  }
3347
+ async #getCommand() {
3348
+ const packageManager = await this.getPackageManager();
3349
+ switch (packageManager) {
3350
+ case "npm":
3351
+ return new NPMCommands();
3352
+ case "pnpm":
3353
+ return new PNPMCommands();
3354
+ case "yarn":
3355
+ return new YarnCommands();
3356
+ default:
3357
+ assertExhaustive(packageManager);
3358
+ }
3359
+ }
3360
+ async getPackageManager() {
3361
+ if (!this._packageManager) {
3362
+ this._packageManager = await getUserPackageManager(this.projectPath);
3363
+ }
3364
+ return this._packageManager;
3365
+ }
3250
3366
  };
3251
3367
  var PNPMCommands = class {
3252
3368
  get name() {
3253
3369
  return "pnpm";
3254
3370
  }
3371
+ get cmd() {
3372
+ return process.platform === "win32" ? "pnpm.cmd" : "pnpm";
3373
+ }
3374
+ async installDependencies(options) {
3375
+ const { stdout, stderr } = await $({ cwd: options.cwd })`${this.cmd} install`;
3376
+ logger.debug(`Installing dependencies using ${this.name}`, { stdout, stderr });
3377
+ }
3255
3378
  async resolveDependencyVersion(packageName, options) {
3256
- const cmd = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
3257
- const { stdout } = await $({ cwd: options.cwd })`${cmd} list ${packageName} -r --json`;
3379
+ const { stdout } = await $({ cwd: options.cwd })`${this.cmd} list ${packageName} -r --json`;
3258
3380
  const result = JSON.parse(stdout);
3259
- logger.debug(`Resolving ${packageName} version using pnpm`, { result });
3381
+ logger.debug(`Resolving ${packageName} version using ${this.name}`, { result });
3260
3382
  for (const dep of result) {
3261
3383
  const dependency = dep.dependencies?.[packageName];
3262
3384
  if (dependency) {
@@ -3269,11 +3391,17 @@ var NPMCommands = class {
3269
3391
  get name() {
3270
3392
  return "npm";
3271
3393
  }
3394
+ get cmd() {
3395
+ return process.platform === "win32" ? "npm.cmd" : "npm";
3396
+ }
3397
+ async installDependencies(options) {
3398
+ const { stdout, stderr } = await $({ cwd: options.cwd })`${this.cmd} install`;
3399
+ logger.debug(`Installing dependencies using ${this.name}`, { stdout, stderr });
3400
+ }
3272
3401
  async resolveDependencyVersion(packageName, options) {
3273
- const cmd = process.platform === "win32" ? "npm.cmd" : "npm";
3274
- const { stdout } = await $({ cwd: options.cwd })`${cmd} list ${packageName} --json`;
3402
+ const { stdout } = await $({ cwd: options.cwd })`${this.cmd} list ${packageName} --json`;
3275
3403
  const output = JSON.parse(stdout);
3276
- logger.debug(`Resolving ${packageName} version using npm`, { output });
3404
+ logger.debug(`Resolving ${packageName} version using ${this.name}`, { output });
3277
3405
  return this.#recursivelySearchDependencies(output.dependencies, packageName);
3278
3406
  }
3279
3407
  #recursivelySearchDependencies(dependencies2, packageName) {
@@ -3294,11 +3422,17 @@ var YarnCommands = class {
3294
3422
  get name() {
3295
3423
  return "yarn";
3296
3424
  }
3425
+ get cmd() {
3426
+ return process.platform === "win32" ? "yarn.cmd" : "yarn";
3427
+ }
3428
+ async installDependencies(options) {
3429
+ const { stdout, stderr } = await $({ cwd: options.cwd })`${this.cmd} install`;
3430
+ logger.debug(`Installing dependencies using ${this.name}`, { stdout, stderr });
3431
+ }
3297
3432
  async resolveDependencyVersion(packageName, options) {
3298
- const cmd = process.platform === "win32" ? "yarn.cmd" : "yarn";
3299
- const { stdout } = await $({ cwd: options.cwd })`${cmd} info ${packageName} --json`;
3433
+ const { stdout } = await $({ cwd: options.cwd })`${this.cmd} info ${packageName} --json`;
3300
3434
  const lines = stdout.split("\n");
3301
- logger.debug(`Resolving ${packageName} version using yarn`, { lines });
3435
+ logger.debug(`Resolving ${packageName} version using ${this.name}`, { lines });
3302
3436
  for (const line of lines) {
3303
3437
  const json = JSON.parse(line);
3304
3438
  if (json.value === packageName) {
@@ -3317,11 +3451,208 @@ function cliRootPath() {
3317
3451
  return __dirname2;
3318
3452
  }
3319
3453
 
3454
+ // src/commands/update.ts
3455
+ import { confirm, intro as intro3, isCancel, log as log4, outro as outro4 } from "@clack/prompts";
3456
+ import { join as join5, resolve as resolve2 } from "path";
3457
+ var UpdateCommandOptions = CommonCommandOptions.pick({
3458
+ logLevel: true,
3459
+ skipTelemetry: true
3460
+ });
3461
+ function configureUpdateCommand(program2) {
3462
+ return program2.command("update").description("Updates all @trigger.dev/* packages to match the CLI version").argument("[path]", "The path to the directory that contains the package.json file", ".").option(
3463
+ "-l, --log-level <level>",
3464
+ "The CLI log level to use (debug, info, log, warn, error, none). This does not effect the log level of your trigger.dev tasks.",
3465
+ "log"
3466
+ ).option("--skip-telemetry", "Opt-out of sending telemetry").action(async (path7, options) => {
3467
+ wrapCommandAction("dev", UpdateCommandOptions, options, async (opts) => {
3468
+ await printStandloneInitialBanner(true);
3469
+ await updateCommand(path7, opts);
3470
+ });
3471
+ });
3472
+ }
3473
+ var triggerPackageFilter = /^@trigger\.dev/;
3474
+ async function updateCommand(dir, options) {
3475
+ await updateTriggerPackages(dir, options);
3476
+ }
3477
+ async function updateTriggerPackages(dir, options, embedded, requireUpdate) {
3478
+ if (!embedded) {
3479
+ intro3("Updating packages");
3480
+ }
3481
+ const projectPath = resolve2(process.cwd(), dir);
3482
+ const { packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath);
3483
+ if (!packageJson) {
3484
+ log4.error("Failed to load package.json. Try to re-run with `-l debug` to see what's going on.");
3485
+ return;
3486
+ }
3487
+ const cliVersion = getVersion();
3488
+ const newCliVersion = await updateCheck();
3489
+ if (newCliVersion) {
3490
+ prettyWarning(
3491
+ "You're not running the latest CLI version, please consider updating ASAP",
3492
+ `Current: ${cliVersion}
3493
+ Latest: ${newCliVersion}`,
3494
+ "Run latest: npx trigger.dev@beta"
3495
+ );
3496
+ }
3497
+ const triggerDependencies = getTriggerDependencies(packageJson);
3498
+ function getVersionMismatches(deps, targetVersion) {
3499
+ const mismatches = [];
3500
+ for (const dep of deps) {
3501
+ if (dep.version === targetVersion) {
3502
+ continue;
3503
+ }
3504
+ mismatches.push(dep);
3505
+ }
3506
+ return mismatches;
3507
+ }
3508
+ const versionMismatches = getVersionMismatches(triggerDependencies, cliVersion);
3509
+ if (versionMismatches.length === 0) {
3510
+ if (!embedded) {
3511
+ outro4(`Nothing to do${newCliVersion ? " ..but you should really update your CLI!" : ""}`);
3512
+ }
3513
+ return;
3514
+ }
3515
+ prettyWarning(
3516
+ "Mismatch between your CLI version and installed packages",
3517
+ "We recommend pinned versions for guaranteed compatibility"
3518
+ );
3519
+ if (!process.stdout.isTTY) {
3520
+ outro4("Deploy failed");
3521
+ console.log(
3522
+ `ERROR: Version mismatch detected while running in CI. This won't end well. Aborting.
3523
+
3524
+ Please run the dev command locally and check that your CLI version matches the one printed below. Additionally, all \`@trigger.dev/*\` packages also need to match this version.
3525
+
3526
+ If your local CLI version doesn't match the one below, you may want to pin the CLI version in this CI step. To do that, just replace \`trigger.dev@beta\` with \`trigger.dev@<FULL_VERSION>\`, for example: \`npx trigger.dev@3.0.0-beta.17 deploy\`
3527
+
3528
+ CLI version: ${cliVersion}
3529
+
3530
+ Current package versions that don't match the CLI:
3531
+ ${versionMismatches.map((dep) => `- ${dep.name}@${dep.version}`).join("\n")}
3532
+ `
3533
+ );
3534
+ process.exit(1);
3535
+ }
3536
+ log4.message("");
3537
+ const userWantsToUpdate = await updateConfirmation(versionMismatches, cliVersion);
3538
+ if (isCancel(userWantsToUpdate)) {
3539
+ throw new OutroCommandError();
3540
+ }
3541
+ if (!userWantsToUpdate) {
3542
+ if (requireUpdate) {
3543
+ outro4("You shall not pass!");
3544
+ logger.log(
3545
+ `${chalkError(
3546
+ "X Error:"
3547
+ )} Update required: Version mismatches are a common source of bugs and errors. Please update or use \`--skip-update-check\` at your own risk.
3548
+ `
3549
+ );
3550
+ process.exit(1);
3551
+ }
3552
+ if (!embedded) {
3553
+ outro4("You've been warned!");
3554
+ }
3555
+ return;
3556
+ }
3557
+ const installSpinner = spinner();
3558
+ installSpinner.start("Writing new package.json file");
3559
+ const packageJsonBackupPath = `${packageJsonPath}.bak`;
3560
+ await writeJSONFile(packageJsonBackupPath, readonlyPackageJson, true);
3561
+ const exitHandler = async (sig) => {
3562
+ log4.warn(
3563
+ `You may have to manually roll back any package.json changes. Backup written to ${packageJsonBackupPath}`
3564
+ );
3565
+ };
3566
+ process.prependOnceListener("exit", exitHandler);
3567
+ mutatePackageJsonWithUpdatedPackages(packageJson, versionMismatches, cliVersion);
3568
+ await writeJSONFile(packageJsonPath, packageJson, true);
3569
+ async function revertPackageJsonChanges() {
3570
+ await writeJSONFile(packageJsonPath, readonlyPackageJson, true);
3571
+ await removeFile(packageJsonBackupPath);
3572
+ }
3573
+ installSpinner.message("Installing new package versions");
3574
+ const jsProject = new JavascriptProject(projectPath);
3575
+ let packageManager;
3576
+ try {
3577
+ packageManager = await jsProject.getPackageManager();
3578
+ installSpinner.message(`Installing new package versions with ${packageManager}`);
3579
+ await jsProject.install();
3580
+ } catch (error) {
3581
+ installSpinner.stop(
3582
+ `Failed to install new package versions${packageManager ? ` with ${packageManager}` : ""}`
3583
+ );
3584
+ process.removeListener("exit", exitHandler);
3585
+ await revertPackageJsonChanges();
3586
+ throw error;
3587
+ }
3588
+ installSpinner.stop("Installed new package versions");
3589
+ process.removeListener("exit", exitHandler);
3590
+ await removeFile(packageJsonBackupPath);
3591
+ if (!embedded) {
3592
+ outro4(
3593
+ `Packages updated${newCliVersion ? " ..but you should really update your CLI too!" : ""}`
3594
+ );
3595
+ }
3596
+ }
3597
+ function getTriggerDependencies(packageJson) {
3598
+ const deps = [];
3599
+ for (const type of ["dependencies", "devDependencies"]) {
3600
+ for (const [name, version2] of Object.entries(packageJson[type] ?? {})) {
3601
+ if (!version2) {
3602
+ continue;
3603
+ }
3604
+ if (version2.startsWith("workspace")) {
3605
+ continue;
3606
+ }
3607
+ if (!triggerPackageFilter.test(name)) {
3608
+ continue;
3609
+ }
3610
+ const ignoredPackages = ["@trigger.dev/companyicons"];
3611
+ if (ignoredPackages.includes(name)) {
3612
+ continue;
3613
+ }
3614
+ deps.push({ type, name, version: version2 });
3615
+ }
3616
+ }
3617
+ return deps;
3618
+ }
3619
+ function mutatePackageJsonWithUpdatedPackages(packageJson, depsToUpdate, targetVersion) {
3620
+ for (const { type, name, version: version2 } of depsToUpdate) {
3621
+ if (!packageJson[type]) {
3622
+ throw new Error(
3623
+ `No ${type} entry found in package.json. Please try to upgrade manually instead.`
3624
+ );
3625
+ }
3626
+ packageJson[type][name] = targetVersion;
3627
+ }
3628
+ }
3629
+ function printUpdateTable(depsToUpdate, targetVersion) {
3630
+ log4.message("Suggested updates");
3631
+ const tableData = depsToUpdate.map((dep) => ({
3632
+ package: dep.name,
3633
+ old: dep.version,
3634
+ new: targetVersion
3635
+ }));
3636
+ logger.table(tableData);
3637
+ }
3638
+ async function updateConfirmation(depsToUpdate, targetVersion) {
3639
+ printUpdateTable(depsToUpdate, targetVersion);
3640
+ let confirmMessage = "Would you like to apply those updates?";
3641
+ return await confirm({
3642
+ message: confirmMessage
3643
+ });
3644
+ }
3645
+ async function getPackageJson(absoluteProjectPath) {
3646
+ const packageJsonPath = join5(absoluteProjectPath, "package.json");
3647
+ const readonlyPackageJson = Object.freeze(await readJSONFile(packageJsonPath));
3648
+ const packageJson = structuredClone(readonlyPackageJson);
3649
+ return { packageJson, readonlyPackageJson, packageJsonPath };
3650
+ }
3651
+
3320
3652
  // src/commands/deploy.ts
3321
3653
  var DeployCommandOptions = CommonCommandOptions.extend({
3322
3654
  skipTypecheck: z4.boolean().default(false),
3323
3655
  skipDeploy: z4.boolean().default(false),
3324
- ignoreEnvVarCheck: z4.boolean().default(false),
3325
3656
  env: z4.enum(["prod", "staging"]),
3326
3657
  loadImage: z4.boolean().default(false),
3327
3658
  buildPlatform: z4.enum(["linux/amd64", "linux/arm64"]).default("linux/amd64"),
@@ -3332,7 +3663,8 @@ var DeployCommandOptions = CommonCommandOptions.extend({
3332
3663
  projectRef: z4.string().optional(),
3333
3664
  outputMetafile: z4.string().optional(),
3334
3665
  apiUrl: z4.string().optional(),
3335
- saveLogs: z4.boolean().default(false)
3666
+ saveLogs: z4.boolean().default(false),
3667
+ skipUpdateCheck: z4.boolean().default(false)
3336
3668
  });
3337
3669
  function configureDeployCommand(program2) {
3338
3670
  return commonOptions(
@@ -3340,10 +3672,7 @@ function configureDeployCommand(program2) {
3340
3672
  "-e, --env <env>",
3341
3673
  "Deploy to a specific environment (currently only prod and staging are supported)",
3342
3674
  "prod"
3343
- ).option("--skip-typecheck", "Whether to skip the pre-build typecheck").option(
3344
- "--ignore-env-var-check",
3345
- "Detected missing environment variables won't block deployment"
3346
- ).option("-c, --config <config file>", "The name of the config file, found at [path]").option(
3675
+ ).option("--skip-typecheck", "Whether to skip the pre-build typecheck").option("--skip-update-check", "Skip checking for @trigger.dev package updates").option("-c, --config <config file>", "The name of the config file, found at [path]").option(
3347
3676
  "-p, --project-ref <project ref>",
3348
3677
  "The project ref. Required if there is no config file. This will override the project specified in the config file."
3349
3678
  )
@@ -3367,6 +3696,11 @@ function configureDeployCommand(program2) {
3367
3696
  "--tag <tag>",
3368
3697
  "(Coming soon) Specify the tag to use when pushing the image to the registry"
3369
3698
  ).hideHelp()
3699
+ ).addOption(
3700
+ new CommandOption(
3701
+ "--ignore-env-var-check",
3702
+ "(deprecated) Detected missing environment variables won't block deployment"
3703
+ ).hideHelp()
3370
3704
  ).addOption(new CommandOption("-D, --skip-deploy", "Skip deploying the image").hideHelp()).addOption(
3371
3705
  new CommandOption("--load-image", "Load the built image into your local docker").hideHelp()
3372
3706
  ).addOption(
@@ -3398,7 +3732,10 @@ async function deployCommand(dir, options) {
3398
3732
  }
3399
3733
  async function _deployCommand(dir, options) {
3400
3734
  const span = trace2.getSpan(context.active());
3401
- intro3("Deploying project");
3735
+ intro4("Deploying project");
3736
+ if (!options.skipUpdateCheck) {
3737
+ await updateTriggerPackages(dir, { ...options }, true, true);
3738
+ }
3402
3739
  const authorization = await login({
3403
3740
  embedded: true,
3404
3741
  defaultApiUrl: options.apiUrl,
@@ -3441,7 +3778,7 @@ async function _deployCommand(dir, options) {
3441
3778
  throw new Error(deploymentEnv.error);
3442
3779
  }
3443
3780
  const environmentClient = new CliApiClient(authorization.auth.apiUrl, deploymentEnv.data.apiKey);
3444
- log3.step(
3781
+ log5.step(
3445
3782
  `Preparing to deploy "${deploymentEnv.data.name}" (${resolvedConfig.config.project}) to ${options.env}`
3446
3783
  );
3447
3784
  const compilation = await compileProject(
@@ -3450,15 +3787,6 @@ async function _deployCommand(dir, options) {
3450
3787
  resolvedConfig.status === "file" ? resolvedConfig.path : void 0
3451
3788
  );
3452
3789
  logger.debug("Compilation result", { compilation });
3453
- if (compilation.envVars.length > 0) {
3454
- await checkEnvVars(
3455
- compilation.envVars ?? [],
3456
- resolvedConfig.config,
3457
- options,
3458
- environmentClient,
3459
- authorization.dashboardUrl
3460
- );
3461
- }
3462
3790
  const deploymentResponse = await environmentClient.initializeDeployment({
3463
3791
  contentHash: compilation.contentHash,
3464
3792
  userId: authorization.userId
@@ -3544,7 +3872,7 @@ async function _deployCommand(dir, options) {
3544
3872
  printWarnings(warnings.warnings);
3545
3873
  if (options.saveLogs) {
3546
3874
  const logPath = await saveLogs(deploymentResponse.data.shortCode, image.logs);
3547
- log3.info(`Build logs have been saved to ${logPath}`);
3875
+ log5.info(`Build logs have been saved to ${logPath}`);
3548
3876
  }
3549
3877
  };
3550
3878
  const imageReference = options.selfHosted ? `${selfHostedRegistryHost ? `${selfHostedRegistryHost}/` : ""}${image.image}${image.digest ? `@${image.digest}` : ""}` : `${registryHost}/${image.image}${image.digest ? `@${image.digest}` : ""}`;
@@ -3601,11 +3929,11 @@ async function _deployCommand(dir, options) {
3601
3929
  await preExitTasks();
3602
3930
  const taskCount = finishedDeployment.worker?.tasks.length ?? 0;
3603
3931
  if (taskCount === 0) {
3604
- outro3(
3932
+ outro5(
3605
3933
  `Version ${version2} deployed with no detected tasks. Please make sure you are exporting tasks in your project. ${deploymentLink}`
3606
3934
  );
3607
3935
  } else {
3608
- outro3(
3936
+ outro5(
3609
3937
  `Version ${version2} deployed with ${taskCount} detected task${taskCount === 1 ? "" : "s"} ${deploymentLink}`
3610
3938
  );
3611
3939
  }
@@ -3661,12 +3989,12 @@ async function _deployCommand(dir, options) {
3661
3989
  }
3662
3990
  function printErrors(errors) {
3663
3991
  for (const error of errors ?? []) {
3664
- log3.error(`${chalkError("Error:")} ${error}`);
3992
+ log5.error(`${chalkError("Error:")} ${error}`);
3665
3993
  }
3666
3994
  }
3667
3995
  function printWarnings(warnings) {
3668
3996
  for (const warning of warnings ?? []) {
3669
- log3.warn(`${chalkWarning("Warning:")} ${warning}`);
3997
+ log5.warn(`${chalkWarning("Warning:")} ${warning}`);
3670
3998
  }
3671
3999
  }
3672
4000
  function checkLogsForWarnings(logs) {
@@ -3740,7 +4068,7 @@ If it's a binary: Please ${terminalLink2(
3740
4068
  continue;
3741
4069
  }
3742
4070
  const message = getMessageFromTemplate(error.message, matches.groups);
3743
- log3.error(`${chalkError("Error:")} ${message}`);
4071
+ log5.error(`${chalkError("Error:")} ${message}`);
3744
4072
  break;
3745
4073
  }
3746
4074
  }
@@ -3754,7 +4082,7 @@ function getMessageFromTemplate(template, replacer) {
3754
4082
  return message;
3755
4083
  }
3756
4084
  async function saveLogs(shortCode, logs) {
3757
- const logPath = join5(await createTempDir(), `build-${shortCode}.log`);
4085
+ const logPath = join6(await createTempDir(), `build-${shortCode}.log`);
3758
4086
  await writeFile2(logPath, logs);
3759
4087
  return logPath;
3760
4088
  }
@@ -3765,55 +4093,11 @@ async function failDeploy(shortCode, errorSummary, logs, deploymentSpinner, warn
3765
4093
  printWarnings(warnings);
3766
4094
  printErrors(errors);
3767
4095
  checkLogsForErrors(logs);
3768
- outro3(`${chalkError("Error:")} ${errorSummary}. Full build logs have been saved to ${logPath}`);
4096
+ outro5(`${chalkError("Error:")} ${errorSummary}. Full build logs have been saved to ${logPath}`);
3769
4097
  } else {
3770
- outro3(`${chalkError("Error:")} ${errorSummary}.`);
4098
+ outro5(`${chalkError("Error:")} ${errorSummary}.`);
3771
4099
  }
3772
4100
  }
3773
- async function checkEnvVars(envVars, config, options, environmentClient, apiUrl) {
3774
- return await tracer.startActiveSpan("detectEnvVars", async (span) => {
3775
- try {
3776
- span.setAttribute("envVars.check", envVars);
3777
- const environmentVariablesSpinner = spinner();
3778
- environmentVariablesSpinner.start("Checking environment variables");
3779
- const environmentVariables = await environmentClient.getEnvironmentVariables(config.project);
3780
- if (!environmentVariables.success) {
3781
- environmentVariablesSpinner.stop(`Failed to fetch environment variables, skipping check`);
3782
- } else {
3783
- const missingEnvironmentVariables = envVars.filter(
3784
- (envVar) => environmentVariables.data.variables[envVar] === void 0
3785
- );
3786
- if (missingEnvironmentVariables.length > 0) {
3787
- environmentVariablesSpinner.stop(
3788
- `Found missing env vars in ${options.env}: ${arrayToSentence(
3789
- missingEnvironmentVariables
3790
- )}. ${options.ignoreEnvVarCheck ? "Continuing deployment because of --ignore-env-var-check. " : "Aborting deployment. "}${chalk5.bgBlueBright(
3791
- terminalLink2(
3792
- "Manage env vars",
3793
- `${apiUrl}/projects/v3/${config.project}/environment-variables`
3794
- )
3795
- )}`
3796
- );
3797
- span.setAttributes({
3798
- "envVars.missing": missingEnvironmentVariables
3799
- });
3800
- if (!options.ignoreEnvVarCheck) {
3801
- throw new SkipLoggingError("Found missing environment variables");
3802
- } else {
3803
- span.end();
3804
- return;
3805
- }
3806
- }
3807
- environmentVariablesSpinner.stop(`Environment variable check passed`);
3808
- }
3809
- span.end();
3810
- } catch (e) {
3811
- recordSpanException4(span, e);
3812
- span.end();
3813
- throw e;
3814
- }
3815
- });
3816
- }
3817
4101
  async function waitForDeploymentToFinish(deploymentId, client, timeoutInSeconds = 60) {
3818
4102
  return tracer.startActiveSpan("waitForDeploymentToFinish", async (span) => {
3819
4103
  try {
@@ -4088,10 +4372,10 @@ async function compileProject(config, options, configPath) {
4088
4372
  compileSpinner.start(`Building project in ${config.projectDir}`);
4089
4373
  const taskFiles = await gatherTaskFiles(config);
4090
4374
  const workerFacade = readFileSync2(
4091
- join5(cliRootPath(), "workers", "prod", "worker-facade.js"),
4375
+ join6(cliRootPath(), "workers", "prod", "worker-facade.js"),
4092
4376
  "utf-8"
4093
4377
  );
4094
- const workerSetupPath = join5(cliRootPath(), "workers", "prod", "worker-setup.js");
4378
+ const workerSetupPath = join6(cliRootPath(), "workers", "prod", "worker-setup.js");
4095
4379
  let workerContents = workerFacade.replace("__TASKS__", createTaskFileImports(taskFiles)).replace(
4096
4380
  "__WORKER_SETUP__",
4097
4381
  `import { tracingSDK } from "${escapeImportPath(workerSetupPath)}";`
@@ -4151,10 +4435,10 @@ async function compileProject(config, options, configPath) {
4151
4435
  throw new Error("Build failed, aborting deployment");
4152
4436
  }
4153
4437
  if (options.outputMetafile) {
4154
- await writeJSONFile(join5(options.outputMetafile, "worker.json"), result.metafile);
4438
+ await writeJSONFile(join6(options.outputMetafile, "worker.json"), result.metafile);
4155
4439
  }
4156
4440
  const entryPointContents = readFileSync2(
4157
- join5(cliRootPath(), "workers", "prod", "entry-point.js"),
4441
+ join6(cliRootPath(), "workers", "prod", "entry-point.js"),
4158
4442
  "utf-8"
4159
4443
  );
4160
4444
  const entryPointResult = await build2({
@@ -4197,7 +4481,7 @@ async function compileProject(config, options, configPath) {
4197
4481
  }
4198
4482
  if (options.outputMetafile) {
4199
4483
  await writeJSONFile(
4200
- join5(options.outputMetafile, "entry-point.json"),
4484
+ join6(options.outputMetafile, "entry-point.json"),
4201
4485
  entryPointResult.metafile
4202
4486
  );
4203
4487
  }
@@ -4208,24 +4492,24 @@ async function compileProject(config, options, configPath) {
4208
4492
  const entryPointMetaOutput = entryPointResult.metafile.outputs[posix.join("out", "stdin.js")];
4209
4493
  invariant(entryPointMetaOutput, "Meta output for the entryPoint build is missing");
4210
4494
  const workerOutputFile = result.outputFiles.find(
4211
- (file) => file.path === join5(config.projectDir, "out", "stdin.js")
4495
+ (file) => file.path === join6(config.projectDir, "out", "stdin.js")
4212
4496
  );
4213
4497
  invariant(workerOutputFile, "Output file for the result build is missing");
4214
4498
  const workerSourcemapFile = result.outputFiles.find(
4215
- (file) => file.path === join5(config.projectDir, "out", "stdin.js.map")
4499
+ (file) => file.path === join6(config.projectDir, "out", "stdin.js.map")
4216
4500
  );
4217
4501
  invariant(workerSourcemapFile, "Sourcemap file for the result build is missing");
4218
4502
  const entryPointOutputFile = entryPointResult.outputFiles.find(
4219
- (file) => file.path === join5(config.projectDir, "out", "stdin.js")
4503
+ (file) => file.path === join6(config.projectDir, "out", "stdin.js")
4220
4504
  );
4221
4505
  invariant(entryPointOutputFile, "Output file for the entryPoint build is missing");
4222
4506
  await writeFile2(
4223
- join5(tempDir, "worker.js"),
4507
+ join6(tempDir, "worker.js"),
4224
4508
  `${workerOutputFile.text}
4225
4509
  //# sourceMappingURL=worker.js.map`
4226
4510
  );
4227
- await writeFile2(join5(tempDir, "worker.js.map"), workerSourcemapFile.text);
4228
- await writeFile2(join5(tempDir, "index.js"), entryPointOutputFile.text);
4511
+ await writeFile2(join6(tempDir, "worker.js.map"), workerSourcemapFile.text);
4512
+ await writeFile2(join6(tempDir, "index.js"), entryPointOutputFile.text);
4229
4513
  logger.debug("Getting the imports for the worker and entryPoint builds", {
4230
4514
  workerImports: metaOutput.imports,
4231
4515
  entryPointImports: entryPointMetaOutput.imports
@@ -4242,11 +4526,11 @@ async function compileProject(config, options, configPath) {
4242
4526
  ...javascriptProject.scripts
4243
4527
  }
4244
4528
  };
4245
- await writeJSONFile(join5(tempDir, "package.json"), packageJsonContents);
4529
+ await writeJSONFile(join6(tempDir, "package.json"), packageJsonContents);
4246
4530
  const copyResult = await copyAdditionalFiles(config, tempDir);
4247
4531
  if (!copyResult.ok) {
4248
4532
  compileSpinner.stop("Project built with warnings");
4249
- log3.warn(
4533
+ log5.warn(
4250
4534
  `No additionalFiles matches for:
4251
4535
 
4252
4536
  ${copyResult.noMatches.map((glob) => `- "${glob}"`).join("\n")}
@@ -4268,25 +4552,18 @@ If this is unexpected you should check your ${terminalLink2(
4268
4552
  if (!resolvingDependenciesResult) {
4269
4553
  throw new SkipLoggingError("Failed to resolve dependencies");
4270
4554
  }
4271
- const containerFilePath = join5(cliRootPath(), "Containerfile.prod");
4272
- await copyFile(containerFilePath, join5(tempDir, "Containerfile"));
4555
+ const containerFilePath = join6(cliRootPath(), "Containerfile.prod");
4556
+ await copyFile(containerFilePath, join6(tempDir, "Containerfile"));
4273
4557
  const contentHasher = createHash("sha256");
4274
4558
  contentHasher.update(Buffer.from(entryPointOutputFile.text));
4275
4559
  contentHasher.update(Buffer.from(workerOutputFile.text));
4276
4560
  contentHasher.update(Buffer.from(JSON.stringify(dependencies2)));
4277
4561
  const contentHash = contentHasher.digest("hex");
4278
- const workerSetupEnvVars = await findAllEnvironmentVariableReferencesInFile(workerSetupPath);
4279
- const workerFacadeEnvVars = findAllEnvironmentVariableReferences(workerContents);
4280
- const envVars = findAllEnvironmentVariableReferences(workerOutputFile.text);
4281
- const finalEnvVars = envVars.filter(
4282
- (envVar) => !workerFacadeEnvVars.includes(envVar) && !workerSetupEnvVars.includes(envVar)
4283
- );
4284
4562
  span.setAttributes({
4285
- contentHash,
4286
- envVars: finalEnvVars
4563
+ contentHash
4287
4564
  });
4288
4565
  span.end();
4289
- return { path: tempDir, contentHash, envVars: finalEnvVars };
4566
+ return { path: tempDir, contentHash };
4290
4567
  } catch (e) {
4291
4568
  recordSpanException4(span, e);
4292
4569
  span.end();
@@ -4301,8 +4578,8 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
4301
4578
  const hasher = createHash("sha256");
4302
4579
  hasher.update(JSON.stringify(packageJsonContents));
4303
4580
  const digest = hasher.digest("hex").slice(0, 16);
4304
- const cacheDir = join5(config.projectDir, ".trigger", "cache");
4305
- const cachePath = join5(cacheDir, `${digest}.json`);
4581
+ const cacheDir = join6(config.projectDir, ".trigger", "cache");
4582
+ const cachePath = join6(cacheDir, `${digest}.json`);
4306
4583
  span.setAttributes({
4307
4584
  "packageJson.digest": digest,
4308
4585
  "cache.path": cachePath,
@@ -4311,7 +4588,7 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
4311
4588
  try {
4312
4589
  const cachedPackageLock = await readFile2(cachePath, "utf-8");
4313
4590
  logger.debug(`Using cached package-lock.json for ${digest}`);
4314
- await writeFile2(join5(projectDir, "package-lock.json"), cachedPackageLock);
4591
+ await writeFile2(join6(projectDir, "package-lock.json"), cachedPackageLock);
4315
4592
  span.setAttributes({
4316
4593
  "cache.hit": true
4317
4594
  });
@@ -4334,11 +4611,11 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
4334
4611
  cwd: projectDir,
4335
4612
  stdio: logger.loggerLevel === "debug" ? "inherit" : "pipe"
4336
4613
  });
4337
- const packageLockContents = await readFile2(join5(projectDir, "package-lock.json"), "utf-8");
4614
+ const packageLockContents = await readFile2(join6(projectDir, "package-lock.json"), "utf-8");
4338
4615
  logger.debug(`Writing package-lock.json to cache for ${digest}`);
4339
4616
  await mkdir(cacheDir, { recursive: true });
4340
4617
  await writeFile2(cachePath, packageLockContents);
4341
- await writeFile2(join5(projectDir, "package-lock.json"), packageLockContents);
4618
+ await writeFile2(join6(projectDir, "package-lock.json"), packageLockContents);
4342
4619
  span.end();
4343
4620
  resolvingDepsSpinner.stop("Dependencies resolved");
4344
4621
  return true;
@@ -4390,8 +4667,8 @@ async function typecheckProject(config, options) {
4390
4667
  tscTypecheck.stdout?.on("data", (chunk) => stdouts.push(chunk.toString()));
4391
4668
  tscTypecheck.stderr?.on("data", (chunk) => stderrs.push(chunk.toString()));
4392
4669
  try {
4393
- await new Promise((resolve4, reject) => {
4394
- tscTypecheck.addListener("exit", (code) => code === 0 ? resolve4(code) : reject(code));
4670
+ await new Promise((resolve5, reject) => {
4671
+ tscTypecheck.addListener("exit", (code) => code === 0 ? resolve5(code) : reject(code));
4395
4672
  });
4396
4673
  } catch (error) {
4397
4674
  typecheckSpinner.stop(
@@ -4509,7 +4786,7 @@ async function copyAdditionalFiles(config, tempDir) {
4509
4786
  for await (const file of glob) {
4510
4787
  matches++;
4511
4788
  const pathInsideTempDir = relative3(config.projectDir, file.fullpath()).split(posix.sep).filter((p) => p !== "..").join(posix.sep);
4512
- const relativeDestinationPath = join5(tempDir, pathInsideTempDir);
4789
+ const relativeDestinationPath = join6(tempDir, pathInsideTempDir);
4513
4790
  logger.debug(`Copying file ${file.fullpath()} to ${relativeDestinationPath}`);
4514
4791
  await mkdir(dirname(relativeDestinationPath), { recursive: true });
4515
4792
  await copyFile(file.fullpath(), relativeDestinationPath);
@@ -4540,7 +4817,7 @@ async function copyAdditionalFiles(config, tempDir) {
4540
4817
  }
4541
4818
  async function ensureLoggedIntoDockerRegistry(registryHost, auth) {
4542
4819
  const tmpDir = await createTempDir();
4543
- const dockerConfigPath = join5(tmpDir, "config.json");
4820
+ const dockerConfigPath = join6(tmpDir, "config.json");
4544
4821
  await writeJSONFile(dockerConfigPath, {
4545
4822
  auths: {
4546
4823
  [registryHost]: {
@@ -4551,42 +4828,20 @@ async function ensureLoggedIntoDockerRegistry(registryHost, auth) {
4551
4828
  logger.debug(`Writing docker config to ${dockerConfigPath}`);
4552
4829
  return tmpDir;
4553
4830
  }
4554
- async function findAllEnvironmentVariableReferencesInFile(filePath) {
4555
- const fileContents = await readFile2(filePath, "utf-8");
4556
- return findAllEnvironmentVariableReferences(fileContents);
4557
- }
4558
- var IGNORED_ENV_VARS = ["NODE_ENV", "SHELL", "HOME", "PWD", "LOGNAME", "USER", "PATH", "DEBUG"];
4559
- function findAllEnvironmentVariableReferences(code) {
4560
- const regex = /\bprocess\.env\.([a-zA-Z_][a-zA-Z0-9_]*)\b/g;
4561
- const matches = code.matchAll(regex);
4562
- const matchesArray = Array.from(matches, (match) => match[1]).filter(Boolean);
4563
- const filteredMatches = matchesArray.filter((match) => !IGNORED_ENV_VARS.includes(match));
4564
- return Array.from(new Set(filteredMatches));
4565
- }
4566
- function arrayToSentence(items) {
4567
- if (items.length === 1 && typeof items[0] === "string") {
4568
- return items[0];
4569
- }
4570
- if (items.length === 2) {
4571
- return `${items[0]} and ${items[1]}`;
4572
- }
4573
- return `${items.slice(0, -1).join(", ")}, and ${items[items.length - 1]}`;
4574
- }
4575
4831
 
4576
4832
  // src/commands/dev.tsx
4577
4833
  import {
4578
- ZodMessageHandler as ZodMessageHandler2,
4579
- ZodMessageSender as ZodMessageSender2,
4580
4834
  clientWebsocketMessages,
4581
4835
  detectDependencyVersion as detectDependencyVersion2,
4582
4836
  serverWebsocketMessages
4583
4837
  } from "@trigger.dev/core/v3";
4838
+ import { ZodMessageHandler as ZodMessageHandler2, ZodMessageSender as ZodMessageSender2 } from "@trigger.dev/core/v3/zodMessageHandler";
4584
4839
  import { watch } from "chokidar";
4585
4840
  import { context as context2 } from "esbuild";
4586
4841
  import { render, useInput } from "ink";
4587
4842
  import { createHash as createHash2 } from "node:crypto";
4588
4843
  import fs7, { readFileSync as readFileSync3 } from "node:fs";
4589
- import { basename, dirname as dirname3, join as join6, normalize } from "node:path";
4844
+ import { basename as basename2, dirname as dirname3, join as join7, normalize } from "node:path";
4590
4845
  import pDebounce from "p-debounce";
4591
4846
  import { WebSocket } from "partysocket";
4592
4847
  import React, { Suspense, useEffect } from "react";
@@ -4615,17 +4870,16 @@ var TaskMetadataParseError = class extends Error {
4615
4870
  import {
4616
4871
  SemanticInternalAttributes,
4617
4872
  TaskRunErrorCodes,
4618
- ZodMessageHandler,
4619
- ZodMessageSender,
4620
4873
  childToWorkerMessages,
4621
4874
  correctErrorStackTrace,
4622
4875
  formatDurationMilliseconds,
4623
4876
  workerToChildMessages
4624
4877
  } from "@trigger.dev/core/v3";
4878
+ import { ZodMessageHandler, ZodMessageSender } from "@trigger.dev/core/v3/zodMessageHandler";
4625
4879
  import dotenv from "dotenv";
4626
4880
  import { Evt } from "evt";
4627
4881
  import { fork } from "node:child_process";
4628
- import { dirname as dirname2, resolve as resolve2 } from "node:path";
4882
+ import { dirname as dirname2, resolve as resolve3 } from "node:path";
4629
4883
  import terminalLink3 from "terminal-link";
4630
4884
  var BackgroundWorkerCoordinator = class {
4631
4885
  constructor(baseURL) {
@@ -4825,7 +5079,7 @@ var BackgroundWorker = class {
4825
5079
  ...this.#readEnvVars()
4826
5080
  };
4827
5081
  logger.debug("Initializing worker", { path: this.path, cwd, fullEnv });
4828
- this.tasks = await new Promise((resolve4, reject) => {
5082
+ this.tasks = await new Promise((resolve5, reject) => {
4829
5083
  const child = fork(this.path, {
4830
5084
  stdio: [
4831
5085
  /*stdin*/
@@ -4852,7 +5106,7 @@ var BackgroundWorker = class {
4852
5106
  if (message.type === "TASKS_READY" && !resolved) {
4853
5107
  clearTimeout(timeout);
4854
5108
  resolved = true;
4855
- resolve4(message.payload.tasks);
5109
+ resolve5(message.payload.tasks);
4856
5110
  child.kill();
4857
5111
  } else if (message.type === "UNCAUGHT_EXCEPTION") {
4858
5112
  clearTimeout(timeout);
@@ -4987,7 +5241,7 @@ var BackgroundWorker = class {
4987
5241
  const result = {};
4988
5242
  dotenv.config({
4989
5243
  processEnv: result,
4990
- path: [".env", ".env.local", ".env.development.local"].map((p) => resolve2(process.cwd(), p))
5244
+ path: [".env", ".env.local", ".env.development.local"].map((p) => resolve3(process.cwd(), p))
4991
5245
  });
4992
5246
  process.env.TRIGGER_API_URL && (result.TRIGGER_API_URL = process.env.TRIGGER_API_URL);
4993
5247
  delete result.TRIGGER_API_URL;
@@ -5088,8 +5342,8 @@ var TaskRunProcess = class {
5088
5342
  async executeTaskRun(payload) {
5089
5343
  let resolver;
5090
5344
  let rejecter;
5091
- const promise = new Promise((resolve4, reject) => {
5092
- resolver = resolve4;
5345
+ const promise = new Promise((resolve5, reject) => {
5346
+ resolver = resolve5;
5093
5347
  rejecter = reject;
5094
5348
  });
5095
5349
  this._attemptStatuses.set(payload.execution.attempt.id, "PENDING");
@@ -5235,14 +5489,15 @@ var DevCommandOptions = CommonCommandOptions.extend({
5235
5489
  debugger: z5.boolean().default(false),
5236
5490
  debugOtel: z5.boolean().default(false),
5237
5491
  config: z5.string().optional(),
5238
- projectRef: z5.string().optional()
5492
+ projectRef: z5.string().optional(),
5493
+ skipUpdateCheck: z5.boolean().default(false)
5239
5494
  });
5240
5495
  function configureDevCommand(program2) {
5241
5496
  return commonOptions(
5242
5497
  program2.command("dev").description("Run your Trigger.dev tasks locally").argument("[path]", "The path to the project", ".").option("-c, --config <config file>", "The name of the config file, found at [path].").option(
5243
5498
  "-p, --project-ref <project ref>",
5244
5499
  "The project ref. Required if there is no config file."
5245
- ).option("--debugger", "Enable the debugger").option("--debug-otel", "Enable OpenTelemetry debugging")
5500
+ ).option("--debugger", "Enable the debugger").option("--debug-otel", "Enable OpenTelemetry debugging").option("--skip-update-check", "Skip checking for @trigger.dev package updates")
5246
5501
  ).action(async (path7, options) => {
5247
5502
  wrapCommandAction("dev", DevCommandOptions, options, async (opts) => {
5248
5503
  await devCommand(path7, opts);
@@ -5284,7 +5539,11 @@ async function startDev(dir, options, authorization, dashboardUrl) {
5284
5539
  logger.loggerLevel = options.logLevel;
5285
5540
  }
5286
5541
  await printStandloneInitialBanner(true);
5287
- printDevBanner();
5542
+ if (!options.skipUpdateCheck) {
5543
+ console.log();
5544
+ await updateTriggerPackages(dir, { ...options }, false, true);
5545
+ }
5546
+ printDevBanner(!options.skipUpdateCheck);
5288
5547
  logger.debug("Starting dev session", { dir, options, authorization });
5289
5548
  let config = await readConfig(dir, {
5290
5549
  projectRef: options.projectRef,
@@ -5449,9 +5708,9 @@ function useDev({
5449
5708
  }
5450
5709
  let latestWorkerContentHash;
5451
5710
  const taskFiles = await gatherTaskFiles(config);
5452
- const workerFacadePath = join6(cliRootPath(), "workers", "dev", "worker-facade.js");
5711
+ const workerFacadePath = join7(cliRootPath(), "workers", "dev", "worker-facade.js");
5453
5712
  const workerFacade = readFileSync3(workerFacadePath, "utf-8");
5454
- const workerSetupPath = join6(cliRootPath(), "workers", "dev", "worker-setup.js");
5713
+ const workerSetupPath = join7(cliRootPath(), "workers", "dev", "worker-setup.js");
5455
5714
  let entryPointContents = workerFacade.replace("__TASKS__", createTaskFileImports(taskFiles)).replace(
5456
5715
  "__WORKER_SETUP__",
5457
5716
  `import { tracingSDK, sender } from "${escapeImportPath(workerSetupPath)}";`
@@ -5516,22 +5775,19 @@ function useDev({
5516
5775
  if (!firstBuild) {
5517
5776
  logger.log(chalkGrey("\u25CB Building background worker\u2026"));
5518
5777
  }
5519
- const metaOutputKey = join6("out", `stdin.js`).replace(/\\/g, "/");
5520
- logger.debug("Metafile", {
5521
- metafileOutputs: JSON.stringify(result.metafile?.outputs)
5522
- });
5778
+ const metaOutputKey = join7("out", `stdin.js`).replace(/\\/g, "/");
5523
5779
  const metaOutput = result.metafile.outputs[metaOutputKey];
5524
5780
  if (!metaOutput) {
5525
5781
  throw new Error(`Could not find metafile`);
5526
5782
  }
5527
- const outputFileKey = join6(config.projectDir, metaOutputKey);
5783
+ const outputFileKey = join7(config.projectDir, metaOutputKey);
5528
5784
  const outputFile = result.outputFiles.find((file) => file.path === outputFileKey);
5529
5785
  if (!outputFile) {
5530
5786
  throw new Error(
5531
5787
  `Could not find output file for entry point ${metaOutput.entryPoint}`
5532
5788
  );
5533
5789
  }
5534
- const sourceMapFileKey = join6(config.projectDir, `${metaOutputKey}.map`);
5790
+ const sourceMapFileKey = join7(config.projectDir, `${metaOutputKey}.map`);
5535
5791
  const sourceMapFile = result.outputFiles.find(
5536
5792
  (file) => file.path === sourceMapFileKey
5537
5793
  );
@@ -5542,10 +5798,10 @@ function useDev({
5542
5798
  logger.log(chalkGrey("\u25CB No changes detected, skipping build\u2026"));
5543
5799
  return;
5544
5800
  }
5545
- const fullPath = join6(config.projectDir, ".trigger", `${contentHash}.js`);
5801
+ const fullPath = join7(config.projectDir, ".trigger", `${contentHash}.js`);
5546
5802
  const sourceMapPath = `${fullPath}.map`;
5547
5803
  const outputFileWithSourceMap = `${outputFile.text}
5548
- //# sourceMappingURL=${basename(sourceMapPath)}`;
5804
+ //# sourceMappingURL=${basename2(sourceMapPath)}`;
5549
5805
  await fs7.promises.mkdir(dirname3(fullPath), { recursive: true });
5550
5806
  await fs7.promises.writeFile(fullPath, outputFileWithSourceMap);
5551
5807
  logger.debug(`Wrote background worker to ${fullPath}`);
@@ -5573,8 +5829,15 @@ function useDev({
5573
5829
  latestWorkerContentHash = contentHash;
5574
5830
  let packageVersion;
5575
5831
  const taskResources = [];
5576
- if (!backgroundWorker.tasks) {
5577
- throw new Error(`Background Worker started without tasks`);
5832
+ if (!backgroundWorker.tasks || backgroundWorker.tasks.length === 0) {
5833
+ logger.log(
5834
+ `${chalkError(
5835
+ "X Error:"
5836
+ )} Worker failed to build: no tasks found. Searched in ${config.triggerDirectories.join(
5837
+ ", "
5838
+ )}`
5839
+ );
5840
+ return;
5578
5841
  }
5579
5842
  for (const task of backgroundWorker.tasks) {
5580
5843
  taskResources.push(task);
@@ -5593,6 +5856,9 @@ function useDev({
5593
5856
  );
5594
5857
  return;
5595
5858
  }
5859
+ logger.debug("Creating background worker with tasks", {
5860
+ tasks: taskResources
5861
+ });
5596
5862
  const backgroundWorkerBody = {
5597
5863
  localOnly: true,
5598
5864
  metadata: {
@@ -5679,7 +5945,7 @@ ${chalkError("X Error:")} The package ${chalkPurple(
5679
5945
  }
5680
5946
  const throttledRebuild = pDebounce(runBuild, 250, { before: true });
5681
5947
  const taskFileWatcher = watch(
5682
- config.triggerDirectories.map((triggerDir) => `${triggerDir}/*.ts`),
5948
+ config.triggerDirectories.map((triggerDir) => `${triggerDir}/**/*.ts`),
5683
5949
  {
5684
5950
  ignoreInitial: true
5685
5951
  }
@@ -5749,7 +6015,7 @@ async function gatherRequiredDependencies2(outputMeta, config) {
5749
6015
  }
5750
6016
  }
5751
6017
  if (config.additionalPackages) {
5752
- const projectPackageJson = await readJSONFile(join6(config.projectDir, "package.json"));
6018
+ const projectPackageJson = await readJSONFile(join7(config.projectDir, "package.json"));
5753
6019
  for (const packageName of config.additionalPackages) {
5754
6020
  if (dependencies2[packageName]) {
5755
6021
  continue;
@@ -5819,7 +6085,7 @@ async function amendNodePathWithPnpmNodeModules(nodePath) {
5819
6085
  async function findPnpmNodeModulesPath() {
5820
6086
  return await findUp3(
5821
6087
  async (directory) => {
5822
- const pnpmModules = join6(directory, "node_modules", ".pnpm", "node_modules");
6088
+ const pnpmModules = join7(directory, "node_modules", ".pnpm", "node_modules");
5823
6089
  const hasPnpmNodeModules = await pathExists2(pnpmModules);
5824
6090
  if (hasPnpmNodeModules) {
5825
6091
  return pnpmModules;
@@ -5830,17 +6096,15 @@ async function findPnpmNodeModulesPath() {
5830
6096
  }
5831
6097
 
5832
6098
  // src/commands/init.ts
5833
- import { intro as intro4, isCancel, log as log4, outro as outro4, select as select2, text } from "@clack/prompts";
6099
+ import { intro as intro5, isCancel as isCancel2, log as log6, outro as outro6, select as select2, text } from "@clack/prompts";
5834
6100
  import { context as context3, trace as trace3 } from "@opentelemetry/api";
5835
- import {
5836
- flattenAttributes as flattenAttributes3,
5837
- recordSpanException as recordSpanException5
5838
- } from "@trigger.dev/core/v3";
5839
- import chalk6 from "chalk";
6101
+ import { flattenAttributes as flattenAttributes3 } from "@trigger.dev/core/v3";
6102
+ import { recordSpanException as recordSpanException5 } from "@trigger.dev/core/v3/workers";
6103
+ import chalk5 from "chalk";
5840
6104
  import { execa as execa3 } from "execa";
5841
6105
  import { applyEdits, modify } from "jsonc-parser";
5842
6106
  import { writeFile as writeFile3 } from "node:fs/promises";
5843
- import { join as join7, relative as relative4, resolve as resolve3 } from "node:path";
6107
+ import { join as join8, relative as relative4, resolve as resolve4 } from "node:path";
5844
6108
  import terminalLink4 from "terminal-link";
5845
6109
  import { z as z6 } from "zod";
5846
6110
 
@@ -5916,7 +6180,7 @@ async function initCommand(dir, options) {
5916
6180
  }
5917
6181
  async function _initCommand(dir, options) {
5918
6182
  const span = trace3.getSpan(context3.active());
5919
- intro4("Initializing project");
6183
+ intro5("Initializing project");
5920
6184
  const authorization = await login({
5921
6185
  embedded: true,
5922
6186
  defaultApiUrl: options.apiUrl,
@@ -5940,7 +6204,7 @@ async function _initCommand(dir, options) {
5940
6204
  if (!options.overrideConfig) {
5941
6205
  try {
5942
6206
  const result = await readConfig(dir);
5943
- outro4(
6207
+ outro6(
5944
6208
  result.status === "file" ? `Project already initialized: Found config file at ${result.path}. Pass --override-config to override` : "Project already initialized"
5945
6209
  );
5946
6210
  return;
@@ -5957,11 +6221,11 @@ async function _initCommand(dir, options) {
5957
6221
  ...flattenAttributes3(selectedProject, "cli.project")
5958
6222
  });
5959
6223
  logger.debug("Selected project", selectedProject);
5960
- log4.step(`Configuring project "${selectedProject.name}" (${selectedProject.externalRef})`);
6224
+ log6.step(`Configuring project "${selectedProject.name}" (${selectedProject.externalRef})`);
5961
6225
  if (!options.skipPackageInstall) {
5962
6226
  await installPackages2(dir, options);
5963
6227
  } else {
5964
- log4.info("Skipping package installation");
6228
+ log6.info("Skipping package installation");
5965
6229
  }
5966
6230
  const triggerDir = await createTriggerDir(dir, options);
5967
6231
  await writeConfigFile(dir, selectedProject, options, triggerDir);
@@ -5971,41 +6235,41 @@ async function _initCommand(dir, options) {
5971
6235
  "project dashboard",
5972
6236
  `${authorization.dashboardUrl}/projects/v3/${selectedProject.externalRef}`
5973
6237
  );
5974
- log4.success("Successfully initialized project for Trigger.dev v3 \u{1FAE1}");
5975
- log4.info("Next steps:");
5976
- log4.info(
5977
- ` 1. To start developing, run ${chalk6.green(
6238
+ log6.success("Successfully initialized project for Trigger.dev v3 \u{1FAE1}");
6239
+ log6.info("Next steps:");
6240
+ log6.info(
6241
+ ` 1. To start developing, run ${chalk5.green(
5978
6242
  `npx trigger.dev@${options.tag} dev`
5979
6243
  )} in your project directory`
5980
6244
  );
5981
- log4.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);
5982
- log4.info(
6245
+ log6.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);
6246
+ log6.info(
5983
6247
  ` 3. Head over to our ${terminalLink4(
5984
6248
  "v3 docs",
5985
6249
  "https://trigger.dev/docs/v3"
5986
6250
  )} to learn more.`
5987
6251
  );
5988
- log4.info(
6252
+ log6.info(
5989
6253
  ` 4. Need help? Join our ${terminalLink4(
5990
6254
  "Discord community",
5991
6255
  "https://trigger.dev/discord"
5992
- )} or email us at ${chalk6.cyan("help@trigger.dev")}`
6256
+ )} or email us at ${chalk5.cyan("help@trigger.dev")}`
5993
6257
  );
5994
- outro4(`Project initialized successfully. Happy coding!`);
6258
+ outro6(`Project initialized successfully. Happy coding!`);
5995
6259
  }
5996
6260
  async function createTriggerDir(dir, options) {
5997
6261
  return await tracer.startActiveSpan("createTriggerDir", async (span) => {
5998
6262
  try {
5999
- const defaultValue = join7(dir, "src", "trigger");
6263
+ const defaultValue = join8(dir, "src", "trigger");
6000
6264
  const location = await text({
6001
6265
  message: "Where would you like to create the Trigger.dev directory?",
6002
6266
  defaultValue,
6003
6267
  placeholder: defaultValue
6004
6268
  });
6005
- if (isCancel(location)) {
6269
+ if (isCancel2(location)) {
6006
6270
  throw new OutroCommandError();
6007
6271
  }
6008
- const triggerDir = resolve3(process.cwd(), location);
6272
+ const triggerDir = resolve4(process.cwd(), location);
6009
6273
  logger.debug({ triggerDir });
6010
6274
  span.setAttributes({
6011
6275
  "cli.triggerDir": triggerDir
@@ -6024,7 +6288,7 @@ async function createTriggerDir(dir, options) {
6024
6288
  }
6025
6289
  ]
6026
6290
  });
6027
- if (isCancel(exampleSelection)) {
6291
+ if (isCancel2(exampleSelection)) {
6028
6292
  throw new OutroCommandError();
6029
6293
  }
6030
6294
  const example = exampleSelection;
@@ -6032,20 +6296,20 @@ async function createTriggerDir(dir, options) {
6032
6296
  "cli.example": example
6033
6297
  });
6034
6298
  if (example === "none") {
6035
- await createFile(join7(triggerDir, ".gitkeep"), "");
6036
- log4.step(`Created directory at ${location}`);
6299
+ await createFile(join8(triggerDir, ".gitkeep"), "");
6300
+ log6.step(`Created directory at ${location}`);
6037
6301
  span.end();
6038
6302
  return { location, isCustomValue: location !== defaultValue };
6039
6303
  }
6040
- const templatePath = join7(cliRootPath(), "templates", "examples", `${example}.ts.template`);
6041
- const outputPath = join7(triggerDir, "example.ts");
6304
+ const templatePath = join8(cliRootPath(), "templates", "examples", `${example}.ts.template`);
6305
+ const outputPath = join8(triggerDir, "example.ts");
6042
6306
  await createFileFromTemplate({
6043
6307
  templatePath,
6044
6308
  outputPath,
6045
6309
  replacements: {}
6046
6310
  });
6047
6311
  const relativeOutputPath = relative4(process.cwd(), outputPath);
6048
- log4.step(`Created example file at ${relativeOutputPath}`);
6312
+ log6.step(`Created example file at ${relativeOutputPath}`);
6049
6313
  span.end();
6050
6314
  return { location, isCustomValue: location !== defaultValue };
6051
6315
  } catch (e) {
@@ -6060,15 +6324,15 @@ async function createTriggerDir(dir, options) {
6060
6324
  async function gitIgnoreDotTriggerDir(dir, options) {
6061
6325
  return await tracer.startActiveSpan("gitIgnoreDotTriggerDir", async (span) => {
6062
6326
  try {
6063
- const projectDir = resolve3(process.cwd(), dir);
6064
- const gitIgnorePath = join7(projectDir, ".gitignore");
6327
+ const projectDir = resolve4(process.cwd(), dir);
6328
+ const gitIgnorePath = join8(projectDir, ".gitignore");
6065
6329
  span.setAttributes({
6066
6330
  "cli.projectDir": projectDir,
6067
6331
  "cli.gitIgnorePath": gitIgnorePath
6068
6332
  });
6069
6333
  if (!await pathExists(gitIgnorePath)) {
6070
6334
  await createFile(gitIgnorePath, ".trigger");
6071
- log4.step(`Added .trigger to .gitignore`);
6335
+ log6.step(`Added .trigger to .gitignore`);
6072
6336
  span.end();
6073
6337
  return;
6074
6338
  }
@@ -6080,7 +6344,7 @@ async function gitIgnoreDotTriggerDir(dir, options) {
6080
6344
  const newGitIgnoreContent = `${gitIgnoreContent}
6081
6345
  .trigger`;
6082
6346
  await writeFile3(gitIgnorePath, newGitIgnoreContent, "utf-8");
6083
- log4.step(`Added .trigger to .gitignore`);
6347
+ log6.step(`Added .trigger to .gitignore`);
6084
6348
  span.end();
6085
6349
  } catch (e) {
6086
6350
  if (!(e instanceof SkipCommandError)) {
@@ -6094,8 +6358,8 @@ async function gitIgnoreDotTriggerDir(dir, options) {
6094
6358
  async function addConfigFileToTsConfig(dir, options) {
6095
6359
  return await tracer.startActiveSpan("createTriggerDir", async (span) => {
6096
6360
  try {
6097
- const projectDir = resolve3(process.cwd(), dir);
6098
- const tsconfigPath = join7(projectDir, "tsconfig.json");
6361
+ const projectDir = resolve4(process.cwd(), dir);
6362
+ const tsconfigPath = join8(projectDir, "tsconfig.json");
6099
6363
  span.setAttributes({
6100
6364
  "cli.projectDir": projectDir,
6101
6365
  "cli.tsconfigPath": tsconfigPath
@@ -6113,7 +6377,7 @@ async function addConfigFileToTsConfig(dir, options) {
6113
6377
  const newTsconfigContent = applyEdits(tsconfigContent, edits);
6114
6378
  logger.debug("new tsconfig.json content", { newTsconfigContent });
6115
6379
  await writeFile3(tsconfigPath, newTsconfigContent, "utf-8");
6116
- log4.step(`Added trigger.config.ts to tsconfig.json`);
6380
+ log6.step(`Added trigger.config.ts to tsconfig.json`);
6117
6381
  span.end();
6118
6382
  } catch (e) {
6119
6383
  if (!(e instanceof SkipCommandError)) {
@@ -6128,7 +6392,7 @@ async function installPackages2(dir, options) {
6128
6392
  return await tracer.startActiveSpan("installPackages", async (span) => {
6129
6393
  const installSpinner = spinner();
6130
6394
  try {
6131
- const projectDir = resolve3(process.cwd(), dir);
6395
+ const projectDir = resolve4(process.cwd(), dir);
6132
6396
  const pkgManager = await getUserPackageManager(projectDir);
6133
6397
  span.setAttributes({
6134
6398
  "cli.projectDir": projectDir,
@@ -6180,9 +6444,9 @@ async function writeConfigFile(dir, project, options, triggerDir) {
6180
6444
  try {
6181
6445
  const spnnr = spinner();
6182
6446
  spnnr.start("Creating config file");
6183
- const projectDir = resolve3(process.cwd(), dir);
6184
- const templatePath = join7(cliRootPath(), "templates", "trigger.config.ts.template");
6185
- const outputPath = join7(projectDir, "trigger.config.ts");
6447
+ const projectDir = resolve4(process.cwd(), dir);
6448
+ const templatePath = join8(cliRootPath(), "templates", "trigger.config.ts.template");
6449
+ const outputPath = join8(projectDir, "trigger.config.ts");
6186
6450
  span.setAttributes({
6187
6451
  "cli.projectDir": projectDir,
6188
6452
  "cli.templatePath": templatePath,
@@ -6222,7 +6486,7 @@ async function selectProject(apiClient2, dashboardUrl, projectRef) {
6222
6486
  if (projectRef) {
6223
6487
  const projectResponse = await apiClient2.getProject(projectRef);
6224
6488
  if (!projectResponse.success) {
6225
- log4.error(
6489
+ log6.error(
6226
6490
  `--project-ref ${projectRef} is not a valid project ref. Request to fetch data resulted in: ${projectResponse.error}`
6227
6491
  );
6228
6492
  throw new SkipCommandError(projectResponse.error);
@@ -6242,7 +6506,7 @@ async function selectProject(apiClient2, dashboardUrl, projectRef) {
6242
6506
  "Create new project",
6243
6507
  `${dashboardUrl}/projects/new?version=v3`
6244
6508
  );
6245
- outro4(`You don't have any projects yet. ${newProjectLink}`);
6509
+ outro6(`You don't have any projects yet. ${newProjectLink}`);
6246
6510
  throw new SkipCommandError();
6247
6511
  }
6248
6512
  const selectedProject = await select2({
@@ -6253,7 +6517,7 @@ async function selectProject(apiClient2, dashboardUrl, projectRef) {
6253
6517
  hint: project.organization.title
6254
6518
  }))
6255
6519
  });
6256
- if (isCancel(selectedProject)) {
6520
+ if (isCancel2(selectedProject)) {
6257
6521
  throw new OutroCommandError();
6258
6522
  }
6259
6523
  const projectData = projectsResponse.data.find(
@@ -6305,7 +6569,7 @@ async function logout(options) {
6305
6569
  }
6306
6570
 
6307
6571
  // src/commands/list-profiles.ts
6308
- import { log as log5, outro as outro5 } from "@clack/prompts";
6572
+ import { log as log7, outro as outro7 } from "@clack/prompts";
6309
6573
  var ListProfilesOptions = CommonCommandOptions;
6310
6574
  function configureListProfilesCommand(program2) {
6311
6575
  return program2.command("list-profiles").description("List all of your CLI profiles").option(
@@ -6331,12 +6595,12 @@ async function listProfiles(options) {
6331
6595
  return;
6332
6596
  }
6333
6597
  const profiles = Object.keys(authConfig);
6334
- log5.message("Profiles:");
6598
+ log7.message("Profiles:");
6335
6599
  for (const profile of profiles) {
6336
6600
  const profileConfig = authConfig[profile];
6337
- log5.info(`${profile}${profileConfig?.apiUrl ? ` - ${chalkGrey(profileConfig.apiUrl)}` : ""}`);
6601
+ log7.info(`${profile}${profileConfig?.apiUrl ? ` - ${chalkGrey(profileConfig.apiUrl)}` : ""}`);
6338
6602
  }
6339
- outro5("Retrieve account info by running whoami --profile <profile>");
6603
+ outro7("Retrieve account info by running whoami --profile <profile>");
6340
6604
  }
6341
6605
 
6342
6606
  // src/cli/index.ts
@@ -6349,6 +6613,7 @@ configureDeployCommand(program);
6349
6613
  configureWhoamiCommand(program);
6350
6614
  configureLogoutCommand(program);
6351
6615
  configureListProfilesCommand(program);
6616
+ configureUpdateCommand(program);
6352
6617
 
6353
6618
  // src/index.ts
6354
6619
  var main = async () => {