@@ -3,7 +3,7 @@ import childProcess from "child_process";
33import chokidar from "chokidar" ;
44import fs from "fs/promises" ;
55import ngrok from "ngrok" ;
6- import { run as ncuRun } from "npm-check-updates" ;
6+ import run , { run as ncuRun } from "npm-check-updates" ;
77import ora , { Ora } from "ora" ;
88import pathModule from "path" ;
99import util from "util" ;
@@ -19,6 +19,7 @@ import { resolvePath } from "../utils/parseNameAndPath";
1919import { RequireKeys } from "../utils/requiredKeys" ;
2020import { TriggerApi } from "../utils/triggerApi" ;
2121import { standardWatchIgnoreRegex , standardWatchFilePaths } from "../frameworks/watchConfig" ;
22+ import { JsRuntime , getJsRuntime } from "../utils/jsRuntime" ;
2223
2324const asyncExecFile = util . promisify ( childProcess . execFile ) ;
2425
@@ -41,6 +42,7 @@ const formattedDate = new Intl.DateTimeFormat("en", {
4142 second : "numeric" ,
4243} ) ;
4344
45+ let runtime : JsRuntime ;
4446export async function devCommand ( path : string , anyOptions : any ) {
4547 telemetryClient . dev . started ( path , anyOptions ) ;
4648
@@ -53,12 +55,12 @@ export async function devCommand(path: string, anyOptions: any) {
5355 const options = result . data ;
5456
5557 const resolvedPath = resolvePath ( path ) ;
56-
58+ runtime = await getJsRuntime ( resolvedPath , logger ) ;
5759 //check for outdated packages, don't await this
58- checkForOutdatedPackages ( resolvedPath ) ;
60+ runtime . checkForOutdatedPackages ( ) ;
5961
6062 // Read from package.json to get the endpointId
61- const endpointId = await getEndpointIdFromPackageJson ( resolvedPath , options ) ;
63+ const endpointId = await getEndpointId ( runtime , options ) ;
6264 if ( ! endpointId ) {
6365 logger . error (
6466 "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"
@@ -69,8 +71,8 @@ export async function devCommand(path: string, anyOptions: any) {
6971 logger . success ( `✔️ [trigger.dev] Detected TriggerClient id: ${ endpointId } ` ) ;
7072
7173 //resolve the options using the detected framework (use default if there isn't a matching framework)
72- const packageManager = await getUserPackageManager ( resolvedPath ) ;
73- const framework = await getFramework ( resolvedPath , packageManager ) ;
74+ const packageManager = await runtime . getUserPackageManager ( ) ;
75+ const framework = await runtime . getFramework ( ) ;
7476 const resolvedOptions = await resolveOptions ( framework , resolvedPath , options ) ;
7577
7678 // Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL
@@ -115,7 +117,7 @@ export async function devCommand(path: string, anyOptions: any) {
115117 const refresh = async ( ) => {
116118 connectingSpinner . start ( ) ;
117119
118- const refreshedEndpointId = await getEndpointIdFromPackageJson ( resolvedPath , resolvedOptions ) ;
120+ const refreshedEndpointId = await getEndpointId ( runtime , resolvedOptions ) ;
119121
120122 // Read from env file to get the TRIGGER_API_KEY and TRIGGER_API_URL
121123 const apiDetails = await getTriggerApiDetails ( resolvedPath , envFile ) ;
@@ -304,43 +306,10 @@ async function verifyEndpoint(
304306 return ;
305307}
306308
307- export async function checkForOutdatedPackages ( path : string ) {
308- const updates = ( await ncuRun ( {
309- packageFile : `${ path } /package.json` ,
310- filter : "/trigger.dev/.+$/" ,
311- upgrade : false ,
312- } ) ) as {
313- [ key : string ] : string ;
314- } ;
315-
316- if ( typeof updates === "undefined" || Object . keys ( updates ) . length === 0 ) {
317- return ;
318- }
319-
320- const packageFile = await fs . readFile ( `${ path } /package.json` ) ;
321- const data = JSON . parse ( Buffer . from ( packageFile ) . toString ( "utf8" ) ) ;
322- const dependencies = data . dependencies ;
323- console . log ( chalk . bgYellow ( "Updates available for trigger.dev packages" ) ) ;
324- console . log ( chalk . bgBlue ( "Run npx @trigger.dev/cli@latest update" ) ) ;
325-
326- for ( let dep in updates ) {
327- console . log ( `${ dep } ${ dependencies [ dep ] } → ${ updates [ dep ] } ` ) ;
328- }
329- }
330-
331- export async function getEndpointIdFromPackageJson ( path : string , options : DevCommandOptions ) {
309+ export function getEndpointId ( runtime : JsRuntime , options : DevCommandOptions ) {
332310 if ( options . clientId ) {
333311 return options . clientId ;
334- }
335-
336- const pkgJsonPath = pathModule . join ( path , "package.json" ) ;
337- const pkgBuffer = await fs . readFile ( pkgJsonPath ) ;
338- const pkgJson = JSON . parse ( pkgBuffer . toString ( ) ) ;
339-
340- const value = pkgJson [ "trigger.dev" ] ?. endpointId ;
341- if ( ! value || typeof value !== "string" ) return ;
342-
343- return value as string ;
312+ } else return runtime . getEndpointId ( ) ;
344313}
345314
346315async function resolveEndpointUrl ( apiUrl : string , port : number , hostname : string ) {
0 commit comments