Skip to content

Commit

Permalink
Merge pull request #130 from superfaceai/feat/load_package_json_using…
Browse files Browse the repository at this point in the history
…_fs_read_file

Use readFileSync to load package json instead of createRequire
  • Loading branch information
freaz committed Feb 19, 2024
2 parents 6591447 + 5b8e6cd commit 1d087f7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/nodejs_host/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs, { FileHandle } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { readFileSync } from 'node:fs';
import { resolve as resolvePath } from 'node:path';
import process from 'node:process';
import { WASI } from 'node:wasi';
Expand All @@ -20,7 +20,6 @@ import {
} from './common/index.js';
import { fetchErrorToHostError, systemErrorToWasiError } from './error.js';

const pkg = createRequire(import.meta.url)('../package.json');
function corePathURL(): URL {
return new URL('../assets/core-async.wasm', import.meta.url);
}
Expand Down Expand Up @@ -234,12 +233,14 @@ class InternalClient {
private app: App;
private readyState: AsyncMutex<{ ready: boolean }>;
private readonly fileSystem: NodeFileSystem;
private readonly pkg: { version: string };

constructor(readonly options: ClientOptions = {}) {
if (options.assetsPath !== undefined) {
this.assetsPath = options.assetsPath;
}

this.pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), { encoding: 'utf8' }));
this.readyState = new AsyncMutex({ ready: false });
this.fileSystem = new NodeFileSystem();

Expand Down Expand Up @@ -351,7 +352,7 @@ class InternalClient {
const platform = process.platform;
const arch = process.arch;
const nodeVersion = process.version;
const version = pkg.version;
const version = this.pkg.version;

return `one-sdk-nodejs/${version} (${platform} ${arch}) node.js/${nodeVersion}`;
}
Expand Down

0 comments on commit 1d087f7

Please sign in to comment.