@@ -15,7 +15,10 @@ const DEFAULT_CONTENT = require.resolve(NAME)
1515
1616const merge = withArrays ( 'branches' , 'distPaths' , 'allowPaths' , 'ignorePaths' )
1717
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 ) } **`
1922
2023const getCmdPath = ( key , { rootConfig, defaultConfig, isRoot, path, root } ) => {
2124 // Make a path relative from a workspace to the root if we are in a workspace
@@ -78,27 +81,27 @@ const getFiles = (path, rawConfig) => {
7881}
7982
8083const getFullConfig = async ( {
84+ // the path to the root of the repo
8185 root,
86+ // the path to the package being operated on
87+ // this is the same as root when operating on the root
8288 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}[]
8492 pkgs,
93+ // an array of all workspaces in this repo
8594 workspaces,
95+ // the config from the package.json in the root
8696 rootConfig : _rootConfig ,
97+ // the config from the package.json being operated on
8798 pkgConfig : _pkgConfig ,
8899} ) => {
89100 const isRoot = root === path
90- const isRootMono = isRoot && workspaces . length > 0
91101 const isLatest = _pkgConfig . version === LATEST_VERSION
92- const isDogFood = pkg . name === NAME
102+ const isDogFood = pkgJson . name === NAME
93103 const isForce = process . argv . includes ( '--force' )
94104
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-
102105 // These config items are merged betweent the root and child workspaces and only come from
103106 // the package.json because they can be used to read configs from other the content directories
104107 const mergedConfig = mergeConfigs ( _rootConfig , _pkgConfig )
@@ -112,6 +115,7 @@ const getFullConfig = async ({
112115
113116 // The content config only gets set from the package we are in, it doesn't inherit
114117 // anything from the root
118+ const rootPkgConfig = merge ( useDefault , rootConfig )
115119 const pkgConfig = merge ( useDefault , getConfig ( _pkgConfig . content , _pkgConfig ) )
116120 const [ pkgFiles , pkgDir ] = getFiles ( mergedConfig . content , mergedConfig )
117121
@@ -128,16 +132,24 @@ const getFullConfig = async ({
128132 ...isRoot ? [
129133 // in the root allow all repo files
130134 ...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 ) ) ,
135139 ] : [ ] ,
136140 ]
137141
142+ // root only configs
138143 const npmPath = getCmdPath ( 'npm' , { rootConfig, defaultConfig, isRoot, path, root } )
139144 const npxPath = getCmdPath ( 'npx' , { rootConfig, defaultConfig, isRoot, path, root } )
140145
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+
141153 // all derived keys
142154 const derived = {
143155 isRoot,
@@ -147,8 +159,8 @@ const getFullConfig = async ({
147159 // For these cases it is helpful to know if we are in a
148160 // monorepo since template-oss might be used only for
149161 // workspaces and not the root or vice versa.
150- isRootMono,
151- isMono : isRootMono || ! isRoot ,
162+ isRootMono : isRoot && ! ! workspaces . length ,
163+ isMono : ! ! workspaces . length ,
152164 // repo
153165 repoDir : root ,
154166 repoFiles,
@@ -158,13 +170,14 @@ const getFullConfig = async ({
158170 moduleFiles,
159171 applyModule : ! ! moduleFiles ,
160172 // 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 ) ,
168181 // booleans to control application of updates
169182 isForce,
170183 isDogFood,
@@ -175,6 +188,9 @@ const getFullConfig = async ({
175188 rootNpmPath : npmPath . root ,
176189 localNpmPath : npmPath . local ,
177190 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 ,
178194 // gitignore
179195 ignorePaths : [
180196 ...gitignore . sort ( [
@@ -185,7 +201,7 @@ const getFullConfig = async ({
185201 ] ) ,
186202 // these cant be sorted since they rely on order
187203 // to allow a previously ignored directoy
188- ...gitignore . allowDir ( workspaceDirs || [ ] ) ,
204+ ...isRoot ? gitignore . allowDir ( workspaces . map ( ( p ) => makePosix ( relative ( root , p ) ) ) ) : [ ] ,
189205 ] ,
190206 // needs update if we are dogfooding this repo, with force argv, or its
191207 // behind the current version
@@ -210,7 +226,7 @@ const getFullConfig = async ({
210226 derived . repository = {
211227 type : 'git' ,
212228 url : gitUrl ,
213- ...( pkgRelPath ? { directory : pkgRelPath } : { } ) ,
229+ ...( ! isRoot ? { directory : pkgPath } : { } ) ,
214230 }
215231 }
216232
0 commit comments