@arponascension/express-inertia 1.5.0 → 1.5.2

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 CHANGED
@@ -812,6 +812,45 @@ function compileBladeDirectives(templateSource, localDirectives) {
812
812
  }
813
813
  return compiled;
814
814
  }
815
+ function globToRegExp(glob) {
816
+ const normalized = glob.replace(/\\/g, "/");
817
+ let source = "";
818
+ let i = 0;
819
+ const escape = (ch) => ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
820
+ while (i < normalized.length) {
821
+ const ch = normalized[i];
822
+ if (ch === "*") {
823
+ if (normalized[i + 1] === "*") {
824
+ if (normalized[i + 2] === "/") {
825
+ source += "(?:.*/)?";
826
+ i += 3;
827
+ } else {
828
+ source += ".*";
829
+ i += 2;
830
+ }
831
+ } else {
832
+ source += "[^/]*";
833
+ i += 1;
834
+ }
835
+ } else if (ch === "?") {
836
+ source += "[^/]";
837
+ i += 1;
838
+ } else {
839
+ source += escape(ch);
840
+ i += 1;
841
+ }
842
+ }
843
+ return new RegExp(`^${source}$`);
844
+ }
845
+ function normalizeRefreshGlobs(refresh) {
846
+ if (refresh === void 0 || refresh === false) {
847
+ return null;
848
+ }
849
+ if (refresh === true) {
850
+ return ["views/**/*.ejs"];
851
+ }
852
+ return Array.isArray(refresh) ? refresh : [refresh];
853
+ }
815
854
  function resolveDevServerUrl(config, override) {
816
855
  if (override) return override.replace(/\/$/, "");
817
856
  const server = config?.server || {};
@@ -833,6 +872,7 @@ function inertiaVitePlugin(options = {}) {
833
872
  const logger2 = createLogger({ prefix: "express-inertia:vite" });
834
873
  let cleanupRegistered = false;
835
874
  let exitConfig = null;
875
+ const buildDirectory = options.buildDirectory || "build";
836
876
  const write = (config, server) => {
837
877
  try {
838
878
  const hotFile = path.resolve(config.root, options.hotFile || "public/hot");
@@ -856,8 +896,56 @@ function inertiaVitePlugin(options = {}) {
856
896
  remove(exitConfig);
857
897
  }
858
898
  };
899
+ const installRefresh = (server) => {
900
+ const refreshGlobs = normalizeRefreshGlobs(options.refresh);
901
+ if (!refreshGlobs) {
902
+ return;
903
+ }
904
+ const root = server.config.root;
905
+ const matchers = refreshGlobs.map(globToRegExp);
906
+ const matches = (file) => {
907
+ const rel = path.relative(root, file).split(path.sep).join("/");
908
+ return matchers.some((re) => re.test(rel));
909
+ };
910
+ const onFileEvent = (file) => {
911
+ if (file && matches(file)) {
912
+ server.ws.send({ type: "full-reload" });
913
+ }
914
+ };
915
+ try {
916
+ server.watcher.add(refreshGlobs);
917
+ } catch (err) {
918
+ logger2.warn("Failed to watch refresh paths", { error: err.message });
919
+ }
920
+ server.watcher.on("change", onFileEvent);
921
+ server.watcher.on("add", onFileEvent);
922
+ server.watcher.on("unlink", onFileEvent);
923
+ };
859
924
  return {
860
925
  name: "express-inertia-hot-file",
926
+ config(config, env) {
927
+ if (options.input) {
928
+ if (config.base === void 0) {
929
+ config.base = env.command === "build" ? `/${buildDirectory}/` : "/";
930
+ }
931
+ if (env.command === "build") {
932
+ if (config.publicDir === void 0 || config.publicDir === "public") {
933
+ config.publicDir = false;
934
+ }
935
+ if (config.build === void 0) {
936
+ config.build = {};
937
+ }
938
+ if (config.build.manifest !== false) {
939
+ config.build.manifest = true;
940
+ }
941
+ if (config.build.outDir === void 0) {
942
+ config.build.outDir = path.resolve(config.root || process.cwd(), "public", buildDirectory);
943
+ }
944
+ config.build.rollupOptions = config.build.rollupOptions || {};
945
+ config.build.rollupOptions.input = config.build.rollupOptions.input || options.input;
946
+ }
947
+ }
948
+ },
861
949
  configResolved(config) {
862
950
  if (config.command === "build") {
863
951
  remove(config);
@@ -874,6 +962,7 @@ function inertiaVitePlugin(options = {}) {
874
962
  process.once("exit", removeOnExit);
875
963
  cleanupRegistered = true;
876
964
  }
965
+ installRefresh(server);
877
966
  },
878
967
  buildStart() {
879
968
  }