UNPKG

@edgeone/nuxt-pages

Version:

A professional deployment package that seamlessly deploys your Nuxt 3/4 applications to Tencent Cloud EdgeOne platform with optimized performance and intelligent caching.

88 lines (80 loc) 3.27 kB
var require = await (async () => { var { createRequire } = await import("node:module"); return createRequire(import.meta.url); })(); import { PLUGIN_DIR, RUN_CONFIG_FILE } from "./chunk-HBXUWFGE.js"; // src/run/config.ts import { existsSync } from "node:fs"; import { readFile } from "node:fs/promises"; import { join, resolve } from "node:path"; // src/run/storage/request-scoped-in-memory-cache.cts var NullValue = Symbol.for("null-value"); var IN_MEMORY_CACHE_MAX_SIZE = Symbol.for("nf-in-memory-cache-max-size"); var IN_MEMORY_LRU_CACHE = Symbol.for("nf-in-memory-lru-cache"); var extendedGlobalThis = globalThis; var DEFAULT_FALLBACK_MAX_SIZE = 50 * 1024 * 1024; function setInMemoryCacheMaxSizeFromNuxtConfig(size) { if (typeof size === "number") { extendedGlobalThis[IN_MEMORY_CACHE_MAX_SIZE] = size; } } // src/run/storage/regional-blob-store.cts var FETCH_BEFORE_NUXT_PATCHED_IT = Symbol.for("nf-not-patched-fetch"); var extendedGlobalThis2 = globalThis; function attemptToGetOriginalFetch(fetch) { return fetch._nuxtOriginalFetch ?? fetch; } function forceOptOutOfUsingDataCache(fetch) { return (input, init) => { return fetch(input, { ...init, next: { ...init?.next, // setting next.internal = true should prevent from trying to use data cache // https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L174 // https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L210-L213 // this is last line of defense in case we didn't manage to get unpatched fetch that will not affect // fetch if it's unpatched so it should be safe to apply always if we aren't sure if we use patched fetch // @ts-expect-error - this is an internal field that Next.js doesn't add to its global // type overrides for RequestInit type (like `next.revalidate` or `next.tags`) internal: true } }); }; } var setFetchBeforeNuxtPatchedIt = (fetch) => { extendedGlobalThis2[FETCH_BEFORE_NUXT_PATCHED_IT] = forceOptOutOfUsingDataCache( attemptToGetOriginalFetch(fetch) ); }; var fetchBeforeNuxtPatchedItFallback = forceOptOutOfUsingDataCache( attemptToGetOriginalFetch(globalThis.fetch) ); // src/run/config.ts var getRunConfig = async () => { return JSON.parse(await readFile(resolve(PLUGIN_DIR, RUN_CONFIG_FILE), "utf-8")); }; var setRunConfig = (config) => { const cacheHandler = join(PLUGIN_DIR, ".edgeone/dist/run/handlers/cache.cjs"); if (!existsSync(cacheHandler)) { throw new Error(`Cache handler not found at ${cacheHandler}`); } config.experimental = { ...config.experimental, // Before Next.js 14.1.0 path to the cache handler was in experimental section, see NextConfigForMultipleVersions type incrementalCacheHandlerPath: cacheHandler }; config.cacheHandler = cacheHandler; setInMemoryCacheMaxSizeFromNuxtConfig( config.cacheMaxMemorySize ?? config.experimental?.isrMemoryCacheSize ); process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config); }; export { setFetchBeforeNuxtPatchedIt, getRunConfig, setRunConfig };