@codefast/cli 0.3.1-canary.1 → 0.3.1-canary.10

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 +89 -1
  2. package/dist/index.cjs +972 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.js +939 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +19 -12
  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,47 +0,0 @@
1
- import type { AnalysisResult, PackageExports, PackageJson } from "../../../commands/update-exports/types";
2
- /**
3
- * Checks if a file exists
4
- * @param filePath - Path to check
5
- * @returns True if a file exists
6
- */
7
- export declare function fileExists(filePath: string): boolean;
8
- /**
9
- * Reads and parses package.json content
10
- * @param filePath - Path to package.json
11
- * @returns Parsed PackageJson or null if error
12
- */
13
- export declare function readPackageJson(filePath: string): null | PackageJson;
14
- /**
15
- * Creates a backup of package.json
16
- * @param filePath - Path to package.json
17
- * @returns True if backup was successful
18
- */
19
- export declare function backupPackageJson(filePath: string): boolean;
20
- /**
21
- * Saves updated package.json content
22
- * @param filePath - Path to package.json
23
- * @param content - Updated content
24
- * @returns True if save was successful
25
- */
26
- export declare function savePackageJson(filePath: string, content: PackageJson): boolean;
27
- /**
28
- * Saves the given JSON content to a specified file within the analysis directory.
29
- *
30
- * @param packageDir - The root directory where the analysis directory resides.
31
- * @param fileName - The name of the file to which the JSON content will be written.
32
- * @param content - The JSON content to save to the file.
33
- */
34
- export declare function saveJsonToFile<T>(packageDir: string, fileName: string, content: T): void;
35
- /**
36
- * Saves exports analysis results
37
- * @param packageDir - Package directory
38
- * @param analysis - Analysis results
39
- */
40
- export declare function saveExportsAnalysis(packageDir: string, analysis: AnalysisResult): void;
41
- /**
42
- * Saves preview of generated exports
43
- * @param packageDir - Package directory
44
- * @param exports - Generated exports
45
- */
46
- export declare function saveExportsPreview(packageDir: string, exports: PackageExports): void;
47
- //# sourceMappingURL=file-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../../../../src/commands/update-exports/file-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AA2FnG;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,WAAW,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAmB3D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAE/E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAIxF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAEtF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAEpF"}
@@ -1,11 +0,0 @@
1
- import type { ImportPath, PackageExports, ScriptConfig } from "../../../commands/update-exports/types";
2
- /**
3
- * Generates export structure for package.json
4
- * @param packageName - Name of the package
5
- * @param imports - Analyzed import paths
6
- * @param existingExports - Current exports to preserve
7
- * @param config - Optional ScriptConfig
8
- * @returns Updated PackageExports
9
- */
10
- export declare function generateExports(packageName: string, imports: ImportPath[], existingExports?: PackageExports, config?: ScriptConfig): PackageExports;
11
- //# sourceMappingURL=generate-exports.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-exports.d.ts","sourceRoot":"","sources":["../../../../../src/commands/update-exports/generate-exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAiBhG;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,UAAU,EAAE,EACrB,eAAe,GAAE,cAAmB,EACpC,MAAM,CAAC,EAAE,YAAY,GACpB,cAAc,CA2ChB"}
@@ -1,2 +0,0 @@
1
- export { createUpdateExportsCommand } from "../../../commands/update-exports/command";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/commands/update-exports/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { ProcessOptions, ScriptConfig } from "../../../commands/update-exports/types";
2
- import type { Logger } from "../../../lib/logger";
3
- /**
4
- * Finds all package.json files in the workspace
5
- * @param config - Optional ScriptConfig
6
- * @returns Array of package.json paths
7
- */
8
- export declare function findAllPackages(config?: ScriptConfig): Promise<string[]>;
9
- /**
10
- * Processes a single package
11
- * @param packageJsonPath - Path to package.json
12
- * @param options - Processing options
13
- * @param logger - Logger instance
14
- * @returns True if processing was successful
15
- */
16
- export declare function processPackage(packageJsonPath: string, options: ProcessOptions, logger: Logger): boolean;
17
- /**
18
- * Processes all packages in the workspace
19
- * @param options - Processing options
20
- * @param logger - Logger instance
21
- */
22
- export declare function processAllPackages(options: ProcessOptions, logger: Logger): Promise<void>;
23
- //# sourceMappingURL=process-package.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process-package.d.ts","sourceRoot":"","sources":["../../../../../src/commands/update-exports/process-package.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAgB3C;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAM9E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAgFxG;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC/F"}
@@ -1,83 +0,0 @@
1
- import { z } from "zod";
2
- export declare const PackageConfigSchema: z.ZodInterface<{
3
- cjsOutputPattern: z.ZodString;
4
- esmOutputPattern: z.ZodString;
5
- packageJsonPath: z.ZodString;
6
- srcIndexPath: z.ZodString;
7
- typesOutputCjsPattern: z.ZodString;
8
- typesOutputPattern: z.ZodString;
9
- exportPathPrefixesToRemove: z.ZodArray<z.ZodString>;
10
- }, {
11
- optional: "exportPathPrefixesToRemove";
12
- defaulted: never;
13
- extra: {};
14
- }>;
15
- export declare const ScriptConfigSchema: z.ZodInterface<{
16
- customPackageConfigs: z.ZodRecord<z.ZodString, z.ZodInterface<{
17
- cjsOutputPattern: z.ZodOptional<z.ZodString>;
18
- esmOutputPattern: z.ZodOptional<z.ZodString>;
19
- packageJsonPath: z.ZodOptional<z.ZodString>;
20
- srcIndexPath: z.ZodOptional<z.ZodString>;
21
- typesOutputCjsPattern: z.ZodOptional<z.ZodString>;
22
- typesOutputPattern: z.ZodOptional<z.ZodString>;
23
- exportPathPrefixesToRemove: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
- }, {
25
- optional: "cjsOutputPattern" | "esmOutputPattern" | "packageJsonPath" | "srcIndexPath" | "typesOutputCjsPattern" | "typesOutputPattern" | "exportPathPrefixesToRemove";
26
- defaulted: never;
27
- extra: {};
28
- }>>;
29
- defaultPackageConfig: z.ZodInterface<{
30
- cjsOutputPattern: z.ZodString;
31
- esmOutputPattern: z.ZodString;
32
- packageJsonPath: z.ZodString;
33
- srcIndexPath: z.ZodString;
34
- typesOutputCjsPattern: z.ZodString;
35
- typesOutputPattern: z.ZodString;
36
- exportPathPrefixesToRemove: z.ZodArray<z.ZodString>;
37
- }, {
38
- optional: "exportPathPrefixesToRemove";
39
- defaulted: never;
40
- extra: {};
41
- }>;
42
- packagesGlob: z.ZodString;
43
- }, {
44
- optional: never;
45
- defaulted: never;
46
- extra: {};
47
- }>;
48
- export type PackageConfig = z.infer<typeof PackageConfigSchema>;
49
- export type ScriptConfig = z.infer<typeof ScriptConfigSchema>;
50
- export interface ImportPath {
51
- directory: string;
52
- exportPath: string;
53
- name: string;
54
- originalPath: string;
55
- }
56
- export interface AnalysisResult {
57
- imports: ImportPath[];
58
- }
59
- export interface ExportConfig {
60
- import: {
61
- default: string;
62
- types: string;
63
- };
64
- require: {
65
- default: string;
66
- types: string;
67
- };
68
- }
69
- export type ExportTarget = ExportConfig | string;
70
- export type PackageExports = Record<string, ExportTarget>;
71
- export interface PackageJson {
72
- [key: string]: unknown;
73
- name: string;
74
- version: string;
75
- exports?: PackageExports;
76
- }
77
- export interface ProcessOptions {
78
- dryRun: boolean;
79
- verbose: boolean;
80
- configPath?: string;
81
- packageFilter?: string;
82
- }
83
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/commands/update-exports/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAsB9B,CAAC;AAGH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW7B,CAAC;AAGH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAG9D,MAAM,WAAW,UAAU;IAEzB,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,MAAM,CAAC;CACtB;AAGD,MAAM,WAAW,cAAc;IAE7B,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAGD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,MAAM,CAAC;AACjD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAG1D,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAEhB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAGD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- interface LoggerOptions {
2
- verbose?: boolean;
3
- }
4
- export declare class Logger {
5
- private readonly verbose;
6
- constructor(options?: LoggerOptions);
7
- info(message: string, ...args: any[]): void;
8
- success(message: string, ...args: any[]): void;
9
- warn(message: string, ...args: any[]): void;
10
- error(message: string, ...args: any[]): void;
11
- debug(message: string, ...args: any[]): void;
12
- table(data: any[]): void;
13
- }
14
- export {};
15
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/lib/logger.ts"],"names":[],"mappings":"AAEA,UAAU,aAAa;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAEtB,OAAO,GAAE,aAAkB;IAIvC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI3C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI9C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5C,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAGzB"}
package/eslint.config.js DELETED
@@ -1,18 +0,0 @@
1
- import { config } from "@codefast/eslint-config/library";
2
-
3
- /** @type {import('eslint').Linter.Config[]} */
4
- export default [
5
- ...config,
6
- {
7
- rules: {
8
- "@typescript-eslint/no-explicit-any": "off",
9
- "@typescript-eslint/no-non-null-assertion": "off",
10
- "@typescript-eslint/no-redundant-type-constituents": "off",
11
- "@typescript-eslint/no-unsafe-argument": "off",
12
- "@typescript-eslint/no-unsafe-assignment": "off",
13
- "@typescript-eslint/no-unsafe-member-access": "off",
14
- "@typescript-eslint/no-unsafe-return": "off",
15
- "no-console": "off",
16
- },
17
- },
18
- ];
package/rslib.config.ts DELETED
@@ -1,40 +0,0 @@
1
- import { defineConfig } from "@rslib/core";
2
-
3
- export default defineConfig({
4
- lib: [
5
- {
6
- bundle: false,
7
- dts: {
8
- distPath: "./dist/types",
9
- },
10
- format: "esm",
11
- output: {
12
- distPath: {
13
- root: "./dist/esm",
14
- },
15
- },
16
- },
17
- {
18
- bundle: false,
19
- format: "cjs",
20
- output: {
21
- distPath: {
22
- root: "./dist/cjs",
23
- },
24
- },
25
- },
26
- ],
27
- output: {
28
- sourceMap: true,
29
- },
30
- performance: {
31
- buildCache: true,
32
- printFileSize: false,
33
- },
34
- source: {
35
- entry: {
36
- index: ["./src/**/*.{ts,tsx}", "!./src/**/*.{test,spec}.{ts,tsx}"],
37
- },
38
- tsconfigPath: "./tsconfig.build.json",
39
- },
40
- });
@@ -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
- };