Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 8208594

Browse files
authored
Switch to ESM (#19)
1 parent cbd4b93 commit 8208594

20 files changed

Lines changed: 69 additions & 66 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ jobs:
4040
run: pnpm install
4141

4242
- name: Build the project
43+
env:
44+
NODE_OPTIONS: --experimental-vm-modules --no-warnings
4345
run: pnpm ci:all

core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"main": "../dist/hatsy.core.cjs",
3-
"module": "../dist/hatsy.core.js",
2+
"main": "../dist/hatsy.core.js",
43
"types": "./index.d.ts"
54
}

jest.config.cjs renamed to jest.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module.exports = {
2-
preset: 'ts-jest',
1+
export default {
2+
preset: 'ts-jest/presets/default-esm',
33
collectCoverage: true,
44
collectCoverageFrom: [
55
'src/**/*.ts',
@@ -18,6 +18,7 @@ module.exports = {
1818
lines: 100,
1919
},
2020
},
21+
extensionsToTreatAsEsm: ['.ts'],
2122
reporters: [
2223
'default',
2324
[
@@ -32,9 +33,11 @@ module.exports = {
3233
},
3334
],
3435
],
36+
testEnvironment: 'node',
3537
globals: {
3638
'ts-jest': {
3739
tsconfig: 'tsconfig.spec.json',
40+
useESM: true,
3841
},
3942
},
4043
};

package.json

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,13 @@
2424
"url": "https://github.com/hatsyjs/hatsy/issues"
2525
},
2626
"type": "module",
27-
"main": "./dist/hatsy.cjs",
28-
"module": "./dist/hatsy.js",
27+
"main": "./dist/hatsy.js",
2928
"types": "./index.d.ts",
3029
"exports": {
31-
".": {
32-
"import": "./dist/hatsy.js",
33-
"require": "./dist/hatsy.cjs"
34-
},
35-
"./core": {
36-
"import": "./dist/hatsy.core.js",
37-
"require": "./dist/hatsy.core.cjs"
38-
},
30+
".": "./dist/hatsy.js",
31+
"./core": "./dist/hatsy.core.js",
3932
"./package.json": "./package.json",
40-
"./testing": {
41-
"import": "./dist/hatsy.testing.js",
42-
"require": "./dist/hatsy.testing.cjs"
43-
}
33+
"./testing": "./dist/hatsy.testing.js"
4434
},
4535
"dependencies": {
4636
"@frontmeans/httongue": "^2.2.0",
@@ -51,26 +41,27 @@
5141
"node": ">=12"
5242
},
5343
"devDependencies": {
44+
"@jest/globals": "^27.0.1",
5445
"@rollup/plugin-commonjs": "^19.0.0",
5546
"@rollup/plugin-node-resolve": "^13.0.0",
5647
"@run-z/eslint-config": "^1.2.1",
5748
"@run-z/rollup-helpers": "^1.1.0",
58-
"@types/jest": "^26.0.23",
5949
"@types/node": "^12.20.13",
6050
"@typescript-eslint/eslint-plugin": "^4.25.0",
6151
"@typescript-eslint/parser": "^4.25.0",
6252
"eslint": "^7.27.0",
6353
"eslint-plugin-jest": "^24.3.6",
6454
"gh-pages": "^3.2.0",
65-
"jest": "^26.6.3",
55+
"jest": "^27.0.1",
6656
"jest-junit": "^12.1.0",
67-
"rollup": "^2.50.0",
57+
"jest-mock": "^27.0.1",
58+
"rollup": "^2.50.1",
6859
"rollup-plugin-flat-dts": "^1.2.1",
6960
"rollup-plugin-sourcemaps": "^0.6.3",
7061
"rollup-plugin-typescript2": "^0.30.0",
7162
"run-z": "^1.7.2",
7263
"shx": "^0.3.3",
73-
"ts-jest": "^26.5.6",
64+
"ts-jest": "^27.0.0",
7465
"tslib": "^2.2.0",
7566
"typedoc": "^0.20.36",
7667
"typescript": "^4.3.1-rc"

rollup.config.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,28 @@ export default {
3737
}
3838
return 'hatsy';
3939
},
40-
output: [
41-
{
42-
dir: 'dist',
43-
format: 'cjs',
44-
sourcemap: true,
45-
entryFileNames: '[name].cjs',
46-
chunkFileNames: '_[name].cjs',
47-
},
48-
{
49-
dir: '.',
50-
format: 'esm',
51-
sourcemap: true,
52-
entryFileNames: 'dist/[name].js',
53-
chunkFileNames: 'dist/_[name].js',
54-
plugins: [
55-
flatDts({
56-
tsconfig: 'tsconfig.main.json',
57-
lib: true,
58-
compilerOptions: {
59-
declarationMap: true,
40+
output: {
41+
dir: '.',
42+
format: 'esm',
43+
sourcemap: true,
44+
entryFileNames: 'dist/[name].js',
45+
chunkFileNames: 'dist/_[name].js',
46+
plugins: [
47+
flatDts({
48+
tsconfig: 'tsconfig.main.json',
49+
lib: true,
50+
compilerOptions: {
51+
declarationMap: true,
52+
},
53+
entries: {
54+
core: {
55+
file: 'core/index.d.ts',
6056
},
61-
entries: {
62-
core: {
63-
file: 'core/index.d.ts',
64-
},
65-
testing: {
66-
file: 'testing/index.d.ts',
67-
},
57+
testing: {
58+
file: 'testing/index.d.ts',
6859
},
69-
}),
70-
],
71-
},
72-
],
60+
},
61+
}),
62+
],
63+
},
7364
};

src/core/logging/logging.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
12
import { noop } from '@proc7ts/primitives';
3+
import type { Mock } from 'jest-mock';
24
import type { RequestContext } from '../request-context';
35
import type { RequestHandler } from '../request-handler';
46
import type { RequestProcessor } from '../request-processor';
@@ -9,7 +11,7 @@ import type { RequestLogger } from './request-logger';
911

1012
describe('Logging', () => {
1113

12-
let handler: jest.Mock<void, [RequestContext<LoggerMeans>]>;
14+
let handler: Mock<void, [RequestContext<LoggerMeans>]>;
1315

1416
beforeEach(() => {
1517
handler = jest.fn();

src/core/request-handler.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { beforeEach, describe, expect, it } from '@jest/globals';
12
import { valueProvider } from '@proc7ts/primitives';
23
import type { ServerResponse } from 'http';
34
import type { RequestContext } from './request-context';

src/http/dispatch/dispatch-by-accepted.handler.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
12
import type { RequestContext } from '../../core';
23
import { Logging } from '../../core';
34
import { suppressedLog, TestHttpServer } from '../../testing';

src/http/dispatch/dispatch-by-language.handler.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Logging } from '../../core/logging';
1+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
2+
import { Logging } from '../../core';
23
import { suppressedLog, TestHttpServer } from '../../testing';
34
import { Rendering } from '../render';
45
import { dispatchByLanguage } from './dispatch-by-language.handler';

src/http/dispatch/dispatch-by-method.handler.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { afterAll, afterEach, beforeAll, describe, expect, it } from '@jest/globals';
12
import { noop } from '@proc7ts/primitives';
23
import { Logging, RequestContext, requestHandler } from '../../core';
34
import { suppressedLog, TestHttpServer } from '../../testing';

0 commit comments

Comments
 (0)