@@ -14,10 +14,10 @@ import { download } from '@electron/get'
1414import envPaths from 'env-paths'
1515import { execa } from 'execa'
1616import extract from 'extract-zip'
17+ import fg from 'fast-glob'
1718import fs from 'fs-extra'
1819import kleur from 'kleur'
1920import Listr from 'listr'
20- import { minimatch } from 'minimatch'
2121import PQueue from 'p-queue'
2222import lockfile from 'proper-lockfile'
2323import { readPackageUpSync } from 'read-pkg-up'
@@ -355,7 +355,7 @@ export async function everyMonorepoProject (projectDir, fn, opts) {
355355 }
356356
357357 /** @type {Record<string, Project> } */
358- const projects = parseProjects ( projectDir , workspaces )
358+ const projects = await parseProjects ( projectDir , workspaces )
359359
360360 checkForCircularDependencies ( projects )
361361
@@ -402,40 +402,45 @@ export async function everyMonorepoProject (projectDir, fn, opts) {
402402 * @param {string } projectDir
403403 * @param {string[] } workspaces
404404 */
405- export function parseProjects ( projectDir , workspaces ) {
405+ export const getSubprojectDirectories = async ( projectDir , workspaces ) => fg . glob ( workspaces , {
406+ cwd : projectDir ,
407+ onlyFiles : false
408+ } )
409+
410+ /**
411+ *
412+ * @param {string } projectDir
413+ * @param {string[] } workspaces
414+ */
415+ export async function parseProjects ( projectDir , workspaces ) {
406416 /** @type {Record<string, Project> } */
407417 const projects = { }
408418
409- for ( const workspace of workspaces ) {
410- for ( const subProjectDir of glob ( '.' , workspace , {
411- cwd : projectDir ,
412- absolute : true
413- } ) ) {
414- const stat = fs . statSync ( subProjectDir )
419+ for ( const subProjectDir of await getSubprojectDirectories ( projectDir , workspaces ) ) {
420+ const stat = fs . statSync ( subProjectDir )
415421
416- if ( ! stat . isDirectory ( ) ) {
417- continue
418- }
422+ if ( ! stat . isDirectory ( ) ) {
423+ continue
424+ }
419425
420- const manfest = path . join ( subProjectDir , 'package.json' )
426+ const manfest = path . join ( subProjectDir , 'package.json' )
421427
422- if ( ! fs . existsSync ( manfest ) ) {
423- continue
424- }
428+ if ( ! fs . existsSync ( manfest ) ) {
429+ continue
430+ }
425431
426- const pkg = fs . readJSONSync ( manfest )
427-
428- projects [ pkg . name ] = {
429- manifest : pkg ,
430- dir : subProjectDir ,
431- siblingDependencies : [ ] ,
432- dependencies : [
433- ...Object . keys ( pkg . dependencies ?? { } ) ,
434- ...Object . keys ( pkg . devDependencies ?? { } ) ,
435- ...Object . keys ( pkg . optionalDependencies ?? { } ) ,
436- ...Object . keys ( pkg . peerDependencies ?? { } )
437- ]
438- }
432+ const pkg = fs . readJSONSync ( manfest )
433+
434+ projects [ pkg . name ] = {
435+ manifest : pkg ,
436+ dir : subProjectDir ,
437+ siblingDependencies : [ ] ,
438+ dependencies : [
439+ ...Object . keys ( pkg . dependencies ?? { } ) ,
440+ ...Object . keys ( pkg . devDependencies ?? { } ) ,
441+ ...Object . keys ( pkg . optionalDependencies ?? { } ) ,
442+ ...Object . keys ( pkg . peerDependencies ?? { } )
443+ ]
439444 }
440445 }
441446
@@ -504,92 +509,6 @@ function checkForCircularDependencies (projects) {
504509 }
505510}
506511
507- /**
508- * @typedef {object } GlobOptions
509- * @property {string } [cwd] The current working directory
510- * @property {boolean } [absolute] If true produces absolute paths (default: false)
511- * @property {boolean } [nodir] If true yields file paths and skip directories (default: false)
512- *
513- * Iterable filename pattern matcher
514- *
515- * @param {string } dir
516- * @param {string } pattern
517- * @param {GlobOptions & import('minimatch').MinimatchOptions } [options]
518- * @returns {Generator<string, void, undefined> }
519- */
520- export function * glob ( dir , pattern , options = { } ) {
521- const absoluteDir = path . resolve ( dir )
522- const relativeDir = path . relative ( options . cwd ?? process . cwd ( ) , dir )
523-
524- const stats = fs . statSync ( absoluteDir )
525-
526- if ( stats . isDirectory ( ) ) {
527- for ( const entry of _glob ( absoluteDir , '' , pattern , options ) ) {
528- yield entry
529- }
530-
531- return
532- }
533-
534- if ( minimatch ( relativeDir , pattern , options ) ) {
535- yield options . absolute === true ? absoluteDir : relativeDir
536- }
537- }
538-
539- /**
540- * @param {string } base
541- * @param {string } dir
542- * @param {string } pattern
543- * @param {GlobOptions & import('minimatch').MinimatchOptions } options
544- * @returns {Generator<string, void, undefined> }
545- */
546- function * _glob ( base , dir , pattern , options ) {
547- const p = path . join ( base , dir )
548-
549- if ( ! fs . existsSync ( p ) ) {
550- return
551- }
552-
553- const stats = fs . statSync ( p )
554-
555- if ( ! stats . isDirectory ( ) ) {
556- return
557- }
558-
559- const d = fs . opendirSync ( p )
560-
561- try {
562- while ( true ) {
563- const entry = d . readSync ( )
564-
565- if ( entry == null ) {
566- break
567- }
568-
569- const relativeEntryPath = path . join ( dir , entry . name )
570- const absoluteEntryPath = path . join ( base , dir , entry . name )
571-
572- let match = minimatch ( relativeEntryPath , pattern , options )
573-
574- const isDirectory = entry . isDirectory ( )
575-
576- if ( isDirectory && options . nodir === true ) {
577- match = false
578- }
579-
580- if ( match ) {
581- yield options . absolute === true ? absoluteEntryPath : relativeEntryPath
582- }
583-
584- if ( isDirectory ) {
585- yield * _glob ( base , relativeEntryPath , pattern , options )
586- }
587- }
588- } finally {
589- d . closeSync ( )
590- }
591- }
592-
593512/**
594513 *
595514 * @param {Error } error
0 commit comments