Skip to content

Commit 202325b

Browse files
authored
fix(build): isolate shared/common declaration emit from @types auto-inclusion (#3306)
The standalone tsc call in ensure-types.cjs ran without a tsconfig, so TypeScript auto-loaded every @types/* package visible in node_modules. When pnpm hoisted the deprecated @types/minimatch@6 stub (a transitive dep of @types/glob, contains no .d.ts), tsc failed with TS2688 mid-build. Write a temp tsconfig with types: [] and invoke tsc -p, making the packaging emit independent of which @types/* happen to be hoisted.
1 parent 0a4b0b3 commit 202325b

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

packages/superdoc/scripts/ensure-types.cjs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
const fs = require('node:fs');
4+
const os = require('node:os');
45
const path = require('node:path');
56

67
// SD-2864: canonical taxonomy for the published type surface. Mirrors
@@ -71,21 +72,36 @@ const SHARED_COMMON_DTS_TARGETS = typeSurface.sharedCommonDtsTargets;
7172
const sharedCommonDistDir = path.join(distRoot, 'shared/common');
7273
fs.mkdirSync(sharedCommonDistDir, { recursive: true });
7374
const sources = SHARED_COMMON_DTS_TARGETS.map((f) => path.join(repoRoot, 'shared/common', f));
74-
const tscResult = _spawnSync(
75-
tscBin,
76-
[
77-
'--declaration',
78-
'--emitDeclarationOnly',
79-
'--skipLibCheck',
80-
'--target', 'ES2022',
81-
'--module', 'ESNext',
82-
'--moduleResolution', 'bundler',
83-
'--outDir', sharedCommonDistDir,
84-
'--rootDir', path.join(repoRoot, 'shared/common'),
85-
...sources,
86-
],
87-
{ stdio: 'inherit' },
75+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'superdoc-ensure-types-'));
76+
const tempTsconfig = path.join(tempDir, 'tsconfig.shared-common.json');
77+
// Keep this packaging-only emit independent of whichever @types packages pnpm hoists.
78+
fs.writeFileSync(
79+
tempTsconfig,
80+
`${JSON.stringify(
81+
{
82+
compilerOptions: {
83+
declaration: true,
84+
emitDeclarationOnly: true,
85+
skipLibCheck: true,
86+
target: 'ES2022',
87+
module: 'ESNext',
88+
moduleResolution: 'bundler',
89+
types: [],
90+
outDir: sharedCommonDistDir,
91+
rootDir: path.join(repoRoot, 'shared/common'),
92+
},
93+
files: sources,
94+
},
95+
null,
96+
2,
97+
)}\n`,
8898
);
99+
let tscResult;
100+
try {
101+
tscResult = _spawnSync(tscBin, ['-p', tempTsconfig], { stdio: 'inherit' });
102+
} finally {
103+
fs.rmSync(tempDir, { recursive: true, force: true });
104+
}
89105
if (tscResult.status !== 0) {
90106
console.error('[ensure-types] tsc failed emitting shared/common declarations');
91107
process.exit(1);

0 commit comments

Comments
 (0)