diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a3df5f..d8bfd05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: version: 8 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 cache: "pnpm" - run: pnpm install --frozen-lockfile - run: pnpm run format:check diff --git a/.gitignore b/.gitignore index 491fc35..d430add 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules lib +*.ignore.ts diff --git a/package.json b/package.json index f495532..28f70a0 100644 --- a/package.json +++ b/package.json @@ -25,19 +25,18 @@ "result-type" ], "scripts": { - "build": "tsup", + "build": "rm -rf lib && tsc --p tsconfig.build.json && prettier --write ./lib --ignore-path ''", "format": "prettier --write .", "format:check": "prettier --check .", "prepublishOnly": "pnpm run build", "test": "vitest", - "types": "tsc --noEmit" + "types": "tsc" }, "devDependencies": { "husky": "^8.0.3", "lint-staged": "^14.0.1", "prettier": "^3.0.2", "prettier-plugin-pkg": "^0.18.0", - "tsup": "^7.2.0", "tsx": "^3.14.0", "typescript": "^5.0.4", "vitest": "^0.34.6" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1717c5e..8cb84cb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,6 @@ devDependencies: prettier-plugin-pkg: specifier: ^0.18.0 version: 0.18.0(prettier@3.0.2) - tsup: - specifier: ^7.2.0 - version: 7.2.0(typescript@5.0.4) tsx: specifier: ^3.14.0 version: 3.14.0 @@ -237,57 +234,10 @@ packages: '@sinclair/typebox': 0.27.8 dev: true - /@jridgewell/gen-mapping@0.3.3: - resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==} - engines: {node: '>=6.0.0'} - dependencies: - '@jridgewell/set-array': 1.1.2 - '@jridgewell/sourcemap-codec': 1.4.15 - '@jridgewell/trace-mapping': 0.3.19 - dev: true - - /@jridgewell/resolve-uri@3.1.1: - resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} - engines: {node: '>=6.0.0'} - dev: true - - /@jridgewell/set-array@1.1.2: - resolution: {integrity: sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==} - engines: {node: '>=6.0.0'} - dev: true - /@jridgewell/sourcemap-codec@1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} dev: true - /@jridgewell/trace-mapping@0.3.19: - resolution: {integrity: sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==} - dependencies: - '@jridgewell/resolve-uri': 3.1.1 - '@jridgewell/sourcemap-codec': 1.4.15 - dev: true - - /@nodelib/fs.scandir@2.1.5: - resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} - engines: {node: '>= 8'} - dependencies: - '@nodelib/fs.stat': 2.0.5 - run-parallel: 1.2.0 - dev: true - - /@nodelib/fs.stat@2.0.5: - resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} - engines: {node: '>= 8'} - dev: true - - /@nodelib/fs.walk@1.2.8: - resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} - engines: {node: '>= 8'} - dependencies: - '@nodelib/fs.scandir': 2.1.5 - fastq: 1.15.0 - dev: true - /@sinclair/typebox@0.27.8: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true @@ -379,43 +329,10 @@ packages: engines: {node: '>=12'} dev: true - /any-promise@1.3.0: - resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} - dev: true - - /anymatch@3.1.3: - resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} - engines: {node: '>= 8'} - dependencies: - normalize-path: 3.0.0 - picomatch: 2.3.1 - dev: true - - /array-union@2.1.0: - resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} - engines: {node: '>=8'} - dev: true - /assertion-error@1.1.0: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} dev: true - /balanced-match@1.0.2: - resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} - dev: true - - /binary-extensions@2.2.0: - resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} - engines: {node: '>=8'} - dev: true - - /brace-expansion@1.1.11: - resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} - dependencies: - balanced-match: 1.0.2 - concat-map: 0.0.1 - dev: true - /braces@3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} @@ -427,16 +344,6 @@ packages: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} dev: true - /bundle-require@4.0.1(esbuild@0.18.20): - resolution: {integrity: sha512-9NQkRHlNdNpDBGmLpngF3EFDcwodhMUuLz9PaWYciVcQF9SE4LFjM2DB/xV1Li5JiuDMv7ZUWuC3rGbqR0MAXQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - peerDependencies: - esbuild: '>=0.17' - dependencies: - esbuild: 0.18.20 - load-tsconfig: 0.2.5 - dev: true - /cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -466,21 +373,6 @@ packages: get-func-name: 2.0.2 dev: true - /chokidar@3.5.3: - resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} - engines: {node: '>= 8.10.0'} - dependencies: - anymatch: 3.1.3 - braces: 3.0.2 - glob-parent: 5.1.2 - is-binary-path: 2.1.0 - is-glob: 4.0.3 - normalize-path: 3.0.0 - readdirp: 3.6.0 - optionalDependencies: - fsevents: 2.3.3 - dev: true - /cli-cursor@4.0.0: resolution: {integrity: sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -505,15 +397,6 @@ packages: engines: {node: '>=16'} dev: true - /commander@4.1.1: - resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} - engines: {node: '>= 6'} - dev: true - - /concat-map@0.0.1: - resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} - dev: true - /cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -547,13 +430,6 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dev: true - /dir-glob@3.0.1: - resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} - engines: {node: '>=8'} - dependencies: - path-type: 4.0.0 - dev: true - /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true @@ -596,21 +472,6 @@ packages: resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} dev: true - /execa@5.1.1: - resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} - engines: {node: '>=10'} - dependencies: - cross-spawn: 7.0.3 - get-stream: 6.0.1 - human-signals: 2.1.0 - is-stream: 2.0.1 - merge-stream: 2.0.0 - npm-run-path: 4.0.1 - onetime: 5.1.2 - signal-exit: 3.0.7 - strip-final-newline: 2.0.0 - dev: true - /execa@7.2.0: resolution: {integrity: sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==} engines: {node: ^14.18.0 || ^16.14.0 || >=18.0.0} @@ -626,23 +487,6 @@ packages: strip-final-newline: 3.0.0 dev: true - /fast-glob@3.3.1: - resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==} - engines: {node: '>=8.6.0'} - dependencies: - '@nodelib/fs.stat': 2.0.5 - '@nodelib/fs.walk': 1.2.8 - glob-parent: 5.1.2 - merge2: 1.4.1 - micromatch: 4.0.5 - dev: true - - /fastq@1.15.0: - resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} - dependencies: - reusify: 1.0.4 - dev: true - /fill-range@7.0.1: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} engines: {node: '>=8'} @@ -650,10 +494,6 @@ packages: to-regex-range: 5.0.1 dev: true - /fs.realpath@1.0.0: - resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} - dev: true - /fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} @@ -677,41 +517,6 @@ packages: resolve-pkg-maps: 1.0.0 dev: true - /glob-parent@5.1.2: - resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} - engines: {node: '>= 6'} - dependencies: - is-glob: 4.0.3 - dev: true - - /glob@7.1.6: - resolution: {integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==} - dependencies: - fs.realpath: 1.0.0 - inflight: 1.0.6 - inherits: 2.0.4 - minimatch: 3.1.2 - once: 1.4.0 - path-is-absolute: 1.0.1 - dev: true - - /globby@11.1.0: - resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} - engines: {node: '>=10'} - dependencies: - array-union: 2.1.0 - dir-glob: 3.0.1 - fast-glob: 3.3.1 - ignore: 5.2.4 - merge2: 1.4.1 - slash: 3.0.0 - dev: true - - /human-signals@2.1.0: - resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} - engines: {node: '>=10.17.0'} - dev: true - /human-signals@4.3.1: resolution: {integrity: sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==} engines: {node: '>=14.18.0'} @@ -723,56 +528,16 @@ packages: hasBin: true dev: true - /ignore@5.2.4: - resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} - engines: {node: '>= 4'} - dev: true - - /inflight@1.0.6: - resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} - dependencies: - once: 1.4.0 - wrappy: 1.0.2 - dev: true - - /inherits@2.0.4: - resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} - dev: true - - /is-binary-path@2.1.0: - resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} - engines: {node: '>=8'} - dependencies: - binary-extensions: 2.2.0 - dev: true - - /is-extglob@2.1.1: - resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} - engines: {node: '>=0.10.0'} - dev: true - /is-fullwidth-code-point@4.0.0: resolution: {integrity: sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==} engines: {node: '>=12'} dev: true - /is-glob@4.0.3: - resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} - engines: {node: '>=0.10.0'} - dependencies: - is-extglob: 2.1.1 - dev: true - /is-number@7.0.0: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} dev: true - /is-stream@2.0.1: - resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} - engines: {node: '>=8'} - dev: true - /is-stream@3.0.0: resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -782,11 +547,6 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /joycon@3.1.1: - resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} - engines: {node: '>=10'} - dev: true - /jsonc-parser@3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} dev: true @@ -796,10 +556,6 @@ packages: engines: {node: '>=10'} dev: true - /lines-and-columns@1.2.4: - resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} - dev: true - /lint-staged@14.0.1: resolution: {integrity: sha512-Mw0cL6HXnHN1ag0mN/Dg4g6sr8uf8sn98w2Oc1ECtFto9tvRF7nkXGJRbx8gPlHyoR0pLyBr2lQHbWwmUHe1Sw==} engines: {node: ^16.14.0 || >=18.0.0} @@ -837,20 +593,11 @@ packages: wrap-ansi: 8.1.0 dev: true - /load-tsconfig@0.2.5: - resolution: {integrity: sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: true - /local-pkg@0.4.3: resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==} engines: {node: '>=14'} dev: true - /lodash.sortby@4.7.0: - resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} - dev: true - /log-update@5.0.1: resolution: {integrity: sha512-5UtUDQ/6edw4ofyljDNcOVJQ4c7OjDro4h3y8e1GQL5iYElYclVHJ3zeWchylvMaKnDbDilC8irOVyexnA/Slw==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -879,11 +626,6 @@ packages: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} dev: true - /merge2@1.4.1: - resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} - engines: {node: '>= 8'} - dev: true - /micromatch@4.0.5: resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} engines: {node: '>=8.6'} @@ -902,12 +644,6 @@ packages: engines: {node: '>=12'} dev: true - /minimatch@3.1.2: - resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} - dependencies: - brace-expansion: 1.1.11 - dev: true - /mlly@1.4.2: resolution: {integrity: sha512-i/Ykufi2t1EZ6NaPLdfnZk2AX8cs0d+mTzVKuPfqPKPatxLApaBoxJQ9x1/uckXtrS/U5oisPMDkNs0yQTaBRg==} dependencies: @@ -921,32 +657,12 @@ packages: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true - /mz@2.7.0: - resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} - dependencies: - any-promise: 1.3.0 - object-assign: 4.1.1 - thenify-all: 1.6.0 - dev: true - /nanoid@3.3.6: resolution: {integrity: sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true dev: true - /normalize-path@3.0.0: - resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} - engines: {node: '>=0.10.0'} - dev: true - - /npm-run-path@4.0.1: - resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} - engines: {node: '>=8'} - dependencies: - path-key: 3.1.1 - dev: true - /npm-run-path@5.1.0: resolution: {integrity: sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -954,17 +670,6 @@ packages: path-key: 4.0.0 dev: true - /object-assign@4.1.1: - resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} - engines: {node: '>=0.10.0'} - dev: true - - /once@1.4.0: - resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} - dependencies: - wrappy: 1.0.2 - dev: true - /onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} @@ -986,11 +691,6 @@ packages: yocto-queue: 1.0.0 dev: true - /path-is-absolute@1.0.1: - resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} - engines: {node: '>=0.10.0'} - dev: true - /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} @@ -1001,11 +701,6 @@ packages: engines: {node: '>=12'} dev: true - /path-type@4.0.0: - resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} - engines: {node: '>=8'} - dev: true - /pathe@1.1.1: resolution: {integrity: sha512-d+RQGp0MAYTIaDBIMmOfMwz3E+LOZnxx1HZd5R18mmCZY0QBlK0LDZfPc8FW8Ed2DlvsuE6PRjroDY+wg4+j/Q==} dev: true @@ -1029,11 +724,6 @@ packages: hasBin: true dev: true - /pirates@4.0.6: - resolution: {integrity: sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==} - engines: {node: '>= 6'} - dev: true - /pkg-types@1.0.3: resolution: {integrity: sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==} dependencies: @@ -1042,22 +732,6 @@ packages: pathe: 1.1.1 dev: true - /postcss-load-config@4.0.1: - resolution: {integrity: sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA==} - engines: {node: '>= 14'} - peerDependencies: - postcss: '>=8.0.9' - ts-node: '>=9.0.0' - peerDependenciesMeta: - postcss: - optional: true - ts-node: - optional: true - dependencies: - lilconfig: 2.1.0 - yaml: 2.3.1 - dev: true - /postcss@8.4.31: resolution: {integrity: sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==} engines: {node: ^10 || ^12 || >=14} @@ -1091,31 +765,10 @@ packages: react-is: 18.2.0 dev: true - /punycode@2.3.0: - resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==} - engines: {node: '>=6'} - dev: true - - /queue-microtask@1.2.3: - resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} - dev: true - /react-is@18.2.0: resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} dev: true - /readdirp@3.6.0: - resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} - engines: {node: '>=8.10.0'} - dependencies: - picomatch: 2.3.1 - dev: true - - /resolve-from@5.0.0: - resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} - engines: {node: '>=8'} - dev: true - /resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} dev: true @@ -1128,23 +781,10 @@ packages: signal-exit: 3.0.7 dev: true - /reusify@1.0.4: - resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} - engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - dev: true - /rfdc@1.3.0: resolution: {integrity: sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==} dev: true - /rollup@3.28.1: - resolution: {integrity: sha512-R9OMQmIHJm9znrU3m3cpE8uhN0fGdXiawME7aZIpQqvpS/85+Vt1Hq1/yVIcYfOmaQiHjvXkQAoJukvLpau6Yw==} - engines: {node: '>=14.18.0', npm: '>=8.0.0'} - hasBin: true - optionalDependencies: - fsevents: 2.3.3 - dev: true - /rollup@3.29.4: resolution: {integrity: sha512-oWzmBZwvYrU0iJHtDmhsm662rC15FRXmcjCk1xD771dFDx5jJ02ufAQQTn0etB2emNk4J9EZg/yWKpsn9BWGRw==} engines: {node: '>=14.18.0', npm: '>=8.0.0'} @@ -1153,12 +793,6 @@ packages: fsevents: 2.3.3 dev: true - /run-parallel@1.2.0: - resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} - dependencies: - queue-microtask: 1.2.3 - dev: true - /shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} @@ -1179,11 +813,6 @@ packages: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} dev: true - /slash@3.0.0: - resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} - engines: {node: '>=8'} - dev: true - /slice-ansi@5.0.0: resolution: {integrity: sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==} engines: {node: '>=12'} @@ -1209,13 +838,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /source-map@0.8.0-beta.0: - resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} - engines: {node: '>= 8'} - dependencies: - whatwg-url: 7.1.0 - dev: true - /stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} dev: true @@ -1245,11 +867,6 @@ packages: ansi-regex: 6.0.1 dev: true - /strip-final-newline@2.0.0: - resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} - engines: {node: '>=6'} - dev: true - /strip-final-newline@3.0.0: resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==} engines: {node: '>=12'} @@ -1261,33 +878,6 @@ packages: acorn: 8.11.2 dev: true - /sucrase@3.34.0: - resolution: {integrity: sha512-70/LQEZ07TEcxiU2dz51FKaE6hCTWC6vr7FOk3Gr0U60C3shtAN+H+BFr9XlYe5xqf3RA8nrc+VIwzCfnxuXJw==} - engines: {node: '>=8'} - hasBin: true - dependencies: - '@jridgewell/gen-mapping': 0.3.3 - commander: 4.1.1 - glob: 7.1.6 - lines-and-columns: 1.2.4 - mz: 2.7.0 - pirates: 4.0.6 - ts-interface-checker: 0.1.13 - dev: true - - /thenify-all@1.6.0: - resolution: {integrity: sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==} - engines: {node: '>=0.8'} - dependencies: - thenify: 3.3.1 - dev: true - - /thenify@3.3.1: - resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} - dependencies: - any-promise: 1.3.0 - dev: true - /tinybench@2.5.1: resolution: {integrity: sha512-65NKvSuAVDP/n4CqH+a9w2kTlLReS9vhsAP06MWx+/89nMinJyB2icyl58RIcqCmIggpojIGeuJGhjU1aGMBSg==} dev: true @@ -1309,57 +899,6 @@ packages: is-number: 7.0.0 dev: true - /tr46@1.0.1: - resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} - dependencies: - punycode: 2.3.0 - dev: true - - /tree-kill@1.2.2: - resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} - hasBin: true - dev: true - - /ts-interface-checker@0.1.13: - resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} - dev: true - - /tsup@7.2.0(typescript@5.0.4): - resolution: {integrity: sha512-vDHlczXbgUvY3rWvqFEbSqmC1L7woozbzngMqTtL2PGBODTtWlRwGDDawhvWzr5c1QjKe4OAKqJGfE1xeXUvtQ==} - engines: {node: '>=16.14'} - hasBin: true - peerDependencies: - '@swc/core': ^1 - postcss: ^8.4.12 - typescript: '>=4.1.0' - peerDependenciesMeta: - '@swc/core': - optional: true - postcss: - optional: true - typescript: - optional: true - dependencies: - bundle-require: 4.0.1(esbuild@0.18.20) - cac: 6.7.14 - chokidar: 3.5.3 - debug: 4.3.4 - esbuild: 0.18.20 - execa: 5.1.1 - globby: 11.1.0 - joycon: 3.1.1 - postcss-load-config: 4.0.1 - resolve-from: 5.0.0 - rollup: 3.28.1 - source-map: 0.8.0-beta.0 - sucrase: 3.34.0 - tree-kill: 1.2.2 - typescript: 5.0.4 - transitivePeerDependencies: - - supports-color - - ts-node - dev: true - /tsx@3.14.0: resolution: {integrity: sha512-xHtFaKtHxM9LOklMmJdI3BEnQq/D5F73Of2E1GDrITi9sgoVkvIsrQUTY1G8FlmGtA+awCI4EBlTRRYxkL2sRg==} hasBin: true @@ -1518,18 +1057,6 @@ packages: - terser dev: true - /webidl-conversions@4.0.2: - resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} - dev: true - - /whatwg-url@7.1.0: - resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} - dependencies: - lodash.sortby: 4.7.0 - tr46: 1.0.1 - webidl-conversions: 4.0.2 - dev: true - /which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} @@ -1556,10 +1083,6 @@ packages: strip-ansi: 7.1.0 dev: true - /wrappy@1.0.2: - resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} - dev: true - /yaml@2.3.1: resolution: {integrity: sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==} engines: {node: '>= 14'} diff --git a/src/error/error_constructor.d.ts b/src/error/error_constructor.d.ts new file mode 100644 index 0000000..ac854a6 --- /dev/null +++ b/src/error/error_constructor.d.ts @@ -0,0 +1,6 @@ +// Extends the ErrorConstructor interface to include an optional `captureStackTrace` method, +// this is needed for generating declaration files for the library without errors, +// as in some environments this method may not be available. +interface ErrorConstructor { + captureStackTrace?(targetObject: object, constructorOpt?: Function | undefined): void +} diff --git a/src/error/panic.test.ts b/src/error/panic.test.ts index 91dc42b..cab350d 100644 --- a/src/error/panic.test.ts +++ b/src/error/panic.test.ts @@ -1,14 +1,17 @@ import {expect, it} from "vitest" import {Panic} from "./panic" +import {inspectSymbol} from "../util" -it("returns an instance without args", () => { +it("returns an instance without params", () => { const panic = new Panic() expect(panic).toBeInstanceOf(Error) expect(panic).toBeInstanceOf(Panic) + expect(panic.name).toEqual("Panic") expect(panic.message).toEqual("") - expect(panic.stack).toContain("Panic: ") + expect(panic.stack).toBeDefined() + expect(panic.origin).toBeUndefined() }) it("returns an instance with message", () => { @@ -18,21 +21,44 @@ it("returns an instance with message", () => { expect(panic).toBeInstanceOf(Error) expect(panic).toBeInstanceOf(Panic) + expect(panic.name).toEqual("Panic") expect(panic.message).toEqual(msg) - expect(panic.stack).toContain(`Panic: ${msg}`) + expect(panic.stack).toBeDefined() + expect(panic.origin).toBeUndefined() }) it("returns an instance with error", () => { - let origin = new Error("msg") - let panic = new Panic(origin) + const panicMsg = "panic message" + const errorMsg = "error message" + let origin = new Error(errorMsg) + let panic = new Panic(panicMsg, origin) + expect(panic).toBeInstanceOf(Error) expect(panic).toBeInstanceOf(Panic) + expect(panic.name).toEqual("Panic") + expect(panic.message).toEqual(panicMsg) + expect(panic.stack).toBeDefined() expect(panic.origin).toEqual(origin) - expect(panic.message).toEqual(origin.message) - expect(panic.stack).toContain(`Panic: ${origin.message}`) + expect(panic[inspectSymbol]()).toEqual(panic.stack + "\nCaused by: " + origin.stack) origin.name = "MyError" - panic = new Panic(origin) - expect(panic.stack).toContain(`Panic from MyError: ${origin.message}`) + panic = new Panic(panicMsg, origin) + expect(panic.stack).toBeDefined() + expect(panic[inspectSymbol]()).toEqual(panic.stack + "\nCaused by: " + origin.stack) +}) + +it("returns an instance with unknown", () => { + const panicMsg = "panic message" + let origin = "string origin" + let panic = new Panic(panicMsg, origin) + + expect(panic).toBeInstanceOf(Error) + expect(panic).toBeInstanceOf(Panic) + + expect(panic.name).toEqual("Panic") + expect(panic.message).toEqual(panicMsg) + expect(panic.stack).toBeDefined() + expect(panic.origin).toEqual(origin) + expect(panic[inspectSymbol]()).toEqual(panic.stack + "\nCaused by: " + String(origin)) }) diff --git a/src/error/panic.ts b/src/error/panic.ts index b6ee498..b504b19 100644 --- a/src/error/panic.ts +++ b/src/error/panic.ts @@ -1,29 +1,38 @@ import {inspectSymbol} from "../util" -import {getName, getOriginName, replaceStack} from "./util" export class Panic extends Error { - readonly origin?: Error - private readonly originName: string - private readonly _stack?: string + readonly origin?: unknown + override readonly name: string = "Panic" - constructor(messageOrError?: string | Error) { - if (messageOrError instanceof Error) { - super(messageOrError.message) - this.origin = messageOrError - } else { - super(messageOrError) - } - this.originName = getOriginName(this.origin) - this.name = getName("Panic", this.originName) - this._stack = this.stack // Save a copy of the stack trace before it gets overridden. + constructor(message?: string, origin?: unknown) { + super(message) + this.origin = origin } - override get stack() { - return replaceStack(this.name, this.originName, this._stack) - } + // override toString() { + // let str = formatErrorString(this.name, this.message) + // if (this.origin !== undefined) { + // str += ", caused by " + // if (this.origin instanceof Error) { + // str += formatErrorString(this.origin.name, this.origin.message) + // } else { + // str += String(this.origin) + // } + // } + // return str + // } [inspectSymbol]() { - return this.stack + let str = this.stack + if (this.origin !== undefined) { + str += "\nCaused by: " + if (this.origin instanceof Error && this.origin.stack) { + str += this.origin.stack + } else { + str += String(this.origin) + } + } + return str } } @@ -32,9 +41,3 @@ export class UnwrapPanic extends Panic { super(msg) } } - -export class InvalidErrorPanic extends Panic { - constructor(value: unknown) { - super(`Invalid error: "${value}"`) - } -} diff --git a/src/error/result_error.test.ts b/src/error/result_error.test.ts index 018cffe..3e442a9 100644 --- a/src/error/result_error.test.ts +++ b/src/error/result_error.test.ts @@ -1,74 +1,108 @@ -import {describe, expect, it} from "vitest" -import {InvalidErrorPanic, Panic, ResultError, toStdError, StdError} from "../internal" - -describe.concurrent("ResultError and StdError", () => { - it("returns instance with no args", () => { - const error = new StdError() - - expect(error).toBeInstanceOf(ResultError) - expect(error).toBeInstanceOf(StdError) - - expect(error.tag).toEqual("StdError") - - expect(error.message).toEqual("") - expect(error.stack).toContain("StdError: ") - }) - - it("returns instance with message", () => { - const msg = "msg" - const error = new StdError(msg) - - expect(error).toBeInstanceOf(ResultError) - expect(error).toBeInstanceOf(StdError) - - expect(error.tag).toEqual("StdError") - - expect(error.message).toEqual(msg) - expect(error.stack).toContain(`StdError: ${msg}`) - }) - - it("returns instance with error", () => { - let origin = new Error("msg") - let error = new StdError(origin) - - expect(error).toBeInstanceOf(ResultError) - expect(error).toBeInstanceOf(StdError) - - expect(error.tag).toEqual("StdError") - - expect(error.origin).toEqual(origin) - expect(error.message).toEqual(origin.message) - expect(error.stack).toContain(`StdError: ${origin.message}`) - - origin = new Error("msg") - origin.name = "MyError" - error = new StdError(origin) - expect(error.stack).toContain(`StdError from MyError: ${origin.message}`) +import {describe, expect, it, test} from "vitest" +import {ResultError, StdError, inspectSymbol} from "../internal" + +describe.concurrent("ResultError", () => { + class MyResultError extends ResultError { + static _tag = "MyResultError" as const + readonly tag = MyResultError._tag + + constructor(message?: string, origin?: Error) { + super(message, origin) + } + } + + describe("returns instance", () => { + test("without params", () => { + const error = new MyResultError() + + expect(error).toBeInstanceOf(ResultError) + expect(error).toBeInstanceOf(MyResultError) + + expect(error.tag).toEqual(MyResultError._tag) + expect(error.name).toEqual(error.tag) + expect(error.stack).toBeDefined() + + expect(error.message).toEqual("") + expect(error.origin).toBeNull() + expect(error.toString()).toEqual(error.name) + expect(error[inspectSymbol]()).toEqual(error.stack) + }) + + test("with message", () => { + const msg = "msg" + const error = new MyResultError(msg) + + expect(error).toBeInstanceOf(ResultError) + expect(error).toBeInstanceOf(MyResultError) + + expect(error.tag).toEqual(MyResultError._tag) + expect(error.name).toEqual(error.tag) + expect(error.stack).toBeDefined() + + expect(error.message).toEqual(msg) + expect(error.origin).toBeNull() + expect(error.toString()).toEqual(`${error.name}: ${error.message}`) + expect(error[inspectSymbol]()).toEqual(error.stack) + }) + + test("with origin", () => { + let origin = new Error("msg") + let error = new MyResultError("", origin) + + expect(error).toBeInstanceOf(ResultError) + expect(error).toBeInstanceOf(MyResultError) + + expect(error.tag).toEqual(MyResultError._tag) + expect(error.name).toEqual(error.tag) + expect(error.stack).toBeDefined() + + expect(error.message).toEqual("") + expect(error.origin).toEqual(origin) + expect(error.toString()).toEqual( + `${error.name}\nCaused by: ${error.origin?.toString()}`, + ) + expect(error[inspectSymbol]()).toEqual(error.stack + `\nCaused by: ${origin.stack}`) + }) + + test("with message and origin", () => { + const msg = "panic message" + let origin = new Error("error message") + let error = new MyResultError(msg, origin) + + expect(error).toBeInstanceOf(ResultError) + expect(error).toBeInstanceOf(MyResultError) + + expect(error.tag).toEqual(MyResultError._tag) + expect(error.name).toEqual(error.tag) + expect(error.stack).toBeDefined() + + expect(error.message).toEqual(msg) + expect(error.origin).toEqual(origin) + expect(error.toString()).toEqual( + `${error.name}: ${error.message}\nCaused by: ${error.origin?.toString()}`, + ) + expect(error[inspectSymbol]()).toEqual(error.stack + `\nCaused by: ${origin.stack}`) + }) }) }) -describe.concurrent("toStdError", () => { - it("returns an StdError when given an Error", () => { - class TestError extends Error {} - const error = new TestError("Test error") - const stdError = toStdError(error) +describe.concurrent("StdError", () => { + it("creates an instance when given an Error", () => { + const error = new Error("Test error") + const stdError = new StdError(error) expect(stdError).toBeInstanceOf(StdError) expect(stdError.origin).toEqual(error) + expect(stdError.originRaw).toEqual(error) }) - it("throws a Panic when given a Panic", () => { - const msg = "Test panic" - const panic = new Panic(msg) - expect(() => toStdError(panic)).toThrow(panic) - }) - - it("throws a Panic when given an unknown value", () => { - expect(() => toStdError(0)).toThrow(InvalidErrorPanic) - expect(() => toStdError("")).toThrow(InvalidErrorPanic) - expect(() => toStdError(true)).toThrow(InvalidErrorPanic) - expect(() => toStdError(undefined)).toThrow(InvalidErrorPanic) - expect(() => toStdError(null)).toThrow(InvalidErrorPanic) - expect(() => toStdError({})).toThrow(InvalidErrorPanic) - expect(() => toStdError([])).toThrow(InvalidErrorPanic) + it("creates an instance when given an unknown value", () => { + const values = [1, "str", true, undefined, null, {}, [], new Date()] as const + for (const value of values) { + const stdError = new StdError(value) + expect(stdError).toBeInstanceOf(StdError) + expect(stdError.origin).toBeInstanceOf(TypeError) + expect(stdError.origin.message).toEqual(`Unexpected error type: "${String(value)}"`) + expect(stdError.originRaw).toEqual(value) + } }) }) diff --git a/src/error/result_error.ts b/src/error/result_error.ts index 8f3a628..4c12659 100644 --- a/src/error/result_error.ts +++ b/src/error/result_error.ts @@ -1,60 +1,60 @@ import {inspectSymbol} from "../util" -import {InvalidErrorPanic, Panic} from "./panic" -import {getName, getOriginName, replaceStack} from "./util" +import {formatErrorString} from "./util" -export abstract class ResultError implements Error { +export abstract class ResultError implements Error { abstract readonly tag: string readonly message: string - readonly origin?: Readonly - private readonly originName: string - private readonly _stack?: string - - constructor(messageOrError: string | Error = "") { - if (messageOrError instanceof Error) { - this.message = messageOrError.message - this.origin = messageOrError - if (this.origin.stack) { - this._stack = this.origin.stack - } + readonly stack?: string + readonly origin: T | null + + constructor(message?: string, origin?: T) { + this.message = message ?? "" + this.origin = origin ?? null + + if (Error.captureStackTrace) { + Error.captureStackTrace(this, this.constructor) } else { - this.message = messageOrError - } - if (!this._stack) { - this._stack = new Error(this.message).stack + this.stack = new Error().stack } - this.originName = getOriginName(this.origin) } get name() { - return getName(this.tag, this.originName) - } - - get stack() { - return replaceStack(this.name, this.originName, this._stack) + return this.tag } toString() { - return `${this.name}${this.message ? `: ${this.message}` : ""}` + let str = formatErrorString(this.name, this.message) + if (this.origin) { + str += `\nCaused by: ${this.origin.toString()}` + } + return str } [inspectSymbol]() { - return this.stack + let str = this.stack + if (this.origin) { + str += `\nCaused by: ${this.origin.stack}` + } + return str } } -export class StdError extends ResultError { +export class StdError extends ResultError { readonly tag = "StdError" -} - -export type ErrorHandler = (error: unknown) => E -export function toStdError(error: unknown): StdError { - if (error instanceof Panic) { - throw error + override readonly origin: Error + readonly originRaw: T + + constructor(origin: T, message?: string) { + const o = + origin instanceof Error + ? origin + : new TypeError(`Unexpected error type: "${String(origin)}"`) + super(message) + this.origin = o + this.originRaw = origin } - if (error instanceof Error) { - return new StdError(error) - } - throw new InvalidErrorPanic(error) } + +export type ErrorHandler = (error: unknown) => E diff --git a/src/error/util.ts b/src/error/util.ts index 920fe95..c4da437 100644 --- a/src/error/util.ts +++ b/src/error/util.ts @@ -12,10 +12,6 @@ export function replaceStack(name: string, originName: string, stack?: string) { return stack?.replace(r, name) } -export function getOriginName(origin?: Error) { - return origin?.name ?? "Error" -} - -export function getName(name: string, originName: string) { - return originName !== "Error" ? `${name} from ${originName}` : name +export function formatErrorString(name: string, message = "") { + return name + (message ? ": " + message : "") } diff --git a/src/helpers/group.test.ts b/src/helpers/group.test.ts index 8916a89..562cae4 100644 --- a/src/helpers/group.test.ts +++ b/src/helpers/group.test.ts @@ -18,17 +18,17 @@ class BarError extends ResultError { readonly tag = "bar" } -const m = createGroup(() => new FooError()) +const g = createGroup(() => new FooError()) test("tryFn", () => { - const result = m.tryFn(() => { + const result = g.tryFn(() => { throw new Error("error") }) expect(result.unwrapErr()).toBeInstanceOf(FooError) }) test("tryFnWith", () => { - const result = m.tryFnWith( + const result = g.tryFnWith( () => { throw new Error("error") }, @@ -38,24 +38,24 @@ test("tryFnWith", () => { }) test("tryPromise", async () => { - const result = m.tryPromise(Promise.reject(new Error("error"))) + const result = g.tryPromise(Promise.reject(new Error("error"))) await expect(result.unwrapErr()).resolves.toBeInstanceOf(FooError) }) test("tryPromiseWith", async () => { - const result = m.tryPromiseWith(Promise.reject(new Error("error")), () => new BarError()) + const result = g.tryPromiseWith(Promise.reject(new Error("error")), () => new BarError()) await expect(result.unwrapErr()).resolves.toBeInstanceOf(BarError) }) test("tryAsyncFn", async () => { - const result = m.tryAsyncFn(async () => { + const result = g.tryAsyncFn(async () => { throw new Error("error") }) await expect(result.unwrapErr()).resolves.toBeInstanceOf(FooError) }) test("tryAsyncFnWith", async () => { - const result = m.tryAsyncFnWith( + const result = g.tryAsyncFnWith( async () => { throw new Error("error") }, @@ -65,14 +65,14 @@ test("tryAsyncFnWith", async () => { }) test("guard", () => { - const f = m.guard(() => { + const f = g.guard(() => { throw new Error("error") }) expect(f().unwrapErr()).toBeInstanceOf(FooError) }) test("guardWith", () => { - const f = m.guardWith( + const f = g.guardWith( () => { throw new Error("error") }, @@ -82,14 +82,14 @@ test("guardWith", () => { }) test("guardAsync", async () => { - const f = m.guardAsync(async () => { + const f = g.guardAsync(async () => { throw new Error("error") }) await expect(f().unwrapErr()).resolves.toBeInstanceOf(FooError) }) test("guardAsyncWith", async () => { - const f = m.guardAsyncWith( + const f = g.guardAsyncWith( async () => { throw new Error("error") }, diff --git a/src/helpers/group.ts b/src/helpers/group.ts index ed58143..d41b301 100644 --- a/src/helpers/group.ts +++ b/src/helpers/group.ts @@ -1,73 +1,59 @@ import {tryAsyncFnWith, tryFnWith, tryPromiseWith} from "./try" -import type {ErrorHandler, ResultError} from "../error/result_error" +import type {ErrorHandler} from "../error/result_error" import type {Result} from "../result/interface" import type {PromiseResult} from "../result/promise" -export type ResultGroupErrorHandler = (error: E) => F - type Fn = (...args: any[]) => any type AsyncFn = (...args: any[]) => Promise -export class ResultGroup { +export class ResultGroup { private constructor(private readonly handleError: ErrorHandler) {} tryFn(f: () => T): Result { return tryFnWith(f, this.handleError) } - tryFnWith( - f: () => T, - h: ResultGroupErrorHandler, - ): Result { - return tryFnWith(f, (error) => h(this.handleError(error))) + tryFnWith(f: () => T, handleError: (error: E) => F): Result { + return tryFnWith(f, (error) => handleError(this.handleError(error))) } tryPromise(promise: Promise): PromiseResult { return tryPromiseWith(promise, this.handleError) } - tryPromiseWith( - promise: Promise, - h: ResultGroupErrorHandler, - ): PromiseResult { - return tryPromiseWith(promise, (error) => h(this.handleError(error))) + tryPromiseWith(promise: Promise, handleError: (error: E) => F): PromiseResult { + return tryPromiseWith(promise, (error) => handleError(this.handleError(error))) } tryAsyncFn(f: () => Promise): PromiseResult { return tryAsyncFnWith(f, this.handleError) } - tryAsyncFnWith( - f: () => Promise, - h: ResultGroupErrorHandler, - ): PromiseResult { - return tryAsyncFnWith(f, (error) => h(this.handleError(error))) + tryAsyncFnWith(f: () => Promise, handleError: (error: E) => F): PromiseResult { + return tryAsyncFnWith(f, (error) => handleError(this.handleError(error))) } guard(f: T) { return (...args: Parameters) => this.tryFn(() => f(...args)) } - guardWith(f: T, h: ResultGroupErrorHandler) { - return (...args: Parameters) => this.tryFnWith(() => f(...args), h) + guardWith(f: T, handleError: (error: E) => F) { + return (...args: Parameters) => this.tryFnWith(() => f(...args), handleError) } guardAsync(f: T) { return (...args: Parameters) => this.tryAsyncFn(() => f(...args)) } - guardAsyncWith( - f: T, - h: ResultGroupErrorHandler, - ) { + guardAsyncWith(f: T, h: (error: E) => F) { return (...args: Parameters) => this.tryAsyncFnWith(() => f(...args), h) } - static with(handleError: ErrorHandler): ResultGroup { + static with(handleError: ErrorHandler): ResultGroup { return new ResultGroup(handleError) } } -export function createGroup(handleError: ErrorHandler): ResultGroup { +export function createGroup(handleError: ErrorHandler): ResultGroup { return ResultGroup.with(handleError) } diff --git a/src/helpers/try.ts b/src/helpers/try.ts index be5b14b..737c1ec 100644 --- a/src/helpers/try.ts +++ b/src/helpers/try.ts @@ -1,5 +1,5 @@ import {Panic} from "../error/panic" -import {type ErrorHandler, type ResultError, StdError, toStdError} from "../error/result_error" +import {type ErrorHandler, StdError} from "../error/result_error" import {Err} from "../result/err" import type {Result} from "../result/interface" import {Ok} from "../result/ok" @@ -19,14 +19,11 @@ export function tryFn(f: () => T): Result { try { return Ok(f()) } catch (error) { - return Err(toStdError(error)) + return Err(new StdError(error)) } } -export function tryFnWith( - f: () => T, - handleError: ErrorHandler, -): Result { +export function tryFnWith(f: () => T, handleError: ErrorHandler): Result { try { return Ok(f()) } catch (error) { @@ -38,12 +35,12 @@ export function tryPromise(promise: Promise): PromiseResult { return new PromiseResult( promise.then( (value) => Ok(value), - (error: unknown) => Err(toStdError(error)), + (error: unknown) => Err(new StdError(error)), ), ) } -export function tryPromiseWith( +export function tryPromiseWith( promise: Promise, handleError: ErrorHandler, ): PromiseResult { @@ -59,7 +56,7 @@ export function tryAsyncFn(f: () => Promise): PromiseResult { return tryPromise(f()) } -export function tryAsyncFnWith( +export function tryAsyncFnWith( f: () => Promise, handleError: ErrorHandler, ): PromiseResult { diff --git a/src/index.ts b/src/index.ts index 3d0c736..62603a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,11 +2,11 @@ export { Err, None, Ok, - Option, + type Option, Panic, PromiseOption, PromiseResult, - Result, + type Result, ResultError, ResultGroup, Some, diff --git a/src/option/interface.ts b/src/option/interface.ts index 7046606..345a813 100644 --- a/src/option/interface.ts +++ b/src/option/interface.ts @@ -1,10 +1,9 @@ -import type {Panic} from "../error/panic" import type {inspectSymbol} from "../util" export interface OptionMethods { and(other: Option): Option andThen(f: (value: T) => Option): Option - expect(panic: string | Panic): T + expect(panic: string): T filter(f: (value: T) => boolean): Option inspect(f: (value: T) => void): Option map(f: (value: T) => U): Option diff --git a/src/option/none.ts b/src/option/none.ts index 6c31a9f..4a24246 100644 --- a/src/option/none.ts +++ b/src/option/none.ts @@ -14,8 +14,8 @@ export class NoneImpl implements NoneVariant, OptionMethods { return None } - expect(panic: string | Panic): never { - throw typeof panic === "string" ? new Panic(panic) : panic + expect(panic: string): never { + throw new Panic(panic) } filter(_f: (value: never) => boolean) { diff --git a/src/option/option.test.ts b/src/option/option.test.ts index 7f9df1e..db28206 100644 --- a/src/option/option.test.ts +++ b/src/option/option.test.ts @@ -60,8 +60,8 @@ describe.concurrent("expect", () => { it("throws when called on a None option", () => { const option = None + expect(() => option.expect("error")).toThrow(Panic) expect(() => option.expect("error")).toThrow("error") - expect(() => option.expect(new Panic("custom panic"))).toThrow("custom panic") }) }) diff --git a/src/option/promise.test.ts b/src/option/promise.test.ts index b90e41b..10d6c86 100644 --- a/src/option/promise.test.ts +++ b/src/option/promise.test.ts @@ -56,9 +56,6 @@ describe.concurrent("expect", () => { it("throws Panic when called on a None option", async () => { const option = promiseNone() await expect(option.expect("msg")).rejects.toEqual(new Panic("msg")) - await expect(option.expect(new Panic("custom panic"))).rejects.toEqual( - new Panic("custom panic"), - ) }) }) diff --git a/src/option/promise.ts b/src/option/promise.ts index 7e83dfa..323feeb 100644 --- a/src/option/promise.ts +++ b/src/option/promise.ts @@ -1,4 +1,3 @@ -import type {Panic} from "../error/panic" import type {Option} from "./interface" export class PromiseOption implements PromiseLike> { @@ -38,7 +37,7 @@ export class PromiseOption implements PromiseLike> { return new PromiseOption(this.then((option) => option.andThen((value) => f(value)))) } - async expect(panic: Panic | string) { + async expect(panic: string) { return (await this).expect(panic) } diff --git a/src/option/some.ts b/src/option/some.ts index 2d8b588..a54d704 100644 --- a/src/option/some.ts +++ b/src/option/some.ts @@ -1,4 +1,3 @@ -import type {Panic} from "../error/panic" import {inspectSymbol} from "../util" import type {OptionMethods, Option, SomeVariant} from "./interface" import {None} from "./none" @@ -20,7 +19,7 @@ export class SomeImpl implements SomeVariant, OptionMethods { return f(this.value) } - expect(_panic: string | Panic) { + expect(_panic: string) { return this.value } diff --git a/src/result/err.ts b/src/result/err.ts index 2e86252..fc0db50 100644 --- a/src/result/err.ts +++ b/src/result/err.ts @@ -19,14 +19,11 @@ export class ErrImpl implements ErrVariant, ResultMethods { return this } - expect(panic: string | Panic): never { - if (panic instanceof Panic) { - throw panic - } - throw new Panic(panic) + expect(panic: string): never { + throw new Panic(panic, this.error) } - expectErr(_panic: string | Panic) { + expectErr(_panic: string) { return this.error } @@ -64,7 +61,7 @@ export class ErrImpl implements ErrVariant, ResultMethods { } unwrap(): never { - throw new UnwrapPanic(`Cannot unwrap on an Err: ${this.error}`) + throw new UnwrapPanic(`called "unwrap()" on ${this.toString()}`) } unwrapErr() { diff --git a/src/result/interface.ts b/src/result/interface.ts index 78c59a1..8e5f8ce 100644 --- a/src/result/interface.ts +++ b/src/result/interface.ts @@ -1,11 +1,10 @@ -import type {Panic} from "../error/panic" import type {inspectSymbol} from "../util" export interface ResultMethods { and(other: Result): Result andThen(f: (value: T) => Result): Result - expect(panic: string | Panic): T - expectErr(panic: string | Panic): E + expect(panic: string): T + expectErr(panic: string): E inspect(f: (value: T) => void): Result inspectErr(f: (error: E) => void): Result map(f: (value: T) => U): Result diff --git a/src/result/ok.ts b/src/result/ok.ts index df2fbf1..52e1032 100644 --- a/src/result/ok.ts +++ b/src/result/ok.ts @@ -19,15 +19,12 @@ export class OkImpl implements OkVariant, ResultMethods { return f(this.value) } - expect(_panic: string | Panic) { + expect(_panic: string) { return this.value } - expectErr(panic: string | Panic): never { - if (panic instanceof Panic) { - throw panic - } - throw new Panic(panic) + expectErr(panic: string): never { + throw new Panic(panic, this.value) } inspect(f: (value: T) => void) { @@ -68,7 +65,7 @@ export class OkImpl implements OkVariant, ResultMethods { } unwrapErr(): never { - throw new UnwrapPanic("Cannot unwrapErr on an Ok") + throw new UnwrapPanic(`called "unwrapErr()" on ${this.toString()}`) } unwrapOr(_defaultValue: U) { diff --git a/src/result/promise.test.ts b/src/result/promise.test.ts index 9ee044f..ff24c18 100644 --- a/src/result/promise.test.ts +++ b/src/result/promise.test.ts @@ -59,13 +59,6 @@ describe.concurrent("expect", () => { const result = new PromiseResult(Promise.resolve(Err(error))) await expect(result.expect("Panic message")).rejects.toThrow(Panic) }) - - it("throws a Panic with the provided Panic when called on an Err result", async () => { - const error = new Error("Original error") - const result = new PromiseResult(Promise.resolve(Err(error))) - const panic = new Panic("Panic") - await expect(result.expect(panic)).rejects.toEqual(panic) - }) }) describe.concurrent("expectErr", () => { @@ -79,12 +72,6 @@ describe.concurrent("expectErr", () => { const result = new PromiseResult(Promise.resolve(Ok())) await expect(result.expectErr("Panic message")).rejects.toThrow(Panic) }) - - it("throws a Panic with the provided Panic when called on an Ok result", async () => { - const result = new PromiseResult(Promise.resolve(Ok())) - const panic = new Panic("Panic") - await expect(result.expectErr(panic)).rejects.toEqual(panic) - }) }) describe.concurrent("inspect", async () => { @@ -293,16 +280,6 @@ describe.concurrent("unwrapOrElse", () => { const result = new PromiseResult(Promise.resolve(Err(error))) await expect(result.unwrapOrElse(() => 42)).resolves.toEqual(42) }) - - it("can panic", async () => { - const error = new Error("Test error") - const result = new PromiseResult(Promise.resolve(Err(error))) - await expect(() => - result.unwrapOrElse((error) => { - throw new Panic(error) - }), - ).rejects.toThrow(Panic) - }) }) describe.concurrent("into", () => { diff --git a/src/result/promise.ts b/src/result/promise.ts index 74b86ce..b9629ca 100644 --- a/src/result/promise.ts +++ b/src/result/promise.ts @@ -1,5 +1,4 @@ import type {Result} from "./interface" -import type {Panic} from "../error/panic" export class PromiseResult implements PromiseLike> { constructor( @@ -42,11 +41,11 @@ export class PromiseResult implements PromiseLike> { ) } - async expect(panic: Panic | string) { + async expect(panic: string) { return (await this).expect(panic) } - async expectErr(panic: Panic | string) { + async expectErr(panic: string) { return (await this).expectErr(panic) } diff --git a/src/result/result.test.ts b/src/result/result.test.ts index 130277f..0e048c5 100644 --- a/src/result/result.test.ts +++ b/src/result/result.test.ts @@ -1,6 +1,8 @@ import {describe, it, expect} from "vitest" import {Panic, UnwrapPanic, Ok, Err, Result} from "../internal" +const testErr = new Error("hello") + describe.concurrent("ok", () => { it("returns an Ok result", () => { const result = Ok(42) @@ -59,20 +61,20 @@ describe.concurrent("expect", () => { it("returns the value when called on an Ok result", () => { const result = Ok(42) const value = result.expect("Panic message") - expect(value).to.equal(42) + expect(value).toEqual(42) }) it("throws a Panic with the provided message when called on an Err result", () => { const error = new Error("Original error") const result = Err(error) - expect(() => result.expect("Panic message")).to.throw(Panic, "Panic message") - }) - - it("throws a Panic with the provided Panic when called on an Err result", () => { - const error = new Error("Original error") - const result = Err(error) - const panic = new Panic("custom panic") - expect(() => result.expect(panic)).to.throw(panic) + const panicMsg = "Panic message" + try { + Err(testErr).expect("hello") + } catch (err) { + console.log(err) + } + expect(() => result.expect(panicMsg)).toThrow(Panic) + expect(() => result.expect(panicMsg)).toThrow(panicMsg) }) }) @@ -85,13 +87,9 @@ describe.concurrent("expectErr", () => { it("throws a Panic with the provided message when called on an Ok result", () => { const ok = Ok() - expect(() => ok.expectErr("Panic message")).to.throw(Panic, "Panic message") - }) - - it("throws a Panic with the provided Panic when called on an Ok result", () => { - const result = Ok() - const panic = new Panic("custom panic") - expect(() => result.expectErr(panic)).to.throw(panic) + const panicMsg = "Panic message" + expect(() => ok.expectErr(panicMsg)).toThrow(Panic) + expect(() => ok.expectErr(panicMsg)).toThrow(panicMsg) }) }) @@ -293,15 +291,6 @@ describe.concurrent("unwrapOrElse", () => { const unwrapped = result.unwrapOrElse(() => 42) expect(unwrapped).toEqual(42) }) - - it("can panic", () => { - const error = new Error("Test error") - expect(() => - Err(error).unwrapOrElse((error) => { - throw new Panic(error) - }), - ).toThrow(Panic) - }) }) describe.concurrent("into", () => { diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..44465b7 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "lib", + "declaration": true, + "removeComments": false + }, + "include": ["src"], + "exclude": ["node_modules", "**/*.ignore.ts", "**/*.test.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index a639859..123109f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,20 @@ { "compilerOptions": { + "skipLibCheck": true, + + "moduleDetection": "force", + "isolatedModules": true, + "resolveJsonModule": true, + "esModuleInterop": true, "moduleResolution": "Bundler", "module": "ESNext", - "target": "ES2021", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + + "target": "ES2022", + "noEmit": true, "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "allowUnusedLabels": false, "allowUnreachableCode": false, // "exactOptionalPropertyTypes": true, @@ -18,9 +24,8 @@ "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true, "noUnusedLocals": true, - "noUnusedParameters": true, - - "checkJs": true + "noUnusedParameters": true }, - "exclude": ["node_modules", "lib"] + "include": ["src"], + "exclude": ["node_modules", "lib", "**/*.ignore.ts"] } diff --git a/tsup.config.ts b/tsup.config.ts deleted file mode 100644 index 4aeb3a7..0000000 --- a/tsup.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {defineConfig} from "tsup" - -export default defineConfig({ - entry: ["src/index.ts", "src/internal.ts"], - clean: true, - dts: true, - format: "esm", - outDir: "lib", -})