vite-react-ssg 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node.cjs +227 -238
- package/dist/node.mjs +228 -239
- package/package.json +10 -10
package/dist/node.cjs
CHANGED
|
@@ -434,50 +434,47 @@ class TimeoutError extends Error {
|
|
|
434
434
|
An error to be thrown when the request is aborted by AbortController.
|
|
435
435
|
DOMException is thrown instead of this Error when DOMException is available.
|
|
436
436
|
*/
|
|
437
|
-
|
|
437
|
+
class AbortError extends Error {
|
|
438
438
|
constructor(message) {
|
|
439
439
|
super();
|
|
440
440
|
this.name = 'AbortError';
|
|
441
441
|
this.message = message;
|
|
442
442
|
}
|
|
443
|
-
}
|
|
443
|
+
}
|
|
444
444
|
|
|
445
445
|
/**
|
|
446
446
|
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
|
447
447
|
*/
|
|
448
|
-
const getDOMException = errorMessage => globalThis.DOMException === undefined
|
|
449
|
-
new AbortError
|
|
450
|
-
new DOMException(errorMessage);
|
|
448
|
+
const getDOMException = errorMessage => globalThis.DOMException === undefined
|
|
449
|
+
? new AbortError(errorMessage)
|
|
450
|
+
: new DOMException(errorMessage);
|
|
451
451
|
|
|
452
452
|
/**
|
|
453
453
|
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
|
|
454
454
|
*/
|
|
455
455
|
const getAbortedReason = signal => {
|
|
456
|
-
const reason = signal.reason === undefined
|
|
457
|
-
getDOMException('This operation was aborted.')
|
|
458
|
-
signal.reason;
|
|
456
|
+
const reason = signal.reason === undefined
|
|
457
|
+
? getDOMException('This operation was aborted.')
|
|
458
|
+
: signal.reason;
|
|
459
459
|
|
|
460
460
|
return reason instanceof Error ? reason : getDOMException(reason);
|
|
461
461
|
};
|
|
462
462
|
|
|
463
|
-
function pTimeout(promise,
|
|
463
|
+
function pTimeout(promise, options) {
|
|
464
|
+
const {
|
|
465
|
+
milliseconds,
|
|
466
|
+
fallback,
|
|
467
|
+
message,
|
|
468
|
+
customTimers = {setTimeout, clearTimeout},
|
|
469
|
+
} = options;
|
|
470
|
+
|
|
464
471
|
let timer;
|
|
465
472
|
|
|
466
|
-
const
|
|
473
|
+
const wrappedPromise = new Promise((resolve, reject) => {
|
|
467
474
|
if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
|
|
468
475
|
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
469
476
|
}
|
|
470
477
|
|
|
471
|
-
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
472
|
-
resolve(promise);
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
options = {
|
|
477
|
-
customTimers: {setTimeout, clearTimeout},
|
|
478
|
-
...options
|
|
479
|
-
};
|
|
480
|
-
|
|
481
478
|
if (options.signal) {
|
|
482
479
|
const {signal} = options;
|
|
483
480
|
if (signal.aborted) {
|
|
@@ -489,8 +486,16 @@ function pTimeout(promise, milliseconds, fallback, options) {
|
|
|
489
486
|
});
|
|
490
487
|
}
|
|
491
488
|
|
|
492
|
-
|
|
493
|
-
|
|
489
|
+
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
490
|
+
promise.then(resolve, reject);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// We create the error outside of `setTimeout` to preserve the stack trace.
|
|
495
|
+
const timeoutError = new TimeoutError();
|
|
496
|
+
|
|
497
|
+
timer = customTimers.setTimeout.call(undefined, () => {
|
|
498
|
+
if (fallback) {
|
|
494
499
|
try {
|
|
495
500
|
resolve(fallback());
|
|
496
501
|
} catch (error) {
|
|
@@ -500,14 +505,18 @@ function pTimeout(promise, milliseconds, fallback, options) {
|
|
|
500
505
|
return;
|
|
501
506
|
}
|
|
502
507
|
|
|
503
|
-
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
|
504
|
-
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
|
505
|
-
|
|
506
508
|
if (typeof promise.cancel === 'function') {
|
|
507
509
|
promise.cancel();
|
|
508
510
|
}
|
|
509
511
|
|
|
510
|
-
|
|
512
|
+
if (message === false) {
|
|
513
|
+
resolve();
|
|
514
|
+
} else if (message instanceof Error) {
|
|
515
|
+
reject(message);
|
|
516
|
+
} else {
|
|
517
|
+
timeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;
|
|
518
|
+
reject(timeoutError);
|
|
519
|
+
}
|
|
511
520
|
}, milliseconds);
|
|
512
521
|
|
|
513
522
|
(async () => {
|
|
@@ -515,14 +524,16 @@ function pTimeout(promise, milliseconds, fallback, options) {
|
|
|
515
524
|
resolve(await promise);
|
|
516
525
|
} catch (error) {
|
|
517
526
|
reject(error);
|
|
518
|
-
} finally {
|
|
519
|
-
options.customTimers.clearTimeout.call(undefined, timer);
|
|
520
527
|
}
|
|
521
528
|
})();
|
|
522
529
|
});
|
|
523
530
|
|
|
531
|
+
const cancelablePromise = wrappedPromise.finally(() => {
|
|
532
|
+
cancelablePromise.clear();
|
|
533
|
+
});
|
|
534
|
+
|
|
524
535
|
cancelablePromise.clear = () => {
|
|
525
|
-
clearTimeout(timer);
|
|
536
|
+
customTimers.clearTimeout.call(undefined, timer);
|
|
526
537
|
timer = undefined;
|
|
527
538
|
};
|
|
528
539
|
|
|
@@ -548,16 +559,8 @@ function lowerBound(array, value, comparator) {
|
|
|
548
559
|
return first;
|
|
549
560
|
}
|
|
550
561
|
|
|
551
|
-
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
552
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
553
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
554
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
555
|
-
};
|
|
556
|
-
var _PriorityQueue_queue;
|
|
557
562
|
class PriorityQueue {
|
|
558
|
-
|
|
559
|
-
_PriorityQueue_queue.set(this, []);
|
|
560
|
-
}
|
|
563
|
+
#queue = [];
|
|
561
564
|
enqueue(run, options) {
|
|
562
565
|
options = {
|
|
563
566
|
priority: 0,
|
|
@@ -567,78 +570,53 @@ class PriorityQueue {
|
|
|
567
570
|
priority: options.priority,
|
|
568
571
|
run,
|
|
569
572
|
};
|
|
570
|
-
if (this.size &&
|
|
571
|
-
|
|
573
|
+
if (this.size && this.#queue[this.size - 1].priority >= options.priority) {
|
|
574
|
+
this.#queue.push(element);
|
|
572
575
|
return;
|
|
573
576
|
}
|
|
574
|
-
const index = lowerBound(
|
|
575
|
-
|
|
577
|
+
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
|
|
578
|
+
this.#queue.splice(index, 0, element);
|
|
576
579
|
}
|
|
577
580
|
dequeue() {
|
|
578
|
-
const item =
|
|
579
|
-
return item
|
|
581
|
+
const item = this.#queue.shift();
|
|
582
|
+
return item?.run;
|
|
580
583
|
}
|
|
581
584
|
filter(options) {
|
|
582
|
-
return
|
|
585
|
+
return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
583
586
|
}
|
|
584
587
|
get size() {
|
|
585
|
-
return
|
|
588
|
+
return this.#queue.length;
|
|
586
589
|
}
|
|
587
590
|
}
|
|
588
|
-
_PriorityQueue_queue = new WeakMap();
|
|
589
591
|
|
|
590
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
591
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
592
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
593
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
594
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
595
|
-
};
|
|
596
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
597
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
598
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
599
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
600
|
-
};
|
|
601
|
-
var _PQueue_instances, _PQueue_carryoverConcurrencyCount, _PQueue_isIntervalIgnored, _PQueue_intervalCount, _PQueue_intervalCap, _PQueue_interval, _PQueue_intervalEnd, _PQueue_intervalId, _PQueue_timeoutId, _PQueue_queue, _PQueue_queueClass, _PQueue_pending, _PQueue_concurrency, _PQueue_isPaused, _PQueue_throwOnTimeout, _PQueue_doesIntervalAllowAnother_get, _PQueue_doesConcurrentAllowAnother_get, _PQueue_next, _PQueue_onResumeInterval, _PQueue_isIntervalPaused_get, _PQueue_tryToStartAnother, _PQueue_initializeIntervalIfNeeded, _PQueue_onInterval, _PQueue_processQueue, _PQueue_throwOnAbort, _PQueue_onEvent;
|
|
602
|
-
/**
|
|
603
|
-
The error thrown by `queue.add()` when a job is aborted before it is run. See `signal`.
|
|
604
|
-
*/
|
|
605
|
-
class AbortError extends Error {
|
|
606
|
-
}
|
|
607
592
|
/**
|
|
608
593
|
Promise queue with concurrency control.
|
|
609
594
|
*/
|
|
610
595
|
class PQueue extends EventEmitter {
|
|
596
|
+
#carryoverConcurrencyCount;
|
|
597
|
+
#isIntervalIgnored;
|
|
598
|
+
#intervalCount = 0;
|
|
599
|
+
#intervalCap;
|
|
600
|
+
#interval;
|
|
601
|
+
#intervalEnd = 0;
|
|
602
|
+
#intervalId;
|
|
603
|
+
#timeoutId;
|
|
604
|
+
#queue;
|
|
605
|
+
#queueClass;
|
|
606
|
+
#pending = 0;
|
|
607
|
+
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
608
|
+
#concurrency;
|
|
609
|
+
#isPaused;
|
|
610
|
+
#throwOnTimeout;
|
|
611
|
+
/**
|
|
612
|
+
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
613
|
+
|
|
614
|
+
Applies to each future operation.
|
|
615
|
+
*/
|
|
616
|
+
timeout;
|
|
611
617
|
// TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
|
|
612
618
|
constructor(options) {
|
|
613
|
-
var _a, _b, _c, _d;
|
|
614
619
|
super();
|
|
615
|
-
_PQueue_instances.add(this);
|
|
616
|
-
_PQueue_carryoverConcurrencyCount.set(this, void 0);
|
|
617
|
-
_PQueue_isIntervalIgnored.set(this, void 0);
|
|
618
|
-
_PQueue_intervalCount.set(this, 0);
|
|
619
|
-
_PQueue_intervalCap.set(this, void 0);
|
|
620
|
-
_PQueue_interval.set(this, void 0);
|
|
621
|
-
_PQueue_intervalEnd.set(this, 0);
|
|
622
|
-
_PQueue_intervalId.set(this, void 0);
|
|
623
|
-
_PQueue_timeoutId.set(this, void 0);
|
|
624
|
-
_PQueue_queue.set(this, void 0);
|
|
625
|
-
_PQueue_queueClass.set(this, void 0);
|
|
626
|
-
_PQueue_pending.set(this, 0);
|
|
627
|
-
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
628
|
-
_PQueue_concurrency.set(this, void 0);
|
|
629
|
-
_PQueue_isPaused.set(this, void 0);
|
|
630
|
-
_PQueue_throwOnTimeout.set(this, void 0);
|
|
631
|
-
/**
|
|
632
|
-
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
633
|
-
|
|
634
|
-
Applies to each future operation.
|
|
635
|
-
*/
|
|
636
|
-
Object.defineProperty(this, "timeout", {
|
|
637
|
-
enumerable: true,
|
|
638
|
-
configurable: true,
|
|
639
|
-
writable: true,
|
|
640
|
-
value: void 0
|
|
641
|
-
});
|
|
642
620
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
643
621
|
options = {
|
|
644
622
|
carryoverConcurrencyCount: false,
|
|
@@ -650,56 +628,149 @@ class PQueue extends EventEmitter {
|
|
|
650
628
|
...options,
|
|
651
629
|
};
|
|
652
630
|
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) {
|
|
653
|
-
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${
|
|
631
|
+
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ''}\` (${typeof options.intervalCap})`);
|
|
654
632
|
}
|
|
655
633
|
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
656
|
-
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${
|
|
634
|
+
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ''}\` (${typeof options.interval})`);
|
|
657
635
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
636
|
+
this.#carryoverConcurrencyCount = options.carryoverConcurrencyCount;
|
|
637
|
+
this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
|
|
638
|
+
this.#intervalCap = options.intervalCap;
|
|
639
|
+
this.#interval = options.interval;
|
|
640
|
+
this.#queue = new options.queueClass();
|
|
641
|
+
this.#queueClass = options.queueClass;
|
|
664
642
|
this.concurrency = options.concurrency;
|
|
665
643
|
this.timeout = options.timeout;
|
|
666
|
-
|
|
667
|
-
|
|
644
|
+
this.#throwOnTimeout = options.throwOnTimeout === true;
|
|
645
|
+
this.#isPaused = options.autoStart === false;
|
|
646
|
+
}
|
|
647
|
+
get #doesIntervalAllowAnother() {
|
|
648
|
+
return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
|
|
649
|
+
}
|
|
650
|
+
get #doesConcurrentAllowAnother() {
|
|
651
|
+
return this.#pending < this.#concurrency;
|
|
652
|
+
}
|
|
653
|
+
#next() {
|
|
654
|
+
this.#pending--;
|
|
655
|
+
this.#tryToStartAnother();
|
|
656
|
+
this.emit('next');
|
|
657
|
+
}
|
|
658
|
+
#onResumeInterval() {
|
|
659
|
+
this.#onInterval();
|
|
660
|
+
this.#initializeIntervalIfNeeded();
|
|
661
|
+
this.#timeoutId = undefined;
|
|
662
|
+
}
|
|
663
|
+
get #isIntervalPaused() {
|
|
664
|
+
const now = Date.now();
|
|
665
|
+
if (this.#intervalId === undefined) {
|
|
666
|
+
const delay = this.#intervalEnd - now;
|
|
667
|
+
if (delay < 0) {
|
|
668
|
+
// Act as the interval was done
|
|
669
|
+
// We don't need to resume it here because it will be resumed on line 160
|
|
670
|
+
this.#intervalCount = (this.#carryoverConcurrencyCount) ? this.#pending : 0;
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
// Act as the interval is pending
|
|
674
|
+
if (this.#timeoutId === undefined) {
|
|
675
|
+
this.#timeoutId = setTimeout(() => {
|
|
676
|
+
this.#onResumeInterval();
|
|
677
|
+
}, delay);
|
|
678
|
+
}
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
#tryToStartAnother() {
|
|
685
|
+
if (this.#queue.size === 0) {
|
|
686
|
+
// We can clear the interval ("pause")
|
|
687
|
+
// Because we can redo it later ("resume")
|
|
688
|
+
if (this.#intervalId) {
|
|
689
|
+
clearInterval(this.#intervalId);
|
|
690
|
+
}
|
|
691
|
+
this.#intervalId = undefined;
|
|
692
|
+
this.emit('empty');
|
|
693
|
+
if (this.#pending === 0) {
|
|
694
|
+
this.emit('idle');
|
|
695
|
+
}
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
if (!this.#isPaused) {
|
|
699
|
+
const canInitializeInterval = !this.#isIntervalPaused;
|
|
700
|
+
if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
|
|
701
|
+
const job = this.#queue.dequeue();
|
|
702
|
+
if (!job) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
this.emit('active');
|
|
706
|
+
job();
|
|
707
|
+
if (canInitializeInterval) {
|
|
708
|
+
this.#initializeIntervalIfNeeded();
|
|
709
|
+
}
|
|
710
|
+
return true;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return false;
|
|
714
|
+
}
|
|
715
|
+
#initializeIntervalIfNeeded() {
|
|
716
|
+
if (this.#isIntervalIgnored || this.#intervalId !== undefined) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
this.#intervalId = setInterval(() => {
|
|
720
|
+
this.#onInterval();
|
|
721
|
+
}, this.#interval);
|
|
722
|
+
this.#intervalEnd = Date.now() + this.#interval;
|
|
723
|
+
}
|
|
724
|
+
#onInterval() {
|
|
725
|
+
if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
|
|
726
|
+
clearInterval(this.#intervalId);
|
|
727
|
+
this.#intervalId = undefined;
|
|
728
|
+
}
|
|
729
|
+
this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
|
|
730
|
+
this.#processQueue();
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
Executes all queued functions until it reaches the limit.
|
|
734
|
+
*/
|
|
735
|
+
#processQueue() {
|
|
736
|
+
// eslint-disable-next-line no-empty
|
|
737
|
+
while (this.#tryToStartAnother()) { }
|
|
668
738
|
}
|
|
669
739
|
get concurrency() {
|
|
670
|
-
return
|
|
740
|
+
return this.#concurrency;
|
|
671
741
|
}
|
|
672
742
|
set concurrency(newConcurrency) {
|
|
673
743
|
if (!(typeof newConcurrency === 'number' && newConcurrency >= 1)) {
|
|
674
744
|
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
675
745
|
}
|
|
676
|
-
|
|
677
|
-
|
|
746
|
+
this.#concurrency = newConcurrency;
|
|
747
|
+
this.#processQueue();
|
|
748
|
+
}
|
|
749
|
+
async #throwOnAbort(signal) {
|
|
750
|
+
return new Promise((_resolve, reject) => {
|
|
751
|
+
signal.addEventListener('abort', () => {
|
|
752
|
+
reject(signal.reason);
|
|
753
|
+
}, { once: true });
|
|
754
|
+
});
|
|
678
755
|
}
|
|
679
756
|
async add(function_, options = {}) {
|
|
680
757
|
options = {
|
|
681
758
|
timeout: this.timeout,
|
|
682
|
-
throwOnTimeout:
|
|
759
|
+
throwOnTimeout: this.#throwOnTimeout,
|
|
683
760
|
...options,
|
|
684
761
|
};
|
|
685
762
|
return new Promise((resolve, reject) => {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
__classPrivateFieldSet(this, _PQueue_pending, (_b = __classPrivateFieldGet(this, _PQueue_pending, "f"), _b++, _b), "f");
|
|
690
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (_c = __classPrivateFieldGet(this, _PQueue_intervalCount, "f"), _c++, _c), "f");
|
|
763
|
+
this.#queue.enqueue(async () => {
|
|
764
|
+
this.#pending++;
|
|
765
|
+
this.#intervalCount++;
|
|
691
766
|
try {
|
|
692
|
-
|
|
693
|
-
if ((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
694
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
695
|
-
throw new AbortError('The task was aborted.');
|
|
696
|
-
}
|
|
767
|
+
options.signal?.throwIfAborted();
|
|
697
768
|
let operation = function_({ signal: options.signal });
|
|
698
769
|
if (options.timeout) {
|
|
699
|
-
operation = pTimeout(Promise.resolve(operation), options.timeout);
|
|
770
|
+
operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
|
|
700
771
|
}
|
|
701
772
|
if (options.signal) {
|
|
702
|
-
operation = Promise.race([operation,
|
|
773
|
+
operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
|
|
703
774
|
}
|
|
704
775
|
const result = await operation;
|
|
705
776
|
resolve(result);
|
|
@@ -714,11 +785,11 @@ class PQueue extends EventEmitter {
|
|
|
714
785
|
this.emit('error', error);
|
|
715
786
|
}
|
|
716
787
|
finally {
|
|
717
|
-
|
|
788
|
+
this.#next();
|
|
718
789
|
}
|
|
719
790
|
}, options);
|
|
720
791
|
this.emit('add');
|
|
721
|
-
|
|
792
|
+
this.#tryToStartAnother();
|
|
722
793
|
});
|
|
723
794
|
}
|
|
724
795
|
async addAll(functions, options) {
|
|
@@ -728,24 +799,24 @@ class PQueue extends EventEmitter {
|
|
|
728
799
|
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
729
800
|
*/
|
|
730
801
|
start() {
|
|
731
|
-
if (!
|
|
802
|
+
if (!this.#isPaused) {
|
|
732
803
|
return this;
|
|
733
804
|
}
|
|
734
|
-
|
|
735
|
-
|
|
805
|
+
this.#isPaused = false;
|
|
806
|
+
this.#processQueue();
|
|
736
807
|
return this;
|
|
737
808
|
}
|
|
738
809
|
/**
|
|
739
810
|
Put queue execution on hold.
|
|
740
811
|
*/
|
|
741
812
|
pause() {
|
|
742
|
-
|
|
813
|
+
this.#isPaused = true;
|
|
743
814
|
}
|
|
744
815
|
/**
|
|
745
816
|
Clear the queue.
|
|
746
817
|
*/
|
|
747
818
|
clear() {
|
|
748
|
-
|
|
819
|
+
this.#queue = new this.#queueClass();
|
|
749
820
|
}
|
|
750
821
|
/**
|
|
751
822
|
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
@@ -754,10 +825,10 @@ class PQueue extends EventEmitter {
|
|
|
754
825
|
*/
|
|
755
826
|
async onEmpty() {
|
|
756
827
|
// Instantly resolve if the queue is empty
|
|
757
|
-
if (
|
|
828
|
+
if (this.#queue.size === 0) {
|
|
758
829
|
return;
|
|
759
830
|
}
|
|
760
|
-
await
|
|
831
|
+
await this.#onEvent('empty');
|
|
761
832
|
}
|
|
762
833
|
/**
|
|
763
834
|
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
@@ -768,10 +839,10 @@ class PQueue extends EventEmitter {
|
|
|
768
839
|
*/
|
|
769
840
|
async onSizeLessThan(limit) {
|
|
770
841
|
// Instantly resolve if the queue is empty.
|
|
771
|
-
if (
|
|
842
|
+
if (this.#queue.size < limit) {
|
|
772
843
|
return;
|
|
773
844
|
}
|
|
774
|
-
await
|
|
845
|
+
await this.#onEvent('next', () => this.#queue.size < limit);
|
|
775
846
|
}
|
|
776
847
|
/**
|
|
777
848
|
The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
|
|
@@ -780,16 +851,28 @@ class PQueue extends EventEmitter {
|
|
|
780
851
|
*/
|
|
781
852
|
async onIdle() {
|
|
782
853
|
// Instantly resolve if none pending and if nothing else is queued
|
|
783
|
-
if (
|
|
854
|
+
if (this.#pending === 0 && this.#queue.size === 0) {
|
|
784
855
|
return;
|
|
785
856
|
}
|
|
786
|
-
await
|
|
857
|
+
await this.#onEvent('idle');
|
|
858
|
+
}
|
|
859
|
+
async #onEvent(event, filter) {
|
|
860
|
+
return new Promise(resolve => {
|
|
861
|
+
const listener = () => {
|
|
862
|
+
if (filter && !filter()) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
this.off(event, listener);
|
|
866
|
+
resolve();
|
|
867
|
+
};
|
|
868
|
+
this.on(event, listener);
|
|
869
|
+
});
|
|
787
870
|
}
|
|
788
871
|
/**
|
|
789
872
|
Size of the queue, the number of queued items waiting to run.
|
|
790
873
|
*/
|
|
791
874
|
get size() {
|
|
792
|
-
return
|
|
875
|
+
return this.#queue.size;
|
|
793
876
|
}
|
|
794
877
|
/**
|
|
795
878
|
Size of the queue, filtered by the given options.
|
|
@@ -798,122 +881,21 @@ class PQueue extends EventEmitter {
|
|
|
798
881
|
*/
|
|
799
882
|
sizeBy(options) {
|
|
800
883
|
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
801
|
-
return
|
|
884
|
+
return this.#queue.filter(options).length;
|
|
802
885
|
}
|
|
803
886
|
/**
|
|
804
887
|
Number of running items (no longer in the queue).
|
|
805
888
|
*/
|
|
806
889
|
get pending() {
|
|
807
|
-
return
|
|
890
|
+
return this.#pending;
|
|
808
891
|
}
|
|
809
892
|
/**
|
|
810
893
|
Whether the queue is currently paused.
|
|
811
894
|
*/
|
|
812
895
|
get isPaused() {
|
|
813
|
-
return
|
|
896
|
+
return this.#isPaused;
|
|
814
897
|
}
|
|
815
898
|
}
|
|
816
|
-
_PQueue_carryoverConcurrencyCount = new WeakMap(), _PQueue_isIntervalIgnored = new WeakMap(), _PQueue_intervalCount = new WeakMap(), _PQueue_intervalCap = new WeakMap(), _PQueue_interval = new WeakMap(), _PQueue_intervalEnd = new WeakMap(), _PQueue_intervalId = new WeakMap(), _PQueue_timeoutId = new WeakMap(), _PQueue_queue = new WeakMap(), _PQueue_queueClass = new WeakMap(), _PQueue_pending = new WeakMap(), _PQueue_concurrency = new WeakMap(), _PQueue_isPaused = new WeakMap(), _PQueue_throwOnTimeout = new WeakMap(), _PQueue_instances = new WeakSet(), _PQueue_doesIntervalAllowAnother_get = function _PQueue_doesIntervalAllowAnother_get() {
|
|
817
|
-
return __classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalCount, "f") < __classPrivateFieldGet(this, _PQueue_intervalCap, "f");
|
|
818
|
-
}, _PQueue_doesConcurrentAllowAnother_get = function _PQueue_doesConcurrentAllowAnother_get() {
|
|
819
|
-
return __classPrivateFieldGet(this, _PQueue_pending, "f") < __classPrivateFieldGet(this, _PQueue_concurrency, "f");
|
|
820
|
-
}, _PQueue_next = function _PQueue_next() {
|
|
821
|
-
var _a;
|
|
822
|
-
__classPrivateFieldSet(this, _PQueue_pending, (_a = __classPrivateFieldGet(this, _PQueue_pending, "f"), _a--, _a), "f");
|
|
823
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this);
|
|
824
|
-
this.emit('next');
|
|
825
|
-
}, _PQueue_onResumeInterval = function _PQueue_onResumeInterval() {
|
|
826
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
827
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
828
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, undefined, "f");
|
|
829
|
-
}, _PQueue_isIntervalPaused_get = function _PQueue_isIntervalPaused_get() {
|
|
830
|
-
const now = Date.now();
|
|
831
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f") === undefined) {
|
|
832
|
-
const delay = __classPrivateFieldGet(this, _PQueue_intervalEnd, "f") - now;
|
|
833
|
-
if (delay < 0) {
|
|
834
|
-
// Act as the interval was done
|
|
835
|
-
// We don't need to resume it here because it will be resumed on line 160
|
|
836
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (__classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f")) ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
837
|
-
}
|
|
838
|
-
else {
|
|
839
|
-
// Act as the interval is pending
|
|
840
|
-
if (__classPrivateFieldGet(this, _PQueue_timeoutId, "f") === undefined) {
|
|
841
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, setTimeout(() => {
|
|
842
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onResumeInterval).call(this);
|
|
843
|
-
}, delay), "f");
|
|
844
|
-
}
|
|
845
|
-
return true;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
return false;
|
|
849
|
-
}, _PQueue_tryToStartAnother = function _PQueue_tryToStartAnother() {
|
|
850
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
851
|
-
// We can clear the interval ("pause")
|
|
852
|
-
// Because we can redo it later ("resume")
|
|
853
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
854
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
855
|
-
}
|
|
856
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
857
|
-
this.emit('empty');
|
|
858
|
-
if (__classPrivateFieldGet(this, _PQueue_pending, "f") === 0) {
|
|
859
|
-
this.emit('idle');
|
|
860
|
-
}
|
|
861
|
-
return false;
|
|
862
|
-
}
|
|
863
|
-
if (!__classPrivateFieldGet(this, _PQueue_isPaused, "f")) {
|
|
864
|
-
const canInitializeInterval = !__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_isIntervalPaused_get);
|
|
865
|
-
if (__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesIntervalAllowAnother_get) && __classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesConcurrentAllowAnother_get)) {
|
|
866
|
-
const job = __classPrivateFieldGet(this, _PQueue_queue, "f").dequeue();
|
|
867
|
-
if (!job) {
|
|
868
|
-
return false;
|
|
869
|
-
}
|
|
870
|
-
this.emit('active');
|
|
871
|
-
job();
|
|
872
|
-
if (canInitializeInterval) {
|
|
873
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
874
|
-
}
|
|
875
|
-
return true;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
return false;
|
|
879
|
-
}, _PQueue_initializeIntervalIfNeeded = function _PQueue_initializeIntervalIfNeeded() {
|
|
880
|
-
if (__classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalId, "f") !== undefined) {
|
|
881
|
-
return;
|
|
882
|
-
}
|
|
883
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, setInterval(() => {
|
|
884
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
885
|
-
}, __classPrivateFieldGet(this, _PQueue_interval, "f")), "f");
|
|
886
|
-
__classPrivateFieldSet(this, _PQueue_intervalEnd, Date.now() + __classPrivateFieldGet(this, _PQueue_interval, "f"), "f");
|
|
887
|
-
}, _PQueue_onInterval = function _PQueue_onInterval() {
|
|
888
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalCount, "f") === 0 && __classPrivateFieldGet(this, _PQueue_pending, "f") === 0 && __classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
889
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
890
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
891
|
-
}
|
|
892
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, __classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f") ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
893
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
894
|
-
}, _PQueue_processQueue = function _PQueue_processQueue() {
|
|
895
|
-
// eslint-disable-next-line no-empty
|
|
896
|
-
while (__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this)) { }
|
|
897
|
-
}, _PQueue_throwOnAbort = async function _PQueue_throwOnAbort(signal) {
|
|
898
|
-
return new Promise((_resolve, reject) => {
|
|
899
|
-
signal.addEventListener('abort', () => {
|
|
900
|
-
// TODO: Reject with signal.throwIfAborted() when targeting Node.js 18
|
|
901
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
902
|
-
reject(new AbortError('The task was aborted.'));
|
|
903
|
-
}, { once: true });
|
|
904
|
-
});
|
|
905
|
-
}, _PQueue_onEvent = async function _PQueue_onEvent(event, filter) {
|
|
906
|
-
return new Promise(resolve => {
|
|
907
|
-
const listener = () => {
|
|
908
|
-
if (filter && !filter()) {
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
|
-
this.off(event, listener);
|
|
912
|
-
resolve();
|
|
913
|
-
};
|
|
914
|
-
this.on(event, listener);
|
|
915
|
-
});
|
|
916
|
-
};
|
|
917
899
|
|
|
918
900
|
function buildLog(text, count) {
|
|
919
901
|
console.log(`
|
|
@@ -1263,6 +1245,12 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1263
1245
|
rollupOptions: {
|
|
1264
1246
|
input: {
|
|
1265
1247
|
app: node_path.join(root, "./index.html")
|
|
1248
|
+
},
|
|
1249
|
+
// @ts-expect-error rollup type
|
|
1250
|
+
onLog(level, log, handler) {
|
|
1251
|
+
if (log.message.includes("react-helmet-async"))
|
|
1252
|
+
return;
|
|
1253
|
+
handler(level, log);
|
|
1266
1254
|
}
|
|
1267
1255
|
}
|
|
1268
1256
|
},
|
|
@@ -1310,8 +1298,9 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1310
1298
|
const critters = crittersOptions !== false ? await getCritters(outDir, crittersOptions) : void 0;
|
|
1311
1299
|
if (critters)
|
|
1312
1300
|
console.log(`${kolorist.gray("[vite-react-ssg]")} ${kolorist.blue("Critical CSS generation enabled via `critters`")}`);
|
|
1313
|
-
const
|
|
1314
|
-
const
|
|
1301
|
+
const dotVitedir = Number.parseInt(vite.version) >= 5 ? [".vite"] : [];
|
|
1302
|
+
const ssrManifest = JSON.parse(await fs__default.readFile(node_path.join(out, ...dotVitedir, "ssr-manifest.json"), "utf-8"));
|
|
1303
|
+
const manifest = JSON.parse(await fs__default.readFile(node_path.join(out, ...dotVitedir, "manifest.json"), "utf-8"));
|
|
1315
1304
|
let indexHTML = await fs__default.readFile(node_path.join(out, "index.html"), "utf-8");
|
|
1316
1305
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
1317
1306
|
const queue = new PQueue({ concurrency });
|