Skip to content
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

Use readFileSync to load package json instead of createRequire #130

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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