diff --git a/index.js b/index.js index 2d55f28c..ff38b0e2 100644 --- a/index.js +++ b/index.js @@ -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. diff --git a/lib/prepare.js b/lib/prepare.js index c54fd5b8..1fd79de6 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -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; } diff --git a/lib/publish.js b/lib/publish.js index 0b8d86e8..a0a17f61 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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}`); diff --git a/lib/verify-auth.js b/lib/verify-auth.js index b3844084..e2a833fb 100644 --- a/lib/verify-auth.js +++ b/lib/verify-auth.js @@ -1,7 +1,9 @@ +// @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) { @@ -9,7 +11,7 @@ module.exports = async (logger) => { } 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'); } diff --git a/lib/verify-ovsx-auth.js b/lib/verify-ovsx-auth.js index b29092dd..b4f02d9a 100644 --- a/lib/verify-ovsx-auth.js +++ b/lib/verify-ovsx-auth.js @@ -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'); // } diff --git a/lib/verify-pkg.js b/lib/verify-pkg.js index fd4f4f98..212d208c 100644 --- a/lib/verify-pkg.js +++ b/lib/verify-pkg.js @@ -1,3 +1,5 @@ +// @ts-check + const SemanticReleaseError = require('@semantic-release/error'); const { readJson } = require('fs-extra'); const fs = require('fs'); diff --git a/lib/verify.js b/lib/verify.js index 4d76baa4..8b3bf03f 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -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); } }; diff --git a/test/index.test.js b/test/index.test.js index 01f08836..6a161107 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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 ]); }); diff --git a/test/prepare.test.js b/test/prepare.test.js index 40d6a61e..c13b475c 100644 --- a/test/prepare.test.js +++ b/test/prepare.test.js @@ -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 }]); }); diff --git a/test/publish.test.js b/test/publish.test.js index 38683ed5..0b5274e8 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -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 }]); }); diff --git a/test/verify-auth.test.js b/test/verify-auth.test.js index 77983d1b..3e31229b 100644 --- a/test/verify-auth.test.js +++ b/test/verify-auth.test.js @@ -6,6 +6,7 @@ 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({ @@ -13,7 +14,7 @@ test('VSCE_PAT is set', 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)); @@ -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' }); diff --git a/test/verify.test.js b/test/verify.test.js index 2fffb15f..e520c8de 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -5,6 +5,7 @@ const proxyquire = require('proxyquire'); const logger = { log: sinon.fake() }; +const cwd = process.cwd(); test('resolves', async t => { const verify = proxyquire('../lib/verify', { @@ -12,7 +13,7 @@ test('resolves', async t => { './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);