Skip to content

Commit

Permalink
Expose version property in public API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lovell committed May 1, 2024
1 parent 4e95635 commit 92dc899
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path');
const { version } = require('./package.json');

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

Expand All @@ -7,6 +8,7 @@ module.exports = {
include_dir: includeDir,
gyp: path.join(includeDir, 'node_api.gyp:nothing'), // deprecated.
targets: path.join(includeDir, 'node_addon_api.gyp'),
version,
isNodeApiBuiltin: true,
needsFlag: false
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@
"fs-extra": "^11.1.1",
"path": "^0.12.7",
"pre-commit": "^1.2.2",
"safe-buffer": "^5.1.1"
"safe-buffer": "^5.1.1",
"semver": "^7.6.0"
},
"directories": {},
"gypfile": false,
Expand Down
19 changes: 19 additions & 0 deletions test/exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const { strictEqual } = require('assert');
const { valid } = require('semver');

const nodeAddonApi = require('../');

module.exports = function test () {
strictEqual(nodeAddonApi.include.startsWith('"'), true);
strictEqual(nodeAddonApi.include.endsWith('"'), true);
strictEqual(nodeAddonApi.include.includes('node-addon-api'), true);
strictEqual(nodeAddonApi.include_dir, '');
strictEqual(nodeAddonApi.gyp, 'node_api.gyp:nothing');
strictEqual(nodeAddonApi.targets, 'node_addon_api.gyp');
strictEqual(valid(nodeAddonApi.version), true);
strictEqual(nodeAddonApi.version, require('../package.json').version);
strictEqual(nodeAddonApi.isNodeApiBuiltin, true);
strictEqual(nodeAddonApi.needsFlag, false);
};
2 changes: 1 addition & 1 deletion tools/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (!dir) {
process.exit(1);
}

const NodeApiVersion = require('../package.json').version;
const NodeApiVersion = require('../').version;

const disable = args[1];
let ConfigFileOperations;
Expand Down

0 comments on commit 92dc899

Please sign in to comment.