Skip to content

Commit

Permalink
support target
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Jul 20, 2021
1 parent 2d6d488 commit 5b47953
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Language="en-US" Id="<%- id %>" Version="<%- version %>" Publisher="<%- publisher %>"/>
<Identity Language="en-US" Id="<%- id %>" Version="<%- version %>" Publisher="<%- publisher %>" <% if (target) { %> TargetPlatform="<%- target %>" <% } %> />
<DisplayName><%- displayName %></DisplayName>
<Description xml:space="preserve"><%- description %></Description>
<Tags><%- tags %></Tags>
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = function (argv: string[]): void {
.command('package [<version>]')
.description('Packages an extension')
.option('-o, --out [path]', 'Output .vsix extension file to [path] location (defaults to <name>-<version>.vsix)')
.option('-t, --target <target>', 'Target architecture')
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
.option('--no-git-tag-version', 'Do not create a version commit and tag when calling `npm version`.')
.option(
Expand All @@ -100,6 +101,7 @@ module.exports = function (argv: string[]): void {
version,
{
out,
target,
message,
gitTagVersion,
githubBranch,
Expand All @@ -116,6 +118,7 @@ module.exports = function (argv: string[]): void {
packageCommand({
packagePath: out,
version,
target,
commitMessage: message,
gitTagVersion,
githubBranch,
Expand All @@ -138,6 +141,7 @@ module.exports = function (argv: string[]): void {
'Personal Access Token (defaults to VSCE_PAT environment variable)',
process.env['VSCE_PAT']
)
.option('-t, --target <target>', 'Target architecture')
.option('-m, --message <commit message>', 'Commit message used when calling `npm version`.')
.option('--no-git-tag-version', 'Do not create a version commit and tag when calling `npm version`.')
.option('--packagePath [path]', 'Publish the VSIX package located at the specified path.')
Expand All @@ -160,6 +164,7 @@ module.exports = function (argv: string[]): void {
version,
{
pat,
target,
message,
gitTagVersion,
packagePath,
Expand All @@ -176,6 +181,7 @@ module.exports = function (argv: string[]): void {
publish({
pat,
version,
target,
commitMessage: message,
gitTagVersion,
packagePath,
Expand Down
23 changes: 21 additions & 2 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface IAsset {
export interface IPackageOptions {
readonly packagePath?: string;
readonly version?: string;
readonly target?: string;
readonly commitMessage?: string;
readonly gitTagVersion?: boolean;
readonly cwd?: string;
Expand Down Expand Up @@ -279,8 +280,20 @@ export async function versionBump(
}
}

const Targets = new Set([
'win32-x64',
'win32-ia32',
'win32-arm64',
'linux-x64',
'linux-arm64',
'linux-armhf',
'darwin-x64',
'darwin-arm64',
'alpine-x64',
]);

export class ManifestProcessor extends BaseProcessor {
constructor(manifest: Manifest) {
constructor(manifest: Manifest, options: IPackageOptions = {}) {
super(manifest);

const flags = ['Public'];
Expand All @@ -304,13 +317,19 @@ export class ManifestProcessor extends BaseProcessor {
}

const extensionKind = getExtensionKind(manifest);
const target = options.target;

if (typeof target === 'string' && !Targets.has(target)) {
throw new Error(`'${target}' is not a valid VS Code target. Valid targets: ${[...Targets].join(', ')}`);
}

this.vsix = {
...this.vsix,
id: manifest.name,
displayName: manifest.displayName || manifest.name,
version: manifest.version,
publisher: manifest.publisher,
target,
engine: manifest.engines['vscode'],
description: manifest.description || '',
categories: (manifest.categories || []).join(','),
Expand Down Expand Up @@ -1194,7 +1213,7 @@ export function processFiles(processors: IProcessor[], files: IFile[]): Promise<

export function createDefaultProcessors(manifest: Manifest, options: IPackageOptions = {}): IProcessor[] {
return [
new ManifestProcessor(manifest),
new ManifestProcessor(manifest, options),
new TagsProcessor(manifest),
new ReadmeProcessor(manifest, options),
new ChangelogProcessor(manifest, options),
Expand Down
37 changes: 35 additions & 2 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type XMLManifest = {
Metadata: {
Description: { _: string }[];
DisplayName: string[];
Identity: { $: { Id: string; Version: string; Publisher: string } }[];
Identity: { $: { Id: string; Version: string; Publisher: string; TargetPlatform?: string } }[];
Tags: string[];
GalleryFlags: string[];
License: string[];
Expand Down Expand Up @@ -108,7 +108,7 @@ function assertMissingProperty(manifest: XMLManifest, name: string): void {
assert.equal(property.length, 0, `Property '${name}' should not exist`);
}

function createManifest(extra: Partial<Manifest>): Manifest {
function createManifest(extra: Partial<Manifest> = {}): Manifest {
return {
name: 'test',
publisher: 'mocha',
Expand Down Expand Up @@ -1547,6 +1547,39 @@ describe('toVsixManifest', () => {
const extensionKindProps = properties.filter(p => p.$.Id === 'Microsoft.VisualStudio.Code.ExtensionKind');
assert.equal(extensionKindProps[0].$.Value, 'workspace');
});

it('should not have target platform by default', async () => {
const manifest = createManifest();
const raw = await _toVsixManifest(manifest, []);
const dom = await parseXmlManifest(raw);

assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.Id, 'test');
assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.Version, '0.0.1');
assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.Publisher, 'mocha');
assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.TargetPlatform, undefined);
});

it('should set the right target platform by default', async () => {
const manifest = createManifest();
const raw = await _toVsixManifest(manifest, [], { target: 'win32-x64' });
const dom = await parseXmlManifest(raw);

assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.Id, 'test');
assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.Version, '0.0.1');
assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.Publisher, 'mocha');
assert.strictEqual(dom.PackageManifest.Metadata[0].Identity[0].$.TargetPlatform, 'win32-x64');
});

it('should throw when using an invalid target platform', async () => {
const manifest = createManifest();

try {
await _toVsixManifest(manifest, [], { target: 'linux-ia32' });
throw new Error('oops');
} catch (err) {
assert(/not a valid VS Code target/.test(err.message));
}
});
});

describe('qna', () => {
Expand Down

3 comments on commit 5b47953

@felipecrs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaomoreno I can't believe this is finally happening. I'll work to add support for this in the ShellCheck extension. Is this documented elsewhere?

@prashantvc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felipecrs it is too early to use this feature for extensions, I will keep you informed once we have something concreate to share.
I would love to get your early feedback :)

@joaomoreno
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The support is not yet pushed to production, but it's getting there.

Is this documented elsewhere?

Currently working on the docs 😉

Please # to comment.