Skip to content

Commit

Permalink
use .res.mjs for JS files generated by rescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnobip committed Jan 6, 2025
1 parent 1c95d8d commit aba8451
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 100 deletions.
2 changes: 1 addition & 1 deletion examples/client-rendering/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lib
# Ignore build output
dist
stats.html
*.mjs
*.res.mjs

# Ignore generated files but allow keeping the folder itself.
src/__generated__/**
Expand Down
39 changes: 18 additions & 21 deletions examples/client-rendering/index.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#043062" />
<title>Test</title>
<link
href="https://fonts.googleapis.com/css2?family=Barlow:wght@400;700&display=swap"
rel="stylesheet"
/>
</head>
<body class="bg-gray-50 font-sans leading-normal tracking-normal">
<script type="text/javascript">
window.global = window;
</script>
<div id="root"></div>
<script type="module" src="/src/EntryClient.mjs"></script>
</body>
</html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="theme-color" content="#043062" />
<title>Test</title>
<link href="https://fonts.googleapis.com/css2?family=Barlow:wght@400;700&display=swap" rel="stylesheet" />
</head>

<body class="bg-gray-50 font-sans leading-normal tracking-normal">
<script type="text/javascript">
window.global = window;
</script>
<div id="root"></div>
<script type="module" src="/src/EntryClient.res.mjs"></script>
</body>

</html>
2 changes: 1 addition & 1 deletion examples/client-rendering/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"in-source": true
}
],
"suffix": ".mjs",
"suffix": ".res.mjs",
"ppx-flags": [["rescript-relay/ppx", "-uncurried"]],
"bs-dependencies": [
"@rescript/react",
Expand Down
2 changes: 1 addition & 1 deletion examples/express/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lib
# Ignore build output
dist
stats.html
*.mjs
*.res.mjs

# Ignore generated files but allow keeping the folder itself.
src/__generated__/**
Expand Down
6 changes: 3 additions & 3 deletions examples/express/Server.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ switch NodeJs.isProduction {
let manifest = loadRouterManifest()

// Load our compiled production server entry.
import_("./dist/server/EntryServer.js")
import_("./dist/server/EntryServer.res.js")
->Promise.thenResolve(entryServer => {
module EntryServer = unpack(entryServer)

Expand Down Expand Up @@ -51,13 +51,13 @@ switch NodeJs.isProduction {
// Load the dev server entry point through Vite within the route handler so it's automatically
// recompiled when any of the code changes (Vite caches it for us).
vite
->ssrLoadModule("/src/EntryServer.mjs")
->ssrLoadModule("/src/EntryServer.res.mjs")
->Promise.then(
(entryServer: module(EntryServer)) => {
open RelayRouter.Manifest
module EntryServer = unpack(entryServer)

let entryPoint = "/src/EntryClient.mjs"
let entryPoint = "/src/EntryClient.res.mjs"
let manifest = {
entryPoint,
files: Dict.fromArray([(entryPoint, {imports: [], css: [], assets: []})]),
Expand Down
4 changes: 2 additions & 2 deletions examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"build:rescript": "rescript build -with-deps",
"build:vite": "run-s 'build:vite:*'",
"build:vite:client": "vite build --outDir dist/client --ssrManifest --manifest",
"build:vite:server": "vite build --outDir dist/server --ssr src/EntryServer.mjs",
"build:vite:server-fix": "perl -i -pe 's/import \\* as ReactRelay/import ReactRelay/' dist/server/EntryServer.js dist/server/assets/*.js",
"build:vite:server": "vite build --outDir dist/server --ssr src/EntryServer.res.mjs",
"build:vite:server-fix": "perl -i -pe 's/import \\* as ReactRelay/import ReactRelay/' dist/server/EntryServer.res.js dist/server/assets/*.js",
"preview": "cross-env ENABLE_FILESERVER=true yarn start",
"start": "cross-env NODE_ENV=production node Server.mjs",
"router:generate": "rescript-relay-router generate",
Expand Down
2 changes: 1 addition & 1 deletion examples/express/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"in-source": true
}
],
"suffix": ".mjs",
"suffix": ".res.mjs",
"ppx-flags": [["rescript-relay/ppx", "-uncurried"]],
"bs-dependencies": [
"@rescript/react",
Expand Down
2 changes: 1 addition & 1 deletion examples/express/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { virtualIndex } from "rescript-relay-router/VirtualIndex.mjs";
export default defineConfig({
base: process.env.APP_PATH ?? "/",
plugins: [
virtualIndex({ entryClient: "/src/EntryClient.mjs" }),
virtualIndex({ entryClient: "/src/EntryClient.res.mjs" }),
reactRefresh(),
process.env.NODE_ENV !== "test"
? rescriptRelayVitePlugin({
Expand Down
11 changes: 6 additions & 5 deletions packages/rescript-relay-router/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ lib
.bsb.lock
.merlin

# Ignore build output
dist
stats.html
*.mjs

# Commit the PreloadInsertingStreamNode as it has no ReScript source file.
!src/PreloadInsertingStreamNode.mjs

# Commit our Vite plugins written in plain JavaScript.
!vite-plugins/**/*.mjs
!test/RescriptRelayServerVitePlugin.test.mjs

# Ignore build output
dist
stats.html
*.res.mjs
*.bundle.mjs
2 changes: 1 addition & 1 deletion packages/rescript-relay-router/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"in-source": true
}
],
"suffix": ".mjs",
"suffix": ".res.mjs",
"bs-dependencies": ["@rescript/react", "rescript-relay", "@rescript/core"],
"bsc-flags": ["-open RescriptCore"]
}
2 changes: 1 addition & 1 deletion packages/rescript-relay-router/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import resolve from "@rollup/plugin-node-resolve";

export default [
{
input: "cli/RescriptRelayRouterCli.mjs",
input: "cli/RescriptRelayRouterCli.res.mjs",
output: {
file: "cli/RescriptRelayRouterCli.bundle.mjs",
format: "esm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import path from "path";
import readline from "readline";
import MagicString from "magic-string";
import { normalizePath } from "vite";
import { runCli } from "../cli/RescriptRelayRouterCli__Commands.mjs";
import { transformManifest } from "./RescriptRelayVitePlugin__ManifestTransform.mjs";
import { runCli } from "../cli/RescriptRelayRouterCli__Commands.res.mjs";
import { transformManifest } from "./RescriptRelayVitePlugin__ManifestTransform.res.mjs";

const ROUTER_MANIFEST_NAME = "routerManifest.json";

Expand Down Expand Up @@ -333,12 +333,12 @@ function replaceAsyncWithMagicString(string, searchValue, replacer) {
}
try {
var values = [];
String.prototype.replace.call(string, searchValue, function() {
String.prototype.replace.call(string, searchValue, function () {
values.push(replacer.apply(undefined, arguments));
return "";
});
let mapTrackingString = new MagicString(string);
return Promise.all(values).then(function(resolvedValues) {
return Promise.all(values).then(function (resolvedValues) {
// Call replace again, this time on the string that tracks a sourcemap.
// We use the replacerFunction so each occurrence can be replaced by the
// previously resolved value for that index.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runCli } from "../cli/RescriptRelayRouterCli__Commands.mjs";
import { runCli } from "../cli/RescriptRelayRouterCli__Commands.res.mjs";

/**
* @typedef {import("vite").ResolvedConfig} ResolvedConfig
Expand Down

This file was deleted.

0 comments on commit aba8451

Please sign in to comment.