@@ -3,6 +3,7 @@ import fs from "node:fs";
33import { TemplatePath , isPlainObject } from "@11ty/eleventy-utils" ;
44import debugUtil from "debug" ;
55
6+ import DirContains from "./Util/DirContains.js" ;
67import TemplateData from "./Data/TemplateData.js" ;
78import TemplateGlob from "./TemplateGlob.js" ;
89import checkPassthroughCopyBehavior from "./Util/PassthroughCopyBehaviorCheck.js" ;
@@ -11,6 +12,7 @@ const debug = debugUtil("Eleventy:EleventyFiles");
1112
1213class EleventyFiles {
1314 #extensionMap;
15+ #watcherGlobs;
1416
1517 constructor ( formats , templateConfig ) {
1618 if ( ! templateConfig ) {
@@ -69,8 +71,8 @@ class EleventyFiles {
6971 this . setupGlobs ( ) ;
7072 }
7173
72- get validTemplateGlobs ( ) {
73- if ( ! this . _validTemplateGlobs ) {
74+ #getWatcherGlobs ( ) {
75+ if ( ! this . #watcherGlobs ) {
7476 let globs ;
7577 // Input is a file
7678 if ( this . inputFile ) {
@@ -79,9 +81,10 @@ class EleventyFiles {
7981 // input is a directory
8082 globs = this . extensionMap . getValidGlobs ( this . inputDir ) ;
8183 }
82- this . _validTemplateGlobs = globs ;
84+ this . #watcherGlobs = globs ;
8385 }
84- return this . _validTemplateGlobs ;
86+
87+ return this . #watcherGlobs;
8588 }
8689
8790 get passthroughGlobs ( ) {
@@ -154,7 +157,7 @@ class EleventyFiles {
154157
155158 setupGlobs ( ) {
156159 this . fileIgnores = this . getIgnores ( ) ;
157- this . extraIgnores = this . _getIncludesAndDataDirs ( ) ;
160+ this . extraIgnores = this . getIncludesAndDataDirs ( ) ;
158161 this . uniqueIgnores = this . getIgnoreGlobs ( ) ;
159162
160163 // Conditional added for tests that don’t have a config
@@ -165,6 +168,13 @@ class EleventyFiles {
165168 this . normalizedTemplateGlobs = this . templateGlobs ;
166169 }
167170
171+ normalizeIgnoreEntry ( entry ) {
172+ if ( ! entry . startsWith ( "**/" ) ) {
173+ return TemplateGlob . normalizePath ( this . localPathRoot || "." , entry ) ;
174+ }
175+ return entry ;
176+ }
177+
168178 getIgnoreGlobs ( ) {
169179 let uniqueIgnores = new Set ( ) ;
170180 for ( let ignore of this . fileIgnores ) {
@@ -173,10 +183,12 @@ class EleventyFiles {
173183 for ( let ignore of this . extraIgnores ) {
174184 uniqueIgnores . add ( ignore ) ;
175185 }
186+
176187 // Placing the config ignores last here is important to the tests
177188 for ( let ignore of this . config . ignores ) {
178- uniqueIgnores . add ( TemplateGlob . normalizePath ( this . localPathRoot || "." , ignore ) ) ;
189+ uniqueIgnores . add ( this . normalizeIgnoreEntry ( ignore ) ) ;
179190 }
191+
180192 return Array . from ( uniqueIgnores ) ;
181193 }
182194
@@ -261,11 +273,12 @@ class EleventyFiles {
261273 files . add ( this . eleventyIgnoreContent ) ;
262274 }
263275
264- // ignore output dir (unless this excludes all input)
265- // input: . and output: . (skip)
266- // input: ./content and output . (skip)
267- // input: . and output: ./_site (add)
268- if ( ! this . inputDir . startsWith ( this . outputDir ) ) {
276+ // Make sure output dir isn’t in the input dir (or it will ignore all input!)
277+ // input: . and output: . (skip ignore)
278+ // input: ./content and output . (skip ignore)
279+ // input: . and output: ./_site (add ignore)
280+ let outputContainsInputDir = DirContains ( this . outputDir , this . inputDir ) ;
281+ if ( ! outputContainsInputDir ) {
269282 // both are already normalized in 3.0
270283 files . add ( TemplateGlob . map ( this . outputDir + "/**" ) ) ;
271284 }
@@ -284,6 +297,7 @@ class EleventyFiles {
284297 if ( this . eleventyIgnoreContent === false ) {
285298 let absoluteInputDir = TemplatePath . absolutePath ( this . inputDir ) ;
286299 ignoreFiles . add ( TemplatePath . join ( rootDirectory , ".eleventyignore" ) ) ;
300+
287301 if ( rootDirectory !== absoluteInputDir ) {
288302 ignoreFiles . add ( TemplatePath . join ( this . inputDir , ".eleventyignore" ) ) ;
289303 }
@@ -427,14 +441,16 @@ class EleventyFiles {
427441 /* For `eleventy --watch` */
428442 getGlobWatcherFiles ( ) {
429443 // TODO improvement: tie the includes and data to specific file extensions (currently using `**`)
430- let directoryGlobs = this . _getIncludesAndDataDirs ( ) ;
444+ let directoryGlobs = this . getIncludesAndDataDirs ( ) ;
445+
446+ let globs = this . #getWatcherGlobs( ) ;
431447
432448 if ( checkPassthroughCopyBehavior ( this . config , this . runMode ) ) {
433- return this . validTemplateGlobs . concat ( directoryGlobs ) ;
449+ return globs . concat ( directoryGlobs ) ;
434450 }
435451
436452 // Revert to old passthroughcopy copy files behavior
437- return this . validTemplateGlobs . concat ( this . passthroughGlobs ) . concat ( directoryGlobs ) ;
453+ return globs . concat ( this . passthroughGlobs ) . concat ( directoryGlobs ) ;
438454 }
439455
440456 /* For `eleventy --watch` */
@@ -456,7 +472,12 @@ class EleventyFiles {
456472 bench . before ( ) ;
457473 let results = TemplatePath . addLeadingDotSlashArray (
458474 await this . fileSystemSearch . search ( "js-dependencies" , globs , {
459- ignore : [ "**/node_modules/**" ] ,
475+ ignore : [
476+ "**/node_modules/**" ,
477+ ".git/**" ,
478+ // TODO outputDir
479+ // this.outputDir,
480+ ] ,
460481 } ) ,
461482 ) ;
462483 bench . after ( ) ;
@@ -471,14 +492,14 @@ class EleventyFiles {
471492 ) ;
472493
473494 for ( let ignore of this . config . watchIgnores ) {
474- entries . add ( TemplateGlob . normalizePath ( this . localPathRoot || "." , ignore ) ) ;
495+ entries . add ( this . normalizeIgnoreEntry ( ignore ) ) ;
475496 }
476497
477498 // de-duplicated
478499 return Array . from ( entries ) ;
479500 }
480501
481- _getIncludesAndDataDirs ( ) {
502+ getIncludesAndDataDirs ( ) {
482503 let rawPaths = new Set ( ) ;
483504 rawPaths . add ( this . includesDir ) ;
484505 if ( this . layoutsDir ) {
0 commit comments