Skip to content
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

ESM Migration #68

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
"jest": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
],
"plugins": [
"import"
],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"import"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"linebreak-style": ["error", "unix"],
"no-empty": 1,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run ts-node
npm run tsx
# run the tests
npm run test
# lint the source code
Expand Down
4 changes: 2 additions & 2 deletions benches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
import DB1KiB from './db_1KiB';
import DB1MiB from './db_1MiB';
import DB1KiB from './db_1KiB.js';
import DB1MiB from './db_1MiB.js';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
Expand Down
27 changes: 15 additions & 12 deletions jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
const path = require('path');
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');
import path from 'node:path';
import url from 'node:url';
import tsconfigJSON from './tsconfig.json' assert { type: "json" };

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

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

module.exports = {
const config = {
testEnvironment: 'node',
verbose: true,
collectCoverage: false,
Expand All @@ -40,10 +38,10 @@ module.exports = {
parser: {
syntax: "typescript",
tsx: true,
decorators: compilerOptions.experimentalDecorators,
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
dynamicImport: true,
},
target: compilerOptions.target.toLowerCase(),
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
keepClassNames: true,
},
}
Expand Down Expand Up @@ -77,5 +75,10 @@ module.exports = {
'jest-extended/all',
'<rootDir>/tests/setupAfterEnv.ts'
],
moduleNameMapper: moduleNameMapper,
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
};

export default config;
Loading