diff --git a/.gitignore b/.gitignore index a2681ce..9ca1941 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ node_modules .cache dist +dist_ .idea package-lock.json .parcel-cache diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..c0dcd29 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + transform: { + '^.+\\.ts$': 'ts-jest' + }, + testEnvironment: "jsdom", + testRegex: '/(src|test)/.*\\.test\\.ts$', + moduleFileExtensions: ['ts', 'js', 'json', 'node'] +}; diff --git a/package.json b/package.json index 4918d2c..d4796a6 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { - "version": "0.8.5", + "version": "0.8.6", "license": "MIT", "main": "dist/index.js", - "typings": "dist/index.d.ts", "files": [ "dist", "src" @@ -10,23 +9,19 @@ "engines": { "node": ">=10" }, + "repository": "https://github.com/kubk/mobx-log", + "types": "dist/mobx-log.d.ts", "scripts": { - "start": "tsdx watch", - "build": "tsdx build", - "test": "tsdx test --passWithNoTests", - "test:update-snapshot": "tsdx test --updateSnapshot", - "test:cache": "tsdx test --clearCache", + "build": "rollup -c", + "test": "jest test --passWithNoTests", + "test:update-snapshot": "jest test --updateSnapshot", + "test:cache": "jest test --clearCache", "lint": "tsdx lint", - "prepare": "tsdx build" + "prepare": "npm run build" }, "peerDependencies": { "react": ">=16" }, - "husky": { - "hooks": { - "pre-commit": "tsdx lint" - } - }, "prettier": { "singleQuote": true }, @@ -35,7 +30,7 @@ "module": "dist/mobx-log.esm.js", "size-limit": [ { - "path": "dist/mobx-log.cjs.production.min.js", + "path": "dist/index.js", "limit": "10 KB" }, { @@ -44,17 +39,24 @@ } ], "devDependencies": { + "@rollup/plugin-commonjs": "^21.0.1", + "@rollup/plugin-node-resolve": "^13.1.1", + "@rollup/plugin-typescript": "^8.3.0", "@size-limit/preset-small-lib": "^5.0.3", + "@types/jest": "^27.0.3", "@types/react": "^17.0.21", "@types/react-dom": "^17.0.9", "husky": "^7.0.2", + "jest": "^27.4.5", "mobx": "^6.3.5", "mobx-react-lite": "^3.2.1", "prettier": "^2.4.1", "react": "^17.0.2", "react-dom": "^17.0.2", + "rollup": "^2.61.1", + "rollup-plugin-dts": "^4.0.1", "size-limit": "^5.0.3", - "tsdx": "^0.14.1", + "ts-jest": "^27.1.2", "tslib": "^2.3.1", "typescript": "^4.4.3" }, diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..5eeff24 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,35 @@ +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import typescript from '@rollup/plugin-typescript'; +import dts from 'rollup-plugin-dts'; + +const packageJson = require('./package.json'); + +export default [ + { + input: 'src/index.ts', + external: ['mobx', 'mobx-react-lite', 'react'], + output: [ + { + file: packageJson.main, + format: 'cjs', + sourcemap: true, + }, + { + file: packageJson.module, + format: 'esm', + sourcemap: true, + }, + ], + plugins: [ + resolve(), + commonjs(), + typescript({ tsconfig: './tsconfig.json' }), + ], + }, + { + input: './dist/types/index.d.ts', + output: [{ file: packageJson.types, format: 'es' }], + plugins: [dts()], + }, +]; diff --git a/tsconfig.json b/tsconfig.json index ac2cddf..6c211bb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,32 +1,22 @@ { - // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], "importHelpers": true, - // output .d.ts declaration files for consumers + "outDir": "dist", + "declarationDir": "types", "declaration": true, - // output .js.map sourcemap files for consumers + "emitDeclarationOnly": true, "sourceMap": true, - // match output dir to input dir. e.g. dist/index instead of dist/src/index "rootDir": "./src", - // stricter type-checking for stronger correctness. Recommended by TS "strict": true, - // linter checks for common issues "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", - // transpile JSX to React.createElement "jsx": "react", - // interop between ESM and CJS modules. Recommended by TS "esModuleInterop": true, - // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS "skipLibCheck": true, - // error out if import and file system have a casing mismatch. Recommended by TS - "forceConsistentCasingInFileNames": true, - // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` - "noEmit": true, + "forceConsistentCasingInFileNames": true } }