diff --git a/examples/client-rendering/.gitignore b/examples/client-rendering/.gitignore index 1616ca9..2cbf765 100644 --- a/examples/client-rendering/.gitignore +++ b/examples/client-rendering/.gitignore @@ -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__/** diff --git a/examples/client-rendering/index.html b/examples/client-rendering/index.html index 67a18a2..64d795b 100644 --- a/examples/client-rendering/index.html +++ b/examples/client-rendering/index.html @@ -1,23 +1,20 @@ - - - - - Test - - - - -
- - - + + + + + + Test + + + + + +
+ + + + \ No newline at end of file diff --git a/examples/client-rendering/rescript.json b/examples/client-rendering/rescript.json index c7b6faa..0bdd4b3 100644 --- a/examples/client-rendering/rescript.json +++ b/examples/client-rendering/rescript.json @@ -18,7 +18,7 @@ "in-source": true } ], - "suffix": ".mjs", + "suffix": ".res.mjs", "ppx-flags": [["rescript-relay/ppx", "-uncurried"]], "bs-dependencies": [ "@rescript/react", diff --git a/examples/express/.gitignore b/examples/express/.gitignore index 1616ca9..2cbf765 100644 --- a/examples/express/.gitignore +++ b/examples/express/.gitignore @@ -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__/** diff --git a/examples/express/Server.res b/examples/express/Server.res index 0847dd3..a8837c8 100644 --- a/examples/express/Server.res +++ b/examples/express/Server.res @@ -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) @@ -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: []})]), diff --git a/examples/express/package.json b/examples/express/package.json index db7c0ef..f859b3d 100644 --- a/examples/express/package.json +++ b/examples/express/package.json @@ -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", diff --git a/examples/express/rescript.json b/examples/express/rescript.json index 73eaa2b..9d35749 100644 --- a/examples/express/rescript.json +++ b/examples/express/rescript.json @@ -19,7 +19,7 @@ "in-source": true } ], - "suffix": ".mjs", + "suffix": ".res.mjs", "ppx-flags": [["rescript-relay/ppx", "-uncurried"]], "bs-dependencies": [ "@rescript/react", diff --git a/examples/express/vite.config.js b/examples/express/vite.config.js index e9d7e50..dc13027 100644 --- a/examples/express/vite.config.js +++ b/examples/express/vite.config.js @@ -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({ diff --git a/packages/rescript-relay-router/.gitignore b/packages/rescript-relay-router/.gitignore index 2482fce..54a4033 100644 --- a/packages/rescript-relay-router/.gitignore +++ b/packages/rescript-relay-router/.gitignore @@ -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 \ No newline at end of file diff --git a/packages/rescript-relay-router/rescript.json b/packages/rescript-relay-router/rescript.json index ca7c18f..754b667 100644 --- a/packages/rescript-relay-router/rescript.json +++ b/packages/rescript-relay-router/rescript.json @@ -32,7 +32,7 @@ "in-source": true } ], - "suffix": ".mjs", + "suffix": ".res.mjs", "bs-dependencies": ["@rescript/react", "rescript-relay", "@rescript/core"], "bsc-flags": ["-open RescriptCore"] } diff --git a/packages/rescript-relay-router/rollup.config.js b/packages/rescript-relay-router/rollup.config.js index 3ae56a9..2aa0b6d 100644 --- a/packages/rescript-relay-router/rollup.config.js +++ b/packages/rescript-relay-router/rollup.config.js @@ -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", diff --git a/packages/rescript-relay-router/vite-plugins/RescriptRelayServerVitePlugin.mjs b/packages/rescript-relay-router/vite-plugins/RescriptRelayServerVitePlugin.mjs index a1d53ba..7d57047 100644 --- a/packages/rescript-relay-router/vite-plugins/RescriptRelayServerVitePlugin.mjs +++ b/packages/rescript-relay-router/vite-plugins/RescriptRelayServerVitePlugin.mjs @@ -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"; @@ -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. diff --git a/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin.mjs b/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin.mjs index 3d9bf9c..94e931c 100644 --- a/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin.mjs +++ b/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin.mjs @@ -1,4 +1,4 @@ -import { runCli } from "../cli/RescriptRelayRouterCli__Commands.mjs"; +import { runCli } from "../cli/RescriptRelayRouterCli__Commands.res.mjs"; /** * @typedef {import("vite").ResolvedConfig} ResolvedConfig diff --git a/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin__ManifestTransform.mjs b/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin__ManifestTransform.mjs deleted file mode 100644 index e898b51..0000000 --- a/packages/rescript-relay-router/vite-plugins/RescriptRelayVitePlugin__ManifestTransform.mjs +++ /dev/null @@ -1,57 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Fs from "fs"; -import * as Core__Array from "@rescript/core/src/Core__Array.mjs"; -import * as RelayRouter__Manifest from "../src/RelayRouter__Manifest.mjs"; - -function viteManifestToRelayRouterManifest(manifest) { - var orEmptyArray = function (nullableArray) { - if (nullableArray === null || nullableArray === undefined) { - if (nullableArray === null) { - return []; - } else { - return []; - } - } else { - return nullableArray; - } - }; - var getFile = function (import_) { - return "/" + manifest[import_].file; - }; - return { - entryPoint: "/" + manifest["index.html"].file, - files: Object.fromEntries(Core__Array.filterMap(Object.entries(manifest), (function (param) { - var chunk = param[1]; - if (!(chunk.isEntry == null) || !(chunk.isDynamicEntry == null)) { - return [ - getFile(param[0]), - { - imports: orEmptyArray(chunk.imports).map(getFile), - css: orEmptyArray(chunk.css), - assets: orEmptyArray(chunk.assets) - } - ]; - } - - }))) - }; -} - -function loadViteManifest(path) { - return JSON.parse(Fs.readFileSync(path, "utf-8")); -} - -function transformManifest(inPath, outPath) { - var viteManifest = loadViteManifest(inPath); - var routerManifest = viteManifestToRelayRouterManifest(viteManifest); - var __x = (function (__x) { - return RelayRouter__Manifest.stringifyWithSpace(__x, 2); - })(routerManifest); - Fs.writeFileSync(outPath, __x, "utf-8"); -} - -export { - transformManifest , -} -/* fs Not a pure module */