Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { getCurrentInstance, reactive } from "/_nuxt/node_modules/.cache/vite/client/deps/vue.js?v=bd4495ba";
- import { createHooks } from "/_nuxt/node_modules/hookable/dist/index.mjs?v=bd4495ba";
- import { getContext } from "/_nuxt/node_modules/.cache/vite/client/deps/unctx.js?v=bd4495ba";
- const nuxtAppCtx = /* @__PURE__ */ getContext("nuxt-app");
- export const NuxtPluginIndicator = "__nuxt_plugin";
- export function createNuxtApp(options) {
- let hydratingCount = 0;
- const nuxtApp = {
- provide: void 0,
- globalName: "nuxt",
- versions: {
- get nuxt() {
- return __NUXT_VERSION__;
- },
- get vue() {
- return nuxtApp.vueApp.version;
- }
- },
- payload: reactive({
- data: {},
- state: {},
- _errors: {},
- ...process.client ? window.__NUXT__ ?? {} : { serverRendered: true }
- }),
- static: {
- data: {}
- },
- isHydrating: process.client,
- deferHydration() {
- if (!nuxtApp.isHydrating) {
- return () => {
- };
- }
- hydratingCount++;
- let called = false;
- return () => {
- if (called) {
- return;
- }
- called = true;
- hydratingCount--;
- if (hydratingCount === 0) {
- nuxtApp.isHydrating = false;
- return nuxtApp.callHook("app:suspense:resolve");
- }
- };
- },
- _asyncDataPromises: {},
- _asyncData: {},
- _payloadRevivers: {},
- ...options
- };
- nuxtApp.hooks = createHooks();
- nuxtApp.hook = nuxtApp.hooks.hook;
- if (process.server) {
- async function contextCaller(hooks, args) {
- for (const hook of hooks) {
- await nuxtAppCtx.call(nuxtApp, () => hook(...args));
- }
- }
- nuxtApp.hooks.callHook = (name, ...args) => nuxtApp.hooks.callHookWith(contextCaller, name, ...args);
- }
- nuxtApp.callHook = nuxtApp.hooks.callHook;
- nuxtApp.provide = (name, value) => {
- const $name = "$" + name;
- defineGetter(nuxtApp, $name, value);
- defineGetter(nuxtApp.vueApp.config.globalProperties, $name, value);
- };
- defineGetter(nuxtApp.vueApp, "$nuxt", nuxtApp);
- defineGetter(nuxtApp.vueApp.config.globalProperties, "$nuxt", nuxtApp);
- if (process.server) {
- if (nuxtApp.ssrContext) {
- nuxtApp.ssrContext.nuxt = nuxtApp;
- }
- if (nuxtApp.ssrContext) {
- nuxtApp.ssrContext._payloadReducers = {};
- }
- nuxtApp.ssrContext = nuxtApp.ssrContext || {};
- if (nuxtApp.ssrContext.payload) {
- Object.assign(nuxtApp.payload, nuxtApp.ssrContext.payload);
- }
- nuxtApp.ssrContext.payload = nuxtApp.payload;
- nuxtApp.ssrContext.config = {
- public: options.ssrContext.runtimeConfig.public,
- app: options.ssrContext.runtimeConfig.app
- };
- }
- if (process.client) {
- window.addEventListener("nuxt.preloadError", (event) => {
- nuxtApp.callHook("app:chunkError", { error: event.payload });
- });
- const unreg = nuxtApp.hook("app:error", (...args) => {
- console.error("[nuxt] error caught during app initialization", ...args);
- });
- nuxtApp.hook("app:mounted", unreg);
- }
- const runtimeConfig = process.server ? options.ssrContext.runtimeConfig : reactive(nuxtApp.payload.config);
- const compatibilityConfig = new Proxy(runtimeConfig, {
- get(target, prop) {
- if (prop in target) {
- return target[prop];
- }
- if (process.dev && prop in target.public) {
- 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}']\`.`);
- }
- return target.public[prop];
- },
- set(target, prop, value) {
- if (process.server || prop === "public" || prop === "app") {
- return false;
- }
- target[prop] = value;
- target.public[prop] = value;
- return true;
- }
- });
- nuxtApp.provide("config", compatibilityConfig);
- return nuxtApp;
- }
- export async function applyPlugin(nuxtApp, plugin) {
- if (typeof plugin !== "function") {
- return;
- }
- const { provide } = await callWithNuxt(nuxtApp, plugin, [nuxtApp]) || {};
- if (provide && typeof provide === "object") {
- for (const key in provide) {
- nuxtApp.provide(key, provide[key]);
- }
- }
- }
- export async function applyPlugins(nuxtApp, plugins) {
- for (const plugin of plugins) {
- await applyPlugin(nuxtApp, plugin);
- }
- }
- export function normalizePlugins(_plugins) {
- const unwrappedPlugins = [];
- const legacyInjectPlugins = [];
- const invalidPlugins = [];
- const plugins = [];
- for (const plugin of _plugins) {
- if (typeof plugin !== "function") {
- if (process.dev) {
- invalidPlugins.push(plugin);
- }
- continue;
- }
- let _plugin = plugin;
- if (plugin.length > 1) {
- if (process.dev) {
- legacyInjectPlugins.push(plugin);
- }
- _plugin = (nuxtApp) => plugin(nuxtApp, nuxtApp.provide);
- }
- if (process.dev && !isNuxtPlugin(_plugin)) {
- unwrappedPlugins.push(_plugin);
- }
- plugins.push(_plugin);
- }
- plugins.sort((a, b) => (a.meta?.order || orderMap.default) - (b.meta?.order || orderMap.default));
- if (process.dev && legacyInjectPlugins.length) {
- 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(","));
- }
- if (process.dev && invalidPlugins.length) {
- console.warn("[warn] [nuxt] Some plugins are not exposing a function and skipped:", invalidPlugins);
- }
- if (process.dev && unwrappedPlugins.length) {
- 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(","));
- }
- return plugins;
- }
- const orderMap = {
- pre: -20,
- default: 0,
- post: 20
- };
- export function definePayloadPlugin(plugin) {
- return /* #__PURE__ */ defineNuxtPlugin(plugin, { order: -40 });
- }
- export function /* #__PURE__ */ defineNuxtPlugin(plugin, meta) {
- if (typeof plugin === "function") {
- return /* #__PURE__ */ defineNuxtPlugin({ setup: plugin }, meta);
- }
- const wrapper = (nuxtApp) => {
- if (plugin.hooks) {
- nuxtApp.hooks.addHooks(plugin.hooks);
- }
- if (plugin.setup) {
- return plugin.setup(nuxtApp);
- }
- };
- wrapper.meta = {
- name: meta?.name || plugin.name || plugin.setup?.name,
- order: meta?.order || plugin.order || orderMap[plugin.enforce || "default"] || orderMap.default
- };
- wrapper[NuxtPluginIndicator] = true;
- return wrapper;
- }
- export function isNuxtPlugin(plugin) {
- return typeof plugin === "function" && NuxtPluginIndicator in plugin;
- }
- export function callWithNuxt(nuxt, setup, args) {
- const fn = () => args ? setup(...args) : setup();
- if (process.server) {
- return nuxtAppCtx.callAsync(nuxt, fn);
- } else {
- nuxtAppCtx.set(nuxt);
- return fn();
- }
- }
- export function useNuxtApp() {
- const nuxtAppInstance = nuxtAppCtx.tryUse();
- if (!nuxtAppInstance) {
- const vm = getCurrentInstance();
- if (!vm) {
- if (process.dev) {
- 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`.");
- } else {
- throw new Error("[nuxt] instance unavailable");
- }
- }
- return vm.appContext.app.$nuxt;
- }
- return nuxtAppInstance;
- }
- export function /* #__PURE__ */ useRuntimeConfig() {
- return useNuxtApp().$config;
- }
- function defineGetter(obj, key, val) {
- Object.defineProperty(obj, key, { get: () => val });
- }
- export function defineAppConfig(config) {
- return config;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement