@aneuhold/core-ts-lib 2.2.9 → 2.2.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 (89) hide show
  1. package/lib/index.d.ts +5 -3
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +3 -2
  4. package/lib/index.js.map +1 -1
  5. package/lib/index.ts +5 -2
  6. package/lib/services/ChangelogService/ChangelogFileService.d.ts +42 -0
  7. package/lib/services/ChangelogService/ChangelogFileService.d.ts.map +1 -0
  8. package/lib/services/ChangelogService/ChangelogFileService.js +65 -0
  9. package/lib/services/ChangelogService/ChangelogFileService.js.map +1 -0
  10. package/lib/services/ChangelogService/ChangelogFileService.ts +68 -0
  11. package/lib/services/ChangelogService/ChangelogGenerator.d.ts +58 -0
  12. package/lib/services/ChangelogService/ChangelogGenerator.d.ts.map +1 -0
  13. package/lib/services/ChangelogService/ChangelogGenerator.js +145 -0
  14. package/lib/services/ChangelogService/ChangelogGenerator.js.map +1 -0
  15. package/lib/services/ChangelogService/ChangelogGenerator.ts +188 -0
  16. package/lib/services/ChangelogService/ChangelogParser.d.ts +21 -0
  17. package/lib/services/ChangelogService/ChangelogParser.d.ts.map +1 -0
  18. package/lib/services/ChangelogService/ChangelogParser.js +76 -0
  19. package/lib/services/ChangelogService/ChangelogParser.js.map +1 -0
  20. package/lib/services/ChangelogService/ChangelogParser.ts +94 -0
  21. package/lib/services/ChangelogService/ChangelogService.d.ts +54 -0
  22. package/lib/services/ChangelogService/ChangelogService.d.ts.map +1 -0
  23. package/lib/services/ChangelogService/ChangelogService.js +201 -0
  24. package/lib/services/ChangelogService/ChangelogService.js.map +1 -0
  25. package/lib/services/ChangelogService/ChangelogService.ts +293 -0
  26. package/lib/services/ChangelogService/ChangelogValidator.d.ts +15 -0
  27. package/lib/services/ChangelogService/ChangelogValidator.d.ts.map +1 -0
  28. package/lib/services/ChangelogService/ChangelogValidator.js +44 -0
  29. package/lib/services/ChangelogService/ChangelogValidator.js.map +1 -0
  30. package/lib/services/ChangelogService/ChangelogValidator.ts +55 -0
  31. package/lib/services/ChangelogService/GitTagService.d.ts +29 -0
  32. package/lib/services/ChangelogService/GitTagService.d.ts.map +1 -0
  33. package/lib/services/ChangelogService/GitTagService.js +57 -0
  34. package/lib/services/ChangelogService/GitTagService.js.map +1 -0
  35. package/lib/services/ChangelogService/GitTagService.ts +60 -0
  36. package/lib/services/ChangelogService/RepositoryInfoService.d.ts +14 -0
  37. package/lib/services/ChangelogService/RepositoryInfoService.d.ts.map +1 -0
  38. package/lib/services/ChangelogService/RepositoryInfoService.js +55 -0
  39. package/lib/services/ChangelogService/RepositoryInfoService.js.map +1 -0
  40. package/lib/services/ChangelogService/RepositoryInfoService.ts +64 -0
  41. package/lib/services/ChangelogService/index.d.ts +2 -0
  42. package/lib/services/ChangelogService/index.d.ts.map +1 -0
  43. package/lib/services/ChangelogService/index.js +2 -0
  44. package/lib/services/ChangelogService/index.js.map +1 -0
  45. package/lib/services/ChangelogService/index.ts +1 -0
  46. package/lib/services/ChangelogService/types.d.ts +27 -0
  47. package/lib/services/ChangelogService/types.d.ts.map +1 -0
  48. package/lib/services/ChangelogService/types.js +3 -0
  49. package/lib/services/ChangelogService/types.js.map +1 -0
  50. package/lib/services/ChangelogService/types.ts +30 -0
  51. package/lib/services/DependencyService.d.ts +2 -9
  52. package/lib/services/DependencyService.d.ts.map +1 -1
  53. package/lib/services/DependencyService.js +2 -11
  54. package/lib/services/DependencyService.js.map +1 -1
  55. package/lib/services/DependencyService.ts +2 -11
  56. package/lib/services/PackageService/JsrPackageService.d.ts +81 -0
  57. package/lib/services/PackageService/JsrPackageService.d.ts.map +1 -0
  58. package/lib/services/{PackageService.js → PackageService/JsrPackageService.js} +70 -312
  59. package/lib/services/PackageService/JsrPackageService.js.map +1 -0
  60. package/lib/services/{PackageService.ts → PackageService/JsrPackageService.ts} +79 -372
  61. package/lib/services/PackageService/NpmPackageService.d.ts +45 -0
  62. package/lib/services/PackageService/NpmPackageService.d.ts.map +1 -0
  63. package/lib/services/PackageService/NpmPackageService.js +146 -0
  64. package/lib/services/PackageService/NpmPackageService.js.map +1 -0
  65. package/lib/services/PackageService/NpmPackageService.ts +178 -0
  66. package/lib/services/PackageService/PackageService.d.ts +77 -0
  67. package/lib/services/PackageService/PackageService.d.ts.map +1 -0
  68. package/lib/services/PackageService/PackageService.js +96 -0
  69. package/lib/services/PackageService/PackageService.js.map +1 -0
  70. package/lib/services/PackageService/PackageService.ts +108 -0
  71. package/lib/services/PackageService/PackageServiceUtils.d.ts +69 -0
  72. package/lib/services/PackageService/PackageServiceUtils.d.ts.map +1 -0
  73. package/lib/services/PackageService/PackageServiceUtils.js +185 -0
  74. package/lib/services/PackageService/PackageServiceUtils.js.map +1 -0
  75. package/lib/services/PackageService/PackageServiceUtils.ts +239 -0
  76. package/lib/services/StringService.d.ts +12 -0
  77. package/lib/services/StringService.d.ts.map +1 -1
  78. package/lib/services/StringService.js +56 -0
  79. package/lib/services/StringService.js.map +1 -1
  80. package/lib/services/StringService.ts +72 -0
  81. package/lib/types/VersionType.d.ts +9 -0
  82. package/lib/types/VersionType.d.ts.map +1 -0
  83. package/lib/types/VersionType.js +10 -0
  84. package/lib/types/VersionType.js.map +1 -0
  85. package/lib/types/VersionType.ts +8 -0
  86. package/package.json +7 -6
  87. package/lib/services/PackageService.d.ts +0 -159
  88. package/lib/services/PackageService.d.ts.map +0 -1
  89. package/lib/services/PackageService.js.map +0 -1
@@ -2,21 +2,20 @@ import { exec, spawn } from 'child_process';
2
2
  import { access, readFile, writeFile } from 'fs/promises';
3
3
  import path from 'path';
4
4
  import { promisify } from 'util';
5
- import { JsonWithVersionProperty } from '../types/JsonWithVersionProperty.js';
6
- import { PackageJson } from '../types/PackageJson.js';
7
- import ErrorUtils from '../utils/ErrorUtils.js';
8
- import { DR } from './DependencyRegistry.js';
9
- import DependencyService from './DependencyService.js';
10
- import FileSystemService from './FileSystemService/FileSystemService.js';
11
- import StringService from './StringService.js';
5
+ import { JsonWithVersionProperty } from '../../types/JsonWithVersionProperty.js';
6
+ import { PackageJson } from '../../types/PackageJson.js';
7
+ import ErrorUtils from '../../utils/ErrorUtils.js';
8
+ import { DR } from '../DependencyRegistry.js';
9
+ import DependencyService from '../DependencyService.js';
10
+ import FileSystemService from '../FileSystemService/FileSystemService.js';
11
+ import PackageServiceUtils from './PackageServiceUtils.js';
12
12
 
13
13
  const execAsync = promisify(exec);
14
14
 
15
15
  /**
16
- * A service which can be used to assist in publishing or validating packages
17
- * for the current project.
16
+ * Service for handling JSR-specific package operations including validation and publishing.
18
17
  */
19
- export default class PackageService {
18
+ export default class JsrPackageService {
20
19
  /**
21
20
  * Validates the current project for publishing to JSR. This will check if the
22
21
  * project has any pending changes first, then update the version of the
@@ -28,13 +27,12 @@ export default class PackageService {
28
27
  * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
29
28
  * if the package name appears in unexpected places. Use with caution.
30
29
  */
31
- static async validateJsrPublish(alternativePackageNames?: string[]): Promise<void> {
32
- if (await FileSystemService.hasPendingChanges()) {
33
- DR.logger.error('Please commit or stash your changes before publishing.');
34
- process.exit(1);
35
- }
30
+ static async validatePublish(alternativePackageNames?: string[]): Promise<void> {
31
+ const { packageName: originalPackageName, version: currentVersion } =
32
+ await PackageServiceUtils.getPackageInfo();
33
+
34
+ await PackageServiceUtils.validatePrePublishRequirements(currentVersion);
36
35
 
37
- const { packageName: originalPackageName } = await PackageService.getPackageInfo();
38
36
  const packageNamesToValidate = [originalPackageName, ...(alternativePackageNames || [])];
39
37
 
40
38
  for (const packageName of packageNamesToValidate) {
@@ -43,14 +41,14 @@ export default class PackageService {
43
41
  DR.logger.info(`Validating JSR publishing for package: ${packageName}`);
44
42
 
45
43
  if (isAlternativeName) {
46
- await PackageService.replacePackageName(originalPackageName, packageName);
44
+ await PackageServiceUtils.replacePackageName(originalPackageName, packageName);
47
45
  }
48
46
 
49
- await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
50
- const { version: currentVersion } = await PackageService.updateJsrFromPackageJson();
51
- const successfulDryRun = await PackageService.publishJsrDryRun(packageName, currentVersion);
47
+ await this.replaceMonorepoImportsWithNpmSpecifiers();
48
+ const { version } = await JsrPackageService.updateJsrFromPackageJson();
49
+ const successfulDryRun = await JsrPackageService.publishDryRun(packageName, version);
52
50
 
53
- await PackageService.resetGitChanges();
51
+ await PackageServiceUtils.resetGitChanges();
54
52
 
55
53
  if (!successfulDryRun) {
56
54
  process.exit(1);
@@ -68,13 +66,13 @@ export default class PackageService {
68
66
  * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
69
67
  * if the package name appears in unexpected places. Use with caution.
70
68
  */
71
- static async publishToJsr(alternativePackageNames?: string[]): Promise<void> {
72
- if (await FileSystemService.hasPendingChanges()) {
73
- DR.logger.error('Please commit or stash your changes before publishing.');
74
- process.exit(1);
75
- }
69
+ static async publish(alternativePackageNames?: string[]): Promise<void> {
70
+ const { packageName: originalPackageName } = await PackageServiceUtils.getPackageInfo();
71
+
72
+ await PackageServiceUtils.validatePrePublishRequirements(
73
+ (await PackageServiceUtils.getPackageInfo()).version
74
+ );
76
75
 
77
- const { packageName: originalPackageName } = await PackageService.getPackageInfo();
78
76
  const packageNamesToPublish = [originalPackageName, ...(alternativePackageNames || [])];
79
77
 
80
78
  for (const packageName of packageNamesToPublish) {
@@ -83,14 +81,14 @@ export default class PackageService {
83
81
  DR.logger.info(`Publishing to JSR for package: ${packageName}`);
84
82
 
85
83
  if (isAlternativeName) {
86
- await PackageService.replacePackageName(originalPackageName, packageName);
84
+ await PackageServiceUtils.replacePackageName(originalPackageName, packageName);
87
85
  }
88
86
 
89
- await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
90
- await PackageService.updateJsrFromPackageJson();
91
- const result = await PackageService.publishJsr();
87
+ await this.replaceMonorepoImportsWithNpmSpecifiers();
88
+ await JsrPackageService.updateJsrFromPackageJson();
89
+ const result = await JsrPackageService.publishToJsr();
92
90
 
93
- await PackageService.resetGitChanges();
91
+ await PackageServiceUtils.resetGitChanges();
94
92
 
95
93
  if (!result) {
96
94
  process.exit(1);
@@ -100,111 +98,6 @@ export default class PackageService {
100
98
  DR.logger.success('Successfully published to JSR for all package names.');
101
99
  }
102
100
 
103
- /**
104
- * Validates the current project for publishing to npm. This will run
105
- * `npm publish --access public --dry-run` and check for version conflicts
106
- * on the npm registry.
107
- *
108
- * @param alternativePackageNames Optional array of alternative package names to validate publishing under
109
- *
110
- * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
111
- * if the package name appears in unexpected places. Use with caution.
112
- */
113
- static async validateNpmPublish(alternativePackageNames?: string[]): Promise<void> {
114
- if (await FileSystemService.hasPendingChanges()) {
115
- DR.logger.error('Please commit or stash your changes before publishing.');
116
- process.exit(1);
117
- }
118
-
119
- const { packageName: originalPackageName, version: currentVersion } =
120
- await PackageService.getPackageInfo();
121
- const packageNamesToValidate = [originalPackageName, ...(alternativePackageNames || [])];
122
-
123
- for (const packageName of packageNamesToValidate) {
124
- const isAlternativeName = packageName !== originalPackageName;
125
-
126
- DR.logger.info(`Validating npm publishing for package: ${packageName}`);
127
-
128
- if (isAlternativeName) {
129
- await PackageService.replacePackageName(originalPackageName, packageName);
130
- }
131
-
132
- const successfulDryRun = await PackageService.publishNpmDryRun();
133
- if (!successfulDryRun) {
134
- if (isAlternativeName) {
135
- await PackageService.resetGitChanges();
136
- }
137
- process.exit(1);
138
- }
139
-
140
- await PackageService.checkNpmVersionConflicts(packageName, currentVersion);
141
-
142
- if (isAlternativeName) {
143
- await PackageService.resetGitChanges();
144
- }
145
- }
146
-
147
- DR.logger.success('Successfully validated npm publishing for all package names.');
148
- }
149
-
150
- /**
151
- * Publishes the current project to npm.
152
- *
153
- * @param alternativePackageNames Optional array of alternative package names to publish under
154
- *
155
- * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
156
- * if the package name appears in unexpected places. Use with caution.
157
- */
158
- static async publishToNpm(alternativePackageNames?: string[]): Promise<void> {
159
- if (await FileSystemService.hasPendingChanges()) {
160
- DR.logger.error('Please commit or stash your changes before publishing.');
161
- process.exit(1);
162
- }
163
-
164
- const { packageName: originalPackageName } = await PackageService.getPackageInfo();
165
- const packageNamesToPublish = [originalPackageName, ...(alternativePackageNames || [])];
166
-
167
- for (const packageName of packageNamesToPublish) {
168
- const isAlternativeName = packageName !== originalPackageName;
169
-
170
- DR.logger.info(`Publishing to npm for package: ${packageName}`);
171
-
172
- if (isAlternativeName) {
173
- await PackageService.replacePackageName(originalPackageName, packageName);
174
- }
175
-
176
- const result = await PackageService.publishNpm();
177
-
178
- if (isAlternativeName) {
179
- await PackageService.resetGitChanges();
180
- }
181
-
182
- if (!result) {
183
- process.exit(1);
184
- }
185
- }
186
-
187
- DR.logger.success('Successfully published to npm for all package names.');
188
- }
189
-
190
- /**
191
- * Test method for string replacement functionality. This method allows testing
192
- * the string replacement behavior without performing actual publishing operations.
193
- *
194
- * @param originalString The original string to replace
195
- * @param newString The new string to replace it with
196
- *
197
- * **Warning:** This method uses simple string replacement, which may have unintended effects
198
- * if the string appears in unexpected places. Use with caution.
199
- */
200
- static async testStringReplacement(originalString: string, newString: string): Promise<void> {
201
- DR.logger.info(`Testing string replacement from "${originalString}" to "${newString}"`);
202
-
203
- await PackageService.replacePackageName(originalString, newString);
204
-
205
- DR.logger.info('Test completed - package name replacement has been applied');
206
- }
207
-
208
101
  /**
209
102
  * Updates the jsr.json file from the package.json file and resolves wildcard
210
103
  * dependencies in package.json for JSR compatibility.
@@ -226,7 +119,7 @@ export default class PackageService {
226
119
  }
227
120
 
228
121
  try {
229
- const { packageName, version } = await PackageService.getPackageInfo();
122
+ const { packageName, version } = await PackageServiceUtils.getPackageInfo();
230
123
  const packageJsonData = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
231
124
  const jsrJsonData = JSON.parse(
232
125
  await readFile(jsrJsonPath, 'utf-8')
@@ -252,51 +145,6 @@ export default class PackageService {
252
145
  }
253
146
  }
254
147
 
255
- /**
256
- * Resolves wildcard dependencies in package.json by replacing them with actual
257
- * version constraints (e.g., "*1.2.3") for JSR compatibility. This will
258
- * write the modified package.json back to disk.
259
- *
260
- * @param packageJsonData The package.json data to modify
261
- * @param packageJsonPath The path to the package.json file
262
- */
263
- private static async resolveWildcardDependenciesInPackageJson(
264
- packageJsonData: PackageJson,
265
- packageJsonPath: string
266
- ): Promise<void> {
267
- try {
268
- // Get all packages one directory up to resolve local wildcard dependencies
269
- const childPackages = await DependencyService.getChildPackageJsons('../');
270
-
271
- // Helper function to resolve dependencies
272
- const resolveDependencies = (deps: Record<string, string> | undefined): void => {
273
- if (!deps) return;
274
-
275
- for (const [depName, depVersion] of Object.entries(deps)) {
276
- if (depVersion === '*' && depName in childPackages) {
277
- // Replace wildcard with "*" + actual version from the monorepo
278
- deps[depName] = `*${childPackages[depName].packageJsonContents.version}`;
279
- }
280
- }
281
- };
282
-
283
- // Resolve each dependency type
284
- resolveDependencies(packageJsonData.dependencies);
285
- resolveDependencies(packageJsonData.devDependencies);
286
- resolveDependencies(packageJsonData.peerDependencies);
287
- resolveDependencies(packageJsonData.optionalDependencies);
288
-
289
- // Write the updated package.json
290
- await writeFile(packageJsonPath, JSON.stringify(packageJsonData, null, 2));
291
-
292
- DR.logger.info('Resolved wildcard dependencies in package.json for JSR compatibility');
293
- } catch (error) {
294
- const errorString = ErrorUtils.getErrorString(error);
295
- DR.logger.error(`Failed to resolve wildcard dependencies: ${errorString}`);
296
- throw error;
297
- }
298
- }
299
-
300
148
  /**
301
149
  * Executes a dry run of JSR publishing. Returns true if the dry run was
302
150
  * successful, false otherwise. Also checks for existing versions on JSR
@@ -306,12 +154,12 @@ export default class PackageService {
306
154
  * @param packageName The package name from jsr.json
307
155
  * @param currentVersion The current version from package.json
308
156
  */
309
- private static async publishJsrDryRun(
157
+ private static async publishDryRun(
310
158
  packageName: string,
311
159
  currentVersion: string
312
160
  ): Promise<boolean> {
313
161
  // Check for existing versions on JSR first
314
- await this.checkJsrVersionConflicts(packageName, currentVersion);
162
+ await JsrPackageService.checkVersionConflicts(packageName, currentVersion);
315
163
 
316
164
  DR.logger.info('Running `jsr publish --dry-run`');
317
165
  try {
@@ -332,7 +180,7 @@ export default class PackageService {
332
180
  *
333
181
  * @returns true if the publish was successful, false otherwise.
334
182
  */
335
- private static async publishJsr(): Promise<boolean> {
183
+ private static async publishToJsr(): Promise<boolean> {
336
184
  DR.logger.info('Running `jsr publish`');
337
185
  return new Promise((resolve) => {
338
186
  const child = spawn('jsr publish', ['--allow-dirty'], {
@@ -351,82 +199,35 @@ export default class PackageService {
351
199
  }
352
200
 
353
201
  /**
354
- * Gets the package name and version from package.json.
355
- *
356
- * @returns An object containing the package name and version
357
- */
358
- private static async getPackageInfo(): Promise<{
359
- packageName: string;
360
- version: string;
361
- }> {
362
- const rootDir = process.cwd();
363
- const packageJsonPath = path.join(rootDir, 'package.json');
364
-
365
- try {
366
- await access(packageJsonPath);
367
- } catch {
368
- throw new Error('No package.json file found in the current directory.');
369
- }
370
-
371
- try {
372
- const packageJsonData = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
373
-
374
- return {
375
- packageName: packageJsonData.name,
376
- version: packageJsonData.version
377
- };
378
- } catch (error) {
379
- const errorString = ErrorUtils.getErrorString(error);
380
- DR.logger.error(`Failed to read package.json: ${errorString}`);
381
- throw error;
382
- }
383
- }
384
-
385
- /**
386
- * Executes a dry run of npm publishing.
387
- *
388
- * @returns true if the dry run was successful, false otherwise.
389
- */
390
- private static async publishNpmDryRun(): Promise<boolean> {
391
- DR.logger.info('Running `npm publish --access public --dry-run`');
392
- try {
393
- await execAsync('npm publish --access public --dry-run');
394
- DR.logger.info('npm dry run completed successfully.');
395
- } catch (error) {
396
- const errorString = ErrorUtils.getErrorString(error);
397
- DR.logger.error(`npm dry run failed: ${errorString}`);
398
- return false;
399
- }
400
- return true;
401
- }
402
-
403
- /**
404
- * Checks npm registry for package information and performs version conflict checks.
202
+ * Checks for version conflicts on JSR by looking up the current package
203
+ * and comparing versions. Throws an error if the current version already
204
+ * exists or if a higher version is already published.
405
205
  *
406
- * @param packageName The package name from package.json
206
+ * @param packageName The package name from jsr.json
407
207
  * @param currentVersion The current version from package.json
408
208
  */
409
- private static async checkNpmVersionConflicts(
209
+ private static async checkVersionConflicts(
410
210
  packageName: string,
411
211
  currentVersion: string
412
212
  ): Promise<void> {
413
- DR.logger.info(`Checking npm registry for existing versions of ${packageName}...`);
213
+ DR.logger.info(`Checking JSR for existing versions of ${packageName}...`);
414
214
 
415
215
  try {
416
- const { stdout } = await execAsync(`npm view ${packageName}`);
216
+ const { stdout } = await execAsync(`jsr view ${packageName}`);
417
217
 
418
- // Parse the npm view output to extract the latest version
218
+ // Parse the JSR view output to extract the latest version
419
219
  const latestVersionMatch = stdout.match(/latest:\s*([^\s|]+)/);
420
220
  if (latestVersionMatch) {
421
221
  const latestVersion = latestVersionMatch[1];
422
- PackageService.checkVersionConflict(currentVersion, latestVersion, 'npm');
222
+
223
+ PackageServiceUtils.checkVersionConflict(currentVersion, latestVersion, 'JSR');
423
224
  }
424
225
  } catch (error) {
425
226
  const errorString = ErrorUtils.getErrorString(error);
426
227
 
427
- // If the package doesn't exist on npm, that's fine for first publish
428
- if (errorString.includes('404') || errorString.includes('not found')) {
429
- DR.logger.info('Package not found on npm - this appears to be a first publish.');
228
+ // If the package doesn't exist on JSR, that's fine for first publish
229
+ if (errorString.includes('Package not found') || errorString.includes('404')) {
230
+ DR.logger.info('Package not found on JSR - this appears to be a first publish.');
430
231
  return;
431
232
  }
432
233
 
@@ -435,8 +236,8 @@ export default class PackageService {
435
236
  throw error;
436
237
  }
437
238
 
438
- // For other npm command errors, log but don't block
439
- DR.logger.warn(`Could not check npm registry: ${errorString}`);
239
+ // For other JSR command errors, log but don't block
240
+ DR.logger.warn(`Could not check JSR versions: ${errorString}`);
440
241
  }
441
242
  }
442
243
 
@@ -557,141 +358,47 @@ export default class PackageService {
557
358
  }
558
359
 
559
360
  /**
560
- * Checks for version conflicts on JSR by looking up the current package
561
- * and comparing versions. Throws an error if the current version already
562
- * exists or if a higher version is already published.
361
+ * Resolves wildcard dependencies in package.json by replacing them with actual
362
+ * version constraints (e.g., "*1.2.3") for JSR compatibility. This will
363
+ * write the modified package.json back to disk.
563
364
  *
564
- * @param packageName The package name from jsr.json
565
- * @param currentVersion The current version from package.json
365
+ * @param packageJsonData The package.json data to modify
366
+ * @param packageJsonPath The path to the package.json file
566
367
  */
567
- private static async checkJsrVersionConflicts(
568
- packageName: string,
569
- currentVersion: string
368
+ private static async resolveWildcardDependenciesInPackageJson(
369
+ packageJsonData: PackageJson,
370
+ packageJsonPath: string
570
371
  ): Promise<void> {
571
- DR.logger.info(`Checking JSR for existing versions of ${packageName}...`);
572
-
573
372
  try {
574
- const { stdout } = await execAsync(`jsr view ${packageName}`);
575
-
576
- // Parse the JSR view output to extract the latest version
577
- const latestVersionMatch = stdout.match(/latest:\s*([^\s|]+)/);
578
- if (latestVersionMatch) {
579
- const latestVersion = latestVersionMatch[1];
580
-
581
- PackageService.checkVersionConflict(currentVersion, latestVersion, 'JSR');
582
- }
583
- } catch (error) {
584
- const errorString = ErrorUtils.getErrorString(error);
585
-
586
- // If the package doesn't exist on JSR, that's fine for first publish
587
- if (errorString.includes('Package not found') || errorString.includes('404')) {
588
- DR.logger.info('Package not found on JSR - this appears to be a first publish.');
589
- return;
590
- }
591
-
592
- // Re-throw version conflict errors
593
- if (errorString.includes('already exists') || errorString.includes('is lower than')) {
594
- throw error;
595
- }
596
-
597
- // For other JSR command errors, log but don't block
598
- DR.logger.warn(`Could not check JSR versions: ${errorString}`);
599
- }
600
- }
601
-
602
- /**
603
- * Common logic for checking version conflicts between current and latest versions.
604
- *
605
- * @param currentVersion The current version from package.json
606
- * @param latestVersion The latest published version
607
- * @param registryName The name of the registry (for error messages)
608
- */
609
- private static checkVersionConflict(
610
- currentVersion: string,
611
- latestVersion: string,
612
- registryName: string
613
- ): void {
614
- DR.logger.info(
615
- `Current version: ${currentVersion}, Latest on ${registryName}: ${latestVersion}`
616
- );
617
-
618
- // Compare versions using semver-like comparison
619
- const comparison = StringService.compareSemanticVersions(currentVersion, latestVersion);
620
-
621
- if (comparison === 0) {
622
- throw new Error(
623
- `Version ${currentVersion} already exists on ${registryName}. Please bump the version before publishing.`
624
- );
625
- } else if (comparison < 0) {
626
- throw new Error(
627
- `Current version ${currentVersion} is lower than the latest published version ${latestVersion} on ${registryName}. Please bump the version.`
628
- );
629
- }
630
-
631
- DR.logger.info('Version check passed - ready to publish.');
632
- }
373
+ // Get all packages one directory up to resolve local wildcard dependencies
374
+ const childPackages = await DependencyService.getChildPackageJsons('../');
633
375
 
634
- /**
635
- * Replaces the package name in all files in the root directory, but no child directories,
636
- * with a new name.
637
- *
638
- * @param originalPackageName The original package name to replace
639
- * @param newPackageName The new package name to use
640
- */
641
- private static async replacePackageName(
642
- originalPackageName: string,
643
- newPackageName: string
644
- ): Promise<void> {
645
- DR.logger.info(`Replacing package name from "${originalPackageName}" to "${newPackageName}"`);
376
+ // Helper function to resolve dependencies
377
+ const resolveDependencies = (deps: Record<string, string> | undefined): void => {
378
+ if (!deps) return;
646
379
 
647
- const rootDir = process.cwd();
380
+ for (const [depName, depVersion] of Object.entries(deps)) {
381
+ if (depVersion === '*' && depName in childPackages) {
382
+ // Replace wildcard with "*" + actual version from the monorepo
383
+ deps[depName] = `*${childPackages[depName].packageJsonContents.version}`;
384
+ }
385
+ }
386
+ };
648
387
 
649
- // Replace in all files in the root directory
650
- await FileSystemService.replaceInFiles({
651
- searchString: originalPackageName,
652
- replaceString: newPackageName,
653
- rootPath: rootDir,
654
- includePatterns: ['*'],
655
- excludePatterns: []
656
- });
388
+ // Resolve each dependency type
389
+ resolveDependencies(packageJsonData.dependencies);
390
+ resolveDependencies(packageJsonData.devDependencies);
391
+ resolveDependencies(packageJsonData.peerDependencies);
392
+ resolveDependencies(packageJsonData.optionalDependencies);
657
393
 
658
- DR.logger.info(`Successfully replaced package name in configuration files`);
659
- }
394
+ // Write the updated package.json
395
+ await writeFile(packageJsonPath, JSON.stringify(packageJsonData, null, 2));
660
396
 
661
- /**
662
- * Performs a git reset to discard all changes in the working directory.
663
- * This is used between alternative package name operations.
664
- */
665
- private static async resetGitChanges(): Promise<void> {
666
- DR.logger.info('Resetting git changes');
667
- try {
668
- await execAsync('git reset --hard HEAD');
397
+ DR.logger.info('Resolved wildcard dependencies in package.json for JSR compatibility');
669
398
  } catch (error) {
670
- DR.logger.error(`Failed to reset git changes: ${ErrorUtils.getErrorString(error)}`);
399
+ const errorString = ErrorUtils.getErrorString(error);
400
+ DR.logger.error(`Failed to resolve wildcard dependencies: ${errorString}`);
671
401
  throw error;
672
402
  }
673
403
  }
674
-
675
- /**
676
- * Publishes the current project to npm.
677
- *
678
- * @returns true if the publish was successful, false otherwise.
679
- */
680
- private static async publishNpm(): Promise<boolean> {
681
- DR.logger.info('Running `npm publish --access public`');
682
- return new Promise((resolve) => {
683
- const child = spawn('npm publish', ['--access', 'public'], {
684
- stdio: 'inherit',
685
- shell: true
686
- });
687
-
688
- child.on('exit', (code) => {
689
- if (code === 0) {
690
- resolve(true);
691
- } else {
692
- resolve(false);
693
- }
694
- });
695
- });
696
- }
697
404
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Service for handling NPM-specific package operations including validation and publishing.
3
+ */
4
+ export default class NpmPackageService {
5
+ /**
6
+ * Validates the current project for publishing to npm. This will run
7
+ * `npm publish --access public --dry-run` and check for version conflicts
8
+ * on the npm registry.
9
+ *
10
+ * @param alternativePackageNames Optional array of alternative package names to validate publishing under
11
+ *
12
+ * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
13
+ * if the package name appears in unexpected places. Use with caution.
14
+ */
15
+ static validatePublish(alternativePackageNames?: string[]): Promise<void>;
16
+ /**
17
+ * Publishes the current project to npm.
18
+ *
19
+ * @param alternativePackageNames Optional array of alternative package names to publish under
20
+ *
21
+ * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
22
+ * if the package name appears in unexpected places. Use with caution.
23
+ */
24
+ static publish(alternativePackageNames?: string[]): Promise<void>;
25
+ /**
26
+ * Executes a dry run of npm publishing.
27
+ *
28
+ * @returns true if the dry run was successful, false otherwise.
29
+ */
30
+ private static publishDryRun;
31
+ /**
32
+ * Checks npm registry for package information and performs version conflict checks.
33
+ *
34
+ * @param packageName The package name from package.json
35
+ * @param currentVersion The current version from package.json
36
+ */
37
+ private static checkVersionConflicts;
38
+ /**
39
+ * Publishes the current project to npm.
40
+ *
41
+ * @returns true if the publish was successful, false otherwise.
42
+ */
43
+ private static publishToNpm;
44
+ }
45
+ //# sourceMappingURL=NpmPackageService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NpmPackageService.d.ts","sourceRoot":"","sources":["../../../src/services/PackageService/NpmPackageService.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;;;;;;OASG;WACU,eAAe,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC/E;;;;;;;OAOG;WACU,OAAO,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCvE;;;;OAIG;mBACkB,aAAa;IAalC;;;;;OAKG;mBACkB,qBAAqB;IAkC1C;;;;OAIG;mBACkB,YAAY;CAiBlC"}