Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tracking context by default #4514

Merged
merged 1 commit into from May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions integrations/rollup/tests/integration.test.js
Expand Up @@ -27,10 +27,7 @@ describe('static build', () => {
})
})

describe.each([
{ TAILWIND_MODE: 'watch' },
{ TAILWIND_MODE: 'watch', TAILWIND_DISABLE_TOUCH: true },
])('watcher %p', (env) => {
describe.each([{ TAILWIND_MODE: 'watch' }, { TAILWIND_MODE: undefined }])('watcher %p', (env) => {
test(`classes are generated when the html file changes`, async () => {
await writeInputFile('index.html', html`<div class="font-bold"></div>`)

Expand Down
5 changes: 1 addition & 4 deletions integrations/webpack-4/tests/integration.test.js
Expand Up @@ -25,10 +25,7 @@ describe('static build', () => {
})
})

describe.each([
{ TAILWIND_MODE: 'watch' },
{ TAILWIND_MODE: 'watch', TAILWIND_DISABLE_TOUCH: true },
])('watcher %p', (env) => {
describe.each([{ TAILWIND_MODE: 'watch' }, { TAILWIND_MODE: undefined }])('watcher %p', (env) => {
test(`classes are generated when the html file changes`, async () => {
await writeInputFile('index.html', html`<div class="font-bold"></div>`)

Expand Down
5 changes: 1 addition & 4 deletions integrations/webpack-5/tests/integration.test.js
Expand Up @@ -25,10 +25,7 @@ describe('static build', () => {
})
})

describe.each([
{ TAILWIND_MODE: 'watch' },
{ TAILWIND_MODE: 'watch', TAILWIND_DISABLE_TOUCH: true },
])('watcher %p', (env) => {
describe.each([{ TAILWIND_MODE: 'watch' }, { TAILWIND_MODE: undefined }])('watcher %p', (env) => {
test(`classes are generated when the html file changes`, async () => {
await writeInputFile('index.html', html`<div class="font-bold"></div>`)

Expand Down
7 changes: 4 additions & 3 deletions src/jit/index.js
Expand Up @@ -24,9 +24,10 @@ export default function (configOrPath = {}) {

let tailwindDirectives = normalizeTailwindDirectives(root)

let context = env.TAILWIND_DISABLE_TOUCH
? setupTrackingContext(configOrPath, tailwindDirectives, registerDependency)(result, root)
: setupWatchingContext(configOrPath, tailwindDirectives, registerDependency)(result, root)
let context =
env.TAILWIND_MODE === 'watch'
? setupWatchingContext(configOrPath, tailwindDirectives, registerDependency)(result, root)
: setupTrackingContext(configOrPath, tailwindDirectives, registerDependency)(result, root)

processTailwindFeatures(context)(root, result)
},
Expand Down
91 changes: 41 additions & 50 deletions src/jit/lib/setupWatchingContext.js
Expand Up @@ -22,7 +22,7 @@ import { env } from './sharedState'
let touchDir =
env.TAILWIND_TOUCH_DIR || path.join(os.homedir() || os.tmpdir(), '.tailwindcss', 'touch')

if (!env.TAILWIND_DISABLE_TOUCH) {
if (env.TAILWIND_MODE === 'watch') {
if (fs.existsSync(touchDir)) {
for (let file of fs.readdirSync(touchDir)) {
try {
Expand Down Expand Up @@ -94,67 +94,58 @@ function rebootWatcher(context, configPath, configDependencies, candidateFiles)
touch(touchFile)
}

if (env.TAILWIND_MODE === 'build') {
return
}
let watcher = getWatcher(context)

if (
env.TAILWIND_MODE === 'watch' ||
(env.TAILWIND_MODE === undefined && env.NODE_ENV === 'development')
) {
let watcher = getWatcher(context)
Promise.resolve(watcher ? watcher.close() : null).then(() => {
log.info([
'Tailwind CSS is watching for changes...',
'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds',
])

Promise.resolve(watcher ? watcher.close() : null).then(() => {
log.info([
'Tailwind CSS is watching for changes...',
'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds',
])
watcher = chokidar.watch([...candidateFiles, ...configDependencies], {
ignoreInitial: true,
})

watcher = chokidar.watch([...candidateFiles, ...configDependencies], {
ignoreInitial: true,
})
setWatcher(context, watcher)

setWatcher(context, watcher)
watcher.on('add', (file) => {
let changedFile = path.resolve('.', file)
let content = fs.readFileSync(changedFile, 'utf8')
let extension = path.extname(changedFile).slice(1)
context.changedContent.push({ content, extension })
touch(touchFile)
})

watcher.on('add', (file) => {
watcher.on('change', (file) => {
// If it was a config dependency, touch the config file to trigger a new context.
// This is not really that clean of a solution but it's the fastest, because we
// can do a very quick check on each build to see if the config has changed instead
// of having to get all of the module dependencies and check every timestamp each
// time.
if (configDependencies.has(file)) {
for (let dependency of configDependencies) {
delete require.cache[require.resolve(dependency)]
}
touch(configPath)
} else {
let changedFile = path.resolve('.', file)
let content = fs.readFileSync(changedFile, 'utf8')
let extension = path.extname(changedFile).slice(1)
context.changedContent.push({ content, extension })
touch(touchFile)
})

watcher.on('change', (file) => {
// If it was a config dependency, touch the config file to trigger a new context.
// This is not really that clean of a solution but it's the fastest, because we
// can do a very quick check on each build to see if the config has changed instead
// of having to get all of the module dependencies and check every timestamp each
// time.
if (configDependencies.has(file)) {
for (let dependency of configDependencies) {
delete require.cache[require.resolve(dependency)]
}
touch(configPath)
} else {
let changedFile = path.resolve('.', file)
let content = fs.readFileSync(changedFile, 'utf8')
let extension = path.extname(changedFile).slice(1)
context.changedContent.push({ content, extension })
touch(touchFile)
}
})

watcher.on('unlink', (file) => {
// Touch the config file if any of the dependencies are deleted.
if (configDependencies.has(file)) {
for (let dependency of configDependencies) {
delete require.cache[require.resolve(dependency)]
}
touch(configPath)
}
})

watcher.on('unlink', (file) => {
// Touch the config file if any of the dependencies are deleted.
if (configDependencies.has(file)) {
for (let dependency of configDependencies) {
delete require.cache[require.resolve(dependency)]
}
})
touch(configPath)
}
})
}
})
}

function generateTouchFileName() {
Expand Down