MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / rewriteTsImportsInDir

Function rewriteTsImportsInDir

tsup.config.ts:10–29  ·  view source on GitHub ↗

* Recursively rewrites .ts imports to .js in all JavaScript files. * Required because Node.js cannot resolve .ts extensions at runtime.

(dir: string)

Source from the content-addressed store, hash-verified

8 * Required because Node.js cannot resolve .ts extensions at runtime.
9 */
10function rewriteTsImportsInDir(dir: string): void {
11 const entries = readdirSync(dir, { withFileTypes: true });
12 for (const entry of entries) {
13 const fullPath = join(dir, entry.name);
14 if (entry.isDirectory()) {
15 rewriteTsImportsInDir(fullPath);
16 } else if (entry.name.endsWith('.js')) {
17 let content = readFileSync(fullPath, 'utf-8');
18 // Rewrite: import ... from "./path.ts" or import ... from "../path.ts"
19 // Also handles: export ... from "./path.ts"
20 const rewritten = content.replace(
21 /((?:import|export)[^'"]*['"])([^'"]+)(\.ts)(['"])/g,
22 '$1$2.js$4',
23 );
24 if (rewritten !== content) {
25 writeFileSync(fullPath, rewritten, 'utf-8');
26 }
27 }
28 }
29}
30
31export default defineConfig({
32 // Include all TypeScript files for unbundled output

Callers 1

tsup.config.tsFile · 0.85

Calls 1

isDirectoryMethod · 0.80

Tested by

no test coverage detected