diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
new file mode 100644
index 0000000..e0680ef
--- /dev/null
+++ b/.github/workflows/docs.yml
@@ -0,0 +1,63 @@
+name: Docs
+
+on:
+ push:
+ branches: [ "main" ]
+ paths: [ "docs/**", ".github/workflows/docs.yml" ]
+ pull_request:
+ paths: [ "docs/**", ".github/workflows/docs.yml" ]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+ pages: write
+ id-token: write
+
+concurrency:
+ group: docs-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Install Rust toolchain
+ uses: dtolnay/rust-toolchain@stable
+
+ - name: Install Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 22
+
+ - name: Build craft
+ run: cargo build --release -p craft
+
+ - name: Install the site's dependencies with craft
+ working-directory: docs
+ run: ../target/release/craft ci
+
+ - name: Build the site
+ working-directory: docs
+ run: ../target/release/craft run docs:build
+
+ - name: Upload the site
+ if: github.event_name != 'pull_request'
+ uses: actions/upload-pages-artifact@v3
+ with:
+ path: docs/.vitepress/dist
+
+ deploy:
+ if: github.event_name != 'pull_request'
+ needs: build
+ runs-on: ubuntu-latest
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+
+ steps:
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v4
diff --git a/Makefile b/Makefile
index fe6a811..0c18957 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-.PHONY: build test lint fmt craft real-world
+.PHONY: build test lint fmt craft real-world docs
all: build test lint
@@ -18,6 +18,10 @@ fmt:
real-world:
cargo test -p craft --test real_world -- --ignored
+docs:
+ cargo build -q --release -p craft
+ cd docs && ../target/release/craft install && ../target/release/craft run docs:dev
+
craft:
cargo run -p craft -- $(filter-out $@,$(MAKECMDGOALS))
diff --git a/README.md b/README.md
index f847d3e..32b1988 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-
+
# π¦ Craft Package Manager
@@ -10,112 +10,43 @@
**Craft** is a fast, strict package manager for Node.js, written in Rust. It installs from the npm registry (or any npm-compatible one) into a pnpm-style `node_modules`, keeps a deterministic `craft.lock`, and runs dependency install scripts only for packages you trust.
+**π Documentation: [craftpkg.github.io/craft](https://craftpkg.github.io/craft/)**
+
## β¨ Features
-- π **Fast**: parallel resolution and downloads, packuments cached on disk and revalidated with ETags, files cloned (copy-on-write) from a global store. An unchanged project installs in milliseconds.
-- π **Deterministic**: `craft.lock` records every resolved version, tarball and integrity; `craft install --frozen-lockfile` (the default in CI) installs exactly that.
-- π¦ **Strict, isolated layout**: every package sees only the dependencies it declares, each project has its own `node_modules/.craft`, and the global store is never modified after extraction.
-- π§© **npm-compatible**: semver ranges, dist-tags, `npm:` aliases, git and tarball URLs, `file:` and `link:` dependencies, peer and optional dependencies, `os`/`cpu`/`libc` platform packages, `.npmrc` registries and auth.
-- π‘οΈ **Safe by default**: tarballs are verified against their integrity hash, and dependencies' install scripts run only when listed in `trustedDependencies`.
+- π **Fast**: parallel downloads, a revalidated metadata cache, and files cloned from a global store. An unchanged project installs in milliseconds.
+- π **Deterministic**: `craft.lock` pins every version, source and integrity hash; installs in CI are frozen by default.
+- π¦ **Strict**: every package sees only the dependencies it declares, so undeclared imports fail on your machine, not in production.
+- π‘οΈ **Safe by default**: tarballs are integrity-checked, and dependencies' install scripts run only when listed in `trustedDependencies`.
+- π§© **npm-compatible**: ranges, dist-tags, aliases, git, tarball, `file:` and `link:` dependencies, peers, platform packages, and `.npmrc` registries and auth.
+- π₯οΈ **Everywhere**: native binaries for Linux (glibc and musl), macOS and Windows.
## π Installation
-### One-line install
-
```bash
curl -fsSL https://raw.githubusercontent.com/craftpkg/craft/main/install.sh | bash
```
-The script downloads the binary for your platform (a static build on musl/Alpine), verifies its SHA-256 checksum, and installs it to `/usr/local/bin` when writable or `~/.local/bin` otherwise β no `sudo`. Set `CRAFT_INSTALL_DIR` to choose the directory and `CRAFT_VERSION` to pin a release.
-
-### From a release
-
-Download a binary and its `.sha256` from the [Releases](https://github.com/craftpkg/craft/releases) page: Linux (x64 and arm64, glibc and musl), macOS (Intel and Apple Silicon) and Windows (x64).
-
-On Windows, directory links are junctions and bins get `.cmd`, `.ps1` and sh shims like npm's, so neither administrator rights nor Developer Mode are needed; scripts run through `cmd`.
-
-### From source
-
-```bash
-git clone https://github.com/craftpkg/craft.git
-cd craft
-cargo install --path apps/craft
-```
+Or download a binary from the [Releases](https://github.com/craftpkg/craft/releases) page. See [Installation](https://craftpkg.github.io/craft/guide/installation) for Windows, checksums and building from source.
## π Usage
```bash
craft init # create a package.json
-craft install # install everything in package.json (alias: craft i)
-craft add react react-dom # add dependencies
-craft add -D typescript # β¦to devDependencies (-E exact, -O optional, -P peer)
-craft remove react # remove dependencies (aliases: rm, uninstall, un)
-craft update [pkgβ¦] # update within the ranges in package.json; --latest to move ranges
-craft outdated # show what has newer versions
-craft list --depth 1 # show the dependency tree (alias: ls)
-craft why ms # show why a package is installed
-craft run build # run a script, with its pre/post scripts (craft run lists them)
-craft start / craft test # shortcuts for craft run start / test
-craft tsc --noEmit # run a dependency's bin directly
-craft exec eslint . # run a dependency's bin, never a script
-craft dlx create-vite my-app # run a package without adding it (alias: craft x)
-craft trust esbuild # allow a dependency's install scripts, then install
+craft install # install everything in package.json
+craft add react # add a dependency (-D dev, -E exact, -O optional, -P peer)
+craft remove react # remove one
+craft update # update within your ranges; --latest to move them
+craft run build # run a script; craft tsc runs a dependency's bin
+craft dlx create-vite my-app # run a package without adding it
craft ci # clean, frozen install for CI
-craft cache clean --force # remove the global store and metadata cache
```
-Global flags: `--offline` (never touch the network), `--prefer-offline` (use cached metadata without revalidating), `--silent`, `--debug`. `craft -v` prints the version. Every command has `--help`.
-
-## π§ How it works
-
-- **Global store** β each package is extracted once into `~/.craft/store/v1/@-/` after its integrity is verified, and never written to afterwards.
-- **Per-project virtual store** β every package lives in `node_modules/.craft/@/node_modules/`, imported from the store by clone, hardlink or copy (whichever the filesystem supports), with its dependencies linked beside it. Your `node_modules/` entries are links into `.craft`. Packages that `require` something they never declared still find it through `node_modules/.craft/node_modules`, while your own code only sees what `package.json` lists.
-- **Peer dependencies** resolve to what the parent provides; a package used with different peers gets one copy per peer set (`ui@1.0.0_react@18.3.1`).
-- **`craft.lock`** is sorted JSON meant to be committed. With it, installs make no registry metadata requests at all; `craft add`, `craft remove` and `craft update` keep it up to date. Anything removed from `package.json` is pruned from `node_modules` on the next install.
-
-## π‘οΈ Install scripts
-
-Dependencies' `preinstall` / `install` / `postinstall` scripts (and implicit `node-gyp` builds) run only for packages listed in `package.json`:
-
-```json
-{
- "trustedDependencies": ["bcrypt", "esbuild"]
-}
-```
-
-Craft lists every package whose scripts it skipped; `craft trust ` adds it and builds it. Your project's own lifecycle scripts always run, and `--ignore-scripts` turns all of them off.
-
-## βοΈ Configuration
-
-Craft reads `.npmrc` from your home directory and the project, plus `npm_config_*` variables:
-
-```ini
-registry=https://registry.npmjs.org/
-@acme:registry=https://npm.pkg.github.com
-//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
-https-proxy=http://proxy.internal:8080
-fetch-retries=3
-network-concurrency=16
-```
-
-Supported keys: `registry`, `@scope:registry`, `//host/:_authToken`, `_auth`, `username` + `_password`, `https-proxy`, `proxy`, `noproxy`, `strict-ssl`, `cafile`, `fetch-retries`, `network-concurrency`, `offline`, `prefer-offline`. Credentials are only ever sent to the host they're configured for. HTTPS uses craft's bundled root certificates; point `cafile` at your CA's certificate to use a private registry or a TLS-inspecting proxy.
-
-| Environment variable | Purpose |
-| --- | --- |
-| `CRAFT_HOME` | Where the store and caches live (default `~/.craft`) |
-| `CRAFT_REGISTRY` | Override the default registry |
-| `CRAFT_OS` / `CRAFT_CPU` / `CRAFT_LIBC` | Install platform packages for another platform (e.g. building a Linux image on a Mac) |
-| `CI` | When set, installs require an up-to-date `craft.lock` |
+Every command is documented in the [CLI reference](https://craftpkg.github.io/craft/reference/cli).
## π€ Contributing
-Contributions are welcome! `make` runs formatting, lints and the full test suite against a local mock registry (the end-to-end tests need Node.js on `PATH`). `make real-world` runs scenarios with real packages against registry.npmjs.org and GitHub, and `docker/windows/test.sh` cross-compiles the tests for Windows and runs them under Wine.
-
-1. Fork the repository
-2. Create your feature branch (`git checkout -b feature/amazing-feature`)
-3. Commit your changes (`git commit -m 'Add some amazing feature'`)
-4. Push to the branch (`git push origin feature/amazing-feature`)
-5. Open a Pull Request
+Contributions are welcome! `make` runs formatting, lints and the full test suite. See [Contributing](https://craftpkg.github.io/craft/contributing/) for the architecture, the test suites and how to work on the docs.
## π License
diff --git a/REMAINING.md b/REMAINING.md
index 284c403..f2a5244 100644
--- a/REMAINING.md
+++ b/REMAINING.md
@@ -735,6 +735,8 @@ Measured: cold install of this repo's `package.json` β 4.8 s, 149 MB RSS; warm
> Done: the release workflow builds `aarch64-unknown-linux-gnu` (native arm64 runner) and static `x86_64`/`aarch64-unknown-linux-musl`, and publishes a `.sha256` beside every binary. reqwest now uses rustls with bundled Mozilla root certificates instead of OpenSSL, so musl builds need no system libraries or CA bundle (npm and JSR installs re-verified over HTTPS); like npm, private CAs are trusted through `cafile`. OS roots were tried first and dropped: loading the macOS keychain made parallel runs 6Γ slower and would fail in containers without `ca-certificates`. `install.sh` picks the musl build on musl systems, verifies the checksum (refuses a mismatch, warns when a release has none), installs to `/usr/local/bin` when writable or `~/.local/bin` without sudo, and takes `CRAFT_INSTALL_DIR`, `CRAFT_VERSION` and `CRAFT_DOWNLOAD_URL`; tested against a local release server with a valid, a tampered and a missing checksum. The README drops the `package-lock.json` and "`craft init` coming soon" claims and documents every command, the store and virtual-store layout, `craft.lock`, `trustedDependencies`, `.npmrc` keys and the `CRAFT_*` variables.
>
> Not verified locally: the new CI matrix entries themselves; they run on the next tag.
+>
+> Docs site: `docs/` is a VitePress site (guide, CLI reference, contributing) whose dependencies craft installs itself; `make docs` previews it and `.github/workflows/docs.yml` builds it with the craft of the same commit and deploys to GitHub Pages from `main`. Dogfooding it found that a published manifest with a non-string script (`speakingurl`'s `"blanket": { β¦ }`) failed to parse; like npm, non-string `scripts` / `dependencies` / `devDependencies` entries are now ignored.
- Release workflow: publish `sha256` checksums; `install.sh` verifies them; support `CRAFT_INSTALL_DIR` / `~/.local/bin` without sudo.
- Linux: add `aarch64-unknown-linux-gnu` and a `musl` static build.
diff --git a/apps/craft/tests/e2e/install.rs b/apps/craft/tests/e2e/install.rs
index b22b7d2..17fe12d 100644
--- a/apps/craft/tests/e2e/install.rs
+++ b/apps/craft/tests/e2e/install.rs
@@ -4,6 +4,26 @@ use testkit::{MockRegistry, PackageFixture};
use crate::common::{Project, block_on};
+#[test]
+fn installs_packages_whose_manifest_has_non_string_entries() {
+ let registry = MockRegistry::start();
+ registry.publish(PackageFixture::new("speakingurl", "14.0.1").manifest_field(
+ "scripts",
+ json!({ "test": "mocha", "blanket": { "pattern": ["/lib/"] } }),
+ ));
+ let project = Project::new(
+ ®istry,
+ json!({ "dependencies": { "speakingurl": "^14.0.0" } }),
+ );
+
+ project.craft().arg("install").assert().success();
+
+ assert_eq!(
+ project.required_version("speakingurl"),
+ Ok("14.0.1".to_string())
+ );
+}
+
#[test]
fn installs_dependencies_and_their_subtree() {
let registry = MockRegistry::start();
diff --git a/crates/package/src/npm.rs b/crates/package/src/npm.rs
index 61c1a74..3745f3a 100644
--- a/crates/package/src/npm.rs
+++ b/crates/package/src/npm.rs
@@ -11,11 +11,14 @@ pub struct PackageJson {
pub name: Option,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option,
+ #[serde(default, deserialize_with = "string_entries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scripts: Option>,
+ #[serde(default, deserialize_with = "string_entries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dependencies: Option>,
#[serde(rename = "devDependencies")]
+ #[serde(default, deserialize_with = "string_entries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dev_dependencies: Option>,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -162,6 +165,28 @@ pub struct NpmPackage {
pub versions: HashMap,
}
+/// Published manifests are loosely typed: some old ones put objects among their scripts
+/// (`"blanket": { "pattern": β¦ }`). Like npm, only the string entries count.
+fn string_entries<'de, D>(
+ deserializer: D,
+) -> std::result::Result