From 2b596de7c7355d8d8149c4f91ff1ac34d51a73f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr?= <8machy@seznam.cz> Date: Sat, 14 Jan 2023 11:24:52 +0000 Subject: [PATCH] CS fixes --- packages/bundler/src/Bundler.ts | 4 ++-- packages/bundler/tests/jest/css-layers.test.ts | 10 ++++++---- packages/unplugin/src/index.ts | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/bundler/src/Bundler.ts b/packages/bundler/src/Bundler.ts index 27ece003..7892d573 100644 --- a/packages/bundler/src/Bundler.ts +++ b/packages/bundler/src/Bundler.ts @@ -659,7 +659,7 @@ export class Bundler { 'bundler:beforeCssFileCreated', { content: generatedCss, bundleConfig } ); - let outputFileContent = hookData.content as string; + let outputFileContent = hookData.content; const isDev = bundleBuildCache.compiler.dev; const whiteSpace = isDev ? '\n' : ''; @@ -669,7 +669,7 @@ export class Bundler { typeof exportLayerName === 'undefined' || !exportLayerName.includes(bundleConfig.cssLayer) ? '' : `@layer ${this.cssLayersOrder.order};${whiteSpace.repeat(2)}`; - layerContent += `@layer ${bundleConfig.cssLayer} {${whiteSpace}${outputFileContent}${whiteSpace}}`; + layerContent += `@layer ${bundleConfig.cssLayer} {${whiteSpace + outputFileContent + whiteSpace}}`; outputFileContent = layerContent; } diff --git a/packages/bundler/tests/jest/css-layers.test.ts b/packages/bundler/tests/jest/css-layers.test.ts index 604d3d16..aefdb40f 100644 --- a/packages/bundler/tests/jest/css-layers.test.ts +++ b/packages/bundler/tests/jest/css-layers.test.ts @@ -16,16 +16,16 @@ if (!fs.existsSync(buildTmpDir)) { fse.copySync(path.join(bundleTestDir, 'input'), buildTmpDir); -test('Single file', (): void => { - return; - new Bundler({ +test('Single file', async (): void => { + const bundler = new Bundler({ dev: true, cssLayersOrder: { order: ['layout', 'page'].join(','), exportLayer: ['layout'], exportFile: path.join(buildTmpDir, 'stylify-css-layers.css') } - }).bundle([ + }) + bundler.bundle([ { outputFile: path.join(buildTmpDir, 'layout.css'), files: [ path.join(buildTmpDir, 'layout.html') ], @@ -38,6 +38,8 @@ test('Single file', (): void => { }, ]); + await bundler.waitOnBundlesProcessed(); + const layoutCssOutput = testUtils.readFile(path.join(buildTmpDir, 'layout.css')); const pageCssOutput = testUtils.readFile(path.join(buildTmpDir, 'page.css')); const layersCssOutput = testUtils.readFile(path.join(buildTmpDir, 'stylify-css-layers.css')); diff --git a/packages/unplugin/src/index.ts b/packages/unplugin/src/index.ts index f34c2acf..3ae60c03 100644 --- a/packages/unplugin/src/index.ts +++ b/packages/unplugin/src/index.ts @@ -149,7 +149,9 @@ export const unplugin = createUnplugin((config: UnpluginConfigInterface|Unplugin await bundlerRunner.waitOnBundlesProcessed(); }; - const shouldMangleSelectors = () => pluginConfig?.compiler?.mangleSelectors + + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + const shouldMangleSelectors = (): boolean => pluginConfig?.compiler?.mangleSelectors ?? pluginConfig?.bundler?.compiler?.mangleSelectors ?? (!pluginConfig.dev && !pluginConfig.bundler.watchFiles);