@wojciechpiskorz/astroix 0.0.21 → 0.0.22
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/chrome.js +10186 -10160
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -786,10 +786,48 @@ function isDocumentRequest(input) {
|
|
|
786
786
|
}
|
|
787
787
|
|
|
788
788
|
// src/node/route-enumeration.ts
|
|
789
|
-
import { join as join3
|
|
789
|
+
import { join as join3 } from "path";
|
|
790
790
|
import { pathToFileURL } from "url";
|
|
791
791
|
import { createServerModuleRunner as createServerModuleRunner2 } from "vite";
|
|
792
792
|
|
|
793
|
+
// src/node/content-signal.ts
|
|
794
|
+
import { sep as sep2 } from "path";
|
|
795
|
+
function toPosixDir(dir) {
|
|
796
|
+
return dir.split(sep2).join("/").replace(/\/+$/, "");
|
|
797
|
+
}
|
|
798
|
+
function createContentSignalClassifier(scope) {
|
|
799
|
+
const srcDir = toPosixDir(scope.srcDir);
|
|
800
|
+
return (file) => {
|
|
801
|
+
const norm = file.split(sep2).join("/");
|
|
802
|
+
if (!norm.startsWith(`${srcDir}/`)) return false;
|
|
803
|
+
if (norm.endsWith(".css")) return false;
|
|
804
|
+
const rel = toRelative(scope.root, file);
|
|
805
|
+
return !scope.routes.captured.some((route) => route.entrypoint === rel);
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
function createLoaderCommitClassifier(root) {
|
|
809
|
+
const storePrefix = `${toPosixDir(root)}/.astro/`;
|
|
810
|
+
return (file) => {
|
|
811
|
+
const norm = file.split(sep2).join("/");
|
|
812
|
+
return norm === `${storePrefix}data-store.json` || norm.startsWith(`${storePrefix}data-store/`);
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
var RENDER_GRACE_MS = 1e3;
|
|
816
|
+
function createContentSyncPusher(server) {
|
|
817
|
+
let timer = null;
|
|
818
|
+
return () => {
|
|
819
|
+
if (timer !== null) return;
|
|
820
|
+
timer = setTimeout(() => {
|
|
821
|
+
timer = null;
|
|
822
|
+
pushToChrome(server, "astroix:content-synced");
|
|
823
|
+
}, RENDER_GRACE_MS);
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
function pushToChrome(server, event) {
|
|
827
|
+
if (server.ws.clients.size === 0) return;
|
|
828
|
+
server.ws.send(event, {});
|
|
829
|
+
}
|
|
830
|
+
|
|
793
831
|
// src/node/paginate.ts
|
|
794
832
|
function generatePaginateFunction(route) {
|
|
795
833
|
function paginateUtility(data, args = {}) {
|
|
@@ -873,15 +911,16 @@ function extractRenders(staticPaths, paramKey) {
|
|
|
873
911
|
return [...seen];
|
|
874
912
|
}
|
|
875
913
|
function registerRouteEnumeration(server, options) {
|
|
876
|
-
const
|
|
914
|
+
const isContentSignal = createContentSignalClassifier(options);
|
|
915
|
+
const isLoaderCommit = createLoaderCommitClassifier(options.root);
|
|
916
|
+
const pushContentSynced = createContentSyncPusher(server);
|
|
877
917
|
const results = /* @__PURE__ */ new Map();
|
|
878
918
|
let timer = null;
|
|
879
919
|
let running = false;
|
|
880
920
|
let rerun = false;
|
|
881
921
|
let contentFollowups = 0;
|
|
882
922
|
const push = () => {
|
|
883
|
-
|
|
884
|
-
server.ws.send("astroix:routes-changed", {});
|
|
923
|
+
pushToChrome(server, "astroix:routes-changed");
|
|
885
924
|
};
|
|
886
925
|
const schedule = (delay = DEBOUNCE_MS) => {
|
|
887
926
|
if (timer !== null) return;
|
|
@@ -895,11 +934,12 @@ function registerRouteEnumeration(server, options) {
|
|
|
895
934
|
schedule();
|
|
896
935
|
};
|
|
897
936
|
const onFileEvent = (file) => {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (
|
|
937
|
+
if (isLoaderCommit(file)) {
|
|
938
|
+
pushContentSynced();
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
if (!isContentSignal(file)) return;
|
|
942
|
+
pushContentSynced();
|
|
903
943
|
contentFollowups = CONTENT_FOLLOWUPS;
|
|
904
944
|
schedule();
|
|
905
945
|
};
|