Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ReScript v12 #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript-schema",
"version": "9.3.0",
"version": "9.3.0-rescript12.0",
"private": true,
"description": "🧬 The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX",
"keywords": [
Expand Down Expand Up @@ -75,11 +75,10 @@
},
"devDependencies": {
"@dzakh/rescript-ava": "2.3.0",
"@rescript/core": "^1.3.0",
"ava": "5.2.0",
"benchmark": "2.1.4",
"c8": "7.12.0",
"rescript": "11.1.0",
"rescript": "12.0.0-alpha.8",
"rescript-stdlib-vendorer": "1.1.0",
"rescript-schema": "link:",
"ts-expect": "1.3.0",
Expand All @@ -90,7 +89,7 @@
"arktype": "2.0.4"
},
"peerDependencies": {
"rescript": "11.x"
"rescript": "^12.0.0-alpha.8"
},
"peerDependenciesMeta": {
"rescript": {
Expand Down
3 changes: 1 addition & 2 deletions packages/prepack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
"lint:stdlib": "rescript-stdlib-vendorer lint"
},
"dependencies": {
"@rescript/core": "1.3.0",
"@rollup/plugin-node-resolve": "16.0.0",
"execa": "7.1.1",
"rescript": "11.1.0",
"rescript": "12.0.0-alpha.7",
"rescript-nodejs": "16.1.0",
"rescript-stdlib-vendorer": "1.1.0",
"rollup": "3.21.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/prepack/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"module": "esmodule",
"in-source": true
},
"bsc-flags": ["-open RescriptCore"],
"bs-dependencies": ["@rescript/core", "rescript-nodejs"],
"bs-dependencies": ["rescript-nodejs"],
"sources": {
"dir": "src"
},
Expand Down
21 changes: 8 additions & 13 deletions packages/prepack/src/Prepack.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@ let sourePaths = [
]

module Stdlib = {
module Dict = {
@val
external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
}

module Json = {
let rec update = (json, path, value) => {
let dict = switch json->JSON.Decode.object {
| Some(dict) => dict->Dict.copy
| None => RescriptCore.Dict.make()
| None => Dict.make()
}
switch path {
| list{} => value
| list{key} => {
dict->RescriptCore.Dict.set(key, value)
dict->Dict.set(key, value)
dict->JSON.Encode.object
}
| list{key, ...path} => {
dict->RescriptCore.Dict.set(
dict->Dict.set(
key,
dict
->RescriptCore.Dict.get(key)
->Option.getOr(RescriptCore.Dict.make()->JSON.Encode.object)
->Dict.get(key)
->Option.getOr(Dict.make()->JSON.Encode.object)
->update(path, value),
)
dict->JSON.Encode.object
Expand Down Expand Up @@ -75,7 +70,7 @@ module Rollup = {
input?: string,
plugins?: array<Plugin.t>,
@as("external")
external_?: array<Re.t>,
external_?: array<RegExp.t>,
}
}

Expand Down Expand Up @@ -118,8 +113,8 @@ let filesMapping = [
("Error", "S.$$Error.$$class"),
("string", "S.string"),
("boolean", "S.bool"),
("int32", "S.$$int"),
("number", "S.$$float"),
("int32", "S.int"),
("number", "S.float"),
("bigint", "S.bigint"),
("json", "S.json"),
("never", "S.never"),
Expand Down
115 changes: 54 additions & 61 deletions packages/prepack/src/Prepack.res.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Fs from "fs";
import * as $$JSON from "rescript/lib/es6/JSON.js";
import * as List from "rescript/lib/es6/List.js";
import * as Execa from "execa";
import * as Option from "rescript/lib/es6/Option.js";
import * as Rollup from "rollup";
import * as Nodefs from "node:fs";
import * as Nodepath from "node:path";
import * as Core__JSON from "@rescript/core/src/Core__JSON.res.mjs";
import * as Core__List from "@rescript/core/src/Core__List.res.mjs";
import * as Core__Option from "@rescript/core/src/Core__Option.res.mjs";
import * as PluginNodeResolve from "@rollup/plugin-node-resolve";

var projectPath = ".";
let projectPath = ".";

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

var sourePaths = [
let sourePaths = [
"package.json",
"node_modules",
"src",
Expand All @@ -24,15 +24,15 @@ var sourePaths = [
];

function update(json, path, value) {
var dict = Core__JSON.Decode.object(json);
var dict$1 = dict !== undefined ? Object.assign({}, dict) : ({});
let dict = $$JSON.Decode.object(json);
let dict$1 = dict !== undefined ? Object.assign({}, dict) : ({});
if (!path) {
return value;
}
var path$1 = path.tl;
var key = path.hd;
let path$1 = path.tl;
let key = path.hd;
if (path$1) {
dict$1[key] = update(Core__Option.getOr(dict$1[key], {}), path$1, value);
dict$1[key] = update(Option.getOr(dict$1[key], {}), path$1, value);
return dict$1;
} else {
dict$1[key] = value;
Expand All @@ -42,14 +42,14 @@ function update(json, path, value) {

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

Nodefs.mkdirSync(artifactsPath);

var filesMapping = [
let filesMapping = [
[
"Error",
"S.$$Error.$$class"
Expand All @@ -64,11 +64,11 @@ var filesMapping = [
],
[
"int32",
"S.$$int"
"S.int"
],
[
"number",
"S.$$float"
"S.float"
],
[
"bigint",
Expand Down Expand Up @@ -336,58 +336,54 @@ var filesMapping = [
]
];

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

function writeSjsEsm(path) {
Nodefs.writeFileSync(path, Buffer.from(["import * as S from \"./S_Core.res.mjs\";"].concat(filesMapping.map(function (param) {
return "export const " + param[0] + " = " + param[1];
})).join("\n")), {
encoding: "utf8"
});
Nodefs.writeFileSync(path, Buffer.from(["import * as S from \"./S_Core.res.mjs\";"].concat(filesMapping.map(param => "export const " + param[0] + " = " + param[1])).join("\n")), {
encoding: "utf8"
});
}

writeSjsEsm("./src/S.js");

writeSjsEsm(Nodepath.join(artifactsPath, "./src/S.mjs"));

Nodefs.writeFileSync(Nodepath.join(artifactsPath, "./src/S.js"), Buffer.from(["var S = require(\"./S_Core.res.js\");"].concat(filesMapping.map(function (param) {
return "exports." + param[0] + " = " + param[1];
})).join("\n")), {
encoding: "utf8"
});
Nodefs.writeFileSync(Nodepath.join(artifactsPath, "./src/S.js"), Buffer.from(["var S = require(\"./S_Core.res.js\");"].concat(filesMapping.map(param => "exports." + param[0] + " = " + param[1])).join("\n")), {
encoding: "utf8"
});

function updateJsonFile(src, path, value) {
var packageJsonData = Nodefs.readFileSync(src, {
encoding: "utf8"
});
var packageJson = JSON.parse(packageJsonData.toString());
var updatedPackageJson = JSON.stringify(update(packageJson, Core__List.fromArray(path), value), undefined, 2);
let packageJsonData = Nodefs.readFileSync(src, {
encoding: "utf8"
});
let packageJson = JSON.parse(packageJsonData.toString());
let updatedPackageJson = JSON.stringify(update(packageJson, List.fromArray(path), value), undefined, 2);
Nodefs.writeFileSync(src, Buffer.from(updatedPackageJson), {
encoding: "utf8"
});
encoding: "utf8"
});
}

Execa.execaSync("npm", [
"run",
"res:build"
], {
cwd: artifactsPath
});
"run",
"res:build"
], {
cwd: artifactsPath
});

async function resolveRescriptRuntime(format, input, output) {
var bundle = await Rollup.rollup({
input: Nodepath.join(artifactsPath, input),
plugins: [PluginNodeResolve.nodeResolve()]
});
let bundle = await Rollup.rollup({
input: Nodepath.join(artifactsPath, input),
plugins: [PluginNodeResolve.nodeResolve()]
});
await bundle.write({
file: Nodepath.join(artifactsPath, output),
format: format,
exports: "named"
});
file: Nodepath.join(artifactsPath, output),
format: format,
exports: "named"
});
return await bundle.close();
}

Expand All @@ -402,16 +398,13 @@ updateJsonFile(Nodepath.join(artifactsPath, "package.json"), ["type"], "commonjs
updateJsonFile(Nodepath.join(artifactsPath, "package.json"), ["private"], false);

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

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

export {

}
/* artifactsPath Not a pure module */
2 changes: 1 addition & 1 deletion packages/tests/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"suffix": ".res.mjs",
"bs-dependencies": ["rescript-schema"],
"bs-dev-dependencies": ["@rescript/core", "@dzakh/rescript-ava"],
"bs-dev-dependencies": ["@dzakh/rescript-ava"],
"ppx-flags": ["../rescript-schema-ppx/bin"],
"bsc-flags": ["-open RescriptSchema"],
"warnings": {
Expand Down
2 changes: 0 additions & 2 deletions packages/tests/src/benchmark/Benchmark.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open RescriptCore

module Suite = {
module BenchmarkResult = {
type t
Expand Down
Loading
Loading