Skip to content

Commit

Permalink
feat: add support for packaging and publishing without license file (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bandantonio authored Aug 30, 2023
1 parent 986df2b commit e0857ea
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = function (argv: string[]): void {
.option('--pre-release', 'Mark this package as a pre-release')
.option('--allow-star-activation', 'Allow using * in activation events')
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
.option('--skip-license', 'Allow packaging without license file')
.action(
(
version,
Expand All @@ -135,6 +136,7 @@ module.exports = function (argv: string[]): void {
preRelease,
allowStarActivation,
allowMissingRepository,
skipLicense,
}
) =>
main(
Expand All @@ -158,6 +160,7 @@ module.exports = function (argv: string[]): void {
preRelease,
allowStarActivation,
allowMissingRepository,
skipLicense,
})
)
);
Expand Down Expand Up @@ -199,6 +202,7 @@ module.exports = function (argv: string[]): void {
.option('--allow-star-activation', 'Allow using * in activation events')
.option('--allow-missing-repository', 'Allow missing a repository URL in package.json')
.option('--skip-duplicate', 'Fail silently if version already exists on the marketplace')
.option('--skip-license', 'Allow publishing without license file')
.action(
(
version,
Expand All @@ -221,6 +225,7 @@ module.exports = function (argv: string[]): void {
allowStarActivation,
allowMissingRepository,
skipDuplicate,
skipLicense,
}
) =>
main(
Expand All @@ -244,6 +249,7 @@ module.exports = function (argv: string[]): void {
allowStarActivation,
allowMissingRepository,
skipDuplicate,
skipLicense,
})
)
);
Expand Down
9 changes: 5 additions & 4 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface IPackageOptions {
readonly preRelease?: boolean;
readonly allowStarActivation?: boolean;
readonly allowMissingRepository?: boolean;
readonly skipLicense?: boolean;
}

export interface IProcessor {
Expand Down Expand Up @@ -919,12 +920,12 @@ export class ChangelogProcessor extends MarkdownProcessor {
}
}

class LicenseProcessor extends BaseProcessor {
export class LicenseProcessor extends BaseProcessor {
private didFindLicense = false;
private expectedLicenseName: string;
filter: (name: string) => boolean;

constructor(manifest: Manifest) {
constructor(manifest: Manifest, private readonly options: IPackageOptions = {}) {
super(manifest);

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

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

if (!/^y$/i.test(await util.read('Do you want to continue? [y/N] '))) {
Expand Down Expand Up @@ -1628,7 +1629,7 @@ export function createDefaultProcessors(manifest: Manifest, options: IPackageOpt
new ReadmeProcessor(manifest, options),
new ChangelogProcessor(manifest, options),
new LaunchEntryPointProcessor(manifest),
new LicenseProcessor(manifest),
new LicenseProcessor(manifest, options),
new IconProcessor(manifest),
new NLSProcessor(manifest),
new ValidationProcessor(manifest),
Expand Down
1 change: 1 addition & 0 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface IPublishOptions {
readonly allowStarActivation?: boolean;
readonly allowMissingRepository?: boolean;
readonly skipDuplicate?: boolean;
readonly skipLicense?: boolean;
}

export async function publish(options: IPublishOptions = {}): Promise<any> {
Expand Down
40 changes: 39 additions & 1 deletion src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ManifestProcessor,
versionBump,
VSIX,
LicenseProcessor,
} from '../package';
import { Manifest } from '../manifest';
import * as path from 'path';
Expand All @@ -21,7 +22,7 @@ import * as assert from 'assert';
import * as tmp from 'tmp';
import { spawnSync } from 'child_process';
import { XMLManifest, parseXmlManifest, parseContentTypes } from '../xml';
import { flatten } from '../util';
import { flatten, log } from '../util';
import { validatePublisher } from '../validation';
import * as jsonc from 'jsonc-parser';

Expand Down Expand Up @@ -2817,6 +2818,43 @@ describe('MarkdownProcessor', () => {
});
});

describe('LicenseProcessor', () => {
it('should fail if license file not specified', async () => {
const originalUtilWarn = log.warn;
const logs: string[] = [];

log.warn = (message) => {
logs.push(message);
};

const message = 'LICENSE, LICENSE.md, or LICENSE.txt not found';

const processor = new LicenseProcessor(createManifest(), {});
await processor.onEnd();

log.warn = originalUtilWarn;

assert.strictEqual(logs.length, 1);
assert.strictEqual(logs[0], message);
});

it('should pass if no license specified and --skip-license flag is passed', async () => {
const originalUtilWarn = log.warn;
const logs: string[] = [];

log.warn = (message) => {
logs.push(message);
};

const processor = new LicenseProcessor(createManifest(), { skipLicense: true });
await processor.onEnd();

log.warn = originalUtilWarn;

assert.strictEqual(logs.length, 0);
});
});

describe('version', function () {
this.timeout(5000);

Expand Down

0 comments on commit e0857ea

Please sign in to comment.