Skip to content

Commit

Permalink
Make sure paths code is run in NodeJS context
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Nov 19, 2020
1 parent 3f98022 commit 7a61d2d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/scripts/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function getBinaryName() {
const platform = process.platform;
const arch = process.arch;
const nodeV8CppApiVersion = process.versions.modules;
if (!process) throw new NotNodeJsError("global object");
if (!platform) throw new NotNodeJsError("process.platform");
if (!arch) throw new NotNodeJsError("process.arch");
if (!process.versions.modules)
throw new NotNodeJsError("process.versions.modules");

return [platform, arch, nodeV8CppApiVersion, "binding.node"].join("-");
}
Expand All @@ -40,3 +45,11 @@ export function ensureDirFromFilepath(filepath: string) {
fs.mkdirSync(dirpath, { recursive: true });
}
}

export class NotNodeJsError extends Error {
constructor(missingItem: string) {
super(
`BLST bindings loader should only run in a NodeJS context: ${missingItem}`
);
}
}

0 comments on commit 7a61d2d

Please sign in to comment.