Skip to content

Commit

Permalink
refactor!: drop yarn option (#233)
Browse files Browse the repository at this point in the history
As `vsce` now supports configuration through the `package.json` file
(see microsoft/vscode-vsce#548), this option
was dropped to simplify the codebase. One should either rely on the
`vsce` automatically detecting when to use `yarn` (see
microsoft/vscode-vsce#480), or add the
following to `package.json`:

```json
{
    "vsce": {
        "yarn": true
    }
}
```
  • Loading branch information
felipecrs committed Jan 18, 2022
1 parent 8fece4f commit df92b55
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 96 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ Use `semantic-release-vsce` as part of `verifyConditions` and `publish`.
If `packageVsix` is set, will also generate a .vsix file at the set file path after publishing. If is a string, it will be used as value for `--out` of `vsce package`.
It is recommended to upload this to your GitHub release page so your users can easily rollback to an earlier version if a version ever introduces a bad bug.

If `yarn` is set to `true`, will use `--yarn`option for `vsce package` and `vsce publish`.

#### Publishing to OpenVSX

Publishing extensions to OpenVSX using this plugin is easy:
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function prepare (pluginConfig, { nextRelease: { version }, logger }) {
await verifyVsce(logger);
verified = true;
}
packagePath = await vscePrepare(version, pluginConfig.packageVsix, pluginConfig.yarn, logger);
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger);
prepared = true;
}

Expand All @@ -28,9 +28,9 @@ async function publish (pluginConfig, { nextRelease: { version }, logger }) {

if (!prepared) {
// BC: prior to semantic-release v15 prepare was part of publish
packagePath = await vscePrepare(version, pluginConfig.packageVsix, pluginConfig.yarn, logger);
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger);
}
return vscePublish(version, packagePath, pluginConfig.yarn, logger);
return vscePublish(version, packagePath, logger);
}

module.exports = {
Expand Down
6 changes: 1 addition & 5 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const execa = require('execa');
const { readJson } = require('fs-extra');
const { isOvsxEnabled } = require('./verify-ovsx-auth');

module.exports = async (version, packageVsix, yarn, logger) => {
module.exports = async (version, packageVsix, logger) => {
const ovsxEnabled = isOvsxEnabled();
if (packageVsix || ovsxEnabled) {
if (!packageVsix && ovsxEnabled) {
Expand All @@ -22,10 +22,6 @@ module.exports = async (version, packageVsix, yarn, logger) => {

const options = ['package', version, '--no-git-tag-version', '--out', packagePath];

if (yarn) {
options.push('--yarn');
}

await execa('vsce', options, { stdio: 'inherit' });

return packagePath;
Expand Down
6 changes: 1 addition & 5 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const execa = require('execa');
const { readJson } = require('fs-extra');
const { isOvsxEnabled } = require('./verify-ovsx-auth');

module.exports = async (version, packagePath, yarn, logger) => {
module.exports = async (version, packagePath, logger) => {
const { publisher, name } = await readJson('./package.json');

const options = ['publish'];
Expand All @@ -15,10 +15,6 @@ module.exports = async (version, packagePath, yarn, logger) => {
options.push(...[version, '--no-git-tag-version']);
}

if (yarn) {
options.push('--yarn');
}

await execa('vsce', options, { stdio: 'inherit' });

const vsceUrl = `https://marketplace.visualstudio.com/items?itemName=${publisher}.${name}`;
Expand Down
8 changes: 1 addition & 7 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const semanticReleasePayload = {
};

const pluginConfig = {
packageVsix: 'test.vsix',
yarn: undefined
packageVsix: 'test.vsix'
};

test.beforeEach(t => {
Expand Down Expand Up @@ -58,7 +57,6 @@ test('prepare and unverified', async t => {
t.deepEqual(vscePrepareStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
pluginConfig.packageVsix,
pluginConfig.yarn,
semanticReleasePayload.logger
]);
});
Expand All @@ -78,7 +76,6 @@ test('prepare and verified', async t => {
t.deepEqual(vscePrepareStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
pluginConfig.packageVsix,
pluginConfig.yarn,
semanticReleasePayload.logger
]);
});
Expand All @@ -98,7 +95,6 @@ test('publish that is unverified and unprepared', async t => {
t.deepEqual(vscePublishStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
undefined,
pluginConfig.yarn,
semanticReleasePayload.logger
]);
});
Expand All @@ -119,7 +115,6 @@ test('publish that is verified but unprepared', async t => {
t.deepEqual(vscePublishStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
undefined,
pluginConfig.yarn,
semanticReleasePayload.logger
]);
});
Expand All @@ -141,7 +136,6 @@ test('publish that is already verified & prepared', async t => {
t.deepEqual(vscePublishStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
packagePath,
pluginConfig.yarn,
semanticReleasePayload.logger
]);
});
45 changes: 4 additions & 41 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,7 @@ test('packageVsix is not specified', async t => {
});

const version = '1.0.0';
await prepare(version, undefined, undefined, logger);

t.true(execaStub.notCalled);
});

test('packageVsix is not specified but yarn is true', async t => {
const { execaStub } = t.context.stubs;
const prepare = proxyquire('../lib/prepare', {
execa: execaStub
});

const version = '1.0.0';
const yarn = true;
await prepare(version, undefined, yarn, logger);
await prepare(version, undefined, logger);

t.true(execaStub.notCalled);
});
Expand All @@ -50,7 +37,7 @@ test('packageVsix is a string', async t => {
const version = '1.0.0';
const packageVsix = 'test.vsix';
const packagePath = packageVsix;
const result = await prepare(version, packageVsix, undefined, logger);
const result = await prepare(version, packageVsix, logger);

t.deepEqual(result, packagePath);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['package', version, '--no-git-tag-version', '--out', packagePath], { stdio: 'inherit' }]);
Expand All @@ -73,36 +60,12 @@ test('packageVsix is true', async t => {
const packageVsix = true;
const packagePath = `${name}-${version}.vsix`;

const result = await prepare(version, packageVsix, undefined, logger);
const result = await prepare(version, packageVsix, logger);

t.deepEqual(result, packagePath);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['package', version, '--no-git-tag-version', '--out', packagePath], { stdio: 'inherit' }]);
});

test('packageVsix is true and yarn is true', async t => {
const { execaStub } = t.context.stubs;
const name = 'test';

const prepare = proxyquire('../lib/prepare', {
execa: execaStub,
'fs-extra': {
readJson: sinon.stub().returns({
name
})
}
});

const version = '1.0.0';
const packageVsix = true;
const yarn = true;
const packagePath = `${name}-${version}.vsix`;

const result = await prepare(version, packageVsix, yarn, logger);

t.deepEqual(result, packagePath);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['package', version, '--no-git-tag-version', '--out', packagePath, '--yarn'], { stdio: 'inherit' }]);
});

test('packageVsix is not set but OVSX_PAT is', async t => {
const { execaStub } = t.context.stubs;
const name = 'test';
Expand All @@ -124,7 +87,7 @@ test('packageVsix is not set but OVSX_PAT is', async t => {
const packageVsix = undefined;
const packagePath = `${name}-${version}.vsix`;

const result = await prepare(version, packageVsix, undefined, logger);
const result = await prepare(version, packageVsix, logger);

t.deepEqual(result, packagePath);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['package', version, '--no-git-tag-version', '--out', packagePath], { stdio: 'inherit' }]);
Expand Down
37 changes: 4 additions & 33 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('publish', async t => {
sinon.stub(process, 'env').value({
VSCE_PAT: token
});
const result = await publish(version, undefined, undefined, logger);
const result = await publish(version, undefined, logger);

t.deepEqual(result, {
name: 'Visual Studio Marketplace',
Expand Down Expand Up @@ -64,7 +64,7 @@ test('publish with packagePath', async t => {
sinon.stub(process, 'env').value({
VSCE_PAT: token
});
const result = await publish(version, packagePath, undefined, logger);
const result = await publish(version, packagePath, logger);

t.deepEqual(result, {
name: 'Visual Studio Marketplace',
Expand All @@ -73,35 +73,6 @@ test('publish with packagePath', async t => {
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['publish', '--packagePath', packagePath], { stdio: 'inherit' }]);
});

test('publish when yarn is true', async t => {
const { execaStub } = t.context.stubs;
const publisher = 'semantic-release-vsce';
const name = 'Semantice Release VSCE';
const publish = proxyquire('../lib/publish', {
execa: execaStub,
'fs-extra': {
readJson: sinon.stub().returns({
publisher,
name
})
}
});

const version = '1.0.0';
const token = 'abc123';
sinon.stub(process, 'env').value({
VSCE_PAT: token
});
const yarn = true;
const result = await publish(version, undefined, yarn, logger);

t.deepEqual(result, {
name: 'Visual Studio Marketplace',
url: `https://marketplace.visualstudio.com/items?itemName=${publisher}.${name}`
});
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['publish', version, '--no-git-tag-version', '--yarn'], { stdio: 'inherit' }]);
});

test('publish with VSCE_PAT and VSCE_TOKEN should prefer VSCE_PAT', async t => {
const { execaStub } = t.context.stubs;
const publisher = 'semantic-release-vsce';
Expand All @@ -122,7 +93,7 @@ test('publish with VSCE_PAT and VSCE_TOKEN should prefer VSCE_PAT', async t => {
VSCE_PAT: token,
VSCE_TOKEN: token
});
const result = await publish(version, undefined, undefined, logger);
const result = await publish(version, undefined, logger);

t.deepEqual(result, {
name: 'Visual Studio Marketplace',
Expand Down Expand Up @@ -152,7 +123,7 @@ test('publish to OpenVSX', async t => {
OVSX_PAT: token,
VSCE_TOKEN: token
});
const result = await publish(version, packagePath, undefined, logger);
const result = await publish(version, packagePath, logger);

t.deepEqual(result, {
name: 'Visual Studio Marketplace',
Expand Down

0 comments on commit df92b55

Please sign in to comment.