-
Notifications
You must be signed in to change notification settings - Fork 979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically validate & set engines.node
in package.json
on firebase init functions
#3894
base: master
Are you sure you want to change the base?
Conversation
When running `firebase init functions`, the generated `package.json` file will have the value of `engines.node` attribute dynamically set to the Node.js version on dev's machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start! Thanks for your contribution.
Can we also do the same trick for JS template in addition to typescript template?
@@ -6,6 +6,7 @@ var path = require("path"); | |||
|
|||
var npmDependencies = require("./npm-dependencies"); | |||
var { prompt } = require("../../../prompt"); | |||
var utils = require("../../../utils"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are only using getNodeVersionString
, I think it make sense to do something like
var { getNodeVersionString} = require("../../../utils");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to use logWarning()
from utils
to warn users of deprecated Node versions (like this code below):
firebase-tools/src/accountImporter.js
Lines 163 to 166 in f413eb9
if (!options.hashAlgo) { | |
utils.logWarning("No hash algorithm specified. Password users cannot be imported."); | |
return { valid: true }; | |
} |
In that case, should I keep it that way?
@@ -64,3 +65,11 @@ module.exports = function (setup, config) { | |||
return npmDependencies.askInstallDependencies(setup.functions, config); | |||
}); | |||
}; | |||
|
|||
function getPackage(useLint) { | |||
const nodeEngineVersion = utils.getNodeVersionString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do we ever check that the user's node version is one supported by Google Cloud Functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taeold I was thinking of using isDeprecatedRuntime()
to check for deprecated node version and utils.logWarning()
to display the warning message. Something like this:
if (isDeprecatedRuntime(`nodejs${nodeEngineVersion}`)) {
utils.logWarning("Your Node version is not supported in Google Cloud Functions.");
}
If it's good enough, I'll go ahead and update the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Tiny bug I'd watch out for is that something like nodejs13
, which is not supported by Google Cloud Functions, may pass the isDeprecatedRuntime()
check. You might to throw in isValidRuntime
check somewhere in the code.
Sure! I'll do the same thing for JS template after I'm done with the Typescript one. |
Hi @taeold, I just wanna circle back to this PR and see if it's still on your radar. Let me know if minor changes need to be made. |
Description
Fix #3407
This PR should help the
engines.node
attribute inpackage.json
file dynamically set to the current Node.js version on a dev's machine. If their Node.js version is not supported by Google Cloud Functions, an error will be logged.For example, if the Node.js version on a dev's machine is 12. After running
firebase init functions
, the generatedpackage.json
file should contain thess lines:If the Node.js version is no longer supported in Google Cloud Functions, a warning will be displayed after
firebase init functions
:Scenarios Tested
package.json
with ESLint for Typescript & Javascriptpackage.json
without ESLint for Typescript & Javascript