Skip to content

Commit

Permalink
Validate node version is >=18
Browse files Browse the repository at this point in the history
for actual-app/api

This was done as part of actualbudget#1903
  • Loading branch information
Marethyu1 committed Nov 28, 2023
1 parent c462604 commit 57d25e5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ export * as methods from './methods';
export * from './methods';
export * as utils from './utils';

function validateNodeVersion() {
if (process?.versions?.node) {
const nodeVersion = process?.versions?.node;
const majorVersionString = nodeVersion.split('.')[0];
const majorVersionNumber = parseInt(majorVersionString);
if (majorVersionNumber < 18) {
throw new Error(
`@actual-app/api requires a node version >= 18. Found that you are using: ${nodeVersion}. Please upgrade to a higher version`,
);
}
}
}

export async function init(config = {}) {
if (actualApp) {
return;
}

validateNodeVersion();

global.fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));

Expand Down

0 comments on commit 57d25e5

Please sign in to comment.