Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: felipecrs/semantic-release-vsce
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.2.2
Choose a base ref
...
head repository: felipecrs/semantic-release-vsce
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.2.3
Choose a head ref
  • 1 commit
  • 12 files changed
  • 2 contributors

Commits on Oct 31, 2022

  1. fix: use context's cwd for vsce calls (#349)

    Co-authored-by: Aram Becker <becker.aram@gmail.com>
    felipecrs and 1nVitr0 committed Oct 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    86b499e View commit details
Showing with 65 additions and 44 deletions.
  1. +10 −8 index.js
  2. +4 −2 lib/prepare.js
  3. +5 −3 lib/publish.js
  4. +4 −2 lib/verify-auth.js
  5. +3 −1 lib/verify-ovsx-auth.js
  6. +2 −0 lib/verify-pkg.js
  7. +4 −2 lib/verify.js
  8. +8 −5 test/index.test.js
  9. +7 −6 test/prepare.test.js
  10. +8 −7 test/publish.test.js
  11. +5 −4 test/verify-auth.test.js
  12. +5 −4 test/verify.test.js
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

const verifyVsce = require('./lib/verify');
const vscePublish = require('./lib/publish');
const vscePrepare = require('./lib/prepare');
@@ -6,29 +8,29 @@ let verified = false;
let prepared = false;
let packagePath;

async function verifyConditions (pluginConfig, { logger }) {
await verifyVsce(logger, pluginConfig);
async function verifyConditions (pluginConfig, { logger, cwd }) {
await verifyVsce(pluginConfig, { logger, cwd });
verified = true;
}

async function prepare (pluginConfig, { nextRelease: { version }, logger }) {
async function prepare (pluginConfig, { nextRelease: { version }, logger, cwd }) {
if (!verified) {
await verifyVsce(logger);
await verifyVsce(pluginConfig, { logger, cwd });
verified = true;
}
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger);
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger, cwd);
prepared = true;
}

async function publish (pluginConfig, { nextRelease: { version }, logger }) {
async function publish (pluginConfig, { nextRelease: { version }, logger, cwd }) {
if (!verified) {
await verifyVsce(logger);
await verifyVsce(pluginConfig, { logger, cwd });
verified = true;
}

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

// If publishing is disabled, return early.
6 changes: 4 additions & 2 deletions lib/prepare.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @ts-check

const execa = require('execa');
const { readJson } = require('fs-extra');
const { isOvsxEnabled } = require('./verify-ovsx-auth');

module.exports = async (version, packageVsix, logger) => {
module.exports = async (version, packageVsix, logger, cwd) => {
const ovsxEnabled = isOvsxEnabled();
if (packageVsix || ovsxEnabled) {
if (!packageVsix && ovsxEnabled) {
@@ -22,7 +24,7 @@ module.exports = async (version, packageVsix, logger) => {

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

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

return packagePath;
}
8 changes: 5 additions & 3 deletions lib/publish.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @ts-check

const execa = require('execa');
const { readJson } = require('fs-extra');
const { isOvsxEnabled } = require('./verify-ovsx-auth');

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

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

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

const vsceUrl = `https://marketplace.visualstudio.com/items?itemName=${publisher}.${name}`;
logger.log(`The new version is available at ${vsceUrl}.`);
@@ -28,7 +30,7 @@ module.exports = async (version, packagePath, logger) => {
if (isOvsxEnabled()) {
logger.log('Now publishing to OpenVSX');

await execa('ovsx', ['publish', packagePath], { stdio: 'inherit', preferLocal: true });
await execa('ovsx', ['publish', packagePath], { stdio: 'inherit', preferLocal: true, cwd });
const ovsxUrl = `https://open-vsx.org/extension/${publisher}/${name}/${version}`;

logger.log(`The new ovsx version is available at ${ovsxUrl}`);
6 changes: 4 additions & 2 deletions lib/verify-auth.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// @ts-check

const execa = require('execa');
const SemanticReleaseError = require('@semantic-release/error');

module.exports = async (logger) => {
module.exports = async (logger, cwd) => {
logger.log('Verifying authentication for vsce');

if (!process.env.VSCE_PAT) {
throw new SemanticReleaseError('No vsce personal access token specified (set the `VSCE_PAT` environment variable).', 'ENOVSCEPAT');
}

try {
await execa('vsce', ['verify-pat'], { preferLocal: true });
await execa('vsce', ['verify-pat'], { preferLocal: true, cwd });
} catch (e) {
throw new SemanticReleaseError(`Invalid vsce token. Additional information:\n\n${e}`, 'EINVALIDVSCETOKEN');
}
4 changes: 3 additions & 1 deletion lib/verify-ovsx-auth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

const SemanticReleaseError = require('@semantic-release/error');

const isOvsxEnabled = () => {
@@ -18,7 +20,7 @@ module.exports = async (logger) => {

// TODO: waiting for https://github.com/eclipse/openvsx/issues/313
// try {
// await execa('ovsx', ['verify-pat'], { preferLocal: true });
// await execa('ovsx', ['verify-pat'], { preferLocal: true, cwd });
// } catch (e) {
// throw new SemanticReleaseError(`Invalid ovsx personal access token. Additional information:\n\n${e}`, 'EINVALIDOVSXPAT');
// }
2 changes: 2 additions & 0 deletions lib/verify-pkg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

const SemanticReleaseError = require('@semantic-release/error');
const { readJson } = require('fs-extra');
const fs = require('fs');
6 changes: 4 additions & 2 deletions lib/verify.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// @ts-check

const verifyPkg = require('./verify-pkg');
const verifyAuth = require('./verify-auth');
const verifyOvsxAuth = require('./verify-ovsx-auth');

module.exports = async (logger, pluginConfig) => {
module.exports = async (pluginConfig, { logger, cwd }) => {
await verifyPkg();

if (pluginConfig?.publish !== false) {
await verifyAuth(logger);
await verifyAuth(logger, cwd);
await verifyOvsxAuth(logger);
}
};
13 changes: 8 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,8 @@ const semanticReleasePayload = {
},
logger: {
log: sinon.fake()
}
},
cwd: process.cwd()
};

const pluginConfig = {
@@ -39,7 +40,7 @@ test('verifyConditions', async t => {

await verifyConditions(pluginConfig, semanticReleasePayload);

t.true(verifyVsceStub.calledOnceWith(semanticReleasePayload.logger));
t.true(verifyVsceStub.calledOnceWith(pluginConfig, { logger: semanticReleasePayload.logger, cwd: semanticReleasePayload.cwd }));
});

test('prepare and unverified', async t => {
@@ -53,11 +54,12 @@ test('prepare and unverified', async t => {

await prepare(pluginConfig, semanticReleasePayload);

t.true(verifyVsceStub.calledOnceWith(semanticReleasePayload.logger));
t.true(verifyVsceStub.calledOnceWith(pluginConfig, { logger: semanticReleasePayload.logger, cwd: semanticReleasePayload.cwd }));
t.deepEqual(vscePrepareStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
pluginConfig.packageVsix,
semanticReleasePayload.logger
semanticReleasePayload.logger,
semanticReleasePayload.cwd
]);
});

@@ -76,7 +78,8 @@ test('prepare and verified', async t => {
t.deepEqual(vscePrepareStub.getCall(0).args, [
semanticReleasePayload.nextRelease.version,
pluginConfig.packageVsix,
semanticReleasePayload.logger
semanticReleasePayload.logger,
semanticReleasePayload.cwd
]);
});

13 changes: 7 additions & 6 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ const proxyquire = require('proxyquire');
const logger = {
log: sinon.fake()
};
const cwd = process.cwd();

test.beforeEach(t => {
t.context.stubs = {
@@ -37,10 +38,10 @@ 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, logger);
const result = await prepare(version, packageVsix, logger, cwd);

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

test('packageVsix is true', async t => {
@@ -60,10 +61,10 @@ test('packageVsix is true', async t => {
const packageVsix = true;
const packagePath = `${name}-${version}.vsix`;

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

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

test('packageVsix is not set but OVSX_PAT is', async t => {
@@ -87,8 +88,8 @@ 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, logger);
const result = await prepare(version, packageVsix, logger, cwd);

t.deepEqual(result, packagePath);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['package', version, '--no-git-tag-version', '--out', packagePath], { stdio: 'inherit', preferLocal: true }]);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['package', version, '--no-git-tag-version', '--out', packagePath], { stdio: 'inherit', preferLocal: true, cwd }]);
});
15 changes: 8 additions & 7 deletions test/publish.test.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ const proxyquire = require('proxyquire');
const logger = {
log: sinon.fake()
};
const cwd = process.cwd();

test.beforeEach(t => {
t.context.stubs = {
@@ -35,13 +36,13 @@ test('publish', async t => {
sinon.stub(process, 'env').value({
VSCE_PAT: token
});
const result = await publish(version, undefined, logger);
const result = await publish(version, undefined, logger, cwd);

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'], { stdio: 'inherit', preferLocal: true }]);
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['publish', version, '--no-git-tag-version'], { stdio: 'inherit', preferLocal: true, cwd }]);
});

test('publish with packagePath', async t => {
@@ -64,13 +65,13 @@ test('publish with packagePath', async t => {
sinon.stub(process, 'env').value({
VSCE_PAT: token
});
const result = await publish(version, packagePath, logger);
const result = await publish(version, packagePath, logger, cwd);

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

test('publish to OpenVSX', async t => {
@@ -94,17 +95,17 @@ test('publish to OpenVSX', async t => {
OVSX_PAT: token,
VSCE_PAT: token
});
const result = await publish(version, packagePath, logger);
const result = await publish(version, packagePath, logger, cwd);

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

// t.deepEqual(result[1], {
// name: 'Open VSX Registry',
// url: `https://open-vsx.org/extension/${publisher}/${name}/${version}`
// });
t.deepEqual(execaStub.getCall(1).args, ['ovsx', ['publish', packagePath], { stdio: 'inherit', preferLocal: true }]);
t.deepEqual(execaStub.getCall(1).args, ['ovsx', ['publish', packagePath], { stdio: 'inherit', preferLocal: true, cwd }]);
});
9 changes: 5 additions & 4 deletions test/verify-auth.test.js
Original file line number Diff line number Diff line change
@@ -6,14 +6,15 @@ const SemanticReleaseError = require('@semantic-release/error');
const logger = {
log: sinon.fake()
};
const cwd = process.cwd();

test('VSCE_PAT is set', async t => {
sinon.stub(process, 'env').value({
VSCE_PAT: 'abc123'
});

const verifyAuth = proxyquire('../lib/verify-auth', {
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true }).resolves()
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true, cwd }).resolves()
});

await t.notThrowsAsync(() => verifyAuth(logger));
@@ -23,7 +24,7 @@ test('VSCE_PAT is not set', async t => {
sinon.stub(process, 'env').value({});

const verifyAuth = proxyquire('../lib/verify-auth', {
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true }).resolves()
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true, cwd }).resolves()
});

await t.throwsAsync(() => verifyAuth(logger), { instanceOf: SemanticReleaseError, code: 'ENOVSCEPAT' });
@@ -35,7 +36,7 @@ test('VSCE_PAT is valid', async t => {
});

const verifyAuth = proxyquire('../lib/verify-auth', {
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true }).resolves()
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true, cwd }).resolves()
});

await t.notThrowsAsync(() => verifyAuth(logger));
@@ -47,7 +48,7 @@ test('VSCE_PAT is invalid', async t => {
});

const verifyAuth = proxyquire('../lib/verify-auth', {
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true }).rejects()
execa: sinon.stub().withArgs('vsce', ['verify-pat'], { preferLocal: true, cwd }).rejects()
});

await t.throwsAsync(() => verifyAuth(logger), { instanceOf: SemanticReleaseError, code: 'EINVALIDVSCETOKEN' });
9 changes: 5 additions & 4 deletions test/verify.test.js
Original file line number Diff line number Diff line change
@@ -5,14 +5,15 @@ const proxyquire = require('proxyquire');
const logger = {
log: sinon.fake()
};
const cwd = process.cwd();

test('resolves', async t => {
const verify = proxyquire('../lib/verify', {
'./verify-auth': sinon.stub().resolves(),
'./verify-pkg': sinon.stub().resolves()
});

await t.notThrowsAsync(() => verify(logger));
await t.notThrowsAsync(() => verify({}, { logger, cwd }));
});

test('rejects with verify-auth', async t => {
@@ -21,7 +22,7 @@ test('rejects with verify-auth', async t => {
'./verify-pkg': sinon.stub().resolves()
});

await t.throwsAsync(() => verify(logger));
await t.throwsAsync(() => verify({}, { logger, cwd }));
});

test('rejects with verify-pkg', async t => {
@@ -30,7 +31,7 @@ test('rejects with verify-pkg', async t => {
'./verify-pkg': sinon.stub().rejects()
});

await t.throwsAsync(() => verify(logger));
await t.throwsAsync(() => verify({}, { logger, cwd }));
});

test('is does not verify the auth tokens if publishing is disabled', async t => {
@@ -45,7 +46,7 @@ test('is does not verify the auth tokens if publishing is disabled', async t =>
'./verify-ovsx-auth': stubs.verifyOvsxAuthStub
});

await verify(logger, { publish: false });
await verify({ publish: false }, { logger, cwd });

t.true(stubs.verifyAuthStub.notCalled);
t.true(stubs.verifyOvsxAuthStub.notCalled);