Skip to content

Commit

Permalink
Use process.execPath instead of resolving node from $PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Oct 7, 2022
1 parent 57759a8 commit 3bb9d03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
20 changes: 10 additions & 10 deletions __tests__/plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestPlugin extends Plugin {
// always assume v1.0.0 unless specifically overridden
'git describe --tags --abbrev=0': 'v1.0.0',

[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`]:
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`]:
'## Unreleased (2020-03-18)\n\nThe changelog',
};

Expand Down Expand Up @@ -95,7 +95,7 @@ describe('@release-it-plugins/lerna-changelog', () => {

expect(plugin.commands).toStrictEqual([
['git describe --tags --abbrev=0', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
]);
});

Expand All @@ -109,7 +109,7 @@ describe('@release-it-plugins/lerna-changelog', () => {

expect(plugin.commands).toStrictEqual([
['git describe --tags --abbrev=0', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
]);

const changelog = fs.readFileSync(infile, { encoding: 'utf8' });
Expand All @@ -130,7 +130,7 @@ describe('@release-it-plugins/lerna-changelog', () => {
let infile = tmp.fileSync().name;
let plugin = buildPlugin({ infile });

plugin.responses[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`] = '';
plugin.responses[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`] = '';

await runTasks(plugin);

Expand All @@ -150,15 +150,15 @@ describe('@release-it-plugins/lerna-changelog', () => {
value: 'hahahahaah, does not exist',
},
'git rev-list --max-parents=0 HEAD': 'aabc',
[`${LERNA_PATH} --next-version=Unreleased --from=aabc`]: `## Unreleased\n\nThe changelog\n## v1.0.0\n\nThe old changelog`,
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=aabc`]: `## Unreleased\n\nThe changelog\n## v1.0.0\n\nThe old changelog`,
});

await runTasks(plugin);

expect(plugin.commands).toStrictEqual([
['git describe --tags --abbrev=0', { write: false }],
['git rev-list --max-parents=0 HEAD', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=aabc`, { write: false }],
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=aabc`, { write: false }],
]);

const changelog = fs.readFileSync(infile, { encoding: 'utf8' });
Expand All @@ -174,16 +174,16 @@ describe('@release-it-plugins/lerna-changelog', () => {

Object.assign(plugin.responses, {
'git rev-list --max-parents=0 HEAD': 'aabc',
[`${LERNA_PATH} --next-version=Unreleased --from=aabc`]: `## Unreleased\n\nThe changelog\n## v1.0.0\n\nThe old changelog`,
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=aabc`]: `## Unreleased\n\nThe changelog\n## v1.0.0\n\nThe old changelog`,
});

await runTasks(plugin);

expect(plugin.commands).toStrictEqual([
['git describe --tags --abbrev=0', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
['git rev-list --max-parents=0 HEAD', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=aabc`, { write: false }],
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=aabc`, { write: false }],
[`git add ${infile}`, {}],
]);

Expand Down Expand Up @@ -296,7 +296,7 @@ describe('@release-it-plugins/lerna-changelog', () => {
} catch (error) {
expect(plugin.commands).toStrictEqual([
['git describe --tags --abbrev=0', { write: false }],
[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
[`${process.execPath} ${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`, { write: false }],
]);

expect(error.message).toEqual(
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ export default class LernaChangelogGeneratorPlugin extends Plugin {
}

async _execLernaChangelog(from) {
let changelog = await this.exec(`node ${LERNA_PATH} --next-version=${UNRELEASED} --from=${from}`, {
options: { write: false },
});
let changelog = await this.exec(
`${process.execPath} ${LERNA_PATH} --next-version=${UNRELEASED} --from=${from}`,
{
options: { write: false },
}
);

return changelog;
}
Expand Down

0 comments on commit 3bb9d03

Please sign in to comment.