@reventlessdev/reventless-ppx 1.0.0-alpha.100

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.
Files changed (4) hide show
  1. package/README.md +81 -0
  2. package/bin +52 -0
  3. package/package.json +32 -0
  4. package/read +41 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ [![npm](https://img.shields.io/npm/v/@reventlessdev/reventless-ppx.svg?label=npm)](https://www.npmjs.com/package/@reventlessdev/reventless-ppx)
2
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
3
+ [![Docs](https://img.shields.io/badge/docs-reventless.dev-blue)](https://docs.reventless.dev)
4
+
5
+ # @reventlessdev/reventless-ppx
6
+
7
+ > ⚠️ **Alpha.** APIs and on-disk formats can change without notice between releases.
8
+ > Pin exact versions and expect breaking changes.
9
+
10
+ The **ReScript PPX** for [Reventless](https://docs.reventless.dev) — a spec-driven,
11
+ event-sourced CQRS framework written in [ReScript](https://rescript-lang.org). It
12
+ is a compile-time preprocessor (native OCaml binary) that eliminates boilerplate
13
+ from Reventless application code by deriving framework metadata and wiring
14
+ directly from your component definitions.
15
+
16
+ ## What it provides
17
+
18
+ A single PPX binary, invoked by the ReScript compiler, that runs a set of
19
+ transforms over component source — among them: display-name and reference
20
+ inference, DCB tag and read-consistency inference, GWT test inference,
21
+ authorization injection, allowed-states annotations, and module-URL derivation.
22
+
23
+ The package ships as a thin launcher that resolves a **prebuilt per-platform
24
+ binary** installed as an optional dependency
25
+ (`@reventlessdev/reventless-ppx-<platform>`), published for **macOS arm64** and
26
+ **Linux x64** — so it installs automatically with no authentication. On platforms
27
+ with no prebuilt binary (e.g. macOS x64, Linux arm64, Windows via WSL2), it is
28
+ built from source with the OCaml toolchain (`opam` + `dune`).
29
+
30
+ ### The source reader
31
+
32
+ The same package ships `reventless-ppx-read`, which prints one ReScript file's
33
+ declarations as JSON, each with its span (byte offsets into the file) and source
34
+ text: types with their cases, fields and attributes; top-level `let`s with a
35
+ function's parameters and defaults; and the tests of a GWT file with their
36
+ scenario-id markers and step values. It is for tools that edit source in place.
37
+
38
+ ```bash
39
+ npx reventless-ppx-read [--bsc <path-to-bsc>] src/PlaceOrder.res
40
+ ```
41
+
42
+ The file is parsed by the workspace's own ReScript compiler (found under
43
+ `node_modules/@rescript`, or given with `--bsc`); nothing is built.
44
+
45
+ ## Where it fits
46
+
47
+ This is build tooling shared across the framework and its example apps, not a
48
+ runtime library. It is referenced from a package's `rescript.json` `ppx-flags`
49
+ and runs only at compile time.
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pnpm add -D @reventlessdev/reventless-ppx
55
+ ```
56
+
57
+ Register it in `rescript.json`:
58
+
59
+ ```json
60
+ {
61
+ "ppx-flags": ["@reventlessdev/reventless-ppx/bin"]
62
+ }
63
+ ```
64
+
65
+ The matching platform binary is pulled in automatically via optional
66
+ dependencies. On an unsupported platform, build from source (requires the OCaml
67
+ toolchain):
68
+
69
+ ```bash
70
+ cd src && opam exec -- dune build
71
+ ```
72
+
73
+ ## Links
74
+
75
+ - 📚 Documentation — [docs.reventless.dev](https://docs.reventless.dev)
76
+ - 📦 Repository — [ReventlessDev/reventless-core](https://github.com/ReventlessDev/reventless-core)
77
+ - 📋 [Changelog](./CHANGELOG.md)
78
+
79
+ ## License
80
+
81
+ [Apache-2.0](https://opensource.org/licenses/Apache-2.0)
package/bin ADDED
@@ -0,0 +1,52 @@
1
+ #!/bin/sh
2
+ # Resolve and exec the reventless-ppx native binary for the current platform.
3
+ #
4
+ # Resolution order:
5
+ # 1. The matching per-platform package @reventlessdev/reventless-ppx-<platform>
6
+ # (declared as an optionalDependency; npm/pnpm install only the one whose
7
+ # os/cpu match). Three layouts covered:
8
+ # a. sibling in node_modules (npm flat / pnpm hoisted, same package dir)
9
+ # b. nested under this package's own node_modules (pnpm strict / per-pkg)
10
+ # c. hoisted to an ancestor node_modules (pnpm hoisted in a workspace —
11
+ # the per-platform pkg lands at the *workspace root* node_modules,
12
+ # not at the consumer's or this package's level)
13
+ # 2. A locally-built or committed fallback binary in this directory — covers PPX
14
+ # development (`pnpm build:ppx`) and the pre-publish transition window.
15
+ #
16
+ # Windows is served via WSL2 (which presents as Linux-x86_64); there is no native
17
+ # Windows binary.
18
+ DIR="$(cd "$(dirname "$0")" && pwd)"
19
+
20
+ case "$(uname -s)-$(uname -m)" in
21
+ Linux-x86_64) PKG="linux-x64"; LOCAL="ppx-linux.exe" ;;
22
+ Linux-aarch64) PKG="linux-arm64"; LOCAL="ppx-linux-arm.exe" ;;
23
+ Darwin-x86_64) PKG="darwin-x64"; LOCAL="ppx-osx-x64.exe" ;;
24
+ Darwin-arm64) PKG="darwin-arm64"; LOCAL="ppx-osx.exe" ;;
25
+ *) echo "reventless-ppx: unsupported platform $(uname -s)-$(uname -m)" >&2; exit 1 ;;
26
+ esac
27
+
28
+ # (1a) sibling in node_modules; (1b) nested under this package; (2) local fallback.
29
+ for CAND in \
30
+ "$DIR/../reventless-ppx-$PKG/ppx.exe" \
31
+ "$DIR/node_modules/@reventlessdev/reventless-ppx-$PKG/ppx.exe" \
32
+ "$DIR/$LOCAL"; do
33
+ # `-f` (exists), not `-x`: npm/pnpm normalize file modes to 0644 when installing
34
+ # from a published tarball (only package.json `bin` targets are guaranteed +x),
35
+ # so the native binary often arrives non-executable. Restore +x, then exec.
36
+ if [ -f "$CAND" ]; then chmod u+x "$CAND" 2>/dev/null; exec "$CAND" "$@"; fi
37
+ done
38
+
39
+ # (1c) Walk up ancestor directories looking for a node_modules with the matching
40
+ # per-platform package — covers pnpm's hoisted workspace layout, where the
41
+ # optionalDep lands at the workspace root rather than at this package's level.
42
+ ANCESTOR="$DIR"
43
+ while [ "$ANCESTOR" != "/" ] && [ -n "$ANCESTOR" ]; do
44
+ ANCESTOR="$(dirname "$ANCESTOR")"
45
+ CAND="$ANCESTOR/node_modules/@reventlessdev/reventless-ppx-$PKG/ppx.exe"
46
+ if [ -f "$CAND" ]; then chmod u+x "$CAND" 2>/dev/null; exec "$CAND" "$@"; fi
47
+ done
48
+
49
+ echo "reventless-ppx: no binary found for $(uname -s)-$(uname -m)." >&2
50
+ echo " Expected package @reventlessdev/reventless-ppx-$PKG, or a local build at $DIR/$LOCAL." >&2
51
+ echo " For PPX development: (cd \"$DIR/src\" && opam exec -- dune build) && cp \"$DIR/src/_build/default/bin/bin.exe\" \"$DIR/$LOCAL\"" >&2
52
+ exit 1
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@reventlessdev/reventless-ppx",
3
+ "version": "1.0.0-alpha.100",
4
+ "description": "ReScript PPX to eliminate boilerplate from Reventless application code",
5
+ "license": "Apache-2.0",
6
+ "files": [
7
+ "bin",
8
+ "read"
9
+ ],
10
+ "bin": {
11
+ "reventless-ppx": "bin",
12
+ "reventless-ppx-read": "read"
13
+ },
14
+ "scripts": {
15
+ "build:ppx": "cd src && opam exec -- dune build",
16
+ "clean:ppx": "cd src && opam exec -- dune clean",
17
+ "publish:platform": "node ../../scripts/publish-ppx-local.mjs",
18
+ "test": "./test/run.sh"
19
+ },
20
+ "optionalDependencies": {
21
+ "@reventlessdev/reventless-ppx-darwin-arm64": "1.0.0-alpha.100",
22
+ "@reventlessdev/reventless-ppx-linux-x64": "1.0.0-alpha.100"
23
+ },
24
+ "publishConfig": {
25
+ "registry": "https://registry.npmjs.org"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/ReventlessDev/reventless-core.git",
30
+ "directory": "packages/reventless-ppx"
31
+ }
32
+ }
package/read ADDED
@@ -0,0 +1,41 @@
1
+ #!/bin/sh
2
+ # Resolve and exec reventless-ppx-read, the source reader, for the current platform.
3
+ #
4
+ # reventless-ppx-read [--bsc <path-to-bsc>] <file.res>
5
+ #
6
+ # Prints the file's declarations with their spans as JSON
7
+ # (docs/plans/done/source-reader-with-spans.md). The binary ships beside ppx.exe in the
8
+ # per-platform package, and is found the way `bin` finds ppx.exe: sibling,
9
+ # nested, or hoisted to an ancestor node_modules, then a local dune build.
10
+ DIR="$(cd "$(dirname "$0")" && pwd)"
11
+
12
+ case "$(uname -s)-$(uname -m)" in
13
+ Linux-x86_64) PKG="linux-x64" ;;
14
+ Linux-aarch64) PKG="linux-arm64" ;;
15
+ Darwin-x86_64) PKG="darwin-x64" ;;
16
+ Darwin-arm64) PKG="darwin-arm64" ;;
17
+ *) echo "reventless-ppx-read: unsupported platform $(uname -s)-$(uname -m)" >&2; exit 1 ;;
18
+ esac
19
+
20
+ # `-f`, then restore +x: installing from a tarball can drop the mode (see `bin`).
21
+ for CAND in \
22
+ "$DIR/../reventless-ppx-$PKG/read.exe" \
23
+ "$DIR/node_modules/@reventlessdev/reventless-ppx-$PKG/read.exe"; do
24
+ if [ -f "$CAND" ]; then chmod u+x "$CAND" 2>/dev/null; exec "$CAND" "$@"; fi
25
+ done
26
+
27
+ ANCESTOR="$DIR"
28
+ while [ "$ANCESTOR" != "/" ] && [ -n "$ANCESTOR" ]; do
29
+ ANCESTOR="$(dirname "$ANCESTOR")"
30
+ CAND="$ANCESTOR/node_modules/@reventlessdev/reventless-ppx-$PKG/read.exe"
31
+ if [ -f "$CAND" ]; then chmod u+x "$CAND" 2>/dev/null; exec "$CAND" "$@"; fi
32
+ done
33
+
34
+ # PPX development: the dune build in this package.
35
+ CAND="$DIR/src/_build/default/read/read.exe"
36
+ if [ -f "$CAND" ]; then exec "$CAND" "$@"; fi
37
+
38
+ echo "reventless-ppx-read: no binary found for $(uname -s)-$(uname -m)." >&2
39
+ echo " Expected read.exe in @reventlessdev/reventless-ppx-$PKG," >&2
40
+ echo " or a local build at $DIR/src/_build/default/read/read.exe." >&2
41
+ exit 1