From 8534bdb85901c0d01af5673e43609fced9b1c663 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 7 Aug 2023 08:41:04 +0200 Subject: [PATCH] Use `ESNext` as default module system (#188) --- jest.config.ts | 15 ++++----------- lib/index.ts | 2 +- lib/index.umd.ts | 2 +- rollup.config.ts | 5 +---- test/tests.ts | 2 +- tsconfig.build.json | 8 ++++++++ tsconfig.json | 14 ++++---------- tsconfig.test.json | 13 ------------- 8 files changed, 20 insertions(+), 41 deletions(-) create mode 100644 tsconfig.build.json delete mode 100644 tsconfig.test.json diff --git a/jest.config.ts b/jest.config.ts index 61b4ecf..081468e 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,25 +1,18 @@ import { type JestConfigWithTsJest } from "ts-jest"; const jestConfig: JestConfigWithTsJest = { - rootDir: "./", - moduleFileExtensions: ["ts", "js"], + preset: "ts-jest/presets/default-esm", + moduleNameMapper: { + "^(\\.{1,2}/.*)\\.js$": "$1", + }, testMatch: ["**/test/**/*.test.ts", "**/test/tests.ts"], coverageProvider: "v8", coveragePathIgnorePatterns: ["/node_modules/", "./test"], - extensionsToTreatAsEsm: [".ts"], reporters: [ "default", ["jest-junit", { outputDirectory: "test-results/jest" }], ], coverageReporters: ["lcov", "text", "text-summary"], - setupFiles: [], - preset: "ts-jest/presets/default-esm", - transform: { - "^.+\\.ts?$": [ - "ts-jest", - { useESM: true, tsconfig: "./tsconfig.test.json" }, - ], - }, }; export default jestConfig; diff --git a/lib/index.ts b/lib/index.ts index cec7b2c..a8b7880 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,4 @@ -import { base64UrlDecode } from "./base64-url-decode"; +import { base64UrlDecode } from "./base64-url-decode.js"; export interface JwtDecodeOptions { header?: boolean; diff --git a/lib/index.umd.ts b/lib/index.umd.ts index ebc82f2..989b2da 100644 --- a/lib/index.umd.ts +++ b/lib/index.umd.ts @@ -1 +1 @@ -export { jwtDecode as default } from "./index"; +export { jwtDecode as default } from "./index.js"; diff --git a/rollup.config.ts b/rollup.config.ts index 86778d4..b45b0bb 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -5,10 +5,7 @@ import livereload from "rollup-plugin-livereload"; import serve from "rollup-plugin-serve"; const isProduction = process.env.NODE_ENV === "production"; -const tsPlugin = typescript({ - rootDir: "lib", - sourceMap: true, -}); +const tsPlugin = typescript({ tsconfig: "tsconfig.build.json" }); const plugins = [ tsPlugin, diff --git a/test/tests.ts b/test/tests.ts index 8bb60c8..cc2d232 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -1,4 +1,4 @@ -import { jwtDecode, InvalidTokenError, JwtPayload } from "./../lib/index"; +import { jwtDecode, InvalidTokenError, JwtPayload } from "./../lib/index.js"; import { describe, expect, it } from "@jest/globals"; const token = diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..5fdd1ea --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "ES2017", + "rootDir": "./lib", + "sourceMap": true + } +} diff --git a/tsconfig.json b/tsconfig.json index 1ce82b3..99bfead 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,9 @@ { "compilerOptions": { - "target": "ES2017", - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "sourceMap": false, - "moduleResolution": "node", - "noImplicitAny": true, - "downlevelIteration": true, - "noImplicitThis": true, + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Node", "strict": true, "noEmitOnError": true - }, - "exclude": ["./test", "./build/typings"] + } } diff --git a/tsconfig.test.json b/tsconfig.test.json deleted file mode 100644 index 744a3f3..0000000 --- a/tsconfig.test.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "noImplicitAny": false, - "target": "es6", - "noImplicitThis": false, - "alwaysStrict": false, - "strictBindCallApply": false, - "strictNullChecks": false, - "strictFunctionTypes": false, - "strictPropertyInitialization": false - } -}