tailwindcss 3.0.8 → 3.0.12

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/lib/cli.js +49 -12
  3. package/lib/corePlugins.js +114 -142
  4. package/lib/css/preflight.css +1 -1
  5. package/lib/featureFlags.js +1 -3
  6. package/lib/index.js +1 -3
  7. package/lib/lib/collapseDuplicateDeclarations.js +52 -1
  8. package/lib/lib/defaultExtractor.js +2 -0
  9. package/lib/lib/expandApplyAtRules.js +0 -40
  10. package/lib/lib/expandTailwindAtRules.js +12 -25
  11. package/lib/lib/normalizeTailwindDirectives.js +8 -1
  12. package/lib/lib/resolveDefaultsAtRules.js +4 -4
  13. package/lib/lib/setupContextUtils.js +131 -69
  14. package/lib/lib/setupTrackingContext.js +11 -10
  15. package/lib/lib/sharedState.js +33 -4
  16. package/lib/processTailwindFeatures.js +3 -2
  17. package/lib/util/pluginUtils.js +1 -1
  18. package/package.json +7 -8
  19. package/peers/index.js +606 -606
  20. package/src/cli.js +57 -12
  21. package/src/corePlugins.js +121 -155
  22. package/src/css/preflight.css +1 -1
  23. package/src/featureFlags.js +1 -5
  24. package/src/index.js +1 -7
  25. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  26. package/src/lib/defaultExtractor.js +2 -0
  27. package/src/lib/expandApplyAtRules.js +0 -42
  28. package/src/lib/expandTailwindAtRules.js +12 -21
  29. package/src/lib/normalizeTailwindDirectives.js +6 -1
  30. package/src/lib/resolveDefaultsAtRules.js +5 -5
  31. package/src/lib/setupContextUtils.js +108 -19
  32. package/src/lib/setupTrackingContext.js +11 -10
  33. package/src/lib/sharedState.js +40 -4
  34. package/src/processTailwindFeatures.js +4 -2
  35. package/src/util/pluginUtils.js +1 -1
  36. package/lib/lib/setupWatchingContext.js +0 -288
  37. package/src/lib/setupWatchingContext.js +0 -311
@@ -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
- }
@@ -1,311 +0,0 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
-
4
- import tmp from 'tmp'
5
- import chokidar from 'chokidar'
6
- import fastGlob from 'fast-glob'
7
- import LRU from 'quick-lru'
8
- import normalizePath from 'normalize-path'
9
-
10
- import hash from '../util/hashConfig'
11
- import log from '../util/log'
12
- import getModuleDependencies from '../lib/getModuleDependencies'
13
- import resolveConfig from '../public/resolve-config'
14
- import resolveConfigPath from '../util/resolveConfigPath'
15
- import { getContext } from './setupContextUtils'
16
-
17
- // This is used to trigger rebuilds. Just updating the timestamp
18
- // is significantly faster than actually writing to the file (10x).
19
-
20
- function touch(filename) {
21
- let time = new Date()
22
-
23
- try {
24
- fs.utimesSync(filename, time, time)
25
- } catch (err) {
26
- fs.closeSync(fs.openSync(filename, 'w'))
27
- }
28
- }
29
-
30
- let watchers = new WeakMap()
31
-
32
- function getWatcher(context) {
33
- if (watchers.has(context)) {
34
- return watchers.get(context)
35
- }
36
-
37
- return null
38
- }
39
-
40
- function setWatcher(context, watcher) {
41
- return watchers.set(context, watcher)
42
- }
43
-
44
- let touchFiles = new WeakMap()
45
-
46
- function getTouchFile(context) {
47
- if (touchFiles.has(context)) {
48
- return touchFiles.get(context)
49
- }
50
-
51
- return null
52
- }
53
-
54
- function setTouchFile(context, touchFile) {
55
- return touchFiles.set(context, touchFile)
56
- }
57
-
58
- let configPaths = new WeakMap()
59
-
60
- function getConfigPath(context, configOrPath) {
61
- if (!configPaths.has(context)) {
62
- configPaths.set(context, resolveConfigPath(configOrPath))
63
- }
64
-
65
- return configPaths.get(context)
66
- }
67
-
68
- function rebootWatcher(context, configPath, configDependencies, candidateFiles) {
69
- let touchFile = getTouchFile(context)
70
-
71
- if (touchFile === null) {
72
- touchFile = tmp.fileSync().name
73
- setTouchFile(context, touchFile)
74
- touch(touchFile)
75
- }
76
-
77
- let watcher = getWatcher(context)
78
-
79
- Promise.resolve(watcher ? watcher.close() : null).then(() => {
80
- log.info([
81
- 'Tailwind CSS is watching for changes...',
82
- 'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds',
83
- ])
84
-
85
- watcher = chokidar.watch([...candidateFiles, ...configDependencies], {
86
- ignoreInitial: true,
87
- awaitWriteFinish:
88
- process.platform === 'win32'
89
- ? {
90
- stabilityThreshold: 50,
91
- pollInterval: 10,
92
- }
93
- : false,
94
- })
95
-
96
- setWatcher(context, watcher)
97
-
98
- watcher.on('add', (file) => {
99
- let changedFile = path.resolve('.', file)
100
- let content = fs.readFileSync(changedFile, 'utf8')
101
- let extension = path.extname(changedFile).slice(1)
102
- context.changedContent.push({ content, extension })
103
- touch(touchFile)
104
- })
105
-
106
- watcher.on('change', (file) => {
107
- // If it was a config dependency, touch the config file to trigger a new context.
108
- // This is not really that clean of a solution but it's the fastest, because we
109
- // can do a very quick check on each build to see if the config has changed instead
110
- // of having to get all of the module dependencies and check every timestamp each
111
- // time.
112
- if (configDependencies.has(file)) {
113
- for (let dependency of configDependencies) {
114
- delete require.cache[require.resolve(dependency)]
115
- }
116
- touch(configPath)
117
- } else {
118
- let changedFile = path.resolve('.', file)
119
- let content = fs.readFileSync(changedFile, 'utf8')
120
- let extension = path.extname(changedFile).slice(1)
121
- context.changedContent.push({ content, extension })
122
- touch(touchFile)
123
- }
124
- })
125
-
126
- watcher.on('unlink', (file) => {
127
- // Touch the config file if any of the dependencies are deleted.
128
- if (configDependencies.has(file)) {
129
- for (let dependency of configDependencies) {
130
- delete require.cache[require.resolve(dependency)]
131
- }
132
- touch(configPath)
133
- }
134
- })
135
- })
136
- }
137
-
138
- let configPathCache = new LRU({ maxSize: 100 })
139
-
140
- let configDependenciesCache = new WeakMap()
141
-
142
- function getConfigDependencies(context) {
143
- if (!configDependenciesCache.has(context)) {
144
- configDependenciesCache.set(context, new Set())
145
- }
146
-
147
- return configDependenciesCache.get(context)
148
- }
149
-
150
- let candidateFilesCache = new WeakMap()
151
-
152
- function getCandidateFiles(context, tailwindConfig) {
153
- if (candidateFilesCache.has(context)) {
154
- return candidateFilesCache.get(context)
155
- }
156
-
157
- let candidateFiles = tailwindConfig.content.files
158
- .filter((item) => typeof item === 'string')
159
- .map((contentPath) => normalizePath(contentPath))
160
-
161
- return candidateFilesCache.set(context, candidateFiles).get(context)
162
- }
163
-
164
- // Get the config object based on a path
165
- function getTailwindConfig(configOrPath) {
166
- let userConfigPath = resolveConfigPath(configOrPath)
167
-
168
- if (userConfigPath !== null) {
169
- let [prevConfig, prevModified = -Infinity, prevConfigHash] =
170
- configPathCache.get(userConfigPath) || []
171
- let modified = fs.statSync(userConfigPath).mtimeMs
172
-
173
- // It hasn't changed (based on timestamp)
174
- if (modified <= prevModified) {
175
- return [prevConfig, userConfigPath, prevConfigHash, [userConfigPath]]
176
- }
177
-
178
- // It has changed (based on timestamp), or first run
179
- delete require.cache[userConfigPath]
180
- let newConfig = resolveConfig(require(userConfigPath))
181
- let newHash = hash(newConfig)
182
- configPathCache.set(userConfigPath, [newConfig, modified, newHash])
183
- return [newConfig, userConfigPath, newHash, [userConfigPath]]
184
- }
185
-
186
- // It's a plain object, not a path
187
- let newConfig = resolveConfig(
188
- configOrPath.config === undefined ? configOrPath : configOrPath.config
189
- )
190
-
191
- return [newConfig, null, hash(newConfig), []]
192
- }
193
-
194
- function resolvedChangedContent(context, candidateFiles) {
195
- let changedContent = context.tailwindConfig.content.files
196
- .filter((item) => typeof item.raw === 'string')
197
- .map(({ raw, extension = 'html' }) => ({ content: raw, extension }))
198
-
199
- for (let changedFile of resolveChangedFiles(context, candidateFiles)) {
200
- let content = fs.readFileSync(changedFile, 'utf8')
201
- let extension = path.extname(changedFile).slice(1)
202
- changedContent.push({ content, extension })
203
- }
204
- return changedContent
205
- }
206
-
207
- let scannedContentCache = new WeakMap()
208
-
209
- function resolveChangedFiles(context, candidateFiles) {
210
- let changedFiles = new Set()
211
-
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.sync(candidateFiles)
217
- for (let file of files) {
218
- changedFiles.add(file)
219
- }
220
- scannedContentCache.set(context, true)
221
- }
222
-
223
- return changedFiles
224
- }
225
-
226
- // DISABLE_TOUCH = FALSE
227
-
228
- // Retrieve an existing context from cache if possible (since contexts are unique per
229
- // source path), or set up a new one (including setting up watchers and registering
230
- // plugins) then return it
231
- export default function setupWatchingContext(configOrPath) {
232
- return ({ tailwindDirectives, registerDependency }) => {
233
- return (root, result) => {
234
- let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] =
235
- getTailwindConfig(configOrPath)
236
-
237
- let contextDependencies = new Set(configDependencies)
238
-
239
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
240
- // to be dependencies of the context. Can reuse the context even if they change.
241
- // We may want to think about `@layer` being part of this trigger too, but it's tough
242
- // because it's impossible for a layer in one file to end up in the actual @tailwind rule
243
- // in another file since independent sources are effectively isolated.
244
- if (tailwindDirectives.size > 0) {
245
- // Add current css file as a context dependencies.
246
- contextDependencies.add(result.opts.from)
247
-
248
- // Add all css @import dependencies as context dependencies.
249
- for (let message of result.messages) {
250
- if (message.type === 'dependency') {
251
- contextDependencies.add(message.file)
252
- }
253
- }
254
- }
255
-
256
- let [context, isNewContext] = getContext(
257
- root,
258
- result,
259
- tailwindConfig,
260
- userConfigPath,
261
- tailwindConfigHash,
262
- contextDependencies
263
- )
264
-
265
- let candidateFiles = getCandidateFiles(context, tailwindConfig)
266
- let contextConfigDependencies = getConfigDependencies(context)
267
-
268
- for (let file of configDependencies) {
269
- registerDependency({ type: 'dependency', file })
270
- }
271
-
272
- context.disposables.push((oldContext) => {
273
- let watcher = getWatcher(oldContext)
274
- if (watcher !== null) {
275
- watcher.close()
276
- }
277
- })
278
-
279
- let configPath = getConfigPath(context, configOrPath)
280
-
281
- if (configPath !== null) {
282
- for (let dependency of getModuleDependencies(configPath)) {
283
- if (dependency.file === configPath) {
284
- continue
285
- }
286
-
287
- contextConfigDependencies.add(dependency.file)
288
- }
289
- }
290
-
291
- if (isNewContext) {
292
- rebootWatcher(context, configPath, contextConfigDependencies, candidateFiles)
293
- }
294
-
295
- // Register our temp file as a dependency — we write to this file
296
- // to trigger rebuilds.
297
- let touchFile = getTouchFile(context)
298
- if (touchFile) {
299
- registerDependency({ type: 'dependency', file: touchFile })
300
- }
301
-
302
- if (tailwindDirectives.size > 0) {
303
- for (let changedContent of resolvedChangedContent(context, candidateFiles)) {
304
- context.changedContent.push(changedContent)
305
- }
306
- }
307
-
308
- return context
309
- }
310
- }
311
- }