Skip to content

Commit 23bb42b

Browse files
authored
Expose version property in public API (#1479)
This value is already used in the conversion tooling and is useful in external contexts too, for example when specifying/detecting node-addon-api as an optional peer dependency. Also adds test expectations for all exported properties.
1 parent c0af9f7 commit 23bb42b

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const { version } = require('./package.json');
23

34
const includeDir = path.relative('.', __dirname);
45

@@ -7,6 +8,7 @@ module.exports = {
78
include_dir: includeDir,
89
gyp: path.join(includeDir, 'node_api.gyp:nothing'), // deprecated.
910
targets: path.join(includeDir, 'node_addon_api.gyp'),
11+
version,
1012
isNodeApiBuiltin: true,
1113
needsFlag: false
1214
};

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@
431431
"fs-extra": "^11.1.1",
432432
"path": "^0.12.7",
433433
"pre-commit": "^1.2.2",
434-
"safe-buffer": "^5.1.1"
434+
"safe-buffer": "^5.1.1",
435+
"semver": "^7.6.0"
435436
},
436437
"directories": {},
437438
"gypfile": false,

test/exports.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const { strictEqual } = require('assert');
4+
const { valid } = require('semver');
5+
6+
const nodeAddonApi = require('../');
7+
8+
module.exports = function test () {
9+
strictEqual(nodeAddonApi.include.startsWith('"'), true);
10+
strictEqual(nodeAddonApi.include.endsWith('"'), true);
11+
strictEqual(nodeAddonApi.include.includes('node-addon-api'), true);
12+
strictEqual(nodeAddonApi.include_dir, '');
13+
strictEqual(nodeAddonApi.gyp, 'node_api.gyp:nothing');
14+
strictEqual(nodeAddonApi.targets, 'node_addon_api.gyp');
15+
strictEqual(valid(nodeAddonApi.version), true);
16+
strictEqual(nodeAddonApi.version, require('../package.json').version);
17+
strictEqual(nodeAddonApi.isNodeApiBuiltin, true);
18+
strictEqual(nodeAddonApi.needsFlag, false);
19+
};

tools/conversion.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!dir) {
1212
process.exit(1);
1313
}
1414

15-
const NodeApiVersion = require('../package.json').version;
15+
const NodeApiVersion = require('../').version;
1616

1717
const disable = args[1];
1818
let ConfigFileOperations;

0 commit comments

Comments
 (0)