Skip to content

Commit

Permalink
Don't update ranges set to */x/X when versioning (#205)
Browse files Browse the repository at this point in the history
* Don't update ranges set to */x/X when versioning

* maybe i should actually listen to eslint sometimes

* a thing didn't need to be async

* Add a test
  • Loading branch information
emmatown committed Oct 26, 2019
1 parent 003db6b commit da11ab8
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/rich-rules-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/apply-release-plan": patch
"@changesets/cli": patch
---

Don't update ranges set to \*/x/X when versioning
3 changes: 3 additions & 0 deletions __fixtures__/simple-star-dep/.changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# We just want a file in here so git collects it

For this we have deliberately not included a config file, as we want to test the defaults
1 change: 1 addition & 0 deletions __fixtures__/simple-star-dep/.changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 11 additions & 0 deletions __fixtures__/simple-star-dep/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"name": "simple-project",
"description": "three projects, each depending on one other",
"version": "1.0.0",
"bolt": {
"workspaces": [
"packages/*"
]
}
}
7 changes: 7 additions & 0 deletions __fixtures__/simple-star-dep/packages/pkg-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "pkg-a",
"version": "1.0.0",
"dependencies": {
"pkg-b": "*"
}
}
4 changes: 4 additions & 0 deletions __fixtures__/simple-star-dep/packages/pkg-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "pkg-b",
"version": "1.0.0"
}
3 changes: 2 additions & 1 deletion packages/apply-release-plan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"lodash.startcase": "^4.4.0",
"outdent": "^0.5.0",
"prettier": "^1.14.3",
"resolve-from": "^5.0.0"
"resolve-from": "^5.0.0",
"semver": "^5.4.1"
},
"devDependencies": {
"jest-fixtures": "^0.5.0",
Expand Down
37 changes: 37 additions & 0 deletions packages/apply-release-plan/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,43 @@ describe("apply release plan", () => {
version: "1.1.0"
});
});
it("should not update ranges set to *", 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-star-dep",
releasePlan.getReleasePlan(),
releasePlan.config
);
let pkgPath = changedFiles.find(a => a.endsWith("pkg-a/package.json"));

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

expect(pkgJSON).toEqual({
name: "pkg-a",
version: "1.1.0",
dependencies: {
"pkg-b": "*"
}
});
});
it("should update a version for two packages with different new versions", async () => {
const releasePlan = new FakeReleasePlan();
releasePlan.releases = [
Expand Down
8 changes: 3 additions & 5 deletions packages/apply-release-plan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ export default async function applyReleasePlan(
);

// iterate over releases updating packages
let finalisedRelease = await Promise.all(
releaseWithChangelogs.map(release => {
return versionPackage(release, versionsToUpdate);
})
);
let finalisedRelease = releaseWithChangelogs.map(release => {
return versionPackage(release, versionsToUpdate);
});

let prettierConfig = await prettier.resolveConfig(cwd);

Expand Down
25 changes: 16 additions & 9 deletions packages/apply-release-plan/src/version-package.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComprehensiveRelease, PackageJSON } from "@changesets/types";
import getVersionRangeType from "@changesets/get-version-range-type";
import { Range } from "semver";

const DEPENDENCY_TYPES = [
"dependencies",
Expand All @@ -8,7 +9,7 @@ const DEPENDENCY_TYPES = [
"optionalDependencies"
] as const;

export default async function versionPackage(
export default function versionPackage(
release: ComprehensiveRelease & {
changelog: string | null;
config: PackageJSON;
Expand All @@ -21,17 +22,23 @@ export default async function versionPackage(
config.version = newVersion;

for (let type of DEPENDENCY_TYPES) {
if (config[type]) {
versionsToUpdate.forEach(({ name, version }) => {
// @ts-ignore I shan't be having with this config[type] might be undefined nonsense
let depCurrentVersion = config[type][name];
if (depCurrentVersion) {
let deps = config[type];
if (deps) {
for (let { name, version } of versionsToUpdate) {
let depCurrentVersion = deps[name];
if (
depCurrentVersion &&
// an empty string is the normalised version of x/X/*
// we don't want to change these versions because they will match
// any version and if someone makes the range that
// they probably want it to stay like that
new Range(depCurrentVersion).range !== ""
) {
let rangeType = getVersionRangeType(depCurrentVersion);
let newNewRange = `${rangeType}${version}`;
// @ts-ignore I shan't be having with this config[type] might be undefined nonsense
config[type][name] = newNewRange;
deps[name] = newNewRange;
}
});
}
}
}

Expand Down

0 comments on commit da11ab8

Please sign in to comment.