Advertisement
Guest User

Untitled

a guest
May 6th, 2023
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { getCurrentInstance, reactive } from "/_nuxt/node_modules/.cache/vite/client/deps/vue.js?v=bd4495ba";
  2. import { createHooks } from "/_nuxt/node_modules/hookable/dist/index.mjs?v=bd4495ba";
  3. import { getContext } from "/_nuxt/node_modules/.cache/vite/client/deps/unctx.js?v=bd4495ba";
  4. const nuxtAppCtx = /* @__PURE__ */ getContext("nuxt-app");
  5. export const NuxtPluginIndicator = "__nuxt_plugin";
  6. export function createNuxtApp(options) {
  7.   let hydratingCount = 0;
  8.   const nuxtApp = {
  9.     provide: void 0,
  10.     globalName: "nuxt",
  11.     versions: {
  12.       get nuxt() {
  13.         return __NUXT_VERSION__;
  14.       },
  15.       get vue() {
  16.         return nuxtApp.vueApp.version;
  17.       }
  18.     },
  19.     payload: reactive({
  20.       data: {},
  21.       state: {},
  22.       _errors: {},
  23.       ...process.client ? window.__NUXT__ ?? {} : { serverRendered: true }
  24.     }),
  25.     static: {
  26.       data: {}
  27.     },
  28.     isHydrating: process.client,
  29.     deferHydration() {
  30.       if (!nuxtApp.isHydrating) {
  31.         return () => {
  32.         };
  33.       }
  34.       hydratingCount++;
  35.       let called = false;
  36.       return () => {
  37.         if (called) {
  38.           return;
  39.         }
  40.         called = true;
  41.         hydratingCount--;
  42.         if (hydratingCount === 0) {
  43.           nuxtApp.isHydrating = false;
  44.           return nuxtApp.callHook("app:suspense:resolve");
  45.         }
  46.       };
  47.     },
  48.     _asyncDataPromises: {},
  49.     _asyncData: {},
  50.     _payloadRevivers: {},
  51.     ...options
  52.   };
  53.   nuxtApp.hooks = createHooks();
  54.   nuxtApp.hook = nuxtApp.hooks.hook;
  55.   if (process.server) {
  56.     async function contextCaller(hooks, args) {
  57.       for (const hook of hooks) {
  58.         await nuxtAppCtx.call(nuxtApp, () => hook(...args));
  59.       }
  60.     }
  61.     nuxtApp.hooks.callHook = (name, ...args) => nuxtApp.hooks.callHookWith(contextCaller, name, ...args);
  62.   }
  63.   nuxtApp.callHook = nuxtApp.hooks.callHook;
  64.   nuxtApp.provide = (name, value) => {
  65.     const $name = "$" + name;
  66.     defineGetter(nuxtApp, $name, value);
  67.     defineGetter(nuxtApp.vueApp.config.globalProperties, $name, value);
  68.   };
  69.   defineGetter(nuxtApp.vueApp, "$nuxt", nuxtApp);
  70.   defineGetter(nuxtApp.vueApp.config.globalProperties, "$nuxt", nuxtApp);
  71.   if (process.server) {
  72.     if (nuxtApp.ssrContext) {
  73.       nuxtApp.ssrContext.nuxt = nuxtApp;
  74.     }
  75.     if (nuxtApp.ssrContext) {
  76.       nuxtApp.ssrContext._payloadReducers = {};
  77.     }
  78.     nuxtApp.ssrContext = nuxtApp.ssrContext || {};
  79.     if (nuxtApp.ssrContext.payload) {
  80.       Object.assign(nuxtApp.payload, nuxtApp.ssrContext.payload);
  81.     }
  82.     nuxtApp.ssrContext.payload = nuxtApp.payload;
  83.     nuxtApp.ssrContext.config = {
  84.       public: options.ssrContext.runtimeConfig.public,
  85.       app: options.ssrContext.runtimeConfig.app
  86.     };
  87.   }
  88.   if (process.client) {
  89.     window.addEventListener("nuxt.preloadError", (event) => {
  90.       nuxtApp.callHook("app:chunkError", { error: event.payload });
  91.     });
  92.     const unreg = nuxtApp.hook("app:error", (...args) => {
  93.       console.error("[nuxt] error caught during app initialization", ...args);
  94.     });
  95.     nuxtApp.hook("app:mounted", unreg);
  96.   }
  97.   const runtimeConfig = process.server ? options.ssrContext.runtimeConfig : reactive(nuxtApp.payload.config);
  98.   const compatibilityConfig = new Proxy(runtimeConfig, {
  99.     get(target, prop) {
  100.       if (prop in target) {
  101.         return target[prop];
  102.       }
  103.       if (process.dev && prop in target.public) {
  104.         console.warn(`[nuxt] [runtimeConfig] You are trying to access a public runtime config value (\`${prop}\`) directly from the top level. This currently works (for backward compatibility with Nuxt 2) but this compatibility layer will be removed in v3.5. Instead, you can update \`config['${prop}']\` to \`config.public['${prop}']\`.`);
  105.       }
  106.       return target.public[prop];
  107.     },
  108.     set(target, prop, value) {
  109.       if (process.server || prop === "public" || prop === "app") {
  110.         return false;
  111.       }
  112.       target[prop] = value;
  113.       target.public[prop] = value;
  114.       return true;
  115.     }
  116.   });
  117.   nuxtApp.provide("config", compatibilityConfig);
  118.   return nuxtApp;
  119. }
  120. export async function applyPlugin(nuxtApp, plugin) {
  121.   if (typeof plugin !== "function") {
  122.     return;
  123.   }
  124.   const { provide } = await callWithNuxt(nuxtApp, plugin, [nuxtApp]) || {};
  125.   if (provide && typeof provide === "object") {
  126.     for (const key in provide) {
  127.       nuxtApp.provide(key, provide[key]);
  128.     }
  129.   }
  130. }
  131. export async function applyPlugins(nuxtApp, plugins) {
  132.   for (const plugin of plugins) {
  133.     await applyPlugin(nuxtApp, plugin);
  134.   }
  135. }
  136. export function normalizePlugins(_plugins) {
  137.   const unwrappedPlugins = [];
  138.   const legacyInjectPlugins = [];
  139.   const invalidPlugins = [];
  140.   const plugins = [];
  141.   for (const plugin of _plugins) {
  142.     if (typeof plugin !== "function") {
  143.       if (process.dev) {
  144.         invalidPlugins.push(plugin);
  145.       }
  146.       continue;
  147.     }
  148.     let _plugin = plugin;
  149.     if (plugin.length > 1) {
  150.       if (process.dev) {
  151.         legacyInjectPlugins.push(plugin);
  152.       }
  153.       _plugin = (nuxtApp) => plugin(nuxtApp, nuxtApp.provide);
  154.     }
  155.     if (process.dev && !isNuxtPlugin(_plugin)) {
  156.       unwrappedPlugins.push(_plugin);
  157.     }
  158.     plugins.push(_plugin);
  159.   }
  160.   plugins.sort((a, b) => (a.meta?.order || orderMap.default) - (b.meta?.order || orderMap.default));
  161.   if (process.dev && legacyInjectPlugins.length) {
  162.     console.warn("[warn] [nuxt] You are using a plugin with legacy Nuxt 2 format (context, inject) which is likely to be broken. In the future they will be ignored:", legacyInjectPlugins.map((p) => p.name || p).join(","));
  163.   }
  164.   if (process.dev && invalidPlugins.length) {
  165.     console.warn("[warn] [nuxt] Some plugins are not exposing a function and skipped:", invalidPlugins);
  166.   }
  167.   if (process.dev && unwrappedPlugins.length) {
  168.     console.warn("[warn] [nuxt] You are using a plugin that has not been wrapped in `defineNuxtPlugin`. It is advised to wrap your plugins as in the future this may enable enhancements:", unwrappedPlugins.map((p) => p.name || p).join(","));
  169.   }
  170.   return plugins;
  171. }
  172. const orderMap = {
  173.   pre: -20,
  174.   default: 0,
  175.   post: 20
  176. };
  177. export function definePayloadPlugin(plugin) {
  178.   return /* #__PURE__ */ defineNuxtPlugin(plugin, { order: -40 });
  179. }
  180. export function /* #__PURE__ */ defineNuxtPlugin(plugin, meta) {
  181.   if (typeof plugin === "function") {
  182.     return /* #__PURE__ */ defineNuxtPlugin({ setup: plugin }, meta);
  183.   }
  184.   const wrapper = (nuxtApp) => {
  185.     if (plugin.hooks) {
  186.       nuxtApp.hooks.addHooks(plugin.hooks);
  187.     }
  188.     if (plugin.setup) {
  189.       return plugin.setup(nuxtApp);
  190.     }
  191.   };
  192.   wrapper.meta = {
  193.     name: meta?.name || plugin.name || plugin.setup?.name,
  194.     order: meta?.order || plugin.order || orderMap[plugin.enforce || "default"] || orderMap.default
  195.   };
  196.   wrapper[NuxtPluginIndicator] = true;
  197.   return wrapper;
  198. }
  199. export function isNuxtPlugin(plugin) {
  200.   return typeof plugin === "function" && NuxtPluginIndicator in plugin;
  201. }
  202. export function callWithNuxt(nuxt, setup, args) {
  203.   const fn = () => args ? setup(...args) : setup();
  204.   if (process.server) {
  205.     return nuxtAppCtx.callAsync(nuxt, fn);
  206.   } else {
  207.     nuxtAppCtx.set(nuxt);
  208.     return fn();
  209.   }
  210. }
  211. export function useNuxtApp() {
  212.   const nuxtAppInstance = nuxtAppCtx.tryUse();
  213.   if (!nuxtAppInstance) {
  214.     const vm = getCurrentInstance();
  215.     if (!vm) {
  216.       if (process.dev) {
  217.         throw new Error("[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at `https://nuxt.com/docs/guide/concepts/auto-imports#using-vue-and-nuxt-composables`.");
  218.       } else {
  219.         throw new Error("[nuxt] instance unavailable");
  220.       }
  221.     }
  222.     return vm.appContext.app.$nuxt;
  223.   }
  224.   return nuxtAppInstance;
  225. }
  226. export function /* #__PURE__ */ useRuntimeConfig() {
  227.   return useNuxtApp().$config;
  228. }
  229. function defineGetter(obj, key, val) {
  230.   Object.defineProperty(obj, key, { get: () => val });
  231. }
  232. export function defineAppConfig(config) {
  233.   return config;
  234. }
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement