@bemedev/codebase 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"remove.cjs","names":["transformModule","getFolderPath","PATH_PROPERTY","FILES_PROPERTY","consoleStars","path"],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n} from '../helpers';\nimport { CodebaseAnalysis, FileAnalysis } from '../schemas';\n\nconst transformModules = (\n entries: [string, FileAnalysis][],\n ...files: string[]\n) => {\n const cwd = process.cwd();\n const out = entries\n .map(\n ([key, { imports, relativePath }]) =>\n [key, relativePath, imports] as const,\n )\n .map(([key, relativePath, imports]) => {\n const specifiers = imports\n .map(({ moduleSpecifier }) => {\n return transformModule({\n cwd,\n relativePath,\n moduleSpecifier,\n });\n })\n .map(_path => [_path, `${_path}.index`]) // Add .index variants\n .flat()\n .filter(s => files.includes(s));\n\n return [key, Array.from(new Set(specifiers))] as const;\n });\n\n return out;\n};\n\nexport const remove = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n jsonConfigPath: string,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for removal.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, jsonConfigPath);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as string[];\n\n const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) =>\n files.includes(key),\n );\n\n const entries = entries2.filter(([key]) =>\n paths.some(p => key.startsWith(p)),\n );\n\n // Check dependencies before deletion\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\n\n entries.forEach(([key]) => {\n const modules = transformModules(entries2, ...files);\n const importedFroms = modules\n .filter(([, specifiers]) => specifiers.includes(key))\n .map(([k]) => k);\n\n const check = importedFroms.length > 0;\n\n console.log('modules', '=>', importedFroms);\n console.log('key', '=>', key);\n\n if (check) return cannotsRemove.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(`🔧 Deletion of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = CODEBASE_ANALYSIS[key].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\n\n let success = 0;\n const length = formatteds.length;\n\n formatteds.forEach(([key, path]) => {\n try {\n unlinkSync(path);\n console.log(` - 🗑️ ${key}`);\n file?.set(\n FILES_PROPERTY,\n files.filter(key1 => key1 !== key),\n );\n success++;\n } catch {\n console.error(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;;;AAWA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;CAAO,CAC/B,CAAC,CACA,KAAK,CAAC,KAAK,cAAc,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","names":["transformModule","getFolderPath","PATH_PROPERTY","FILES_PROPERTY","consoleStars","path"],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport { consoleStars, getFolderPath, transformModule } from '#helpers';\nimport { CodebaseAnalysis, FileAnalysis } from '../schemas';\n\nconst transformModules = (\n entries: [string, FileAnalysis][],\n ...files: string[]\n) => {\n const cwd = process.cwd();\n const out = entries\n .map(\n ([key, { imports, relativePath }]) =>\n [key, relativePath, imports] as const,\n )\n .map(([key, relativePath, imports]) => {\n const specifiers = imports\n .map(({ moduleSpecifier }) => {\n return transformModule({\n cwd,\n relativePath,\n moduleSpecifier,\n });\n })\n .map(_path => [_path, `${_path}.index`]) // Add .index variants\n .flat()\n .filter(s => files.includes(s));\n\n return [key, Array.from(new Set(specifiers))] as const;\n });\n\n return out;\n};\n\nexport const remove = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n jsonConfigPath: string,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for removal.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, jsonConfigPath);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as string[];\n\n const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) =>\n files.includes(key),\n );\n\n const entries = entries2.filter(([key]) =>\n paths.some(p => key.startsWith(p)),\n );\n\n // Check dependencies before deletion\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\n\n entries.forEach(([key]) => {\n const modules = transformModules(entries2, ...files);\n const importedFroms = modules\n .filter(([, specifiers]) => specifiers.includes(key))\n .map(([k]) => k);\n\n const check = importedFroms.length > 0;\n\n console.log('modules', '=>', importedFroms);\n console.log('key', '=>', key);\n\n if (check) return cannotsRemove.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(`🔧 Deletion of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = CODEBASE_ANALYSIS[key].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\n\n let success = 0;\n const length = formatteds.length;\n\n formatteds.forEach(([key, path]) => {\n try {\n unlinkSync(path);\n console.log(` - 🗑️ ${key}`);\n file?.set(\n FILES_PROPERTY,\n files.filter(key1 => key1 !== key),\n );\n success++;\n } catch {\n console.error(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;;;AAOA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;CAAO,CAC/B,CAAC,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,aAAa,QAChB,KAAK,EAAE,sBAAsB;GAC5B,OAAOA,gBAAAA,gBAAgB;IACrB;IACA;IACA;GACF,CAAC;EACH,CAAC,CAAC,CACD,KAAI,UAAS,CAAC,OAAO,GAAG,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,EACnC,gBAAgB,MAAM,EACtB,GAAG,OAAO,MAAM,EAAE,mBAiGnB,CAAC"}
1
+ {"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../src/functions/remove.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,YAAY,CAAC;AA+B5D,eAAO,MAAM,MAAM,GACjB,mBAAmB,gBAAgB,EACnC,gBAAgB,MAAM,EACtB,GAAG,OAAO,MAAM,EAAE,mBAiGnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"remove.js","names":[],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n} from '../helpers';\nimport { CodebaseAnalysis, FileAnalysis } from '../schemas';\n\nconst transformModules = (\n entries: [string, FileAnalysis][],\n ...files: string[]\n) => {\n const cwd = process.cwd();\n const out = entries\n .map(\n ([key, { imports, relativePath }]) =>\n [key, relativePath, imports] as const,\n )\n .map(([key, relativePath, imports]) => {\n const specifiers = imports\n .map(({ moduleSpecifier }) => {\n return transformModule({\n cwd,\n relativePath,\n moduleSpecifier,\n });\n })\n .map(_path => [_path, `${_path}.index`]) // Add .index variants\n .flat()\n .filter(s => files.includes(s));\n\n return [key, Array.from(new Set(specifiers))] as const;\n });\n\n return out;\n};\n\nexport const remove = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n jsonConfigPath: string,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for removal.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, jsonConfigPath);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as string[];\n\n const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) =>\n files.includes(key),\n );\n\n const entries = entries2.filter(([key]) =>\n paths.some(p => key.startsWith(p)),\n );\n\n // Check dependencies before deletion\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\n\n entries.forEach(([key]) => {\n const modules = transformModules(entries2, ...files);\n const importedFroms = modules\n .filter(([, specifiers]) => specifiers.includes(key))\n .map(([k]) => k);\n\n const check = importedFroms.length > 0;\n\n console.log('modules', '=>', importedFroms);\n console.log('key', '=>', key);\n\n if (check) return cannotsRemove.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(`🔧 Deletion of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = CODEBASE_ANALYSIS[key].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\n\n let success = 0;\n const length = formatteds.length;\n\n formatteds.forEach(([key, path]) => {\n try {\n unlinkSync(path);\n console.log(` - 🗑️ ${key}`);\n file?.set(\n FILES_PROPERTY,\n files.filter(key1 => key1 !== key),\n );\n success++;\n } catch {\n console.error(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;AAWA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAA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/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport { consoleStars, getFolderPath, transformModule } from '#helpers';\nimport { CodebaseAnalysis, FileAnalysis } from '../schemas';\n\nconst transformModules = (\n entries: [string, FileAnalysis][],\n ...files: string[]\n) => {\n const cwd = process.cwd();\n const out = entries\n .map(\n ([key, { imports, relativePath }]) =>\n [key, relativePath, imports] as const,\n )\n .map(([key, relativePath, imports]) => {\n const specifiers = imports\n .map(({ moduleSpecifier }) => {\n return transformModule({\n cwd,\n relativePath,\n moduleSpecifier,\n });\n })\n .map(_path => [_path, `${_path}.index`]) // Add .index variants\n .flat()\n .filter(s => files.includes(s));\n\n return [key, Array.from(new Set(specifiers))] as const;\n });\n\n return out;\n};\n\nexport const remove = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n jsonConfigPath: string,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for removal.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, jsonConfigPath);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as string[];\n\n const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) =>\n files.includes(key),\n );\n\n const entries = entries2.filter(([key]) =>\n paths.some(p => key.startsWith(p)),\n );\n\n // Check dependencies before deletion\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\n\n entries.forEach(([key]) => {\n const modules = transformModules(entries2, ...files);\n const importedFroms = modules\n .filter(([, specifiers]) => specifiers.includes(key))\n .map(([k]) => k);\n\n const check = importedFroms.length > 0;\n\n console.log('modules', '=>', importedFroms);\n console.log('key', '=>', key);\n\n if (check) return cannotsRemove.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(`🔧 Deletion of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = CODEBASE_ANALYSIS[key].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\n\n let success = 0;\n const length = formatteds.length;\n\n formatteds.forEach(([key, path]) => {\n try {\n unlinkSync(path);\n console.log(` - 🗑️ ${key}`);\n file?.set(\n FILES_PROPERTY,\n files.filter(key1 => key1 !== key),\n );\n success++;\n } catch {\n console.error(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;AAOA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;CAAO,CAC/B,CAAC,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,aAAa,QAChB,KAAK,EAAE,sBAAsB;GAC5B,OAAO,gBAAgB;IACrB;IACA;IACA;GACF,CAAC;EACH,CAAC,CAAC,CACD,KAAI,UAAS,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,CACvC,KAAK,CAAC,CACN,QAAO,MAAK,MAAM,SAAS,CAAC,CAAC;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K,WAAW,IAAI,cAAc;IAC1C,QAAQ,SAAQ,MAAK,QAAQ,KAAK,aAAa,GAAG,CAAC;GACrD,CAAC;EACH;EAEA,IAAI,cAAc,WAAW,GAAG;GAC9B,QAAQ,KAAK,4BAA4B;GACzC,OAAO,aAAa;EACtB;EAEA,MAAM,aAAa,cAAc,KAAI,QAAO;GAC1C,MAAM,QAAQ,kBAAkB,IAAI,CAAC;GAErC,OAAO,CAAC,KADS,KAAK,MAAM,KACR,CAAC;EACvB,CAAC;EAED,QAAQ,IAAI,uBAAuB,cAAc,OAAO,WAAW;EAEnE,IAAI,UAAU;EACd,MAAM,SAAS,WAAW;EAE1B,WAAW,SAAS,CAAC,KAAK,UAAU;GAClC,IAAI;IACF,WAAW,IAAI;IACf,QAAQ,IAAI,WAAW,KAAK;IAC5B,MAAM,IACJ,gBACA,MAAM,QAAO,SAAQ,SAAS,GAAG,CACnC;IACA;GACF,QAAQ;IACN,QAAQ,MAAM,gBAAgB,IAAI,GAAG;GACvC;EACF,CAAC;EAED,KAAK,KAAK;EACV,QAAQ,IAAI,uBAAuB,QAAQ,GAAG,OAAO,EAAE;EACvD,OAAO,KAAA;CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,aAAa;EACb,OAAO;CACT;CACA,aAAa;CACb,OAAO;AACT"}
package/lib/imports.cjs CHANGED
@@ -5,7 +5,7 @@ let ts_morph = require("ts-morph");
5
5
  /**
6
6
  * Resolves the moduleSpecifier using the tsconfig paths if it starts with "#"
7
7
  */
8
- const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
8
+ const _resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
9
9
  const paths = sourceFile.getProject().getCompilerOptions().paths;
10
10
  if (!paths) return moduleSpecifier;
11
11
  const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;
@@ -24,6 +24,9 @@ const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
24
24
  }
25
25
  return moduleSpecifier;
26
26
  };
27
+ const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
28
+ return _resolveModuleSpecifier(sourceFile, moduleSpecifier).replace(/\.tsx?$/, "");
29
+ };
27
30
  /**
28
31
  * Analyzes a file's imports
29
32
  */
@@ -1 +1 @@
1
- {"version":3,"file":"imports.cjs","names":["SyntaxKind"],"sources":["../src/imports.ts"],"sourcesContent":["import { join, relative } from 'path';\nimport { SourceFile, SyntaxKind } from 'ts-morph';\nimport type { ImportInfo } from './schemas';\n\n/**\n * Resolves the moduleSpecifier using the tsconfig paths if it starts with \"#\"\n */\nconst resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n const paths = sourceFile.getProject().getCompilerOptions().paths;\n\n if (!paths) return moduleSpecifier;\n\n const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;\n const paths2 = Object.entries(paths);\n\n // Find the match in paths\n for (const [pattern, mappings] of paths2) {\n // Replace * with a regex to match\n const regexPattern = pattern.replace(/\\*/g, '(.*)');\n const regex = new RegExp(`^${regexPattern}$`);\n const match = moduleSpecifier.match(regex);\n\n if (match) {\n // Take the first available mapping\n const first = mappings[0];\n\n // Resolve the absolute path\n let relativedPath = baseUrl ? join(baseUrl, first) : first;\n\n if (match[1]) {\n relativedPath = relativedPath.replace('*', match[1]);\n }\n\n // Calculate the relative path from the current source file\n const sourceFileDir = relative(\n process.cwd(),\n sourceFile.getDirectoryPath(),\n );\n const relativePath = relative(sourceFileDir, relativedPath);\n\n // Make sure the relative path starts with ./ or ../\n return relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n }\n }\n\n return moduleSpecifier;\n};\n\n/**\n * Analyzes a file's imports\n */\nexport const analyzeImports = (\n sourceFile: SourceFile,\n): ImportInfo[] => {\n const imports: ImportInfo[] = [];\n\n // Import declarations (import ... from '...')\n sourceFile.getImportDeclarations().forEach(importDecl => {\n // Determine if this is a type-only import\n const isTypeOnly = importDecl.isTypeOnly();\n\n const rawModuleSpecifier = importDecl.getModuleSpecifierValue();\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n\n // Import default\n const defaultImport = importDecl.getDefaultImport();\n if (defaultImport) {\n imports.push({\n moduleSpecifier,\n kind: 'default',\n default: defaultImport.getText(),\n isTypeOnly,\n });\n }\n\n // Import namespace (* as name)\n const namespaceImport = importDecl.getNamespaceImport();\n if (namespaceImport) {\n imports.push({\n moduleSpecifier,\n kind: 'namespace',\n default: namespaceImport.getText(),\n isTypeOnly,\n });\n }\n\n // Named imports ({ name1, name2 })\n const namedImports = importDecl.getNamedImports();\n if (namedImports.length > 0) {\n imports.push({\n moduleSpecifier,\n kind: 'named',\n namedImports: namedImports.map(ni => ni.getName()),\n isTypeOnly,\n });\n }\n\n // Side-effect import (import '...')\n if (\n !defaultImport &&\n !namespaceImport &&\n namedImports.length === 0\n ) {\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isTypeOnly,\n });\n }\n });\n\n // Dynamic imports (import('...'))\n sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .forEach(callExpr => {\n if (\n callExpr.getExpression().getKind() === SyntaxKind.ImportKeyword\n ) {\n const arg = callExpr.getArguments()[0];\n if (arg && arg.getKind() === SyntaxKind.StringLiteral) {\n const rawModuleSpecifier = arg.getText().replace(/['\"]/g, '');\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isDynamic: true,\n });\n }\n }\n });\n\n return imports;\n};\n\nexport const buildImportStrings = (imports: ImportInfo[]) => {\n return imports.map(imp => {\n switch (imp.kind) {\n case 'named': {\n const namedImports = imp.namedImports?.join(', ') || '';\n return `import ${imp.isTypeOnly ? 'type ' : ''}{ ${namedImports} } from '${imp.moduleSpecifier}';`;\n }\n case 'namespace':\n return `import ${imp.isTypeOnly ? 'type ' : ''}* as ${imp.default} from '${imp.moduleSpecifier}';`;\n case 'side-effect': {\n if (imp.isDynamic) {\n return `// Dynamic import: import('${imp.moduleSpecifier}')`;\n }\n return `import '${imp.moduleSpecifier}';`;\n }\n\n case 'default':\n return `import ${imp.isTypeOnly ? 'type ' : ''}${imp.default} from '${imp.moduleSpecifier}';`;\n default:\n return '';\n }\n });\n};\n"],"mappings":";;;;;;;AAOA,MAAM,0BACJ,YACA,oBACW;CACX,MAAM,QAAQ,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAE3D,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,UAAU,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAC7D,MAAM,SAAS,OAAO,QAAQ,KAAK;CAGnC,KAAK,MAAM,CAAC,SAAS,aAAa,QAAQ;EAExC,MAAM,eAAe,QAAQ,QAAQ,OAAO,MAAM;EAClD,MAAM,QAAQ,IAAI,OAAO,IAAI,aAAa,EAAE;EAC5C,MAAM,QAAQ,gBAAgB,MAAM,KAAK;EAEzC,IAAI,OAAO;GAET,MAAM,QAAQ,SAAS;GAGvB,IAAI,gBAAgB,WAAA,GAAA,KAAA,KAAA,CAAe,SAAS,KAAK,IAAI;GAErD,IAAI,MAAM,IACR,gBAAgB,cAAc,QAAQ,KAAK,MAAM,EAAE;GAQrD,MAAM,gBAAA,GAAA,KAAA,SAAA,EAAA,GAAA,KAAA,SAAA,CAHJ,QAAQ,IAAI,GACZ,WAAW,iBAAiB,CAEY,GAAG,aAAa;GAG1D,OAAO,aAAa,WAAW,GAAG,IAC9B,eACA,KAAK;EACX;CACF;CAEA,OAAO;AACT;;;;AAKA,MAAa,kBACX,eACiB;CACjB,MAAM,UAAwB,CAAC;CAG/B,WAAW,sBAAsB,CAAC,CAAC,SAAQ,eAAc;EAEvD,MAAM,aAAa,WAAW,WAAW;EAGzC,MAAM,kBAAkB,uBACtB,YAFyB,WAAW,wBAGnB,CACnB;EAGA,MAAM,gBAAgB,WAAW,iBAAiB;EAClD,IAAI,eACF,QAAQ,KAAK;GACX;GACA,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AAgB;IAE3D,OAAO,WAAW,IAAI,gBAAgB;GAGxC,KAAK,WACH,OAAO,UAAU,IAAI,aAAa,UAAU,KAAK,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GAC5F,SACE,OAAO;EACX;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"imports.cjs","names":["SyntaxKind"],"sources":["../src/imports.ts"],"sourcesContent":["import { join, relative } from 'path';\nimport { SourceFile, SyntaxKind } from 'ts-morph';\nimport type { ImportInfo } from './schemas';\n\n/**\n * Resolves the moduleSpecifier using the tsconfig paths if it starts with \"#\"\n */\nconst _resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n const paths = sourceFile.getProject().getCompilerOptions().paths;\n\n if (!paths) return moduleSpecifier;\n\n const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;\n const paths2 = Object.entries(paths);\n\n // Find the match in paths\n for (const [pattern, mappings] of paths2) {\n // Replace * with a regex to match\n const regexPattern = pattern.replace(/\\*/g, '(.*)');\n const regex = new RegExp(`^${regexPattern}$`);\n const match = moduleSpecifier.match(regex);\n\n if (match) {\n // Take the first available mapping\n const first = mappings[0];\n\n // Resolve the absolute path\n let relativedPath = baseUrl ? join(baseUrl, first) : first;\n\n if (match[1]) {\n relativedPath = relativedPath.replace('*', match[1]);\n }\n\n // Calculate the relative path from the current source file\n const sourceFileDir = relative(\n process.cwd(),\n sourceFile.getDirectoryPath(),\n );\n const relativePath = relative(sourceFileDir, relativedPath);\n\n // Make sure the relative path starts with ./ or ../\n const resolved = relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n\n return resolved;\n }\n }\n\n return moduleSpecifier;\n};\n\nconst resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n return _resolveModuleSpecifier(sourceFile, moduleSpecifier).replace(\n /\\.tsx?$/,\n '',\n );\n};\n\n/**\n * Analyzes a file's imports\n */\nexport const analyzeImports = (\n sourceFile: SourceFile,\n): ImportInfo[] => {\n const imports: ImportInfo[] = [];\n\n // Import declarations (import ... from '...')\n sourceFile.getImportDeclarations().forEach(importDecl => {\n // Determine if this is a type-only import\n const isTypeOnly = importDecl.isTypeOnly();\n\n const rawModuleSpecifier = importDecl.getModuleSpecifierValue();\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n\n // Import default\n const defaultImport = importDecl.getDefaultImport();\n if (defaultImport) {\n imports.push({\n moduleSpecifier,\n kind: 'default',\n default: defaultImport.getText(),\n isTypeOnly,\n });\n }\n\n // Import namespace (* as name)\n const namespaceImport = importDecl.getNamespaceImport();\n if (namespaceImport) {\n imports.push({\n moduleSpecifier,\n kind: 'namespace',\n default: namespaceImport.getText(),\n isTypeOnly,\n });\n }\n\n // Named imports ({ name1, name2 })\n const namedImports = importDecl.getNamedImports();\n if (namedImports.length > 0) {\n imports.push({\n moduleSpecifier,\n kind: 'named',\n namedImports: namedImports.map(ni => ni.getName()),\n isTypeOnly,\n });\n }\n\n // Side-effect import (import '...')\n if (\n !defaultImport &&\n !namespaceImport &&\n namedImports.length === 0\n ) {\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isTypeOnly,\n });\n }\n });\n\n // Dynamic imports (import('...'))\n sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .forEach(callExpr => {\n if (\n callExpr.getExpression().getKind() === SyntaxKind.ImportKeyword\n ) {\n const arg = callExpr.getArguments()[0];\n if (arg && arg.getKind() === SyntaxKind.StringLiteral) {\n const rawModuleSpecifier = arg.getText().replace(/['\"]/g, '');\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isDynamic: true,\n });\n }\n }\n });\n\n return imports;\n};\n\nexport const buildImportStrings = (imports: ImportInfo[]) => {\n return imports.map(imp => {\n switch (imp.kind) {\n case 'named': {\n const namedImports = imp.namedImports?.join(', ') || '';\n return `import ${imp.isTypeOnly ? 'type ' : ''}{ ${namedImports} } from '${imp.moduleSpecifier}';`;\n }\n case 'namespace':\n return `import ${imp.isTypeOnly ? 'type ' : ''}* as ${imp.default} from '${imp.moduleSpecifier}';`;\n case 'side-effect': {\n if (imp.isDynamic) {\n return `// Dynamic import: import('${imp.moduleSpecifier}')`;\n }\n return `import '${imp.moduleSpecifier}';`;\n }\n\n case 'default':\n return `import ${imp.isTypeOnly ? 'type ' : ''}${imp.default} from '${imp.moduleSpecifier}';`;\n default:\n return '';\n }\n });\n};\n"],"mappings":";;;;;;;AAOA,MAAM,2BACJ,YACA,oBACW;CACX,MAAM,QAAQ,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAE3D,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,UAAU,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAC7D,MAAM,SAAS,OAAO,QAAQ,KAAK;CAGnC,KAAK,MAAM,CAAC,SAAS,aAAa,QAAQ;EAExC,MAAM,eAAe,QAAQ,QAAQ,OAAO,MAAM;EAClD,MAAM,QAAQ,IAAI,OAAO,IAAI,aAAa,EAAE;EAC5C,MAAM,QAAQ,gBAAgB,MAAM,KAAK;EAEzC,IAAI,OAAO;GAET,MAAM,QAAQ,SAAS;GAGvB,IAAI,gBAAgB,WAAA,GAAA,KAAA,KAAA,CAAe,SAAS,KAAK,IAAI;GAErD,IAAI,MAAM,IACR,gBAAgB,cAAc,QAAQ,KAAK,MAAM,EAAE;GAQrD,MAAM,gBAAA,GAAA,KAAA,SAAA,EAAA,GAAA,KAAA,SAAA,CAHJ,QAAQ,IAAI,GACZ,WAAW,iBAAiB,CAEY,GAAG,aAAa;GAO1D,OAJiB,aAAa,WAAW,GAAG,IACxC,eACA,KAAK;EAGX;CACF;CAEA,OAAO;AACT;AAEA,MAAM,0BACJ,YACA,oBACW;CACX,OAAO,wBAAwB,YAAY,eAAe,CAAC,CAAC,QAC1D,WACA,EACF;AACF;;;;AA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AI,cAAc,KAAK,IAAI,KAAK;IACrD,OAAO,UAAU,IAAI,aAAa,UAAU,GAAG,IAAI,aAAa,WAAW,IAAI,gBAAgB;GACjG;GACA,KAAK,aACH,OAAO,UAAU,IAAI,aAAa,UAAU,GAAG,OAAO,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GACjG,KAAK;IACH,IAAI,IAAI,WACN,OAAO,8BAA8B,IAAI,gBAAgB;IAE3D,OAAO,WAAW,IAAI,gBAAgB;GAGxC,KAAK,WACH,OAAO,UAAU,IAAI,aAAa,UAAU,KAAK,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GAC5F,SACE,OAAO;EACX;CACF,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAmD5C;;GAEG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,UAAU,KACrB,UAAU,EAqFZ,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,UAAU,EAAE,aAsBvD,CAAC"}
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA+D5C;;GAEG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,UAAU,KACrB,UAAU,EAqFZ,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,UAAU,EAAE,aAsBvD,CAAC"}
package/lib/imports.js CHANGED
@@ -4,7 +4,7 @@ import { SyntaxKind } from "ts-morph";
4
4
  /**
5
5
  * Resolves the moduleSpecifier using the tsconfig paths if it starts with "#"
6
6
  */
7
- const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
7
+ const _resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
8
8
  const paths = sourceFile.getProject().getCompilerOptions().paths;
9
9
  if (!paths) return moduleSpecifier;
10
10
  const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;
@@ -23,6 +23,9 @@ const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
23
23
  }
24
24
  return moduleSpecifier;
25
25
  };
26
+ const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
27
+ return _resolveModuleSpecifier(sourceFile, moduleSpecifier).replace(/\.tsx?$/, "");
28
+ };
26
29
  /**
27
30
  * Analyzes a file's imports
28
31
  */
@@ -1 +1 @@
1
- {"version":3,"file":"imports.js","names":[],"sources":["../src/imports.ts"],"sourcesContent":["import { join, relative } from 'path';\nimport { SourceFile, SyntaxKind } from 'ts-morph';\nimport type { ImportInfo } from './schemas';\n\n/**\n * Resolves the moduleSpecifier using the tsconfig paths if it starts with \"#\"\n */\nconst resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n const paths = sourceFile.getProject().getCompilerOptions().paths;\n\n if (!paths) return moduleSpecifier;\n\n const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;\n const paths2 = Object.entries(paths);\n\n // Find the match in paths\n for (const [pattern, mappings] of paths2) {\n // Replace * with a regex to match\n const regexPattern = pattern.replace(/\\*/g, '(.*)');\n const regex = new RegExp(`^${regexPattern}$`);\n const match = moduleSpecifier.match(regex);\n\n if (match) {\n // Take the first available mapping\n const first = mappings[0];\n\n // Resolve the absolute path\n let relativedPath = baseUrl ? join(baseUrl, first) : first;\n\n if (match[1]) {\n relativedPath = relativedPath.replace('*', match[1]);\n }\n\n // Calculate the relative path from the current source file\n const sourceFileDir = relative(\n process.cwd(),\n sourceFile.getDirectoryPath(),\n );\n const relativePath = relative(sourceFileDir, relativedPath);\n\n // Make sure the relative path starts with ./ or ../\n return relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n }\n }\n\n return moduleSpecifier;\n};\n\n/**\n * Analyzes a file's imports\n */\nexport const analyzeImports = (\n sourceFile: SourceFile,\n): ImportInfo[] => {\n const imports: ImportInfo[] = [];\n\n // Import declarations (import ... from '...')\n sourceFile.getImportDeclarations().forEach(importDecl => {\n // Determine if this is a type-only import\n const isTypeOnly = importDecl.isTypeOnly();\n\n const rawModuleSpecifier = importDecl.getModuleSpecifierValue();\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n\n // Import default\n const defaultImport = importDecl.getDefaultImport();\n if (defaultImport) {\n imports.push({\n moduleSpecifier,\n kind: 'default',\n default: defaultImport.getText(),\n isTypeOnly,\n });\n }\n\n // Import namespace (* as name)\n const namespaceImport = importDecl.getNamespaceImport();\n if (namespaceImport) {\n imports.push({\n moduleSpecifier,\n kind: 'namespace',\n default: namespaceImport.getText(),\n isTypeOnly,\n });\n }\n\n // Named imports ({ name1, name2 })\n const namedImports = importDecl.getNamedImports();\n if (namedImports.length > 0) {\n imports.push({\n moduleSpecifier,\n kind: 'named',\n namedImports: namedImports.map(ni => ni.getName()),\n isTypeOnly,\n });\n }\n\n // Side-effect import (import '...')\n if (\n !defaultImport &&\n !namespaceImport &&\n namedImports.length === 0\n ) {\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isTypeOnly,\n });\n }\n });\n\n // Dynamic imports (import('...'))\n sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .forEach(callExpr => {\n if (\n callExpr.getExpression().getKind() === SyntaxKind.ImportKeyword\n ) {\n const arg = callExpr.getArguments()[0];\n if (arg && arg.getKind() === SyntaxKind.StringLiteral) {\n const rawModuleSpecifier = arg.getText().replace(/['\"]/g, '');\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isDynamic: true,\n });\n }\n }\n });\n\n return imports;\n};\n\nexport const buildImportStrings = (imports: ImportInfo[]) => {\n return imports.map(imp => {\n switch (imp.kind) {\n case 'named': {\n const namedImports = imp.namedImports?.join(', ') || '';\n return `import ${imp.isTypeOnly ? 'type ' : ''}{ ${namedImports} } from '${imp.moduleSpecifier}';`;\n }\n case 'namespace':\n return `import ${imp.isTypeOnly ? 'type ' : ''}* as ${imp.default} from '${imp.moduleSpecifier}';`;\n case 'side-effect': {\n if (imp.isDynamic) {\n return `// Dynamic import: import('${imp.moduleSpecifier}')`;\n }\n return `import '${imp.moduleSpecifier}';`;\n }\n\n case 'default':\n return `import ${imp.isTypeOnly ? 'type ' : ''}${imp.default} from '${imp.moduleSpecifier}';`;\n default:\n return '';\n }\n });\n};\n"],"mappings":";;;;;;AAOA,MAAM,0BACJ,YACA,oBACW;CACX,MAAM,QAAQ,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAE3D,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,UAAU,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAC7D,MAAM,SAAS,OAAO,QAAQ,KAAK;CAGnC,KAAK,MAAM,CAAC,SAAS,aAAa,QAAQ;EAExC,MAAM,eAAe,QAAQ,QAAQ,OAAO,MAAM;EAClD,MAAM,QAAQ,IAAI,OAAO,IAAI,aAAa,EAAE;EAC5C,MAAM,QAAQ,gBAAgB,MAAM,KAAK;EAEzC,IAAI,OAAO;GAET,MAAM,QAAQ,SAAS;GAGvB,IAAI,gBAAgB,UAAU,KAAK,SAAS,KAAK,IAAI;GAErD,IAAI,MAAM,IACR,gBAAgB,cAAc,QAAQ,KAAK,MAAM,EAAE;GAQrD,MAAM,eAAe,SAJC,SACpB,QAAQ,IAAI,GACZ,WAAW,iBAAiB,CAEY,GAAG,aAAa;GAG1D,OAAO,aAAa,WAAW,GAAG,IAC9B,eACA,KAAK;EACX;CACF;CAEA,OAAO;AACT;;;;AAKA,MAAa,kBACX,eACiB;CACjB,MAAM,UAAwB,CAAC;CAG/B,WAAW,sBA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AAI,gBAAgB;GACjG;GACA,KAAK,aACH,OAAO,UAAU,IAAI,aAAa,UAAU,GAAG,OAAO,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GACjG,KAAK;IACH,IAAI,IAAI,WACN,OAAO,8BAA8B,IAAI,gBAAgB;IAE3D,OAAO,WAAW,IAAI,gBAAgB;GAGxC,KAAK,WACH,OAAO,UAAU,IAAI,aAAa,UAAU,KAAK,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GAC5F,SACE,OAAO;EACX;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"imports.js","names":[],"sources":["../src/imports.ts"],"sourcesContent":["import { join, relative } from 'path';\nimport { SourceFile, SyntaxKind } from 'ts-morph';\nimport type { ImportInfo } from './schemas';\n\n/**\n * Resolves the moduleSpecifier using the tsconfig paths if it starts with \"#\"\n */\nconst _resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n const paths = sourceFile.getProject().getCompilerOptions().paths;\n\n if (!paths) return moduleSpecifier;\n\n const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;\n const paths2 = Object.entries(paths);\n\n // Find the match in paths\n for (const [pattern, mappings] of paths2) {\n // Replace * with a regex to match\n const regexPattern = pattern.replace(/\\*/g, '(.*)');\n const regex = new RegExp(`^${regexPattern}$`);\n const match = moduleSpecifier.match(regex);\n\n if (match) {\n // Take the first available mapping\n const first = mappings[0];\n\n // Resolve the absolute path\n let relativedPath = baseUrl ? join(baseUrl, first) : first;\n\n if (match[1]) {\n relativedPath = relativedPath.replace('*', match[1]);\n }\n\n // Calculate the relative path from the current source file\n const sourceFileDir = relative(\n process.cwd(),\n sourceFile.getDirectoryPath(),\n );\n const relativePath = relative(sourceFileDir, relativedPath);\n\n // Make sure the relative path starts with ./ or ../\n const resolved = relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n\n return resolved;\n }\n }\n\n return moduleSpecifier;\n};\n\nconst resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n return _resolveModuleSpecifier(sourceFile, moduleSpecifier).replace(\n /\\.tsx?$/,\n '',\n );\n};\n\n/**\n * Analyzes a file's imports\n */\nexport const analyzeImports = (\n sourceFile: SourceFile,\n): ImportInfo[] => {\n const imports: ImportInfo[] = [];\n\n // Import declarations (import ... from '...')\n sourceFile.getImportDeclarations().forEach(importDecl => {\n // Determine if this is a type-only import\n const isTypeOnly = importDecl.isTypeOnly();\n\n const rawModuleSpecifier = importDecl.getModuleSpecifierValue();\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n\n // Import default\n const defaultImport = importDecl.getDefaultImport();\n if (defaultImport) {\n imports.push({\n moduleSpecifier,\n kind: 'default',\n default: defaultImport.getText(),\n isTypeOnly,\n });\n }\n\n // Import namespace (* as name)\n const namespaceImport = importDecl.getNamespaceImport();\n if (namespaceImport) {\n imports.push({\n moduleSpecifier,\n kind: 'namespace',\n default: namespaceImport.getText(),\n isTypeOnly,\n });\n }\n\n // Named imports ({ name1, name2 })\n const namedImports = importDecl.getNamedImports();\n if (namedImports.length > 0) {\n imports.push({\n moduleSpecifier,\n kind: 'named',\n namedImports: namedImports.map(ni => ni.getName()),\n isTypeOnly,\n });\n }\n\n // Side-effect import (import '...')\n if (\n !defaultImport &&\n !namespaceImport &&\n namedImports.length === 0\n ) {\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isTypeOnly,\n });\n }\n });\n\n // Dynamic imports (import('...'))\n sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .forEach(callExpr => {\n if (\n callExpr.getExpression().getKind() === SyntaxKind.ImportKeyword\n ) {\n const arg = callExpr.getArguments()[0];\n if (arg && arg.getKind() === SyntaxKind.StringLiteral) {\n const rawModuleSpecifier = arg.getText().replace(/['\"]/g, '');\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isDynamic: true,\n });\n }\n }\n });\n\n return imports;\n};\n\nexport const buildImportStrings = (imports: ImportInfo[]) => {\n return imports.map(imp => {\n switch (imp.kind) {\n case 'named': {\n const namedImports = imp.namedImports?.join(', ') || '';\n return `import ${imp.isTypeOnly ? 'type ' : ''}{ ${namedImports} } from '${imp.moduleSpecifier}';`;\n }\n case 'namespace':\n return `import ${imp.isTypeOnly ? 'type ' : ''}* as ${imp.default} from '${imp.moduleSpecifier}';`;\n case 'side-effect': {\n if (imp.isDynamic) {\n return `// Dynamic import: import('${imp.moduleSpecifier}')`;\n }\n return `import '${imp.moduleSpecifier}';`;\n }\n\n case 'default':\n return `import ${imp.isTypeOnly ? 'type ' : ''}${imp.default} from '${imp.moduleSpecifier}';`;\n default:\n return '';\n }\n });\n};\n"],"mappings":";;;;;;AAOA,MAAM,2BACJ,YACA,oBACW;CACX,MAAM,QAAQ,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAE3D,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,UAAU,WAAW,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;CAC7D,MAAM,SAAS,OAAO,QAAQ,KAAK;CAGnC,KAAK,MAAM,CAAC,SAAS,aAAa,QAAQ;EAExC,MAAM,eAAe,QAAQ,QAAQ,OAAO,MAAM;EAClD,MAAM,QAAQ,IAAI,OAAO,IAAI,aAAa,EAAE;EAC5C,MAAM,QAAQ,gBAAgB,MAAM,KAAK;EAEzC,IAAI,OAAO;GAET,MAAM,QAAQ,SAAS;GAGvB,IAAI,gBAAgB,UAAU,KAAK,SAAS,KAAK,IAAI;GAErD,IAAI,MAAM,IACR,gBAAgB,cAAc,QAAQ,KAAK,MAAM,EAAE;GAQrD,MAAM,eAAe,SAJC,SACpB,QAAQ,IAAI,GACZ,WAAW,iBAAiB,CAEY,GAAG,aAAa;GAO1D,OAJiB,aAAa,WAAW,GAAG,IACxC,eACA,KAAK;EAGX;CACF;CAEA,OAAO;AACT;AAE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I,QAAO;EACxB,QAAQ,IAAI,MAAZ;GACE,KAAK,SAAS;IACZ,MAAM,eAAe,IAAI,cAAc,KAAK,IAAI,KAAK;IACrD,OAAO,UAAU,IAAI,aAAa,UAAU,GAAG,IAAI,aAAa,WAAW,IAAI,gBAAgB;GACjG;GACA,KAAK,aACH,OAAO,UAAU,IAAI,aAAa,UAAU,GAAG,OAAO,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GACjG,KAAK;IACH,IAAI,IAAI,WACN,OAAO,8BAA8B,IAAI,gBAAgB;IAE3D,OAAO,WAAW,IAAI,gBAAgB;GAGxC,KAAK,WACH,OAAO,UAAU,IAAI,aAAa,UAAU,KAAK,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GAC5F,SACE,OAAO;EACX;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemedev/codebase",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "The CLI for to generate codebase, and import partially a library. From @bemedev.",
5
5
  "author": {
6
6
  "email": "bri_lvi@icloud.com",
@@ -72,10 +72,10 @@
72
72
  }
73
73
  ],
74
74
  "devDependencies": {
75
- "@bemedev/dev-utils": "^0.8.0",
75
+ "@bemedev/dev-utils": "^0.8.2",
76
76
  "@size-limit/file": "^12.1.0",
77
- "@types/node": "^25.9.3",
78
- "rolldown": "1.1.1",
77
+ "@types/node": "^26.0.1",
78
+ "rolldown": "1.1.3",
79
79
  "size-limit": "^12.1.0",
80
80
  "tsx": "^4.22.4",
81
81
  "typescript": "^6.0.3"