Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions packages/superdoc/scripts/ensure-types.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');

// SD-2864: canonical taxonomy for the published type surface. Mirrors
Expand Down Expand Up @@ -71,21 +72,36 @@ const SHARED_COMMON_DTS_TARGETS = typeSurface.sharedCommonDtsTargets;
const sharedCommonDistDir = path.join(distRoot, 'shared/common');
fs.mkdirSync(sharedCommonDistDir, { recursive: true });
const sources = SHARED_COMMON_DTS_TARGETS.map((f) => path.join(repoRoot, 'shared/common', f));
const tscResult = _spawnSync(
tscBin,
[
'--declaration',
'--emitDeclarationOnly',
'--skipLibCheck',
'--target', 'ES2022',
'--module', 'ESNext',
'--moduleResolution', 'bundler',
'--outDir', sharedCommonDistDir,
'--rootDir', path.join(repoRoot, 'shared/common'),
...sources,
],
{ stdio: 'inherit' },
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'superdoc-ensure-types-'));
const tempTsconfig = path.join(tempDir, 'tsconfig.shared-common.json');
// Keep this packaging-only emit independent of whichever @types packages pnpm hoists.
fs.writeFileSync(
tempTsconfig,
`${JSON.stringify(
{
compilerOptions: {
declaration: true,
emitDeclarationOnly: true,
skipLibCheck: true,
target: 'ES2022',
module: 'ESNext',
moduleResolution: 'bundler',
types: [],
outDir: sharedCommonDistDir,
rootDir: path.join(repoRoot, 'shared/common'),
},
files: sources,
},
null,
2,
)}\n`,
);
let tscResult;
try {
tscResult = _spawnSync(tscBin, ['-p', tempTsconfig], { stdio: 'inherit' });
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
if (tscResult.status !== 0) {
console.error('[ensure-types] tsc failed emitting shared/common declarations');
process.exit(1);
Expand Down
Loading