Skip to content

Commit e0857ea

Browse files
authored
feat: add support for packaging and publishing without license file (#887)
1 parent 986df2b commit e0857ea

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

Diff for: src/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ module.exports = function (argv: string[]): void {
113113
.option('--pre-release', 'Mark this package as a pre-release')
114114
.option('--allow-star-activation', 'Allow using * in activation events')
115115
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
116+
.option('--skip-license', 'Allow packaging without license file')
116117
.action(
117118
(
118119
version,
@@ -135,6 +136,7 @@ module.exports = function (argv: string[]): void {
135136
preRelease,
136137
allowStarActivation,
137138
allowMissingRepository,
139+
skipLicense,
138140
}
139141
) =>
140142
main(
@@ -158,6 +160,7 @@ module.exports = function (argv: string[]): void {
158160
preRelease,
159161
allowStarActivation,
160162
allowMissingRepository,
163+
skipLicense,
161164
})
162165
)
163166
);
@@ -199,6 +202,7 @@ module.exports = function (argv: string[]): void {
199202
.option('--allow-star-activation', 'Allow using * in activation events')
200203
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
201204
.option('--skip-duplicate', 'Fail silently if version already exists on the marketplace')
205+
.option('--skip-license', 'Allow publishing without license file')
202206
.action(
203207
(
204208
version,
@@ -221,6 +225,7 @@ module.exports = function (argv: string[]): void {
221225
allowStarActivation,
222226
allowMissingRepository,
223227
skipDuplicate,
228+
skipLicense,
224229
}
225230
) =>
226231
main(
@@ -244,6 +249,7 @@ module.exports = function (argv: string[]): void {
244249
allowStarActivation,
245250
allowMissingRepository,
246251
skipDuplicate,
252+
skipLicense,
247253
})
248254
)
249255
);

Diff for: src/package.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export interface IPackageOptions {
136136
readonly preRelease?: boolean;
137137
readonly allowStarActivation?: boolean;
138138
readonly allowMissingRepository?: boolean;
139+
readonly skipLicense?: boolean;
139140
}
140141

141142
export interface IProcessor {
@@ -919,12 +920,12 @@ export class ChangelogProcessor extends MarkdownProcessor {
919920
}
920921
}
921922

922-
class LicenseProcessor extends BaseProcessor {
923+
export class LicenseProcessor extends BaseProcessor {
923924
private didFindLicense = false;
924925
private expectedLicenseName: string;
925926
filter: (name: string) => boolean;
926927

927-
constructor(manifest: Manifest) {
928+
constructor(manifest: Manifest, private readonly options: IPackageOptions = {}) {
928929
super(manifest);
929930

930931
const match = /^SEE LICENSE IN (.*)$/.exec(manifest.license || '');
@@ -961,7 +962,7 @@ class LicenseProcessor extends BaseProcessor {
961962
}
962963

963964
async onEnd(): Promise<void> {
964-
if (!this.didFindLicense) {
965+
if (!this.didFindLicense && !this.options.skipLicense) {
965966
util.log.warn(`${this.expectedLicenseName} not found`);
966967

967968
if (!/^y$/i.test(await util.read('Do you want to continue? [y/N] '))) {
@@ -1628,7 +1629,7 @@ export function createDefaultProcessors(manifest: Manifest, options: IPackageOpt
16281629
new ReadmeProcessor(manifest, options),
16291630
new ChangelogProcessor(manifest, options),
16301631
new LaunchEntryPointProcessor(manifest),
1631-
new LicenseProcessor(manifest),
1632+
new LicenseProcessor(manifest, options),
16321633
new IconProcessor(manifest),
16331634
new NLSProcessor(manifest),
16341635
new ValidationProcessor(manifest),

Diff for: src/publish.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface IPublishOptions {
6262
readonly allowStarActivation?: boolean;
6363
readonly allowMissingRepository?: boolean;
6464
readonly skipDuplicate?: boolean;
65+
readonly skipLicense?: boolean;
6566
}
6667

6768
export async function publish(options: IPublishOptions = {}): Promise<any> {

Diff for: src/test/package.test.ts

+39-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ManifestProcessor,
1414
versionBump,
1515
VSIX,
16+
LicenseProcessor,
1617
} from '../package';
1718
import { Manifest } from '../manifest';
1819
import * as path from 'path';
@@ -21,7 +22,7 @@ import * as assert from 'assert';
2122
import * as tmp from 'tmp';
2223
import { spawnSync } from 'child_process';
2324
import { XMLManifest, parseXmlManifest, parseContentTypes } from '../xml';
24-
import { flatten } from '../util';
25+
import { flatten, log } from '../util';
2526
import { validatePublisher } from '../validation';
2627
import * as jsonc from 'jsonc-parser';
2728

@@ -2817,6 +2818,43 @@ describe('MarkdownProcessor', () => {
28172818
});
28182819
});
28192820

2821+
describe('LicenseProcessor', () => {
2822+
it('should fail if license file not specified', async () => {
2823+
const originalUtilWarn = log.warn;
2824+
const logs: string[] = [];
2825+
2826+
log.warn = (message) => {
2827+
logs.push(message);
2828+
};
2829+
2830+
const message = 'LICENSE, LICENSE.md, or LICENSE.txt not found';
2831+
2832+
const processor = new LicenseProcessor(createManifest(), {});
2833+
await processor.onEnd();
2834+
2835+
log.warn = originalUtilWarn;
2836+
2837+
assert.strictEqual(logs.length, 1);
2838+
assert.strictEqual(logs[0], message);
2839+
});
2840+
2841+
it('should pass if no license specified and --skip-license flag is passed', async () => {
2842+
const originalUtilWarn = log.warn;
2843+
const logs: string[] = [];
2844+
2845+
log.warn = (message) => {
2846+
logs.push(message);
2847+
};
2848+
2849+
const processor = new LicenseProcessor(createManifest(), { skipLicense: true });
2850+
await processor.onEnd();
2851+
2852+
log.warn = originalUtilWarn;
2853+
2854+
assert.strictEqual(logs.length, 0);
2855+
});
2856+
});
2857+
28202858
describe('version', function () {
28212859
this.timeout(5000);
28222860

0 commit comments

Comments
 (0)