@xyd-js/plugin-docs 0.1.0-xyd.5 → 0.1.0-xyd.56

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.js CHANGED
@@ -3211,7 +3211,7 @@ File must be named 'docs' with one of the following extensions: ${extensions.joi
3211
3211
  let json = JSON.parse(rawJsonSettings);
3212
3212
  return json;
3213
3213
  } catch (e) {
3214
- console.error(e);
3214
+ console.error("\u26A0\uFE0F Error parsing settings file");
3215
3215
  return null;
3216
3216
  }
3217
3217
  }
@@ -3281,25 +3281,42 @@ function preinstall() {
3281
3281
  }
3282
3282
  function vitePluginSettings() {
3283
3283
  return async function({ preinstall: preinstall3 }) {
3284
+ const virtualId = "virtual:xyd-settings";
3285
+ const resolvedId = virtualId + ".jsx";
3286
+ let currentSettings = globalThis.__xydSettings;
3287
+ if (!currentSettings && preinstall3?.settings) {
3288
+ currentSettings = typeof preinstall3?.settings === "string" ? preinstall3?.settings : JSON.stringify(preinstall3?.settings || {});
3289
+ }
3284
3290
  return {
3285
- name: "virtual:xyd-settings",
3291
+ name: "xyd:virtual-settings",
3286
3292
  resolveId(id) {
3287
- if (id === "virtual:xyd-settings") {
3288
- return id + ".jsx";
3293
+ if (id === virtualId) {
3294
+ return resolvedId;
3289
3295
  }
3290
3296
  return null;
3291
3297
  },
3292
3298
  async load(id) {
3293
3299
  if (id === "virtual:xyd-settings.jsx") {
3294
3300
  return `
3295
- export default {
3296
- get settings() {
3297
- return globalThis.__xydSettings || ${typeof preinstall3.settings === "string" ? preinstall3.settings : JSON.stringify(preinstall3.settings)}
3301
+ export default {
3302
+ get settings() {
3303
+ return globalThis.__xydSettings || ${typeof preinstall3.settings === "string" ? preinstall3.settings : JSON.stringify(preinstall3.settings)}
3298
3304
  }
3299
3305
  }
3300
3306
  `;
3301
3307
  }
3302
3308
  return null;
3309
+ },
3310
+ async hotUpdate(ctx) {
3311
+ const isPageFileChanged = ctx.file.includes("xyd-plugin-docs/src/pages/layout.tsx") || ctx.file.includes("xyd-plugin-docs/src/pages/page.tsx");
3312
+ if (!isPageFileChanged) {
3313
+ return;
3314
+ }
3315
+ const newSettings = await readSettings();
3316
+ if (!newSettings) {
3317
+ return;
3318
+ }
3319
+ globalThis.__xydSettings = newSettings;
3303
3320
  }
3304
3321
  };
3305
3322
  };