Skip to content

Commit 5f20f07

Browse files
committed
feat: switched to ESM
1 parent 8cbaf0c commit 5f20f07

33 files changed

+3520
-6966
lines changed

.eslintrc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
"jest": true
88
},
99
"parser": "@typescript-eslint/parser",
10-
"extends": [
11-
"eslint:recommended",
12-
"plugin:@typescript-eslint/recommended",
13-
"plugin:prettier/recommended",
14-
"prettier"
15-
],
16-
"plugins": [
17-
"import"
18-
],
1910
"parserOptions": {
2011
"project": "tsconfig.json",
2112
"sourceType": "module"
2213
},
14+
"plugins": [
15+
"import"
16+
],
17+
"extends": [
18+
"eslint:recommended",
19+
"plugin:@typescript-eslint/recommended",
20+
"plugin:prettier/recommended"
21+
],
2322
"rules": {
2423
"linebreak-style": ["error", "unix"],
2524
"no-empty": 1,

.github/workflows/codesee-arch-diagram.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.npmrc

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# js-contexts
22

3-
staging:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-contexts/badges/staging/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-contexts/commits/staging)
4-
master:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-contexts/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-contexts/commits/master)
5-
63
Asynchronous contexts.
74

85
## Installation
@@ -13,15 +10,15 @@ npm install --save @matrixai/contexts
1310

1411
## Development
1512

16-
Run `nix-shell`, and once you're inside, you can use:
13+
Run `nix develop`, and once you're inside, you can use:
1714

1815
```sh
1916
# install (or reinstall packages from package.json)
2017
npm install
2118
# build the dist
2219
npm run build
2320
# run the repl (this allows you to import from ./src)
24-
npm run ts-node
21+
npm run tsx
2522
# run the tests
2623
npm run test
2724
# lint the source code

flake.lock

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

flake.nix

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
inputs = {
3+
nixpkgs-matrix = {
4+
type = "indirect";
5+
id = "nixpkgs-matrix";
6+
};
7+
flake-utils.url = "github:numtide/flake-utils";
8+
};
9+
10+
outputs = { nixpkgs-matrix, flake-utils, ... }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let
13+
pkgs = nixpkgs-matrix.legacyPackages.${system};
14+
15+
shell = { ci ? false }:
16+
with pkgs;
17+
mkShell {
18+
nativeBuildInputs = [ nodejs_20 shellcheck gitAndTools.gh ];
19+
NIX_DONT_SET_RPATH = true;
20+
NIX_NO_SELF_RPATH = true;
21+
shellHook = ''
22+
echo "Entering $(npm pkg get name)"
23+
set -o allexport
24+
. ./.env
25+
set +o allexport
26+
set -v
27+
${lib.optionalString ci ''
28+
set -o errexit
29+
set -o nounset
30+
set -o pipefail
31+
shopt -s inherit_errexit
32+
''}
33+
mkdir --parents "$(pwd)/tmp"
34+
export PATH="$(pwd)/dist/bin:$(npm root)/.bin:$PATH"
35+
npm install --ignore-scripts
36+
set +v
37+
'';
38+
};
39+
in {
40+
devShells = {
41+
default = shell { ci = false; };
42+
ci = shell { ci = true; };
43+
};
44+
});
45+
}

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)