Skip to content

Commit

Permalink
Use rescript v11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Apr 27, 2024
1 parent 4b507df commit f385409
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 70 deletions.
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -43,17 +43,17 @@
"src/S.bs.mjs",
"src/S.d.ts",
"RescriptSchema.gen.ts",
"bsconfig.json"
"rescript.json"
],
"scripts": {
"benchmark": "node ./packages/tests/src/benchmark/Benchmark.bs.mjs",
"benchmark:comparison": "node ./packages/tests/src/benchmark/comparison.js",
"coverage": "c8 --reporter=lcov npm test",
"prepack": "node ./packages/prepack/src/Prepack.bs.mjs",
"ppx:install": "node ./packages/rescript-schema-ppx/install.cjs",
"res": "rescript build -w",
"res": "rescript -w",
"res:build": "rescript build",
"test:res": "cd ./packages/tests && rescript clean && rescript build -w",
"test:res": "cd ./packages/tests && rescript clean && rescript -w",
"test": "ava",
"lint:stdlib": "rescript-stdlib-vendorer lint --project-path=packages/tests --ignore-path=src/ppx/Ppx_Primitive_test.res"
},
Expand All @@ -73,11 +73,11 @@
},
"devDependencies": {
"@dzakh/rescript-ava": "2.3.0",
"@dzakh/rescript-core": "0.2.0",
"@rescript/core": "1.3.0",
"ava": "5.2.0",
"benchmark": "2.1.4",
"c8": "7.12.0",
"rescript": "11.0.1",
"rescript": "11.1.0",
"rescript-stdlib-vendorer": "1.1.0",
"rescript-schema": ".",
"ts-expect": "1.3.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/prepack/package.json
Expand Up @@ -5,15 +5,15 @@
"type": "module",
"scripts": {
"res:build": "rescript build",
"res": "rescript build -w",
"res": "rescript -w",
"lint:stdlib": "rescript-stdlib-vendorer lint"
},
"dependencies": {
"@dzakh/rescript-core": "0.2.0",
"@rescript/core": "1.3.0",
"@rollup/plugin-replace": "5.0.2",
"execa": "7.1.1",
"rescript": "11.0.1",
"rescript-nodejs": "15.0.0",
"rescript": "11.1.0",
"rescript-nodejs": "16.1.0",
"rescript-stdlib-vendorer": "1.1.0",
"rollup": "3.21.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/prepack/rescript.json
Expand Up @@ -2,11 +2,11 @@
"name": "prepack",
"suffix": ".bs.mjs",
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"bsc-flags": ["-open RescriptCore"],
"bs-dependencies": ["@dzakh/rescript-core", "rescript-nodejs"],
"bs-dependencies": ["@rescript/core", "rescript-nodejs"],
"sources": {
"dir": "src"
},
Expand Down
46 changes: 23 additions & 23 deletions packages/prepack/src/Prepack.bs.mjs
@@ -1,33 +1,33 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Fs from "fs";
import * as Path from "path";
import * as Execa from "execa";
import * as Rollup from "rollup";
import * as Core__JSON from "@dzakh/rescript-core/src/Core__JSON.bs.mjs";
import * as Core__List from "@dzakh/rescript-core/src/Core__List.bs.mjs";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as Core__Option from "@dzakh/rescript-core/src/Core__Option.bs.mjs";
import * as Nodefs from "node:fs";
import * as Nodepath from "node:path";
import * as Core__JSON from "@rescript/core/src/Core__JSON.bs.mjs";
import * as Core__List from "@rescript/core/src/Core__List.bs.mjs";
import * as Core__Option from "@rescript/core/src/Core__Option.bs.mjs";
import PluginReplace from "@rollup/plugin-replace";

var projectPath = ".";

var artifactsPath = Path.join(projectPath, "packages/artifacts");
var artifactsPath = Nodepath.join(projectPath, "packages/artifacts");

var sourePaths = [
"package.json",
"node_modules",
"src",
"bsconfig.json",
"rescript.json",
"README.md",
"RescriptSchema.gen.ts"
];

var jsInputPath = Path.join(artifactsPath, "src/S.js");
var jsInputPath = Nodepath.join(artifactsPath, "src/S.js");

function update(json, path, value) {
var dict = Core__JSON.Decode.object(json);
var dict$1 = dict !== undefined ? Object.assign({}, Caml_option.valFromOption(dict)) : ({});
var dict$1 = dict !== undefined ? Object.assign({}, dict) : ({});
if (!path) {
return value;
}
Expand All @@ -42,28 +42,28 @@ function update(json, path, value) {
}
}

if (Fs.existsSync(artifactsPath)) {
if (Nodefs.existsSync(artifactsPath)) {
Fs.rmSync(artifactsPath, {
recursive: true,
force: true
});
}

Fs.mkdirSync(artifactsPath);
Nodefs.mkdirSync(artifactsPath);

sourePaths.forEach(function (path) {
Fs.cpSync(Path.join(projectPath, path), Path.join(artifactsPath, path), {
Fs.cpSync(Nodepath.join(projectPath, path), Nodepath.join(artifactsPath, path), {
recursive: true
});
});

function updateJsonFile(src, path, value) {
var packageJsonData = Fs.readFileSync(src, {
var packageJsonData = Nodefs.readFileSync(src, {
encoding: "utf8"
});
var packageJson = JSON.parse(packageJsonData.toString());
var updatedPackageJson = JSON.stringify(update(packageJson, Core__List.fromArray(path), value), null, 2);
Fs.writeFileSync(src, Buffer.from(updatedPackageJson), {
var updatedPackageJson = JSON.stringify(update(packageJson, Core__List.fromArray(path), value), undefined, 2);
Nodefs.writeFileSync(src, Buffer.from(updatedPackageJson), {
encoding: "utf8"
});
}
Expand All @@ -82,7 +82,7 @@ var bundle = await Rollup.rollup({

var output = [
{
file: Path.join(artifactsPath, "dist/S.js"),
file: Nodepath.join(artifactsPath, "dist/S.js"),
format: "cjs",
exports: "named",
plugins: [PluginReplace({
Expand All @@ -99,7 +99,7 @@ var output = [
})]
},
{
file: Path.join(artifactsPath, "dist/S.mjs"),
file: Nodepath.join(artifactsPath, "dist/S.mjs"),
format: "es",
exports: "named",
plugins: [PluginReplace({
Expand All @@ -118,17 +118,17 @@ for(var idx = 0 ,idx_finish = output.length; idx < idx_finish; ++idx){

await bundle.close();

Fs.rmSync(Path.join(artifactsPath, "lib"), {
Fs.rmSync(Nodepath.join(artifactsPath, "lib"), {
recursive: true,
force: true
});

updateJsonFile(Path.join(artifactsPath, "bsconfig.json"), [
updateJsonFile(Nodepath.join(artifactsPath, "rescript.json"), [
"package-specs",
"module"
], "commonjs");

updateJsonFile(Path.join(artifactsPath, "bsconfig.json"), ["suffix"], ".bs.js");
updateJsonFile(Nodepath.join(artifactsPath, "rescript.json"), ["suffix"], ".bs.js");

Execa.execaSync("npm", [
"run",
Expand All @@ -137,14 +137,14 @@ Execa.execaSync("npm", [
cwd: artifactsPath
});

updateJsonFile(Path.join(artifactsPath, "package.json"), ["type"], "commonjs");
updateJsonFile(Nodepath.join(artifactsPath, "package.json"), ["type"], "commonjs");

Fs.rmSync(Path.join(artifactsPath, "lib"), {
Fs.rmSync(Nodepath.join(artifactsPath, "lib"), {
recursive: true,
force: true
});

Fs.rmSync(Path.join(artifactsPath, "node_modules"), {
Fs.rmSync(Nodepath.join(artifactsPath, "node_modules"), {
recursive: true,
force: true
});
Expand Down
16 changes: 10 additions & 6 deletions packages/prepack/src/Prepack.res
Expand Up @@ -4,7 +4,7 @@ let sourePaths = [
"package.json",
"node_modules",
"src",
"bsconfig.json",
"rescript.json",
"README.md",
"RescriptSchema.gen.ts",
]
Expand Down Expand Up @@ -126,15 +126,19 @@ sourePaths->Array.forEach(path => {
let updateJsonFile = (~src, ~path, ~value) => {
let packageJsonData = NodeJs.Fs.readFileSyncWith(
src,
NodeJs.Fs.readFileOptions(~encoding="utf8", ()),
{
encoding: "utf8",
},
)
let packageJson = packageJsonData->NodeJs.Buffer.toString->JSON.parseExn
let updatedPackageJson =
packageJson->Stdlib.Json.update(path->List.fromArray, value)->JSON.stringifyWithIndent(2)
packageJson->Stdlib.Json.update(path->List.fromArray, value)->JSON.stringify(~space=2)
NodeJs.Fs.writeFileSyncWith(
src,
updatedPackageJson->NodeJs.Buffer.fromString,
NodeJs.Fs.writeFileOptions(~encoding="utf8", ()),
{
encoding: "utf8",
},
)
}

Expand Down Expand Up @@ -175,12 +179,12 @@ await bundle->Rollup.Bundle.close
// Clean up rescript artifacts so the compiled .bs.js files aren't removed on the .bs.mjs build
FsX.rmSync(NodeJs.Path.join2(artifactsPath, "lib"), {force: true, recursive: true})
updateJsonFile(
~src=NodeJs.Path.join2(artifactsPath, "bsconfig.json"),
~src=NodeJs.Path.join2(artifactsPath, "rescript.json"),
~path=["package-specs", "module"],
~value=JSON.Encode.string("commonjs"),
)
updateJsonFile(
~src=NodeJs.Path.join2(artifactsPath, "bsconfig.json"),
~src=NodeJs.Path.join2(artifactsPath, "rescript.json"),
~path=["suffix"],
~value=JSON.Encode.string(".bs.js"),
)
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/rescript.json
Expand Up @@ -8,7 +8,7 @@
}
],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".bs.mjs",
Expand Down
54 changes: 30 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bsconfig.json → rescript.json
Expand Up @@ -3,7 +3,7 @@
"namespace": true,
"suffix": ".bs.mjs",
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"sources": {
Expand Down

1 comment on commit f385409

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f385409 Previous: 9fb2e69 Ratio
Parse string 819804757 ops/sec (±0.13%) 819064824 ops/sec (±0.11%) 1.00
Serialize string 820460554 ops/sec (±0.09%) 819779932 ops/sec (±0.08%) 1.00
Advanced object schema factory 433593 ops/sec (±0.49%) 431262 ops/sec (±0.44%) 0.99
Parse advanced object 46945294 ops/sec (±0.29%) 46671133 ops/sec (±0.42%) 0.99
Create and parse advanced object 33852 ops/sec (±1.29%) 34129 ops/sec (±0.58%) 1.01
Parse advanced strict object 22458821 ops/sec (±0.25%) 22262984 ops/sec (±0.24%) 0.99
Serialize advanced object 808680656 ops/sec (±0.18%) 807737293 ops/sec (±0.20%) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.