From 80ff2a3c8ab821d1ef503546b162da30808aa564 Mon Sep 17 00:00:00 2001 From: Mattia Manzati Date: Tue, 21 Jan 2025 11:10:48 +0100 Subject: [PATCH] update internal effect version to 3 --- .changeset/cuddly-mangos-unite.md | 6 + .vscode/settings.json | 4 +- examples/refactors/pipeableToDatafirst.ts | 2 +- package.json | 5 +- pnpm-lock.yaml | 296 +++++++++++++++----- src/definition.ts | 5 +- src/index.ts | 12 +- src/quickinfo.ts | 4 +- src/refactors/asyncAwaitToGen.ts | 21 +- src/refactors/asyncAwaitToGenTryPromise.ts | 21 +- src/refactors/functionToArrow.ts | 18 +- src/refactors/pipeableToDatafirst.ts | 24 +- src/refactors/toggleLazyConst.ts | 14 +- src/refactors/toggleReturnTypeAnnotation.ts | 10 +- src/refactors/toggleTypeAnnotation.ts | 14 +- src/refactors/wrapWithPipe.ts | 6 +- src/utils/AST.ts | 77 +++-- test/__snapshots__/refactors.test.ts.snap | 30 +- tsup.config.ts | 5 +- 19 files changed, 362 insertions(+), 212 deletions(-) create mode 100644 .changeset/cuddly-mangos-unite.md diff --git a/.changeset/cuddly-mangos-unite.md b/.changeset/cuddly-mangos-unite.md new file mode 100644 index 0000000..36358a0 --- /dev/null +++ b/.changeset/cuddly-mangos-unite.md @@ -0,0 +1,6 @@ +--- +"@effect/language-service": minor +--- + +- Update internal version of effect from 2.x beta to 3.12.5 +- Remove adapter from gen refactors diff --git a/.vscode/settings.json b/.vscode/settings.json index 7161e79..0e8edd7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,7 +24,7 @@ }, "eslint.validate": ["markdown", "javascript", "typescript"], "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "editor.quickSuggestions": { "other": true, @@ -38,7 +38,7 @@ "editor.tabCompletion": "off", "editor.suggest.localityBonus": true, "editor.suggestSelection": "recentlyUsed", - "editor.wordBasedSuggestions": true, + "editor.wordBasedSuggestions": "matchingDocuments", "editor.parameterHints.enabled": true, "files.insertFinalNewline": true } diff --git a/examples/refactors/pipeableToDatafirst.ts b/examples/refactors/pipeableToDatafirst.ts index f41dd7f..e89638e 100644 --- a/examples/refactors/pipeableToDatafirst.ts +++ b/examples/refactors/pipeableToDatafirst.ts @@ -9,7 +9,7 @@ const test = pipe( T.map((_) => _ * 2) ) -const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) +const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) const test2 = pipe( T.succeed("Hello"), diff --git a/package.json b/package.json index 91a8b17..81dcbc9 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "@effect/docgen": "^0.3.6", "@effect/eslint-plugin": "^0.1.2", "@effect/language-service": "link:dist", - "@effect/platform-node": "^0.34.2", "@rollup/pluginutils": "^5.0.2", "@types/node": "^20.10.2", "@typescript-eslint/eslint-plugin": "^6.13.1", @@ -54,7 +53,9 @@ "@typescript-eslint/type-utils": "6.13.2", "@typescript-eslint/utils": "^6.13.1", "@vitest/coverage-v8": "^1.0.2", - "effect": "2.0.0-next.59", + "effect": "3.12.5", + "@effect/platform-node": "0.70.0", + "@effect/platform": "0.74.0", "eslint": "^8.55.0", "eslint-import-resolver-typescript": "^3.5.2", "eslint-plugin-codegen": "^0.21.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9b36c2..ec1edf5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,12 @@ devDependencies: '@effect/language-service': specifier: link:dist version: link:dist + '@effect/platform': + specifier: 0.74.0 + version: 0.74.0(effect@3.12.5) '@effect/platform-node': - specifier: ^0.34.2 - version: 0.34.2(@effect/schema@0.52.0)(effect@2.0.0-next.59) + specifier: 0.70.0 + version: 0.70.0(@effect/platform@0.74.0)(effect@3.12.5) '@rollup/pluginutils': specifier: ^5.0.2 version: 5.1.0 @@ -48,8 +51,8 @@ devDependencies: specifier: ^1.0.2 version: 1.0.2(vitest@1.0.2) effect: - specifier: 2.0.0-next.59 - version: 2.0.0-next.59 + specifier: 3.12.5 + version: 3.12.5 eslint: specifier: ^8.55.0 version: 8.55.0 @@ -543,7 +546,7 @@ packages: dependencies: doctrine: 3.0.0 glob: 10.3.10 - markdown-toc: github.com/effect-ts/markdown-toc/4bfeb0f140105440ea0d12df2fa23199cc3ec1d5 + markdown-toc: github.com/effect-ts/markdown-toc/3ea4550bf1352c612aa8b9e582dc263a89f2b64d prettier: 3.1.0 tsx: 4.6.2 typescript: 5.3.3 @@ -557,40 +560,43 @@ packages: diff: 5.1.0 dev: true - /@effect/platform-node@0.34.2(@effect/schema@0.52.0)(effect@2.0.0-next.59): - resolution: {integrity: sha512-9oE6wlQtcP+aX2ZqD2Q7cD6MjAkRxE4wD7MZICb65QOhXjtblXijgMbxVuGnHIhr5+cNCS7lFgzEEqhU/BX72Q==} + /@effect/platform-node-shared@0.24.0(@effect/platform@0.74.0)(effect@3.12.5): + resolution: {integrity: sha512-kgvA2MhpGX2ubwzr5JexoyucKPvy6arCqJjpENX8SWz5eJ8UqtH2LUX3hDwjDQOkOTu37i0zLUi5FeogtXj85A==} peerDependencies: - effect: 2.0.0-next.59 + '@effect/platform': ^0.74.0 + effect: ^3.12.5 dependencies: - '@effect/platform': 0.33.1(@effect/schema@0.52.0)(effect@2.0.0-next.59) - effect: 2.0.0-next.59 - mime: 3.0.0 - multipasta: 0.1.19 - transitivePeerDependencies: - - '@effect/schema' + '@effect/platform': 0.74.0(effect@3.12.5) + '@parcel/watcher': 2.5.0 + effect: 3.12.5 + multipasta: 0.2.5 dev: true - /@effect/platform@0.33.1(@effect/schema@0.52.0)(effect@2.0.0-next.59): - resolution: {integrity: sha512-0NVh8Rt22kYrVrgKpivSuPT27d+JgpENyfdzpOy09/9EQpA/33XKgCXrGSBpkRGrCsH7DIpmeWIVSHMrkcpCUw==} + /@effect/platform-node@0.70.0(@effect/platform@0.74.0)(effect@3.12.5): + resolution: {integrity: sha512-ID8TAU3Eqign7cByYu9dau5Q+10fN5C/9AJ+MxzxUaGb2s0hddTO4lpyCSzyHnk3m8uAVsDyAJG555NfRtHrug==} peerDependencies: - '@effect/schema': ^0.52.0 - effect: 2.0.0-next.59 + '@effect/platform': ^0.74.0 + effect: ^3.12.5 dependencies: - '@effect/schema': 0.52.0(effect@2.0.0-next.59)(fast-check@3.14.0) - effect: 2.0.0-next.59 - find-my-way: 7.7.0 - multipasta: 0.1.19 - path-browserify: 1.0.1 + '@effect/platform': 0.74.0(effect@3.12.5) + '@effect/platform-node-shared': 0.24.0(@effect/platform@0.74.0)(effect@3.12.5) + effect: 3.12.5 + mime: 3.0.0 + undici: 7.2.3 + ws: 8.18.0 + transitivePeerDependencies: + - bufferutil + - utf-8-validate dev: true - /@effect/schema@0.52.0(effect@2.0.0-next.59)(fast-check@3.14.0): - resolution: {integrity: sha512-x6SmSdoL6PeZVAaK895NoRkKF8D/w+XyO8i17cUsQYFJBHNyUTi9Y1H2wrO8TkxhTmC93ejburpM+35/OKCi2Q==} + /@effect/platform@0.74.0(effect@3.12.5): + resolution: {integrity: sha512-WTniLZ9j5+sLZWKIEwJIUBvA5xKKG/xiLbgApTotc24ohjBZTldcMRNG/a+nAtKuFUSFn88DYY3iReW790xPFw==} peerDependencies: - effect: 2.0.0-next.59 - fast-check: ^3.13.2 + effect: ^3.12.5 dependencies: - effect: 2.0.0-next.59 - fast-check: 3.14.0 + effect: 3.12.5 + find-my-way-ts: 0.1.5 + multipasta: 0.2.5 dev: true /@esbuild/android-arm64@0.18.20: @@ -1160,6 +1166,148 @@ packages: fastq: 1.15.0 dev: true + /@parcel/watcher-android-arm64@2.5.0: + resolution: {integrity: sha512-qlX4eS28bUcQCdribHkg/herLe+0A9RyYC+mm2PXpncit8z5b3nSqGVzMNR3CmtAOgRutiZ02eIJJgP/b1iEFQ==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-darwin-arm64@2.5.0: + resolution: {integrity: sha512-hyZ3TANnzGfLpRA2s/4U1kbw2ZI4qGxaRJbBH2DCSREFfubMswheh8TeiC1sGZ3z2jUf3s37P0BBlrD3sjVTUw==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-darwin-x64@2.5.0: + resolution: {integrity: sha512-9rhlwd78saKf18fT869/poydQK8YqlU26TMiNg7AIu7eBp9adqbJZqmdFOsbZ5cnLp5XvRo9wcFmNHgHdWaGYA==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-freebsd-x64@2.5.0: + resolution: {integrity: sha512-syvfhZzyM8kErg3VF0xpV8dixJ+RzbUaaGaeb7uDuz0D3FK97/mZ5AJQ3XNnDsXX7KkFNtyQyFrXZzQIcN49Tw==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-linux-arm-glibc@2.5.0: + resolution: {integrity: sha512-0VQY1K35DQET3dVYWpOaPFecqOT9dbuCfzjxoQyif1Wc574t3kOSkKevULddcR9znz1TcklCE7Ht6NIxjvTqLA==} + engines: {node: '>= 10.0.0'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-linux-arm-musl@2.5.0: + resolution: {integrity: sha512-6uHywSIzz8+vi2lAzFeltnYbdHsDm3iIB57d4g5oaB9vKwjb6N6dRIgZMujw4nm5r6v9/BQH0noq6DzHrqr2pA==} + engines: {node: '>= 10.0.0'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-linux-arm64-glibc@2.5.0: + resolution: {integrity: sha512-BfNjXwZKxBy4WibDb/LDCriWSKLz+jJRL3cM/DllnHH5QUyoiUNEp3GmL80ZqxeumoADfCCP19+qiYiC8gUBjA==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-linux-arm64-musl@2.5.0: + resolution: {integrity: sha512-S1qARKOphxfiBEkwLUbHjCY9BWPdWnW9j7f7Hb2jPplu8UZ3nes7zpPOW9bkLbHRvWM0WDTsjdOTUgW0xLBN1Q==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-linux-x64-glibc@2.5.0: + resolution: {integrity: sha512-d9AOkusyXARkFD66S6zlGXyzx5RvY+chTP9Jp0ypSTC9d4lzyRs9ovGf/80VCxjKddcUvnsGwCHWuF2EoPgWjw==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-linux-x64-musl@2.5.0: + resolution: {integrity: sha512-iqOC+GoTDoFyk/VYSFHwjHhYrk8bljW6zOhPuhi5t9ulqiYq1togGJB5e3PwYVFFfeVgc6pbz3JdQyDoBszVaA==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-win32-arm64@2.5.0: + resolution: {integrity: sha512-twtft1d+JRNkM5YbmexfcH/N4znDtjgysFaV9zvZmmJezQsKpkfLYJ+JFV3uygugK6AtIM2oADPkB2AdhBrNig==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-win32-ia32@2.5.0: + resolution: {integrity: sha512-+rgpsNRKwo8A53elqbbHXdOMtY/tAtTzManTWShB5Kk54N8Q9mzNWV7tV+IbGueCbcj826MfWGU3mprWtuf1TA==} + engines: {node: '>= 10.0.0'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher-win32-x64@2.5.0: + resolution: {integrity: sha512-lPrxve92zEHdgeff3aiu4gDOIt4u7sJYha6wbdEZDCDUhtjTsOMiaJzG5lMY4GkWH8p0fMmO2Ppq5G5XXG+DQw==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@parcel/watcher@2.5.0: + resolution: {integrity: sha512-i0GV1yJnm2n3Yq1qw6QrUrd/LI9bE8WEBOTtOkpCXHHdyN3TAGgqAK/DAT05z4fq2x04cARXt2pDmjWjL92iTQ==} + engines: {node: '>= 10.0.0'} + requiresBuild: true + dependencies: + detect-libc: 1.0.3 + is-glob: 4.0.3 + micromatch: 4.0.5 + node-addon-api: 7.1.1 + optionalDependencies: + '@parcel/watcher-android-arm64': 2.5.0 + '@parcel/watcher-darwin-arm64': 2.5.0 + '@parcel/watcher-darwin-x64': 2.5.0 + '@parcel/watcher-freebsd-x64': 2.5.0 + '@parcel/watcher-linux-arm-glibc': 2.5.0 + '@parcel/watcher-linux-arm-musl': 2.5.0 + '@parcel/watcher-linux-arm64-glibc': 2.5.0 + '@parcel/watcher-linux-arm64-musl': 2.5.0 + '@parcel/watcher-linux-x64-glibc': 2.5.0 + '@parcel/watcher-linux-x64-musl': 2.5.0 + '@parcel/watcher-win32-arm64': 2.5.0 + '@parcel/watcher-win32-ia32': 2.5.0 + '@parcel/watcher-win32-x64': 2.5.0 + dev: true + /@pkgjs/parseargs@0.11.0: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} @@ -2300,6 +2448,12 @@ packages: engines: {node: '>=8'} dev: true + /detect-libc@1.0.3: + resolution: {integrity: sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==} + engines: {node: '>=0.10'} + hasBin: true + dev: true + /detective-amd@3.1.2: resolution: {integrity: sha512-jffU26dyqJ37JHR/o44La6CxtrDf3Rt9tvd2IbImJYxWKTMdBjctp37qoZ6ZcY80RHg+kzWz4bXn39e4P7cctQ==} engines: {node: '>=6.0'} @@ -2499,8 +2653,10 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /effect@2.0.0-next.59: - resolution: {integrity: sha512-EE87vFl0/zIN5lKDtFccU3YCnbPqjxg9rY72obNN65/GE4JOJsXciyX8XC4pIDr3lE6KeJ0le8IXf+A7d92ntQ==} + /effect@3.12.5: + resolution: {integrity: sha512-hP+ev9NTjYcvySbPOOgrYiwCYxiIcjuvtR8WXMoSZEZEshOyQlDwgo1Z56kVezv1rTxz20PEGVqZGlXwxe6Ofw==} + dependencies: + fast-check: 3.23.2 dev: true /electron-to-chromium@1.4.607: @@ -3049,15 +3205,11 @@ packages: tmp: 0.0.33 dev: true - /fast-check@3.14.0: - resolution: {integrity: sha512-9Z0zqASzDNjXBox/ileV/fd+4P+V/f3o4shM6QawvcdLFh8yjPG4h5BrHUZ8yzY6amKGDTAmRMyb/JZqe+dCgw==} + /fast-check@3.23.2: + resolution: {integrity: sha512-h5+1OzzfCC3Ef7VbtKdcv7zsstUQwUDlYpUTvjeUsJAssPgLn7QzbboPtL5ro04Mq0rPOsMzl7q5hIbRs2wD1A==} engines: {node: '>=8.0.0'} dependencies: - pure-rand: 6.0.4 - dev: true - - /fast-decode-uri-component@1.0.1: - resolution: {integrity: sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==} + pure-rand: 6.1.0 dev: true /fast-deep-equal@3.1.3: @@ -3083,12 +3235,6 @@ packages: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} dev: true - /fast-querystring@1.1.2: - resolution: {integrity: sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==} - dependencies: - fast-decode-uri-component: 1.0.1 - dev: true - /fastq@1.15.0: resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} dependencies: @@ -3143,13 +3289,8 @@ packages: to-regex-range: 5.0.1 dev: true - /find-my-way@7.7.0: - resolution: {integrity: sha512-+SrHpvQ52Q6W9f3wJoJBbAQULJuNEEQwBvlvYwACDhBTLOTMiQ0HYWh4+vC3OivGP2ENcTI1oKlFA2OepJNjhQ==} - engines: {node: '>=14'} - dependencies: - fast-deep-equal: 3.1.3 - fast-querystring: 1.1.2 - safe-regex2: 2.0.0 + /find-my-way-ts@0.1.5: + resolution: {integrity: sha512-4GOTMrpGQVzsCH2ruUn2vmwzV/02zF4q+ybhCIrw/Rkt3L8KWcycdC6aJMctJzwN4fXD4SD5F/4B9Sksh5rE0A==} dev: true /find-up@4.1.0: @@ -4459,8 +4600,8 @@ packages: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} dev: true - /multipasta@0.1.19: - resolution: {integrity: sha512-vRQ17a7eQRImx/vS4PcJlDDuzzCT5nigItgDFNT/db9NiVEiscdkUWbUg3cHrv2x0oznNu5YNO+NBo5Z2rBL+w==} + /multipasta@0.2.5: + resolution: {integrity: sha512-c8eMDb1WwZcE02WVjHoOmUVk7fnKU/RmUcosHACglrWAuPQsEJv+E8430sXj6jNc1jHw0zrS16aCjQh4BcEb4A==} dev: true /mz@2.7.0: @@ -4485,6 +4626,10 @@ packages: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: true + /node-addon-api@7.1.1: + resolution: {integrity: sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==} + dev: true + /node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -4743,10 +4888,6 @@ packages: engines: {node: '>=6'} dev: true - /path-browserify@1.0.1: - resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} - dev: true - /path-exists@4.0.0: resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} engines: {node: '>=8'} @@ -4977,8 +5118,8 @@ packages: engines: {node: '>=6'} dev: true - /pure-rand@6.0.4: - resolution: {integrity: sha512-LA0Y9kxMYv47GIPJy6MI84fqTd2HmYZI83W/kM/SkKfDlajnZYfmXFTxkbY+xSBPkLJxltMa9hIkmdc29eguMA==} + /pure-rand@6.1.0: + resolution: {integrity: sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==} dev: true /queue-microtask@1.2.3: @@ -5174,11 +5315,6 @@ packages: signal-exit: 3.0.7 dev: true - /ret@0.2.2: - resolution: {integrity: sha512-M0b3YWQs7R3Z917WRQy1HHA7Ba7D8hvZg6UE5mLykJxQVE2ju0IXbGlaHPPlkY+WN7wFP+wUMXmBFA0aV6vYGQ==} - engines: {node: '>=4'} - dev: true - /reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -5251,12 +5387,6 @@ packages: is-regex: 1.1.4 dev: true - /safe-regex2@2.0.0: - resolution: {integrity: sha512-PaUSFsUaNNuKwkBijoAPHAK6/eM6VirvyPWlZ7BAQy4D+hCvh4B6lIG+nPdhbFfIbP+gTGBcrdsOaUs0F+ZBOQ==} - dependencies: - ret: 0.2.2 - dev: true - /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} dev: true @@ -5989,6 +6119,11 @@ packages: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} dev: true + /undici@7.2.3: + resolution: {integrity: sha512-2oSLHaDalSt2/O/wHA9M+/ZPAOcU2yrSP/cdBYJ+YxZskiPYDSqHbysLSlD7gq3JMqOoJI5O31RVU3BxX/MnAA==} + engines: {node: '>=20.18.1'} + dev: true + /uniq@1.0.1: resolution: {integrity: sha512-Gw+zz50YNKPDKXs+9d+aKAjVwpjNwqzvNpLigIruT4HA9lMZNdMqs9x07kKHB/L9WRzqp4+DlTU5s4wG2esdoA==} dev: true @@ -6277,6 +6412,19 @@ packages: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} dev: true + /ws@8.18.0: + resolution: {integrity: sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: true + /xtend@4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} @@ -6361,10 +6509,10 @@ packages: engines: {node: '>=12.20'} dev: true - github.com/effect-ts/markdown-toc/4bfeb0f140105440ea0d12df2fa23199cc3ec1d5: - resolution: {tarball: https://codeload.github.com/effect-ts/markdown-toc/tar.gz/4bfeb0f140105440ea0d12df2fa23199cc3ec1d5} - name: markdown-toc - version: 1.2.0 + github.com/effect-ts/markdown-toc/3ea4550bf1352c612aa8b9e582dc263a89f2b64d: + resolution: {tarball: https://codeload.github.com/effect-ts/markdown-toc/tar.gz/3ea4550bf1352c612aa8b9e582dc263a89f2b64d} + name: '@effect/markdown-toc' + version: 0.1.0 engines: {node: '>=0.10.0'} hasBin: true dependencies: diff --git a/src/definition.ts b/src/definition.ts index 52a3471..f7653fb 100644 --- a/src/definition.ts +++ b/src/definition.ts @@ -1,7 +1,7 @@ /** * @since 1.0.0 */ -import type * as O from "effect/Option" +import type * as Option from "effect/Option" import type ts from "typescript" import type * as AST from "./utils/AST.js" @@ -15,7 +15,7 @@ export interface RefactorDefinition { apply: (ts: AST.TypeScriptApi, program: ts.Program, options: PluginOptions) => ( sourceFile: ts.SourceFile, textRange: ts.TextRange - ) => O.Option + ) => Option.Option } /** @@ -41,5 +41,4 @@ export function createRefactor(definition: RefactorDefinition) { * @category plugin */ export interface PluginOptions { - preferredEffectGenAdapterName: string } diff --git a/src/index.ts b/src/index.ts index d86b480..3154a13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ * @since 1.0.0 */ import { pipe } from "effect/Function" -import * as O from "effect/Option" +import * as Option from "effect/Option" import type ts from "typescript" import type { PluginOptions } from "./definition.js" import { dedupeJsDocTags } from "./quickinfo.js" @@ -19,9 +19,7 @@ const init = ( function create(info: ts.server.PluginCreateInfo) { const languageService = info.languageService - const pluginOptions: PluginOptions = { - preferredEffectGenAdapterName: info.config.preferredEffectGenAdapterName ?? "_" - } + const pluginOptions: PluginOptions = {} // create the proxy const proxy: ts.LanguageService = Object.create(null) @@ -47,7 +45,7 @@ const init = ( sourceFile, textRange ), - O.map((_) => ({ + Option.map((_) => ({ name: refactor.name, description: refactor.description, actions: [{ @@ -61,7 +59,7 @@ const init = ( (_) => _.reduce( (arr, maybeRefactor) => - arr.concat(O.isSome(maybeRefactor) ? [maybeRefactor.value] : []), + arr.concat(Option.isSome(maybeRefactor) ? [maybeRefactor.value] : []), [] as Array ) ) @@ -96,7 +94,7 @@ const init = ( textRange ) - if (O.isNone(possibleRefactor)) { + if (Option.isNone(possibleRefactor)) { info.project.projectService.logger.info( "[@effect/language-service] requested refactor " + refactorName + " is not applicable" diff --git a/src/quickinfo.ts b/src/quickinfo.ts index 0790ed5..2700c0d 100644 --- a/src/quickinfo.ts +++ b/src/quickinfo.ts @@ -1,8 +1,8 @@ /** * @since 1.0.0 */ +import * as ReadonlyArray from "effect/Array" import * as Eq from "effect/Equivalence" -import * as A from "effect/ReadonlyArray" import type ts from "typescript" const SymbolDisplayPartEq = Eq.make((fa, fb) => @@ -21,7 +21,7 @@ export function dedupeJsDocTags(quickInfo: ts.QuickInfo): ts.QuickInfo { if (quickInfo.tags) { return { ...quickInfo, - tags: A.dedupeWith(quickInfo.tags, JSDocTagInfoEq) + tags: ReadonlyArray.dedupeWith(quickInfo.tags, JSDocTagInfoEq) } } return quickInfo diff --git a/src/refactors/asyncAwaitToGen.ts b/src/refactors/asyncAwaitToGen.ts index b9635dc..d80e552 100644 --- a/src/refactors/asyncAwaitToGen.ts +++ b/src/refactors/asyncAwaitToGen.ts @@ -1,28 +1,29 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" export const asyncAwaitToGen = createRefactor({ name: "effect/asyncAwaitToGen", description: "Convert to Effect.gen", - apply: (ts, program, options) => (sourceFile, textRange) => + apply: (ts, program) => (sourceFile, textRange) => pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(ts.isFunctionDeclaration), - Ch.filter((node) => !!node.body), - Ch.filter((node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)), - Ch.head, - O.map((node) => ({ + ReadonlyArray.filter(ts.isFunctionDeclaration), + ReadonlyArray.filter((node) => !!node.body), + ReadonlyArray.filter((node) => + !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async) + ), + ReadonlyArray.head, + Option.map((node) => ({ kind: "refactor.rewrite.effect.asyncAwaitToGen", description: "Rewrite to Effect.gen", apply: (changeTracker) => { const effectName = AST.getEffectModuleIdentifier(ts, program.getTypeChecker())(sourceFile) const newDeclaration = AST.transformAsyncAwaitToEffectGen( - ts, - options.preferredEffectGenAdapterName + ts )( node, effectName, diff --git a/src/refactors/asyncAwaitToGenTryPromise.ts b/src/refactors/asyncAwaitToGenTryPromise.ts index e8ef40f..070a3a4 100644 --- a/src/refactors/asyncAwaitToGenTryPromise.ts +++ b/src/refactors/asyncAwaitToGenTryPromise.ts @@ -1,20 +1,22 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" export const asyncAwaitToGenTryPromise = createRefactor({ name: "effect/asyncAwaitToGenTryPromise", description: "Convert to Effect.gen with failures", - apply: (ts, program, options) => (sourceFile, textRange) => + apply: (ts, program) => (sourceFile, textRange) => pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(ts.isFunctionDeclaration), - Ch.filter((node) => !!node.body), - Ch.filter((node) => !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async)), - Ch.head, - O.map((node) => ({ + ReadonlyArray.filter(ts.isFunctionDeclaration), + ReadonlyArray.filter((node) => !!node.body), + ReadonlyArray.filter((node) => + !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Async) + ), + ReadonlyArray.head, + Option.map((node) => ({ kind: "refactor.rewrite.effect.asyncAwaitToGenTryPromise", description: "Rewrite to Effect.gen with failures", apply: (changeTracker) => { @@ -37,8 +39,7 @@ export const asyncAwaitToGenTryPromise = createRefactor({ } const newDeclaration = AST.transformAsyncAwaitToEffectGen( - ts, - options.preferredEffectGenAdapterName + ts )( node, effectName, diff --git a/src/refactors/functionToArrow.ts b/src/refactors/functionToArrow.ts index 5442d1e..ab4843c 100644 --- a/src/refactors/functionToArrow.ts +++ b/src/refactors/functionToArrow.ts @@ -1,6 +1,6 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import type ts from "typescript" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" @@ -12,18 +12,18 @@ export const functionToArrow = createRefactor({ pipe( pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(ts.isFunctionDeclaration) + ReadonlyArray.filter(ts.isFunctionDeclaration) ), - Ch.appendAll( + ReadonlyArray.appendAll( pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(ts.isMethodDeclaration) + ReadonlyArray.filter(ts.isMethodDeclaration) ) ), - Ch.filter((node) => !!node.body), - Ch.filter((node) => !!node.name && AST.isNodeInRange(textRange)(node.name)), - Ch.head, - O.map( + ReadonlyArray.filter((node) => !!node.body), + ReadonlyArray.filter((node) => !!node.name && AST.isNodeInRange(textRange)(node.name)), + ReadonlyArray.head, + Option.map( (node) => ({ kind: "refactor.rewrite.effect.functionToArrow", description: "Convert to arrow", diff --git a/src/refactors/pipeableToDatafirst.ts b/src/refactors/pipeableToDatafirst.ts index b9481bd..64b1f1e 100644 --- a/src/refactors/pipeableToDatafirst.ts +++ b/src/refactors/pipeableToDatafirst.ts @@ -1,6 +1,6 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" @@ -10,18 +10,18 @@ export const pipeableToDatafirst = createRefactor({ apply: (ts, program) => (sourceFile, textRange) => pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(AST.isPipeCall(ts)), - Ch.filter((node) => AST.isNodeInRange(textRange)(node.expression)), - Ch.filter( + ReadonlyArray.filter(AST.isPipeCall(ts)), + ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.expression)), + ReadonlyArray.filter( (node) => node.arguments.length > 0 ), - Ch.map((node) => { + ReadonlyArray.map((node) => { let newNode = node.arguments[0] let didSomething = false for (let i = 1; i < node.arguments.length; i++) { const arg = node.arguments[i] const a = AST.asDataFirstExpression(ts, program.getTypeChecker())(arg, newNode) - if (O.isSome(a)) { + if (Option.isSome(a)) { // use found datafirst newNode = a.value didSomething = true @@ -42,12 +42,12 @@ export const pipeableToDatafirst = createRefactor({ } } } - return didSomething ? O.some([node, newNode] as const) : O.none() + return didSomething ? Option.some([node, newNode] as const) : Option.none() }), - Ch.filter(O.isSome), - Ch.map((_) => _.value), - Ch.head, - O.map(([node, newNode]) => ({ + ReadonlyArray.filter(Option.isSome), + ReadonlyArray.map((_) => _.value), + ReadonlyArray.head, + Option.map(([node, newNode]) => ({ kind: "refactor.rewrite.effect.pipeableToDatafirst", description: "Rewrite to datafirst", apply: (changeTracker) => { diff --git a/src/refactors/toggleLazyConst.ts b/src/refactors/toggleLazyConst.ts index fb4f40f..2da1ee4 100644 --- a/src/refactors/toggleLazyConst.ts +++ b/src/refactors/toggleLazyConst.ts @@ -1,6 +1,6 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" @@ -10,14 +10,14 @@ export const toggleLazyConst = createRefactor({ apply: (ts) => (sourceFile, textRange) => pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(ts.isVariableDeclaration), - Ch.filter((node) => AST.isNodeInRange(textRange)(node.name)), - Ch.filter((node) => + ReadonlyArray.filter(ts.isVariableDeclaration), + ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)), + ReadonlyArray.filter((node) => !!node.initializer && !(ts.isArrowFunction(node.initializer) && ts.isBlock(node.initializer.body)) ), - Ch.head, - O.map( + ReadonlyArray.head, + Option.map( (node) => ({ kind: "refactor.rewrite.effect.toggleLazyConst", description: "Toggle lazy const", diff --git a/src/refactors/toggleReturnTypeAnnotation.ts b/src/refactors/toggleReturnTypeAnnotation.ts index 6bfb789..564e2be 100644 --- a/src/refactors/toggleReturnTypeAnnotation.ts +++ b/src/refactors/toggleReturnTypeAnnotation.ts @@ -1,6 +1,6 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import type ts from "typescript" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" @@ -29,9 +29,9 @@ export const toggleReturnTypeAnnotation = createRefactor({ return pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(isConvertibleDeclaration), - Ch.head, - O.map( + ReadonlyArray.filter(isConvertibleDeclaration), + ReadonlyArray.head, + Option.map( (node) => ({ kind: "refactor.rewrite.effect.toggleReturnTypeAnnotation", description: "Toggle return type annotation", diff --git a/src/refactors/toggleTypeAnnotation.ts b/src/refactors/toggleTypeAnnotation.ts index ea4c2e1..da7271f 100644 --- a/src/refactors/toggleTypeAnnotation.ts +++ b/src/refactors/toggleTypeAnnotation.ts @@ -1,6 +1,6 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import { createRefactor } from "../definition.js" import * as AST from "../utils/AST.js" @@ -10,11 +10,11 @@ export const toggleTypeAnnotation = createRefactor({ apply: (ts, program) => (sourceFile, textRange) => pipe( AST.getNodesContainingRange(ts)(sourceFile, textRange), - Ch.filter(ts.isVariableDeclaration), - Ch.filter((node) => AST.isNodeInRange(textRange)(node.name)), - Ch.filter((node) => !!node.initializer), - Ch.head, - O.map( + ReadonlyArray.filter(ts.isVariableDeclaration), + ReadonlyArray.filter((node) => AST.isNodeInRange(textRange)(node.name)), + ReadonlyArray.filter((node) => !!node.initializer), + ReadonlyArray.head, + Option.map( (node) => ({ kind: "refactor.rewrite.effect.toggleTypeAnnotation", description: "Toggle type annotation", diff --git a/src/refactors/wrapWithPipe.ts b/src/refactors/wrapWithPipe.ts index fdcdda0..281944c 100644 --- a/src/refactors/wrapWithPipe.ts +++ b/src/refactors/wrapWithPipe.ts @@ -1,13 +1,13 @@ -import * as O from "effect/Option" +import * as Option from "effect/Option" import { createRefactor } from "../definition.js" export const wrapWithPipe = createRefactor({ name: "effect/wrapWithPipe", description: "Wrap with pipe", apply: () => (sourceFile, textRange) => { - if (textRange.end - textRange.pos === 0) return O.none() + if (textRange.end - textRange.pos === 0) return Option.none() - return O.some({ + return Option.some({ kind: "refactor.rewrite.effect.wrapWithPipe", description: `Wrap with pipe(...)`, apply: (changeTracker) => { diff --git a/src/utils/AST.ts b/src/utils/AST.ts index a88183f..7f8aae8 100644 --- a/src/utils/AST.ts +++ b/src/utils/AST.ts @@ -1,6 +1,6 @@ +import * as ReadonlyArray from "effect/Array" import { pipe } from "effect/Function" -import * as O from "effect/Option" -import * as Ch from "effect/ReadonlyArray" +import * as Option from "effect/Option" import type ts from "typescript" declare module "typescript" { @@ -164,12 +164,12 @@ export function getNodesContainingRange( ) { return ((sourceFile: ts.SourceFile, textRange: ts.TextRange) => { const precedingToken = ts.findPrecedingToken(textRange.pos, sourceFile) - if (!precedingToken) return Ch.empty() + if (!precedingToken) return ReadonlyArray.empty() - let result = Ch.empty() + let result = ReadonlyArray.empty() let parent = precedingToken while (parent) { - result = pipe(result, Ch.append(parent)) + result = pipe(result, ReadonlyArray.append(parent)) parent = parent.parent } @@ -193,10 +193,10 @@ export function getHumanReadableName(sourceFile: ts.SourceFile, node: ts.Node) { export function collectAll(ts: TypeScriptApi) { return (rootNode: ts.Node, test: (node: ts.Node) => node is A) => { - let result = Ch.empty() + let result = ReadonlyArray.empty() function visitor(node: ts.Node) { - if (test(node)) result = pipe(result, Ch.append(node)) + if (test(node)) result = pipe(result, ReadonlyArray.append(node)) ts.forEachChild(node, visitor) } @@ -220,11 +220,11 @@ export function getRelevantTokens( sourceFile, /*startNode*/ undefined )! // TODO: GH#18217 - return { contextToken: O.some(contextToken), previousToken: O.some(previousToken) } + return { contextToken: Option.some(contextToken), previousToken: Option.some(previousToken) } } return { - contextToken: O.fromNullable(previousToken), - previousToken: O.fromNullable(previousToken) + contextToken: Option.fromNullable(previousToken), + previousToken: Option.fromNullable(previousToken) } }) } @@ -237,7 +237,7 @@ export function findModuleNamedBindings( ts: TypeScriptApi ) { return (sourceFile: ts.SourceFile, moduleName: string) => - O.fromNullable(ts.forEachChild(sourceFile, (node) => { + Option.fromNullable(ts.forEachChild(sourceFile, (node) => { if (!ts.isImportDeclaration(node)) return const moduleSpecifier = node.moduleSpecifier if (!ts.isStringLiteral(moduleSpecifier)) return @@ -256,13 +256,13 @@ export function findModuleNamespaceImportIdentifierName( return (sourceFile: ts.SourceFile, moduleName: string) => pipe( findModuleNamedBindings(ts)(sourceFile, moduleName), - O.map( + Option.map( (namedBindings) => { if (!ts.isNamespaceImport(namedBindings)) return return namedBindings.name.text } ), - O.flatMap(O.fromNullable) + Option.flatMap(Option.fromNullable) ) } @@ -272,7 +272,7 @@ export function findModuleNamedImportIdentifierName( return (sourceFile: ts.SourceFile, moduleName: string, namedImport: string) => pipe( findModuleNamedBindings(ts)(sourceFile, moduleName), - O.map((namedBindings) => { + Option.map((namedBindings) => { if (!ts.isNamedImports(namedBindings)) return for (const importSpecifier of namedBindings.elements) { if (importSpecifier.propertyName?.escapedText === namedImport) { @@ -280,7 +280,7 @@ export function findModuleNamedImportIdentifierName( } } }), - O.flatMap(O.fromNullable) + Option.flatMap(Option.fromNullable) ) } @@ -289,7 +289,7 @@ export function findModuleImportIdentifierNameViaTypeChecker( typeChecker: ts.TypeChecker ) { return (sourceFile: ts.SourceFile, importName: string) => { - return O.fromNullable(ts.forEachChild(sourceFile, (node) => { + return Option.fromNullable(ts.forEachChild(sourceFile, (node) => { if (!ts.isImportDeclaration(node)) return if (!node.importClause) return const namedBindings = node.importClause.namedBindings @@ -314,8 +314,7 @@ export function findModuleImportIdentifierNameViaTypeChecker( } export function transformAsyncAwaitToEffectGen( - ts: TypeScriptApi, - preferredEffectGenAdapterName: string + ts: TypeScriptApi ) { return ( node: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression, @@ -328,13 +327,7 @@ export function transformAsyncAwaitToEffectGen( return ts.factory.createYieldExpression( ts.factory.createToken(ts.SyntaxKind.AsteriskToken), - ts.factory.createCallExpression( - ts.factory.createIdentifier(preferredEffectGenAdapterName), - undefined, - [ - onAwait(expression) - ] - ) + onAwait(expression) ) } return ts.visitEachChild(_, visitor, ts.nullTransformationContext) @@ -346,7 +339,7 @@ export function transformAsyncAwaitToEffectGen( ts.factory.createToken(ts.SyntaxKind.AsteriskToken), undefined, [], - [ts.factory.createParameterDeclaration(undefined, undefined, preferredEffectGenAdapterName)], + [], undefined, generatorBody as any // NOTE(mattia): intended, to use same routine for both ConciseBody and Body ) @@ -461,11 +454,11 @@ export function getEffectModuleIdentifier(ts: TypeScriptApi, typeChecker: ts.Typ return (sourceFile: ts.SourceFile) => pipe( findModuleNamespaceImportIdentifierName(ts)(sourceFile, "effect/Effect"), - O.orElse(() => findModuleNamedImportIdentifierName(ts)(sourceFile, "effect", "Effect")), - O.orElse(() => + Option.orElse(() => findModuleNamedImportIdentifierName(ts)(sourceFile, "effect", "Effect")), + Option.orElse(() => findModuleImportIdentifierNameViaTypeChecker(ts, typeChecker)(sourceFile, "Effect") ), - O.getOrElse( + Option.getOrElse( () => "Effect" ) ) @@ -474,12 +467,14 @@ export function getEffectModuleIdentifier(ts: TypeScriptApi, typeChecker: ts.Typ export function simplifyTypeNode( ts: TypeScriptApi ) { - function collectCallable(typeNode: ts.TypeNode): O.Option> { + function collectCallable( + typeNode: ts.TypeNode + ): Option.Option> { // (() => 1) -> skip to inner node if (ts.isParenthesizedTypeNode(typeNode)) return collectCallable(typeNode.type) // () => 1 -> convert to call signature if (ts.isFunctionTypeNode(typeNode)) { - return O.some([ + return Option.some([ ts.factory.createCallSignature(typeNode.typeParameters, typeNode.parameters, typeNode.type) ]) } @@ -487,23 +482,23 @@ export function simplifyTypeNode( if (ts.isTypeLiteralNode(typeNode)) { const allCallSignatures = typeNode.members.every(ts.isCallSignatureDeclaration) if (allCallSignatures) { - return O.some(typeNode.members as any as Array) + return Option.some(typeNode.members as any as Array) } } // ... & ... -> if both are callable, return merge of both if (ts.isIntersectionTypeNode(typeNode)) { const members = typeNode.types.map(collectCallable) - if (members.every(O.isSome)) { - return O.some(members.map((_) => O.isSome(_) ? _.value : []).flat()) + if (members.every(Option.isSome)) { + return Option.some(members.map((_) => Option.isSome(_) ? _.value : []).flat()) } } - return O.none() + return Option.none() } return (typeNode: ts.TypeNode) => { const callSignatures = collectCallable(typeNode) - if (O.isSome(callSignatures) && callSignatures.value.length > 1) { + if (Option.isSome(callSignatures) && callSignatures.value.length > 1) { return ts.factory.createTypeLiteralNode(callSignatures.value) } return typeNode @@ -521,15 +516,15 @@ export function isPipeCall(ts: TypeScriptApi) { } export function asDataFirstExpression(ts: TypeScriptApi, checker: ts.TypeChecker) { - return (node: ts.Node, self: ts.Expression): O.Option => { - if (!ts.isCallExpression(node)) return O.none() + return (node: ts.Node, self: ts.Expression): Option.Option => { + if (!ts.isCallExpression(node)) return Option.none() const signature = checker.getResolvedSignature(node) - if (!signature) return O.none() + if (!signature) return Option.none() const callSignatures = checker.getTypeAtLocation(node.expression).getCallSignatures() for (let i = 0; i < callSignatures.length; i++) { const callSignature = callSignatures[i] if (callSignature.parameters.length === node.arguments.length + 1) { - return O.some( + return Option.some( ts.factory.createCallExpression( node.expression, [], @@ -538,6 +533,6 @@ export function asDataFirstExpression(ts: TypeScriptApi, checker: ts.TypeChecker ) } } - return O.none() + return Option.none() } } diff --git a/test/__snapshots__/refactors.test.ts.snap b/test/__snapshots__/refactors.test.ts.snap index 222e2e6..5bf3ba9 100644 --- a/test/__snapshots__/refactors.test.ts.snap +++ b/test/__snapshots__/refactors.test.ts.snap @@ -5,8 +5,8 @@ exports[`asyncAwaitToGen.ts > asyncAwaitToGen.ts at 4:28 1`] = ` import * as T from "effect/Effect" export function refactorMe(arg: string) { - return T.gen(function*(_) { - return yield* _(T.promise(() => Promise.resolve(1))) + return T.gen(function*() { + return yield* T.promise(() => Promise.resolve(1)) }) } " @@ -17,8 +17,8 @@ exports[`asyncAwaitToGen_namedImport.ts > asyncAwaitToGen_namedImport.ts at 4:28 import { Effect as T } from "effect" export function refactorMe(arg: string) { - return T.gen(function*(_) { - return yield* _(T.promise(() => Promise.resolve(1))) + return T.gen(function*() { + return yield* T.promise(() => Promise.resolve(1)) }) } " @@ -29,8 +29,8 @@ exports[`asyncAwaitToGen_reExport.ts > asyncAwaitToGen_reExport.ts at 4:28 1`] = import { Eff } from "@/utils/reExport.js" export function refactorMe(arg: string) { - return Eff.gen(function*(_) { - return yield* _(Eff.promise(() => Promise.resolve(1))) + return Eff.gen(function*() { + return yield* Eff.promise(() => Promise.resolve(1)) }) } " @@ -41,11 +41,11 @@ exports[`asyncAwaitToGenTryPromise.ts > asyncAwaitToGenTryPromise.ts at 4:28 1`] import * as Effect from "effect/Effect" export function refactorMe(arg: string) { - return Effect.gen(function*(_) { + return Effect.gen(function*() { for (let i = 0; i < 10; i++) { - yield* _(Effect.tryPromise({ try: () => Promise.resolve(i), catch: error => ({ _tag: "Error1" as const, error }) })) + yield* Effect.tryPromise({ try: () => Promise.resolve(i), catch: error => ({ _tag: "Error1" as const, error }) }) } - return yield* _(Effect.tryPromise({ try: () => Promise.resolve(arg), catch: error => ({ _tag: "Error2" as const, error }) })) + return yield* Effect.tryPromise({ try: () => Promise.resolve(arg), catch: error => ({ _tag: "Error2" as const, error }) }) }) } " @@ -141,7 +141,7 @@ import { pipe } from "effect/Function" const test = T.map(T.zipRight(T.flatMap(T.succeed("Hello"), (_) => T.log(_)), T.succeed(42)), (_) => _ * 2) -const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) +const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) const test2 = pipe( T.succeed("Hello"), @@ -171,7 +171,7 @@ const test = pipe( T.map((_) => _ * 2) ) -const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) +const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) const test2 = pipe(T.flatMap(T.succeed("Hello"), (_) => T.log(_)), noDataFirst("42")) @@ -197,7 +197,7 @@ const test = pipe( T.map((_) => _ * 2) ) -const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) +const noDataFirst = (value: string) => (eff: T.Effect) => pipe(eff, T.zipLeft(T.log(value))) const test2 = pipe( T.succeed("Hello"), @@ -254,7 +254,7 @@ exports[`toggleReturnTypeAnnotation.ts > toggleReturnTypeAnnotation.ts at 4:32 1 "// Result of running refactor effect/toggleReturnTypeAnnotation at position 4:32 import * as T from "effect/Effect" -export const test1 = (): T.Effect => T.succeed(42) +export const test1 = (): T.Effect => T.succeed(42) export const test2 = () => (true ? T.succeed(42) : false) @@ -278,7 +278,7 @@ import * as T from "effect/Effect" export const test1 = () => T.succeed(42) -export const test2 = (): false | T.Effect => (true ? T.succeed(42) : false) +export const test2 = (): false | T.Effect => (true ? T.succeed(42) : false) function sillyGenerics(value: A) { return T.fail(value) @@ -364,7 +364,7 @@ exports[`toggleTypeAnnotation.ts > toggleTypeAnnotation.ts at 4:16 1`] = ` "// Result of running refactor effect/toggleTypeAnnotation at position 4:16 import * as T from "effect/Effect" -export const test1: (value: A) => T.Effect = T.succeed +export const test1: (value: A) => T.Effect = T.succeed export const test2 = T.fail("LOL") const predefined = 42 diff --git a/tsup.config.ts b/tsup.config.ts index cbec597..739cecb 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,4 +1,5 @@ -import { FileSystem, Path } from "@effect/platform-node" +import { FileSystem, Path } from "@effect/platform" +import { NodeFileSystem, NodePath } from "@effect/platform-node" import { Effect, Layer } from "effect" import { defineConfig } from "tsup" @@ -26,7 +27,7 @@ export default defineConfig({ } yield* _(fs.writeFileString(path.join("dist", "package.json"), JSON.stringify(pkg, null, 2))) }).pipe( - Effect.provide(Layer.merge(FileSystem.layer, Path.layerPosix)) + Effect.provide(Layer.merge(NodeFileSystem.layer, NodePath.layerPosix)) ) return Effect.runPromise(program)