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

Add flag to disable "touch" files in favour of registering directory dependencies #162

Merged
merged 11 commits into from
Mar 26, 2021
144 changes: 144 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"lodash.topath": "^4.5.2",
"normalize-path": "^3.0.0",
"object-hash": "^2.1.1",
"parse-glob": "^3.0.4",
"postcss-selector-parser": "^6.0.4",
"quick-lru": "^5.1.1"
},
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module.exports = (configOrPath = {}) => {
return root
},
function (root, result) {
function registerDependency(fileName) {
function registerDependency(fileName, type = 'dependency') {
result.messages.push({
type: 'dependency',
type,
plugin: 'tailwindcss-jit',
parent: result.opts.from,
file: fileName,
Expand All @@ -36,8 +36,10 @@ module.exports = (configOrPath = {}) => {

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

if (context.configPath !== null) {
registerDependency(context.configPath)
if (!env.TAILWIND_DISABLE_TOUCH) {
if (context.configPath !== null) {
registerDependency(context.configPath)
}
}

return postcss([
Expand Down
55 changes: 45 additions & 10 deletions src/lib/expandTailwindAtRules.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const path = require('path')
const fastGlob = require('fast-glob')
const parseGlob = require('parse-glob')
const sharedState = require('./sharedState')
const { generateRules } = require('./generateRules')
const { bigSign, cloneNodes } = require('./utils')
Expand Down Expand Up @@ -141,21 +142,55 @@ function expandTailwindAtRules(context, registerDependency) {

// ---

// Register our temp file as a dependency — we write to this file
// to trigger rebuilds.
if (context.touchFile) {
registerDependency(context.touchFile)
}
if (sharedState.env.TAILWIND_DISABLE_TOUCH) {
for (let maybeGlob of context.candidateFiles) {
let {
is: { glob: isGlob },
base,
} = parseGlob(maybeGlob)

if (isGlob) {
// register base dir as `dependency` _and_ `context-dependency` for
// increased compatibility
registerDependency(path.resolve(base))
registerDependency(path.resolve(base), 'context-dependency')
} else {
registerDependency(path.resolve(maybeGlob))
}
}

// If we're not set up and watching files ourselves, we need to do
// the work of grabbing all of the template files for candidate
// detection.
if (!context.scannedContent) {
env.DEBUG && console.time('Finding changed files')
let files = fastGlob.sync(context.candidateFiles)
for (let file of files) {
context.changedFiles.add(file)
let prevModified = context.fileModifiedMap.has(file)
? context.fileModifiedMap.get(file)
: -Infinity
let modified = fs.statSync(file).mtimeMs

if (!context.scannedContent || modified > prevModified) {
context.changedFiles.add(file)
context.fileModifiedMap.set(file, modified)
}
}
context.scannedContent = true
env.DEBUG && console.timeEnd('Finding changed files')
} else {
// Register our temp file as a dependency — we write to this file
// to trigger rebuilds.
if (context.touchFile) {
registerDependency(context.touchFile)
}

// If we're not set up and watching files ourselves, we need to do
// the work of grabbing all of the template files for candidate
// detection.
if (!context.scannedContent) {
let files = fastGlob.sync(context.candidateFiles)
for (let file of files) {
context.changedFiles.add(file)
}
context.scannedContent = true
}
}

// ---
Expand Down
Loading