Skip to content

Commit 0561e69

Browse files
committed
Fix build
1 parent 17fcef2 commit 0561e69

4 files changed

Lines changed: 45 additions & 29 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"fix:clang": "node scripts/clang-format.mjs --fix",
2525
"build": "yarn clean && yarn build:lib && yarn build:bindings:configure && yarn build:bindings",
2626
"build:lib": "tsc",
27-
"build:copy-binary": "node -e \"const { copyBinary } = require('.'); copyBinary();\"",
27+
"build:copy-binary": "node -e \"const { copyBinary } = require('./lib/copy-binary.js'); copyBinary();\"",
2828
"build:bindings:configure": "node-gyp configure",
2929
"build:bindings:configure:arm64": "node-gyp configure --arch=arm64 --target_arch=arm64",
3030
"build:bindings": "yarn build:lib && node-gyp build && yarn build:copy-binary",

src/copy-binary.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable no-console */
2+
import * as fs from 'node:fs';
3+
import * as path from 'node:path';
4+
import { identifier } from './identifier';
5+
6+
const source = path.join(__dirname, '..', 'build', 'Release', 'stack-trace.node');
7+
const target = path.join(__dirname, '..', 'lib', `stack-trace-${identifier}.node`);
8+
9+
/**
10+
* Copies the compiled binary from the build directory to the lib directory with the correct name based on the current platform and Node version.
11+
*
12+
* @hidden We only use this for copying the binary after building, it is not intended to be used by end users.
13+
*/
14+
export function copyBinary(): void {
15+
const build = path.resolve(__dirname, '..', 'lib');
16+
if (!fs.existsSync(build)) {
17+
fs.mkdirSync(build, { recursive: true });
18+
}
19+
20+
if (!fs.existsSync(source)) {
21+
console.log('Source file does not exist:', source);
22+
process.exit(1);
23+
} else {
24+
if (fs.existsSync(target)) {
25+
console.log('Target file already exists, overwriting it');
26+
fs.unlinkSync(target);
27+
}
28+
console.log('Copying', source, 'to', target);
29+
fs.copyFileSync(source, target);
30+
}
31+
}

src/identifier.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import * as os from 'node:os';
3+
import { versions } from 'node:process';
4+
import * as libc from 'detect-libc';
5+
import { getAbi } from 'node-abi';
6+
7+
const stdlib = libc.familySync();
8+
const platform = process.env['BUILD_PLATFORM'] || os.platform();
9+
const arch = process.env['BUILD_ARCH'] || os.arch();
10+
const abi = getAbi(versions.node, 'node');
11+
12+
export const identifier = [platform, arch, stdlib, abi].filter(c => c !== undefined && c !== null).join('-');

src/index.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-console */
22
import type { AsyncLocalStorage } from 'node:async_hooks';
33
import { spawnSync } from 'node:child_process';
4-
import * as fs from 'node:fs';
54
import * as os from 'node:os';
65
import * as path from 'node:path';
76
import { env, versions } from 'node:process';
87
import { threadId } from 'node:worker_threads';
98
import * as libc from 'detect-libc';
109
import { getAbi } from 'node-abi';
10+
import { copyBinary } from './copy-binary';
1111

1212
const stdlib = libc.familySync();
1313
const platform = process.env['BUILD_PLATFORM'] || os.platform();
@@ -56,33 +56,6 @@ interface Native {
5656
getThreadsLastSeen(): Record<string, number>;
5757
}
5858

59-
/**
60-
* Copies the compiled binary from the build directory to the lib directory with the correct name based on the current platform and Node version.
61-
*
62-
* @hidden We only use this for copying the binary after building, it is not intended to be used by end users.
63-
*/
64-
export function copyBinary(): void {
65-
const build = path.resolve(__dirname, '..', 'lib');
66-
if (!fs.existsSync(build)) {
67-
fs.mkdirSync(build, { recursive: true });
68-
}
69-
70-
if (!fs.existsSync(source)) {
71-
console.log('Source file does not exist:', source);
72-
process.exit(1);
73-
} else {
74-
if (fs.existsSync(target)) {
75-
console.log('Target file already exists, overwriting it');
76-
fs.unlinkSync(target);
77-
}
78-
console.log('Copying', source, 'to', target);
79-
fs.copyFileSync(source, target);
80-
}
81-
}
82-
83-
const source = path.join(__dirname, '..', 'build', 'Release', 'stack-trace.node');
84-
const target = path.join(__dirname, '..', 'lib', `stack-trace-${identifier}.node`);
85-
8659
function clean(err: Buffer): string {
8760
return err.toString().trim();
8861
}

0 commit comments

Comments
 (0)