Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Use Zig 0.16.0, Node.js 24, and Yarn 1.22.22.
- Node is used for development and publishing only; the published command must execute the Zig binary directly.
- Keep version `0.0.1` synchronized in `package.json`, `build.zig.zon`, `src/version.zig`, tests, and documentation until a release change is explicitly requested.
- Treat `package.json` as the sole source of truth for the release version. Keep `build.zig.zon` at the neutral `0.0.0` placeholder and derive build/test/package expectations from `package.json`.
- Never change the `build.zig.zon` fingerprint.

## Required validation
Expand Down
15 changes: 15 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const package_json = std.Io.Dir.cwd().readFileAlloc(
b.graph.io,
"package.json",
b.allocator,
.limited(64 * 1024),
) catch @panic("failed to read package.json");
const package = std.json.parseFromSliceLeaky(
struct { version: []const u8 },
b.allocator,
package_json,
.{ .ignore_unknown_fields = true },
) catch @panic("failed to parse package.json");
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", package.version);

const lib = b.addModule("quick_commitlint", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
lib.addOptions("build_options", build_options);
const cli = b.createModule(.{
.root_source_file = b.path("src/cli.zig"),
.target = target,
Expand Down
3 changes: 2 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.{
.name = .quick_commitlint,
.version = "0.0.1",
.version = "0.0.0",
.fingerprint = 0x2a96102bdeea7bbc,
.minimum_zig_version = "0.16.0",
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"package.json",
"src",
"LICENSE",
"README.md",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"description": "A very fast native commit message linter built with Zig",
"scripts": {
"validate": "yarn format:check && yarn typecheck:scripts && yarn build && yarn test && yarn test:integration && yarn test:differential",
"format:check": "zig fmt --check src/root.zig src/main.zig src/cli.zig src/config.zig src/lint.zig src/version.zig build.zig",
"format:check": "zig fmt --check src/root.zig src/main.zig src/cli.zig src/config.zig src/lint.zig build.zig",
"typecheck:scripts": "tsc --project scripts/tsconfig.json",
"build": "zig build",
"build:release": "zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux -Dcpu=baseline",
Expand Down
7 changes: 5 additions & 2 deletions scripts/integration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { spawnSync } from 'child_process';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { join, resolve } from 'path';

const native = resolve(__dirname, '..', 'zig-out', 'bin', 'quick-commitlint');
const expectedVersion = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf8')).version;
const temp = mkdtempSync(join(tmpdir(), 'quick-commitlint-integration-'));

function run(args: string[], input?: string | Buffer, cwd = temp) {
Expand Down Expand Up @@ -86,7 +87,9 @@ try {

const version = run(['--version']);
expectStatus(version.status, 0, 'version');
if (String(version.stdout).trim() !== 'quick-commitlint 0.0.1') throw new Error('Incorrect version output.');
if (String(version.stdout).trim() !== `quick-commitlint ${expectedVersion}`) {
throw new Error('Incorrect version output.');
}

const help = run(['--help']);
expectStatus(help.status, 0, 'help');
Expand Down
8 changes: 6 additions & 2 deletions scripts/smoke-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { join, resolve } from 'path';

const projectRoot = resolve(__dirname, '..');
const distDir = join(projectRoot, 'dist');
const projectManifest = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'));
const manifest = JSON.parse(readFileSync(join(distDir, 'package.json'), 'utf8'));
const expectedVersion = projectManifest.version;

if (manifest.version !== '0.0.1') throw new Error('Packaged version is not 0.0.1.');
if (manifest.version !== expectedVersion) {
throw new Error(`Packaged version ${manifest.version} does not match ${expectedVersion}.`);
}
if (manifest.bin?.['quick-commitlint'] !== 'bin/quick-commitlint') {
throw new Error('Packaged bin does not point directly to the native executable.');
}
Expand Down Expand Up @@ -36,7 +40,7 @@ try {
});
const executable = join(installDir, 'node_modules', '.bin', 'quick-commitlint');
const version = execFileSync(executable, ['--version'], { encoding: 'utf8' }).trim();
if (version !== 'quick-commitlint 0.0.1') throw new Error(`Unexpected version: ${version}`);
if (version !== `quick-commitlint ${expectedVersion}`) throw new Error(`Unexpected version: ${version}`);
} finally {
rmSync(tarball, { force: true });
rmSync(installDir, { recursive: true, force: true });
Expand Down
2 changes: 1 addition & 1 deletion src/root.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Fast, dependency-free commit message linting.
pub const config = @import("config.zig");
pub const linting = @import("lint.zig");
pub const version = @import("version.zig").value;
pub const version = @import("build_options").version;

test {
_ = config;
Expand Down
1 change: 0 additions & 1 deletion src/version.zig

This file was deleted.

Loading