diff options
author | 2024-10-11 20:48:31 +0800 | |
---|---|---|
committer | 2024-10-11 20:48:31 +0800 | |
commit | 2f5b28e93851f39708d0d683832c70730b40afe9 (patch) | |
tree | f026d9590d4c599a51f8235bbdc175ea40078bee | |
parent | 49c4f64673390f7035258d662755988f0fb71a94 (diff) | |
download | astro-2f5b28e93851f39708d0d683832c70730b40afe9.tar.gz astro-2f5b28e93851f39708d0d683832c70730b40afe9.tar.zst astro-2f5b28e93851f39708d0d683832c70730b40afe9.zip |
Use p-queue instead of fastq (#12189)
Diffstat (limited to '')
-rw-r--r-- | packages/astro/package.json | 2 | ||||
-rw-r--r-- | packages/astro/src/content/content-layer.ts | 10 | ||||
-rw-r--r-- | packages/astro/src/core/logger/core.ts | 19 | ||||
-rw-r--r-- | pnpm-lock.yaml | 6 |
4 files changed, 5 insertions, 32 deletions
diff --git a/packages/astro/package.json b/packages/astro/package.json index 2a8f592cc..31abc763e 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 b2729ce4d..7917c2500 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, unknown> | string) => string; - #queue: fastq.queueAsPromised<RefreshContentOptions, void>; + #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<void> { - 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 51ebd9325..e77f6014d 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<T> { 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<any>) { - 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 5cb1df3b9..b8982deaf 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 |