fix-imports.ts — drizzle-orm Source File
Architecture documentation for fix-imports.ts, a typescript file in the drizzle-orm codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 2f5e9e14_c063_bf83_8ef1_37a740ee091a["fix-imports.ts"] c10a8be4_82f5_0980_d482_1683db51662a["globals"] 2f5e9e14_c063_bf83_8ef1_37a740ee091a --> c10a8be4_82f5_0980_d482_1683db51662a 280f1710_c8f3_6949_a146_8e6bc686e489["node:path"] 2f5e9e14_c063_bf83_8ef1_37a740ee091a --> 280f1710_c8f3_6949_a146_8e6bc686e489 7d26bf42_e04b_b274_d5cf_8e2b69b87ce9["recast"] 2f5e9e14_c063_bf83_8ef1_37a740ee091a --> 7d26bf42_e04b_b274_d5cf_8e2b69b87ce9 9ade0a20_1901_c568_bc95_68e1789de5f2["typescript"] 2f5e9e14_c063_bf83_8ef1_37a740ee091a --> 9ade0a20_1901_c568_bc95_68e1789de5f2 style 2f5e9e14_c063_bf83_8ef1_37a740ee091a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
#!/usr/bin/env -S pnpm tsx
import 'zx/globals';
import path from 'node:path';
import { parse, print, visit } from 'recast';
import parser from 'recast/parsers/typescript';
function resolvePathAlias(importPath: string, file: string) {
if (importPath.startsWith('~/')) {
const relativePath = path.relative(path.dirname(file), path.resolve('dist.new', importPath.slice(2)));
importPath = relativePath.startsWith('.') ? relativePath : './' + relativePath;
}
return importPath;
}
function fixImportPath(importPath: string, file: string, ext: string) {
importPath = resolvePathAlias(importPath, file);
if (!/\..*\.(js|ts)$/.test(importPath)) {
return importPath;
}
return importPath.replace(/\.(js|ts)$/, ext);
}
const cjsFiles = await glob('dist/**/*.{cjs,d.cts}');
await Promise.all(cjsFiles.map(async (file) => {
const code = parse(await fs.readFile(file, 'utf8'), { parser });
visit(code, {
visitImportDeclaration(path) {
path.value.source.value = fixImportPath(path.value.source.value, file, '.cjs');
this.traverse(path);
},
visitExportAllDeclaration(path) {
path.value.source.value = fixImportPath(path.value.source.value, file, '.cjs');
this.traverse(path);
},
visitExportNamedDeclaration(path) {
if (path.value.source) {
path.value.source.value = fixImportPath(path.value.source.value, file, '.cjs');
}
this.traverse(path);
},
visitCallExpression(path) {
if (path.value.callee.type === 'Identifier' && path.value.callee.name === 'require') {
path.value.arguments[0].value = fixImportPath(path.value.arguments[0].value, file, '.cjs');
}
this.traverse(path);
},
visitTSImportType(path) {
path.value.argument.value = resolvePathAlias(path.value.argument.value, file);
this.traverse(path);
},
visitAwaitExpression(path) {
if (print(path.value).code.startsWith(`await import("./`)) {
path.value.argument.arguments[0].value = fixImportPath(path.value.argument.arguments[0].value, file, '.cjs');
}
// ... (77 more lines)
Domain
Subdomains
Functions
Dependencies
- globals
- node:path
- recast
- typescript
Source
Frequently Asked Questions
What does fix-imports.ts do?
fix-imports.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, QueryBuilders subdomain.
What functions are defined in fix-imports.ts?
fix-imports.ts defines 2 function(s): fixImportPath, resolvePathAlias.
What does fix-imports.ts depend on?
fix-imports.ts imports 4 module(s): globals, node:path, recast, typescript.
Where is fix-imports.ts in the architecture?
fix-imports.ts is located at drizzle-zod/scripts/fix-imports.ts (domain: DrizzleORM, subdomain: QueryBuilders, directory: drizzle-zod/scripts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free