adminizer 5.0.0-build.19 → 5.0.0-build.20

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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Adminizer package version. Built entry assets keep stable file names
3
+ * (app.js, agent.es.js, controls/*.es.js and controls/*.css), so this version
4
+ * is appended as a query string to invalidate browser caches on release.
5
+ */
6
+ export declare function getAssetVersion(): string;
7
+ /** Appends ?v=<version> to a production asset URL; dev URLs pass through untouched. */
8
+ export declare function withAssetVersion(url: string): string;
9
+ export declare function withAssetVersion(url: string | undefined): string | undefined;
@@ -0,0 +1,30 @@
1
+ import fs from "fs";
2
+ import path from "node:path";
3
+ let cachedVersion = null;
4
+ /**
5
+ * Adminizer package version. Built entry assets keep stable file names
6
+ * (app.js, agent.es.js, controls/*.es.js and controls/*.css), so this version
7
+ * is appended as a query string to invalidate browser caches on release.
8
+ */
9
+ export function getAssetVersion() {
10
+ if (cachedVersion !== null) {
11
+ return cachedVersion;
12
+ }
13
+ let version = "";
14
+ try {
15
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(import.meta.dirname, "../../package.json"), "utf-8"));
16
+ version = typeof pkg.version === "string" ? pkg.version : "";
17
+ }
18
+ catch {
19
+ // Missing or unreadable package.json: fall back to an empty version.
20
+ }
21
+ cachedVersion = version;
22
+ return version;
23
+ }
24
+ export function withAssetVersion(url) {
25
+ const version = getAssetVersion();
26
+ if (!url || !version || process.env.ADMINIZER_ENV === "dev") {
27
+ return url;
28
+ }
29
+ return `${url}${url.includes("?") ? "&" : "?"}v=${version}`;
30
+ }
@@ -1,5 +1,6 @@
1
1
  import inertiaActionsHelper from "./inertiaActionsHelper.js";
2
2
  import { isObject } from "./JsUtils.js";
3
+ import { withAssetVersion } from "./assetVersionHelper.js";
3
4
  import { Adminizer } from "../lib/Adminizer.js";
4
5
  const missingControlWarnings = new Set();
5
6
  /**
@@ -195,8 +196,8 @@ export function getControlsOptions(fieldConfig, req, type, defaultControlName, c
195
196
  ...(control?.getConfig() || {}), // Base config of the editor
196
197
  ...(shouldUseFieldConfig ? fieldOptions?.config || {} : {}),
197
198
  },
198
- path: control.getJsPath(),
199
- cssPath: control.getCssPath(),
199
+ path: withAssetVersion(control.getJsPath()),
200
+ cssPath: withAssetVersion(control.getCssPath()),
200
201
  };
201
202
  // If items are provided, use them instead of the CKEditor defaults.
202
203
  if (type === 'wysiwyg'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "5.0.0-build.19",
4
+ "version": "5.0.0-build.20",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",
@@ -5,6 +5,7 @@ import path from "node:path";
5
5
  import { Adminizer } from "../lib/Adminizer.js";
6
6
  import { InertiaMenuHelper } from "../helpers/inertiaMenuHelper.js";
7
7
  import { getUiTranslations } from "../lib/ui-i18n/getUiTranslations.js";
8
+ import { getAssetVersion } from "../helpers/assetVersionHelper.js";
8
9
  import { COMMON_UI_TRANSLATION_KEYS } from "../lib/ui-i18n/uiTranslationKeys.js";
9
10
  export function bindInertia(adminizer) {
10
11
  const escapeHtmlAttribute = (value) => value
@@ -31,6 +32,9 @@ export function bindInertia(adminizer) {
31
32
  }
32
33
  return `${adminizer.config.routePrefix}/${customFavicon.replace(/^\/+/, "")}`;
33
34
  };
35
+ // Entry files are built with stable names (app.js, agent.es.js, controls),
36
+ // so a version query string is what invalidates browser caches on release.
37
+ const assetVersion = getAssetVersion();
34
38
  const viteRender = () => {
35
39
  if (process.env.ADMINIZER_ENV === 'dev') {
36
40
  return `
@@ -73,19 +77,21 @@ export function bindInertia(adminizer) {
73
77
  }
74
78
  // JS resource
75
79
  if (entry.file) {
76
- const href = `${adminizer.config.routePrefix}/assets/${entry.file}`;
80
+ const href = `${adminizer.config.routePrefix}/assets/${entry.file}?v=${assetVersion}`;
77
81
  preloadLinks.push(`<link rel="modulepreload" href="${href}" as="script">`);
78
82
  scripts.push(`<script type="module" src="${href}"></script>`);
79
83
  }
80
84
  // Route prefix script
81
85
  const routePrefixScript = `<script>window.routePrefix = "${adminizer.config.routePrefix}";</script>`;
82
86
  const bindPublic = `<script>window.bindPublic = ${adminizer.config.bind?.public}</script>`;
87
+ const versionScript = `<script>window.adminizerVersion = "${assetVersion}";</script>`;
83
88
  return `
84
89
  ${preloadLinks.join('\n')}
85
90
  ${stylesheets.join('\n')}
86
91
  ${scripts.join('\n')}
87
92
  ${routePrefixScript}
88
93
  ${bindPublic}
94
+ ${versionScript}
89
95
  `;
90
96
  }
91
97
  };