Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit eeef28a

Browse files
committed
put context dependencies behind TAILWIND_DISABLE_TOUCH flag
1 parent 5207bfd commit eeef28a

File tree

4 files changed

+248
-61
lines changed

4 files changed

+248
-61
lines changed

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ module.exports = (configOrPath = {}) => {
3636

3737
let context = setupContext(configOrPath)(result, root)
3838

39+
if (!env.TAILWIND_DISABLE_TOUCH) {
40+
if (context.configPath !== null) {
41+
registerDependency(context.configPath)
42+
}
43+
}
44+
3945
return postcss([
4046
removeLayerAtRules(context),
4147
expandTailwindAtRules(context, registerDependency),

src/lib/expandTailwindAtRules.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,37 +142,56 @@ function expandTailwindAtRules(context, registerDependency) {
142142

143143
// ---
144144

145-
for (let maybeGlob of context.candidateFiles) {
146-
let {
147-
is: { glob: isGlob },
148-
base,
149-
} = parseGlob(maybeGlob)
150-
151-
if (isGlob) {
152-
// register base dir as `dependency` _and_ `context-dependency` for
153-
// increased compatibility
154-
registerDependency(path.resolve(base))
155-
registerDependency(path.resolve(base), 'context-dependency')
156-
} else {
157-
registerDependency(path.resolve(maybeGlob))
145+
if (sharedState.env.TAILWIND_DISABLE_TOUCH) {
146+
for (let maybeGlob of context.candidateFiles) {
147+
let {
148+
is: { glob: isGlob },
149+
base,
150+
} = parseGlob(maybeGlob)
151+
152+
if (isGlob) {
153+
// register base dir as `dependency` _and_ `context-dependency` for
154+
// increased compatibility
155+
registerDependency(path.resolve(base))
156+
registerDependency(path.resolve(base), 'context-dependency')
157+
} else {
158+
registerDependency(path.resolve(maybeGlob))
159+
}
160+
}
161+
162+
env.DEBUG && console.time('Finding changed files')
163+
let files = fastGlob.sync(context.candidateFiles)
164+
for (let file of files) {
165+
let prevModified = sharedState.fileModifiedCache.has(file)
166+
? sharedState.fileModifiedCache.get(file)
167+
: -Infinity
168+
let modified = fs.statSync(file).mtimeMs
169+
170+
if (!context.scannedContent || modified > prevModified) {
171+
context.changedFiles.add(file)
172+
sharedState.fileModifiedCache.set(file, modified)
173+
}
174+
}
175+
context.scannedContent = true
176+
env.DEBUG && console.timeEnd('Finding changed files')
177+
} else {
178+
// Register our temp file as a dependency — we write to this file
179+
// to trigger rebuilds.
180+
if (context.touchFile) {
181+
registerDependency(context.touchFile)
158182
}
159-
}
160183

161-
env.DEBUG && console.time('Finding changed files')
162-
let files = fastGlob.sync(context.candidateFiles)
163-
for (let file of files) {
164-
let prevModified = sharedState.fileModifiedCache.has(file)
165-
? sharedState.fileModifiedCache.get(file)
166-
: -Infinity
167-
let modified = fs.statSync(file).mtimeMs
168-
169-
if (!context.scannedContent || modified > prevModified) {
170-
context.changedFiles.add(file)
171-
sharedState.fileModifiedCache.set(file, modified)
184+
// If we're not set up and watching files ourselves, we need to do
185+
// the work of grabbing all of the template files for candidate
186+
// detection.
187+
if (!context.scannedContent) {
188+
let files = fastGlob.sync(context.candidateFiles)
189+
for (let file of files) {
190+
context.changedFiles.add(file)
191+
}
192+
context.scannedContent = true
172193
}
173194
}
174-
context.scannedContent = true
175-
env.DEBUG && console.timeEnd('Finding changed files')
176195

177196
// ---
178197

0 commit comments

Comments
 (0)