mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
Use p-queue instead of fastq (#12189)
This commit is contained in:
parent
49c4f64673
commit
2f5b28e938
4 changed files with 5 additions and 32 deletions
|
@ -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",
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue