@rust-js/create 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/index.js +1 -6
- package/package.json +1 -1
- package/template/Cargo.toml +7 -7
- package/template/README.md +8 -4
- package/template/_gitignore +4 -2
- package/template/package.json +8 -3
- package/template/src/App.css +3 -0
- package/template/vite.config.js +4 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @rust-js/create
|
|
2
2
|
|
|
3
3
|
```bash
|
|
4
|
-
bun create @rust-js my-app # with Bun
|
|
5
|
-
npm create @rust-js my-app # with Node.js
|
|
4
|
+
bun create @rust-js@latest my-app # with Bun
|
|
5
|
+
npm create @rust-js@latest my-app # with Node.js
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
makes `my-app`, a Vite and React app whose component is written in Rust
|
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const at = args.indexOf("--local");
|
|
|
20
20
|
const local = at >= 0 ? args.splice(at, 2)[1] : undefined;
|
|
21
21
|
if (at >= 0 && !local) fail("--local needs a distribution, the directory `bun run pack:distribution` makes");
|
|
22
22
|
const [directory, ...extra] = args;
|
|
23
|
-
if (!directory || extra.length) fail("usage: bun create @rust-js <directory> [--local <distribution>]");
|
|
23
|
+
if (!directory || extra.length) fail("usage: bun create @rust-js@latest <directory> [--local <distribution>]");
|
|
24
24
|
|
|
25
25
|
// A distribution is for one host, and one compiler: this one's.
|
|
26
26
|
const dist = local && resolve(local);
|
|
@@ -53,11 +53,6 @@ for (const field of ["dependencies", "devDependencies"]) {
|
|
|
53
53
|
if (spec.startsWith("workspace:")) manifest[field][name] = dist ? archive(name) : self.version;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
// The app's own, so every package manager has it at node_modules/@rust-js/resources,
|
|
57
|
-
// where its Cargo.toml has the crates the app uses.
|
|
58
|
-
manifest.devDependencies["@rust-js/resources"] = dist ? archive("@rust-js/resources") : self.version;
|
|
59
|
-
const cargo = join(app, "Cargo.toml");
|
|
60
|
-
writeFileSync(cargo, readFileSync(cargo, "utf8").replaceAll('path = "../../', 'path = "node_modules/@rust-js/resources/'));
|
|
61
56
|
// The compiler is the app's own, as the plugin finds it, from the app: a
|
|
62
57
|
// release's or a distribution's. A distribution's `@rust-js/build` is the
|
|
63
58
|
// app's too, and the plugin's, where a release's is the registry's.
|
package/package.json
CHANGED
package/template/Cargo.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# src/App.rs
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
1
|
+
# The app's crate, src/App.rs, which the Vite plugin builds with Cargo, and
|
|
2
|
+
# an editor's rust-analyzer checks (ADR 0114). Its crates are npm packages,
|
|
3
|
+
# named by version, which rust-js-patch, the app's `postinstall`, tells
|
|
4
|
+
# Cargo are in node_modules; rust-js's own example has them by path.
|
|
5
5
|
[package]
|
|
6
6
|
name = "app"
|
|
7
7
|
version = "0.0.0"
|
|
@@ -12,9 +12,9 @@ publish = false
|
|
|
12
12
|
path = "src/App.rs"
|
|
13
13
|
|
|
14
14
|
[dependencies]
|
|
15
|
-
js = { package = "rust-js-builtins",
|
|
16
|
-
react = { package = "rust-js-react",
|
|
17
|
-
webapi = { package = "rust-js-webapi",
|
|
15
|
+
js = { package = "rust-js-builtins", version = "~0.0.1" }
|
|
16
|
+
react = { package = "rust-js-react", version = "~0.0.3" }
|
|
17
|
+
webapi = { package = "rust-js-webapi", version = "~0.0.2" }
|
|
18
18
|
|
|
19
19
|
# rust-js compiles with `--cfg=rust_js` (ADR 0113): a `cfg` Cargo checks for,
|
|
20
20
|
# here too, in what `js::import!` expands to.
|
package/template/README.md
CHANGED
|
@@ -38,10 +38,14 @@ version that compiled. The browser's source map points at `App.rs`.
|
|
|
38
38
|
else { "text-sky-500" }`, not a string built from pieces.
|
|
39
39
|
- `rustJs()` comes first in `vite.config.js`, before `tailwindcss()`, so that
|
|
40
40
|
a save refreshes the page instead of reloading it.
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
- **The app is a Cargo package**, `Cargo.toml`, which the Vite plugin builds
|
|
42
|
+
with Cargo, and your editor's rust-analyzer checks. Its crates, `react`,
|
|
43
|
+
`webapi` and `js`, are npm packages, `@rust-js/react` and the others, named
|
|
44
|
+
in `Cargo.toml` by version: `rust-js-patch`, the app's `postinstall`, tells
|
|
45
|
+
Cargo they're in `node_modules`, in `.cargo/config.toml`. A binding of another
|
|
46
|
+
library, `@rust-js-bindings/canvas-confetti`, is added the same way: its npm
|
|
47
|
+
package, and a line in `Cargo.toml`. rust-analyzer doesn't look inside
|
|
48
|
+
`jsx!`, so a variable used only in JSX shows as unused there.
|
|
45
49
|
- **`Cargo.toml` also sets how the JS is laid out**, by oxfmt's options,
|
|
46
50
|
`[package.metadata.rust-js.format]` with `printWidth = 120`, say, and can run
|
|
47
51
|
your own tools on it, a formatter or a linter, in
|
package/template/_gitignore
CHANGED
|
@@ -27,7 +27,9 @@ dist-ssr
|
|
|
27
27
|
# ReScript recommends for its JS. Its source map isn't.
|
|
28
28
|
/src/App.jsx.map
|
|
29
29
|
|
|
30
|
-
# What
|
|
31
|
-
# which
|
|
30
|
+
# What Cargo writes, and the patch rust-js-patch writes, of what's
|
|
31
|
+
# installed: its crates are npm packages, which the lockfile of the app's
|
|
32
|
+
# package manager pins.
|
|
32
33
|
/target
|
|
33
34
|
/Cargo.lock
|
|
35
|
+
/.cargo
|
package/template/package.json
CHANGED
|
@@ -7,14 +7,18 @@
|
|
|
7
7
|
"dev": "vite",
|
|
8
8
|
"build": "vite build",
|
|
9
9
|
"lint": "oxlint",
|
|
10
|
-
"preview": "vite preview"
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"postinstall": "rust-js-patch"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"@rust-js/runtime": "workspace:*",
|
|
14
15
|
"@tailwindcss/vite": "^4.3.3",
|
|
15
16
|
"react": "^19.2.8",
|
|
16
17
|
"react-dom": "^19.2.8",
|
|
17
|
-
"tailwindcss": "^4.3.3"
|
|
18
|
+
"tailwindcss": "^4.3.3",
|
|
19
|
+
"@rust-js/builtins": "0.0.1",
|
|
20
|
+
"@rust-js/webapi": "0.0.2",
|
|
21
|
+
"@rust-js/react": "0.0.3"
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
20
24
|
"@babel/core": "^7.29.7",
|
|
@@ -25,6 +29,7 @@
|
|
|
25
29
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
26
30
|
"oxlint": "^1.81.0",
|
|
27
31
|
"vite": "^8.3.0",
|
|
28
|
-
"@rust-js/vite-plugin": "workspace:*"
|
|
32
|
+
"@rust-js/vite-plugin": "workspace:*",
|
|
33
|
+
"@rust-js/build": "workspace:*"
|
|
29
34
|
}
|
|
30
35
|
}
|
package/template/src/App.css
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
border: 2px solid transparent;
|
|
8
8
|
transition: border-color 0.3s;
|
|
9
9
|
margin-bottom: 24px;
|
|
10
|
+
/* A flex box ends its text, "Count is ", at its last letter, and the count
|
|
11
|
+
is a box of its own: one character, as its font is monospace. */
|
|
12
|
+
gap: 1ch;
|
|
10
13
|
|
|
11
14
|
&:hover {
|
|
12
15
|
border-color: var(--accent-border);
|
package/template/vite.config.js
CHANGED
|
@@ -7,9 +7,10 @@ import rustJs from '@rust-js/vite-plugin'
|
|
|
7
7
|
// https://vite.dev/config/
|
|
8
8
|
export default defineConfig({
|
|
9
9
|
plugins: [
|
|
10
|
-
// rust-js compiles
|
|
11
|
-
// with Fast Refresh, and React
|
|
12
|
-
|
|
10
|
+
// rust-js compiles the app's crate, src/App.rs, with Cargo (ADR 0101),
|
|
11
|
+
// to src/App.jsx, which plugin-react serves with Fast Refresh, and React
|
|
12
|
+
// Compiler memoizes.
|
|
13
|
+
rustJs({ cargo: { package: 'app' } }),
|
|
13
14
|
react(),
|
|
14
15
|
babel({ presets: [reactCompilerPreset()] }),
|
|
15
16
|
tailwindcss(),
|