Skip to content

Commit

Permalink
Merge pull request #4 from plumelo/feat/update-deps
Browse files Browse the repository at this point in the history
Update p-queue import
  • Loading branch information
megheaiulian authored Dec 22, 2023
2 parents c50de33 + 29e3577 commit 3b810ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .husky/commit-msg
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm exec -- commitlint --edit "$1"
npm run commitlint --edit "$1"
4 changes: 2 additions & 2 deletions .husky/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm t -- --no-cache
pnpm exec -- lint-staged
npm test -- --no-cache
npm run lint-staged
11 changes: 8 additions & 3 deletions src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line import/no-unresolved
import PQueue from "p-queue";
import type PQueue from "p-queue";
import { Loader, LoaderContext, Payload } from "./types";
import postcssLoader from "./postcss";
import sourcemapLoader from "./sourcemap";
Expand All @@ -19,7 +18,6 @@ function matchFile(file: string, condition: Loader["test"]): boolean {
const threadPoolSize = process.env.UV_THREADPOOL_SIZE
? Number.parseInt(process.env.UV_THREADPOOL_SIZE)
: 4; // default `libuv` threadpool size
const workQueue = new PQueue({ concurrency: threadPoolSize - 1 });

/** Options for {@link Loaders} class */
interface LoadersOptions {
Expand All @@ -35,6 +33,7 @@ export default class Loaders {
private readonly use: Map<string, Record<string, unknown>>;
private readonly test: (file: string) => boolean;
private readonly loaders = new Map<string, Loader>();
private workQueue: PQueue;

constructor(options: LoadersOptions) {
this.use = new Map(options.use.reverse());
Expand All @@ -59,6 +58,12 @@ export default class Loaders {
}

async process(payload: Payload, context: LoaderContext): Promise<Payload> {
if (!this.workQueue) {
// eslint-disable-next-line import/no-unresolved
const { default: pQueue } = await import("p-queue");
this.workQueue = new pQueue({ concurrency: threadPoolSize - 1 });
}
const workQueue = this.workQueue;
for await (const [name, options] of this.use) {
const loader = this.loaders.get(name);
if (!loader) continue;
Expand Down

0 comments on commit 3b810ad

Please sign in to comment.