@@ -672,6 +672,14 @@ export class FunctionsEmulator implements EmulatorInstance {
672
672
disabled_features : this . args . disabledRuntimeFeatures ,
673
673
} ;
674
674
}
675
+ /**
676
+ * Returns a node major version ("10", "8") or null
677
+ * @param frb the current Functions Runtime Bundle
678
+ */
679
+ getRequestedNodeRuntimeVersion ( frb : FunctionsRuntimeBundle ) : string | undefined {
680
+ const pkg = require ( path . join ( frb . cwd , "package.json" ) ) ;
681
+ return frb . nodeMajorVersion || ( pkg . engines && pkg . engines . node ) ;
682
+ }
675
683
/**
676
684
* Returns the path to a "node" executable to use.
677
685
* @param cwd the directory to checkout for a package.json file.
@@ -707,24 +715,24 @@ export class FunctionsEmulator implements EmulatorInstance {
707
715
// Will happen if we haven't asked about local version yet
708
716
}
709
717
710
- // If the requested version is the same as the host , let's use that
711
- if ( requestedMajorVersion === hostMajorVersion ) {
718
+ // If the requested version is already locally available , let's use that
719
+ if ( requestedMajorVersion === localMajorVersion ) {
712
720
this . logger . logLabeled (
713
721
"SUCCESS" ,
714
722
"functions" ,
715
- `Using node@${ requestedMajorVersion } from host .`
723
+ `Using node@${ requestedMajorVersion } from local cache .`
716
724
) ;
717
- return process . execPath ;
725
+ return localNodePath ;
718
726
}
719
727
720
- // If the requested version is already locally available , let's use that
721
- if ( localMajorVersion === requestedMajorVersion ) {
728
+ // If the requested version is the same as the host , let's use that
729
+ if ( requestedMajorVersion === hostMajorVersion ) {
722
730
this . logger . logLabeled (
723
731
"SUCCESS" ,
724
732
"functions" ,
725
- `Using node@${ requestedMajorVersion } from local cache .`
733
+ `Using node@${ requestedMajorVersion } from host .`
726
734
) ;
727
- return localNodePath ;
735
+ return process . execPath ;
728
736
}
729
737
730
738
// Otherwise we'll begin the conversational flow to install the correct version locally
@@ -750,8 +758,16 @@ export class FunctionsEmulator implements EmulatorInstance {
750
758
}
751
759
752
760
if ( this . args . debugPort ) {
753
- const { host } = this . getInfo ( ) ;
754
- args . unshift ( `--inspect=${ host } :${ this . args . debugPort } ` ) ;
761
+ if ( process . env . FIREPIT_VERSION && process . execPath == opts . nodeBinary ) {
762
+ const requestedMajorNodeVersion = this . getRequestedNodeRuntimeVersion ( frb ) ;
763
+ this . logger . log (
764
+ "WARN" ,
765
+ `To enable function inspection, please run "${ process . execPath } is:npm i node@${ requestedMajorNodeVersion } --save-dev" in your functions directory`
766
+ ) ;
767
+ } else {
768
+ const { host } = this . getInfo ( ) ;
769
+ args . unshift ( `--inspect=${ host } :${ this . args . debugPort } ` ) ;
770
+ }
755
771
}
756
772
757
773
const childProcess = spawn ( opts . nodeBinary , args , {
0 commit comments