vike 0.4.239 → 0.4.240
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.d.ts +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} +2 -2
- package/dist/esm/client/runtime-client-routing/{globalContext.js → getGlobalContextClientInternal.js} +8 -4
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +6 -6
- package/dist/esm/client/runtime-client-routing/isClientSideRoutable.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +4 -4
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +15 -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.d.ts +4 -2
- package/dist/esm/node/prerender/runPrerender.js +5 -2
- package/dist/esm/node/runtime/globalContext.d.ts +15 -2
- package/dist/esm/node/runtime/globalContext.js +46 -32
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +8 -4
- package/dist/esm/node/runtime/renderPage.d.ts +4 -2
- package/dist/esm/node/vite/index.js +41 -17
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/handleAssetsManifest.d.ts +4 -0
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/handleAssetsManifest.js +21 -6
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildApp.js +24 -20
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildConfig.js +20 -6
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistFileNames.d.ts +1 -1
- package/dist/esm/node/vite/plugins/build/pluginDistFileNames.js +253 -0
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistPackageJsonFile.d.ts +1 -1
- package/dist/esm/node/vite/plugins/build/pluginDistPackageJsonFile.js +40 -0
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginModuleBanner.d.ts +1 -1
- package/dist/esm/node/vite/plugins/build/pluginModuleBanner.js +49 -0
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginProdBuildEntry.js +4 -2
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginSuppressRollupWarning.d.ts +1 -1
- package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginSuppressRollupWarning.js +27 -23
- package/dist/esm/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.d.ts +7 -0
- package/dist/esm/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js +47 -0
- package/dist/esm/node/vite/plugins/{pluginNonRunnableDev.d.ts → non-runnable-dev/pluginViteRPC.d.ts} +3 -7
- package/dist/esm/node/vite/plugins/non-runnable-dev/pluginViteRPC.js +30 -0
- package/dist/esm/node/vite/plugins/pluginBaseUrls.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBaseUrls.js +39 -33
- package/dist/esm/node/vite/plugins/pluginCommon.js +8 -28
- package/dist/esm/node/vite/plugins/pluginDev/determineFsAllowList.js +0 -1
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
- package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +88 -63
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +108 -92
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +39 -23
- package/dist/esm/node/vite/plugins/pluginFileEnv.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +117 -92
- package/dist/esm/node/vite/plugins/pluginPreview.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginPreview.js +38 -30
- 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 +87 -0
- package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +1 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +67 -47
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +13 -9
- package/dist/esm/node/vite/plugins/pluginWorkaroundVite6HmrRegression.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +26 -24
- package/dist/esm/node/vite/shared/getMagicString.d.ts +1 -1
- package/dist/esm/node/vite/shared/getMagicString.js +2 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +4 -4
- 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/debug.js +10 -0
- package/dist/esm/utils/findPackageJson.js +0 -1
- package/dist/esm/utils/getViteRPC.js +0 -2
- package/dist/esm/utils/isDev.js +3 -1
- package/dist/esm/utils/isNonRunnableDev.js +2 -2
- package/dist/esm/utils/requireResolve.js +0 -1
- package/dist/esm/utils/virtualFileId.d.ts +4 -0
- package/dist/esm/utils/virtualFileId.js +14 -11
- package/package.json +6 -25
- 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 -777
- 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 -572
- 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 -48
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +0 -342
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +0 -179
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -220
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +0 -254
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -36
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +0 -41
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +0 -109
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +0 -63
- package/dist/cjs/node/vite/plugins/pluginBuild.js +0 -21
- package/dist/cjs/node/vite/plugins/pluginCommon/assertResolveAlias.js +0 -88
- package/dist/cjs/node/vite/plugins/pluginCommon.js +0 -197
- 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 -107
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +0 -87
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +0 -227
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +0 -99
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +0 -149
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +0 -52
- package/dist/cjs/node/vite/plugins/pluginPreview.js +0 -76
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +0 -69
- package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +0 -49
- 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 -215
- package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +0 -15
- 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 -39
- 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/pluginDistFileNames.js +0 -249
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -34
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +0 -39
- package/dist/esm/node/vite/plugins/pluginBuild.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginBuild.js +0 -19
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +0 -50
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +0 -67
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildApp.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildConfig.d.ts +0 -0
- /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginProdBuildEntry.d.ts +0 -0
|
@@ -1,829 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.processStream = processStream;
|
|
7
|
-
exports.streamToString = streamToString;
|
|
8
|
-
exports.stampPipe = stampPipe;
|
|
9
|
-
exports.pipeStream = pipeStream;
|
|
10
|
-
exports.pipeWebStream = pipeWebStream;
|
|
11
|
-
exports.pipeNodeStream = pipeNodeStream;
|
|
12
|
-
exports.getStreamReadableNode = getStreamReadableNode;
|
|
13
|
-
exports.getStreamReadableWeb = getStreamReadableWeb;
|
|
14
|
-
exports.pipeToStreamWritableNode = pipeToStreamWritableNode;
|
|
15
|
-
exports.pipeToStreamWritableWeb = pipeToStreamWritableWeb;
|
|
16
|
-
exports.isStream = isStream;
|
|
17
|
-
exports.isStreamPipeWeb = isStreamPipeWeb;
|
|
18
|
-
exports.isStreamPipeNode = isStreamPipeNode;
|
|
19
|
-
exports.isStreamReadableWeb = isStreamReadableWeb;
|
|
20
|
-
exports.isStreamReadableNode = isStreamReadableNode;
|
|
21
|
-
exports.getStreamName = getStreamName;
|
|
22
|
-
exports.inferStreamName = inferStreamName;
|
|
23
|
-
exports.streamReadableWebToString = streamReadableWebToString;
|
|
24
|
-
exports.streamPipeNodeToString = streamPipeNodeToString;
|
|
25
|
-
exports.isStreamWritableWeb = isStreamWritableWeb;
|
|
26
|
-
exports.isStreamWritableNode = isStreamWritableNode;
|
|
27
|
-
const utils_js_1 = require("../../utils.js");
|
|
28
|
-
const react_streaming_js_1 = require("./stream/react-streaming.js");
|
|
29
|
-
const import_1 = require("@brillout/import");
|
|
30
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
31
|
-
const debug = (0, utils_js_1.createDebugger)('vike:stream');
|
|
32
|
-
function isStreamReadableWeb(thing) {
|
|
33
|
-
return typeof ReadableStream !== 'undefined' && thing instanceof ReadableStream;
|
|
34
|
-
}
|
|
35
|
-
function isStreamWritableWeb(thing) {
|
|
36
|
-
return typeof WritableStream !== 'undefined' && thing instanceof WritableStream;
|
|
37
|
-
}
|
|
38
|
-
function isStreamReadableNode(thing) {
|
|
39
|
-
if (isStreamReadableWeb(thing)) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
// https://stackoverflow.com/questions/17009975/how-to-test-if-an-object-is-a-stream-in-nodejs/37022523#37022523
|
|
43
|
-
return (0, utils_js_1.hasProp)(thing, 'read', 'function');
|
|
44
|
-
}
|
|
45
|
-
function isStreamWritableNode(thing) {
|
|
46
|
-
if (isStreamWritableWeb(thing)) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
// https://stackoverflow.com/questions/17009975/how-to-test-if-an-object-is-a-stream-in-nodejs/37022523#37022523
|
|
50
|
-
return (0, utils_js_1.hasProp)(thing, 'write', 'function');
|
|
51
|
-
}
|
|
52
|
-
async function streamReadableNodeToString(readableNode) {
|
|
53
|
-
// Copied from: https://stackoverflow.com/questions/10623798/how-do-i-read-the-contents-of-a-node-js-stream-into-a-string-variable/49428486#49428486
|
|
54
|
-
const chunks = [];
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
readableNode.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
57
|
-
readableNode.on('error', (err) => reject(err));
|
|
58
|
-
readableNode.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async function streamReadableWebToString(readableWeb) {
|
|
62
|
-
const reader = readableWeb.getReader();
|
|
63
|
-
const { decode, getClosingChunk } = decodeChunks();
|
|
64
|
-
let str = '';
|
|
65
|
-
while (true) {
|
|
66
|
-
const { done, value } = await reader.read();
|
|
67
|
-
if (done)
|
|
68
|
-
break;
|
|
69
|
-
str += decode(value);
|
|
70
|
-
}
|
|
71
|
-
str += getClosingChunk();
|
|
72
|
-
return str;
|
|
73
|
-
}
|
|
74
|
-
async function stringToStreamReadableNode(str) {
|
|
75
|
-
const { Readable } = await loadStreamNodeModule();
|
|
76
|
-
return Readable.from(str);
|
|
77
|
-
}
|
|
78
|
-
function stringToStreamReadableWeb(str) {
|
|
79
|
-
// ReadableStream.from() spec discussion: https://github.com/whatwg/streams/issues/1018
|
|
80
|
-
assertReadableStreamConstructor();
|
|
81
|
-
const readableStream = new ReadableStream({
|
|
82
|
-
start(controller) {
|
|
83
|
-
controller.enqueue(encodeForWebStream(str));
|
|
84
|
-
controller.close();
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
return readableStream;
|
|
88
|
-
}
|
|
89
|
-
function stringToStreamPipeNode(str) {
|
|
90
|
-
return (writable) => {
|
|
91
|
-
writable.write(str);
|
|
92
|
-
writable.end();
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function stringToStreamPipeWeb(str) {
|
|
96
|
-
return (writable) => {
|
|
97
|
-
const writer = writable.getWriter();
|
|
98
|
-
writer.write(encodeForWebStream(str));
|
|
99
|
-
writer.close();
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async function streamPipeNodeToString(streamPipeNode) {
|
|
103
|
-
let str = '';
|
|
104
|
-
let resolve;
|
|
105
|
-
let reject;
|
|
106
|
-
const promise = new Promise((resolve_, reject_) => {
|
|
107
|
-
resolve = () => resolve_(str);
|
|
108
|
-
reject = reject_;
|
|
109
|
-
});
|
|
110
|
-
const { Writable } = await loadStreamNodeModule();
|
|
111
|
-
const writable = new Writable({
|
|
112
|
-
write(chunk, _encoding, callback) {
|
|
113
|
-
const s = chunk.toString();
|
|
114
|
-
(0, utils_js_1.assert)(typeof s === 'string');
|
|
115
|
-
str += s;
|
|
116
|
-
callback();
|
|
117
|
-
},
|
|
118
|
-
final(callback) {
|
|
119
|
-
resolve();
|
|
120
|
-
callback();
|
|
121
|
-
},
|
|
122
|
-
destroy(err) {
|
|
123
|
-
if (err) {
|
|
124
|
-
reject(err);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
resolve();
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
streamPipeNode(writable);
|
|
132
|
-
return promise;
|
|
133
|
-
}
|
|
134
|
-
function streamPipeWebToString(streamPipeWeb) {
|
|
135
|
-
const { decode, getClosingChunk } = decodeChunks();
|
|
136
|
-
let str = '';
|
|
137
|
-
let resolve;
|
|
138
|
-
const promise = new Promise((r) => (resolve = r));
|
|
139
|
-
const writable = new WritableStream({
|
|
140
|
-
write(chunk) {
|
|
141
|
-
str += decode(chunk);
|
|
142
|
-
},
|
|
143
|
-
close() {
|
|
144
|
-
str += getClosingChunk();
|
|
145
|
-
resolve(str);
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
streamPipeWeb(writable);
|
|
149
|
-
return promise;
|
|
150
|
-
}
|
|
151
|
-
async function getStreamReadableNode(htmlRender) {
|
|
152
|
-
if (typeof htmlRender === 'string') {
|
|
153
|
-
return stringToStreamReadableNode(htmlRender);
|
|
154
|
-
}
|
|
155
|
-
if (isStreamReadableNode(htmlRender)) {
|
|
156
|
-
return htmlRender;
|
|
157
|
-
}
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
function getStreamReadableWeb(htmlRender) {
|
|
161
|
-
if (typeof htmlRender === 'string') {
|
|
162
|
-
return stringToStreamReadableWeb(htmlRender);
|
|
163
|
-
}
|
|
164
|
-
if (isStreamReadableWeb(htmlRender)) {
|
|
165
|
-
return htmlRender;
|
|
166
|
-
}
|
|
167
|
-
if (isStreamPipeWeb(htmlRender)) {
|
|
168
|
-
const streamPipeWeb = getStreamPipeWeb(htmlRender);
|
|
169
|
-
(0, utils_js_1.assert)(streamPipeWeb);
|
|
170
|
-
const { readable, writable } = new TransformStream();
|
|
171
|
-
streamPipeWeb(writable);
|
|
172
|
-
return readable;
|
|
173
|
-
}
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
function pipeToStreamWritableWeb(htmlRender, writable) {
|
|
177
|
-
if (typeof htmlRender === 'string') {
|
|
178
|
-
const streamPipeWeb = stringToStreamPipeWeb(htmlRender);
|
|
179
|
-
streamPipeWeb(writable);
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
if (isStreamReadableWeb(htmlRender)) {
|
|
183
|
-
htmlRender.pipeTo(writable);
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
if (isStreamPipeWeb(htmlRender)) {
|
|
187
|
-
const streamPipeWeb = getStreamPipeWeb(htmlRender);
|
|
188
|
-
(0, utils_js_1.assert)(streamPipeWeb);
|
|
189
|
-
streamPipeWeb(writable);
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
if (isStreamReadableNode(htmlRender) || isStreamPipeNode(htmlRender)) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
(0, utils_js_1.checkType)(htmlRender);
|
|
196
|
-
(0, utils_js_1.assert)(false);
|
|
197
|
-
}
|
|
198
|
-
function pipeToStreamWritableNode(htmlRender, writable) {
|
|
199
|
-
if (typeof htmlRender === 'string') {
|
|
200
|
-
const streamPipeNode = stringToStreamPipeNode(htmlRender);
|
|
201
|
-
streamPipeNode(writable);
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
if (isStreamReadableNode(htmlRender)) {
|
|
205
|
-
htmlRender.pipe(writable);
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
if (isStreamPipeNode(htmlRender)) {
|
|
209
|
-
const streamPipeNode = getStreamPipeNode(htmlRender);
|
|
210
|
-
(0, utils_js_1.assert)(streamPipeNode);
|
|
211
|
-
streamPipeNode(writable);
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
if (isStreamReadableWeb(htmlRender) || isStreamPipeWeb(htmlRender)) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
(0, utils_js_1.checkType)(htmlRender);
|
|
218
|
-
(0, utils_js_1.assert)(false);
|
|
219
|
-
}
|
|
220
|
-
async function processStream(streamOriginal, { injectStringAtBegin, injectStringAfterFirstChunk, injectStringAtEnd, onErrorWhileStreaming, enableEagerStreaming, }) {
|
|
221
|
-
const buffer = [];
|
|
222
|
-
let streamOriginalHasStartedEmitting = false;
|
|
223
|
-
let streamOriginalEnded = false;
|
|
224
|
-
let streamClosed = false;
|
|
225
|
-
let onEndWasCalled = false;
|
|
226
|
-
let isReadyToWrite = false;
|
|
227
|
-
let wrapperCreated = false;
|
|
228
|
-
let shouldFlushStream = false;
|
|
229
|
-
let resolve;
|
|
230
|
-
let reject;
|
|
231
|
-
let promiseHasResolved = false;
|
|
232
|
-
let injectStringAfterFirstChunk_done = false;
|
|
233
|
-
const streamWrapperPromise = new Promise((resolve_, reject_) => {
|
|
234
|
-
resolve = (streamWrapper) => {
|
|
235
|
-
promiseHasResolved = true;
|
|
236
|
-
resolve_(streamWrapper);
|
|
237
|
-
};
|
|
238
|
-
reject = (err) => {
|
|
239
|
-
promiseHasResolved = true;
|
|
240
|
-
reject_(err);
|
|
241
|
-
};
|
|
242
|
-
});
|
|
243
|
-
let resolveReadyToWrite;
|
|
244
|
-
const promiseReadyToWrite = new Promise((r) => (resolveReadyToWrite = r));
|
|
245
|
-
if (injectStringAtBegin) {
|
|
246
|
-
const injectedChunk = await injectStringAtBegin();
|
|
247
|
-
writeStream(injectedChunk); // Adds injectedChunk to buffer
|
|
248
|
-
flushStream(); // Sets shouldFlushStream to true
|
|
249
|
-
}
|
|
250
|
-
// We call onStreamEvent() also when the stream ends in order to properly handle the situation when the stream didn't emit any data
|
|
251
|
-
const onStreamDataOrEnd = (cb) => {
|
|
252
|
-
(0, utils_js_1.assert)(streamOriginalEnded === false);
|
|
253
|
-
streamOriginalHasStartedEmitting = true;
|
|
254
|
-
cb();
|
|
255
|
-
if (wrapperCreated)
|
|
256
|
-
resolvePromise();
|
|
257
|
-
};
|
|
258
|
-
const { streamWrapper, streamWrapperOperations } = await createStreamWrapper({
|
|
259
|
-
streamOriginal,
|
|
260
|
-
onReadyToWrite() {
|
|
261
|
-
debug('stream begin');
|
|
262
|
-
isReadyToWrite = true;
|
|
263
|
-
flushBuffer();
|
|
264
|
-
resolveReadyToWrite();
|
|
265
|
-
},
|
|
266
|
-
onError(err) {
|
|
267
|
-
if (!promiseHasResolved) {
|
|
268
|
-
reject(err);
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
onErrorWhileStreaming(err);
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
onData(chunk) {
|
|
275
|
-
onStreamDataOrEnd(() => {
|
|
276
|
-
writeStream(chunk);
|
|
277
|
-
if (injectStringAfterFirstChunk && !injectStringAfterFirstChunk_done) {
|
|
278
|
-
const injectedChunk = injectStringAfterFirstChunk();
|
|
279
|
-
if (injectedChunk !== null)
|
|
280
|
-
writeStream(injectedChunk);
|
|
281
|
-
injectStringAfterFirstChunk_done = true;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
},
|
|
285
|
-
async onEnd(
|
|
286
|
-
// Should we use this `isCancel`? Maybe we can skip `injectStringAtEnd()`?
|
|
287
|
-
isCancel) {
|
|
288
|
-
try {
|
|
289
|
-
(0, utils_js_1.assert)(!onEndWasCalled);
|
|
290
|
-
onEndWasCalled = true;
|
|
291
|
-
debug('stream end');
|
|
292
|
-
// We call onStreamEvent() also here in case the stream didn't emit any data
|
|
293
|
-
onStreamDataOrEnd(() => {
|
|
294
|
-
streamOriginalEnded = true;
|
|
295
|
-
});
|
|
296
|
-
if (injectStringAtEnd) {
|
|
297
|
-
const injectedChunk = await injectStringAtEnd();
|
|
298
|
-
writeStream(injectedChunk);
|
|
299
|
-
}
|
|
300
|
-
await promiseReadyToWrite; // E.g. if the user calls the pipe wrapper after the original writable has ended
|
|
301
|
-
(0, utils_js_1.assert)(isReady());
|
|
302
|
-
flushBuffer();
|
|
303
|
-
streamClosed = true;
|
|
304
|
-
debug('stream ended');
|
|
305
|
-
}
|
|
306
|
-
catch (err) {
|
|
307
|
-
// Ideally, we should catch and gracefully handle user land errors, as any error thrown here kills the server. (I assume that the fact it kills the server is a Node.js bug?)
|
|
308
|
-
// Show "[vike][Bug] You stumbled upon a bug in Vike's source code" to user while printing original error
|
|
309
|
-
if (!(0, utils_js_1.isBug)(err)) {
|
|
310
|
-
console.error(err);
|
|
311
|
-
(0, utils_js_1.assert)(false);
|
|
312
|
-
}
|
|
313
|
-
throw err;
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
onFlush() {
|
|
317
|
-
flushStream();
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
wrapperCreated = true;
|
|
321
|
-
flushBuffer(); // In case onReadyToWrite() was already called (the flushBuffer() of onReadyToWrite() wasn't called because `wrapperCreated === false`)
|
|
322
|
-
if (!delayStreamStart())
|
|
323
|
-
resolvePromise();
|
|
324
|
-
return streamWrapperPromise;
|
|
325
|
-
function writeStream(chunk) {
|
|
326
|
-
buffer.push(chunk);
|
|
327
|
-
flushBuffer();
|
|
328
|
-
}
|
|
329
|
-
function flushBuffer() {
|
|
330
|
-
if (!isReady())
|
|
331
|
-
return;
|
|
332
|
-
(0, utils_js_1.assert)(!streamClosed);
|
|
333
|
-
buffer.forEach((chunk) => {
|
|
334
|
-
streamWrapperOperations.writeChunk(chunk);
|
|
335
|
-
});
|
|
336
|
-
buffer.length = 0;
|
|
337
|
-
if (shouldFlushStream)
|
|
338
|
-
flushStream();
|
|
339
|
-
}
|
|
340
|
-
function resolvePromise() {
|
|
341
|
-
(0, utils_js_1.assert)(!delayStreamStart()); // The stream promise shouldn't resolve before delayStreamStart()
|
|
342
|
-
(0, utils_js_1.assert)(wrapperCreated); // Doesn't make sense to resolve streamWrapper if it isn't defined yet
|
|
343
|
-
debug('stream promise resolved');
|
|
344
|
-
resolve(streamWrapper);
|
|
345
|
-
}
|
|
346
|
-
function flushStream() {
|
|
347
|
-
if (!isReady()) {
|
|
348
|
-
shouldFlushStream = true;
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
if (streamWrapperOperations.flushStream === null)
|
|
352
|
-
return;
|
|
353
|
-
streamWrapperOperations.flushStream();
|
|
354
|
-
shouldFlushStream = false;
|
|
355
|
-
debug('stream flushed');
|
|
356
|
-
}
|
|
357
|
-
function isReady() {
|
|
358
|
-
/*
|
|
359
|
-
console.log('isReadyToWrite', isReadyToWrite)
|
|
360
|
-
console.log('wrapperCreated', wrapperCreated)
|
|
361
|
-
console.log('!delayStreamStart()', !delayStreamStart())
|
|
362
|
-
*/
|
|
363
|
-
return (isReadyToWrite &&
|
|
364
|
-
// We can't use streamWrapperOperations.writeChunk() if it isn't defined yet
|
|
365
|
-
wrapperCreated &&
|
|
366
|
-
// See comment below
|
|
367
|
-
!delayStreamStart());
|
|
368
|
-
}
|
|
369
|
-
// Delay streaming, so that if the page shell fails then Vike is able to render the error page.
|
|
370
|
-
// - We can't erase the previously written stream data => we need to delay streaming if we want to be able to restart rendering anew for the error page
|
|
371
|
-
// - This is what React expects.
|
|
372
|
-
// - Does this make sense for UI frameworks other than React?
|
|
373
|
-
// - We don't need this anymore if we implement a client-side recover mechanism.
|
|
374
|
-
// - I.e. rendering the error page on the client-side if there is an error during the stream.
|
|
375
|
-
// - We cannot do this with Server Routing
|
|
376
|
-
// - Emitting the wrong status code doesn't matter with libraries like react-streaming which automatically disable streaming for bots. (Emitting the right status code only matters for bots.)
|
|
377
|
-
function delayStreamStart() {
|
|
378
|
-
return !enableEagerStreaming && !streamOriginalHasStartedEmitting;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onFlush, onReadyToWrite, }) {
|
|
382
|
-
if ((0, react_streaming_js_1.isStreamFromReactStreamingPackage)(streamOriginal)) {
|
|
383
|
-
debug(`onRenderHtml() hook returned ${picocolors_1.default.cyan('react-streaming')} result`);
|
|
384
|
-
const stream = (0, react_streaming_js_1.getStreamOfReactStreamingPackage)(streamOriginal);
|
|
385
|
-
streamOriginal = stream;
|
|
386
|
-
}
|
|
387
|
-
if (isStreamPipeNode(streamOriginal)) {
|
|
388
|
-
debug('onRenderHtml() hook returned Node.js Stream Pipe');
|
|
389
|
-
let writableOriginal = null;
|
|
390
|
-
const pipeProxy = (writable_) => {
|
|
391
|
-
writableOriginal = writable_;
|
|
392
|
-
debug('original Node.js Writable received');
|
|
393
|
-
onReadyToWrite();
|
|
394
|
-
if (hasEnded) {
|
|
395
|
-
// onReadyToWrite() already wrote everything; we can close the stream right away
|
|
396
|
-
writableOriginal.end();
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
stampPipe(pipeProxy, 'node-stream');
|
|
400
|
-
const writeChunk = (chunk) => {
|
|
401
|
-
(0, utils_js_1.assert)(writableOriginal);
|
|
402
|
-
writableOriginal.write(chunk);
|
|
403
|
-
debugWithChunk('data written (Node.js Writable)', chunk);
|
|
404
|
-
};
|
|
405
|
-
// For libraries such as https://www.npmjs.com/package/compression
|
|
406
|
-
// - React calls writable.flush() when available
|
|
407
|
-
// - https://github.com/vikejs/vike/issues/466#issuecomment-1269601710
|
|
408
|
-
const flushStream = () => {
|
|
409
|
-
(0, utils_js_1.assert)(writableOriginal);
|
|
410
|
-
if (typeof writableOriginal.flush === 'function') {
|
|
411
|
-
writableOriginal.flush();
|
|
412
|
-
debug('stream flush() performed (Node.js Writable)');
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
let hasEnded = false;
|
|
416
|
-
const endStream = () => {
|
|
417
|
-
hasEnded = true;
|
|
418
|
-
if (writableOriginal) {
|
|
419
|
-
writableOriginal.end();
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
const { Writable } = await loadStreamNodeModule();
|
|
423
|
-
const writableProxy = new Writable({
|
|
424
|
-
async write(chunk, _encoding, callback) {
|
|
425
|
-
onData(chunk);
|
|
426
|
-
callback();
|
|
427
|
-
},
|
|
428
|
-
async destroy(err, callback) {
|
|
429
|
-
if (err) {
|
|
430
|
-
onError(err);
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
await onEnd();
|
|
434
|
-
}
|
|
435
|
-
callback(err);
|
|
436
|
-
endStream();
|
|
437
|
-
},
|
|
438
|
-
});
|
|
439
|
-
// Forward the flush() call
|
|
440
|
-
(0, utils_js_1.objectAssign)(writableProxy, {
|
|
441
|
-
flush: () => {
|
|
442
|
-
onFlush();
|
|
443
|
-
},
|
|
444
|
-
});
|
|
445
|
-
(0, utils_js_1.assert)(typeof writableProxy.flush === 'function');
|
|
446
|
-
const pipeOriginal = getStreamPipeNode(streamOriginal);
|
|
447
|
-
pipeOriginal(writableProxy);
|
|
448
|
-
return { streamWrapper: pipeProxy, streamWrapperOperations: { writeChunk, flushStream } };
|
|
449
|
-
}
|
|
450
|
-
if (isStreamPipeWeb(streamOriginal)) {
|
|
451
|
-
debug('onRenderHtml() hook returned Web Stream Pipe');
|
|
452
|
-
let writerOriginal = null;
|
|
453
|
-
const pipeProxy = (writableOriginal) => {
|
|
454
|
-
writerOriginal = writableOriginal.getWriter();
|
|
455
|
-
debug('original Web Writable received');
|
|
456
|
-
(async () => {
|
|
457
|
-
// CloudFlare Workers does not implement `ready` property
|
|
458
|
-
// - https://github.com/vuejs/vue-next/issues/4287
|
|
459
|
-
try {
|
|
460
|
-
await writerOriginal.ready;
|
|
461
|
-
}
|
|
462
|
-
catch (e) { }
|
|
463
|
-
onReadyToWrite();
|
|
464
|
-
if (hasEnded) {
|
|
465
|
-
// onReadyToWrite() already wrote everything; we can close the stream right away
|
|
466
|
-
writerOriginal.close();
|
|
467
|
-
}
|
|
468
|
-
})();
|
|
469
|
-
};
|
|
470
|
-
stampPipe(pipeProxy, 'web-stream');
|
|
471
|
-
const writeChunk = (chunk) => {
|
|
472
|
-
(0, utils_js_1.assert)(writerOriginal);
|
|
473
|
-
writerOriginal.write(encodeForWebStream(chunk));
|
|
474
|
-
debugWithChunk('data written (Web Writable)', chunk);
|
|
475
|
-
};
|
|
476
|
-
// Web Streams have compression built-in
|
|
477
|
-
// - https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API
|
|
478
|
-
// - It seems that there is no flush interface? Flushing just works automagically?
|
|
479
|
-
const flushStream = null;
|
|
480
|
-
let hasEnded = false;
|
|
481
|
-
const endStream = () => {
|
|
482
|
-
hasEnded = true;
|
|
483
|
-
if (writerOriginal) {
|
|
484
|
-
writerOriginal.close();
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
let writableProxy;
|
|
488
|
-
if (typeof ReadableStream !== 'function') {
|
|
489
|
-
writableProxy = new WritableStream({
|
|
490
|
-
write(chunk) {
|
|
491
|
-
onData(chunk);
|
|
492
|
-
},
|
|
493
|
-
async close() {
|
|
494
|
-
await onEnd();
|
|
495
|
-
endStream();
|
|
496
|
-
},
|
|
497
|
-
abort(err) {
|
|
498
|
-
onError(err);
|
|
499
|
-
endStream();
|
|
500
|
-
},
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
const { readable, writable } = new TransformStream();
|
|
505
|
-
writableProxy = writable;
|
|
506
|
-
handleReadableWeb(readable, {
|
|
507
|
-
onData,
|
|
508
|
-
onError(err) {
|
|
509
|
-
onError(err);
|
|
510
|
-
endStream();
|
|
511
|
-
},
|
|
512
|
-
async onEnd() {
|
|
513
|
-
await onEnd();
|
|
514
|
-
endStream();
|
|
515
|
-
},
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
const pipeOriginal = getStreamPipeWeb(streamOriginal);
|
|
519
|
-
pipeOriginal(writableProxy);
|
|
520
|
-
return { streamWrapper: pipeProxy, streamWrapperOperations: { writeChunk, flushStream } };
|
|
521
|
-
}
|
|
522
|
-
if (isStreamReadableWeb(streamOriginal)) {
|
|
523
|
-
debug('onRenderHtml() hook returned Web Readable');
|
|
524
|
-
const readableOriginal = streamOriginal;
|
|
525
|
-
let isClosed = false;
|
|
526
|
-
let isCancel = false;
|
|
527
|
-
const closeStream = async () => {
|
|
528
|
-
if (isClosed)
|
|
529
|
-
return;
|
|
530
|
-
await onEnd(isCancel);
|
|
531
|
-
isClosed = true;
|
|
532
|
-
controllerProxy.close();
|
|
533
|
-
};
|
|
534
|
-
let controllerProxy;
|
|
535
|
-
assertReadableStreamConstructor();
|
|
536
|
-
const readableProxy = new ReadableStream({
|
|
537
|
-
start(controller) {
|
|
538
|
-
controllerProxy = controller;
|
|
539
|
-
onReadyToWrite();
|
|
540
|
-
handleReadableWeb(readableOriginal, {
|
|
541
|
-
onData,
|
|
542
|
-
onError(err) {
|
|
543
|
-
onError(err);
|
|
544
|
-
controllerProxy.close();
|
|
545
|
-
},
|
|
546
|
-
async onEnd() {
|
|
547
|
-
await closeStream();
|
|
548
|
-
},
|
|
549
|
-
});
|
|
550
|
-
},
|
|
551
|
-
async cancel(...args) {
|
|
552
|
-
isCancel = true;
|
|
553
|
-
await readableOriginal.cancel(...args);
|
|
554
|
-
// If readableOriginal has implemented readableOriginal.cancel() then the onEnd() callback and therefore closeStream() may already have been called at this point
|
|
555
|
-
await closeStream();
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
const writeChunk = (chunk) => {
|
|
559
|
-
if (
|
|
560
|
-
// If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether the steam is closed.
|
|
561
|
-
!isClosed) {
|
|
562
|
-
controllerProxy.enqueue(encodeForWebStream(chunk));
|
|
563
|
-
debugWithChunk('data written (Web Readable)', chunk);
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
debugWithChunk('data emitted but not written (Web Readable)', chunk);
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
// Readables don't have the notion of flushing
|
|
570
|
-
const flushStream = null;
|
|
571
|
-
return {
|
|
572
|
-
streamWrapper: readableProxy,
|
|
573
|
-
streamWrapperOperations: { writeChunk, flushStream },
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
if (isStreamReadableNode(streamOriginal)) {
|
|
577
|
-
debug('onRenderHtml() hook returned Node.js Readable');
|
|
578
|
-
const readableOriginal = streamOriginal;
|
|
579
|
-
const { Readable } = await loadStreamNodeModule();
|
|
580
|
-
// Vue doesn't always set the read() handler: https://github.com/vikejs/vike/issues/138#issuecomment-934743375
|
|
581
|
-
if (readableOriginal._read === Readable.prototype._read) {
|
|
582
|
-
readableOriginal._read = function () { };
|
|
583
|
-
}
|
|
584
|
-
const writeChunk = (chunk) => {
|
|
585
|
-
readableProxy.push(chunk);
|
|
586
|
-
debugWithChunk('data written (Node.js Readable)', chunk);
|
|
587
|
-
};
|
|
588
|
-
// Readables don't have the notion of flushing
|
|
589
|
-
const flushStream = null;
|
|
590
|
-
const closeProxy = () => {
|
|
591
|
-
readableProxy.push(null);
|
|
592
|
-
};
|
|
593
|
-
const readableProxy = new Readable({ read() { } });
|
|
594
|
-
onReadyToWrite();
|
|
595
|
-
readableOriginal.on('data', (chunk) => {
|
|
596
|
-
onData(chunk);
|
|
597
|
-
});
|
|
598
|
-
readableOriginal.on('error', (err) => {
|
|
599
|
-
onError(err);
|
|
600
|
-
closeProxy();
|
|
601
|
-
});
|
|
602
|
-
readableOriginal.on('end', async () => {
|
|
603
|
-
await onEnd();
|
|
604
|
-
closeProxy();
|
|
605
|
-
});
|
|
606
|
-
return {
|
|
607
|
-
streamWrapper: readableProxy,
|
|
608
|
-
streamWrapperOperations: { writeChunk, flushStream },
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
(0, utils_js_1.assert)(false);
|
|
612
|
-
}
|
|
613
|
-
async function handleReadableWeb(readable, { onData, onError, onEnd, }) {
|
|
614
|
-
const reader = readable.getReader();
|
|
615
|
-
while (true) {
|
|
616
|
-
let result;
|
|
617
|
-
try {
|
|
618
|
-
result = await reader.read();
|
|
619
|
-
}
|
|
620
|
-
catch (err) {
|
|
621
|
-
onError(err);
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
const { value, done } = result;
|
|
625
|
-
if (done) {
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
onData(value);
|
|
629
|
-
}
|
|
630
|
-
await onEnd();
|
|
631
|
-
}
|
|
632
|
-
function isStream(something) {
|
|
633
|
-
if (isStreamReadableWeb(something) ||
|
|
634
|
-
isStreamReadableNode(something) ||
|
|
635
|
-
isStreamPipeNode(something) ||
|
|
636
|
-
isStreamPipeWeb(something) ||
|
|
637
|
-
(0, react_streaming_js_1.isStreamFromReactStreamingPackage)(something)) {
|
|
638
|
-
(0, utils_js_1.checkType)(something);
|
|
639
|
-
return true;
|
|
640
|
-
}
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
const __streamPipeWeb = '__streamPipeWeb';
|
|
644
|
-
/** @deprecated */
|
|
645
|
-
function pipeWebStream(pipe) {
|
|
646
|
-
(0, utils_js_1.assertWarning)(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
647
|
-
onlyOnce: true,
|
|
648
|
-
showStackTrace: true,
|
|
649
|
-
});
|
|
650
|
-
return { [__streamPipeWeb]: pipe };
|
|
651
|
-
}
|
|
652
|
-
function getStreamPipeWeb(thing) {
|
|
653
|
-
if (!isStreamPipeWeb(thing)) {
|
|
654
|
-
return null;
|
|
655
|
-
}
|
|
656
|
-
if ((0, utils_js_1.isObject)(thing)) {
|
|
657
|
-
// pipeWebStream()
|
|
658
|
-
(0, utils_js_1.assert)(__streamPipeWeb && thing);
|
|
659
|
-
return thing[__streamPipeWeb];
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
// stampPipe()
|
|
663
|
-
(0, utils_js_1.assert)((0, utils_js_1.isCallable)(thing) && 'isWebStreamPipe' in thing);
|
|
664
|
-
return thing;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
function isStreamPipeWeb(thing) {
|
|
668
|
-
// pipeWebStream()
|
|
669
|
-
if ((0, utils_js_1.isObject)(thing) && __streamPipeWeb in thing) {
|
|
670
|
-
return true;
|
|
671
|
-
}
|
|
672
|
-
// stampPipe()
|
|
673
|
-
if ((0, utils_js_1.isCallable)(thing) && 'isWebStreamPipe' in thing) {
|
|
674
|
-
return true;
|
|
675
|
-
}
|
|
676
|
-
return false;
|
|
677
|
-
}
|
|
678
|
-
const __streamPipeNode = '__streamPipeNode';
|
|
679
|
-
/** @deprecated */
|
|
680
|
-
function pipeNodeStream(pipe) {
|
|
681
|
-
(0, utils_js_1.assertWarning)(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
682
|
-
onlyOnce: true,
|
|
683
|
-
showStackTrace: true,
|
|
684
|
-
});
|
|
685
|
-
return { [__streamPipeNode]: pipe };
|
|
686
|
-
}
|
|
687
|
-
function getStreamPipeNode(thing) {
|
|
688
|
-
if (!isStreamPipeNode(thing)) {
|
|
689
|
-
return null;
|
|
690
|
-
}
|
|
691
|
-
if ((0, utils_js_1.isObject)(thing)) {
|
|
692
|
-
// pipeNodeStream()
|
|
693
|
-
(0, utils_js_1.assert)(__streamPipeNode in thing);
|
|
694
|
-
return thing[__streamPipeNode];
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
697
|
-
// stampPipe()
|
|
698
|
-
(0, utils_js_1.assert)((0, utils_js_1.isCallable)(thing) && 'isNodeStreamPipe' in thing);
|
|
699
|
-
return thing;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
function isStreamPipeNode(thing) {
|
|
703
|
-
// pipeNodeStream()
|
|
704
|
-
if ((0, utils_js_1.isObject)(thing) && __streamPipeNode in thing) {
|
|
705
|
-
return true;
|
|
706
|
-
}
|
|
707
|
-
// stampPipe()
|
|
708
|
-
if ((0, utils_js_1.isCallable)(thing) && 'isNodeStreamPipe' in thing) {
|
|
709
|
-
return true;
|
|
710
|
-
}
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
function stampPipe(pipe, pipeType) {
|
|
714
|
-
(0, utils_js_1.assertUsage)(pipeType, `stampPipe(pipe, pipeType): argument ${picocolors_1.default.cyan('pipeType')} is missing.)`, {
|
|
715
|
-
showStackTrace: true,
|
|
716
|
-
});
|
|
717
|
-
(0, utils_js_1.assertUsage)(['web-stream', 'node-stream'].includes(pipeType), `stampPipe(pipe, pipeType): argument ${picocolors_1.default.cyan('pipeType')} should be either ${picocolors_1.default.cyan("'web-stream'")} or ${picocolors_1.default.cyan("'node-stream'")}.`, { showStackTrace: true });
|
|
718
|
-
if (pipeType === 'node-stream') {
|
|
719
|
-
Object.assign(pipe, { isNodeStreamPipe: true });
|
|
720
|
-
}
|
|
721
|
-
else {
|
|
722
|
-
Object.assign(pipe, { isWebStreamPipe: true });
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
const __streamPipe = '__streamPipe';
|
|
726
|
-
function pipeStream(pipe) {
|
|
727
|
-
return { [__streamPipe]: pipe };
|
|
728
|
-
}
|
|
729
|
-
async function streamToString(stream) {
|
|
730
|
-
if (isStreamReadableWeb(stream)) {
|
|
731
|
-
return await streamReadableWebToString(stream);
|
|
732
|
-
}
|
|
733
|
-
if (isStreamReadableNode(stream)) {
|
|
734
|
-
return await streamReadableNodeToString(stream);
|
|
735
|
-
}
|
|
736
|
-
if (isStreamPipeNode(stream)) {
|
|
737
|
-
return await streamPipeNodeToString(getStreamPipeNode(stream));
|
|
738
|
-
}
|
|
739
|
-
if (isStreamPipeWeb(stream)) {
|
|
740
|
-
return await streamPipeWebToString(getStreamPipeWeb(stream));
|
|
741
|
-
}
|
|
742
|
-
if ((0, react_streaming_js_1.isStreamFromReactStreamingPackage)(stream)) {
|
|
743
|
-
return await (0, react_streaming_js_1.streamFromReactStreamingPackageToString)(stream);
|
|
744
|
-
}
|
|
745
|
-
(0, utils_js_1.assert)(false);
|
|
746
|
-
}
|
|
747
|
-
function assertReadableStreamConstructor() {
|
|
748
|
-
(0, utils_js_1.assertUsage)(typeof ReadableStream === 'function',
|
|
749
|
-
// Error message copied from vue's renderToWebStream() implementation
|
|
750
|
-
"ReadableStream constructor isn't available in the global scope. " +
|
|
751
|
-
'If the target environment does support web streams, consider using ' +
|
|
752
|
-
'pipeToWebWritable() with an existing WritableStream instance instead.');
|
|
753
|
-
}
|
|
754
|
-
let encoder;
|
|
755
|
-
function encodeForWebStream(thing) {
|
|
756
|
-
if (!encoder) {
|
|
757
|
-
encoder = new TextEncoder();
|
|
758
|
-
}
|
|
759
|
-
if (typeof thing === 'string') {
|
|
760
|
-
return encoder.encode(thing);
|
|
761
|
-
}
|
|
762
|
-
return thing;
|
|
763
|
-
}
|
|
764
|
-
// Because of Cloudflare Workers, we cannot statically import the `stream` module, instead we dynamically import it.
|
|
765
|
-
async function loadStreamNodeModule() {
|
|
766
|
-
const streamModule = (await (0, import_1.import_)('stream')).default;
|
|
767
|
-
const { Readable, Writable } = streamModule;
|
|
768
|
-
return { Readable, Writable };
|
|
769
|
-
}
|
|
770
|
-
function getStreamName(kind, type) {
|
|
771
|
-
let typeName = (0, utils_js_1.capitalizeFirstLetter)(type);
|
|
772
|
-
if (typeName === 'Node') {
|
|
773
|
-
typeName = 'Node.js';
|
|
774
|
-
}
|
|
775
|
-
const kindName = (0, utils_js_1.capitalizeFirstLetter)(kind);
|
|
776
|
-
if (kind !== 'pipe') {
|
|
777
|
-
return `a ${kindName} ${typeName} Stream`;
|
|
778
|
-
}
|
|
779
|
-
if (kind === 'pipe') {
|
|
780
|
-
return `a ${typeName} Stream Pipe`;
|
|
781
|
-
}
|
|
782
|
-
(0, utils_js_1.assert)(false);
|
|
783
|
-
}
|
|
784
|
-
function inferStreamName(stream) {
|
|
785
|
-
if (isStreamReadableWeb(stream)) {
|
|
786
|
-
return getStreamName('readable', 'web');
|
|
787
|
-
}
|
|
788
|
-
if (isStreamReadableNode(stream)) {
|
|
789
|
-
return getStreamName('readable', 'node');
|
|
790
|
-
}
|
|
791
|
-
if (isStreamPipeNode(stream)) {
|
|
792
|
-
return getStreamName('pipe', 'node');
|
|
793
|
-
}
|
|
794
|
-
if (isStreamPipeWeb(stream)) {
|
|
795
|
-
return getStreamName('pipe', 'web');
|
|
796
|
-
}
|
|
797
|
-
(0, utils_js_1.assert)(false);
|
|
798
|
-
}
|
|
799
|
-
function decodeChunks() {
|
|
800
|
-
const decoder = new TextDecoder();
|
|
801
|
-
const decode = (chunk) => {
|
|
802
|
-
if (typeof chunk === 'string') {
|
|
803
|
-
return chunk;
|
|
804
|
-
}
|
|
805
|
-
else if (chunk instanceof Uint8Array) {
|
|
806
|
-
return decoder.decode(chunk, { stream: true });
|
|
807
|
-
}
|
|
808
|
-
else {
|
|
809
|
-
(0, utils_js_1.assert)(false);
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
// https://github.com/vikejs/vike/pull/1799#discussion_r1713554096
|
|
813
|
-
const getClosingChunk = () => {
|
|
814
|
-
return decoder.decode();
|
|
815
|
-
};
|
|
816
|
-
return { decode, getClosingChunk };
|
|
817
|
-
}
|
|
818
|
-
function debugWithChunk(msg, chunk) {
|
|
819
|
-
if (!debug.isActivated)
|
|
820
|
-
return;
|
|
821
|
-
let chunkStr;
|
|
822
|
-
try {
|
|
823
|
-
chunkStr = new TextDecoder().decode(chunk);
|
|
824
|
-
}
|
|
825
|
-
catch (err) {
|
|
826
|
-
chunkStr = String(chunk);
|
|
827
|
-
}
|
|
828
|
-
debug(msg, chunkStr);
|
|
829
|
-
}
|