@crxjs/vite-plugin 2.6.0 → 2.6.1
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/index.mjs +47 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { simple } from 'acorn-walk';
|
|
|
2
2
|
import { createHash } from 'crypto';
|
|
3
3
|
import debug$5 from 'debug';
|
|
4
4
|
import { join, normalize, dirname, basename, isAbsolute, relative, resolve, parse as parse$1 } from 'pathe';
|
|
5
|
-
import { Subject, filter, ReplaySubject, switchMap, of, startWith, map, BehaviorSubject, mergeMap, firstValueFrom, takeUntil, first, toArray, retry, concatWith, Subscription, buffer } from 'rxjs';
|
|
5
|
+
import { Subject, filter, ReplaySubject, switchMap, of, startWith, tap, debounceTime, map, share, BehaviorSubject, mergeMap, firstValueFrom, takeUntil, first, toArray, retry, concatWith, Subscription, buffer } from 'rxjs';
|
|
6
6
|
import fsx from 'fs-extra';
|
|
7
7
|
import { performance } from 'perf_hooks';
|
|
8
8
|
import { rollup } from 'rollup';
|
|
@@ -515,12 +515,39 @@ fileWriterEvent$.pipe(
|
|
|
515
515
|
filter((e) => e.type === "build_start"),
|
|
516
516
|
switchMap((e) => of(e))
|
|
517
517
|
);
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
518
|
+
const allFilesReadyDebounceMs = 100;
|
|
519
|
+
let currentAllFilesReadyGeneration = 0;
|
|
520
|
+
let completedAllFilesReadyGeneration = 0;
|
|
521
|
+
let lastAllFilesReadyResults;
|
|
522
|
+
const allFilesReadyState$ = buildEnd$.pipe(
|
|
521
523
|
switchMap(
|
|
522
|
-
(
|
|
523
|
-
|
|
524
|
+
() => outputFiles.change$.pipe(
|
|
525
|
+
startWith({ type: "start" }),
|
|
526
|
+
tap(() => {
|
|
527
|
+
currentAllFilesReadyGeneration += 1;
|
|
528
|
+
}),
|
|
529
|
+
debounceTime(allFilesReadyDebounceMs)
|
|
530
|
+
)
|
|
531
|
+
),
|
|
532
|
+
map(() => ({
|
|
533
|
+
generation: currentAllFilesReadyGeneration,
|
|
534
|
+
files: [...outputFiles.values()]
|
|
535
|
+
})),
|
|
536
|
+
switchMap(async ({ generation, files }) => {
|
|
537
|
+
const seen = /* @__PURE__ */ new Set();
|
|
538
|
+
const results = await Promise.allSettled(
|
|
539
|
+
files.map((file) => waitForOutputFile(file, seen))
|
|
540
|
+
);
|
|
541
|
+
return { generation, results };
|
|
542
|
+
}),
|
|
543
|
+
tap(({ generation, results }) => {
|
|
544
|
+
completedAllFilesReadyGeneration = generation;
|
|
545
|
+
lastAllFilesReadyResults = results;
|
|
546
|
+
}),
|
|
547
|
+
share()
|
|
548
|
+
);
|
|
549
|
+
const allFilesReady$ = allFilesReadyState$.pipe(
|
|
550
|
+
map(({ results }) => results)
|
|
524
551
|
);
|
|
525
552
|
async function waitForOutputFile(file, seen = /* @__PURE__ */ new Set()) {
|
|
526
553
|
if (seen.has(file))
|
|
@@ -529,6 +556,18 @@ async function waitForOutputFile(file, seen = /* @__PURE__ */ new Set()) {
|
|
|
529
556
|
const { deps } = await file.file;
|
|
530
557
|
await Promise.all(deps.map((dep) => waitForOutputFile(dep, seen)));
|
|
531
558
|
}
|
|
559
|
+
async function waitForAllFilesReadyResults() {
|
|
560
|
+
const targetGeneration = currentAllFilesReadyGeneration;
|
|
561
|
+
if (lastAllFilesReadyResults && completedAllFilesReadyGeneration >= targetGeneration) {
|
|
562
|
+
return lastAllFilesReadyResults;
|
|
563
|
+
}
|
|
564
|
+
const { results } = await firstValueFrom(
|
|
565
|
+
allFilesReadyState$.pipe(
|
|
566
|
+
filter(({ generation }) => generation >= targetGeneration)
|
|
567
|
+
)
|
|
568
|
+
);
|
|
569
|
+
return results;
|
|
570
|
+
}
|
|
532
571
|
const timestamp$ = new BehaviorSubject(Date.now());
|
|
533
572
|
allFilesReady$.subscribe(() => {
|
|
534
573
|
timestamp$.next(Date.now());
|
|
@@ -731,7 +770,7 @@ function prepIifeScript(fileName, script) {
|
|
|
731
770
|
);
|
|
732
771
|
}
|
|
733
772
|
async function allFilesReady() {
|
|
734
|
-
await
|
|
773
|
+
await waitForAllFilesReadyResults();
|
|
735
774
|
}
|
|
736
775
|
|
|
737
776
|
const { outputFile } = fsx;
|
|
@@ -1735,7 +1774,7 @@ async function prepareVitePayloadForCrx(p) {
|
|
|
1735
1774
|
return update(id).map((file) => file.file);
|
|
1736
1775
|
});
|
|
1737
1776
|
await Promise.all(pendingFiles);
|
|
1738
|
-
await
|
|
1777
|
+
await allFilesReady();
|
|
1739
1778
|
}
|
|
1740
1779
|
return mapVitePayloadForCrx(p);
|
|
1741
1780
|
}
|