Skip to content

Commit 5049771

Browse files
hyperpolymathclaude
andcommitted
feat(rescript): vite.config.res CLI wrapper + Deno starter (no npm)
rescript-vite-config: - CLI wrapper enabling vite.config.res (Vite rejected native support) - Compiles ReScript config → JS bridge → invokes Vite → cleans up - Works with rescript, rescript-legacy, and Deno-based ReScript - npx rescript-vite-config dev/build/preview rescript-deno-starter: - Create ReScript projects with Deno, zero npm dependency - deno run cli.js init my-app → generates deno.json + rescript.json - deno task build/dev/clean — no npm install, no node_modules - Uses Deno npm: specifiers for @rescript/core and compiler Both target awesome-rescript submission after testing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1aa11ce commit 5049771

6 files changed

Lines changed: 528 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# rescript-deno
2+
3+
Start ReScript projects with Deno, not npm.
4+
5+
## Why
6+
7+
ReScript's compiler ships as an npm package, but your project doesn't need npm. This tool wraps `rescript` to work natively with Deno's module system — no `npm install`, no `node_modules` sprawl, no `package.json`.
8+
9+
## Install
10+
11+
```bash
12+
# No install needed — run directly:
13+
deno run -A https://raw.githubusercontent.com/hyperpolymath/developer-ecosystem/main/rescript-ecosystem/rescript-deno-starter/src/cli.js init my-app
14+
```
15+
16+
## Usage
17+
18+
```bash
19+
# Create a new project
20+
rescript-deno init my-app
21+
cd my-app
22+
23+
# Build
24+
deno task build
25+
26+
# Watch mode
27+
deno task dev
28+
29+
# Run
30+
deno run src/Main.res.mjs
31+
32+
# Clean
33+
deno task res:clean
34+
```
35+
36+
## What it generates
37+
38+
```
39+
my-app/
40+
├── deno.json # Deno config with ReScript tasks
41+
├── rescript.json # ReScript compiler config (esmodule, in-source)
42+
├── src/
43+
│ └── Main.res # Entry point
44+
└── .gitignore
45+
```
46+
47+
The generated `deno.json` maps `@rescript/core` and `@rescript/runtime` to npm packages via Deno's npm specifier support. No `package.json` needed.
48+
49+
## How it works
50+
51+
Deno can import npm packages directly via `npm:` specifiers. The ReScript compiler runs through `deno run npm:rescript`, and the compiled `.res.mjs` output is native ES modules that Deno runs directly.
52+
53+
## License
54+
55+
PMPL-1.0-or-later
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@hyperpolymath/rescript-deno",
3+
"version": "1.0.0",
4+
"exports": "./src/cli.js",
5+
"tasks": {
6+
"start": "deno run --allow-run --allow-read --allow-write --allow-env --allow-net src/cli.js"
7+
}
8+
}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write --allow-env --allow-net
2+
// SPDX-License-Identifier: PMPL-1.0-or-later
3+
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath)
4+
//
5+
// rescript-deno — Start ReScript projects with Deno, not npm.
6+
//
7+
// Wraps the ReScript compiler to work natively with Deno's module system.
8+
// No npm, no node_modules (unless --node-modules-dir is needed for ReScript).
9+
//
10+
// Usage:
11+
// deno run -A jsr:@hyperpolymath/rescript-deno init my-app
12+
// deno run -A jsr:@hyperpolymath/rescript-deno build
13+
// deno run -A jsr:@hyperpolymath/rescript-deno dev
14+
// deno run -A jsr:@hyperpolymath/rescript-deno clean
15+
16+
const VERSION = "1.0.0";
17+
18+
// --- Templates ---
19+
20+
const DENO_JSON_TEMPLATE = `{
21+
"imports": {
22+
"@rescript/core": "npm:@rescript/core@1.6.1",
23+
"@rescript/runtime": "npm:@rescript/runtime@12.2.0",
24+
"rescript": "npm:rescript@12.2.0"
25+
},
26+
"tasks": {
27+
"res:build": "deno run --node-modules-dir=auto --allow-read --allow-write --allow-env --allow-run npm:rescript@12.2.0",
28+
"res:dev": "deno run --node-modules-dir=auto --allow-read --allow-write --allow-env --allow-run npm:rescript@12.2.0 -w",
29+
"res:clean": "deno run --node-modules-dir=auto --allow-read --allow-write --allow-env --allow-run npm:rescript@12.2.0 clean",
30+
"dev": "deno task res:dev",
31+
"build": "deno task res:build"
32+
}
33+
}
34+
`;
35+
36+
const RESCRIPT_JSON_TEMPLATE = `{
37+
"name": "{{NAME}}",
38+
"sources": [{"dir": "src", "subdirs": true}],
39+
"package-specs": [{"module": "esmodule", "in-source": true}],
40+
"suffix": ".res.mjs",
41+
"compiler-flags": ["-open RescriptCore"],
42+
"dependencies": ["@rescript/core"]
43+
}
44+
`;
45+
46+
const MAIN_RES_TEMPLATE = `// SPDX-License-Identifier: PMPL-1.0-or-later
47+
// {{NAME}} — entry point
48+
49+
let greeting = "Hello from ReScript on Deno!"
50+
51+
Console.log(greeting)
52+
Console.log("No npm required.")
53+
`;
54+
55+
const GITIGNORE_TEMPLATE = `node_modules/
56+
.deno/
57+
*.res.mjs
58+
lib/
59+
`;
60+
61+
// --- Commands ---
62+
63+
async function init(name) {
64+
if (!name) {
65+
console.error("Usage: rescript-deno init <project-name>");
66+
Deno.exit(1);
67+
}
68+
69+
console.log(`Creating ReScript + Deno project: ${name}`);
70+
71+
await Deno.mkdir(`${name}/src`, { recursive: true });
72+
73+
await Deno.writeTextFile(`${name}/deno.json`, DENO_JSON_TEMPLATE);
74+
await Deno.writeTextFile(
75+
`${name}/rescript.json`,
76+
RESCRIPT_JSON_TEMPLATE.replaceAll("{{NAME}}", name)
77+
);
78+
await Deno.writeTextFile(
79+
`${name}/src/Main.res`,
80+
MAIN_RES_TEMPLATE.replaceAll("{{NAME}}", name)
81+
);
82+
await Deno.writeTextFile(`${name}/.gitignore`, GITIGNORE_TEMPLATE);
83+
84+
console.log(`
85+
Done! Next steps:
86+
87+
cd ${name}
88+
deno task build # compile ReScript
89+
deno run src/Main.res.mjs # run it
90+
91+
No npm install needed. Deno handles everything.
92+
`);
93+
}
94+
95+
async function build() {
96+
console.log("[rescript-deno] Building...");
97+
const cmd = new Deno.Command("deno", {
98+
args: [
99+
"run",
100+
"--node-modules-dir=auto",
101+
"--allow-read",
102+
"--allow-write",
103+
"--allow-env",
104+
"--allow-run",
105+
"npm:rescript@12.2.0",
106+
],
107+
stdout: "inherit",
108+
stderr: "inherit",
109+
});
110+
const { code } = await cmd.output();
111+
Deno.exit(code);
112+
}
113+
114+
async function dev() {
115+
console.log("[rescript-deno] Starting watch mode...");
116+
const cmd = new Deno.Command("deno", {
117+
args: [
118+
"run",
119+
"--node-modules-dir=auto",
120+
"--allow-read",
121+
"--allow-write",
122+
"--allow-env",
123+
"--allow-run",
124+
"npm:rescript@12.2.0",
125+
"-w",
126+
],
127+
stdout: "inherit",
128+
stderr: "inherit",
129+
});
130+
const { code } = await cmd.output();
131+
Deno.exit(code);
132+
}
133+
134+
async function clean() {
135+
console.log("[rescript-deno] Cleaning build artifacts...");
136+
const cmd = new Deno.Command("deno", {
137+
args: [
138+
"run",
139+
"--node-modules-dir=auto",
140+
"--allow-read",
141+
"--allow-write",
142+
"--allow-env",
143+
"--allow-run",
144+
"npm:rescript@12.2.0",
145+
"clean",
146+
],
147+
stdout: "inherit",
148+
stderr: "inherit",
149+
});
150+
const { code } = await cmd.output();
151+
Deno.exit(code);
152+
}
153+
154+
// --- Main ---
155+
156+
const command = Deno.args[0];
157+
158+
switch (command) {
159+
case "init":
160+
await init(Deno.args[1]);
161+
break;
162+
case "build":
163+
await build();
164+
break;
165+
case "dev":
166+
await dev();
167+
break;
168+
case "clean":
169+
await clean();
170+
break;
171+
case "--version":
172+
case "-v":
173+
console.log(`rescript-deno ${VERSION}`);
174+
break;
175+
case "--help":
176+
case "-h":
177+
case undefined:
178+
console.log(`
179+
rescript-deno ${VERSION} — ReScript on Deno, no npm required
180+
181+
Commands:
182+
init <name> Create a new ReScript + Deno project
183+
build Compile ReScript sources
184+
dev Watch mode (recompile on change)
185+
clean Remove build artifacts
186+
--version Show version
187+
--help Show this help
188+
189+
Example:
190+
rescript-deno init my-app
191+
cd my-app
192+
deno task build
193+
deno run src/Main.res.mjs
194+
`);
195+
break;
196+
default:
197+
console.error(`Unknown command: ${command}. Use --help for usage.`);
198+
Deno.exit(1);
199+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# rescript-vite-config
2+
3+
Use `vite.config.res` instead of `vite.config.ts`.
4+
5+
Vite core rejected native ReScript config support ([vitejs/vite#21649](https://github.com/vitejs/vite/issues/21649)), but suggested a CLI wrapper. This is that wrapper.
6+
7+
## Install
8+
9+
```bash
10+
deno add npm:rescript-vite-config
11+
# or
12+
npm install -D rescript-vite-config
13+
```
14+
15+
## Usage
16+
17+
Write your Vite config in ReScript:
18+
19+
```rescript
20+
// vite.config.res
21+
let default = Vite.defineConfig({
22+
"build": {"outDir": "dist"},
23+
"server": {"port": 3000},
24+
})
25+
```
26+
27+
Then use the CLI instead of `vite` directly:
28+
29+
```bash
30+
npx rescript-vite-config dev # compile config + vite dev
31+
npx rescript-vite-config build # compile config + vite build
32+
npx rescript-vite-config preview # compile config + vite preview
33+
```
34+
35+
## How it works
36+
37+
1. Compiles `vite.config.res` → `vite.config.res.mjs` using `rescript`
38+
2. Creates a thin `vite.config.js` bridge that re-exports from the compiled output
39+
3. Invokes Vite with your command
40+
4. Cleans up the generated bridge on exit
41+
42+
Works with `rescript`, `rescript-legacy`, and Deno-based ReScript.
43+
44+
## License
45+
46+
PMPL-1.0-or-later
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "rescript-vite-config",
3+
"version": "1.0.0",
4+
"description": "Use vite.config.res instead of vite.config.ts — CLI wrapper that compiles ReScript configs and invokes Vite",
5+
"license": "PMPL-1.0-or-later",
6+
"author": "Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/hyperpolymath/developer-ecosystem.git",
10+
"directory": "rescript-ecosystem/rescript-vite-config"
11+
},
12+
"keywords": [
13+
"rescript",
14+
"vite",
15+
"config",
16+
"build-tool",
17+
"bundler"
18+
],
19+
"type": "module",
20+
"bin": {
21+
"rescript-vite-config": "./src/cli.js"
22+
},
23+
"main": "./src/cli.js",
24+
"files": [
25+
"src/"
26+
],
27+
"engines": {
28+
"node": ">=18.0.0"
29+
},
30+
"peerDependencies": {
31+
"vite": ">=5.0.0",
32+
"rescript": ">=11.0.0"
33+
}
34+
}

0 commit comments

Comments
 (0)