|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | 3 | const fs = require('node:fs'); |
| 4 | +const os = require('node:os'); |
4 | 5 | const path = require('node:path'); |
5 | 6 |
|
6 | 7 | // SD-2864: canonical taxonomy for the published type surface. Mirrors |
@@ -71,21 +72,36 @@ const SHARED_COMMON_DTS_TARGETS = typeSurface.sharedCommonDtsTargets; |
71 | 72 | const sharedCommonDistDir = path.join(distRoot, 'shared/common'); |
72 | 73 | fs.mkdirSync(sharedCommonDistDir, { recursive: true }); |
73 | 74 | 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`, |
88 | 98 | ); |
| 99 | + let tscResult; |
| 100 | + try { |
| 101 | + tscResult = _spawnSync(tscBin, ['-p', tempTsconfig], { stdio: 'inherit' }); |
| 102 | + } finally { |
| 103 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 104 | + } |
89 | 105 | if (tscResult.status !== 0) { |
90 | 106 | console.error('[ensure-types] tsc failed emitting shared/common declarations'); |
91 | 107 | process.exit(1); |
|
0 commit comments