From 4bae6b25803c00d0a053521ccd8c35b9a2816e91 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 21 Apr 2023 00:48:17 +0900 Subject: [PATCH 01/18] parse moduleResolution field from gentypeconfig --- jscomp/gentype/GenTypeConfig.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jscomp/gentype/GenTypeConfig.ml b/jscomp/gentype/GenTypeConfig.ml index aa8e2af049..da4ce60b6d 100644 --- a/jscomp/gentype/GenTypeConfig.ml +++ b/jscomp/gentype/GenTypeConfig.ml @@ -1,6 +1,7 @@ module ModuleNameMap = Map.Make (ModuleName) type module_ = CommonJS | ES6 +type moduleResolution = Node | Node16 | Bundler type bsVersion = int * int * int type t = { @@ -13,6 +14,7 @@ type t = { exportInterfaces: bool; generatedFileExtension: string option; module_: module_; + moduleResolution: moduleResolution; namespace: string option; platformLib: string; mutable projectRoot: string; @@ -32,6 +34,7 @@ let default = exportInterfaces = false; generatedFileExtension = None; module_ = ES6; + moduleResolution = Node; namespace = None; platformLib = ""; projectRoot = ""; @@ -112,6 +115,7 @@ let readConfig ~getBsConfigFile ~namespace = in let parseConfig ~bsconf ~gtconf = let moduleString = gtconf |> getStringOption "module" in + let moduleResolutionString = gtconf |> getStringOption "moduleResolution" in let exportInterfacesBool = gtconf |> getBool "exportInterfaces" in let generatedFileExtensionStringOption = gtconf |> getStringOption "generatedFileExtension" @@ -143,6 +147,13 @@ let readConfig ~getBsConfigFile ~namespace = | None, Some ("es6" | "es6-global") -> ES6 | _ -> default.module_ in + let moduleResolution = + match moduleResolutionString with + | Some "node" -> Node + | Some "node16" -> Node16 + | Some "bundler" -> Bundler + | _ -> default.moduleResolution + in let exportInterfaces = match exportInterfacesBool with | None -> default.exportInterfaces @@ -204,6 +215,7 @@ let readConfig ~getBsConfigFile ~namespace = exportInterfaces; generatedFileExtension; module_; + moduleResolution; namespace; platformLib; projectRoot; From 7b17a4e88492164391bb78c2d46b03f43582fd3a Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 21 Apr 2023 01:15:52 +0900 Subject: [PATCH 02/18] gentype_test: upgrade typescript --- .../package-lock.json | 87 ++++++++----------- .../typescript-react-example/package.json | 6 +- 2 files changed, 39 insertions(+), 54 deletions(-) diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index 888a014276..eb125cf67d 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -13,28 +13,10 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@types/node": "^13.13.4", - "@types/react-dom": "^16.9.7", + "@types/node": "^18.15.12", + "@types/react-dom": "^18.0.11", "rescript": "file:../../..", - "typescript": "3.9.2" - } - }, - "../../..": { - "name": "rescript", - "version": "11.0.0-alpha.3", - "dev": true, - "hasInstallScript": true, - "license": "SEE LICENSE IN LICENSE", - "bin": { - "bsc": "bsc", - "bstracing": "lib/bstracing", - "rescript": "rescript" - }, - "devDependencies": { - "mocha": "^10.1.0", - "nyc": "^15.0.0", - "prettier": "^2.7.1", - "rollup": "^0.49.2" + "typescript": "^5.0.4" } }, "node_modules/@rescript/react": { @@ -47,9 +29,9 @@ } }, "node_modules/@types/node": { - "version": "13.13.52", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", - "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==", + "version": "18.15.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.12.tgz", + "integrity": "sha512-Wha1UwsB3CYdqUm2PPzh/1gujGCNtWVUYF0mB00fJFoR4gTyWTDPjSm+zBF787Ahw8vSGgBja90MkgFwvB86Dg==", "dev": true }, "node_modules/@types/prop-types": { @@ -70,12 +52,12 @@ } }, "node_modules/@types/react-dom": { - "version": "16.9.16", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.16.tgz", - "integrity": "sha512-Oqc0RY4fggGA3ltEgyPLc3IV9T73IGoWjkONbsyJ3ZBn+UPPCYpU2ec0i3cEbJuEdZtkqcCF2l1zf2pBdgUGSg==", + "version": "18.0.11", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.11.tgz", + "integrity": "sha512-O38bPbI2CWtgw/OoQoY+BRelw7uysmXbWvw3nLWO21H1HSh+GOlqPuXshJfjmpNlKiiSDG9cc1JZAaMmVdcTlw==", "dev": true, "dependencies": { - "@types/react": "^16" + "@types/react": "*" } }, "node_modules/@types/scheduler": { @@ -130,8 +112,16 @@ } }, "node_modules/rescript": { - "resolved": "../../..", - "link": true + "version": "11.0.0-alpha.5", + "resolved": "file:../../..", + "dev": true, + "hasInstallScript": true, + "license": "SEE LICENSE IN LICENSE", + "bin": { + "bsc": "bsc", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } }, "node_modules/scheduler": { "version": "0.23.0", @@ -142,16 +132,16 @@ } }, "node_modules/typescript": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.2.tgz", - "integrity": "sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=12.20" } } }, @@ -163,9 +153,9 @@ "requires": {} }, "@types/node": { - "version": "13.13.52", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", - "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==", + "version": "18.15.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.12.tgz", + "integrity": "sha512-Wha1UwsB3CYdqUm2PPzh/1gujGCNtWVUYF0mB00fJFoR4gTyWTDPjSm+zBF787Ahw8vSGgBja90MkgFwvB86Dg==", "dev": true }, "@types/prop-types": { @@ -186,12 +176,12 @@ } }, "@types/react-dom": { - "version": "16.9.16", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.16.tgz", - "integrity": "sha512-Oqc0RY4fggGA3ltEgyPLc3IV9T73IGoWjkONbsyJ3ZBn+UPPCYpU2ec0i3cEbJuEdZtkqcCF2l1zf2pBdgUGSg==", + "version": "18.0.11", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.11.tgz", + "integrity": "sha512-O38bPbI2CWtgw/OoQoY+BRelw7uysmXbWvw3nLWO21H1HSh+GOlqPuXshJfjmpNlKiiSDG9cc1JZAaMmVdcTlw==", "dev": true, "requires": { - "@types/react": "^16" + "@types/react": "*" } }, "@types/scheduler": { @@ -237,13 +227,8 @@ } }, "rescript": { - "version": "file:../../..", - "requires": { - "mocha": "^10.1.0", - "nyc": "^15.0.0", - "prettier": "^2.7.1", - "rollup": "^0.49.2" - } + "version": "11.0.0-alpha.5", + "dev": true }, "scheduler": { "version": "0.23.0", @@ -254,9 +239,9 @@ } }, "typescript": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.2.tgz", - "integrity": "sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true } } diff --git a/jscomp/gentype_tests/typescript-react-example/package.json b/jscomp/gentype_tests/typescript-react-example/package.json index a494cc27a5..b8a0cec5b8 100644 --- a/jscomp/gentype_tests/typescript-react-example/package.json +++ b/jscomp/gentype_tests/typescript-react-example/package.json @@ -14,9 +14,9 @@ "tsc": "tsc -p tsconfig.json" }, "devDependencies": { - "@types/node": "^13.13.4", - "@types/react-dom": "^16.9.7", + "@types/node": "^18.15.12", + "@types/react-dom": "^18.0.11", "rescript": "file:../../..", - "typescript": "3.9.2" + "typescript": "^5.0.4" } } From 0e65bea89b19a5b2b7e618a44c4511d4091dcf27 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 21 Apr 2023 01:37:10 +0900 Subject: [PATCH 03/18] add gentypeTests for other moduleResolutions --- .../typescript-res-bundler/.gitignore | 17 ++++++++ .../typescript-res-bundler/bsconfig.json | 25 +++++++++++ .../typescript-res-bundler/package-lock.json | 41 +++++++++++++++++++ .../typescript-res-bundler/package.json | 17 ++++++++ .../typescript-res-bundler/src/Bar.res | 5 +++ .../typescript-res-bundler/src/Foo.res | 5 +++ .../typescript-res-bundler/tsconfig.json | 14 +++++++ .../typescript-res-node16/.gitignore | 17 ++++++++ .../typescript-res-node16/bsconfig.json | 25 +++++++++++ .../typescript-res-node16/package-lock.json | 41 +++++++++++++++++++ .../typescript-res-node16/package.json | 17 ++++++++ .../typescript-res-node16/src/Bar.res | 5 +++ .../typescript-res-node16/src/Foo.res | 5 +++ .../typescript-res-node16/tsconfig.json | 14 +++++++ 14 files changed, 248 insertions(+) create mode 100644 jscomp/gentype_tests/typescript-res-bundler/.gitignore create mode 100644 jscomp/gentype_tests/typescript-res-bundler/bsconfig.json create mode 100644 jscomp/gentype_tests/typescript-res-bundler/package-lock.json create mode 100644 jscomp/gentype_tests/typescript-res-bundler/package.json create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Bar.res create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Foo.res create mode 100644 jscomp/gentype_tests/typescript-res-bundler/tsconfig.json create mode 100644 jscomp/gentype_tests/typescript-res-node16/.gitignore create mode 100644 jscomp/gentype_tests/typescript-res-node16/bsconfig.json create mode 100644 jscomp/gentype_tests/typescript-res-node16/package-lock.json create mode 100644 jscomp/gentype_tests/typescript-res-node16/package.json create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Bar.res create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Foo.res create mode 100644 jscomp/gentype_tests/typescript-res-node16/tsconfig.json diff --git a/jscomp/gentype_tests/typescript-res-bundler/.gitignore b/jscomp/gentype_tests/typescript-res-bundler/.gitignore new file mode 100644 index 0000000000..3099aa9bf1 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/.gitignore @@ -0,0 +1,17 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + + +# misc +/lib +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json new file mode 100644 index 0000000000..74808a987a --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json @@ -0,0 +1,25 @@ +{ + "gentypeconfig": { + "language": "typescript", + "module": "es6", + "moduleResolution": "node16", + "importPath": "relative", + "debug": { + "all": false + }, + "exportInterfaces": false + }, + "name": "sample-typescript-app", + "bsc-flags": ["-bs-super-errors"], + "sources": [ + { + "dir": "src", + "subdirs": true + } + ], + "package-specs": { + "module": "es6", + "in-source": true + }, + "suffix": ".bs.js" +} diff --git a/jscomp/gentype_tests/typescript-res-bundler/package-lock.json b/jscomp/gentype_tests/typescript-res-bundler/package-lock.json new file mode 100644 index 0000000000..2cbf01470b --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/package-lock.json @@ -0,0 +1,41 @@ +{ + "name": "typescript-res-node16", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "typescript-res-node16", + "version": "0.1.0", + "devDependencies": { + "rescript": "file:../../..", + "typescript": "^5.0.4" + } + }, + "node_modules/rescript": { + "version": "11.0.0-alpha.5", + "resolved": "file:../../..", + "dev": true, + "hasInstallScript": true, + "license": "SEE LICENSE IN LICENSE", + "bin": { + "bsc": "bsc", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } + }, + "node_modules/typescript": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=12.20" + } + } + } +} diff --git a/jscomp/gentype_tests/typescript-res-bundler/package.json b/jscomp/gentype_tests/typescript-res-bundler/package.json new file mode 100644 index 0000000000..8f2295f0e5 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/package.json @@ -0,0 +1,17 @@ +{ + "name": "typescript-res-node16", + "version": "0.1.0", + "private": true, + "dependencies": { + }, + "scripts": { + "start": "rescript build -w", + "build": "rescript", + "clean": "rescript clean -with-deps", + "tsc": "tsc -p tsconfig.json" + }, + "devDependencies": { + "rescript": "file:../../..", + "typescript": "^5.0.4" + } +} diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res new file mode 100644 index 0000000000..bb5acc1ee6 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res @@ -0,0 +1,5 @@ +@genType +let makeFoo = (~bar) => { + let foo = Foo.make + {...foo, bar} +} diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res new file mode 100644 index 0000000000..326db7ec26 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res @@ -0,0 +1,5 @@ +@genType +type t = {foo: int, bar: int} + +@genType +let make = () => {foo: 0, bar: int} diff --git a/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json new file mode 100644 index 0000000000..20424e50c7 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "moduleResolution": "bundler", + "rootDir": "src", + "noEmit": true + }, + "include": [ + "src" + ], + "exclude": [ + ] +} diff --git a/jscomp/gentype_tests/typescript-res-node16/.gitignore b/jscomp/gentype_tests/typescript-res-node16/.gitignore new file mode 100644 index 0000000000..3099aa9bf1 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/.gitignore @@ -0,0 +1,17 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + + +# misc +/lib +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/jscomp/gentype_tests/typescript-res-node16/bsconfig.json b/jscomp/gentype_tests/typescript-res-node16/bsconfig.json new file mode 100644 index 0000000000..74808a987a --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/bsconfig.json @@ -0,0 +1,25 @@ +{ + "gentypeconfig": { + "language": "typescript", + "module": "es6", + "moduleResolution": "node16", + "importPath": "relative", + "debug": { + "all": false + }, + "exportInterfaces": false + }, + "name": "sample-typescript-app", + "bsc-flags": ["-bs-super-errors"], + "sources": [ + { + "dir": "src", + "subdirs": true + } + ], + "package-specs": { + "module": "es6", + "in-source": true + }, + "suffix": ".bs.js" +} diff --git a/jscomp/gentype_tests/typescript-res-node16/package-lock.json b/jscomp/gentype_tests/typescript-res-node16/package-lock.json new file mode 100644 index 0000000000..2cbf01470b --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/package-lock.json @@ -0,0 +1,41 @@ +{ + "name": "typescript-res-node16", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "typescript-res-node16", + "version": "0.1.0", + "devDependencies": { + "rescript": "file:../../..", + "typescript": "^5.0.4" + } + }, + "node_modules/rescript": { + "version": "11.0.0-alpha.5", + "resolved": "file:../../..", + "dev": true, + "hasInstallScript": true, + "license": "SEE LICENSE IN LICENSE", + "bin": { + "bsc": "bsc", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } + }, + "node_modules/typescript": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=12.20" + } + } + } +} diff --git a/jscomp/gentype_tests/typescript-res-node16/package.json b/jscomp/gentype_tests/typescript-res-node16/package.json new file mode 100644 index 0000000000..8f2295f0e5 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/package.json @@ -0,0 +1,17 @@ +{ + "name": "typescript-res-node16", + "version": "0.1.0", + "private": true, + "dependencies": { + }, + "scripts": { + "start": "rescript build -w", + "build": "rescript", + "clean": "rescript clean -with-deps", + "tsc": "tsc -p tsconfig.json" + }, + "devDependencies": { + "rescript": "file:../../..", + "typescript": "^5.0.4" + } +} diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res new file mode 100644 index 0000000000..bb5acc1ee6 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res @@ -0,0 +1,5 @@ +@genType +let makeFoo = (~bar) => { + let foo = Foo.make + {...foo, bar} +} diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.res b/jscomp/gentype_tests/typescript-res-node16/src/Foo.res new file mode 100644 index 0000000000..326db7ec26 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/Foo.res @@ -0,0 +1,5 @@ +@genType +type t = {foo: int, bar: int} + +@genType +let make = () => {foo: 0, bar: int} diff --git a/jscomp/gentype_tests/typescript-res-node16/tsconfig.json b/jscomp/gentype_tests/typescript-res-node16/tsconfig.json new file mode 100644 index 0000000000..23a63a9334 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "moduleResolution": "node16", + "rootDir": "src", + "noEmit": true + }, + "include": [ + "src" + ], + "exclude": [ + ] +} From 383c288670c850e3ac5021aeb2cbf95294c6cab6 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 21 Apr 2023 02:10:23 +0900 Subject: [PATCH 04/18] add makefile for tests --- .../gentype_tests/typescript-res-bundler/Makefile | 14 ++++++++++++++ .../gentype_tests/typescript-res-node16/Makefile | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 jscomp/gentype_tests/typescript-res-bundler/Makefile create mode 100644 jscomp/gentype_tests/typescript-res-node16/Makefile diff --git a/jscomp/gentype_tests/typescript-res-bundler/Makefile b/jscomp/gentype_tests/typescript-res-bundler/Makefile new file mode 100644 index 0000000000..2bb4e9b8a2 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/Makefile @@ -0,0 +1,14 @@ +SHELL = /bin/bash + +node_modules/.bin/tsc: + npm install + +test: node_modules/.bin/tsc + npm run build + +clean: + rm -rf node_modules lib src/*.bs.js src/*.gen.tsx + +.DEFAULT_GOAL := test + +.PHONY: clean test diff --git a/jscomp/gentype_tests/typescript-res-node16/Makefile b/jscomp/gentype_tests/typescript-res-node16/Makefile new file mode 100644 index 0000000000..2bb4e9b8a2 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/Makefile @@ -0,0 +1,14 @@ +SHELL = /bin/bash + +node_modules/.bin/tsc: + npm install + +test: node_modules/.bin/tsc + npm run build + +clean: + rm -rf node_modules lib src/*.bs.js src/*.gen.tsx + +.DEFAULT_GOAL := test + +.PHONY: clean test From 9c4350b02f368121c24d3b74667c714f031b609b Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Fri, 21 Apr 2023 02:53:35 +0900 Subject: [PATCH 05/18] emit types import --- jscomp/gentype/EmitType.ml | 11 ++++-- jscomp/gentype/Paths.ml | 2 +- .../package-lock.json | 38 +++++++++++++------ .../typescript-res-bundler/bsconfig.json | 2 +- .../typescript-res-bundler/package-lock.json | 18 +++++++-- .../typescript-res-bundler/package.json | 2 +- .../typescript-res-bundler/src/Bar.bs.js | 16 ++++++++ .../typescript-res-bundler/src/Bar.gen.tsx | 11 ++++++ .../typescript-res-bundler/src/Bar.res | 4 +- .../typescript-res-bundler/src/Foo.bs.js | 14 +++++++ .../typescript-res-bundler/src/Foo.gen.tsx | 12 ++++++ .../typescript-res-bundler/src/Foo.res | 2 +- .../typescript-res-bundler/tsconfig.json | 2 + .../typescript-res-node16/package-lock.json | 13 ++++++- .../typescript-res-node16/src/Bar.bs.js | 16 ++++++++ .../typescript-res-node16/src/Bar.gen.tsx | 11 ++++++ .../typescript-res-node16/src/Bar.res | 4 +- .../typescript-res-node16/src/Foo.bs.js | 14 +++++++ .../typescript-res-node16/src/Foo.gen.tsx | 12 ++++++ .../typescript-res-node16/src/Foo.res | 2 +- .../typescript-res-node16/tsconfig.json | 1 + 21 files changed, 177 insertions(+), 30 deletions(-) create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx diff --git a/jscomp/gentype/EmitType.ml b/jscomp/gentype/EmitType.ml index caa4756f77..251e1083dd 100644 --- a/jscomp/gentype/EmitType.ml +++ b/jscomp/gentype/EmitType.ml @@ -20,12 +20,17 @@ let generatedFilesExtension ~(config : Config.t) = Filename.remove_extension s | None -> ".gen" -let outputFileSuffix ~(config : Config.t) = +let outputFileSuffix ~(config : Config.t) ?(moduleExtension = ".tsx") () = match config.generatedFileExtension with | Some s when Filename.extension s <> "" (* double extension *) -> s - | _ -> generatedFilesExtension ~config ^ ".tsx" + | _ -> generatedFilesExtension ~config ^ moduleExtension + +let generatedModuleExtension ~(config : Config.t) = + match config.moduleResolution with + | Node -> generatedFilesExtension ~config + | Node16 -> outputFileSuffix ~config ~moduleExtension:".js" () + | Bundler -> outputFileSuffix ~config () -let generatedModuleExtension ~config = generatedFilesExtension ~config let shimExtension = ".shim.ts" let interfaceName ~(config : Config.t) name = diff --git a/jscomp/gentype/Paths.ml b/jscomp/gentype/Paths.ml index c1c35b0c24..10d3f8e2e3 100644 --- a/jscomp/gentype/Paths.ml +++ b/jscomp/gentype/Paths.ml @@ -29,7 +29,7 @@ let findNameSpace cmt = |> keepAfterDash let getOutputFileRelative ~config cmt = - (cmt |> handleNamespace) ^ EmitType.outputFileSuffix ~config + (cmt |> handleNamespace) ^ EmitType.outputFileSuffix ~config () let getOutputFile ~(config : Config.t) cmt = Filename.concat config.projectRoot (getOutputFileRelative ~config cmt) diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index eb125cf67d..fd77465fb2 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -19,6 +19,23 @@ "typescript": "^5.0.4" } }, + "../../..": { + "version": "11.0.0-alpha.5", + "dev": true, + "hasInstallScript": true, + "license": "SEE LICENSE IN LICENSE", + "bin": { + "bsc": "bsc", + "bstracing": "lib/bstracing", + "rescript": "rescript" + }, + "devDependencies": { + "mocha": "^10.1.0", + "nyc": "^15.0.0", + "prettier": "^2.7.1", + "rollup": "^0.49.2" + } + }, "node_modules/@rescript/react": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@rescript/react/-/react-0.11.0.tgz", @@ -112,16 +129,8 @@ } }, "node_modules/rescript": { - "version": "11.0.0-alpha.5", - "resolved": "file:../../..", - "dev": true, - "hasInstallScript": true, - "license": "SEE LICENSE IN LICENSE", - "bin": { - "bsc": "bsc", - "bstracing": "lib/bstracing", - "rescript": "rescript" - } + "resolved": "../../..", + "link": true }, "node_modules/scheduler": { "version": "0.23.0", @@ -227,8 +236,13 @@ } }, "rescript": { - "version": "11.0.0-alpha.5", - "dev": true + "version": "file:../../..", + "requires": { + "mocha": "^10.1.0", + "nyc": "^15.0.0", + "prettier": "^2.7.1", + "rollup": "^0.49.2" + } }, "scheduler": { "version": "0.23.0", diff --git a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json index 74808a987a..31dab8bd71 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json +++ b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json @@ -2,7 +2,7 @@ "gentypeconfig": { "language": "typescript", "module": "es6", - "moduleResolution": "node16", + "moduleResolution": "bundler", "importPath": "relative", "debug": { "all": false diff --git a/jscomp/gentype_tests/typescript-res-bundler/package-lock.json b/jscomp/gentype_tests/typescript-res-bundler/package-lock.json index 2cbf01470b..ff7fcee850 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/package-lock.json +++ b/jscomp/gentype_tests/typescript-res-bundler/package-lock.json @@ -1,20 +1,20 @@ { - "name": "typescript-res-node16", + "name": "typescript-res-bundler", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "typescript-res-node16", + "name": "typescript-res-bundler", "version": "0.1.0", "devDependencies": { "rescript": "file:../../..", "typescript": "^5.0.4" } }, - "node_modules/rescript": { + "../../..": { + "name": "rescript", "version": "11.0.0-alpha.5", - "resolved": "file:../../..", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", @@ -22,8 +22,18 @@ "bsc": "bsc", "bstracing": "lib/bstracing", "rescript": "rescript" + }, + "devDependencies": { + "mocha": "^10.1.0", + "nyc": "^15.0.0", + "prettier": "^2.7.1", + "rollup": "^0.49.2" } }, + "node_modules/rescript": { + "resolved": "../../..", + "link": true + }, "node_modules/typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", diff --git a/jscomp/gentype_tests/typescript-res-bundler/package.json b/jscomp/gentype_tests/typescript-res-bundler/package.json index 8f2295f0e5..2060d29109 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/package.json +++ b/jscomp/gentype_tests/typescript-res-bundler/package.json @@ -1,5 +1,5 @@ { - "name": "typescript-res-node16", + "name": "typescript-res-bundler", "version": "0.1.0", "private": true, "dependencies": { diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js new file mode 100644 index 0000000000..287f7a99a4 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js @@ -0,0 +1,16 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Foo from "./Foo.bs.js"; + +function makeFoo(bar) { + var init = Foo.make(undefined); + return { + foo: init.foo, + bar: bar + }; +} + +export { + makeFoo , +} +/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx new file mode 100644 index 0000000000..c87c012526 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx @@ -0,0 +1,11 @@ +/* TypeScript file generated from Bar.res by genType. */ +/* eslint-disable import/first */ + + +// @ts-ignore: Implicit any on import +import * as BarBS__Es6Import from './Bar.bs'; +const BarBS: any = BarBS__Es6Import; + +import type {t as Foo_t} from './Foo.gen.tsx'; + +export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res index bb5acc1ee6..48f50ef17d 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res @@ -1,5 +1,5 @@ @genType let makeFoo = (~bar) => { - let foo = Foo.make - {...foo, bar} + open Foo + {...make(), bar} } diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js new file mode 100644 index 0000000000..940f3ec814 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js @@ -0,0 +1,14 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +function make(param) { + return { + foo: 0, + bar: 0 + }; +} + +export { + make , +} +/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx new file mode 100644 index 0000000000..2f2e3f7611 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx @@ -0,0 +1,12 @@ +/* TypeScript file generated from Foo.res by genType. */ +/* eslint-disable import/first */ + + +// @ts-ignore: Implicit any on import +import * as FooBS__Es6Import from './Foo.bs'; +const FooBS: any = FooBS__Es6Import; + +// tslint:disable-next-line:interface-over-type-literal +export type t = { readonly foo: number; readonly bar: number }; + +export const make: () => t = FooBS.make; diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res index 326db7ec26..565eb4abcc 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res @@ -2,4 +2,4 @@ type t = {foo: int, bar: int} @genType -let make = () => {foo: 0, bar: int} +let make = () => {foo: 0, bar: 0} diff --git a/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json index 20424e50c7..63b7744074 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json +++ b/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json @@ -3,7 +3,9 @@ "target": "esnext", "module": "esnext", "moduleResolution": "bundler", + "allowImportingTsExtensions": true, "rootDir": "src", + "jsx": "react", "noEmit": true }, "include": [ diff --git a/jscomp/gentype_tests/typescript-res-node16/package-lock.json b/jscomp/gentype_tests/typescript-res-node16/package-lock.json index 2cbf01470b..3626816831 100644 --- a/jscomp/gentype_tests/typescript-res-node16/package-lock.json +++ b/jscomp/gentype_tests/typescript-res-node16/package-lock.json @@ -12,9 +12,8 @@ "typescript": "^5.0.4" } }, - "node_modules/rescript": { + "../../..": { "version": "11.0.0-alpha.5", - "resolved": "file:../../..", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", @@ -22,8 +21,18 @@ "bsc": "bsc", "bstracing": "lib/bstracing", "rescript": "rescript" + }, + "devDependencies": { + "mocha": "^10.1.0", + "nyc": "^15.0.0", + "prettier": "^2.7.1", + "rollup": "^0.49.2" } }, + "node_modules/rescript": { + "resolved": "../../..", + "link": true + }, "node_modules/typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js b/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js new file mode 100644 index 0000000000..287f7a99a4 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js @@ -0,0 +1,16 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Foo from "./Foo.bs.js"; + +function makeFoo(bar) { + var init = Foo.make(undefined); + return { + foo: init.foo, + bar: bar + }; +} + +export { + makeFoo , +} +/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx new file mode 100644 index 0000000000..e91190d874 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx @@ -0,0 +1,11 @@ +/* TypeScript file generated from Bar.res by genType. */ +/* eslint-disable import/first */ + + +// @ts-ignore: Implicit any on import +import * as BarBS__Es6Import from './Bar.bs'; +const BarBS: any = BarBS__Es6Import; + +import type {t as Foo_t} from './Foo.gen.js'; + +export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res index bb5acc1ee6..48f50ef17d 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res @@ -1,5 +1,5 @@ @genType let makeFoo = (~bar) => { - let foo = Foo.make - {...foo, bar} + open Foo + {...make(), bar} } diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js b/jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js new file mode 100644 index 0000000000..940f3ec814 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js @@ -0,0 +1,14 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +function make(param) { + return { + foo: 0, + bar: 0 + }; +} + +export { + make , +} +/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx new file mode 100644 index 0000000000..2f2e3f7611 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx @@ -0,0 +1,12 @@ +/* TypeScript file generated from Foo.res by genType. */ +/* eslint-disable import/first */ + + +// @ts-ignore: Implicit any on import +import * as FooBS__Es6Import from './Foo.bs'; +const FooBS: any = FooBS__Es6Import; + +// tslint:disable-next-line:interface-over-type-literal +export type t = { readonly foo: number; readonly bar: number }; + +export const make: () => t = FooBS.make; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.res b/jscomp/gentype_tests/typescript-res-node16/src/Foo.res index 326db7ec26..565eb4abcc 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Foo.res +++ b/jscomp/gentype_tests/typescript-res-node16/src/Foo.res @@ -2,4 +2,4 @@ type t = {foo: int, bar: int} @genType -let make = () => {foo: 0, bar: int} +let make = () => {foo: 0, bar: 0} diff --git a/jscomp/gentype_tests/typescript-res-node16/tsconfig.json b/jscomp/gentype_tests/typescript-res-node16/tsconfig.json index 23a63a9334..f16aff10b1 100644 --- a/jscomp/gentype_tests/typescript-res-node16/tsconfig.json +++ b/jscomp/gentype_tests/typescript-res-node16/tsconfig.json @@ -4,6 +4,7 @@ "module": "esnext", "moduleResolution": "node16", "rootDir": "src", + "jsx": "react", "noEmit": true }, "include": [ From 6aec4cda835679f1cf6f5c85fd974bc2749a80bc Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Apr 2023 18:17:03 +0900 Subject: [PATCH 06/18] apply moduleResolution to shim imports --- jscomp/gentype/ModuleResolver.ml | 8 +++++++- .../typescript-react-example/package-lock.json | 1 + jscomp/gentype_tests/typescript-res-bundler/bsconfig.json | 3 +++ jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js | 5 +++++ .../gentype_tests/typescript-res-bundler/src/Bar.gen.tsx | 4 ++++ jscomp/gentype_tests/typescript-res-bundler/src/Bar.res | 2 ++ .../typescript-res-bundler/src/shims/Js.shim.ts | 1 + jscomp/gentype_tests/typescript-res-node16/bsconfig.json | 3 +++ jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js | 5 +++++ .../gentype_tests/typescript-res-node16/src/Bar.gen.tsx | 4 ++++ jscomp/gentype_tests/typescript-res-node16/src/Bar.res | 2 ++ .../typescript-res-node16/src/shims/Js.shim.ts | 1 + 12 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts create mode 100644 jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts diff --git a/jscomp/gentype/ModuleResolver.ml b/jscomp/gentype/ModuleResolver.ml index e7d5e26960..5f4730419e 100644 --- a/jscomp/gentype/ModuleResolver.ml +++ b/jscomp/gentype/ModuleResolver.ml @@ -272,8 +272,14 @@ let importPathForReasonModuleName ~(config : Config.t) ~outputFileRelative | shimModuleName -> if !Debug.moduleResolution then Log_.item "ShimModuleName: %s\n" (shimModuleName |> ModuleName.toString); + let importExtension = + match config.moduleResolution with + | Node -> ".shim" + | Node16 -> ".shim.js" + | Bundler -> ".shim.ts" + in let importPath = - resolveModule ~config ~importExtension:".shim" ~outputFileRelative + resolveModule ~config ~importExtension ~outputFileRelative ~resolver ~useBsDependencies:false shimModuleName in if !Debug.moduleResolution then diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index fd77465fb2..ba9633e710 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -20,6 +20,7 @@ } }, "../../..": { + "name": "rescript", "version": "11.0.0-alpha.5", "dev": true, "hasInstallScript": true, diff --git a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json index 31dab8bd71..98d757232d 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json +++ b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json @@ -4,6 +4,9 @@ "module": "es6", "moduleResolution": "bundler", "importPath": "relative", + "shims": { + "Js": "Js" + }, "debug": { "all": false }, diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js index 287f7a99a4..7e54a0b9e0 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js @@ -10,7 +10,12 @@ function makeFoo(bar) { }; } +function jsonStringify(prim) { + return JSON.stringify(prim); +} + export { makeFoo , + jsonStringify , } /* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx index c87c012526..6e0bdc027a 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx @@ -6,6 +6,10 @@ import * as BarBS__Es6Import from './Bar.bs'; const BarBS: any = BarBS__Es6Import; +import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.ts'; + import type {t as Foo_t} from './Foo.gen.tsx'; export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; + +export const jsonStringify: (_1:Js_Json_t) => string = BarBS.jsonStringify; diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res index 48f50ef17d..03a8c37de2 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res @@ -3,3 +3,5 @@ let makeFoo = (~bar) => { open Foo {...make(), bar} } + +@genType let jsonStringify = Js.Json.stringify diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts b/jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts new file mode 100644 index 0000000000..459d805696 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts @@ -0,0 +1 @@ +export type Json_t = unknown; diff --git a/jscomp/gentype_tests/typescript-res-node16/bsconfig.json b/jscomp/gentype_tests/typescript-res-node16/bsconfig.json index 74808a987a..100052917d 100644 --- a/jscomp/gentype_tests/typescript-res-node16/bsconfig.json +++ b/jscomp/gentype_tests/typescript-res-node16/bsconfig.json @@ -4,6 +4,9 @@ "module": "es6", "moduleResolution": "node16", "importPath": "relative", + "shims": { + "Js": "Js" + }, "debug": { "all": false }, diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js b/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js index 287f7a99a4..7e54a0b9e0 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js @@ -10,7 +10,12 @@ function makeFoo(bar) { }; } +function jsonStringify(prim) { + return JSON.stringify(prim); +} + export { makeFoo , + jsonStringify , } /* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx index e91190d874..ad53dcf6d2 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx @@ -6,6 +6,10 @@ import * as BarBS__Es6Import from './Bar.bs'; const BarBS: any = BarBS__Es6Import; +import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.js'; + import type {t as Foo_t} from './Foo.gen.js'; export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; + +export const jsonStringify: (_1:Js_Json_t) => string = BarBS.jsonStringify; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res index 48f50ef17d..03a8c37de2 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res @@ -3,3 +3,5 @@ let makeFoo = (~bar) => { open Foo {...make(), bar} } + +@genType let jsonStringify = Js.Json.stringify diff --git a/jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts b/jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts new file mode 100644 index 0000000000..459d805696 --- /dev/null +++ b/jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts @@ -0,0 +1 @@ +export type Json_t = unknown; From d9fca1c6303b353b9b00ba16f502b74a19dc25f8 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Apr 2023 18:35:34 +0900 Subject: [PATCH 07/18] refactor --- jscomp/gentype/EmitType.ml | 11 +++++++---- jscomp/gentype/Paths.ml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/jscomp/gentype/EmitType.ml b/jscomp/gentype/EmitType.ml index 251e1083dd..7e16b0e043 100644 --- a/jscomp/gentype/EmitType.ml +++ b/jscomp/gentype/EmitType.ml @@ -20,16 +20,19 @@ let generatedFilesExtension ~(config : Config.t) = Filename.remove_extension s | None -> ".gen" -let outputFileSuffix ~(config : Config.t) ?(moduleExtension = ".tsx") () = +let inputFileSuffix ~(config : Config.t) = match config.generatedFileExtension with | Some s when Filename.extension s <> "" (* double extension *) -> s - | _ -> generatedFilesExtension ~config ^ moduleExtension + | _ -> generatedFilesExtension ~config ^ ".tsx" + +let outputFileSuffix ~(config : Config.t) = + generatedFilesExtension ~config ^ ".js" let generatedModuleExtension ~(config : Config.t) = match config.moduleResolution with | Node -> generatedFilesExtension ~config - | Node16 -> outputFileSuffix ~config ~moduleExtension:".js" () - | Bundler -> outputFileSuffix ~config () + | Node16 -> inputFileSuffix ~config + | Bundler -> outputFileSuffix ~config let shimExtension = ".shim.ts" diff --git a/jscomp/gentype/Paths.ml b/jscomp/gentype/Paths.ml index 10d3f8e2e3..048394c2eb 100644 --- a/jscomp/gentype/Paths.ml +++ b/jscomp/gentype/Paths.ml @@ -29,7 +29,7 @@ let findNameSpace cmt = |> keepAfterDash let getOutputFileRelative ~config cmt = - (cmt |> handleNamespace) ^ EmitType.outputFileSuffix ~config () + (cmt |> handleNamespace) ^ EmitType.inputFileSuffix ~config let getOutputFile ~(config : Config.t) cmt = Filename.concat config.projectRoot (getOutputFileRelative ~config cmt) From c661b63420a0d4d050a1d3713c3feb204805e61a Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Apr 2023 20:33:35 +0900 Subject: [PATCH 08/18] apply moduleResolution to bs imports --- jscomp/gentype/EmitType.ml | 28 ++++--------------- jscomp/gentype/GenTypeConfig.ml | 5 ++-- jscomp/gentype/GenTypeMain.ml | 2 +- jscomp/gentype/ImportPath.ml | 8 +++--- jscomp/gentype/ImportPath.mli | 1 + jscomp/gentype/ModuleExtension.ml | 28 +++++++++++++++++++ jscomp/gentype/ModuleResolver.ml | 9 ++---- jscomp/gentype/Paths.ml | 2 +- .../typescript-res-bundler/src/Bar.gen.tsx | 4 +-- .../typescript-res-bundler/src/Foo.gen.tsx | 2 +- .../typescript-res-node16/package-lock.json | 1 + .../typescript-res-node16/src/Bar.gen.tsx | 4 +-- .../typescript-res-node16/src/Foo.gen.tsx | 2 +- 13 files changed, 51 insertions(+), 45 deletions(-) create mode 100644 jscomp/gentype/ModuleExtension.ml diff --git a/jscomp/gentype/EmitType.ml b/jscomp/gentype/EmitType.ml index 7e16b0e043..bde6a045eb 100644 --- a/jscomp/gentype/EmitType.ml +++ b/jscomp/gentype/EmitType.ml @@ -13,29 +13,6 @@ let fileHeader ~sourceFile = ~lines:["TypeScript file generated from " ^ sourceFile ^ " by genType."] ^ "/* eslint-disable import/first */\n\n" -let generatedFilesExtension ~(config : Config.t) = - match config.generatedFileExtension with - | Some s -> - (* from .foo.bar to .foo *) - Filename.remove_extension s - | None -> ".gen" - -let inputFileSuffix ~(config : Config.t) = - match config.generatedFileExtension with - | Some s when Filename.extension s <> "" (* double extension *) -> s - | _ -> generatedFilesExtension ~config ^ ".tsx" - -let outputFileSuffix ~(config : Config.t) = - generatedFilesExtension ~config ^ ".js" - -let generatedModuleExtension ~(config : Config.t) = - match config.moduleResolution with - | Node -> generatedFilesExtension ~config - | Node16 -> inputFileSuffix ~config - | Bundler -> outputFileSuffix ~config - -let shimExtension = ".shim.ts" - let interfaceName ~(config : Config.t) name = match config.exportInterfaces with | true -> "I" ^ name @@ -395,6 +372,11 @@ let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t) | true -> "// tslint:disable-next-line:no-var-requires\n" | false -> "// @ts-ignore: Implicit any on import\n" in + let importPath = + match config.moduleResolution with + | Node -> importPath |> ImportPath.chopExtensionSafe (* for backward compatibility *) + | _ -> importPath + in match config.module_ with | ES6 when not importedValueOrComponent -> let moduleNameString = ModuleName.toString moduleName in diff --git a/jscomp/gentype/GenTypeConfig.ml b/jscomp/gentype/GenTypeConfig.ml index da4ce60b6d..0d7195c033 100644 --- a/jscomp/gentype/GenTypeConfig.ml +++ b/jscomp/gentype/GenTypeConfig.ml @@ -40,7 +40,7 @@ let default = projectRoot = ""; shimsMap = ModuleNameMap.empty; sources = None; - suffix = ""; + suffix = ".bs.js"; } let bsPlatformLib ~config = @@ -182,9 +182,8 @@ let readConfig ~getBsConfigFile ~namespace = in let suffix = match bsconf |> getStringOption "suffix" with - | Some ".bs.js" -> ".bs" | Some s -> s - | _ -> ".bs" + | _ -> default.suffix in let bsDependencies = match bsconf |> getOpt "bs-dependencies" with diff --git a/jscomp/gentype/GenTypeMain.ml b/jscomp/gentype/GenTypeMain.ml index 7269de6451..f190a7bb5c 100644 --- a/jscomp/gentype/GenTypeMain.ml +++ b/jscomp/gentype/GenTypeMain.ml @@ -104,7 +104,7 @@ let processCmtFile cmt = let isInterface = Filename.check_suffix cmtFile ".cmti" in let resolver = ModuleResolver.createLazyResolver ~config - ~extensions:[".res"; EmitType.shimExtension] ~excludeFile:(fun fname -> + ~extensions:[".res"; ".shim.ts"] ~excludeFile:(fun fname -> fname = "React.res" || fname = "ReasonReact.res") in let inputCMT, hasGenTypeAnnotations = diff --git a/jscomp/gentype/ImportPath.ml b/jscomp/gentype/ImportPath.ml index 6715b18b97..13f3f3e1f1 100644 --- a/jscomp/gentype/ImportPath.ml +++ b/jscomp/gentype/ImportPath.ml @@ -13,8 +13,8 @@ let fromModule ~dir ~importExtension moduleName = let fromStringUnsafe s = ("", s) -let chopExtensionSafe s = - try s |> Filename.chop_extension with Invalid_argument _ -> s +let chopExtensionSafe (dir, s) = + try (dir, s |> Filename.chop_extension) with Invalid_argument _ -> (dir, s) let dump (dir, s) = NodeFilename.concat dir s @@ -22,10 +22,10 @@ let toCmt ~(config : Config.t) ~outputFileRelative (dir, s) = let open Filename in concat (outputFileRelative |> dirname) - (((dir, s |> chopExtensionSafe) |> dump) + ((dir, s) |> chopExtensionSafe |> dump) ^ (match config.namespace with | None -> "" | Some name -> "-" ^ name) - ^ ".cmt") + ^ ".cmt" let emit (dir, s) = (dir, s) |> dump diff --git a/jscomp/gentype/ImportPath.mli b/jscomp/gentype/ImportPath.mli index 54d72d4254..5f319d00bc 100644 --- a/jscomp/gentype/ImportPath.mli +++ b/jscomp/gentype/ImportPath.mli @@ -3,6 +3,7 @@ open GenTypeCommon type t val bsCurryPath : config:Config.t -> t +val chopExtensionSafe : t -> t val dump : t -> string val emit : t -> string val fromModule : dir:string -> importExtension:string -> ModuleName.t -> t diff --git a/jscomp/gentype/ModuleExtension.ml b/jscomp/gentype/ModuleExtension.ml new file mode 100644 index 0000000000..1f4c404e48 --- /dev/null +++ b/jscomp/gentype/ModuleExtension.ml @@ -0,0 +1,28 @@ +open GenTypeCommon + +let shimExtension ~(config : Config.t) = + match config.moduleResolution with + | Node -> ".shim" + | Node16 -> ".shim.js" + | Bundler -> ".shim.ts" + +let generatedFilesExtension ~(config : Config.t) = + match config.generatedFileExtension with + | Some s -> + (* from .foo.bar to .foo *) + Filename.remove_extension s + | None -> ".gen" + +let inputFileSuffix ~(config : Config.t) = + match config.generatedFileExtension with + | Some s when Filename.extension s <> "" (* double extension *) -> s + | _ -> generatedFilesExtension ~config ^ ".tsx" + +let outputFileSuffix ~(config : Config.t) = + generatedFilesExtension ~config ^ ".js" + +let generatedModuleExtension ~(config : Config.t) = + match config.moduleResolution with + | Node -> generatedFilesExtension ~config + | Node16 -> inputFileSuffix ~config + | Bundler -> outputFileSuffix ~config diff --git a/jscomp/gentype/ModuleResolver.ml b/jscomp/gentype/ModuleResolver.ml index 5f4730419e..dd465d5a71 100644 --- a/jscomp/gentype/ModuleResolver.ml +++ b/jscomp/gentype/ModuleResolver.ml @@ -256,7 +256,7 @@ let resolveGeneratedModule ~config ~outputFileRelative ~resolver moduleName = (moduleName |> ModuleName.toString); let importPath = resolveModule ~config - ~importExtension:(EmitType.generatedModuleExtension ~config) + ~importExtension:(ModuleExtension.generatedModuleExtension ~config) ~outputFileRelative ~resolver ~useBsDependencies:true moduleName in if !Debug.moduleResolution then @@ -272,12 +272,7 @@ let importPathForReasonModuleName ~(config : Config.t) ~outputFileRelative | shimModuleName -> if !Debug.moduleResolution then Log_.item "ShimModuleName: %s\n" (shimModuleName |> ModuleName.toString); - let importExtension = - match config.moduleResolution with - | Node -> ".shim" - | Node16 -> ".shim.js" - | Bundler -> ".shim.ts" - in + let importExtension = ModuleExtension.shimExtension ~config in let importPath = resolveModule ~config ~importExtension ~outputFileRelative ~resolver ~useBsDependencies:false shimModuleName diff --git a/jscomp/gentype/Paths.ml b/jscomp/gentype/Paths.ml index 048394c2eb..c170065a43 100644 --- a/jscomp/gentype/Paths.ml +++ b/jscomp/gentype/Paths.ml @@ -29,7 +29,7 @@ let findNameSpace cmt = |> keepAfterDash let getOutputFileRelative ~config cmt = - (cmt |> handleNamespace) ^ EmitType.inputFileSuffix ~config + (cmt |> handleNamespace) ^ ModuleExtension.inputFileSuffix ~config let getOutputFile ~(config : Config.t) cmt = Filename.concat config.projectRoot (getOutputFileRelative ~config cmt) diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx index 6e0bdc027a..72e78927e0 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx @@ -3,12 +3,12 @@ // @ts-ignore: Implicit any on import -import * as BarBS__Es6Import from './Bar.bs'; +import * as BarBS__Es6Import from './Bar.bs.js'; const BarBS: any = BarBS__Es6Import; import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.ts'; -import type {t as Foo_t} from './Foo.gen.tsx'; +import type {t as Foo_t} from './Foo.gen.js'; export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx index 2f2e3f7611..f97f38f93e 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx @@ -3,7 +3,7 @@ // @ts-ignore: Implicit any on import -import * as FooBS__Es6Import from './Foo.bs'; +import * as FooBS__Es6Import from './Foo.bs.js'; const FooBS: any = FooBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal diff --git a/jscomp/gentype_tests/typescript-res-node16/package-lock.json b/jscomp/gentype_tests/typescript-res-node16/package-lock.json index 3626816831..4e8c6c58c2 100644 --- a/jscomp/gentype_tests/typescript-res-node16/package-lock.json +++ b/jscomp/gentype_tests/typescript-res-node16/package-lock.json @@ -13,6 +13,7 @@ } }, "../../..": { + "name": "rescript", "version": "11.0.0-alpha.5", "dev": true, "hasInstallScript": true, diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx index ad53dcf6d2..5391d130d9 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx @@ -3,12 +3,12 @@ // @ts-ignore: Implicit any on import -import * as BarBS__Es6Import from './Bar.bs'; +import * as BarBS__Es6Import from './Bar.bs.js'; const BarBS: any = BarBS__Es6Import; import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.js'; -import type {t as Foo_t} from './Foo.gen.js'; +import type {t as Foo_t} from './Foo.gen.tsx'; export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx index 2f2e3f7611..f97f38f93e 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx @@ -3,7 +3,7 @@ // @ts-ignore: Implicit any on import -import * as FooBS__Es6Import from './Foo.bs'; +import * as FooBS__Es6Import from './Foo.bs.js'; const FooBS: any = FooBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal From befeb0b91f8ead06d8501045beab0dd8f408d565 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Apr 2023 20:34:06 +0900 Subject: [PATCH 09/18] format --- jscomp/gentype/EmitType.ml | 4 +++- jscomp/gentype/GenTypeMain.ml | 4 ++-- jscomp/gentype/ImportPath.ml | 12 +++++------- jscomp/gentype/ModuleResolver.ml | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jscomp/gentype/EmitType.ml b/jscomp/gentype/EmitType.ml index bde6a045eb..7f6dbe7e27 100644 --- a/jscomp/gentype/EmitType.ml +++ b/jscomp/gentype/EmitType.ml @@ -374,7 +374,9 @@ let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t) in let importPath = match config.moduleResolution with - | Node -> importPath |> ImportPath.chopExtensionSafe (* for backward compatibility *) + | Node -> + importPath + |> ImportPath.chopExtensionSafe (* for backward compatibility *) | _ -> importPath in match config.module_ with diff --git a/jscomp/gentype/GenTypeMain.ml b/jscomp/gentype/GenTypeMain.ml index f190a7bb5c..e4bcaf0346 100644 --- a/jscomp/gentype/GenTypeMain.ml +++ b/jscomp/gentype/GenTypeMain.ml @@ -103,8 +103,8 @@ let processCmtFile cmt = let fileName = cmt |> Paths.getModuleName in let isInterface = Filename.check_suffix cmtFile ".cmti" in let resolver = - ModuleResolver.createLazyResolver ~config - ~extensions:[".res"; ".shim.ts"] ~excludeFile:(fun fname -> + ModuleResolver.createLazyResolver ~config ~extensions:[".res"; ".shim.ts"] + ~excludeFile:(fun fname -> fname = "React.res" || fname = "ReasonReact.res") in let inputCMT, hasGenTypeAnnotations = diff --git a/jscomp/gentype/ImportPath.ml b/jscomp/gentype/ImportPath.ml index 13f3f3e1f1..a1c11145d2 100644 --- a/jscomp/gentype/ImportPath.ml +++ b/jscomp/gentype/ImportPath.ml @@ -20,12 +20,10 @@ let dump (dir, s) = NodeFilename.concat dir s let toCmt ~(config : Config.t) ~outputFileRelative (dir, s) = let open Filename in - concat - (outputFileRelative |> dirname) - ((dir, s) |> chopExtensionSafe |> dump) - ^ (match config.namespace with - | None -> "" - | Some name -> "-" ^ name) - ^ ".cmt" + concat (outputFileRelative |> dirname) ((dir, s) |> chopExtensionSafe |> dump) + ^ (match config.namespace with + | None -> "" + | Some name -> "-" ^ name) + ^ ".cmt" let emit (dir, s) = (dir, s) |> dump diff --git a/jscomp/gentype/ModuleResolver.ml b/jscomp/gentype/ModuleResolver.ml index dd465d5a71..711219a75e 100644 --- a/jscomp/gentype/ModuleResolver.ml +++ b/jscomp/gentype/ModuleResolver.ml @@ -274,8 +274,8 @@ let importPathForReasonModuleName ~(config : Config.t) ~outputFileRelative Log_.item "ShimModuleName: %s\n" (shimModuleName |> ModuleName.toString); let importExtension = ModuleExtension.shimExtension ~config in let importPath = - resolveModule ~config ~importExtension ~outputFileRelative - ~resolver ~useBsDependencies:false shimModuleName + resolveModule ~config ~importExtension ~outputFileRelative ~resolver + ~useBsDependencies:false shimModuleName in if !Debug.moduleResolution then Log_.item "Import Path: %s\n" (importPath |> ImportPath.dump); From 3338fbe80807ffb765df1e640f8c58adf2b00dba Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Apr 2023 20:42:39 +0900 Subject: [PATCH 10/18] fix --- jscomp/gentype/ModuleExtension.ml | 4 ++-- jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx | 2 +- jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jscomp/gentype/ModuleExtension.ml b/jscomp/gentype/ModuleExtension.ml index 1f4c404e48..199db6a045 100644 --- a/jscomp/gentype/ModuleExtension.ml +++ b/jscomp/gentype/ModuleExtension.ml @@ -24,5 +24,5 @@ let outputFileSuffix ~(config : Config.t) = let generatedModuleExtension ~(config : Config.t) = match config.moduleResolution with | Node -> generatedFilesExtension ~config - | Node16 -> inputFileSuffix ~config - | Bundler -> outputFileSuffix ~config + | Node16 -> outputFileSuffix ~config + | Bundler -> inputFileSuffix ~config diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx index 72e78927e0..c72f8d2b79 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx @@ -8,7 +8,7 @@ const BarBS: any = BarBS__Es6Import; import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.ts'; -import type {t as Foo_t} from './Foo.gen.js'; +import type {t as Foo_t} from './Foo.gen.tsx'; export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx index 5391d130d9..edd0bb3206 100644 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx +++ b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx @@ -8,7 +8,7 @@ const BarBS: any = BarBS__Es6Import; import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.js'; -import type {t as Foo_t} from './Foo.gen.tsx'; +import type {t as Foo_t} from './Foo.gen.js'; export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; From 6a76b2487924729312bd34641ee5ce97426de0ba Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Apr 2023 20:43:07 +0900 Subject: [PATCH 11/18] add recipe --- Makefile | 4 ++++ jscomp/gentype_tests/typescript-res-bundler/Makefile | 1 + jscomp/gentype_tests/typescript-res-node16/Makefile | 1 + 3 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 047c9a9dff..b35036a67e 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,8 @@ test-syntax-roundtrip: test-gentype: make -C jscomp/gentype_tests/typescript-react-example clean test + make -C jscomp/gentype_tests/typescript-res-node16 clean test + make -C jscomp/gentype_tests/typescript-res-bundler clean test test-all: test test-gentype @@ -61,6 +63,8 @@ checkformat: clean-gentype: make -C jscomp/gentype_tests/typescript-react-example clean + make -C jscomp/gentype_tests/typescript-res-node16 clean + make -C jscomp/gentype_tests/typescript-res-bundler clean clean: dune clean diff --git a/jscomp/gentype_tests/typescript-res-bundler/Makefile b/jscomp/gentype_tests/typescript-res-bundler/Makefile index 2bb4e9b8a2..71d10b870f 100644 --- a/jscomp/gentype_tests/typescript-res-bundler/Makefile +++ b/jscomp/gentype_tests/typescript-res-bundler/Makefile @@ -5,6 +5,7 @@ node_modules/.bin/tsc: test: node_modules/.bin/tsc npm run build + npm run tsc clean: rm -rf node_modules lib src/*.bs.js src/*.gen.tsx diff --git a/jscomp/gentype_tests/typescript-res-node16/Makefile b/jscomp/gentype_tests/typescript-res-node16/Makefile index 2bb4e9b8a2..71d10b870f 100644 --- a/jscomp/gentype_tests/typescript-res-node16/Makefile +++ b/jscomp/gentype_tests/typescript-res-node16/Makefile @@ -5,6 +5,7 @@ node_modules/.bin/tsc: test: node_modules/.bin/tsc npm run build + npm run tsc clean: rm -rf node_modules lib src/*.bs.js src/*.gen.tsx From 2b00aaf85fcad8a40b825b7c3175e5292dec6fc0 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 02:47:08 +0900 Subject: [PATCH 12/18] remove tests --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index b35036a67e..047c9a9dff 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,6 @@ test-syntax-roundtrip: test-gentype: make -C jscomp/gentype_tests/typescript-react-example clean test - make -C jscomp/gentype_tests/typescript-res-node16 clean test - make -C jscomp/gentype_tests/typescript-res-bundler clean test test-all: test test-gentype @@ -63,8 +61,6 @@ checkformat: clean-gentype: make -C jscomp/gentype_tests/typescript-react-example clean - make -C jscomp/gentype_tests/typescript-res-node16 clean - make -C jscomp/gentype_tests/typescript-res-bundler clean clean: dune clean From 71a3448b8059429530df6c26cc9adfb4beade7eb Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 02:52:46 +0900 Subject: [PATCH 13/18] add docstrings --- jscomp/gentype/GenTypeConfig.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jscomp/gentype/GenTypeConfig.ml b/jscomp/gentype/GenTypeConfig.ml index 0d7195c033..125d94fb5c 100644 --- a/jscomp/gentype/GenTypeConfig.ml +++ b/jscomp/gentype/GenTypeConfig.ml @@ -1,7 +1,15 @@ module ModuleNameMap = Map.Make (ModuleName) type module_ = CommonJS | ES6 -type moduleResolution = Node | Node16 | Bundler + +(** Compatibility for `compilerOptions.moduleResolution` in TypeScript projects. *) +type moduleResolution = + | Node (** should drop extension on import statements *) + | Node16 + (** should use TS output's extension (e.g. `.gen.js`) on import statements *) + | Bundler + (** should use TS input's extension (e.g. `.gen.tsx`) on import statements *) + type bsVersion = int * int * int type t = { From b0f1e2d24916b9e81640e71440c1efc6fde75dd9 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 03:04:29 +0900 Subject: [PATCH 14/18] add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b31db042c5..7d6dfa3930 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ #### :rocket: Main New Feature - Add support for Dynamic import. https://github.com/rescript-lang/rescript-compiler/pull/5703 +- GenType: Add `moduleResolution` option to customize extensions on emitted import statements. This helps to adjust output compatibility with TypeScript projects. https://github.com/rescript-lang/rescript-compiler/pull/6182 + - `node` (default): Drop extensions. + - `node16`: Use TS output's extensions (e.g. `.gen.js`). + - `bundler`: Use TS input's extensions (e.g. `.gen.tsx`). #### :boom: Breaking Change From 61559825c50ddb97c50058e4bb1e1368b30812df Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 03:14:29 +0900 Subject: [PATCH 15/18] changelog [skip ci] --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d6dfa3930..97e8885ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,10 @@ #### :rocket: Main New Feature - Add support for Dynamic import. https://github.com/rescript-lang/rescript-compiler/pull/5703 -- GenType: Add `moduleResolution` option to customize extensions on emitted import statements. This helps to adjust output compatibility with TypeScript projects. https://github.com/rescript-lang/rescript-compiler/pull/6182 +- GenType: Add `moduleResolution` option to customize extensions on emitted import statements. This helps to adjust output compatibility with TypeScript projects using ESM. https://github.com/rescript-lang/rescript-compiler/pull/6182 - `node` (default): Drop extensions. - - `node16`: Use TS output's extensions (e.g. `.gen.js`). - - `bundler`: Use TS input's extensions (e.g. `.gen.tsx`). + - `node16`: Use TS output's extensions (e.g. `.gen.js`). Make it ESM-compatible. + - `bundler`: Use TS input's extensions (e.g. `.gen.tsx`). Make it ESM-compatible. #### :boom: Breaking Change From 2d39bedbf437f7f03bb9ec29c22d38ce15c6a9d3 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 23:04:53 +0900 Subject: [PATCH 16/18] remove snapshots completely --- .../typescript-res-bundler/.gitignore | 17 ------- .../typescript-res-bundler/Makefile | 15 ------ .../typescript-res-bundler/bsconfig.json | 28 ---------- .../typescript-res-bundler/package-lock.json | 51 ------------------- .../typescript-res-bundler/package.json | 17 ------- .../typescript-res-bundler/src/Bar.bs.js | 21 -------- .../typescript-res-bundler/src/Bar.gen.tsx | 15 ------ .../typescript-res-bundler/src/Bar.res | 7 --- .../typescript-res-bundler/src/Foo.bs.js | 14 ----- .../typescript-res-bundler/src/Foo.gen.tsx | 12 ----- .../typescript-res-bundler/src/Foo.res | 5 -- .../src/shims/Js.shim.ts | 1 - .../typescript-res-bundler/tsconfig.json | 16 ------ .../typescript-res-node16/.gitignore | 17 ------- .../typescript-res-node16/Makefile | 15 ------ .../typescript-res-node16/bsconfig.json | 28 ---------- .../typescript-res-node16/package-lock.json | 51 ------------------- .../typescript-res-node16/package.json | 17 ------- .../typescript-res-node16/src/Bar.bs.js | 21 -------- .../typescript-res-node16/src/Bar.gen.tsx | 15 ------ .../typescript-res-node16/src/Bar.res | 7 --- .../typescript-res-node16/src/Foo.bs.js | 14 ----- .../typescript-res-node16/src/Foo.gen.tsx | 12 ----- .../typescript-res-node16/src/Foo.res | 5 -- .../src/shims/Js.shim.ts | 1 - .../typescript-res-node16/tsconfig.json | 15 ------ 26 files changed, 437 deletions(-) delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/.gitignore delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/Makefile delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/bsconfig.json delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/package-lock.json delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/package.json delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Bar.res delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/Foo.res delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts delete mode 100644 jscomp/gentype_tests/typescript-res-bundler/tsconfig.json delete mode 100644 jscomp/gentype_tests/typescript-res-node16/.gitignore delete mode 100644 jscomp/gentype_tests/typescript-res-node16/Makefile delete mode 100644 jscomp/gentype_tests/typescript-res-node16/bsconfig.json delete mode 100644 jscomp/gentype_tests/typescript-res-node16/package-lock.json delete mode 100644 jscomp/gentype_tests/typescript-res-node16/package.json delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Bar.res delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/Foo.res delete mode 100644 jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts delete mode 100644 jscomp/gentype_tests/typescript-res-node16/tsconfig.json diff --git a/jscomp/gentype_tests/typescript-res-bundler/.gitignore b/jscomp/gentype_tests/typescript-res-bundler/.gitignore deleted file mode 100644 index 3099aa9bf1..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# See https://help.github.com/ignore-files/ for more about ignoring files. - -# dependencies -/node_modules - - -# misc -/lib -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* diff --git a/jscomp/gentype_tests/typescript-res-bundler/Makefile b/jscomp/gentype_tests/typescript-res-bundler/Makefile deleted file mode 100644 index 71d10b870f..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -SHELL = /bin/bash - -node_modules/.bin/tsc: - npm install - -test: node_modules/.bin/tsc - npm run build - npm run tsc - -clean: - rm -rf node_modules lib src/*.bs.js src/*.gen.tsx - -.DEFAULT_GOAL := test - -.PHONY: clean test diff --git a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json deleted file mode 100644 index 98d757232d..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/bsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "gentypeconfig": { - "language": "typescript", - "module": "es6", - "moduleResolution": "bundler", - "importPath": "relative", - "shims": { - "Js": "Js" - }, - "debug": { - "all": false - }, - "exportInterfaces": false - }, - "name": "sample-typescript-app", - "bsc-flags": ["-bs-super-errors"], - "sources": [ - { - "dir": "src", - "subdirs": true - } - ], - "package-specs": { - "module": "es6", - "in-source": true - }, - "suffix": ".bs.js" -} diff --git a/jscomp/gentype_tests/typescript-res-bundler/package-lock.json b/jscomp/gentype_tests/typescript-res-bundler/package-lock.json deleted file mode 100644 index ff7fcee850..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/package-lock.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "typescript-res-bundler", - "version": "0.1.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "typescript-res-bundler", - "version": "0.1.0", - "devDependencies": { - "rescript": "file:../../..", - "typescript": "^5.0.4" - } - }, - "../../..": { - "name": "rescript", - "version": "11.0.0-alpha.5", - "dev": true, - "hasInstallScript": true, - "license": "SEE LICENSE IN LICENSE", - "bin": { - "bsc": "bsc", - "bstracing": "lib/bstracing", - "rescript": "rescript" - }, - "devDependencies": { - "mocha": "^10.1.0", - "nyc": "^15.0.0", - "prettier": "^2.7.1", - "rollup": "^0.49.2" - } - }, - "node_modules/rescript": { - "resolved": "../../..", - "link": true - }, - "node_modules/typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=12.20" - } - } - } -} diff --git a/jscomp/gentype_tests/typescript-res-bundler/package.json b/jscomp/gentype_tests/typescript-res-bundler/package.json deleted file mode 100644 index 2060d29109..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "typescript-res-bundler", - "version": "0.1.0", - "private": true, - "dependencies": { - }, - "scripts": { - "start": "rescript build -w", - "build": "rescript", - "clean": "rescript clean -with-deps", - "tsc": "tsc -p tsconfig.json" - }, - "devDependencies": { - "rescript": "file:../../..", - "typescript": "^5.0.4" - } -} diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js deleted file mode 100644 index 7e54a0b9e0..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.bs.js +++ /dev/null @@ -1,21 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Foo from "./Foo.bs.js"; - -function makeFoo(bar) { - var init = Foo.make(undefined); - return { - foo: init.foo, - bar: bar - }; -} - -function jsonStringify(prim) { - return JSON.stringify(prim); -} - -export { - makeFoo , - jsonStringify , -} -/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx deleted file mode 100644 index c72f8d2b79..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.gen.tsx +++ /dev/null @@ -1,15 +0,0 @@ -/* TypeScript file generated from Bar.res by genType. */ -/* eslint-disable import/first */ - - -// @ts-ignore: Implicit any on import -import * as BarBS__Es6Import from './Bar.bs.js'; -const BarBS: any = BarBS__Es6Import; - -import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.ts'; - -import type {t as Foo_t} from './Foo.gen.tsx'; - -export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; - -export const jsonStringify: (_1:Js_Json_t) => string = BarBS.jsonStringify; diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res b/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res deleted file mode 100644 index 03a8c37de2..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Bar.res +++ /dev/null @@ -1,7 +0,0 @@ -@genType -let makeFoo = (~bar) => { - open Foo - {...make(), bar} -} - -@genType let jsonStringify = Js.Json.stringify diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js deleted file mode 100644 index 940f3ec814..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.bs.js +++ /dev/null @@ -1,14 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - - -function make(param) { - return { - foo: 0, - bar: 0 - }; -} - -export { - make , -} -/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx deleted file mode 100644 index f97f38f93e..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.gen.tsx +++ /dev/null @@ -1,12 +0,0 @@ -/* TypeScript file generated from Foo.res by genType. */ -/* eslint-disable import/first */ - - -// @ts-ignore: Implicit any on import -import * as FooBS__Es6Import from './Foo.bs.js'; -const FooBS: any = FooBS__Es6Import; - -// tslint:disable-next-line:interface-over-type-literal -export type t = { readonly foo: number; readonly bar: number }; - -export const make: () => t = FooBS.make; diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res b/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res deleted file mode 100644 index 565eb4abcc..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/Foo.res +++ /dev/null @@ -1,5 +0,0 @@ -@genType -type t = {foo: int, bar: int} - -@genType -let make = () => {foo: 0, bar: 0} diff --git a/jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts b/jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts deleted file mode 100644 index 459d805696..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/src/shims/Js.shim.ts +++ /dev/null @@ -1 +0,0 @@ -export type Json_t = unknown; diff --git a/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json b/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json deleted file mode 100644 index 63b7744074..0000000000 --- a/jscomp/gentype_tests/typescript-res-bundler/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "target": "esnext", - "module": "esnext", - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "rootDir": "src", - "jsx": "react", - "noEmit": true - }, - "include": [ - "src" - ], - "exclude": [ - ] -} diff --git a/jscomp/gentype_tests/typescript-res-node16/.gitignore b/jscomp/gentype_tests/typescript-res-node16/.gitignore deleted file mode 100644 index 3099aa9bf1..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# See https://help.github.com/ignore-files/ for more about ignoring files. - -# dependencies -/node_modules - - -# misc -/lib -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* diff --git a/jscomp/gentype_tests/typescript-res-node16/Makefile b/jscomp/gentype_tests/typescript-res-node16/Makefile deleted file mode 100644 index 71d10b870f..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -SHELL = /bin/bash - -node_modules/.bin/tsc: - npm install - -test: node_modules/.bin/tsc - npm run build - npm run tsc - -clean: - rm -rf node_modules lib src/*.bs.js src/*.gen.tsx - -.DEFAULT_GOAL := test - -.PHONY: clean test diff --git a/jscomp/gentype_tests/typescript-res-node16/bsconfig.json b/jscomp/gentype_tests/typescript-res-node16/bsconfig.json deleted file mode 100644 index 100052917d..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/bsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "gentypeconfig": { - "language": "typescript", - "module": "es6", - "moduleResolution": "node16", - "importPath": "relative", - "shims": { - "Js": "Js" - }, - "debug": { - "all": false - }, - "exportInterfaces": false - }, - "name": "sample-typescript-app", - "bsc-flags": ["-bs-super-errors"], - "sources": [ - { - "dir": "src", - "subdirs": true - } - ], - "package-specs": { - "module": "es6", - "in-source": true - }, - "suffix": ".bs.js" -} diff --git a/jscomp/gentype_tests/typescript-res-node16/package-lock.json b/jscomp/gentype_tests/typescript-res-node16/package-lock.json deleted file mode 100644 index 4e8c6c58c2..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/package-lock.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "typescript-res-node16", - "version": "0.1.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "typescript-res-node16", - "version": "0.1.0", - "devDependencies": { - "rescript": "file:../../..", - "typescript": "^5.0.4" - } - }, - "../../..": { - "name": "rescript", - "version": "11.0.0-alpha.5", - "dev": true, - "hasInstallScript": true, - "license": "SEE LICENSE IN LICENSE", - "bin": { - "bsc": "bsc", - "bstracing": "lib/bstracing", - "rescript": "rescript" - }, - "devDependencies": { - "mocha": "^10.1.0", - "nyc": "^15.0.0", - "prettier": "^2.7.1", - "rollup": "^0.49.2" - } - }, - "node_modules/rescript": { - "resolved": "../../..", - "link": true - }, - "node_modules/typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=12.20" - } - } - } -} diff --git a/jscomp/gentype_tests/typescript-res-node16/package.json b/jscomp/gentype_tests/typescript-res-node16/package.json deleted file mode 100644 index 8f2295f0e5..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "typescript-res-node16", - "version": "0.1.0", - "private": true, - "dependencies": { - }, - "scripts": { - "start": "rescript build -w", - "build": "rescript", - "clean": "rescript clean -with-deps", - "tsc": "tsc -p tsconfig.json" - }, - "devDependencies": { - "rescript": "file:../../..", - "typescript": "^5.0.4" - } -} diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js b/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js deleted file mode 100644 index 7e54a0b9e0..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.bs.js +++ /dev/null @@ -1,21 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Foo from "./Foo.bs.js"; - -function makeFoo(bar) { - var init = Foo.make(undefined); - return { - foo: init.foo, - bar: bar - }; -} - -function jsonStringify(prim) { - return JSON.stringify(prim); -} - -export { - makeFoo , - jsonStringify , -} -/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx deleted file mode 100644 index edd0bb3206..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.gen.tsx +++ /dev/null @@ -1,15 +0,0 @@ -/* TypeScript file generated from Bar.res by genType. */ -/* eslint-disable import/first */ - - -// @ts-ignore: Implicit any on import -import * as BarBS__Es6Import from './Bar.bs.js'; -const BarBS: any = BarBS__Es6Import; - -import type {Json_t as Js_Json_t} from '../src/shims/Js.shim.js'; - -import type {t as Foo_t} from './Foo.gen.js'; - -export const makeFoo: (_1:{ readonly bar: number }) => Foo_t = BarBS.makeFoo; - -export const jsonStringify: (_1:Js_Json_t) => string = BarBS.jsonStringify; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res b/jscomp/gentype_tests/typescript-res-node16/src/Bar.res deleted file mode 100644 index 03a8c37de2..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/Bar.res +++ /dev/null @@ -1,7 +0,0 @@ -@genType -let makeFoo = (~bar) => { - open Foo - {...make(), bar} -} - -@genType let jsonStringify = Js.Json.stringify diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js b/jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js deleted file mode 100644 index 940f3ec814..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/Foo.bs.js +++ /dev/null @@ -1,14 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - - -function make(param) { - return { - foo: 0, - bar: 0 - }; -} - -export { - make , -} -/* No side effect */ diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx b/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx deleted file mode 100644 index f97f38f93e..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/Foo.gen.tsx +++ /dev/null @@ -1,12 +0,0 @@ -/* TypeScript file generated from Foo.res by genType. */ -/* eslint-disable import/first */ - - -// @ts-ignore: Implicit any on import -import * as FooBS__Es6Import from './Foo.bs.js'; -const FooBS: any = FooBS__Es6Import; - -// tslint:disable-next-line:interface-over-type-literal -export type t = { readonly foo: number; readonly bar: number }; - -export const make: () => t = FooBS.make; diff --git a/jscomp/gentype_tests/typescript-res-node16/src/Foo.res b/jscomp/gentype_tests/typescript-res-node16/src/Foo.res deleted file mode 100644 index 565eb4abcc..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/Foo.res +++ /dev/null @@ -1,5 +0,0 @@ -@genType -type t = {foo: int, bar: int} - -@genType -let make = () => {foo: 0, bar: 0} diff --git a/jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts b/jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts deleted file mode 100644 index 459d805696..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/src/shims/Js.shim.ts +++ /dev/null @@ -1 +0,0 @@ -export type Json_t = unknown; diff --git a/jscomp/gentype_tests/typescript-res-node16/tsconfig.json b/jscomp/gentype_tests/typescript-res-node16/tsconfig.json deleted file mode 100644 index f16aff10b1..0000000000 --- a/jscomp/gentype_tests/typescript-res-node16/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "target": "esnext", - "module": "esnext", - "moduleResolution": "node16", - "rootDir": "src", - "jsx": "react", - "noEmit": true - }, - "include": [ - "src" - ], - "exclude": [ - ] -} From 484bd15fe8b04452de34e3c64a464cef4f714d68 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 23:07:39 +0900 Subject: [PATCH 17/18] refactor: more clear var names --- jscomp/gentype/ModuleExtension.ml | 10 +++++----- jscomp/gentype/ModuleResolver.ml | 2 +- jscomp/gentype/Paths.ml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jscomp/gentype/ModuleExtension.ml b/jscomp/gentype/ModuleExtension.ml index 199db6a045..c983f4ec30 100644 --- a/jscomp/gentype/ModuleExtension.ml +++ b/jscomp/gentype/ModuleExtension.ml @@ -1,6 +1,6 @@ open GenTypeCommon -let shimExtension ~(config : Config.t) = +let shimTsOutputFileExtension ~(config : Config.t) = match config.moduleResolution with | Node -> ".shim" | Node16 -> ".shim.js" @@ -13,16 +13,16 @@ let generatedFilesExtension ~(config : Config.t) = Filename.remove_extension s | None -> ".gen" -let inputFileSuffix ~(config : Config.t) = +let tsInputFileSuffix ~(config : Config.t) = match config.generatedFileExtension with | Some s when Filename.extension s <> "" (* double extension *) -> s | _ -> generatedFilesExtension ~config ^ ".tsx" -let outputFileSuffix ~(config : Config.t) = +let tsOutputFileSuffix ~(config : Config.t) = generatedFilesExtension ~config ^ ".js" let generatedModuleExtension ~(config : Config.t) = match config.moduleResolution with | Node -> generatedFilesExtension ~config - | Node16 -> outputFileSuffix ~config - | Bundler -> inputFileSuffix ~config + | Node16 -> tsOutputFileSuffix ~config + | Bundler -> tsInputFileSuffix ~config diff --git a/jscomp/gentype/ModuleResolver.ml b/jscomp/gentype/ModuleResolver.ml index 711219a75e..838ecca198 100644 --- a/jscomp/gentype/ModuleResolver.ml +++ b/jscomp/gentype/ModuleResolver.ml @@ -272,7 +272,7 @@ let importPathForReasonModuleName ~(config : Config.t) ~outputFileRelative | shimModuleName -> if !Debug.moduleResolution then Log_.item "ShimModuleName: %s\n" (shimModuleName |> ModuleName.toString); - let importExtension = ModuleExtension.shimExtension ~config in + let importExtension = ModuleExtension.shimTsOutputFileExtension ~config in let importPath = resolveModule ~config ~importExtension ~outputFileRelative ~resolver ~useBsDependencies:false shimModuleName diff --git a/jscomp/gentype/Paths.ml b/jscomp/gentype/Paths.ml index c170065a43..b64b5c0b36 100644 --- a/jscomp/gentype/Paths.ml +++ b/jscomp/gentype/Paths.ml @@ -29,7 +29,7 @@ let findNameSpace cmt = |> keepAfterDash let getOutputFileRelative ~config cmt = - (cmt |> handleNamespace) ^ ModuleExtension.inputFileSuffix ~config + (cmt |> handleNamespace) ^ ModuleExtension.tsInputFileSuffix ~config let getOutputFile ~(config : Config.t) cmt = Filename.concat config.projectRoot (getOutputFileRelative ~config cmt) From eb791b9b9f0437c1581c17237425eae6f7c2fdd5 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Apr 2023 23:10:02 +0900 Subject: [PATCH 18/18] [skip ci] doc --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97e8885ff9..699b88bc72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,8 @@ - Add support for Dynamic import. https://github.com/rescript-lang/rescript-compiler/pull/5703 - GenType: Add `moduleResolution` option to customize extensions on emitted import statements. This helps to adjust output compatibility with TypeScript projects using ESM. https://github.com/rescript-lang/rescript-compiler/pull/6182 - `node` (default): Drop extensions. - - `node16`: Use TS output's extensions (e.g. `.gen.js`). Make it ESM-compatible. - - `bundler`: Use TS input's extensions (e.g. `.gen.tsx`). Make it ESM-compatible. + - `node16`: Use TS output's extensions. Make it ESM-compatible. + - `bundler`: Use TS input's extensions. Make it ESM-compatible. #### :boom: Breaking Change