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.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { join, isAbsolute as isAbsolute$1, parse as parse$1, dirname } from 'nod
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { gray, yellow, blue, dim, cyan, red, green, bold, reset, bgLightCyan } from 'kolorist';
|
|
4
4
|
import fs$7 from 'fs-extra';
|
|
5
|
-
import { resolveConfig, build as build$1, mergeConfig,
|
|
5
|
+
import { resolveConfig, build as build$1, mergeConfig, version as version$3, createServer } from 'vite';
|
|
6
6
|
import { JSDOM } from 'jsdom';
|
|
7
7
|
import { S as SiteMetadataDefaults, s as serializeState } from './shared/vite-react-ssg.9d005d5e.mjs';
|
|
8
8
|
import { readFileSync } from 'node:fs';
|
|
@@ -412,50 +412,47 @@ class TimeoutError extends Error {
|
|
|
412
412
|
An error to be thrown when the request is aborted by AbortController.
|
|
413
413
|
DOMException is thrown instead of this Error when DOMException is available.
|
|
414
414
|
*/
|
|
415
|
-
|
|
415
|
+
class AbortError extends Error {
|
|
416
416
|
constructor(message) {
|
|
417
417
|
super();
|
|
418
418
|
this.name = 'AbortError';
|
|
419
419
|
this.message = message;
|
|
420
420
|
}
|
|
421
|
-
}
|
|
421
|
+
}
|
|
422
422
|
|
|
423
423
|
/**
|
|
424
424
|
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
|
425
425
|
*/
|
|
426
|
-
const getDOMException = errorMessage => globalThis.DOMException === undefined
|
|
427
|
-
new AbortError
|
|
428
|
-
new DOMException(errorMessage);
|
|
426
|
+
const getDOMException = errorMessage => globalThis.DOMException === undefined
|
|
427
|
+
? new AbortError(errorMessage)
|
|
428
|
+
: new DOMException(errorMessage);
|
|
429
429
|
|
|
430
430
|
/**
|
|
431
431
|
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
|
|
432
432
|
*/
|
|
433
433
|
const getAbortedReason = signal => {
|
|
434
|
-
const reason = signal.reason === undefined
|
|
435
|
-
getDOMException('This operation was aborted.')
|
|
436
|
-
signal.reason;
|
|
434
|
+
const reason = signal.reason === undefined
|
|
435
|
+
? getDOMException('This operation was aborted.')
|
|
436
|
+
: signal.reason;
|
|
437
437
|
|
|
438
438
|
return reason instanceof Error ? reason : getDOMException(reason);
|
|
439
439
|
};
|
|
440
440
|
|
|
441
|
-
function pTimeout(promise,
|
|
441
|
+
function pTimeout(promise, options) {
|
|
442
|
+
const {
|
|
443
|
+
milliseconds,
|
|
444
|
+
fallback,
|
|
445
|
+
message,
|
|
446
|
+
customTimers = {setTimeout, clearTimeout},
|
|
447
|
+
} = options;
|
|
448
|
+
|
|
442
449
|
let timer;
|
|
443
450
|
|
|
444
|
-
const
|
|
451
|
+
const wrappedPromise = new Promise((resolve, reject) => {
|
|
445
452
|
if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
|
|
446
453
|
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
447
454
|
}
|
|
448
455
|
|
|
449
|
-
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
450
|
-
resolve(promise);
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
options = {
|
|
455
|
-
customTimers: {setTimeout, clearTimeout},
|
|
456
|
-
...options
|
|
457
|
-
};
|
|
458
|
-
|
|
459
456
|
if (options.signal) {
|
|
460
457
|
const {signal} = options;
|
|
461
458
|
if (signal.aborted) {
|
|
@@ -467,8 +464,16 @@ function pTimeout(promise, milliseconds, fallback, options) {
|
|
|
467
464
|
});
|
|
468
465
|
}
|
|
469
466
|
|
|
470
|
-
|
|
471
|
-
|
|
467
|
+
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
468
|
+
promise.then(resolve, reject);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// We create the error outside of `setTimeout` to preserve the stack trace.
|
|
473
|
+
const timeoutError = new TimeoutError();
|
|
474
|
+
|
|
475
|
+
timer = customTimers.setTimeout.call(undefined, () => {
|
|
476
|
+
if (fallback) {
|
|
472
477
|
try {
|
|
473
478
|
resolve(fallback());
|
|
474
479
|
} catch (error) {
|
|
@@ -478,14 +483,18 @@ function pTimeout(promise, milliseconds, fallback, options) {
|
|
|
478
483
|
return;
|
|
479
484
|
}
|
|
480
485
|
|
|
481
|
-
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
|
482
|
-
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
|
483
|
-
|
|
484
486
|
if (typeof promise.cancel === 'function') {
|
|
485
487
|
promise.cancel();
|
|
486
488
|
}
|
|
487
489
|
|
|
488
|
-
|
|
490
|
+
if (message === false) {
|
|
491
|
+
resolve();
|
|
492
|
+
} else if (message instanceof Error) {
|
|
493
|
+
reject(message);
|
|
494
|
+
} else {
|
|
495
|
+
timeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;
|
|
496
|
+
reject(timeoutError);
|
|
497
|
+
}
|
|
489
498
|
}, milliseconds);
|
|
490
499
|
|
|
491
500
|
(async () => {
|
|
@@ -493,14 +502,16 @@ function pTimeout(promise, milliseconds, fallback, options) {
|
|
|
493
502
|
resolve(await promise);
|
|
494
503
|
} catch (error) {
|
|
495
504
|
reject(error);
|
|
496
|
-
} finally {
|
|
497
|
-
options.customTimers.clearTimeout.call(undefined, timer);
|
|
498
505
|
}
|
|
499
506
|
})();
|
|
500
507
|
});
|
|
501
508
|
|
|
509
|
+
const cancelablePromise = wrappedPromise.finally(() => {
|
|
510
|
+
cancelablePromise.clear();
|
|
511
|
+
});
|
|
512
|
+
|
|
502
513
|
cancelablePromise.clear = () => {
|
|
503
|
-
clearTimeout(timer);
|
|
514
|
+
customTimers.clearTimeout.call(undefined, timer);
|
|
504
515
|
timer = undefined;
|
|
505
516
|
};
|
|
506
517
|
|
|
@@ -526,16 +537,8 @@ function lowerBound(array, value, comparator) {
|
|
|
526
537
|
return first;
|
|
527
538
|
}
|
|
528
539
|
|
|
529
|
-
var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
530
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
531
|
-
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");
|
|
532
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
533
|
-
};
|
|
534
|
-
var _PriorityQueue_queue;
|
|
535
540
|
class PriorityQueue {
|
|
536
|
-
|
|
537
|
-
_PriorityQueue_queue.set(this, []);
|
|
538
|
-
}
|
|
541
|
+
#queue = [];
|
|
539
542
|
enqueue(run, options) {
|
|
540
543
|
options = {
|
|
541
544
|
priority: 0,
|
|
@@ -545,78 +548,53 @@ class PriorityQueue {
|
|
|
545
548
|
priority: options.priority,
|
|
546
549
|
run,
|
|
547
550
|
};
|
|
548
|
-
if (this.size &&
|
|
549
|
-
|
|
551
|
+
if (this.size && this.#queue[this.size - 1].priority >= options.priority) {
|
|
552
|
+
this.#queue.push(element);
|
|
550
553
|
return;
|
|
551
554
|
}
|
|
552
|
-
const index = lowerBound(
|
|
553
|
-
|
|
555
|
+
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
|
|
556
|
+
this.#queue.splice(index, 0, element);
|
|
554
557
|
}
|
|
555
558
|
dequeue() {
|
|
556
|
-
const item =
|
|
557
|
-
return item
|
|
559
|
+
const item = this.#queue.shift();
|
|
560
|
+
return item?.run;
|
|
558
561
|
}
|
|
559
562
|
filter(options) {
|
|
560
|
-
return
|
|
563
|
+
return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
561
564
|
}
|
|
562
565
|
get size() {
|
|
563
|
-
return
|
|
566
|
+
return this.#queue.length;
|
|
564
567
|
}
|
|
565
568
|
}
|
|
566
|
-
_PriorityQueue_queue = new WeakMap();
|
|
567
569
|
|
|
568
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
569
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
570
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
571
|
-
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");
|
|
572
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
573
|
-
};
|
|
574
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
575
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
576
|
-
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");
|
|
577
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
578
|
-
};
|
|
579
|
-
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;
|
|
580
|
-
/**
|
|
581
|
-
The error thrown by `queue.add()` when a job is aborted before it is run. See `signal`.
|
|
582
|
-
*/
|
|
583
|
-
class AbortError extends Error {
|
|
584
|
-
}
|
|
585
570
|
/**
|
|
586
571
|
Promise queue with concurrency control.
|
|
587
572
|
*/
|
|
588
573
|
class PQueue extends EventEmitter {
|
|
574
|
+
#carryoverConcurrencyCount;
|
|
575
|
+
#isIntervalIgnored;
|
|
576
|
+
#intervalCount = 0;
|
|
577
|
+
#intervalCap;
|
|
578
|
+
#interval;
|
|
579
|
+
#intervalEnd = 0;
|
|
580
|
+
#intervalId;
|
|
581
|
+
#timeoutId;
|
|
582
|
+
#queue;
|
|
583
|
+
#queueClass;
|
|
584
|
+
#pending = 0;
|
|
585
|
+
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
586
|
+
#concurrency;
|
|
587
|
+
#isPaused;
|
|
588
|
+
#throwOnTimeout;
|
|
589
|
+
/**
|
|
590
|
+
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
591
|
+
|
|
592
|
+
Applies to each future operation.
|
|
593
|
+
*/
|
|
594
|
+
timeout;
|
|
589
595
|
// TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
|
|
590
596
|
constructor(options) {
|
|
591
|
-
var _a, _b, _c, _d;
|
|
592
597
|
super();
|
|
593
|
-
_PQueue_instances.add(this);
|
|
594
|
-
_PQueue_carryoverConcurrencyCount.set(this, void 0);
|
|
595
|
-
_PQueue_isIntervalIgnored.set(this, void 0);
|
|
596
|
-
_PQueue_intervalCount.set(this, 0);
|
|
597
|
-
_PQueue_intervalCap.set(this, void 0);
|
|
598
|
-
_PQueue_interval.set(this, void 0);
|
|
599
|
-
_PQueue_intervalEnd.set(this, 0);
|
|
600
|
-
_PQueue_intervalId.set(this, void 0);
|
|
601
|
-
_PQueue_timeoutId.set(this, void 0);
|
|
602
|
-
_PQueue_queue.set(this, void 0);
|
|
603
|
-
_PQueue_queueClass.set(this, void 0);
|
|
604
|
-
_PQueue_pending.set(this, 0);
|
|
605
|
-
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
606
|
-
_PQueue_concurrency.set(this, void 0);
|
|
607
|
-
_PQueue_isPaused.set(this, void 0);
|
|
608
|
-
_PQueue_throwOnTimeout.set(this, void 0);
|
|
609
|
-
/**
|
|
610
|
-
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
611
|
-
|
|
612
|
-
Applies to each future operation.
|
|
613
|
-
*/
|
|
614
|
-
Object.defineProperty(this, "timeout", {
|
|
615
|
-
enumerable: true,
|
|
616
|
-
configurable: true,
|
|
617
|
-
writable: true,
|
|
618
|
-
value: void 0
|
|
619
|
-
});
|
|
620
598
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
621
599
|
options = {
|
|
622
600
|
carryoverConcurrencyCount: false,
|
|
@@ -628,56 +606,149 @@ class PQueue extends EventEmitter {
|
|
|
628
606
|
...options,
|
|
629
607
|
};
|
|
630
608
|
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) {
|
|
631
|
-
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${
|
|
609
|
+
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ''}\` (${typeof options.intervalCap})`);
|
|
632
610
|
}
|
|
633
611
|
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
634
|
-
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${
|
|
612
|
+
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ''}\` (${typeof options.interval})`);
|
|
635
613
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
614
|
+
this.#carryoverConcurrencyCount = options.carryoverConcurrencyCount;
|
|
615
|
+
this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
|
|
616
|
+
this.#intervalCap = options.intervalCap;
|
|
617
|
+
this.#interval = options.interval;
|
|
618
|
+
this.#queue = new options.queueClass();
|
|
619
|
+
this.#queueClass = options.queueClass;
|
|
642
620
|
this.concurrency = options.concurrency;
|
|
643
621
|
this.timeout = options.timeout;
|
|
644
|
-
|
|
645
|
-
|
|
622
|
+
this.#throwOnTimeout = options.throwOnTimeout === true;
|
|
623
|
+
this.#isPaused = options.autoStart === false;
|
|
624
|
+
}
|
|
625
|
+
get #doesIntervalAllowAnother() {
|
|
626
|
+
return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
|
|
627
|
+
}
|
|
628
|
+
get #doesConcurrentAllowAnother() {
|
|
629
|
+
return this.#pending < this.#concurrency;
|
|
630
|
+
}
|
|
631
|
+
#next() {
|
|
632
|
+
this.#pending--;
|
|
633
|
+
this.#tryToStartAnother();
|
|
634
|
+
this.emit('next');
|
|
635
|
+
}
|
|
636
|
+
#onResumeInterval() {
|
|
637
|
+
this.#onInterval();
|
|
638
|
+
this.#initializeIntervalIfNeeded();
|
|
639
|
+
this.#timeoutId = undefined;
|
|
640
|
+
}
|
|
641
|
+
get #isIntervalPaused() {
|
|
642
|
+
const now = Date.now();
|
|
643
|
+
if (this.#intervalId === undefined) {
|
|
644
|
+
const delay = this.#intervalEnd - now;
|
|
645
|
+
if (delay < 0) {
|
|
646
|
+
// Act as the interval was done
|
|
647
|
+
// We don't need to resume it here because it will be resumed on line 160
|
|
648
|
+
this.#intervalCount = (this.#carryoverConcurrencyCount) ? this.#pending : 0;
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
// Act as the interval is pending
|
|
652
|
+
if (this.#timeoutId === undefined) {
|
|
653
|
+
this.#timeoutId = setTimeout(() => {
|
|
654
|
+
this.#onResumeInterval();
|
|
655
|
+
}, delay);
|
|
656
|
+
}
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
#tryToStartAnother() {
|
|
663
|
+
if (this.#queue.size === 0) {
|
|
664
|
+
// We can clear the interval ("pause")
|
|
665
|
+
// Because we can redo it later ("resume")
|
|
666
|
+
if (this.#intervalId) {
|
|
667
|
+
clearInterval(this.#intervalId);
|
|
668
|
+
}
|
|
669
|
+
this.#intervalId = undefined;
|
|
670
|
+
this.emit('empty');
|
|
671
|
+
if (this.#pending === 0) {
|
|
672
|
+
this.emit('idle');
|
|
673
|
+
}
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
if (!this.#isPaused) {
|
|
677
|
+
const canInitializeInterval = !this.#isIntervalPaused;
|
|
678
|
+
if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
|
|
679
|
+
const job = this.#queue.dequeue();
|
|
680
|
+
if (!job) {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
this.emit('active');
|
|
684
|
+
job();
|
|
685
|
+
if (canInitializeInterval) {
|
|
686
|
+
this.#initializeIntervalIfNeeded();
|
|
687
|
+
}
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
#initializeIntervalIfNeeded() {
|
|
694
|
+
if (this.#isIntervalIgnored || this.#intervalId !== undefined) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
this.#intervalId = setInterval(() => {
|
|
698
|
+
this.#onInterval();
|
|
699
|
+
}, this.#interval);
|
|
700
|
+
this.#intervalEnd = Date.now() + this.#interval;
|
|
701
|
+
}
|
|
702
|
+
#onInterval() {
|
|
703
|
+
if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
|
|
704
|
+
clearInterval(this.#intervalId);
|
|
705
|
+
this.#intervalId = undefined;
|
|
706
|
+
}
|
|
707
|
+
this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
|
|
708
|
+
this.#processQueue();
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
Executes all queued functions until it reaches the limit.
|
|
712
|
+
*/
|
|
713
|
+
#processQueue() {
|
|
714
|
+
// eslint-disable-next-line no-empty
|
|
715
|
+
while (this.#tryToStartAnother()) { }
|
|
646
716
|
}
|
|
647
717
|
get concurrency() {
|
|
648
|
-
return
|
|
718
|
+
return this.#concurrency;
|
|
649
719
|
}
|
|
650
720
|
set concurrency(newConcurrency) {
|
|
651
721
|
if (!(typeof newConcurrency === 'number' && newConcurrency >= 1)) {
|
|
652
722
|
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
653
723
|
}
|
|
654
|
-
|
|
655
|
-
|
|
724
|
+
this.#concurrency = newConcurrency;
|
|
725
|
+
this.#processQueue();
|
|
726
|
+
}
|
|
727
|
+
async #throwOnAbort(signal) {
|
|
728
|
+
return new Promise((_resolve, reject) => {
|
|
729
|
+
signal.addEventListener('abort', () => {
|
|
730
|
+
reject(signal.reason);
|
|
731
|
+
}, { once: true });
|
|
732
|
+
});
|
|
656
733
|
}
|
|
657
734
|
async add(function_, options = {}) {
|
|
658
735
|
options = {
|
|
659
736
|
timeout: this.timeout,
|
|
660
|
-
throwOnTimeout:
|
|
737
|
+
throwOnTimeout: this.#throwOnTimeout,
|
|
661
738
|
...options,
|
|
662
739
|
};
|
|
663
740
|
return new Promise((resolve, reject) => {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
__classPrivateFieldSet(this, _PQueue_pending, (_b = __classPrivateFieldGet(this, _PQueue_pending, "f"), _b++, _b), "f");
|
|
668
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (_c = __classPrivateFieldGet(this, _PQueue_intervalCount, "f"), _c++, _c), "f");
|
|
741
|
+
this.#queue.enqueue(async () => {
|
|
742
|
+
this.#pending++;
|
|
743
|
+
this.#intervalCount++;
|
|
669
744
|
try {
|
|
670
|
-
|
|
671
|
-
if ((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
672
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
673
|
-
throw new AbortError('The task was aborted.');
|
|
674
|
-
}
|
|
745
|
+
options.signal?.throwIfAborted();
|
|
675
746
|
let operation = function_({ signal: options.signal });
|
|
676
747
|
if (options.timeout) {
|
|
677
|
-
operation = pTimeout(Promise.resolve(operation), options.timeout);
|
|
748
|
+
operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
|
|
678
749
|
}
|
|
679
750
|
if (options.signal) {
|
|
680
|
-
operation = Promise.race([operation,
|
|
751
|
+
operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
|
|
681
752
|
}
|
|
682
753
|
const result = await operation;
|
|
683
754
|
resolve(result);
|
|
@@ -692,11 +763,11 @@ class PQueue extends EventEmitter {
|
|
|
692
763
|
this.emit('error', error);
|
|
693
764
|
}
|
|
694
765
|
finally {
|
|
695
|
-
|
|
766
|
+
this.#next();
|
|
696
767
|
}
|
|
697
768
|
}, options);
|
|
698
769
|
this.emit('add');
|
|
699
|
-
|
|
770
|
+
this.#tryToStartAnother();
|
|
700
771
|
});
|
|
701
772
|
}
|
|
702
773
|
async addAll(functions, options) {
|
|
@@ -706,24 +777,24 @@ class PQueue extends EventEmitter {
|
|
|
706
777
|
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.)
|
|
707
778
|
*/
|
|
708
779
|
start() {
|
|
709
|
-
if (!
|
|
780
|
+
if (!this.#isPaused) {
|
|
710
781
|
return this;
|
|
711
782
|
}
|
|
712
|
-
|
|
713
|
-
|
|
783
|
+
this.#isPaused = false;
|
|
784
|
+
this.#processQueue();
|
|
714
785
|
return this;
|
|
715
786
|
}
|
|
716
787
|
/**
|
|
717
788
|
Put queue execution on hold.
|
|
718
789
|
*/
|
|
719
790
|
pause() {
|
|
720
|
-
|
|
791
|
+
this.#isPaused = true;
|
|
721
792
|
}
|
|
722
793
|
/**
|
|
723
794
|
Clear the queue.
|
|
724
795
|
*/
|
|
725
796
|
clear() {
|
|
726
|
-
|
|
797
|
+
this.#queue = new this.#queueClass();
|
|
727
798
|
}
|
|
728
799
|
/**
|
|
729
800
|
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
@@ -732,10 +803,10 @@ class PQueue extends EventEmitter {
|
|
|
732
803
|
*/
|
|
733
804
|
async onEmpty() {
|
|
734
805
|
// Instantly resolve if the queue is empty
|
|
735
|
-
if (
|
|
806
|
+
if (this.#queue.size === 0) {
|
|
736
807
|
return;
|
|
737
808
|
}
|
|
738
|
-
await
|
|
809
|
+
await this.#onEvent('empty');
|
|
739
810
|
}
|
|
740
811
|
/**
|
|
741
812
|
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
@@ -746,10 +817,10 @@ class PQueue extends EventEmitter {
|
|
|
746
817
|
*/
|
|
747
818
|
async onSizeLessThan(limit) {
|
|
748
819
|
// Instantly resolve if the queue is empty.
|
|
749
|
-
if (
|
|
820
|
+
if (this.#queue.size < limit) {
|
|
750
821
|
return;
|
|
751
822
|
}
|
|
752
|
-
await
|
|
823
|
+
await this.#onEvent('next', () => this.#queue.size < limit);
|
|
753
824
|
}
|
|
754
825
|
/**
|
|
755
826
|
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.
|
|
@@ -758,16 +829,28 @@ class PQueue extends EventEmitter {
|
|
|
758
829
|
*/
|
|
759
830
|
async onIdle() {
|
|
760
831
|
// Instantly resolve if none pending and if nothing else is queued
|
|
761
|
-
if (
|
|
832
|
+
if (this.#pending === 0 && this.#queue.size === 0) {
|
|
762
833
|
return;
|
|
763
834
|
}
|
|
764
|
-
await
|
|
835
|
+
await this.#onEvent('idle');
|
|
836
|
+
}
|
|
837
|
+
async #onEvent(event, filter) {
|
|
838
|
+
return new Promise(resolve => {
|
|
839
|
+
const listener = () => {
|
|
840
|
+
if (filter && !filter()) {
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
this.off(event, listener);
|
|
844
|
+
resolve();
|
|
845
|
+
};
|
|
846
|
+
this.on(event, listener);
|
|
847
|
+
});
|
|
765
848
|
}
|
|
766
849
|
/**
|
|
767
850
|
Size of the queue, the number of queued items waiting to run.
|
|
768
851
|
*/
|
|
769
852
|
get size() {
|
|
770
|
-
return
|
|
853
|
+
return this.#queue.size;
|
|
771
854
|
}
|
|
772
855
|
/**
|
|
773
856
|
Size of the queue, filtered by the given options.
|
|
@@ -776,122 +859,21 @@ class PQueue extends EventEmitter {
|
|
|
776
859
|
*/
|
|
777
860
|
sizeBy(options) {
|
|
778
861
|
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
779
|
-
return
|
|
862
|
+
return this.#queue.filter(options).length;
|
|
780
863
|
}
|
|
781
864
|
/**
|
|
782
865
|
Number of running items (no longer in the queue).
|
|
783
866
|
*/
|
|
784
867
|
get pending() {
|
|
785
|
-
return
|
|
868
|
+
return this.#pending;
|
|
786
869
|
}
|
|
787
870
|
/**
|
|
788
871
|
Whether the queue is currently paused.
|
|
789
872
|
*/
|
|
790
873
|
get isPaused() {
|
|
791
|
-
return
|
|
874
|
+
return this.#isPaused;
|
|
792
875
|
}
|
|
793
876
|
}
|
|
794
|
-
_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() {
|
|
795
|
-
return __classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalCount, "f") < __classPrivateFieldGet(this, _PQueue_intervalCap, "f");
|
|
796
|
-
}, _PQueue_doesConcurrentAllowAnother_get = function _PQueue_doesConcurrentAllowAnother_get() {
|
|
797
|
-
return __classPrivateFieldGet(this, _PQueue_pending, "f") < __classPrivateFieldGet(this, _PQueue_concurrency, "f");
|
|
798
|
-
}, _PQueue_next = function _PQueue_next() {
|
|
799
|
-
var _a;
|
|
800
|
-
__classPrivateFieldSet(this, _PQueue_pending, (_a = __classPrivateFieldGet(this, _PQueue_pending, "f"), _a--, _a), "f");
|
|
801
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this);
|
|
802
|
-
this.emit('next');
|
|
803
|
-
}, _PQueue_onResumeInterval = function _PQueue_onResumeInterval() {
|
|
804
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
805
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
806
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, undefined, "f");
|
|
807
|
-
}, _PQueue_isIntervalPaused_get = function _PQueue_isIntervalPaused_get() {
|
|
808
|
-
const now = Date.now();
|
|
809
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f") === undefined) {
|
|
810
|
-
const delay = __classPrivateFieldGet(this, _PQueue_intervalEnd, "f") - now;
|
|
811
|
-
if (delay < 0) {
|
|
812
|
-
// Act as the interval was done
|
|
813
|
-
// We don't need to resume it here because it will be resumed on line 160
|
|
814
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (__classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f")) ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
815
|
-
}
|
|
816
|
-
else {
|
|
817
|
-
// Act as the interval is pending
|
|
818
|
-
if (__classPrivateFieldGet(this, _PQueue_timeoutId, "f") === undefined) {
|
|
819
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, setTimeout(() => {
|
|
820
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onResumeInterval).call(this);
|
|
821
|
-
}, delay), "f");
|
|
822
|
-
}
|
|
823
|
-
return true;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
return false;
|
|
827
|
-
}, _PQueue_tryToStartAnother = function _PQueue_tryToStartAnother() {
|
|
828
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
829
|
-
// We can clear the interval ("pause")
|
|
830
|
-
// Because we can redo it later ("resume")
|
|
831
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
832
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
833
|
-
}
|
|
834
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
835
|
-
this.emit('empty');
|
|
836
|
-
if (__classPrivateFieldGet(this, _PQueue_pending, "f") === 0) {
|
|
837
|
-
this.emit('idle');
|
|
838
|
-
}
|
|
839
|
-
return false;
|
|
840
|
-
}
|
|
841
|
-
if (!__classPrivateFieldGet(this, _PQueue_isPaused, "f")) {
|
|
842
|
-
const canInitializeInterval = !__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_isIntervalPaused_get);
|
|
843
|
-
if (__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesIntervalAllowAnother_get) && __classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesConcurrentAllowAnother_get)) {
|
|
844
|
-
const job = __classPrivateFieldGet(this, _PQueue_queue, "f").dequeue();
|
|
845
|
-
if (!job) {
|
|
846
|
-
return false;
|
|
847
|
-
}
|
|
848
|
-
this.emit('active');
|
|
849
|
-
job();
|
|
850
|
-
if (canInitializeInterval) {
|
|
851
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
852
|
-
}
|
|
853
|
-
return true;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
return false;
|
|
857
|
-
}, _PQueue_initializeIntervalIfNeeded = function _PQueue_initializeIntervalIfNeeded() {
|
|
858
|
-
if (__classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalId, "f") !== undefined) {
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, setInterval(() => {
|
|
862
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
863
|
-
}, __classPrivateFieldGet(this, _PQueue_interval, "f")), "f");
|
|
864
|
-
__classPrivateFieldSet(this, _PQueue_intervalEnd, Date.now() + __classPrivateFieldGet(this, _PQueue_interval, "f"), "f");
|
|
865
|
-
}, _PQueue_onInterval = function _PQueue_onInterval() {
|
|
866
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalCount, "f") === 0 && __classPrivateFieldGet(this, _PQueue_pending, "f") === 0 && __classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
867
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
868
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
869
|
-
}
|
|
870
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, __classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f") ? __classPrivateFieldGet(this, _PQueue_pending, "f") : 0, "f");
|
|
871
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
872
|
-
}, _PQueue_processQueue = function _PQueue_processQueue() {
|
|
873
|
-
// eslint-disable-next-line no-empty
|
|
874
|
-
while (__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this)) { }
|
|
875
|
-
}, _PQueue_throwOnAbort = async function _PQueue_throwOnAbort(signal) {
|
|
876
|
-
return new Promise((_resolve, reject) => {
|
|
877
|
-
signal.addEventListener('abort', () => {
|
|
878
|
-
// TODO: Reject with signal.throwIfAborted() when targeting Node.js 18
|
|
879
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
880
|
-
reject(new AbortError('The task was aborted.'));
|
|
881
|
-
}, { once: true });
|
|
882
|
-
});
|
|
883
|
-
}, _PQueue_onEvent = async function _PQueue_onEvent(event, filter) {
|
|
884
|
-
return new Promise(resolve => {
|
|
885
|
-
const listener = () => {
|
|
886
|
-
if (filter && !filter()) {
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
this.off(event, listener);
|
|
890
|
-
resolve();
|
|
891
|
-
};
|
|
892
|
-
this.on(event, listener);
|
|
893
|
-
});
|
|
894
|
-
};
|
|
895
877
|
|
|
896
878
|
function buildLog(text, count) {
|
|
897
879
|
console.log(`
|
|
@@ -1241,6 +1223,12 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1241
1223
|
rollupOptions: {
|
|
1242
1224
|
input: {
|
|
1243
1225
|
app: join(root, "./index.html")
|
|
1226
|
+
},
|
|
1227
|
+
// @ts-expect-error rollup type
|
|
1228
|
+
onLog(level, log, handler) {
|
|
1229
|
+
if (log.message.includes("react-helmet-async"))
|
|
1230
|
+
return;
|
|
1231
|
+
handler(level, log);
|
|
1244
1232
|
}
|
|
1245
1233
|
}
|
|
1246
1234
|
},
|
|
@@ -1288,8 +1276,9 @@ async function build(ssgOptions = {}, viteConfig = {}) {
|
|
|
1288
1276
|
const critters = crittersOptions !== false ? await getCritters(outDir, crittersOptions) : void 0;
|
|
1289
1277
|
if (critters)
|
|
1290
1278
|
console.log(`${gray("[vite-react-ssg]")} ${blue("Critical CSS generation enabled via `critters`")}`);
|
|
1291
|
-
const
|
|
1292
|
-
const
|
|
1279
|
+
const dotVitedir = Number.parseInt(version$3) >= 5 ? [".vite"] : [];
|
|
1280
|
+
const ssrManifest = JSON.parse(await fs$7.readFile(join(out, ...dotVitedir, "ssr-manifest.json"), "utf-8"));
|
|
1281
|
+
const manifest = JSON.parse(await fs$7.readFile(join(out, ...dotVitedir, "manifest.json"), "utf-8"));
|
|
1293
1282
|
let indexHTML = await fs$7.readFile(join(out, "index.html"), "utf-8");
|
|
1294
1283
|
indexHTML = rewriteScripts(indexHTML, script);
|
|
1295
1284
|
const queue = new PQueue({ concurrency });
|