Skip to content

Commit

Permalink
fix: remove it-glob dependency (#1200)
Browse files Browse the repository at this point in the history
it-glob uses aegir to release so we can't depend on it here, otherwise
the aegir dependency on it gets symlinked to the package in the it
monorepo which isn't built at the time aegir tries to build it so
building fails.
  • Loading branch information
achingbrain authored Mar 2, 2023
1 parent e0bd5b0 commit 2285b4e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
"fs-extra": "^11.1.0",
"gh-pages": "^5.0.0",
"globby": "^13.1.1",
"it-glob": "^2.0.0",
"kleur": "^4.1.4",
"lilconfig": "^2.0.5",
"listr": "~0.14.2",
Expand All @@ -285,6 +284,7 @@
"micromark-extension-gfm-strikethrough": "^1.0.4",
"micromark-extension-gfm-table": "^1.0.5",
"micromark-extension-gfm-task-list-item": "^1.0.3",
"minimatch": "^5.1.0",
"mocha": "^10.0.0",
"npm-package-json-lint": "^6.3.0",
"nyc": "^15.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/check-project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import fs from 'fs-extra'
import path from 'path'
import { execa } from 'execa'
import prompt from 'prompt'
import glob from 'it-glob'
import { monorepoManifest } from './manifests/monorepo.js'
import { typedESMManifest } from './manifests/typed-esm.js'
import { typescriptManifest } from './manifests/typescript.js'
Expand All @@ -25,7 +24,8 @@ import Listr from 'listr'
import yargsParser from 'yargs-parser'
import { fileURLToPath } from 'url'
import {
isMonorepoProject
isMonorepoProject,
glob
} from '../utils.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down
3 changes: 1 addition & 2 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import Listr from 'listr'
import { execa } from 'execa'
import { isMonorepoProject, hasDocs } from './utils.js'
import { isMonorepoProject, hasDocs, glob } from './utils.js'
import fs from 'fs-extra'
import path from 'path'
import glob from 'it-glob'
import { calculateSiblingVersion } from './check-project/utils.js'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test-dependant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import path from 'path'
import os from 'os'
import {
exec
exec,
glob
} from '../utils.js'
import fs from 'fs-extra'
import glob from 'it-glob'

/**
* @param {string} name
Expand Down
64 changes: 63 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import envPaths from 'env-paths'
import lockfile from 'proper-lockfile'
import { fileURLToPath } from 'url'
import Listr from 'listr'
import glob from 'it-glob'
import minimatch from 'minimatch'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const EnvPaths = envPaths('aegir', { suffix: '' })
Expand Down Expand Up @@ -451,3 +451,65 @@ function checkForCircularDependencies (projects) {
}
}
}

/**
* @typedef {object} GlobOptions
* @property {string} [cwd] The current working directory
* @property {boolean} [absolute] If true produces absolute paths (default: false)
* @property {boolean} [nodir] If true yields file paths and skip directories (default: false)
*
* Async iterable filename pattern matcher
*
* @param {string} dir
* @param {string} pattern
* @param {GlobOptions & import('minimatch').IOptions} [options]
* @returns {AsyncGenerator<string, void, undefined>}
*/
export async function * glob (dir, pattern, options = {}) {
const absoluteDir = path.resolve(dir)
const relativeDir = path.relative(options.cwd ?? process.cwd(), dir)

const stats = await fs.stat(absoluteDir)

if (stats.isDirectory()) {
for await (const entry of _glob(absoluteDir, '', pattern, options)) {
yield entry
}

return
}

if (minimatch(relativeDir, pattern, options)) {
yield options.absolute === true ? absoluteDir : relativeDir
}
}

/**
* @param {string} base
* @param {string} dir
* @param {string} pattern
* @param {GlobOptions & import('minimatch').IOptions} options
* @returns {AsyncGenerator<string, void, undefined>}
*/
async function * _glob (base, dir, pattern, options) {
for await (const entry of await fs.opendir(path.join(base, dir))) {
const relativeEntryPath = path.join(dir, entry.name)
const absoluteEntryPath = path.join(base, dir, entry.name)

let match = minimatch(relativeEntryPath, pattern, options)

const isDirectory = entry.isDirectory()

if (isDirectory && options.nodir === true) {
match = false
}

if (match) {
yield options.absolute === true ? absoluteEntryPath : relativeEntryPath
}

if (isDirectory) {
yield * _glob(base, relativeEntryPath, pattern, options)
}
}
}

0 comments on commit 2285b4e

Please sign in to comment.