@common-stack/common-tools 8.2.4-alpha.11

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 (50) hide show
  1. package/LICENSE +34 -0
  2. package/README.md +186 -0
  3. package/bin/common-tools.js +26 -0
  4. package/bin/generate-resolutions.js +22 -0
  5. package/bin/sort-package-json.js +23 -0
  6. package/bin/update-dependencies.js +23 -0
  7. package/bin/update-dependency-version.js +22 -0
  8. package/lib/cli/generateResolutions.d.ts +25 -0
  9. package/lib/cli/generateResolutions.d.ts.map +1 -0
  10. package/lib/cli/generateResolutions.js +75 -0
  11. package/lib/cli/generateResolutions.js.map +1 -0
  12. package/lib/cli/sortPackageJson.d.ts +42 -0
  13. package/lib/cli/sortPackageJson.d.ts.map +1 -0
  14. package/lib/cli/sortPackageJson.js +163 -0
  15. package/lib/cli/sortPackageJson.js.map +1 -0
  16. package/lib/cli/updateDependencies.d.ts +27 -0
  17. package/lib/cli/updateDependencies.d.ts.map +1 -0
  18. package/lib/cli/updateDependencies.js +85 -0
  19. package/lib/cli/updateDependencies.js.map +1 -0
  20. package/lib/cli/updateDependencyVersion.d.ts +39 -0
  21. package/lib/cli/updateDependencyVersion.d.ts.map +1 -0
  22. package/lib/cli/updateDependencyVersion.js +170 -0
  23. package/lib/cli/updateDependencyVersion.js.map +1 -0
  24. package/lib/config/index.d.ts +6 -0
  25. package/lib/config/index.d.ts.map +1 -0
  26. package/lib/config/loader.d.ts +30 -0
  27. package/lib/config/loader.d.ts.map +1 -0
  28. package/lib/config/loader.js +109 -0
  29. package/lib/config/loader.js.map +1 -0
  30. package/lib/config/types.d.ts +82 -0
  31. package/lib/config/types.d.ts.map +1 -0
  32. package/lib/config/types.js +43 -0
  33. package/lib/config/types.js.map +1 -0
  34. package/lib/index.d.ts +376 -0
  35. package/lib/index.d.ts.map +1 -0
  36. package/lib/index.js +11 -0
  37. package/lib/index.js.map +1 -0
  38. package/lib/utils/dependencies.d.ts +47 -0
  39. package/lib/utils/dependencies.d.ts.map +1 -0
  40. package/lib/utils/dependencies.js +96 -0
  41. package/lib/utils/dependencies.js.map +1 -0
  42. package/lib/utils/monorepo.d.ts +29 -0
  43. package/lib/utils/monorepo.d.ts.map +1 -0
  44. package/lib/utils/monorepo.js +102 -0
  45. package/lib/utils/monorepo.js.map +1 -0
  46. package/lib/utils/packageJson.d.ts +53 -0
  47. package/lib/utils/packageJson.d.ts.map +1 -0
  48. package/lib/utils/packageJson.js +76 -0
  49. package/lib/utils/packageJson.js.map +1 -0
  50. package/package.json +69 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,376 @@
1
+ export { ResolutionResult, CDecodeConfig as ServerCDecodeConfig, ServerConfig, analyzeModuleDependencies, generateResolutionsFromCDecodeConfig, generateServerResolutions, getServersFromCDecodeConfig, readCDecodeConfig as readCDecodeConfigFromServer, updateServerPackageJson } from '@common-stack/rollup-vite-utils';
2
+ import { Command } from 'commander';
3
+
4
+ /**
5
+ * Central configuration types for cdecode-config.json
6
+ *
7
+ * This file defines the structure of the cdecode-config.json configuration file
8
+ * that drives all the common-tools utilities.
9
+ */
10
+ interface CDecodeConfig {
11
+ /** Server config.json paths for codegen */
12
+ servers?: string[];
13
+ /** Codegen configuration */
14
+ codegen?: CodegenConfig;
15
+ /** Update dependencies configuration */
16
+ updateDependencies?: UpdateDependenciesConfig;
17
+ /** Update dependency version configuration */
18
+ updateDependencyVersion?: UpdateDependencyVersionConfig;
19
+ /** Sort package.json configuration */
20
+ sortPackageJson?: SortPackageJsonConfig;
21
+ /** Deploy version update configuration */
22
+ deployVersionUpdate?: DeployVersionUpdateConfig;
23
+ /** Project paths configuration */
24
+ projectPaths?: ProjectPathsConfig;
25
+ /** Service schemas configuration */
26
+ serviceSchemas?: ServiceSchemasConfig;
27
+ }
28
+ interface CodegenConfig {
29
+ outputFile?: string;
30
+ rootSchema?: string;
31
+ fullConfig?: Record<string, unknown>;
32
+ }
33
+ interface UpdateDependenciesConfig {
34
+ /** Packages to check for updates */
35
+ packagesToCheck?: string[];
36
+ /** Package paths by category */
37
+ packagePaths?: {
38
+ backend?: string[];
39
+ frontend?: string[];
40
+ mobile?: string[];
41
+ };
42
+ }
43
+ interface UpdateDependencyVersionConfig {
44
+ /** Root directories to scan */
45
+ roots?: string[];
46
+ /** Pattern to ignore */
47
+ ignorePattern?: string;
48
+ /** JSON indentation spacing */
49
+ jsonSpacing?: number;
50
+ /** Add newline at end of files */
51
+ addEndNewLine?: boolean;
52
+ /** Git commit message */
53
+ commitMessage?: string;
54
+ }
55
+ interface SortPackageJsonConfig {
56
+ /** Directories to process */
57
+ directories?: string[];
58
+ /** Skip node_modules directories */
59
+ skipNodeModules?: boolean;
60
+ }
61
+ interface DeployVersionUpdateConfig {
62
+ lernaJsonPath?: string;
63
+ jenkinsfilePath?: string;
64
+ valuesDevYamlPath?: string;
65
+ valuesProdYamlPath?: string;
66
+ }
67
+ interface ProjectPathsConfig {
68
+ packages?: string;
69
+ packagesModules?: string;
70
+ servers?: string;
71
+ portableDevices?: string;
72
+ }
73
+ interface ServiceSchemasConfig {
74
+ servicesDir?: string;
75
+ outputFile?: string;
76
+ skipServices?: string[];
77
+ knownEnums?: string[];
78
+ constEnumSchemas?: string[];
79
+ graphqlSchemasPath?: string;
80
+ }
81
+ /**
82
+ * Default configuration values
83
+ */
84
+ declare const DEFAULT_CONFIG: Partial<CDecodeConfig>;
85
+
86
+ /**
87
+ * Configuration loader for cdecode-config.json
88
+ */
89
+
90
+ /**
91
+ * Finds the cdecode-config.json file by walking up the directory tree
92
+ */
93
+ declare function findConfigFile(startDir?: string): string | null;
94
+ /**
95
+ * Loads and parses the cdecode-config.json file
96
+ */
97
+ declare function loadConfig(rootDir?: string): {
98
+ config: CDecodeConfig;
99
+ configPath: string;
100
+ repoRoot: string;
101
+ };
102
+ /**
103
+ * Loads config with defaults merged in
104
+ */
105
+ declare function loadConfigWithDefaults(rootDir?: string): {
106
+ config: CDecodeConfig;
107
+ configPath: string;
108
+ repoRoot: string;
109
+ };
110
+ /**
111
+ * Resolves relative paths in config to absolute paths
112
+ */
113
+ declare function resolveConfigPaths(config: CDecodeConfig, repoRoot: string): CDecodeConfig;
114
+
115
+ /**
116
+ * Package.json utility functions
117
+ */
118
+ declare const JSON_SPACING = 4;
119
+ declare const ADD_END_NEWLINE = true;
120
+ interface PackageJson {
121
+ name?: string;
122
+ version?: string;
123
+ dependencies?: Record<string, string>;
124
+ devDependencies?: Record<string, string>;
125
+ peerDependencies?: Record<string, string>;
126
+ resolutions?: Record<string, string>;
127
+ [key: string]: unknown;
128
+ }
129
+ /**
130
+ * Reads and parses a package.json file
131
+ */
132
+ declare function readPackageJson(filePath: string): Promise<PackageJson>;
133
+ /**
134
+ * Reads and parses a package.json file synchronously
135
+ */
136
+ declare function readPackageJsonSync(filePath: string): PackageJson;
137
+ /**
138
+ * Writes a package.json file with proper formatting
139
+ */
140
+ declare function writePackageJson(filePath: string, content: PackageJson, options?: {
141
+ spacing?: number;
142
+ endNewline?: boolean;
143
+ }): Promise<void>;
144
+ /**
145
+ * Writes a package.json file synchronously with proper formatting
146
+ */
147
+ declare function writePackageJsonSync(filePath: string, content: PackageJson, options?: {
148
+ spacing?: number;
149
+ endNewline?: boolean;
150
+ }): void;
151
+ /**
152
+ * Merges dependencies from source into target
153
+ */
154
+ declare function mergeDependencies(target?: Record<string, string>, source?: Record<string, string>): Record<string, string>;
155
+ /**
156
+ * Sorts an object's keys alphabetically
157
+ */
158
+ declare function sortObjectKeys<T extends Record<string, unknown>>(obj: T): T;
159
+ /**
160
+ * Checks if a file exists
161
+ */
162
+ declare function fileExists(filePath: string): Promise<boolean>;
163
+ /**
164
+ * Checks if a file exists synchronously
165
+ */
166
+ declare function fileExistsSync(filePath: string): boolean;
167
+
168
+ /**
169
+ * Dependency management utilities
170
+ */
171
+ /**
172
+ * Executes a command in a directory and returns a promise
173
+ */
174
+ declare function execCommand(command: string, cwd: string): Promise<string>;
175
+ /**
176
+ * Configuration for dependency update operations
177
+ */
178
+ interface DependencyUpdateConfig {
179
+ /** Paths to server/app package.json files by category */
180
+ packagePaths: {
181
+ backend?: string[];
182
+ frontend?: string[];
183
+ mobile?: string[];
184
+ };
185
+ /** Packages to check and update */
186
+ packagesToCheck: string[];
187
+ /** Root directory of the monorepo */
188
+ rootDir: string;
189
+ }
190
+ /**
191
+ * Default packages to check for @common-stack based monorepos
192
+ */
193
+ declare const DEFAULT_COMMON_STACK_PACKAGES: string[];
194
+ /**
195
+ * Updates dependencies in a target package.json from a source package.json
196
+ */
197
+ declare function updateDependencies(targetPackagePath: string, sourcePackagePath: string): Promise<void>;
198
+ /**
199
+ * Gets the target package paths based on the package name
200
+ */
201
+ declare function getTargetPathsForPackage(packageName: string, config: DependencyUpdateConfig): string[];
202
+ /**
203
+ * Runs npm-check-updates for @common-stack packages
204
+ */
205
+ declare function runNcuUpdate(rootDir: string): Promise<void>;
206
+ /**
207
+ * Runs yarn install from the root directory
208
+ */
209
+ declare function runYarnInstall(rootDir: string): Promise<void>;
210
+ /**
211
+ * Runs the complete dependency update workflow
212
+ */
213
+ declare function runUpdateDependenciesWorkflow(config: DependencyUpdateConfig): Promise<void>;
214
+
215
+ /**
216
+ * Monorepo utilities for finding and processing packages
217
+ */
218
+ /**
219
+ * Finds all package.json files in a monorepo
220
+ */
221
+ declare function findPackageJsonFiles(rootDir: string, patterns?: string[]): Promise<string[]>;
222
+ /**
223
+ * Builds a map of package name to path and version
224
+ */
225
+ declare function buildPackageMap(rootDir: string, patterns?: string[]): Promise<Map<string, {
226
+ path: string;
227
+ version: string;
228
+ }>>;
229
+ /**
230
+ * Recursively finds all directories containing package.json
231
+ */
232
+ declare function findPackageDirectories(dir: string, options?: {
233
+ exclude?: string[];
234
+ }): Promise<string[]>;
235
+ /**
236
+ * Gets all workspace packages from yarn/npm workspaces config
237
+ */
238
+ declare function getWorkspacePackages(rootPackageJsonPath: string): Promise<string[]>;
239
+ /**
240
+ * Reads cdecode-config.json from a directory
241
+ */
242
+ declare function readCDecodeConfigFile(rootDir: string): Record<string, unknown> | null;
243
+
244
+ /**
245
+ * CLI for generating package resolutions
246
+ *
247
+ * Reads configuration from cdecode-config.json:
248
+ * - updateDependencies.packagePaths: Server package.json paths by category
249
+ */
250
+
251
+ interface GenerateResolutionsOptions {
252
+ category: 'backend' | 'frontend' | 'mobile' | 'all';
253
+ dryRun: boolean;
254
+ packages: string[];
255
+ }
256
+ /**
257
+ * Creates the generate-resolutions command
258
+ */
259
+ declare function createGenerateResolutionsCommand(): Command;
260
+ /**
261
+ * Runs the resolution generation process
262
+ */
263
+ declare function runGenerateResolutions(repoRoot: string, options: GenerateResolutionsOptions): Promise<void>;
264
+ /**
265
+ * Standalone CLI entry point
266
+ */
267
+ declare function runGenerateResolutionsCLI(args?: string[]): Promise<void>;
268
+
269
+ /**
270
+ * CLI for updating dependencies from @common-stack packages
271
+ *
272
+ * Reads configuration from cdecode-config.json:
273
+ * - updateDependencies.packagesToCheck: Packages to check for updates
274
+ * - updateDependencies.packagePaths: Server package.json paths by category
275
+ */
276
+
277
+ interface UpdateDependenciesOptions {
278
+ packages?: string[];
279
+ skipNcu?: boolean;
280
+ skipYarn?: boolean;
281
+ }
282
+ /**
283
+ * Creates the update-dependencies command
284
+ */
285
+ declare function createUpdateDependenciesCommand(): Command;
286
+ /**
287
+ * Runs the update dependencies CLI action
288
+ */
289
+ declare function runUpdateDependenciesCLIAction(rootDir: string, options: UpdateDependenciesOptions, configPackagePaths?: DependencyUpdateConfig['packagePaths']): Promise<void>;
290
+ /**
291
+ * Standalone CLI entry point
292
+ */
293
+ declare function runUpdateDependenciesCLI(args?: string[]): Promise<void>;
294
+
295
+ /**
296
+ * CLI for sorting package.json files
297
+ *
298
+ * Reads configuration from cdecode-config.json:
299
+ * - sortPackageJson.directories: Directories to process
300
+ * - sortPackageJson.skipNodeModules: Skip node_modules directories
301
+ */
302
+
303
+ interface SortPackageJsonOptions {
304
+ directories?: string[];
305
+ recursive?: boolean;
306
+ dryRun?: boolean;
307
+ }
308
+ /**
309
+ * Creates the sort-package-json command
310
+ */
311
+ declare function createSortPackageJsonCommand(): Command;
312
+ /**
313
+ * Sorts a single package.json file
314
+ */
315
+ declare function sortPackageJsonFile(filePath: string, options?: {
316
+ dryRun?: boolean;
317
+ }): Promise<boolean>;
318
+ /**
319
+ * Recursively sorts all package.json files in a directory
320
+ */
321
+ declare function sortAllPackageJsonFiles(dir: string, options?: {
322
+ dryRun?: boolean;
323
+ }): Promise<{
324
+ sorted: string[];
325
+ unchanged: string[];
326
+ errors: string[];
327
+ }>;
328
+ /**
329
+ * Runs the sort package.json process
330
+ */
331
+ declare function runSortPackageJson(rootDir: string, options: SortPackageJsonOptions): Promise<void>;
332
+ /**
333
+ * Standalone CLI entry point
334
+ */
335
+ declare function runSortPackageJsonCLI(args?: string[]): Promise<void>;
336
+
337
+ /**
338
+ * CLI for updating dependency versions across monorepo packages
339
+ *
340
+ * Reads configuration from cdecode-config.json:
341
+ * - updateDependencyVersion.roots: Root directories to scan
342
+ * - updateDependencyVersion.ignorePattern: Pattern to ignore
343
+ * - updateDependencyVersion.jsonSpacing: JSON indentation
344
+ * - updateDependencyVersion.addEndNewLine: Add newline at end
345
+ * - updateDependencyVersion.commitMessage: Git commit message
346
+ *
347
+ * This tool updates all package.json files to use consistent versions
348
+ * for internal monorepo packages and replaces link: references with actual versions.
349
+ */
350
+
351
+ interface UpdateDependencyVersionOptions {
352
+ commit?: boolean;
353
+ dryRun?: boolean;
354
+ }
355
+ /**
356
+ * Creates the update-dependency-version command
357
+ */
358
+ declare function createUpdateDependencyVersionCommand(): Command;
359
+ /**
360
+ * Updates all package.json files in the monorepo
361
+ */
362
+ declare function updateDependencyVersions(monorepoRoot: string, options?: {
363
+ dryRun?: boolean;
364
+ config?: UpdateDependencyVersionConfig;
365
+ }): Promise<string[]>;
366
+ /**
367
+ * Runs the update dependency version process
368
+ */
369
+ declare function runUpdateDependencyVersion(rootDir: string, options: UpdateDependencyVersionOptions, config?: UpdateDependencyVersionConfig): Promise<void>;
370
+ /**
371
+ * Standalone CLI entry point
372
+ */
373
+ declare function runUpdateDependencyVersionCLI(args?: string[]): Promise<void>;
374
+
375
+ export { ADD_END_NEWLINE, DEFAULT_COMMON_STACK_PACKAGES, DEFAULT_CONFIG, JSON_SPACING, buildPackageMap, createGenerateResolutionsCommand, createSortPackageJsonCommand, createUpdateDependenciesCommand, createUpdateDependencyVersionCommand, execCommand, fileExists, fileExistsSync, findConfigFile, findPackageDirectories, findPackageJsonFiles, getTargetPathsForPackage, getWorkspacePackages, loadConfig, loadConfigWithDefaults, mergeDependencies, readCDecodeConfigFile, readPackageJson, readPackageJsonSync, resolveConfigPaths, runGenerateResolutions, runGenerateResolutionsCLI, runNcuUpdate, runSortPackageJson, runSortPackageJsonCLI, runUpdateDependenciesCLI, runUpdateDependenciesCLIAction, runUpdateDependenciesWorkflow, runUpdateDependencyVersion, runUpdateDependencyVersionCLI, runYarnInstall, sortAllPackageJsonFiles, sortObjectKeys, sortPackageJsonFile, updateDependencies, updateDependencyVersions, writePackageJson, writePackageJsonSync };
376
+ export type { CDecodeConfig, CodegenConfig, DependencyUpdateConfig, DeployVersionUpdateConfig, GenerateResolutionsOptions, PackageJson, ProjectPathsConfig, ServiceSchemasConfig, SortPackageJsonConfig, SortPackageJsonOptions, UpdateDependenciesConfig, UpdateDependenciesOptions, UpdateDependencyVersionConfig, UpdateDependencyVersionOptions };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACH,yBAAyB,EACzB,oCAAoC,EACpC,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,IAAI,2BAA2B,EAChD,2BAA2B,EAC3B,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,aAAa,IAAI,mBAAmB,GAC5C,MAAM,iCAAiC,CAAC;AAGzC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { analyzeModuleDependencies, generateResolutionsFromCDecodeConfig, generateServerResolutions, getServersFromCDecodeConfig, readCDecodeConfig as readCDecodeConfigFromServer, updateServerPackageJson } from '@common-stack/rollup-vite-utils';
2
+ export { DEFAULT_CONFIG } from './config/types.js';
3
+ export { findConfigFile, loadConfig, loadConfigWithDefaults, resolveConfigPaths } from './config/loader.js';
4
+ export { ADD_END_NEWLINE, JSON_SPACING, fileExists, fileExistsSync, mergeDependencies, readPackageJson, readPackageJsonSync, sortObjectKeys, writePackageJson, writePackageJsonSync } from './utils/packageJson.js';
5
+ export { DEFAULT_COMMON_STACK_PACKAGES, execCommand, getTargetPathsForPackage, runNcuUpdate, runUpdateDependenciesWorkflow, runYarnInstall, updateDependencies } from './utils/dependencies.js';
6
+ export { buildPackageMap, findPackageDirectories, findPackageJsonFiles, getWorkspacePackages, readCDecodeConfigFile } from './utils/monorepo.js';
7
+ export { createGenerateResolutionsCommand, runGenerateResolutions, runGenerateResolutionsCLI } from './cli/generateResolutions.js';
8
+ export { createUpdateDependenciesCommand, runUpdateDependenciesCLI, runUpdateDependenciesCLIAction } from './cli/updateDependencies.js';
9
+ export { createSortPackageJsonCommand, runSortPackageJson, runSortPackageJsonCLI, sortAllPackageJsonFiles, sortPackageJsonFile } from './cli/sortPackageJson.js';
10
+ export { createUpdateDependencyVersionCommand, runUpdateDependencyVersion, runUpdateDependencyVersionCLI, updateDependencyVersions } from './cli/updateDependencyVersion.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Dependency management utilities
3
+ */
4
+ /**
5
+ * Executes a command in a directory and returns a promise
6
+ */
7
+ export declare function execCommand(command: string, cwd: string): Promise<string>;
8
+ /**
9
+ * Configuration for dependency update operations
10
+ */
11
+ export interface DependencyUpdateConfig {
12
+ /** Paths to server/app package.json files by category */
13
+ packagePaths: {
14
+ backend?: string[];
15
+ frontend?: string[];
16
+ mobile?: string[];
17
+ };
18
+ /** Packages to check and update */
19
+ packagesToCheck: string[];
20
+ /** Root directory of the monorepo */
21
+ rootDir: string;
22
+ }
23
+ /**
24
+ * Default packages to check for @common-stack based monorepos
25
+ */
26
+ export declare const DEFAULT_COMMON_STACK_PACKAGES: string[];
27
+ /**
28
+ * Updates dependencies in a target package.json from a source package.json
29
+ */
30
+ export declare function updateDependencies(targetPackagePath: string, sourcePackagePath: string): Promise<void>;
31
+ /**
32
+ * Gets the target package paths based on the package name
33
+ */
34
+ export declare function getTargetPathsForPackage(packageName: string, config: DependencyUpdateConfig): string[];
35
+ /**
36
+ * Runs npm-check-updates for @common-stack packages
37
+ */
38
+ export declare function runNcuUpdate(rootDir: string): Promise<void>;
39
+ /**
40
+ * Runs yarn install from the root directory
41
+ */
42
+ export declare function runYarnInstall(rootDir: string): Promise<void>;
43
+ /**
44
+ * Runs the complete dependency update workflow
45
+ */
46
+ export declare function runUpdateDependenciesWorkflow(config: DependencyUpdateConfig): Promise<void>;
47
+ //# sourceMappingURL=dependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/utils/dependencies.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWzE;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC,yDAAyD;IACzD,YAAY,EAAE;QACV,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,mCAAmC;IACnC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,6BAA6B,UAIzC,CAAC;AAEF;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ5G;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,GAAG,MAAM,EAAE,CAQtG;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnE;AAED;;GAEG;AACH,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBjG"}
@@ -0,0 +1,96 @@
1
+ import { exec } from 'child_process';
2
+ import { resolve } from 'path';
3
+ import { readPackageJson, mergeDependencies, writePackageJson } from './packageJson.js';
4
+
5
+ /**
6
+ * Dependency management utilities
7
+ */
8
+ /**
9
+ * Executes a command in a directory and returns a promise
10
+ */
11
+ function execCommand(command, cwd) {
12
+ return new Promise((resolve, reject) => {
13
+ exec(command, { cwd, maxBuffer: 1024 * 1024 * 10 }, (err, stdout, stderr) => {
14
+ if (err) {
15
+ console.error(`Error executing command: ${command}\n${stderr}`);
16
+ return reject(err);
17
+ }
18
+ console.log(stdout);
19
+ resolve(stdout);
20
+ });
21
+ });
22
+ }
23
+ /**
24
+ * Default packages to check for @common-stack based monorepos
25
+ */
26
+ const DEFAULT_COMMON_STACK_PACKAGES = [
27
+ '@common-stack/server-stack',
28
+ '@common-stack/frontend-stack-react',
29
+ '@common-stack/mobile-stack-react',
30
+ ];
31
+ /**
32
+ * Updates dependencies in a target package.json from a source package.json
33
+ */
34
+ async function updateDependencies(targetPackagePath, sourcePackagePath) {
35
+ const targetPackageJson = await readPackageJson(targetPackagePath);
36
+ const sourcePackageJson = await readPackageJson(sourcePackagePath);
37
+ // Merge dependencies only
38
+ targetPackageJson.dependencies = mergeDependencies(targetPackageJson.dependencies, sourcePackageJson.dependencies);
39
+ await writePackageJson(targetPackagePath, targetPackageJson);
40
+ }
41
+ /**
42
+ * Gets the target package paths based on the package name
43
+ */
44
+ function getTargetPathsForPackage(packageName, config) {
45
+ if (packageName.includes('server-stack')) {
46
+ return config.packagePaths.backend || [];
47
+ }
48
+ else if (packageName.includes('mobile-stack-react')) {
49
+ return config.packagePaths.mobile || [];
50
+ }
51
+ else {
52
+ return config.packagePaths.frontend || [];
53
+ }
54
+ }
55
+ /**
56
+ * Runs npm-check-updates for @common-stack packages
57
+ */
58
+ async function runNcuUpdate(rootDir) {
59
+ console.log('Updating dependencies using `ncu`...');
60
+ await execCommand('ncu -u -t minor "@common-stack*" && lerna exec "ncu -u -t minor /@common-stack*/"', rootDir);
61
+ }
62
+ /**
63
+ * Runs yarn install from the root directory
64
+ */
65
+ async function runYarnInstall(rootDir) {
66
+ console.log('Running yarn install...');
67
+ await execCommand('yarn', rootDir);
68
+ }
69
+ /**
70
+ * Runs the complete dependency update workflow
71
+ */
72
+ async function runUpdateDependenciesWorkflow(config) {
73
+ const { rootDir, packagesToCheck, packagePaths } = config;
74
+ // Step 1: Run ncu to update dependencies
75
+ await runNcuUpdate(rootDir);
76
+ // Step 2: Run yarn to install updated packages
77
+ await runYarnInstall(rootDir);
78
+ // Step 3: Update dependencies for each package
79
+ for (const packageName of packagesToCheck) {
80
+ const packagePath = resolve(rootDir, `node_modules/${packageName}/package.json`);
81
+ const targetPaths = getTargetPathsForPackage(packageName, config);
82
+ for (const targetPackagePath of targetPaths) {
83
+ try {
84
+ await updateDependencies(targetPackagePath, packagePath);
85
+ console.log(`Updated dependencies for ${packageName} in ${targetPackagePath}`);
86
+ }
87
+ catch (error) {
88
+ console.warn(`Package ${packageName} not found or failed to update in ${targetPackagePath}:`, error);
89
+ }
90
+ }
91
+ }
92
+ console.log('Dependencies from @common-stack packages have been updated.');
93
+ }
94
+
95
+ export { DEFAULT_COMMON_STACK_PACKAGES, execCommand, getTargetPathsForPackage, runNcuUpdate, runUpdateDependenciesWorkflow, runYarnInstall, updateDependencies };
96
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.js","sources":["../../src/utils/dependencies.ts"],"sourcesContent":[null],"names":[],"mappings":"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"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Monorepo utilities for finding and processing packages
3
+ */
4
+ /**
5
+ * Finds all package.json files in a monorepo
6
+ */
7
+ export declare function findPackageJsonFiles(rootDir: string, patterns?: string[]): Promise<string[]>;
8
+ /**
9
+ * Builds a map of package name to path and version
10
+ */
11
+ export declare function buildPackageMap(rootDir: string, patterns?: string[]): Promise<Map<string, {
12
+ path: string;
13
+ version: string;
14
+ }>>;
15
+ /**
16
+ * Recursively finds all directories containing package.json
17
+ */
18
+ export declare function findPackageDirectories(dir: string, options?: {
19
+ exclude?: string[];
20
+ }): Promise<string[]>;
21
+ /**
22
+ * Gets all workspace packages from yarn/npm workspaces config
23
+ */
24
+ export declare function getWorkspacePackages(rootPackageJsonPath: string): Promise<string[]>;
25
+ /**
26
+ * Reads cdecode-config.json from a directory
27
+ */
28
+ export declare function readCDecodeConfigFile(rootDir: string): Record<string, unknown> | null;
29
+ //# sourceMappingURL=monorepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monorepo.d.ts","sourceRoot":"","sources":["../../src/utils/monorepo.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,wBAAsB,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAM,EAAoE,GACrF,OAAO,CAAC,MAAM,EAAE,CAAC,CAKnB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAmBzD;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0BjH;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAsBzF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAQrF"}
@@ -0,0 +1,102 @@
1
+ import { promises } from 'fs';
2
+ import path from 'path';
3
+ import { readPackageJsonSync } from './packageJson.js';
4
+ import { glob } from 'glob';
5
+
6
+ /**
7
+ * Monorepo utilities for finding and processing packages
8
+ */
9
+ /**
10
+ * Finds all package.json files in a monorepo
11
+ */
12
+ async function findPackageJsonFiles(rootDir, patterns = ['servers', 'portable-devices', 'packages', 'packages-modules']) {
13
+ const globPattern = `${rootDir}/+(${patterns.join('|')})/**/package.json`;
14
+ return glob(globPattern, {
15
+ ignore: ['**/node_modules/**'],
16
+ });
17
+ }
18
+ /**
19
+ * Builds a map of package name to path and version
20
+ */
21
+ async function buildPackageMap(rootDir, patterns) {
22
+ const packageJsonFiles = await findPackageJsonFiles(rootDir, patterns);
23
+ const packageMap = new Map();
24
+ for (const file of packageJsonFiles) {
25
+ try {
26
+ const packageJson = readPackageJsonSync(file);
27
+ if (packageJson.name) {
28
+ packageMap.set(packageJson.name, {
29
+ path: path.dirname(file),
30
+ version: packageJson.version || '0.0.0',
31
+ });
32
+ }
33
+ }
34
+ catch (error) {
35
+ console.warn(`Failed to read ${file}:`, error);
36
+ }
37
+ }
38
+ return packageMap;
39
+ }
40
+ /**
41
+ * Recursively finds all directories containing package.json
42
+ */
43
+ async function findPackageDirectories(dir, options = {}) {
44
+ const { exclude = ['node_modules'] } = options;
45
+ const directories = [];
46
+ async function walk(currentDir) {
47
+ const entries = await promises.readdir(currentDir, { withFileTypes: true });
48
+ for (const entry of entries) {
49
+ if (entry.isDirectory() && !exclude.includes(entry.name)) {
50
+ const fullPath = path.join(currentDir, entry.name);
51
+ const packageJsonPath = path.join(fullPath, 'package.json');
52
+ try {
53
+ await promises.access(packageJsonPath);
54
+ directories.push(fullPath);
55
+ }
56
+ catch {
57
+ // No package.json, continue walking
58
+ }
59
+ await walk(fullPath);
60
+ }
61
+ }
62
+ }
63
+ await walk(dir);
64
+ return directories;
65
+ }
66
+ /**
67
+ * Gets all workspace packages from yarn/npm workspaces config
68
+ */
69
+ async function getWorkspacePackages(rootPackageJsonPath) {
70
+ const rootPackage = readPackageJsonSync(rootPackageJsonPath);
71
+ const workspaces = rootPackage.workspaces;
72
+ if (!workspaces) {
73
+ return [];
74
+ }
75
+ // Handle both array format and object format with packages property
76
+ const patterns = Array.isArray(workspaces) ? workspaces : workspaces.packages || [];
77
+ const rootDir = path.dirname(rootPackageJsonPath);
78
+ const allPackages = [];
79
+ for (const pattern of patterns) {
80
+ const matches = await glob(path.join(rootDir, pattern, 'package.json'), {
81
+ ignore: ['**/node_modules/**'],
82
+ });
83
+ allPackages.push(...matches.map((m) => path.dirname(m)));
84
+ }
85
+ return allPackages;
86
+ }
87
+ /**
88
+ * Reads cdecode-config.json from a directory
89
+ */
90
+ function readCDecodeConfigFile(rootDir) {
91
+ try {
92
+ const configPath = path.join(rootDir, 'cdecode-config.json');
93
+ const content = readPackageJsonSync(configPath);
94
+ return content;
95
+ }
96
+ catch {
97
+ return null;
98
+ }
99
+ }
100
+
101
+ export { buildPackageMap, findPackageDirectories, findPackageJsonFiles, getWorkspacePackages, readCDecodeConfigFile };
102
+ //# sourceMappingURL=monorepo.js.map