@@ -5,7 +5,8 @@ import fetch from "node-fetch";
5
5
import { safeLoad } from "js-yaml" ;
6
6
import { Packages , Tool } from "@manypkg/get-packages" ;
7
7
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" ;
9
10
import parseChangeset from "@changesets/parse" ;
10
11
11
12
type Sha = string & { ___sha : string } ;
@@ -16,7 +17,7 @@ export let getChangedPackages = async ({
16
17
ref,
17
18
changedFiles : changedFilesPromise ,
18
19
octokit,
19
- installationToken
20
+ installationToken,
20
21
} : {
21
22
owner : string ;
22
23
repo : string ;
@@ -35,16 +36,16 @@ export let getChangedPackages = async ({
35
36
`https://raw.githubusercontent.com/${ owner } /${ repo } /${ ref } /${ path } ` ,
36
37
{
37
38
headers : {
38
- Authorization : `Basic ${ encodedCredentials } `
39
- }
39
+ Authorization : `Basic ${ encodedCredentials } ` ,
40
+ } ,
40
41
}
41
42
) ;
42
43
}
43
44
44
45
function fetchJsonFile ( path : string ) {
45
46
return fetchFile ( path )
46
- . then ( x => x . json ( ) )
47
- . catch ( err => {
47
+ . then ( ( x ) => x . json ( ) )
48
+ . catch ( ( err ) => {
48
49
hasErrored = true ;
49
50
console . error ( err ) ;
50
51
return { } ;
@@ -53,8 +54,8 @@ export let getChangedPackages = async ({
53
54
54
55
function fetchTextFile ( path : string ) {
55
56
return fetchFile ( path )
56
- . then ( x => x . text ( ) )
57
- . catch ( err => {
57
+ . then ( ( x ) => x . text ( ) )
58
+ . catch ( ( err ) => {
58
59
hasErrored = true ;
59
60
console . error ( err ) ;
60
61
return "" ;
@@ -65,18 +66,18 @@ export let getChangedPackages = async ({
65
66
let jsonContent = await fetchJsonFile ( pkgPath + "/package.json" ) ;
66
67
return {
67
68
packageJson : jsonContent ,
68
- dir : pkgPath
69
+ dir : pkgPath ,
69
70
} ;
70
71
}
71
72
72
73
let rootPackageJsonContentsPromise = fetchJsonFile ( "package.json" ) ;
73
- let configPromise : Promise < Config > = fetchJsonFile ( ".changeset/config.json" ) ;
74
+ let configPromise : Promise < any > = fetchJsonFile ( ".changeset/config.json" ) ;
74
75
75
76
let tree = await octokit . git . getTree ( {
76
77
owner,
77
78
repo,
78
79
recursive : "1" ,
79
- tree_sha : ref
80
+ tree_sha : ref ,
80
81
} ) ;
81
82
82
83
let preStatePromise : Promise < PreState > | undefined ;
@@ -107,7 +108,7 @@ export let getChangedPackages = async ({
107
108
}
108
109
let id = res [ 1 ] ;
109
110
changesetPromises . push (
110
- fetchTextFile ( item . path ) . then ( text => {
111
+ fetchTextFile ( item . path ) . then ( ( text ) => {
111
112
return { ...parseChangeset ( text ) , id } ;
112
113
} )
113
114
) ;
@@ -123,7 +124,7 @@ export let getChangedPackages = async ({
123
124
if ( isPnpm ) {
124
125
tool = {
125
126
tool : "pnpm" ,
126
- globs : safeLoad ( await fetchTextFile ( "pnpm-workspace.yaml" ) ) . packages
127
+ globs : safeLoad ( await fetchTextFile ( "pnpm-workspace.yaml" ) ) . packages ,
127
128
} ;
128
129
} else {
129
130
let rootPackageJsonContent = await rootPackageJsonContentsPromise ;
@@ -132,12 +133,12 @@ export let getChangedPackages = async ({
132
133
if ( ! Array . isArray ( rootPackageJsonContent . workspaces ) ) {
133
134
tool = {
134
135
tool : "yarn" ,
135
- globs : rootPackageJsonContent . workspaces . packages
136
+ globs : rootPackageJsonContent . workspaces . packages ,
136
137
} ;
137
138
} else {
138
139
tool = {
139
140
tool : "yarn" ,
140
- globs : rootPackageJsonContent . workspaces
141
+ globs : rootPackageJsonContent . workspaces ,
141
142
} ;
142
143
}
143
144
} else if (
@@ -146,14 +147,17 @@ export let getChangedPackages = async ({
146
147
) {
147
148
tool = {
148
149
tool : "bolt" ,
149
- globs : rootPackageJsonContent . bolt . workspaces
150
+ globs : rootPackageJsonContent . bolt . workspaces ,
150
151
} ;
151
152
}
152
153
}
153
154
154
155
if (
155
156
! 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
+ )
157
161
) {
158
162
throw new Error ( "globs are not valid" ) ;
159
163
}
@@ -163,16 +167,18 @@ export let getChangedPackages = async ({
163
167
let packages : Packages = {
164
168
root : {
165
169
dir : "/" ,
166
- packageJson : rootPackageJsonContent
170
+ packageJson : rootPackageJsonContent ,
167
171
} ,
168
172
tool : tool . tool ,
169
- packages : [ ]
173
+ packages : [ ] ,
170
174
} ;
171
175
172
176
if ( tool ) {
173
177
let matches = micromatch ( potentialWorkspaceDirectories , tool . globs ) ;
174
178
175
- packages . packages = await Promise . all ( matches . map ( dir => getPackage ( dir ) ) ) ;
179
+ packages . packages = await Promise . all (
180
+ matches . map ( ( dir ) => getPackage ( dir ) )
181
+ ) ;
176
182
} else {
177
183
packages . packages . push ( packages . root ) ;
178
184
}
@@ -183,16 +189,16 @@ export let getChangedPackages = async ({
183
189
const releasePlan = assembleReleasePlan (
184
190
await Promise . all ( changesetPromises ) ,
185
191
packages ,
186
- await configPromise ,
192
+ await configPromise . then ( ( rawConfig ) => parseConfig ( rawConfig , packages ) ) ,
187
193
await preStatePromise
188
194
) ;
189
195
190
196
return {
191
197
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 ) )
194
200
)
195
- . map ( x => x . packageJson . name ) ,
196
- releasePlan
201
+ . map ( ( x ) => x . packageJson . name ) ,
202
+ releasePlan,
197
203
} ;
198
204
} ;
0 commit comments