Skip to content

Commit a0f87f1

Browse files
NetailcefnAndarist
authored
Fixed changelog application when executing through npx (#1562)
* Resolve module from global node_modules Fixes #566 * fix: NPX apply changelog * fix: feedback * fix: feedback v2 * fix: feedback v3 * Create seven-beans-jump.md * Apply suggestions from code review --------- Co-authored-by: Cefn Hoile <[email protected]> Co-authored-by: Mateusz Burzyński <[email protected]>
1 parent a8c474f commit a0f87f1

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

.changeset/seven-beans-jump.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@changesets/apply-release-plan": patch
3+
---
4+
5+
author: @Netail
6+
author: @cefn
7+
8+
Add an ability to pass in `contextDir` of the running script (like the `@changesets/cli`) so the changelog modules can be alternatively resolved using it

.changeset/warm-results-rescue.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@changesets/cli": patch
3+
---
4+
5+
author: @Netail
6+
author: @cefn
7+
8+
Fixed changelog application when executing using `npx` and similar tools

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"type": "git",
2222
"url": "https://github.com/changesets/changesets.git"
2323
},
24+
"packageManager": "[email protected]",
2425
"workspaces": [
2526
"packages/*",
2627
"scripts/*"

packages/apply-release-plan/src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export default async function applyReleasePlan(
6868
releasePlan: ReleasePlan,
6969
packages: Packages,
7070
config: Config = defaultConfig,
71-
snapshot?: string | boolean
71+
snapshot?: string | boolean,
72+
contextDir = __dirname
7273
) {
7374
let cwd = packages.root.dir;
7475

@@ -97,7 +98,8 @@ export default async function applyReleasePlan(
9798
releasesWithPackage,
9899
changesets,
99100
config,
100-
cwd
101+
cwd,
102+
contextDir
101103
);
102104

103105
if (releasePlan.preState !== undefined && snapshot === undefined) {
@@ -189,7 +191,8 @@ async function getNewChangelogEntry(
189191
releasesWithPackage: ModCompWithPackage[],
190192
changesets: NewChangeset[],
191193
config: Config,
192-
cwd: string
194+
cwd: string,
195+
contextDir: string
193196
) {
194197
if (!config.changelog) {
195198
return Promise.resolve(
@@ -207,7 +210,13 @@ async function getNewChangelogEntry(
207210

208211
const changelogOpts = config.changelog[1];
209212
let changesetPath = path.join(cwd, ".changeset");
210-
let changelogPath = resolveFrom(changesetPath, config.changelog[0]);
213+
let changelogPath;
214+
215+
try {
216+
changelogPath = resolveFrom(changesetPath, config.changelog[0]);
217+
} catch {
218+
changelogPath = resolveFrom(contextDir, config.changelog[0]);
219+
}
211220

212221
let possibleChangelogFunc = require(changelogPath);
213222
if (possibleChangelogFunc.default) {

packages/cli/src/commands/version/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export default async function version(
8585
releasePlan,
8686
packages,
8787
releaseConfig,
88-
options.snapshot
88+
options.snapshot,
89+
__dirname
8990
);
9091

9192
const [{ getVersionMessage }, commitOpts] = getCommitFunctions(

0 commit comments

Comments
 (0)