Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ignore ranges when snapshot versioning is performed (use exact versio…
…ns) (#857)

* bugfix: ignore ranges when snapshot versioning is performed (use exact version)

* cleanup

* fixes

* Apply suggestions from code review

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
dotansimha and Andarist committed Jul 4, 2022
1 parent 2827c7a commit 7febb59
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/stupid-jars-rest.md
@@ -0,0 +1,6 @@
---
"@changesets/cli": patch
"@changesets/apply-release-plan": patch
---

Fixed an issue with dependency ranges still using pre-existing range modifiers instead of fixed package versions when performing a snapshot release. This ensures that installs of snapshot versions are always reproducible.
50 changes: 49 additions & 1 deletion packages/apply-release-plan/src/index.test.ts
Expand Up @@ -74,6 +74,7 @@ async function testSetup(
fixtureName: string,
releasePlan: ReleasePlan,
config?: Config,
snapshot?: string | undefined,
setupFunc?: (tempDir: string) => Promise<any>
) {
if (!config) {
Expand Down Expand Up @@ -108,7 +109,8 @@ async function testSetup(
changedFiles: await applyReleasePlan(
releasePlan,
await getPackages(tempDir),
config
config,
snapshot
),
tempDir
};
Expand Down Expand Up @@ -653,6 +655,47 @@ describe("apply release plan", () => {
version: "1.0.0"
});
});
it("should use exact versioning when snapshot release is applied, and ignore any range modifiers", async () => {
const releasePlan = new FakeReleasePlan(
[
{
id: "some-id",
releases: [{ name: "pkg-b", type: "minor" }],
summary: "a very useful summary"
}
],
[
{
changesets: ["some-id"],
name: "pkg-b",
newVersion: "1.1.0",
oldVersion: "1.0.0",
type: "minor"
}
]
);
let { changedFiles } = await testSetup(
"simple-project-caret-dep",
releasePlan.getReleasePlan(),
releasePlan.config,
"canary"
);

let pkgPath = changedFiles.find(a =>
a.endsWith(`pkg-a${path.sep}package.json`)
);

if (!pkgPath) throw new Error(`could not find an updated package json`);
let pkgJSON = await fs.readJSON(pkgPath);

expect(pkgJSON).toMatchObject({
name: "pkg-a",
version: "1.1.0",
dependencies: {
"pkg-b": "1.1.0"
}
});
});

describe("internal dependency bumping", () => {
describe("updateInternalDependencies set to patch", () => {
Expand Down Expand Up @@ -2088,6 +2131,7 @@ describe("apply release plan", () => {
"simple-project",
releasePlan.getReleasePlan(),
releasePlan.config,
undefined,
setupFunc
);

Expand All @@ -2114,6 +2158,7 @@ describe("apply release plan", () => {
"simple-project",
releasePlan.getReleasePlan(),
{ ...releasePlan.config, ignore: ["pkg-a"] },
undefined,
setupFunc
);

Expand Down Expand Up @@ -2156,6 +2201,7 @@ describe("apply release plan", () => {
"simple-project",
releasePlan.getReleasePlan(),
releasePlan.config,
undefined,
setupFunc
);

Expand Down Expand Up @@ -2212,6 +2258,7 @@ describe("apply release plan", () => {
null
]
},
undefined,
setupFunc
);

Expand Down Expand Up @@ -2294,6 +2341,7 @@ describe("apply release plan", () => {
null
]
},
undefined,
setupFunc
);

Expand Down
3 changes: 2 additions & 1 deletion packages/apply-release-plan/src/index.ts
Expand Up @@ -117,7 +117,8 @@ export default async function applyReleasePlan(
config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH
.onlyUpdatePeerDependentsWhenOutOfRange,
bumpVersionsWithWorkspaceProtocolOnly:
config.bumpVersionsWithWorkspaceProtocolOnly
config.bumpVersionsWithWorkspaceProtocolOnly,
snapshot
});
});

Expand Down
9 changes: 6 additions & 3 deletions packages/apply-release-plan/src/version-package.ts
Expand Up @@ -24,11 +24,13 @@ export default function versionPackage(
{
updateInternalDependencies,
onlyUpdatePeerDependentsWhenOutOfRange,
bumpVersionsWithWorkspaceProtocolOnly
bumpVersionsWithWorkspaceProtocolOnly,
snapshot
}: {
updateInternalDependencies: "patch" | "minor";
onlyUpdatePeerDependentsWhenOutOfRange: boolean;
bumpVersionsWithWorkspaceProtocolOnly?: boolean;
snapshot?: string | boolean | undefined;
}
) {
let { newVersion, packageJson } = release;
Expand Down Expand Up @@ -91,8 +93,9 @@ export default function versionPackage(
// leaving those as is would leave the package in a non-installable state (wrong dep versions would get installed)
semver.prerelease(version) !== null
) {
let rangeType = getVersionRangeType(depCurrentVersion);
let newNewRange = `${rangeType}${version}`;
let newNewRange = snapshot
? version
: `${getVersionRangeType(depCurrentVersion)}${version}`;
if (usesWorkspaceRange) newNewRange = `workspace:${newNewRange}`;
deps[name] = newNewRange;
}
Expand Down

0 comments on commit 7febb59

Please sign in to comment.