Skip to content

Commit

Permalink
feat: migrated to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed May 15, 2024
1 parent 620ea7b commit 8a616ab
Show file tree
Hide file tree
Showing 22 changed files with 2,931 additions and 2,110 deletions.
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
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ build:windows:
- windows
before_script:
- mkdir -Force "$CI_PROJECT_DIR/tmp"
- Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
script:
- .\scripts\choco-install.ps1
- refreshenv
Expand Down
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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
20 changes: 14 additions & 6 deletions benches/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env ts-node

import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';
import si from 'systeminformation';
import tableNotIndexed from './table_not_indexed';
import tableIndexed from './table_indexed';
import tableDerived from './table_derived';
import tableNotIndexed from './table_not_indexed.js';
import tableIndexed from './table_indexed.js';
import tableDerived from './table_derived.js';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
Expand Down Expand Up @@ -44,4 +45,11 @@ async function main(): Promise<void> {
);
}

void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
4 changes: 2 additions & 2 deletions benches/table_derived.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import b from 'benny';
import Table from '@';
import { suiteCommon } from './utils';
import { suiteCommon } from './utils.js';
import Table from '#Table.js';

async function main() {
const summary = await b.suite(
Expand Down
4 changes: 2 additions & 2 deletions benches/table_indexed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import b from 'benny';
import Table from '@';
import { suiteCommon } from './utils';
import { suiteCommon } from './utils.js';
import Table from '#Table.js';

async function main() {
const summary = await b.suite(
Expand Down
4 changes: 2 additions & 2 deletions benches/table_not_indexed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import b from 'benny';
import Table from '@';
import { suiteCommon } from './utils';
import { suiteCommon } from './utils.js';
import Table from '#Table.js';

async function main() {
const summary = await b.suite(
Expand Down
6 changes: 3 additions & 3 deletions benches/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import b from 'benny';
import { codeBlock } from 'common-tags';
import packageJson from '../package.json';
import packageJson from '../package.json' assert { type: 'json' };

const suiteCommon = [
b.cycle(),
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

0 comments on commit 8a616ab

Please sign in to comment.