1
1
import { intro , log , outro , spinner } from "@clack/prompts" ;
2
2
import { depot } from "@depot/cli" ;
3
3
import { context , trace } from "@opentelemetry/api" ;
4
- import { ResolvedConfig , detectDependencyVersion , flattenAttributes , recordSpanException } from "@trigger.dev/core/v3" ;
4
+ import {
5
+ ResolvedConfig ,
6
+ detectDependencyVersion ,
7
+ flattenAttributes ,
8
+ recordSpanException ,
9
+ } from "@trigger.dev/core/v3" ;
5
10
import chalk from "chalk" ;
6
11
import { Command , Option as CommandOption } from "commander" ;
7
12
import { Metafile , build } from "esbuild" ;
@@ -29,7 +34,7 @@ import {
29
34
import { readConfig } from "../utilities/configFiles.js" ;
30
35
import { createTempDir , readJSONFile , writeJSONFile } from "../utilities/fileSystem" ;
31
36
import { printStandloneInitialBanner } from "../utilities/initialBanner.js" ;
32
- import { detectPackageNameFromImportPath } from "../utilities/installPackages" ;
37
+ import { detectPackageNameFromImportPath , parsePackageName } from "../utilities/installPackages" ;
33
38
import { logger } from "../utilities/logger.js" ;
34
39
import { createTaskFileImports , gatherTaskFiles } from "../utilities/taskFiles" ;
35
40
import { login } from "./login" ;
@@ -63,11 +68,7 @@ export function configureDeployCommand(program: Command) {
63
68
"prod"
64
69
)
65
70
. option ( "-T, --skip-typecheck" , "Whether to skip the pre-build typecheck" )
66
- . option (
67
- "-c, --config <config file>" ,
68
- "The name of the config file, found at [path]" ,
69
- "trigger.config.mjs"
70
- )
71
+ . option ( "-c, --config <config file>" , "The name of the config file, found at [path]" )
71
72
. option (
72
73
"-p, --project-ref <project ref>" ,
73
74
"The project ref. Required if there is no config file."
@@ -134,7 +135,11 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
134
135
135
136
intro ( "Deploying project" ) ;
136
137
137
- const authorization = await login ( { embedded : true , defaultApiUrl : options . apiUrl , profile : options . profile } ) ;
138
+ const authorization = await login ( {
139
+ embedded : true ,
140
+ defaultApiUrl : options . apiUrl ,
141
+ profile : options . profile ,
142
+ } ) ;
138
143
139
144
if ( ! authorization . ok ) {
140
145
if ( authorization . error === "fetch failed" ) {
@@ -228,7 +233,8 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
228
233
const deploymentSpinner = spinner ( ) ;
229
234
230
235
deploymentSpinner . start ( `Deploying version ${ version } ` ) ;
231
- const registryHost = deploymentResponse . data . registryHost ?? options . registry ?? "registry.trigger.dev" ;
236
+ const registryHost =
237
+ deploymentResponse . data . registryHost ?? options . registry ?? "registry.trigger.dev" ;
232
238
233
239
const buildImage = async ( ) => {
234
240
if ( options . selfHosted ) {
@@ -345,7 +351,8 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
345
351
) ;
346
352
} else {
347
353
outro (
348
- `Version ${ version } deployed with ${ taskCount } detected task${ taskCount === 1 ? "" : "s"
354
+ `Version ${ version } deployed with ${ taskCount } detected task${
355
+ taskCount === 1 ? "" : "s"
349
356
} ${ deploymentLink } `
350
357
) ;
351
358
}
@@ -515,14 +522,14 @@ type BuildAndPushImageOptions = {
515
522
516
523
type BuildAndPushImageResults =
517
524
| {
518
- ok : true ;
519
- image : string ;
520
- digest ?: string ;
521
- }
525
+ ok : true ;
526
+ image : string ;
527
+ digest ?: string ;
528
+ }
522
529
| {
523
- ok : false ;
524
- error : string ;
525
- } ;
530
+ ok : false ;
531
+ error : string ;
532
+ } ;
526
533
527
534
async function buildAndPushImage (
528
535
options : BuildAndPushImageOptions
@@ -774,12 +781,12 @@ async function compileProject(
774
781
775
782
workerContents = workerContents . replace (
776
783
"__IMPORTED_PROJECT_CONFIG__" ,
777
- `import importedConfig from "${ configPath } ";`
784
+ `import * as importedConfigExports from "${ configPath } "; const importedConfig = importedConfigExports.config; const handleError = importedConfigExports.handleError ;`
778
785
) ;
779
786
} else {
780
787
workerContents = workerContents . replace (
781
788
"__IMPORTED_PROJECT_CONFIG__" ,
782
- `const importedConfig = undefined;`
789
+ `const importedConfig = undefined; const handleError = undefined; `
783
790
) ;
784
791
}
785
792
@@ -919,8 +926,7 @@ async function compileProject(
919
926
920
927
// Get all the required dependencies from the metaOutputs and save them to /tmp/dir/package.json
921
928
const allImports = [ ...metaOutput . imports , ...entryPointMetaOutput . imports ] ;
922
- const projectPackageJson = await readJSONFile ( join ( config . projectDir , "package.json" ) ) ;
923
- const dependencies = gatherRequiredDependencies ( allImports , projectPackageJson ) ;
929
+ const dependencies = await gatherRequiredDependencies ( allImports , config ) ;
924
930
925
931
const packageJsonContents = {
926
932
name : "trigger-worker" ,
@@ -1141,10 +1147,12 @@ async function typecheckProject(config: ResolvedConfig, options: DeployCommandOp
1141
1147
1142
1148
// Returns the dependencies that are required by the output that are found in output and the CLI package dependencies
1143
1149
// Returns the dependency names and the version to use (taken from the CLI deps package.json)
1144
- function gatherRequiredDependencies (
1150
+ async function gatherRequiredDependencies (
1145
1151
imports : Metafile [ "outputs" ] [ string ] [ "imports" ] ,
1146
- externalPackageJson ?: { dependencies : Record < string , string > }
1152
+ config : ResolvedConfig
1147
1153
) {
1154
+ const externalPackageJson = await readJSONFile ( join ( config . projectDir , "package.json" ) ) ;
1155
+
1148
1156
const dependencies : Record < string , string > = { } ;
1149
1157
1150
1158
for ( const file of imports ) {
@@ -1165,15 +1173,44 @@ function gatherRequiredDependencies(
1165
1173
continue ;
1166
1174
}
1167
1175
1168
- const internalDependencyVersion = ( packageJson . dependencies as Record < string , string > ) [
1169
- packageName
1170
- ] ?? detectDependencyVersion ( packageName ) ;
1176
+ const internalDependencyVersion =
1177
+ ( packageJson . dependencies as Record < string , string > ) [ packageName ] ??
1178
+ detectDependencyVersion ( packageName ) ;
1171
1179
1172
1180
if ( internalDependencyVersion ) {
1173
1181
dependencies [ packageName ] = internalDependencyVersion ;
1174
1182
}
1175
1183
}
1176
1184
1185
+ if ( config . additionalPackages ) {
1186
+ for ( const packageName of config . additionalPackages ) {
1187
+ if ( dependencies [ packageName ] ) {
1188
+ continue ;
1189
+ }
1190
+
1191
+ const packageParts = parsePackageName ( packageName ) ;
1192
+
1193
+ if ( packageParts . version ) {
1194
+ dependencies [ packageParts . name ] = packageParts . version ;
1195
+ continue ;
1196
+ } else {
1197
+ const externalDependencyVersion = {
1198
+ ...externalPackageJson ?. devDependencies ,
1199
+ ...externalPackageJson ?. dependencies ,
1200
+ } [ packageName ] ;
1201
+
1202
+ if ( externalDependencyVersion ) {
1203
+ dependencies [ packageParts . name ] = externalDependencyVersion ;
1204
+ continue ;
1205
+ } else {
1206
+ logger . warn (
1207
+ `Could not find version for package ${ packageName } , add a version specifier to the package name (e.g. ${ packageParts . name } @latest) or add it to your project's package.json`
1208
+ ) ;
1209
+ }
1210
+ }
1211
+ }
1212
+ }
1213
+
1177
1214
// Make sure we sort the dependencies by key to ensure consistent hashing
1178
1215
return Object . fromEntries ( Object . entries ( dependencies ) . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) ) ) ;
1179
1216
}
0 commit comments