Skip to content

Commit 55b6a32

Browse files
committed
feat: conversion to ESM
1 parent 4cda5f0 commit 55b6a32

39 files changed

+925
-425
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"message": "Use `globalThis` instead"
3939
}
4040
],
41+
"prefer-rest-params": 0,
4142
"require-yield": 0,
4243
"eqeqeq": ["error", "smart"],
4344
"spaced-comment": [

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ npm install
471471
# build the dist
472472
npm run build
473473
# run the repl (this allows you to import from ./src)
474-
npm run ts-node
474+
npm run tsx
475475
# run the tests
476476
npm run test
477477
# lint the source code

benches/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
import fs from 'fs';
44
import path from 'path';
5+
import url from 'url';
56
import si from 'systeminformation';
67

8+
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
9+
710
async function main(): Promise<void> {
8-
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
11+
await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true });
912
const resultFilenames = await fs.promises.readdir(
10-
path.join(__dirname, 'results'),
13+
path.join(dirname, 'results'),
1114
);
1215
const metricsFile = await fs.promises.open(
13-
path.join(__dirname, 'results', 'metrics.txt'),
16+
path.join(dirname, 'results', 'metrics.txt'),
1417
'w',
1518
);
1619
let concatenating = false;
1720
for (const resultFilename of resultFilenames) {
1821
if (/.+_metrics\.txt$/.test(resultFilename)) {
1922
const metricsData = await fs.promises.readFile(
20-
path.join(__dirname, 'results', resultFilename),
23+
path.join(dirname, 'results', resultFilename),
2124
);
2225
if (concatenating) {
2326
await metricsFile.write('\n');
@@ -33,7 +36,7 @@ async function main(): Promise<void> {
3336
system: 'model, manufacturer',
3437
});
3538
await fs.promises.writeFile(
36-
path.join(__dirname, 'results', 'system.json'),
39+
path.join(dirname, 'results', 'system.json'),
3740
JSON.stringify(systemData, null, 2),
3841
);
3942
}

benches/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './utils';
1+
export * from './utils.js';

benches/utils/utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import url from 'url';
34
import b from 'benny';
45
import { codeBlock } from 'common-tags';
56
import packageJson from '../../package.json';
67

8+
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
9+
710
const suiteCommon = [
811
b.cycle(),
912
b.complete(),
1013
b.save({
1114
file: (summary) => summary.name,
12-
folder: path.join(__dirname, '../results'),
15+
folder: path.join(dirname, '../results'),
1316
version: packageJson.version,
1417
details: true,
1518
}),
1619
b.save({
1720
file: (summary) => summary.name,
18-
folder: path.join(__dirname, '../results'),
21+
folder: path.join(dirname, '../results'),
1922
version: packageJson.version,
2023
format: 'chart.html',
2124
}),
2225
b.complete((summary) => {
2326
const filePath = path.join(
24-
__dirname,
27+
dirname,
2528
'../results',
2629
summary.name + '_metrics.txt',
2730
);

jest.config.js renamed to jest.config.mjs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
const path = require('path');
2-
const { pathsToModuleNameMapper } = require('ts-jest');
3-
const { compilerOptions } = require('./tsconfig');
1+
import path from 'node:path';
2+
import url from 'node:url';
3+
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
44

5-
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, {
6-
prefix: '<rootDir>/src/',
7-
});
5+
const projectPath = path.dirname(url.fileURLToPath(import.meta.url));
86

97
// Global variables that are shared across the jest worker pool
108
// These variables must be static and serializable
119
const globals = {
1210
// Absolute directory to the project root
13-
projectDir: __dirname,
11+
projectDir: projectPath,
1412
// Absolute directory to the test root
15-
testDir: path.join(__dirname, 'tests'),
13+
testDir: path.join(projectPath, 'tests'),
1614
// Default asynchronous test timeout
1715
defaultTimeout: 20000,
1816
// Timeouts rely on setTimeout which takes 32 bit numbers
@@ -24,7 +22,7 @@ const globals = {
2422
// They can however receive the process environment
2523
// Use `process.env` to set variables
2624

27-
module.exports = {
25+
const config = {
2826
testEnvironment: 'node',
2927
verbose: true,
3028
collectCoverage: false,
@@ -40,10 +38,10 @@ module.exports = {
4038
parser: {
4139
syntax: "typescript",
4240
tsx: true,
43-
decorators: compilerOptions.experimentalDecorators,
41+
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
4442
dynamicImport: true,
4543
},
46-
target: compilerOptions.target.toLowerCase(),
44+
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
4745
keepClassNames: true,
4846
},
4947
}
@@ -77,5 +75,10 @@ module.exports = {
7775
'jest-extended/all',
7876
'<rootDir>/tests/setupAfterEnv.ts'
7977
],
80-
moduleNameMapper: moduleNameMapper,
78+
moduleNameMapper: {
79+
"^(\\.{1,2}/.*)\\.js$": "$1",
80+
},
81+
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
8182
};
83+
84+
export default config;

0 commit comments

Comments
 (0)