diff --git a/packages/astro/package.json b/packages/astro/package.json index 2a8f592cc404..31abc763eaee 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -152,7 +152,6 @@ "esbuild": "^0.21.5", "estree-walker": "^3.0.3", "fast-glob": "^3.3.2", - "fastq": "^1.17.1", "flattie": "^1.1.1", "github-slugger": "^2.0.0", "gray-matter": "^4.0.3", @@ -173,7 +172,6 @@ "rehype": "^13.0.2", "semver": "^7.6.3", "shiki": "^1.22.0", - "string-width": "^7.2.0", "tinyexec": "^0.3.0", "tsconfck": "^3.1.3", "unist-util-visit": "^5.0.0", diff --git a/packages/astro/src/content/content-layer.ts b/packages/astro/src/content/content-layer.ts index b2729ce4dd72..7917c2500379 100644 --- a/packages/astro/src/content/content-layer.ts +++ b/packages/astro/src/content/content-layer.ts @@ -1,5 +1,5 @@ import { promises as fs, existsSync } from 'node:fs'; -import * as fastq from 'fastq'; +import PQueue from 'p-queue'; import type { FSWatcher } from 'vite'; import xxhash from 'xxhash-wasm'; import type { AstroSettings, ContentEntryType, RefreshContentOptions } from '../@types/astro.js'; @@ -36,7 +36,7 @@ export class ContentLayer { #generateDigest?: (data: Record | string) => string; - #queue: fastq.queueAsPromised; + #queue: PQueue; constructor({ settings, logger, store, watcher }: ContentLayerOptions) { // The default max listeners is 10, which can be exceeded when using a lot of loaders @@ -46,14 +46,14 @@ export class ContentLayer { this.#store = store; this.#settings = settings; this.#watcher = watcher; - this.#queue = fastq.promise(this.#doSync.bind(this), 1); + this.#queue = new PQueue({ concurrency: 1 }); } /** * Whether the content layer is currently loading content */ get loading() { - return !this.#queue.idle(); + return this.#queue.size > 0 || this.#queue.pending > 0; } /** @@ -124,7 +124,7 @@ export class ContentLayer { */ sync(options: RefreshContentOptions = {}): Promise { - return this.#queue.push(options); + return this.#queue.add(() => this.#doSync(options)); } async #doSync(options: RefreshContentOptions) { diff --git a/packages/astro/src/core/logger/core.ts b/packages/astro/src/core/logger/core.ts index 51ebd9325b06..e77f6014d8d6 100644 --- a/packages/astro/src/core/logger/core.ts +++ b/packages/astro/src/core/logger/core.ts @@ -1,5 +1,4 @@ import { blue, bold, dim, red, yellow } from 'kleur/colors'; -import stringWidth from 'string-width'; export interface LogWritable { write: (chunk: T) => boolean; @@ -117,30 +116,12 @@ export function error(opts: LogOptions, label: string | null, message: string, n return log(opts, 'error', label, message, newLine); } -type LogFn = typeof info | typeof warn | typeof error; - -export function table(opts: LogOptions, columns: number[]) { - return function logTable(logFn: LogFn, ...input: Array) { - const message = columns.map((len, i) => padStr(input[i].toString(), len)).join(' '); - logFn(opts, null, message); - }; -} - export function debug(...args: any[]) { if ('_astroGlobalDebug' in globalThis) { (globalThis as any)._astroGlobalDebug(...args); } } -function padStr(str: string, len: number) { - const strLen = stringWidth(str); - if (strLen > len) { - return str.substring(0, len - 3) + '...'; - } - const spaces = Array.from({ length: len - strLen }, () => ' ').join(''); - return str + spaces; -} - /** * Get the prefix for a log message. * This includes the timestamp, log level, and label all properly formatted diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5cb1df3b9858..b8982deaf1c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -642,9 +642,6 @@ importers: fast-glob: specifier: ^3.3.2 version: 3.3.2 - fastq: - specifier: ^1.17.1 - version: 1.17.1 flattie: specifier: ^1.1.1 version: 1.1.1 @@ -705,9 +702,6 @@ importers: shiki: specifier: ^1.22.0 version: 1.22.0 - string-width: - specifier: ^7.2.0 - version: 7.2.0 tinyexec: specifier: ^0.3.0 version: 0.3.0