From d9806edc505879e7fd9993b722351e9b00c978ef Mon Sep 17 00:00:00 2001 From: Ryo Igarashi Date: Fri, 14 Jul 2023 16:39:01 +0900 Subject: [PATCH] chore(build): Use ES Module for config files --- .eslintrc.json | 10 ++++----- jest.config.cjs | 30 ------------------------- jest.config.js | 30 +++++++++++++++++++++++++ package.json | 6 ++--- rollup.config.cjs | 34 ----------------------------- rollup.config.js | 35 ++++++++++++++++++++++++++++++ test-utils/jest-setup-after-env.ts | 1 + 7 files changed, 74 insertions(+), 72 deletions(-) delete mode 100644 jest.config.cjs create mode 100644 jest.config.js delete mode 100644 rollup.config.cjs create mode 100644 rollup.config.js diff --git a/.eslintrc.json b/.eslintrc.json index f8e50ad8b..13a227ee7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,11 +7,6 @@ "plugin:prettier/recommended" ], "plugins": ["import", "simple-import-sort"], - "parserOptions": { - "ecmaVersion": 9, - "sourceType": "module", - "project": "./tsconfig.json" - }, "env": { "browser": true, "node": true @@ -32,6 +27,11 @@ "plugin:import/typescript", "plugin:prettier/recommended" ], + "parserOptions": { + "ecmaVersion": 9, + "sourceType": "module", + "project": "./tsconfig.json" + }, "rules": { "@typescript-eslint/explicit-module-boundary-types": "error", "@typescript-eslint/explicit-member-accessibility": [ diff --git a/jest.config.cjs b/jest.config.cjs deleted file mode 100644 index 29f4ac0ca..000000000 --- a/jest.config.cjs +++ /dev/null @@ -1,30 +0,0 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} */ -module.exports = { - projects: [ - { - displayName: 'unit', - testEnvironment: 'node', - testMatch: ['/src/**/*.spec.ts'], - transform: { '^.+\\.tsx?$': 'ts-jest' }, - }, - { - displayName: 'e2e', - testEnvironment: './test-utils/jest-environment.ts', - testMatch: ['/tests/**/*.spec.ts'], - transform: { - '^.+\\.tsx?$': [ - 'ts-jest', - { - tsconfig: { - target: 'esnext', - module: 'esnext', - }, - }, - ], - }, - globalSetup: '/test-utils/jest-global-setup.ts', - setupFilesAfterEnv: ['/test-utils/jest-setup-after-env.ts'], - }, - ], - collectCoverageFrom: ['src/**/*.ts', '!src/**/*.spec.ts', '!**/__mocks__/**'], -}; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..7bccef85f --- /dev/null +++ b/jest.config.js @@ -0,0 +1,30 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +export default { + projects: [ + { + displayName: "unit", + testEnvironment: "node", + testMatch: ["/src/**/*.spec.ts"], + transform: { "^.+\\.tsx?$": "ts-jest" }, + }, + { + displayName: "e2e", + testEnvironment: "./test-utils/jest-environment.ts", + testMatch: ["/tests/**/*.spec.ts"], + transform: { + "^.+\\.tsx?$": [ + "ts-jest", + { + tsconfig: { + target: "esnext", + module: "esnext", + }, + }, + ], + }, + globalSetup: "/test-utils/jest-global-setup.ts", + setupFilesAfterEnv: ["/test-utils/jest-setup-after-env.ts"], + }, + ], + collectCoverageFrom: ["src/**/*.ts", "!src/**/*.spec.ts", "!**/__mocks__/**"], +}; diff --git a/package.json b/package.json index 5d9585bc4..e2da2dfa0 100644 --- a/package.json +++ b/package.json @@ -19,12 +19,12 @@ }, "scripts": { "test": "npm-run-all test:*", - "test:unit": "jest --coverage --config=jest.config.cjs --selectProjects unit", - "test:e2e": "jest --coverage --config=jest.config.cjs --selectProjects e2e", + "test:unit": "jest --coverage --config=jest.config.js --selectProjects unit", + "test:e2e": "jest --coverage --config=jest.config.js --selectProjects e2e", "lint": "npm-run-all lint:*", "lint:eslint": "eslint --ext ts --report-unused-disable-directives --cache '{src,tests,test-utils}/**/*'", "lint:spellcheck": "cspell '{src,test,test-utils}/**/*.{ts,tsx,js,json,md}'", - "build": "rollup -c rollup.config.cjs", + "build": "rollup -c rollup.config.js", "prepublishOnly": "yarn run build", "docs:build": "typedoc ./src/index.ts && touch ./docs/.nojekyll", "purge:cache": "rm -rf ./node_modules/.cache/masto" diff --git a/rollup.config.cjs b/rollup.config.cjs deleted file mode 100644 index c0e64f6a0..000000000 --- a/rollup.config.cjs +++ /dev/null @@ -1,34 +0,0 @@ -const commonjs = require('@rollup/plugin-commonjs'); -const json = require('@rollup/plugin-json'); -const autoExternal = require('rollup-plugin-auto-external'); -const { default: dts } = require('rollup-plugin-dts'); -const typescript = require('rollup-plugin-typescript2'); - -const packageJSON = require('./package.json'); - -module.exports = [ - { - input: './src/index.ts', - output: { - file: packageJSON.exports['.'].require, - format: 'cjs', - }, - plugins: [json(), typescript(), autoExternal()], - }, - { - input: './src/index.ts', - output: { - file: packageJSON.exports['.'].import, - format: 'esm', - }, - plugins: [commonjs(), json(), typescript(), autoExternal()], - }, - { - input: './src/index.ts', - output: { - file: packageJSON.exports['.'].types, - format: 'esm', - }, - plugins: [dts()], - }, -]; diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 000000000..8fa98250a --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,35 @@ +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import autoExternal from "rollup-plugin-auto-external"; +import dts from "rollup-plugin-dts"; +import typescript from "rollup-plugin-typescript2"; + +import packageJSON from "./package.json" assert { type: "json" }; + +/** @type {import('rollup').RollupOptions[]} */ +export default [ + { + input: "./src/index.ts", + output: { + file: packageJSON.exports["."].require, + format: "cjs", + }, + plugins: [json(), typescript(), autoExternal()], + }, + { + input: "./src/index.ts", + output: { + file: packageJSON.exports["."].import, + format: "esm", + }, + plugins: [commonjs(), json(), typescript(), autoExternal()], + }, + { + input: "./src/index.ts", + output: { + file: packageJSON.exports["."].types, + format: "esm", + }, + plugins: [dts()], + }, +]; diff --git a/test-utils/jest-setup-after-env.ts b/test-utils/jest-setup-after-env.ts index 077b1aafb..728be696f 100644 --- a/test-utils/jest-setup-after-env.ts +++ b/test-utils/jest-setup-after-env.ts @@ -4,6 +4,7 @@ import "./jest-extend-expect"; import { createRestClient } from "../src"; import { SessionPoolImpl } from "./pools"; +jest.retryTimes(3); jest.setTimeout(1000 * 60); globalThis.admin = createRestClient({