tailwindcss 3.0.7 → 3.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -1
- package/README.md +8 -4
- package/lib/cli.js +49 -12
- package/lib/css/preflight.css +1 -1
- package/lib/index.js +1 -3
- package/lib/lib/collapseDuplicateDeclarations.js +52 -1
- package/lib/lib/defaultExtractor.js +10 -2
- package/lib/lib/expandApplyAtRules.js +1 -1
- package/lib/lib/expandTailwindAtRules.js +16 -7
- package/lib/lib/normalizeTailwindDirectives.js +8 -1
- package/lib/lib/setupContextUtils.js +7 -1
- package/lib/lib/setupTrackingContext.js +11 -10
- package/lib/lib/sharedState.js +33 -4
- package/lib/processTailwindFeatures.js +2 -1
- package/lib/util/color.js +23 -8
- package/package.json +10 -11
- package/peers/index.js +72 -86
- package/src/cli.js +57 -12
- package/src/css/preflight.css +1 -1
- package/src/index.js +1 -7
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/defaultExtractor.js +17 -0
- package/src/lib/expandApplyAtRules.js +1 -1
- package/src/lib/expandTailwindAtRules.js +18 -7
- package/src/lib/normalizeTailwindDirectives.js +6 -1
- package/src/lib/setupContextUtils.js +8 -1
- package/src/lib/setupTrackingContext.js +11 -10
- package/src/lib/sharedState.js +40 -4
- package/src/processTailwindFeatures.js +2 -1
- package/src/util/color.js +20 -7
- package/lib/lib/setupWatchingContext.js +0 -288
- package/src/lib/setupWatchingContext.js +0 -311
|
@@ -140,14 +140,25 @@ export default function expandTailwindAtRules(context) {
|
|
|
140
140
|
variants: null,
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
// let hasApply = false
|
|
144
|
+
|
|
145
|
+
root.walkAtRules((rule) => {
|
|
146
|
+
// Make sure this file contains Tailwind directives. If not, we can save
|
|
147
|
+
// a lot of work and bail early. Also we don't have to register our touch
|
|
148
|
+
// file as a dependency since the output of this CSS does not depend on
|
|
149
|
+
// the source of any templates. Think Vue <style> blocks for example.
|
|
150
|
+
if (rule.name === 'tailwind') {
|
|
151
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
152
|
+
layerNodes[rule.params] = rule
|
|
153
|
+
}
|
|
150
154
|
}
|
|
155
|
+
|
|
156
|
+
// We also want to check for @apply because the user can
|
|
157
|
+
// apply classes in an isolated environment like CSS
|
|
158
|
+
// modules and we still need to inject defaults
|
|
159
|
+
// if (rule.name === 'apply') {
|
|
160
|
+
// hasApply = true
|
|
161
|
+
// }
|
|
151
162
|
})
|
|
152
163
|
|
|
153
164
|
if (Object.values(layerNodes).every((n) => n === null)) {
|
|
@@ -3,8 +3,13 @@ import log from '../util/log'
|
|
|
3
3
|
export default function normalizeTailwindDirectives(root) {
|
|
4
4
|
let tailwindDirectives = new Set()
|
|
5
5
|
let layerDirectives = new Set()
|
|
6
|
+
let applyDirectives = new Set()
|
|
6
7
|
|
|
7
8
|
root.walkAtRules((atRule) => {
|
|
9
|
+
if (atRule.name === 'apply') {
|
|
10
|
+
applyDirectives.add(atRule)
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
if (atRule.name === 'import') {
|
|
9
14
|
if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
|
|
10
15
|
atRule.name = 'tailwind'
|
|
@@ -74,5 +79,5 @@ export default function normalizeTailwindDirectives(root) {
|
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
return tailwindDirectives
|
|
82
|
+
return { tailwindDirectives, applyDirectives }
|
|
78
83
|
}
|
|
@@ -435,7 +435,14 @@ function trackModified(files, fileModifiedMap) {
|
|
|
435
435
|
let parsed = url.parse(file)
|
|
436
436
|
let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
|
|
437
437
|
pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
|
|
438
|
-
let newModified = fs.statSync(decodeURIComponent(pathname))
|
|
438
|
+
let newModified = fs.statSync(decodeURIComponent(pathname), { throwIfNoEntry: false })?.mtimeMs
|
|
439
|
+
if (!newModified) {
|
|
440
|
+
// It could happen that a file is passed in that doesn't exist. E.g.:
|
|
441
|
+
// postcss-cli will provide you a fake path when reading from stdin. This
|
|
442
|
+
// path then looks like /path-to-your-project/stdin In that case we just
|
|
443
|
+
// want to ignore it and don't track changes at all.
|
|
444
|
+
continue
|
|
445
|
+
}
|
|
439
446
|
|
|
440
447
|
if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
|
|
441
448
|
changed = true
|
|
@@ -112,19 +112,20 @@ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
|
|
|
112
112
|
// source path), or set up a new one (including setting up watchers and registering
|
|
113
113
|
// plugins) then return it
|
|
114
114
|
export default function setupTrackingContext(configOrPath) {
|
|
115
|
-
return ({ tailwindDirectives, registerDependency }) => {
|
|
115
|
+
return ({ tailwindDirectives, registerDependency, applyDirectives }) => {
|
|
116
116
|
return (root, result) => {
|
|
117
117
|
let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] =
|
|
118
118
|
getTailwindConfig(configOrPath)
|
|
119
119
|
|
|
120
120
|
let contextDependencies = new Set(configDependencies)
|
|
121
121
|
|
|
122
|
-
// If there are no @tailwind rules, we don't consider this CSS
|
|
123
|
-
// to be dependencies of the context. Can reuse
|
|
124
|
-
// We may want to think about `@layer`
|
|
125
|
-
//
|
|
126
|
-
// in
|
|
127
|
-
|
|
122
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS
|
|
123
|
+
// file or its dependencies to be dependencies of the context. Can reuse
|
|
124
|
+
// the context even if they change. We may want to think about `@layer`
|
|
125
|
+
// being part of this trigger too, but it's tough because it's impossible
|
|
126
|
+
// for a layer in one file to end up in the actual @tailwind rule in
|
|
127
|
+
// another file since independent sources are effectively isolated.
|
|
128
|
+
if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
|
|
128
129
|
// Add current css file as a context dependencies.
|
|
129
130
|
contextDependencies.add(result.opts.from)
|
|
130
131
|
|
|
@@ -147,12 +148,12 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
147
148
|
|
|
148
149
|
let candidateFiles = getCandidateFiles(context, tailwindConfig)
|
|
149
150
|
|
|
150
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's
|
|
151
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
151
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
|
|
152
|
+
// dependencies to be dependencies of the context. Can reuse the context even if they change.
|
|
152
153
|
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
153
154
|
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
154
155
|
// in another file since independent sources are effectively isolated.
|
|
155
|
-
if (tailwindDirectives.size > 0) {
|
|
156
|
+
if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
|
|
156
157
|
let fileModifiedMap = getFileModifiedMap(context)
|
|
157
158
|
|
|
158
159
|
// Add template paths as postcss dependencies.
|
package/src/lib/sharedState.js
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
1
|
export const env = {
|
|
2
|
-
TAILWIND_MODE: process.env.TAILWIND_MODE,
|
|
3
2
|
NODE_ENV: process.env.NODE_ENV,
|
|
4
|
-
DEBUG: process.env.DEBUG
|
|
5
|
-
TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined,
|
|
6
|
-
TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR,
|
|
3
|
+
DEBUG: resolveDebug(process.env.DEBUG),
|
|
7
4
|
}
|
|
8
5
|
export const contextMap = new Map()
|
|
9
6
|
export const configContextMap = new Map()
|
|
10
7
|
export const contextSourcesMap = new Map()
|
|
8
|
+
|
|
9
|
+
export function resolveDebug(debug) {
|
|
10
|
+
if (debug === undefined) {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Environment variables are strings, so convert to boolean
|
|
15
|
+
if (debug === 'true' || debug === '1') {
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (debug === 'false' || debug === '0') {
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Keep the debug convention into account:
|
|
24
|
+
// DEBUG=* -> This enables all debug modes
|
|
25
|
+
// DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
|
|
26
|
+
// DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
|
|
27
|
+
// DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
|
|
28
|
+
|
|
29
|
+
if (debug === '*') {
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let debuggers = debug.split(',').map((d) => d.split(':')[0])
|
|
34
|
+
|
|
35
|
+
// Ignoring tailwindcss
|
|
36
|
+
if (debuggers.includes('-tailwindcss')) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Including tailwindcss
|
|
41
|
+
if (debuggers.includes('tailwindcss')) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
@@ -12,10 +12,11 @@ import { issueFlagNotices } from './featureFlags'
|
|
|
12
12
|
|
|
13
13
|
export default function processTailwindFeatures(setupContext) {
|
|
14
14
|
return function (root, result) {
|
|
15
|
-
let tailwindDirectives = normalizeTailwindDirectives(root)
|
|
15
|
+
let { tailwindDirectives, applyDirectives } = normalizeTailwindDirectives(root)
|
|
16
16
|
|
|
17
17
|
let context = setupContext({
|
|
18
18
|
tailwindDirectives,
|
|
19
|
+
applyDirectives,
|
|
19
20
|
registerDependency(dependency) {
|
|
20
21
|
result.messages.push({
|
|
21
22
|
plugin: 'tailwindcss',
|
package/src/util/color.js
CHANGED
|
@@ -5,8 +5,11 @@ let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i
|
|
|
5
5
|
let VALUE = `(?:\\d+|\\d*\\.\\d+)%?`
|
|
6
6
|
let SEP = `(?:\\s*,\\s*|\\s+)`
|
|
7
7
|
let ALPHA_SEP = `\\s*[,/]\\s*`
|
|
8
|
-
let
|
|
9
|
-
`^
|
|
8
|
+
let RGB = new RegExp(
|
|
9
|
+
`^rgba?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
|
|
10
|
+
)
|
|
11
|
+
let HSL = new RegExp(
|
|
12
|
+
`^hsla?\\(\\s*((?:${VALUE})(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
|
|
10
13
|
)
|
|
11
14
|
|
|
12
15
|
export function parseColor(value) {
|
|
@@ -37,13 +40,23 @@ export function parseColor(value) {
|
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
let
|
|
43
|
+
let rgbMatch = value.match(RGB)
|
|
44
|
+
|
|
45
|
+
if (rgbMatch !== null) {
|
|
46
|
+
return {
|
|
47
|
+
mode: 'rgb',
|
|
48
|
+
color: [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map((v) => v.toString()),
|
|
49
|
+
alpha: rgbMatch[4]?.toString?.(),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let hslMatch = value.match(HSL)
|
|
41
54
|
|
|
42
|
-
if (
|
|
55
|
+
if (hslMatch !== null) {
|
|
43
56
|
return {
|
|
44
|
-
mode:
|
|
45
|
-
color: [
|
|
46
|
-
alpha:
|
|
57
|
+
mode: 'hsl',
|
|
58
|
+
color: [hslMatch[1], hslMatch[2], hslMatch[3]].map((v) => v.toString()),
|
|
59
|
+
alpha: hslMatch[4]?.toString?.(),
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
62
|
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
exports.default = setupWatchingContext;
|
|
6
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var _tmp = _interopRequireDefault(require("tmp"));
|
|
9
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
10
|
-
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
11
|
-
var _quickLru = _interopRequireDefault(require("quick-lru"));
|
|
12
|
-
var _normalizePath = _interopRequireDefault(require("normalize-path"));
|
|
13
|
-
var _hashConfig = _interopRequireDefault(require("../util/hashConfig"));
|
|
14
|
-
var _log = _interopRequireDefault(require("../util/log"));
|
|
15
|
-
var _getModuleDependencies = _interopRequireDefault(require("../lib/getModuleDependencies"));
|
|
16
|
-
var _resolveConfig = _interopRequireDefault(require("../public/resolve-config"));
|
|
17
|
-
var _resolveConfigPath = _interopRequireDefault(require("../util/resolveConfigPath"));
|
|
18
|
-
var _setupContextUtils = require("./setupContextUtils");
|
|
19
|
-
function _interopRequireDefault(obj) {
|
|
20
|
-
return obj && obj.__esModule ? obj : {
|
|
21
|
-
default: obj
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
// This is used to trigger rebuilds. Just updating the timestamp
|
|
25
|
-
// is significantly faster than actually writing to the file (10x).
|
|
26
|
-
function touch(filename) {
|
|
27
|
-
let time = new Date();
|
|
28
|
-
try {
|
|
29
|
-
_fs.default.utimesSync(filename, time, time);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
_fs.default.closeSync(_fs.default.openSync(filename, 'w'));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
let watchers = new WeakMap();
|
|
35
|
-
function getWatcher(context) {
|
|
36
|
-
if (watchers.has(context)) {
|
|
37
|
-
return watchers.get(context);
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
function setWatcher(context, watcher) {
|
|
42
|
-
return watchers.set(context, watcher);
|
|
43
|
-
}
|
|
44
|
-
let touchFiles = new WeakMap();
|
|
45
|
-
function getTouchFile(context) {
|
|
46
|
-
if (touchFiles.has(context)) {
|
|
47
|
-
return touchFiles.get(context);
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
function setTouchFile(context, touchFile) {
|
|
52
|
-
return touchFiles.set(context, touchFile);
|
|
53
|
-
}
|
|
54
|
-
let configPaths = new WeakMap();
|
|
55
|
-
function getConfigPath(context, configOrPath) {
|
|
56
|
-
if (!configPaths.has(context)) {
|
|
57
|
-
configPaths.set(context, (0, _resolveConfigPath).default(configOrPath));
|
|
58
|
-
}
|
|
59
|
-
return configPaths.get(context);
|
|
60
|
-
}
|
|
61
|
-
function rebootWatcher(context, configPath, configDependencies, candidateFiles) {
|
|
62
|
-
let touchFile = getTouchFile(context);
|
|
63
|
-
if (touchFile === null) {
|
|
64
|
-
touchFile = _tmp.default.fileSync().name;
|
|
65
|
-
setTouchFile(context, touchFile);
|
|
66
|
-
touch(touchFile);
|
|
67
|
-
}
|
|
68
|
-
let watcher = getWatcher(context);
|
|
69
|
-
Promise.resolve(watcher ? watcher.close() : null).then(()=>{
|
|
70
|
-
_log.default.info([
|
|
71
|
-
'Tailwind CSS is watching for changes...',
|
|
72
|
-
'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds',
|
|
73
|
-
]);
|
|
74
|
-
watcher = _chokidar.default.watch([
|
|
75
|
-
...candidateFiles,
|
|
76
|
-
...configDependencies
|
|
77
|
-
], {
|
|
78
|
-
ignoreInitial: true,
|
|
79
|
-
awaitWriteFinish: process.platform === 'win32' ? {
|
|
80
|
-
stabilityThreshold: 50,
|
|
81
|
-
pollInterval: 10
|
|
82
|
-
} : false
|
|
83
|
-
});
|
|
84
|
-
setWatcher(context, watcher);
|
|
85
|
-
watcher.on('add', (file)=>{
|
|
86
|
-
let changedFile = _path.default.resolve('.', file);
|
|
87
|
-
let content = _fs.default.readFileSync(changedFile, 'utf8');
|
|
88
|
-
let extension = _path.default.extname(changedFile).slice(1);
|
|
89
|
-
context.changedContent.push({
|
|
90
|
-
content,
|
|
91
|
-
extension
|
|
92
|
-
});
|
|
93
|
-
touch(touchFile);
|
|
94
|
-
});
|
|
95
|
-
watcher.on('change', (file)=>{
|
|
96
|
-
// If it was a config dependency, touch the config file to trigger a new context.
|
|
97
|
-
// This is not really that clean of a solution but it's the fastest, because we
|
|
98
|
-
// can do a very quick check on each build to see if the config has changed instead
|
|
99
|
-
// of having to get all of the module dependencies and check every timestamp each
|
|
100
|
-
// time.
|
|
101
|
-
if (configDependencies.has(file)) {
|
|
102
|
-
for (let dependency of configDependencies){
|
|
103
|
-
delete require.cache[require.resolve(dependency)];
|
|
104
|
-
}
|
|
105
|
-
touch(configPath);
|
|
106
|
-
} else {
|
|
107
|
-
let changedFile = _path.default.resolve('.', file);
|
|
108
|
-
let content = _fs.default.readFileSync(changedFile, 'utf8');
|
|
109
|
-
let extension = _path.default.extname(changedFile).slice(1);
|
|
110
|
-
context.changedContent.push({
|
|
111
|
-
content,
|
|
112
|
-
extension
|
|
113
|
-
});
|
|
114
|
-
touch(touchFile);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
watcher.on('unlink', (file)=>{
|
|
118
|
-
// Touch the config file if any of the dependencies are deleted.
|
|
119
|
-
if (configDependencies.has(file)) {
|
|
120
|
-
for (let dependency of configDependencies){
|
|
121
|
-
delete require.cache[require.resolve(dependency)];
|
|
122
|
-
}
|
|
123
|
-
touch(configPath);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
let configPathCache = new _quickLru.default({
|
|
129
|
-
maxSize: 100
|
|
130
|
-
});
|
|
131
|
-
let configDependenciesCache = new WeakMap();
|
|
132
|
-
function getConfigDependencies(context) {
|
|
133
|
-
if (!configDependenciesCache.has(context)) {
|
|
134
|
-
configDependenciesCache.set(context, new Set());
|
|
135
|
-
}
|
|
136
|
-
return configDependenciesCache.get(context);
|
|
137
|
-
}
|
|
138
|
-
let candidateFilesCache = new WeakMap();
|
|
139
|
-
function getCandidateFiles(context, tailwindConfig) {
|
|
140
|
-
if (candidateFilesCache.has(context)) {
|
|
141
|
-
return candidateFilesCache.get(context);
|
|
142
|
-
}
|
|
143
|
-
let candidateFiles = tailwindConfig.content.files.filter((item)=>typeof item === 'string'
|
|
144
|
-
).map((contentPath)=>(0, _normalizePath).default(contentPath)
|
|
145
|
-
);
|
|
146
|
-
return candidateFilesCache.set(context, candidateFiles).get(context);
|
|
147
|
-
}
|
|
148
|
-
// Get the config object based on a path
|
|
149
|
-
function getTailwindConfig(configOrPath) {
|
|
150
|
-
let userConfigPath = (0, _resolveConfigPath).default(configOrPath);
|
|
151
|
-
if (userConfigPath !== null) {
|
|
152
|
-
let [prevConfig, prevModified = -Infinity, prevConfigHash] = configPathCache.get(userConfigPath) || [];
|
|
153
|
-
let modified = _fs.default.statSync(userConfigPath).mtimeMs;
|
|
154
|
-
// It hasn't changed (based on timestamp)
|
|
155
|
-
if (modified <= prevModified) {
|
|
156
|
-
return [
|
|
157
|
-
prevConfig,
|
|
158
|
-
userConfigPath,
|
|
159
|
-
prevConfigHash,
|
|
160
|
-
[
|
|
161
|
-
userConfigPath
|
|
162
|
-
]
|
|
163
|
-
];
|
|
164
|
-
}
|
|
165
|
-
// It has changed (based on timestamp), or first run
|
|
166
|
-
delete require.cache[userConfigPath];
|
|
167
|
-
let newConfig = (0, _resolveConfig).default(require(userConfigPath));
|
|
168
|
-
let newHash = (0, _hashConfig).default(newConfig);
|
|
169
|
-
configPathCache.set(userConfigPath, [
|
|
170
|
-
newConfig,
|
|
171
|
-
modified,
|
|
172
|
-
newHash
|
|
173
|
-
]);
|
|
174
|
-
return [
|
|
175
|
-
newConfig,
|
|
176
|
-
userConfigPath,
|
|
177
|
-
newHash,
|
|
178
|
-
[
|
|
179
|
-
userConfigPath
|
|
180
|
-
]
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
// It's a plain object, not a path
|
|
184
|
-
let newConfig = (0, _resolveConfig).default(configOrPath.config === undefined ? configOrPath : configOrPath.config);
|
|
185
|
-
return [
|
|
186
|
-
newConfig,
|
|
187
|
-
null,
|
|
188
|
-
(0, _hashConfig).default(newConfig),
|
|
189
|
-
[]
|
|
190
|
-
];
|
|
191
|
-
}
|
|
192
|
-
function resolvedChangedContent(context, candidateFiles) {
|
|
193
|
-
let changedContent = context.tailwindConfig.content.files.filter((item)=>typeof item.raw === 'string'
|
|
194
|
-
).map(({ raw , extension ='html' })=>({
|
|
195
|
-
content: raw,
|
|
196
|
-
extension
|
|
197
|
-
})
|
|
198
|
-
);
|
|
199
|
-
for (let changedFile of resolveChangedFiles(context, candidateFiles)){
|
|
200
|
-
let content = _fs.default.readFileSync(changedFile, 'utf8');
|
|
201
|
-
let extension = _path.default.extname(changedFile).slice(1);
|
|
202
|
-
changedContent.push({
|
|
203
|
-
content,
|
|
204
|
-
extension
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
return changedContent;
|
|
208
|
-
}
|
|
209
|
-
let scannedContentCache = new WeakMap();
|
|
210
|
-
function resolveChangedFiles(context, candidateFiles) {
|
|
211
|
-
let changedFiles = new Set();
|
|
212
|
-
// If we're not set up and watching files ourselves, we need to do
|
|
213
|
-
// the work of grabbing all of the template files for candidate
|
|
214
|
-
// detection.
|
|
215
|
-
if (!scannedContentCache.has(context)) {
|
|
216
|
-
let files = _fastGlob.default.sync(candidateFiles);
|
|
217
|
-
for (let file of files){
|
|
218
|
-
changedFiles.add(file);
|
|
219
|
-
}
|
|
220
|
-
scannedContentCache.set(context, true);
|
|
221
|
-
}
|
|
222
|
-
return changedFiles;
|
|
223
|
-
}
|
|
224
|
-
function setupWatchingContext(configOrPath) {
|
|
225
|
-
return ({ tailwindDirectives , registerDependency })=>{
|
|
226
|
-
return (root, result)=>{
|
|
227
|
-
let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = getTailwindConfig(configOrPath);
|
|
228
|
-
let contextDependencies = new Set(configDependencies);
|
|
229
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
|
|
230
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
231
|
-
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
232
|
-
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
233
|
-
// in another file since independent sources are effectively isolated.
|
|
234
|
-
if (tailwindDirectives.size > 0) {
|
|
235
|
-
// Add current css file as a context dependencies.
|
|
236
|
-
contextDependencies.add(result.opts.from);
|
|
237
|
-
// Add all css @import dependencies as context dependencies.
|
|
238
|
-
for (let message of result.messages){
|
|
239
|
-
if (message.type === 'dependency') {
|
|
240
|
-
contextDependencies.add(message.file);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
let [context, isNewContext] = (0, _setupContextUtils).getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies);
|
|
245
|
-
let candidateFiles = getCandidateFiles(context, tailwindConfig);
|
|
246
|
-
let contextConfigDependencies = getConfigDependencies(context);
|
|
247
|
-
for (let file of configDependencies){
|
|
248
|
-
registerDependency({
|
|
249
|
-
type: 'dependency',
|
|
250
|
-
file
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
context.disposables.push((oldContext)=>{
|
|
254
|
-
let watcher = getWatcher(oldContext);
|
|
255
|
-
if (watcher !== null) {
|
|
256
|
-
watcher.close();
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
let configPath = getConfigPath(context, configOrPath);
|
|
260
|
-
if (configPath !== null) {
|
|
261
|
-
for (let dependency of (0, _getModuleDependencies).default(configPath)){
|
|
262
|
-
if (dependency.file === configPath) {
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
contextConfigDependencies.add(dependency.file);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (isNewContext) {
|
|
269
|
-
rebootWatcher(context, configPath, contextConfigDependencies, candidateFiles);
|
|
270
|
-
}
|
|
271
|
-
// Register our temp file as a dependency — we write to this file
|
|
272
|
-
// to trigger rebuilds.
|
|
273
|
-
let touchFile = getTouchFile(context);
|
|
274
|
-
if (touchFile) {
|
|
275
|
-
registerDependency({
|
|
276
|
-
type: 'dependency',
|
|
277
|
-
file: touchFile
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
if (tailwindDirectives.size > 0) {
|
|
281
|
-
for (let changedContent of resolvedChangedContent(context, candidateFiles)){
|
|
282
|
-
context.changedContent.push(changedContent);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return context;
|
|
286
|
-
};
|
|
287
|
-
};
|
|
288
|
-
}
|