Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: support _cacheGroup
  • Loading branch information
pi0 committed Mar 13, 2021
commit a896c60258fa42ecbf19cf08ba79766071580c60
16 changes: 14 additions & 2 deletions src/lib/setupContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { isBuffer } = require('util')
let contextMap = sharedState.contextMap
let configContextMap = sharedState.configContextMap
let contextSourcesMap = sharedState.contextSourcesMap
let configHashMap = sharedState.configHashMap
let env = sharedState.env

// Earmarks a directory for our touch files.
Expand Down Expand Up @@ -629,6 +630,8 @@ function setupContext(configOrPath) {
let [tailwindConfig, userConfigPath, tailwindConfigHash] = getTailwindConfig(configOrPath)
let isConfigFile = userConfigPath !== null

const { _cacheGroup = 'default', _hash } = tailwindConfig

let contextDependencies = new Set()

// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
Expand Down Expand Up @@ -656,8 +659,13 @@ function setupContext(configOrPath) {
if (!contextDependenciesChanged) {
// If this file already has a context in the cache and we don't need to
// reset the context, return the cached context.
if (isConfigFile && contextMap.has(sourcePath)) {
return contextMap.get(sourcePath)
if (contextMap.has(sourcePath)) {
if (
isConfigFile ||
(_hash && configHashMap.has(_cacheGroup) && _hash === configHashMap.get(_cacheGroup))
) {
return contextMap.get(sourcePath)
}
}

// If the config used already exists in the cache, return that.
Expand All @@ -669,6 +677,10 @@ function setupContext(configOrPath) {
}
}

if (_hash) {
configHashMap.set(_cacheGroup, _hash)
}

// If this source is in the context map, get the old context.
// Remove this source from the context sources for the old context,
// and clean up that context if no one else is using it. This can be
Expand Down
1 change: 1 addition & 0 deletions src/lib/sharedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
contextMap: new Map(),
configContextMap: new Map(),
contextSourcesMap: new Map(),
configHashMap: new Map(),
contentMatchCache: new LRU({ maxSize: 25000 }),
}