diff --git a/core/scripts/css/postcss-watch.js b/core/scripts/css/postcss-watch.js index 472c4a944b449981da35ca05734530413ed2b353..43e2138ce434c092b44d62979f35bc76087cbe06 100644 --- a/core/scripts/css/postcss-watch.js +++ b/core/scripts/css/postcss-watch.js @@ -9,19 +9,18 @@ 'use strict'; -const fs = require('node:fs'); -const path = require('node:path'); -const chokidar = require('chokidar'); +const { watch } = require('chokidar'); +const { stat, unlink } = require('node:fs'); const changeOrAdded = require('./changeOrAdded'); const log = require('./log'); -// Match only on .pcss.css files. -const fileMatch = './**/*.pcss.css'; -// Ignore everything in node_modules -const watcher = chokidar.watch(fileMatch, { +// Initialize watcher. +const watcher = watch(['./themes', './modules', './profiles'], { ignoreInitial: true, - ignored: './node_modules/**' + ignored: (filePath, stats) => + stats?.isFile() && !filePath.endsWith('.pcss.css') || filePath.includes('node_modules'), + usePolling: true, }); const unlinkHandler = (err) => { @@ -36,8 +35,10 @@ watcher .on('change', changeOrAdded) .on('unlink', (filePath) => { const fileName = filePath.slice(0, -9); - fs.stat(`${fileName}.css`, () => { - fs.unlink(`${fileName}.css`, unlinkHandler); + stat(`${fileName}.css`, (err) => { + if (!err) { + unlink(`${fileName}.css`, unlinkHandler); + } }); }) - .on('ready', () => log(`Watching '${fileMatch}' for changes.`)); + .on('ready', () => log(`Watching '**/*.pcss.css' for changes.`));