@aneuhold/core-ts-lib 2.2.9 → 2.2.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.
- package/lib/index.d.ts +5 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/lib/index.ts +5 -2
- package/lib/services/ChangelogService/ChangelogFileService.d.ts +42 -0
- package/lib/services/ChangelogService/ChangelogFileService.d.ts.map +1 -0
- package/lib/services/ChangelogService/ChangelogFileService.js +65 -0
- package/lib/services/ChangelogService/ChangelogFileService.js.map +1 -0
- package/lib/services/ChangelogService/ChangelogFileService.ts +68 -0
- package/lib/services/ChangelogService/ChangelogGenerator.d.ts +58 -0
- package/lib/services/ChangelogService/ChangelogGenerator.d.ts.map +1 -0
- package/lib/services/ChangelogService/ChangelogGenerator.js +145 -0
- package/lib/services/ChangelogService/ChangelogGenerator.js.map +1 -0
- package/lib/services/ChangelogService/ChangelogGenerator.ts +188 -0
- package/lib/services/ChangelogService/ChangelogParser.d.ts +21 -0
- package/lib/services/ChangelogService/ChangelogParser.d.ts.map +1 -0
- package/lib/services/ChangelogService/ChangelogParser.js +59 -0
- package/lib/services/ChangelogService/ChangelogParser.js.map +1 -0
- package/lib/services/ChangelogService/ChangelogParser.ts +71 -0
- package/lib/services/ChangelogService/ChangelogService.d.ts +54 -0
- package/lib/services/ChangelogService/ChangelogService.d.ts.map +1 -0
- package/lib/services/ChangelogService/ChangelogService.js +201 -0
- package/lib/services/ChangelogService/ChangelogService.js.map +1 -0
- package/lib/services/ChangelogService/ChangelogService.ts +293 -0
- package/lib/services/ChangelogService/ChangelogValidator.d.ts +15 -0
- package/lib/services/ChangelogService/ChangelogValidator.d.ts.map +1 -0
- package/lib/services/ChangelogService/ChangelogValidator.js +44 -0
- package/lib/services/ChangelogService/ChangelogValidator.js.map +1 -0
- package/lib/services/ChangelogService/ChangelogValidator.ts +55 -0
- package/lib/services/ChangelogService/GitTagService.d.ts +29 -0
- package/lib/services/ChangelogService/GitTagService.d.ts.map +1 -0
- package/lib/services/ChangelogService/GitTagService.js +57 -0
- package/lib/services/ChangelogService/GitTagService.js.map +1 -0
- package/lib/services/ChangelogService/GitTagService.ts +60 -0
- package/lib/services/ChangelogService/RepositoryInfoService.d.ts +14 -0
- package/lib/services/ChangelogService/RepositoryInfoService.d.ts.map +1 -0
- package/lib/services/ChangelogService/RepositoryInfoService.js +55 -0
- package/lib/services/ChangelogService/RepositoryInfoService.js.map +1 -0
- package/lib/services/ChangelogService/RepositoryInfoService.ts +64 -0
- package/lib/services/ChangelogService/index.d.ts +2 -0
- package/lib/services/ChangelogService/index.d.ts.map +1 -0
- package/lib/services/ChangelogService/index.js +2 -0
- package/lib/services/ChangelogService/index.js.map +1 -0
- package/lib/services/ChangelogService/index.ts +1 -0
- package/lib/services/ChangelogService/types.d.ts +27 -0
- package/lib/services/ChangelogService/types.d.ts.map +1 -0
- package/lib/services/ChangelogService/types.js +3 -0
- package/lib/services/ChangelogService/types.js.map +1 -0
- package/lib/services/ChangelogService/types.ts +30 -0
- package/lib/services/DependencyService.d.ts +2 -9
- package/lib/services/DependencyService.d.ts.map +1 -1
- package/lib/services/DependencyService.js +2 -11
- package/lib/services/DependencyService.js.map +1 -1
- package/lib/services/DependencyService.ts +2 -11
- package/lib/services/PackageService/JsrPackageService.d.ts +81 -0
- package/lib/services/PackageService/JsrPackageService.d.ts.map +1 -0
- package/lib/services/{PackageService.js → PackageService/JsrPackageService.js} +70 -312
- package/lib/services/PackageService/JsrPackageService.js.map +1 -0
- package/lib/services/{PackageService.ts → PackageService/JsrPackageService.ts} +79 -372
- package/lib/services/PackageService/NpmPackageService.d.ts +45 -0
- package/lib/services/PackageService/NpmPackageService.d.ts.map +1 -0
- package/lib/services/PackageService/NpmPackageService.js +146 -0
- package/lib/services/PackageService/NpmPackageService.js.map +1 -0
- package/lib/services/PackageService/NpmPackageService.ts +178 -0
- package/lib/services/PackageService/PackageService.d.ts +77 -0
- package/lib/services/PackageService/PackageService.d.ts.map +1 -0
- package/lib/services/PackageService/PackageService.js +96 -0
- package/lib/services/PackageService/PackageService.js.map +1 -0
- package/lib/services/PackageService/PackageService.ts +108 -0
- package/lib/services/PackageService/PackageServiceUtils.d.ts +69 -0
- package/lib/services/PackageService/PackageServiceUtils.d.ts.map +1 -0
- package/lib/services/PackageService/PackageServiceUtils.js +185 -0
- package/lib/services/PackageService/PackageServiceUtils.js.map +1 -0
- package/lib/services/PackageService/PackageServiceUtils.ts +239 -0
- package/lib/services/StringService.d.ts +12 -0
- package/lib/services/StringService.d.ts.map +1 -1
- package/lib/services/StringService.js +56 -0
- package/lib/services/StringService.js.map +1 -1
- package/lib/services/StringService.ts +72 -0
- package/lib/types/VersionType.d.ts +9 -0
- package/lib/types/VersionType.d.ts.map +1 -0
- package/lib/types/VersionType.js +10 -0
- package/lib/types/VersionType.js.map +1 -0
- package/lib/types/VersionType.ts +8 -0
- package/package.json +6 -5
- package/lib/services/PackageService.d.ts +0 -159
- package/lib/services/PackageService.d.ts.map +0 -1
- package/lib/services/PackageService.js.map +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { exec, spawn } from 'child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import ErrorUtils from '../../utils/ErrorUtils.js';
|
|
4
|
+
import { DR } from '../DependencyRegistry.js';
|
|
5
|
+
import PackageServiceUtils from './PackageServiceUtils.js';
|
|
6
|
+
const execAsync = promisify(exec);
|
|
7
|
+
/**
|
|
8
|
+
* Service for handling NPM-specific package operations including validation and publishing.
|
|
9
|
+
*/
|
|
10
|
+
export default class NpmPackageService {
|
|
11
|
+
/**
|
|
12
|
+
* Validates the current project for publishing to npm. This will run
|
|
13
|
+
* `npm publish --access public --dry-run` and check for version conflicts
|
|
14
|
+
* on the npm registry.
|
|
15
|
+
*
|
|
16
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
17
|
+
*
|
|
18
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
19
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
20
|
+
*/
|
|
21
|
+
static async validatePublish(alternativePackageNames) {
|
|
22
|
+
const { packageName: originalPackageName, version: currentVersion } = await PackageServiceUtils.getPackageInfo();
|
|
23
|
+
await PackageServiceUtils.validatePrePublishRequirements(currentVersion);
|
|
24
|
+
const packageNamesToValidate = [originalPackageName, ...(alternativePackageNames || [])];
|
|
25
|
+
for (const packageName of packageNamesToValidate) {
|
|
26
|
+
const isAlternativeName = packageName !== originalPackageName;
|
|
27
|
+
DR.logger.info(`Validating npm publishing for package: ${packageName}`);
|
|
28
|
+
if (isAlternativeName) {
|
|
29
|
+
await PackageServiceUtils.replacePackageName(originalPackageName, packageName);
|
|
30
|
+
}
|
|
31
|
+
const successfulDryRun = await NpmPackageService.publishDryRun();
|
|
32
|
+
if (!successfulDryRun) {
|
|
33
|
+
if (isAlternativeName) {
|
|
34
|
+
await PackageServiceUtils.resetGitChanges();
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
await NpmPackageService.checkVersionConflicts(packageName, currentVersion);
|
|
39
|
+
if (isAlternativeName) {
|
|
40
|
+
await PackageServiceUtils.resetGitChanges();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
DR.logger.success('Successfully validated npm publishing for all package names.');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Publishes the current project to npm.
|
|
47
|
+
*
|
|
48
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
49
|
+
*
|
|
50
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
51
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
52
|
+
*/
|
|
53
|
+
static async publish(alternativePackageNames) {
|
|
54
|
+
const { packageName: originalPackageName } = await PackageServiceUtils.getPackageInfo();
|
|
55
|
+
await PackageServiceUtils.validatePrePublishRequirements((await PackageServiceUtils.getPackageInfo()).version);
|
|
56
|
+
const packageNamesToPublish = [originalPackageName, ...(alternativePackageNames || [])];
|
|
57
|
+
for (const packageName of packageNamesToPublish) {
|
|
58
|
+
const isAlternativeName = packageName !== originalPackageName;
|
|
59
|
+
DR.logger.info(`Publishing to npm for package: ${packageName}`);
|
|
60
|
+
if (isAlternativeName) {
|
|
61
|
+
await PackageServiceUtils.replacePackageName(originalPackageName, packageName);
|
|
62
|
+
}
|
|
63
|
+
const result = await NpmPackageService.publishToNpm();
|
|
64
|
+
if (isAlternativeName) {
|
|
65
|
+
await PackageServiceUtils.resetGitChanges();
|
|
66
|
+
}
|
|
67
|
+
if (!result) {
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
DR.logger.success('Successfully published to npm for all package names.');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Executes a dry run of npm publishing.
|
|
75
|
+
*
|
|
76
|
+
* @returns true if the dry run was successful, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
static async publishDryRun() {
|
|
79
|
+
DR.logger.info('Running `npm publish --access public --dry-run`');
|
|
80
|
+
try {
|
|
81
|
+
await execAsync('npm publish --access public --dry-run');
|
|
82
|
+
DR.logger.info('npm dry run completed successfully.');
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const errorString = ErrorUtils.getErrorString(error);
|
|
86
|
+
DR.logger.error(`npm dry run failed: ${errorString}`);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Checks npm registry for package information and performs version conflict checks.
|
|
93
|
+
*
|
|
94
|
+
* @param packageName The package name from package.json
|
|
95
|
+
* @param currentVersion The current version from package.json
|
|
96
|
+
*/
|
|
97
|
+
static async checkVersionConflicts(packageName, currentVersion) {
|
|
98
|
+
DR.logger.info(`Checking npm registry for existing versions of ${packageName}...`);
|
|
99
|
+
try {
|
|
100
|
+
const { stdout } = await execAsync(`npm view ${packageName}`);
|
|
101
|
+
// Parse the npm view output to extract the latest version
|
|
102
|
+
const latestVersionMatch = stdout.match(/latest:\s*([^\s|]+)/);
|
|
103
|
+
if (latestVersionMatch) {
|
|
104
|
+
const latestVersion = latestVersionMatch[1];
|
|
105
|
+
PackageServiceUtils.checkVersionConflict(currentVersion, latestVersion, 'npm');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
const errorString = ErrorUtils.getErrorString(error);
|
|
110
|
+
// If the package doesn't exist on npm, that's fine for first publish
|
|
111
|
+
if (errorString.includes('404') || errorString.includes('not found')) {
|
|
112
|
+
DR.logger.info('Package not found on npm - this appears to be a first publish.');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Re-throw version conflict errors
|
|
116
|
+
if (errorString.includes('already exists') || errorString.includes('is lower than')) {
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
// For other npm command errors, log but don't block
|
|
120
|
+
DR.logger.warn(`Could not check npm registry: ${errorString}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Publishes the current project to npm.
|
|
125
|
+
*
|
|
126
|
+
* @returns true if the publish was successful, false otherwise.
|
|
127
|
+
*/
|
|
128
|
+
static async publishToNpm() {
|
|
129
|
+
DR.logger.info('Running `npm publish --access public`');
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
const child = spawn('npm publish', ['--access', 'public'], {
|
|
132
|
+
stdio: 'inherit',
|
|
133
|
+
shell: true
|
|
134
|
+
});
|
|
135
|
+
child.on('exit', (code) => {
|
|
136
|
+
if (code === 0) {
|
|
137
|
+
resolve(true);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
resolve(false);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=NpmPackageService.js.map
|
|
@@ -0,0 +1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
|
+
import { DR } from '../DependencyRegistry.js';
|
|
5
|
+
import PackageServiceUtils from './PackageServiceUtils.js';
|
|
6
|
+
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Service for handling NPM-specific package operations including validation and publishing.
|
|
11
|
+
*/
|
|
12
|
+
export default class NpmPackageService {
|
|
13
|
+
/**
|
|
14
|
+
* Validates the current project for publishing to npm. This will run
|
|
15
|
+
* `npm publish --access public --dry-run` and check for version conflicts
|
|
16
|
+
* on the npm registry.
|
|
17
|
+
*
|
|
18
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
19
|
+
*
|
|
20
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
21
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
22
|
+
*/
|
|
23
|
+
static async validatePublish(alternativePackageNames?: string[]): Promise<void> {
|
|
24
|
+
const { packageName: originalPackageName, version: currentVersion } =
|
|
25
|
+
await PackageServiceUtils.getPackageInfo();
|
|
26
|
+
|
|
27
|
+
await PackageServiceUtils.validatePrePublishRequirements(currentVersion);
|
|
28
|
+
|
|
29
|
+
const packageNamesToValidate = [originalPackageName, ...(alternativePackageNames || [])];
|
|
30
|
+
|
|
31
|
+
for (const packageName of packageNamesToValidate) {
|
|
32
|
+
const isAlternativeName = packageName !== originalPackageName;
|
|
33
|
+
|
|
34
|
+
DR.logger.info(`Validating npm publishing for package: ${packageName}`);
|
|
35
|
+
|
|
36
|
+
if (isAlternativeName) {
|
|
37
|
+
await PackageServiceUtils.replacePackageName(originalPackageName, packageName);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const successfulDryRun = await NpmPackageService.publishDryRun();
|
|
41
|
+
if (!successfulDryRun) {
|
|
42
|
+
if (isAlternativeName) {
|
|
43
|
+
await PackageServiceUtils.resetGitChanges();
|
|
44
|
+
}
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await NpmPackageService.checkVersionConflicts(packageName, currentVersion);
|
|
49
|
+
|
|
50
|
+
if (isAlternativeName) {
|
|
51
|
+
await PackageServiceUtils.resetGitChanges();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
DR.logger.success('Successfully validated npm publishing for all package names.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Publishes the current project to npm.
|
|
60
|
+
*
|
|
61
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
62
|
+
*
|
|
63
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
64
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
65
|
+
*/
|
|
66
|
+
static async publish(alternativePackageNames?: string[]): Promise<void> {
|
|
67
|
+
const { packageName: originalPackageName } = await PackageServiceUtils.getPackageInfo();
|
|
68
|
+
|
|
69
|
+
await PackageServiceUtils.validatePrePublishRequirements(
|
|
70
|
+
(await PackageServiceUtils.getPackageInfo()).version
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const packageNamesToPublish = [originalPackageName, ...(alternativePackageNames || [])];
|
|
74
|
+
|
|
75
|
+
for (const packageName of packageNamesToPublish) {
|
|
76
|
+
const isAlternativeName = packageName !== originalPackageName;
|
|
77
|
+
|
|
78
|
+
DR.logger.info(`Publishing to npm for package: ${packageName}`);
|
|
79
|
+
|
|
80
|
+
if (isAlternativeName) {
|
|
81
|
+
await PackageServiceUtils.replacePackageName(originalPackageName, packageName);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const result = await NpmPackageService.publishToNpm();
|
|
85
|
+
|
|
86
|
+
if (isAlternativeName) {
|
|
87
|
+
await PackageServiceUtils.resetGitChanges();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!result) {
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
DR.logger.success('Successfully published to npm for all package names.');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Executes a dry run of npm publishing.
|
|
100
|
+
*
|
|
101
|
+
* @returns true if the dry run was successful, false otherwise.
|
|
102
|
+
*/
|
|
103
|
+
private static async publishDryRun(): Promise<boolean> {
|
|
104
|
+
DR.logger.info('Running `npm publish --access public --dry-run`');
|
|
105
|
+
try {
|
|
106
|
+
await execAsync('npm publish --access public --dry-run');
|
|
107
|
+
DR.logger.info('npm dry run completed successfully.');
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const errorString = ErrorUtils.getErrorString(error);
|
|
110
|
+
DR.logger.error(`npm dry run failed: ${errorString}`);
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Checks npm registry for package information and performs version conflict checks.
|
|
118
|
+
*
|
|
119
|
+
* @param packageName The package name from package.json
|
|
120
|
+
* @param currentVersion The current version from package.json
|
|
121
|
+
*/
|
|
122
|
+
private static async checkVersionConflicts(
|
|
123
|
+
packageName: string,
|
|
124
|
+
currentVersion: string
|
|
125
|
+
): Promise<void> {
|
|
126
|
+
DR.logger.info(`Checking npm registry for existing versions of ${packageName}...`);
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const { stdout } = await execAsync(`npm view ${packageName}`);
|
|
130
|
+
|
|
131
|
+
// Parse the npm view output to extract the latest version
|
|
132
|
+
const latestVersionMatch = stdout.match(/latest:\s*([^\s|]+)/);
|
|
133
|
+
if (latestVersionMatch) {
|
|
134
|
+
const latestVersion = latestVersionMatch[1];
|
|
135
|
+
PackageServiceUtils.checkVersionConflict(currentVersion, latestVersion, 'npm');
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const errorString = ErrorUtils.getErrorString(error);
|
|
139
|
+
|
|
140
|
+
// If the package doesn't exist on npm, that's fine for first publish
|
|
141
|
+
if (errorString.includes('404') || errorString.includes('not found')) {
|
|
142
|
+
DR.logger.info('Package not found on npm - this appears to be a first publish.');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Re-throw version conflict errors
|
|
147
|
+
if (errorString.includes('already exists') || errorString.includes('is lower than')) {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// For other npm command errors, log but don't block
|
|
152
|
+
DR.logger.warn(`Could not check npm registry: ${errorString}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Publishes the current project to npm.
|
|
158
|
+
*
|
|
159
|
+
* @returns true if the publish was successful, false otherwise.
|
|
160
|
+
*/
|
|
161
|
+
private static async publishToNpm(): Promise<boolean> {
|
|
162
|
+
DR.logger.info('Running `npm publish --access public`');
|
|
163
|
+
return new Promise((resolve) => {
|
|
164
|
+
const child = spawn('npm publish', ['--access', 'public'], {
|
|
165
|
+
stdio: 'inherit',
|
|
166
|
+
shell: true
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
child.on('exit', (code) => {
|
|
170
|
+
if (code === 0) {
|
|
171
|
+
resolve(true);
|
|
172
|
+
} else {
|
|
173
|
+
resolve(false);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { VersionType } from '../../types/VersionType.js';
|
|
2
|
+
/**
|
|
3
|
+
* A service which can be used to assist in publishing or validating packages
|
|
4
|
+
* for the current project. This service provides convenient aliases to the
|
|
5
|
+
* specialized JSR and NPM package services.
|
|
6
|
+
*/
|
|
7
|
+
export default class PackageService {
|
|
8
|
+
/**
|
|
9
|
+
* Validates the current project for publishing to JSR. This will check if the
|
|
10
|
+
* project has any pending changes first, then update the version of the
|
|
11
|
+
* jsr.json to match the package.json file, then run the
|
|
12
|
+
* `jsr publish --dry-run` command, and finally cleanup the changes made.
|
|
13
|
+
*
|
|
14
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
15
|
+
*
|
|
16
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
17
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
18
|
+
*/
|
|
19
|
+
static validateJsrPublish(alternativePackageNames?: string[]): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Publishes the current project to JSR.
|
|
22
|
+
*
|
|
23
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
24
|
+
*
|
|
25
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
26
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
27
|
+
*/
|
|
28
|
+
static publishToJsr(alternativePackageNames?: string[]): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Validates the current project for publishing to npm. This will run
|
|
31
|
+
* `npm publish --access public --dry-run` and check for version conflicts
|
|
32
|
+
* on the npm registry.
|
|
33
|
+
*
|
|
34
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
35
|
+
*
|
|
36
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
37
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
38
|
+
*/
|
|
39
|
+
static validateNpmPublish(alternativePackageNames?: string[]): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Publishes the current project to npm.
|
|
42
|
+
*
|
|
43
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
44
|
+
*
|
|
45
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
46
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
47
|
+
*/
|
|
48
|
+
static publishToNpm(alternativePackageNames?: string[]): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Test method for string replacement functionality. This method allows testing
|
|
51
|
+
* the string replacement behavior without performing actual publishing operations.
|
|
52
|
+
*
|
|
53
|
+
* @param originalString The original string to replace
|
|
54
|
+
* @param newString The new string to replace it with
|
|
55
|
+
*
|
|
56
|
+
* **Warning:** This method uses simple string replacement, which may have unintended effects
|
|
57
|
+
* if the string appears in unexpected places. Use with caution.
|
|
58
|
+
*/
|
|
59
|
+
static testStringReplacement(originalString: string, newString: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Initializes a changelog for the current project if one doesn't exist.
|
|
62
|
+
* This operation is idempotent - it won't modify existing content.
|
|
63
|
+
*
|
|
64
|
+
* @param packagePath Optional path to the package directory (defaults to current working directory)
|
|
65
|
+
*/
|
|
66
|
+
static initializeChangelog(packagePath?: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Bumps the version if needed based on npm registry comparison and initializes changelog.
|
|
69
|
+
* This operation is idempotent - it will only bump if the current version conflicts with
|
|
70
|
+
* the registry, and changelog initialization won't modify existing content.
|
|
71
|
+
*
|
|
72
|
+
* @param versionType The type of version bump (patch, minor, major). Defaults to patch.
|
|
73
|
+
* @param packagePath Optional path to the package directory (defaults to current working directory)
|
|
74
|
+
*/
|
|
75
|
+
static bumpVersionIfNeededAndInitializeChangelog(versionType?: VersionType, packagePath?: string): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=PackageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageService.d.ts","sourceRoot":"","sources":["../../../src/services/PackageService/PackageService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAMzD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC;;;;;;;;;;OAUG;WACU,kBAAkB,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlF;;;;;;;OAOG;WACU,YAAY,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E;;;;;;;;;OASG;WACU,kBAAkB,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlF;;;;;;;OAOG;WACU,YAAY,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E;;;;;;;;;OASG;WACU,qBAAqB,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5F;;;;;OAKG;WACU,mBAAmB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE;;;;;;;OAOG;WACU,yCAAyC,CACpD,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;CAGjB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DR } from '../DependencyRegistry.js';
|
|
2
|
+
import JsrPackageService from './JsrPackageService.js';
|
|
3
|
+
import NpmPackageService from './NpmPackageService.js';
|
|
4
|
+
import PackageServiceUtils from './PackageServiceUtils.js';
|
|
5
|
+
/**
|
|
6
|
+
* A service which can be used to assist in publishing or validating packages
|
|
7
|
+
* for the current project. This service provides convenient aliases to the
|
|
8
|
+
* specialized JSR and NPM package services.
|
|
9
|
+
*/
|
|
10
|
+
export default class PackageService {
|
|
11
|
+
/**
|
|
12
|
+
* Validates the current project for publishing to JSR. This will check if the
|
|
13
|
+
* project has any pending changes first, then update the version of the
|
|
14
|
+
* jsr.json to match the package.json file, then run the
|
|
15
|
+
* `jsr publish --dry-run` command, and finally cleanup the changes made.
|
|
16
|
+
*
|
|
17
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
18
|
+
*
|
|
19
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
20
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
21
|
+
*/
|
|
22
|
+
static async validateJsrPublish(alternativePackageNames) {
|
|
23
|
+
return JsrPackageService.validatePublish(alternativePackageNames);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Publishes the current project to JSR.
|
|
27
|
+
*
|
|
28
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
29
|
+
*
|
|
30
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
31
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
32
|
+
*/
|
|
33
|
+
static async publishToJsr(alternativePackageNames) {
|
|
34
|
+
return JsrPackageService.publish(alternativePackageNames);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validates the current project for publishing to npm. This will run
|
|
38
|
+
* `npm publish --access public --dry-run` and check for version conflicts
|
|
39
|
+
* on the npm registry.
|
|
40
|
+
*
|
|
41
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
42
|
+
*
|
|
43
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
44
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
45
|
+
*/
|
|
46
|
+
static async validateNpmPublish(alternativePackageNames) {
|
|
47
|
+
return NpmPackageService.validatePublish(alternativePackageNames);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Publishes the current project to npm.
|
|
51
|
+
*
|
|
52
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
53
|
+
*
|
|
54
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
55
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
56
|
+
*/
|
|
57
|
+
static async publishToNpm(alternativePackageNames) {
|
|
58
|
+
return NpmPackageService.publish(alternativePackageNames);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Test method for string replacement functionality. This method allows testing
|
|
62
|
+
* the string replacement behavior without performing actual publishing operations.
|
|
63
|
+
*
|
|
64
|
+
* @param originalString The original string to replace
|
|
65
|
+
* @param newString The new string to replace it with
|
|
66
|
+
*
|
|
67
|
+
* **Warning:** This method uses simple string replacement, which may have unintended effects
|
|
68
|
+
* if the string appears in unexpected places. Use with caution.
|
|
69
|
+
*/
|
|
70
|
+
static async testStringReplacement(originalString, newString) {
|
|
71
|
+
DR.logger.info(`Testing string replacement from "${originalString}" to "${newString}"`);
|
|
72
|
+
await PackageServiceUtils.replacePackageName(originalString, newString);
|
|
73
|
+
DR.logger.info('Test completed - package name replacement has been applied');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Initializes a changelog for the current project if one doesn't exist.
|
|
77
|
+
* This operation is idempotent - it won't modify existing content.
|
|
78
|
+
*
|
|
79
|
+
* @param packagePath Optional path to the package directory (defaults to current working directory)
|
|
80
|
+
*/
|
|
81
|
+
static async initializeChangelog(packagePath) {
|
|
82
|
+
return PackageServiceUtils.initializeChangelog(packagePath);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Bumps the version if needed based on npm registry comparison and initializes changelog.
|
|
86
|
+
* This operation is idempotent - it will only bump if the current version conflicts with
|
|
87
|
+
* the registry, and changelog initialization won't modify existing content.
|
|
88
|
+
*
|
|
89
|
+
* @param versionType The type of version bump (patch, minor, major). Defaults to patch.
|
|
90
|
+
* @param packagePath Optional path to the package directory (defaults to current working directory)
|
|
91
|
+
*/
|
|
92
|
+
static async bumpVersionIfNeededAndInitializeChangelog(versionType, packagePath) {
|
|
93
|
+
return PackageServiceUtils.bumpVersionIfNeededAndInitializeChangelog(versionType, packagePath);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=PackageService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageService.js","sourceRoot":"","sources":["../../../src/services/PackageService/PackageService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,mBAAmB,MAAM,0BAA0B,CAA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;IACjG,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { VersionType } from '../../types/VersionType.js';
|
|
2
|
+
import { DR } from '../DependencyRegistry.js';
|
|
3
|
+
import JsrPackageService from './JsrPackageService.js';
|
|
4
|
+
import NpmPackageService from './NpmPackageService.js';
|
|
5
|
+
import PackageServiceUtils from './PackageServiceUtils.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A service which can be used to assist in publishing or validating packages
|
|
9
|
+
* for the current project. This service provides convenient aliases to the
|
|
10
|
+
* specialized JSR and NPM package services.
|
|
11
|
+
*/
|
|
12
|
+
export default class PackageService {
|
|
13
|
+
/**
|
|
14
|
+
* Validates the current project for publishing to JSR. This will check if the
|
|
15
|
+
* project has any pending changes first, then update the version of the
|
|
16
|
+
* jsr.json to match the package.json file, then run the
|
|
17
|
+
* `jsr publish --dry-run` command, and finally cleanup the changes made.
|
|
18
|
+
*
|
|
19
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing 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 async validateJsrPublish(alternativePackageNames?: string[]): Promise<void> {
|
|
25
|
+
return JsrPackageService.validatePublish(alternativePackageNames);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Publishes the current project to JSR.
|
|
30
|
+
*
|
|
31
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
32
|
+
*
|
|
33
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
34
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
35
|
+
*/
|
|
36
|
+
static async publishToJsr(alternativePackageNames?: string[]): Promise<void> {
|
|
37
|
+
return JsrPackageService.publish(alternativePackageNames);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Validates the current project for publishing to npm. This will run
|
|
42
|
+
* `npm publish --access public --dry-run` and check for version conflicts
|
|
43
|
+
* on the npm registry.
|
|
44
|
+
*
|
|
45
|
+
* @param alternativePackageNames Optional array of alternative package names to validate publishing under
|
|
46
|
+
*
|
|
47
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
48
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
49
|
+
*/
|
|
50
|
+
static async validateNpmPublish(alternativePackageNames?: string[]): Promise<void> {
|
|
51
|
+
return NpmPackageService.validatePublish(alternativePackageNames);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Publishes the current project to npm.
|
|
56
|
+
*
|
|
57
|
+
* @param alternativePackageNames Optional array of alternative package names to publish under
|
|
58
|
+
*
|
|
59
|
+
* **Warning:** This method uses simple string replacement for package names, which may have unintended effects
|
|
60
|
+
* if the package name appears in unexpected places. Use with caution.
|
|
61
|
+
*/
|
|
62
|
+
static async publishToNpm(alternativePackageNames?: string[]): Promise<void> {
|
|
63
|
+
return NpmPackageService.publish(alternativePackageNames);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Test method for string replacement functionality. This method allows testing
|
|
68
|
+
* the string replacement behavior without performing actual publishing operations.
|
|
69
|
+
*
|
|
70
|
+
* @param originalString The original string to replace
|
|
71
|
+
* @param newString The new string to replace it with
|
|
72
|
+
*
|
|
73
|
+
* **Warning:** This method uses simple string replacement, which may have unintended effects
|
|
74
|
+
* if the string appears in unexpected places. Use with caution.
|
|
75
|
+
*/
|
|
76
|
+
static async testStringReplacement(originalString: string, newString: string): Promise<void> {
|
|
77
|
+
DR.logger.info(`Testing string replacement from "${originalString}" to "${newString}"`);
|
|
78
|
+
|
|
79
|
+
await PackageServiceUtils.replacePackageName(originalString, newString);
|
|
80
|
+
|
|
81
|
+
DR.logger.info('Test completed - package name replacement has been applied');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Initializes a changelog for the current project if one doesn't exist.
|
|
86
|
+
* This operation is idempotent - it won't modify existing content.
|
|
87
|
+
*
|
|
88
|
+
* @param packagePath Optional path to the package directory (defaults to current working directory)
|
|
89
|
+
*/
|
|
90
|
+
static async initializeChangelog(packagePath?: string): Promise<void> {
|
|
91
|
+
return PackageServiceUtils.initializeChangelog(packagePath);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Bumps the version if needed based on npm registry comparison and initializes changelog.
|
|
96
|
+
* This operation is idempotent - it will only bump if the current version conflicts with
|
|
97
|
+
* the registry, and changelog initialization won't modify existing content.
|
|
98
|
+
*
|
|
99
|
+
* @param versionType The type of version bump (patch, minor, major). Defaults to patch.
|
|
100
|
+
* @param packagePath Optional path to the package directory (defaults to current working directory)
|
|
101
|
+
*/
|
|
102
|
+
static async bumpVersionIfNeededAndInitializeChangelog(
|
|
103
|
+
versionType?: VersionType,
|
|
104
|
+
packagePath?: string
|
|
105
|
+
): Promise<void> {
|
|
106
|
+
return PackageServiceUtils.bumpVersionIfNeededAndInitializeChangelog(versionType, packagePath);
|
|
107
|
+
}
|
|
108
|
+
}
|