From c6af229a481ab9676720b6c3429adf8a145a9fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Tue, 31 May 2022 16:01:28 +0100 Subject: [PATCH] feat(angular): support tailwind.config.cjs as valid config file in library executors (#10531) --- .../src/executors/utilities/tailwindcss.ts | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/angular/src/executors/utilities/tailwindcss.ts b/packages/angular/src/executors/utilities/tailwindcss.ts index 82f9c2e154011..1216326df6da8 100644 --- a/packages/angular/src/executors/utilities/tailwindcss.ts +++ b/packages/angular/src/executors/utilities/tailwindcss.ts @@ -25,15 +25,7 @@ export function getTailwindSetup( let tailwindConfigPath = tailwindConfig; if (!tailwindConfigPath) { - // Try to find TailwindCSS configuration file in the project or workspace root. - const tailwindConfigFile = 'tailwind.config.js'; - for (const path of [basePath, workspaceRoot]) { - const fullPath = join(path, tailwindConfigFile); - if (existsSync(fullPath)) { - tailwindConfigPath = fullPath; - break; - } - } + tailwindConfigPath = getTailwindConfigPath(basePath, workspaceRoot); } // Only load Tailwind CSS plugin if configuration file was found. @@ -65,6 +57,25 @@ export function getTailwindSetup( return { tailwindConfigPath, tailwindPackagePath }; } +function getTailwindConfigPath( + projectRoot: string, + workspaceRoot: string +): string | undefined { + // valid tailwind config files https://github.com/tailwindlabs/tailwindcss/blob/master/src/util/resolveConfigPath.js#L46 + const tailwindConfigFiles = ['tailwind.config.js', 'tailwind.config.cjs']; + + for (const basePath of [projectRoot, workspaceRoot]) { + for (const configFile of tailwindConfigFiles) { + const fullPath = join(basePath, configFile); + if (existsSync(fullPath)) { + return fullPath; + } + } + } + + return undefined; +} + export function getTailwindPostCssPlugins( { tailwindConfigPath, tailwindPackagePath }: TailwindSetup, includePaths?: string[],