@codefast/cli 0.3.1-canary.0 โ†’ 0.3.1-canary.2

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/index.cjs +430 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.js +397 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +16 -9
  7. package/.turbo/turbo-build.log +0 -12
  8. package/dist/cjs/commands/update-exports/analyze-imports.cjs +0 -92
  9. package/dist/cjs/commands/update-exports/analyze-imports.cjs.map +0 -1
  10. package/dist/cjs/commands/update-exports/command.cjs +0 -58
  11. package/dist/cjs/commands/update-exports/command.cjs.map +0 -1
  12. package/dist/cjs/commands/update-exports/config.cjs +0 -113
  13. package/dist/cjs/commands/update-exports/config.cjs.map +0 -1
  14. package/dist/cjs/commands/update-exports/file-utils.cjs +0 -144
  15. package/dist/cjs/commands/update-exports/file-utils.cjs.map +0 -1
  16. package/dist/cjs/commands/update-exports/generate-exports.cjs +0 -76
  17. package/dist/cjs/commands/update-exports/generate-exports.cjs.map +0 -1
  18. package/dist/cjs/commands/update-exports/index.cjs +0 -36
  19. package/dist/cjs/commands/update-exports/process-package.cjs +0 -143
  20. package/dist/cjs/commands/update-exports/process-package.cjs.map +0 -1
  21. package/dist/cjs/commands/update-exports/types.cjs +0 -55
  22. package/dist/cjs/commands/update-exports/types.cjs.map +0 -1
  23. package/dist/cjs/index.cjs +0 -46
  24. package/dist/cjs/index.cjs.map +0 -1
  25. package/dist/cjs/lib/logger.cjs +0 -72
  26. package/dist/cjs/lib/logger.cjs.map +0 -1
  27. package/dist/esm/commands/update-exports/analyze-imports.js +0 -58
  28. package/dist/esm/commands/update-exports/analyze-imports.js.map +0 -1
  29. package/dist/esm/commands/update-exports/command.js +0 -24
  30. package/dist/esm/commands/update-exports/command.js.map +0 -1
  31. package/dist/esm/commands/update-exports/config.js +0 -62
  32. package/dist/esm/commands/update-exports/config.js.map +0 -1
  33. package/dist/esm/commands/update-exports/file-utils.js +0 -81
  34. package/dist/esm/commands/update-exports/file-utils.js.map +0 -1
  35. package/dist/esm/commands/update-exports/generate-exports.js +0 -42
  36. package/dist/esm/commands/update-exports/generate-exports.js.map +0 -1
  37. package/dist/esm/commands/update-exports/index.js +0 -3
  38. package/dist/esm/commands/update-exports/process-package.js +0 -93
  39. package/dist/esm/commands/update-exports/process-package.js.map +0 -1
  40. package/dist/esm/commands/update-exports/types.js +0 -18
  41. package/dist/esm/commands/update-exports/types.js.map +0 -1
  42. package/dist/esm/index.js +0 -18
  43. package/dist/esm/index.js.map +0 -1
  44. package/dist/esm/lib/logger.js +0 -28
  45. package/dist/esm/lib/logger.js.map +0 -1
  46. package/dist/types/src/commands/update-exports/analyze-imports.d.ts +0 -9
  47. package/dist/types/src/commands/update-exports/analyze-imports.d.ts.map +0 -1
  48. package/dist/types/src/commands/update-exports/command.d.ts +0 -7
  49. package/dist/types/src/commands/update-exports/command.d.ts.map +0 -1
  50. package/dist/types/src/commands/update-exports/config.d.ts +0 -16
  51. package/dist/types/src/commands/update-exports/config.d.ts.map +0 -1
  52. package/dist/types/src/commands/update-exports/file-utils.d.ts +0 -47
  53. package/dist/types/src/commands/update-exports/file-utils.d.ts.map +0 -1
  54. package/dist/types/src/commands/update-exports/generate-exports.d.ts +0 -11
  55. package/dist/types/src/commands/update-exports/generate-exports.d.ts.map +0 -1
  56. package/dist/types/src/commands/update-exports/index.d.ts +0 -2
  57. package/dist/types/src/commands/update-exports/index.d.ts.map +0 -1
  58. package/dist/types/src/commands/update-exports/process-package.d.ts +0 -23
  59. package/dist/types/src/commands/update-exports/process-package.d.ts.map +0 -1
  60. package/dist/types/src/commands/update-exports/types.d.ts +0 -83
  61. package/dist/types/src/commands/update-exports/types.d.ts.map +0 -1
  62. package/dist/types/src/index.d.ts +0 -3
  63. package/dist/types/src/index.d.ts.map +0 -1
  64. package/dist/types/src/lib/logger.d.ts +0 -15
  65. package/dist/types/src/lib/logger.d.ts.map +0 -1
  66. package/eslint.config.js +0 -18
  67. package/rslib.config.ts +0 -40
  68. package/src/commands/update-exports/analyze-imports.ts +0 -112
  69. package/src/commands/update-exports/command.ts +0 -38
  70. package/src/commands/update-exports/config.ts +0 -99
  71. package/src/commands/update-exports/file-utils.ts +0 -178
  72. package/src/commands/update-exports/generate-exports.ts +0 -74
  73. package/src/commands/update-exports/index.ts +0 -1
  74. package/src/commands/update-exports/process-package.ts +0 -164
  75. package/src/commands/update-exports/types.ts +0 -94
  76. package/src/index.ts +0 -28
  77. package/src/lib/logger.ts +0 -39
  78. package/tsconfig.build.json +0 -5
  79. package/tsconfig.json +0 -14
@@ -1,112 +0,0 @@
1
- import type { SourceFile } from "ts-morph";
2
-
3
- import { Project } from "ts-morph";
4
-
5
- import type { AnalysisResult, ImportPath, PackageConfig } from "@/commands/update-exports/types";
6
-
7
- /**
8
- * Creates a regex to remove specified prefixes from paths
9
- * @param prefixes - Array of prefixes to remove
10
- * @returns RegExp matching any prefix
11
- */
12
- function makeRegexPrefixesToRemove(prefixes: string[]): RegExp {
13
- // Matches: ^\.?\/?(prefix1|prefix2)\/(.*)
14
- // - ^\.?\/? : Optional ./ or /
15
- // - (prefix1|prefix2): Any prefix from the list
16
- // - \/(.*) : Remaining path after prefix
17
- const prefixPattern = prefixes.join("|");
18
-
19
- return new RegExp(`^.?\\/?(?:${prefixPattern})\\/(.*)$`);
20
- }
21
-
22
- /**
23
- * Processes an export path by removing specified prefixes
24
- * @param modulePath - Path to process
25
- * @param regexPattern - Regex for prefix removal
26
- * @returns Processed path starting with ./
27
- */
28
- function processExportPath(modulePath: string, regexPattern: RegExp): string {
29
- let processedPath = modulePath;
30
- const match = processedPath.match(regexPattern);
31
-
32
- if (match) {
33
- const remainingPath = match[1];
34
-
35
- processedPath = remainingPath.startsWith("./") ? remainingPath : `./${remainingPath}`;
36
- }
37
-
38
- return processedPath;
39
- }
40
-
41
- /**
42
- * Analyzes imports from an index.ts file
43
- * @param indexFilePath - Path to index.ts
44
- * @param packageConfig - Package configuration
45
- * @returns AnalysisResult containing import paths
46
- */
47
- export function analyzeImports(indexFilePath: string, packageConfig: PackageConfig): AnalysisResult {
48
- const project = new Project();
49
- let sourceFile: SourceFile;
50
-
51
- try {
52
- sourceFile = project.addSourceFileAtPath(indexFilePath);
53
- } catch (error) {
54
- console.error(`Error loading source file at ${indexFilePath}:`, error);
55
-
56
- return { imports: [] };
57
- }
58
-
59
- const imports: ImportPath[] = [];
60
- const prefixesToRemove = packageConfig.exportPathPrefixesToRemove ?? [];
61
- const regexPattern = makeRegexPrefixesToRemove(prefixesToRemove);
62
-
63
- for (const exportDecl of sourceFile.getExportDeclarations()) {
64
- let moduleSpecifier = exportDecl.getModuleSpecifierValue();
65
-
66
- if (!moduleSpecifier) {
67
- continue;
68
- }
69
-
70
- // Normalize @/ to ./
71
- if (moduleSpecifier.startsWith("@/")) {
72
- moduleSpecifier = `./${moduleSpecifier.slice(2)}`;
73
- }
74
-
75
- const isExternal = !moduleSpecifier.startsWith(".");
76
-
77
- if (isExternal) {
78
- continue;
79
- }
80
-
81
- const parts = moduleSpecifier.split("/").filter(Boolean);
82
-
83
- if (parts.length < 2) {
84
- continue;
85
- }
86
-
87
- let directory;
88
-
89
- if (parts.length <= 1) {
90
- directory = ".";
91
- } else {
92
- directory = parts.slice(0, -1).join("/");
93
-
94
- if (directory.startsWith("./")) {
95
- directory = directory.slice(2);
96
- }
97
- }
98
-
99
- const name = parts.at(-1) ?? "";
100
-
101
- const importPath: ImportPath = {
102
- originalPath: moduleSpecifier,
103
- directory,
104
- name,
105
- exportPath: processExportPath(moduleSpecifier, regexPattern),
106
- };
107
-
108
- imports.push(importPath);
109
- }
110
-
111
- return { imports };
112
- }
@@ -1,38 +0,0 @@
1
- import type { Command } from "commander";
2
-
3
- import type { ProcessOptions } from "@/commands/update-exports/types";
4
-
5
- import { processAllPackages } from "@/commands/update-exports/process-package";
6
- import { Logger } from "@/lib/logger";
7
-
8
- /**
9
- * Creates a commander command for updating exports
10
- * @param program - Commander program instance
11
- */
12
- export function createUpdateExportsCommand(program: Command): void {
13
- // noinspection RequiredAttributes
14
- program
15
- .command("update-exports")
16
- .description("Updates exports for all packages")
17
- .option("-p, --package <package>", "Filter by package name")
18
- .option("-d, --dry-run", "Run without making changes")
19
- .option("-v, --verbose", "Show detailed output")
20
- .option("-c, --config <path>", "Path to configuration file")
21
- .action(async (options) => {
22
- const processorOptions: ProcessOptions = {
23
- packageFilter: options.package,
24
- dryRun: Boolean(options.dryRun),
25
- verbose: Boolean(options.verbose),
26
- configPath: options.config,
27
- };
28
-
29
- const logger = new Logger({ verbose: processorOptions.verbose });
30
-
31
- try {
32
- await processAllPackages(processorOptions, logger);
33
- } catch (error) {
34
- logger.error("Error processing packages:", error);
35
- process.exit(1);
36
- }
37
- });
38
- }
@@ -1,99 +0,0 @@
1
- import { merge } from "lodash-es";
2
- import fs from "node:fs";
3
- import path from "node:path";
4
-
5
- import type { PackageConfig, ScriptConfig } from "@/commands/update-exports/types";
6
-
7
- import { ScriptConfigSchema } from "@/commands/update-exports/types";
8
-
9
- // Cache for storing configuration to avoid repeated file reads
10
- let cachedConfig: null | ScriptConfig = null;
11
-
12
- /**
13
- * Loads and validates configuration from a file
14
- * @param configPath - Optional path to the config file
15
- * @returns Partial ScriptConfig or empty object if not found/invalid
16
- */
17
- function loadConfigFile(configPath?: string): Partial<ScriptConfig> {
18
- if (!configPath) {
19
- return {};
20
- }
21
-
22
- try {
23
- const fullPath = path.resolve(configPath);
24
-
25
- if (!fs.existsSync(fullPath)) {
26
- console.warn(`Configuration file not found at ${fullPath}`);
27
-
28
- return {};
29
- }
30
-
31
- const configContent = fs.readFileSync(fullPath, "utf8");
32
- const config = JSON.parse(configContent);
33
-
34
- // Validate against schema
35
- return ScriptConfigSchema.parse(config);
36
- } catch (error) {
37
- console.error("Error reading configuration file:", error);
38
-
39
- return {};
40
- }
41
- }
42
-
43
- /**
44
- * Retrieves merged configuration, using cache if no path is provided
45
- * @param configPath - Optional path to override default config
46
- * @returns Merged ScriptConfig
47
- */
48
- export function getConfig(configPath?: string): ScriptConfig {
49
- if (cachedConfig && !configPath) {
50
- return cachedConfig;
51
- }
52
-
53
- const userConfig = loadConfigFile(configPath);
54
- const config = merge({}, defaultConfig, userConfig) as ScriptConfig;
55
-
56
- // Cache config if no path is provided
57
- if (!configPath) {
58
- cachedConfig = config;
59
- }
60
-
61
- return config;
62
- }
63
-
64
- /**
65
- * Retrieves configuration for a specific package
66
- * @param packageName - Name of the package
67
- * @param config - Optional ScriptConfig to use
68
- * @returns PackageConfig combining defaults and custom settings
69
- */
70
- export function getPackageConfig(packageName: string, config?: ScriptConfig): PackageConfig {
71
- const configObj = config ?? getConfig();
72
- const customConfig = configObj.customPackageConfigs[packageName] ?? {};
73
-
74
- return {
75
- ...configObj.defaultPackageConfig,
76
- ...customConfig,
77
- };
78
- }
79
-
80
- // Default configuration for the script
81
- export const defaultConfig: ScriptConfig = {
82
- packagesGlob: "./packages/**/package.json",
83
- defaultPackageConfig: {
84
- cjsOutputPattern: "./dist/cjs/{dir}/{name}.cjs",
85
- esmOutputPattern: "./dist/esm/{dir}/{name}.js",
86
- packageJsonPath: "package.json",
87
- srcIndexPath: "src/index.ts",
88
- typesOutputCjsPattern: "./dist/types/{dir}/{name}.d.ts",
89
- typesOutputPattern: "./dist/types/{dir}/{name}.d.ts",
90
- },
91
- customPackageConfigs: {
92
- "@codefast/ui": {
93
- exportPathPrefixesToRemove: ["components"],
94
- },
95
- "@codefast/style-guide": {
96
- exportPathPrefixesToRemove: ["configs"],
97
- },
98
- },
99
- };
@@ -1,178 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
-
4
- import type { AnalysisResult, PackageExports, PackageJson } from "@/commands/update-exports/types";
5
-
6
- // Constants for file operations
7
- const EXPORTS_ANALYSIS_DIR = ".exports-analysis";
8
- const EXPORTS_PREVIEW_FILE = "exports-preview.json";
9
- const EXPORTS_ANALYSIS_FILE = "exports-analysis.json";
10
- const ENCODING = "utf8";
11
- const JSON_INDENT = 2;
12
- /**
13
- * Utility functions for file and directory operations
14
- */
15
- const FileUtils = {
16
- /**
17
- * Checks if a file exists
18
- * @param filePath - Path to check
19
- * @returns True if a file exists
20
- */
21
- exists(filePath: string): boolean {
22
- return fs.existsSync(filePath);
23
- },
24
-
25
- /**
26
- * Creates a directory if it doesn't exist
27
- * @param dirPath - Directory path
28
- */
29
- ensureDirectoryExists(dirPath: string): void {
30
- if (!fs.existsSync(dirPath)) {
31
- fs.mkdirSync(dirPath, { recursive: true });
32
- }
33
- },
34
-
35
- /**
36
- * Reads and parses a JSON file
37
- * @param filePath - Path to JSON file
38
- * @returns Parsed content or null if error
39
- */
40
- readJsonFile<T>(filePath: string): null | T {
41
- try {
42
- const content = fs.readFileSync(filePath, ENCODING);
43
-
44
- return JSON.parse(content) as T;
45
- } catch (error) {
46
- console.error(`Error reading JSON file at ${filePath}:`, error);
47
-
48
- return null;
49
- }
50
- },
51
-
52
- /**
53
- * Writes content to a JSON file
54
- * @param filePath - Path to write
55
- * @param content - Content to write
56
- * @returns True if successful
57
- */
58
- writeJsonFile<T>(filePath: string, content: T): boolean {
59
- try {
60
- fs.writeFileSync(filePath, `${JSON.stringify(content, null, JSON_INDENT)}\n`, ENCODING);
61
-
62
- return true;
63
- } catch (error) {
64
- console.error(`Error writing JSON file at ${filePath}:`, error);
65
-
66
- return false;
67
- }
68
- },
69
-
70
- /**
71
- * Gets the exports analysis directory path
72
- * @param packageDir - Package directory
73
- * @returns Analysis directory path
74
- */
75
- getAnalysisDir(packageDir: string): string {
76
- const outputDir = path.join(packageDir, EXPORTS_ANALYSIS_DIR);
77
-
78
- this.ensureDirectoryExists(outputDir);
79
-
80
- return outputDir;
81
- },
82
-
83
- /**
84
- * Creates a timestamped backup filename
85
- * @param baseFilename - Original filename
86
- * @returns Backup filename with timestamp
87
- */
88
- createBackupFilename(baseFilename: string): string {
89
- const timestamp = new Date().toISOString().replaceAll(/[:.]/g, "-");
90
-
91
- return `${baseFilename}.backup.${timestamp}`;
92
- },
93
- };
94
-
95
- /**
96
- * Checks if a file exists
97
- * @param filePath - Path to check
98
- * @returns True if a file exists
99
- */
100
- export function fileExists(filePath: string): boolean {
101
- return FileUtils.exists(filePath);
102
- }
103
-
104
- /**
105
- * Reads and parses package.json content
106
- * @param filePath - Path to package.json
107
- * @returns Parsed PackageJson or null if error
108
- */
109
- export function readPackageJson(filePath: string): null | PackageJson {
110
- return FileUtils.readJsonFile<PackageJson>(filePath);
111
- }
112
-
113
- /**
114
- * Creates a backup of package.json
115
- * @param filePath - Path to package.json
116
- * @returns True if backup was successful
117
- */
118
- export function backupPackageJson(filePath: string): boolean {
119
- try {
120
- const content = fs.readFileSync(filePath, ENCODING);
121
- const dir = path.dirname(filePath);
122
- const backupDir = path.join(dir, EXPORTS_ANALYSIS_DIR);
123
-
124
- FileUtils.ensureDirectoryExists(backupDir);
125
-
126
- const baseName = path.basename(filePath);
127
- const backupPath = path.join(backupDir, FileUtils.createBackupFilename(baseName));
128
-
129
- fs.writeFileSync(backupPath, content, ENCODING);
130
-
131
- return true;
132
- } catch (error) {
133
- console.error(`Error backing up package.json at ${filePath}:`, error);
134
-
135
- return false;
136
- }
137
- }
138
-
139
- /**
140
- * Saves updated package.json content
141
- * @param filePath - Path to package.json
142
- * @param content - Updated content
143
- * @returns True if save was successful
144
- */
145
- export function savePackageJson(filePath: string, content: PackageJson): boolean {
146
- return FileUtils.writeJsonFile(filePath, content);
147
- }
148
-
149
- /**
150
- * Saves the given JSON content to a specified file within the analysis directory.
151
- *
152
- * @param packageDir - The root directory where the analysis directory resides.
153
- * @param fileName - The name of the file to which the JSON content will be written.
154
- * @param content - The JSON content to save to the file.
155
- */
156
- export function saveJsonToFile<T>(packageDir: string, fileName: string, content: T): void {
157
- const outputDir = FileUtils.getAnalysisDir(packageDir);
158
-
159
- FileUtils.writeJsonFile(path.join(outputDir, fileName), content);
160
- }
161
-
162
- /**
163
- * Saves exports analysis results
164
- * @param packageDir - Package directory
165
- * @param analysis - Analysis results
166
- */
167
- export function saveExportsAnalysis(packageDir: string, analysis: AnalysisResult): void {
168
- saveJsonToFile(packageDir, EXPORTS_ANALYSIS_FILE, analysis);
169
- }
170
-
171
- /**
172
- * Saves preview of generated exports
173
- * @param packageDir - Package directory
174
- * @param exports - Generated exports
175
- */
176
- export function saveExportsPreview(packageDir: string, exports: PackageExports): void {
177
- saveJsonToFile(packageDir, EXPORTS_PREVIEW_FILE, exports);
178
- }
@@ -1,74 +0,0 @@
1
- import type { ImportPath, PackageExports, ScriptConfig } from "@/commands/update-exports/types";
2
-
3
- import { getPackageConfig } from "@/commands/update-exports/config";
4
-
5
- /**
6
- * Formats an output path based on a pattern, directory, and name
7
- * @param pattern - Output pattern
8
- * @param directory - Directory path
9
- * @param name - Module name
10
- * @returns Formatted output path
11
- */
12
- function formatOutputPath(pattern: string, directory: string, name: string): string {
13
- const dirPart = directory === "." ? "" : `${directory}/`;
14
-
15
- return pattern.replace("{dir}/", dirPart).replace("{dir}", directory).replace("{name}", name);
16
- }
17
-
18
- /**
19
- * Generates export structure for package.json
20
- * @param packageName - Name of the package
21
- * @param imports - Analyzed import paths
22
- * @param existingExports - Current exports to preserve
23
- * @param config - Optional ScriptConfig
24
- * @returns Updated PackageExports
25
- */
26
- export function generateExports(
27
- packageName: string,
28
- imports: ImportPath[],
29
- existingExports: PackageExports = {},
30
- config?: ScriptConfig,
31
- ): PackageExports {
32
- const packageConfig = getPackageConfig(packageName, config);
33
-
34
- const exports: PackageExports = {
35
- ".": existingExports["."] ?? {
36
- import: {
37
- types: "./dist/types/index.d.ts",
38
- default: "./dist/esm/index.js",
39
- },
40
- require: {
41
- types: "./dist/types/index.d.cts",
42
- default: "./dist/cjs/index.cjs",
43
- },
44
- },
45
- };
46
-
47
- // Preserve existing CSS exports
48
- if (existingExports["./styles.css"]) {
49
- exports["./styles.css"] = existingExports["./styles.css"];
50
- }
51
-
52
- // Generate exports for each import path
53
- for (const importPath of imports) {
54
- const { directory, name, exportPath } = importPath;
55
-
56
- const esmOutput = formatOutputPath(packageConfig.esmOutputPattern, directory, name);
57
- const cjsOutput = formatOutputPath(packageConfig.cjsOutputPattern, directory, name);
58
- const typesOutput = formatOutputPath(packageConfig.typesOutputPattern, directory, name);
59
- const typesCjsOutput = formatOutputPath(packageConfig.typesOutputCjsPattern, directory, name);
60
-
61
- exports[exportPath] = {
62
- import: {
63
- types: typesOutput,
64
- default: esmOutput,
65
- },
66
- require: {
67
- types: typesCjsOutput,
68
- default: cjsOutput,
69
- },
70
- };
71
- }
72
-
73
- return exports;
74
- }
@@ -1 +0,0 @@
1
- export { createUpdateExportsCommand } from "@/commands/update-exports/command";
@@ -1,164 +0,0 @@
1
- import { glob } from "glob";
2
- import path from "node:path";
3
-
4
- import type { ProcessOptions, ScriptConfig } from "@/commands/update-exports/types";
5
- import type { Logger } from "@/lib/logger";
6
-
7
- import { analyzeImports } from "@/commands/update-exports/analyze-imports";
8
- import { getConfig, getPackageConfig } from "@/commands/update-exports/config";
9
- import {
10
- backupPackageJson,
11
- fileExists,
12
- readPackageJson,
13
- saveExportsAnalysis,
14
- saveExportsPreview,
15
- savePackageJson,
16
- } from "@/commands/update-exports/file-utils";
17
- import { generateExports } from "@/commands/update-exports/generate-exports";
18
-
19
- const DEFAULT_IGNORE_PATTERN = ["**/node_modules/**"];
20
-
21
- /**
22
- * Finds all package.json files in the workspace
23
- * @param config - Optional ScriptConfig
24
- * @returns Array of package.json paths
25
- */
26
- export async function findAllPackages(config?: ScriptConfig): Promise<string[]> {
27
- const configObj = config ?? getConfig();
28
-
29
- return await glob(configObj.packagesGlob, {
30
- ignore: DEFAULT_IGNORE_PATTERN,
31
- });
32
- }
33
-
34
- /**
35
- * Processes a single package
36
- * @param packageJsonPath - Path to package.json
37
- * @param options - Processing options
38
- * @param logger - Logger instance
39
- * @returns True if processing was successful
40
- */
41
- export function processPackage(packageJsonPath: string, options: ProcessOptions, logger: Logger): boolean {
42
- const packageDir = path.dirname(packageJsonPath);
43
- const packageJson = readPackageJson(packageJsonPath);
44
-
45
- if (!packageJson) {
46
- logger.error(`Failed to read ${packageJsonPath}`);
47
-
48
- return false;
49
- }
50
-
51
- const packageName = packageJson.name;
52
-
53
- // Skip if package doesn't match filter
54
- if (options.packageFilter && packageName !== options.packageFilter) {
55
- logger.debug(`Skipping ${packageName} (does not match filter)`);
56
-
57
- return false;
58
- }
59
-
60
- logger.info(`\n๐Ÿ“ฆ Processing package: ${packageName}`);
61
-
62
- const config = getConfig(options.configPath);
63
- const packageConfig = getPackageConfig(packageName, config);
64
- const srcIndexPath = path.join(packageDir, packageConfig.srcIndexPath);
65
-
66
- if (!fileExists(srcIndexPath)) {
67
- logger.error(`Source file not found at ${srcIndexPath}`);
68
-
69
- return false;
70
- }
71
-
72
- // Analyze imports
73
- logger.info(`๐Ÿ” Analyzing imports from ${srcIndexPath}...`);
74
- const { imports } = analyzeImports(srcIndexPath, packageConfig);
75
-
76
- if (imports.length === 0) {
77
- logger.warn(`No imports found to analyze in ${packageName}`);
78
-
79
- return false;
80
- }
81
-
82
- logger.success(`Analysis complete. Found ${imports.length} subpath exports.`);
83
-
84
- // Save analysis results
85
- saveExportsAnalysis(packageDir, { imports });
86
-
87
- // Generate new exports
88
- const newExports = generateExports(packageName, imports, packageJson.exports, config);
89
-
90
- // Compare export counts
91
- const currentExportsCount = packageJson.exports ? Object.keys(packageJson.exports).length : 0;
92
- const newExportsCount = Object.keys(newExports).length;
93
-
94
- logger.info(`๐Ÿ“Š Exports: ${currentExportsCount} -> ${newExportsCount}`);
95
-
96
- if (options.dryRun) {
97
- saveExportsPreview(packageDir, newExports);
98
- logger.warn(`๐Ÿงช ๐Ÿ“„ Saved exports preview to .exports-analysis`);
99
- logger.warn(`๐Ÿงช ๐Ÿšซ Dry run: no changes saved for ${packageName}`);
100
-
101
- return true;
102
- }
103
-
104
- // Backup package.json
105
- if (backupPackageJson(packageJsonPath)) {
106
- logger.success(`Backed up ${packageJsonPath}`);
107
- }
108
-
109
- // Update package.json
110
- const updatedPackageJson = { ...packageJson, exports: newExports };
111
-
112
- if (savePackageJson(packageJsonPath, updatedPackageJson)) {
113
- logger.success(`Updated exports for ${packageName}`);
114
-
115
- return true;
116
- }
117
-
118
- logger.error(`Failed to update ${packageJsonPath}`);
119
-
120
- return false;
121
- }
122
-
123
- /**
124
- * Processes all packages in the workspace
125
- * @param options - Processing options
126
- * @param logger - Logger instance
127
- */
128
- export async function processAllPackages(options: ProcessOptions, logger: Logger): Promise<void> {
129
- try {
130
- logger.info("๐Ÿ” Searching for packages...");
131
- const config = getConfig(options.configPath);
132
- const packageJsonPaths = await findAllPackages(config);
133
-
134
- if (packageJsonPaths.length === 0) {
135
- logger.warn("โš ๏ธ No packages found.");
136
-
137
- return;
138
- }
139
-
140
- logger.success(`โœ… Found ${packageJsonPaths.length} packages.`);
141
-
142
- let successCount = 0;
143
- let skipCount = 0;
144
- let errorCount = 0;
145
-
146
- for (const packageJsonPath of packageJsonPaths) {
147
- const result = processPackage(packageJsonPath, options, logger);
148
-
149
- if (result) {
150
- successCount++;
151
- } else if (options.packageFilter) {
152
- skipCount++;
153
- } else {
154
- errorCount++;
155
- }
156
- }
157
-
158
- logger.success("\nโœ… Completed exports update.");
159
- logger.info(`๐Ÿ“Š Stats: ${successCount} succeeded, ${skipCount} skipped, ${errorCount} failed`);
160
- } catch (error) {
161
- logger.error("โŒ Error processing packages:", error);
162
- throw error;
163
- }
164
- }