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

Commit 4c965b4

Browse files
committed
enable diagnostics based on process.env.DEBUG
1 parent f1ca6ab commit 4c965b4

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/index.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ function insertInto(list, value, { before = [] } = {}) {
315315

316316
function cleanupContext(context) {
317317
if (context.watcher) {
318-
// console.log('Cleaning up old watcher')
319318
context.watcher.close()
320319
}
321320
contextMap.delete(context.configHash)
@@ -671,6 +670,12 @@ module.exports = (pluginOptions = {}) => {
671670
return {
672671
postcssPlugin: 'tailwindcss-jit',
673672
plugins: [
673+
env.DEBUG &&
674+
function (root) {
675+
console.log('\n')
676+
console.time('JIT TOTAL')
677+
return root
678+
},
674679
function (root, result) {
675680
function registerDependency(fileName) {
676681
result.messages.push({
@@ -751,22 +756,26 @@ module.exports = (pluginOptions = {}) => {
751756
let candidates = new Set()
752757
let seen = new Set()
753758

759+
env.DEBUG && console.time('Reading changed files')
754760
for (let file of context.changedFiles) {
755761
let content = fs.readFileSync(file, 'utf8')
756762
getClassCandidates(content, contentMatchCache, candidates, seen)
757763
}
764+
env.DEBUG && console.timeEnd('Reading changed files')
758765

759766
// ---
760767

761768
// Generate the actual CSS
762769

763770
let classCacheCount = context.classCache.size
764771

772+
env.DEBUG && console.time('Generate rules')
765773
let { utilities, components } = generateRules(
766774
context.tailwindConfig,
767775
candidates,
768776
context
769777
)
778+
env.DEBUG && console.timeEnd('Generate rules')
770779

771780
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
772781
if (context.classCache.size !== classCacheCount) {
@@ -778,10 +787,12 @@ module.exports = (pluginOptions = {}) => {
778787
context.utilityRuleCache.add(rule)
779788
}
780789

790+
env.DEBUG && console.time('Build stylesheet')
781791
context.stylesheetCache = buildStylesheet(
782792
[...context.componentRuleCache, ...context.utilityRuleCache],
783793
context
784794
)
795+
env.DEBUG && console.timeEnd('Build stylesheet')
785796
}
786797

787798
let {
@@ -818,19 +829,27 @@ module.exports = (pluginOptions = {}) => {
818829

819830
// ---
820831

821-
// console.log('Changed files: ', context.changedFiles.size)
822-
// console.log('Potential classes: ', candidates.size)
823-
// console.log('Active contexts: ', contextMap.size)
824-
// console.log('Active sources:', sourceContextMap.size)
825-
// console.log('Context source size: ', contextSources.size)
826-
// console.log('Content match entries', contentMatchCache.size)
832+
if (env.DEBUG) {
833+
console.log('Changed files: ', context.changedFiles.size)
834+
console.log('Potential classes: ', candidates.size)
835+
console.log('Active contexts: ', contextMap.size)
836+
console.log('Active sources:', sourceContextMap.size)
837+
console.log('Context source size: ', contextSources.size)
838+
console.log('Content match entries', contentMatchCache.size)
839+
}
827840

828841
// Clear the cache for the changed files
829842
context.changedFiles.clear()
830843
},
831844
evaluateTailwindFunctions(context.tailwindConfig),
832845
]).process(root, { from: undefined })
833846
},
847+
env.DEBUG &&
848+
function (root) {
849+
console.timeEnd('JIT TOTAL')
850+
console.log('\n')
851+
return root
852+
},
834853
],
835854
}
836855
}

0 commit comments

Comments
 (0)