Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1f7e2e7
fix: Ignore non-string manifest entries
shahen94 Oct 24, 2026
49cdee8
test: Cover manifests with non-string entries
shahen94 Oct 24, 2026
765ef19
docs: Add the docs site package
shahen94 Oct 24, 2026
ee67612
docs: Lock the docs site dependencies
shahen94 Oct 24, 2026
37f916e
docs: Ignore VitePress output
shahen94 Oct 24, 2026
3d8584e
docs: Configure the docs site
shahen94 Oct 24, 2026
bba5ca9
docs: Add the home page
shahen94 Oct 24, 2026
5a2c5f2
docs: Add the Introduction guide
shahen94 Oct 24, 2026
92489b4
docs: Add the Installation guide
shahen94 Oct 24, 2026
4ea937e
docs: Add the Quick start guide
shahen94 Oct 24, 2026
e761b11
docs: Add the How it works guide
shahen94 Oct 24, 2026
c289eb7
docs: Add the Lockfile guide
shahen94 Oct 24, 2026
c0b1e7b
docs: Add the Dependency sources guide
shahen94 Oct 24, 2026
f70a92b
docs: Add the Install scripts guide
shahen94 Oct 24, 2026
9e7dadc
docs: Add the Platform packages guide
shahen94 Oct 24, 2026
d4bd058
docs: Add the Configuration guide
shahen94 Oct 24, 2026
0a4c4d8
docs: Add the Continuous integration guide
shahen94 Oct 24, 2026
1316d0a
docs: Add the Windows guide
shahen94 Oct 24, 2026
2a0b5c4
docs: Add the Migrating from npm or pnpm guide
shahen94 Oct 24, 2026
093cbc3
docs: Add the Troubleshooting guide
shahen94 Oct 24, 2026
7929e0b
docs: Add the CLI overview
shahen94 Oct 24, 2026
ffabb9a
docs: Add the craft install reference
shahen94 Oct 24, 2026
1ffd980
docs: Add the craft add reference
shahen94 Oct 24, 2026
0f261b5
docs: Add the craft remove reference
shahen94 Oct 24, 2026
2e3568b
docs: Add the craft update reference
shahen94 Oct 24, 2026
8e94082
docs: Add the craft outdated reference
shahen94 Oct 24, 2026
9436b60
docs: Add the craft list reference
shahen94 Oct 24, 2026
49687a0
docs: Add the craft why reference
shahen94 Oct 24, 2026
6ce97b1
docs: Add the craft run reference
shahen94 Oct 24, 2026
2492e06
docs: Add the craft exec reference
shahen94 Oct 24, 2026
cfde69d
docs: Add the craft dlx reference
shahen94 Oct 24, 2026
a05d8d2
docs: Add the craft trust reference
shahen94 Oct 24, 2026
2ac480b
docs: Add the craft init reference
shahen94 Oct 24, 2026
0e11519
docs: Add the craft ci reference
shahen94 Oct 24, 2026
022aa45
docs: Add the craft cache reference
shahen94 Oct 24, 2026
c441ac1
docs: Add the contributing overview
shahen94 Oct 24, 2026
c4c13c0
docs: Add the architecture page
shahen94 Oct 24, 2026
9b5f9e1
docs: Add the testing page
shahen94 Oct 24, 2026
0c5738a
ci: Build and deploy the docs site
shahen94 Oct 24, 2026
22352d1
build: Add make docs
shahen94 Oct 24, 2026
e6773f0
docs: Point the README at the docs site
shahen94 Oct 24, 2026
d5ac3fc
docs: Record the docs site
shahen94 Oct 24, 2026
4e04249
docs: Move the logo into the site's public folder
shahen94 Oct 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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))

Expand Down
105 changes: 18 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="docs/assets/logo.png" alt="Craft Logo" width="200" />
<img src="docs/public/logo.png" alt="Craft Logo" width="200" />
</p>

# 📦 Craft Package Manager
Expand All @@ -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/<name>@<version>-<hash>/` after its integrity is verified, and never written to afterwards.
- **Per-project virtual store** — every package lives in `node_modules/.craft/<name>@<version>/node_modules/<name>`, imported from the store by clone, hardlink or copy (whichever the filesystem supports), with its dependencies linked beside it. Your `node_modules/<dep>` 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 <pkg>` 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

Expand Down
2 changes: 2 additions & 0 deletions REMAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<asset>.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.
Expand Down
20 changes: 20 additions & 0 deletions apps/craft/tests/e2e/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
&registry,
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();
Expand Down
47 changes: 47 additions & 0 deletions crates/package/src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ pub struct PackageJson {
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(default, deserialize_with = "string_entries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub scripts: Option<HashMap<String, String>>,
#[serde(default, deserialize_with = "string_entries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dependencies: Option<HashMap<String, String>>,
#[serde(rename = "devDependencies")]
#[serde(default, deserialize_with = "string_entries")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dev_dependencies: Option<HashMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -162,6 +165,28 @@ pub struct NpmPackage {
pub versions: HashMap<String, PackageJson>,
}

/// 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<Option<HashMap<String, String>>, D::Error>
where
D: serde::Deserializer<'de>,
{
let value = serde_json::Value::deserialize(deserializer)?;
let serde_json::Value::Object(entries) = value else {
return Ok(None);
};
let strings = entries
.into_iter()
.filter_map(|(key, value)| match value {
serde_json::Value::String(text) => Some((key, text)),
_ => None,
})
.collect();
Ok(Some(strings))
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -218,6 +243,28 @@ mod tests {
assert_eq!(manifest.trusted_dependencies(), ["bcrypt", "esbuild"]);
}

#[test]
fn test_ignores_entries_that_are_not_strings() {
let manifest: PackageJson = serde_json::from_str(
r#"{
"scripts": { "test": "mocha", "blanket": { "pattern": ["/lib/"] } },
"dependencies": { "ms": "^2.0.0", "broken": {} },
"devDependencies": []
}"#,
)
.unwrap();

assert_eq!(
manifest.scripts,
Some(HashMap::from([("test".to_string(), "mocha".to_string())]))
);
assert_eq!(
manifest.dependencies,
Some(HashMap::from([("ms".to_string(), "^2.0.0".to_string())]))
);
assert_eq!(manifest.dev_dependencies, None);
}

#[test]
fn test_install_scripts_in_order_with_implicit_node_gyp() {
let dir = tempfile::tempdir().unwrap();
Expand Down
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vitepress/cache
.vitepress/dist
Loading
Loading