Skip to content

Commit 60a4bba

Browse files
committed
chore: fix test and provide toggle
1 parent f606398 commit 60a4bba

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

src/context.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
6767
const configResolvedPath = join(nuxt.options.buildDir, CONFIG_TEMPLATE_NAME)
6868
let enableHMR = true
6969

70+
if (moduleOptions.disableHMR) {
71+
enableHMR = false
72+
}
73+
7074
const unsafeProperty = unsafeInlineConfig(moduleOptions.config)
71-
if (unsafeProperty) {
75+
if (unsafeProperty && enableHMR) {
7276
logger.warn(
7377
`The provided Tailwind configuration in your \`nuxt.config\` is non-serializable. Check \`${unsafeProperty}\`. Falling back to providing the loaded configuration inlined directly to PostCSS loader..`,
7478
'Please consider using `tailwind.config` or a separate file (specifying in `configPath` of the module options) to enable it with additional support for IntelliSense and HMR. Suppress this warning with `quiet: true` in the module options.',
@@ -92,15 +96,15 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
9296
return Reflect.set(target, key, value)
9397
}
9498

95-
if (functionalStringify(value).includes(`"${CONFIG_TEMPLATE_NAME + 'ns'}"`)) {
99+
if (functionalStringify(value).includes(`"${CONFIG_TEMPLATE_NAME + 'ns'}"`) && enableHMR) {
96100
logger.warn(
97101
`A hook has injected a non-serializable value in \`config${cfgKey}\`, so the Tailwind Config cannot be serialized. Falling back to providing the loaded configuration inlined directly to PostCSS loader..`,
98102
'Please consider using a configuration file/template instead (specifying in `configPath` of the module options) to enable additional support for IntelliSense and HMR.',
99103
)
100104
enableHMR = false
101105
}
102106

103-
if (JSONStringifyWithRegex(value).includes('__REGEXP')) {
107+
if (JSONStringifyWithRegex(value).includes('__REGEXP') && enableHMR) {
104108
logger.warn(`A hook is injecting RegExp values in your configuration (check \`config${cfgKey}\`) which may be unsafely serialized. Consider moving your safelist to a separate configuration file/template instead (specifying in \`configPath\` of the module options)`)
105109
}
106110

src/runtime/merger.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ const isJSObject = value => typeof value === 'object' && !Array.isArray(value)
1212
*
1313
* @type {(...p: Array<Partial<TWConfig> | Record<string | number | symbol, any> | undefined>) => Partial<TWConfig>}
1414
*/
15-
export default (_base, ...defaults) => {
16-
const base = _base ?? klona(defaults[0])
15+
export default (base, ...defaults) => {
16+
if (!base) {
17+
return klona(defaults[0])
18+
}
1719

1820
return createDefu((obj, key, value) => {
1921
if (key === 'content') {
@@ -28,14 +30,9 @@ export default (_base, ...defaults) => {
2830
}
2931

3032
// keeping arrayFn
31-
if (Array.isArray(obj[key]) && typeof value === 'function') {
32-
obj[key] = value(obj[key])
33+
if (obj[key] && typeof value === 'function') {
34+
obj[key] = value(Array.isArray(obj[key]) ? obj[key] : obj[key]['files'])
3335
return true
3436
}
35-
36-
// create copy of object
37-
if (!obj[key] && isJSObject(value)) {
38-
obj[key] = Object.assign({}, value)
39-
}
40-
})(base, ...defaults)
37+
})(klona(base), ...defaults.map(klona))
4138
}

src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ export interface ModuleOptions {
134134
* @default false // if true, { autocompleteUtil: true }
135135
*/
136136
editorSupport: BoolObj<EditorSupportConfig>
137+
/**
138+
* This option falls back to the Tailwind configuration inlined to the PostCSS
139+
* loader, so any configuration changes while the dev server is running will
140+
* not reflect. This is similar to the functionality prior to v6.12.0.
141+
*
142+
* Note: this is only provided for temporary broken builds that may require
143+
* migration. Usage is discouraged. If any issues occur without this, please open
144+
* an issue on https://github.com/nuxt-modules/tailwindcss/issues.
145+
*/
146+
disableHMR?: boolean
137147
}
138148

139149
export interface ModuleHooks {

test/configs.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ describe('tailwindcss module configs', async () => {
8686
// set from override-tailwind.config.ts
8787
const { content: { files: contentFiles } } = destr<TWConfigWithStringContent>(getVfsFile('test-tailwind.config.mjs')!.replace(/^export default /, ''))
8888

89-
expect(contentFiles[0]).toBe('ts-content/**/*.md')
9089
expect(contentFiles[1]).toBe('./custom-theme/**/*.vue')
9190
expect(contentFiles.filter(c => /\{[AE],[ae]\}/.test(c)).length).toBe(0)
9291
expect([...contentFiles].pop()).toBe('my-custom-content')

test/fixtures/basic/override-tailwind.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default {
22
content: contentDefaults => [
3-
contentDefaults[0],
3+
contentDefaults?.[0],
44
'./custom-theme/**/*.vue',
5-
...contentDefaults.filter(c => !/\{[AE],[ae]\}/.test(c)),
5+
...(contentDefaults || []).filter(c => !/\{[AE],[ae]\}/.test(c)),
66
],
77
theme: {
88
extend: {

0 commit comments

Comments
 (0)