import type { ResolvedBarrelImport, ResolvedBarrelReexport, ResolvedCodeFileDetails, ResolvedDynamicImport, ResolvedExport, ResolvedOtherFileDetails, ResolvedPackageInfo, ResolvedSideEffectImport, ResolvedSingleImport, ResolvedSingleReexport } from './resolved.js'; type AnalyzedImportBase = { /** * A rootModuleType of `undefined` indicates that either: * 1. The statement is a reexport statement that is not an entry point, * 2. The root export could not be resolved */ rootModuleType: undefined; rootModulePath?: undefined; rootExportEntry?: undefined; } | { rootModuleType: 'builtin'; rootModulePath?: undefined; rootExportEntry?: undefined; } | { rootModuleType: 'thirdParty'; rootModulePath?: undefined; rootExportEntry?: undefined; } | { rootModuleType: 'firstPartyOther'; /** * The absolute path of the root file with the export that the * import/reexport statement ultimately resolves to. In other words, if we * have: * * ``` * // foo.ts * import { baz } from './bar' * * // bar.ts * export { baz } from './baz' * * // baz.ts * export const baz = 10; * ``` * * then `rootModulePath` in `foo.ts` is `/path/to/baz.ts`. Contrast this * with `resolvedModulePath` which equals `/path/to/bar.ts`. */ rootModulePath: string; rootExportEntry?: undefined; } | { rootModuleType: 'firstPartyCode'; /** * The absolute path of the root file with the export that the * import/reexport statement ultimately resolves to. In other words, if we * have: * * ``` * // foo.ts * import { baz } from './bar' * * // bar.ts * export { baz } from './baz' * * // baz.ts * export const baz = 10; * ``` * * then `rootModulePath` in `foo.ts` is `/path/to/baz.ts`. Contrast this * with `resolvedModulePath` which equals `/path/to/bar.ts`. */ rootModulePath: string; /** * The root export entry that this import/reexport statement ultimately * resolves to. * * Most of the time this is an export statement, but on occasion it can * be a named barrel reexportin the middle of the reexport chain. * * Consider this code: * * ``` * // foo.ts * import { baz } from './bar' * * // bar.ts * export * as baz from './baz' * ``` * * In this case, there is a named export we found, but we can't go any * further because there is nothing named, or singular, past this point */ rootExportEntry: AnalyzedExport | AnalyzedBarrelReexport; }; type AnalyzedExportBase = { /** * A list of files and import entries that imports this export, including * indirect imports that are funneled through reexport statements. * * This also includes reexports that are entry points, since they are acting * like an import for the purposes of this plugin */ importedBy: Array<{ filePath: string; importEntry: AnalyzedSingleImport | AnalyzedSingleReexport; }>; /** * A list of files and import entries that imports this export from another * package in the same monorepo. * * This computation is not as in-depth as `importedBy` because it does not * follow reexports in the consuming package. If another package reexports * this export, then it is immediately considered an external import and added * to this list, instead of tracing through the reexport chain. * * This list is an empty array of monorepoRootDir is not set by the user. */ externallyImportedBy: Array<{ packageRootDir: string; filePath: string; importEntry: AnalyzedSingleImport | AnalyzedSingleReexport | AnalyzedBarrelImport | AnalyzedBarrelReexport | AnalyzedDynamicImport; }>; /** * A list of files that barrel imports this export, including indirect imports * that are funneled through reexport statements. * * This also includes reexports that are entry points, since they are acting * like an import for the purposes of this plugin * * Note: unlike `importedBy`, entries here do not actually guarantee this * import is actually used */ barrelImportedBy: Array<{ filePath: string; importEntry: AnalyzedBarrelReexport | AnalyzedSingleImport | AnalyzedSingleReexport | AnalyzedBarrelImport | AnalyzedDynamicImport; }>; }; export type AnalyzedSingleImport = ResolvedSingleImport & AnalyzedImportBase; export type AnalyzedBarrelImport = ResolvedBarrelImport; export type AnalyzedDynamicImport = ResolvedDynamicImport; export type AnalyzedSideEffectImport = ResolvedSideEffectImport; export type AnalyzedExport = ResolvedExport & AnalyzedExportBase; export type AnalyzedSingleReexport = ResolvedSingleReexport & AnalyzedImportBase & AnalyzedExportBase; export type AnalyzedBarrelReexport = ResolvedBarrelReexport & AnalyzedExportBase; export type AnalyzedOtherFileDetails = ResolvedOtherFileDetails; export type AnalyzedCodeFileDetails = Omit & { exports: AnalyzedExport[]; singleImports: AnalyzedSingleImport[]; barrelImports: AnalyzedBarrelImport[]; dynamicImports: AnalyzedDynamicImport[]; sideEffectImports: AnalyzedSideEffectImport[]; singleReexports: AnalyzedSingleReexport[]; barrelReexports: AnalyzedBarrelReexport[]; }; type AnalyzedFileDetails = AnalyzedOtherFileDetails | AnalyzedCodeFileDetails; export type AnalyzedPackageInfo = Omit & { /** * Mapping of _absolute_ file paths to file details */ files: Map; /** * The entry point files for this package that maps from import specifer * (package name + subpath) to file details for quick lookup */ packageEntryPointExports: Map; }; export {};