@@ -19,7 +19,16 @@ const DEFAULT_CONTENT = require.resolve(NAME)
1919const getPkgConfig = ( pkg ) => pkg [ CONFIG_KEY ] || { }
2020
2121const merge = mergeWithCustomizers (
22- customizers . mergeArrays ( 'branches' , 'distPaths' , 'allowPaths' , 'ignorePaths' ) ,
22+ customizers . mergeArrays (
23+ 'branches' ,
24+ 'distPaths' ,
25+ 'allowPaths' ,
26+ 'ignorePaths' ,
27+ 'lintIgnorePaths' ,
28+ 'lintExtensions' ,
29+ 'formatIgnorePaths' ,
30+ 'formatExtensions'
31+ ) ,
2332 ( value , srcValue , key ) => {
2433 if ( key === 'ciVersions' && ( Array . isArray ( srcValue ) || isPlainObject ( srcValue ) ) ) {
2534 return { ...ciVersions . parse ( value ) , ...ciVersions . parse ( srcValue ) }
@@ -196,17 +205,42 @@ const getFullConfig = async ({
196205 pkgConfig . requiredPackages . devDependencies . filter ( p => ! p . includes ( 'eslint' ) )
197206 }
198207
208+ pkgConfig . lintIgnorePaths = [
209+ ...( pkgConfig . ignorePaths || [ ] ) ,
210+ ...( pkgConfig . lintIgnorePaths || [ ] ) ,
211+ ...derived . workspaceGlobs ,
212+ ]
213+
214+ pkgConfig . formatIgnorePaths = [
215+ ...( pkgConfig . ignorePaths || [ ] ) ,
216+ ...( pkgConfig . formatIgnorePaths || [ ] ) ,
217+ ...derived . workspaceGlobs ,
218+ ]
219+
199220 if ( pkgConfig . typescript ) {
200221 defaultsDeep ( pkgConfig , { allowPaths : [ ] , requiredPackages : { devDependencies : [ ] } } )
201222 pkgConfig . distPaths = [ 'dist/' ]
223+ pkgConfig . lintIgnorePaths = uniq ( [ ...pkgConfig . lintIgnorePaths , 'dist/' ] )
224+ pkgConfig . formatIgnorePaths = uniq ( [ ...pkgConfig . formatIgnorePaths , 'dist/' ] )
202225 pkgConfig . allowDistPaths = false
203- pkgConfig . allowPaths . push ( '/src/' )
204- pkgConfig . requiredPackages . devDependencies . push (
226+ pkgConfig . allowPaths = uniq ( [ ...pkgConfig . allowPaths , '/src/' ] )
227+ pkgConfig . requiredPackages . devDependencies = uniq ( [
228+ ...pkgConfig . requiredPackages . devDependencies ,
205229 'typescript' ,
206230 'tshy' ,
207231 '@typescript-eslint/parser' ,
208- ...derived . tap16 ? [ 'c8' , 'ts-node' ] : [ ]
209- )
232+ ...derived . tap16 ? [ 'c8' , 'ts-node' ] : [ ] ,
233+ ] )
234+ }
235+
236+ if ( pkgConfig . prettier ) {
237+ defaultsDeep ( pkgConfig , { requiredPackages : { devDependencies : [ ] } } )
238+ pkgConfig . requiredPackages . devDependencies = uniq ( [
239+ ...pkgConfig . requiredPackages . devDependencies ,
240+ 'prettier' ,
241+ 'eslint-config-prettier' ,
242+ '@github/prettier-config' ,
243+ ] )
210244 }
211245
212246 const gitUrl = await git . getUrl ( rootPkg . path )
@@ -238,24 +272,47 @@ const getFullConfig = async ({
238272 applyRepo : ! ! repoFiles ,
239273 applyModule : ! ! moduleFiles ,
240274 __PARTIAL_DIRS__ : fileDirs ,
275+ } )
276+
277+ const ignoreAddedPaths = gitignore . sort ( [
278+ ...gitignore . allowRootDir ( [
279+ // Allways allow module files in root or workspaces
280+ ...getAddedFiles ( moduleFiles ) . map ( s => template ( s , fullConfig ) ) ,
281+ ...( isRoot
282+ ? [
283+ // in the root allow all repo files
284+ ...getAddedFiles ( repoFiles ) . map ( s => template ( s , fullConfig ) ) ,
285+ // and allow all workspace repo level files in the root
286+ ...pkgs
287+ . filter ( p => p . path !== rootPkg . path && p . config . workspaceRepo !== false )
288+ . flatMap ( ( ) => getAddedFiles ( files . workspaceRepo ) ) ,
289+ ]
290+ : [ ] ) ,
291+ ] ) ,
292+ ...( isRoot && pkgConfig . lockfile ? [ '!/package-lock.json' ] : [ ] ) ,
293+ ] )
294+
295+ Object . assign ( fullConfig , {
296+ // Make sure we don't format any files that are being generated since they will cause template-oss-check to fail
297+ // This could be changed if those files were also formatted before save but then we would need to read generated
298+ // the prettier config first and use that as the formatting rules which would get weird
299+ formatIgnorePaths : [
300+ ...fullConfig . formatIgnorePaths ,
301+ ...ignoreAddedPaths
302+ . filter ( f => f . startsWith ( '!' ) )
303+ . map ( f => f . replace ( / ^ ! / , '' ) )
304+ . filter ( f => {
305+ const ext = extname ( f ) . slice ( 1 )
306+ // ignore it if the specified format extensions match or if its a directory
307+ return ( fullConfig . formatExtensions || [ ] ) . includes ( ext ) || ( ! ext && f . endsWith ( '/' ) )
308+ } ) ,
309+ ] ,
241310 // gitignore, these use the full config so need to come at the very end
242311 ignorePaths : [
243312 ...gitignore . sort ( [
244- ...gitignore . allowRootDir ( [
245- // Allways allow module files in root or workspaces
246- ...getAddedFiles ( moduleFiles ) . map ( s => template ( s , fullConfig ) ) ,
247- ...isRoot ? [
248- // in the root allow all repo files
249- ...getAddedFiles ( repoFiles ) . map ( s => template ( s , fullConfig ) ) ,
250- // and allow all workspace repo level files in the root
251- ...pkgs
252- . filter ( p => p . path !== rootPkg . path && p . config . workspaceRepo !== false )
253- . flatMap ( ( ) => getAddedFiles ( files . workspaceRepo ) ) ,
254- ] : [ ] ,
255- ] ) ,
256- ...isRoot && pkgConfig . lockfile ? [ '!/package-lock.json' ] : [ ] ,
257- ...( pkgConfig . allowPaths || [ ] ) . map ( ( p ) => `!${ p } ` ) ,
258- ...( pkgConfig . allowDistPaths ? pkgConfig . distPaths : [ ] ) . map ( ( p ) => `!/${ p } ` ) ,
313+ ...ignoreAddedPaths ,
314+ ...( pkgConfig . allowPaths || [ ] ) . map ( p => `!${ p } ` ) ,
315+ ...( pkgConfig . allowDistPaths ? pkgConfig . distPaths : [ ] ) . map ( p => `!/${ p } ` ) ,
259316 ...( pkgConfig . ignorePaths || [ ] ) ,
260317 ] ) ,
261318 // these cant be sorted since they rely on order
0 commit comments