Skip to content

Commit

Permalink
fix: support nodejs16 env (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus authored Sep 8, 2021
1 parent 508b856 commit 3645519
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kleur from 'kleur';
* @typedef FunctionsConfig
* @type {object} functions
* @property {undefined|string} functions.source
* @property {undefined|'nodejs14'} functions.runtime
* @property {undefined|'nodejs14'|'nodejs16'} functions.runtime
*/

/**
Expand Down Expand Up @@ -333,17 +333,17 @@ function ensureStaticResourceDirsDiffer({source, dest}) {
*/
function ensureCompatibleCloudFunctionVersion({functionsPackageJsonEngine, firebaseJsonFunctionsRuntime}) {
const validPackageJsonValues = [
'14'
// "16"
'14',
'16'
];
const validFirebaseJsonValues = [
'nodejs14'
// 'nodejs16'
'nodejs14',
'nodejs16'
];

if (!validPackageJsonValues.includes(functionsPackageJsonEngine) && !validFirebaseJsonValues.includes(firebaseJsonFunctionsRuntime)) {
logErrorThrow({
why: 'Node.js runtime not supported. SvelteKit on Cloud Functions requires Node.js 14 or newer runtime.',
why: `Node.js runtime not supported. SvelteKit on Cloud Functions requires one of runtime: ${validFirebaseJsonValues}`,
hint: `Set this in "package.json:engines.node" with one of "${validPackageJsonValues}" or "firebase.json:functions.runtime" with one of "${validFirebaseJsonValues}"`,
docs: 'https://firebase.google.com/docs/functions/manage-functions#set_nodejs_version',
hintCode: 1061
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,18 @@ test(
);

// EnsureCompatibleCloudFunctionVersion
test('Valid Function runtime version in package.json', () => {
test('Valid Function runtime (nodejs14) version in package.json', () => {
assert.not.throws(() => ensureCompatibleCloudFunctionVersion({functionsPackageJsonEngine: '14'}));
});
test('Valid Function runtime version in firebase.json', () => {
test('Valid Function runtime (nodejs14) version in firebase.json', () => {
assert.not.throws(() => ensureCompatibleCloudFunctionVersion({firebaseJsonFunctionsRuntime: 'nodejs14'}));
});
test('Valid Function runtime (nodejs16) version in package.json', () => {
assert.not.throws(() => ensureCompatibleCloudFunctionVersion({functionsPackageJsonEngine: '16'}));
});
test('Valid Function runtime (nodejs16) version in firebase.json', () => {
assert.not.throws(() => ensureCompatibleCloudFunctionVersion({firebaseJsonFunctionsRuntime: 'nodejs16'}));
});

test(
'No Function runtime provided',
Expand Down

0 comments on commit 3645519

Please sign in to comment.