Skip to content

Commit

Permalink
Use p-queue instead of fastq (#12189)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 11, 2024
1 parent 49c4f64 commit 2f5b28e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 32 deletions.
2 changes: 0 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/content/content-layer.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 0 additions & 19 deletions packages/astro/src/core/logger/core.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f5b28e

Please sign in to comment.