Skip to content

refactor(types): centralize public-surface taxonomy in single config (SD-2864)#3161

Merged
caio-pizzol merged 7 commits intomainfrom
caio-pizzol/SD-2864-type-surface-config
May 5, 2026
Merged

refactor(types): centralize public-surface taxonomy in single config (SD-2864)#3161
caio-pizzol merged 7 commits intomainfrom
caio-pizzol/SD-2864-type-surface-config

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Stacked on #3155. Consolidates the workspace-relocation taxonomy that was previously duplicated across four files into a single source of truth.

The duplication: ensure-types.cjs, audit-declarations.cjs, vite.config.js, and tsconfig.json each carried parallel data about which packages get relocated, which sources to include, which packages to guard, and which specifiers are allowlisted. Adding a new relocation required coordinated edits in all four. PR #3144 (pm-adapter) and several SD-2893 stack PRs each shipped a regression caused by drift.

The fix: packages/superdoc/scripts/type-surface.config.cjs is now the canonical taxonomy. Each consumer derives what it needs:

  • ensure-types.cjs: RELOCATION_RULES, RELOCATION_GUARD_PACKAGES, UNSHIMMED_PRIVATE_SPECIFIERS, SHARED_COMMON_DTS_TARGETS, requiredEntryPoints, HANDWRITTEN_DTS_BLOCKLIST
  • audit-declarations.cjs: RELOCATION_GUARD_PACKAGES, RULE1_ALLOWLIST
  • vite.config.js: dts include list spreads relocations[*].viteIncludes after the foundational base entries (createRequire from ESM)
  • tsconfig.json stays hand-edited (it's JSON), but a new check-tsconfig-type-surface.cjs enforces parity in postbuild - drift fails the build with a clear message

Net diff: -138 +47 lines across the consumer scripts; +208 lines for the new config + parity check. Net is +117 because the config carries explanatory comments alongside the data, but the duplicated data is gone - the next contributor adding a relocation edits one place instead of four.

Verified:

  • pnpm --filter superdoc build:es clean (10 guarded packages, no shim emitted)
  • Consumer matrix 47/0/0
  • Declaration audit clean
  • Negative drift test: programmatically removing pm-adapter entries from tsconfig.json's include makes the parity check exit 1 with tsconfig.json \include` is missing relocation entries: ../layout-engine/pm-adapter/src/converter-context.ts (required by @superdoc/pm-adapter/converter-context.js)and a remediation hint. Restoring the entries exits 0 with✓ tsconfig.json mirrors 9 relocation include paths`.

Closes the SD-2828 cleanup arc. After SD-2942 (#3155) and this PR land, the type-surface contract has both substantive enforcement (audit Rule 1 + Rule 3) and structural coherence (single-source-of-truth taxonomy + tsconfig parity check).

…SD-2942)

After SD-2893 drained every shim entry to zero, the auto-generated
_internal-shims.d.ts file ships empty (header comments only). The
auto-capture mechanism that wrote it is no longer load-bearing: it
was a soft fallback that captured any unrelocated private @superdoc/*
specifier in dist d.ts files and silently shimmed it as `any`. With
the relocation rules + RULE1_ALLOWLIST + UNSHIMMED_PRIVATE_SPECIFIERS
now covering the entire workspace surface, that soft path mostly
swallows new private leaks instead of failing the build.

This change makes new leaks fail loudly:

- ensure-types.cjs: drop the workspace-imports scanning loops, the
  shim-file write, the triple-slash reference injection, and the
  SHIM_FORBIDDEN regression net (now redundant with the relocation
  rules + audit Rule 1). Add an explicit unlink for any stale
  _internal-shims.d.ts left over from prior builds.
- audit-declarations.cjs: update the rule documentation. Rule 1 now
  fails for any unrelocated private @superdoc/* specifier; Rule 3
  becomes a no-op in steady state (kept as defense against stale
  tarballs or future re-introduction). The internalShimsPresent
  graceful-handling already existed in audit code; no behavioral
  change there.

A future PR that introduces a new private @superdoc/* import on the
public surface fails audit Rule 1 at build time. Verified with a
synthetic injection: import('@superdoc/some-new-private-pkg').T in a
public-reachable d.ts produces FAIL findings: private-specifiers and
exits 1.

Net diff: -167 +41 lines across the two scripts.

Verified: build:es clean (10 guarded packages, no shim file emitted),
consumer matrix 47/0/0, runtime smoke 4/4, dist has zero
_internal-shims references, negative test confirms hard-landing.
…942)

The comment above the inline-replacement block was inherited from the
pre-SD-2893 era and described two things that are no longer true after
the shim drain:

1. "fall through to the ambient shim block below" — SD-2942 (this PR)
   removes the shim block, so non-main-entry @superdoc/common imports
   now resolve via the RELOCATION_RULES rewriter, not via a fallback
   shim.
2. "Comment, CommentContent, CommentJSON ... not on the public surface"
   — SD-2893 stack 6 (PR #3154) relocated these types via the bare
   @superdoc/common rule mapping to comments-types.d.ts. `Comment` is
   now publicly importable as
   `import type { Comment } from 'superdoc/super-editor'`.

Replace the block with a description of what the inline-replacement
step actually does today: handle the main entry's runtime-value imports
(DOCX, PDF, HTML, getFileObject, compareVersions, BlankDOCX) which are
not type-only and so the relocation rule cannot serve them.
…(SD-2864)

The same workspace-relocation taxonomy was duplicated across four files:
ensure-types.cjs, audit-declarations.cjs, vite.config.js, and tsconfig.json.
Adding a new public-surface relocation required coordinated edits in all
four. PR #3144 (pm-adapter) and several SD-2893 stack PRs each shipped a
regression caused by drift between these lists.

Add packages/superdoc/scripts/type-surface.config.cjs as the single source
of truth and refactor each consumer to derive what it needs.

Consumer changes:

- ensure-types.cjs: derives RELOCATION_RULES, RELOCATION_GUARD_PACKAGES,
  UNSHIMMED_PRIVATE_SPECIFIERS, SHARED_COMMON_DTS_TARGETS,
  requiredEntryPoints, and HANDWRITTEN_DTS_BLOCKLIST from the config.
- audit-declarations.cjs: derives RELOCATION_GUARD_PACKAGES and
  RULE1_ALLOWLIST from the config.
- vite.config.js: derives the dts include list by spreading
  relocations[*].viteIncludes after the foundational base entries (uses
  createRequire to load the CJS config from ESM Vite config).
- tsconfig.json stays hand-edited (it's plain JSON), but a new
  check-tsconfig-type-surface.cjs script enforces parity by verifying
  every relocation's tsconfigIncludes paths are present in tsconfig.json's
  include array. Wired into postbuild so drift fails the build.

Net diff: -138 +47 lines across the consumer scripts plus +208 lines for
the new config + parity check. The config is the authoritative taxonomy;
the parity check is the safety net that makes accidental drift loud.

Verified: build:es clean (10 guarded packages, no shim file emitted),
consumer matrix 47/0/0, declaration audit clean. Negative drift test:
removing pm-adapter entries from tsconfig.json's include makes the parity
check exit 1 with a clear message naming the missing entries and the
relocation that requires them; restoring exits 0.
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 5, 2026 15:08
@linear
Copy link
Copy Markdown

linear Bot commented May 5, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b84be7b33

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/superdoc/scripts/check-tsconfig-type-surface.cjs Outdated
Base automatically changed from caio-pizzol/SD-2942-remove-shim-fallback to main May 5, 2026 15:31
…ig (SD-2864)

The previous commit's claim that these two lists derive from
type-surface.config.cjs was wrong: the inline literals in
ensure-types.cjs were never replaced. The build kept passing because
the values matched, but a contributor editing the config without also
editing the script would silently land a half-applied change.

Replace the inline `new Set([...])` for HANDWRITTEN_DTS_BLOCKLIST and
the inline string array for SHARED_COMMON_DTS_TARGETS with references
to the config's handwrittenDtsBlocklist and sharedCommonDtsTargets so
the original commit's claims hold.

Also annotate the two @superdoc/common relocation entries' empty
viteIncludes/tsconfigIncludes arrays inline so a reader does not have
to walk back to the module-level JSDoc to learn they are emitted via
the tsc-postbuild path.
The previous fix commit caught HANDWRITTEN_DTS_BLOCKLIST and
SHARED_COMMON_DTS_TARGETS but missed requiredEntryPoints, which
remained inline. With this commit all three lists in ensure-types.cjs
that the SD-2864 PR description claims to derive from the config
actually do.

Verified: build clean, the three list lengths read from
type-surface.config.cjs match what was previously hardcoded
(requiredEntryPoints: 4, sharedCommonDtsTargets: 3,
handwrittenDtsBlocklist: 1).
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

caio-pizzol and others added 2 commits May 5, 2026 12:56
The original check only fired on missing-entry drift (config requires
X, tsconfig is missing X). It tolerated stale-entry drift (tsconfig
has Y, config no longer requires Y), undermining the single-source-of-
truth claim: a relocation removed from type-surface.config.cjs could
leave a stale tsconfig include compiling against source the type
surface no longer claims to manage.

Add baseTsconfigIncludes to type-surface.config.cjs for the
foundational source roots that aren't relocations
(`src`, `../super-editor/src`, `../document-api/src`). The check now
asserts tsconfig.include equals exactly baseTsconfigIncludes plus
relocations[*].tsconfigIncludes - no more, no less.

Catches three drift modes now:
  1. New relocation in config but not mirrored in tsconfig.
  2. Relocation removed from config but tsconfig entry left stale.
  3. Foundational base entry dropped from tsconfig by mistake.

Verified end-to-end:
  - Clean build passes (12 expected paths matched exactly)
  - Synthetic missing-entry drift exits 1 with named owner
  - Synthetic stale-entry drift exits 1 with remediation hint
  - Restored exits 0
@caio-pizzol caio-pizzol self-assigned this May 5, 2026
@caio-pizzol caio-pizzol merged commit ef85846 into main May 5, 2026
66 of 67 checks passed
@caio-pizzol caio-pizzol deleted the caio-pizzol/SD-2864-type-surface-config branch May 5, 2026 17:32
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.55

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in vscode-ext v2.3.0-next.99

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in @superdoc-dev/react v1.2.0-next.97

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in superdoc-cli v0.8.0-next.73

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in superdoc v1.30.0-next.56

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in superdoc-sdk v1.8.0-next.56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants