Skip to content

refactor(types): remove _internal-shims.d.ts soft-landing mechanism (SD-2942)#3155

Merged
caio-pizzol merged 2 commits intomainfrom
caio-pizzol/SD-2942-remove-shim-fallback
May 5, 2026
Merged

refactor(types): remove _internal-shims.d.ts soft-landing mechanism (SD-2942)#3155
caio-pizzol merged 2 commits intomainfrom
caio-pizzol/SD-2942-remove-shim-fallback

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Capstone follow-up to SD-2893. After every originally-shimmed package was relocated or guarded, the auto-generated _internal-shims.d.ts file ships empty. This PR removes the mechanism that wrote it.

The shim mechanism was a soft fallback: ensure-types.cjs scanned every dist d.ts for from '@superdoc/...' patterns and emitted a declare module 'X' { export type Y = any; } block for each unrelocated specifier. With SD-2893 complete, that path mostly swallows new private leaks as silent any instead of failing the build.

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

ensure-types.cjs changes:

  • Drop workspace-imports scanning loops, shim file write, triple-slash injection, and the SHIM_FORBIDDEN regression net (relocation rules + UNSHIMMED_PRIVATE_SPECIFIERS + audit Rule 1 cover the same ground).
  • Add explicit unlink for stale _internal-shims.d.ts from prior builds.
  • Keep shouldSkipWorkspaceShim as policy documentation for future audit work.

audit-declarations.cjs changes:

  • Rule 1 documentation updated to reflect that there is no shim fallback in steady state. Behavior unchanged: Rule 1 fails for any unrelocated private @superdoc/* specifier on the public surface.
  • Rule 3 documentation updated. Becomes a no-op when the file is absent (which is now steady state). Kept as defense if a stale tarball re-introduces the file.
  • Existing internalShimsPresent graceful-handling code stays as-is.

Hard-landing verified end-to-end. Synthetic injection of import('@superdoc/some-new-private-pkg').T into a public-reachable d.ts:

FAIL  Private @superdoc/* specifiers: 1 files / 1 occurrences
      distinct: @superdoc/some-new-private-pkg
FAIL findings: private-specifiers
Audit exit: 1

Pre-SD-2942 the same injection would have been silently shimmed.

Verified:

  • pnpm --filter superdoc build:es clean (audit OK, 10 guarded packages, no shim file emitted)
  • Consumer matrix: 47 passed, 0 failed, 0 warnings
  • Runtime smoke 4/4 against the freshly packed tarball
  • grep -r '_internal-shims' dist/ returns zero matches
  • Negative test confirms hard-landing on synthetic private-import injection (exit 1)

…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.
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 5, 2026 13:37
@linear
Copy link
Copy Markdown

linear Bot commented May 5, 2026

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…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.
@caio-pizzol caio-pizzol merged commit b4963d8 into main May 5, 2026
67 of 68 checks passed
@caio-pizzol caio-pizzol deleted the caio-pizzol/SD-2942-remove-shim-fallback branch May 5, 2026 15:31
@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.98

@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.54

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-dev/react v1.2.0-next.96

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.72

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.55

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

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

The release is available on GitHub release

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