Skip to content

Commit d6b78ea

Browse files
felipecrs1nVitr0
andauthoredOct 31, 2022
fix: use context's cwd for vsce calls (#349)
Co-authored-by: Aram Becker <becker.aram@gmail.com>
1 parent f116f33 commit d6b78ea

12 files changed

+65
-44
lines changed
 

‎index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-check
2+
13
const verifyVsce = require('./lib/verify');
24
const vscePublish = require('./lib/publish');
35
const vscePrepare = require('./lib/prepare');
@@ -6,29 +8,29 @@ let verified = false;
68
let prepared = false;
79
let packagePath;
810

9-
async function verifyConditions (pluginConfig, { logger }) {
10-
await verifyVsce(logger, pluginConfig);
11+
async function verifyConditions (pluginConfig, { logger, cwd }) {
12+
await verifyVsce(pluginConfig, { logger, cwd });
1113
verified = true;
1214
}
1315

14-
async function prepare (pluginConfig, { nextRelease: { version }, logger }) {
16+
async function prepare (pluginConfig, { nextRelease: { version }, logger, cwd }) {
1517
if (!verified) {
16-
await verifyVsce(logger);
18+
await verifyVsce(pluginConfig, { logger, cwd });
1719
verified = true;
1820
}
19-
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger);
21+
packagePath = await vscePrepare(version, pluginConfig.packageVsix, logger, cwd);
2022
prepared = true;
2123
}
2224

23-
async function publish (pluginConfig, { nextRelease: { version }, logger }) {
25+
async function publish (pluginConfig, { nextRelease: { version }, logger, cwd }) {
2426
if (!verified) {
25-
await verifyVsce(logger);
27+
await verifyVsce(pluginConfig, { logger, cwd });
2628
verified = true;
2729
}
2830

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

3436
// If publishing is disabled, return early.

‎lib/prepare.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// @ts-check
2+
13
const execa = require('execa');
24
const { readJson } = require('fs-extra');
35
const { isOvsxEnabled } = require('./verify-ovsx-auth');
46

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

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

25-
await execa('vsce', options, { stdio: 'inherit', preferLocal: true });
27+
await execa('vsce', options, { stdio: 'inherit', preferLocal: true, cwd });
2628

2729
return packagePath;
2830
}

‎lib/publish.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// @ts-check
2+
13
const execa = require('execa');
24
const { readJson } = require('fs-extra');
35
const { isOvsxEnabled } = require('./verify-ovsx-auth');
46

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

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

18-
await execa('vsce', options, { stdio: 'inherit', preferLocal: true });
20+
await execa('vsce', options, { stdio: 'inherit', preferLocal: true, cwd });
1921

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

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

3436
logger.log(`The new ovsx version is available at ${ovsxUrl}`);

‎lib/verify-auth.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
// @ts-check
2+
13
const execa = require('execa');
24
const SemanticReleaseError = require('@semantic-release/error');
35

4-
module.exports = async (logger) => {
6+
module.exports = async (logger, cwd) => {
57
logger.log('Verifying authentication for vsce');
68

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

1113
try {
12-
await execa('vsce', ['verify-pat'], { preferLocal: true });
14+
await execa('vsce', ['verify-pat'], { preferLocal: true, cwd });
1315
} catch (e) {
1416
throw new SemanticReleaseError(`Invalid vsce token. Additional information:\n\n${e}`, 'EINVALIDVSCETOKEN');
1517
}

‎lib/verify-ovsx-auth.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-check
2+
13
const SemanticReleaseError = require('@semantic-release/error');
24

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

1921
// TODO: waiting for https://github.com/eclipse/openvsx/issues/313
2022
// try {
21-
// await execa('ovsx', ['verify-pat'], { preferLocal: true });
23+
// await execa('ovsx', ['verify-pat'], { preferLocal: true, cwd });
2224
// } catch (e) {
2325
// throw new SemanticReleaseError(`Invalid ovsx personal access token. Additional information:\n\n${e}`, 'EINVALIDOVSXPAT');
2426
// }

‎lib/verify-pkg.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-check
2+
13
const SemanticReleaseError = require('@semantic-release/error');
24
const { readJson } = require('fs-extra');
35
const fs = require('fs');

‎lib/verify.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// @ts-check
2+
13
const verifyPkg = require('./verify-pkg');
24
const verifyAuth = require('./verify-auth');
35
const verifyOvsxAuth = require('./verify-ovsx-auth');
46

5-
module.exports = async (logger, pluginConfig) => {
7+
module.exports = async (pluginConfig, { logger, cwd }) => {
68
await verifyPkg();
79

810
if (pluginConfig?.publish !== false) {
9-
await verifyAuth(logger);
11+
await verifyAuth(logger, cwd);
1012
await verifyOvsxAuth(logger);
1113
}
1214
};

‎test/index.test.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const semanticReleasePayload = {
88
},
99
logger: {
1010
log: sinon.fake()
11-
}
11+
},
12+
cwd: process.cwd()
1213
};
1314

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

4041
await verifyConditions(pluginConfig, semanticReleasePayload);
4142

42-
t.true(verifyVsceStub.calledOnceWith(semanticReleasePayload.logger));
43+
t.true(verifyVsceStub.calledOnceWith(pluginConfig, { logger: semanticReleasePayload.logger, cwd: semanticReleasePayload.cwd }));
4344
});
4445

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

5455
await prepare(pluginConfig, semanticReleasePayload);
5556

56-
t.true(verifyVsceStub.calledOnceWith(semanticReleasePayload.logger));
57+
t.true(verifyVsceStub.calledOnceWith(pluginConfig, { logger: semanticReleasePayload.logger, cwd: semanticReleasePayload.cwd }));
5758
t.deepEqual(vscePrepareStub.getCall(0).args, [
5859
semanticReleasePayload.nextRelease.version,
5960
pluginConfig.packageVsix,
60-
semanticReleasePayload.logger
61+
semanticReleasePayload.logger,
62+
semanticReleasePayload.cwd
6163
]);
6264
});
6365

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

‎test/prepare.test.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const proxyquire = require('proxyquire');
55
const logger = {
66
log: sinon.fake()
77
};
8+
const cwd = process.cwd();
89

910
test.beforeEach(t => {
1011
t.context.stubs = {
@@ -37,10 +38,10 @@ test('packageVsix is a string', async t => {
3738
const version = '1.0.0';
3839
const packageVsix = 'test.vsix';
3940
const packagePath = packageVsix;
40-
const result = await prepare(version, packageVsix, logger);
41+
const result = await prepare(version, packageVsix, logger, cwd);
4142

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

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

63-
const result = await prepare(version, packageVsix, logger);
64+
const result = await prepare(version, packageVsix, logger, cwd);
6465

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

6970
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 => {
8788
const packageVsix = undefined;
8889
const packagePath = `${name}-${version}.vsix`;
8990

90-
const result = await prepare(version, packageVsix, logger);
91+
const result = await prepare(version, packageVsix, logger, cwd);
9192

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

‎test/publish.test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const proxyquire = require('proxyquire');
55
const logger = {
66
log: sinon.fake()
77
};
8+
const cwd = process.cwd();
89

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

4041
t.deepEqual(result, {
4142
name: 'Visual Studio Marketplace',
4243
url: `https://marketplace.visualstudio.com/items?itemName=${publisher}.${name}`
4344
});
44-
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['publish', version, '--no-git-tag-version'], { stdio: 'inherit', preferLocal: true }]);
45+
t.deepEqual(execaStub.getCall(0).args, ['vsce', ['publish', version, '--no-git-tag-version'], { stdio: 'inherit', preferLocal: true, cwd }]);
4546
});
4647

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

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

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

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

105106
// t.deepEqual(result[1], {
106107
// name: 'Open VSX Registry',
107108
// url: `https://open-vsx.org/extension/${publisher}/${name}/${version}`
108109
// });
109-
t.deepEqual(execaStub.getCall(1).args, ['ovsx', ['publish', packagePath], { stdio: 'inherit', preferLocal: true }]);
110+
t.deepEqual(execaStub.getCall(1).args, ['ovsx', ['publish', packagePath], { stdio: 'inherit', preferLocal: true, cwd }]);
110111
});

‎test/verify-auth.test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ const SemanticReleaseError = require('@semantic-release/error');
66
const logger = {
77
log: sinon.fake()
88
};
9+
const cwd = process.cwd();
910

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

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

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

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

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

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

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

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

5354
await t.throwsAsync(() => verifyAuth(logger), { instanceOf: SemanticReleaseError, code: 'EINVALIDVSCETOKEN' });

‎test/verify.test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const proxyquire = require('proxyquire');
55
const logger = {
66
log: sinon.fake()
77
};
8+
const cwd = process.cwd();
89

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

15-
await t.notThrowsAsync(() => verify(logger));
16+
await t.notThrowsAsync(() => verify({}, { logger, cwd }));
1617
});
1718

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

24-
await t.throwsAsync(() => verify(logger));
25+
await t.throwsAsync(() => verify({}, { logger, cwd }));
2526
});
2627

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

33-
await t.throwsAsync(() => verify(logger));
34+
await t.throwsAsync(() => verify({}, { logger, cwd }));
3435
});
3536

3637
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 =>
4546
'./verify-ovsx-auth': stubs.verifyOvsxAuthStub
4647
});
4748

48-
await verify(logger, { publish: false });
49+
await verify({ publish: false }, { logger, cwd });
4950

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

0 commit comments

Comments
 (0)
Please sign in to comment.