Skip to content

[heft-json-schema-typings-plugin]/[node-core-library] Add x-tsdoc-release-tag support and improve compile() usage#5631

Merged
iclanton merged 14 commits intomicrosoft:mainfrom
iclanton:x-tsdoc-tag
Feb 18, 2026
Merged

[heft-json-schema-typings-plugin]/[node-core-library] Add x-tsdoc-release-tag support and improve compile() usage#5631
iclanton merged 14 commits intomicrosoft:mainfrom
iclanton:x-tsdoc-tag

Conversation

@iclanton
Copy link
Member

@iclanton iclanton commented Feb 18, 2026

Summary

Schema authors can now add an "x-tsdoc-release-tag" custom property (e.g. "x-tsdoc-release-tag": "@public") to their JSON schema files. The heft-json-schema-typings-plugin will read this property and inject the corresponding TSDoc release tag into all exported declarations in the generated .d.ts files, so that API Extractor applies the correct release level when these types are re-exported from package entry points.

Additionally, the plugin now uses compile() instead of compileFromFile() from json-schema-to-typescript, reading file contents through the TypingsGenerator base class. A new formatWithPrettier option (defaulting to false) controls whether prettier formats the generated output. Cross-file $ref resolution is fixed by passing the absolute schema directory as cwd.

Details

@rushstack/heft-json-schema-typings-plugin:

  • Switched from compileFromFile() to compile(), letting TypingsGenerator handle file I/O. This enables the plugin to parse the schema JSON first, strip the custom x-tsdoc-release-tag property before passing it to the compiler, and inject the tag into the generated typings via post-processing.
  • Extracted the TSDoc tag injection logic into a separate TsDocTagHelpers.ts module with its own unit tests.
  • Fixed cross-file $ref resolution by passing path.dirname(filePath) (absolute path) as cwd to compile(), instead of a relative dirname that resolved to an empty string for root-level schemas.
  • Added a formatWithPrettier option (defaults to false) to the generator constructor, Heft plugin options, and the plugin's JSON schema. When false, prettier is skipped entirely, which also avoids a dynamic import() crash in Jest VM sandboxes on Node 22+.
  • Added a Jest moduleNameMapper stub for prettier in config/jest.config.json to prevent the module-load crash regardless of the format setting.

@rushstack/node-core-library:

  • Registered x-tsdoc-release-tag as a custom AJV keyword in JsonSchema so that strict mode validation does not reject schema files containing this property.

How it was tested

  • Added 3 snapshot unit tests for JsonSchemaTypingsGenerator: basic schema generation, x-tsdoc-release-tag injection, and cross-file $ref resolution between parent.schema.json and child.schema.json.
  • Added 6 snapshot unit tests for _addTsDocTagToExports covering: exports with existing JSDoc, exports without JSDoc, multiple exports, interface with properties, already-tagged exports, and multi-line JSDoc comments.
  • Added a unit test for the x-tsdoc-release-tag AJV keyword registration in node-core-library.
  • Ran rush build --to @rushstack/heft-json-schema-typings-plugin and rush build --to heft-json-schema-typings-plugin-test — all tests pass.

Impacted documentation

  • The heft-json-schema-typings-plugin.schema.json was updated with the new formatWithPrettier property.

…re-library.

The plugin now reads the `x-tsdoc-tag` property from schema JSON files and injects the specified TSDoc release tag into generated `.d.ts` declarations. `JsonSchema` registers `x-tsdoc-tag` as a known AJV keyword so that strict mode validation does not reject schema files containing this property.
…emaTypingsGenerator

- Replace compileFromFile with compile (reads file via TypingsGenerator base class)
- Parse and strip x-tsdoc-tag from schema before passing to compile()
- Pass format: false to skip prettier (avoids dynamic import issue in Jest)
- Add jest.config.json with moduleNameMapper to stub prettier at load time
- Add 3 snapshot tests: basic schema, x-tsdoc-tag injection, cross-file $ref
- Add test fixture schemas in src/test/schemas/
- Add formatWithPrettier option to JsonSchemaTypingsGenerator constructor
- Expose formatWithPrettier in the Heft plugin options and JSON schema
- Defaults to false (skip prettier formatting)
@github-project-automation github-project-automation bot moved this to Needs triage in Bug Triage Feb 18, 2026
@iclanton iclanton moved this from Needs triage to In Progress in Bug Triage Feb 18, 2026
- Rename x-tsdoc-tag to x-tsdoc-release-tag across all files
- Add X_TSDOC_RELEASE_TAG_KEYWORD constant exported from node-core-library
- Move validation into TsDocReleaseTagHelpers.ts (renamed from TsDocTagHelpers.ts)
- Validate that x-tsdoc-release-tag value is a single lowercase word starting with @
- Add unit tests for _validateTsDocReleaseTag
- Update changelog messages
@iclanton iclanton changed the title [heft-json-schema-typings-plugin]/[node-core-library] Add x-tsdoc-tag support and improve compile() usage [heft-json-schema-typings-plugin]/[node-core-library] Add x-tsdoc-release-tag support and improve compile() usage Feb 18, 2026
…ion support

- Remove X_TSDOC_RELEASE_TAG_KEYWORD constant from node-core-library exports
- Add allowVendorExtensionKeywords option (@beta) to IJsonSchemaLoadOptions
- When enabled, recursively scans schema tree for x-<vendor>-<keyword> keys
  and registers them with AJV so strict mode does not reject them
- Restore local X_TSDOC_RELEASE_TAG_KEY constant in heft-json-schema-typings-plugin
- Update node-core-library changelog to describe the new option
- Add tests for both enabled and disabled vendor extension behavior
- Rename allowVendorExtensionKeywords to rejectVendorExtensionKeywords
- Vendor extensions (x-<vendor>-<keyword>) are now accepted by default
- Set rejectVendorExtensionKeywords: true to restore strict behavior
- Update tests and changelog accordingly
- Add setup instructions with heft.json configuration example
- Document all plugin options (srcFolder, generatedTsFolders, formatWithPrettier)
- Document the x-tsdoc-release-tag vendor extension with usage example
- Note that JsonSchema accepts vendor extensions by default
- Test that non-root vendor extension keywords are rejected
- Test that malformed vendor tags (missing vendor segment, uppercase) are rejected
@iclanton iclanton enabled auto-merge (squash) February 18, 2026 20:08
@iclanton iclanton merged commit 3b74694 into microsoft:main Feb 18, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Closed in Bug Triage Feb 18, 2026
@iclanton iclanton deleted the x-tsdoc-tag branch February 18, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants