Repository navigation
Description
Summary
craft prepare --dry-run writes the automatic version bump into the checkout Craft was started from, not the temporary dry-run worktree. A dry run of a workspace that uses automatic bumping (no preReleaseCommand, npm target) leaves package.json modified in the user's checkout.
Seen with Craft 3.7.0 (055aa3c), but the code path predates 3.7.0.
Reproduction
In getsentry/toolkit, where packages/logger has no preReleaseCommand, no logger@ tags, and package.json at 1.0.0-dev.0:
craft prepare minor --workspace packages/logger --dry-run --no-push --no-git-checks --no-changelog --rev HEAD
git status # packages/logger/package.json is now modified (1.0.0)
craft prepare patch --workspace packages/logger --dry-run --no-push --no-git-checks --no-changelog --rev HEAD
# computes 1.0.1 instead of 1.0.0, because the previous dry run changed the real package.jsonExpected: the checkout is untouched, and each dry run computes the same version.
Likely cause (from reading the source, not confirmed with a debugger)
prepareresolves config before isolation, sofindConfigFile()(src/config.ts) caches the original checkout's.craft.ymlpath in_configPathCache.createDryRunIsolation()(src/utils/dryRun.ts) adds the worktree, callsenableWorktreeMode(), andprocess.chdir(worktreePath).runPreReleaseCommand({ rootDir: getReleaseUnitDir() })(src/commands/prepare.ts):getReleaseUnitDir()→getConfigFileDir()→findConfigFile()returns the cached original path because it still exists. SorootDiris the original checkout's workspace directory, not the worktree.NpmTarget.bumpVersion(rootDir, …)runsnpm versionwithcwd: rootDir.spawnProcesslets it run becauseisInWorktreeMode()is true. So the realpackage.jsongets written.
A custom preReleaseCommand is likely unaffected, since it runs in process.cwd() (the worktree). Every automatic bumpVersion target that uses rootDir is probably affected, as is readProjectVersion (#947), though that one only reads. postReleaseBump (#950) only logs in dry-run mode.
Possible fix
Resolve the release unit directory against the worktree in dry-run mode. For example: clear _configPathCache when entering or leaving the worktree, or map getReleaseUnitDir() onto isolation.worktreePath, relative to the original config dir. Add a test where a dry-run automatic npm bump leaves the original package.json unchanged.
Found while moving getsentry/toolkit to Craft 3.7.0 (getsentry/toolkit#1731).
via @BYK.
--
Activity