Skip to content

Commit

Permalink
engine: update package json importer
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Dec 17, 2024
1 parent a053528 commit fb670c0
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions packages/engine-multi/src/util/load-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { Versions } from '../types';

const pkg = JSON.parse(
fs.readFileSync(
path.join(fileURLToPath(import.meta.url), '../../package.json'),
'utf-8'
)
);
let pkg: any;

// Load key versions at init time
const versions = {
node: process.version.substring(1),
engine: pkg.version,
compiler: pkg.dependencies?.['@openfn/compiler'],
runtime: pkg.dependencies?.['@openfn/runtime'],
};
function getPkg(): any {
if (!pkg) {
let nextPath = path.dirname(fileURLToPath(import.meta.url));
while (nextPath) {
const pkgPath = path.resolve(nextPath, 'package.json');
try {
fs.statSync(pkgPath);
nextPath = pkgPath;
break;
} catch (e) {
nextPath = path.dirname(nextPath);
}
}

pkg = JSON.parse(fs.readFileSync(nextPath, 'utf-8'));
}
return pkg;
}

// Return a shallow clone of versions
// because each workflow will scribble to it
export default (): Versions => ({ ...versions });
export default (): Versions => {
const pkg = getPkg();
return {
node: process.version.substring(1),
engine: pkg.version,
compiler: pkg.dependencies?.['@openfn/compiler'],
runtime: pkg.dependencies?.['@openfn/runtime'],
};
};

0 comments on commit fb670c0

Please sign in to comment.