Skip to content

Commit b5ecd06

Browse files
committed
Fixes for CLI update command, and make the hide the "whoami" command output when running in dev
1 parent 74c2076 commit b5ecd06

File tree

5 files changed

+67
-33
lines changed

5 files changed

+67
-33
lines changed

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

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: 38 additions & 22 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(
@@ -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.
@@ -187,14 +193,20 @@ export async function updateTriggerPackages(
187193

188194
if (!userWantsToUpdate) {
189195
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);
196+
if (embedded) {
197+
outro("You shall not pass!");
198+
199+
logger.log(
200+
`${chalkError(
201+
"X Error:"
202+
)} Update required: Version mismatches are a common source of bugs and errors. Please update or use \`--skip-update-check\` at your own risk.\n`
203+
);
204+
process.exit(1);
205+
} else {
206+
outro("No updates applied");
207+
208+
process.exit(0);
209+
}
198210
}
199211

200212
if (!embedded) {
@@ -205,7 +217,7 @@ export async function updateTriggerPackages(
205217
}
206218

207219
const installSpinner = spinner();
208-
installSpinner.start("Writing new package.json file");
220+
installSpinner.start("Updating dependencies in package.json");
209221

210222
// Backup package.json
211223
const packageJsonBackupPath = `${packageJsonPath}.bak`;
@@ -235,12 +247,16 @@ export async function updateTriggerPackages(
235247
const packageManager = await detectPackageManager(projectPath);
236248

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

240-
await installDependencies({ cwd: projectPath });
254+
await installDependencies({ cwd: projectPath, silent: true });
241255
} catch (error) {
242256
installSpinner.stop(
243-
`Failed to install new package versions${packageManager ? ` with ${packageManager}` : ""}`
257+
`Failed to install new package versions${
258+
packageManager ? ` with ${packageManager.name}` : ""
259+
}`
244260
);
245261

246262
// 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;

0 commit comments

Comments
 (0)