From 5e3b8b69e70df24c4e452d6f2c4872faac03b76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogn=C3=A1r=20L=C3=A1szl=C3=B3?= Date: Thu, 19 Aug 2021 11:55:14 +0200 Subject: [PATCH] watchFiles should look for changes in all files inside sourceDir --- src/index.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1b4f034..4b7e222 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,12 @@ import { Plugin } from "esbuild"; import { Plugin as PostCSSPlugin } from "postcss"; -import { ensureDir, readFile, writeFile } from "fs-extra"; +import { + ensureDir, + readFile, + readdirSync, + statSync, + writeFile +} from "fs-extra"; import { TextDecoder } from "util"; import { SassException, @@ -135,7 +141,7 @@ const postCSSPlugin = ({ return { namespace: isModule ? "postcss-module" : "file", path: tmpFilePath, - watchFiles: [sourceFullPath], + watchFiles: getFilesRecursive(sourceDir), pluginData: { originalPath: sourceFullPath } @@ -199,4 +205,14 @@ function getSassImpl() { return require(impl); } +function getFilesRecursive(directory: string): string[] { + return readdirSync(directory).reduce((files, file) => { + const name = path.join(directory, file); + + return statSync(name).isDirectory() + ? [...files, getFilesRecursive(name)] + : [...files, name]; + }, []); +} + export default postCSSPlugin;