tailwindcss 0.0.0-insiders.ea139f2 → 0.0.0-insiders.ea3d9cd

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 (232) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -7
  3. package/colors.d.ts +3 -0
  4. package/colors.js +2 -1
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultConfig.js +2 -1
  7. package/defaultTheme.d.ts +4 -0
  8. package/defaultTheme.js +2 -1
  9. package/index.css +5 -0
  10. package/lib/cli/build/index.js +57 -0
  11. package/lib/cli/build/plugin.js +381 -0
  12. package/lib/cli/build/utils.js +88 -0
  13. package/lib/cli/build/watching.js +182 -0
  14. package/lib/cli/help/index.js +73 -0
  15. package/lib/cli/index.js +231 -0
  16. package/lib/cli/init/index.js +63 -0
  17. package/lib/cli.js +1 -704
  18. package/lib/corePluginList.js +13 -3
  19. package/lib/corePlugins.js +2399 -1865
  20. package/lib/css/preflight.css +17 -9
  21. package/lib/featureFlags.js +50 -26
  22. package/lib/index.js +1 -31
  23. package/lib/lib/cacheInvalidation.js +92 -0
  24. package/lib/lib/collapseAdjacentRules.js +30 -10
  25. package/lib/lib/collapseDuplicateDeclarations.js +60 -4
  26. package/lib/lib/content.js +207 -0
  27. package/lib/lib/defaultExtractor.js +243 -0
  28. package/lib/lib/detectNesting.js +21 -10
  29. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  30. package/lib/lib/expandApplyAtRules.js +467 -161
  31. package/lib/lib/expandTailwindAtRules.js +200 -133
  32. package/lib/lib/findAtConfigPath.js +46 -0
  33. package/lib/lib/generateRules.js +550 -200
  34. package/lib/lib/getModuleDependencies.js +88 -37
  35. package/lib/lib/handleImportAtRules.js +50 -0
  36. package/lib/lib/load-config.js +42 -0
  37. package/lib/lib/normalizeTailwindDirectives.js +36 -38
  38. package/lib/lib/offsets.js +306 -0
  39. package/lib/lib/partitionApplyAtRules.js +58 -0
  40. package/lib/lib/regex.js +74 -0
  41. package/lib/lib/remap-bitfield.js +89 -0
  42. package/lib/lib/resolveDefaultsAtRules.js +98 -58
  43. package/lib/lib/setupContextUtils.js +767 -325
  44. package/lib/lib/setupTrackingContext.js +71 -75
  45. package/lib/lib/sharedState.js +70 -10
  46. package/lib/lib/substituteScreenAtRules.js +14 -10
  47. package/lib/plugin.js +116 -0
  48. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  49. package/lib/postcss-plugins/nesting/index.js +21 -0
  50. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  51. package/lib/processTailwindFeatures.js +39 -26
  52. package/lib/public/colors.js +272 -246
  53. package/lib/public/create-plugin.js +9 -5
  54. package/lib/public/default-config.js +10 -6
  55. package/lib/public/default-theme.js +10 -6
  56. package/lib/public/load-config.js +12 -0
  57. package/lib/public/resolve-config.js +11 -6
  58. package/lib/util/applyImportantSelector.js +36 -0
  59. package/lib/util/bigSign.js +6 -1
  60. package/lib/util/buildMediaQuery.js +13 -6
  61. package/lib/util/cloneDeep.js +9 -6
  62. package/lib/util/cloneNodes.js +23 -3
  63. package/lib/util/color.js +70 -38
  64. package/lib/util/colorNames.js +752 -0
  65. package/lib/util/configurePlugins.js +7 -2
  66. package/lib/util/createPlugin.js +8 -6
  67. package/lib/util/createUtilityPlugin.js +16 -16
  68. package/lib/util/dataTypes.js +182 -109
  69. package/lib/util/defaults.js +14 -3
  70. package/lib/util/escapeClassName.js +13 -8
  71. package/lib/util/escapeCommas.js +7 -2
  72. package/lib/util/flattenColorPalette.js +11 -12
  73. package/lib/util/formatVariantSelector.js +228 -151
  74. package/lib/util/getAllConfigs.js +33 -12
  75. package/lib/util/hashConfig.js +9 -4
  76. package/lib/util/isKeyframeRule.js +7 -2
  77. package/lib/util/isPlainObject.js +7 -2
  78. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  79. package/lib/util/log.js +44 -13
  80. package/lib/util/nameClass.js +27 -10
  81. package/lib/util/negateValue.js +25 -8
  82. package/lib/util/normalizeConfig.js +167 -67
  83. package/lib/util/normalizeScreens.js +131 -11
  84. package/lib/util/parseAnimationValue.js +44 -40
  85. package/lib/util/parseBoxShadowValue.js +34 -23
  86. package/lib/util/parseDependency.js +39 -55
  87. package/lib/util/parseGlob.js +36 -0
  88. package/lib/util/parseObjectStyles.js +15 -10
  89. package/lib/util/pluginUtils.js +157 -69
  90. package/lib/util/prefixSelector.js +30 -12
  91. package/lib/util/pseudoElements.js +209 -0
  92. package/lib/util/removeAlphaVariables.js +31 -0
  93. package/lib/util/resolveConfig.js +97 -75
  94. package/lib/util/resolveConfigPath.js +30 -12
  95. package/lib/util/responsive.js +11 -6
  96. package/lib/util/splitAtTopLevelOnly.js +51 -0
  97. package/lib/util/tap.js +6 -1
  98. package/lib/util/toColorValue.js +7 -3
  99. package/lib/util/toPath.js +26 -3
  100. package/lib/util/transformThemeValue.js +40 -30
  101. package/lib/util/validateConfig.js +48 -0
  102. package/lib/util/validateFormalSyntax.js +26 -0
  103. package/lib/util/withAlphaVariable.js +27 -15
  104. package/lib/value-parser/LICENSE +22 -0
  105. package/lib/value-parser/README.md +3 -0
  106. package/lib/value-parser/index.d.js +2 -0
  107. package/lib/value-parser/index.js +22 -0
  108. package/lib/value-parser/parse.js +259 -0
  109. package/lib/value-parser/stringify.js +38 -0
  110. package/lib/value-parser/unit.js +86 -0
  111. package/lib/value-parser/walk.js +16 -0
  112. package/loadConfig.d.ts +4 -0
  113. package/loadConfig.js +2 -0
  114. package/nesting/index.js +2 -12
  115. package/package.json +61 -59
  116. package/plugin.d.ts +11 -0
  117. package/plugin.js +2 -1
  118. package/resolveConfig.d.ts +12 -0
  119. package/resolveConfig.js +2 -1
  120. package/scripts/generate-types.js +105 -0
  121. package/scripts/release-channel.js +18 -0
  122. package/scripts/release-notes.js +21 -0
  123. package/scripts/type-utils.js +27 -0
  124. package/src/cli/build/index.js +53 -0
  125. package/src/cli/build/plugin.js +457 -0
  126. package/src/cli/build/utils.js +76 -0
  127. package/src/cli/build/watching.js +229 -0
  128. package/src/cli/help/index.js +70 -0
  129. package/src/cli/index.js +217 -0
  130. package/src/cli/init/index.js +79 -0
  131. package/src/cli.js +1 -766
  132. package/src/corePluginList.js +1 -1
  133. package/src/corePlugins.js +816 -308
  134. package/src/css/preflight.css +17 -9
  135. package/src/featureFlags.js +20 -6
  136. package/src/index.js +1 -34
  137. package/src/lib/cacheInvalidation.js +52 -0
  138. package/src/lib/collapseAdjacentRules.js +21 -2
  139. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  140. package/src/lib/content.js +240 -0
  141. package/src/lib/defaultExtractor.js +217 -0
  142. package/src/lib/detectNesting.js +9 -1
  143. package/src/lib/evaluateTailwindFunctions.js +83 -9
  144. package/src/lib/expandApplyAtRules.js +515 -153
  145. package/src/lib/expandTailwindAtRules.js +147 -86
  146. package/src/lib/findAtConfigPath.js +48 -0
  147. package/src/lib/generateRules.js +541 -147
  148. package/src/lib/getModuleDependencies.js +70 -30
  149. package/src/lib/handleImportAtRules.js +34 -0
  150. package/src/lib/load-config.ts +31 -0
  151. package/src/lib/normalizeTailwindDirectives.js +5 -26
  152. package/src/lib/offsets.js +373 -0
  153. package/src/lib/partitionApplyAtRules.js +52 -0
  154. package/src/lib/regex.js +74 -0
  155. package/src/lib/remap-bitfield.js +82 -0
  156. package/src/lib/resolveDefaultsAtRules.js +59 -17
  157. package/src/lib/setupContextUtils.js +693 -176
  158. package/src/lib/setupTrackingContext.js +52 -65
  159. package/src/lib/sharedState.js +54 -7
  160. package/src/plugin.js +124 -0
  161. package/src/postcss-plugins/nesting/README.md +42 -0
  162. package/src/postcss-plugins/nesting/index.js +13 -0
  163. package/src/postcss-plugins/nesting/plugin.js +80 -0
  164. package/src/processTailwindFeatures.js +12 -2
  165. package/src/public/colors.js +22 -0
  166. package/src/public/default-config.js +1 -1
  167. package/src/public/default-theme.js +2 -2
  168. package/src/public/load-config.js +2 -0
  169. package/src/util/applyImportantSelector.js +27 -0
  170. package/src/util/buildMediaQuery.js +5 -3
  171. package/src/util/cloneNodes.js +19 -2
  172. package/src/util/color.js +44 -12
  173. package/src/util/colorNames.js +150 -0
  174. package/src/util/dataTypes.js +64 -18
  175. package/src/util/defaults.js +6 -0
  176. package/src/util/formatVariantSelector.js +264 -144
  177. package/src/util/getAllConfigs.js +21 -2
  178. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  179. package/src/util/log.js +35 -7
  180. package/src/util/nameClass.js +4 -0
  181. package/src/util/negateValue.js +11 -3
  182. package/src/util/normalizeConfig.js +86 -7
  183. package/src/util/normalizeScreens.js +105 -7
  184. package/src/util/parseBoxShadowValue.js +4 -3
  185. package/src/util/parseDependency.js +37 -42
  186. package/src/util/parseGlob.js +24 -0
  187. package/src/util/pluginUtils.js +118 -23
  188. package/src/util/prefixSelector.js +30 -10
  189. package/src/util/pseudoElements.js +167 -0
  190. package/src/util/removeAlphaVariables.js +24 -0
  191. package/src/util/resolveConfig.js +74 -26
  192. package/src/util/resolveConfigPath.js +12 -1
  193. package/src/util/splitAtTopLevelOnly.js +52 -0
  194. package/src/util/toPath.js +23 -1
  195. package/src/util/transformThemeValue.js +13 -3
  196. package/src/util/validateConfig.js +36 -0
  197. package/src/util/validateFormalSyntax.js +34 -0
  198. package/src/util/withAlphaVariable.js +1 -1
  199. package/src/value-parser/LICENSE +22 -0
  200. package/src/value-parser/README.md +3 -0
  201. package/src/value-parser/index.d.ts +177 -0
  202. package/src/value-parser/index.js +28 -0
  203. package/src/value-parser/parse.js +303 -0
  204. package/src/value-parser/stringify.js +41 -0
  205. package/src/value-parser/unit.js +118 -0
  206. package/src/value-parser/walk.js +18 -0
  207. package/stubs/.gitignore +1 -0
  208. package/stubs/.prettierrc.json +6 -0
  209. package/stubs/{defaultConfig.stub.js → config.full.js} +220 -167
  210. package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
  211. package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
  212. package/stubs/postcss.config.js +5 -0
  213. package/stubs/tailwind.config.cjs +2 -0
  214. package/stubs/tailwind.config.js +2 -0
  215. package/stubs/tailwind.config.ts +3 -0
  216. package/types/config.d.ts +369 -0
  217. package/types/generated/.gitkeep +0 -0
  218. package/types/generated/colors.d.ts +298 -0
  219. package/types/generated/corePluginList.d.ts +1 -0
  220. package/types/generated/default-theme.d.ts +372 -0
  221. package/types/index.d.ts +7 -0
  222. package/CHANGELOG.md +0 -1843
  223. package/lib/cli-peer-dependencies.js +0 -15
  224. package/lib/constants.js +0 -37
  225. package/lib/lib/setupWatchingContext.js +0 -288
  226. package/nesting/plugin.js +0 -41
  227. package/peers/index.js +0 -76015
  228. package/scripts/install-integrations.js +0 -27
  229. package/scripts/rebuildFixtures.js +0 -68
  230. package/src/cli-peer-dependencies.js +0 -9
  231. package/src/constants.js +0 -17
  232. package/src/lib/setupWatchingContext.js +0 -311
@@ -1,27 +0,0 @@
1
- let fs = require('fs/promises')
2
- let { spawn } = require('child_process')
3
- let path = require('path')
4
- let root = process.cwd()
5
-
6
- function npmInstall(cwd) {
7
- return new Promise((resolve) => {
8
- let childProcess = spawn('npm', ['install'], { cwd })
9
- childProcess.on('exit', resolve)
10
- })
11
- }
12
-
13
- async function install() {
14
- let base = path.resolve(root, 'integrations')
15
- let ignoreFolders = ['node_modules']
16
- let integrations = (await fs.readdir(base, { withFileTypes: true }))
17
- .filter((integration) => integration.isDirectory())
18
- .filter((integration) => !ignoreFolders.includes(integration.name))
19
- .map((folder) => path.resolve(base, folder.name))
20
- .concat([base])
21
- .map((integration) => npmInstall(integration))
22
-
23
- await Promise.all(integrations)
24
- console.log('Done!')
25
- }
26
-
27
- install()
@@ -1,68 +0,0 @@
1
- import fs from 'fs'
2
- import postcss from 'postcss'
3
- import tailwind from '..'
4
-
5
- function build({ from, to, config }) {
6
- return new Promise((resolve, reject) => {
7
- console.log(`Processing ./${from}...`)
8
-
9
- fs.readFile(`./${from}`, (err, css) => {
10
- if (err) throw err
11
-
12
- return postcss([tailwind(config)])
13
- .process(css, {
14
- from: undefined,
15
- })
16
- .then((result) => {
17
- fs.writeFileSync(`./${to}`, result.css)
18
- return result
19
- })
20
- .then(resolve)
21
- .catch((error) => {
22
- console.log(error)
23
- reject()
24
- })
25
- })
26
- })
27
- }
28
-
29
- console.info('\nRebuilding fixtures...\n')
30
-
31
- Promise.all([
32
- build({
33
- from: 'tests/fixtures/tailwind-input.css',
34
- to: 'tests/fixtures/tailwind-output.css',
35
- config: {},
36
- }),
37
- build({
38
- from: 'tests/fixtures/tailwind-input.css',
39
- to: 'tests/fixtures/tailwind-output-important.css',
40
- config: { important: true },
41
- }),
42
- build({
43
- from: 'tests/fixtures/tailwind-input.css',
44
- to: 'tests/fixtures/tailwind-output-no-color-opacity.css',
45
- config: {
46
- corePlugins: {
47
- textOpacity: false,
48
- backgroundOpacity: false,
49
- borderOpacity: false,
50
- placeholderOpacity: false,
51
- divideOpacity: false,
52
- },
53
- },
54
- }),
55
- build({
56
- from: 'tests/fixtures/tailwind-input.css',
57
- to: 'tests/fixtures/tailwind-output-flagged.css',
58
- config: {
59
- future: 'all',
60
- experimental: 'all',
61
- },
62
- }),
63
- ]).then(() => {
64
- console.log('\nFinished rebuilding fixtures.')
65
- console.log(
66
- '\nPlease triple check that the fixture output matches what you expect before committing this change.'
67
- )
68
- })
@@ -1,9 +0,0 @@
1
- export let postcss = require('postcss')
2
-
3
- export function lazyAutoprefixer() {
4
- return require('autoprefixer')
5
- }
6
-
7
- export function lazyCssnano() {
8
- return require('cssnano')
9
- }
package/src/constants.js DELETED
@@ -1,17 +0,0 @@
1
- import path from 'path'
2
-
3
- export const cli = 'tailwind'
4
- export const defaultConfigFile = './tailwind.config.js'
5
- export const defaultPostCssConfigFile = './postcss.config.js'
6
- export const cjsConfigFile = './tailwind.config.cjs'
7
- export const cjsPostCssConfigFile = './postcss.config.cjs'
8
-
9
- export const supportedConfigFiles = [cjsConfigFile, defaultConfigFile]
10
- export const supportedPostCssConfigFile = [cjsPostCssConfigFile, defaultPostCssConfigFile]
11
-
12
- export const defaultConfigStubFile = path.resolve(__dirname, '../stubs/defaultConfig.stub.js')
13
- export const simpleConfigStubFile = path.resolve(__dirname, '../stubs/simpleConfig.stub.js')
14
- export const defaultPostCssConfigStubFile = path.resolve(
15
- __dirname,
16
- '../stubs/defaultPostCssConfig.stub.js'
17
- )
@@ -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
- }