tailwindcss 3.2.7 → 3.3.1

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 (87) hide show
  1. package/CHANGELOG.md +55 -8
  2. package/lib/cli/build/index.js +7 -3
  3. package/lib/cli/build/plugin.js +28 -19
  4. package/lib/cli/build/watching.js +4 -2
  5. package/lib/cli/index.js +12 -21
  6. package/lib/cli/init/index.js +21 -6
  7. package/lib/corePluginList.js +4 -0
  8. package/lib/corePlugins.js +282 -26
  9. package/lib/css/preflight.css +2 -0
  10. package/lib/featureFlags.js +8 -1
  11. package/lib/lib/expandApplyAtRules.js +12 -1
  12. package/lib/lib/generateRules.js +14 -10
  13. package/lib/lib/getModuleDependencies.js +79 -33
  14. package/lib/lib/load-config.js +40 -0
  15. package/lib/lib/setupContextUtils.js +10 -2
  16. package/lib/lib/setupTrackingContext.js +4 -4
  17. package/lib/lib/sharedState.js +6 -1
  18. package/lib/oxide/cli/build/index.js +7 -3
  19. package/lib/oxide/cli/build/plugin.js +27 -18
  20. package/lib/oxide/cli/build/watching.js +1 -1
  21. package/lib/oxide/cli/index.js +10 -16
  22. package/lib/oxide/cli/init/index.js +19 -4
  23. package/lib/public/colors.js +44 -22
  24. package/lib/public/default-config.js +2 -2
  25. package/lib/public/default-theme.js +2 -2
  26. package/lib/public/load-config.js +10 -0
  27. package/lib/util/applyImportantSelector.js +37 -0
  28. package/lib/util/dataTypes.js +3 -0
  29. package/lib/util/formatVariantSelector.js +34 -32
  30. package/lib/util/getAllConfigs.js +2 -2
  31. package/lib/util/normalizeConfig.js +2 -3
  32. package/lib/util/pluginUtils.js +9 -2
  33. package/lib/util/resolveConfigPath.js +19 -7
  34. package/lib/util/splitAtTopLevelOnly.js +7 -1
  35. package/lib/util/validateConfig.js +11 -0
  36. package/loadConfig.d.ts +4 -0
  37. package/loadConfig.js +2 -0
  38. package/package.json +5 -4
  39. package/src/cli/build/index.js +7 -7
  40. package/src/cli/build/plugin.js +28 -23
  41. package/src/cli/build/watching.js +4 -2
  42. package/src/cli/index.js +8 -26
  43. package/src/cli/init/index.js +37 -8
  44. package/src/corePluginList.js +1 -1
  45. package/src/corePlugins.js +184 -27
  46. package/src/css/preflight.css +2 -0
  47. package/src/featureFlags.js +7 -0
  48. package/src/lib/expandApplyAtRules.js +14 -1
  49. package/src/lib/generateRules.js +15 -5
  50. package/src/lib/getModuleDependencies.js +70 -30
  51. package/src/lib/load-config.ts +31 -0
  52. package/src/lib/setupContextUtils.js +9 -2
  53. package/src/lib/setupTrackingContext.js +4 -4
  54. package/src/lib/sharedState.js +15 -6
  55. package/src/oxide/cli/build/index.ts +7 -7
  56. package/src/oxide/cli/build/plugin.ts +28 -22
  57. package/src/oxide/cli/build/watching.ts +1 -1
  58. package/src/oxide/cli/index.ts +7 -15
  59. package/src/oxide/cli/init/index.ts +34 -7
  60. package/src/public/colors.js +22 -0
  61. package/src/public/default-config.js +1 -1
  62. package/src/public/default-theme.js +2 -2
  63. package/src/public/load-config.js +2 -0
  64. package/src/util/applyImportantSelector.js +30 -0
  65. package/src/util/dataTypes.js +4 -0
  66. package/src/util/formatVariantSelector.js +36 -10
  67. package/src/util/getAllConfigs.js +2 -2
  68. package/src/util/normalizeConfig.js +2 -1
  69. package/src/util/pluginUtils.js +10 -2
  70. package/src/util/resolveConfigPath.js +12 -1
  71. package/src/util/splitAtTopLevelOnly.js +8 -1
  72. package/src/util/validateConfig.js +13 -0
  73. package/stubs/.gitignore +1 -0
  74. package/stubs/.prettierrc.json +6 -0
  75. package/stubs/{defaultConfig.stub.js → config.full.js} +36 -1
  76. package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -1
  77. package/stubs/postcss.config.js +6 -0
  78. package/stubs/tailwind.config.cjs +2 -0
  79. package/stubs/tailwind.config.js +2 -0
  80. package/stubs/tailwind.config.ts +3 -0
  81. package/types/config.d.ts +8 -7
  82. package/types/generated/colors.d.ts +22 -0
  83. package/types/generated/corePluginList.d.ts +1 -1
  84. package/types/generated/default-theme.d.ts +31 -2
  85. package/lib/constants.js +0 -44
  86. package/src/constants.js +0 -17
  87. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -12,12 +12,13 @@ import { loadAutoprefixer, loadCssNano, loadPostcss, loadPostcssImport } from '.
12
12
  import { formatNodes, drainStdin, outputFile } from './utils'
13
13
  import { env } from '../../lib/sharedState'
14
14
  import resolveConfig from '../../../resolveConfig.js'
15
- import getModuleDependencies from '../../lib/getModuleDependencies.js'
16
15
  import { parseCandidateFiles } from '../../lib/content.js'
17
16
  import { createWatcher } from './watching.js'
18
17
  import fastGlob from 'fast-glob'
19
18
  import { findAtConfigPath } from '../../lib/findAtConfigPath.js'
20
19
  import log from '../../util/log'
20
+ import { loadConfig } from '../../lib/load-config'
21
+ import getModuleDependencies from '../../lib/getModuleDependencies'
21
22
 
22
23
  /**
23
24
  *
@@ -117,7 +118,9 @@ let state = {
117
118
  /** @type {{content: string, extension: string}[]} */
118
119
  changedContent: [],
119
120
 
120
- configDependencies: new Set(),
121
+ /** @type {ReturnType<typeof load> | null} */
122
+ configBag: null,
123
+
121
124
  contextDependencies: new Set(),
122
125
 
123
126
  /** @type {import('../../lib/content.js').ContentPath[]} */
@@ -142,37 +145,35 @@ let state = {
142
145
 
143
146
  loadConfig(configPath, content) {
144
147
  if (this.watcher && configPath) {
145
- this.refreshConfigDependencies(configPath)
148
+ this.refreshConfigDependencies()
146
149
  }
147
150
 
148
- let config = configPath ? require(configPath) : {}
151
+ let config = loadConfig(configPath)
152
+ let dependencies = getModuleDependencies(configPath)
153
+ this.configBag = {
154
+ config,
155
+ dependencies,
156
+ dispose() {
157
+ for (let file of dependencies) {
158
+ delete require.cache[require.resolve(file)]
159
+ }
160
+ },
161
+ }
149
162
 
150
163
  // @ts-ignore
151
- config = resolveConfig(config, { content: { files: [] } })
164
+ this.configBag.config = resolveConfig(this.configBag.config, { content: { files: [] } })
152
165
 
153
166
  // Override content files if `--content` has been passed explicitly
154
167
  if (content?.length > 0) {
155
- config.content.files = content
168
+ this.configBag.config.content.files = content
156
169
  }
157
170
 
158
- return config
171
+ return this.configBag.config
159
172
  },
160
173
 
161
- refreshConfigDependencies(configPath) {
174
+ refreshConfigDependencies() {
162
175
  env.DEBUG && console.time('Module dependencies')
163
-
164
- for (let file of this.configDependencies) {
165
- delete require.cache[require.resolve(file)]
166
- }
167
-
168
- if (configPath) {
169
- let deps = getModuleDependencies(configPath).map(({ file }) => file)
170
-
171
- for (let dependency of deps) {
172
- this.configDependencies.add(dependency)
173
- }
174
- }
175
-
176
+ this.configBag?.dispose()
176
177
  env.DEBUG && console.timeEnd('Module dependencies')
177
178
  },
178
179
 
@@ -383,7 +384,11 @@ export async function createProcessor(args, cliConfigPath) {
383
384
  // The watcher will start watching the imported CSS files and will be
384
385
  // resilient to future errors.
385
386
 
386
- console.error(err)
387
+ if (state.watcher) {
388
+ console.error(err)
389
+ } else {
390
+ return Promise.reject(err)
391
+ }
387
392
  }
388
393
  )
389
394
  }
@@ -416,7 +421,7 @@ export async function createProcessor(args, cliConfigPath) {
416
421
  async rebuild(changes) {
417
422
  let needsNewContext = changes.some((change) => {
418
423
  return (
419
- state.configDependencies.has(change.file) ||
424
+ state.configBag?.dependencies.has(change.file) ||
420
425
  state.contextDependencies.has(change.file)
421
426
  )
422
427
  })
@@ -89,7 +89,9 @@ export function createWatcher(args, { state, rebuild }) {
89
89
  // Resolve the promise even when the rebuild fails
90
90
  return rebuild(changes).then(
91
91
  () => {},
92
- () => {}
92
+ (e) => {
93
+ console.error(e.toString())
94
+ }
93
95
  )
94
96
  }
95
97
 
@@ -220,7 +222,7 @@ export function createWatcher(args, { state, rebuild }) {
220
222
 
221
223
  refreshWatchedFiles() {
222
224
  watcher.add(Array.from(state.contextDependencies))
223
- watcher.add(Array.from(state.configDependencies))
225
+ watcher.add(Array.from(state.configBag.dependencies))
224
226
  watcher.add(state.contentPatterns.all)
225
227
  },
226
228
  }
package/src/cli/index.js CHANGED
@@ -8,29 +8,6 @@ import { build } from './build'
8
8
  import { help } from './help'
9
9
  import { init } from './init'
10
10
 
11
- function isESM() {
12
- const pkgPath = path.resolve('./package.json')
13
-
14
- try {
15
- let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
16
- return pkg.type && pkg.type === 'module'
17
- } catch (err) {
18
- return false
19
- }
20
- }
21
-
22
- let configs = isESM()
23
- ? {
24
- tailwind: 'tailwind.config.cjs',
25
- postcss: 'postcss.config.cjs',
26
- }
27
- : {
28
- tailwind: 'tailwind.config.js',
29
- postcss: 'postcss.config.js',
30
- }
31
-
32
- // ---
33
-
34
11
  function oneOf(...options) {
35
12
  return Object.assign(
36
13
  (value = true) => {
@@ -51,8 +28,13 @@ let commands = {
51
28
  init: {
52
29
  run: init,
53
30
  args: {
54
- '--full': { type: Boolean, description: `Initialize a full \`${configs.tailwind}\` file` },
55
- '--postcss': { type: Boolean, description: `Initialize a \`${configs.postcss}\` file` },
31
+ '--esm': { type: Boolean, description: `Initialize configuration file as ESM` },
32
+ '--ts': { type: Boolean, description: `Initialize configuration file as TypeScript` },
33
+ '--postcss': { type: Boolean, description: `Initialize a \`postcss.config.js\` file` },
34
+ '--full': {
35
+ type: Boolean,
36
+ description: `Include the default values for all options in the generated configuration file`,
37
+ },
56
38
  '-f': '--full',
57
39
  '-p': '--postcss',
58
40
  },
@@ -231,4 +213,4 @@ if (args['--help']) {
231
213
  process.exit(0)
232
214
  }
233
215
 
234
- run(args, configs)
216
+ run(args)
@@ -3,22 +3,49 @@
3
3
  import fs from 'fs'
4
4
  import path from 'path'
5
5
 
6
- export function init(args, configs) {
6
+ function isESM() {
7
+ const pkgPath = path.resolve('./package.json')
8
+
9
+ try {
10
+ let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
11
+ return pkg.type && pkg.type === 'module'
12
+ } catch (err) {
13
+ return false
14
+ }
15
+ }
16
+
17
+ export function init(args) {
7
18
  let messages = []
8
19
 
9
- let tailwindConfigLocation = path.resolve(args['_'][1] ?? `./${configs.tailwind}`)
20
+ let isProjectESM = args['--ts'] || args['--esm'] || isESM()
21
+ let syntax = args['--ts'] ? 'ts' : isProjectESM ? 'js' : 'cjs'
22
+ let extension = args['--ts'] ? 'ts' : 'js'
23
+
24
+ let tailwindConfigLocation = path.resolve(args['_'][1] ?? `./tailwind.config.${extension}`)
25
+
10
26
  if (fs.existsSync(tailwindConfigLocation)) {
11
27
  messages.push(`${path.basename(tailwindConfigLocation)} already exists.`)
12
28
  } else {
13
- let stubFile = fs.readFileSync(
29
+ let stubContentsFile = fs.readFileSync(
14
30
  args['--full']
15
- ? path.resolve(__dirname, '../../../stubs/defaultConfig.stub.js')
16
- : path.resolve(__dirname, '../../../stubs/simpleConfig.stub.js'),
31
+ ? path.resolve(__dirname, '../../../stubs/config.full.js')
32
+ : path.resolve(__dirname, '../../../stubs/config.simple.js'),
33
+ 'utf8'
34
+ )
35
+
36
+ let stubFile = fs.readFileSync(
37
+ path.resolve(__dirname, `../../../stubs/tailwind.config.${syntax}`),
17
38
  'utf8'
18
39
  )
19
40
 
20
41
  // Change colors import
21
- stubFile = stubFile.replace('../colors', 'tailwindcss/colors')
42
+ stubContentsFile = stubContentsFile.replace('../colors', 'tailwindcss/colors')
43
+
44
+ // Replace contents of {ts,js,cjs} file with the stub {simple,full}.
45
+ stubFile =
46
+ stubFile
47
+ .replace('__CONFIG__', stubContentsFile.replace('module.exports =', '').trim())
48
+ .trim() + '\n\n'
22
49
 
23
50
  fs.writeFileSync(tailwindConfigLocation, stubFile, 'utf8')
24
51
 
@@ -26,12 +53,14 @@ export function init(args, configs) {
26
53
  }
27
54
 
28
55
  if (args['--postcss']) {
29
- let postcssConfigLocation = path.resolve(`./${configs.postcss}`)
56
+ let postcssConfigLocation = path.resolve('./postcss.config.js')
30
57
  if (fs.existsSync(postcssConfigLocation)) {
31
58
  messages.push(`${path.basename(postcssConfigLocation)} already exists.`)
32
59
  } else {
33
60
  let stubFile = fs.readFileSync(
34
- path.resolve(__dirname, '../../../stubs/defaultPostCssConfig.stub.js'),
61
+ isProjectESM
62
+ ? path.resolve(__dirname, '../../../stubs/postcss.config.js')
63
+ : path.resolve(__dirname, '../../../stubs/postcss.config.cjs'),
35
64
  'utf8'
36
65
  )
37
66
 
@@ -1 +1 @@
1
- export default ["preflight","container","accessibility","pointerEvents","visibility","position","inset","isolation","zIndex","order","gridColumn","gridColumnStart","gridColumnEnd","gridRow","gridRowStart","gridRowEnd","float","clear","margin","boxSizing","display","aspectRatio","height","maxHeight","minHeight","width","minWidth","maxWidth","flex","flexShrink","flexGrow","flexBasis","tableLayout","borderCollapse","borderSpacing","transformOrigin","translate","rotate","skew","scale","transform","animation","cursor","touchAction","userSelect","resize","scrollSnapType","scrollSnapAlign","scrollSnapStop","scrollMargin","scrollPadding","listStylePosition","listStyleType","appearance","columns","breakBefore","breakInside","breakAfter","gridAutoColumns","gridAutoFlow","gridAutoRows","gridTemplateColumns","gridTemplateRows","flexDirection","flexWrap","placeContent","placeItems","alignContent","alignItems","justifyContent","justifyItems","gap","space","divideWidth","divideStyle","divideColor","divideOpacity","placeSelf","alignSelf","justifySelf","overflow","overscrollBehavior","scrollBehavior","textOverflow","whitespace","wordBreak","borderRadius","borderWidth","borderStyle","borderColor","borderOpacity","backgroundColor","backgroundOpacity","backgroundImage","gradientColorStops","boxDecorationBreak","backgroundSize","backgroundAttachment","backgroundClip","backgroundPosition","backgroundRepeat","backgroundOrigin","fill","stroke","strokeWidth","objectFit","objectPosition","padding","textAlign","textIndent","verticalAlign","fontFamily","fontSize","fontWeight","textTransform","fontStyle","fontVariantNumeric","lineHeight","letterSpacing","textColor","textOpacity","textDecoration","textDecorationColor","textDecorationStyle","textDecorationThickness","textUnderlineOffset","fontSmoothing","placeholderColor","placeholderOpacity","caretColor","accentColor","opacity","backgroundBlendMode","mixBlendMode","boxShadow","boxShadowColor","outlineStyle","outlineWidth","outlineOffset","outlineColor","ringWidth","ringColor","ringOpacity","ringOffsetWidth","ringOffsetColor","blur","brightness","contrast","dropShadow","grayscale","hueRotate","invert","saturate","sepia","filter","backdropBlur","backdropBrightness","backdropContrast","backdropGrayscale","backdropHueRotate","backdropInvert","backdropOpacity","backdropSaturate","backdropSepia","backdropFilter","transitionProperty","transitionDelay","transitionDuration","transitionTimingFunction","willChange","content"]
1
+ export default ["preflight","container","accessibility","pointerEvents","visibility","position","inset","isolation","zIndex","order","gridColumn","gridColumnStart","gridColumnEnd","gridRow","gridRowStart","gridRowEnd","float","clear","margin","boxSizing","lineClamp","display","aspectRatio","height","maxHeight","minHeight","width","minWidth","maxWidth","flex","flexShrink","flexGrow","flexBasis","tableLayout","captionSide","borderCollapse","borderSpacing","transformOrigin","translate","rotate","skew","scale","transform","animation","cursor","touchAction","userSelect","resize","scrollSnapType","scrollSnapAlign","scrollSnapStop","scrollMargin","scrollPadding","listStylePosition","listStyleType","listStyleImage","appearance","columns","breakBefore","breakInside","breakAfter","gridAutoColumns","gridAutoFlow","gridAutoRows","gridTemplateColumns","gridTemplateRows","flexDirection","flexWrap","placeContent","placeItems","alignContent","alignItems","justifyContent","justifyItems","gap","space","divideWidth","divideStyle","divideColor","divideOpacity","placeSelf","alignSelf","justifySelf","overflow","overscrollBehavior","scrollBehavior","textOverflow","hyphens","whitespace","wordBreak","borderRadius","borderWidth","borderStyle","borderColor","borderOpacity","backgroundColor","backgroundOpacity","backgroundImage","gradientColorStops","boxDecorationBreak","backgroundSize","backgroundAttachment","backgroundClip","backgroundPosition","backgroundRepeat","backgroundOrigin","fill","stroke","strokeWidth","objectFit","objectPosition","padding","textAlign","textIndent","verticalAlign","fontFamily","fontSize","fontWeight","textTransform","fontStyle","fontVariantNumeric","lineHeight","letterSpacing","textColor","textOpacity","textDecoration","textDecorationColor","textDecorationStyle","textDecorationThickness","textUnderlineOffset","fontSmoothing","placeholderColor","placeholderOpacity","caretColor","accentColor","opacity","backgroundBlendMode","mixBlendMode","boxShadow","boxShadowColor","outlineStyle","outlineWidth","outlineOffset","outlineColor","ringWidth","ringColor","ringOpacity","ringOffsetWidth","ringOffsetColor","blur","brightness","contrast","dropShadow","grayscale","hueRotate","invert","saturate","sepia","filter","backdropBlur","backdropBrightness","backdropContrast","backdropGrayscale","backdropHueRotate","backdropInvert","backdropOpacity","backdropSaturate","backdropSepia","backdropFilter","transitionProperty","transitionDelay","transitionDuration","transitionTimingFunction","willChange","content"]