Skip to content

Commit 2b8c21a

Browse files
authored
Merge pull request #19 from alexrecuenco/enable-esm-again
Enable esm again
2 parents f99082a + 44088b1 commit 2b8c21a

24 files changed

+920
-62
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
- uses: actions/setup-python@v4
16+
- uses: actions/setup-python@v5
1717
with:
18+
# python-version: '3.12'
1819
cache: 'pip'
1920
- uses: pre-commit/action@v3.0.1
2021

@@ -23,7 +24,7 @@ jobs:
2324

2425
strategy:
2526
matrix:
26-
node-version: [18.x, 20.x]
27+
node-version: [20.x, 22.x]
2728

2829
steps:
2930
- uses: actions/checkout@v4
@@ -38,3 +39,5 @@ jobs:
3839
- run: npm run format
3940
- run: npm run build:debug
4041
- run: npm run build:prod
42+
- run: npm run check:esmloads
43+
- run: npm run check:cjsloads

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# Created by git when using merge tools for conflicts
1111
*.BACKUP.*
1212
*.BASE.*
13+
!tsconfig.base*
1314
*.LOCAL.*
1415
*.REMOTE.*
1516
*_BACKUP_*.txt
@@ -395,3 +396,4 @@ $RECYCLE.BIN/
395396
*.lnk
396397

397398
# End of https://www.gitignore.io/api/git,node,linux,macos,python,pycharm,windows,visualstudiocode
399+
build*/

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*
2+
!dist/**
3+
!src/**
4+
!package*json
5+
!README*
6+
!tsconfig*
7+
tsconfig.eslint.json

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos: #The order matters, we want prospector to run after all the sorting was d
88
- id: check-json
99
# JSON that are not json
1010
# (?x) means verbose (we can add spaces for better readibility, but they are ignored)
11-
exclude: (?x) ^(tsconfig(\.\w+)? | \.vscode/.*) \.json$
11+
exclude: (?x) /?(tsconfig(\.\w+)? | \.vscode/.*) \.json$
1212
- id: check-merge-conflict
1313
- id: check-symlinks
1414
- id: check-toml
@@ -19,10 +19,10 @@ repos: #The order matters, we want prospector to run after all the sorting was d
1919
# File normalization
2020
- id: end-of-file-fixer
2121
- id: trailing-whitespace
22-
- repo: https://github.com/pre-commit/mirrors-prettier
23-
rev: 'v3.1.0'
24-
hooks:
25-
- id: prettier
26-
additional_dependencies:
27-
- prettier@3.2.5
28-
- prettier-plugin-jsdoc@1.3.0
22+
# - repo: https://github.com/pre-commit/mirrors-prettier
23+
# rev: 'v3.1.0'
24+
# hooks:
25+
# - id: prettier
26+
# additional_dependencies:
27+
# - prettier@3.2.5
28+
# - prettier-plugin-jsdoc@1.3.0

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
},
88
"editor.formatOnSaveMode": "modificationsIfAvailable",
99
"[javascript,typescript,jsonc,json]": {
10+
"editor.indentSize": "tabSize",
11+
"editor.tabSize": 2,
1012
"editor.defaultFormatter": "esbenp.prettier-vscode",
1113
"editor.formatOnSaveMode": "modificationsIfAvailable",
1214
},
13-
"eslint.experimental.useFlatConfig": true,
15+
"eslint.useFlatConfig": true,
1416
"jest.jestCommandLine": "npm test -- ",
1517
"jest.runMode": {
1618
"type": "on-demand",

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default [
7474
project: [
7575
'./tsconfig.eslint.json',
7676
'./tsconfig.json',
77-
'./tsconfig.prod.json',
77+
'./tsconfig.node.json',
7878
],
7979
},
8080
},

jest.config.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
1-
import type { JestConfigWithTsJest } from 'ts-jest';
1+
import {
2+
createDefaultEsmPreset,
3+
pathsToModuleNameMapper,
4+
type JestConfigWithTsJest,
5+
} from 'ts-jest';
6+
7+
import { compilerOptions } from './tsconfig.aliases.json';
8+
import packageJson from './package.json';
9+
10+
const pathAliases = {
11+
...compilerOptions.paths,
12+
// Jest wants to know the folder to do the transformation, not the `src/index.js`. 🤷
13+
[packageJson.name]: ['src'],
14+
};
15+
16+
// See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced
17+
const preset = createDefaultEsmPreset({
18+
tsconfig: './tests/tsconfig.json',
19+
});
220

321
const config: JestConfigWithTsJest = {
4-
preset: 'ts-jest',
5-
testRegex: [
6-
'/tests/.*tests?.[jt]sx?',
7-
'/__tests__/.*tests?.[jt]sx?',
8-
'.*.(spec|test).[jt]sx?',
9-
],
22+
...preset,
23+
roots: ['<rootDir>'],
24+
modulePaths: [compilerOptions.baseUrl],
25+
moduleNameMapper: pathsToModuleNameMapper(pathAliases, {
26+
useESM: true,
27+
}),
28+
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'],
29+
testRegex: ['/tests/.*tests?.[mc]?[jt]sx?$', '.*.(spec|test).[mc]?[jt]sx?$'],
1030
// I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe.
11-
// We can change this if we consider it useful to run the spec tests when the code is transpiled to javascript
12-
testPathIgnorePatterns: ['node_modules', 'build/'],
31+
// We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript
32+
testPathIgnorePatterns: [
33+
'node_modules',
34+
'<rootDir>/build[^/]*/',
35+
'<rootDir>/dist/',
36+
],
1337
testEnvironment: 'node',
14-
collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'],
38+
collectCoverageFrom: [
39+
'src/**/*.{js,ts,jsx,tsx}',
40+
'!src/**/*.{spec,test}.{js,ts,jsx,tsx}',
41+
],
1542
verbose: true,
1643
// Important to use the AfterEnv to have the jest timeout and all the other settings inside that file to be correctly understood
1744
// See the difference between setupFiles and setupFilesAfterEnv to see the difference.

0 commit comments

Comments
 (0)