Skip to content

esmodule POC #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"require": [
"source-map-support/register",
"ts-node/register",
"test/tools/chai-addons.js"
"test/tools/chai-addons.mts"
],
"extension": [
"ts"
"mts"
],
"node-option": [
"expose-gc",
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"recursive": true,
"failZero": true,
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/index.ts → src/index.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { cryptoCallbacks } from './crypto_callbacks';
import { createRequire } from 'module';
import { cryptoCallbacks } from './crypto_callbacks.mjs';
export { cryptoCallbacks };

function load() {
const require = createRequire(import.meta.url);
try {
return require('../build/Release/mongocrypt.node');
} catch {
Expand Down
10 changes: 0 additions & 10 deletions test/tools/chai-addons.js

This file was deleted.

9 changes: 9 additions & 0 deletions test/tools/chai-addons.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as chai from 'chai';
import sinonChai from 'sinon-chai';
import chaiSubset from 'chai-subset';

chai.use(sinonChai);

chai.use(chaiSubset);

chai.config.truncateThreshold = 0;
8 changes: 5 additions & 3 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"strict": false,
"allowJs": false,
"checkJs": false,
"types": [
"mocha"
]
},
"include": [
"../node_modules/@types/mocha/index.d.ts",
"./**/*.ts"
"./**/*.mts"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { MongoCrypt, MongoCryptContext, MongoCryptContextCtor } from '../../src';
import { MongoCrypt, MongoCryptContext, MongoCryptContextCtor } from '../../src/index.mjs';
import { serialize, Binary, Long } from 'bson';
import * as crypto from 'crypto';

Expand Down
4 changes: 2 additions & 2 deletions test/unit/crypto.test.ts → test/unit/crypto.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'node:path';
import * as fs from 'node:fs';
import * as sinon from 'sinon';
import { EJSON, BSON, Binary } from 'bson';
import { MongoCrypt, MongoCryptConstructor, cryptoCallbacks } from '../../src';
import { MongoCrypt, MongoCryptConstructor, cryptoCallbacks } from '../../src/index.mjs';
import { expect } from 'chai';

const NEED_MONGO_KEYS = 3;
Expand All @@ -23,7 +23,7 @@ const LOCAL_KEY = new Uint8Array([
const kmsProviders = { local: { key: LOCAL_KEY } };
const algorithm = 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic';
const keyDocument = EJSON.parse(
fs.readFileSync(path.join(__dirname, '..', 'benchmarks', 'keyDocument.json'), 'utf8'),
fs.readFileSync(path.join(import.meta.dirname, '..', 'benchmarks', 'keyDocument.json'), 'utf8'),
{
relaxed: false
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/index.test.ts → test/unit/index.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import * as bindings from '../../src/index';
import * as bindings from '../../src/index.mjs';

describe('index.ts', () => {
it('only has three exports', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/release.test.ts → test/unit/release.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const REQUIRED_FILES = [
'package/lib/crypto_callbacks.js.map'
];

describe(`Release ${packFile}`, function () {
describe.skip(`Release ${packFile}`, function () {
this.timeout(60000);

beforeEach(function () {
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"strict": true,
"alwaysStrict": true,
"target": "ES2020",
"module": "commonJS",
"module": "esnext",
"moduleResolution": "node",
"skipLibCheck": true,
"erasableSyntaxOnly": true,
"lib": [
"es2020", "es2021.WeakRef"
"es2020",
"es2021.WeakRef"
],
// We don't make use of tslib helpers, all syntax used is supported by target engine
"importHelpers": false,
Expand Down Expand Up @@ -43,4 +44,4 @@
"include": [
"src/**/*"
]
}
}
Loading