chore: use readdir internally rather than globby

This commit is contained in:
Daniel Roe 2024-06-24 14:33:47 +01:00
parent c45131b46f
commit 0ef8febb8c
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 10 additions and 14 deletions

View File

@ -2,7 +2,6 @@ import { execSync } from 'node:child_process'
import { promises as fsp } from 'node:fs' import { promises as fsp } from 'node:fs'
import { $fetch } from 'ofetch' import { $fetch } from 'ofetch'
import { resolve } from 'pathe' import { resolve } from 'pathe'
import { globby } from 'globby'
import { execaSync } from 'execa' import { execaSync } from 'execa'
import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen' import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen'
@ -43,12 +42,13 @@ export async function loadPackage (dir: string) {
export async function loadWorkspace (dir: string) { export async function loadWorkspace (dir: string) {
const workspacePkg = await loadPackage(dir) const workspacePkg = await loadPackage(dir)
const pkgDirs = (await globby(['packages/*'], { onlyDirectories: true })).sort() const pkgDirs = await fsp.readdir('packages', { withFileTypes: true })
const packages: Package[] = [] const packages: Package[] = []
for (const pkgDir of pkgDirs) { for (const pkgDir of pkgDirs) {
const pkg = await loadPackage(pkgDir) if (!pkgDir.isDirectory()) { continue }
const pkg = await loadPackage(resolve('packages', pkgDir.name))
if (!pkg.data.name) { continue } if (!pkg.data.name) { continue }
packages.push(pkg) packages.push(pkg)
} }

View File

@ -1,26 +1,22 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { rm } from 'node:fs/promises' import { readdir, rm } from 'node:fs/promises'
import { globby } from 'globby'
import { execa } from 'execa' import { execa } from 'execa'
import { join } from 'pathe'
async function initTesting () { async function initTesting () {
const dirs = await globby('*', { const fixturesDir = fileURLToPath(new URL('./fixtures', import.meta.url))
onlyDirectories: true, const dirs = await readdir(fixturesDir)
cwd: fileURLToPath(new URL('./fixtures', import.meta.url)),
absolute: true,
})
await Promise.all([ await Promise.all([
// clear nuxt build files // clear nuxt build files
...dirs.map(dir => rm(`${dir}/.nuxt`, { force: true, recursive: true })), ...dirs.map(dir => rm(join(fixturesDir, `${dir}/.nuxt`), { force: true, recursive: true })),
// clear vite cache // clear vite cache
...dirs.map(dir => rm(`${dir}/node_modules/.cache`, { force: true, recursive: true })), ...dirs.map(dir => rm(join(fixturesDir, `${dir}/node_modules/.cache`), { force: true, recursive: true })),
]) ])
await Promise.all( await Promise.all(
dirs.map(dir => execa('pnpm', ['nuxi', 'prepare'], { cwd: dir })), dirs.map(dir => execa('pnpm', ['nuxi', 'prepare'], { cwd: join(fixturesDir, dir) })),
) )
} }