Repository navigation
feat(blocks): cdk-blocks docs prints the bundled Building Block docs by name - #1511
Conversation
🦋 Changeset detectedLatest commit: aa9bb91 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
9ea95be to
a1fd549
Compare
|
The Both are false positives. |
…by name `cdk-blocks docs` reads the docs that ship in @aws-blocks/blocks wherever npm installed the package, so a coding agent or a developer finds a block's docs and exact signatures in one call instead of resolving paths in node_modules: - `cdk-blocks docs` lists the blocks, their classes and what each does, then the framework docs. - `cdk-blocks docs <block>...` prints each block's README; `--api` prints its API report instead. A block is its class (DistributedTable), its folder (bb-distributed-table) or the folder without bb-; a doc path (bb-cron-job/DESIGN.md) prints that file. - `cdk-blocks docs <name>` prints the import line, the declaration and the README section of an export, an option or Owner.member (inherited members included). - `--section <topic>`, `--exports [filter...]` and `--search <term>` print one section, the importable names and their entry, or matching lines with their section. Every printed doc starts with `# <folder>/<file>` alone on its line (`# bb-kv-store/README.md`, `# README.md`), and that doc path prints the file again. No output names a path on disk: headers, search preambles, the listing, errors, hints and --help never point into node_modules. Unknown names and sections are usage errors (exit 2) that name the closest matches. The CLI exits 0 when its reader closes the pipe early (`| head`), and arguments after `--` are names for docs. The README's CLI table lists the command.
- Secret.get and other members of a forgotten export resolve from the type file an app reads (the
package's types export), not the entry the CLI's own conditions pick (cdk, browser).
- --section '(' or '' names no section (exit 2) instead of the doc's first section.
- A doc path the block lacks exits 2, like an unknown name.
- A name over 200 characters is unknown before it reaches a RegExp; the error quotes its start.
- The regex sink guard allowlists sectionMentioning()'s two escaped patterns.
- The help, examples and comments name KVStore now that DistributedTable is folded into it; the CLI
tests read KVStore's docs. The usage test escapes every regex metacharacter.
Problem
A coding agent or developer working in an AWS Blocks app needs a block's docs and exact signatures for the version the app has installed. Those docs ship in
@aws-blocks/blocks, but finding them means resolving paths insidenode_modules(hoisted or not), and reading a block's API report to find one option's declaration.Issue #, if available: none
Stack: 3 of 5 (base: #1510). The pointers that send readers to this command are in #1512, and #1521 adds
--output json.Rebased on
mainafter #1453 (KVStore consolidation): the help, examples and CLI tests nameKVStore(bb-kv-store) where they namedDistributedTable. Review fixes are in their own commit.Changes
cdk-blocks docs(@aws-blocks/blocks, minor) prints the bundled docs by name, from wherever npm installed the package:cdk-blocks docslists the blocks, their classes and what each does, then the framework docs (guide, the package README;troubleshooting).cdk-blocks docs <block>...prints each block's README;--apiprints its API report instead. A block is its class (KVStore), its folder (bb-kv-store) or the folder withoutbb-; a doc path (bb-cron-job/DESIGN.md) prints that file.cdk-blocks docs <name>prints the import line, the declaration and the README section of an export, a type, an option orOwner.member(inherited members included; declarations an API report leaves out come from the installed type files).--section <topic>,--exports [filter...]and--search <term>print one section, the importable names and the entry to import each from, or matching lines with their section.Output names no path on disk. Every printed doc starts with
# <folder>/<file>alone on its line (# bb-kv-store/README.md;# README.mdfor the package README), with a(lines a-b)line under it for a section, and that doc path prints the file again (cdk-blocks docs README.mdworks too). A type file is named by its package and path (# @aws-blocks/bb-secret/dist/index.mock.d.ts). The listing,--search's first line, errors,Try:hints and--helpname no absolute path either, so nothing the command prints points intonode_modules. (The text of a few shipped docs mentionsnode_moduleson its own, for example core's README on framework detection; the command prints docs as they are.)Unknown names, sections and doc files are usage errors (exit 2) that name the closest matches and the doc lines that mention the name;
--searchand--exportswith no match exit 1. A topic with no letters or digits (--section '(') names no section, and a name over 200 characters is unknown before any lookup. Declarations an API report leaves out (SecretImplforSecret.get) come from the type file of the package'stypesexport, whatever conditions the CLI runs under. The CLI exits 0 when its reader closes the pipe early (| head), and arguments after--are names for docs. The package README's CLI table and its "Output and exit codes" section describe the command.No breaking change: a new command; the bundled
docs/folder is unchanged.Validation
Run locally at the stack top (
f05527191, onmainat03778d9f6) with Node 22.23.1 (.nvmrc):npm run build,npm run lint(warnings only),npm run lint:deps: exit 0.node --test scripts/sink-guards/*.test.mjs): 35 pass, 0 fail (ci(kotlin): pass the emulator script path through env #1603 fixed the workflows site from ci(kotlin): retry the Android e2e leg when the device drops out #1600).cdk-blocks docstests (docs,bin,parse,help) with@aws-blocks/blocks'docs-pointers.test.js: 110 pass, 0 fail;@aws-blocks/create-blocks-app'sdocs-pointers.test.js: 5 pass;@aws-blocks/bb-auth'sreadme-recipes.test.js: 8 pass.The full suites ran on the previous head (
b8a78177a, onmainatd01c34c96), Node 22.23.1, before this rebase onto nine moremaincommits; the rebase changed onlybb-kv-store/README.md(a conflict with #1608) in this stack's own diff:npm run test:e2e:local: exit 0; 580 tests, 574 pass, 0 fail, 6 skipped.npm test: 13,802 tests, 13,767 pass, 21 fail, 10 skipped. Every failure is a dev-server, signal or file-watcher test incore,hostingorblocks'cli/context.test.js(none incdk-blocks docs,bb-auth,bb-kv-storeorcreate-blocks-app), and the log has 46EMFILEerrors fromfs.watch: this machine'sfs.inotify.max_user_instances(128) was used up by other processes. CI runs these suites.No sandbox run: nothing here changes deployed behaviour or serialization.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.