Skip to content

Commit 2589114

Browse files
feat: allow to skip publishing duplicate package (#776)
* feat: allow to skip publishing duplicate package * Update src/main.ts * Update src/publish.ts * Update src/publish.ts * Update src/publish.ts Co-authored-by: João Moreno <[email protected]>
1 parent 8e193c9 commit 2589114

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main.ts

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ module.exports = function (argv: string[]): void {
197197
.option('--pre-release', 'Mark this package as a pre-release')
198198
.option('--allow-star-activation', 'Allow using * in activation events')
199199
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
200+
.option('--skip-duplicate', 'Fail silently if version already exists on the marketplace')
200201
.action(
201202
(
202203
version,
@@ -218,6 +219,7 @@ module.exports = function (argv: string[]): void {
218219
preRelease,
219220
allowStarActivation,
220221
allowMissingRepository,
222+
skipDuplicate,
221223
}
222224
) =>
223225
main(
@@ -240,6 +242,7 @@ module.exports = function (argv: string[]): void {
240242
preRelease,
241243
allowStarActivation,
242244
allowMissingRepository,
245+
skipDuplicate,
243246
})
244247
)
245248
);

src/publish.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export interface IPublishOptions {
5757
readonly preRelease?: boolean;
5858
readonly allowStarActivation?: boolean;
5959
readonly allowMissingRepository?: boolean;
60+
readonly skipDuplicate?: boolean;
6061
}
6162

6263
export async function publish(options: IPublishOptions = {}): Promise<any> {
@@ -123,6 +124,7 @@ export interface IInternalPublishOptions {
123124
readonly target?: string;
124125
readonly pat?: string;
125126
readonly noVerify?: boolean;
127+
readonly skipDuplicate?: boolean;
126128
}
127129

128130
async function _publish(packagePath: string, manifest: Manifest, options: IInternalPublishOptions) {
@@ -170,6 +172,10 @@ async function _publish(packagePath: string, manifest: Manifest, options: IInter
170172
const sameVersion = extension.versions.filter(v => v.version === manifest.version);
171173

172174
if (sameVersion.length > 0) {
175+
if (options.skipDuplicate) {
176+
log.done(`Version ${manifest.version} is already published. Skipping publish.`);
177+
return;
178+
}
173179
if (!options.target) {
174180
throw new Error(`${description} already exists.`);
175181
}
@@ -187,7 +193,12 @@ async function _publish(packagePath: string, manifest: Manifest, options: IInter
187193
await api.updateExtension(undefined, packageStream, manifest.publisher, manifest.name);
188194
} catch (err: any) {
189195
if (err.statusCode === 409) {
190-
throw new Error(`${description} already exists.`);
196+
if (options.skipDuplicate) {
197+
log.done(`Version ${manifest.version} is already published. Skipping publish.`);
198+
return;
199+
} else {
200+
throw new Error(`${description} already exists.`);
201+
}
191202
} else {
192203
throw err;
193204
}

0 commit comments

Comments
 (0)