vike 0.4.239-commit-59f1017 → 0.4.239-commit-9dcde6d
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/esm/client/index.d.ts +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-client-routing/entry.js +5 -3
- package/dist/esm/client/runtime-client-routing/getBaseServer.js +0 -1
- package/dist/esm/client/runtime-client-routing/{globalContext.d.ts → getGlobalContextClientInternal.d.ts} +1 -1
- package/dist/esm/client/runtime-client-routing/{globalContext.js → getGlobalContextClientInternal.js} +8 -4
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +4 -4
- package/dist/esm/client/runtime-client-routing/isClientSideRoutable.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +2 -4
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-server-routing/entry.js +5 -3
- package/dist/esm/client/runtime-server-routing/{globalContext.d.ts → getGlobalContextClientInternal.d.ts} +2 -2
- package/dist/esm/client/runtime-server-routing/getGlobalContextClientInternal.js +6 -0
- package/dist/esm/client/shared/execHookOnRenderClient.d.ts +1 -1
- package/dist/esm/client/shared/{createGetGlobalContextClient.d.ts → getGlobalContextClientInternalShared.d.ts} +11 -8
- package/dist/esm/client/shared/getGlobalContextClientInternalShared.js +66 -0
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +1 -3
- package/dist/esm/node/prerender/runPrerender.js +3 -1
- package/dist/esm/node/vite/index.js +34 -15
- package/dist/esm/node/vite/plugins/pluginBaseUrls.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBaseUrls.js +37 -35
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +82 -80
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +23 -21
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +38 -36
- package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +26 -24
- package/dist/esm/node/vite/plugins/pluginDev/determineFsAllowList.js +0 -1
- package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +87 -65
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +29 -27
- package/dist/esm/node/vite/plugins/pluginFileEnv.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +75 -73
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +30 -28
- package/dist/esm/node/vite/plugins/pluginPreview.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginPreview.js +35 -33
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.d.ts +9 -0
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.js +45 -0
- package/dist/esm/node/vite/plugins/pluginReplaceIsClientSide.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginReplaceIsClientSide.js +89 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +50 -48
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +12 -10
- package/dist/esm/node/vite/plugins/pluginWorkaroundVite6HmrRegression.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +26 -24
- package/dist/esm/shared/createGlobalContextShared.d.ts +1 -1
- package/dist/esm/shared/route/abort.d.ts +22 -11
- package/dist/esm/shared/route/abort.js +37 -5
- package/dist/esm/types/PageContext.d.ts +8 -8
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/findPackageJson.js +0 -1
- package/dist/esm/utils/getViteRPC.js +0 -2
- package/dist/esm/utils/requireResolve.js +0 -1
- package/package.json +2 -21
- package/dist/cjs/__internal/index.js +0 -35
- package/dist/cjs/client/runtime-client-routing/globalContext.js +0 -49
- package/dist/cjs/client/runtime-client-routing/prefetch/PrefetchSetting.js +0 -2
- package/dist/cjs/client/runtime-server-routing/globalContext.js +0 -41
- package/dist/cjs/client/runtime-server-routing/onLoad.js +0 -7
- package/dist/cjs/client/runtime-server-routing/utils.js +0 -34
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +0 -65
- package/dist/cjs/client/shared/getJsonSerializedInHtml.js +0 -40
- package/dist/cjs/client/shared/preparePageContextForPublicUsageClientShared.js +0 -41
- package/dist/cjs/client/shared/utils.js +0 -23
- package/dist/cjs/node/api/build.js +0 -24
- package/dist/cjs/node/api/context.js +0 -23
- package/dist/cjs/node/api/dev.js +0 -18
- package/dist/cjs/node/api/index.js +0 -44
- package/dist/cjs/node/api/onLoad.js +0 -9
- package/dist/cjs/node/api/prepareViteApiCall.js +0 -206
- package/dist/cjs/node/api/prerender.js +0 -18
- package/dist/cjs/node/api/preview.js +0 -38
- package/dist/cjs/node/api/types.js +0 -2
- package/dist/cjs/node/api/utils.js +0 -27
- package/dist/cjs/node/cli/context.js +0 -17
- package/dist/cjs/node/cli/entry.js +0 -121
- package/dist/cjs/node/cli/index.js +0 -12
- package/dist/cjs/node/cli/onLoad.js +0 -9
- package/dist/cjs/node/cli/parseCli.js +0 -95
- package/dist/cjs/node/cli/utils.js +0 -24
- package/dist/cjs/node/client/router.js +0 -19
- package/dist/cjs/node/createPageRenderer.js +0 -132
- package/dist/cjs/node/importBuild.js +0 -3
- package/dist/cjs/node/prerender/context.js +0 -26
- package/dist/cjs/node/prerender/index.js +0 -12
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +0 -66
- package/dist/cjs/node/prerender/runPrerender.js +0 -778
- package/dist/cjs/node/prerender/runPrerenderEntry.js +0 -55
- package/dist/cjs/node/prerender/utils.js +0 -37
- package/dist/cjs/node/runtime/globalContext.js +0 -582
- package/dist/cjs/node/runtime/index-deprecated.js +0 -33
- package/dist/cjs/node/runtime/index.js +0 -74
- package/dist/cjs/node/runtime/loggerRuntime.js +0 -17
- package/dist/cjs/node/runtime/onLoad.js +0 -29
- package/dist/cjs/node/runtime/page-files/setup.js +0 -5
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +0 -71
- package/dist/cjs/node/runtime/renderPage/assertArguments.js +0 -42
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +0 -51
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +0 -114
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +0 -59
- package/dist/cjs/node/runtime/renderPage/csp.js +0 -47
- package/dist/cjs/node/runtime/renderPage/execHookDataAndOnBeforeRender.js +0 -31
- package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +0 -120
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +0 -8
- package/dist/cjs/node/runtime/renderPage/getCacheControl.js +0 -24
- package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +0 -20
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +0 -137
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +0 -125
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.js +0 -86
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.js +0 -77
- package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +0 -36
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +0 -50
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +0 -41
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +0 -68
- package/dist/cjs/node/runtime/renderPage/headersResponse.js +0 -48
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/getHtmlTags.js +0 -269
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/getViteDevScript.js +0 -32
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/inferHtmlTags.js +0 -55
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/injectAssets__public.js +0 -31
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/injectHtmlTags.js +0 -161
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/mergeScriptTags.js +0 -73
- package/dist/cjs/node/runtime/renderPage/html/injectAssets/sanitizeJson.js +0 -8
- package/dist/cjs/node/runtime/renderPage/html/injectAssets.js +0 -93
- package/dist/cjs/node/runtime/renderPage/html/propKeys.js +0 -47
- package/dist/cjs/node/runtime/renderPage/html/renderHtml.js +0 -245
- package/dist/cjs/node/runtime/renderPage/html/serializeContext.js +0 -189
- package/dist/cjs/node/runtime/renderPage/html/stream/react-streaming.js +0 -36
- package/dist/cjs/node/runtime/renderPage/html/stream.js +0 -829
- package/dist/cjs/node/runtime/renderPage/inferMediaType.js +0 -81
- package/dist/cjs/node/runtime/renderPage/isFontFallback.js +0 -29
- package/dist/cjs/node/runtime/renderPage/isNewError.js +0 -25
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +0 -124
- package/dist/cjs/node/runtime/renderPage/log404/index.js +0 -154
- package/dist/cjs/node/runtime/renderPage/logErrorHint/errors.js +0 -20
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +0 -200
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +0 -34
- package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +0 -10
- package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +0 -83
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +0 -71
- package/dist/cjs/node/runtime/renderPage.js +0 -502
- package/dist/cjs/node/runtime/universal-middleware.js +0 -20
- package/dist/cjs/node/runtime/utils.js +0 -83
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +0 -27
- package/dist/cjs/node/runtime-dev/index.js +0 -42
- package/dist/cjs/node/shared/assertV1Design.js +0 -30
- package/dist/cjs/node/shared/extractAssetsQuery.js +0 -29
- package/dist/cjs/node/shared/getVikeConfigError.js +0 -22
- package/dist/cjs/node/shared/isErrorDebug.js +0 -7
- package/dist/cjs/node/shared/prependEntriesDir.js +0 -13
- package/dist/cjs/node/shared/resolveBase.js +0 -35
- package/dist/cjs/node/shared/utils.js +0 -35
- package/dist/cjs/node/shared/virtualFileId.js +0 -110
- package/dist/cjs/node/vite/index.js +0 -69
- package/dist/cjs/node/vite/onLoad.js +0 -21
- package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +0 -52
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +0 -357
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +0 -183
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -234
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +0 -256
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -40
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +0 -49
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +0 -111
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +0 -65
- package/dist/cjs/node/vite/plugins/pluginBuild.js +0 -22
- package/dist/cjs/node/vite/plugins/pluginCommon/assertResolveAlias.js +0 -88
- package/dist/cjs/node/vite/plugins/pluginCommon.js +0 -183
- package/dist/cjs/node/vite/plugins/pluginDev/determineFsAllowList.js +0 -28
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +0 -163
- package/dist/cjs/node/vite/plugins/pluginDev.js +0 -111
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +0 -92
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +0 -241
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +0 -113
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +0 -172
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +0 -70
- package/dist/cjs/node/vite/plugins/pluginPreview.js +0 -82
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +0 -95
- package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +0 -51
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/debug.js +0 -5
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +0 -56
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +0 -190
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +0 -54
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +0 -97
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +0 -233
- package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +0 -17
- package/dist/cjs/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +0 -35
- package/dist/cjs/node/vite/shared/addSsrMiddleware.js +0 -60
- package/dist/cjs/node/vite/shared/findPageFiles.js +0 -25
- package/dist/cjs/node/vite/shared/getAssetsDir.js +0 -10
- package/dist/cjs/node/vite/shared/getClientEntrySrcDev.js +0 -42
- package/dist/cjs/node/vite/shared/getEnvVarObject.js +0 -37
- package/dist/cjs/node/vite/shared/getFilePath.js +0 -172
- package/dist/cjs/node/vite/shared/getHttpRequestAsyncStore.js +0 -125
- package/dist/cjs/node/vite/shared/getMagicString.js +0 -18
- package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +0 -10
- package/dist/cjs/node/vite/shared/getOutDirs.js +0 -146
- package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +0 -21
- package/dist/cjs/node/vite/shared/isAsset.js +0 -40
- package/dist/cjs/node/vite/shared/isViteCliCall.js +0 -83
- package/dist/cjs/node/vite/shared/isViteServerSide.js +0 -68
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errBabelReact.js +0 -15
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errBabelSolid.js +0 -15
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errEsbuild.js +0 -38
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx1.js +0 -26
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.js +0 -85
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errPostcss.js +0 -30
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +0 -19
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +0 -19
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +0 -29
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +0 -13
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +0 -15
- package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet.js +0 -162
- package/dist/cjs/node/vite/shared/loggerNotProd/log.js +0 -102
- package/dist/cjs/node/vite/shared/loggerNotProd.js +0 -208
- package/dist/cjs/node/vite/shared/loggerVite/removeSuperfluousViteLog.js +0 -26
- package/dist/cjs/node/vite/shared/loggerVite.js +0 -54
- package/dist/cjs/node/vite/shared/normalizeId.js +0 -9
- package/dist/cjs/node/vite/shared/parseEsModule.js +0 -33
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/assertExtensions.js +0 -136
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -262
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles/ignorePatternsBuiltIn.js +0 -18
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +0 -252
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +0 -190
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/getConfigFileExport.js +0 -17
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/getPlusFilesAll.js +0 -127
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.js +0 -129
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +0 -195
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +0 -102
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +0 -425
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +0 -1151
- package/dist/cjs/node/vite/shared/rollupIsEsm.js +0 -15
- package/dist/cjs/node/vite/utils.js +0 -45
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/shared/NOT_SERIALIZABLE.js +0 -4
- package/dist/cjs/shared/RenderErrorPage.js +0 -6
- package/dist/cjs/shared/abort.js +0 -16
- package/dist/cjs/shared/addIs404ToPageProps.js +0 -18
- package/dist/cjs/shared/assertHookReturnedObject.js +0 -21
- package/dist/cjs/shared/assertOnBeforeRenderHookReturn.js +0 -21
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +0 -20
- package/dist/cjs/shared/createGlobalContextShared.js +0 -109
- package/dist/cjs/shared/createPageContextShared.js +0 -17
- package/dist/cjs/shared/determinePageIdOld.js +0 -11
- package/dist/cjs/shared/error-page.js +0 -40
- package/dist/cjs/shared/getPageContext.js +0 -6
- package/dist/cjs/shared/getPageContextRequestUrl.js +0 -16
- package/dist/cjs/shared/getPageContextUrlComputed.js +0 -132
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +0 -19
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/ClientDependency.js +0 -2
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +0 -50
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +0 -30
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/getExportNames.js +0 -15
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide.js +0 -59
- package/dist/cjs/shared/getPageFiles/analyzePageServerSide.js +0 -22
- package/dist/cjs/shared/getPageFiles/assert_exports_old_design.js +0 -24
- package/dist/cjs/shared/getPageFiles/fileTypes.js +0 -52
- package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +0 -102
- package/dist/cjs/shared/getPageFiles/getPageFileObject.js +0 -56
- package/dist/cjs/shared/getPageFiles/parseVirtualFileExportsGlobalEntry.js +0 -100
- package/dist/cjs/shared/getPageFiles.js +0 -7
- package/dist/cjs/shared/getProxyForPublicUsage.js +0 -56
- package/dist/cjs/shared/hooks/execHook.js +0 -147
- package/dist/cjs/shared/hooks/getHook.js +0 -173
- package/dist/cjs/shared/htmlElementIds.js +0 -5
- package/dist/cjs/shared/misc/isServerSideError.js +0 -4
- package/dist/cjs/shared/misc/pageContextInitIsPassedToClient.js +0 -4
- package/dist/cjs/shared/modifyUrl.js +0 -28
- package/dist/cjs/shared/modifyUrlSameOrigin.js +0 -47
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +0 -42
- package/dist/cjs/shared/page-configs/findPageConfig.js +0 -10
- package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +0 -65
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +0 -68
- package/dist/cjs/shared/page-configs/getConfigValueRuntime.js +0 -10
- package/dist/cjs/shared/page-configs/getConfigValueTyped.js +0 -32
- package/dist/cjs/shared/page-configs/getExportPath.js +0 -29
- package/dist/cjs/shared/page-configs/helpers.js +0 -27
- package/dist/cjs/shared/page-configs/loadAndParseVirtualFilePageEntry.js +0 -25
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +0 -287
- package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +0 -2
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +0 -1
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigsSerialized.js +0 -145
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +0 -290
- package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +0 -10
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +0 -80
- package/dist/cjs/shared/route/abort.js +0 -178
- package/dist/cjs/shared/route/debug.js +0 -23
- package/dist/cjs/shared/route/deduceRouteStringFromFilesystemPath.js +0 -52
- package/dist/cjs/shared/route/execHookGuard.js +0 -37
- package/dist/cjs/shared/route/execHookOnBeforeRoute.js +0 -84
- package/dist/cjs/shared/route/index.js +0 -107
- package/dist/cjs/shared/route/loadPageRoutes.js +0 -197
- package/dist/cjs/shared/route/noRouteMatch.js +0 -4
- package/dist/cjs/shared/route/resolvePrecedence.js +0 -93
- package/dist/cjs/shared/route/resolveRoute.js +0 -20
- package/dist/cjs/shared/route/resolveRouteFunction.js +0 -73
- package/dist/cjs/shared/route/resolveRouteString.js +0 -153
- package/dist/cjs/shared/route/resolveUrlPathname.js +0 -47
- package/dist/cjs/shared/route/routing.js +0 -9
- package/dist/cjs/shared/route/utils.js +0 -40
- package/dist/cjs/shared/utils.js +0 -49
- package/dist/cjs/types/Config/ConfigResolved.js +0 -2
- package/dist/cjs/types/Config.js +0 -2
- package/dist/cjs/types/FilePath.js +0 -2
- package/dist/cjs/types/PageConfig.js +0 -2
- package/dist/cjs/types/PageContext.js +0 -2
- package/dist/cjs/types/VikeGlobalInternal.js +0 -2
- package/dist/cjs/types/VikeNamespace.js +0 -2
- package/dist/cjs/types/ViteManifest.js +0 -2
- package/dist/cjs/types/defineConfig.js +0 -6
- package/dist/cjs/types/index-dreprecated.js +0 -3
- package/dist/cjs/types/index.js +0 -5
- package/dist/cjs/utils/PROJECT_VERSION.js +0 -5
- package/dist/cjs/utils/PromiseType.js +0 -2
- package/dist/cjs/utils/assert.js +0 -211
- package/dist/cjs/utils/assertIsBrowser.js +0 -8
- package/dist/cjs/utils/assertIsNotBrowser.js +0 -9
- package/dist/cjs/utils/assertKeys.js +0 -27
- package/dist/cjs/utils/assertNodeVersion.js +0 -14
- package/dist/cjs/utils/assertRoutingType.js +0 -29
- package/dist/cjs/utils/assertSetup.js +0 -171
- package/dist/cjs/utils/assertSingleInstance.js +0 -110
- package/dist/cjs/utils/assertVersion.js +0 -60
- package/dist/cjs/utils/capitalizeFirstLetter.js +0 -9
- package/dist/cjs/utils/cast.js +0 -6
- package/dist/cjs/utils/catchInfiniteLoop.js +0 -34
- package/dist/cjs/utils/changeEnumerable.js +0 -8
- package/dist/cjs/utils/checkType.js +0 -6
- package/dist/cjs/utils/compareString.js +0 -10
- package/dist/cjs/utils/createErrorWithCleanStackTrace.js +0 -39
- package/dist/cjs/utils/debug.js +0 -178
- package/dist/cjs/utils/debugGlob.js +0 -6
- package/dist/cjs/utils/deepEqual.js +0 -10
- package/dist/cjs/utils/escapeHtml.js +0 -13
- package/dist/cjs/utils/escapeRegex.js +0 -7
- package/dist/cjs/utils/findFile.js +0 -30
- package/dist/cjs/utils/findPackageJson.js +0 -18
- package/dist/cjs/utils/formatHintLog.js +0 -17
- package/dist/cjs/utils/freezePartial.js +0 -35
- package/dist/cjs/utils/genPromise.js +0 -51
- package/dist/cjs/utils/getFileExtension.js +0 -16
- package/dist/cjs/utils/getGlobalObject.js +0 -15
- package/dist/cjs/utils/getMostSimilar.js +0 -68
- package/dist/cjs/utils/getPropAccessNotation.js +0 -9
- package/dist/cjs/utils/getRandomId.js +0 -14
- package/dist/cjs/utils/getTerminalWidth.js +0 -7
- package/dist/cjs/utils/getValuePrintable.js +0 -10
- package/dist/cjs/utils/getViteRPC.js +0 -79
- package/dist/cjs/utils/hasProp.js +0 -50
- package/dist/cjs/utils/humanizeTime.js +0 -24
- package/dist/cjs/utils/includes.js +0 -13
- package/dist/cjs/utils/injectRollupInputs.js +0 -29
- package/dist/cjs/utils/isArray.js +0 -7
- package/dist/cjs/utils/isArrayOfStrings.js +0 -7
- package/dist/cjs/utils/isBrowser.js +0 -8
- package/dist/cjs/utils/isCallable.js +0 -6
- package/dist/cjs/utils/isDev.js +0 -20
- package/dist/cjs/utils/isDocker.js +0 -45
- package/dist/cjs/utils/isEqualStringList.js +0 -13
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +0 -66
- package/dist/cjs/utils/isHtml.js +0 -9
- package/dist/cjs/utils/isImportPath.js +0 -21
- package/dist/cjs/utils/isNodeJS.js +0 -16
- package/dist/cjs/utils/isNonRunnableDev.js +0 -12
- package/dist/cjs/utils/isNullish.js +0 -16
- package/dist/cjs/utils/isObject.js +0 -6
- package/dist/cjs/utils/isObjectOfStrings.js +0 -7
- package/dist/cjs/utils/isObjectWithKeys.js +0 -15
- package/dist/cjs/utils/isPlainObject.js +0 -19
- package/dist/cjs/utils/isPromise.js +0 -7
- package/dist/cjs/utils/isPropertyGetter.js +0 -7
- package/dist/cjs/utils/isReact.js +0 -23
- package/dist/cjs/utils/isRunnableDevEnvironment.js +0 -9
- package/dist/cjs/utils/isSameErrorMessage.js +0 -9
- package/dist/cjs/utils/isScriptFile.js +0 -67
- package/dist/cjs/utils/isVikeReactApp.js +0 -8
- package/dist/cjs/utils/isVitest.js +0 -6
- package/dist/cjs/utils/joinEnglish.js +0 -14
- package/dist/cjs/utils/normalizeHeaders.js +0 -17
- package/dist/cjs/utils/objectAssign.js +0 -14
- package/dist/cjs/utils/objectAssignSafe.js +0 -7
- package/dist/cjs/utils/objectDefineProperty.js +0 -7
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/cjs/utils/objectEntriesForEach.js +0 -7
- package/dist/cjs/utils/objectFilter.js +0 -10
- package/dist/cjs/utils/objectFromEntries.js +0 -7
- package/dist/cjs/utils/objectKeys.js +0 -9
- package/dist/cjs/utils/objectReplace.js +0 -9
- package/dist/cjs/utils/onPageVisibilityChange.js +0 -18
- package/dist/cjs/utils/pLimit.js +0 -134
- package/dist/cjs/utils/parseNpmPackage.js +0 -106
- package/dist/cjs/utils/parseUrl-extras.js +0 -110
- package/dist/cjs/utils/parseUrl.js +0 -338
- package/dist/cjs/utils/path.js +0 -59
- package/dist/cjs/utils/pick.js +0 -12
- package/dist/cjs/utils/preservePropertyGetters.js +0 -30
- package/dist/cjs/utils/redirectHard.js +0 -6
- package/dist/cjs/utils/removeEmptyLines.js +0 -9
- package/dist/cjs/utils/removeFileExtension.js +0 -6
- package/dist/cjs/utils/requireResolve.js +0 -214
- package/dist/cjs/utils/rollupSourceMap.js +0 -19
- package/dist/cjs/utils/sleep.js +0 -6
- package/dist/cjs/utils/slice.js +0 -35
- package/dist/cjs/utils/sorter.js +0 -117
- package/dist/cjs/utils/stringifyStringArray.js +0 -6
- package/dist/cjs/utils/stripAnsi.js +0 -21
- package/dist/cjs/utils/styleFileRE.js +0 -6
- package/dist/cjs/utils/throttle.js +0 -15
- package/dist/cjs/utils/trackLogs.js +0 -31
- package/dist/cjs/utils/trimWithAnsi.js +0 -40
- package/dist/cjs/utils/truncateString.js +0 -23
- package/dist/cjs/utils/unique.js +0 -6
- package/dist/cjs/utils/updateType.js +0 -9
- package/dist/cjs/utils/urlToFile.js +0 -36
- package/dist/cjs/utils/virtualFileId.js +0 -43
- package/dist/cjs/utils/warnIfErrorIsNotObject.js +0 -23
- package/dist/esm/client/runtime-server-routing/globalContext.js +0 -5
- package/dist/esm/client/shared/createGetGlobalContextClient.js +0 -65
- package/dist/esm/node/vite/plugins/pluginBuild.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginBuild.js +0 -20
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +0 -14
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +0 -92
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyzePageClientSide = analyzePageClientSide;
|
|
4
|
-
exports.analyzePageClientSideInit = analyzePageClientSideInit;
|
|
5
|
-
const analyzeExports_js_1 = require("./analyzePageClientSide/analyzeExports.js");
|
|
6
|
-
const determineClientEntry_js_1 = require("./analyzePageClientSide/determineClientEntry.js");
|
|
7
|
-
const getAllPageIdFiles_js_1 = require("./getAllPageIdFiles.js");
|
|
8
|
-
const getAllPageIdFiles_js_2 = require("./getAllPageIdFiles.js");
|
|
9
|
-
const utils_js_1 = require("../utils.js");
|
|
10
|
-
const getExportNames_js_1 = require("./analyzePageClientSide/getExportNames.js");
|
|
11
|
-
// TO-DO/next-major-release: remove analyzePageClientSide(), use analyzeClientSide() instead
|
|
12
|
-
function analyzePageClientSide(pageFilesAll, pageId) {
|
|
13
|
-
let pageFilesClientSide = (0, getAllPageIdFiles_js_1.getPageFilesClientSide)(pageFilesAll, pageId);
|
|
14
|
-
const pageFilesServerSide = (0, getAllPageIdFiles_js_2.getPageFilesServerSide)(pageFilesAll, pageId);
|
|
15
|
-
const { isHtmlOnly, isClientRouting } = (0, analyzeExports_js_1.analyzeExports)({ pageFilesClientSide, pageFilesServerSide, pageId });
|
|
16
|
-
if (isHtmlOnly) {
|
|
17
|
-
// HTML-only pages don't need any client-side `render()` hook. For apps that have both HTML-only and SSR/SPA pages, we skip the `.page.client.js` file that defines `render()` for HTML-only pages.
|
|
18
|
-
pageFilesClientSide = pageFilesClientSide.filter((p) => p.isEnv('CLIENT_ONLY') && !(0, getExportNames_js_1.getExportNames)(p).includes('render'));
|
|
19
|
-
pageFilesClientSide = removeOverriddenPageFiles(pageFilesClientSide);
|
|
20
|
-
}
|
|
21
|
-
const { clientEntries, clientDependencies } = (0, determineClientEntry_js_1.determineClientEntry)({
|
|
22
|
-
pageFilesClientSide,
|
|
23
|
-
pageFilesServerSide,
|
|
24
|
-
isHtmlOnly,
|
|
25
|
-
isClientRouting,
|
|
26
|
-
});
|
|
27
|
-
return { isHtmlOnly, isClientRouting, clientEntries, clientDependencies, pageFilesClientSide, pageFilesServerSide };
|
|
28
|
-
}
|
|
29
|
-
// TO-DO/next-major-release: remove
|
|
30
|
-
async function analyzePageClientSideInit(pageFilesAll, pageId, { sharedPageFilesAlreadyLoaded }) {
|
|
31
|
-
const pageFilesClientSide = (0, getAllPageIdFiles_js_1.getPageFilesClientSide)(pageFilesAll, pageId);
|
|
32
|
-
await Promise.all(pageFilesClientSide.map(async (p) => {
|
|
33
|
-
(0, utils_js_1.assert)(p.isEnv('CLIENT_ONLY') || p.isEnv('CLIENT_AND_SERVER'));
|
|
34
|
-
if (sharedPageFilesAlreadyLoaded && p.isEnv('CLIENT_AND_SERVER')) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
await p.loadExportNames?.();
|
|
38
|
-
/*
|
|
39
|
-
if (pageFile.exportNames) {
|
|
40
|
-
return pageFile.exportNames.includes(clientRouting)
|
|
41
|
-
}
|
|
42
|
-
if (pageFile.fileExports) {
|
|
43
|
-
return Object.keys(pageFile.fileExports).includes(clientRouting)
|
|
44
|
-
}
|
|
45
|
-
*/
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
// [WIP] Just an experiment needed by https://vike.dev/banner
|
|
49
|
-
// - Not sure I want to make something like a public API: the CSS of `_default.page.server.js` are still loaded -> weird DX.
|
|
50
|
-
function removeOverriddenPageFiles(pageFilesClientSide) {
|
|
51
|
-
const pageFilesClientSide_ = [];
|
|
52
|
-
for (const p of pageFilesClientSide) {
|
|
53
|
-
pageFilesClientSide_.push(p);
|
|
54
|
-
if ((0, getExportNames_js_1.getExportNames)(p).includes('overrideDefaultPages')) {
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return pageFilesClientSide_;
|
|
59
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyzePageServerSide = analyzePageServerSide;
|
|
4
|
-
const utils_js_1 = require("../utils.js");
|
|
5
|
-
const getAllPageIdFiles_js_1 = require("./getAllPageIdFiles.js");
|
|
6
|
-
async function analyzePageServerSide(pageFilesAll, pageId) {
|
|
7
|
-
const pageFilesServerSide = (0, getAllPageIdFiles_js_1.getPageFilesServerSide)(pageFilesAll, pageId);
|
|
8
|
-
const pageFilesServerSideOnly = pageFilesServerSide.filter((p) => p.fileType === '.page.server');
|
|
9
|
-
await Promise.all(pageFilesServerSideOnly.map(async (p) => {
|
|
10
|
-
// In production, `exportNames` are preload
|
|
11
|
-
if (p.exportNames) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
(0, utils_js_1.assert)(p.loadExportNames, pageId);
|
|
15
|
-
await p.loadExportNames();
|
|
16
|
-
}));
|
|
17
|
-
const hasOnBeforeRenderServerSideOnlyHook = pageFilesServerSideOnly.some(({ exportNames }) => {
|
|
18
|
-
(0, utils_js_1.assert)(exportNames);
|
|
19
|
-
return exportNames.includes('onBeforeRender');
|
|
20
|
-
});
|
|
21
|
-
return { hasOnBeforeRenderServerSideOnlyHook };
|
|
22
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// TO-DO/next-major-release: remove this
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.forbiddenDefaultExports = void 0;
|
|
5
|
-
exports.assertDefaultExports = assertDefaultExports;
|
|
6
|
-
exports.assertExportValues = assertExportValues;
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const enforceTrue = ['clientRouting'];
|
|
9
|
-
function assertExportValues(pageFile) {
|
|
10
|
-
enforceTrue.forEach((exportName) => {
|
|
11
|
-
(0, utils_js_1.assert)(pageFile.fileExports);
|
|
12
|
-
if (!(exportName in pageFile.fileExports))
|
|
13
|
-
return;
|
|
14
|
-
const explainer = `The value of \`${exportName}\` is only allowed to be \`true\`.`;
|
|
15
|
-
(0, utils_js_1.assertUsage)(pageFile.fileExports[exportName] !== false, `${pageFile.filePath} has \`export { ${exportName} }\` with the value \`false\` which is prohibited: remove \`export { ${exportName} }\` instead. (${explainer})`);
|
|
16
|
-
(0, utils_js_1.assertUsage)(pageFile.fileExports[exportName] === true, `${pageFile.filePath} has \`export { ${exportName} }\` with a forbidden value. ${explainer}`);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// Forbid exports such as `export default { render }`, because only `export { render }` can be statically analyzed by `es-module-lexer`.
|
|
20
|
-
const forbiddenDefaultExports = ['render', 'clientRouting', 'prerender', 'doNotPrerender'];
|
|
21
|
-
exports.forbiddenDefaultExports = forbiddenDefaultExports;
|
|
22
|
-
function assertDefaultExports(defaultExportName, filePath) {
|
|
23
|
-
(0, utils_js_1.assertUsage)(!forbiddenDefaultExports.includes(defaultExportName), `${filePath} has \`export default { ${defaultExportName} }\` which is prohibited, use \`export { ${defaultExportName} }\` instead.`);
|
|
24
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// TO-DO/next-major-release: remove
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.fileTypes = void 0;
|
|
5
|
-
exports.isValidFileType = isValidFileType;
|
|
6
|
-
exports.determineFileType = determineFileType;
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const isScriptFile_js_1 = require("../../utils/isScriptFile.js");
|
|
9
|
-
const fileTypes = [
|
|
10
|
-
'.page',
|
|
11
|
-
'.page.server',
|
|
12
|
-
'.page.route',
|
|
13
|
-
'.page.client',
|
|
14
|
-
// New type `.page.css`/`.page.server.css`/`.page.client.css` for `extensions[number].pageFileDist`.
|
|
15
|
-
// - Extensions using `pageFileDist` are expected to use a bundler that generates a `.css` colocated next to the original `.page.js` file (e.g. `/renderer/_default.page.server.css` for `/renderer/_default.page.server.js`.
|
|
16
|
-
// - Since these `.page.css` files Bundlers We can therefore expect that there isn't any `.page.server.sass`/...
|
|
17
|
-
'.css',
|
|
18
|
-
];
|
|
19
|
-
exports.fileTypes = fileTypes;
|
|
20
|
-
function isValidFileType(filePath) {
|
|
21
|
-
return ['.js', '.mjs', '.cjs', '.css'].some((ext) => filePath.endsWith(ext));
|
|
22
|
-
}
|
|
23
|
-
function determineFileType(filePath) {
|
|
24
|
-
{
|
|
25
|
-
const isCSS = filePath.endsWith('.css');
|
|
26
|
-
if (isCSS) {
|
|
27
|
-
/* This assert() is skipped to reduce client-side bundle size
|
|
28
|
-
assert(isImportPathNpmPackage(filePath), filePath) // `.css` page files are only supported for npm packages
|
|
29
|
-
*/
|
|
30
|
-
return '.css';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
(0, utils_js_1.assert)((0, isScriptFile_js_1.isScriptFile)(filePath), filePath);
|
|
34
|
-
const fileName = filePath.split('/').slice(-1)[0];
|
|
35
|
-
const parts = fileName.split('.');
|
|
36
|
-
const suffix1 = parts.slice(-3)[0];
|
|
37
|
-
const suffix2 = parts.slice(-2)[0];
|
|
38
|
-
if (suffix2 === 'page') {
|
|
39
|
-
return '.page';
|
|
40
|
-
}
|
|
41
|
-
(0, utils_js_1.assert)(suffix1 === 'page', filePath);
|
|
42
|
-
if (suffix2 === 'server') {
|
|
43
|
-
return '.page.server';
|
|
44
|
-
}
|
|
45
|
-
if (suffix2 === 'client') {
|
|
46
|
-
return '.page.client';
|
|
47
|
-
}
|
|
48
|
-
if (suffix2 === 'route') {
|
|
49
|
-
return '.page.route';
|
|
50
|
-
}
|
|
51
|
-
(0, utils_js_1.assert)(false, filePath);
|
|
52
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// TO-DO/next-major-release: remove this file
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getPageFilesClientSide = getPageFilesClientSide;
|
|
5
|
-
exports.getPageFilesServerSide = getPageFilesServerSide;
|
|
6
|
-
const utils_js_1 = require("../utils.js");
|
|
7
|
-
function getPageFilesClientSide(pageFilesAll, pageId) {
|
|
8
|
-
return determine(pageFilesAll, pageId, true);
|
|
9
|
-
}
|
|
10
|
-
function getPageFilesServerSide(pageFilesAll, pageId) {
|
|
11
|
-
return determine(pageFilesAll, pageId, false);
|
|
12
|
-
}
|
|
13
|
-
function determine(pageFilesAll, pageId, envIsClient) {
|
|
14
|
-
const env = envIsClient ? 'CLIENT_ONLY' : 'SERVER_ONLY';
|
|
15
|
-
const pageFilesRelevant = pageFilesAll
|
|
16
|
-
.filter((p) => p.isRelevant(pageId) && p.fileType !== '.page.route')
|
|
17
|
-
.sort(getPageFilesSorter(envIsClient, pageId));
|
|
18
|
-
// Load the `.page.js` files specific to `pageId`
|
|
19
|
-
const getPageIdFile = (iso) => {
|
|
20
|
-
const files = pageFilesRelevant.filter((p) => p.pageId === pageId && p.isEnv(iso ? 'CLIENT_AND_SERVER' : env));
|
|
21
|
-
(0, utils_js_1.assertUsage)(files.length <= 1, `Merge the following files into a single file: ${files.map((p) => p.filePath).join(' ')}`);
|
|
22
|
-
const pageIdFile = files[0];
|
|
23
|
-
(0, utils_js_1.assert)(pageIdFile === undefined || !pageIdFile.isDefaultPageFile);
|
|
24
|
-
return pageIdFile;
|
|
25
|
-
};
|
|
26
|
-
const pageIdFileEnv = getPageIdFile(false);
|
|
27
|
-
const pageIdFileIso = getPageIdFile(true);
|
|
28
|
-
// A page can have only one renderer. In other words: Multiple `renderer/` overwrite each other.
|
|
29
|
-
// Load only load renderer (`/renderer/_default.*`)
|
|
30
|
-
const getRendererFile = (iso) => pageFilesRelevant.filter((p) => p.isRendererPageFile && p.isEnv(iso ? 'CLIENT_AND_SERVER' : env))[0];
|
|
31
|
-
const rendererFileEnv = getRendererFile(false);
|
|
32
|
-
const rendererFileIso = getRendererFile(true);
|
|
33
|
-
// A page can load multiple `_default.page.*` files of the same `fileType`. In other words: non-renderer `_default.page.*` files are cumulative.
|
|
34
|
-
// The exception being HTML-only pages because we pick a single page file as client entry. We handle that use case at `renderPage()`.
|
|
35
|
-
const defaultFilesNonRenderer = pageFilesRelevant.filter((p) => p.isDefaultPageFile && !p.isRendererPageFile && (p.isEnv(env) || p.isEnv('CLIENT_AND_SERVER')));
|
|
36
|
-
// Ordered by `pageContext.exports` precedence
|
|
37
|
-
const pageFiles = [pageIdFileEnv, pageIdFileIso, ...defaultFilesNonRenderer, rendererFileEnv, rendererFileIso].filter(utils_js_1.isNotNullish);
|
|
38
|
-
return pageFiles;
|
|
39
|
-
}
|
|
40
|
-
function getPageFilesSorter(envIsClient, pageId) {
|
|
41
|
-
const env = envIsClient ? 'CLIENT_ONLY' : 'SERVER_ONLY';
|
|
42
|
-
const e1First = -1;
|
|
43
|
-
const e2First = +1;
|
|
44
|
-
const noOrder = 0;
|
|
45
|
-
return (e1, e2) => {
|
|
46
|
-
// `.page.js` files specific to `pageId` first
|
|
47
|
-
if (!e1.isDefaultPageFile && e2.isDefaultPageFile) {
|
|
48
|
-
return e1First;
|
|
49
|
-
}
|
|
50
|
-
if (!e2.isDefaultPageFile && e1.isDefaultPageFile) {
|
|
51
|
-
return e2First;
|
|
52
|
-
}
|
|
53
|
-
// Non-renderer `_default.page.*` before `renderer/**/_default.page.*`
|
|
54
|
-
{
|
|
55
|
-
const e1_isRenderer = e1.isRendererPageFile;
|
|
56
|
-
const e2_isRenderer = e2.isRendererPageFile;
|
|
57
|
-
if (!e1_isRenderer && e2_isRenderer) {
|
|
58
|
-
return e1First;
|
|
59
|
-
}
|
|
60
|
-
if (!e2_isRenderer && e1_isRenderer) {
|
|
61
|
-
return e2First;
|
|
62
|
-
}
|
|
63
|
-
(0, utils_js_1.assert)(e1_isRenderer === e2_isRenderer);
|
|
64
|
-
}
|
|
65
|
-
// Filesystem nearest first
|
|
66
|
-
{
|
|
67
|
-
const e1_distance = getPathDistance(pageId, e1.filePath);
|
|
68
|
-
const e2_distance = getPathDistance(pageId, e2.filePath);
|
|
69
|
-
if (e1_distance < e2_distance) {
|
|
70
|
-
return e1First;
|
|
71
|
-
}
|
|
72
|
-
if (e2_distance < e1_distance) {
|
|
73
|
-
return e2First;
|
|
74
|
-
}
|
|
75
|
-
(0, utils_js_1.assert)(e1_distance === e2_distance);
|
|
76
|
-
}
|
|
77
|
-
// `.page.server.js`/`.page.client.js` before `.page.js`
|
|
78
|
-
{
|
|
79
|
-
if (e1.isEnv(env) && e2.isEnv('CLIENT_AND_SERVER')) {
|
|
80
|
-
return e1First;
|
|
81
|
-
}
|
|
82
|
-
if (e2.isEnv(env) && e1.isEnv('CLIENT_AND_SERVER')) {
|
|
83
|
-
return e2First;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return noOrder;
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function getPathDistance(pathA, pathB) {
|
|
90
|
-
// Index of first different character
|
|
91
|
-
let idx = 0;
|
|
92
|
-
for (; idx < pathA.length && idx < pathB.length; idx++) {
|
|
93
|
-
if (pathA[idx] !== pathB[idx])
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
const pathAWithoutCommon = pathA.slice(idx);
|
|
97
|
-
const pathBWithoutCommon = pathB.slice(idx);
|
|
98
|
-
const distanceA = pathAWithoutCommon.split('/').length;
|
|
99
|
-
const distanceB = pathBWithoutCommon.split('/').length;
|
|
100
|
-
const distance = distanceA + distanceB;
|
|
101
|
-
return distance;
|
|
102
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// TO-DO/next-major-release: remove
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getPageFileObject = getPageFileObject;
|
|
5
|
-
const determinePageIdOld_js_1 = require("../determinePageIdOld.js");
|
|
6
|
-
const error_page_js_1 = require("../error-page.js");
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const fileTypes_js_1 = require("./fileTypes.js");
|
|
9
|
-
function getPageFileObject(filePath) {
|
|
10
|
-
const isRelevant = (pageId) => pageFile.pageId === pageId ||
|
|
11
|
-
(pageFile.isDefaultPageFile &&
|
|
12
|
-
(isRendererFilePath(pageFile.filePath) || isAncestorDefaultPage(pageId, pageFile.filePath)));
|
|
13
|
-
const fileType = (0, fileTypes_js_1.determineFileType)(filePath);
|
|
14
|
-
const isEnv = (env) => {
|
|
15
|
-
(0, utils_js_1.assert)(fileType !== '.page.route'); // We can't determine `.page.route.js`
|
|
16
|
-
if (env === 'CLIENT_ONLY') {
|
|
17
|
-
return fileType === '.page.client' || fileType === '.css';
|
|
18
|
-
}
|
|
19
|
-
if (env === 'SERVER_ONLY') {
|
|
20
|
-
return fileType === '.page.server';
|
|
21
|
-
}
|
|
22
|
-
if (env === 'CLIENT_AND_SERVER') {
|
|
23
|
-
return fileType === '.page';
|
|
24
|
-
}
|
|
25
|
-
(0, utils_js_1.assert)(false);
|
|
26
|
-
};
|
|
27
|
-
const pageFile = {
|
|
28
|
-
filePath,
|
|
29
|
-
fileType,
|
|
30
|
-
isEnv,
|
|
31
|
-
isRelevant,
|
|
32
|
-
isDefaultPageFile: isDefaultFilePath(filePath),
|
|
33
|
-
isRendererPageFile: fileType !== '.css' && isDefaultFilePath(filePath) && isRendererFilePath(filePath),
|
|
34
|
-
isErrorPageFile: (0, error_page_js_1.isErrorPageId)(filePath, false),
|
|
35
|
-
pageId: (0, determinePageIdOld_js_1.determinePageIdOld)(filePath),
|
|
36
|
-
};
|
|
37
|
-
return pageFile;
|
|
38
|
-
}
|
|
39
|
-
function isDefaultFilePath(filePath) {
|
|
40
|
-
if ((0, error_page_js_1.isErrorPageId)(filePath, false)) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
return filePath.includes('/_default');
|
|
44
|
-
}
|
|
45
|
-
function isRendererFilePath(filePath) {
|
|
46
|
-
return filePath.includes('/renderer/');
|
|
47
|
-
}
|
|
48
|
-
function isAncestorDefaultPage(pageId, defaultPageFilePath) {
|
|
49
|
-
(0, utils_js_1.assert)(!pageId.endsWith('/'));
|
|
50
|
-
(0, utils_js_1.assert)(!defaultPageFilePath.endsWith('/'));
|
|
51
|
-
(0, utils_js_1.assert)(isDefaultFilePath(defaultPageFilePath));
|
|
52
|
-
const defaultPageDir = (0, utils_js_1.slice)(defaultPageFilePath.split('/'), 0, -1)
|
|
53
|
-
.filter((filePathSegment) => filePathSegment !== '_default')
|
|
54
|
-
.join('/');
|
|
55
|
-
return pageId.startsWith(defaultPageDir);
|
|
56
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseVirtualFileExportsGlobalEntry = parseVirtualFileExportsGlobalEntry;
|
|
4
|
-
// TO-DO/next-major-release: remove old design code, and remove all assertions.
|
|
5
|
-
const utils_js_1 = require("../utils.js");
|
|
6
|
-
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
7
|
-
const getPageFileObject_js_1 = require("./getPageFileObject.js");
|
|
8
|
-
const fileTypes_js_1 = require("./fileTypes.js");
|
|
9
|
-
const parsePageConfigsSerialized_js_1 = require("../page-configs/serialize/parsePageConfigsSerialized.js");
|
|
10
|
-
function parseVirtualFileExportsGlobalEntry(virtualFileExportsGlobalEntry) {
|
|
11
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageFilesLazy', 'object'));
|
|
12
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageFilesEager', 'object'));
|
|
13
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageFilesExportNamesLazy', 'object'));
|
|
14
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageFilesExportNamesEager', 'object'));
|
|
15
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry.pageFilesLazy, '.page'));
|
|
16
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry.pageFilesLazy, '.page.client') ||
|
|
17
|
-
(0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry.pageFilesLazy, '.page.server'));
|
|
18
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageFilesList', 'string[]'));
|
|
19
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageConfigsSerialized'));
|
|
20
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(virtualFileExportsGlobalEntry, 'pageConfigGlobalSerialized'));
|
|
21
|
-
const { pageConfigsSerialized, pageConfigGlobalSerialized } = virtualFileExportsGlobalEntry;
|
|
22
|
-
assertPageConfigsSerialized(pageConfigsSerialized);
|
|
23
|
-
assertPageConfigGlobalSerialized(pageConfigGlobalSerialized);
|
|
24
|
-
const { pageConfigs, pageConfigGlobal } = (0, parsePageConfigsSerialized_js_1.parsePageConfigsSerialized)(pageConfigsSerialized, pageConfigGlobalSerialized);
|
|
25
|
-
const pageFilesMap = {};
|
|
26
|
-
parseGlobResult(virtualFileExportsGlobalEntry.pageFilesLazy).forEach(({ filePath, pageFile, globValue }) => {
|
|
27
|
-
pageFile = pageFilesMap[filePath] = pageFilesMap[filePath] ?? pageFile;
|
|
28
|
-
const loadModule = globValue;
|
|
29
|
-
assertLoadModule(loadModule);
|
|
30
|
-
pageFile.loadFile = async () => {
|
|
31
|
-
if (!('fileExports' in pageFile)) {
|
|
32
|
-
pageFile.fileExports = await loadModule();
|
|
33
|
-
(0, assert_exports_old_design_js_1.assertExportValues)(pageFile);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
parseGlobResult(virtualFileExportsGlobalEntry.pageFilesExportNamesLazy).forEach(({ filePath, pageFile, globValue }) => {
|
|
38
|
-
pageFile = pageFilesMap[filePath] = pageFilesMap[filePath] ?? pageFile;
|
|
39
|
-
const loadModule = globValue;
|
|
40
|
-
assertLoadModule(loadModule);
|
|
41
|
-
pageFile.loadExportNames = async () => {
|
|
42
|
-
if (!('exportNames' in pageFile)) {
|
|
43
|
-
const moduleExports = await loadModule();
|
|
44
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(moduleExports, 'exportNames', 'string[]'), pageFile.filePath);
|
|
45
|
-
pageFile.exportNames = moduleExports.exportNames;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
// `pageFilesEager` contains `.page.route.js` files
|
|
50
|
-
parseGlobResult(virtualFileExportsGlobalEntry.pageFilesEager).forEach(({ filePath, pageFile, globValue }) => {
|
|
51
|
-
pageFile = pageFilesMap[filePath] = pageFilesMap[filePath] ?? pageFile;
|
|
52
|
-
const moduleExports = globValue;
|
|
53
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(moduleExports));
|
|
54
|
-
pageFile.fileExports = moduleExports;
|
|
55
|
-
});
|
|
56
|
-
parseGlobResult(virtualFileExportsGlobalEntry.pageFilesExportNamesEager).forEach(({ filePath, pageFile, globValue }) => {
|
|
57
|
-
pageFile = pageFilesMap[filePath] = pageFilesMap[filePath] ?? pageFile;
|
|
58
|
-
const moduleExports = globValue;
|
|
59
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(moduleExports));
|
|
60
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(moduleExports, 'exportNames', 'string[]'), pageFile.filePath);
|
|
61
|
-
pageFile.exportNames = moduleExports.exportNames;
|
|
62
|
-
});
|
|
63
|
-
virtualFileExportsGlobalEntry.pageFilesList.forEach((filePath) => {
|
|
64
|
-
pageFilesMap[filePath] = pageFilesMap[filePath] ?? (0, getPageFileObject_js_1.getPageFileObject)(filePath);
|
|
65
|
-
});
|
|
66
|
-
const pageFilesAll = Object.values(pageFilesMap);
|
|
67
|
-
pageFilesAll.forEach(({ filePath }) => {
|
|
68
|
-
(0, utils_js_1.assert)(!filePath.includes('\\'));
|
|
69
|
-
});
|
|
70
|
-
return { pageFilesAll, pageConfigs, pageConfigGlobal };
|
|
71
|
-
}
|
|
72
|
-
function parseGlobResult(globObject) {
|
|
73
|
-
const ret = [];
|
|
74
|
-
Object.entries(globObject).forEach(([fileType, globFiles]) => {
|
|
75
|
-
(0, utils_js_1.cast)(fileType);
|
|
76
|
-
(0, utils_js_1.assert)(fileTypes_js_1.fileTypes.includes(fileType));
|
|
77
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(globFiles));
|
|
78
|
-
Object.entries(globFiles).forEach(([filePath, globValue]) => {
|
|
79
|
-
const pageFile = (0, getPageFileObject_js_1.getPageFileObject)(filePath);
|
|
80
|
-
(0, utils_js_1.assert)(pageFile.fileType === fileType);
|
|
81
|
-
ret.push({ filePath, pageFile, globValue });
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
return ret;
|
|
85
|
-
}
|
|
86
|
-
function assertLoadModule(globValue) {
|
|
87
|
-
(0, utils_js_1.assert)((0, utils_js_1.isCallable)(globValue));
|
|
88
|
-
}
|
|
89
|
-
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
90
|
-
(0, utils_js_1.assert)((0, utils_js_1.isArray)(pageConfigsSerialized));
|
|
91
|
-
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
92
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
|
|
93
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
|
|
94
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
|
|
95
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
99
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
100
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPageFilesServerSide = exports.getPageFilesClientSide = void 0;
|
|
4
|
-
var getAllPageIdFiles_js_1 = require("./getPageFiles/getAllPageIdFiles.js");
|
|
5
|
-
Object.defineProperty(exports, "getPageFilesClientSide", { enumerable: true, get: function () { return getAllPageIdFiles_js_1.getPageFilesClientSide; } });
|
|
6
|
-
var getAllPageIdFiles_js_2 = require("./getPageFiles/getAllPageIdFiles.js");
|
|
7
|
-
Object.defineProperty(exports, "getPageFilesServerSide", { enumerable: true, get: function () { return getAllPageIdFiles_js_2.getPageFilesServerSide; } });
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProxyForPublicUsage = getProxyForPublicUsage;
|
|
4
|
-
// We use a proxy instead of property getters.
|
|
5
|
-
// - The issue with property getters is that they can't be `writable: true` but we do want the user to be able to modify the value of internal properties.
|
|
6
|
-
// ```console
|
|
7
|
-
// TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
|
|
8
|
-
// ```
|
|
9
|
-
// - Previous implementation using property getters: https://github.com/vikejs/vike/blob/4dbb354b0bcec04e862041fc9183fc4691bb8711/vike/utils/makePublicCopy.ts
|
|
10
|
-
// Show warning when user is accessing internal `_` properties.
|
|
11
|
-
const NOT_SERIALIZABLE_js_1 = require("./NOT_SERIALIZABLE.js");
|
|
12
|
-
const utils_js_1 = require("./utils.js");
|
|
13
|
-
function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
|
|
14
|
-
return new Proxy(obj, {
|
|
15
|
-
get: getTrapGet(obj, objName, skipOnInternalProp, fallback),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
|
|
19
|
-
return function (_, prop) {
|
|
20
|
-
const propStr = String(prop);
|
|
21
|
-
if (prop === '_isProxyObject')
|
|
22
|
-
return true;
|
|
23
|
-
if (!skipOnInternalProp)
|
|
24
|
-
onInternalProp(propStr, objName);
|
|
25
|
-
if (fallback && !(prop in obj)) {
|
|
26
|
-
// Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
|
|
27
|
-
// Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
|
|
28
|
-
return fallback(prop);
|
|
29
|
-
}
|
|
30
|
-
const val = obj[prop];
|
|
31
|
-
onNotSerializable(propStr, val, objName);
|
|
32
|
-
return val;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function onNotSerializable(propStr, val, objName) {
|
|
36
|
-
if (val !== NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE)
|
|
37
|
-
return;
|
|
38
|
-
const propName = (0, utils_js_1.getPropAccessNotation)(propStr);
|
|
39
|
-
(0, utils_js_1.assert)((0, utils_js_1.isBrowser)());
|
|
40
|
-
(0, utils_js_1.assertUsage)(false, `Can't access ${objName}${propName} on the client side. Because it can't be serialized, see server logs.`);
|
|
41
|
-
}
|
|
42
|
-
function onInternalProp(propStr, objName) {
|
|
43
|
-
// - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
44
|
-
// - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
|
|
45
|
-
// - Where import.meta.CLIENT is defined by Vike
|
|
46
|
-
// - Using ({}).CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_({})
|
|
47
|
-
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use ({}).SSR
|
|
48
|
-
if ((0, utils_js_1.isBrowser)())
|
|
49
|
-
return;
|
|
50
|
-
// TO-DO/soon/proxy: remove this and only warn on built-in access instead
|
|
51
|
-
if (propStr === '_configFromHook')
|
|
52
|
-
return;
|
|
53
|
-
if (propStr.startsWith('_')) {
|
|
54
|
-
(0, utils_js_1.assertWarning)(false, `Using internal ${objName}.${propStr} which may break in any minor version update. Reach out on GitHub to request official support for your use case.`, { onlyOnce: true, showStackTrace: true });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.execHook = execHook;
|
|
4
|
-
exports.execHookGlobal = execHookGlobal;
|
|
5
|
-
exports.execHookDirect = execHookDirect;
|
|
6
|
-
exports.execHookDirectSingle = execHookDirectSingle;
|
|
7
|
-
exports.execHookDirectSingleWithReturn = execHookDirectSingleWithReturn;
|
|
8
|
-
exports.execHookDirectWithoutPageContext = execHookDirectWithoutPageContext;
|
|
9
|
-
exports.execHookDirectSync = execHookDirectSync;
|
|
10
|
-
exports.getPageContext = getPageContext;
|
|
11
|
-
exports.providePageContext = providePageContext;
|
|
12
|
-
exports.isUserHookError = isUserHookError;
|
|
13
|
-
const assert_js_1 = require("../../utils/assert.js");
|
|
14
|
-
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
15
|
-
const humanizeTime_js_1 = require("../../utils/humanizeTime.js");
|
|
16
|
-
const isObject_js_1 = require("../../utils/isObject.js");
|
|
17
|
-
const getHook_js_1 = require("./getHook.js");
|
|
18
|
-
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
19
|
-
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/execHook.ts', {
|
|
20
|
-
userHookErrors: new WeakMap(),
|
|
21
|
-
pageContext: null,
|
|
22
|
-
});
|
|
23
|
-
async function execHook(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
24
|
-
const hooks = (0, getHook_js_1.getHookFromPageContextNew)(hookName, pageContext);
|
|
25
|
-
return await execHookDirect(hooks, pageContext, preparePageContextForPublicUsage);
|
|
26
|
-
}
|
|
27
|
-
async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
|
|
28
|
-
const hooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(pageConfigGlobal, hookName);
|
|
29
|
-
const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
|
|
30
|
-
await Promise.all(hooks.map(async (hook) => {
|
|
31
|
-
await execHookDirectAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
async function execHookDirect(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
35
|
-
if (!hooks.length)
|
|
36
|
-
return [];
|
|
37
|
-
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
38
|
-
const hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
39
|
-
const hookReturn = await execHookDirectAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
40
|
-
return { ...hook, hookReturn };
|
|
41
|
-
}));
|
|
42
|
-
return hooksWithResult;
|
|
43
|
-
}
|
|
44
|
-
async function execHookDirectSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
45
|
-
const hooksWithResult = await execHookDirect([hook], pageContext, preparePageContextForPublicUsage);
|
|
46
|
-
const { hookReturn } = hooksWithResult[0];
|
|
47
|
-
(0, assert_js_1.assertUsage)(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
48
|
-
}
|
|
49
|
-
async function execHookDirectSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
50
|
-
const hooksWithResult = await execHookDirect([hook], pageContext, preparePageContextForPublicUsage);
|
|
51
|
-
const { hookReturn } = hooksWithResult[0];
|
|
52
|
-
return { hookReturn };
|
|
53
|
-
}
|
|
54
|
-
function isUserHookError(err) {
|
|
55
|
-
if (!(0, isObject_js_1.isObject)(err))
|
|
56
|
-
return false;
|
|
57
|
-
return globalObject.userHookErrors.get(err) ?? false;
|
|
58
|
-
}
|
|
59
|
-
async function execHookDirectWithoutPageContext(hookFnCaller, hook) {
|
|
60
|
-
const { hookName, hookFilePath, hookTimeout } = hook;
|
|
61
|
-
const hookReturn = await execHookDirectAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
|
|
62
|
-
return hookReturn;
|
|
63
|
-
}
|
|
64
|
-
function execHookDirectAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
65
|
-
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn }, } = hook;
|
|
66
|
-
let resolve;
|
|
67
|
-
let reject;
|
|
68
|
-
const promise = new Promise((resolve_, reject_) => {
|
|
69
|
-
resolve = (ret) => {
|
|
70
|
-
clearTimeouts();
|
|
71
|
-
resolve_(ret);
|
|
72
|
-
};
|
|
73
|
-
reject = (err) => {
|
|
74
|
-
clearTimeouts();
|
|
75
|
-
reject_(err);
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
const clearTimeouts = () => {
|
|
79
|
-
if (currentTimeoutWarn)
|
|
80
|
-
clearTimeout(currentTimeoutWarn);
|
|
81
|
-
if (currentTimeoutErr)
|
|
82
|
-
clearTimeout(currentTimeoutErr);
|
|
83
|
-
};
|
|
84
|
-
const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
|
|
85
|
-
setTimeout(() => {
|
|
86
|
-
(0, assert_js_1.assertWarning)(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${(0, humanizeTime_js_1.humanizeTime)(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
|
|
87
|
-
}, timeoutWarn);
|
|
88
|
-
const currentTimeoutErr = isNotDisabled(timeoutErr) &&
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
const err = (0, assert_js_1.getProjectError)(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${(0, humanizeTime_js_1.humanizeTime)(timeoutErr)} (https://vike.dev/hooksTimeout)`);
|
|
91
|
-
reject(err);
|
|
92
|
-
}, timeoutErr);
|
|
93
|
-
(async () => {
|
|
94
|
-
try {
|
|
95
|
-
providePageContextInternal(pageContextForPublicUsage);
|
|
96
|
-
const ret = await hookFnCaller();
|
|
97
|
-
resolve(ret);
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
if ((0, isObject_js_1.isObject)(err)) {
|
|
101
|
-
globalObject.userHookErrors.set(err, { hookName, hookFilePath });
|
|
102
|
-
}
|
|
103
|
-
reject(err);
|
|
104
|
-
}
|
|
105
|
-
})();
|
|
106
|
-
return promise;
|
|
107
|
-
}
|
|
108
|
-
function execHookDirectSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
109
|
-
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
110
|
-
providePageContextInternal(pageContextForPublicUsage);
|
|
111
|
-
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
112
|
-
return { hookReturn };
|
|
113
|
-
}
|
|
114
|
-
function isNotDisabled(timeout) {
|
|
115
|
-
return !!timeout && timeout !== Infinity;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
119
|
-
*
|
|
120
|
-
* https://vike.dev/getPageContext
|
|
121
|
-
*/
|
|
122
|
-
function getPageContext() {
|
|
123
|
-
const { pageContext } = globalObject;
|
|
124
|
-
if (!pageContext)
|
|
125
|
-
return null;
|
|
126
|
-
const pageContextForPublicUsage = pageContext._isProxyObject
|
|
127
|
-
? // providePageContext() is called on the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus it's already a proxy
|
|
128
|
-
pageContext
|
|
129
|
-
: (0, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage)(pageContext);
|
|
130
|
-
return pageContextForPublicUsage;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Provide `pageContext` for universal hooks.
|
|
134
|
-
*
|
|
135
|
-
* https://vike.dev/getPageContext
|
|
136
|
-
*/
|
|
137
|
-
function providePageContext(pageContext) {
|
|
138
|
-
providePageContextInternal(pageContext);
|
|
139
|
-
}
|
|
140
|
-
function providePageContextInternal(pageContext) {
|
|
141
|
-
globalObject.pageContext = pageContext;
|
|
142
|
-
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
143
|
-
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
144
|
-
Promise.resolve().then(() => {
|
|
145
|
-
globalObject.pageContext = null;
|
|
146
|
-
});
|
|
147
|
-
}
|