From ad1e4f24c55c6ec7703a2f903509b5d2c34e7eca Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 4 Jul 2024 04:12:47 +0900 Subject: [PATCH 1/3] cleanup TypeScript config --- .gitignore | 2 + .../typescript-react-example/Makefile | 2 +- .../package-lock.json | 43 ++++++--------- .../typescript-react-example/package.json | 8 +-- .../typescript-react-example/tsconfig.json | 38 ++++--------- .../tsconfig.prod.json | 3 -- .../tsconfig.test.json | 6 --- jsconfig.json | 14 ----- package-lock.json | 53 ++++++++++++++++++- package.json | 7 ++- tsconfig.json | 22 ++++++++ 11 files changed, 111 insertions(+), 87 deletions(-) delete mode 100644 jscomp/gentype_tests/typescript-react-example/tsconfig.prod.json delete mode 100644 jscomp/gentype_tests/typescript-react-example/tsconfig.test.json delete mode 100644 jsconfig.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 862159ef35..483e948ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,5 @@ playground/compiler.js rewatch/target/ rewatch/rewatch + +*.tsbuildinfo \ No newline at end of file diff --git a/jscomp/gentype_tests/typescript-react-example/Makefile b/jscomp/gentype_tests/typescript-react-example/Makefile index 1d66d5442b..fd0b54fcd1 100644 --- a/jscomp/gentype_tests/typescript-react-example/Makefile +++ b/jscomp/gentype_tests/typescript-react-example/Makefile @@ -4,7 +4,7 @@ test: npm install npm run lint npm run build - npm run tsc + npm run typecheck @git diff --quiet src/ \ || { echo; echo "Please review the Gentype outputs too!"; echo; false; } \ || exit 1 diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index a276c375bf..8c8e8bd159 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -14,15 +14,15 @@ }, "devDependencies": { "@biomejs/biome": "1.8.3", - "@types/node": "^18.15.12", - "@types/react-dom": "^18.0.11", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", "rescript": "file:../../..", - "typescript": "^5.2.2" + "typescript": "5.5.3" } }, "../../..": { "name": "rescript", - "version": "12.0.0-alpha.1", + "version": "12.0.0-alpha.2", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", @@ -34,8 +34,10 @@ }, "devDependencies": { "@biomejs/biome": "1.8.3", + "@types/node": "^20.14.9", "mocha": "10.1.0", - "nyc": "15.0.0" + "nyc": "15.0.0", + "typescript": "5.5.3" }, "engines": { "node": ">=18" @@ -214,12 +216,6 @@ "react-dom": ">=18.0.0" } }, - "node_modules/@types/node": { - "version": "18.18.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.6.tgz", - "integrity": "sha512-wf3Vz+jCmOQ2HV1YUJuCWdL64adYxumkrxtc+H1VUQlnQI04+5HtH+qZCOE21lBE7gIrt+CwX2Wv8Acrw5Ak6w==", - "dev": true - }, "node_modules/@types/prop-types": { "version": "15.7.9", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.9.tgz", @@ -227,31 +223,24 @@ "dev": true }, "node_modules/@types/react": { - "version": "18.2.29", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.29.tgz", - "integrity": "sha512-Z+ZrIRocWtdD70j45izShRwDuiB4JZqDegqMFW/I8aG5DxxLKOzVNoq62UIO82v9bdgi+DO1jvsb9sTEZUSm+Q==", + "version": "18.3.3", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.3.tgz", + "integrity": "sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==", "dev": true, "dependencies": { "@types/prop-types": "*", - "@types/scheduler": "*", "csstype": "^3.0.2" } }, "node_modules/@types/react-dom": { - "version": "18.2.14", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.14.tgz", - "integrity": "sha512-V835xgdSVmyQmI1KLV2BEIUgqEuinxp9O4G6g3FqO/SqLac049E53aysv0oEFD2kHfejeKU+ZqL2bcFWj9gLAQ==", + "version": "18.3.0", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.0.tgz", + "integrity": "sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==", "dev": true, "dependencies": { "@types/react": "*" } }, - "node_modules/@types/scheduler": { - "version": "0.16.5", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.5.tgz", - "integrity": "sha512-s/FPdYRmZR8SjLWGMCuax7r3qCWQw9QKHzXVukAuuIJkXkDRwp+Pu5LMIVFi0Fxbav35WURicYr8u1QsoybnQw==", - "dev": true - }, "node_modules/csstype": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz", @@ -310,9 +299,9 @@ } }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/jscomp/gentype_tests/typescript-react-example/package.json b/jscomp/gentype_tests/typescript-react-example/package.json index 2e24046cf4..17169d3abe 100644 --- a/jscomp/gentype_tests/typescript-react-example/package.json +++ b/jscomp/gentype_tests/typescript-react-example/package.json @@ -6,7 +6,7 @@ "start": "rescript build -w", "build": "rescript", "clean": "rescript clean", - "tsc": "tsc -p tsconfig.json", + "typecheck": "tsc", "lint": "biome check src" }, "dependencies": { @@ -16,9 +16,9 @@ }, "devDependencies": { "@biomejs/biome": "1.8.3", - "@types/node": "^18.15.12", - "@types/react-dom": "^18.0.11", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", "rescript": "file:../../..", - "typescript": "^5.2.2" + "typescript": "5.5.3" } } diff --git a/jscomp/gentype_tests/typescript-react-example/tsconfig.json b/jscomp/gentype_tests/typescript-react-example/tsconfig.json index fef2a942b1..bc0391c192 100644 --- a/jscomp/gentype_tests/typescript-react-example/tsconfig.json +++ b/jscomp/gentype_tests/typescript-react-example/tsconfig.json @@ -1,39 +1,19 @@ { "compilerOptions": { - "outDir": "build/dist", - "module": "esnext", - "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], - "sourceMap": true, - "allowJs": true, + "module": "ESNext", + "moduleResolution": "Node", + "lib": ["DOM", "DOM.Iterable", "ESNext"], "jsx": "react-jsx", - "skipLibCheck": true, - "moduleResolution": "node", - "rootDir": ".", - "forceConsistentCasingInFileNames": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noImplicitAny": true, - "strictNullChecks": true, - "noUnusedLocals": true, - "strictPropertyInitialization": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, + "allowJs": true, "strict": true, - "resolveJsonModule": true, - "isolatedModules": true, + "strictNullChecks": true, + "skipLibCheck": true, "noEmit": true, - "noFallthroughCasesInSwitch": true + "composite": true, + "incremental": true }, "include": ["src"], - "exclude": [ - "node_modules", - "build", - "scripts", - "acceptance-tests", - "webpack", - "jest", - "src/setupTests.ts", - "src/AutoAnnotate.bs.js" - ] + "exclude": ["src/setupTests.ts", "src/AutoAnnotate.bs.js"] } diff --git a/jscomp/gentype_tests/typescript-react-example/tsconfig.prod.json b/jscomp/gentype_tests/typescript-react-example/tsconfig.prod.json deleted file mode 100644 index fc8520e737..0000000000 --- a/jscomp/gentype_tests/typescript-react-example/tsconfig.prod.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./tsconfig.json" -} diff --git a/jscomp/gentype_tests/typescript-react-example/tsconfig.test.json b/jscomp/gentype_tests/typescript-react-example/tsconfig.test.json deleted file mode 100644 index 2c7b284162..0000000000 --- a/jscomp/gentype_tests/typescript-react-example/tsconfig.test.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "commonjs" - } -} diff --git a/jsconfig.json b/jsconfig.json deleted file mode 100644 index 5ac7dffc06..0000000000 --- a/jsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "alwaysStrict": true, - "noImplicitAny": true, - // , "strictNullChecks": true - "target": "es2018", - // target need be set up - // otherwise some method is missing - "module": "nodenext", - // setup to understand commonjs module - - "moduleResolution": "nodenext" - } -} diff --git a/package-lock.json b/package-lock.json index 97d277e1d9..ea2ff3acb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,8 +17,10 @@ }, "devDependencies": { "@biomejs/biome": "1.8.3", + "@types/node": "^20.14.9", "mocha": "10.1.0", - "nyc": "15.0.0" + "nyc": "15.0.0", + "typescript": "5.5.3" }, "engines": { "node": ">=18" @@ -512,6 +514,15 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "node_modules/@types/node": { + "version": "20.14.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", + "integrity": "sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/aggregate-error": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", @@ -2373,6 +2384,25 @@ "is-typedarray": "^1.0.0" } }, + "node_modules/typescript": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", @@ -2883,6 +2913,15 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/node": { + "version": "20.14.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.9.tgz", + "integrity": "sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } + }, "aggregate-error": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", @@ -4296,6 +4335,18 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", + "dev": true + }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", diff --git a/package.json b/package.json index a7e30fdaba..9c66718280 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "format:all": "biome format --write .", "checkFormat": "biome format --changed --no-errors-on-unmatched .", "checkFormat:all": "biome format .", - "coverage": "nyc --timeout=3000 --reporter=html mocha jscomp/test/*test.js && open ./coverage/index.html" + "coverage": "nyc --timeout=3000 --reporter=html mocha jscomp/test/*test.js && open ./coverage/index.html", + "typecheck": "tsc" }, "files": [ "CHANGELOG.md", @@ -77,8 +78,10 @@ }, "devDependencies": { "@biomejs/biome": "1.8.3", + "@types/node": "^20.14.9", "mocha": "10.1.0", - "nyc": "15.0.0" + "nyc": "15.0.0", + "typescript": "5.5.3" }, "packageManager": "npm@10.8.1+sha512.0e9d42e92bd2318408ed81eaff2da5f78baf23ee7d12a6eed44a6e2901d0f29d7ab715d1b918ade601f72e769a824d9a5c322383f22bbbda5dd396e79de2a077" } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..f83400749c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "allowJs": true, + "resolveJsonModule": true, + "strict": true, + "strictNullChecks": true, + "noImplicitAny": true, + "noEmit": true, + "skipLibCheck": true, + "composite": true, + "incremental": true + }, + "include": ["./cli/*", "./scripts/*", "./package.json"], + "exclude": [ + "node_modules", + "./jscomp/test/**/*", + "./jscomp/gentype_tests/**/*" + ] +} From 2f4a376aded809715d916dafed160ac5f421a697 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 22 Jul 2024 02:37:20 +0900 Subject: [PATCH 2/3] remove unused scripts --- scripts/shake.js | 138 ----------------------------------------------- scripts/tmp.js | 98 --------------------------------- 2 files changed, 236 deletions(-) delete mode 100644 scripts/shake.js delete mode 100644 scripts/tmp.js diff --git a/scripts/shake.js b/scripts/shake.js deleted file mode 100644 index a3f1178a1d..0000000000 --- a/scripts/shake.js +++ /dev/null @@ -1,138 +0,0 @@ -//@ts-check -// usage : node ./script/shake.js bsb -var cp = require("child_process"); -var path = require("path"); -var fs = require("fs"); - -var bsc = path.join(__dirname, "..", process.platform, "bsc"); -var ocamlopt = path.join( - __dirname, - "..", - "native", - "4.06.1", - "bin", - "ocamlopt.opt", -); - -var base = process.argv[2]; -if (base === undefined) { - console.error(`please specifiy a base`); - process.exit(2); -} -var file = `${base}.ml`; -var cwd = path.join(__dirname, "..", "lib", "4.06.1"); - -// TODO replace it with yours -var esy = `/Users/hongbozhang/git/genType/_esy/default/build/install/default/bin`; - -/** - * - * @param {string} file - */ -function dsource(file) { - let tmp = path.join(cwd, "tmp.ml"); - var output = cp.spawnSync( - `${bsc} -bs-no-builtin-ppx -bs-syntax-only -dsource -c ${file} 2>${tmp}`, - { - cwd, - encoding: "utf8", - shell: true, - }, - ); - // check output.status - if (output.status === 0) { - // fs.writeFileSync(path.join(cwd, file), output.stderr); - fs.copyFileSync(tmp, path.join(cwd, file)); - fs.unlinkSync(tmp); - } else { - console.error(`dsource failure`); - console.error(fs.readFileSync(tmp) + ""); - process.exit(2); - } - - // fs.copyFileSync(path.join(cwd, tmp), path.join(cwd, file)); -} - -/** - * - * @param {string} file - * @param {string} msg - */ -function checkDiff(file, msg) { - var output = cp.spawnSync(`git diff --quiet ${file}`, { - shell: true, - encoding: "utf8", - cwd, - }); - if (output.status !== 0) { - var output = cp.spawnSync( - `git add ${file} && git commit -m "${msg} for ${file}"`, - { shell: true, encoding: "utf8", cwd }, - ); - if (output.status !== 0) { - console.error(`diff failure for ${file} -- ${msg}`); - process.exit(2); - } else { - console.log(output.stdout); - } - } else { - console.log(`nothing changes to ${file}`); - } -} -/** - * - * @param {string} file - */ -function shake(file) { - let tmp = path.join(cwd, "tmp.ml"); - var output = cp.spawnSync( - `${bsc} -bs-no-builtin-ppx -bs-syntax-only -dsource -ppx ${esy}/deadcodeppx.exe -c ${file} 2>${tmp}`, - { - cwd, - encoding: "utf8", - shell: true, - }, - ); - if (output.status !== 0) { - console.error(`shake failure`); - console.error(fs.readFileSync(tmp) + ""); - process.exit(2); - } else { - // fs.writeFileSync(path.join(cwd, file), output.stderr); - fs.copyFileSync(tmp, path.join(cwd, file)); - fs.unlinkSync(tmp); - } -} - -/** - * - * @param {string} file - */ -function attachDead(file) { - var output = cp.spawnSync(`${ocamlopt} -bin-annot -c ${file}`, { - cwd, - encoding: "utf8", - shell: true, - }); - - var genType = path.join(esy, "genType.exe"); - - output = cp.spawnSync(`Write=1 ${genType} -dce-cmt ${base}.cmt`, { - cwd, - encoding: "utf8", - shell: true, - }); - if (output.status !== 0) { - console.error(`dce failure`); - console.error(output.stderr); - process.exit(2); - } - // fs.writeFileSync(path.join(cwd,file),output.stderr) -} - -// normalize files -dsource(file); -checkDiff(file, `dsource changes`); -attachDead(file); -shake(file); -checkDiff(file, `shake`); diff --git a/scripts/tmp.js b/scripts/tmp.js deleted file mode 100644 index cfe6c54fd4..0000000000 --- a/scripts/tmp.js +++ /dev/null @@ -1,98 +0,0 @@ -//@ts-check -var fs = require("fs"); -var path = require("path"); -/** - * - * @param {number} n - */ -function* range(n) { - for (var i = 0; i < n; ++i) { - yield i; - } -} - -/** - * - * @param {number} n - */ -var constructors = n => { - return [...range(n)].map(x => `| A${x} \n`).reduce((x, y) => x + y); -}; - -/** - * - * @param {number} n - */ -var polyConstructors = n => { - return [...range(n)].map(x => `| \`variant${x} \n`).reduce((x, y) => x + y); -}; - -/** - * - * @param {number} n - */ -var matches = n => { - return [...range(n)].map(x => `| A${x} -> ${x} \n `).reduce((x, y) => x + y); -}; - -/** - * - * @param {number} n - */ -var xs = n => { - return [...range(n)] - .map(x => `| A${x} -> "A${x}" \n `) - .reduce((x, y) => x + y); -}; - -/** - * - * @param {number} n - */ -var code = n => { - var content = `type t = \n ${constructors(n)}`; - var match = `let to_enum = function\n ${matches(n)}`; - var to_string = `let to_string = function\n ${xs(n)}`; - return content + match + to_string; -}; - -/** - * - * @param {number} n - */ -var polyCode = n => { - var content = `type t = [ \n ${polyConstructors( - n, - )}\n ] [@@deriving jsConverter] `; - var eq = ` - let eq (x : t option) (y: t option) = - match x with - | Some x -> - (match y with None -> false | Some y -> x = y) - | None -> y = None - `; - var assertions = [...range(n)] - .map(x => `\n;;assert (tToJs \`variant${x} = "variant${x}")`) - .reduce((x, y) => x + y); - var assertions2 = [...range(n)] - .map(x => `\n;;assert (eq (tFromJs "variant${x}") (Some \`variant${x}))`) - .reduce((x, y) => x + y); - var assertions3 = `\n;;assert (eq (tFromJs "xx") None) \n`; - return content + eq + assertions + assertions2 + assertions3; -}; -var run = () => { - fs.writeFileSync( - path.join(__dirname, "..", "jscomp", "test", "big_enum.ml"), - code(300), - "utf8", - ); -}; - -var runPol = () => { - fs.writeFileSync( - path.join(__dirname, "..", "jscomp", "test", "big_polyvar_test.ml"), - polyCode(300), - ); -}; - -runPol(); From 879df4d728a588dae04eb492ef4c2f2c63f2c6a5 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 22 Jul 2024 02:48:31 +0900 Subject: [PATCH 3/3] enable lint for js --- .github/workflows/get_artifact_dir_name.js | 4 +- .github/workflows/prepare_package_upload.js | 4 +- .gitignore | 2 +- biome.json | 38 +- cli/bin_path.js | 29 +- cli/rescript_arg.js | 59 +- cli/rescript_bsb.js | 159 ++-- cli/rescript_dump.js | 20 +- cli/rescript_format.js | 72 +- cli/rescript_postinstall.js | 11 +- .../build_tests/build_warn_as_error/input.js | 24 +- jscomp/build_tests/case/input.js | 12 +- jscomp/build_tests/case2/input.js | 12 +- jscomp/build_tests/case3/input.js | 12 +- .../build_tests/cli_compile_status/input.js | 22 +- jscomp/build_tests/cli_help/input.js | 46 +- jscomp/build_tests/custom_namespace/input.js | 8 +- jscomp/build_tests/cycle/input.js | 16 +- jscomp/build_tests/cycle1/input.js | 14 +- .../deprecated-package-specs/input.js | 4 +- jscomp/build_tests/devonly/input.js | 4 +- .../duplicated_symlinked_packages/input.js | 14 +- jscomp/build_tests/exports/input.js | 4 +- jscomp/build_tests/hyphen2/input.js | 4 +- jscomp/build_tests/in_source/input.js | 15 +- jscomp/build_tests/install/input.js | 20 +- jscomp/build_tests/nested/input.js | 12 +- jscomp/build_tests/nnest/input.js | 12 +- jscomp/build_tests/ns/input.js | 4 +- jscomp/build_tests/post-build/input.js | 8 +- jscomp/build_tests/react_ppx/input.js | 4 +- jscomp/build_tests/rerror/input.js | 16 +- jscomp/build_tests/scoped_ppx/input.js | 17 +- jscomp/build_tests/super_errors/input.js | 25 +- .../transitive_pinned_dependency1/input.js | 8 +- .../transitive_pinned_dependency2/input.js | 8 +- .../unboxed_bool_with_const/input.js | 8 +- jscomp/build_tests/uncurried-always/input.js | 4 +- jscomp/build_tests/unicode/input.js | 13 +- jscomp/build_tests/utils.js | 2 +- .../build_tests/warn_legacy_config/input.js | 4 +- jscomp/build_tests/weird_deps/input.js | 8 +- jscomp/build_tests/weird_devdeps/input.js | 8 +- jscomp/build_tests/weird_names/input.js | 18 +- .../weird_names_not_found_bug/input.js | 8 +- jscomp/build_tests/x-y/input.js | 4 +- jscomp/build_tests/xpkg/input.js | 8 +- jscomp/build_tests/zerocycle/input.js | 10 +- .../typescript-react-example/biome.json | 10 +- .../package-lock.json | 2 + .../typescript-react-example/src/index.tsx | 8 +- jscomp/others/release.ninja | 66 +- jscomp/runtime/release.ninja | 6 +- lib/bstracing | 52 +- lib/minisocket.js | 147 ++-- package-lock.json | 48 +- package.json | 7 +- .../scripts/generate_cmijs.js | 40 +- packages/playground-bundling/tsconfig.json | 8 + playground/playground_test.js | 32 +- scripts/buildNinjaBinary.js | 10 +- scripts/ciTest.js | 16 +- scripts/copyExes.js | 21 +- scripts/dune.js | 12 - scripts/lib/meta.js | 7 + scripts/lib/paths.js | 86 +++ scripts/makeArtifactList.js | 40 +- scripts/ninja.js | 695 +++++++++--------- scripts/prebuilt.js | 79 +- scripts/release.js | 54 +- scripts/setVersion.js | 12 +- tsconfig.json | 12 +- 72 files changed, 1222 insertions(+), 1086 deletions(-) create mode 100644 packages/playground-bundling/tsconfig.json delete mode 100644 scripts/dune.js create mode 100644 scripts/lib/meta.js create mode 100644 scripts/lib/paths.js diff --git a/.github/workflows/get_artifact_dir_name.js b/.github/workflows/get_artifact_dir_name.js index 28e245bb5c..7d15b8e8dc 100644 --- a/.github/workflows/get_artifact_dir_name.js +++ b/.github/workflows/get_artifact_dir_name.js @@ -1,5 +1,5 @@ -const fs = require("fs"); -const os = require("os"); +const fs = require("node:fs"); +const os = require("node:os"); const { dirName: artifactDirName } = require("../../cli/bin_path.js"); diff --git a/.github/workflows/prepare_package_upload.js b/.github/workflows/prepare_package_upload.js index b94e20153e..bbf4ef206c 100644 --- a/.github/workflows/prepare_package_upload.js +++ b/.github/workflows/prepare_package_upload.js @@ -1,5 +1,5 @@ -const fs = require("fs"); -const os = require("os"); +const fs = require("node:fs"); +const os = require("node:os"); const packageSpec = require("rescript/package.json"); const { version } = packageSpec; diff --git a/.gitignore b/.gitignore index 483e948ffd..bafe93954b 100644 --- a/.gitignore +++ b/.gitignore @@ -97,4 +97,4 @@ playground/compiler.js rewatch/target/ rewatch/rewatch -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo diff --git a/biome.json b/biome.json index c5e429052d..29f2b61fa0 100644 --- a/biome.json +++ b/biome.json @@ -7,10 +7,39 @@ "useIgnoreFile": true }, "linter": { - "enabled": false + "enabled": true, + "rules": { + "recommended": true + }, + "ignore": [ + "jscomp/build_tests/**/lib/**", + "jscomp/build_tests/**/src/**", + "jscomp/test/**", + "lib/es6/**", + "lib/js/**", + "ninja/**", + "playground/packages/**", + "**/*.bs.js", + "**/*.res.js", + "**/*.gen.ts*", + "package.json" + ] }, "organizeImports": { - "enabled": false + "enabled": true, + "ignore": [ + "jscomp/build_tests/**/lib/**", + "jscomp/build_tests/**/src/**", + "jscomp/test/**", + "lib/es6/**", + "lib/js/**", + "ninja/**", + "playground/packages/**", + "**/*.bs.js", + "**/*.res.js", + "**/*.gen.ts*", + "package.json" + ] }, "formatter": { "enabled": true, @@ -24,9 +53,10 @@ "jscomp/build_tests/**/lib/**", "jscomp/build_tests/**/src/**", "jscomp/test/**", - "lib/**", + "lib/es6/**", + "lib/js/**", "ninja/**", - "playground/**", + "playground/packages/**", "**/*.bs.js", "**/*.res.js", "**/*.gen.ts*", diff --git a/cli/bin_path.js b/cli/bin_path.js index ca2e8afa08..81be768493 100644 --- a/cli/bin_path.js +++ b/cli/bin_path.js @@ -1,41 +1,26 @@ -//@ts-check +// @ts-check -var path = require("path"); +const path = require("node:path"); /** - * @type{string} - * * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. * So we'll have "darwin", "linux" and "win32" for x64 arch, * but "darwinarm64" and "linuxarm64" for arm64 arch. * Also, we do not have Windows ARM binaries yet. But the x64 binaries do work on Windows 11 ARM. * So omit the architecture for Windows, too. */ -var binDirName = +const binDirName = process.arch === "x64" || process.platform === "win32" ? process.platform : process.platform + process.arch; -/** - * - * @type{string} - */ -var binAbsolutePath = path.join(__dirname, "..", binDirName); +const binAbsolutePath = path.join(__dirname, "..", binDirName); -/** - * @type{string} - */ -var bsc_exe = path.join(binAbsolutePath, "bsc.exe"); +const bsc_exe = path.join(binAbsolutePath, "bsc.exe"); -/** - * @type{string} - */ -var ninja_exe = path.join(binAbsolutePath, "ninja.exe"); +const ninja_exe = path.join(binAbsolutePath, "ninja.exe"); -/** - * @type{string} - */ -var rescript_exe = path.join(binAbsolutePath, "rescript.exe"); +const rescript_exe = path.join(binAbsolutePath, "rescript.exe"); exports.dirName = binDirName; exports.absolutePath = binAbsolutePath; diff --git a/cli/rescript_arg.js b/cli/rescript_arg.js index 3bfdc1283e..11451f6667 100644 --- a/cli/rescript_arg.js +++ b/cli/rescript_arg.js @@ -1,4 +1,5 @@ -//@ts-check +// @ts-check + class StringBuilder { constructor() { this.val = ""; @@ -13,10 +14,10 @@ class StringBuilder { return this; } } + class ArgError extends Error {} /** - * * @param {string} s */ function bad_arg(s) { @@ -24,12 +25,21 @@ function bad_arg(s) { } /** - * @typedef {{val : string}} stringref - * @typedef {{val : boolean}} boolref - * @typedef {{kind:"Unit_call",data : ()=>void } | {kind : "Unit_set", data : boolref}} unit_action - * @typedef {{kind:"String_call",data:(s : string)=>void} | {kind : "String_set",data: stringref}} string_action - * @typedef {{kind:"Unit",data : unit_action } | {kind:"String", data: string_action}} action - * @typedef {Array<[string,action,string]>} specs + * @typedef {{ val: string }} stringref + * @typedef {{ val: boolean }} boolref + * @typedef {( + * | { kind: "Unit_call", data: () => void } + * | { kind: "Unit_set", data: boolref } + * )} unit_action + * @typedef {( + * | { kind: "String_call", data: (s: string) => void } + * | {kind: "String_set", data: stringref } + * )} string_action + * @typedef {( + * | { kind: "Unit", data: unit_action } + * | { kind: "String", data: string_action} + * )} action + * @typedef {Array<[string, action, string]>} specs * @param {StringBuilder} b * @param {string} usage * @param {specs} specs @@ -39,33 +49,32 @@ function usage_b(b, usage, specs) { if (specs.length === 0) { return; } - b.add(`\nOptions:\n`); - var max_col = 0; - for (let [key] of specs) { + b.add("\nOptions:\n"); + let max_col = 0; + for (const [key] of specs) { if (key.length > max_col) { max_col = key.length; } } for (let i = 0; i < specs.length; i++) { - let [key, _, doc] = specs[i]; + const [key, _, doc] = specs[i]; if (!doc.startsWith("*internal*")) { b.add(" ") .add(key) .add(" ".repeat(max_col - key.length + 2)); let cur = 0; - let doc_length = doc.length; + const doc_length = doc.length; while (cur < doc_length) { if (cur !== 0) { b.add("\n").add(" ".repeat(max_col + 4)); } - let i = doc.indexOf("\n", cur); + const i = doc.indexOf("\n", cur); if (i < 0) { b.add(doc.substring(cur)); break; - } else { - b.add(doc.substr(cur, i - cur)); - cur = i + 1; } + b.add(doc.substring(cur, i - cur)); + cur = i + 1; } b.add("\n"); } @@ -79,7 +88,7 @@ function usage_b(b, usage, specs) { * @param {specs} specs */ function stop_raise(usage, error, specs) { - var b = new StringBuilder(); + const b = new StringBuilder(); switch (error.kind) { case "Unknown": if (["-help", "--help", "-h"].includes(error.data)) { @@ -89,8 +98,10 @@ function stop_raise(usage, error, specs) { } else { b.add(`Unknown option "${error.data}".\n'`); } + break; case "Missing": b.add(`Option "${error.data}" needs an argument.\n'`); + break; } usage_b(b, usage, specs); bad_arg(b.val); @@ -114,15 +125,15 @@ function parse_exn( // first 3 are [node, rescript, subcommand] finish = argv.length, ) { - var current = start; - var list = []; + let current = start; + const list = []; while (current < finish) { - let s = argv[current]; + const s = argv[current]; ++current; if (s !== "" && s[0] === "-") { - var out = specs.find(([flag]) => flag === s); + const out = specs.find(([flag]) => flag === s); if (out !== undefined) { - let [_, action] = out; + const [_, action] = out; switch (action.kind) { case "Unit": switch (action.data.kind) { @@ -139,7 +150,7 @@ function parse_exn( if (current >= finish) { stop_raise(usage, { kind: "Missing", data: s }, specs); } else { - let arg = argv[current]; + const arg = argv[current]; ++current; switch (action.data.kind) { case "String_call": diff --git a/cli/rescript_bsb.js b/cli/rescript_bsb.js index a18f3ef0ac..2ccd6f58e5 100644 --- a/cli/rescript_bsb.js +++ b/cli/rescript_bsb.js @@ -1,9 +1,9 @@ -//@ts-check +// @ts-check -const fs = require("fs"); -const path = require("path"); -var os = require("os"); -const child_process = require("child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const os = require("node:os"); +const child_process = require("node:child_process"); const { rescript_exe } = require("./bin_path"); const cwd = process.cwd(); @@ -45,24 +45,28 @@ function releaseBuild() { function acquireBuild(args, options) { if (ownerProcess) { return null; - } else { - try { - ownerProcess = child_process.spawn(rescript_exe, args, { - stdio: "inherit", - ...options, - }); - fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { - encoding: "utf8", - flag: "wx", - mode: 0o664, - }); - } catch (err) { - if (err.code === "EEXIST") { - console.warn(lockFileName, "already exists, try later"); - } else console.log(err); + } + try { + ownerProcess = child_process.spawn(rescript_exe, args, { + stdio: "inherit", + ...options, + }); + if (!ownerProcess?.pid) { + throw new Error("Failed to spawn new process"); + } + fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { + encoding: "utf8", + flag: "wx", + mode: 0o664, + }); + } catch (err) { + if (err.code === "EEXIST") { + console.warn("%s already exists, try later", lockFileName); + } else { + console.log(err); } - return ownerProcess; } + return ownerProcess; } /** @@ -70,8 +74,8 @@ function acquireBuild(args, options) { * @param {(code: number) => void} [maybeOnClose] */ function delegate(args, maybeOnClose) { - let p; - if ((p = acquireBuild(args))) { + const p = acquireBuild(args); + if (p) { p.once("error", e => { console.error(String(e)); releaseBuild(); @@ -129,12 +133,12 @@ function updateFinishTime() { * @param {number} [code] */ function logFinishCompiling(code) { - let log = `>>>> Finish compiling`; + let log = ">>>> Finish compiling"; if (code) { - log = log + " (exit: " + code + ")"; + log = `${log} (exit: ${code})`; } if (isTtyStd) { - log = "\x1b[36m" + log + "\x1b[0m"; + log = `\x1b[36m${log}\x1b[0m`; } if (code) { console.log(log); @@ -145,9 +149,9 @@ function logFinishCompiling(code) { function logStartCompiling() { updateStartTime(); - let log = `>>>> Start compiling`; + let log = ">>>> Start compiling"; if (isTtyStd) { - log = "\x1b[36m" + log + "\x1b[0m"; + log = `\x1b[36m${log}\x1b[0m`; } console.log(log); } @@ -164,9 +168,8 @@ function exitProcess() { function getProjectFiles(file) { if (fs.existsSync(file)) { return JSON.parse(fs.readFileSync(file, "utf8")); - } else { - return { dirs: [], generated: [] }; } + return { dirs: [], generated: [] }; } /** @@ -189,7 +192,7 @@ function watch(args) { const sourcedirs = path.join("lib", "bs", ".sourcedirs.json"); - var LAST_SUCCESS_BUILD_STAMP = 0; + let LAST_SUCCESS_BUILD_STAMP = 0; let LAST_BUILD_START = 0; let LAST_FIRED_EVENT = 0; @@ -211,20 +214,20 @@ function watch(args) { const verbose = args.includes("-verbose"); const dlog = verbose ? console.log : () => {}; - var wsParamIndex = args.indexOf("-ws"); + const wsParamIndex = args.indexOf("-ws"); if (wsParamIndex > -1) { - var hostAndPortNumber = (args[wsParamIndex + 1] || "").split(":"); + const hostAndPortNumber = (args[wsParamIndex + 1] || "").split(":"); /** * @type {number} */ - var portNumber; + let portNumber; if (hostAndPortNumber.length === 1) { - portNumber = parseInt(hostAndPortNumber[0]); + portNumber = Number.parseInt(hostAndPortNumber[0]); } else { webSocketHost = hostAndPortNumber[0]; - portNumber = parseInt(hostAndPortNumber[1]); + portNumber = Number.parseInt(hostAndPortNumber[1]); } - if (!isNaN(portNumber)) { + if (!Number.isNaN(portNumber)) { webSocketPort = portNumber; } withWebSocket = true; @@ -237,35 +240,35 @@ function watch(args) { function notifyClients() { wsClients = wsClients.filter(x => !x.closed && !x.socket.destroyed); - var wsClientsLen = wsClients.length; + const wsClientsLen = wsClients.length; dlog(`Alive sockets number: ${wsClientsLen}`); - var data = '{"LAST_SUCCESS_BUILD_STAMP":' + LAST_SUCCESS_BUILD_STAMP + "}"; - for (var i = 0; i < wsClientsLen; ++i) { + const data = { LAST_SUCCESS_BUILD_STAMP }; + for (let i = 0; i < wsClientsLen; ++i) { // in reverse order, the last pushed get notified earlier - var client = wsClients[wsClientsLen - i - 1]; + const client = wsClients[wsClientsLen - i - 1]; if (!client.closed) { - client.sendText(data); + client.sendText(JSON.stringify(data)); } } } function setUpWebSocket() { - var WebSocket = require("../lib/minisocket.js").MiniWebSocket; - var id = setInterval(notifyClients, 3000); - require("http") + const WebSocket = require("../lib/minisocket.js").MiniWebSocket; + const id = setInterval(notifyClients, 3000); + require("node:http") .createServer() - .on("upgrade", function (req, socket, upgradeHead) { + .on("upgrade", (req, socket, upgradeHead) => { dlog("connection opened"); - var ws = new WebSocket(req, socket, upgradeHead); - socket.on("error", function (err) { + const ws = new WebSocket(req, socket, upgradeHead); + socket.on("error", err => { dlog(`Socket Error ${err}`); }); wsClients.push(ws); }) - .on("error", function (err) { + .on("error", err => { // @ts-ignore if (err !== undefined && err.code === "EADDRINUSE") { - var error = isTtyStd ? `\x1b[1;31mERROR:\x1b[0m` : `ERROR:`; + const error = isTtyStd ? "\x1b[1;31mERROR:\x1b[0m" : "ERROR:"; console.error(`${error} The websocket port number ${webSocketPort} is in use. Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); } else { @@ -280,35 +283,30 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); * @param {ProjectFiles} projectFiles */ function watchBuild(projectFiles) { - var watchFiles = projectFiles.dirs; + const watchFiles = projectFiles.dirs; watchGenerated = projectFiles.generated; // close and remove all unused watchers - watchers = watchers.filter(function (watcher) { + watchers = watchers.filter(watcher => { if (watcher.dir === resConfig) { return true; - } else if (watchFiles.indexOf(watcher.dir) < 0) { + } + if (watchFiles.indexOf(watcher.dir) < 0) { dlog(`${watcher.dir} is no longer watched`); watcher.watcher.close(); return false; - } else { - return true; } + return true; }); // adding new watchers - for (var i = 0; i < watchFiles.length; ++i) { - var dir = watchFiles[i]; - if ( - !watchers.find(function (watcher) { - return watcher.dir === dir; - }) - ) { - dlog(`watching dir ${dir} now`); - var watcher = fs.watch(dir, onChange); - watchers.push({ dir: dir, watcher: watcher }); - } else { - // console.log(dir, 'already watched') + for (const dir of watchFiles) { + if (watchers.find(watcher => watcher.dir === dir)) { + // already watched + continue; } + dlog(`watching dir ${dir} now`); + const watcher = fs.watch(dir, onChange); + watchers.push({ dir: dir, watcher: watcher }); } } @@ -360,7 +358,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); function outputError(error, highlight) { if (isTtyError && highlight) { process.stderr.write( - error.replace(highlight, "\x1b[1;31m" + highlight + "\x1b[0m"), + error.replace(highlight, `\x1b[1;31m${highlight}\x1b[0m`), ); } else { process.stderr.write(error); @@ -379,21 +377,18 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); if (reasonsToRebuild.length === 0) { dlog("No need to rebuild"); return; - } else { - dlog(`Rebuilding since ${reasonsToRebuild}`); } - let p; - if ( - (p = acquireBuild(rescriptWatchBuildArgs, { - stdio: ["inherit", "inherit", "pipe"], - })) - ) { + dlog(`Rebuilding since ${reasonsToRebuild}`); + const p = acquireBuild(rescriptWatchBuildArgs, { + stdio: ["inherit", "inherit", "pipe"], + }); + if (p) { logStartCompiling(); - p.on("data", function (s) { + p.on("data", s => { outputError(s, "ninja: error"); }) .once("exit", buildFinishedCallback) - .stderr.setEncoding("utf8"); + .stderr?.setEncoding("utf8"); // This is important to clean up all // previous queued events reasonsToRebuild = []; @@ -407,7 +402,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); dlog( `Acquire lock failed, do the build later ${depth} : ${reasonsToRebuild}`, ); - const waitTime = Math.pow(2, depth) * 40; + const waitTime = 2 ** depth * 40; setTimeout(() => { build(Math.min(depth + 1, 5)); }, waitTime); @@ -420,9 +415,9 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); * @param {string | null} reason */ function onChange(event, reason) { - var eventTime = Date.now(); - var timeDiff = eventTime - LAST_BUILD_START; - var eventDiff = eventTime - LAST_FIRED_EVENT; + const eventTime = Date.now(); + const timeDiff = eventTime - LAST_BUILD_START; + const eventDiff = eventTime - LAST_FIRED_EVENT; dlog(`Since last build: ${timeDiff} -- ${eventDiff}`); if (timeDiff < 5 || eventDiff < 5) { // for 5ms, we could think that the ninja not get diff --git a/cli/rescript_dump.js b/cli/rescript_dump.js index 0aa46d4b44..5bf717f175 100644 --- a/cli/rescript_dump.js +++ b/cli/rescript_dump.js @@ -1,14 +1,16 @@ -//@ts-check -var arg = require("./rescript_arg.js"); -var dump_usage = `Usage: rescript dump [target] +// @ts-check + +const arg = require("./rescript_arg.js"); +const dump_usage = `Usage: rescript dump [target] \`rescript dump\` dumps the information for the target `; -var child_process = require("child_process"); -var path = require("path"); +const child_process = require("node:child_process"); +const path = require("node:path"); + /** * @type {arg.specs} */ -var specs = []; +const specs = []; /** * @param {string[]} argv @@ -16,7 +18,7 @@ var specs = []; * @param {string} bsc_exe */ function main(argv, rescript_exe, bsc_exe) { - var target; + let target; arg.parse_exn(dump_usage, argv, specs, xs => { if (xs.length !== 1) { arg.bad_arg(`Expect only one target, ${xs.length} found`); @@ -24,13 +26,13 @@ function main(argv, rescript_exe, bsc_exe) { target = xs[0]; }); - var { ext } = path.parse(target); + const { ext } = path.parse(target); if (ext !== ".cmi") { console.error("Only .cmi target allowed"); process.exit(2); } - var output = child_process.spawnSync(rescript_exe, ["build", "--", target], { + let output = child_process.spawnSync(rescript_exe, ["build", "--", target], { encoding: "utf-8", }); if (output.status !== 0) { diff --git a/cli/rescript_format.js b/cli/rescript_format.js index 51037f2580..dbd378fae5 100644 --- a/cli/rescript_format.js +++ b/cli/rescript_format.js @@ -1,34 +1,35 @@ //@ts-check -var arg = require("./rescript_arg.js"); -var format_usage = `Usage: rescript format [files] +const arg = require("./rescript_arg.js"); +const format_usage = `Usage: rescript format [files] \`rescript format\` formats the current directory `; -var child_process = require("child_process"); -var util = require("util"); -var asyncExecFile = util.promisify(child_process.execFile); -var path = require("path"); -var fs = require("fs"); -var asyncFs = fs.promises; +const child_process = require("node:child_process"); +const util = require("node:util"); +const asyncExecFile = util.promisify(child_process.execFile); +const path = require("node:path"); +const fs = require("node:fs"); +const asyncFs = fs.promises; + /** * @type {arg.stringref} */ -var stdin = { val: undefined }; +const stdin = { val: "" }; /** * @type {arg.boolref} */ -var format = { val: undefined }; +const format = { val: false }; /** * @type {arg.boolref} */ -var check = { val: undefined }; +const check = { val: false }; /** * @type{arg.specs} */ -var specs = [ +const specs = [ [ "-stdin", { kind: "String", data: { kind: "String_set", data: stdin } }, @@ -46,8 +47,8 @@ the formatted code to stdout in ReScript syntax`, "Check formatting for file or the whole project. Use `-all` to check the whole project", ], ]; -var formattedStdExtensions = [".res", ".resi"]; -var formattedFileExtensions = [".res", ".resi"]; +const formattedStdExtensions = [".res", ".resi"]; +const formattedFileExtensions = [".res", ".resi"]; /** * @@ -57,11 +58,11 @@ function hasExtension(extensions) { /** * @param {string} x */ - var pred = x => extensions.some(ext => x.endsWith(ext)); + const pred = x => extensions.some(ext => x.endsWith(ext)); return pred; } async function readStdin() { - var stream = process.stdin; + const stream = process.stdin; const chunks = []; for await (const chunk of stream) chunks.push(chunk); return Buffer.concat(chunks).toString("utf8"); @@ -74,7 +75,7 @@ async function readStdin() { * @param {boolean} checkFormatting */ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { - var incorrectlyFormattedFiles = 0; + let incorrectlyFormattedFiles = 0; try { const _promises = await Promise.all( files.map(async file => { @@ -85,7 +86,7 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { const { stdout } = await asyncExecFile(bsc_exe, flags); if (check.val) { const original = await asyncFs.readFile(file, "utf-8"); - if (original != stdout) { + if (original !== stdout) { console.error("[format check]", file); incorrectlyFormattedFiles++; } @@ -99,7 +100,7 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { process.exit(2); } if (incorrectlyFormattedFiles > 0) { - if (incorrectlyFormattedFiles == 1) { + if (incorrectlyFormattedFiles === 1) { console.error("The file listed above needs formatting"); } else { console.error( @@ -116,24 +117,24 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { * @param {string} bsc_exe */ async function main(argv, rescript_exe, bsc_exe) { - var isSupportedFile = hasExtension(formattedFileExtensions); - var isSupportedStd = hasExtension(formattedStdExtensions); + const isSupportedFile = hasExtension(formattedFileExtensions); + const isSupportedStd = hasExtension(formattedStdExtensions); try { /** * @type {string[]} */ - var files = []; + let files = []; arg.parse_exn(format_usage, argv, specs, xs => { files = xs; }); - var format_project = format.val; - var use_stdin = stdin.val; + const format_project = format.val; + const use_stdin = stdin.val; // Only -check arg // Require: -all or path to a file - if (check.val && !format_project && files.length == 0) { + if (check.val && !format_project && files.length === 0) { console.error( "format check require path to a file or use `-all` to check the whole project", ); @@ -147,7 +148,7 @@ async function main(argv, rescript_exe, bsc_exe) { } // -all // TODO: check the rest arguments - var output = child_process.spawnSync( + const output = child_process.spawnSync( rescript_exe, ["info", "-list-files"], { @@ -167,17 +168,15 @@ async function main(argv, rescript_exe, bsc_exe) { process.exit(2); } if (isSupportedStd(use_stdin)) { - var crypto = require("crypto"); - var os = require("os"); - var filename = path.join( + const crypto = require("node:crypto"); + const os = require("node:os"); + const filename = path.join( os.tmpdir(), - "rescript_" + - crypto.randomBytes(8).toString("hex") + - path.parse(use_stdin).base, + `rescript_${crypto.randomBytes(8).toString("hex")}${path.parse(use_stdin).base}`, ); - (async function () { - var content = await readStdin(); - var fd = fs.openSync(filename, "wx", 0o600); // Avoid overwriting existing file + (async () => { + const content = await readStdin(); + const fd = fs.openSync(filename, "wx", 0o600); // Avoid overwriting existing file fs.writeFileSync(fd, content, "utf8"); fs.closeSync(fd); process.addListener("exit", () => fs.unlinkSync(filename)); @@ -206,8 +205,7 @@ async function main(argv, rescript_exe, bsc_exe) { files = fs.readdirSync(process.cwd()).filter(isSupportedFile); } - for (let i = 0; i < files.length; ++i) { - let file = files[i]; + for (const file of files) { if (!isSupportedStd(file)) { console.error(`Don't know what do with ${file}`); console.error(`Supported extensions: ${formattedFileExtensions}`); diff --git a/cli/rescript_postinstall.js b/cli/rescript_postinstall.js index 482d3b7962..dcac75f855 100644 --- a/cli/rescript_postinstall.js +++ b/cli/rescript_postinstall.js @@ -1,6 +1,7 @@ -//@ts-check -const child_process = require("child_process"); -const fs = require("fs"); +// @ts-check + +const child_process = require("node:child_process"); +const fs = require("node:fs"); const { bsc_exe, ninja_exe } = require("./bin_path"); @@ -36,7 +37,7 @@ function checkCompiler() { } } -var ninjaVersion = checkNinja(); -var compilerVersion = checkCompiler(); +const ninjaVersion = checkNinja(); +const compilerVersion = checkCompiler(); console.log(`${compilerVersion} (ninja ${ninjaVersion})`); diff --git a/jscomp/build_tests/build_warn_as_error/input.js b/jscomp/build_tests/build_warn_as_error/input.js index 01e4c30179..9e771b3e80 100644 --- a/jscomp/build_tests/build_warn_as_error/input.js +++ b/jscomp/build_tests/build_warn_as_error/input.js @@ -1,31 +1,31 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var o1 = p.spawnSync(rescript_exe, ["build"], { +const o1 = p.spawnSync(rescript_exe, ["build"], { encoding: "utf8", cwd: __dirname, }); -var first_message = o1.stdout +const first_message = o1.stdout .split("\n") .map(s => s.trim()) - .find(s => s == "Warning number 110"); + .find(s => s === "Warning number 110"); if (!first_message) { assert.fail(o1.stdout); } // Second build using -warn-error +110 -var o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], { +const o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], { encoding: "utf8", cwd: __dirname, }); -var second_message = o2.stdout +const second_message = o2.stdout .split("\n") .map(s => s.trim()) - .find(s => s == "Warning number 110 (configured as error)"); + .find(s => s === "Warning number 110 (configured as error)"); if (!second_message) { assert.fail(o2.stdout); @@ -33,15 +33,15 @@ if (!second_message) { // Third build, without -warn-error +110 // The result should not be a warning as error -var o3 = p.spawnSync(rescript_exe, ["build"], { +const o3 = p.spawnSync(rescript_exe, ["build"], { encoding: "utf8", cwd: __dirname, }); -var third_message = o3.stdout +const third_message = o3.stdout .split("\n") .map(s => s.trim()) - .find(s => s == "Dependency Finished"); + .find(s => s === "Dependency Finished"); if (!third_message) { assert.fail(o3.stdout); diff --git a/jscomp/build_tests/case/input.js b/jscomp/build_tests/case/input.js index 8e5cced399..7ab4b52882 100644 --- a/jscomp/build_tests/case/input.js +++ b/jscomp/build_tests/case/input.js @@ -1,13 +1,13 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); if ( ![ - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/demo vs src/Demo\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/demo vs src/Demo\n", // On linux files are parsed in different order - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/Demo vs src/demo\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/Demo vs src/demo\n", ].includes(o.stderr) ) { assert.fail(o.stderr); diff --git a/jscomp/build_tests/case2/input.js b/jscomp/build_tests/case2/input.js index a4a3245189..15333f9a37 100644 --- a/jscomp/build_tests/case2/input.js +++ b/jscomp/build_tests/case2/input.js @@ -1,13 +1,13 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); if ( ![ - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/X vs src/x\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/X vs src/x\n", // On linux files are parsed in different order - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/x vs src/X\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/x vs src/X\n", ].includes(o.stderr) ) { assert.fail(o.stderr); diff --git a/jscomp/build_tests/case3/input.js b/jscomp/build_tests/case3/input.js index c33330667b..40dc2be6b6 100644 --- a/jscomp/build_tests/case3/input.js +++ b/jscomp/build_tests/case3/input.js @@ -1,14 +1,14 @@ //@ts-check -var p = require("child_process"); -var fs = require("fs"); -var path = require("path"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); p.spawnSync(`${rescript_exe} clean && ${rescript_exe} build`, { encoding: "utf8", cwd: __dirname, }); -var o = fs.readFileSync(path.join(__dirname, "src", "hello.bs.js"), "ascii"); +const o = fs.readFileSync(path.join(__dirname, "src", "hello.bs.js"), "ascii"); assert.ok(/HelloGen\.f/.test(o)); diff --git a/jscomp/build_tests/cli_compile_status/input.js b/jscomp/build_tests/cli_compile_status/input.js index 90f72542c3..9ce6132609 100755 --- a/jscomp/build_tests/cli_compile_status/input.js +++ b/jscomp/build_tests/cli_compile_status/input.js @@ -1,43 +1,37 @@ // @ts-check -const assert = require("assert"); -const child_process = require("child_process"); +const assert = require("node:assert"); +const child_process = require("node:child_process"); // Shows compile time for `rescript build` command -let out = child_process.spawnSync(`../../../rescript`, ["build"], { +let out = child_process.spawnSync("../../../rescript", ["build"], { encoding: "utf8", cwd: __dirname, }); assert.match( out.stdout, - new RegExp(`>>>> Start compiling -Dependency Finished ->>>> Finish compiling \\d+ mseconds`), + />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, ); // Shows compile time for `rescript` command -out = child_process.spawnSync(`../../../rescript`, { +out = child_process.spawnSync("../../../rescript", { encoding: "utf8", cwd: __dirname, }); assert.match( out.stdout, - new RegExp(`>>>> Start compiling -Dependency Finished ->>>> Finish compiling \\d+ mseconds`), + />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, ); // Doesn't show compile time for `rescript build -verbose` command // Because we can't be sure that -verbose is a valid argument // And bsb won't fail with a usage message. // It works this way not only for -verbose, but any other arg, including -h/--help/-help -out = child_process.spawnSync(`../../../rescript`, ["build", "-verbose"], { +out = child_process.spawnSync("../../../rescript", ["build", "-verbose"], { encoding: "utf8", cwd: __dirname, }); assert.match( out.stdout, - new RegExp( - `Package stack: test \nDependency Finished\nninja.exe -C lib/bs \n`, - ), + /Package stack: test {2}\nDependency Finished\nninja.exe -C lib\/bs \n/, ); diff --git a/jscomp/build_tests/cli_help/input.js b/jscomp/build_tests/cli_help/input.js index 8fe5b9b9b4..bc65c6accd 100755 --- a/jscomp/build_tests/cli_help/input.js +++ b/jscomp/build_tests/cli_help/input.js @@ -1,6 +1,6 @@ // @ts-check -const assert = require("assert"); +const assert = require("node:assert"); const { exec } = require("../utils.js"); const cliHelp = @@ -64,7 +64,7 @@ const dumpHelp = async function test() { { // Shows build help with --help arg - const out = await exec(`../../../rescript`, ["build", "--help"], { + const out = await exec("../../../rescript", ["build", "--help"], { cwd: __dirname, }); assert.equal(out.stdout, buildHelp); @@ -73,7 +73,7 @@ async function test() { } { - const out = await exec(`../../../rescript`, ["build", "-w", "--help"], { + const out = await exec("../../../rescript", ["build", "-w", "--help"], { cwd: __dirname, }); assert.equal(out.stdout, buildHelp); @@ -82,7 +82,7 @@ async function test() { } { - const out = await exec(`../../../rescript`, ["-w", "--help"], { + const out = await exec("../../../rescript", ["-w", "--help"], { cwd: __dirname, }); assert.equal(out.stdout, cliHelp); @@ -92,7 +92,7 @@ async function test() { { // Shows cli help with --help arg even if there are invalid arguments after it - const out = await exec(`../../../rescript`, ["--help", "-w"], { + const out = await exec("../../../rescript", ["--help", "-w"], { cwd: __dirname, }); assert.equal(out.stdout, cliHelp); @@ -102,7 +102,7 @@ async function test() { { // Shows build help with -h arg - const out = await exec(`../../../rescript`, ["build", "-h"], { + const out = await exec("../../../rescript", ["build", "-h"], { cwd: __dirname, }); assert.equal(out.stdout, buildHelp); @@ -112,17 +112,17 @@ async function test() { { // Exits with build help with unknown arg - const out = await exec(`../../../rescript`, ["build", "-foo"], { + const out = await exec("../../../rescript", ["build", "-foo"], { cwd: __dirname, }); assert.equal(out.stdout, ""); - assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); + assert.equal(out.stderr, `Error: Unknown option "-foo".\n${buildHelp}`); assert.equal(out.status, 2); } { // Shows cli help with --help arg - const out = await exec(`../../../rescript`, ["--help"], { + const out = await exec("../../../rescript", ["--help"], { cwd: __dirname, }); assert.equal(out.stdout, cliHelp); @@ -132,7 +132,7 @@ async function test() { { // Shows cli help with -h arg - const out = await exec(`../../../rescript`, ["-h"], { + const out = await exec("../../../rescript", ["-h"], { cwd: __dirname, }); assert.equal(out.stdout, cliHelp); @@ -142,7 +142,7 @@ async function test() { { // Shows cli help with -h arg - const out = await exec(`../../../rescript`, ["help"], { + const out = await exec("../../../rescript", ["help"], { cwd: __dirname, }); assert.equal(out.stdout, cliHelp); @@ -152,27 +152,27 @@ async function test() { { // Exits with cli help with unknown command - const out = await exec(`../../../rescript`, ["built"], { + const out = await exec("../../../rescript", ["built"], { cwd: __dirname, }); assert.equal(out.stdout, ""); - assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); + assert.equal(out.stderr, `Error: Unknown command "built".\n${cliHelp}`); assert.equal(out.status, 2); } { // Exits with build help with unknown args - const out = await exec(`../../../rescript`, ["-foo"], { + const out = await exec("../../../rescript", ["-foo"], { cwd: __dirname, }); assert.equal(out.stdout, ""); - assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); + assert.equal(out.stderr, `Error: Unknown option "-foo".\n${buildHelp}`); assert.equal(out.status, 2); } { // Shows clean help with --help arg - const out = await exec(`../../../rescript`, ["clean", "--help"], { + const out = await exec("../../../rescript", ["clean", "--help"], { cwd: __dirname, }); assert.equal(out.stdout, cleanHelp); @@ -182,7 +182,7 @@ async function test() { { // Shows clean help with -h arg - const out = await exec(`../../../rescript`, ["clean", "-h"], { + const out = await exec("../../../rescript", ["clean", "-h"], { cwd: __dirname, }); assert.equal(out.stdout, cleanHelp); @@ -192,17 +192,17 @@ async function test() { { // Exits with clean help with unknown arg - const out = await exec(`../../../rescript`, ["clean", "-foo"], { + const out = await exec("../../../rescript", ["clean", "-foo"], { cwd: __dirname, }); assert.equal(out.stdout, ""); - assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); + assert.equal(out.stderr, `Error: Unknown option "-foo".\n${cleanHelp}`); assert.equal(out.status, 2); } { // Shows format help with --help arg - const out = await exec(`../../../rescript`, ["format", "--help"], { + const out = await exec("../../../rescript", ["format", "--help"], { cwd: __dirname, }); assert.equal(out.stdout, formatHelp); @@ -212,7 +212,7 @@ async function test() { { // Shows format help with -h arg - const out = await exec(`../../../rescript`, ["format", "-h"], { + const out = await exec("../../../rescript", ["format", "-h"], { cwd: __dirname, }); assert.equal(out.stdout, formatHelp); @@ -222,7 +222,7 @@ async function test() { { // Shows dump help with --help arg - const out = await exec(`../../../rescript`, ["dump", "--help"], { + const out = await exec("../../../rescript", ["dump", "--help"], { cwd: __dirname, }); assert.equal(out.stdout, dumpHelp); @@ -232,7 +232,7 @@ async function test() { { // Shows dump help with -h arg - const out = await exec(`../../../rescript`, ["dump", "-h"], { + const out = await exec("../../../rescript", ["dump", "-h"], { cwd: __dirname, }); assert.equal(out.stdout, dumpHelp); diff --git a/jscomp/build_tests/custom_namespace/input.js b/jscomp/build_tests/custom_namespace/input.js index e4502cb0c4..6e113560da 100644 --- a/jscomp/build_tests/custom_namespace/input.js +++ b/jscomp/build_tests/custom_namespace/input.js @@ -1,10 +1,10 @@ -var child_process = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); child_process.execSync(`${rescript_exe} clean && ${rescript_exe} build`, { cwd: __dirname, }); -var x = require("./src/demo.bs.js"); +const x = require("./src/demo.bs.js"); assert.equal(x.v, 42); diff --git a/jscomp/build_tests/cycle/input.js b/jscomp/build_tests/cycle/input.js index d94a234e49..fc4f9892ee 100644 --- a/jscomp/build_tests/cycle/input.js +++ b/jscomp/build_tests/cycle/input.js @@ -1,14 +1,14 @@ //@ts-check -const cp = require("child_process"); -const assert = require("assert"); -const fs = require("fs"); -const path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); -var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); +const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); assert(/dependency cycle/.test(output.stdout)); -var compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -var compilerLog = fs.readFileSync(compilerLogFile, "utf8"); +const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); +const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); assert(/dependency cycle/.test(compilerLog)); diff --git a/jscomp/build_tests/cycle1/input.js b/jscomp/build_tests/cycle1/input.js index 1894a6c1a8..b9123e7fa3 100644 --- a/jscomp/build_tests/cycle1/input.js +++ b/jscomp/build_tests/cycle1/input.js @@ -1,16 +1,16 @@ //@ts-check -const cp = require("child_process"); -const assert = require("assert"); -const fs = require("fs"); -const path = require("path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); const { rescript_exe } = require("#cli/bin_path"); cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); -var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); +const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); assert(/is dangling/.test(output.stdout)); -var compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -var compilerLog = fs.readFileSync(compilerLogFile, "utf8"); +const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); +const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); assert(/is dangling/.test(compilerLog)); diff --git a/jscomp/build_tests/deprecated-package-specs/input.js b/jscomp/build_tests/deprecated-package-specs/input.js index 7a7769861d..d403bda1f6 100644 --- a/jscomp/build_tests/deprecated-package-specs/input.js +++ b/jscomp/build_tests/deprecated-package-specs/input.js @@ -1,5 +1,5 @@ -const child_process = require("child_process"); -const assert = require("assert"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); const { rescript_exe } = require("#cli/bin_path"); const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); diff --git a/jscomp/build_tests/devonly/input.js b/jscomp/build_tests/devonly/input.js index 2aec9809b2..c1304efb8e 100644 --- a/jscomp/build_tests/devonly/input.js +++ b/jscomp/build_tests/devonly/input.js @@ -1,5 +1,5 @@ //@ts-check -var cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" }); diff --git a/jscomp/build_tests/duplicated_symlinked_packages/input.js b/jscomp/build_tests/duplicated_symlinked_packages/input.js index b4f70bfd6a..fbd72fab4f 100644 --- a/jscomp/build_tests/duplicated_symlinked_packages/input.js +++ b/jscomp/build_tests/duplicated_symlinked_packages/input.js @@ -1,16 +1,18 @@ -const fs = require("fs"); -const path = require("path"); -const child_process = require("child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const child_process = require("node:child_process"); const { rescript_exe } = require("#cli/bin_path"); const expectedFilePath = path.join(__dirname, "out.expected"); const updateTests = process.argv[2] === "update"; +/** + * @param {string} output + * @return {string} + */ function postProcessErrorOutput(output) { - output = output.trimRight(); - output = output.replace(new RegExp(__dirname, "gi"), "."); - return output; + return output.trimEnd().replace(new RegExp(__dirname, "gi"), "."); } child_process.execSync(`${rescript_exe} clean`, { cwd: __dirname }); child_process.exec(rescript_exe, { cwd: __dirname }, (err, stdout, stderr) => { diff --git a/jscomp/build_tests/exports/input.js b/jscomp/build_tests/exports/input.js index 76ead396b3..596c5522a0 100644 --- a/jscomp/build_tests/exports/input.js +++ b/jscomp/build_tests/exports/input.js @@ -1,5 +1,5 @@ -var child_process = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); child_process.execSync(rescript_exe, { cwd: __dirname, diff --git a/jscomp/build_tests/hyphen2/input.js b/jscomp/build_tests/hyphen2/input.js index 84c35bb893..4e568e556e 100644 --- a/jscomp/build_tests/hyphen2/input.js +++ b/jscomp/build_tests/hyphen2/input.js @@ -1,4 +1,4 @@ -var p = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe, { cwd: __dirname }); diff --git a/jscomp/build_tests/in_source/input.js b/jscomp/build_tests/in_source/input.js index 533a61a521..d25402fbe9 100644 --- a/jscomp/build_tests/in_source/input.js +++ b/jscomp/build_tests/in_source/input.js @@ -1,24 +1,19 @@ -var child_process = require("child_process"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); -var assert = require("assert"); - -var { rescript_exe } = require("#cli/bin_path"); +const { rescript_exe } = require("#cli/bin_path"); assert.throws( () => { - var output = child_process.execSync(`${rescript_exe} build -regen`, { + const output = child_process.execSync(`${rescript_exe} build -regen`, { cwd: __dirname, encoding: "utf8", }); }, - function (err) { + err => { if (err.message.match(/detected two module formats/)) { return true; } return false; }, ); - -// assert.throws(()=>{ -// throw new Error('Wrong value') -// }, /x/) diff --git a/jscomp/build_tests/install/input.js b/jscomp/build_tests/install/input.js index 407e1f9558..4d720c5892 100644 --- a/jscomp/build_tests/install/input.js +++ b/jscomp/build_tests/install/input.js @@ -1,26 +1,26 @@ -var p = require("child_process"); -var fs = require("fs"); -var path = require("path"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -p.spawnSync(rescript_exe, [`clean`], { +p.spawnSync(rescript_exe, ["clean"], { encoding: "utf8", cwd: __dirname, }); -p.spawnSync(rescript_exe, [`build`, `-install`], { +p.spawnSync(rescript_exe, ["build", "-install"], { encoding: "utf8", cwd: __dirname, }); -var fooExists = fs.existsSync(path.join(__dirname, "lib", "ocaml", "Foo.cmi")); -assert.ok(fooExists == false); +let fooExists = fs.existsSync(path.join(__dirname, "lib", "ocaml", "Foo.cmi")); +assert.ok(fooExists === false); p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname, }); -p.spawnSync(rescript_exe, [`build`, `-install`], { +p.spawnSync(rescript_exe, ["build", "-install"], { encoding: "utf8", cwd: __dirname, }); diff --git a/jscomp/build_tests/nested/input.js b/jscomp/build_tests/nested/input.js index a56e24f14e..0e7135a212 100644 --- a/jscomp/build_tests/nested/input.js +++ b/jscomp/build_tests/nested/input.js @@ -1,11 +1,11 @@ -var p = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe, { cwd: __dirname }); -var content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); +const content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); assert.ok(content.match(/A00_a1_main/g).length === 3); assert.ok(content.match(/B00_b1_main/g).length === 3); diff --git a/jscomp/build_tests/nnest/input.js b/jscomp/build_tests/nnest/input.js index e3ad473862..d9de24ac45 100644 --- a/jscomp/build_tests/nnest/input.js +++ b/jscomp/build_tests/nnest/input.js @@ -1,13 +1,13 @@ // @ts-check -var p = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe, { cwd: __dirname }); -var content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); +const content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); assert.ok(content.match(/A0_a1_main/g).length === 3); assert.ok(content.match(/B0_b1_main/g).length === 3); diff --git a/jscomp/build_tests/ns/input.js b/jscomp/build_tests/ns/input.js index 55e41645da..1c14e98e41 100755 --- a/jscomp/build_tests/ns/input.js +++ b/jscomp/build_tests/ns/input.js @@ -1,4 +1,4 @@ -var child_process = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); child_process.execSync(rescript_exe, { cwd: __dirname }); diff --git a/jscomp/build_tests/post-build/input.js b/jscomp/build_tests/post-build/input.js index 9cb97455d0..e6485eb835 100644 --- a/jscomp/build_tests/post-build/input.js +++ b/jscomp/build_tests/post-build/input.js @@ -1,8 +1,8 @@ -var child_process = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.status !== 0) { assert.fail(out.stdout + out.stderr); diff --git a/jscomp/build_tests/react_ppx/input.js b/jscomp/build_tests/react_ppx/input.js index 96e9ab8353..8cfd468c7a 100644 --- a/jscomp/build_tests/react_ppx/input.js +++ b/jscomp/build_tests/react_ppx/input.js @@ -1,5 +1,5 @@ //@ts-check -var cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(rescript_exe, { cwd: __dirname }); diff --git a/jscomp/build_tests/rerror/input.js b/jscomp/build_tests/rerror/input.js index 18276be1cc..7bd64b308c 100644 --- a/jscomp/build_tests/rerror/input.js +++ b/jscomp/build_tests/rerror/input.js @@ -1,27 +1,27 @@ -var child_process = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); child_process.spawnSync(`${rescript_exe} clean`, { cwd: __dirname, encoding: "utf8", }); -var o = child_process.spawnSync(rescript_exe, { +const o = child_process.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", shell: true, }); // verify the output is in reason syntax -var u = o.stdout.match(/=>/g); +const u = o.stdout.match(/=>/g); -var lines = o.stdout +const lines = o.stdout .split("\n") .map(x => x.trim()) .filter(Boolean); // console.log(`lines: \n${lines}`) // console.log(lines[4]) -var test = false; -for (var i = 0; i < lines.length; ++i) { +let test = false; +for (let i = 0; i < lines.length; ++i) { if (lines[i] === "We've found a bug for you!") { console.log(`line ${i} found`); assert.ok(/src\/demo.res:1:21-23/.test(lines[i + 1])); diff --git a/jscomp/build_tests/scoped_ppx/input.js b/jscomp/build_tests/scoped_ppx/input.js index 57815a9ef1..c9d109743b 100644 --- a/jscomp/build_tests/scoped_ppx/input.js +++ b/jscomp/build_tests/scoped_ppx/input.js @@ -1,12 +1,15 @@ -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" }); -var output = cp.execSync(`${rescript_exe} build -- -t commands src/hello.ast`, { - cwd: __dirname, - encoding: "utf8", -}); +const output = cp.execSync( + `${rescript_exe} build -- -t commands src/hello.ast`, + { + cwd: __dirname, + encoding: "utf8", + }, +); assert( /-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/.test( output, diff --git a/jscomp/build_tests/super_errors/input.js b/jscomp/build_tests/super_errors/input.js index d6bf82eb3a..f4c364047a 100644 --- a/jscomp/build_tests/super_errors/input.js +++ b/jscomp/build_tests/super_errors/input.js @@ -1,6 +1,6 @@ -const fs = require("fs"); -const path = require("path"); -const child_process = require("child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const child_process = require("node:child_process"); const { bsc_exe: bsc } = require("#cli/bin_path"); @@ -15,19 +15,20 @@ const prefix = `${bsc} -w +A`; const updateTests = process.argv[2] === "update"; +/** + * @param {string} output + * @return {string} + */ function postProcessErrorOutput(output) { - output = output.trimRight(); - output = output.replace( - /\/[^ ]+?jscomp\/build_tests\/super_errors\//g, - "/.../", - ); - return output; + return output + .trimEnd() + .replace(/\/[^ ]+?jscomp\/build_tests\/super_errors\//g, "/.../"); } let doneTasksCount = 0; let atLeastOneTaskFailed = false; -fixtures.forEach(fileName => { +for (const fileName of fixtures) { const fullFilePath = path.join(__dirname, "fixtures", fileName); const command = `${prefix} -color always ${fullFilePath}`; console.log(`running ${command}`); @@ -38,7 +39,7 @@ fixtures.forEach(fileName => { // - accidentally succeeding tests (not likely in this context), // actual, correctly erroring test case const actualErrorOutput = postProcessErrorOutput(stderr.toString()); - const expectedFilePath = path.join(expectedDir, fileName + ".expected"); + const expectedFilePath = path.join(expectedDir, `${fileName}.expected`); if (updateTests) { fs.writeFileSync(expectedFilePath, actualErrorOutput); } else { @@ -61,4 +62,4 @@ fixtures.forEach(fileName => { } } }); -}); +} diff --git a/jscomp/build_tests/transitive_pinned_dependency1/input.js b/jscomp/build_tests/transitive_pinned_dependency1/input.js index 565410ca01..dfba1b2c3d 100644 --- a/jscomp/build_tests/transitive_pinned_dependency1/input.js +++ b/jscomp/build_tests/transitive_pinned_dependency1/input.js @@ -1,8 +1,8 @@ //@ts-check -var child_process = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const { rescript_exe } = require("#cli/bin_path"); console.log( child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), diff --git a/jscomp/build_tests/transitive_pinned_dependency2/input.js b/jscomp/build_tests/transitive_pinned_dependency2/input.js index aa9c501afc..879e701f81 100644 --- a/jscomp/build_tests/transitive_pinned_dependency2/input.js +++ b/jscomp/build_tests/transitive_pinned_dependency2/input.js @@ -1,8 +1,8 @@ //@ts-check -var child_process = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const { rescript_exe } = require("#cli/bin_path"); console.log( child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), diff --git a/jscomp/build_tests/unboxed_bool_with_const/input.js b/jscomp/build_tests/unboxed_bool_with_const/input.js index 2f5c856668..483d90dcb8 100644 --- a/jscomp/build_tests/unboxed_bool_with_const/input.js +++ b/jscomp/build_tests/unboxed_bool_with_const/input.js @@ -1,10 +1,10 @@ //@ts-check -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { +const out = cp.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", }); diff --git a/jscomp/build_tests/uncurried-always/input.js b/jscomp/build_tests/uncurried-always/input.js index a7370b0c2f..4d511dcd41 100644 --- a/jscomp/build_tests/uncurried-always/input.js +++ b/jscomp/build_tests/uncurried-always/input.js @@ -1,6 +1,6 @@ //@ts-check -const cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); cp.execSync(`${rescript_exe}`, { cwd: __dirname }); diff --git a/jscomp/build_tests/unicode/input.js b/jscomp/build_tests/unicode/input.js index 9208b96e34..e32a89f0b0 100644 --- a/jscomp/build_tests/unicode/input.js +++ b/jscomp/build_tests/unicode/input.js @@ -1,14 +1,13 @@ //@ts-check -var child_process = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); console.log(child_process.execSync(rescript_exe, { encoding: "utf8" })); -var fs = require("fs"); -var path = require("path"); -var content = - "" + fs.readFileSync(path.join(__dirname, "lib", "bs", ".sourcedirs.json")); +const fs = require("node:fs"); +const path = require("node:path"); +const content = `${fs.readFileSync(path.join(__dirname, "lib", "bs", ".sourcedirs.json"))}`; -var assert = require("assert"); +const assert = require("node:assert"); assert(JSON.parse(content).dirs.some(x => x.includes("📕annotation"))); diff --git a/jscomp/build_tests/utils.js b/jscomp/build_tests/utils.js index ac97290156..893729b142 100644 --- a/jscomp/build_tests/utils.js +++ b/jscomp/build_tests/utils.js @@ -1,4 +1,4 @@ -const child_process = require("child_process"); +const child_process = require("node:child_process"); const signals = { SIGINT: 2, diff --git a/jscomp/build_tests/warn_legacy_config/input.js b/jscomp/build_tests/warn_legacy_config/input.js index 6a273a047f..b37c60cc07 100644 --- a/jscomp/build_tests/warn_legacy_config/input.js +++ b/jscomp/build_tests/warn_legacy_config/input.js @@ -1,5 +1,5 @@ -const { spawnSync } = require("child_process"); -const assert = require("assert"); +const { spawnSync } = require("node:child_process"); +const assert = require("node:assert"); const { rescript_exe } = require("#cli/bin_path"); const output = spawnSync(rescript_exe, { encoding: "utf8" }); diff --git a/jscomp/build_tests/weird_deps/input.js b/jscomp/build_tests/weird_deps/input.js index 30d0fdd927..fba7fea540 100644 --- a/jscomp/build_tests/weird_deps/input.js +++ b/jscomp/build_tests/weird_deps/input.js @@ -1,10 +1,10 @@ //@ts-check -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { +const out = cp.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", }); diff --git a/jscomp/build_tests/weird_devdeps/input.js b/jscomp/build_tests/weird_devdeps/input.js index 892b4bdf37..e0a4315b70 100644 --- a/jscomp/build_tests/weird_devdeps/input.js +++ b/jscomp/build_tests/weird_devdeps/input.js @@ -1,10 +1,10 @@ //@ts-check -var cp = require("child_process"); -var assert = require("assert"); -var rescript_exe = require("#cli/bin_path").rescript_exe; +const cp = require("node:child_process"); +const assert = require("node:assert"); +const rescript_exe = require("#cli/bin_path").rescript_exe; -var out = cp.spawnSync(rescript_exe, { +const out = cp.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", }); diff --git a/jscomp/build_tests/weird_names/input.js b/jscomp/build_tests/weird_names/input.js index c8e27d5371..5e0d591d88 100644 --- a/jscomp/build_tests/weird_names/input.js +++ b/jscomp/build_tests/weird_names/input.js @@ -1,15 +1,15 @@ -var cp = require("child_process"); -var assert = require("assert"); -var path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.stderr !== "") { assert.fail(out.stderr); } -let files = [ +const files = [ "_app.res", "[...params_max_3].res", "[...params].res", @@ -19,8 +19,8 @@ let files = [ "utils.test.res", ]; -for (let f of files) { - let { name } = path.parse(f); - let m = `./lib/js/src/${name}.js`; +for (const f of files) { + const { name } = path.parse(f); + const m = `./lib/js/src/${name}.js`; assert.deepEqual(require(m).a, 1); } diff --git a/jscomp/build_tests/weird_names_not_found_bug/input.js b/jscomp/build_tests/weird_names_not_found_bug/input.js index 3bb70620c5..8582cc0bde 100644 --- a/jscomp/build_tests/weird_names_not_found_bug/input.js +++ b/jscomp/build_tests/weird_names_not_found_bug/input.js @@ -1,8 +1,8 @@ -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.stderr !== "") { assert.fail(out.stderr); } diff --git a/jscomp/build_tests/x-y/input.js b/jscomp/build_tests/x-y/input.js index 1b2ea568cb..6d8c53998c 100644 --- a/jscomp/build_tests/x-y/input.js +++ b/jscomp/build_tests/x-y/input.js @@ -1,4 +1,4 @@ -var p = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe); diff --git a/jscomp/build_tests/xpkg/input.js b/jscomp/build_tests/xpkg/input.js index d499746478..e68c3a87db 100644 --- a/jscomp/build_tests/xpkg/input.js +++ b/jscomp/build_tests/xpkg/input.js @@ -1,8 +1,8 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); try { - var output = p.spawnSync(`${rescript_exe} build -regen`, { + const output = p.spawnSync(`${rescript_exe} build -regen`, { shell: true, encoding: "utf8", }); diff --git a/jscomp/build_tests/zerocycle/input.js b/jscomp/build_tests/zerocycle/input.js index aa23bdbc08..cfa9e940d8 100644 --- a/jscomp/build_tests/zerocycle/input.js +++ b/jscomp/build_tests/zerocycle/input.js @@ -1,5 +1,5 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var out = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); -assert(out.status == 0); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const out = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +assert(out.status === 0); diff --git a/jscomp/gentype_tests/typescript-react-example/biome.json b/jscomp/gentype_tests/typescript-react-example/biome.json index d9c8975046..0339ee3a61 100644 --- a/jscomp/gentype_tests/typescript-react-example/biome.json +++ b/jscomp/gentype_tests/typescript-react-example/biome.json @@ -2,10 +2,12 @@ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", "extends": ["../../../biome.json"], "linter": { - "enabled": true, - "rules": { - "recommended": true - }, + "ignore": ["**/*.res.js", "**/*.gen.ts*"] + }, + "organizeImports": { + "ignore": ["**/*.res.js", "**/*.gen.ts*"] + }, + "formatter": { "ignore": ["**/*.res.js", "**/*.gen.ts*"] } } diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index 8c8e8bd159..8235b7eb1b 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -35,8 +35,10 @@ "devDependencies": { "@biomejs/biome": "1.8.3", "@types/node": "^20.14.9", + "@types/semver": "^7.5.8", "mocha": "10.1.0", "nyc": "15.0.0", + "semver": "7.6.2", "typescript": "5.5.3" }, "engines": { diff --git a/jscomp/gentype_tests/typescript-react-example/src/index.tsx b/jscomp/gentype_tests/typescript-react-example/src/index.tsx index 5984d48e6b..18384cf167 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/index.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/index.tsx @@ -4,13 +4,13 @@ import App from "./App"; import * as ImportJsValue from "./ImportJsValue.gen"; import * as Uncurried from "./Uncurried.gen"; import "./index.css"; +import * as DocStrings from "./Docstrings.gen"; +import Hooks from "./Hooks.gen"; import * as MyMath from "./MyMath"; -import * as Types from "./nested/Types.gen"; import { Universe_Nested2_Nested3_nested3Value } from "./NestedModules.gen"; import * as Records from "./Records.gen"; +import * as TestPromise from "./TestPromise.gen"; import * as Variants from "./Variants.gen"; -import Hooks from "./Hooks.gen"; -import * as DocStrings from "./Docstrings.gen"; import { printManyPayloads, printVariantWithPayload, @@ -19,7 +19,7 @@ import { testVariantWithPayloads, testWithPayload, } from "./VariantsWithPayload.gen"; -import * as TestPromise from "./TestPromise.gen"; +import * as Types from "./nested/Types.gen"; const consoleLog = console.log; diff --git a/jscomp/others/release.ninja b/jscomp/others/release.ninja index 691a688422..691e6c95fb 100644 --- a/jscomp/others/release.ninja +++ b/jscomp/others/release.ninja @@ -69,17 +69,17 @@ o others/belt_Array.cmj : cc_cmi others/belt_Array.res | others/belt.cmi others/ o others/belt_Array.cmi : cc others/belt_Array.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_Float.cmj : cc_cmi others/belt_Float.res | others/belt.cmi others/belt_Float.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_Float.cmi : cc others/belt_Float.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashMap.cmj : cc_cmi others/belt_HashMap.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMap.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmj others/belt_Id.cmj others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashMap.cmi : cc others/belt_HashMap.resi | others/belt.cmi others/belt_HashMapInt.cmi others/belt_HashMapString.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashMapInt.cmj : cc_cmi others/belt_HashMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapInt.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashMap.cmj : cc_cmi others/belt_HashMap.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMap.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmj others/belt_Id.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashMap.cmi : cc others/belt_HashMap.resi | others/belt.cmi others/belt_HashMapInt.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmi others/belt_HashMapString.cmj others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashMapInt.cmj : cc_cmi others/belt_HashMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapInt.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_HashMapInt.cmi : cc others/belt_HashMapInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashMapString.cmj : cc_cmi others/belt_HashMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapString.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashMapString.cmj : cc_cmi others/belt_HashMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_HashMapString.cmi : cc others/belt_HashMapString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashSet.cmj : cc_cmi others/belt_HashSet.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSet.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmj others/belt_Id.cmj others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashSet.cmi : cc others/belt_HashSet.resi | others/belt.cmi others/belt_HashSetInt.cmi others/belt_HashSetString.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashSetInt.cmj : cc_cmi others/belt_HashSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetInt.cmi others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashSet.cmj : cc_cmi others/belt_HashSet.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSet.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmj others/belt_Id.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashSet.cmi : cc others/belt_HashSet.resi | others/belt.cmi others/belt_HashSetInt.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashSetInt.cmj : cc_cmi others/belt_HashSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetInt.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_HashSetInt.cmi : cc others/belt_HashSetInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashSetString.cmj : cc_cmi others/belt_HashSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetString.cmi others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_HashSetString.cmj : cc_cmi others/belt_HashSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_HashSetString.cmi : cc others/belt_HashSetString.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_Id.cmj : cc_cmi others/belt_Id.res | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_Id.cmi : cc others/belt_Id.resi | others/belt_internals.cmi others/js.cmi $bsc @@ -89,25 +89,25 @@ o others/belt_List.cmj : cc_cmi others/belt_List.res | others/belt.cmi others/be o others/belt_List.cmi : cc others/belt_List.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_Map.cmj : cc_cmi others/belt_Map.res | others/belt.cmi others/belt_Id.cmj others/belt_Map.cmi others/belt_MapDict.cmj others/belt_MapInt.cmj others/belt_MapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_Map.cmi : cc others/belt_Map.resi | others/belt.cmi others/belt_Id.cmi others/belt_MapDict.cmi others/belt_MapInt.cmi others/belt_MapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapDict.cmj : cc_cmi others/belt_MapDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MapDict.cmi others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MapDict.cmj : cc_cmi others/belt_MapDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MapDict.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MapDict.cmi : cc others/belt_MapDict.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapInt.cmj : cc_cmi others/belt_MapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MapInt.cmi others/belt_internalAVLtree.cmj others/belt_internalMapInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MapInt.cmj : cc_cmi others/belt_MapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MapInt.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MapInt.cmi : cc others/belt_MapInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MapString.cmj : cc_cmi others/belt_MapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MapString.cmi others/belt_internalAVLtree.cmj others/belt_internalMapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MapString.cmj : cc_cmi others/belt_MapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MapString.cmi : cc others/belt_MapString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableMap.cmj : cc_cmi others/belt_MutableMap.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableMap.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmj others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MutableMap.cmj : cc_cmi others/belt_MutableMap.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableMap.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableMap.cmi : cc others/belt_MutableMap.resi | others/belt.cmi others/belt_Id.cmi others/belt_MutableMapInt.cmi others/belt_MutableMapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableMapInt.cmj : cc_cmi others/belt_MutableMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapInt.cmi others/belt_internalAVLtree.cmj others/belt_internalMapInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MutableMapInt.cmj : cc_cmi others/belt_MutableMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapInt.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableMapInt.cmi : cc others/belt_MutableMapInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableMapString.cmj : cc_cmi others/belt_MutableMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapString.cmi others/belt_internalAVLtree.cmj others/belt_internalMapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MutableMapString.cmj : cc_cmi others/belt_MutableMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableMapString.cmi : cc others/belt_MutableMapString.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_MutableQueue.cmj : cc_cmi others/belt_MutableQueue.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableQueue.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableQueue.cmi : cc others/belt_MutableQueue.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_MutableSet.cmj : cc_cmi others/belt_MutableSet.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableSet.cmi others/belt_MutableSetInt.cmj others/belt_MutableSetString.cmj others/belt_SortArray.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableSet.cmi : cc others/belt_MutableSet.resi | others/belt.cmi others/belt_Id.cmi others/belt_MutableSetInt.cmi others/belt_MutableSetString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableSetInt.cmj : cc_cmi others/belt_MutableSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetInt.cmi others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/belt_internalSetInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MutableSetInt.cmj : cc_cmi others/belt_MutableSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetInt.cmi others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableSetInt.cmi : cc others/belt_MutableSetInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableSetString.cmj : cc_cmi others/belt_MutableSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/belt_internalSetString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_MutableSetString.cmj : cc_cmi others/belt_MutableSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableSetString.cmi : cc others/belt_MutableSetString.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_MutableStack.cmj : cc_cmi others/belt_MutableStack.res | others/belt.cmi others/belt_MutableStack.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_MutableStack.cmi : cc others/belt_MutableStack.resi | others/belt_internals.cmi others/js.cmi $bsc @@ -121,9 +121,9 @@ o others/belt_Set.cmj : cc_cmi others/belt_Set.res | others/belt.cmi others/belt o others/belt_Set.cmi : cc others/belt_Set.resi | others/belt.cmi others/belt_Id.cmi others/belt_SetDict.cmi others/belt_SetInt.cmi others/belt_SetString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_SetDict.cmj : cc_cmi others/belt_SetDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SetDict.cmi others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_SetDict.cmi : cc others/belt_SetDict.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SetInt.cmj : cc_cmi others/belt_SetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SetInt.cmi others/belt_internalAVLset.cmj others/belt_internalSetInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_SetInt.cmj : cc_cmi others/belt_SetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SetInt.cmi others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_SetInt.cmi : cc others/belt_SetInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_SetString.cmj : cc_cmi others/belt_SetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SetString.cmi others/belt_internalAVLset.cmj others/belt_internalSetString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_SetString.cmj : cc_cmi others/belt_SetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SetString.cmi others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_SetString.cmi : cc others/belt_SetString.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_SortArray.cmj : cc_cmi others/belt_SortArray.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmi others/belt_SortArrayInt.cmj others/belt_SortArrayString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_SortArray.cmi : cc others/belt_SortArray.resi | others/belt.cmi others/belt_SortArrayInt.cmi others/belt_SortArrayString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg @@ -132,24 +132,24 @@ o others/belt_SortArrayInt.cmi : cc others/belt_SortArrayInt.resi | others/belt_ o others/belt_SortArrayString.cmj : cc_cmi others/belt_SortArrayString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg o others/belt_SortArrayString.cmi : cc others/belt_SortArrayString.resi | others/belt_internals.cmi others/js.cmi $bsc o others/belt_internalAVLset.cmj : cc_cmi others/belt_internalAVLset.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SortArray.cmj others/belt_internalAVLset.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalAVLset.cmi : cc others/belt_internalAVLset.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalAVLtree.cmj : cc_cmi others/belt_internalAVLtree.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalAVLtree.cmi : cc others/belt_internalAVLtree.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBuckets.cmj : cc_cmi others/belt_internalBuckets.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBuckets.cmi others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBuckets.cmi : cc others/belt_internalBuckets.resi | others/belt.cmi others/belt_internalBucketsType.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBucketsType.cmj : cc_cmi others/belt_internalBucketsType.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBucketsType.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg +o others/belt_internalAVLset.cmi : cc others/belt_internalAVLset.resi | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalAVLtree.cmj : cc_cmi others/belt_internalAVLtree.res | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalAVLtree.cmi : cc others/belt_internalAVLtree.resi | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalBuckets.cmj : cc_cmi others/belt_internalBuckets.res | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalBuckets.cmi : cc others/belt_internalBuckets.resi | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalBucketsType.cmj : cc_cmi others/belt_internalBucketsType.res | others/belt_internals.cmi others/js.cmi $bsc o others/belt_internalBucketsType.cmi : cc others/belt_internalBucketsType.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj : cc others/belt_internalMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalMapString.cmi others/belt_internalMapString.cmj : cc others/belt_internalMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetBuckets.cmj : cc_cmi others/belt_internalSetBuckets.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetBuckets.cmi : cc others/belt_internalSetBuckets.resi | others/belt.cmi others/belt_internalBucketsType.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj : cc others/belt_internalSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetString.cmi others/belt_internalSetString.cmj : cc others/belt_internalSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/dom.cmi others/dom.cmj : cc others/dom.res | others/belt_internals.cmi others/dom_storage.cmj others/dom_storage2.cmj others/js.cmi $bsc js_pkg -o others/dom_storage.cmi others/dom_storage.cmj : cc others/dom_storage.res | others/belt_internals.cmi others/dom_storage2.cmj others/js.cmi $bsc js_pkg +o others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj : cc others/belt_internalMapInt.res | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalMapString.cmi others/belt_internalMapString.cmj : cc others/belt_internalMapString.res | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalSetBuckets.cmj : cc_cmi others/belt_internalSetBuckets.res | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalSetBuckets.cmi : cc others/belt_internalSetBuckets.resi | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj : cc others/belt_internalSetInt.res | others/belt_internals.cmi others/js.cmi $bsc +o others/belt_internalSetString.cmi others/belt_internalSetString.cmj : cc others/belt_internalSetString.res | others/belt_internals.cmi others/js.cmi $bsc +o others/dom.cmi others/dom.cmj : cc others/dom.res | others/belt_internals.cmi others/js.cmi $bsc +o others/dom_storage.cmi others/dom_storage.cmj : cc others/dom_storage.res | others/belt_internals.cmi others/js.cmi $bsc o others/dom_storage2.cmi others/dom_storage2.cmj : cc others/dom_storage2.res | others/belt_internals.cmi others/js.cmi $bsc o others/runtime_ast_extensions.cmi others/runtime_ast_extensions.cmj : cc others/runtime_ast_extensions.res | others/belt_internals.cmi others/js.cmi $bsc -o others/runtime_deriving.cmj : cc_cmi others/runtime_deriving.res | others/belt_internals.cmi others/js.cmi others/runtime_deriving.cmi $bsc js_pkg +o others/runtime_deriving.cmj : cc_cmi others/runtime_deriving.res | others/belt_internals.cmi others/js.cmi $bsc o others/runtime_deriving.cmi : cc others/runtime_deriving.resi | others/belt_internals.cmi others/js.cmi $bsc o others/runtime_promise.cmi others/runtime_promise.cmj : cc others/runtime_promise.res | others/belt_internals.cmi others/js.cmi $bsc o others : phony others/belt_Array.cmi others/belt_Array.cmj others/belt_Float.cmi others/belt_Float.cmj others/belt_HashMap.cmi others/belt_HashMap.cmj others/belt_HashMapInt.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmi others/belt_HashMapString.cmj others/belt_HashSet.cmi others/belt_HashSet.cmj others/belt_HashSetInt.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmi others/belt_HashSetString.cmj others/belt_Id.cmi others/belt_Id.cmj others/belt_Int.cmi others/belt_Int.cmj others/belt_List.cmi others/belt_List.cmj others/belt_Map.cmi others/belt_Map.cmj others/belt_MapDict.cmi others/belt_MapDict.cmj others/belt_MapInt.cmi others/belt_MapInt.cmj others/belt_MapString.cmi others/belt_MapString.cmj others/belt_MutableMap.cmi others/belt_MutableMap.cmj others/belt_MutableMapInt.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmi others/belt_MutableMapString.cmj others/belt_MutableQueue.cmi others/belt_MutableQueue.cmj others/belt_MutableSet.cmi others/belt_MutableSet.cmj others/belt_MutableSetInt.cmi others/belt_MutableSetInt.cmj others/belt_MutableSetString.cmi others/belt_MutableSetString.cmj others/belt_MutableStack.cmi others/belt_MutableStack.cmj others/belt_Option.cmi others/belt_Option.cmj others/belt_Range.cmi others/belt_Range.cmj others/belt_Result.cmi others/belt_Result.cmj others/belt_Set.cmi others/belt_Set.cmj others/belt_SetDict.cmi others/belt_SetDict.cmj others/belt_SetInt.cmi others/belt_SetInt.cmj others/belt_SetString.cmi others/belt_SetString.cmj others/belt_SortArray.cmi others/belt_SortArray.cmj others/belt_SortArrayInt.cmi others/belt_SortArrayInt.cmj others/belt_SortArrayString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmi others/belt_internalAVLset.cmj others/belt_internalAVLtree.cmi others/belt_internalAVLtree.cmj others/belt_internalBuckets.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmi others/belt_internalBucketsType.cmj others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj others/belt_internalMapString.cmi others/belt_internalMapString.cmj others/belt_internalSetBuckets.cmi others/belt_internalSetBuckets.cmj others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj others/belt_internalSetString.cmi others/belt_internalSetString.cmj others/dom.cmi others/dom.cmj others/dom_storage.cmi others/dom_storage.cmj others/dom_storage2.cmi others/dom_storage2.cmj others/runtime_ast_extensions.cmi others/runtime_ast_extensions.cmj others/runtime_deriving.cmi others/runtime_deriving.cmj others/runtime_promise.cmi others/runtime_promise.cmj diff --git a/jscomp/runtime/release.ninja b/jscomp/runtime/release.ninja index d0bd28fbd2..1f96dcb3fa 100644 --- a/jscomp/runtime/release.ninja +++ b/jscomp/runtime/release.ninja @@ -25,7 +25,7 @@ o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/cam o runtime/caml_exceptions.cmi : cc runtime/caml_exceptions.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_float.cmj : cc_cmi runtime/caml_float.res | runtime/caml_float.cmi runtime/caml_float_extern.cmj o runtime/caml_float.cmi : cc runtime/caml_float.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_format.cmj : cc_cmi runtime/caml_format.res | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj +o runtime/caml_format.cmj : cc_cmi runtime/caml_format.res | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj o runtime/caml_format.cmi : cc runtime/caml_format.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj @@ -41,7 +41,7 @@ o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.res | runtime/caml_array_extern o runtime/caml_md5.cmi : cc runtime/caml_md5.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj +o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj @@ -58,7 +58,7 @@ o runtime/caml_bigint_extern.cmi runtime/caml_bigint_extern.cmj : cc runtime/cam o runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj : cc runtime/caml_external_polyfill.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj +o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj diff --git a/lib/bstracing b/lib/bstracing index 2a365a6052..55012b5aa6 100755 --- a/lib/bstracing +++ b/lib/bstracing @@ -1,10 +1,10 @@ #!/usr/bin/env node -"use strict"; -//@ts-check -const fs = require("fs"); -const readline = require("readline"); -const path = require("path"); +// @ts-check + +const fs = require("node:fs"); +const readline = require("node:readline"); +const path = require("node:path"); /** * @@ -13,8 +13,8 @@ const path = require("path"); * @param {()=>void} finish */ function processEntry(file, lineCb, finish) { - let input = fs.createReadStream(file); - input.on("error", function (error) { + const input = fs.createReadStream(file); + input.on("error", (error) => { console.error(error.message); console.error( "make sure you are running after bsb building and in the top directory" @@ -23,7 +23,7 @@ function processEntry(file, lineCb, finish) { }); const rl = readline.createInterface({ input: input, - crlfDelay: Infinity, + crlfDelay: Number.POSITIVE_INFINITY, }); rl.on("line", lineCb); @@ -121,7 +121,7 @@ const colors = [ "cq_build_attempt_failed", ]; -let allocated = new Map(); +const allocated = new Map(); function getColorName(obj, cat) { obj.cat = cat; @@ -139,9 +139,9 @@ function getColorName(obj, cat) { * @param {Interval} target */ function category(target, obj) { - let targets = target.targets; + const targets = target.targets; if (targets.length === 1) { - let curTar = targets[0]; + const curTar = targets[0]; if (curTar.endsWith(".d")) { getColorName(obj, "dep"); } else if (curTar.endsWith(".mlast") || curTar.endsWith(".mliast")) { @@ -174,13 +174,13 @@ function readIntervals(file, showAll, outputFile) { processEntry( file, (line) => { - let lineTrim = line.trim(); + const lineTrim = line.trim(); if (lineTrim.startsWith("#")) { return; } let [start, end, _, name, cmdHash] = lineTrim.split("\t"); - cmdHash += "/" + end; + cmdHash += `/${end}`; if (+end < lastEndSeen) { // This is a guess // it could be wrong, when there's multiple small compilation @@ -199,12 +199,12 @@ function readIntervals(file, showAll, outputFile) { ).targets.push(name); }, () => { - let sorted = [...targets.values()].sort((a, b) => { + const sorted = [...targets.values()].sort((a, b) => { return a.start - b.start; }); - let jsonArray = []; - let threads = new Threads(); - for (let target of sorted) { + const jsonArray = []; + const threads = new Threads(); + for (const target of sorted) { jsonArray.push( category(target, { ph: "X", @@ -221,38 +221,38 @@ function readIntervals(file, showAll, outputFile) { } ); } -let logName = ".ninja_log"; +const logName = ".ninja_log"; /** * @type {string} */ -var file; +let file; /** * * @param ps {string[]} */ function tryLocation(ps) { - for (let p of ps) { - let log = path.join(p, logName); + for (const p of ps) { + const log = path.join(p, logName); if (fs.existsSync(log)) { file = log; return; } } console.error( - `no .ninja_log found in specified paths, make sure you set bstracing to the proper directory` + "no .ninja_log found in specified paths, make sure you set bstracing to the proper directory" ); process.exit(2); } let showAll = false; -let curDate = new Date(); +const curDate = new Date(); let outputFile = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDate.getSeconds()}.json`; { - let index = process.argv.indexOf(`-C`); + let index = process.argv.indexOf("-C"); if (index >= 0) { - let p = process.argv[index + 1]; + const p = process.argv[index + 1]; tryLocation([p, path.join(p, "lib", "bs")]); } else { tryLocation([".", path.join("lib", "bs")]); @@ -260,7 +260,7 @@ let outputFile = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDat if (process.argv.includes("-all")) { showAll = true; } - index = process.argv.indexOf(`-o`); + index = process.argv.indexOf("-o"); if (index >= 0) { outputFile = process.argv[index + 1]; } diff --git a/lib/minisocket.js b/lib/minisocket.js index 780a53e0a0..6bcb965aa4 100644 --- a/lib/minisocket.js +++ b/lib/minisocket.js @@ -1,93 +1,92 @@ - -var crypto = require("crypto"); -var KEY_SUFFIX = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; +const crypto = require("node:crypto"); +const KEY_SUFFIX = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; function hashWebSocketKey(key) { - var sha1 = crypto.createHash("sha1"); - sha1.update(key + KEY_SUFFIX, "ascii"); - return sha1.digest("base64"); + const sha1 = crypto.createHash("sha1"); + sha1.update(key + KEY_SUFFIX, "ascii"); + return sha1.digest("base64"); } /** - * Limitations: the current implementation does not + * Limitations: the current implementation does not * care about what the client send: * - we don't know `ws.close` only know `socket.closed` which is later so it has a latency * - ping pong protocol */ // http://tools.ietf.org/html/rfc6455#section-5.2 -var opcodes = { - TEXT: 1, - BINARY: 2, - CLOSE: 8, - PING: 9, - PONG: 10 +const opcodes = { + TEXT: 1, + BINARY: 2, + CLOSE: 8, + PING: 9, + PONG: 10, }; /** - * - * @param {number} opcode - * @param {Buffer} payload + * + * @param {number} opcode + * @param {Buffer} payload */ function encodeMessage(opcode, payload) { - var buf; // Buffer type - var b1 = 0x80 | opcode; - // always send message as one frame (fin) + let buf; // Buffer type + const b1 = 0x80 | opcode; + // always send message as one frame (fin) - // second byte: maks and length part 1 - // followed by 0, 2, or 8 additional bytes of continued length - var b2 = 0; - // server does not mask frames - var length = payload.length; - if (length < 126) { - buf = Buffer.allocUnsafe(payload.length + 2 + 0); - // zero extra bytes - b2 |= length; - buf.writeUInt8(b1, 0); - buf.writeUInt8(b2, 1); - payload.copy(buf, 2); - } else if (length < (1 << 16)) { - buf = Buffer.allocUnsafe(payload.length + 2 + 2); - // two bytes extra - b2 |= 126; - buf.writeUInt8(b1, 0); - buf.writeUInt8(b2, 1); - // add two byte length - buf.writeUInt16BE(length, 2); - payload.copy(buf, 4); - } else { - buf = Buffer.allocUnsafe(payload.length + 2 + 8); - // eight bytes extra - b2 |= 127; - buf.writeUInt8(b1, 0); - buf.writeUInt8(b2, 1); - // add eight byte length - // note: this implementation cannot handle lengths greater than 2^32 - // the 32 bit length is prefixed with 0x0000 - buf.writeUInt32BE(0, 2); - buf.writeUInt32BE(length, 6); - payload.copy(buf, 10); - } - return buf; -}; + // second byte: maks and length part 1 + // followed by 0, 2, or 8 additional bytes of continued length + let b2 = 0; + // server does not mask frames + const length = payload.length; + if (length < 126) { + buf = Buffer.allocUnsafe(payload.length + 2 + 0); + // zero extra bytes + b2 |= length; + buf.writeUInt8(b1, 0); + buf.writeUInt8(b2, 1); + payload.copy(buf, 2); + } else if (length < 1 << 16) { + buf = Buffer.allocUnsafe(payload.length + 2 + 2); + // two bytes extra + b2 |= 126; + buf.writeUInt8(b1, 0); + buf.writeUInt8(b2, 1); + // add two byte length + buf.writeUInt16BE(length, 2); + payload.copy(buf, 4); + } else { + buf = Buffer.allocUnsafe(payload.length + 2 + 8); + // eight bytes extra + b2 |= 127; + buf.writeUInt8(b1, 0); + buf.writeUInt8(b2, 1); + // add eight byte length + // note: this implementation cannot handle lengths greater than 2^32 + // the 32 bit length is prefixed with 0x0000 + buf.writeUInt32BE(0, 2); + buf.writeUInt32BE(length, 6); + payload.copy(buf, 10); + } + return buf; +} -var upgradeHeader = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nsec-websocket-accept: ' -class MiniWebSocket { - constructor(req, socket, upgradeHead) { - this.socket = socket; - this.closed = false; - var self = this; - var key = hashWebSocketKey(req.headers["sec-websocket-key"]) +const upgradeHeader = + "HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nsec-websocket-accept: "; +class MiniWebSocket { + constructor(req, socket, upgradeHead) { + this.socket = socket; + this.closed = false; + const key = hashWebSocketKey(req.headers["sec-websocket-key"]); - // http://tools.ietf.org/html/rfc6455#section-4.2.2 - socket.write( upgradeHeader + key + '\r\n\r\n'); - socket.on("close", function (hadError) { - if (!self.closed) { - self.closed = true; - } - }); - }; - sendText(obj) { - this.socket.write(encodeMessage(opcodes.TEXT,Buffer.from(obj, "utf8"))) - }; + // http://tools.ietf.org/html/rfc6455#section-4.2.2 + socket.write(`${upgradeHeader + key}\r\n\r\n`); + socket.on("close", hadError => { + if (!this.closed) { + this.closed = true; + } + }); + } + sendText(obj) { + this.socket.write(encodeMessage(opcodes.TEXT, Buffer.from(obj, "utf8"))); + } } -exports.MiniWebSocket = MiniWebSocket \ No newline at end of file +exports.MiniWebSocket = MiniWebSocket; diff --git a/package-lock.json b/package-lock.json index ea2ff3acb7..a5ebf6e2d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,8 +18,10 @@ "devDependencies": { "@biomejs/biome": "1.8.3", "@types/node": "^20.14.9", + "@types/semver": "^7.5.8", "mocha": "10.1.0", "nyc": "15.0.0", + "semver": "7.6.2", "typescript": "5.5.3" }, "engines": { @@ -69,6 +71,15 @@ "url": "https://opencollective.com/babel" } }, + "node_modules/@babel/core/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "dev": true, + "bin": { + "semver": "bin/semver" + } + }, "node_modules/@babel/generator": { "version": "7.24.5", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.5.tgz", @@ -523,6 +534,12 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/semver": { + "version": "7.5.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", + "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", + "dev": true + }, "node_modules/aggregate-error": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", @@ -2163,12 +2180,15 @@ "dev": true }, "node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", "dev": true, "bin": { - "semver": "bin/semver" + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/serialize-javascript": { @@ -2619,6 +2639,14 @@ "resolve": "^1.3.2", "semver": "^5.4.1", "source-map": "^0.5.0" + }, + "dependencies": { + "semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "dev": true + } } }, "@babel/generator": { @@ -2922,6 +2950,12 @@ "undici-types": "~5.26.4" } }, + "@types/semver": { + "version": "7.5.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", + "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", + "dev": true + }, "aggregate-error": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", @@ -4167,9 +4201,9 @@ "dev": true }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", "dev": true }, "serialize-javascript": { diff --git a/package.json b/package.json index 9c66718280..1003bca070 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,8 @@ "test": "node scripts/ciTest.js -all", "test-bsb": "node scripts/ciTest.js -bsb", "test-ocaml": "node scripts/ciTest.js -ounit", + "lint": "biome lint --changed --no-errors-on-unmatched .", + "lint:all": "biome lint .", "format": "biome format --changed --no-errors-on-unmatched --write .", "format:all": "biome format --write .", "checkFormat": "biome format --changed --no-errors-on-unmatched .", @@ -74,13 +76,16 @@ "./package.json": "./package.json" }, "imports": { - "#cli/bin_path": "./cli/bin_path.js" + "#cli/bin_path": "./cli/bin_path.js", + "#internal/*": "./scripts/lib/*.js" }, "devDependencies": { "@biomejs/biome": "1.8.3", "@types/node": "^20.14.9", + "@types/semver": "^7.5.8", "mocha": "10.1.0", "nyc": "15.0.0", + "semver": "7.6.2", "typescript": "5.5.3" }, "packageManager": "npm@10.8.1+sha512.0e9d42e92bd2318408ed81eaff2da5f78baf23ee7d12a6eed44a6e2901d0f29d7ab715d1b918ade601f72e769a824d9a5c322383f22bbbda5dd396e79de2a077" diff --git a/packages/playground-bundling/scripts/generate_cmijs.js b/packages/playground-bundling/scripts/generate_cmijs.js index d2f42b4640..f496c1f967 100644 --- a/packages/playground-bundling/scripts/generate_cmijs.js +++ b/packages/playground-bundling/scripts/generate_cmijs.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -"use strict"; +// @ts-check /* * Requires the version matching `rescript` binary to be `npm link`ed in this @@ -15,9 +15,9 @@ * playground bundle. */ -const child_process = require("child_process"); -const fs = require("fs"); -const path = require("path"); +const child_process = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); const resConfig = require("../rescript.json"); @@ -35,23 +35,23 @@ if (!fs.existsSync(PACKAGES_DIR)) { fs.mkdirSync(PACKAGES_DIR, { recursive: true }); } -const config = { - cwd: PROJECT_ROOT_DIR, - encoding: "utf8", - stdio: [0, 1, 2], - shell: true, -}; - +/** + * @param {string} cmd + */ function e(cmd) { console.log(`>>>>>> running command: ${cmd}`); - child_process.execSync(cmd, config); - console.log(`<<<<<<`); + child_process.execSync(cmd, { + cwd: PROJECT_ROOT_DIR, + encoding: "utf8", + stdio: [0, 1, 2], + }); + console.log("<<<<<<"); } -e(`npm install`); +e("npm install"); e(`npm link ${RESCRIPT_COMPILER_ROOT_DIR}`); -e(`npx rescript clean`); -e(`npx rescript`); +e("npx rescript clean"); +e("npx rescript"); const packages = resConfig["bs-dependencies"]; @@ -68,7 +68,7 @@ function buildCompilerCmij() { const outputFolder = path.join(PACKAGES_DIR, "compiler-builtins"); - const cmijFile = path.join(outputFolder, `cmij.js`); + const cmijFile = path.join(outputFolder, "cmij.js"); if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder, { recursive: true }); @@ -80,7 +80,7 @@ function buildCompilerCmij() { } function buildThirdPartyCmijs() { - packages.forEach(function installLib(pkg) { + for (const pkg of packages) { const libOcamlFolder = path.join( PROJECT_ROOT_DIR, "node_modules", @@ -97,7 +97,7 @@ function buildThirdPartyCmijs() { ); const outputFolder = path.join(PACKAGES_DIR, pkg); - const cmijFile = path.join(outputFolder, `cmij.js`); + const cmijFile = path.join(outputFolder, "cmij.js"); if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder, { recursive: true }); @@ -107,7 +107,7 @@ function buildThirdPartyCmijs() { e( `find ${libOcamlFolder} -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${cmijFile} -I ${libOcamlFolder}`, ); - }); + } } buildCompilerCmij(); diff --git a/packages/playground-bundling/tsconfig.json b/packages/playground-bundling/tsconfig.json new file mode 100644 index 0000000000..49d00ee978 --- /dev/null +++ b/packages/playground-bundling/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "resolveJsonModule": true + }, + "include": ["scripts", "rescript.json"], + "exclude": ["lib/**"] +} diff --git a/playground/playground_test.js b/playground/playground_test.js index 62fefcc180..407db67abc 100644 --- a/playground/playground_test.js +++ b/playground/playground_test.js @@ -1,13 +1,13 @@ -require("./compiler.js") -require("./packages/compiler-builtins/cmij.js") -require("./packages/@rescript/react/cmij.js") -require("./packages/@rescript/core/cmij.js") +require("./compiler.js"); +require("./packages/compiler-builtins/cmij.js"); +require("./packages/@rescript/react/cmij.js"); +require("./packages/@rescript/core/cmij.js"); -let compiler = rescript_compiler.make() +const compiler = rescript_compiler.make(); -compiler.setOpenModules(["RescriptCore"]) +compiler.setOpenModules(["RescriptCore"]); -let result = compiler.rescript.compile(` +const result = compiler.rescript.compile(` @@jsxConfig({ version: 4, mode: "automatic" }) module A = { @@ -27,7 +27,7 @@ let result = compiler.rescript.compile(` } } - let sum = [1,2,3] + let sum = [1,2,3] ->Array.map(x => x * 2) ->Array.reduce(0, (acc, item) => acc + item) @@ -41,29 +41,29 @@ let result = compiler.rescript.compile(` let a = `); -if(result.js_code != "") { - console.log('-- Playground test output --'); +if (result.js_code !== "") { + console.log("-- Playground test output --"); console.log(`ReScript version: ${compiler.rescript.version}`); - console.log('----'); - if(result.type === "unexpected_error") { + console.log("----"); + if (result.type === "unexpected_error") { console.log("UNEXPECTED ERROR"); console.log(result); process.exit(1); } - if(result.errors && result.errors.length > 0) { + if (result.errors && result.errors.length > 0) { console.log("COMPILATION ERROR"); - for(let error of result.errors) { + for (const error of result.errors) { console.log(error.shortMsg); } process.exit(1); } - if(result.warnings.length === 0) { + if (result.warnings.length === 0) { console.log("TEST FAILED"); console.log("The code should have at least one warning."); process.exit(1); } console.log(result.js_code); - console.log('-- Playground test complete --'); + console.log("-- Playground test complete --"); } diff --git a/scripts/buildNinjaBinary.js b/scripts/buildNinjaBinary.js index 92e3411be2..af73d99056 100755 --- a/scripts/buildNinjaBinary.js +++ b/scripts/buildNinjaBinary.js @@ -1,7 +1,9 @@ #!/usr/bin/env node -const child_process = require("child_process"); -const path = require("path"); +// @ts-check + +const child_process = require("node:child_process"); +const path = require("node:path"); const platform = process.platform; const ninjaDir = path.join(__dirname, "..", "ninja"); @@ -12,8 +14,8 @@ if (platform === "win32") { child_process.execSync(buildCommand, { cwd: ninjaDir }); } else { if (process.platform === "darwin") { - process.env["CXXFLAGS"] = "-flto"; + process.env.CXXFLAGS = "-flto"; } child_process.execSync(buildCommand, { stdio: [0, 1, 2], cwd: ninjaDir }); - child_process.execSync(`strip ninja`, { stdio: [0, 1, 2], cwd: ninjaDir }); + child_process.execSync("strip ninja", { stdio: [0, 1, 2], cwd: ninjaDir }); } diff --git a/scripts/ciTest.js b/scripts/ciTest.js index 1394fb531e..dac10243cc 100644 --- a/scripts/ciTest.js +++ b/scripts/ciTest.js @@ -1,10 +1,12 @@ -//@ts-check -const cp = require("child_process"); -const path = require("path"); -const fs = require("fs"); +#!/usr/bin/env node -const duneBinDir = require("./dune").duneBinDir; +// @ts-check +const cp = require("node:child_process"); +const path = require("node:path"); +const fs = require("node:fs"); + +const { duneBinDir } = require("#internal/paths"); const { exec } = require("../jscomp/build_tests/utils.js"); let ounitTest = false; @@ -56,7 +58,7 @@ async function runTests() { // running generated js tests if (mochaTest) { - cp.execSync(`npx mocha -t 10000 jscomp/test/**/*test.js`, { + cp.execSync("npx mocha -t 10000 jscomp/test/**/*test.js", { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }); @@ -80,7 +82,7 @@ async function runTests() { console.log(`testing ${file}`); // note existsSync test already ensure that it is a directory - const out = await exec(`node`, ["input.js"], { cwd: testDir }); + const out = await exec("node", ["input.js"], { cwd: testDir }); console.log(out.stdout); if (out.status === 0) { diff --git a/scripts/copyExes.js b/scripts/copyExes.js index e14b21d8fb..141adaed37 100755 --- a/scripts/copyExes.js +++ b/scripts/copyExes.js @@ -1,23 +1,28 @@ #!/usr/bin/env node + +// @ts-check + // Copy exes built by dune to platform bin dir -const path = require("path"); -const fs = require("fs"); -const child_process = require("child_process"); -const { duneBinDir } = require("./dune"); +const path = require("node:path"); +const fs = require("node:fs"); +const child_process = require("node:child_process"); const { absolutePath: platformBinDir } = require("#cli/bin_path"); +const { duneBinDir } = require("#internal/paths"); const ninjaDir = path.join(__dirname, "..", "ninja"); const rewatchDir = path.join(__dirname, "..", "rewatch"); -if (!fs.existsSync(platformBinDir)) { - fs.mkdirSync(platformBinDir); -} +fs.mkdirSync(platformBinDir, { recursive: true }); +/** + * @param {string} dir + * @param {string} exe + */ function copyExe(dir, exe) { const ext = process.platform === "win32" ? ".exe" : ""; const src = path.join(dir, exe + ext); - const dest = path.join(platformBinDir, exe + ".exe"); + const dest = path.join(platformBinDir, `${exe}.exe`); // For some reason, the copy operation fails in Windows CI if the file already exists. if (process.platform === "win32" && fs.existsSync(dest)) { diff --git a/scripts/dune.js b/scripts/dune.js deleted file mode 100644 index dd22149381..0000000000 --- a/scripts/dune.js +++ /dev/null @@ -1,12 +0,0 @@ -var path = require("path"); - -var duneBinDir = path.join( - __dirname, - "..", - "_build", - "install", - "default", - "bin", -); - -exports.duneBinDir = duneBinDir; diff --git a/scripts/lib/meta.js b/scripts/lib/meta.js new file mode 100644 index 0000000000..a21af58dcf --- /dev/null +++ b/scripts/lib/meta.js @@ -0,0 +1,7 @@ +// @ts-check + +const packageJson = require("rescript/package.json"); + +module.exports = { + packageJson, +}; diff --git a/scripts/lib/paths.js b/scripts/lib/paths.js new file mode 100644 index 0000000000..bf5a1e680f --- /dev/null +++ b/scripts/lib/paths.js @@ -0,0 +1,86 @@ +// @ts-check + +const path = require("node:path"); + +/** + * The project root path + */ +const projectDir = path.resolve(__dirname, "..", ".."); + +/** + * path: `/jscomp/` + */ +const compilerRootDir = path.resolve(projectDir, "jscomp"); + +/** + * path: `/jscomp/runtime` + */ +const compilerRuntimeDir = path.resolve(compilerRootDir, "runtime"); + +/** + * path: `/jscomp/others/` + */ +const compilerBuiltinDir = path.resolve(compilerRootDir, "others"); + +/** + * path: `/lib/js/` + */ +const compilerBuiltinCjsOutputDir = path.resolve(projectDir, "lib", "js"); + +/** + * path: `/lib/es6/` + */ +const compilerBuiltinMjsOutputDir = path.resolve(projectDir, "lib", "es6"); + +/** + * path: `/jscomp/test/` + */ +const compilerTestDir = path.resolve(compilerRootDir, "test"); + +/** + * path: `/jscomp/build_tests/` + */ +const compilerBuildTestDir = path.resolve(compilerRootDir, "build_tests"); + +/** + * path: `/jscomp/common/bs_version.ml` + */ +const compilerVersionFile = path.resolve( + compilerRootDir, + "common", + "bs_version.ml", +); + +/** + * path: `/_build/install/default/bin/` + */ +const duneBinDir = path.resolve( + projectDir, + "_build", + "install", + "default", + "bin", +); + +/** + * path: `/jscomp/gentype_tests/typescript-react-example/` + */ +const gentypeExampleDir = path.resolve( + compilerRootDir, + "gentype_tests", + "typescript-react-example", +); + +module.exports = { + projectDir, + compilerRootDir, + compilerRuntimeDir, + compilerBuiltinDir, + compilerBuiltinCjsOutputDir, + compilerBuiltinMjsOutputDir, + compilerTestDir, + compilerBuildTestDir, + compilerVersionFile, + duneBinDir, + gentypeExampleDir, +}; diff --git a/scripts/makeArtifactList.js b/scripts/makeArtifactList.js index 477202b8f2..5b3800fb4e 100755 --- a/scripts/makeArtifactList.js +++ b/scripts/makeArtifactList.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +// @ts-check + // This script creates the list of the files that go into the rescript npm package. // // In local dev, invoke it without any args after adding or removing files. @@ -9,22 +11,38 @@ // In CI, it is invoked with -check. It then recreates the list and verifies // that it has no changes compared to the committed state. -const { spawnSync, execSync } = require("child_process"); -const path = require("path"); -const fs = require("fs"); +const { spawnSync, execSync } = require("node:child_process"); +const path = require("node:path"); +const fs = require("node:fs"); const isCheckMode = process.argv.includes("-check"); const rootPath = path.join(__dirname, ".."); const fileListPath = path.join(rootPath, "packages", "artifacts.txt"); -const output = spawnSync(`npm pack --dry-run --json`, { - cwd: rootPath, - encoding: "utf8", - shell: true, -}).stdout; +/** + * @typedef {{ + * path: string, + * size: number, + * mode: number, + * }} PackOutputFile + * @typedef {{ + * files: PackOutputFile[], + * entryCount: number, + * bundled: unknown[], + * }} PackOutputEntry + * @typedef {[PackOutputEntry]} PackOutput + * @type {PackOutput} + */ +const output = JSON.parse( + spawnSync("npm pack --dry-run --json", { + cwd: rootPath, + encoding: "utf8", + shell: true, + }).stdout, +); -const [{ files }] = JSON.parse(output); +const [{ files }] = output; let filePaths = files.map(file => file.path); if (!isCheckMode) { @@ -50,8 +68,8 @@ function getFilesAddedByCI() { const files = ["ninja.COPYING"]; - for (let platform of platforms) { - for (let exe of exes) { + for (const platform of platforms) { + for (const exe of exes) { files.push(`${platform}/${exe}`); } } diff --git a/scripts/ninja.js b/scripts/ninja.js index c0fb7f4e20..8ef21c4c6c 100755 --- a/scripts/ninja.js +++ b/scripts/ninja.js @@ -1,40 +1,43 @@ #!/usr/bin/env node -//@ts-check -var os = require("os"); -var fs = require("fs"); -var path = require("path"); -var cp = require("child_process"); -var semver = require("semver"); +// @ts-check -var jscompDir = path.join(__dirname, "..", "jscomp"); -var runtimeDir = path.join(jscompDir, "runtime"); -var othersDir = path.join(jscompDir, "others"); -var testDir = path.join(jscompDir, "test"); +const os = require("node:os"); +const fs = require("node:fs"); +const path = require("node:path"); +const cp = require("node:child_process"); +const semver = require("semver"); -var jsDir = path.join(__dirname, "..", "lib", "js"); +const { + absolutePath: my_target, + bsc_exe, + ninja_exe: vendorNinjaPath, +} = require("#cli/bin_path"); +const { + compilerRootDir, + compilerRuntimeDir, + compilerBuiltinDir, + compilerTestDir, + compilerBuiltinCjsOutputDir, +} = require("#internal/paths"); -var runtimeFiles = fs.readdirSync(runtimeDir, "ascii"); -var runtimeMlFiles = runtimeFiles.filter( +const runtimeFiles = fs.readdirSync(compilerRuntimeDir, "ascii"); +const runtimeMlFiles = runtimeFiles.filter( x => !x.startsWith("bs_stdlib_mini") && x.endsWith(".res") && x !== "js.res", ); -var runtimeMliFiles = runtimeFiles.filter( +const runtimeMliFiles = runtimeFiles.filter( x => !x.startsWith("bs_stdlib_mini") && x.endsWith(".resi") && x !== "js.resi", ); -var runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles); -var runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))]; - -var commonBsFlags = `-no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib `; -var js_package = pseudoTarget("js_pkg"); -var runtimeTarget = pseudoTarget("runtime"); -var othersTarget = pseudoTarget("others"); -var stdlibTarget = pseudoTarget("$stdlib"); -var { - absolutePath: my_target, - bsc_exe, - ninja_exe: vendorNinjaPath, -} = require("#cli/bin_path"); +const runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles); +const runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))]; + +const commonBsFlags = + "-no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib "; +const js_package = pseudoTarget("js_pkg"); +const runtimeTarget = pseudoTarget("runtime"); +const othersTarget = pseudoTarget("others"); +const stdlibTarget = pseudoTarget("$stdlib"); // Let's enforce a Node version >= 16 to make sure M1 users don't trip up on // cryptic issues caused by mismatching assembly architectures Node 16 ships @@ -45,7 +48,6 @@ if (semver.lt(process.version, "16.0.0")) { process.exit(1); } -exports.vendorNinjaPath = vendorNinjaPath; /** * By default we use vendored, * we produce two ninja files which won't overlap @@ -83,36 +85,37 @@ exports.vendorNinjaPath = vendorNinjaPath; */ /** - * @type {string} + * @type {string | undefined} */ -var versionString = undefined; +let versionString = undefined; /** - * * @returns {string} */ -var getVersionString = () => { +function getVersionString() { if (versionString === undefined) { - var searcher = "version"; + const searcher = "version"; try { - var output = cp.execSync(`ocamldep.opt -version`, { + const output = cp.execSync("ocamldep.opt -version", { encoding: "ascii", }); versionString = output .substring(output.indexOf(searcher) + searcher.length) .trim(); } catch (err) { - console.error(`This error probably came from that you don't have OCaml installed. -Make sure you have the OCaml compiler available in your path.`); - console.error(err.message); - process.exit(err.status); + throw new Error( + `This error probably came from that you don't have OCaml installed. +Make sure you have the OCaml compiler available in your path.`, + { + cause: err, + }, + ); } } return versionString; -}; +} /** - * * @param {string} ninjaCwd */ function ruleCC(ninjaCwd) { @@ -126,7 +129,6 @@ rule cc_cmi `; } /** - * * @param {string} name * @param {string} content */ @@ -135,7 +137,6 @@ function writeFileAscii(name, content) { } /** - * * @param {string} name * @param {string} content */ @@ -143,8 +144,7 @@ function writeFileSync(name, content) { return fs.writeFileSync(name, content, "ascii"); } /** - * - * @param {NodeJS.ErrnoException} err + * @param {NodeJS.ErrnoException | null} err */ function throwIfError(err) { if (err !== null) { @@ -152,30 +152,31 @@ function throwIfError(err) { } } /** - * - * @typedef { {kind : "file" , name : string} | {kind : "pseudo" , name : string}} Target - * @typedef {{key : string, value : string}} Override - * @typedef { Target[]} Targets - * @typedef {Map} DepsMap + * @typedef {{ kind: "file", name: string } | { kind: "pseudo", name: string }} Target + * @typedef {{ key: string, value: string }} Override + * @typedef {Target[]} Targets + * @typedef {Map} DepsMap */ class TargetSet { /** - * * @param {Targets} xs */ constructor(xs = []) { this.data = xs; } + + [Symbol.iterator]() { + return this.data[Symbol.iterator](); + } + /** - * * @param {Target} x */ add(x) { - var data = this.data; - var found = false; - for (var i = 0; i < data.length; ++i) { - var cur = data[i]; + const data = this.data; + let found = false; + for (const cur of data) { if (cur.kind === x.kind && cur.name === x.name) { found = true; break; @@ -186,57 +187,49 @@ class TargetSet { } return this; } + /** * @returns {Targets} a copy - * */ toSortedArray() { - var newData = this.data.concat(); + const newData = this.data.concat(); newData.sort((x, y) => { - var kindx = x.kind; - var kindy = y.kind; + const kindx = x.kind; + const kindy = y.kind; if (kindx > kindy) { return 1; - } else if (kindx < kindy) { + } + if (kindx < kindy) { return -1; - } else { - if (x.name > y.name) { - return 1; - } else if (x.name < y.name) { - return -1; - } else { - return 0; - } } + if (x.name > y.name) { + return 1; + } + if (x.name < y.name) { + return -1; + } + return 0; }); return newData; } - /** - * - * @param {(item:Target)=>void} callback - */ - forEach(callback) { - this.data.forEach(callback); - } } /** - * * @param {string} target * @param {string} dependency * @param {DepsMap} depsMap */ function updateDepsKVByFile(target, dependency, depsMap) { - var singleTon = fileTarget(dependency); - if (depsMap.has(target)) { - depsMap.get(target).add(singleTon); + const singleTon = fileTarget(dependency); + const deps = depsMap.get(target); + if (deps) { + deps.add(singleTon); } else { depsMap.set(target, new TargetSet([singleTon])); } } /** - * * @param {string} s */ function uncapitalize(s) { @@ -245,18 +238,18 @@ function uncapitalize(s) { } return s[0].toLowerCase() + s.slice(1); } + /** - * * @param {string} target * @param {string[]} dependencies * @param {DepsMap} depsMap */ function updateDepsKVsByFile(target, dependencies, depsMap) { - var targets = fileTargets(dependencies); - if (depsMap.has(target)) { - var s = depsMap.get(target); - for (var i = 0; i < targets.length; ++i) { - s.add(targets[i]); + const targets = fileTargets(dependencies); + const deps = depsMap.get(target); + if (deps) { + for (const target of targets) { + deps.add(target); } } else { depsMap.set(target, new TargetSet(targets)); @@ -264,34 +257,34 @@ function updateDepsKVsByFile(target, dependencies, depsMap) { } /** - * * @param {string} target * @param {string[]} modules * @param {DepsMap} depsMap */ function updateDepsKVsByModule(target, modules, depsMap) { - if (depsMap.has(target)) { - let s = depsMap.get(target); - for (let module of modules) { - let filename = uncapitalize(module); - let filenameAsCmi = filename + ".cmi"; - let filenameAsCmj = filename + ".cmj"; - if (target.endsWith(".cmi")) { - if (depsMap.has(filenameAsCmi) || depsMap.has(filenameAsCmj)) { - s.add(fileTarget(filenameAsCmi)); - } - } else if (target.endsWith(".cmj")) { - if (depsMap.has(filenameAsCmj)) { - s.add(fileTarget(filenameAsCmj)); - } else if (depsMap.has(filenameAsCmi)) { - s.add(fileTarget(filenameAsCmi)); - } + const deps = depsMap.get(target); + if (deps === undefined) { + return; + } + for (const module of modules) { + const filename = uncapitalize(module); + const filenameAsCmi = `${filename}.cmi`; + const filenameAsCmj = `${filename}.cmj`; + if (target.endsWith(".cmi")) { + if (depsMap.has(filenameAsCmi) || depsMap.has(filenameAsCmj)) { + deps.add(fileTarget(filenameAsCmi)); + } + } else if (target.endsWith(".cmj")) { + if (depsMap.has(filenameAsCmj)) { + deps.add(fileTarget(filenameAsCmj)); + } else if (depsMap.has(filenameAsCmi)) { + deps.add(fileTarget(filenameAsCmi)); } } } } + /** - * * @param {string[]}sources * @return {DepsMap} */ @@ -299,25 +292,21 @@ function createDepsMapWithTargets(sources) { /** * @type {DepsMap} */ - let depsMap = new Map(); - for (let source of sources) { - let target = sourceToTarget(source); + const depsMap = new Map(); + for (const source of sources) { + const target = sourceToTarget(source); depsMap.set(target, new TargetSet([])); } - depsMap.forEach((set, name) => { - let cmiFile; - if ( - name.endsWith(".cmj") && - depsMap.has((cmiFile = replaceExt(name, ".cmi"))) - ) { + for (const [name, set] of depsMap) { + const cmiFile = replaceExt(name, ".cmi"); + if (name.endsWith(".cmj") && depsMap.has(cmiFile)) { set.add(fileTarget(cmiFile)); } - }); + } return depsMap; } /** - * * @param {Target} file * @param {string} cwd */ @@ -332,7 +321,6 @@ function targetToString(file, cwd) { } } /** - * * @param {Targets} files * @param {string} cwd * @@ -342,7 +330,6 @@ function targetsToString(files, cwd) { return files.map(x => targetToString(x, cwd)).join(" "); } /** - * * @param {Targets} outputs * @param {Targets} inputs * @param {Targets} deps @@ -352,28 +339,25 @@ function targetsToString(files, cwd) { * @return {string} */ function ninjaBuild(outputs, inputs, rule, deps, cwd, overrides) { - var fileOutputs = targetsToString(outputs, cwd); - var fileInputs = targetsToString(inputs, cwd); - var stmt = `o ${fileOutputs} : ${rule} ${fileInputs}`; - // deps.push(pseudoTarget('../lib/bsc')) + const fileOutputs = targetsToString(outputs, cwd); + const fileInputs = targetsToString(inputs, cwd); + let stmt = `o ${fileOutputs} : ${rule} ${fileInputs}`; if (deps.length > 0) { - var fileDeps = targetsToString(deps, cwd); + const fileDeps = targetsToString(deps, cwd); stmt += ` | ${fileDeps}`; } if (overrides.length > 0) { - stmt += - `\n` + - overrides - .map(x => { - return ` ${x.key} = ${x.value}`; - }) - .join("\n"); + stmt += "\n"; + stmt += overrides + .map(x => { + return ` ${x.key} = ${x.value}`; + }) + .join("\n"); } return stmt; } /** - * * @param {Target} outputs * @param {Targets} inputs * @param {string} cwd @@ -383,13 +367,12 @@ function phony(outputs, inputs, cwd) { } /** - * * @param {string | string[]} outputs * @param {string | string[]} inputs * @param {string | string[]} fileDeps * @param {string} rule * @param {string} cwd - * @param {[string,string][]} overrides + * @param {Array<[key: string, value: string]>} overrides * @param {Target | Targets} extraDeps */ function ninjaQuickBuild( @@ -401,14 +384,14 @@ function ninjaQuickBuild( fileDeps, extraDeps, ) { - var os = Array.isArray(outputs) + const os = Array.isArray(outputs) ? fileTargets(outputs) : [fileTarget(outputs)]; - var is = Array.isArray(inputs) ? fileTargets(inputs) : [fileTarget(inputs)]; - var ds = Array.isArray(fileDeps) + const is = Array.isArray(inputs) ? fileTargets(inputs) : [fileTarget(inputs)]; + const ds = Array.isArray(fileDeps) ? fileTargets(fileDeps) : [fileTarget(fileDeps)]; - var dds = Array.isArray(extraDeps) ? extraDeps : [extraDeps]; + const dds = Array.isArray(extraDeps) ? extraDeps : [extraDeps]; return ninjaBuild( os, @@ -423,9 +406,17 @@ function ninjaQuickBuild( } /** - * @typedef { (string | string []) } Strings - * @typedef { [string,string]} KV - * @typedef { [Strings, Strings, string, string, KV[], Strings, (Target|Targets)] } BuildList + * @typedef {string | string[]} Strings + * @typedef {[key: string, value: string]} KV + * @typedef {[ + * outputs: Strings, + * inputs: Strings, + * rule: string, + * cwd: string, + * overrides: KV[], + * deps: Strings, + * extraDeps: (Target | Targets) + * ]} BuildList * @param {BuildList[]} xs * @returns {string} */ @@ -436,7 +427,7 @@ function ninjaQuickBuildList(xs) { } /** - * @typedef { [string,string,string?]} CppoInput + * @typedef {[output: string, input: string, string?]} CppoInput * @param {CppoInput[]} xs * @param {string} cwd * @returns {string} @@ -447,7 +438,7 @@ function cppoList(cwd, xs) { /** * @type {KV[]} */ - var variables; + let variables; if (x[2]) { variables = [["type", `-D ${x[2]}`]]; } else { @@ -459,7 +450,6 @@ function cppoList(cwd, xs) { } /** - * * @param {string} name * @returns {Target} */ @@ -468,7 +458,6 @@ function fileTarget(name) { } /** - * * @param {string} name * @returns {Target} */ @@ -477,7 +466,6 @@ function pseudoTarget(name) { } /** - * * @param {string[]} args * @returns {Targets} */ @@ -486,7 +474,6 @@ function fileTargets(args) { } /** - * * @param {string[]} outputs * @param {string[]} inputs * @param {DepsMap} depsMap @@ -496,21 +483,24 @@ function fileTargets(args) { * @param {string} cwd */ function buildStmt(outputs, inputs, rule, depsMap, cwd, overrides, extraDeps) { - var os = outputs.map(fileTarget); - var is = inputs.map(fileTarget); - var deps = new TargetSet(); - for (var i = 0; i < outputs.length; ++i) { - var curDeps = depsMap.get(outputs[i]); + const os = outputs.map(fileTarget); + const is = inputs.map(fileTarget); + const deps = new TargetSet(); + for (const output of outputs) { + const curDeps = depsMap.get(output); if (curDeps !== undefined) { - curDeps.forEach(x => deps.add(x)); + for (const dep of curDeps) { + deps.add(dep); + } } } - extraDeps.forEach(x => deps.add(x)); + for (const dep of extraDeps) { + deps.add(dep); + } return ninjaBuild(os, is, rule, deps.toSortedArray(), cwd, overrides); } /** - * * @param {string} x */ function replaceCmj(x) { @@ -518,41 +508,46 @@ function replaceCmj(x) { } /** - * * @param {string} y */ function sourceToTarget(y) { if (y.endsWith(".res")) { return replaceExt(y, ".cmj"); - } else if (y.endsWith(".resi")) { + } + if (y.endsWith(".resi")) { return replaceExt(y, ".cmi"); } return y; } + /** + * Note `bsdep.exe` does not need post processing and -one-line flag + * By default `ocamldep.opt` only list dependencies in its args * * @param {string[]} files * @param {string} dir * @param {DepsMap} depsMap * @return {Promise} - * Note `bsdep.exe` does not need post processing and -one-line flag - * By default `ocamldep.opt` only list dependencies in its args */ function ocamlDepForBscAsync(files, dir, depsMap) { return new Promise((resolve, reject) => { - var tmpdir = null; + /** @type {string | null} */ + let tmpdir = null; + + /** @type {string[]} */ const mlfiles = []; // convert .res files to temporary .ml files in tmpdir - files.forEach(f => { - const { name, ext } = path.parse(f); + + for (const file of files) { + const { name, ext } = path.parse(file); if (ext === ".res" || ext === ".resi") { - const mlname = ext === ".resi" ? name + ".mli" : name + ".ml"; + const mlname = ext === ".resi" ? `${name}.mli` : `${name}.ml`; if (tmpdir == null) { tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "resToMl")); } try { const mlfile = path.join(tmpdir, mlname); cp.execSync( - `${bsc_exe} -dsource -only-parse -bs-no-builtin-ppx ${f} 2>${mlfile}`, + `${bsc_exe} -dsource -only-parse -bs-no-builtin-ppx ${file} 2>${mlfile}`, { cwd: dir, encoding: "ascii", @@ -563,84 +558,79 @@ function ocamlDepForBscAsync(files, dir, depsMap) { console.log(err); } } - }); - const minusI = tmpdir == null ? "" : `-I ${tmpdir}`; - cp.exec( - `ocamldep.opt -allow-approx -one-line ${minusI} -native ${files.join( - " ", - )} ${mlfiles.join(" ")}`, - { - cwd: dir, - encoding: "ascii", - }, - function (error, stdout, stderr) { - if (tmpdir != null) { - fs.rmSync(tmpdir, { recursive: true, force: true }); - } - if (error !== null) { - return reject(error); - } else { + + const minusI = tmpdir == null ? "" : `-I ${tmpdir}`; + cp.exec( + `ocamldep.opt -allow-approx -one-line ${minusI} -native ${files.join( + " ", + )} ${mlfiles.join(" ")}`, + { + cwd: dir, + encoding: "ascii", + }, + (error, stdout, stderr) => { + if (tmpdir != null) { + fs.rmSync(tmpdir, { recursive: true, force: true }); + } + if (error !== null) { + return reject(error); + } const pairs = stdout.split("\n").map(x => x.split(":")); - pairs.forEach(x => { - var deps; - let source = replaceCmj(path.basename(x[0])); - if (x[1] !== undefined && (deps = x[1].trim())) { - deps = deps.split(" "); - updateDepsKVsByFile( - source, - deps.map(x => replaceCmj(path.basename(x))), - depsMap, - ); - } - }); + for (const [file, depsOutput] of pairs) { + if (!depsOutput) continue; + const source = replaceCmj(path.basename(file)); + const deps = depsOutput.trim().split(" "); + updateDepsKVsByFile( + source, + deps.map(dep => replaceCmj(path.basename(dep))), + depsMap, + ); + } return resolve(); - } - }, - ); + }, + ); + } }); } /** + * Note `bsdep.exe` does not need post processing and -one-line flag + * By default `ocamldep.opt` only list dependencies in its args * * @param {string[]} files * @param {string} dir * @param {DepsMap} depsMap - * @return { Promise []} - * Note `bsdep.exe` does not need post processing and -one-line flag - * By default `ocamldep.opt` only list dependencies in its args + * @return {Array>} */ function depModulesForBscAsync(files, dir, depsMap) { - let resFiles = files.filter(x => x.endsWith(".res") || x.endsWith(".resi")); + const resFiles = files.filter(x => x.endsWith(".res") || x.endsWith(".resi")); /** * * @param {(value:void) =>void} resolve * @param {(value:any)=>void} reject */ - let cb = (resolve, reject) => { + const cb = (resolve, reject) => { /** * @param {any} error * @param {string} stdout * @param {string} stderr */ - let fn = function (error, stdout, stderr) { + const fn = (error, stdout, stderr) => { if (error !== null) { return reject(error); - } else { - var pairs = stdout.split("\n").map(x => x.split(":")); - pairs.forEach(x => { - var modules; - let source = sourceToTarget(x[0].trim()); - if (x[1] !== undefined && (modules = x[1].trim())) { - modules = modules.split(" "); - updateDepsKVsByModule(source, modules, depsMap); - } - }); - return resolve(); } + const pairs = stdout.split("\n").map(x => x.split(":")); + for (const [sourceFile, modulesOutput] of pairs) { + if (!modulesOutput) continue; + const target = sourceToTarget(sourceFile.trim()); + const modules = modulesOutput.trim().split(" "); + updateDepsKVsByModule(target, modules, depsMap); + } + return resolve(); }; return fn; }; - let config = { + const config = { cwd: dir, encoding: "ascii", }; @@ -659,16 +649,15 @@ function depModulesForBscAsync(files, dir, depsMap) { * @typedef {('HAS_RES' | 'HAS_RESI' | 'HAS_BOTH_RES')} FileInfo * @param {string[]} sourceFiles * @returns {Map} - * We make a set to ensure that `sourceFiles` are not duplicated */ function collectTarget(sourceFiles) { /** - * @type {Map} + * @type {Map} */ - var allTargets = new Map(); - sourceFiles.forEach(x => { - var { ext, name } = path.parse(x); - var existExt = allTargets.get(name); + const allTargets = new Map(); + for (const file of sourceFiles) { + const { ext, name } = path.parse(file); + const existExt = allTargets.get(name); if (existExt === undefined) { if (ext === ".res") { allTargets.set(name, "HAS_RES"); @@ -691,20 +680,18 @@ function collectTarget(sourceFiles) { break; } } - }); + } return allTargets; } /** - * * @param {Map} allTargets * @param {string[]} collIn * @returns {string[]} A new copy which is - * */ function scanFileTargets(allTargets, collIn) { - var coll = collIn.concat(); - allTargets.forEach((ext, mod) => { + const coll = collIn.concat(); + for (const [mod, ext] of allTargets) { switch (ext) { case "HAS_RESI": coll.push(`${mod}.cmi`); @@ -716,14 +703,13 @@ function scanFileTargets(allTargets, collIn) { coll.push(`${mod}.cmi`, `${mod}.cmj`); break; } - }); + } return coll; } /** - * * @param {DepsMap} depsMap - * @param {Map} allTargets + * @param {Map} allTargets * @param {string} cwd * @param {Targets} extraDeps * @return {string[]} @@ -732,27 +718,22 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) { /** * @type {string[]} */ - var build_stmts = []; + const build_stmts = []; allTargets.forEach((x, mod) => { - let ouptput_cmj = mod + ".cmj"; - let output_cmi = mod + ".cmi"; - let input_res = mod + ".res"; - let input_resi = mod + ".resi"; + const ouptput_cmj = `${mod}.cmj`; + const output_cmi = `${mod}.cmi`; + const input_res = `${mod}.res`; + const input_resi = `${mod}.resi`; /** * @type {Override[]} */ - var overrides = []; - // if (mod.endsWith("Labels")) { - // overrides.push({ key: "bsc_flags", value: "$bsc_flags -nolabels" }); - // } + const overrides = []; /** - * * @param {string[]} outputs * @param {string[]} inputs - * */ - let mk = (outputs, inputs, rule = "cc") => { + const mk = (outputs, inputs, rule = "cc") => { return build_stmts.push( buildStmt(outputs, inputs, rule, depsMap, cwd, overrides, extraDeps), ); @@ -773,15 +754,15 @@ function generateNinja(depsMap, allTargets, cwd, extraDeps = []) { return build_stmts; } -var COMPILIER = bsc_exe; -var BSC_COMPILER = `bsc = ${COMPILIER}`; +const COMPILIER = bsc_exe; +const BSC_COMPILER = `bsc = ${COMPILIER}`; async function runtimeNinja(devmode = true) { - var ninjaCwd = "runtime"; - var compilerTarget = pseudoTarget("$bsc"); - var externalDeps = devmode ? [compilerTarget] : []; - var ninjaOutput = devmode ? "build.ninja" : "release.ninja"; - var templateRuntimeRules = ` + const ninjaCwd = "runtime"; + const compilerTarget = pseudoTarget("$bsc"); + const externalDeps = devmode ? [compilerTarget] : []; + const ninjaOutput = devmode ? "build.ninja" : "release.ninja"; + const templateRuntimeRules = ` bsc_no_open_flags = ${commonBsFlags} -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini ${ruleCC(ninjaCwd)} @@ -809,18 +790,18 @@ ${ninjaQuickBuildList([ /** * @type {DepsMap} */ - var depsMap = new Map(); - var allTargets = collectTarget([...runtimeMliFiles, ...runtimeMlFiles]); - var manualDeps = ["bs_stdlib_mini.cmi", "js.cmj", "js.cmi"]; - var allFileTargetsInRuntime = scanFileTargets(allTargets, manualDeps); + const depsMap = new Map(); + const allTargets = collectTarget([...runtimeMliFiles, ...runtimeMlFiles]); + const manualDeps = ["bs_stdlib_mini.cmi", "js.cmj", "js.cmi"]; + const allFileTargetsInRuntime = scanFileTargets(allTargets, manualDeps); allTargets.forEach((ext, mod) => { switch (ext) { case "HAS_RESI": case "HAS_BOTH_RES": - updateDepsKVsByFile(mod + ".cmi", manualDeps, depsMap); + updateDepsKVsByFile(`${mod}.cmi`, manualDeps, depsMap); break; case "HAS_RES": - updateDepsKVsByFile(mod + ".cmj", manualDeps, depsMap); + updateDepsKVsByFile(`${mod}.cmj`, manualDeps, depsMap); break; } }); @@ -829,40 +810,39 @@ ${ninjaQuickBuildList([ try { await Promise.all([ runJSCheckAsync(depsMap), - ocamlDepForBscAsync(runtimeSourceFiles, runtimeDir, depsMap), + ocamlDepForBscAsync(runtimeSourceFiles, compilerRuntimeDir, depsMap), ]); - var stmts = generateNinja(depsMap, allTargets, ninjaCwd, externalDeps); + const stmts = generateNinja(depsMap, allTargets, ninjaCwd, externalDeps); stmts.push( phony(runtimeTarget, fileTargets(allFileTargetsInRuntime), ninjaCwd), ); writeFileAscii( - path.join(runtimeDir, ninjaOutput), - templateRuntimeRules + stmts.join("\n") + "\n", + path.join(compilerRuntimeDir, ninjaOutput), + `${templateRuntimeRules + stmts.join("\n")}\n`, ); } catch (e) { console.log(e); } } -var cppoRuleName = `cppo`; - -var cppoRule = (flags = "") => ` +const cppoRuleName = "cppo"; +const cppoRule = (flags = "") => ` rule ${cppoRuleName} command = cppo -V OCAML:${getVersionString()} ${flags} $type $in -o $out generator = true `; async function othersNinja(devmode = true) { - var compilerTarget = pseudoTarget("$bsc"); - var externalDeps = [ + const compilerTarget = pseudoTarget("$bsc"); + const externalDeps = [ compilerTarget, fileTarget("belt_internals.cmi"), fileTarget("js.cmi"), ]; - var ninjaOutput = devmode ? "build.ninja" : "release.ninja"; - var ninjaCwd = "others"; + const ninjaOutput = devmode ? "build.ninja" : "release.ninja"; + const ninjaCwd = "others"; - var templateOthersRules = ` + const templateOthersRules = ` bsc_primitive_flags = ${commonBsFlags} -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A bsc_flags = $bsc_primitive_flags -open Belt_internals ${ruleCC(ninjaCwd)} @@ -896,8 +876,8 @@ ${ninjaQuickBuildList([ ], ])} `; - var othersDirFiles = fs.readdirSync(othersDir, "ascii"); - var jsPrefixSourceFiles = othersDirFiles.filter( + const othersDirFiles = fs.readdirSync(compilerBuiltinDir, "ascii"); + const jsPrefixSourceFiles = othersDirFiles.filter( x => x.startsWith("js") && (x.endsWith(".res") || x.endsWith(".resi")) && @@ -906,7 +886,7 @@ ${ninjaQuickBuildList([ !x.includes("#") && x !== "js.res", ); - var othersFiles = othersDirFiles.filter( + const othersFiles = othersDirFiles.filter( x => !x.startsWith("js") && x !== "belt.res" && @@ -915,61 +895,61 @@ ${ninjaQuickBuildList([ !x.includes("#") && !x.includes(".cppo"), ); - var jsTargets = collectTarget(jsPrefixSourceFiles); - var allJsTargets = scanFileTargets(jsTargets, []); - let jsDepsMap = new Map(); - let depsMap = new Map(); + const jsTargets = collectTarget(jsPrefixSourceFiles); + const allJsTargets = scanFileTargets(jsTargets, []); + const jsDepsMap = new Map(); + const depsMap = new Map(); await Promise.all([ - ocamlDepForBscAsync(jsPrefixSourceFiles, othersDir, jsDepsMap), - ocamlDepForBscAsync(othersFiles, othersDir, depsMap), + ocamlDepForBscAsync(jsPrefixSourceFiles, compilerBuiltinDir, jsDepsMap), + ocamlDepForBscAsync(othersFiles, compilerBuiltinDir, depsMap), ]); - var jsOutput = generateNinja(jsDepsMap, jsTargets, ninjaCwd, externalDeps); + const jsOutput = generateNinja(jsDepsMap, jsTargets, ninjaCwd, externalDeps); jsOutput.push(phony(js_package, fileTargets(allJsTargets), ninjaCwd)); // Note compiling belt.res still try to read // belt_xx.cmi we need enforce the order to // avoid data race issues - var beltPackage = fileTarget("belt.cmi"); - var beltTargets = collectTarget(othersFiles); + const beltPackage = fileTarget("belt.cmi"); + const beltTargets = collectTarget(othersFiles); depsMap.forEach((s, k) => { if (k.startsWith("belt")) { s.add(beltPackage); } s.add(js_package); }); - var allOthersTarget = scanFileTargets(beltTargets, []); - var beltOutput = generateNinja(depsMap, beltTargets, ninjaCwd, externalDeps); + const allOthersTarget = scanFileTargets(beltTargets, []); + const beltOutput = generateNinja( + depsMap, + beltTargets, + ninjaCwd, + externalDeps, + ); beltOutput.push(phony(othersTarget, fileTargets(allOthersTarget), ninjaCwd)); writeFileAscii( - path.join(othersDir, ninjaOutput), - templateOthersRules + - jsOutput.join("\n") + - "\n" + - beltOutput.join("\n") + - "\n", + path.join(compilerBuiltinDir, ninjaOutput), + `${templateOthersRules + jsOutput.join("\n")}\n${beltOutput.join("\n")}\n`, ); } /** - * * @param {boolean} devmode * generate build.ninja/release.ninja for stdlib-402 */ async function stdlibNinja(devmode = true) { - var stdlibVersion = "stdlib-406"; - var ninjaCwd = stdlibVersion; - var stdlibDir = path.join(jscompDir, stdlibVersion); - var compilerTarget = pseudoTarget("$bsc"); - var externalDeps = [compilerTarget, othersTarget]; - var ninjaOutput = devmode ? "build.ninja" : "release.ninja"; - var bsc_flags = "bsc_flags"; + const stdlibVersion = "stdlib-406"; + const ninjaCwd = stdlibVersion; + const stdlibDir = path.join(compilerRootDir, stdlibVersion); + const compilerTarget = pseudoTarget("$bsc"); + const externalDeps = [compilerTarget, othersTarget]; + const ninjaOutput = devmode ? "build.ninja" : "release.ninja"; + const bsc_flags = "bsc_flags"; /** - * @type [string,string][] + * @type Array<[string, string]> */ - var bsc_builtin_overrides = [[bsc_flags, `$${bsc_flags} -nopervasives`]]; + const bsc_builtin_overrides = [[bsc_flags, `$${bsc_flags} -nopervasives`]]; // It is interesting `-w -a` would generate not great code sometimes // deprecations diabled due to string_of_float - var warnings = "-w -9-3-106 -warn-error A"; - var templateStdlibRules = ` + const warnings = "-w -9-3-106 -warn-error A"; + const templateStdlibRules = ` ${bsc_flags} = ${commonBsFlags} -bs-cross-module-opt -make-runtime ${warnings} -I others ${ruleCC(ninjaCwd)} ${ninjaQuickBuildList([ @@ -996,49 +976,48 @@ ${ninjaQuickBuildList([ ], ])} `; - var stdlibDirFiles = fs.readdirSync(stdlibDir, "ascii"); - var sources = stdlibDirFiles.filter(x => { + const stdlibDirFiles = fs.readdirSync(stdlibDir, "ascii"); + const sources = stdlibDirFiles.filter(x => { return ( !x.startsWith("pervasives.") && (x.endsWith(".res") || x.endsWith(".resi")) ); }); - let depsMap = new Map(); + const depsMap = new Map(); await ocamlDepForBscAsync(sources, stdlibDir, depsMap); - var targets = collectTarget(sources); - var allTargets = scanFileTargets(targets, []); + const targets = collectTarget(sources); + const allTargets = scanFileTargets(targets, []); targets.forEach((ext, mod) => { switch (ext) { case "HAS_RESI": case "HAS_BOTH_RES": - updateDepsKVByFile(mod + ".cmi", "pervasives.cmj", depsMap); + updateDepsKVByFile(`${mod}.cmi`, "pervasives.cmj", depsMap); break; case "HAS_RES": - updateDepsKVByFile(mod + ".cmj", "pervasives.cmj", depsMap); + updateDepsKVByFile(`${mod}.cmj`, "pervasives.cmj", depsMap); break; } }); - var output = generateNinja(depsMap, targets, ninjaCwd, externalDeps); + const output = generateNinja(depsMap, targets, ninjaCwd, externalDeps); output.push(phony(stdlibTarget, fileTargets(allTargets), ninjaCwd)); writeFileAscii( path.join(stdlibDir, ninjaOutput), - templateStdlibRules + output.join("\n") + "\n", + `${templateStdlibRules + output.join("\n")}\n`, ); } /** - * * @param {string} text */ function getDeps(text) { /** * @type {string[]} */ - var deps = []; + const deps = []; text.replace( /(\/\*[\w\W]*?\*\/|\/\/[^\n]*|[.$]r)|\brequire\s*\(\s*["']([^"']*)["']\s*\)/g, - function (_, ignore, id) { + (_, ignore, id) => { if (!ignore) deps.push(id); return ""; // TODO: examine the regex }, @@ -1058,7 +1037,7 @@ function getDeps(text) { * */ function replaceExt(x, newExt) { - let index = x.lastIndexOf("."); + const index = x.lastIndexOf("."); if (index < 0) { return x; } @@ -1077,22 +1056,21 @@ function baseName(x) { * @returns {Promise} */ async function testNinja() { - var ninjaOutput = "build.ninja"; - var ninjaCwd = `test`; - var templateTestRules = ` + const ninjaOutput = "build.ninja"; + const ninjaCwd = "test"; + const templateTestRules = ` bsc_flags = -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others ${ruleCC(ninjaCwd)} `; - var testDirFiles = fs.readdirSync(testDir, "ascii"); - //testDirFiles = []; - var sources = testDirFiles.filter(x => { + const testDirFiles = fs.readdirSync(compilerTestDir, "ascii"); + const sources = testDirFiles.filter(x => { return x.endsWith(".resi") || x.endsWith(".res"); }); - let depsMap = createDepsMapWithTargets(sources); - await Promise.all(depModulesForBscAsync(sources, testDir, depsMap)); - var targets = collectTarget(sources); - var output = generateNinja(depsMap, targets, ninjaCwd, [ + const depsMap = createDepsMapWithTargets(sources); + await Promise.all(depModulesForBscAsync(sources, compilerTestDir, depsMap)); + const targets = collectTarget(sources); + const output = generateNinja(depsMap, targets, ninjaCwd, [ runtimeTarget, stdlibTarget, pseudoTarget("$bsc"), @@ -1105,8 +1083,8 @@ ${ruleCC(ninjaCwd)} ), ); writeFileAscii( - path.join(testDir, ninjaOutput), - templateTestRules + output.join("\n") + "\n", + path.join(compilerTestDir, ninjaOutput), + `${templateTestRules + output.join("\n")}\n`, ); } @@ -1116,22 +1094,24 @@ ${ruleCC(ninjaCwd)} */ function runJSCheckAsync(depsMap) { return new Promise(resolve => { - var count = 0; - var tasks = runtimeJsFiles.length; - var updateTick = () => { + let count = 0; + const tasks = runtimeJsFiles.length; + const updateTick = () => { count++; if (count === tasks) { resolve(count); } }; - runtimeJsFiles.forEach(name => { - var jsFile = path.join(jsDir, name + ".js"); - fs.readFile(jsFile, "utf8", function (err, fileContent) { + for (const name of runtimeFiles) { + const jsFile = path.join(compilerBuiltinCjsOutputDir, `${name}.js`); + fs.readFile(jsFile, "utf8", (err, fileContent) => { if (err === null) { - var deps = getDeps(fileContent).map(x => path.parse(x).name + ".cmj"); - fs.exists(path.join(runtimeDir, name + ".resi"), exist => { + const deps = getDeps(fileContent).map( + x => `${path.parse(x).name}.cmj`, + ); + fs.exists(path.join(compilerRuntimeDir, `${name}.resi`), exist => { if (exist) { - deps.push(name + ".cmi"); + deps.push(`${name}.cmi`); } updateDepsKVsByFile(`${name}.cmj`, deps, depsMap); updateTick(); @@ -1141,13 +1121,15 @@ function runJSCheckAsync(depsMap) { updateTick(); } }); - }); + } }); } function checkEffect() { - var jsPaths = runtimeJsFiles.map(x => path.join(jsDir, x + ".js")); - var effect = jsPaths + const jsPaths = runtimeJsFiles.map(x => + path.join(compilerBuiltinCjsOutputDir, `${x}.js`), + ); + const effect = jsPaths .map(x => { return { file: x, @@ -1160,27 +1142,26 @@ function checkEffect() { file, effect: "pure", }; - } else if (/Not a pure module/.test(x)) { + } + if (/Not a pure module/.test(x)) { return { file, effect: "false", }; - } else { - return { - file, - effect: "unknown", - }; } + return { + file, + effect: "unknown", + }; }) .filter(({ effect }) => effect !== "pure") .map(({ file, effect }) => { return { file: path.basename(file), effect }; }); - var black_list = new Set(["caml_lexer.js", "caml_parser.js"]); + const black_list = new Set(["caml_lexer.js", "caml_parser.js"]); - var assert = require("assert"); - // @ts-ignore + const assert = require("node:assert"); assert( effect.length === black_list.size && effect.every(x => black_list.has(x.file)), @@ -1197,7 +1178,7 @@ function updateRelease() { function updateDev() { writeFileAscii( - path.join(jscompDir, "build.ninja"), + path.join(compilerRootDir, "build.ninja"), ` stdlib = stdlib-406 ${BSC_COMPILER} @@ -1210,7 +1191,7 @@ o all: phony runtime others $stdlib test `, ); writeFileAscii( - path.join(jscompDir, "..", "lib", "build.ninja"), + path.join(compilerRootDir, "..", "lib", "build.ninja"), ` ocamlopt = ocamlopt.opt ext = exe @@ -1231,10 +1212,10 @@ exports.updateDev = updateDev; exports.updateRelease = updateRelease; function preprocessorNinjaSync() { - var dTypeString = "TYPE_STRING"; - var dTypeInt = "TYPE_INT"; + const dTypeString = "TYPE_STRING"; + const dTypeInt = "TYPE_INT"; - var cppoNative = ` + const cppoNative = ` ${cppoRule("-n")} ${cppoList("others", [ ["belt_HashSetString.res", "hashset.cppo.res", dTypeString], @@ -1275,10 +1256,10 @@ rule copy command = cp $in $out description = $in -> $out `; - var cppoNinjaFile = "cppoVendor.ninja"; - writeFileSync(path.join(jscompDir, cppoNinjaFile), cppoNative); + const cppoNinjaFile = "cppoVendor.ninja"; + writeFileSync(path.join(compilerRootDir, cppoNinjaFile), cppoNative); cp.execFileSync(vendorNinjaPath, ["-f", cppoNinjaFile, "--verbose", "-v"], { - cwd: jscompDir, + cwd: compilerRootDir, stdio: [0, 1, 2], encoding: "utf8", }); @@ -1290,13 +1271,13 @@ function main() { checkEffect(); } - var subcommand = process.argv[2]; + const subcommand = process.argv[2]; switch (subcommand) { case "build": try { cp.execFileSync(vendorNinjaPath, ["all"], { encoding: "utf8", - cwd: jscompDir, + cwd: compilerRootDir, stdio: [0, 1, 2], }); } catch (e) { @@ -1309,7 +1290,7 @@ function main() { try { cp.execFileSync(vendorNinjaPath, ["-t", "clean"], { encoding: "utf8", - cwd: jscompDir, + cwd: compilerRootDir, stdio: [0, 1], }); } catch (e) {} @@ -1323,13 +1304,13 @@ function main() { ); break; case "config": - console.log(`config for the first time may take a while`); + console.log("config for the first time may take a while"); updateDev(); updateRelease(); break; case "cleanbuild": - console.log(`run cleaning first`); + console.log("run cleaning first"); cp.execSync(`node ${__filename} clean`, { cwd: __dirname, stdio: [0, 1, 2], @@ -1357,9 +1338,9 @@ function main() { updateDev(); updateRelease(); } else { - var dev = process.argv.includes("-dev"); - var release = process.argv.includes("-release"); - var all = process.argv.includes("-all"); + const dev = process.argv.includes("-dev"); + const release = process.argv.includes("-release"); + const all = process.argv.includes("-all"); if (all) { updateDev(); updateRelease(); diff --git a/scripts/prebuilt.js b/scripts/prebuilt.js index 8862c22a93..f429bdb4b4 100755 --- a/scripts/prebuilt.js +++ b/scripts/prebuilt.js @@ -1,37 +1,25 @@ #!/usr/bin/env node -//@ts-check -const path = require("path"); -const fs = require("fs"); -const assert = require("assert"); +// @ts-check -const package_config = require(path.join(__dirname, "..", "package.json")); -const bsVersion = fs.readFileSync( - path.join(__dirname, "..", "jscomp", "common", "bs_version.ml"), - "utf-8", -); +const path = require("node:path"); +const fs = require("node:fs"); +const assert = require("node:assert"); +const semver = require("semver"); +const { compilerVersionFile } = require("#internal/paths"); +const { packageJson } = require("#internal/meta"); /** - * @param {string} bsVersion - * @param {string} version + * @param {semver.SemVer} bsVersion + * @param {semver.SemVer} version */ function verifyVersion(bsVersion, version) { - try { - let [major, minor] = bsVersion - .split("\n") - .find(x => x.startsWith("let version = ")) - .split("=")[1] - .trim() - .slice(1, -1) - .split("."); - let [specifiedMajor, specifiedMinor] = version.split("."); - console.log( - `Version check: package.json: ${specifiedMajor}.${specifiedMinor} vs ABI: ${major}.${minor}`, - ); - return major === specifiedMajor && minor === specifiedMinor; - } catch (e) { - return false; - } + const { major, minor } = bsVersion; + const { major: specifiedMajor, minor: specifiedMinor } = version; + console.log( + `Version check: package.json: ${specifiedMajor}.${specifiedMinor} vs ABI: ${major}.${minor}`, + ); + return major === specifiedMajor && minor === specifiedMinor; } /** @@ -41,16 +29,15 @@ function verifyVersion(bsVersion, version) { * @param {string} dest */ function installDirBy(src, dest, filter) { - fs.readdir(src, function (err, files) { + fs.readdir(src, (err, files) => { if (err === null) { - files.forEach(function (file) { + for (const file of files) { if (filter(file)) { - var x = path.join(src, file); - var y = path.join(dest, file); - // console.log(x, '----->', y ) + const x = path.join(src, file); + const y = path.join(dest, file); fs.copyFile(x, y, err => assert.equal(err, null)); } - }); + } } else { throw err; } @@ -70,13 +57,13 @@ function populateLibDir() { fs.mkdirSync(ocaml_dir); } - installDirBy(runtime_dir, ocaml_dir, function (file) { - var y = path.parse(file); + installDirBy(runtime_dir, ocaml_dir, file => { + const y = path.parse(file); return y.name === "js"; }); // for merlin or other IDE - var installed_suffixes = [ + const installed_suffixes = [ ".ml", ".mli", ".res", @@ -87,18 +74,32 @@ function populateLibDir() { ".cmti", ]; installDirBy(others_dir, ocaml_dir, file => { - var y = path.parse(file); + const y = path.parse(file); if (y.ext === ".cmi") { return !y.base.match(/Belt_internal/i); } return installed_suffixes.includes(y.ext) && !y.name.endsWith(".cppo"); }); installDirBy(stdlib_dir, ocaml_dir, file => { - var y = path.parse(file); + const y = path.parse(file); return installed_suffixes.includes(y.ext); }); } -assert(verifyVersion(bsVersion, package_config.version)); +const bsVersionPattern = /let version = "(?.*)"/m; +const bsVersionFileContent = fs.readFileSync(compilerVersionFile, "utf-8"); +const bsVersionMatch = bsVersionFileContent.match(bsVersionPattern)?.groups; +assert.ok(bsVersionMatch, "Failed to parse the compiler version file"); + +const bsVersion = semver.parse(bsVersionMatch.version); +assert.ok(bsVersion, "Failed to parse the compiler version file"); + +const version = semver.parse(packageJson.version); +assert.ok(version, "Failed to parse the version of the package.json"); + +assert.ok( + verifyVersion(bsVersion, version), + "Please bump versions to be matched", +); populateLibDir(); diff --git a/scripts/release.js b/scripts/release.js index 1ddacab96e..a99817e6f4 100755 --- a/scripts/release.js +++ b/scripts/release.js @@ -1,39 +1,25 @@ #!/usr/bin/env node -//@ts-check + +// @ts-check // used as a unit of releasing -var path = require("path"); -var fs = require("fs"); -var cp = require("child_process"); -var rootDir = path.join(__dirname, ".."); -var libJsDir = path.join(rootDir, "lib", "js"); -var jscompDir = path.join(rootDir, "jscomp"); -function run() { - // Note removing js file would affect `release.ninja` - // for (let file of fs.readdirSync(libJsDir)) { - // if (file.endsWith('.js')) { - // fs.unlinkSync(path.join(libJsDir, file)) - // } - // } +const path = require("node:path"); +const cp = require("node:child_process"); +const { projectDir, compilerRootDir } = require("#internal/paths"); - cp.execSync( - `git clean -dfx stubs ext common syntax depends core bsb main .`, - { cwd: jscompDir, encoding: "utf8", stdio: [0, 1, 2] }, - ); - cp.execSync(`ninja -t clean -g && ninja`, { - cwd: jscompDir, - encoding: "utf8", - stdio: [0, 1, 2], - }); - cp.execSync("ninja", { cwd: path.join(rootDir, "lib"), stdio: [0, 1, 2] }); - cp.execSync("ninja -f release.ninja -t clean && ninja -f release.ninja", { - cwd: path.join(rootDir, "jscomp"), - stdio: [0, 1, 2], - }); - require("./doc_gen").main(); -} -if (require.main === module) { - run(); -} -exports.run = run; +cp.execSync("git clean -dfx stubs ext common syntax depends core bsb main .", { + cwd: compilerRootDir, + encoding: "utf8", + stdio: [0, 1, 2], +}); +cp.execSync("ninja -t clean -g && ninja", { + cwd: compilerRootDir, + encoding: "utf8", + stdio: [0, 1, 2], +}); +cp.execSync("ninja", { cwd: path.join(projectDir, "lib"), stdio: [0, 1, 2] }); +cp.execSync("ninja -f release.ninja -t clean && ninja -f release.ninja", { + cwd: compilerRootDir, + stdio: [0, 1, 2], +}); diff --git a/scripts/setVersion.js b/scripts/setVersion.js index e0d600bfcb..3871302877 100644 --- a/scripts/setVersion.js +++ b/scripts/setVersion.js @@ -1,9 +1,9 @@ -//@ts-check -/** - * This file is used only in dev time, feel free to use es6 - */ -const fs = require("fs"); -const { execSync } = require("child_process"); +#!/usr/bin/env node + +// @ts-check + +const fs = require("node:fs"); +const { execSync } = require("node:child_process"); const packageSpec = JSON.parse(fs.readFileSync("./package.json", "utf8")); const { version, name } = packageSpec; diff --git a/tsconfig.json b/tsconfig.json index f83400749c..b3bc209b4c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,14 +9,8 @@ "strictNullChecks": true, "noImplicitAny": true, "noEmit": true, - "skipLibCheck": true, - "composite": true, - "incremental": true + "skipLibCheck": true }, - "include": ["./cli/*", "./scripts/*", "./package.json"], - "exclude": [ - "node_modules", - "./jscomp/test/**/*", - "./jscomp/gentype_tests/**/*" - ] + "include": ["cli/*", "lib/*", "scripts/**/*", "package.json"], + "exclude": ["jscomp/test/**/*", "jscomp/gentype_tests/**/*"] }