trigger.dev 0.0.0-v3-trigger-dirs-20240423091017 → 0.0.0-v3-update-command-20240423125505
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,7 +777,7 @@ var require_retry2 = __commonJS({
|
|
|
777
777
|
import { Command as Command2 } from "commander";
|
|
778
778
|
|
|
779
779
|
// src/commands/deploy.ts
|
|
780
|
-
import { intro as
|
|
780
|
+
import { intro as intro4, log as log5, outro as outro4 } from "@clack/prompts";
|
|
781
781
|
import { depot } from "@depot/cli";
|
|
782
782
|
import { context, trace as trace2 } from "@opentelemetry/api";
|
|
783
783
|
import {
|
|
@@ -793,14 +793,14 @@ import { execa as execa2 } from "execa";
|
|
|
793
793
|
import { createHash } from "node:crypto";
|
|
794
794
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
795
795
|
import { copyFile, mkdir, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
796
|
-
import { dirname, join as
|
|
796
|
+
import { dirname, join as join6, relative as relative3, posix } from "node:path";
|
|
797
797
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
798
798
|
import terminalLink2 from "terminal-link";
|
|
799
799
|
import invariant from "tiny-invariant";
|
|
800
|
-
import { z as
|
|
800
|
+
import { z as z5 } from "zod";
|
|
801
801
|
|
|
802
802
|
// package.json
|
|
803
|
-
var version = "0.0.0-v3-
|
|
803
|
+
var version = "0.0.0-v3-update-command-20240423125505";
|
|
804
804
|
var dependencies = {
|
|
805
805
|
"@clack/prompts": "^0.7.0",
|
|
806
806
|
"@depot/cli": "0.0.1-cli.2.55.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:0.0.0-v3-
|
|
819
|
+
"@trigger.dev/core": "workspace:0.0.0-v3-update-command-20240423125505",
|
|
820
820
|
"@types/degit": "^2.8.3",
|
|
821
821
|
chalk: "^5.2.0",
|
|
822
822
|
chokidar: "^3.5.3",
|
|
@@ -1318,6 +1318,7 @@ var logger = new Logger();
|
|
|
1318
1318
|
import { outro } from "@clack/prompts";
|
|
1319
1319
|
|
|
1320
1320
|
// src/utilities/cliOutput.ts
|
|
1321
|
+
import { log } from "@clack/prompts";
|
|
1321
1322
|
import chalk2 from "chalk";
|
|
1322
1323
|
var green = "#4FFF54";
|
|
1323
1324
|
var purple = "#735BF3";
|
|
@@ -1366,6 +1367,18 @@ function prettyPrintDate(date = /* @__PURE__ */ new Date()) {
|
|
|
1366
1367
|
formattedDate += "." + ("00" + date.getMilliseconds()).slice(-3);
|
|
1367
1368
|
return formattedDate;
|
|
1368
1369
|
}
|
|
1370
|
+
function prettyWarning(header, body, footer) {
|
|
1371
|
+
const prefix = "Warning: ";
|
|
1372
|
+
const indent = Array(prefix.length).fill(" ").join("");
|
|
1373
|
+
const spacing = "\n\n";
|
|
1374
|
+
const prettyPrefix = chalkWarning(prefix);
|
|
1375
|
+
const withIndents = (text3) => text3?.split("\n").map((line) => `${indent}${line}`).join("\n");
|
|
1376
|
+
const prettyBody = withIndents(body);
|
|
1377
|
+
const prettyFooter = withIndents(footer);
|
|
1378
|
+
log.warn(
|
|
1379
|
+
`${prettyPrefix}${header}${prettyBody ? `${spacing}${prettyBody}` : ""}${prettyFooter ? `${spacing}${prettyFooter}` : ""}`
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1369
1382
|
|
|
1370
1383
|
// src/cli/common.ts
|
|
1371
1384
|
var CommonCommandOptions = z.object({
|
|
@@ -1474,6 +1487,9 @@ async function createFile(path7, contents) {
|
|
|
1474
1487
|
async function pathExists(path7) {
|
|
1475
1488
|
return fsSync.existsSync(path7);
|
|
1476
1489
|
}
|
|
1490
|
+
async function removeFile(path7) {
|
|
1491
|
+
await fsModule.unlink(path7);
|
|
1492
|
+
}
|
|
1477
1493
|
async function readFile(path7) {
|
|
1478
1494
|
return await fsModule.readFile(path7, "utf8");
|
|
1479
1495
|
}
|
|
@@ -1481,8 +1497,8 @@ async function readJSONFile(path7) {
|
|
|
1481
1497
|
const fileContents = await fsModule.readFile(path7, "utf8");
|
|
1482
1498
|
return JSON.parse(fileContents);
|
|
1483
1499
|
}
|
|
1484
|
-
async function writeJSONFile(path7, json) {
|
|
1485
|
-
await writeFile(path7, JSON.stringify(json), "utf8");
|
|
1500
|
+
async function writeJSONFile(path7, json, pretty = false) {
|
|
1501
|
+
await writeFile(path7, JSON.stringify(json, void 0, pretty ? 2 : void 0), "utf8");
|
|
1486
1502
|
}
|
|
1487
1503
|
function readJSONFileSync(path7) {
|
|
1488
1504
|
const fileContents = fsSync.readFileSync(path7, "utf8");
|
|
@@ -1540,12 +1556,9 @@ async function getTriggerDirectories(dirPath) {
|
|
|
1540
1556
|
const entries = await fs2.promises.readdir(dirPath, { withFileTypes: true });
|
|
1541
1557
|
const triggerDirectories = [];
|
|
1542
1558
|
for (const entry of entries) {
|
|
1543
|
-
if (!entry.isDirectory() || IGNORED_DIRS.includes(entry.name)
|
|
1559
|
+
if (!entry.isDirectory() || IGNORED_DIRS.includes(entry.name))
|
|
1544
1560
|
continue;
|
|
1545
1561
|
const fullPath = join(dirPath, entry.name);
|
|
1546
|
-
if (fullPath.endsWith("app/api/trigger")) {
|
|
1547
|
-
continue;
|
|
1548
|
-
}
|
|
1549
1562
|
if (entry.name === "trigger") {
|
|
1550
1563
|
triggerDirectories.push(fullPath);
|
|
1551
1564
|
}
|
|
@@ -1619,15 +1632,6 @@ async function getConfigPath(dir, fileName) {
|
|
|
1619
1632
|
});
|
|
1620
1633
|
return await findUp(fileName ? [fileName] : CONFIG_FILES, { cwd: dir });
|
|
1621
1634
|
}
|
|
1622
|
-
async function findFilePath(dir, fileName) {
|
|
1623
|
-
const result = await findUp([fileName], { cwd: dir });
|
|
1624
|
-
logger.debug("Searched for the file", {
|
|
1625
|
-
dir,
|
|
1626
|
-
fileName,
|
|
1627
|
-
result
|
|
1628
|
-
});
|
|
1629
|
-
return result;
|
|
1630
|
-
}
|
|
1631
1635
|
async function readConfig(dir, options) {
|
|
1632
1636
|
const absoluteDir = path2.resolve(process.cwd(), dir);
|
|
1633
1637
|
const configPath = await getConfigPath(dir, options?.configFile);
|
|
@@ -1680,7 +1684,6 @@ async function resolveConfig(path7, config) {
|
|
|
1680
1684
|
config.triggerDirectories = await findTriggerDirectories(path7);
|
|
1681
1685
|
}
|
|
1682
1686
|
config.triggerDirectories = resolveTriggerDirectories(config.triggerDirectories);
|
|
1683
|
-
logger.debug("Resolved trigger directories", { triggerDirectories: config.triggerDirectories });
|
|
1684
1687
|
if (!config.triggerUrl) {
|
|
1685
1688
|
config.triggerUrl = CLOUD_API_URL;
|
|
1686
1689
|
}
|
|
@@ -1688,7 +1691,7 @@ async function resolveConfig(path7, config) {
|
|
|
1688
1691
|
config.projectDir = path7;
|
|
1689
1692
|
}
|
|
1690
1693
|
if (!config.tsconfigPath) {
|
|
1691
|
-
config.tsconfigPath = await
|
|
1694
|
+
config.tsconfigPath = await getConfigPath(path7, "tsconfig.json");
|
|
1692
1695
|
}
|
|
1693
1696
|
return config;
|
|
1694
1697
|
}
|
|
@@ -1714,29 +1717,29 @@ function getVersion() {
|
|
|
1714
1717
|
}
|
|
1715
1718
|
|
|
1716
1719
|
// src/utilities/windows.ts
|
|
1717
|
-
import { log, spinner as clackSpinner } from "@clack/prompts";
|
|
1720
|
+
import { log as log2, spinner as clackSpinner } from "@clack/prompts";
|
|
1718
1721
|
var isWindows = process.platform === "win32";
|
|
1719
1722
|
function escapeImportPath(path7) {
|
|
1720
1723
|
return isWindows ? path7.replaceAll("\\", "\\\\") : path7;
|
|
1721
1724
|
}
|
|
1722
1725
|
var ballmerSpinner = () => ({
|
|
1723
1726
|
start: (msg) => {
|
|
1724
|
-
|
|
1727
|
+
log2.step(msg ?? "");
|
|
1725
1728
|
},
|
|
1726
1729
|
stop: (msg, code) => {
|
|
1727
|
-
|
|
1730
|
+
log2.message(msg ?? "");
|
|
1728
1731
|
},
|
|
1729
1732
|
message: (msg) => {
|
|
1730
|
-
|
|
1733
|
+
log2.message(msg ?? "");
|
|
1731
1734
|
}
|
|
1732
1735
|
});
|
|
1733
1736
|
var spinner = () => isWindows ? ballmerSpinner() : clackSpinner();
|
|
1734
1737
|
|
|
1735
1738
|
// src/utilities/initialBanner.ts
|
|
1736
1739
|
async function printInitialBanner(performUpdateCheck = true) {
|
|
1737
|
-
const
|
|
1740
|
+
const cliVersion = getVersion();
|
|
1738
1741
|
const text3 = `
|
|
1739
|
-
${logo()} ${chalkGrey(`(${
|
|
1742
|
+
${logo()} ${chalkGrey(`(${cliVersion})`)}
|
|
1740
1743
|
`;
|
|
1741
1744
|
logger.info(text3);
|
|
1742
1745
|
let maybeNewVersion;
|
|
@@ -1746,7 +1749,7 @@ ${logo()} ${chalkGrey(`(${packageVersion})`)}
|
|
|
1746
1749
|
maybeNewVersion = await updateCheck();
|
|
1747
1750
|
if (maybeNewVersion !== void 0) {
|
|
1748
1751
|
loadingSpinner.stop(`Update available ${chalk3.green(maybeNewVersion)}`);
|
|
1749
|
-
const currentMajor = parseInt(
|
|
1752
|
+
const currentMajor = parseInt(cliVersion.split(".")[0]);
|
|
1750
1753
|
const newMajor = parseInt(maybeNewVersion.split(".")[0]);
|
|
1751
1754
|
if (newMajor > currentMajor) {
|
|
1752
1755
|
logger.warn(
|
|
@@ -1761,9 +1764,10 @@ After installation, run Trigger.dev with \`npx trigger.dev\`.`
|
|
|
1761
1764
|
}
|
|
1762
1765
|
}
|
|
1763
1766
|
async function printStandloneInitialBanner(performUpdateCheck = true) {
|
|
1764
|
-
const
|
|
1767
|
+
const cliVersion = getVersion();
|
|
1765
1768
|
logger.log(`
|
|
1766
|
-
${logo()} ${chalkGrey(
|
|
1769
|
+
${logo()} ${chalkGrey(`(${cliVersion})`)}
|
|
1770
|
+
`);
|
|
1767
1771
|
if (performUpdateCheck) {
|
|
1768
1772
|
const maybeNewVersion = await updateCheck();
|
|
1769
1773
|
if (maybeNewVersion !== void 0) {
|
|
@@ -1772,7 +1776,10 @@ ${logo()} ${chalkGrey("(v3 Developer Preview)")}`);
|
|
|
1772
1776
|
}
|
|
1773
1777
|
logger.log(`${chalkGrey("-".repeat(54))}`);
|
|
1774
1778
|
}
|
|
1775
|
-
function printDevBanner() {
|
|
1779
|
+
function printDevBanner(printTopBorder = true) {
|
|
1780
|
+
if (printTopBorder) {
|
|
1781
|
+
logger.log(chalkGrey("-".repeat(54)));
|
|
1782
|
+
}
|
|
1776
1783
|
logger.log(
|
|
1777
1784
|
`${chalkGrey("Key:")} ${chalkWorker("Version")} ${chalkGrey("|")} ${chalkTask(
|
|
1778
1785
|
"Task"
|
|
@@ -1784,7 +1791,7 @@ async function doUpdateCheck() {
|
|
|
1784
1791
|
let update = null;
|
|
1785
1792
|
try {
|
|
1786
1793
|
update = await checkForUpdate(package_default, {
|
|
1787
|
-
distTag: package_default.version.startsWith("
|
|
1794
|
+
distTag: package_default.version.startsWith("3.0.0-beta") ? "beta" : "latest"
|
|
1788
1795
|
});
|
|
1789
1796
|
} catch (err) {
|
|
1790
1797
|
}
|
|
@@ -1853,7 +1860,7 @@ async function setPackageJsonDeps(path7, deps) {
|
|
|
1853
1860
|
}
|
|
1854
1861
|
|
|
1855
1862
|
// src/commands/login.ts
|
|
1856
|
-
import { intro as intro2, log as
|
|
1863
|
+
import { intro as intro2, log as log3, outro as outro2, select } from "@clack/prompts";
|
|
1857
1864
|
import { recordSpanException as recordSpanException3 } from "@trigger.dev/core/v3";
|
|
1858
1865
|
|
|
1859
1866
|
// ../../node_modules/.pnpm/open@10.0.3/node_modules/open/index.js
|
|
@@ -2224,14 +2231,14 @@ var baseOpen = async (options) => {
|
|
|
2224
2231
|
}
|
|
2225
2232
|
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
2226
2233
|
if (options.wait) {
|
|
2227
|
-
return new Promise((
|
|
2234
|
+
return new Promise((resolve5, reject) => {
|
|
2228
2235
|
subprocess.once("error", reject);
|
|
2229
2236
|
subprocess.once("close", (exitCode) => {
|
|
2230
2237
|
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
2231
2238
|
reject(new Error(`Exited with code ${exitCode}`));
|
|
2232
2239
|
return;
|
|
2233
2240
|
}
|
|
2234
|
-
|
|
2241
|
+
resolve5(subprocess);
|
|
2235
2242
|
});
|
|
2236
2243
|
});
|
|
2237
2244
|
}
|
|
@@ -2348,7 +2355,7 @@ var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
|
2348
2355
|
return error;
|
|
2349
2356
|
};
|
|
2350
2357
|
async function pRetry(input, options) {
|
|
2351
|
-
return new Promise((
|
|
2358
|
+
return new Promise((resolve5, reject) => {
|
|
2352
2359
|
options = {
|
|
2353
2360
|
onFailedAttempt() {
|
|
2354
2361
|
},
|
|
@@ -2371,7 +2378,7 @@ async function pRetry(input, options) {
|
|
|
2371
2378
|
try {
|
|
2372
2379
|
const result = await input(attemptNumber);
|
|
2373
2380
|
cleanUp();
|
|
2374
|
-
|
|
2381
|
+
resolve5(result);
|
|
2375
2382
|
} catch (error) {
|
|
2376
2383
|
try {
|
|
2377
2384
|
if (!(error instanceof Error)) {
|
|
@@ -2646,11 +2653,11 @@ async function login(options) {
|
|
|
2646
2653
|
}
|
|
2647
2654
|
}
|
|
2648
2655
|
if (opts.embedded) {
|
|
2649
|
-
|
|
2656
|
+
log3.step("You must login to continue.");
|
|
2650
2657
|
}
|
|
2651
2658
|
const apiClient2 = new CliApiClient(authConfig?.apiUrl ?? opts.defaultApiUrl);
|
|
2652
2659
|
const authorizationCodeResult = await createAuthorizationCode(apiClient2);
|
|
2653
|
-
|
|
2660
|
+
log3.step(
|
|
2654
2661
|
`Please visit the following URL to login:
|
|
2655
2662
|
${chalkLink(authorizationCodeResult.url)}`
|
|
2656
2663
|
);
|
|
@@ -2684,7 +2691,7 @@ ${chalkLink(authorizationCodeResult.url)}`
|
|
|
2684
2691
|
throw new Error(whoAmIResult.error);
|
|
2685
2692
|
}
|
|
2686
2693
|
if (opts.embedded) {
|
|
2687
|
-
|
|
2694
|
+
log3.step("Logged in successfully");
|
|
2688
2695
|
} else {
|
|
2689
2696
|
outro2("Logged in successfully");
|
|
2690
2697
|
}
|
|
@@ -2703,7 +2710,7 @@ ${chalkLink(authorizationCodeResult.url)}`
|
|
|
2703
2710
|
} catch (e) {
|
|
2704
2711
|
getPersonalAccessTokenSpinner.stop(`Failed to get access token`);
|
|
2705
2712
|
if (e instanceof AbortError) {
|
|
2706
|
-
|
|
2713
|
+
log3.error(e.message);
|
|
2707
2714
|
}
|
|
2708
2715
|
recordSpanException3(span, e);
|
|
2709
2716
|
span.end();
|
|
@@ -3130,7 +3137,13 @@ import { join as join4 } from "node:path";
|
|
|
3130
3137
|
|
|
3131
3138
|
// src/utilities/getUserPackageManager.ts
|
|
3132
3139
|
import { findUp as findUp2 } from "find-up";
|
|
3140
|
+
import { basename } from "path";
|
|
3133
3141
|
async function getUserPackageManager(path7) {
|
|
3142
|
+
const packageManager = await detectPackageManager(path7);
|
|
3143
|
+
logger.debug("Detected package manager", { packageManager });
|
|
3144
|
+
return packageManager;
|
|
3145
|
+
}
|
|
3146
|
+
async function detectPackageManager(path7) {
|
|
3134
3147
|
try {
|
|
3135
3148
|
return await detectPackageManagerFromArtifacts(path7);
|
|
3136
3149
|
} catch (error) {
|
|
@@ -3152,19 +3165,33 @@ function detectPackageManagerFromCurrentCommand() {
|
|
|
3152
3165
|
}
|
|
3153
3166
|
}
|
|
3154
3167
|
async function detectPackageManagerFromArtifacts(path7) {
|
|
3155
|
-
const
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3168
|
+
const artifacts = {
|
|
3169
|
+
yarn: "yarn.lock",
|
|
3170
|
+
pnpm: "pnpm-lock.yaml",
|
|
3171
|
+
npm: "package-lock.json",
|
|
3172
|
+
npmShrinkwrap: "npm-shrinkwrap.json"
|
|
3173
|
+
};
|
|
3174
|
+
const foundPath = await findUp2(Object.values(artifacts), { cwd: path7 });
|
|
3175
|
+
if (!foundPath) {
|
|
3176
|
+
throw new Error("Could not detect package manager from artifacts");
|
|
3177
|
+
}
|
|
3178
|
+
logger.debug("Found path from package manager artifacts", { foundPath });
|
|
3179
|
+
switch (basename(foundPath)) {
|
|
3180
|
+
case artifacts.yarn:
|
|
3181
|
+
return "yarn";
|
|
3182
|
+
case artifacts.pnpm:
|
|
3183
|
+
return "pnpm";
|
|
3184
|
+
case artifacts.npm:
|
|
3185
|
+
case artifacts.npmShrinkwrap:
|
|
3186
|
+
return "npm";
|
|
3187
|
+
default:
|
|
3188
|
+
throw new Error(`Unhandled package manager detection path: ${foundPath}`);
|
|
3166
3189
|
}
|
|
3167
|
-
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
// src/utilities/assertExhaustive.ts
|
|
3193
|
+
function assertExhaustive(x) {
|
|
3194
|
+
throw new Error("Unexpected object: " + x);
|
|
3168
3195
|
}
|
|
3169
3196
|
|
|
3170
3197
|
// src/utilities/javascriptProject.ts
|
|
@@ -3223,17 +3250,25 @@ var JavascriptProject = class {
|
|
|
3223
3250
|
}
|
|
3224
3251
|
get scripts() {
|
|
3225
3252
|
return {
|
|
3226
|
-
postinstall: this.packageJson.scripts?.postinstall
|
|
3253
|
+
postinstall: this.packageJson.scripts?.postinstall ?? ""
|
|
3227
3254
|
};
|
|
3228
3255
|
}
|
|
3256
|
+
async install() {
|
|
3257
|
+
const command = await this.#getCommand();
|
|
3258
|
+
try {
|
|
3259
|
+
await command.installDependencies({
|
|
3260
|
+
cwd: this.projectPath
|
|
3261
|
+
});
|
|
3262
|
+
} catch (error) {
|
|
3263
|
+
logger.debug(`Failed to install dependencies using ${command.name}`, {
|
|
3264
|
+
error
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3229
3268
|
async resolve(packageName, options) {
|
|
3230
3269
|
if (BuiltInModules.has(packageName)) {
|
|
3231
3270
|
return void 0;
|
|
3232
3271
|
}
|
|
3233
|
-
if (!this._packageManager) {
|
|
3234
|
-
this._packageManager = await getUserPackageManager(this.projectPath);
|
|
3235
|
-
}
|
|
3236
|
-
const packageManager = this._packageManager;
|
|
3237
3272
|
const opts = { allowDev: false, ...options };
|
|
3238
3273
|
const packageJsonVersion = this.packageJson.dependencies?.[packageName];
|
|
3239
3274
|
if (typeof packageJsonVersion === "string") {
|
|
@@ -3245,7 +3280,7 @@ var JavascriptProject = class {
|
|
|
3245
3280
|
return devPackageJsonVersion;
|
|
3246
3281
|
}
|
|
3247
3282
|
}
|
|
3248
|
-
const command =
|
|
3283
|
+
const command = await this.#getCommand();
|
|
3249
3284
|
try {
|
|
3250
3285
|
const version2 = await command.resolveDependencyVersion(packageName, {
|
|
3251
3286
|
cwd: this.projectPath
|
|
@@ -3260,14 +3295,39 @@ var JavascriptProject = class {
|
|
|
3260
3295
|
});
|
|
3261
3296
|
}
|
|
3262
3297
|
}
|
|
3298
|
+
async #getCommand() {
|
|
3299
|
+
const packageManager = await this.getPackageManager();
|
|
3300
|
+
switch (packageManager) {
|
|
3301
|
+
case "npm":
|
|
3302
|
+
return new NPMCommands();
|
|
3303
|
+
case "pnpm":
|
|
3304
|
+
return new PNPMCommands();
|
|
3305
|
+
case "yarn":
|
|
3306
|
+
return new YarnCommands();
|
|
3307
|
+
default:
|
|
3308
|
+
assertExhaustive(packageManager);
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
async getPackageManager() {
|
|
3312
|
+
if (!this._packageManager) {
|
|
3313
|
+
this._packageManager = await getUserPackageManager(this.projectPath);
|
|
3314
|
+
}
|
|
3315
|
+
return this._packageManager;
|
|
3316
|
+
}
|
|
3263
3317
|
};
|
|
3264
3318
|
var PNPMCommands = class {
|
|
3265
3319
|
get name() {
|
|
3266
3320
|
return "pnpm";
|
|
3267
3321
|
}
|
|
3322
|
+
get cmd() {
|
|
3323
|
+
return process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
3324
|
+
}
|
|
3325
|
+
async installDependencies(options) {
|
|
3326
|
+
const { stdout, stderr } = await $({ cwd: options.cwd })`${this.cmd} install`;
|
|
3327
|
+
logger.debug(`Installing dependencies using ${this.name}`, { stdout, stderr });
|
|
3328
|
+
}
|
|
3268
3329
|
async resolveDependencyVersion(packageName, options) {
|
|
3269
|
-
const
|
|
3270
|
-
const { stdout } = await $({ cwd: options.cwd })`${cmd} list ${packageName} -r --json`;
|
|
3330
|
+
const { stdout } = await $({ cwd: options.cwd })`${this.cmd} list ${packageName} -r --json`;
|
|
3271
3331
|
const result = JSON.parse(stdout);
|
|
3272
3332
|
logger.debug(`Resolving ${packageName} version using pnpm`, { result });
|
|
3273
3333
|
for (const dep of result) {
|
|
@@ -3282,9 +3342,15 @@ var NPMCommands = class {
|
|
|
3282
3342
|
get name() {
|
|
3283
3343
|
return "npm";
|
|
3284
3344
|
}
|
|
3345
|
+
get cmd() {
|
|
3346
|
+
return process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
3347
|
+
}
|
|
3348
|
+
async installDependencies(options) {
|
|
3349
|
+
const { stdout, stderr } = await $({ cwd: options.cwd })`${this.cmd} install`;
|
|
3350
|
+
logger.debug(`Installing dependencies using ${this.name}`, { stdout, stderr });
|
|
3351
|
+
}
|
|
3285
3352
|
async resolveDependencyVersion(packageName, options) {
|
|
3286
|
-
const
|
|
3287
|
-
const { stdout } = await $({ cwd: options.cwd })`${cmd} list ${packageName} --json`;
|
|
3353
|
+
const { stdout } = await $({ cwd: options.cwd })`${this.cmd} list ${packageName} --json`;
|
|
3288
3354
|
const output = JSON.parse(stdout);
|
|
3289
3355
|
logger.debug(`Resolving ${packageName} version using npm`, { output });
|
|
3290
3356
|
return this.#recursivelySearchDependencies(output.dependencies, packageName);
|
|
@@ -3307,9 +3373,15 @@ var YarnCommands = class {
|
|
|
3307
3373
|
get name() {
|
|
3308
3374
|
return "yarn";
|
|
3309
3375
|
}
|
|
3376
|
+
get cmd() {
|
|
3377
|
+
return process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
|
3378
|
+
}
|
|
3379
|
+
async installDependencies(options) {
|
|
3380
|
+
const { stdout, stderr } = await $({ cwd: options.cwd })`${this.cmd} install`;
|
|
3381
|
+
logger.debug(`Installing dependencies using ${this.name}`, { stdout, stderr });
|
|
3382
|
+
}
|
|
3310
3383
|
async resolveDependencyVersion(packageName, options) {
|
|
3311
|
-
const
|
|
3312
|
-
const { stdout } = await $({ cwd: options.cwd })`${cmd} info ${packageName} --json`;
|
|
3384
|
+
const { stdout } = await $({ cwd: options.cwd })`${this.cmd} info ${packageName} --json`;
|
|
3313
3385
|
const lines = stdout.split("\n");
|
|
3314
3386
|
logger.debug(`Resolving ${packageName} version using yarn`, { lines });
|
|
3315
3387
|
for (const line of lines) {
|
|
@@ -3330,22 +3402,219 @@ function cliRootPath() {
|
|
|
3330
3402
|
return __dirname2;
|
|
3331
3403
|
}
|
|
3332
3404
|
|
|
3405
|
+
// src/commands/update.ts
|
|
3406
|
+
import { confirm, intro as intro3, isCancel, log as log4, outro as outro3 } from "@clack/prompts";
|
|
3407
|
+
import { run as ncuRun } from "npm-check-updates";
|
|
3408
|
+
import { z as z4 } from "zod";
|
|
3409
|
+
import { join as join5, resolve as resolve2 } from "path";
|
|
3410
|
+
var UpdateCommandOptions = CommonCommandOptions.pick({
|
|
3411
|
+
logLevel: true,
|
|
3412
|
+
skipTelemetry: true
|
|
3413
|
+
});
|
|
3414
|
+
function configureUpdateCommand(program2) {
|
|
3415
|
+
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(
|
|
3416
|
+
"-l, --log-level <level>",
|
|
3417
|
+
"The CLI log level to use (debug, info, log, warn, error, none). This does not effect the log level of your trigger.dev tasks.",
|
|
3418
|
+
"log"
|
|
3419
|
+
).option("--skip-telemetry", "Opt-out of sending telemetry").action(async (path7, options) => {
|
|
3420
|
+
wrapCommandAction("dev", UpdateCommandOptions, options, async (opts) => {
|
|
3421
|
+
await printStandloneInitialBanner(true);
|
|
3422
|
+
await updateCommand(path7, opts);
|
|
3423
|
+
});
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
var NcuRunResult = z4.record(z4.string());
|
|
3427
|
+
var triggerPackageFilter = /^@trigger\.dev/;
|
|
3428
|
+
async function updateCommand(dir, options) {
|
|
3429
|
+
await updateTriggerPackages(dir, options);
|
|
3430
|
+
}
|
|
3431
|
+
async function updateTriggerPackages(dir, options, embedded, requireUpdate) {
|
|
3432
|
+
if (!embedded) {
|
|
3433
|
+
intro3("Updating packages");
|
|
3434
|
+
}
|
|
3435
|
+
const projectPath = resolve2(process.cwd(), dir);
|
|
3436
|
+
const { packageJson, readonlyPackageJson, packageJsonPath } = await getPackageJson(projectPath);
|
|
3437
|
+
if (!packageJson) {
|
|
3438
|
+
log4.error("Failed to load package.json. Try to re-run with `-l debug` to see what's going on.");
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
const cliVersion = getVersion();
|
|
3442
|
+
const newCliVersion = await updateCheck();
|
|
3443
|
+
if (newCliVersion) {
|
|
3444
|
+
prettyWarning(
|
|
3445
|
+
"You're not running the latest CLI version, please consider updating ASAP",
|
|
3446
|
+
"To update, run: `(p)npm i trigger.dev@beta`\nOr run with: `(p)npx trigger.dev@beta`",
|
|
3447
|
+
"Yarn works too!"
|
|
3448
|
+
);
|
|
3449
|
+
}
|
|
3450
|
+
const triggerDependencies = getTriggerDependencies(packageJson);
|
|
3451
|
+
function getVersionMismatches(deps, targetVersion) {
|
|
3452
|
+
const mismatches = [];
|
|
3453
|
+
for (const dep of deps) {
|
|
3454
|
+
if (dep.version === targetVersion) {
|
|
3455
|
+
continue;
|
|
3456
|
+
}
|
|
3457
|
+
mismatches.push(dep);
|
|
3458
|
+
}
|
|
3459
|
+
return mismatches;
|
|
3460
|
+
}
|
|
3461
|
+
const versionMismatches = getVersionMismatches(triggerDependencies, cliVersion);
|
|
3462
|
+
if (versionMismatches.length === 0) {
|
|
3463
|
+
if (!embedded) {
|
|
3464
|
+
outro3(`Nothing to do${newCliVersion ? " ..but you should really update your CLI!" : ""}`);
|
|
3465
|
+
}
|
|
3466
|
+
return;
|
|
3467
|
+
}
|
|
3468
|
+
prettyWarning(
|
|
3469
|
+
"Mismatch between your CLI version and installed packages",
|
|
3470
|
+
"We recommend pinned versions for guaranteed compatibility"
|
|
3471
|
+
);
|
|
3472
|
+
if (!process.stdout.isTTY) {
|
|
3473
|
+
outro3("Deploy failed");
|
|
3474
|
+
console.log(
|
|
3475
|
+
`ERROR: Version mismatch detected while running in CI. This won't end well. Aborting.
|
|
3476
|
+
|
|
3477
|
+
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.
|
|
3478
|
+
|
|
3479
|
+
If your local CLI version doesn't match the one below, you may want to add the \`trigger.dev\` package to your dependencies. You will also have to update your workflow deploy command to \`npx trigger.dev deploy\` to ensure your pinned CLI version is used.
|
|
3480
|
+
|
|
3481
|
+
CLI version: ${cliVersion}
|
|
3482
|
+
|
|
3483
|
+
Current package versions that don't match the CLI:
|
|
3484
|
+
${versionMismatches.map((dep) => `- ${dep.name}@${dep.version}`).join("\n")}
|
|
3485
|
+
`
|
|
3486
|
+
);
|
|
3487
|
+
process.exit(1);
|
|
3488
|
+
}
|
|
3489
|
+
log4.message("");
|
|
3490
|
+
const userWantsToUpdate = await updateConfirmation(versionMismatches, cliVersion);
|
|
3491
|
+
if (isCancel(userWantsToUpdate)) {
|
|
3492
|
+
throw new OutroCommandError();
|
|
3493
|
+
}
|
|
3494
|
+
if (!userWantsToUpdate) {
|
|
3495
|
+
if (requireUpdate) {
|
|
3496
|
+
outro3("You shall not pass!");
|
|
3497
|
+
logger.log(
|
|
3498
|
+
`${chalkError(
|
|
3499
|
+
"X Error:"
|
|
3500
|
+
)} Update required: Version mismatches will cause errors and headaches. Don't use \`--skip-update-check\`, just update, please.
|
|
3501
|
+
`
|
|
3502
|
+
);
|
|
3503
|
+
process.exit(1);
|
|
3504
|
+
}
|
|
3505
|
+
if (!embedded) {
|
|
3506
|
+
outro3("You've been warned!");
|
|
3507
|
+
}
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
const installSpinner = spinner();
|
|
3511
|
+
installSpinner.start("Writing new package.json file");
|
|
3512
|
+
const packageJsonBackupPath = `${packageJsonPath}.bak`;
|
|
3513
|
+
await writeJSONFile(packageJsonBackupPath, readonlyPackageJson, true);
|
|
3514
|
+
const exitHandler = async (sig) => {
|
|
3515
|
+
log4.warn(
|
|
3516
|
+
`You may have to manually roll back any package.json changes. Backup written to ${packageJsonBackupPath}`
|
|
3517
|
+
);
|
|
3518
|
+
};
|
|
3519
|
+
process.prependOnceListener("exit", exitHandler);
|
|
3520
|
+
mutatePackageJsonWithUpdatedPackages(packageJson, versionMismatches, cliVersion);
|
|
3521
|
+
await writeJSONFile(packageJsonPath, packageJson, true);
|
|
3522
|
+
async function revertPackageJsonChanges() {
|
|
3523
|
+
await writeJSONFile(packageJsonPath, readonlyPackageJson, true);
|
|
3524
|
+
await removeFile(packageJsonBackupPath);
|
|
3525
|
+
}
|
|
3526
|
+
installSpinner.message("Installing new package versions");
|
|
3527
|
+
const jsProject = new JavascriptProject(projectPath);
|
|
3528
|
+
let packageManager;
|
|
3529
|
+
try {
|
|
3530
|
+
packageManager = await jsProject.getPackageManager();
|
|
3531
|
+
installSpinner.message(`Installing new package versions with ${packageManager}`);
|
|
3532
|
+
await jsProject.install();
|
|
3533
|
+
} catch (error) {
|
|
3534
|
+
installSpinner.stop(
|
|
3535
|
+
`Failed to install new package versions${packageManager ? ` with ${packageManager}` : ""}`
|
|
3536
|
+
);
|
|
3537
|
+
process.removeListener("exit", exitHandler);
|
|
3538
|
+
await revertPackageJsonChanges();
|
|
3539
|
+
throw error;
|
|
3540
|
+
}
|
|
3541
|
+
installSpinner.stop("Installed new package versions");
|
|
3542
|
+
process.removeListener("exit", exitHandler);
|
|
3543
|
+
await removeFile(packageJsonBackupPath);
|
|
3544
|
+
if (!embedded) {
|
|
3545
|
+
outro3(
|
|
3546
|
+
`Packages updated${newCliVersion ? " ..but you should really update your CLI too!" : ""}`
|
|
3547
|
+
);
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
function getTriggerDependencies(packageJson) {
|
|
3551
|
+
const deps = [];
|
|
3552
|
+
for (const type of ["dependencies", "devDependencies"]) {
|
|
3553
|
+
for (const [name, version2] of Object.entries(packageJson[type] ?? {})) {
|
|
3554
|
+
if (!version2) {
|
|
3555
|
+
continue;
|
|
3556
|
+
}
|
|
3557
|
+
if (version2.startsWith("workspace")) {
|
|
3558
|
+
continue;
|
|
3559
|
+
}
|
|
3560
|
+
if (!triggerPackageFilter.test(name)) {
|
|
3561
|
+
continue;
|
|
3562
|
+
}
|
|
3563
|
+
deps.push({ type, name, version: version2 });
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
return deps;
|
|
3567
|
+
}
|
|
3568
|
+
function mutatePackageJsonWithUpdatedPackages(packageJson, depsToUpdate, targetVersion) {
|
|
3569
|
+
for (const { type, name, version: version2 } of depsToUpdate) {
|
|
3570
|
+
if (!packageJson[type]) {
|
|
3571
|
+
throw new Error(
|
|
3572
|
+
`No ${type} entry found in package.json. Please try to upgrade manually instead.`
|
|
3573
|
+
);
|
|
3574
|
+
}
|
|
3575
|
+
packageJson[type][name] = targetVersion;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
function printUpdateTable(depsToUpdate, targetVersion) {
|
|
3579
|
+
log4.message("Suggested updates");
|
|
3580
|
+
const tableData = depsToUpdate.map((dep) => ({
|
|
3581
|
+
package: dep.name,
|
|
3582
|
+
old: dep.version,
|
|
3583
|
+
new: targetVersion
|
|
3584
|
+
}));
|
|
3585
|
+
logger.table(tableData);
|
|
3586
|
+
}
|
|
3587
|
+
async function updateConfirmation(depsToUpdate, targetVersion) {
|
|
3588
|
+
printUpdateTable(depsToUpdate, targetVersion);
|
|
3589
|
+
let confirmMessage = "Would you like to apply those updates?";
|
|
3590
|
+
return await confirm({
|
|
3591
|
+
message: confirmMessage
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
async function getPackageJson(absoluteProjectPath) {
|
|
3595
|
+
const packageJsonPath = join5(absoluteProjectPath, "package.json");
|
|
3596
|
+
const readonlyPackageJson = Object.freeze(await readJSONFile(packageJsonPath));
|
|
3597
|
+
const packageJson = structuredClone(readonlyPackageJson);
|
|
3598
|
+
return { packageJson, readonlyPackageJson, packageJsonPath };
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3333
3601
|
// src/commands/deploy.ts
|
|
3334
3602
|
var DeployCommandOptions = CommonCommandOptions.extend({
|
|
3335
|
-
skipTypecheck:
|
|
3336
|
-
skipDeploy:
|
|
3337
|
-
ignoreEnvVarCheck:
|
|
3338
|
-
env:
|
|
3339
|
-
loadImage:
|
|
3340
|
-
buildPlatform:
|
|
3341
|
-
selfHosted:
|
|
3342
|
-
registry:
|
|
3343
|
-
push:
|
|
3344
|
-
config:
|
|
3345
|
-
projectRef:
|
|
3346
|
-
outputMetafile:
|
|
3347
|
-
apiUrl:
|
|
3348
|
-
saveLogs:
|
|
3603
|
+
skipTypecheck: z5.boolean().default(false),
|
|
3604
|
+
skipDeploy: z5.boolean().default(false),
|
|
3605
|
+
ignoreEnvVarCheck: z5.boolean().default(false),
|
|
3606
|
+
env: z5.enum(["prod", "staging"]),
|
|
3607
|
+
loadImage: z5.boolean().default(false),
|
|
3608
|
+
buildPlatform: z5.enum(["linux/amd64", "linux/arm64"]).default("linux/amd64"),
|
|
3609
|
+
selfHosted: z5.boolean().default(false),
|
|
3610
|
+
registry: z5.string().optional(),
|
|
3611
|
+
push: z5.boolean().default(false),
|
|
3612
|
+
config: z5.string().optional(),
|
|
3613
|
+
projectRef: z5.string().optional(),
|
|
3614
|
+
outputMetafile: z5.string().optional(),
|
|
3615
|
+
apiUrl: z5.string().optional(),
|
|
3616
|
+
saveLogs: z5.boolean().default(false),
|
|
3617
|
+
skipUpdateCheck: z5.boolean().default(false)
|
|
3349
3618
|
});
|
|
3350
3619
|
function configureDeployCommand(program2) {
|
|
3351
3620
|
return commonOptions(
|
|
@@ -3353,7 +3622,7 @@ function configureDeployCommand(program2) {
|
|
|
3353
3622
|
"-e, --env <env>",
|
|
3354
3623
|
"Deploy to a specific environment (currently only prod and staging are supported)",
|
|
3355
3624
|
"prod"
|
|
3356
|
-
).option("--skip-typecheck", "Whether to skip the pre-build typecheck").option(
|
|
3625
|
+
).option("--skip-typecheck", "Whether to skip the pre-build typecheck").option("--skip-update-check", "Skip checking for @trigger.dev package updates").option(
|
|
3357
3626
|
"--ignore-env-var-check",
|
|
3358
3627
|
"Detected missing environment variables won't block deployment"
|
|
3359
3628
|
).option("-c, --config <config file>", "The name of the config file, found at [path]").option(
|
|
@@ -3411,7 +3680,10 @@ async function deployCommand(dir, options) {
|
|
|
3411
3680
|
}
|
|
3412
3681
|
async function _deployCommand(dir, options) {
|
|
3413
3682
|
const span = trace2.getSpan(context.active());
|
|
3414
|
-
|
|
3683
|
+
intro4("Deploying project");
|
|
3684
|
+
if (!options.skipUpdateCheck) {
|
|
3685
|
+
await updateTriggerPackages(dir, { ...options }, true, true);
|
|
3686
|
+
}
|
|
3415
3687
|
const authorization = await login({
|
|
3416
3688
|
embedded: true,
|
|
3417
3689
|
defaultApiUrl: options.apiUrl,
|
|
@@ -3454,7 +3726,7 @@ async function _deployCommand(dir, options) {
|
|
|
3454
3726
|
throw new Error(deploymentEnv.error);
|
|
3455
3727
|
}
|
|
3456
3728
|
const environmentClient = new CliApiClient(authorization.auth.apiUrl, deploymentEnv.data.apiKey);
|
|
3457
|
-
|
|
3729
|
+
log5.step(
|
|
3458
3730
|
`Preparing to deploy "${deploymentEnv.data.name}" (${resolvedConfig.config.project}) to ${options.env}`
|
|
3459
3731
|
);
|
|
3460
3732
|
const compilation = await compileProject(
|
|
@@ -3557,7 +3829,7 @@ async function _deployCommand(dir, options) {
|
|
|
3557
3829
|
printWarnings(warnings.warnings);
|
|
3558
3830
|
if (options.saveLogs) {
|
|
3559
3831
|
const logPath = await saveLogs(deploymentResponse.data.shortCode, image.logs);
|
|
3560
|
-
|
|
3832
|
+
log5.info(`Build logs have been saved to ${logPath}`);
|
|
3561
3833
|
}
|
|
3562
3834
|
};
|
|
3563
3835
|
const imageReference = options.selfHosted ? `${selfHostedRegistryHost ? `${selfHostedRegistryHost}/` : ""}${image.image}${image.digest ? `@${image.digest}` : ""}` : `${registryHost}/${image.image}${image.digest ? `@${image.digest}` : ""}`;
|
|
@@ -3614,11 +3886,11 @@ async function _deployCommand(dir, options) {
|
|
|
3614
3886
|
await preExitTasks();
|
|
3615
3887
|
const taskCount = finishedDeployment.worker?.tasks.length ?? 0;
|
|
3616
3888
|
if (taskCount === 0) {
|
|
3617
|
-
|
|
3889
|
+
outro4(
|
|
3618
3890
|
`Version ${version2} deployed with no detected tasks. Please make sure you are exporting tasks in your project. ${deploymentLink}`
|
|
3619
3891
|
);
|
|
3620
3892
|
} else {
|
|
3621
|
-
|
|
3893
|
+
outro4(
|
|
3622
3894
|
`Version ${version2} deployed with ${taskCount} detected task${taskCount === 1 ? "" : "s"} ${deploymentLink}`
|
|
3623
3895
|
);
|
|
3624
3896
|
}
|
|
@@ -3674,12 +3946,12 @@ async function _deployCommand(dir, options) {
|
|
|
3674
3946
|
}
|
|
3675
3947
|
function printErrors(errors) {
|
|
3676
3948
|
for (const error of errors ?? []) {
|
|
3677
|
-
|
|
3949
|
+
log5.error(`${chalkError("Error:")} ${error}`);
|
|
3678
3950
|
}
|
|
3679
3951
|
}
|
|
3680
3952
|
function printWarnings(warnings) {
|
|
3681
3953
|
for (const warning of warnings ?? []) {
|
|
3682
|
-
|
|
3954
|
+
log5.warn(`${chalkWarning("Warning:")} ${warning}`);
|
|
3683
3955
|
}
|
|
3684
3956
|
}
|
|
3685
3957
|
function checkLogsForWarnings(logs) {
|
|
@@ -3753,7 +4025,7 @@ If it's a binary: Please ${terminalLink2(
|
|
|
3753
4025
|
continue;
|
|
3754
4026
|
}
|
|
3755
4027
|
const message = getMessageFromTemplate(error.message, matches.groups);
|
|
3756
|
-
|
|
4028
|
+
log5.error(`${chalkError("Error:")} ${message}`);
|
|
3757
4029
|
break;
|
|
3758
4030
|
}
|
|
3759
4031
|
}
|
|
@@ -3767,7 +4039,7 @@ function getMessageFromTemplate(template, replacer) {
|
|
|
3767
4039
|
return message;
|
|
3768
4040
|
}
|
|
3769
4041
|
async function saveLogs(shortCode, logs) {
|
|
3770
|
-
const logPath =
|
|
4042
|
+
const logPath = join6(await createTempDir(), `build-${shortCode}.log`);
|
|
3771
4043
|
await writeFile2(logPath, logs);
|
|
3772
4044
|
return logPath;
|
|
3773
4045
|
}
|
|
@@ -3778,9 +4050,9 @@ async function failDeploy(shortCode, errorSummary, logs, deploymentSpinner, warn
|
|
|
3778
4050
|
printWarnings(warnings);
|
|
3779
4051
|
printErrors(errors);
|
|
3780
4052
|
checkLogsForErrors(logs);
|
|
3781
|
-
|
|
4053
|
+
outro4(`${chalkError("Error:")} ${errorSummary}. Full build logs have been saved to ${logPath}`);
|
|
3782
4054
|
} else {
|
|
3783
|
-
|
|
4055
|
+
outro4(`${chalkError("Error:")} ${errorSummary}.`);
|
|
3784
4056
|
}
|
|
3785
4057
|
}
|
|
3786
4058
|
async function checkEnvVars(envVars, config, options, environmentClient, apiUrl) {
|
|
@@ -4101,10 +4373,10 @@ async function compileProject(config, options, configPath) {
|
|
|
4101
4373
|
compileSpinner.start(`Building project in ${config.projectDir}`);
|
|
4102
4374
|
const taskFiles = await gatherTaskFiles(config);
|
|
4103
4375
|
const workerFacade = readFileSync2(
|
|
4104
|
-
|
|
4376
|
+
join6(cliRootPath(), "workers", "prod", "worker-facade.js"),
|
|
4105
4377
|
"utf-8"
|
|
4106
4378
|
);
|
|
4107
|
-
const workerSetupPath =
|
|
4379
|
+
const workerSetupPath = join6(cliRootPath(), "workers", "prod", "worker-setup.js");
|
|
4108
4380
|
let workerContents = workerFacade.replace("__TASKS__", createTaskFileImports(taskFiles)).replace(
|
|
4109
4381
|
"__WORKER_SETUP__",
|
|
4110
4382
|
`import { tracingSDK } from "${escapeImportPath(workerSetupPath)}";`
|
|
@@ -4164,10 +4436,10 @@ async function compileProject(config, options, configPath) {
|
|
|
4164
4436
|
throw new Error("Build failed, aborting deployment");
|
|
4165
4437
|
}
|
|
4166
4438
|
if (options.outputMetafile) {
|
|
4167
|
-
await writeJSONFile(
|
|
4439
|
+
await writeJSONFile(join6(options.outputMetafile, "worker.json"), result.metafile);
|
|
4168
4440
|
}
|
|
4169
4441
|
const entryPointContents = readFileSync2(
|
|
4170
|
-
|
|
4442
|
+
join6(cliRootPath(), "workers", "prod", "entry-point.js"),
|
|
4171
4443
|
"utf-8"
|
|
4172
4444
|
);
|
|
4173
4445
|
const entryPointResult = await build2({
|
|
@@ -4210,7 +4482,7 @@ async function compileProject(config, options, configPath) {
|
|
|
4210
4482
|
}
|
|
4211
4483
|
if (options.outputMetafile) {
|
|
4212
4484
|
await writeJSONFile(
|
|
4213
|
-
|
|
4485
|
+
join6(options.outputMetafile, "entry-point.json"),
|
|
4214
4486
|
entryPointResult.metafile
|
|
4215
4487
|
);
|
|
4216
4488
|
}
|
|
@@ -4221,24 +4493,24 @@ async function compileProject(config, options, configPath) {
|
|
|
4221
4493
|
const entryPointMetaOutput = entryPointResult.metafile.outputs[posix.join("out", "stdin.js")];
|
|
4222
4494
|
invariant(entryPointMetaOutput, "Meta output for the entryPoint build is missing");
|
|
4223
4495
|
const workerOutputFile = result.outputFiles.find(
|
|
4224
|
-
(file) => file.path ===
|
|
4496
|
+
(file) => file.path === join6(config.projectDir, "out", "stdin.js")
|
|
4225
4497
|
);
|
|
4226
4498
|
invariant(workerOutputFile, "Output file for the result build is missing");
|
|
4227
4499
|
const workerSourcemapFile = result.outputFiles.find(
|
|
4228
|
-
(file) => file.path ===
|
|
4500
|
+
(file) => file.path === join6(config.projectDir, "out", "stdin.js.map")
|
|
4229
4501
|
);
|
|
4230
4502
|
invariant(workerSourcemapFile, "Sourcemap file for the result build is missing");
|
|
4231
4503
|
const entryPointOutputFile = entryPointResult.outputFiles.find(
|
|
4232
|
-
(file) => file.path ===
|
|
4504
|
+
(file) => file.path === join6(config.projectDir, "out", "stdin.js")
|
|
4233
4505
|
);
|
|
4234
4506
|
invariant(entryPointOutputFile, "Output file for the entryPoint build is missing");
|
|
4235
4507
|
await writeFile2(
|
|
4236
|
-
|
|
4508
|
+
join6(tempDir, "worker.js"),
|
|
4237
4509
|
`${workerOutputFile.text}
|
|
4238
4510
|
//# sourceMappingURL=worker.js.map`
|
|
4239
4511
|
);
|
|
4240
|
-
await writeFile2(
|
|
4241
|
-
await writeFile2(
|
|
4512
|
+
await writeFile2(join6(tempDir, "worker.js.map"), workerSourcemapFile.text);
|
|
4513
|
+
await writeFile2(join6(tempDir, "index.js"), entryPointOutputFile.text);
|
|
4242
4514
|
logger.debug("Getting the imports for the worker and entryPoint builds", {
|
|
4243
4515
|
workerImports: metaOutput.imports,
|
|
4244
4516
|
entryPointImports: entryPointMetaOutput.imports
|
|
@@ -4255,11 +4527,11 @@ async function compileProject(config, options, configPath) {
|
|
|
4255
4527
|
...javascriptProject.scripts
|
|
4256
4528
|
}
|
|
4257
4529
|
};
|
|
4258
|
-
await writeJSONFile(
|
|
4530
|
+
await writeJSONFile(join6(tempDir, "package.json"), packageJsonContents);
|
|
4259
4531
|
const copyResult = await copyAdditionalFiles(config, tempDir);
|
|
4260
4532
|
if (!copyResult.ok) {
|
|
4261
4533
|
compileSpinner.stop("Project built with warnings");
|
|
4262
|
-
|
|
4534
|
+
log5.warn(
|
|
4263
4535
|
`No additionalFiles matches for:
|
|
4264
4536
|
|
|
4265
4537
|
${copyResult.noMatches.map((glob) => `- "${glob}"`).join("\n")}
|
|
@@ -4281,8 +4553,8 @@ If this is unexpected you should check your ${terminalLink2(
|
|
|
4281
4553
|
if (!resolvingDependenciesResult) {
|
|
4282
4554
|
throw new SkipLoggingError("Failed to resolve dependencies");
|
|
4283
4555
|
}
|
|
4284
|
-
const containerFilePath =
|
|
4285
|
-
await copyFile(containerFilePath,
|
|
4556
|
+
const containerFilePath = join6(cliRootPath(), "Containerfile.prod");
|
|
4557
|
+
await copyFile(containerFilePath, join6(tempDir, "Containerfile"));
|
|
4286
4558
|
const contentHasher = createHash("sha256");
|
|
4287
4559
|
contentHasher.update(Buffer.from(entryPointOutputFile.text));
|
|
4288
4560
|
contentHasher.update(Buffer.from(workerOutputFile.text));
|
|
@@ -4314,8 +4586,8 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
|
|
|
4314
4586
|
const hasher = createHash("sha256");
|
|
4315
4587
|
hasher.update(JSON.stringify(packageJsonContents));
|
|
4316
4588
|
const digest = hasher.digest("hex").slice(0, 16);
|
|
4317
|
-
const cacheDir =
|
|
4318
|
-
const cachePath =
|
|
4589
|
+
const cacheDir = join6(config.projectDir, ".trigger", "cache");
|
|
4590
|
+
const cachePath = join6(cacheDir, `${digest}.json`);
|
|
4319
4591
|
span.setAttributes({
|
|
4320
4592
|
"packageJson.digest": digest,
|
|
4321
4593
|
"cache.path": cachePath,
|
|
@@ -4324,7 +4596,7 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
|
|
|
4324
4596
|
try {
|
|
4325
4597
|
const cachedPackageLock = await readFile2(cachePath, "utf-8");
|
|
4326
4598
|
logger.debug(`Using cached package-lock.json for ${digest}`);
|
|
4327
|
-
await writeFile2(
|
|
4599
|
+
await writeFile2(join6(projectDir, "package-lock.json"), cachedPackageLock);
|
|
4328
4600
|
span.setAttributes({
|
|
4329
4601
|
"cache.hit": true
|
|
4330
4602
|
});
|
|
@@ -4347,11 +4619,11 @@ async function resolveDependencies(projectDir, packageJsonContents, config, opti
|
|
|
4347
4619
|
cwd: projectDir,
|
|
4348
4620
|
stdio: logger.loggerLevel === "debug" ? "inherit" : "pipe"
|
|
4349
4621
|
});
|
|
4350
|
-
const packageLockContents = await readFile2(
|
|
4622
|
+
const packageLockContents = await readFile2(join6(projectDir, "package-lock.json"), "utf-8");
|
|
4351
4623
|
logger.debug(`Writing package-lock.json to cache for ${digest}`);
|
|
4352
4624
|
await mkdir(cacheDir, { recursive: true });
|
|
4353
4625
|
await writeFile2(cachePath, packageLockContents);
|
|
4354
|
-
await writeFile2(
|
|
4626
|
+
await writeFile2(join6(projectDir, "package-lock.json"), packageLockContents);
|
|
4355
4627
|
span.end();
|
|
4356
4628
|
resolvingDepsSpinner.stop("Dependencies resolved");
|
|
4357
4629
|
return true;
|
|
@@ -4403,8 +4675,8 @@ async function typecheckProject(config, options) {
|
|
|
4403
4675
|
tscTypecheck.stdout?.on("data", (chunk) => stdouts.push(chunk.toString()));
|
|
4404
4676
|
tscTypecheck.stderr?.on("data", (chunk) => stderrs.push(chunk.toString()));
|
|
4405
4677
|
try {
|
|
4406
|
-
await new Promise((
|
|
4407
|
-
tscTypecheck.addListener("exit", (code) => code === 0 ?
|
|
4678
|
+
await new Promise((resolve5, reject) => {
|
|
4679
|
+
tscTypecheck.addListener("exit", (code) => code === 0 ? resolve5(code) : reject(code));
|
|
4408
4680
|
});
|
|
4409
4681
|
} catch (error) {
|
|
4410
4682
|
typecheckSpinner.stop(
|
|
@@ -4522,7 +4794,7 @@ async function copyAdditionalFiles(config, tempDir) {
|
|
|
4522
4794
|
for await (const file of glob) {
|
|
4523
4795
|
matches++;
|
|
4524
4796
|
const pathInsideTempDir = relative3(config.projectDir, file.fullpath()).split(posix.sep).filter((p) => p !== "..").join(posix.sep);
|
|
4525
|
-
const relativeDestinationPath =
|
|
4797
|
+
const relativeDestinationPath = join6(tempDir, pathInsideTempDir);
|
|
4526
4798
|
logger.debug(`Copying file ${file.fullpath()} to ${relativeDestinationPath}`);
|
|
4527
4799
|
await mkdir(dirname(relativeDestinationPath), { recursive: true });
|
|
4528
4800
|
await copyFile(file.fullpath(), relativeDestinationPath);
|
|
@@ -4553,7 +4825,7 @@ async function copyAdditionalFiles(config, tempDir) {
|
|
|
4553
4825
|
}
|
|
4554
4826
|
async function ensureLoggedIntoDockerRegistry(registryHost, auth) {
|
|
4555
4827
|
const tmpDir = await createTempDir();
|
|
4556
|
-
const dockerConfigPath =
|
|
4828
|
+
const dockerConfigPath = join6(tmpDir, "config.json");
|
|
4557
4829
|
await writeJSONFile(dockerConfigPath, {
|
|
4558
4830
|
auths: {
|
|
4559
4831
|
[registryHost]: {
|
|
@@ -4588,22 +4860,23 @@ function arrayToSentence(items) {
|
|
|
4588
4860
|
|
|
4589
4861
|
// src/commands/dev.tsx
|
|
4590
4862
|
import {
|
|
4863
|
+
ZodMessageHandler as ZodMessageHandler2,
|
|
4864
|
+
ZodMessageSender as ZodMessageSender2,
|
|
4591
4865
|
clientWebsocketMessages,
|
|
4592
4866
|
detectDependencyVersion as detectDependencyVersion2,
|
|
4593
4867
|
serverWebsocketMessages
|
|
4594
4868
|
} from "@trigger.dev/core/v3";
|
|
4595
|
-
import { ZodMessageHandler as ZodMessageHandler2, ZodMessageSender as ZodMessageSender2 } from "@trigger.dev/core/v3/zodMessageHandler";
|
|
4596
4869
|
import { watch } from "chokidar";
|
|
4597
4870
|
import { context as context2 } from "esbuild";
|
|
4598
4871
|
import { render, useInput } from "ink";
|
|
4599
4872
|
import { createHash as createHash2 } from "node:crypto";
|
|
4600
4873
|
import fs7, { readFileSync as readFileSync3 } from "node:fs";
|
|
4601
|
-
import { basename, dirname as dirname3, join as
|
|
4874
|
+
import { basename as basename2, dirname as dirname3, join as join7, normalize } from "node:path";
|
|
4602
4875
|
import pDebounce from "p-debounce";
|
|
4603
4876
|
import { WebSocket } from "partysocket";
|
|
4604
4877
|
import React, { Suspense, useEffect } from "react";
|
|
4605
4878
|
import { WebSocket as wsWebSocket } from "ws";
|
|
4606
|
-
import { z as
|
|
4879
|
+
import { z as z6 } from "zod";
|
|
4607
4880
|
|
|
4608
4881
|
// src/workers/common/errors.ts
|
|
4609
4882
|
var UncaughtExceptionError = class extends Error {
|
|
@@ -4627,16 +4900,17 @@ var TaskMetadataParseError = class extends Error {
|
|
|
4627
4900
|
import {
|
|
4628
4901
|
SemanticInternalAttributes,
|
|
4629
4902
|
TaskRunErrorCodes,
|
|
4903
|
+
ZodMessageHandler,
|
|
4904
|
+
ZodMessageSender,
|
|
4630
4905
|
childToWorkerMessages,
|
|
4631
4906
|
correctErrorStackTrace,
|
|
4632
4907
|
formatDurationMilliseconds,
|
|
4633
4908
|
workerToChildMessages
|
|
4634
4909
|
} from "@trigger.dev/core/v3";
|
|
4635
|
-
import { ZodMessageHandler, ZodMessageSender } from "@trigger.dev/core/v3/zodMessageHandler";
|
|
4636
4910
|
import dotenv from "dotenv";
|
|
4637
4911
|
import { Evt } from "evt";
|
|
4638
4912
|
import { fork } from "node:child_process";
|
|
4639
|
-
import { dirname as dirname2, resolve as
|
|
4913
|
+
import { dirname as dirname2, resolve as resolve3 } from "node:path";
|
|
4640
4914
|
import terminalLink3 from "terminal-link";
|
|
4641
4915
|
var BackgroundWorkerCoordinator = class {
|
|
4642
4916
|
constructor(baseURL) {
|
|
@@ -4836,7 +5110,7 @@ var BackgroundWorker = class {
|
|
|
4836
5110
|
...this.#readEnvVars()
|
|
4837
5111
|
};
|
|
4838
5112
|
logger.debug("Initializing worker", { path: this.path, cwd, fullEnv });
|
|
4839
|
-
this.tasks = await new Promise((
|
|
5113
|
+
this.tasks = await new Promise((resolve5, reject) => {
|
|
4840
5114
|
const child = fork(this.path, {
|
|
4841
5115
|
stdio: [
|
|
4842
5116
|
/*stdin*/
|
|
@@ -4863,7 +5137,7 @@ var BackgroundWorker = class {
|
|
|
4863
5137
|
if (message.type === "TASKS_READY" && !resolved) {
|
|
4864
5138
|
clearTimeout(timeout);
|
|
4865
5139
|
resolved = true;
|
|
4866
|
-
|
|
5140
|
+
resolve5(message.payload.tasks);
|
|
4867
5141
|
child.kill();
|
|
4868
5142
|
} else if (message.type === "UNCAUGHT_EXCEPTION") {
|
|
4869
5143
|
clearTimeout(timeout);
|
|
@@ -4998,7 +5272,7 @@ var BackgroundWorker = class {
|
|
|
4998
5272
|
const result = {};
|
|
4999
5273
|
dotenv.config({
|
|
5000
5274
|
processEnv: result,
|
|
5001
|
-
path: [".env", ".env.local", ".env.development.local"].map((p) =>
|
|
5275
|
+
path: [".env", ".env.local", ".env.development.local"].map((p) => resolve3(process.cwd(), p))
|
|
5002
5276
|
});
|
|
5003
5277
|
process.env.TRIGGER_API_URL && (result.TRIGGER_API_URL = process.env.TRIGGER_API_URL);
|
|
5004
5278
|
delete result.TRIGGER_API_URL;
|
|
@@ -5099,8 +5373,8 @@ var TaskRunProcess = class {
|
|
|
5099
5373
|
async executeTaskRun(payload) {
|
|
5100
5374
|
let resolver;
|
|
5101
5375
|
let rejecter;
|
|
5102
|
-
const promise = new Promise((
|
|
5103
|
-
resolver =
|
|
5376
|
+
const promise = new Promise((resolve5, reject) => {
|
|
5377
|
+
resolver = resolve5;
|
|
5104
5378
|
rejecter = reject;
|
|
5105
5379
|
});
|
|
5106
5380
|
this._attemptStatuses.set(payload.execution.attempt.id, "PENDING");
|
|
@@ -5243,17 +5517,18 @@ function runtimeCheck(minimumMajor, minimumMinor) {
|
|
|
5243
5517
|
import { findUp as findUp3, pathExists as pathExists2 } from "find-up";
|
|
5244
5518
|
var apiClient;
|
|
5245
5519
|
var DevCommandOptions = CommonCommandOptions.extend({
|
|
5246
|
-
debugger:
|
|
5247
|
-
debugOtel:
|
|
5248
|
-
config:
|
|
5249
|
-
projectRef:
|
|
5520
|
+
debugger: z6.boolean().default(false),
|
|
5521
|
+
debugOtel: z6.boolean().default(false),
|
|
5522
|
+
config: z6.string().optional(),
|
|
5523
|
+
projectRef: z6.string().optional(),
|
|
5524
|
+
skipUpdateCheck: z6.boolean().default(false)
|
|
5250
5525
|
});
|
|
5251
5526
|
function configureDevCommand(program2) {
|
|
5252
5527
|
return commonOptions(
|
|
5253
5528
|
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(
|
|
5254
5529
|
"-p, --project-ref <project ref>",
|
|
5255
5530
|
"The project ref. Required if there is no config file."
|
|
5256
|
-
).option("--debugger", "Enable the debugger").option("--debug-otel", "Enable OpenTelemetry debugging")
|
|
5531
|
+
).option("--debugger", "Enable the debugger").option("--debug-otel", "Enable OpenTelemetry debugging").option("--skip-update-check", "Skip checking for @trigger.dev package updates")
|
|
5257
5532
|
).action(async (path7, options) => {
|
|
5258
5533
|
wrapCommandAction("dev", DevCommandOptions, options, async (opts) => {
|
|
5259
5534
|
await devCommand(path7, opts);
|
|
@@ -5295,7 +5570,11 @@ async function startDev(dir, options, authorization, dashboardUrl) {
|
|
|
5295
5570
|
logger.loggerLevel = options.logLevel;
|
|
5296
5571
|
}
|
|
5297
5572
|
await printStandloneInitialBanner(true);
|
|
5298
|
-
|
|
5573
|
+
if (!options.skipUpdateCheck) {
|
|
5574
|
+
console.log();
|
|
5575
|
+
await updateTriggerPackages(dir, { ...options }, false, true);
|
|
5576
|
+
}
|
|
5577
|
+
printDevBanner(!options.skipUpdateCheck);
|
|
5299
5578
|
logger.debug("Starting dev session", { dir, options, authorization });
|
|
5300
5579
|
let config = await readConfig(dir, {
|
|
5301
5580
|
projectRef: options.projectRef,
|
|
@@ -5460,9 +5739,9 @@ function useDev({
|
|
|
5460
5739
|
}
|
|
5461
5740
|
let latestWorkerContentHash;
|
|
5462
5741
|
const taskFiles = await gatherTaskFiles(config);
|
|
5463
|
-
const workerFacadePath =
|
|
5742
|
+
const workerFacadePath = join7(cliRootPath(), "workers", "dev", "worker-facade.js");
|
|
5464
5743
|
const workerFacade = readFileSync3(workerFacadePath, "utf-8");
|
|
5465
|
-
const workerSetupPath =
|
|
5744
|
+
const workerSetupPath = join7(cliRootPath(), "workers", "dev", "worker-setup.js");
|
|
5466
5745
|
let entryPointContents = workerFacade.replace("__TASKS__", createTaskFileImports(taskFiles)).replace(
|
|
5467
5746
|
"__WORKER_SETUP__",
|
|
5468
5747
|
`import { tracingSDK, sender } from "${escapeImportPath(workerSetupPath)}";`
|
|
@@ -5527,7 +5806,7 @@ function useDev({
|
|
|
5527
5806
|
if (!firstBuild) {
|
|
5528
5807
|
logger.log(chalkGrey("\u25CB Building background worker\u2026"));
|
|
5529
5808
|
}
|
|
5530
|
-
const metaOutputKey =
|
|
5809
|
+
const metaOutputKey = join7("out", `stdin.js`).replace(/\\/g, "/");
|
|
5531
5810
|
logger.debug("Metafile", {
|
|
5532
5811
|
metafileOutputs: JSON.stringify(result.metafile?.outputs)
|
|
5533
5812
|
});
|
|
@@ -5535,14 +5814,14 @@ function useDev({
|
|
|
5535
5814
|
if (!metaOutput) {
|
|
5536
5815
|
throw new Error(`Could not find metafile`);
|
|
5537
5816
|
}
|
|
5538
|
-
const outputFileKey =
|
|
5817
|
+
const outputFileKey = join7(config.projectDir, metaOutputKey);
|
|
5539
5818
|
const outputFile = result.outputFiles.find((file) => file.path === outputFileKey);
|
|
5540
5819
|
if (!outputFile) {
|
|
5541
5820
|
throw new Error(
|
|
5542
5821
|
`Could not find output file for entry point ${metaOutput.entryPoint}`
|
|
5543
5822
|
);
|
|
5544
5823
|
}
|
|
5545
|
-
const sourceMapFileKey =
|
|
5824
|
+
const sourceMapFileKey = join7(config.projectDir, `${metaOutputKey}.map`);
|
|
5546
5825
|
const sourceMapFile = result.outputFiles.find(
|
|
5547
5826
|
(file) => file.path === sourceMapFileKey
|
|
5548
5827
|
);
|
|
@@ -5553,10 +5832,10 @@ function useDev({
|
|
|
5553
5832
|
logger.log(chalkGrey("\u25CB No changes detected, skipping build\u2026"));
|
|
5554
5833
|
return;
|
|
5555
5834
|
}
|
|
5556
|
-
const fullPath =
|
|
5835
|
+
const fullPath = join7(config.projectDir, ".trigger", `${contentHash}.js`);
|
|
5557
5836
|
const sourceMapPath = `${fullPath}.map`;
|
|
5558
5837
|
const outputFileWithSourceMap = `${outputFile.text}
|
|
5559
|
-
//# sourceMappingURL=${
|
|
5838
|
+
//# sourceMappingURL=${basename2(sourceMapPath)}`;
|
|
5560
5839
|
await fs7.promises.mkdir(dirname3(fullPath), { recursive: true });
|
|
5561
5840
|
await fs7.promises.writeFile(fullPath, outputFileWithSourceMap);
|
|
5562
5841
|
logger.debug(`Wrote background worker to ${fullPath}`);
|
|
@@ -5760,7 +6039,7 @@ async function gatherRequiredDependencies2(outputMeta, config) {
|
|
|
5760
6039
|
}
|
|
5761
6040
|
}
|
|
5762
6041
|
if (config.additionalPackages) {
|
|
5763
|
-
const projectPackageJson = await readJSONFile(
|
|
6042
|
+
const projectPackageJson = await readJSONFile(join7(config.projectDir, "package.json"));
|
|
5764
6043
|
for (const packageName of config.additionalPackages) {
|
|
5765
6044
|
if (dependencies2[packageName]) {
|
|
5766
6045
|
continue;
|
|
@@ -5830,7 +6109,7 @@ async function amendNodePathWithPnpmNodeModules(nodePath) {
|
|
|
5830
6109
|
async function findPnpmNodeModulesPath() {
|
|
5831
6110
|
return await findUp3(
|
|
5832
6111
|
async (directory) => {
|
|
5833
|
-
const pnpmModules =
|
|
6112
|
+
const pnpmModules = join7(directory, "node_modules", ".pnpm", "node_modules");
|
|
5834
6113
|
const hasPnpmNodeModules = await pathExists2(pnpmModules);
|
|
5835
6114
|
if (hasPnpmNodeModules) {
|
|
5836
6115
|
return pnpmModules;
|
|
@@ -5841,7 +6120,7 @@ async function findPnpmNodeModulesPath() {
|
|
|
5841
6120
|
}
|
|
5842
6121
|
|
|
5843
6122
|
// src/commands/init.ts
|
|
5844
|
-
import { intro as
|
|
6123
|
+
import { intro as intro5, isCancel as isCancel2, log as log6, outro as outro5, select as select2, text } from "@clack/prompts";
|
|
5845
6124
|
import { context as context3, trace as trace3 } from "@opentelemetry/api";
|
|
5846
6125
|
import {
|
|
5847
6126
|
flattenAttributes as flattenAttributes3,
|
|
@@ -5851,9 +6130,9 @@ import chalk6 from "chalk";
|
|
|
5851
6130
|
import { execa as execa3 } from "execa";
|
|
5852
6131
|
import { applyEdits, modify } from "jsonc-parser";
|
|
5853
6132
|
import { writeFile as writeFile3 } from "node:fs/promises";
|
|
5854
|
-
import { join as
|
|
6133
|
+
import { join as join8, relative as relative4, resolve as resolve4 } from "node:path";
|
|
5855
6134
|
import terminalLink4 from "terminal-link";
|
|
5856
|
-
import { z as
|
|
6135
|
+
import { z as z7 } from "zod";
|
|
5857
6136
|
|
|
5858
6137
|
// src/utilities/createFileFromTemplate.ts
|
|
5859
6138
|
import fs8 from "fs/promises";
|
|
@@ -5898,10 +6177,10 @@ function replaceAll(input, replacements) {
|
|
|
5898
6177
|
|
|
5899
6178
|
// src/commands/init.ts
|
|
5900
6179
|
var InitCommandOptions = CommonCommandOptions.extend({
|
|
5901
|
-
projectRef:
|
|
5902
|
-
overrideConfig:
|
|
5903
|
-
tag:
|
|
5904
|
-
skipPackageInstall:
|
|
6180
|
+
projectRef: z7.string().optional(),
|
|
6181
|
+
overrideConfig: z7.boolean().default(false),
|
|
6182
|
+
tag: z7.string().default("beta"),
|
|
6183
|
+
skipPackageInstall: z7.boolean().default(false)
|
|
5905
6184
|
});
|
|
5906
6185
|
function configureInitCommand(program2) {
|
|
5907
6186
|
return commonOptions(
|
|
@@ -5927,7 +6206,7 @@ async function initCommand(dir, options) {
|
|
|
5927
6206
|
}
|
|
5928
6207
|
async function _initCommand(dir, options) {
|
|
5929
6208
|
const span = trace3.getSpan(context3.active());
|
|
5930
|
-
|
|
6209
|
+
intro5("Initializing project");
|
|
5931
6210
|
const authorization = await login({
|
|
5932
6211
|
embedded: true,
|
|
5933
6212
|
defaultApiUrl: options.apiUrl,
|
|
@@ -5951,7 +6230,7 @@ async function _initCommand(dir, options) {
|
|
|
5951
6230
|
if (!options.overrideConfig) {
|
|
5952
6231
|
try {
|
|
5953
6232
|
const result = await readConfig(dir);
|
|
5954
|
-
|
|
6233
|
+
outro5(
|
|
5955
6234
|
result.status === "file" ? `Project already initialized: Found config file at ${result.path}. Pass --override-config to override` : "Project already initialized"
|
|
5956
6235
|
);
|
|
5957
6236
|
return;
|
|
@@ -5968,11 +6247,11 @@ async function _initCommand(dir, options) {
|
|
|
5968
6247
|
...flattenAttributes3(selectedProject, "cli.project")
|
|
5969
6248
|
});
|
|
5970
6249
|
logger.debug("Selected project", selectedProject);
|
|
5971
|
-
|
|
6250
|
+
log6.step(`Configuring project "${selectedProject.name}" (${selectedProject.externalRef})`);
|
|
5972
6251
|
if (!options.skipPackageInstall) {
|
|
5973
6252
|
await installPackages2(dir, options);
|
|
5974
6253
|
} else {
|
|
5975
|
-
|
|
6254
|
+
log6.info("Skipping package installation");
|
|
5976
6255
|
}
|
|
5977
6256
|
const triggerDir = await createTriggerDir(dir, options);
|
|
5978
6257
|
await writeConfigFile(dir, selectedProject, options, triggerDir);
|
|
@@ -5982,41 +6261,41 @@ async function _initCommand(dir, options) {
|
|
|
5982
6261
|
"project dashboard",
|
|
5983
6262
|
`${authorization.dashboardUrl}/projects/v3/${selectedProject.externalRef}`
|
|
5984
6263
|
);
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
6264
|
+
log6.success("Successfully initialized project for Trigger.dev v3 \u{1FAE1}");
|
|
6265
|
+
log6.info("Next steps:");
|
|
6266
|
+
log6.info(
|
|
5988
6267
|
` 1. To start developing, run ${chalk6.green(
|
|
5989
6268
|
`npx trigger.dev@${options.tag} dev`
|
|
5990
6269
|
)} in your project directory`
|
|
5991
6270
|
);
|
|
5992
|
-
|
|
5993
|
-
|
|
6271
|
+
log6.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);
|
|
6272
|
+
log6.info(
|
|
5994
6273
|
` 3. Head over to our ${terminalLink4(
|
|
5995
6274
|
"v3 docs",
|
|
5996
6275
|
"https://trigger.dev/docs/v3"
|
|
5997
6276
|
)} to learn more.`
|
|
5998
6277
|
);
|
|
5999
|
-
|
|
6278
|
+
log6.info(
|
|
6000
6279
|
` 4. Need help? Join our ${terminalLink4(
|
|
6001
6280
|
"Discord community",
|
|
6002
6281
|
"https://trigger.dev/discord"
|
|
6003
6282
|
)} or email us at ${chalk6.cyan("help@trigger.dev")}`
|
|
6004
6283
|
);
|
|
6005
|
-
|
|
6284
|
+
outro5(`Project initialized successfully. Happy coding!`);
|
|
6006
6285
|
}
|
|
6007
6286
|
async function createTriggerDir(dir, options) {
|
|
6008
6287
|
return await tracer.startActiveSpan("createTriggerDir", async (span) => {
|
|
6009
6288
|
try {
|
|
6010
|
-
const defaultValue =
|
|
6289
|
+
const defaultValue = join8(dir, "src", "trigger");
|
|
6011
6290
|
const location = await text({
|
|
6012
6291
|
message: "Where would you like to create the Trigger.dev directory?",
|
|
6013
6292
|
defaultValue,
|
|
6014
6293
|
placeholder: defaultValue
|
|
6015
6294
|
});
|
|
6016
|
-
if (
|
|
6295
|
+
if (isCancel2(location)) {
|
|
6017
6296
|
throw new OutroCommandError();
|
|
6018
6297
|
}
|
|
6019
|
-
const triggerDir =
|
|
6298
|
+
const triggerDir = resolve4(process.cwd(), location);
|
|
6020
6299
|
logger.debug({ triggerDir });
|
|
6021
6300
|
span.setAttributes({
|
|
6022
6301
|
"cli.triggerDir": triggerDir
|
|
@@ -6035,7 +6314,7 @@ async function createTriggerDir(dir, options) {
|
|
|
6035
6314
|
}
|
|
6036
6315
|
]
|
|
6037
6316
|
});
|
|
6038
|
-
if (
|
|
6317
|
+
if (isCancel2(exampleSelection)) {
|
|
6039
6318
|
throw new OutroCommandError();
|
|
6040
6319
|
}
|
|
6041
6320
|
const example = exampleSelection;
|
|
@@ -6043,20 +6322,20 @@ async function createTriggerDir(dir, options) {
|
|
|
6043
6322
|
"cli.example": example
|
|
6044
6323
|
});
|
|
6045
6324
|
if (example === "none") {
|
|
6046
|
-
await createFile(
|
|
6047
|
-
|
|
6325
|
+
await createFile(join8(triggerDir, ".gitkeep"), "");
|
|
6326
|
+
log6.step(`Created directory at ${location}`);
|
|
6048
6327
|
span.end();
|
|
6049
6328
|
return { location, isCustomValue: location !== defaultValue };
|
|
6050
6329
|
}
|
|
6051
|
-
const templatePath =
|
|
6052
|
-
const outputPath =
|
|
6330
|
+
const templatePath = join8(cliRootPath(), "templates", "examples", `${example}.ts.template`);
|
|
6331
|
+
const outputPath = join8(triggerDir, "example.ts");
|
|
6053
6332
|
await createFileFromTemplate({
|
|
6054
6333
|
templatePath,
|
|
6055
6334
|
outputPath,
|
|
6056
6335
|
replacements: {}
|
|
6057
6336
|
});
|
|
6058
6337
|
const relativeOutputPath = relative4(process.cwd(), outputPath);
|
|
6059
|
-
|
|
6338
|
+
log6.step(`Created example file at ${relativeOutputPath}`);
|
|
6060
6339
|
span.end();
|
|
6061
6340
|
return { location, isCustomValue: location !== defaultValue };
|
|
6062
6341
|
} catch (e) {
|
|
@@ -6071,15 +6350,15 @@ async function createTriggerDir(dir, options) {
|
|
|
6071
6350
|
async function gitIgnoreDotTriggerDir(dir, options) {
|
|
6072
6351
|
return await tracer.startActiveSpan("gitIgnoreDotTriggerDir", async (span) => {
|
|
6073
6352
|
try {
|
|
6074
|
-
const projectDir =
|
|
6075
|
-
const gitIgnorePath =
|
|
6353
|
+
const projectDir = resolve4(process.cwd(), dir);
|
|
6354
|
+
const gitIgnorePath = join8(projectDir, ".gitignore");
|
|
6076
6355
|
span.setAttributes({
|
|
6077
6356
|
"cli.projectDir": projectDir,
|
|
6078
6357
|
"cli.gitIgnorePath": gitIgnorePath
|
|
6079
6358
|
});
|
|
6080
6359
|
if (!await pathExists(gitIgnorePath)) {
|
|
6081
6360
|
await createFile(gitIgnorePath, ".trigger");
|
|
6082
|
-
|
|
6361
|
+
log6.step(`Added .trigger to .gitignore`);
|
|
6083
6362
|
span.end();
|
|
6084
6363
|
return;
|
|
6085
6364
|
}
|
|
@@ -6091,7 +6370,7 @@ async function gitIgnoreDotTriggerDir(dir, options) {
|
|
|
6091
6370
|
const newGitIgnoreContent = `${gitIgnoreContent}
|
|
6092
6371
|
.trigger`;
|
|
6093
6372
|
await writeFile3(gitIgnorePath, newGitIgnoreContent, "utf-8");
|
|
6094
|
-
|
|
6373
|
+
log6.step(`Added .trigger to .gitignore`);
|
|
6095
6374
|
span.end();
|
|
6096
6375
|
} catch (e) {
|
|
6097
6376
|
if (!(e instanceof SkipCommandError)) {
|
|
@@ -6105,8 +6384,8 @@ async function gitIgnoreDotTriggerDir(dir, options) {
|
|
|
6105
6384
|
async function addConfigFileToTsConfig(dir, options) {
|
|
6106
6385
|
return await tracer.startActiveSpan("createTriggerDir", async (span) => {
|
|
6107
6386
|
try {
|
|
6108
|
-
const projectDir =
|
|
6109
|
-
const tsconfigPath =
|
|
6387
|
+
const projectDir = resolve4(process.cwd(), dir);
|
|
6388
|
+
const tsconfigPath = join8(projectDir, "tsconfig.json");
|
|
6110
6389
|
span.setAttributes({
|
|
6111
6390
|
"cli.projectDir": projectDir,
|
|
6112
6391
|
"cli.tsconfigPath": tsconfigPath
|
|
@@ -6124,7 +6403,7 @@ async function addConfigFileToTsConfig(dir, options) {
|
|
|
6124
6403
|
const newTsconfigContent = applyEdits(tsconfigContent, edits);
|
|
6125
6404
|
logger.debug("new tsconfig.json content", { newTsconfigContent });
|
|
6126
6405
|
await writeFile3(tsconfigPath, newTsconfigContent, "utf-8");
|
|
6127
|
-
|
|
6406
|
+
log6.step(`Added trigger.config.ts to tsconfig.json`);
|
|
6128
6407
|
span.end();
|
|
6129
6408
|
} catch (e) {
|
|
6130
6409
|
if (!(e instanceof SkipCommandError)) {
|
|
@@ -6139,7 +6418,7 @@ async function installPackages2(dir, options) {
|
|
|
6139
6418
|
return await tracer.startActiveSpan("installPackages", async (span) => {
|
|
6140
6419
|
const installSpinner = spinner();
|
|
6141
6420
|
try {
|
|
6142
|
-
const projectDir =
|
|
6421
|
+
const projectDir = resolve4(process.cwd(), dir);
|
|
6143
6422
|
const pkgManager = await getUserPackageManager(projectDir);
|
|
6144
6423
|
span.setAttributes({
|
|
6145
6424
|
"cli.projectDir": projectDir,
|
|
@@ -6191,9 +6470,9 @@ async function writeConfigFile(dir, project, options, triggerDir) {
|
|
|
6191
6470
|
try {
|
|
6192
6471
|
const spnnr = spinner();
|
|
6193
6472
|
spnnr.start("Creating config file");
|
|
6194
|
-
const projectDir =
|
|
6195
|
-
const templatePath =
|
|
6196
|
-
const outputPath =
|
|
6473
|
+
const projectDir = resolve4(process.cwd(), dir);
|
|
6474
|
+
const templatePath = join8(cliRootPath(), "templates", "trigger.config.ts.template");
|
|
6475
|
+
const outputPath = join8(projectDir, "trigger.config.ts");
|
|
6197
6476
|
span.setAttributes({
|
|
6198
6477
|
"cli.projectDir": projectDir,
|
|
6199
6478
|
"cli.templatePath": templatePath,
|
|
@@ -6233,7 +6512,7 @@ async function selectProject(apiClient2, dashboardUrl, projectRef) {
|
|
|
6233
6512
|
if (projectRef) {
|
|
6234
6513
|
const projectResponse = await apiClient2.getProject(projectRef);
|
|
6235
6514
|
if (!projectResponse.success) {
|
|
6236
|
-
|
|
6515
|
+
log6.error(
|
|
6237
6516
|
`--project-ref ${projectRef} is not a valid project ref. Request to fetch data resulted in: ${projectResponse.error}`
|
|
6238
6517
|
);
|
|
6239
6518
|
throw new SkipCommandError(projectResponse.error);
|
|
@@ -6253,7 +6532,7 @@ async function selectProject(apiClient2, dashboardUrl, projectRef) {
|
|
|
6253
6532
|
"Create new project",
|
|
6254
6533
|
`${dashboardUrl}/projects/new?version=v3`
|
|
6255
6534
|
);
|
|
6256
|
-
|
|
6535
|
+
outro5(`You don't have any projects yet. ${newProjectLink}`);
|
|
6257
6536
|
throw new SkipCommandError();
|
|
6258
6537
|
}
|
|
6259
6538
|
const selectedProject = await select2({
|
|
@@ -6264,7 +6543,7 @@ async function selectProject(apiClient2, dashboardUrl, projectRef) {
|
|
|
6264
6543
|
hint: project.organization.title
|
|
6265
6544
|
}))
|
|
6266
6545
|
});
|
|
6267
|
-
if (
|
|
6546
|
+
if (isCancel2(selectedProject)) {
|
|
6268
6547
|
throw new OutroCommandError();
|
|
6269
6548
|
}
|
|
6270
6549
|
const projectData = projectsResponse.data.find(
|
|
@@ -6316,7 +6595,7 @@ async function logout(options) {
|
|
|
6316
6595
|
}
|
|
6317
6596
|
|
|
6318
6597
|
// src/commands/list-profiles.ts
|
|
6319
|
-
import { log as
|
|
6598
|
+
import { log as log7, outro as outro6 } from "@clack/prompts";
|
|
6320
6599
|
var ListProfilesOptions = CommonCommandOptions;
|
|
6321
6600
|
function configureListProfilesCommand(program2) {
|
|
6322
6601
|
return program2.command("list-profiles").description("List all of your CLI profiles").option(
|
|
@@ -6342,12 +6621,12 @@ async function listProfiles(options) {
|
|
|
6342
6621
|
return;
|
|
6343
6622
|
}
|
|
6344
6623
|
const profiles = Object.keys(authConfig);
|
|
6345
|
-
|
|
6624
|
+
log7.message("Profiles:");
|
|
6346
6625
|
for (const profile of profiles) {
|
|
6347
6626
|
const profileConfig = authConfig[profile];
|
|
6348
|
-
|
|
6627
|
+
log7.info(`${profile}${profileConfig?.apiUrl ? ` - ${chalkGrey(profileConfig.apiUrl)}` : ""}`);
|
|
6349
6628
|
}
|
|
6350
|
-
|
|
6629
|
+
outro6("Retrieve account info by running whoami --profile <profile>");
|
|
6351
6630
|
}
|
|
6352
6631
|
|
|
6353
6632
|
// src/cli/index.ts
|
|
@@ -6360,6 +6639,7 @@ configureDeployCommand(program);
|
|
|
6360
6639
|
configureWhoamiCommand(program);
|
|
6361
6640
|
configureLogoutCommand(program);
|
|
6362
6641
|
configureListProfilesCommand(program);
|
|
6642
|
+
configureUpdateCommand(program);
|
|
6363
6643
|
|
|
6364
6644
|
// src/index.ts
|
|
6365
6645
|
var main = async () => {
|