diff --git a/.changeset/clever-buses-watch.md b/.changeset/clever-buses-watch.md new file mode 100644 index 0000000000..a2cc1065de --- /dev/null +++ b/.changeset/clever-buses-watch.md @@ -0,0 +1,6 @@ +--- +"trigger.dev": patch +"@trigger.dev/core": patch +--- + +Fix an issue where a missing tsconfig.json file would throw an error on dev/deploy diff --git a/.changeset/soft-ladybugs-promise.md b/.changeset/soft-ladybugs-promise.md new file mode 100644 index 0000000000..68eafd4563 --- /dev/null +++ b/.changeset/soft-ladybugs-promise.md @@ -0,0 +1,5 @@ +--- +"trigger.dev": patch +--- + +Fixes for CLI update command, and make the hide the "whoami" command output when running in dev. diff --git a/.changeset/twelve-onions-decide.md b/.changeset/twelve-onions-decide.md new file mode 100644 index 0000000000..8d33f8341c --- /dev/null +++ b/.changeset/twelve-onions-decide.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/build": patch +--- + +Strip out TRIGGER\_ keys when using syncEnvVars, to prevent deploy errors diff --git a/packages/build/src/extensions/core/syncEnvVars.ts b/packages/build/src/extensions/core/syncEnvVars.ts index f0a0ac5dc1..231bdb86f0 100644 --- a/packages/build/src/extensions/core/syncEnvVars.ts +++ b/packages/build/src/extensions/core/syncEnvVars.ts @@ -63,6 +63,8 @@ const UNSYNCABLE_ENV_VARS = [ "_", ]; +const UNSYNCABLE_ENV_VARS_PREFIXES = ["TRIGGER_"]; + export type SyncEnvVarsFunction = (params: SyncEnvVarsParams) => SyncEnvVarsResult; export type SyncEnvVarsOptions = { @@ -98,6 +100,11 @@ export function syncEnvVars(fn: SyncEnvVarsFunction, options?: SyncEnvVarsOption return acc; } + // Strip out any TRIGGER_ prefix env vars + if (UNSYNCABLE_ENV_VARS_PREFIXES.some((prefix) => key.startsWith(prefix))) { + return acc; + } + acc[key] = value; return acc; }, diff --git a/packages/cli-v3/src/commands/dev.ts b/packages/cli-v3/src/commands/dev.ts index 55f1f41123..da82bc9078 100644 --- a/packages/cli-v3/src/commands/dev.ts +++ b/packages/cli-v3/src/commands/dev.ts @@ -51,6 +51,7 @@ export async function devCommand(options: DevCommandOptions) { const authorization = await login({ embedded: true, + silent: true, defaultApiUrl: options.apiUrl, profile: options.profile, }); diff --git a/packages/cli-v3/src/commands/login.ts b/packages/cli-v3/src/commands/login.ts index f4aa318f72..67e136c771 100644 --- a/packages/cli-v3/src/commands/login.ts +++ b/packages/cli-v3/src/commands/login.ts @@ -59,12 +59,18 @@ export type LoginOptions = { defaultApiUrl?: string; embedded?: boolean; profile?: string; + silent?: boolean; }; export async function login(options?: LoginOptions): Promise { return await tracer.startActiveSpan("login", async (span) => { try { - const opts = { defaultApiUrl: "https://api.trigger.dev", embedded: false, ...options }; + const opts = { + defaultApiUrl: "https://api.trigger.dev", + embedded: false, + silent: false, + ...options, + }; span.setAttributes({ "cli.config.apiUrl": opts.defaultApiUrl, @@ -111,7 +117,8 @@ export async function login(options?: LoginOptions): Promise { skipTelemetry: !span.isRecording(), logLevel: logger.loggerLevel, }, - true + true, + opts.silent ); if (!whoAmIResult.success) { diff --git a/packages/cli-v3/src/commands/update.ts b/packages/cli-v3/src/commands/update.ts index c8262da2f2..d6d1bb75cf 100644 --- a/packages/cli-v3/src/commands/update.ts +++ b/packages/cli-v3/src/commands/update.ts @@ -43,7 +43,7 @@ export function configureUpdateCommand(program: Command) { const triggerPackageFilter = /^@trigger\.dev/; export async function updateCommand(dir: string, options: UpdateCommandOptions) { - await updateTriggerPackages(dir, options); + await updateTriggerPackages(dir, options, false); } export async function updateTriggerPackages( @@ -74,7 +74,7 @@ export async function updateTriggerPackages( const newCliVersion = await updateCheck(); - if (newCliVersion) { + if (newCliVersion && !cliVersion.startsWith("0.0.0")) { prettyWarning( "You're not running the latest CLI version, please consider updating ASAP", `Current: ${cliVersion}\nLatest: ${newCliVersion}`, @@ -127,24 +127,30 @@ export async function updateTriggerPackages( if (mismatches.length === 0) { if (!embedded) { - outro(`Nothing to do${newCliVersion ? " ..but you should really update your CLI!" : ""}`); + outro(`Nothing to update${newCliVersion ? " ..but you should really update your CLI!" : ""}`); return hasOutput; } return hasOutput; } - if (isDowngrade) { - prettyError("Some of the installed @trigger.dev packages are newer than your CLI version"); - } else { - prettyWarning( - "Mismatch between your CLI version and installed packages", - "We recommend pinned versions for guaranteed compatibility" - ); + if (embedded) { + if (isDowngrade) { + prettyError("Some of the installed @trigger.dev packages are newer than your CLI version"); + } else { + if (embedded) { + prettyWarning( + "Mismatch between your CLI version and installed packages", + "We recommend pinned versions for guaranteed compatibility" + ); + } + } } if (!hasTTY) { // Running in CI with version mismatch detected - outro("Deploy failed"); + if (embedded) { + outro("Deploy failed"); + } console.log( `ERROR: Version mismatch detected while running in CI. This won't end well. Aborting. @@ -162,8 +168,7 @@ export async function updateTriggerPackages( } // 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 - - if (isDowngrade) { + if (isDowngrade && embedded) { printUpdateTable("Versions", mismatches, cliVersion, "installed", "CLI"); outro("CLI update required!"); @@ -187,14 +192,20 @@ export async function updateTriggerPackages( if (!userWantsToUpdate) { if (requireUpdate) { - outro("You shall not pass!"); - - logger.log( - `${chalkError( - "X Error:" - )} Update required: Version mismatches are a common source of bugs and errors. Please update or use \`--skip-update-check\` at your own risk.\n` - ); - process.exit(1); + if (embedded) { + outro("You shall not pass!"); + + logger.log( + `${chalkError( + "X Error:" + )} Update required: Version mismatches are a common source of bugs and errors. Please update or use \`--skip-update-check\` at your own risk.\n` + ); + process.exit(1); + } else { + outro("No updates applied"); + + process.exit(0); + } } if (!embedded) { @@ -205,7 +216,7 @@ export async function updateTriggerPackages( } const installSpinner = spinner(); - installSpinner.start("Writing new package.json file"); + installSpinner.start("Updating dependencies in package.json"); // Backup package.json const packageJsonBackupPath = `${packageJsonPath}.bak`; @@ -235,12 +246,16 @@ export async function updateTriggerPackages( const packageManager = await detectPackageManager(projectPath); try { - installSpinner.message(`Installing new package versions with ${packageManager}`); + installSpinner.message( + `Installing new package versions${packageManager ? ` with ${packageManager.name}` : ""}` + ); - await installDependencies({ cwd: projectPath }); + await installDependencies({ cwd: projectPath, silent: true }); } catch (error) { installSpinner.stop( - `Failed to install new package versions${packageManager ? ` with ${packageManager}` : ""}` + `Failed to install new package versions${ + packageManager ? ` with ${packageManager.name}` : "" + }` ); // Remove exit handler in case of failure diff --git a/packages/cli-v3/src/commands/whoami.ts b/packages/cli-v3/src/commands/whoami.ts index 73c740c94b..f4451da363 100644 --- a/packages/cli-v3/src/commands/whoami.ts +++ b/packages/cli-v3/src/commands/whoami.ts @@ -51,27 +51,32 @@ export async function whoAmICommand(options: unknown) { export async function whoAmI( options?: WhoamiCommandOptions, - embedded: boolean = false + embedded: boolean = false, + silent: boolean = false ): Promise { if (!embedded) { intro(`Displaying your account details [${options?.profile ?? "default"}]`); } const loadingSpinner = spinner(); - loadingSpinner.start("Checking your account details"); + + if (!silent) { + loadingSpinner.start("Checking your account details"); + } const authentication = await isLoggedIn(options?.profile); if (!authentication.ok) { if (authentication.error === "fetch failed") { - loadingSpinner.stop("Fetch failed. Platform down?"); + !silent && loadingSpinner.stop("Fetch failed. Platform down?"); } else { if (embedded) { - loadingSpinner.stop( - `Failed to check account details. You may want to run \`trigger.dev logout --profile ${ - options?.profile ?? "default" - }\` and try again.` - ); + !silent && + loadingSpinner.stop( + `Failed to check account details. You may want to run \`trigger.dev logout --profile ${ + options?.profile ?? "default" + }\` and try again.` + ); } else { loadingSpinner.stop( `You must login first. Use \`trigger.dev login --profile ${ @@ -110,7 +115,7 @@ URL: ${chalkLink(authentication.auth.apiUrl)} `Account details [${authentication.profile}]` ); } else { - loadingSpinner.stop(`Retrieved your account details for ${userData.data.email}`); + !silent && loadingSpinner.stop(`Retrieved your account details for ${userData.data.email}`); } return userData; diff --git a/packages/cli-v3/src/config.ts b/packages/cli-v3/src/config.ts index 5e284572d4..6cab7dd45e 100644 --- a/packages/cli-v3/src/config.ts +++ b/packages/cli-v3/src/config.ts @@ -138,7 +138,7 @@ async function resolveConfig( warn = true ): Promise { const packageJsonPath = await resolvePackageJSON(cwd); - const tsconfigPath = await resolveTSConfig(cwd); + const tsconfigPath = await safeResolveTsConfig(cwd); const lockfilePath = await resolveLockfile(cwd); const workspaceDir = await findWorkspaceDir(cwd); @@ -179,7 +179,7 @@ async function resolveConfig( conditions: [], }, } - ); + ) 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 return { ...mergedConfig, @@ -188,6 +188,14 @@ async function resolveConfig( }; } +async function safeResolveTsConfig(cwd: string) { + try { + return await resolveTSConfig(cwd); + } catch { + return undefined; + } +} + const IGNORED_DIRS = ["node_modules", ".git", "dist", "out", "build"]; async function autoDetectDirs(workingDir: string): Promise { diff --git a/packages/cli-v3/src/utilities/sourceFiles.ts b/packages/cli-v3/src/utilities/sourceFiles.ts index 556e5d8e57..b0b976ff8f 100644 --- a/packages/cli-v3/src/utilities/sourceFiles.ts +++ b/packages/cli-v3/src/utilities/sourceFiles.ts @@ -31,7 +31,7 @@ export async function resolveFileSources( } await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.configFile); - await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.tsconfig); + await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.tsconfigPath); await resolveConfigSource(sources, resolvedConfig.workingDir, resolvedConfig.packageJsonPath); return sources; diff --git a/packages/core/src/v3/build/resolvedConfig.ts b/packages/core/src/v3/build/resolvedConfig.ts index 9aa249a5ff..674a7fce14 100644 --- a/packages/core/src/v3/build/resolvedConfig.ts +++ b/packages/core/src/v3/build/resolvedConfig.ts @@ -24,6 +24,7 @@ export type ResolvedConfig = Prettify< packageJsonPath: string; lockfilePath: string; configFile?: string; + tsconfigPath?: string; resolveEnvVars?: ResolveEnvironmentVariablesFunction; instrumentedPackageNames?: string[]; }