From b6d5eca5642c4d18ad150e8af2635c44ddb4fc42 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 30 Oct 2023 10:47:24 -0400 Subject: [PATCH 01/14] =?UTF-8?q?Don=E2=80=99t=20add=20spaces=20to=20negat?= =?UTF-8?q?ive=20numbers=20following=20a=20comma=20(#12324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Don’t add spaces to negative numbers following a comma * Update changelog --- CHANGELOG.md | 4 ++++ src/util/dataTypes.js | 4 ++-- tests/normalize-data-types.test.js | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 378335207b8a..f655b0888d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324)) + ## [3.3.5] - 2023-10-25 ### Fixed diff --git a/src/util/dataTypes.js b/src/util/dataTypes.js index 005c37ad1501..06ccb9524303 100644 --- a/src/util/dataTypes.js +++ b/src/util/dataTypes.js @@ -77,7 +77,7 @@ export function normalize(value, context = null, isRoot = true) { /** * Add spaces around operators inside math functions - * like calc() that do not follow an operator or '('. + * like calc() that do not follow an operator, '(', or `,`. * * @param {string} value * @returns {string} @@ -164,7 +164,7 @@ function normalizeMathOperatorSpacing(value) { // Handle operators else if ( ['+', '-', '*', '/'].includes(char) && - !['(', '+', '-', '*', '/'].includes(lastChar()) + !['(', '+', '-', '*', '/', ','].includes(lastChar()) ) { result += ` ${char} ` } else { diff --git a/tests/normalize-data-types.test.js b/tests/normalize-data-types.test.js index f11e38b790e3..b249f787450a 100644 --- a/tests/normalize-data-types.test.js +++ b/tests/normalize-data-types.test.js @@ -69,6 +69,9 @@ let table = [ ['calc(theme(spacing.foo-2))', 'calc(theme(spacing.foo-2))'], ['calc(theme(spacing.foo-bar))', 'calc(theme(spacing.foo-bar))'], + // A negative number immediately after a `,` should not have spaces inserted + ['clamp(-3px+4px,-3px+4px,-3px+4px)', 'clamp(-3px + 4px,-3px + 4px,-3px + 4px)'], + // Prevent formatting inside `var()` functions ['calc(var(--foo-bar-bar)*2)', 'calc(var(--foo-bar-bar) * 2)'], From 8c3f80a2316d3433e5888e65ad30ee9e97c24a58 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 30 Oct 2023 14:37:49 -0400 Subject: [PATCH 02/14] =?UTF-8?q?Don=E2=80=99t=20output=20`@config`=20in?= =?UTF-8?q?=20CSS=20file=20after=20a=20rebuild=20(#12327)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/build/plugin.js | 8 ++++---- src/oxide/cli/build/plugin.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cli/build/plugin.js b/src/cli/build/plugin.js index 6af590dc5efe..0bef4d649728 100644 --- a/src/cli/build/plugin.js +++ b/src/cli/build/plugin.js @@ -211,16 +211,16 @@ let state = { }, getContext({ createContext, cliConfigPath, root, result, content }) { + env.DEBUG && console.time('Searching for config') + let configPath = findAtConfigPath(root, result) ?? cliConfigPath + env.DEBUG && console.timeEnd('Searching for config') + if (this.context) { this.context.changedContent = this.changedContent.splice(0) return this.context } - env.DEBUG && console.time('Searching for config') - let configPath = findAtConfigPath(root, result) ?? cliConfigPath - env.DEBUG && console.timeEnd('Searching for config') - env.DEBUG && console.time('Loading config') let config = this.loadConfig(configPath, content) env.DEBUG && console.timeEnd('Loading config') diff --git a/src/oxide/cli/build/plugin.ts b/src/oxide/cli/build/plugin.ts index b878b91dc81c..729797c89155 100644 --- a/src/oxide/cli/build/plugin.ts +++ b/src/oxide/cli/build/plugin.ts @@ -210,16 +210,16 @@ let state = { }, getContext({ createContext, cliConfigPath, root, result, content }) { + env.DEBUG && console.time('Searching for config') + let configPath = findAtConfigPath(root, result) ?? cliConfigPath + env.DEBUG && console.timeEnd('Searching for config') + if (this.context) { this.context.changedContent = this.changedContent.splice(0) return this.context } - env.DEBUG && console.time('Searching for config') - let configPath = findAtConfigPath(root, result) ?? cliConfigPath - env.DEBUG && console.timeEnd('Searching for config') - env.DEBUG && console.time('Loading config') let config = this.loadConfig(configPath, content) env.DEBUG && console.timeEnd('Loading config') From ac171f02c7a1e497edcde8055406d78c84265445 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 30 Oct 2023 14:48:26 -0400 Subject: [PATCH 03/14] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f655b0888d01..9b8d4590ad0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324)) +- Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) ## [3.3.5] - 2023-10-25 From ffadf2ba4b55c844106067aea8ca62aafebf8f67 Mon Sep 17 00:00:00 2001 From: Nikita Gaidakov <33629446+baffalop@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:46:02 +0100 Subject: [PATCH 04/14] Improve resolveConfig return type: merge themes (#12272) * Generate types: do not intersect with Config theme type when generating DefaultTheme * Merge default theme in ResolvedConfig * UnwrapResolvables on theme.extend as well * Apply extend to overrides and default theme * Omit extend from DefaultTheme * Relax generic constraints, better generic variable names * Fall back to ThemeConfig if key not in DefaultTheme * Split out ThemeConfigCustomizable to avoid anys in ThemeConfigResolved * Allow custom theme properties * handle TypeScript error * apply prettier formatting * update changelog * change type name --------- Co-authored-by: Nikita Gaidakov Co-authored-by: Robin Malfait --- CHANGELOG.md | 1 + resolveConfig.d.ts | 25 ++++++++++++++++++++++--- scripts/generate-types.js | 3 +-- types/config.d.ts | 7 ++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8d4590ad0e..081e64db5bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324)) - Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) +- Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272)) ## [3.3.5] - 2023-10-25 diff --git a/resolveConfig.d.ts b/resolveConfig.d.ts index 2402a267e8cd..792162775bf6 100644 --- a/resolveConfig.d.ts +++ b/resolveConfig.d.ts @@ -1,11 +1,30 @@ -import type { Config, ResolvableTo } from './types/config' +import { Config, ResolvableTo, ThemeConfig } from './types/config' +import { DefaultTheme } from './types/generated/default-theme' +import { DefaultColors } from './types/generated/colors' + +type ResolvedConfig = Omit & { + theme: MergeThemes< + UnwrapResolvables>, + T['theme'] extends { extend: infer TExtend } ? UnwrapResolvables : {} + > +} type UnwrapResolvables = { [K in keyof T]: T[K] extends ResolvableTo ? R : T[K] } -type ResolvedConfig = Omit & { - theme: UnwrapResolvables +type ThemeConfigResolved = UnwrapResolvables +type DefaultThemeFull = DefaultTheme & { colors: DefaultColors } + +type MergeThemes = { + [K in keyof ThemeConfigResolved | keyof Overrides]: (K extends keyof Overrides + ? Overrides[K] + : K extends keyof DefaultThemeFull + ? DefaultThemeFull[K] + : K extends keyof ThemeConfigResolved + ? ThemeConfigResolved[K] + : never) & + (K extends keyof Extensions ? Extensions[K] : {}) } declare function resolveConfig(config: T): ResolvedConfig diff --git a/scripts/generate-types.js b/scripts/generate-types.js index d3e0d303eefc..a0bd5d523d9f 100644 --- a/scripts/generate-types.js +++ b/scripts/generate-types.js @@ -91,9 +91,8 @@ fs.writeFileSync( path.join(process.cwd(), 'types', 'generated', 'default-theme.d.ts'), prettier.format( ` - import { Config } from '../../types' type CSSDeclarationList = Record - export type DefaultTheme = Config['theme'] & { ${defaultThemeTypes} } + export type DefaultTheme = { ${defaultThemeTypes} } `, { semi: false, diff --git a/types/config.d.ts b/types/config.d.ts index 6d171ceed3ee..b5d9ddc802b8 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -79,7 +79,7 @@ type Screen = { raw: string } | { min: string } | { max: string } | { min: strin type ScreensConfig = string[] | KeyValuePair // Theme related config -interface ThemeConfig { +export interface ThemeConfig { // Responsiveness screens: ResolvableTo supports: ResolvableTo> @@ -234,8 +234,9 @@ interface ThemeConfig { transitionDuration: ResolvableTo willChange: ResolvableTo content: ResolvableTo +} - // Custom +interface CustomThemeConfig extends ThemeConfig { [key: string]: any } @@ -358,7 +359,7 @@ interface OptionalConfig { future: Partial experimental: Partial darkMode: Partial - theme: Partial }> + theme: Partial }> corePlugins: Partial plugins: Partial // Custom From 817c466c1e9dd530026df7e905090d50adf37974 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Nov 2023 22:57:35 +0800 Subject: [PATCH 05/14] Ensure configured `font-feature-settings` for `mono` are included in Preflight (#12342) * Use the default font-feature-settings for mono * Update changelog * Update tests --------- Co-authored-by: Jordan Pittman --- CHANGELOG.md | 1 + src/css/preflight.css | 10 +- tests/source-maps.test.js | 440 +++++++++++++++++++------------------- 3 files changed, 229 insertions(+), 222 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 081e64db5bc7..b1150ed680ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324)) - Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) - Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272)) +- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) ## [3.3.5] - 2023-10-25 diff --git a/src/css/preflight.css b/src/css/preflight.css index e5e52cd8f323..8783e9b935ea 100644 --- a/src/css/preflight.css +++ b/src/css/preflight.css @@ -99,8 +99,10 @@ strong { } /* -1. Use the user's configured `mono` font family by default. -2. Correct the odd `em` font sizing in all browsers. +1. Use the user's configured `mono` font-family by default. +2. Use the user's configured `mono` font-feature-settings by default. +3. Use the user's configured `mono` font-variation-settings by default. +4. Correct the odd `em` font sizing in all browsers. */ code, @@ -108,7 +110,9 @@ kbd, samp, pre { font-family: theme('fontFamily.mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace); /* 1 */ - font-size: 1em; /* 2 */ + font-feature-settings: theme('fontFamily.mono[1].fontFeatureSettings', normal); /* 2 */ + font-variation-settings: theme('fontFamily.mono[1].fontVariationSettings', normal); /* 3 */ + font-size: 1em; /* 4 */ } /* diff --git a/tests/source-maps.test.js b/tests/source-maps.test.js index a19aea687bdd..5add3b0c81e3 100644 --- a/tests/source-maps.test.js +++ b/tests/source-maps.test.js @@ -144,261 +144,263 @@ crosscheck(({ stable, oxide }) => { '2:6-20 -> 100:2-21', '2:20 -> 101:0', '2:6 -> 103:0', - '2:20 -> 106:1', - '2:6 -> 108:0', - '2:6-20 -> 112:2-121', - '2:6-20 -> 113:2-24', - '2:20 -> 114:0', - '2:6 -> 116:0', - '2:20 -> 118:1', + '2:20 -> 108:1', + '2:6 -> 110:0', + '2:6-20 -> 114:2-121', + '2:6-20 -> 115:2-39', + '2:6-20 -> 116:2-41', + '2:6-20 -> 117:2-24', + '2:20 -> 118:0', '2:6 -> 120:0', - '2:6-20 -> 121:2-16', - '2:20 -> 122:0', + '2:20 -> 122:1', '2:6 -> 124:0', - '2:20 -> 126:1', + '2:6-20 -> 125:2-16', + '2:20 -> 126:0', '2:6 -> 128:0', - '2:6-20 -> 130:2-16', - '2:6-20 -> 131:2-16', - '2:6-20 -> 132:2-20', - '2:6-20 -> 133:2-26', - '2:20 -> 134:0', - '2:6 -> 136:0', - '2:6-20 -> 137:2-17', + '2:20 -> 130:1', + '2:6 -> 132:0', + '2:6-20 -> 134:2-16', + '2:6-20 -> 135:2-16', + '2:6-20 -> 136:2-20', + '2:6-20 -> 137:2-26', '2:20 -> 138:0', '2:6 -> 140:0', - '2:6-20 -> 141:2-13', + '2:6-20 -> 141:2-17', '2:20 -> 142:0', '2:6 -> 144:0', - '2:20 -> 148:1', - '2:6 -> 150:0', - '2:6-20 -> 151:2-24', - '2:6-20 -> 152:2-31', - '2:6-20 -> 153:2-35', - '2:20 -> 154:0', - '2:6 -> 156:0', - '2:20 -> 160:1', - '2:6 -> 162:0', - '2:6-20 -> 167:2-30', - '2:6-20 -> 168:2-40', - '2:6-20 -> 169:2-42', - '2:6-20 -> 170:2-25', + '2:6-20 -> 145:2-13', + '2:20 -> 146:0', + '2:6 -> 148:0', + '2:20 -> 152:1', + '2:6 -> 154:0', + '2:6-20 -> 155:2-24', + '2:6-20 -> 156:2-31', + '2:6-20 -> 157:2-35', + '2:20 -> 158:0', + '2:6 -> 160:0', + '2:20 -> 164:1', + '2:6 -> 166:0', '2:6-20 -> 171:2-30', - '2:6-20 -> 172:2-30', - '2:6-20 -> 173:2-24', - '2:6-20 -> 174:2-19', - '2:6-20 -> 175:2-20', - '2:20 -> 176:0', - '2:6 -> 178:0', - '2:20 -> 180:1', + '2:6-20 -> 172:2-40', + '2:6-20 -> 173:2-42', + '2:6-20 -> 174:2-25', + '2:6-20 -> 175:2-30', + '2:6-20 -> 176:2-30', + '2:6-20 -> 177:2-24', + '2:6-20 -> 178:2-19', + '2:6-20 -> 179:2-20', + '2:20 -> 180:0', '2:6 -> 182:0', - '2:6-20 -> 184:2-22', - '2:20 -> 185:0', - '2:6 -> 187:0', - '2:20 -> 190:1', - '2:6 -> 192:0', - '2:6-20 -> 196:2-36', - '2:6-20 -> 197:2-39', - '2:6-20 -> 198:2-32', - '2:20 -> 199:0', - '2:6 -> 201:0', - '2:20 -> 203:1', + '2:20 -> 184:1', + '2:6 -> 186:0', + '2:6-20 -> 188:2-22', + '2:20 -> 189:0', + '2:6 -> 191:0', + '2:20 -> 194:1', + '2:6 -> 196:0', + '2:6-20 -> 200:2-36', + '2:6-20 -> 201:2-39', + '2:6-20 -> 202:2-32', + '2:20 -> 203:0', '2:6 -> 205:0', - '2:6-20 -> 206:2-15', - '2:20 -> 207:0', + '2:20 -> 207:1', '2:6 -> 209:0', - '2:20 -> 211:1', + '2:6-20 -> 210:2-15', + '2:20 -> 211:0', '2:6 -> 213:0', - '2:6-20 -> 214:2-18', - '2:20 -> 215:0', + '2:20 -> 215:1', '2:6 -> 217:0', - '2:20 -> 219:1', + '2:6-20 -> 218:2-18', + '2:20 -> 219:0', '2:6 -> 221:0', - '2:6-20 -> 222:2-26', - '2:20 -> 223:0', + '2:20 -> 223:1', '2:6 -> 225:0', - '2:20 -> 227:1', + '2:6-20 -> 226:2-26', + '2:20 -> 227:0', '2:6 -> 229:0', - '2:6-20 -> 231:2-14', - '2:20 -> 232:0', - '2:6 -> 234:0', - '2:20 -> 237:1', - '2:6 -> 239:0', - '2:6-20 -> 240:2-39', - '2:6-20 -> 241:2-30', - '2:20 -> 242:0', - '2:6 -> 244:0', - '2:20 -> 246:1', + '2:20 -> 231:1', + '2:6 -> 233:0', + '2:6-20 -> 235:2-14', + '2:20 -> 236:0', + '2:6 -> 238:0', + '2:20 -> 241:1', + '2:6 -> 243:0', + '2:6-20 -> 244:2-39', + '2:6-20 -> 245:2-30', + '2:20 -> 246:0', '2:6 -> 248:0', - '2:6-20 -> 249:2-26', - '2:20 -> 250:0', + '2:20 -> 250:1', '2:6 -> 252:0', - '2:20 -> 255:1', - '2:6 -> 257:0', - '2:6-20 -> 258:2-36', - '2:6-20 -> 259:2-23', - '2:20 -> 260:0', - '2:6 -> 262:0', - '2:20 -> 264:1', + '2:6-20 -> 253:2-26', + '2:20 -> 254:0', + '2:6 -> 256:0', + '2:20 -> 259:1', + '2:6 -> 261:0', + '2:6-20 -> 262:2-36', + '2:6-20 -> 263:2-23', + '2:20 -> 264:0', '2:6 -> 266:0', - '2:6-20 -> 267:2-20', - '2:20 -> 268:0', + '2:20 -> 268:1', '2:6 -> 270:0', - '2:20 -> 272:1', + '2:6-20 -> 271:2-20', + '2:20 -> 272:0', '2:6 -> 274:0', - '2:6-20 -> 287:2-11', - '2:20 -> 288:0', - '2:6 -> 290:0', + '2:20 -> 276:1', + '2:6 -> 278:0', '2:6-20 -> 291:2-11', - '2:6-20 -> 292:2-12', - '2:20 -> 293:0', - '2:6 -> 295:0', + '2:20 -> 292:0', + '2:6 -> 294:0', + '2:6-20 -> 295:2-11', '2:6-20 -> 296:2-12', '2:20 -> 297:0', '2:6 -> 299:0', - '2:6-20 -> 302:2-18', - '2:6-20 -> 303:2-11', - '2:6-20 -> 304:2-12', - '2:20 -> 305:0', - '2:6 -> 307:0', - '2:20 -> 309:1', - '2:6 -> 310:0', - '2:6-20 -> 311:2-12', - '2:20 -> 312:0', + '2:6-20 -> 300:2-12', + '2:20 -> 301:0', + '2:6 -> 303:0', + '2:6-20 -> 306:2-18', + '2:6-20 -> 307:2-11', + '2:6-20 -> 308:2-12', + '2:20 -> 309:0', + '2:6 -> 311:0', + '2:20 -> 313:1', '2:6 -> 314:0', - '2:20 -> 316:1', + '2:6-20 -> 315:2-12', + '2:20 -> 316:0', '2:6 -> 318:0', - '2:6-20 -> 319:2-18', - '2:20 -> 320:0', + '2:20 -> 320:1', '2:6 -> 322:0', - '2:20 -> 325:1', - '2:6 -> 327:0', - '2:6-20 -> 329:2-20', - '2:6-20 -> 330:2-24', - '2:20 -> 331:0', - '2:6 -> 333:0', - '2:20 -> 335:1', + '2:6-20 -> 323:2-18', + '2:20 -> 324:0', + '2:6 -> 326:0', + '2:20 -> 329:1', + '2:6 -> 331:0', + '2:6-20 -> 333:2-20', + '2:6-20 -> 334:2-24', + '2:20 -> 335:0', '2:6 -> 337:0', - '2:6-20 -> 339:2-17', - '2:20 -> 340:0', - '2:6 -> 342:0', - '2:20 -> 344:1', - '2:6 -> 345:0', - '2:6-20 -> 346:2-17', - '2:20 -> 347:0', + '2:20 -> 339:1', + '2:6 -> 341:0', + '2:6-20 -> 343:2-17', + '2:20 -> 344:0', + '2:6 -> 346:0', + '2:20 -> 348:1', '2:6 -> 349:0', - '2:20 -> 353:1', - '2:6 -> 355:0', - '2:6-20 -> 363:2-24', - '2:6-20 -> 364:2-32', - '2:20 -> 365:0', - '2:6 -> 367:0', - '2:20 -> 369:1', + '2:6-20 -> 350:2-17', + '2:20 -> 351:0', + '2:6 -> 353:0', + '2:20 -> 357:1', + '2:6 -> 359:0', + '2:6-20 -> 367:2-24', + '2:6-20 -> 368:2-32', + '2:20 -> 369:0', '2:6 -> 371:0', - '2:6-20 -> 373:2-17', - '2:6-20 -> 374:2-14', - '2:20 -> 375:0', - '2:6-20 -> 377:0-72', - '2:6 -> 378:0', - '2:6-20 -> 379:2-15', - '2:20 -> 380:0', + '2:20 -> 373:1', + '2:6 -> 375:0', + '2:6-20 -> 377:2-17', + '2:6-20 -> 378:2-14', + '2:20 -> 379:0', + '2:6-20 -> 381:0-72', '2:6 -> 382:0', - '2:6-20 -> 383:2-26', - '2:6-20 -> 384:2-26', - '2:6-20 -> 385:2-21', - '2:6-20 -> 386:2-21', - '2:6-20 -> 387:2-16', - '2:6-20 -> 388:2-16', - '2:6-20 -> 389:2-16', - '2:6-20 -> 390:2-17', - '2:6-20 -> 391:2-17', - '2:6-20 -> 392:2-15', - '2:6-20 -> 393:2-15', - '2:6-20 -> 394:2-20', - '2:6-20 -> 395:2-40', - '2:6-20 -> 396:2-32', - '2:6-20 -> 397:2-31', - '2:6-20 -> 398:2-30', - '2:6-20 -> 399:2-17', - '2:6-20 -> 400:2-22', - '2:6-20 -> 401:2-24', - '2:6-20 -> 402:2-25', - '2:6-20 -> 403:2-26', - '2:6-20 -> 404:2-20', - '2:6-20 -> 405:2-29', - '2:6-20 -> 406:2-30', - '2:6-20 -> 407:2-40', - '2:6-20 -> 408:2-36', + '2:6-20 -> 383:2-15', + '2:20 -> 384:0', + '2:6 -> 386:0', + '2:6-20 -> 387:2-26', + '2:6-20 -> 388:2-26', + '2:6-20 -> 389:2-21', + '2:6-20 -> 390:2-21', + '2:6-20 -> 391:2-16', + '2:6-20 -> 392:2-16', + '2:6-20 -> 393:2-16', + '2:6-20 -> 394:2-17', + '2:6-20 -> 395:2-17', + '2:6-20 -> 396:2-15', + '2:6-20 -> 397:2-15', + '2:6-20 -> 398:2-20', + '2:6-20 -> 399:2-40', + '2:6-20 -> 400:2-32', + '2:6-20 -> 401:2-31', + '2:6-20 -> 402:2-30', + '2:6-20 -> 403:2-17', + '2:6-20 -> 404:2-22', + '2:6-20 -> 405:2-24', + '2:6-20 -> 406:2-25', + '2:6-20 -> 407:2-26', + '2:6-20 -> 408:2-20', '2:6-20 -> 409:2-29', - '2:6-20 -> 410:2-24', - '2:6-20 -> 411:2-32', - '2:6-20 -> 412:2-14', - '2:6-20 -> 413:2-20', - '2:6-20 -> 414:2-18', - '2:6-20 -> 415:2-19', - '2:6-20 -> 416:2-20', - '2:6-20 -> 417:2-16', + '2:6-20 -> 410:2-30', + '2:6-20 -> 411:2-40', + '2:6-20 -> 412:2-36', + '2:6-20 -> 413:2-29', + '2:6-20 -> 414:2-24', + '2:6-20 -> 415:2-32', + '2:6-20 -> 416:2-14', + '2:6-20 -> 417:2-20', '2:6-20 -> 418:2-18', - '2:6-20 -> 419:2-15', - '2:6-20 -> 420:2-21', - '2:6-20 -> 421:2-23', - '2:6-20 -> 422:2-29', - '2:6-20 -> 423:2-27', - '2:6-20 -> 424:2-28', - '2:6-20 -> 425:2-29', - '2:6-20 -> 426:2-25', - '2:6-20 -> 427:2-26', - '2:6-20 -> 428:2-27', - '2:6 -> 429:2', - '2:20 -> 430:0', - '2:6 -> 432:0', - '2:6-20 -> 433:2-26', - '2:6-20 -> 434:2-26', - '2:6-20 -> 435:2-21', - '2:6-20 -> 436:2-21', - '2:6-20 -> 437:2-16', - '2:6-20 -> 438:2-16', - '2:6-20 -> 439:2-16', - '2:6-20 -> 440:2-17', - '2:6-20 -> 441:2-17', - '2:6-20 -> 442:2-15', - '2:6-20 -> 443:2-15', - '2:6-20 -> 444:2-20', - '2:6-20 -> 445:2-40', - '2:6-20 -> 446:2-32', - '2:6-20 -> 447:2-31', - '2:6-20 -> 448:2-30', - '2:6-20 -> 449:2-17', - '2:6-20 -> 450:2-22', - '2:6-20 -> 451:2-24', - '2:6-20 -> 452:2-25', - '2:6-20 -> 453:2-26', - '2:6-20 -> 454:2-20', - '2:6-20 -> 455:2-29', - '2:6-20 -> 456:2-30', - '2:6-20 -> 457:2-40', - '2:6-20 -> 458:2-36', + '2:6-20 -> 419:2-19', + '2:6-20 -> 420:2-20', + '2:6-20 -> 421:2-16', + '2:6-20 -> 422:2-18', + '2:6-20 -> 423:2-15', + '2:6-20 -> 424:2-21', + '2:6-20 -> 425:2-23', + '2:6-20 -> 426:2-29', + '2:6-20 -> 427:2-27', + '2:6-20 -> 428:2-28', + '2:6-20 -> 429:2-29', + '2:6-20 -> 430:2-25', + '2:6-20 -> 431:2-26', + '2:6-20 -> 432:2-27', + '2:6 -> 433:2', + '2:20 -> 434:0', + '2:6 -> 436:0', + '2:6-20 -> 437:2-26', + '2:6-20 -> 438:2-26', + '2:6-20 -> 439:2-21', + '2:6-20 -> 440:2-21', + '2:6-20 -> 441:2-16', + '2:6-20 -> 442:2-16', + '2:6-20 -> 443:2-16', + '2:6-20 -> 444:2-17', + '2:6-20 -> 445:2-17', + '2:6-20 -> 446:2-15', + '2:6-20 -> 447:2-15', + '2:6-20 -> 448:2-20', + '2:6-20 -> 449:2-40', + '2:6-20 -> 450:2-32', + '2:6-20 -> 451:2-31', + '2:6-20 -> 452:2-30', + '2:6-20 -> 453:2-17', + '2:6-20 -> 454:2-22', + '2:6-20 -> 455:2-24', + '2:6-20 -> 456:2-25', + '2:6-20 -> 457:2-26', + '2:6-20 -> 458:2-20', '2:6-20 -> 459:2-29', - '2:6-20 -> 460:2-24', - '2:6-20 -> 461:2-32', - '2:6-20 -> 462:2-14', - '2:6-20 -> 463:2-20', - '2:6-20 -> 464:2-18', - '2:6-20 -> 465:2-19', - '2:6-20 -> 466:2-20', - '2:6-20 -> 467:2-16', + '2:6-20 -> 460:2-30', + '2:6-20 -> 461:2-40', + '2:6-20 -> 462:2-36', + '2:6-20 -> 463:2-29', + '2:6-20 -> 464:2-24', + '2:6-20 -> 465:2-32', + '2:6-20 -> 466:2-14', + '2:6-20 -> 467:2-20', '2:6-20 -> 468:2-18', - '2:6-20 -> 469:2-15', - '2:6-20 -> 470:2-21', - '2:6-20 -> 471:2-23', - '2:6-20 -> 472:2-29', - '2:6-20 -> 473:2-27', - '2:6-20 -> 474:2-28', - '2:6-20 -> 475:2-29', - '2:6-20 -> 476:2-25', - '2:6-20 -> 477:2-26', - '2:6-20 -> 478:2-27', - '2:6 -> 479:2', - '2:20 -> 480:0', + '2:6-20 -> 469:2-19', + '2:6-20 -> 470:2-20', + '2:6-20 -> 471:2-16', + '2:6-20 -> 472:2-18', + '2:6-20 -> 473:2-15', + '2:6-20 -> 474:2-21', + '2:6-20 -> 475:2-23', + '2:6-20 -> 476:2-29', + '2:6-20 -> 477:2-27', + '2:6-20 -> 478:2-28', + '2:6-20 -> 479:2-29', + '2:6-20 -> 480:2-25', + '2:6-20 -> 481:2-26', + '2:6-20 -> 482:2-27', + '2:6 -> 483:2', + '2:20 -> 484:0', ]) }) From da0ee9c746b37444ee129d774cb83fc9c25f436c Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 29 Nov 2023 13:32:01 -0500 Subject: [PATCH 06/14] Remove unused import --- src/lib/defaultExtractor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index ae546e9a4569..0751c1acba7e 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -1,4 +1,3 @@ -import { flagEnabled } from '../featureFlags' import * as regex from './regex' export function defaultExtractor(context) { From 37132077445c882c19478b263d4545432e443ddb Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 29 Nov 2023 13:31:43 -0500 Subject: [PATCH 07/14] Fix code style --- src/featureFlags.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/featureFlags.js b/src/featureFlags.js index 76dd3736843a..69fa569ffb59 100644 --- a/src/featureFlags.js +++ b/src/featureFlags.js @@ -19,10 +19,7 @@ let featureFlags = { 'disableColorOpacityUtilitiesByDefault', 'relativeContentPathsByDefault', ], - experimental: [ - 'optimizeUniversalDefaults', - 'generalizedModifiers', - ], + experimental: ['optimizeUniversalDefaults', 'generalizedModifiers'], } export function flagEnabled(config, flag) { From bbfb5a3c663346410c277599db6d6e4df0854d75 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 10:22:45 -0500 Subject: [PATCH 08/14] Don't crash when given applying a variant to a negated version of a simple utility (#12514) * Don't crash when given applying a variant to a negated version of a simple utility * Update changelog --- CHANGELOG.md | 1 + src/lib/generateRules.js | 5 +++++ tests/negative-prefix.test.js | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1150ed680ba..ae28119ce22e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) - Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272)) - Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) +- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) ## [3.3.5] - 2023-10-25 diff --git a/src/lib/generateRules.js b/src/lib/generateRules.js index 69b6827733e7..57bb1d140cd3 100644 --- a/src/lib/generateRules.js +++ b/src/lib/generateRules.js @@ -845,6 +845,11 @@ function applyFinalFormat(match, { context, candidate }) { return null } + // If all rules have been eliminated we can skip this candidate entirely + if (container.nodes.length === 0) { + return null + } + match[1] = container.nodes[0] return match diff --git a/tests/negative-prefix.test.js b/tests/negative-prefix.test.js index c799bb54ecb4..d352c1d63e0e 100644 --- a/tests/negative-prefix.test.js +++ b/tests/negative-prefix.test.js @@ -343,4 +343,24 @@ crosscheck(() => { return expect(result.css).toMatchCss(css``) }) }) + + // This is a weird test but it used to crash because the negative prefix + variant used to cause an undefined utility to be generated + test('addUtilities without negative prefix + variant + negative prefix in content should not crash', async () => { + let config = { + content: [{ raw: html`
` }], + plugins: [ + ({ addUtilities }) => { + addUtilities({ + '.top-lg': { + top: '6rem', + }, + }) + }, + ], + } + + let result = await run('@tailwind utilities', config) + + expect(result.css).toMatchCss(css``) + }) }) From adb6f15bc19477afea21e6a24eca16f5108c2935 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 10:44:08 -0500 Subject: [PATCH 09/14] Fix generation of utilities that use slashes in arbitrary modifiers (#12515) * Fix support for slashes in arbitrary modifiers * Update changelog --- CHANGELOG.md | 1 + src/util/pluginUtils.js | 16 ++++++++++++++++ tests/arbitrary-values.test.js | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae28119ce22e..981553e8083a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272)) - Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) - Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) +- Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515)) ## [3.3.5] - 2023-10-25 diff --git a/src/util/pluginUtils.js b/src/util/pluginUtils.js index bef9fc1658e7..256d891a2150 100644 --- a/src/util/pluginUtils.js +++ b/src/util/pluginUtils.js @@ -88,6 +88,22 @@ function isArbitraryValue(input) { function splitUtilityModifier(modifier) { let slashIdx = modifier.lastIndexOf('/') + // If the `/` is inside an arbitrary, we want to find the previous one if any + // This logic probably isn't perfect but it should work for most cases + let arbitraryStartIdx = modifier.lastIndexOf('[', slashIdx) + let arbitraryEndIdx = modifier.indexOf(']', slashIdx) + + let isNextToArbitrary = modifier[slashIdx - 1] === ']' || modifier[slashIdx + 1] === '[' + + // Backtrack to the previous `/` if the one we found was inside an arbitrary + if (!isNextToArbitrary) { + if (arbitraryStartIdx !== -1 && arbitraryEndIdx !== -1) { + if (arbitraryStartIdx < slashIdx && slashIdx < arbitraryEndIdx) { + slashIdx = modifier.lastIndexOf('/', arbitraryStartIdx) + } + } + } + if (slashIdx === -1 || slashIdx === modifier.length - 1) { return [modifier, undefined] } diff --git a/tests/arbitrary-values.test.js b/tests/arbitrary-values.test.js index ff7abcd84fdc..b9400ef55f6f 100644 --- a/tests/arbitrary-values.test.js +++ b/tests/arbitrary-values.test.js @@ -654,6 +654,21 @@ crosscheck(({ stable, oxide }) => { }) }) +it('should support slashes in arbitrary modifiers', () => { + let config = { + content: [{ raw: html`
` }], + } + + return run('@tailwind utilities', config).then((result) => { + return expect(result.css).toMatchFormattedCss(css` + .text-lg\/\[calc\(50px\/1rem\)\] { + font-size: 1.125rem; + line-height: calc(50px / 1rem); + } + `) + }) +}) + it('should not insert spaces around operators inside `env()`', () => { let config = { content: [{ raw: html`
` }], From 2dcb1fcd8203a43df0c10bd8e9ebffe9b36231fe Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 11:05:34 -0500 Subject: [PATCH 10/14] Fix source maps of variant utilities that come from an `@layer` rule (#12508) * Refactor * Keep traversing sibling nodes * Make sure the root node has a source location for the end * Add source map test for at-rule variants * Update changelog --- CHANGELOG.md | 1 + src/lib/expandTailwindAtRules.js | 3 ++ src/util/cloneNodes.js | 49 +++++++++++++++++++++++--------- tests/source-maps.test.js | 7 ++++- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 981553e8083a..24ed1afc5059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) - Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) - Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515)) +- Fix source maps of variant utilities that come from an `@layer` rule ([#12508](https://github.com/tailwindlabs/tailwindcss/pull/12508)) ## [3.3.5] - 2023-10-25 diff --git a/src/lib/expandTailwindAtRules.js b/src/lib/expandTailwindAtRules.js index 2933d6f3e44e..b78bf1e2b08b 100644 --- a/src/lib/expandTailwindAtRules.js +++ b/src/lib/expandTailwindAtRules.js @@ -265,6 +265,9 @@ export default function expandTailwindAtRules(context) { ) } + // TODO: Why is the root node having no source location for `end` possible? + root.source.end = root.source.end ?? root.source.start + // If we've got a utility layer and no utilities are generated there's likely something wrong const hasUtilityVariants = variantNodes.some( (node) => node.raws.tailwind?.parentLayer === 'utilities' diff --git a/src/util/cloneNodes.js b/src/util/cloneNodes.js index 299dd63b3e2e..9fa1c14a99b7 100644 --- a/src/util/cloneNodes.js +++ b/src/util/cloneNodes.js @@ -1,21 +1,13 @@ +/** + * @param {import('postcss').Container[]} nodes + * @param {any} source + * @param {any} raws + * @returns {import('postcss').Container[]} + */ export default function cloneNodes(nodes, source = undefined, raws = undefined) { return nodes.map((node) => { let cloned = node.clone() - // We always want override the source map - // except when explicitly told not to - let shouldOverwriteSource = node.raws.tailwind?.preserveSource !== true || !cloned.source - - if (source !== undefined && shouldOverwriteSource) { - cloned.source = source - - if ('walk' in cloned) { - cloned.walk((child) => { - child.source = source - }) - } - } - if (raws !== undefined) { cloned.raws.tailwind = { ...cloned.raws.tailwind, @@ -23,6 +15,35 @@ export default function cloneNodes(nodes, source = undefined, raws = undefined) } } + if (source !== undefined) { + traverse(cloned, (node) => { + // Do not traverse nodes that have opted + // to preserve their original source + let shouldPreserveSource = node.raws.tailwind?.preserveSource === true && node.source + if (shouldPreserveSource) { + return false + } + + // Otherwise we can safely replace the source + // And continue traversing + node.source = source + }) + } + return cloned }) } + +/** + * Traverse a tree of nodes and don't traverse children if the callback + * returns false. Ideally we'd use Container#walk instead of this + * function but it stops traversing siblings too. + * + * @param {import('postcss').Container} node + * @param {(node: import('postcss').Container) => boolean} onNode + */ +function traverse(node, onNode) { + if (onNode(node) !== false) { + node.each?.((child) => traverse(child, onNode)) + } +} diff --git a/tests/source-maps.test.js b/tests/source-maps.test.js index 5add3b0c81e3..75bfd84fc7b7 100644 --- a/tests/source-maps.test.js +++ b/tests/source-maps.test.js @@ -485,7 +485,7 @@ crosscheck(({ stable, oxide }) => { 'source maps for layer rules are not rewritten to point to @tailwind directives', async () => { let config = { - content: [{ raw: `font-normal foo hover:foo` }], + content: [{ raw: `font-normal foo hover:foo lg:foo` }], } let utilitiesFile = postcss.parse( @@ -535,6 +535,11 @@ crosscheck(({ stable, oxide }) => { '3:12 -> 7:12', '4:14-35 -> 8:14-35', '5:12 -> 9:12', + '1:0 -> 10:12', + '3:12 -> 11:12', + '4:14-35 -> 12:14-35', + '5:12 -> 13:12', + '1:0 -> 14:0', ]) } ) From e26a1ba5f1fc70f781f62f312f4684a1ef8a83eb Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 1 Dec 2023 11:44:30 -0500 Subject: [PATCH 11/14] Fix loading of built-in plugins when using an ESM or TypeScript config with the Standalone CLI (#12506) --- CHANGELOG.md | 1 + src/lib/load-config.ts | 8 ++++++ standalone-cli/patch-require.js | 50 +++++++++++++++++++++++++++++++++ standalone-cli/standalone.js | 41 +++++++++++++++++++++------ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 standalone-cli/patch-require.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ed1afc5059..384e35bef151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) - Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515)) - Fix source maps of variant utilities that come from an `@layer` rule ([#12508](https://github.com/tailwindlabs/tailwindcss/pull/12508)) +- Fix loading of built-in plugins when using an ESM or TypeScript config with the Standalone CLI ([#12506](https://github.com/tailwindlabs/tailwindcss/pull/12506)) ## [3.3.5] - 2023-10-25 diff --git a/src/lib/load-config.ts b/src/lib/load-config.ts index 645e8e1d55c4..e879412a3977 100644 --- a/src/lib/load-config.ts +++ b/src/lib/load-config.ts @@ -4,6 +4,14 @@ import { transform } from 'sucrase' import { Config } from '../../types/config' let jiti: ReturnType | null = null + +// @internal +// This WILL be removed in some future release +// If you rely on this your stuff WILL break +export function useCustomJiti(_jiti: ReturnType) { + jiti = _jiti +} + function lazyJiti() { return ( jiti ?? diff --git a/standalone-cli/patch-require.js b/standalone-cli/patch-require.js new file mode 100644 index 000000000000..c5857baf807a --- /dev/null +++ b/standalone-cli/patch-require.js @@ -0,0 +1,50 @@ +const Module = require('node:module') + +/** + * @param {Record} mods + */ +module.exports.patchRequire = function patchRequire(mods, parentCache) { + function wrapRequire(origRequire) { + return Object.assign( + function (id) { + // Patch require(…) to return the cached module + if (mods.hasOwnProperty(id)) { + return mods[id] + } + + return origRequire.apply(this, arguments) + }, + + // Make sure we carry over other properties of the original require(…) + origRequire, + + { + resolve(id) { + // Defer to the "parent" require cache when resolving the module + // This also requires that the module be provided as a "native module" to JITI + + // The path returned here is VERY important as it ensures that the `isNativeRe` in JITI + // passes which is required for the module to be loaded via the native require(…) function + // Thankfully, the regex just means that it needs to be in a node_modules folder which is true + // even when bundled using Vercel's `pkg` + if (parentCache.hasOwnProperty(id)) { + return parentCache[id].filename + } + + return origRequire.resolve.apply(this, arguments) + }, + } + ) + } + + let origRequire = Module.prototype.require + let origCreateRequire = Module.createRequire + + // We have to augment the default "require" in every module + Module.prototype.require = wrapRequire(origRequire) + + // And any "require" created by the "createRequire" method + Module.createRequire = function () { + return wrapRequire(origCreateRequire.apply(this, arguments)) + } +} diff --git a/standalone-cli/standalone.js b/standalone-cli/standalone.js index 28ddf69a960d..ce0bde1cb64e 100644 --- a/standalone-cli/standalone.js +++ b/standalone-cli/standalone.js @@ -1,5 +1,3 @@ -let Module = require('module') -let origRequire = Module.prototype.require let log = require('tailwindcss/lib/util/log').default let localModules = { @@ -25,11 +23,38 @@ let localModules = { tailwindcss: require('tailwindcss'), } -Module.prototype.require = function (id) { - if (localModules.hasOwnProperty(id)) { - return localModules[id] - } - return origRequire.apply(this, arguments) -} +// Swap out the default JITI implementation with one that has the built-in modules above preloaded as "native modules" +// NOTE: This uses a private, internal API of Tailwind CSS and is subject to change at any time +let { useCustomJiti } = require('tailwindcss/lib/lib/load-config') +let { transform } = require('sucrase') + +useCustomJiti(() => + require('jiti')(__filename, { + interopDefault: true, + nativeModules: Object.keys(localModules), + transform: (opts) => { + return transform(opts.source, { + transforms: ['typescript', 'imports'], + }) + }, + }) +) + +let { patchRequire } = require('./patch-require.js') +patchRequire( + // Patch require(…) to return the bundled modules above so they don't need to be installed + localModules, + + // Create a require cache that maps module IDs to module objects + // This MUST be done before require is patched to handle caching + Object.fromEntries( + Object.keys(localModules).map((id) => [ + id, + id === '@tailwindcss/line-clamp' + ? `node_modules/@tailwindcss/line-clamp/` + : require.cache[require.resolve(id)], + ]) + ) +) require('tailwindcss/lib/cli') From 89470d29b4cd0f35989e41b84856fa3222a1c5c6 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 10 Nov 2023 23:06:02 +0100 Subject: [PATCH 12/14] Improve candidate detection in minified JS arrays (without spaces) (#12396) * add test to verify `["util1","util2"]` works * update extractor regex, to reduce valid values in the arbitrary value part Co-authored-by: Autom * add special case with deeply nested `[]` * update changelog * move oxide changelog itemsto the bottom --------- Co-authored-by: Autom --- CHANGELOG.md | 1 + src/lib/defaultExtractor.js | 4 ++-- tests/default-extractor.test.js | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 384e35bef151..705d1d7f0257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't emit `@config` in CSS when watching via the CLI ([#12327](https://github.com/tailwindlabs/tailwindcss/pull/12327)) - Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272)) - Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342)) +- Improve candidate detection in minified JS arrays (without spaces) ([#12396](https://github.com/tailwindlabs/tailwindcss/pull/12396)) - Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514)) - Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515)) - Fix source maps of variant utilities that come from an `@layer` rule ([#12508](https://github.com/tailwindlabs/tailwindcss/pull/12508)) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index 0751c1acba7e..75ee8af50f81 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -47,7 +47,7 @@ function* buildRegExps(context) { regex.any([ regex.pattern([ // Arbitrary values - /-(?:\w+-)*\[[^\s:]+\]/, + /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, // Not immediately followed by an `{[(` /(?![{([]])/, @@ -58,7 +58,7 @@ function* buildRegExps(context) { regex.pattern([ // Arbitrary values - /-(?:\w+-)*\[[^\s]+\]/, + /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, // Not immediately followed by an `{[(` /(?![{([]])/, diff --git a/tests/default-extractor.test.js b/tests/default-extractor.test.js index 05a19e62653f..bbf0960bd805 100644 --- a/tests/default-extractor.test.js +++ b/tests/default-extractor.test.js @@ -503,3 +503,17 @@ test('arbitrary properties followed by square bracketed stuff', () => { expect(extractions).toContain(`[display:inherit]`) }) + +it.each([ + ['["min-w-[17rem]","max-w-[17rem]"]', ['min-w-[17rem]', 'max-w-[17rem]']], + [ + '["w-[calc(theme(spacing[2]*-1px))]","h-[calc(theme(spacing[2]*-1px))]"]', + ['w-[calc(theme(spacing[2]*-1px))]', 'h-[calc(theme(spacing[2]*-1px))]'], + ], +])('should work for issue #12371 (%#)', async (content, expectations) => { + let extractions = defaultExtractor(content) + + for (let value of expectations) { + expect(extractions).toContain(value) + } +}) From 16fd9ffdb486582334451cc3af75e88c5e11cf45 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 4 Dec 2023 11:23:33 -0500 Subject: [PATCH 13/14] Fix candidate detection regex --- src/lib/defaultExtractor.js | 14 ++++++++++++-- tests/arbitrary-values.test.js | 5 +++++ tests/basic-usage.test.js | 4 ---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index 75ee8af50f81..3a1ff321eee7 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -47,7 +47,12 @@ function* buildRegExps(context) { regex.any([ regex.pattern([ // Arbitrary values - /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, + regex.any([ + /-(?:\w+-)*\['[^\s]+'\]/, + /-(?:\w+-)*\["[^\s]+"\]/, + /-(?:\w+-)*\[`[^\s]+`\]/, + /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, + ]), // Not immediately followed by an `{[(` /(?![{([]])/, @@ -58,7 +63,12 @@ function* buildRegExps(context) { regex.pattern([ // Arbitrary values - /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s:\[\]]+\]/, + regex.any([ + /-(?:\w+-)*\['[^\s]+'\]/, + /-(?:\w+-)*\["[^\s]+"\]/, + /-(?:\w+-)*\[`[^\s]+`\]/, + /-(?:\w+-)*\[(?:[^\s\[\]]+\[[^\s\[\]]+\])*[^\s\[\]]+\]/, + ]), // Not immediately followed by an `{[(` /(?![{([]])/, diff --git a/tests/arbitrary-values.test.js b/tests/arbitrary-values.test.js index b9400ef55f6f..a5bf2e46c520 100644 --- a/tests/arbitrary-values.test.js +++ b/tests/arbitrary-values.test.js @@ -25,6 +25,10 @@ crosscheck(({ stable, oxide }) => { oxide.test.todo( 'should only detect classes with arbitrary values that are properly terminated after the arbitrary value' ) + stable.test.todo( + 'should only detect classes with arbitrary values that are properly terminated after the arbitrary value' + ) + /* stable.test( 'should only detect classes with arbitrary values that are properly terminated after the arbitrary value', () => { @@ -41,6 +45,7 @@ crosscheck(({ stable, oxide }) => { }) } ) + */ it('should be possible to differentiate between decoration utilities', () => { let config = { diff --git a/tests/basic-usage.test.js b/tests/basic-usage.test.js index fefaab93460c..24bae0e68537 100644 --- a/tests/basic-usage.test.js +++ b/tests/basic-usage.test.js @@ -982,7 +982,6 @@ crosscheck(({ stable, oxide, engine }) => { `) stable.expect(result.css).toMatchFormattedCss(css` - .hidden, .group[href^='/'] .group-\[\[href\^\=\'\/\'\]\]\:hidden { display: none; } @@ -1011,7 +1010,6 @@ crosscheck(({ stable, oxide, engine }) => { `) stable.expect(result.css).toMatchFormattedCss(css` - .hidden, .group[href^=' bar'] .group-\[\[href\^\=\'_bar\'\]\]\:hidden { display: none; } @@ -1041,7 +1039,6 @@ crosscheck(({ stable, oxide, engine }) => { } ` : css` - .hidden, .group[href^='/'] .group-\[\[href\^\=\'\/\'\]\]\:hidden { display: none; } @@ -1072,7 +1069,6 @@ crosscheck(({ stable, oxide, engine }) => { } ` : css` - .hidden, .group[href^=' bar'] .group-\[\[href\^\=\'_bar\'\]\]\:hidden { display: none; } From 312582991953e5c3abba2a91d0b0c87e129eb517 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 4 Dec 2023 12:07:03 -0500 Subject: [PATCH 14/14] 3.3.6 --- CHANGELOG.md | 7 ++++++- package-lock.json | 4 ++-- package-lock.stable.json | 4 ++-- package.json | 2 +- package.stable.json | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 705d1d7f0257..e99e80392cad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Nothing yet! + +## [3.3.6] - 2023-12-04 + ### Fixed - Don’t add spaces to negative numbers following a comma ([#12324](https://github.com/tailwindlabs/tailwindcss/pull/12324)) @@ -2299,7 +2303,8 @@ No release notes - Everything! -[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.3.5...HEAD +[unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.3.6...HEAD +[3.3.6]: https://github.com/tailwindlabs/tailwindcss/compare/v3.3.5...v3.3.6 [3.3.5]: https://github.com/tailwindlabs/tailwindcss/compare/v3.3.4...v3.3.5 [3.3.4]: https://github.com/tailwindlabs/tailwindcss/compare/v3.3.3...v3.3.4 [3.3.3]: https://github.com/tailwindlabs/tailwindcss/compare/v3.3.2...v3.3.3 diff --git a/package-lock.json b/package-lock.json index bb63f7dbd67e..0f7ddc503f1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tailwindcss", - "version": "3.3.5", + "version": "3.3.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tailwindcss", - "version": "3.3.5", + "version": "3.3.6", "license": "MIT", "workspaces": [ "integrations/*", diff --git a/package-lock.stable.json b/package-lock.stable.json index 8dad6996de85..f8b4709fade9 100644 --- a/package-lock.stable.json +++ b/package-lock.stable.json @@ -1,12 +1,12 @@ { "name": "tailwindcss", - "version": "3.3.5", + "version": "3.3.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tailwindcss", - "version": "3.3.5", + "version": "3.3.6", "license": "MIT", "dependencies": { "@alloc/quick-lru": "^5.2.0", diff --git a/package.json b/package.json index 51975ceed021..5a93cb514e61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tailwindcss", - "version": "3.3.5", + "version": "3.3.6", "description": "A utility-first CSS framework for rapidly building custom user interfaces.", "license": "MIT", "main": "lib/index.js", diff --git a/package.stable.json b/package.stable.json index 95ec17247f19..ba9d99f52b17 100644 --- a/package.stable.json +++ b/package.stable.json @@ -1,6 +1,6 @@ { "name": "tailwindcss", - "version": "3.3.5", + "version": "3.3.6", "description": "A utility-first CSS framework for rapidly building custom user interfaces.", "license": "MIT", "main": "lib/index.js",