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
Open
Conversation
|
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.
5f51673 to
7197193
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
npx @google/design.md spec(andspec --rules/spec --format jsonwithout--rules-only) fails in an installed/published package with:Reproduction
Or from a packed tarball:
bun pm pack(ornpm pack), extract/install it elsewhere, and runnode dist/index.js spec.Root cause
bun build src/index.ts src/linter/index.ts --outdir distbundles the CLI intodist/index.js, so at runtimegetSpecContent()(Strategy 1 inspec-helpers.ts) resolvesspec.mdnext to the executing module — i.e.dist/spec.md. The build script copiesdocs/spec.mdonly todist/linter/, sodist/spec.mdis absent. Strategy 2 (the dev fallback) then resolves../../../../../docs/spec.md, which points outside an installed package, so the command throws.spec --rules-onlyhappened to keep working because that path doesn't readspec.md.This mirrors
spec-config.yaml, which the build already copies to bothdist/anddist/linter/for exactly the same reason —spec.mdwas just missing thedist/copy.Fix
docs/spec.mdtodist/as well asdist/linter/in the build script (one extracp, consistent with the existingspec-config.yamlhandling on the same line).npx design.md specto the tarball smoke test so the bundled-spec.mdresolution is exercised in CI. The existing Windows registry-smoke job only runsspec --rules-only, which skips spec loading, so this regression was not covered.Testing
bun test(packages/cli): 282 pass, 1 skip, 0 failbun run lint(tsc --noEmit): cleanbun run buildthennode dist/index.js spec,spec --rules,spec --format json: all exit0with full outputnode package/dist/index.js specfrom the installed layout: exits0with the full spec (confirmsdist/spec.mdships and resolves)