Skip to content

Commit 3d53d4c

Browse files
authored
Improve the update CLI command and fix missing tsconfig.json error (#1315)
* Fixes for CLI update command, and make the hide the "whoami" command output when running in dev * Fix an issue where a missing tsconfig.json file would throw an error on dev/deploy * Don’t show latest CLI warning when using a prerelease * Only print CLI update required message when update is embedded * Strip out TRIGGER\_ keys when using syncEnvVars, to prevent deploy errors
1 parent 56a5b58 commit 3d53d4c

File tree

11 files changed

+99
-39
lines changed

11 files changed

+99
-39
lines changed

.changeset/clever-buses-watch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Fix an issue where a missing tsconfig.json file would throw an error on dev/deploy

.changeset/soft-ladybugs-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Fixes for CLI update command, and make the hide the "whoami" command output when running in dev.

.changeset/twelve-onions-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
Strip out TRIGGER\_ keys when using syncEnvVars, to prevent deploy errors

packages/build/src/extensions/core/syncEnvVars.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const UNSYNCABLE_ENV_VARS = [
6363
"_",
6464
];
6565

66+
const UNSYNCABLE_ENV_VARS_PREFIXES = ["TRIGGER_"];
67+
6668
export type SyncEnvVarsFunction = (params: SyncEnvVarsParams) => SyncEnvVarsResult;
6769

6870
export type SyncEnvVarsOptions = {
@@ -98,6 +100,11 @@ export function syncEnvVars(fn: SyncEnvVarsFunction, options?: SyncEnvVarsOption
98100
return acc;
99101
}
100102

103+
// Strip out any TRIGGER_ prefix env vars
104+
if (UNSYNCABLE_ENV_VARS_PREFIXES.some((prefix) => key.startsWith(prefix))) {
105+
return acc;
106+
}
107+
101108
acc[key] = value;
102109
return acc;
103110
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export async function devCommand(options: DevCommandOptions) {
5151

5252
const authorization = await login({
5353
embedded: true,
54+
silent: true,
5455
defaultApiUrl: options.apiUrl,
5556
profile: options.profile,
5657
});

packages/cli-v3/src/commands/login.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ export type LoginOptions = {
5959
defaultApiUrl?: string;
6060
embedded?: boolean;
6161
profile?: string;
62+
silent?: boolean;
6263
};
6364

6465
export async function login(options?: LoginOptions): Promise<LoginResult> {
6566
return await tracer.startActiveSpan("login", async (span) => {
6667
try {
67-
const opts = { defaultApiUrl: "https://api.trigger.dev", embedded: false, ...options };
68+
const opts = {
69+
defaultApiUrl: "https://api.trigger.dev",
70+
embedded: false,
71+
silent: false,
72+
...options,
73+
};
6874

6975
span.setAttributes({
7076
"cli.config.apiUrl": opts.defaultApiUrl,
@@ -111,7 +117,8 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
111117
skipTelemetry: !span.isRecording(),
112118
logLevel: logger.loggerLevel,
113119
},
114-
true
120+
true,
121+
opts.silent
115122
);
116123

117124
if (!whoAmIResult.success) {

packages/cli-v3/src/commands/update.ts

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function configureUpdateCommand(program: Command) {
4343
const triggerPackageFilter = /^@trigger\.dev/;
4444

4545
export async function updateCommand(dir: string, options: UpdateCommandOptions) {
46-
await updateTriggerPackages(dir, options);
46+
await updateTriggerPackages(dir, options, false);
4747
}
4848

4949
export async function updateTriggerPackages(
@@ -74,7 +74,7 @@ export async function updateTriggerPackages(
7474

7575
const newCliVersion = await updateCheck();
7676

77-
if (newCliVersion) {
77+
if (newCliVersion && !cliVersion.startsWith("0.0.0")) {
7878
prettyWarning(
7979
"You're not running the latest CLI version, please consider updating ASAP",
8080
`Current: ${cliVersion}\nLatest: ${newCliVersion}`,
@@ -127,24 +127,30 @@ export async function updateTriggerPackages(
127127

128128
if (mismatches.length === 0) {
129129
if (!embedded) {
130-
outro(`Nothing to do${newCliVersion ? " ..but you should really update your CLI!" : ""}`);
130+
outro(`Nothing to update${newCliVersion ? " ..but you should really update your CLI!" : ""}`);
131131
return hasOutput;
132132
}
133133
return hasOutput;
134134
}
135135

136-
if (isDowngrade) {
137-
prettyError("Some of the installed @trigger.dev packages are newer than your CLI version");
138-
} else {
139-
prettyWarning(
140-
"Mismatch between your CLI version and installed packages",
141-
"We recommend pinned versions for guaranteed compatibility"
142-
);
136+
if (embedded) {
137+
if (isDowngrade) {
138+
prettyError("Some of the installed @trigger.dev packages are newer than your CLI version");
139+
} else {
140+
if (embedded) {
141+
prettyWarning(
142+
"Mismatch between your CLI version and installed packages",
143+
"We recommend pinned versions for guaranteed compatibility"
144+
);
145+
}
146+
}
143147
}
144148

145149
if (!hasTTY) {
146150
// Running in CI with version mismatch detected
147-
outro("Deploy failed");
151+
if (embedded) {
152+
outro("Deploy failed");
153+
}
148154

149155
console.log(
150156
`ERROR: Version mismatch detected while running in CI. This won't end well. Aborting.
@@ -162,8 +168,7 @@ export async function updateTriggerPackages(
162168
}
163169

164170
// WARNING: We can only start accepting user input once we know this is a TTY, otherwise, the process will exit with an error in CI
165-
166-
if (isDowngrade) {
171+
if (isDowngrade && embedded) {
167172
printUpdateTable("Versions", mismatches, cliVersion, "installed", "CLI");
168173

169174
outro("CLI update required!");
@@ -187,14 +192,20 @@ export async function updateTriggerPackages(
187192

188193
if (!userWantsToUpdate) {
189194
if (requireUpdate) {
190-
outro("You shall not pass!");
191-
192-
logger.log(
193-
`${chalkError(
194-
"X Error:"
195-
)} Update required: Version mismatches are a common source of bugs and errors. Please update or use \`--skip-update-check\` at your own risk.\n`
196-
);
197-
process.exit(1);
195+
if (embedded) {
196+
outro("You shall not pass!");
197+
198+
logger.log(
199+
`${chalkError(
200+
"X Error:"
201+
)} Update required: Version mismatches are a common source of bugs and errors. Please update or use \`--skip-update-check\` at your own risk.\n`
202+
);
203+
process.exit(1);
204+
} else {
205+
outro("No updates applied");
206+
207+
process.exit(0);
208+
}
198209
}
199210

200211
if (!embedded) {
@@ -205,7 +216,7 @@ export async function updateTriggerPackages(
205216
}
206217

207218
const installSpinner = spinner();
208-
installSpinner.start("Writing new package.json file");
219+
installSpinner.start("Updating dependencies in package.json");
209220

210221
// Backup package.json
211222
const packageJsonBackupPath = `${packageJsonPath}.bak`;
@@ -235,12 +246,16 @@ export async function updateTriggerPackages(
235246
const packageManager = await detectPackageManager(projectPath);
236247

237248
try {
238-
installSpinner.message(`Installing new package versions with ${packageManager}`);
249+
installSpinner.message(
250+
`Installing new package versions${packageManager ? ` with ${packageManager.name}` : ""}`
251+
);
239252

240-
await installDependencies({ cwd: projectPath });
253+
await installDependencies({ cwd: projectPath, silent: true });
241254
} catch (error) {
242255
installSpinner.stop(
243-
`Failed to install new package versions${packageManager ? ` with ${packageManager}` : ""}`
256+
`Failed to install new package versions${
257+
packageManager ? ` with ${packageManager.name}` : ""
258+
}`
244259
);
245260

246261
// Remove exit handler in case of failure

packages/cli-v3/src/commands/whoami.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,32 @@ export async function whoAmICommand(options: unknown) {
5151

5252
export async function whoAmI(
5353
options?: WhoamiCommandOptions,
54-
embedded: boolean = false
54+
embedded: boolean = false,
55+
silent: boolean = false
5556
): Promise<WhoAmIResult> {
5657
if (!embedded) {
5758
intro(`Displaying your account details [${options?.profile ?? "default"}]`);
5859
}
5960

6061
const loadingSpinner = spinner();
61-
loadingSpinner.start("Checking your account details");
62+
63+
if (!silent) {
64+
loadingSpinner.start("Checking your account details");
65+
}
6266

6367
const authentication = await isLoggedIn(options?.profile);
6468

6569
if (!authentication.ok) {
6670
if (authentication.error === "fetch failed") {
67-
loadingSpinner.stop("Fetch failed. Platform down?");
71+
!silent && loadingSpinner.stop("Fetch failed. Platform down?");
6872
} else {
6973
if (embedded) {
70-
loadingSpinner.stop(
71-
`Failed to check account details. You may want to run \`trigger.dev logout --profile ${
72-
options?.profile ?? "default"
73-
}\` and try again.`
74-
);
74+
!silent &&
75+
loadingSpinner.stop(
76+
`Failed to check account details. You may want to run \`trigger.dev logout --profile ${
77+
options?.profile ?? "default"
78+
}\` and try again.`
79+
);
7580
} else {
7681
loadingSpinner.stop(
7782
`You must login first. Use \`trigger.dev login --profile ${
@@ -110,7 +115,7 @@ URL: ${chalkLink(authentication.auth.apiUrl)}
110115
`Account details [${authentication.profile}]`
111116
);
112117
} else {
113-
loadingSpinner.stop(`Retrieved your account details for ${userData.data.email}`);
118+
!silent && loadingSpinner.stop(`Retrieved your account details for ${userData.data.email}`);
114119
}
115120

116121
return userData;

packages/cli-v3/src/config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async function resolveConfig(
138138
warn = true
139139
): Promise<ResolvedConfig> {
140140
const packageJsonPath = await resolvePackageJSON(cwd);
141-
const tsconfigPath = await resolveTSConfig(cwd);
141+
const tsconfigPath = await safeResolveTsConfig(cwd);
142142
const lockfilePath = await resolveLockfile(cwd);
143143
const workspaceDir = await findWorkspaceDir(cwd);
144144

@@ -179,7 +179,7 @@ async function resolveConfig(
179179
conditions: [],
180180
},
181181
}
182-
);
182+
) as ResolvedConfig; // TODO: For some reason, without this, there is a weird type error complaining about tsconfigPath being string | nullish, which can't be assigned to string | undefined
183183

184184
return {
185185
...mergedConfig,
@@ -188,6 +188,14 @@ async function resolveConfig(
188188
};
189189
}
190190

191+
async function safeResolveTsConfig(cwd: string) {
192+
try {
193+
return await resolveTSConfig(cwd);
194+
} catch {
195+
return undefined;
196+
}
197+
}
198+
191199
const IGNORED_DIRS = ["node_modules", ".git", "dist", "out", "build"];
192200

193201
async function autoDetectDirs(workingDir: string): Promise<string[]> {

packages/cli-v3/src/utilities/sourceFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function resolveFileSources(
3131
}
3232

3333
await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.configFile);
34-
await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.tsconfig);
34+
await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.tsconfigPath);
3535
await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.packageJsonPath);
3636

3737
return sources;

packages/core/src/v3/build/resolvedConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type ResolvedConfig = Prettify<
2424
packageJsonPath: string;
2525
lockfilePath: string;
2626
configFile?: string;
27+
tsconfigPath?: string;
2728
resolveEnvVars?: ResolveEnvironmentVariablesFunction;
2829
instrumentedPackageNames?: string[];
2930
}

0 commit comments

Comments
 (0)