| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9656979 commit 193b161
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,17 @@ import outputFile from './lib/outputFile.js' | |||
| 21 | 21 | const reporter = postcssReporter() | |
| 22 | 22 | const depGraph = createDependencyGraph() | |
| 23 | 23 | ||
| 24 | + const expandGlob = async (patterns) => { | ||
| 25 | + if (!Array.isArray(patterns)) patterns = [patterns] | ||
| 26 | + | ||
| 27 | + const paths = await glob( | ||
| 28 | + patterns.map((i) => slash(String(i))), | ||
| 29 | + { dot: argv.includeDotfiles }, | ||
| 30 | + ) | ||
| 31 | + | ||
| 32 | + return paths.map((i) => path.resolve(i)) | ||
| 33 | + } | ||
| 34 | + | ||
| 24 | 35 | let input = argv._ | |
| 25 | 36 | const { dir, output } = argv | |
| 26 | 37 | ||
@@ -79,19 +90,15 @@ if (argv.watch && !(argv.output || argv.replace || argv.dir)) { | |||
| 79 | 90 | } | |
| 80 | 91 | ||
| 81 | 92 | if (input && input.length) { | |
| 82 | - input = await glob( | ||
| 83 | - input.map((i) => slash(String(i))), | ||
| 84 | - { dot: argv.includeDotfiles }, | ||
| 85 | - ) | ||
| 93 | + input = await expandGlob(input) | ||
| 94 | + | ||
| 86 | 95 | if (!input.length) { | |
| 87 | 96 | error('Input Error: You must pass a valid list of files to parse') | |
| 88 | 97 | } | |
| 89 | 98 | ||
| 90 | 99 | if (input.length > 1 && !argv.dir && !argv.replace) { | |
| 91 | 100 | error('Input Error: Must use --dir or --replace with multiple input files') | |
| 92 | 101 | } | |
| 93 | - | ||
| 94 | - input = input.map((i) => path.resolve(i)) | ||
| 95 | 102 | } else { | |
| 96 | 103 | if (argv.replace || argv.dir) { | |
| 97 | 104 | error('Input Error: Cannot use --dir or --replace when reading from stdin') | |
@@ -110,7 +117,8 @@ try { | |||
| 110 | 117 | if (argv.watch) { | |
| 111 | 118 | const printMessage = () => | |
| 112 | 119 | printVerbose(pc.dim('\nWaiting for file changes...')) | |
| 113 | - const watcher = chokidar.watch(input.concat(dependencies(results)), { | ||
| 120 | + const deps = await dependencies(results) | ||
| 121 | + const watcher = chokidar.watch(input.concat(deps), { | ||
| 114 | 122 | usePolling: argv.poll, | |
| 115 | 123 | interval: argv.poll && typeof argv.poll === 'number' ? argv.poll : 100, | |
| 116 | 124 | awaitWriteFinish: { | |
@@ -137,7 +145,8 @@ try { | |||
| 137 | 145 | if (!recompile.length) recompile = input | |
| 138 | 146 | ||
| 139 | 147 | return files([...new Set(recompile)]) | |
| 140 | - .then((results) => watcher.add(dependencies(results))) | ||
| 148 | + .then((results) => dependencies(results)) | ||
| 149 | + .then((deps) => watcher.add(deps)) | ||
| 141 | 150 | .then(printMessage) | |
| 142 | 151 | .catch((err) => { | |
| 143 | 152 | // Watch mode shouldn't exit on file processing error | |
@@ -260,27 +269,34 @@ async function css(css, file) { | |||
| 260 | 269 | return result | |
| 261 | 270 | } | |
| 262 | 271 | ||
| 263 | - function dependencies(results) { | ||
| 272 | + async function dependencies(results) { | ||
| 264 | 273 | if (!Array.isArray(results)) results = [results] | |
| 265 | 274 | ||
| 266 | - return results.flatMap((result) => { | ||
| 267 | - if (result.messages.length <= 0) return [] | ||
| 268 | - | ||
| 269 | - return result.messages | ||
| 270 | - .filter( | ||
| 271 | - (msg) => msg.type === 'dependency' || msg.type === 'dir-dependency', | ||
| 275 | + const depArrays = await Promise.all( | ||
| 276 | + results.map(async (result) => { | ||
| 277 | + if (result.messages.length <= 0) return [] | ||
| 278 | + | ||
| 279 | + return Promise.all( | ||
| 280 | + result.messages | ||
| 281 | + .filter( | ||
| 282 | + (msg) => msg.type === 'dependency' || msg.type === 'dir-dependency', | ||
| 283 | + ) | ||
| 284 | + .map(depGraph.add) | ||
| 285 | + .map(async (dependency) => { | ||
| 286 | + if (dependency.type === 'dir-dependency') { | ||
| 287 | + return dependency.glob | ||
| 288 | + ? await expandGlob(path.join(dependency.dir, dependency.glob)) | ||
| 289 | + : dependency.dir | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + return dependency.file | ||
| 293 | + }), | ||
| 272 | 294 | ) | |
| 273 | - .map(depGraph.add) | ||
| 274 | - .map((dependency) => { | ||
| 275 | - if (dependency.type === 'dir-dependency') { | ||
| 276 | - return dependency.glob | ||
| 277 | - ? path.join(dependency.dir, dependency.glob) | ||
| 278 | - : dependency.dir | ||
| 279 | - } | ||
| 280 | - | ||
| 281 | - return dependency.file | ||
| 282 | - }) | ||
| 283 | - }) | ||
| 295 | + }), | ||
| 296 | + ) | ||
| 297 | + | ||
| 298 | + // depth of 2 is needed because glob dir-dependency can return an array of files | ||
| 299 | + return depArrays.flat(2) | ||
| 284 | 300 | } | |
| 285 | 301 | ||
| 286 | 302 | function printVerbose(message) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ | |||
| 18 | 18 | "test": "c8 ava -v" | |
| 19 | 19 | }, | |
| 20 | 20 | "dependencies": { | |
| 21 | - "chokidar": "^3.3.0", | ||
| 21 | + "chokidar": "^5.0.0", | ||
| 22 | 22 | "dependency-graph": "^1.0.0", | |
| 23 | 23 | "picocolors": "^1.0.0", | |
| 24 | 24 | "postcss-load-config": "^6.0.0", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments