Skip to content

fix: bundle spec.md next to the CLI entry so the spec command works after build#118

Open
rmyndharis wants to merge 1 commit into
google-labs-code:mainfrom
rmyndharis:fix/spec-command-bundled-spec-md
Open

fix: bundle spec.md next to the CLI entry so the spec command works after build#118
rmyndharis wants to merge 1 commit into
google-labs-code:mainfrom
rmyndharis:fix/spec-command-bundled-spec-md

Conversation

@rmyndharis

Copy link
Copy Markdown

Summary

npx @google/design.md spec (and spec --rules / spec --format json without --rules-only) fails in an installed/published package with:

ERROR Failed to load spec.md.
  Bundled path: .../packages/cli/dist/spec.md
  Dev path:     .../docs/spec.md

Reproduction

cd packages/cli && bun run build
node dist/index.js spec        # throws "Failed to load spec.md"

Or from a packed tarball: bun pm pack (or npm pack), extract/install it elsewhere, and run node dist/index.js spec.

Root cause

bun build src/index.ts src/linter/index.ts --outdir dist bundles the CLI into dist/index.js, so at runtime getSpecContent() (Strategy 1 in spec-helpers.ts) resolves spec.md next to the executing module — i.e. dist/spec.md. The build script copies docs/spec.md only to dist/linter/, so dist/spec.md is absent. Strategy 2 (the dev fallback) then resolves ../../../../../docs/spec.md, which points outside an installed package, so the command throws.

spec --rules-only happened to keep working because that path doesn't read spec.md.

This mirrors spec-config.yaml, which the build already copies to both dist/ and dist/linter/ for exactly the same reason — spec.md was just missing the dist/ copy.

Fix

  • Copy docs/spec.md to dist/ as well as dist/linter/ in the build script (one extra cp, consistent with the existing spec-config.yaml handling on the same line).
  • Add npx design.md spec to the tarball smoke test so the bundled-spec.md resolution is exercised in CI. The existing Windows registry-smoke job only runs spec --rules-only, which skips spec loading, so this regression was not covered.

Testing

  • bun test (packages/cli): 282 pass, 1 skip, 0 fail
  • bun run lint (tsc --noEmit): clean
  • bun run build then node dist/index.js spec, spec --rules, spec --format json: all exit 0 with full output
  • Packed the tarball, extracted it, and ran node package/dist/index.js spec from the installed layout: exits 0 with the full spec (confirms dist/spec.md ships and resolves)

@google-cla

google-cla Bot commented Jun 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

`npx @google/design.md spec` failed with "Failed to load spec.md" in
installed/published packages. The bundler emits the CLI to dist/index.js,
so getSpecContent() resolves spec.md alongside it at dist/spec.md, but the
build only copied docs/spec.md to dist/linter/. The dev-path fallback then
resolves outside the package, so the command threw.

Copy spec.md to dist/ as well, mirroring how spec-config.yaml is already
copied to both dist/ and dist/linter/. Add a `spec` invocation to the
tarball smoke test so the bundled-spec.md resolution is exercised in CI.
@rmyndharis rmyndharis force-pushed the fix/spec-command-bundled-spec-md branch from 5f51673 to 7197193 Compare June 25, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant