Skip to content

Commit df4b698

Browse files
committed
feat(package): Use microbundle to create cjs and mjs builds and convert package to module
Signed-off-by: Tilman Vatteroth <[email protected]>
1 parent 82c5b19 commit df4b698

9 files changed

+3672
-348
lines changed

.eslintrc.json

+22-15
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66
{
7-
"parser": "@typescript-eslint/parser",
8-
"parserOptions": {
9-
"project": ["./tsconfig-eslint.json"]
7+
"parser" : "@typescript-eslint/parser",
8+
"parserOptions" : {
9+
"project" : [
10+
"./tsconfig.json"
11+
]
1012
},
11-
"plugins": ["@typescript-eslint", "jest"],
12-
"env": {
13-
"jest": true,
14-
"jest/globals": true
13+
"plugins" : [
14+
"@typescript-eslint",
15+
"jest",
16+
"prettier"
17+
],
18+
"env" : {
19+
"jest" : true,
20+
"jest/globals" : true
1521
},
16-
"extends": [
22+
"extends" : [
1723
"eslint:recommended",
1824
"plugin:@typescript-eslint/eslint-recommended",
1925
"plugin:@typescript-eslint/recommended-requiring-type-checking",
20-
"plugin:@typescript-eslint/recommended"
26+
"plugin:@typescript-eslint/recommended",
27+
"prettier"
2128
],
22-
"rules": {
23-
"jest/no-disabled-tests": "warn",
24-
"jest/no-focused-tests": "error",
25-
"jest/no-identical-title": "error",
26-
"jest/prefer-to-have-length": "warn",
27-
"jest/valid-expect": "error"
29+
"rules" : {
30+
"jest/no-disabled-tests" : "warn",
31+
"jest/no-focused-tests" : "error",
32+
"jest/no-identical-title" : "error",
33+
"jest/prefer-to-have-length" : "warn",
34+
"jest/valid-expect" : "error"
2835
}
2936
}

jest.config.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{
22
"preset": "ts-jest",
3-
"transform": {
4-
"^.+\\.tsx?$": "ts-jest"
5-
},
63
"testEnvironment": "node",
74
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
85
"testPathIgnorePatterns": [
96
"/dist/"
107
],
11-
"moduleFileExtensions": [
12-
"ts",
13-
"tsx",
14-
"js"
8+
"extensionsToTreatAsEsm" : [
9+
".ts"
1510
],
16-
"globals": {
17-
"ts-jest": {
18-
"tsconfig": "tsconfig-cjs.json"
19-
}
11+
"moduleNameMapper" : {
12+
"^(\\.{1,2}/.*)\\.js$" : "$1"
13+
},
14+
"transform" : {
15+
"^.+\\.tsx?$" : [
16+
"ts-jest",
17+
{
18+
"useESM" : true
19+
}
20+
]
2021
}
2122
}

package.json

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,57 @@
11
{
22
"name": "@mrdrogdrog/optional",
3-
"version": "0.2.0",
3+
"version": "1.0.0",
44
"description": "Provides a java-like optional class",
55
"author": "Tilman Vatteroth <[email protected]>",
66
"license": "MIT",
77
"scripts": {
8-
"build": "tsc-esm && tsc -p tsconfig-cjs.json && find dist/cjs -type d -execdir sh -c 'cd {}; mmv -rd \"*.js*\" \"#1#2\"' \\;",
8+
"build": "microbundle",
99
"test": "jest",
10-
"prepublish": "rm -rf dist && yarn format && yarn lint && yarn build && yarn test",
10+
"prepublish": "rm -rf dist && yarn lint && yarn build && yarn test",
1111
"lint": "eslint src --ext .ts",
12-
"format": "prettier -c \"src/**/*.{ts,tsx,js}\"",
13-
"format:fix": "prettier -w \"src/**/*.{ts,tsx,js}\"",
12+
"lint:fix": "eslint --fix --ext .ts src",
1413
"docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts"
1514
},
1615
"type": "module",
17-
"main": "dist/cjs/index",
18-
"module": "dist/mjs/index.js",
19-
"types": "dist/cjs/index.d.ts",
16+
"source": "src/index.ts",
17+
"main": "dist/index.js",
18+
"types": "dist/index.d.ts",
19+
"module": "./dist/index.esm.js",
20+
"unpkg": "./dist/index.umd.js",
2021
"exports": {
21-
".": {
22-
"import": "./dist/mjs/index.js",
23-
"require": "./dist/cjs/index"
24-
}
25-
},
26-
"typesVersions": {
27-
"*": {
28-
"index.d.ts": [
29-
"dist/mjs/index.d.ts"
30-
]
31-
}
22+
"require": "./dist/index.cjs",
23+
"types": "./dist/index.d.ts",
24+
"default": "./dist/index.mjs"
3225
},
3326
"files": [
3427
"LICENSES/*",
3528
"package.json",
3629
"README.md",
37-
"dist/**"
30+
"dist/index.d.ts",
31+
"dist/index.test.d.ts",
32+
"dist/index.cjs.map",
33+
"dist/index.cjs",
34+
"dist/index.mjs.map",
35+
"dist/index.mjs",
36+
"dist/index.esm.js.map",
37+
"dist/index.esm.js",
38+
"dist/index.umd.js.map",
39+
"dist/index.umd.js"
3840
],
3941
"repository": {
4042
"type": "git",
4143
"url": "https://github.com/mrdrogdrog/optional.git"
4244
},
4345
"devDependencies": {
44-
"@digitak/tsc-esm": "3.1.4",
4546
"@jest/types": "29.2.1",
4647
"@typescript-eslint/eslint-plugin": "5.40.1",
4748
"@typescript-eslint/parser": "5.40.1",
4849
"eslint": "8.26.0",
4950
"eslint-config-prettier": "8.5.0",
5051
"eslint-plugin-jest": "27.1.3",
52+
"eslint-plugin-prettier": "4.2.1",
5153
"jest": "29.2.1",
54+
"microbundle": "0.15.1",
5255
"prettier": "2.7.1",
5356
"ts-jest": "29.0.3",
5457
"typescript": "4.8.4"

tsconfig-cjs.json

-8
This file was deleted.

tsconfig-cjs.json.license

-3
This file was deleted.

tsconfig-eslint.json

-4
This file was deleted.

tsconfig-eslint.json.license

-3
This file was deleted.

tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
"module": "esnext",
1515
"moduleResolution": "node",
1616
"esModuleInterop": true,
17-
"outDir": "dist/mjs",
18-
"rootDir": "./src",
1917
"allowJs": true,
2018
"sourceMap": true
2119
},
22-
"include": ["./src"],
23-
"exclude": ["./dist", "**/*.test.*", "**/__mocks__/*", "**/__tests__/*"]
20+
"include": ["src"],
21+
"exclude": ["dist"]
2422
}

0 commit comments

Comments
 (0)