Skip to content

Commit ba9d52e

Browse files
committed
Fix Node v18
1 parent 6e54459 commit ba9d52e

File tree

6 files changed

+38
-36
lines changed

6 files changed

+38
-36
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
"types": "lib/index.d.ts",
66
"license": "MIT",
77
"scripts": {
8-
"install": "node scripts/check-build.js",
8+
"install": "node scripts/check-build.mjs",
99
"lint": "yarn lint:eslint && yarn lint:clang",
1010
"lint:eslint": "eslint . --format stylish",
11-
"lint:clang": "node scripts/clang-format.js",
11+
"lint:clang": "node scripts/clang-format.mjs",
1212
"fix": "yarn fix:eslint && yarn fix:clang",
1313
"fix:eslint": "eslint . --format stylish --fix",
14-
"fix:clang": "node scripts/clang-format.js --fix",
14+
"fix:clang": "node scripts/clang-format.mjs --fix",
1515
"build": "yarn build:lib && yarn build:bindings:configure && yarn build:bindings",
1616
"build:lib": "tsc",
1717
"build:bindings:configure": "node-gyp configure",
1818
"build:bindings:configure:arm64": "node-gyp configure --arch=arm64 --target_arch=arm64",
19-
"build:bindings": "node-gyp build && node scripts/copy-target.js",
20-
"build:bindings:arm64": "node-gyp build --arch=arm64 && node scripts/copy-target.js",
19+
"build:bindings": "node-gyp build && node scripts/copy-target.mjs",
20+
"build:bindings:arm64": "node-gyp build --arch=arm64 && node scripts/copy-target.mjs",
2121
"build:dev": "yarn clean && yarn build:bindings:configure && yarn build",
2222
"build:tarball": "npm pack",
2323
"clean": "node-gyp clean && rm -rf lib && rm -rf build",
@@ -45,8 +45,8 @@
4545
"/module.cc",
4646
"/binding.gyp",
4747
"package.json",
48-
"/scripts/binaries.js",
49-
"/scripts/check-build.js",
50-
"/scripts/copy-target.js"
48+
"/scripts/binaries.mjs",
49+
"/scripts/check-build.mjs",
50+
"/scripts/copy-target.mjs"
5151
]
52-
}
52+
}

scripts/binaries.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/binaries.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import libc from 'detect-libc';
2+
import * as abi from 'node-abi';
3+
import os from 'os';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
export function getModuleName() {
10+
const stdlib = libc.familySync();
11+
const platform = process.env['BUILD_PLATFORM'] || os.platform();
12+
const arch = process.env['BUILD_ARCH'] || os.arch();
13+
const identifier = [platform, arch, stdlib, abi.getAbi(process.versions.node, 'node')].filter(Boolean).join('-');
14+
return `stack-trace-${identifier}.node`;
15+
}
16+
17+
export const source = path.join(__dirname, '..', 'build', 'Release', 'stack-trace.node');
18+
export const target = path.join(__dirname, '..', 'lib', getModuleName());

scripts/check-build.js renamed to scripts/check-build.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const fs = require('fs');
2-
const child_process = require('child_process');
3-
const binaries = require('./binaries.js');
1+
import fs from 'fs';
2+
import child_process from 'child_process';
3+
import * as binaries from './binaries.mjs';
44

55
function clean(err) {
66
return err.toString().trim();
@@ -32,7 +32,7 @@ function recompileFromSource() {
3232

3333
if (fs.existsSync(binaries.target)) {
3434
try {
35-
require(binaries.target);
35+
await import(binaries.target);
3636
console.log('Precompiled binary found, skipping build from source.');
3737
} catch (e) {
3838
console.log('Precompiled binary found but failed loading');

scripts/clang-format.js renamed to scripts/clang-format.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const child_process = require('child_process');
1+
import child_process from 'child_process';
22

33
const args = ['--Werror', '-i', '--style=file', 'module.cc'];
44
const cmd = `./node_modules/.bin/clang-format ${args.join(' ')}`;

scripts/copy-target.js renamed to scripts/copy-target.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const binaries = require('./binaries.js');
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
import * as binaries from './binaries.mjs';
5+
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
47

58
const build = path.resolve(__dirname, '..', 'lib');
69
if (!fs.existsSync(build)) {

0 commit comments

Comments
 (0)