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

Commit a187332

Browse files
authored
Add flag to disable "touch" files in favour of registering directory dependencies (#162)
* use context dependencies and remove file watcher and touch files * remove broken bail out * register glob base dirs as dependency as well as context-dependency improves tooling compatibility: now works with postcss-cli and rollup, as well as webpack * add parse-glob dependency * fix fresh context build * rejig config dependency tracking * replace ?? * put context dependencies behind TAILWIND_DISABLE_TOUCH flag * move file modified map to context * don't start watcher if touch is disabled
1 parent 4a95641 commit a187332

File tree

6 files changed

+272
-24
lines changed

6 files changed

+272
-24
lines changed

package-lock.json

+144
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lodash.topath": "^4.5.2",
2121
"normalize-path": "^3.0.0",
2222
"object-hash": "^2.1.1",
23+
"parse-glob": "^3.0.4",
2324
"postcss-selector-parser": "^6.0.4",
2425
"quick-lru": "^5.1.1"
2526
},

src/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ module.exports = (configOrPath = {}) => {
2323
return root
2424
},
2525
function (root, result) {
26-
function registerDependency(fileName) {
26+
function registerDependency(fileName, type = 'dependency') {
2727
result.messages.push({
28-
type: 'dependency',
28+
type,
2929
plugin: 'tailwindcss-jit',
3030
parent: result.opts.from,
3131
file: fileName,
@@ -36,8 +36,10 @@ module.exports = (configOrPath = {}) => {
3636

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

39-
if (context.configPath !== null) {
40-
registerDependency(context.configPath)
39+
if (!env.TAILWIND_DISABLE_TOUCH) {
40+
if (context.configPath !== null) {
41+
registerDependency(context.configPath)
42+
}
4143
}
4244

4345
return postcss([

src/lib/expandTailwindAtRules.js

+45-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs')
22
const path = require('path')
33
const fastGlob = require('fast-glob')
4+
const parseGlob = require('parse-glob')
45
const sharedState = require('./sharedState')
56
const { generateRules } = require('./generateRules')
67
const { bigSign, cloneNodes } = require('./utils')
@@ -141,21 +142,55 @@ function expandTailwindAtRules(context, registerDependency) {
141142

142143
// ---
143144

144-
// Register our temp file as a dependency — we write to this file
145-
// to trigger rebuilds.
146-
if (context.touchFile) {
147-
registerDependency(context.touchFile)
148-
}
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+
}
149161

150-
// If we're not set up and watching files ourselves, we need to do
151-
// the work of grabbing all of the template files for candidate
152-
// detection.
153-
if (!context.scannedContent) {
162+
env.DEBUG && console.time('Finding changed files')
154163
let files = fastGlob.sync(context.candidateFiles)
155164
for (let file of files) {
156-
context.changedFiles.add(file)
165+
let prevModified = context.fileModifiedMap.has(file)
166+
? context.fileModifiedMap.get(file)
167+
: -Infinity
168+
let modified = fs.statSync(file).mtimeMs
169+
170+
if (!context.scannedContent || modified > prevModified) {
171+
context.changedFiles.add(file)
172+
context.fileModifiedMap.set(file, modified)
173+
}
157174
}
158175
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)
182+
}
183+
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
193+
}
159194
}
160195

161196
// ---

0 commit comments

Comments
 (0)