Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 9c34f48

Browse files
pilartomasTomas2D
andauthored
fix(commonjs): import p-queue dynamically (#97)
Signed-off-by: Tomas Pilar <tomas.pilar@ibm.com> Co-authored-by: Tomas Dvorak <toomas2d@gmail.com>
1 parent d44ec5e commit 9c34f48

5 files changed

Lines changed: 268 additions & 111 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"pinst": "^3.0.0",
8888
"prettier": "^3.0.3",
8989
"ts-node": "^10.9.1",
90-
"tsup": "^7.2.0",
90+
"tsup": "^8.0.2",
9191
"typescript": "^5.3.3",
9292
"vitest": "^0.34.6"
9393
},

src/utils/concurrency.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PQueue, { QueueAddOptions } from 'p-queue';
1+
import type { default as PQueueType, QueueAddOptions } from 'p-queue';
22

33
import { HttpError } from '../errors.js';
44

@@ -11,8 +11,13 @@ function isConcurrencyLimitError(err: unknown): err is HttpError {
1111
);
1212
}
1313

14+
const PQueue = (async () => {
15+
const lib = await import('p-queue');
16+
return lib.default;
17+
})();
18+
1419
export class ConcurrencyLimiter {
15-
private _queue?: PQueue;
20+
private _queue?: PQueueType;
1621
private _limiterPromise?: ReturnType<Limiter>;
1722

1823
constructor(private readonly limiter: Limiter) {}
@@ -42,6 +47,6 @@ export class ConcurrencyLimiter {
4247

4348
this._limiterPromise = this.limiter();
4449
const { limit } = await this._limiterPromise;
45-
this._queue = new PQueue({ concurrency: limit });
50+
this._queue = new (await PQueue)({ concurrency: limit });
4651
}
4752
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
"ts-node": {
3030
"esm": true
3131
}
32-
}
32+
}

tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default defineConfig({
1616
format: ['esm', 'cjs'],
1717
platform: 'node',
1818
shims: true,
19+
splitting: true,
1920
env: {
2021
NODE_ENV: 'production',
2122
GENAI_DEFAULT_ENDPOINT: GENAI_DEFAULT_ENDPOINT,

0 commit comments

Comments
 (0)