Skip to content

Commit d23c287

Browse files
authored
Provide def file for windows import lib (#17)
1 parent 8a0be91 commit d23c287

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

.github/workflows/sync-headers.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
VERSION=${COMMIT_MESSAGE##* }
2727
echo $COMMIT_MESSAGE
2828
npm run --silent write-symbols
29+
npm run --silent write-win32-def
2930
CHANGED_FILES=$(git diff --name-only)
3031
BRANCH_NAME="update-headers/${VERSION}"
3132
if [ -z "$CHANGED_FILES" ]; then

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
},
4848
"scripts": {
4949
"update-headers": "node --no-warnings scripts/update-headers.js",
50-
"write-symbols": "node --no-warnings scripts/write-symbols.js"
50+
"write-symbols": "node --no-warnings scripts/write-symbols.js",
51+
"write-win32-def": "node --no-warnings scripts/write-win32-def.js"
5152
},
5253
"version": "0.0.4",
5354
"support": true
5455
}
55-

scripts/write-win32-def.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const { resolve: resolvePath } = require('path');
4+
const { writeFile } = require('fs/promises');
5+
const { symbols } = require('..');
6+
7+
function getNodeApiDef() {
8+
const symbolsSet = new Set();
9+
for (const ver of Object.values(symbols)) {
10+
for (const sym of ver.node_api_symbols) {
11+
symbolsSet.add(sym);
12+
}
13+
for (const sym of ver.js_native_api_symbols) {
14+
symbolsSet.add(sym);
15+
}
16+
}
17+
return 'NAME NODE.EXE\nEXPORTS\n' + Array.from(symbolsSet).join('\n');
18+
}
19+
20+
function getJsNativeApiDef() {
21+
const symbolsSet = new Set();
22+
for (const ver of Object.values(symbols)) {
23+
for (const sym of ver.js_native_api_symbols) {
24+
symbolsSet.add(sym);
25+
}
26+
}
27+
return 'NAME NODE.EXE\nEXPORTS\n' + Array.from(symbolsSet).join('\n');
28+
}
29+
30+
async function main() {
31+
const nodeApiDefPath = resolvePath(__dirname, '../node_api.def');
32+
console.log(`Writing Windows .def file to ${nodeApiDefPath}`);
33+
await writeFile(nodeApiDefPath, getNodeApiDef());
34+
35+
const jsNativeApiDefPath = resolvePath(__dirname, '../js_native_api.def');
36+
console.log(`Writing Windows .def file to ${jsNativeApiDefPath}`);
37+
await writeFile(jsNativeApiDefPath, getJsNativeApiDef());
38+
}
39+
40+
main().catch(e => {
41+
console.error(e);
42+
process.exitCode = 1;
43+
});

0 commit comments

Comments
 (0)