Describe the bug
A bug was reported indicating that dirent.path is problematic on Windows within @buildScripts/build/esmodules.mjs.
Cause
In older versions of Node.js or in specific environments, fs.Dirent objects might not uniformly expose .path (they sometimes use parentPath or missing it completely). Furthermore, relying on exact directory name matching via if (dirent.name === 'resources') combined with nested manual traversals creates brittle path resolutions when dealing with cross-platform slashes (e.g. \ vs /).
Solution
- Fallback gracefully:
const currentPath = dirent.parentPath || dirent.path;
- Normalize all paths before inspection to
/ so string matching is OS-agnostic: .replace(/\\/g, '/').
- Refactor the
minifyDirectory to evaluate file-by-file recursively rather than doing an awkward combination of file reading and directory copying inside a single conditional block. This removes the need to parse the outputPath to find JSON files within a copied directory.
- Add a safeguard to only minify
ServiceWorker.mjs if it actually exists in the root directory.
Describe the bug A bug was reported indicating that
dirent.pathis problematic on Windows within@buildScripts/build/esmodules.mjs.Cause In older versions of Node.js or in specific environments,
fs.Direntobjects might not uniformly expose.path(they sometimes useparentPathor missing it completely). Furthermore, relying on exact directory name matching viaif (dirent.name === 'resources')combined with nested manual traversals creates brittle path resolutions when dealing with cross-platform slashes (e.g.\vs/).Solution
const currentPath = dirent.parentPath || dirent.path;/so string matching is OS-agnostic:.replace(/\\/g, '/').minifyDirectoryto evaluate file-by-file recursively rather than doing an awkward combination of file reading and directory copying inside a single conditional block. This removes the need to parse theoutputPathto find JSON files within a copied directory.ServiceWorker.mjsif it actually exists in the root directory.