Skip to content

Commit 3d4e927

Browse files
authored
Fix getting changed packages (changesets#20)
1 parent c1d585f commit 3d4e927

File tree

3 files changed

+48
-42
lines changed

3 files changed

+48
-42
lines changed

get-changed-packages.ts

+31-25
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import fetch from "node-fetch";
55
import { safeLoad } from "js-yaml";
66
import { Packages, Tool } from "@manypkg/get-packages";
77
import assembleReleasePlan from "@changesets/assemble-release-plan";
8-
import { PreState, Config, NewChangeset } from "@changesets/types";
8+
import { parse as parseConfig } from "@changesets/config";
9+
import { PreState, NewChangeset } from "@changesets/types";
910
import parseChangeset from "@changesets/parse";
1011

1112
type Sha = string & { ___sha: string };
@@ -16,7 +17,7 @@ export let getChangedPackages = async ({
1617
ref,
1718
changedFiles: changedFilesPromise,
1819
octokit,
19-
installationToken
20+
installationToken,
2021
}: {
2122
owner: string;
2223
repo: string;
@@ -35,16 +36,16 @@ export let getChangedPackages = async ({
3536
`https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${path}`,
3637
{
3738
headers: {
38-
Authorization: `Basic ${encodedCredentials}`
39-
}
39+
Authorization: `Basic ${encodedCredentials}`,
40+
},
4041
}
4142
);
4243
}
4344

4445
function fetchJsonFile(path: string) {
4546
return fetchFile(path)
46-
.then(x => x.json())
47-
.catch(err => {
47+
.then((x) => x.json())
48+
.catch((err) => {
4849
hasErrored = true;
4950
console.error(err);
5051
return {};
@@ -53,8 +54,8 @@ export let getChangedPackages = async ({
5354

5455
function fetchTextFile(path: string) {
5556
return fetchFile(path)
56-
.then(x => x.text())
57-
.catch(err => {
57+
.then((x) => x.text())
58+
.catch((err) => {
5859
hasErrored = true;
5960
console.error(err);
6061
return "";
@@ -65,18 +66,18 @@ export let getChangedPackages = async ({
6566
let jsonContent = await fetchJsonFile(pkgPath + "/package.json");
6667
return {
6768
packageJson: jsonContent,
68-
dir: pkgPath
69+
dir: pkgPath,
6970
};
7071
}
7172

7273
let rootPackageJsonContentsPromise = fetchJsonFile("package.json");
73-
let configPromise: Promise<Config> = fetchJsonFile(".changeset/config.json");
74+
let configPromise: Promise<any> = fetchJsonFile(".changeset/config.json");
7475

7576
let tree = await octokit.git.getTree({
7677
owner,
7778
repo,
7879
recursive: "1",
79-
tree_sha: ref
80+
tree_sha: ref,
8081
});
8182

8283
let preStatePromise: Promise<PreState> | undefined;
@@ -107,7 +108,7 @@ export let getChangedPackages = async ({
107108
}
108109
let id = res[1];
109110
changesetPromises.push(
110-
fetchTextFile(item.path).then(text => {
111+
fetchTextFile(item.path).then((text) => {
111112
return { ...parseChangeset(text), id };
112113
})
113114
);
@@ -123,7 +124,7 @@ export let getChangedPackages = async ({
123124
if (isPnpm) {
124125
tool = {
125126
tool: "pnpm",
126-
globs: safeLoad(await fetchTextFile("pnpm-workspace.yaml")).packages
127+
globs: safeLoad(await fetchTextFile("pnpm-workspace.yaml")).packages,
127128
};
128129
} else {
129130
let rootPackageJsonContent = await rootPackageJsonContentsPromise;
@@ -132,12 +133,12 @@ export let getChangedPackages = async ({
132133
if (!Array.isArray(rootPackageJsonContent.workspaces)) {
133134
tool = {
134135
tool: "yarn",
135-
globs: rootPackageJsonContent.workspaces.packages
136+
globs: rootPackageJsonContent.workspaces.packages,
136137
};
137138
} else {
138139
tool = {
139140
tool: "yarn",
140-
globs: rootPackageJsonContent.workspaces
141+
globs: rootPackageJsonContent.workspaces,
141142
};
142143
}
143144
} else if (
@@ -146,14 +147,17 @@ export let getChangedPackages = async ({
146147
) {
147148
tool = {
148149
tool: "bolt",
149-
globs: rootPackageJsonContent.bolt.workspaces
150+
globs: rootPackageJsonContent.bolt.workspaces,
150151
};
151152
}
152153
}
153154

154155
if (
155156
!tool ||
156-
!(Array.isArray(tool.globs) && tool.globs.every(x => typeof x === "string"))
157+
!(
158+
Array.isArray(tool.globs) &&
159+
tool.globs.every((x) => typeof x === "string")
160+
)
157161
) {
158162
throw new Error("globs are not valid");
159163
}
@@ -163,16 +167,18 @@ export let getChangedPackages = async ({
163167
let packages: Packages = {
164168
root: {
165169
dir: "/",
166-
packageJson: rootPackageJsonContent
170+
packageJson: rootPackageJsonContent,
167171
},
168172
tool: tool.tool,
169-
packages: []
173+
packages: [],
170174
};
171175

172176
if (tool) {
173177
let matches = micromatch(potentialWorkspaceDirectories, tool.globs);
174178

175-
packages.packages = await Promise.all(matches.map(dir => getPackage(dir)));
179+
packages.packages = await Promise.all(
180+
matches.map((dir) => getPackage(dir))
181+
);
176182
} else {
177183
packages.packages.push(packages.root);
178184
}
@@ -183,16 +189,16 @@ export let getChangedPackages = async ({
183189
const releasePlan = assembleReleasePlan(
184190
await Promise.all(changesetPromises),
185191
packages,
186-
await configPromise,
192+
await configPromise.then((rawConfig) => parseConfig(rawConfig, packages)),
187193
await preStatePromise
188194
);
189195

190196
return {
191197
changedPackages: packages.packages
192-
.filter(pkg =>
193-
changedFiles.some(changedFile => changedFile.includes(pkg.dir))
198+
.filter((pkg) =>
199+
changedFiles.some((changedFile) => changedFile.includes(pkg.dir))
194200
)
195-
.map(x => x.packageJson.name),
196-
releasePlan
201+
.map((x) => x.packageJson.name),
202+
releasePlan,
197203
};
198204
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"repository": "https://github.com/changesets/bot",
77
"homepage": "https://github.com/apps/changeset-bot",
88
"dependencies": {
9-
"@changesets/assemble-release-plan": "^3.0.0",
9+
"@changesets/assemble-release-plan": "^4.0.0",
1010
"@changesets/config": "^1.3.0",
1111
"@changesets/parse": "^0.3.6",
12-
"@changesets/types": "^3.1.0",
12+
"@changesets/types": "^3.1.1",
1313
"@manypkg/get-packages": "^1.1.0",
1414
"@types/bunyan": "^1.8.6",
1515
"@types/express": "^4.17.2",

yarn.lock

+15-15
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@
9797
dependencies:
9898
"@babel/helper-plugin-utils" "^7.0.0"
9999

100-
"@babel/runtime@^7.4.4":
101-
version "7.8.4"
102-
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.4.tgz#d79f5a2040f7caa24d53e563aad49cbc05581308"
103-
integrity sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==
100+
"@babel/runtime@^7.10.4":
101+
version "7.11.2"
102+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.11.2.tgz#f549c13c754cc40b87644b9fa9f09a6a95fe0736"
103+
integrity sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw==
104104
dependencies:
105-
regenerator-runtime "^0.13.2"
105+
regenerator-runtime "^0.13.4"
106106

107107
"@babel/runtime@^7.5.5":
108108
version "7.8.7"
@@ -144,12 +144,12 @@
144144
lodash "^4.17.13"
145145
to-fast-properties "^2.0.0"
146146

147-
"@changesets/assemble-release-plan@^3.0.0":
148-
version "3.0.0"
149-
resolved "https://registry.yarnpkg.com/@changesets/assemble-release-plan/-/assemble-release-plan-3.0.0.tgz#23c280b0ea352003302b0c262b8dadb8bda517ed"
150-
integrity sha512-TvcqUhNhKoqwE+L8dFtcwwAmos4+fqwmSkOWP3TSjw7K/inz2wjC46bA7IFtbx2hrwEq1iG0RCweQZTS2vrx1w==
147+
"@changesets/assemble-release-plan@^4.0.0":
148+
version "4.0.0"
149+
resolved "https://registry.yarnpkg.com/@changesets/assemble-release-plan/-/assemble-release-plan-4.0.0.tgz#60c2392c0e2c99f24778ab3a5c8e8c80ddaaaa59"
150+
integrity sha512-3Kv21FNvysTQvZs3fHr6aZeDibhZHtgI1++fMZplzVtwNVmpjow3zv9lcZmJP26LthbpVH3I8+nqlU7M43lfWA==
151151
dependencies:
152-
"@babel/runtime" "^7.4.4"
152+
"@babel/runtime" "^7.10.4"
153153
"@changesets/errors" "^0.1.4"
154154
"@changesets/get-dependents-graph" "^1.1.3"
155155
"@changesets/types" "^3.1.0"
@@ -206,6 +206,11 @@
206206
resolved "https://registry.yarnpkg.com/@changesets/types/-/types-3.1.0.tgz#68957af45a0be29f0908e20a990ecf382282e1f1"
207207
integrity sha512-czOfaaxr5aGnNwVRgWr3n2CKoc3iRTfrHM4wUHQ+rBlLKKk9NzGwZ2EPsXkp4CUw4hWHGEOi8hdeIfDTWKrWgg==
208208

209+
"@changesets/types@^3.1.1":
210+
version "3.1.1"
211+
resolved "https://registry.yarnpkg.com/@changesets/types/-/types-3.1.1.tgz#447481380c42044a8788e46c0dbdf592b338b62f"
212+
integrity sha512-XWGEGWXhM92zvBWiQt2sOwhjTt8eCQbrsRbqkv4WYwW3Zsl4qPpvhHsNt845S42dJXrxgjWvId+jxFQocCayNQ==
213+
209214
"@cnakazawa/watch@^1.0.3":
210215
version "1.0.3"
211216
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef"
@@ -4138,11 +4143,6 @@ redis-parser@^3.0.0:
41384143
dependencies:
41394144
redis-errors "^1.0.0"
41404145

4141-
regenerator-runtime@^0.13.2:
4142-
version "0.13.3"
4143-
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5"
4144-
integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==
4145-
41464146
regenerator-runtime@^0.13.4:
41474147
version "0.13.4"
41484148
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.4.tgz#e96bf612a3362d12bb69f7e8f74ffeab25c7ac91"

0 commit comments

Comments
 (0)