Skip to content

Commit 0b7ec67

Browse files
authored
fix(types): drain bare @superdoc/common shim, reach zero shims (SD-2893) (#3154)
The remaining @superdoc/common shim is referenced by three internal dist d.ts files for four Comment* types (Comment, CommentContent, CommentJSON, CommentThreadingProfile). All four live in shared/common/comments-types.ts. Approach matches the list-marker-utils pattern from #3150: tsc-emit just comments-types.ts into dist/shared/common/, then rewrite bare @superdoc/common imports to that file. matchSubpaths: false because only the bare specifier is referenced; any future @superdoc/common/<other-subpath> import falls through to the shim generator and audit Rule 3 fires (because @superdoc/common is now in RELOCATION_GUARD_PACKAGES, the regex matches the subpath). Verified end-to-end: a synthetic @superdoc/common/some-other-subpath probe is left unchanged by ensure-types, the shim generator captures it, audit Rule 3 fails with exit 1. The existing inline-replacement step at ensure-types.cjs:89-119 that handles the main entry's runtime-value imports (DOCX, PDF, HTML, getFileObject, compareVersions, BlankDOCX) stays as-is. Two paths through the script address different concerns: - Inline-replacement: runtime values from @superdoc/common in superdoc/src/index.d.ts (handles those 6 specific imports) - Relocation rule: bare @superdoc/common type imports in three internal dist d.ts files (resolves to comments-types.d.ts) Shim count: 1 to 0. Final shim drain. _internal-shims.d.ts has no declare-module entries; all originally-shimmed @superdoc/* packages have been relocated, removed from the public surface, or guarded. Verified: build:es clean (10 guarded packages, 0 shim modules), consumer matrix 47/0/0, runtime smoke 4/4, dist has the relocation target at shared/common/comments-types.d.ts, the three consumer d.ts files now import from a relative path. Negative test confirms the audit gate catches future @superdoc/common subpath leaks.
1 parent 630e536 commit 0b7ec67

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

packages/superdoc/scripts/audit-declarations.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const RELOCATION_GUARD_PACKAGES = [
7373
'@superdoc/painter-dom',
7474
'@superdoc/pm-adapter',
7575
'@superdoc/style-engine',
76+
'@superdoc/common',
7677
'@superdoc/common/list-marker-utils',
7778
];
7879

packages/superdoc/scripts/ensure-types.cjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ if (handwrittenCopiedSuperEditor > 0) {
6666
// public surface. Adding shared/ to vite-plugin-dts's `include` would shift the
6767
// common-ancestor of all source files to the repo root and reorganise the
6868
// entire dist tree, so we run tsc directly for just the files we relocate.
69-
// Today: list-marker-utils plus its sibling layout-constants. Add new entries
70-
// here in lockstep with `RELOCATION_RULES` below.
71-
const SHARED_COMMON_DTS_TARGETS = ['list-marker-utils.ts', 'layout-constants.ts'];
69+
// Today: list-marker-utils plus its sibling layout-constants, and
70+
// comments-types (the four Comment* types referenced via bare @superdoc/common
71+
// imports in three internal-only dist d.ts files). Add new entries here in
72+
// lockstep with `RELOCATION_RULES` below.
73+
const SHARED_COMMON_DTS_TARGETS = ['list-marker-utils.ts', 'layout-constants.ts', 'comments-types.ts'];
7274
{
7375
const { spawnSync: _spawnSync } = require('node:child_process');
7476
const tscBin = path.join(repoRoot, 'node_modules', '.bin', 'tsc');
@@ -285,6 +287,20 @@ const RELOCATION_RULES = [
285287
distEntry: 'layout-engine/style-engine/src/ooxml/index.d.ts',
286288
matchSubpaths: false,
287289
},
290+
// SD-2893: bare @superdoc/common appears in three internal-only dist d.ts
291+
// files for the four Comment* types (Comment, CommentContent, CommentJSON,
292+
// CommentThreadingProfile). Point the bare specifier at comments-types.d.ts
293+
// (emitted via SHARED_COMMON_DTS_TARGETS) so the rewrite resolves to a real
294+
// file. matchSubpaths: false because only the bare specifier is referenced;
295+
// any future @superdoc/common/<other-subpath> import would not be auto-
296+
// rewritten, falling through to the audit gate. The runtime-value imports
297+
// from the main entry (DOCX, PDF, HTML, getFileObject, compareVersions,
298+
// BlankDOCX) are still handled by the inline-replacement step above.
299+
{
300+
pkg: '@superdoc/common',
301+
distEntry: 'shared/common/comments-types.d.ts',
302+
matchSubpaths: false,
303+
},
288304
];
289305

290306
// Guard packages that must never fall back to `_internal-shims.d.ts`.
@@ -300,6 +316,7 @@ const RELOCATION_GUARD_PACKAGES = [
300316
'@superdoc/painter-dom',
301317
'@superdoc/pm-adapter',
302318
'@superdoc/style-engine',
319+
'@superdoc/common',
303320
'@superdoc/common/list-marker-utils',
304321
];
305322

0 commit comments

Comments
 (0)