@@ -15,7 +15,10 @@ const DEFAULT_CONTENT = require.resolve(NAME)
15
15
16
16
const merge = withArrays ( 'branches' , 'distPaths' , 'allowPaths' , 'ignorePaths' )
17
17
18
- const makePosix = ( str ) => str . split ( win32 . sep ) . join ( posix . sep )
18
+ const makePosix = ( v ) => v . split ( win32 . sep ) . join ( posix . sep )
19
+ const deglob = ( v ) => makePosix ( v ) . replace ( / [ / * ] + $ / , '' )
20
+ const posixDir = ( v ) => `${ v === '.' ? '' : deglob ( v ) . replace ( / \/ $ / , '' ) } ${ posix . sep } `
21
+ const posixGlob = ( str ) => `${ posixDir ( str ) } **`
19
22
20
23
const getCmdPath = ( key , { rootConfig, defaultConfig, isRoot, path, root } ) => {
21
24
// Make a path relative from a workspace to the root if we are in a workspace
@@ -78,27 +81,27 @@ const getFiles = (path, rawConfig) => {
78
81
}
79
82
80
83
const getFullConfig = async ( {
84
+ // the path to the root of the repo
81
85
root,
86
+ // the path to the package being operated on
87
+ // this is the same as root when operating on the root
82
88
path,
83
- pkg,
89
+ // the full contents of the package.json for this package
90
+ pkgJson,
91
+ // an array of all package info {pkgJson,path,config}[]
84
92
pkgs,
93
+ // an array of all workspaces in this repo
85
94
workspaces,
95
+ // the config from the package.json in the root
86
96
rootConfig : _rootConfig ,
97
+ // the config from the package.json being operated on
87
98
pkgConfig : _pkgConfig ,
88
99
} ) => {
89
100
const isRoot = root === path
90
- const isRootMono = isRoot && workspaces . length > 0
91
101
const isLatest = _pkgConfig . version === LATEST_VERSION
92
- const isDogFood = pkg . name === NAME
102
+ const isDogFood = pkgJson . name === NAME
93
103
const isForce = process . argv . includes ( '--force' )
94
104
95
- // this is written to ci yml files so it needs to always use posix
96
- const pkgRelPath = makePosix ( relative ( root , path ) )
97
-
98
- const workspacePkgs = pkgs . filter ( ( p ) => p . path !== path )
99
- const workspaceDirs = isRootMono && workspaces . map ( ( p ) => makePosix ( relative ( root , p ) ) )
100
- const workspaceGlobs = isRootMono && pkg . workspaces . map ( p => p . replace ( / [ / * ] + $ / , '' ) )
101
-
102
105
// These config items are merged betweent the root and child workspaces and only come from
103
106
// the package.json because they can be used to read configs from other the content directories
104
107
const mergedConfig = mergeConfigs ( _rootConfig , _pkgConfig )
@@ -112,6 +115,7 @@ const getFullConfig = async ({
112
115
113
116
// The content config only gets set from the package we are in, it doesn't inherit
114
117
// anything from the root
118
+ const rootPkgConfig = merge ( useDefault , rootConfig )
115
119
const pkgConfig = merge ( useDefault , getConfig ( _pkgConfig . content , _pkgConfig ) )
116
120
const [ pkgFiles , pkgDir ] = getFiles ( mergedConfig . content , mergedConfig )
117
121
@@ -128,16 +132,24 @@ const getFullConfig = async ({
128
132
...isRoot ? [
129
133
// in the root allow all repo files
130
134
...getAddedFiles ( repoFiles ) ,
131
- // and allow all workspace repo level files
132
- ...workspacePkgs . filter ( p => p . config . workspaceRepo !== false ) . flatMap ( ( p ) =>
133
- getAddedFiles ( files . workspaceRepo )
134
- ) ,
135
+ // and allow all workspace repo level files in the root
136
+ ...pkgs
137
+ . filter ( p => p . path !== root && p . config . workspaceRepo !== false )
138
+ . flatMap ( ( ) => getAddedFiles ( files . workspaceRepo ) ) ,
135
139
] : [ ] ,
136
140
]
137
141
142
+ // root only configs
138
143
const npmPath = getCmdPath ( 'npm' , { rootConfig, defaultConfig, isRoot, path, root } )
139
144
const npxPath = getCmdPath ( 'npx' , { rootConfig, defaultConfig, isRoot, path, root } )
140
145
146
+ // these are written to ci yml files so it needs to always use posix
147
+ const pkgPath = makePosix ( relative ( root , path ) ) || '.'
148
+
149
+ // we use the raw paths from the package.json workspaces as ignore patterns in
150
+ // some cases. the workspaces passed in have already been run through map workspaces
151
+ const workspacePaths = ( pkgJson . workspaces || [ ] ) . map ( deglob )
152
+
141
153
// all derived keys
142
154
const derived = {
143
155
isRoot,
@@ -147,8 +159,8 @@ const getFullConfig = async ({
147
159
// For these cases it is helpful to know if we are in a
148
160
// monorepo since template-oss might be used only for
149
161
// workspaces and not the root or vice versa.
150
- isRootMono,
151
- isMono : isRootMono || ! isRoot ,
162
+ isRootMono : isRoot && ! ! workspaces . length ,
163
+ isMono : ! ! workspaces . length ,
152
164
// repo
153
165
repoDir : root ,
154
166
repoFiles,
@@ -158,13 +170,14 @@ const getFullConfig = async ({
158
170
moduleFiles,
159
171
applyModule : ! ! moduleFiles ,
160
172
// package
161
- pkgName : pkg . name ,
162
- pkgNameFs : pkg . name . replace ( / \/ / g, '-' ) . replace ( / @ / g, '' ) ,
163
- pkgRelPath : pkgRelPath ,
164
- pkgPrivate : ! ! pkg . private ,
165
- pkgPublic : ! pkg . private ,
166
- workspaces : workspaceDirs ,
167
- workspaceGlobs,
173
+ pkgName : pkgJson . name ,
174
+ pkgNameFs : pkgJson . name . replace ( / \/ / g, '-' ) . replace ( / @ / g, '' ) ,
175
+ // paths
176
+ pkgPath,
177
+ pkgDir : posixDir ( pkgPath ) ,
178
+ pkgGlob : posixGlob ( pkgPath ) ,
179
+ workspacePaths,
180
+ workspaceGlobs : workspacePaths . map ( posixGlob ) ,
168
181
// booleans to control application of updates
169
182
isForce,
170
183
isDogFood,
@@ -175,6 +188,9 @@ const getFullConfig = async ({
175
188
rootNpmPath : npmPath . root ,
176
189
localNpmPath : npmPath . local ,
177
190
rootNpxPath : npxPath . root ,
191
+ // lockfiles are only present at the root, so this only should be set for
192
+ // all workspaces based on the root
193
+ lockfile : rootPkgConfig . lockfile ,
178
194
// gitignore
179
195
ignorePaths : [
180
196
...gitignore . sort ( [
@@ -185,7 +201,7 @@ const getFullConfig = async ({
185
201
] ) ,
186
202
// these cant be sorted since they rely on order
187
203
// to allow a previously ignored directoy
188
- ...gitignore . allowDir ( workspaceDirs || [ ] ) ,
204
+ ...isRoot ? gitignore . allowDir ( workspaces . map ( ( p ) => makePosix ( relative ( root , p ) ) ) ) : [ ] ,
189
205
] ,
190
206
// needs update if we are dogfooding this repo, with force argv, or its
191
207
// behind the current version
@@ -210,7 +226,7 @@ const getFullConfig = async ({
210
226
derived . repository = {
211
227
type : 'git' ,
212
228
url : gitUrl ,
213
- ...( pkgRelPath ? { directory : pkgRelPath } : { } ) ,
229
+ ...( ! isRoot ? { directory : pkgPath } : { } ) ,
214
230
}
215
231
}
216
232
0 commit comments