-
Notifications
You must be signed in to change notification settings - Fork 981
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?
Changes from all commits
a1e9632
c766fe1
9978b2d
4d9bb59
a9ef6b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ var path = require("path"); | |
|
||
var npmDependencies = require("./npm-dependencies"); | ||
var { prompt } = require("../../../prompt"); | ||
var utils = require("../../../utils"); | ||
const { isValidRuntime } = require("../../../deploy/functions/runtimes/index"); | ||
|
||
var TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/typescript/"); | ||
var PACKAGE_LINTING_TEMPLATE = fs.readFileSync( | ||
|
@@ -38,13 +40,13 @@ module.exports = function (setup, config) { | |
'npm --prefix "$RESOURCE_DIR" run build', | ||
]); | ||
return config | ||
.askWriteProjectFile("functions/package.json", PACKAGE_LINTING_TEMPLATE) | ||
.askWriteProjectFile("functions/package.json", getPackage(true)) | ||
.then(function () { | ||
return config.askWriteProjectFile("functions/.eslintrc.js", ESLINT_TEMPLATE); | ||
}); | ||
} | ||
_.set(setup, "config.functions.predeploy", 'npm --prefix "$RESOURCE_DIR" run build'); | ||
return config.askWriteProjectFile("functions/package.json", PACKAGE_NO_LINTING_TEMPLATE); | ||
return config.askWriteProjectFile("functions/package.json", getPackage(false)); | ||
}) | ||
.then(function () { | ||
return config.askWriteProjectFile("functions/tsconfig.json", TSCONFIG_TEMPLATE); | ||
|
@@ -64,3 +66,18 @@ 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @taeold I was thinking of using 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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 Tiny bug I'd watch out for is that something like |
||
if (!isValidRuntime(`nodejs${nodeEngineVersion}`)) { | ||
utils.logWarning(`Node ${nodeEngineVersion} is no longer supported in Google Cloud Functions.`); | ||
utils.logWarning( | ||
"See https://firebase.google.com/docs/functions/manage-functions for more details" | ||
); | ||
} | ||
|
||
if (useLint) { | ||
return PACKAGE_LINTING_TEMPLATE.replace(/{{NODE_VERSION}}/g, nodeEngineVersion); | ||
} | ||
return PACKAGE_NO_LINTING_TEMPLATE.replace(/{{NODE_VERSION}}/g, nodeEngineVersion); | ||
} |
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 likeThere 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()
fromutils
to warn users of deprecated Node versions (like this code below):firebase-tools/src/accountImporter.js
Lines 163 to 166 in f413eb9
In that case, should I keep it that way?