From cb9cc313b4b6940873a566c220750072e8f4fb2a Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 11 Nov 2024 19:42:13 +0100 Subject: [PATCH] Ship RescriptTools module with the rescript npm package --- lib/es6/RescriptTools.js | 13 ++++++ lib/es6/RescriptTools_Docgen.js | 11 +++++ lib/js/RescriptTools.js | 11 +++++ lib/js/RescriptTools_Docgen.js | 9 ++++ package.json | 1 + packages/artifacts.txt | 14 ++++++ {tools/npm => runtime}/RescriptTools.res | 8 ++-- .../RescriptTools_Docgen.res | 0 .../RescriptTools_Docgen.resi | 0 .../tests/src/expected/Completion.res.txt | 20 +++++++++ .../tests/src/expected/RecoveryOnProp.res.txt | 20 +++++++++ tools/binaries/.gitkeep | 0 tools/npm/cli.js | 16 ------- tools/npm/getBinaryPath.js | 19 -------- tools/package-lock.json | 43 ------------------- tools/package.json | 42 ------------------ 16 files changed, 103 insertions(+), 124 deletions(-) create mode 100644 lib/es6/RescriptTools.js create mode 100644 lib/es6/RescriptTools_Docgen.js create mode 100644 lib/js/RescriptTools.js create mode 100644 lib/js/RescriptTools_Docgen.js rename {tools/npm => runtime}/RescriptTools.res (62%) rename tools/npm/Tools_Docgen.res => runtime/RescriptTools_Docgen.res (100%) rename tools/npm/Tools_Docgen.resi => runtime/RescriptTools_Docgen.resi (100%) delete mode 100644 tools/binaries/.gitkeep delete mode 100755 tools/npm/cli.js delete mode 100644 tools/npm/getBinaryPath.js delete mode 100644 tools/package-lock.json delete mode 100644 tools/package.json diff --git a/lib/es6/RescriptTools.js b/lib/es6/RescriptTools.js new file mode 100644 index 0000000000..f76422c40f --- /dev/null +++ b/lib/es6/RescriptTools.js @@ -0,0 +1,13 @@ + + +import * as Bin_path from "../../cli/bin_path"; + +let binaryPath = Bin_path.rescript_tools_exe; + +let Docgen; + +export { + Docgen, + binaryPath, +} +/* binaryPath Not a pure module */ diff --git a/lib/es6/RescriptTools_Docgen.js b/lib/es6/RescriptTools_Docgen.js new file mode 100644 index 0000000000..66f679a790 --- /dev/null +++ b/lib/es6/RescriptTools_Docgen.js @@ -0,0 +1,11 @@ + + + +function decodeFromJson(prim) { + return prim; +} + +export { + decodeFromJson, +} +/* No side effect */ diff --git a/lib/js/RescriptTools.js b/lib/js/RescriptTools.js new file mode 100644 index 0000000000..8c8de6638f --- /dev/null +++ b/lib/js/RescriptTools.js @@ -0,0 +1,11 @@ +'use strict'; + +let Bin_path = require("../../cli/bin_path"); + +let binaryPath = Bin_path.rescript_tools_exe; + +let Docgen; + +exports.Docgen = Docgen; +exports.binaryPath = binaryPath; +/* binaryPath Not a pure module */ diff --git a/lib/js/RescriptTools_Docgen.js b/lib/js/RescriptTools_Docgen.js new file mode 100644 index 0000000000..c11bf77584 --- /dev/null +++ b/lib/js/RescriptTools_Docgen.js @@ -0,0 +1,9 @@ +'use strict'; + + +function decodeFromJson(prim) { + return prim; +} + +exports.decodeFromJson = decodeFromJson; +/* No side effect */ diff --git a/package.json b/package.json index 6b4f07f1e7..c1c9f1d857 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "bsc": "cli/bsc", "bstracing": "lib/bstracing", "rescript": "cli/rescript", + "rescript-tools": "cli/rescript-tools", "rewatch": "cli/rewatch" }, "scripts": { diff --git a/packages/artifacts.txt b/packages/artifacts.txt index 9df8ab614c..7ed7e6d183 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -185,6 +185,8 @@ lib/es6/Primitive_string_extern.js lib/es6/Primitive_util.js lib/es6/Promise.js lib/es6/RegExp.js +lib/es6/RescriptTools.js +lib/es6/RescriptTools_Docgen.js lib/es6/Result.js lib/es6/Set.js lib/es6/String.js @@ -353,6 +355,8 @@ lib/js/Primitive_string_extern.js lib/js/Primitive_util.js lib/js/Promise.js lib/js/RegExp.js +lib/js/RescriptTools.js +lib/js/RescriptTools_Docgen.js lib/js/Result.js lib/js/Set.js lib/js/String.js @@ -1134,6 +1138,16 @@ lib/ocaml/RegExp.cmt lib/ocaml/RegExp.cmti lib/ocaml/RegExp.res lib/ocaml/RegExp.resi +lib/ocaml/RescriptTools.cmi +lib/ocaml/RescriptTools.cmj +lib/ocaml/RescriptTools.cmt +lib/ocaml/RescriptTools.res +lib/ocaml/RescriptTools_Docgen.cmi +lib/ocaml/RescriptTools_Docgen.cmj +lib/ocaml/RescriptTools_Docgen.cmt +lib/ocaml/RescriptTools_Docgen.cmti +lib/ocaml/RescriptTools_Docgen.res +lib/ocaml/RescriptTools_Docgen.resi lib/ocaml/Result.cmi lib/ocaml/Result.cmj lib/ocaml/Result.cmt diff --git a/tools/npm/RescriptTools.res b/runtime/RescriptTools.res similarity index 62% rename from tools/npm/RescriptTools.res rename to runtime/RescriptTools.res index 9e2a23adde..a636f55225 100644 --- a/tools/npm/RescriptTools.res +++ b/runtime/RescriptTools.res @@ -1,4 +1,4 @@ -module Docgen = Tools_Docgen +module Docgen = RescriptTools_Docgen /** Returns the full file system path to the `rescript-tools` binary for the current platform, side stepping the JS that wraps the CLI. @@ -7,8 +7,8 @@ module Docgen = Tools_Docgen ## Examples ```rescript // Prints the current ReScript Tools version. - let stringifiedJson = ChildProcess.execFileSync(RescriptTools.getBinaryPath(), ["-v"]) + let stringifiedJson = ChildProcess.execFileSync(RescriptTools.binaryPath, ["-v"]) ``` */ -@module("./getBinaryPath.js") -external getBinaryPath: unit => string = "getBinaryPath" +@module("../../cli/bin_path.js") +external binaryPath: string = "rescript_tools_exe" diff --git a/tools/npm/Tools_Docgen.res b/runtime/RescriptTools_Docgen.res similarity index 100% rename from tools/npm/Tools_Docgen.res rename to runtime/RescriptTools_Docgen.res diff --git a/tools/npm/Tools_Docgen.resi b/runtime/RescriptTools_Docgen.resi similarity index 100% rename from tools/npm/Tools_Docgen.resi rename to runtime/RescriptTools_Docgen.resi diff --git a/tests/analysis_tests/tests/src/expected/Completion.res.txt b/tests/analysis_tests/tests/src/expected/Completion.res.txt index 85a4cf1695..da4248ef4d 100644 --- a/tests/analysis_tests/tests/src/expected/Completion.res.txt +++ b/tests/analysis_tests/tests/src/expected/Completion.res.txt @@ -1886,6 +1886,26 @@ Path Res "modulePath": "RescriptReactRouter", "filePath": "src/Completion.res" } + }, { + "label": "RescriptTools", + "kind": 9, + "tags": [], + "detail": "module RescriptTools", + "documentation": null, + "data": { + "modulePath": "RescriptTools", + "filePath": "src/Completion.res" + } + }, { + "label": "RescriptTools_Docgen", + "kind": 9, + "tags": [], + "detail": "module RescriptTools_Docgen", + "documentation": null, + "data": { + "modulePath": "RescriptTools_Docgen", + "filePath": "src/Completion.res" + } }, { "label": "Result", "kind": 9, diff --git a/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt b/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt index 9bc9a79338..042b5569db 100644 --- a/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt +++ b/tests/analysis_tests/tests/src/expected/RecoveryOnProp.res.txt @@ -35,6 +35,26 @@ Path Res "modulePath": "RescriptReactRouter", "filePath": "src/RecoveryOnProp.res" } + }, { + "label": "RescriptTools", + "kind": 9, + "tags": [], + "detail": "module RescriptTools", + "documentation": null, + "data": { + "modulePath": "RescriptTools", + "filePath": "src/RecoveryOnProp.res" + } + }, { + "label": "RescriptTools_Docgen", + "kind": 9, + "tags": [], + "detail": "module RescriptTools_Docgen", + "documentation": null, + "data": { + "modulePath": "RescriptTools_Docgen", + "filePath": "src/RecoveryOnProp.res" + } }, { "label": "Result", "kind": 9, diff --git a/tools/binaries/.gitkeep b/tools/binaries/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tools/npm/cli.js b/tools/npm/cli.js deleted file mode 100755 index 79ee7ffa14..0000000000 --- a/tools/npm/cli.js +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env node -//@ts-check -"use strict"; - -const child_process = require("child_process"); -const { getBinaryPath } = require("./getBinaryPath"); - -const args = process.argv.slice(2); - -const spawn = child_process.spawnSync(getBinaryPath(), args, { - stdio: "inherit", -}); - -if (spawn.status != null) { - process.exit(spawn.status); -} diff --git a/tools/npm/getBinaryPath.js b/tools/npm/getBinaryPath.js deleted file mode 100644 index e110a991c3..0000000000 --- a/tools/npm/getBinaryPath.js +++ /dev/null @@ -1,19 +0,0 @@ -const path = require("path"); - -function getBinaryPath() { - const platformArch = - process.arch === "x64" ? process.platform : process.platform + process.arch; - - const binPath = path.join( - __dirname, - "..", - "binaries", - platformArch, - "rescript-tools.exe", - ); - return binPath; -} - -module.exports = { - getBinaryPath, -}; diff --git a/tools/package-lock.json b/tools/package-lock.json deleted file mode 100644 index 68bf9c6632..0000000000 --- a/tools/package-lock.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "@rescript/tools", - "version": "0.6.4", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "@rescript/tools", - "version": "0.6.4", - "license": "MIT", - "dependencies": { - "rescript": "^11.0.0-rc.7" - }, - "bin": { - "rescript-tools": "npm/cli.js" - }, - "engines": { - "node": "*" - } - }, - "node_modules/rescript": { - "version": "11.0.0-rc.7", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.0.0-rc.7.tgz", - "integrity": "sha512-N2ImQVkzF4rzV5PBcQ8htKe4NPnqsS2DhtG9A4iic4eYsNim1Ixt8qyuD40WEYl4AZOuYUaEfJlvLTOV9wHogA==", - "hasInstallScript": true, - "bin": { - "bsc": "bsc", - "bstracing": "lib/bstracing", - "rescript": "rescript" - }, - "engines": { - "node": ">=10" - } - } - }, - "dependencies": { - "rescript": { - "version": "11.0.0-rc.7", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.0.0-rc.7.tgz", - "integrity": "sha512-N2ImQVkzF4rzV5PBcQ8htKe4NPnqsS2DhtG9A4iic4eYsNim1Ixt8qyuD40WEYl4AZOuYUaEfJlvLTOV9wHogA==" - } - } -} diff --git a/tools/package.json b/tools/package.json deleted file mode 100644 index 405cc49194..0000000000 --- a/tools/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "@rescript/tools", - "description": "ReScript Tools", - "version": "0.6.4", - "author": "ReScript Team", - "license": "MIT", - "bin": { - "rescript-tools": "npm/cli.js" - }, - "keywords": [ - "ReScript", - "Tools", - "Docgen" - ], - "files": [ - "npm/cli.js", - "npm/getBinaryPath.js", - "npm/*.res", - "npm/*.resi", - "binaries", - "rescript.json", - "README.md" - ], - "engines": { - "node": "*" - }, - "homepage": "https://github.com/rescript-lang/rescript-vscode/tools/README.md", - "repository": { - "type": "git", - "url": "https://github.com/rescript-lang/rescript-vscode", - "directory": "tools" - }, - "bugs": { - "url": "https://github.com/rescript-lang/rescript-vscode/issues" - }, - "scripts": { - "build": "rescript build" - }, - "dependencies": { - "rescript": "^11.0.0-rc.7" - } -}