Verified Commit 3a84566d authored by Jess's avatar Jess
Browse files

Issue #3504265 by finnsky, smustgrave, ksenzee, nod_: Yarn watch task broken

(cherry picked from commit 1bf26ca8)
parent a0a7eec9
Loading
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -9,19 +9,18 @@

'use strict';

const fs = require('fs');
const path = require('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.`));