From d9e55546d939e4319facb6f587a23887893dc66a Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 24 Jun 2024 14:34:07 +0100 Subject: [PATCH] refactor(ui-templates): use `fdir` --- packages/ui-templates/lib/prerender.ts | 6 ++---- packages/ui-templates/lib/render.ts | 6 +++--- packages/ui-templates/package.json | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/ui-templates/lib/prerender.ts b/packages/ui-templates/lib/prerender.ts index 2d1c4660c5..1157df6aa6 100644 --- a/packages/ui-templates/lib/prerender.ts +++ b/packages/ui-templates/lib/prerender.ts @@ -1,14 +1,12 @@ import { join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' import { promises as fsp } from 'node:fs' -import { globby } from 'globby' +import { fdir } from 'fdir' const templatesRoot = fileURLToPath(new URL('..', import.meta.url)) -const r = (...path: string[]) => resolve(join(templatesRoot, ...path)) - async function main () { - const templates = await globby(r('dist/templates/*.js')) + const templates = new fdir().glob('*.js').crawl(join(templatesRoot, 'dist/templates')).sync() for (const file of templates) { const { template } = await import(file) const updated = template({ diff --git a/packages/ui-templates/lib/render.ts b/packages/ui-templates/lib/render.ts index c9d5986c4f..a92efcec55 100644 --- a/packages/ui-templates/lib/render.ts +++ b/packages/ui-templates/lib/render.ts @@ -1,13 +1,13 @@ import { fileURLToPath } from 'node:url' import { readFileSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs' import { copyFile } from 'node:fs/promises' -import { basename, dirname, join, resolve } from 'pathe' +import { basename, dirname, join } from 'pathe' import type { Plugin } from 'vite' // @ts-expect-error https://github.com/GoogleChromeLabs/critters/pull/151 import Critters from 'critters' import { genObjectFromRawEntries } from 'knitwork' import htmlMinifier from 'html-minifier' -import { globby } from 'globby' +import { fdir } from 'fdir' import { camelCase } from 'scule' import genericMessages from '../templates/messages.json' @@ -25,7 +25,7 @@ export const RenderPlugin = () => { enforce: 'post', async writeBundle () { const critters = new Critters({ path: outputDir }) - const htmlFiles = await globby(resolve(outputDir, 'templates/**/*.html'), { absolute: true }) + const htmlFiles = new fdir().withFullPaths().glob('**/*.html').crawl(join(outputDir, 'templates')).sync() const templateExports: Array<{ exportName: string diff --git a/packages/ui-templates/package.json b/packages/ui-templates/package.json index 2721e46670..2bac4a6a8d 100644 --- a/packages/ui-templates/package.json +++ b/packages/ui-templates/package.json @@ -23,11 +23,12 @@ "@unocss/reset": "0.61.0", "critters": "0.0.22", "execa": "9.2.0", - "globby": "14.0.1", + "fdir": "6.1.1", "html-minifier": "4.0.0", "jiti": "1.21.6", "knitwork": "1.1.0", "pathe": "1.1.2", + "picomatch": "4.0.2", "prettier": "3.3.2", "scule": "1.3.0", "unocss": "0.61.0",