@@ -4,7 +4,7 @@ import childProcess from "child_process";
44import chokidar from "chokidar" ;
55import fs from "fs/promises" ;
66import ngrok from "ngrok" ;
7- import { run as ncuRun } from "npm-check-updates" ;
7+ import run , { run as ncuRun } from "npm-check-updates" ;
88import ora , { Ora } from "ora" ;
99import pRetry , { AbortError } from "p-retry" ;
1010import pathModule from "path" ;
@@ -22,6 +22,8 @@ import { resolvePath } from "../utils/parseNameAndPath";
2222import { RequireKeys } from "../utils/requiredKeys" ;
2323import { Throttle } from "../utils/throttle" ;
2424import { TriggerApi } from "../utils/triggerApi" ;
25+ import { standardWatchIgnoreRegex , standardWatchFilePaths } from "../frameworks/watchConfig" ;
26+ import { JsRuntime , getJsRuntime } from "../utils/jsRuntime" ;
2527import { wait } from "../utils/wait" ;
2628
2729const asyncExecFile = util . promisify ( childProcess . execFile ) ;
@@ -45,6 +47,7 @@ const formattedDate = new Intl.DateTimeFormat("en", {
4547 second : "numeric" ,
4648} ) ;
4749
50+ let runtime : JsRuntime ;
4851export async function devCommand ( path : string , anyOptions : any ) {
4952 telemetryClient . dev . started ( path , anyOptions ) ;
5053
@@ -57,12 +60,12 @@ export async function devCommand(path: string, anyOptions: any) {
5760 const options = result . data ;
5861
5962 const resolvedPath = resolvePath ( path ) ;
60-
63+ runtime = await getJsRuntime ( resolvedPath , logger ) ;
6164 //check for outdated packages, don't await this
62- checkForOutdatedPackages ( resolvedPath ) ;
65+ runtime . checkForOutdatedPackages ( ) ;
6366
6467 // Read from package.json to get the endpointId
65- const endpointId = await getEndpointIdFromPackageJson ( resolvedPath , options ) ;
68+ const endpointId = await getEndpointId ( runtime , options ) ;
6669 if ( ! endpointId ) {
6770 logger . error (
6871 "You must run the `init` command first to setup the project – you are missing \n'trigger.dev': { 'endpointId': 'your-client-id' } from your package.json file, or pass in the --client-id option to this command"
@@ -73,8 +76,8 @@ export async function devCommand(path: string, anyOptions: any) {
7376 logger . success ( `✔️ [trigger.dev] Detected TriggerClient id: ${ endpointId } ` ) ;
7477
7578 //resolve the options using the detected framework (use default if there isn't a matching framework)
76- const packageManager = await getUserPackageManager ( resolvedPath ) ;
77- const framework = await getFramework ( resolvedPath , packageManager ) ;
79+ const packageManager = await runtime . getUserPackageManager ( ) ;
80+ const framework = await runtime . getFramework ( ) ;
7881 const resolvedOptions = await resolveOptions ( framework , resolvedPath , options ) ;
7982
8083 // Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL
@@ -170,6 +173,7 @@ async function refresh(options: RefreshOptions) {
170173 return ;
171174 }
172175
176+ const refreshedEndpointId = await getEndpointId ( runtime , resolvedOptions ) ;
173177 const { apiKey, apiUrl } = apiDetails ;
174178 const apiClient = new TriggerApi ( apiKey , apiUrl ) ;
175179
@@ -396,43 +400,10 @@ async function verifyEndpoint(
396400 return ;
397401}
398402
399- export async function checkForOutdatedPackages ( path : string ) {
400- const updates = ( await ncuRun ( {
401- packageFile : `${ path } /package.json` ,
402- filter : "/trigger.dev/.+$/" ,
403- upgrade : false ,
404- } ) ) as {
405- [ key : string ] : string ;
406- } ;
407-
408- if ( typeof updates === "undefined" || Object . keys ( updates ) . length === 0 ) {
409- return ;
410- }
411-
412- const packageFile = await fs . readFile ( `${ path } /package.json` ) ;
413- const data = JSON . parse ( Buffer . from ( packageFile ) . toString ( "utf8" ) ) ;
414- const dependencies = data . dependencies ;
415- console . log ( chalk . bgYellow ( "Updates available for trigger.dev packages" ) ) ;
416- console . log ( chalk . bgBlue ( "Run npx @trigger.dev/cli@latest update" ) ) ;
417-
418- for ( let dep in updates ) {
419- console . log ( `${ dep } ${ dependencies [ dep ] } → ${ updates [ dep ] } ` ) ;
420- }
421- }
422-
423- export async function getEndpointIdFromPackageJson ( path : string , options : DevCommandOptions ) {
403+ export function getEndpointId ( runtime : JsRuntime , options : DevCommandOptions ) {
424404 if ( options . clientId ) {
425405 return options . clientId ;
426- }
427-
428- const pkgJsonPath = pathModule . join ( path , "package.json" ) ;
429- const pkgBuffer = await fs . readFile ( pkgJsonPath ) ;
430- const pkgJson = JSON . parse ( pkgBuffer . toString ( ) ) ;
431-
432- const value = pkgJson [ "trigger.dev" ] ?. endpointId ;
433- if ( ! value || typeof value !== "string" ) return ;
434-
435- return value as string ;
406+ } else return runtime . getEndpointId ( ) ;
436407}
437408
438409async function resolveEndpointUrl ( apiUrl : string , port : number , hostname : string ) {
0 commit comments