@crustjs/crust 0.0.20 → 0.0.22

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 CHANGED
@@ -17,12 +17,12 @@ The `crust` binary provides three distinct workflows:
17
17
  | Command | Description |
18
18
  | -------------------------- | ---------------------------------------------- |
19
19
  | `crust build` | Compile raw standalone Bun executable(s) |
20
- | `crust build --distribute` | Stage per-platform npm packages in `dist/npm` |
20
+ | `crust build --package` | Stage per-platform npm packages in `dist/npm` |
21
21
  | `crust publish` | Publish an existing staged `dist/npm` manifest |
22
22
 
23
23
  ### `crust build`
24
24
 
25
- Compiles your CLI entry file to standalone Bun executables using the `Bun.build()` API.
25
+ Compiles your CLI entry file to standalone Bun executables.
26
26
 
27
27
  **By default, builds for all 6 supported platforms** and generates a shell resolver script that detects the host platform at runtime and runs the correct binary. This makes it easy to distribute your CLI as a single npm package that works everywhere — no runtime (Node.js or Bun) required.
28
28
 
@@ -31,6 +31,7 @@ crust build # All platforms + shell resolver (default)
31
31
  crust build --entry src/main.ts # Custom entry point
32
32
  crust build --name my-tool # Set base binary name
33
33
  crust build --no-minify # Disable minification
34
+ crust build --env-file .env.production # Explicit build-time env file
34
35
  ```
35
36
 
36
37
  To build for specific platform(s) only, use `--target`:
@@ -39,6 +40,7 @@ To build for specific platform(s) only, use `--target`:
39
40
  crust build --target linux-x64 # Single platform
40
41
  crust build --target linux-x64 --target darwin-arm64 # Multiple platforms
41
42
  crust build --target linux-x64 --outfile ./my-cli # Custom output (single target only)
43
+ crust build --env-file .env --env-file .env.local # Repeatable env files
42
44
  ```
43
45
 
44
46
  #### Supported Targets
@@ -63,9 +65,10 @@ crust build --target linux-x64 --outfile ./my-cli # Custom output (single
63
65
  | `--target` | `-t` | `"string"` | _(all platforms)_ | Target platform(s); repeatable |
64
66
  | `--outdir` | `-d` | `"string"` | `dist` | Output directory for compiled binaries |
65
67
  | `--resolver` | `-r` | `"string"` | `cli` | Resolver script filename (multi-target only, no extension) |
68
+ | `--env-file` | — | `"string"` | — | Explicit env file(s) used for build-time constants |
66
69
  | `--validate` | — | `"boolean"` | `true` | Pre-compile validation of command definitions |
67
- | `--distribute` | — | `"boolean"` | `false` | Stage npm distribution packages instead of raw binaries |
68
- | `--stage-dir` | — | `"string"` | `dist/npm` | Staging directory used with `--distribute` |
70
+ | `--package` | — | `"boolean"` | `false` | Stage npm packages in `dist/npm` instead of raw binaries |
71
+ | `--stage-dir` | — | `"string"` | `dist/npm` | Staging directory used with `--package` |
69
72
 
70
73
  #### Output
71
74
 
@@ -90,16 +93,25 @@ dist/
90
93
  my-cli # Single binary (no resolver)
91
94
  ```
92
95
 
93
- `crust build` is the raw binary workflow by default. Add `--distribute` when you want staged npm packages instead of raw `dist/` binaries.
96
+ `crust build` is the raw binary workflow by default. Add `--package` when you want staged npm packages instead of raw `dist/` binaries.
94
97
 
95
- ### `crust build --distribute`
98
+ #### Environment Variables
99
+
100
+ Compiled executables still use Bun's **runtime env** behavior. Build-time constants follow Bun's `PUBLIC_*` env-prefix model, sourcing values from Bun's auto-loaded cwd env by default or from explicit `--env-file` inputs.
101
+
102
+ `PUBLIC_*` values are embedded in the binary and are therefore public.
103
+
104
+ See the full guide: [Environment Variables](https://crustjs.com/docs/guide/environment)
105
+
106
+ ### `crust build --package`
96
107
 
97
108
  Stages a root npm package plus one npm package per supported target for optionalDependency-based distribution.
98
109
 
99
110
  ```sh
100
- crust build --distribute
101
- crust build --distribute --target linux-x64
102
- crust build --distribute --stage-dir .crust/npm
111
+ crust build --package
112
+ crust build --package --target linux-x64
113
+ crust build --package --stage-dir .crust/npm
114
+ crust build --package --env-file .env.production
103
115
  ```
104
116
 
105
117
  #### Output
@@ -109,8 +121,7 @@ dist/npm/
109
121
  manifest.json
110
122
  root/
111
123
  package.json
112
- bin/my-cli
113
- bin/my-cli.cmd
124
+ bin/my-cli.js
114
125
  linux-x64/
115
126
  package.json
116
127
  bin/my-cli-bun-linux-x64-baseline
@@ -131,9 +142,9 @@ dist/npm/
131
142
  bin/my-cli-bun-windows-arm64.exe
132
143
  ```
133
144
 
134
- The generated root package contains shell and `.cmd` launchers plus `optionalDependencies` on the platform packages. Each platform package is tagged with npm `os` / `cpu` metadata and contains only its native binary.
145
+ The generated root package contains a JS resolver plus `optionalDependencies` on the platform packages. Each platform package is tagged with npm `os` / `cpu` metadata and contains only its native binary. npm generates the platform launchers from the root package `bin` entry during install, so Crust does not stage its own `.cmd` file for `--package`.
135
146
 
136
- `crust build --distribute` is the npm-packaging workflow. The staged interface is:
147
+ `crust build --package` is the npm-packaging workflow. The staged interface is:
137
148
 
138
149
  - `dist/npm/root`
139
150
  - `dist/npm/<target>`
@@ -143,7 +154,7 @@ The generated root package contains shell and `.cmd` launchers plus `optionalDep
143
154
 
144
155
  ### `crust publish`
145
156
 
146
- Publishes the already-staged directories from `crust build --distribute`.
157
+ Publishes the already-staged directories from `crust build --package`.
147
158
 
148
159
  ```sh
149
160
  crust publish
@@ -167,13 +178,13 @@ crust publish --stage-dir .crust/npm --tag next
167
178
  ## Recommended Flow
168
179
 
169
180
  1. `crust build` — compile raw binaries
170
- 2. `crust build --distribute` — stage per-platform npm packages
181
+ 2. `crust build --package` — stage per-platform npm packages
171
182
  3. `crust publish` — publish staged packages to the registry
172
183
 
173
184
  The three steps are intentionally separate:
174
185
 
175
186
  - `build` produces raw binary artifacts.
176
- - `build --distribute` creates npm-ready staged packages.
187
+ - `build --package` creates npm-ready staged packages.
177
188
  - `publish` uploads the staged packages to the registry.
178
189
 
179
190
  ## Documentation
package/bin/crust.js ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ // Auto-generated by crust build --package -- do not edit
3
+ import { spawn } from "node:child_process";
4
+ import { chmodSync, existsSync } from "node:fs";
5
+ import { dirname, resolve } from "node:path";
6
+ import process from "node:process";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const PLATFORMS = {
10
+ "linux-x64": {
11
+ "packagePathSegment": "crust-linux-x64",
12
+ "packageName": "@crustjs/crust-linux-x64",
13
+ "binaryFilename": "crust-bun-linux-x64-baseline"
14
+ },
15
+ "linux-arm64": {
16
+ "packagePathSegment": "crust-linux-arm64",
17
+ "packageName": "@crustjs/crust-linux-arm64",
18
+ "binaryFilename": "crust-bun-linux-arm64"
19
+ },
20
+ "darwin-x64": {
21
+ "packagePathSegment": "crust-darwin-x64",
22
+ "packageName": "@crustjs/crust-darwin-x64",
23
+ "binaryFilename": "crust-bun-darwin-x64"
24
+ },
25
+ "darwin-arm64": {
26
+ "packagePathSegment": "crust-darwin-arm64",
27
+ "packageName": "@crustjs/crust-darwin-arm64",
28
+ "binaryFilename": "crust-bun-darwin-arm64"
29
+ },
30
+ "win32-x64": {
31
+ "packagePathSegment": "crust-windows-x64",
32
+ "packageName": "@crustjs/crust-windows-x64",
33
+ "binaryFilename": "crust-bun-windows-x64-baseline.exe"
34
+ },
35
+ "win32-arm64": {
36
+ "packagePathSegment": "crust-windows-arm64",
37
+ "packageName": "@crustjs/crust-windows-arm64",
38
+ "binaryFilename": "crust-bun-windows-arm64.exe"
39
+ }
40
+ };
41
+ const dir = dirname(fileURLToPath(import.meta.url));
42
+ const platformKey = `${process.platform}-${process.arch}`;
43
+ const target = PLATFORMS[platformKey];
44
+
45
+ if (!target) {
46
+ console.error("[crust] Unsupported platform: " + platformKey);
47
+ console.error("[crust] Supported platforms: linux-x64, linux-arm64, darwin-x64, darwin-arm64, windows-x64, windows-arm64");
48
+ process.exit(1);
49
+ }
50
+
51
+ const candidateOne = resolve(
52
+ dir,
53
+ "..",
54
+ "..",
55
+ target.packagePathSegment,
56
+ "bin",
57
+ target.binaryFilename,
58
+ );
59
+ const candidateTwo = resolve(
60
+ dir,
61
+ "..",
62
+ "node_modules",
63
+ target.packageName,
64
+ "bin",
65
+ target.binaryFilename,
66
+ );
67
+
68
+ const binPath = existsSync(candidateOne)
69
+ ? candidateOne
70
+ : existsSync(candidateTwo)
71
+ ? candidateTwo
72
+ : null;
73
+
74
+ if (!binPath) {
75
+ console.error("[crust] Missing platform package for " + platformKey);
76
+ console.error("[crust] Tried:");
77
+ console.error(" " + candidateOne);
78
+ console.error(" " + candidateTwo);
79
+ console.error(
80
+ "[crust] Reinstall dependencies on this platform and ensure optional dependencies are enabled.",
81
+ );
82
+ process.exit(1);
83
+ }
84
+
85
+ if (process.platform !== "win32") {
86
+ try {
87
+ chmodSync(binPath, 0o755);
88
+ } catch {
89
+ // Ignore permission adjustment failures and let spawn surface real errors.
90
+ }
91
+ }
92
+
93
+ const child = spawn(binPath, process.argv.slice(2), {
94
+ stdio: "inherit",
95
+ });
96
+
97
+ child.on("error", (error) => {
98
+ console.error("[crust] Failed to launch binary: " + error.message);
99
+ process.exit(1);
100
+ });
101
+
102
+ child.on("exit", (code, signal) => {
103
+ if (signal) {
104
+ try {
105
+ process.kill(process.pid, signal);
106
+ } catch {
107
+ process.exit(1);
108
+ }
109
+ return;
110
+ }
111
+
112
+ process.exit(code ?? 0);
113
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crustjs/crust",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "CLI tooling for the Crust framework",
5
5
  "license": "MIT",
6
6
  "author": "chenxin-yan",
@@ -29,14 +29,14 @@
29
29
  "bin"
30
30
  ],
31
31
  "bin": {
32
- "crust": "bin/crust"
32
+ "crust": "bin/crust.js"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@crustjs/crust-linux-x64": "0.0.20",
36
- "@crustjs/crust-linux-arm64": "0.0.20",
37
- "@crustjs/crust-darwin-x64": "0.0.20",
38
- "@crustjs/crust-darwin-arm64": "0.0.20",
39
- "@crustjs/crust-windows-x64": "0.0.20",
40
- "@crustjs/crust-windows-arm64": "0.0.20"
35
+ "@crustjs/crust-linux-x64": "0.0.22",
36
+ "@crustjs/crust-linux-arm64": "0.0.22",
37
+ "@crustjs/crust-darwin-x64": "0.0.22",
38
+ "@crustjs/crust-darwin-arm64": "0.0.22",
39
+ "@crustjs/crust-windows-x64": "0.0.22",
40
+ "@crustjs/crust-windows-arm64": "0.0.22"
41
41
  }
42
42
  }
package/bin/crust DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Auto-generated by crust build --distribute -- do not edit
3
- set -e
4
-
5
- source="$0"
6
- while [ -L "$source" ]; do
7
- link_dir="$(cd "$(dirname "$source")" && pwd)"
8
- source="$(readlink "$source")"
9
- case "$source" in
10
- /*) ;;
11
- *) source="$link_dir/$source" ;;
12
- esac
13
- done
14
-
15
- dir="$(cd "$(dirname "$source")" && pwd)"
16
- platform="$(uname -s)-$(uname -m)"
17
- platform_pkg=""
18
- fallback_pkg=""
19
- binary=""
20
-
21
- case "$platform" in
22
- Linux-x86_64)
23
- platform_pkg="crust-linux-x64"
24
- fallback_pkg="@crustjs/crust-linux-x64"
25
- binary="crust-bun-linux-x64-baseline"
26
- ;;
27
- Linux-aarch64)
28
- platform_pkg="crust-linux-arm64"
29
- fallback_pkg="@crustjs/crust-linux-arm64"
30
- binary="crust-bun-linux-arm64"
31
- ;;
32
- Darwin-x86_64)
33
- platform_pkg="crust-darwin-x64"
34
- fallback_pkg="@crustjs/crust-darwin-x64"
35
- binary="crust-bun-darwin-x64"
36
- ;;
37
- Darwin-arm64)
38
- platform_pkg="crust-darwin-arm64"
39
- fallback_pkg="@crustjs/crust-darwin-arm64"
40
- binary="crust-bun-darwin-arm64"
41
- ;;
42
- *)
43
- echo "[crust] Unsupported platform: $platform" >&2
44
- echo "[crust] Supported platforms: linux-x64, linux-arm64, darwin-x64, darwin-arm64" >&2
45
- exit 1
46
- ;;
47
- esac
48
-
49
- candidate_one="$dir/../../$platform_pkg/bin/$binary"
50
- candidate_two="$dir/../node_modules/$fallback_pkg/bin/$binary"
51
-
52
- if [ -f "$candidate_one" ]; then
53
- exec "$candidate_one" "$@"
54
- fi
55
-
56
- if [ -f "$candidate_two" ]; then
57
- exec "$candidate_two" "$@"
58
- fi
59
-
60
- echo "[crust] Missing platform package for $platform" >&2
61
- echo "[crust] Tried:" >&2
62
- echo " $candidate_one" >&2
63
- echo " $candidate_two" >&2
64
- echo "[crust] Reinstall dependencies on this platform and ensure optional dependencies are enabled." >&2
65
- exit 1
package/bin/crust.cmd DELETED
@@ -1,45 +0,0 @@
1
- @echo off
2
- rem Auto-generated by crust build --distribute -- do not edit
3
- setlocal
4
- set "dir=%~dp0"
5
- set "host_arch=%PROCESSOR_ARCHITECTURE%"
6
- set "pkg_segment="
7
- set "fallback_pkg="
8
- set "binary="
9
-
10
- if /I "%PROCESSOR_ARCHITEW6432%"=="ARM64" set "host_arch=ARM64"
11
-
12
- if /I "%host_arch%"=="AMD64" (
13
- set "pkg_segment=crust-windows-x64"
14
- set "fallback_pkg=@crustjs\crust-windows-x64"
15
- set "binary=crust-bun-windows-x64-baseline.exe"
16
- )
17
- if /I "%host_arch%"=="ARM64" (
18
- set "pkg_segment=crust-windows-arm64"
19
- set "fallback_pkg=@crustjs\crust-windows-arm64"
20
- set "binary=crust-bun-windows-arm64.exe"
21
- )
22
-
23
- if "%binary%"=="" (
24
- echo [crust] Unsupported Windows architecture: %host_arch% >&2
25
- exit /b 1
26
- )
27
-
28
- set "candidate_one=%dir%..\..\%pkg_segment%\bin\%binary%"
29
- set "candidate_two=%dir%..\node_modules\%fallback_pkg%\bin\%binary%"
30
-
31
- if exist "%candidate_one%" (
32
- "%candidate_one%" %*
33
- exit /b %ERRORLEVEL%
34
- )
35
-
36
- if exist "%candidate_two%" (
37
- "%candidate_two%" %*
38
- exit /b %ERRORLEVEL%
39
- )
40
-
41
- echo [crust] Missing platform package for Windows %host_arch% >&2
42
- echo [crust] Tried: %candidate_one% >&2
43
- echo [crust] Tried: %candidate_two% >&2
44
- echo [crust] Reinstall dependencies on this platform and ensure optional dependencies are enabled. >&2
45
- exit /b 1