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 9fb2e69
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 65 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
44 changes: 22 additions & 22 deletions packages/prepack/src/Prepack.bs.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// 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",
Expand All @@ -23,11 +23,11 @@ var sourePaths = [
"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, "bsconfig.json"), [
"package-specs",
"module"
], "commonjs");

updateJsonFile(Path.join(artifactsPath, "bsconfig.json"), ["suffix"], ".bs.js");
updateJsonFile(Nodepath.join(artifactsPath, "bsconfig.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
10 changes: 7 additions & 3 deletions packages/prepack/src/Prepack.res
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion packages/tests/rescript.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"namespace": true,
"suffix": ".bs.mjs",
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"sources": {
Expand Down
6 changes: 2 additions & 4 deletions src/S_Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,8 @@ type exn += private Raised(error)
external castUnknownSchemaToAnySchema: t<unknown> => t<'any> = "%identity"
external toUnknown: t<'any> => t<unknown> = "%identity"

type payloadedVariant<'payload> = private {_0: 'payload}
type payloadedError<'payload> = private {_1: 'payload}
let unsafeGetVariantPayload = variant => (variant->Obj.magic)._0
let unsafeGetErrorPayload = variant => (variant->Obj.magic)._1
let unsafeGetVariantPayload = variant => (variant->Obj.magic)["_0"]
let unsafeGetErrorPayload = variant => (variant->Obj.magic)["_1"]

module InternalError = {
%%raw(`
Expand Down

0 comments on commit 9fb2e69

Please sign in to comment.