From 962eb52ec6d73e503c30718b03bbbe75249b8697 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 17 Feb 2023 21:42:10 +0100 Subject: [PATCH] Enable relative content paths for the `oxide` engine (#10621) * enable `relativeContentPathsByDefault` for the `oxide` engine * update tests to reflect `relative` change in the `oxide` engine * update changelog --- CHANGELOG.md | 1 + src/featureFlags.js | 3 ++ src/util/normalizeConfig.js | 3 +- tests/normalize-config.test.js | 50 ++++++++++++++++++++++++---------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3931d5f91..e76da292e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [Oxide] Disable color opacity plugins by default in the `oxide` engine ([#10618](https://github.com/tailwindlabs/tailwindcss/pull/10618)) +- [Oxide] Enable relative content paths for the `oxide` engine ([#10621](https://github.com/tailwindlabs/tailwindcss/pull/10621)) ## [3.2.7] - 2023-02-16 diff --git a/src/featureFlags.js b/src/featureFlags.js index 7013c7534..bc5f167a0 100644 --- a/src/featureFlags.js +++ b/src/featureFlags.js @@ -8,6 +8,9 @@ let defaults = { get disableColorOpacityUtilitiesByDefault() { return env.OXIDE }, + get relativeContentPathsByDefault() { + return env.OXIDE + }, } let featureFlags = { diff --git a/src/util/normalizeConfig.js b/src/util/normalizeConfig.js index 95f63a39e..7e1a592de 100644 --- a/src/util/normalizeConfig.js +++ b/src/util/normalizeConfig.js @@ -1,3 +1,4 @@ +import { flagEnabled } from '../featureFlags' import log, { dim } from './log' export function normalizeConfig(config) { @@ -189,7 +190,7 @@ export function normalizeConfig(config) { return content.relative } - return config.future?.relativeContentPathsByDefault ?? false + return flagEnabled(config, 'relativeContentPathsByDefault') })(), files: (() => { diff --git a/tests/normalize-config.test.js b/tests/normalize-config.test.js index ac9892c8c..dff357a81 100644 --- a/tests/normalize-config.test.js +++ b/tests/normalize-config.test.js @@ -36,19 +36,21 @@ crosscheck(({ stable, oxide }) => { oxide.test.todo('should normalize extractors') stable.test.each` - config - ${{ content: [{ raw: 'text-center' }], purge: { extract: () => ['font-bold'] } }} - ${{ content: [{ raw: 'text-center' }], purge: { extract: { DEFAULT: () => ['font-bold'] } } }} - ${{ - content: [{ raw: 'text-center' }], - purge: { options: { defaultExtractor: () => ['font-bold'] } }, - }} - ${{ - content: [{ raw: 'text-center' }], - purge: { options: { extractors: [{ extractor: () => ['font-bold'], extensions: ['html'] }] } }, - }} - ${{ content: [{ raw: 'text-center' }], purge: { extract: { html: () => ['font-bold'] } } }} -`('should normalize extractors $config', ({ config }) => { + config + ${{ content: [{ raw: 'text-center' }], purge: { extract: () => ['font-bold'] } }} + ${{ content: [{ raw: 'text-center' }], purge: { extract: { DEFAULT: () => ['font-bold'] } } }} + ${{ + content: [{ raw: 'text-center' }], + purge: { options: { defaultExtractor: () => ['font-bold'] } }, + }} + ${{ + content: [{ raw: 'text-center' }], + purge: { + options: { extractors: [{ extractor: () => ['font-bold'], extensions: ['html'] }] }, + }, + }} + ${{ content: [{ raw: 'text-center' }], purge: { extract: { html: () => ['font-bold'] } } }} + `('should normalize extractors $config', ({ config }) => { return run('@tailwind utilities', config).then((result) => { return expect(result.css).toMatchFormattedCss(css` .font-bold { @@ -111,12 +113,18 @@ crosscheck(({ stable, oxide }) => { content: ['./example-folder/**/*.{html,js}'], } - expect(normalizeConfig(resolveConfig(config)).content).toEqual({ + stable.expect(normalizeConfig(resolveConfig(config)).content).toEqual({ files: ['./example-folder/**/*.{html,js}'], relative: false, extract: {}, transform: {}, }) + oxide.expect(normalizeConfig(resolveConfig(config)).content).toEqual({ + files: ['./example-folder/**/*.{html,js}'], + relative: true, + extract: {}, + transform: {}, + }) }) it('should warn when we detect invalid globs with incorrect brace expansion', () => { @@ -130,8 +138,10 @@ crosscheck(({ stable, oxide }) => { ], } + let normalizedConfig = normalizeConfig(resolveConfig(config)).content + // No rewrite happens - expect(normalizeConfig(resolveConfig(config)).content).toEqual({ + stable.expect(normalizedConfig).toEqual({ files: [ './{example-folder}/**/*.{html,js}', './{example-folder}/**/*.{html}', @@ -141,6 +151,16 @@ crosscheck(({ stable, oxide }) => { extract: {}, transform: {}, }) + oxide.expect(normalizedConfig).toEqual({ + files: [ + './{example-folder}/**/*.{html,js}', + './{example-folder}/**/*.{html}', + './example-folder/**/*.{html}', + ], + relative: true, + extract: {}, + transform: {}, + }) // But a warning should happen expect(spy).toHaveBeenCalledTimes(2)