Skip to content

Commit 9f2bd47

Browse files
feat(NODE-7167)!: specify napi version of 9 (#87)
1 parent 9b8025f commit 9f2bd47

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

addon/zstd.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "zstd.h"
22

3+
#define NAPI_VERSION 9
4+
35
#include <napi.h>
46

57
#include <vector>
@@ -49,9 +51,17 @@ void Decompress(const CallbackInfo& info) {
4951
worker->Queue();
5052
}
5153

54+
Value GetDefinedNapiVersion(const CallbackInfo& info) {
55+
return Napi::String::New(info.Env(), std::to_string(NAPI_VERSION));
56+
}
57+
5258
Object Init(Env env, Object exports) {
5359
exports.Set(String::New(env, "compress"), Function::New(env, Compress));
5460
exports.Set(String::New(env, "decompress"), Function::New(env, Decompress));
61+
62+
exports.Set(String::New(env, "getDefinedNapiVersion"),
63+
Function::New(env, GetDefinedNapiVersion));
64+
5565
return exports;
5666
}
5767

lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exports.compress = async function compress(data, compressionLevel) {
3939
throw new Error(`zstd: ${e.message}`);
4040
}
4141
};
42+
4243
exports.decompress = async function decompress(data) {
4344
if (!isUint8Array(data)) {
4445
throw new TypeError(`parameter 'data' must be a Uint8Array.`);
@@ -49,3 +50,6 @@ exports.decompress = async function decompress(data) {
4950
throw new Error(`zstd: ${e.message}`);
5051
}
5152
};
53+
54+
/** used for testing */
55+
exports.getDefinedNapiVersion = zstd.getDefinedNapiVersion;

package-lock.json

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"binding.gyp"
1212
],
1313
"dependencies": {
14-
"node-addon-api": "^4.3.0",
14+
"node-addon-api": "^8.5.0",
1515
"prebuild-install": "^7.1.3"
1616
},
1717
"license": "Apache-2.0",
@@ -49,7 +49,7 @@
4949
},
5050
"binary": {
5151
"napi_versions": [
52-
4
52+
9
5353
]
5454
},
5555
"mongodb:zstd_version": "1.5.6"

test/bundling/webpack/install_zstd.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { execSync } = require('node:child_process');
42
const { readFileSync } = require('node:fs');
53
const { resolve } = require('node:path');
@@ -19,6 +17,6 @@ console.log(`zstd Version: ${zstdVersion}`);
1917

2018
xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: zstdRoot });
2119

22-
xtrace(`npm install --no-save mongodb-js-zstd-${zstdVersion}.tgz`);
20+
xtrace(`npm install --ignore-scripts --no-save mongodb-js-zstd-${zstdVersion}.tgz`);
2321

2422
console.log('zstd installed!');

test/index.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { test } = require('mocha');
2-
const { compress, decompress } = require('../lib/index');
2+
const { compress, decompress, getDefinedNapiVersion } = require('../lib/index');
33

44
const { expect } = require('chai');
55

@@ -55,6 +55,12 @@ describe('compress', function () {
5555
});
5656
});
5757

58+
describe('misc', function () {
59+
test('getDefinedNapiVersion() returns 9', function () {
60+
expect(getDefinedNapiVersion()).to.equal('9');
61+
});
62+
});
63+
5864
/**
5965
* @param {import('../index').decompress} decompress
6066
* @param {import('../index').compress} compress

0 commit comments

Comments
 (0)