vike 0.4.195 → 0.4.196

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.
Files changed (290) hide show
  1. package/LICENSE.md +9 -0
  2. package/dist/cjs/__internal/index.js +3 -4
  3. package/dist/cjs/node/cli/onLoad.js +1 -2
  4. package/dist/cjs/node/createPageRenderer.js +1 -2
  5. package/dist/cjs/node/plugin/index.js +3 -3
  6. package/dist/cjs/node/plugin/onLoad.js +1 -2
  7. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +1 -2
  8. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -2
  9. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +2 -3
  10. package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -4
  11. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -2
  12. package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -2
  13. package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +1 -2
  14. package/dist/cjs/node/plugin/plugins/config/index.js +1 -2
  15. package/dist/cjs/node/plugin/plugins/config/pickFirst.js +1 -2
  16. package/dist/cjs/node/plugin/plugins/config/resolveBase.js +2 -3
  17. package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -2
  18. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -2
  19. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -2
  20. package/dist/cjs/node/plugin/plugins/distFileNames.js +1 -2
  21. package/dist/cjs/node/plugin/plugins/envVars.js +1 -2
  22. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
  23. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +3 -3
  24. package/dist/cjs/node/plugin/plugins/fileEnv.js +109 -88
  25. package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -2
  26. package/dist/cjs/node/plugin/plugins/importBuild/index.js +2 -3
  27. package/dist/cjs/node/plugin/plugins/importUserCode/addImportStatement.js +1 -2
  28. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -3
  29. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -2
  30. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +2 -3
  31. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +1 -2
  32. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -2
  33. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -2
  34. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +8 -9
  35. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -4
  36. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +3 -4
  37. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +3 -4
  38. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +5 -7
  39. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +6 -6
  40. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -2
  41. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -2
  42. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +1 -2
  43. package/dist/cjs/node/plugin/plugins/packageJsonFile.js +1 -2
  44. package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -2
  45. package/dist/cjs/node/plugin/plugins/removeRequireHookPlugin.js +1 -2
  46. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -2
  47. package/dist/cjs/node/plugin/plugins/suppressRollupWarning.js +1 -2
  48. package/dist/cjs/node/plugin/plugins/workaroundCssModuleHmr.js +1 -2
  49. package/dist/cjs/node/plugin/resolveClientEntriesDev.js +1 -2
  50. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +1 -2
  51. package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -2
  52. package/dist/cjs/node/plugin/shared/getAssetsDir.js +1 -2
  53. package/dist/cjs/node/plugin/shared/getFilePath.js +8 -9
  54. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +2 -3
  55. package/dist/cjs/node/plugin/shared/isAsset.js +1 -2
  56. package/dist/cjs/node/plugin/shared/isViteCliCall.js +2 -3
  57. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -5
  58. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +4 -5
  59. package/dist/cjs/node/plugin/shared/loggerNotProd.js +6 -7
  60. package/dist/cjs/node/plugin/shared/loggerVite/removeSuperfluousViteLog.js +3 -4
  61. package/dist/cjs/node/plugin/shared/loggerVite.js +1 -2
  62. package/dist/cjs/node/plugin/shared/parseEsModule.js +2 -3
  63. package/dist/cjs/node/plugin/shared/rollupIsEsm.js +1 -2
  64. package/dist/cjs/node/plugin/shared/rollupSourceMap.js +2 -3
  65. package/dist/cjs/node/prerender/runPrerender.js +4 -5
  66. package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +2 -3
  67. package/dist/cjs/node/runtime/globalContext.js +13 -14
  68. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -2
  69. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +1 -2
  70. package/dist/cjs/node/runtime/html/injectAssets/inferHtmlTags.js +4 -4
  71. package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -2
  72. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +6 -7
  73. package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +1 -2
  74. package/dist/cjs/node/runtime/html/injectAssets/sanitizeJson.js +1 -2
  75. package/dist/cjs/node/runtime/html/injectAssets.js +2 -3
  76. package/dist/cjs/node/runtime/html/renderHtml.js +5 -6
  77. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -3
  78. package/dist/cjs/node/runtime/html/stream/react-streaming.js +3 -4
  79. package/dist/cjs/node/runtime/html/stream.js +21 -22
  80. package/dist/cjs/node/runtime/onLoad.js +1 -2
  81. package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +1 -2
  82. package/dist/cjs/node/runtime/renderPage/analyzePage.js +5 -6
  83. package/dist/cjs/node/runtime/renderPage/assertArguments.js +1 -2
  84. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -2
  85. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -2
  86. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +19 -8
  87. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +1 -2
  88. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -2
  89. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
  90. package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -2
  91. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -3
  92. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -2
  93. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -2
  94. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -2
  95. package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +1 -2
  96. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +2 -3
  97. package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +2 -3
  98. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -2
  99. package/dist/cjs/node/runtime/renderPage/inferMediaType.js +1 -2
  100. package/dist/cjs/node/runtime/renderPage/isNewError.js +2 -3
  101. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -2
  102. package/dist/cjs/node/runtime/renderPage/log404/index.js +2 -3
  103. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +2 -3
  104. package/dist/cjs/node/runtime/renderPage/loggerProd.js +2 -3
  105. package/dist/cjs/node/runtime/renderPage/loggerRuntime.js +2 -2
  106. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -2
  107. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -6
  108. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +2 -3
  109. package/dist/cjs/node/runtime/renderPage.js +8 -8
  110. package/dist/cjs/node/shared/assertPluginManifest.js +1 -2
  111. package/dist/cjs/node/shared/assertRuntimeManifest.js +1 -2
  112. package/dist/cjs/node/shared/assertV1Design.js +1 -2
  113. package/dist/cjs/node/shared/extractAssetsQuery.js +2 -3
  114. package/dist/cjs/node/shared/getConfigVike.js +1 -2
  115. package/dist/cjs/node/shared/isErrorDebug.js +1 -2
  116. package/dist/cjs/node/shared/prependEntriesDir.js +1 -2
  117. package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +2 -2
  118. package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +2 -3
  119. package/dist/cjs/shared/addIs404ToPageProps.js +1 -2
  120. package/dist/cjs/shared/assertHookReturnedObject.js +1 -2
  121. package/dist/cjs/shared/assertOnBeforeRenderHookReturn.js +1 -2
  122. package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -2
  123. package/dist/cjs/shared/assertPageFilePath.js +1 -2
  124. package/dist/cjs/shared/determinePageIdOld.js +1 -2
  125. package/dist/cjs/shared/error-page.js +3 -4
  126. package/dist/cjs/shared/getPageContextRequestUrl.js +2 -2
  127. package/dist/cjs/shared/getPageContextUrlComputed.js +2 -3
  128. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -5
  129. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +1 -2
  130. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +2 -3
  131. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/getExportNames.js +1 -2
  132. package/dist/cjs/shared/getPageFiles/analyzePageClientSide.js +2 -3
  133. package/dist/cjs/shared/getPageFiles/analyzePageServerSide.js +1 -2
  134. package/dist/cjs/shared/getPageFiles/assert_exports_old_design.js +3 -3
  135. package/dist/cjs/shared/getPageFiles/fileTypes.js +3 -3
  136. package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +2 -3
  137. package/dist/cjs/shared/getPageFiles/getExports.js +1 -2
  138. package/dist/cjs/shared/getPageFiles/getPageFileObject.js +1 -2
  139. package/dist/cjs/shared/getPageFiles/parseGlobResults.js +1 -2
  140. package/dist/cjs/shared/getPageFiles/setPageFiles.js +3 -4
  141. package/dist/cjs/shared/hooks/executeHook.js +4 -5
  142. package/dist/cjs/shared/hooks/getHook.js +6 -7
  143. package/dist/cjs/shared/modifyUrl.js +1 -2
  144. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -2
  145. package/dist/cjs/shared/page-configs/findPageConfig.js +1 -2
  146. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +3 -4
  147. package/dist/cjs/shared/page-configs/getConfigValue.js +2 -3
  148. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +1 -2
  149. package/dist/cjs/shared/page-configs/getExportPath.js +1 -2
  150. package/dist/cjs/shared/page-configs/helpers.js +3 -4
  151. package/dist/cjs/shared/page-configs/loadConfigValues.js +1 -2
  152. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -3
  153. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -2
  154. package/dist/cjs/shared/route/abort.js +9 -10
  155. package/dist/cjs/shared/route/debug.js +1 -2
  156. package/dist/cjs/shared/route/deduceRouteStringFromFilesystemPath.js +1 -2
  157. package/dist/cjs/shared/route/executeGuardHook.js +1 -2
  158. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -2
  159. package/dist/cjs/shared/route/index.js +1 -2
  160. package/dist/cjs/shared/route/loadPageRoutes.js +1 -2
  161. package/dist/cjs/shared/route/resolvePrecedence.js +1 -2
  162. package/dist/cjs/shared/route/resolveRoute.js +1 -2
  163. package/dist/cjs/shared/route/resolveRouteFunction.js +4 -5
  164. package/dist/cjs/shared/route/resolveRouteString.js +6 -7
  165. package/dist/cjs/shared/route/resolveUrlPathname.js +1 -2
  166. package/dist/cjs/shared/sortPageContext.js +1 -2
  167. package/dist/cjs/types/defineConfig.js +1 -2
  168. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  169. package/dist/cjs/utils/assert.js +10 -11
  170. package/dist/cjs/utils/assertIsBrowser.js +1 -2
  171. package/dist/cjs/utils/assertIsNotBrowser.js +1 -2
  172. package/dist/cjs/utils/assertIsNotProductionRuntime.js +6 -6
  173. package/dist/cjs/utils/assertKeys.js +1 -2
  174. package/dist/cjs/utils/assertNodeEnv.js +5 -6
  175. package/dist/cjs/utils/assertNodeVersion.js +1 -2
  176. package/dist/cjs/utils/assertRoutingType.js +3 -4
  177. package/dist/cjs/utils/assertSingleInstance.js +3 -4
  178. package/dist/cjs/utils/assertVersion.js +2 -3
  179. package/dist/cjs/utils/augmentType.js +1 -2
  180. package/dist/cjs/utils/capitalizeFirstLetter.js +1 -2
  181. package/dist/cjs/utils/cast.js +2 -3
  182. package/dist/cjs/utils/changeEnumerable.js +1 -2
  183. package/dist/cjs/utils/checkType.js +2 -3
  184. package/dist/cjs/utils/compareString.js +1 -2
  185. package/dist/cjs/utils/createErrorWithCleanStackTrace.js +1 -2
  186. package/dist/cjs/utils/debug.js +2 -3
  187. package/dist/cjs/utils/deepEqual.js +1 -2
  188. package/dist/cjs/utils/escapeHtml.js +1 -2
  189. package/dist/cjs/utils/escapeRegex.js +1 -2
  190. package/dist/cjs/utils/filesystemPathHandling.js +2 -3
  191. package/dist/cjs/utils/findFile.js +1 -2
  192. package/dist/cjs/utils/findPackageJson.js +1 -2
  193. package/dist/cjs/utils/formatHintLog.js +1 -2
  194. package/dist/cjs/utils/freezePartial.js +1 -2
  195. package/dist/cjs/utils/genPromise.js +1 -2
  196. package/dist/cjs/utils/getCurrentUrl.js +1 -2
  197. package/dist/cjs/utils/getFileExtension.js +1 -2
  198. package/dist/cjs/utils/getGlobalObject.js +2 -3
  199. package/dist/cjs/utils/getMostSimilar.js +1 -2
  200. package/dist/cjs/utils/getOutDirs.js +2 -3
  201. package/dist/cjs/utils/getPropAccessNotation.js +1 -2
  202. package/dist/cjs/utils/getRandomId.js +1 -2
  203. package/dist/cjs/utils/getTerminWidth.js +1 -2
  204. package/dist/cjs/utils/getValuePrintable.js +1 -2
  205. package/dist/cjs/utils/hasProp.js +1 -2
  206. package/dist/cjs/utils/humanizeTime.js +1 -2
  207. package/dist/cjs/utils/includes.js +1 -2
  208. package/dist/cjs/utils/injectRollupInputs.js +2 -3
  209. package/dist/cjs/utils/isArray.js +1 -2
  210. package/dist/cjs/utils/isArrayOfStrings.js +1 -2
  211. package/dist/cjs/utils/isBrowser.js +1 -2
  212. package/dist/cjs/utils/isCallable.js +1 -2
  213. package/dist/cjs/utils/isDev.js +2 -3
  214. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -3
  215. package/dist/cjs/utils/isHtml.js +1 -2
  216. package/dist/cjs/utils/isNodeJS.js +1 -2
  217. package/dist/cjs/utils/isNpmPackage.js +5 -6
  218. package/dist/cjs/utils/isObject.js +1 -2
  219. package/dist/cjs/utils/isObjectOfStrings.js +1 -2
  220. package/dist/cjs/utils/isObjectWithKeys.js +1 -2
  221. package/dist/cjs/utils/isPlainObject.js +1 -2
  222. package/dist/cjs/utils/isPromise.js +1 -2
  223. package/dist/cjs/utils/isPropertyGetter.js +1 -2
  224. package/dist/cjs/utils/isReact.js +1 -2
  225. package/dist/cjs/utils/isSameErrorMessage.js +1 -2
  226. package/dist/cjs/utils/isScriptFile.js +4 -4
  227. package/dist/cjs/utils/isVikeReactApp.js +1 -2
  228. package/dist/cjs/utils/isVitest.js +1 -2
  229. package/dist/cjs/utils/joinEnglish.js +1 -2
  230. package/dist/cjs/utils/normalizeHeaders.js +1 -2
  231. package/dist/cjs/utils/objectAssign.js +1 -2
  232. package/dist/cjs/utils/objectDefineProperty.js +1 -2
  233. package/dist/cjs/utils/objectEntries.js +1 -2
  234. package/dist/cjs/utils/objectEntriesForEach.js +1 -2
  235. package/dist/cjs/utils/objectFromEntries.js +1 -2
  236. package/dist/cjs/utils/objectKeys.js +1 -2
  237. package/dist/cjs/utils/onPageVisibilityChange.js +2 -3
  238. package/dist/cjs/utils/pLimit.js +1 -2
  239. package/dist/cjs/utils/parseUrl-extras.js +8 -9
  240. package/dist/cjs/utils/parseUrl.js +11 -12
  241. package/dist/cjs/utils/path-shim.js +1 -2
  242. package/dist/cjs/utils/redirectHard.js +1 -2
  243. package/dist/cjs/utils/removeEmptyLines.js +1 -2
  244. package/dist/cjs/utils/removeFileExtention.js +1 -2
  245. package/dist/cjs/utils/requireResolve.js +1 -2
  246. package/dist/cjs/utils/sleep.js +1 -2
  247. package/dist/cjs/utils/slice.js +1 -2
  248. package/dist/cjs/utils/sorter.js +5 -6
  249. package/dist/cjs/utils/stringifyStringArray.js +1 -2
  250. package/dist/cjs/utils/stripAnsi.js +1 -2
  251. package/dist/cjs/utils/throttle.js +1 -2
  252. package/dist/cjs/utils/trimWithAnsi.js +2 -3
  253. package/dist/cjs/utils/truncateString.js +1 -2
  254. package/dist/cjs/utils/unique.js +1 -2
  255. package/dist/cjs/utils/urlToFile.js +2 -2
  256. package/dist/cjs/utils/virtual-files.js +3 -4
  257. package/dist/cjs/utils/viteIsSSR.js +2 -3
  258. package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -2
  259. package/dist/esm/client/client-routing-runtime/installClientRouter.js +2 -4
  260. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +2 -2
  261. package/dist/esm/client/client-routing-runtime/navigate.js +3 -1
  262. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +2 -0
  263. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +39 -12
  264. package/dist/esm/client/client-routing-runtime/skipLink.js +1 -1
  265. package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
  266. package/dist/esm/client/client-routing-runtime/utils.js +1 -0
  267. package/dist/esm/node/plugin/plugins/fileEnv.js +109 -87
  268. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
  269. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +2 -2
  270. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -2
  271. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +1 -2
  272. package/dist/esm/node/runtime/html/stream.d.ts +0 -1
  273. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -1
  274. package/dist/esm/node/runtime/renderPage/analyzePage.js +4 -4
  275. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +5 -1
  276. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +15 -3
  277. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +0 -1
  278. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -0
  279. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
  280. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +6 -6
  281. package/dist/esm/node/runtime/renderPage.js +6 -6
  282. package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +1 -1
  283. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
  284. package/dist/esm/shared/page-configs/Config.d.ts +1 -1
  285. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  286. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  287. package/dist/esm/utils/debugGlob.d.ts +2 -2
  288. package/dist/esm/utils/genPromise.d.ts +1 -1
  289. package/dist/esm/utils/projectInfo.d.ts +1 -1
  290. package/package.json +6 -5
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throttle = void 0;
3
+ exports.throttle = throttle;
4
4
  function throttle(func, waitTime) {
5
5
  let isQueued = false;
6
6
  return () => {
@@ -13,4 +13,3 @@ function throttle(func, waitTime) {
13
13
  }
14
14
  };
15
15
  }
16
- exports.throttle = throttle;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trimWithAnsiTrailOnly = exports.trimWithAnsi = void 0;
3
+ exports.trimWithAnsi = trimWithAnsi;
4
+ exports.trimWithAnsiTrailOnly = trimWithAnsiTrailOnly;
4
5
  const assert_js_1 = require("./assert.js");
5
6
  const stripAnsi_js_1 = require("./stripAnsi.js");
6
7
  const whitespaceRegex = /(\s+)/; // Capturing parathesis so that split preserves seperator
@@ -10,14 +11,12 @@ function trimWithAnsi(str) {
10
11
  str = trimWithAnsiTrailOnly(str);
11
12
  return str;
12
13
  }
13
- exports.trimWithAnsi = trimWithAnsi;
14
14
  function trimWithAnsiHead(str) {
15
15
  return trim(str, false);
16
16
  }
17
17
  function trimWithAnsiTrailOnly(str) {
18
18
  return trim(str, true);
19
19
  }
20
- exports.trimWithAnsiTrailOnly = trimWithAnsiTrailOnly;
21
20
  function trim(str, trail) {
22
21
  let parts = str.split(whitespaceRegex);
23
22
  if (trail)
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.truncateString = void 0;
6
+ exports.truncateString = truncateString;
7
7
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
8
  const assert_js_1 = require("./assert.js");
9
9
  function truncateString(str, lenMax) {
@@ -21,4 +21,3 @@ function truncateString(str, lenMax) {
21
21
  return str;
22
22
  }
23
23
  }
24
- exports.truncateString = truncateString;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unique = void 0;
3
+ exports.unique = unique;
4
4
  function unique(arr) {
5
5
  return Array.from(new Set(arr));
6
6
  }
7
- exports.unique = unique;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseServer = exports.urlToFile = void 0;
3
+ exports.baseServer = void 0;
4
+ exports.urlToFile = urlToFile;
4
5
  const assert_js_1 = require("./assert.js");
5
6
  const parseUrl_js_1 = require("./parseUrl.js");
6
7
  const slice_js_1 = require("./slice.js");
@@ -33,4 +34,3 @@ function urlToFile(url, fileExtension, doNotCreateExtraDirectory) {
33
34
  const fileUrl = `${pathnameModified}${searchOriginal || ''}${hashOriginal || ''}`;
34
35
  return fileUrl;
35
36
  }
36
- exports.urlToFile = urlToFile;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVirtualFileId = exports.getVirtualFileId = exports.isVirtualFileId = void 0;
3
+ exports.isVirtualFileId = isVirtualFileId;
4
+ exports.getVirtualFileId = getVirtualFileId;
5
+ exports.resolveVirtualFileId = resolveVirtualFileId;
4
6
  const assert_js_1 = require("./assert.js");
5
7
  const idBase = 'virtual:vike:';
6
8
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
@@ -13,7 +15,6 @@ function isVirtualFileId(id) {
13
15
  (0, assert_js_1.assert)(!id.includes(idBase));
14
16
  return false;
15
17
  }
16
- exports.isVirtualFileId = isVirtualFileId;
17
18
  function getVirtualFileId(id) {
18
19
  if (id.startsWith(tag)) {
19
20
  id = id.slice(tag.length);
@@ -21,7 +22,6 @@ function getVirtualFileId(id) {
21
22
  (0, assert_js_1.assert)(!id.startsWith(tag));
22
23
  return id;
23
24
  }
24
- exports.getVirtualFileId = getVirtualFileId;
25
25
  function resolveVirtualFileId(id) {
26
26
  (0, assert_js_1.assert)(isVirtualFileId(id));
27
27
  if (!id.startsWith(tag)) {
@@ -30,4 +30,3 @@ function resolveVirtualFileId(id) {
30
30
  (0, assert_js_1.assert)(id.startsWith(tag));
31
31
  return id;
32
32
  }
33
- exports.resolveVirtualFileId = resolveVirtualFileId;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.viteIsSSR_options = exports.viteIsSSR = void 0;
3
+ exports.viteIsSSR = viteIsSSR;
4
+ exports.viteIsSSR_options = viteIsSSR_options;
4
5
  const assert_js_1 = require("./assert.js");
5
6
  const isObject_js_1 = require("./isObject.js");
6
7
  function viteIsSSR(config) {
7
8
  return !!config?.build?.ssr;
8
9
  }
9
- exports.viteIsSSR = viteIsSSR;
10
10
  // https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
11
11
  function viteIsSSR_options(options) {
12
12
  if (options === undefined) {
@@ -20,4 +20,3 @@ function viteIsSSR_options(options) {
20
20
  }
21
21
  (0, assert_js_1.assert)(false);
22
22
  }
23
- exports.viteIsSSR_options = viteIsSSR_options;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.warnIfErrorIsNotObject = void 0;
6
+ exports.warnIfErrorIsNotObject = warnIfErrorIsNotObject;
7
7
  const assert_js_1 = require("./assert.js");
8
8
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
9
9
  const isObject_js_1 = require("./isObject.js");
@@ -21,4 +21,3 @@ function warnIfErrorIsNotObject(err) {
21
21
  (0, assert_js_1.assertWarning)(false, `One of your hooks threw an error ${picocolors_1.default.cyan('throw someValue')} but ${picocolors_1.default.cyan('someValue')} isn't an object (it's ${picocolors_1.default.cyan(`typeof someValue === ${typeof err}`)} instead). Make sure thrown values are always wrapped with ${picocolors_1.default.cyan('new Error()')}, in other words: ${picocolors_1.default.cyan('throw someValue')} should be replaced with ${picocolors_1.default.cyan('throw new Error(someValue)')}. The thrown value is printed above.`, { onlyOnce: false });
22
22
  }
23
23
  }
24
- exports.warnIfErrorIsNotObject = warnIfErrorIsNotObject;
@@ -16,15 +16,13 @@ async function installClientRouter() {
16
16
  // Preserve stack track
17
17
  await renderPromise;
18
18
  }
19
- function render() {
19
+ async function render() {
20
20
  assert(getRenderCount() === 0);
21
- const renderPromise = renderPageClientSide({
21
+ await renderPageClientSide({
22
22
  scrollTarget: { preserveScroll: true },
23
23
  isBackwardNavigation: null,
24
24
  isClientSideNavigation: false
25
25
  });
26
- assert(getRenderCount() === 1);
27
- return renderPromise;
28
26
  }
29
27
  function initHistoryAndScroll() {
30
28
  setupNativeScrollRestoration();
@@ -7,6 +7,6 @@ async function isClientSideRoutable(pageId, pageContext) {
7
7
  sharedPageFilesAlreadyLoaded: false
8
8
  });
9
9
  const pageConfig = findPageConfig(pageContext._pageConfigs, pageId);
10
- const { clientEntryLoaded, isClientRouting } = analyzeClientSide(pageConfig, pageContext._pageFilesAll, pageId);
11
- return clientEntryLoaded && isClientRouting;
10
+ const { isClientRuntimeLoaded, isClientRouting } = analyzeClientSide(pageConfig, pageContext._pageFilesAll, pageId);
11
+ return isClientRuntimeLoaded && isClientRouting;
12
12
  }
@@ -1,6 +1,6 @@
1
1
  export { navigate };
2
2
  export { reload };
3
- import { renderPageClientSide } from './renderPageClientSide.js';
3
+ import { firstRenderStartPromise, renderPageClientSide } from './renderPageClientSide.js';
4
4
  import { assertClientRouting, assertUsageUrlPathname, getCurrentUrl } from './utils.js';
5
5
  assertClientRouting();
6
6
  /** Programmatically navigate to a new page.
@@ -13,6 +13,8 @@ assertClientRouting();
13
13
  */
14
14
  async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryEntry = false } = {}) {
15
15
  assertUsageUrlPathname(url, '[navigate(url)] url');
16
+ // If `hydrationCanBeAborted === false` (e.g. Vue) then we can apply navigate() only after hydration is done
17
+ await firstRenderStartPromise;
16
18
  const scrollTarget = { preserveScroll: keepScrollPosition };
17
19
  await renderPageClientSide({
18
20
  scrollTarget,
@@ -1,8 +1,10 @@
1
1
  export { renderPageClientSide };
2
2
  export { getRenderCount };
3
3
  export { disableClientRouting };
4
+ export { firstRenderStartPromise };
4
5
  import { type PageContextFromRewrite } from '../../shared/route/abort.js';
5
6
  import { type ScrollTarget } from './setScrollPosition.js';
7
+ declare const firstRenderStartPromise: Promise<void>;
6
8
  type RenderArgs = {
7
9
  scrollTarget: ScrollTarget;
8
10
  isBackwardNavigation: boolean | null;
@@ -1,7 +1,8 @@
1
1
  export { renderPageClientSide };
2
2
  export { getRenderCount };
3
3
  export { disableClientRouting };
4
- import { assert, getCurrentUrl, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType } from './utils.js';
4
+ export { firstRenderStartPromise };
5
+ import { assert, getCurrentUrl, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType, genPromise } from './utils.js';
5
6
  import { getPageContextFromHooks_isHydration, getPageContextFromHooks_isNotHydration, getPageContextFromHooks_serialized } from './getPageContextFromHooks.js';
6
7
  import { createPageContext } from './createPageContext.js';
7
8
  import { addLinkPrefetchHandlers } from './prefetch.js';
@@ -17,7 +18,15 @@ import { setScrollPosition } from './setScrollPosition.js';
17
18
  import { updateState } from './onBrowserHistoryNavigation.js';
18
19
  import { browserNativeScrollRestoration_disable, setInitialRenderIsDone } from './scrollRestoration.js';
19
20
  import { getErrorPageId } from '../../shared/error-page.js';
20
- const globalObject = getGlobalObject('renderPageClientSide.ts', { renderCounter: 0 });
21
+ const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
22
+ const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
23
+ return {
24
+ renderCounter: 0,
25
+ firstRenderStartPromise,
26
+ firstRenderStartPromiseResolve
27
+ };
28
+ })());
29
+ const { firstRenderStartPromise } = globalObject;
21
30
  async function renderPageClientSide(renderArgs) {
22
31
  const { scrollTarget, urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, isUserLandPushStateNavigation, isClientSideNavigation = true } = renderArgs;
23
32
  const { previousPageContext } = globalObject;
@@ -31,6 +40,9 @@ async function renderPageClientSide(renderArgs) {
31
40
  redirectHard(urlOriginal);
32
41
  return;
33
42
  }
43
+ globalObject.firstRenderStartPromiseResolve();
44
+ if (isRenderOutdated())
45
+ return;
34
46
  await renderPageNominal();
35
47
  return;
36
48
  async function renderPageNominal() {
@@ -81,20 +93,27 @@ async function renderPageClientSide(renderArgs) {
81
93
  }
82
94
  if (isRenderOutdated())
83
95
  return;
84
- let isClientRoutable;
85
96
  if (!pageContextFromRoute._pageId) {
86
- isClientRoutable = false;
87
- }
88
- else {
89
- isClientRoutable = await isClientSideRoutable(pageContextFromRoute._pageId, pageContext);
90
- if (isRenderOutdated())
91
- return;
97
+ /*
98
+ // We don't use the client router to render the 404 page:
99
+ // - So that the +redirects setting (https://vike.dev/redirects) can be applied.
100
+ // - This is the main argument.
101
+ // - See also failed CI: https://github.com/vikejs/vike/pull/1871
102
+ // - So that server-side error tracking can track 404 links?
103
+ // - We do use the client router for rendering the error page, so I don't think this is much of an argument.
104
+ await renderErrorPage({ is404: true })
105
+ */
106
+ redirectHard(urlOriginal);
107
+ return;
92
108
  }
109
+ assert(hasProp(pageContextFromRoute, '_pageId', 'string')); // Help TS
110
+ const isClientRoutable = await isClientSideRoutable(pageContextFromRoute._pageId, pageContext);
111
+ if (isRenderOutdated())
112
+ return;
93
113
  if (!isClientRoutable) {
94
114
  redirectHard(urlOriginal);
95
115
  return;
96
116
  }
97
- assert(hasProp(pageContextFromRoute, '_pageId', 'string')); // Help TS
98
117
  const isSamePage = pageContextFromRoute._pageId &&
99
118
  previousPageContext?._pageId &&
100
119
  pageContextFromRoute._pageId === previousPageContext._pageId;
@@ -208,9 +227,10 @@ async function renderPageClientSide(renderArgs) {
208
227
  const pageContext = await getPageContextBegin();
209
228
  if (isRenderOutdated())
210
229
  return;
211
- if (args.pageContextError) {
230
+ if (args.is404)
231
+ objectAssign(pageContext, { is404: true });
232
+ if (args.pageContextError)
212
233
  objectAssign(pageContext, args.pageContextError);
213
- }
214
234
  if ('err' in args) {
215
235
  const { err } = args;
216
236
  assert(!('errorWhileRendering' in pageContext));
@@ -266,6 +286,13 @@ async function renderPageClientSide(renderArgs) {
266
286
  objectAssign(pageContext, {
267
287
  _pageId: errorPageId
268
288
  });
289
+ const isClientRoutable = await isClientSideRoutable(pageContext._pageId, pageContext);
290
+ if (isRenderOutdated())
291
+ return;
292
+ if (!isClientRoutable) {
293
+ redirectHard(urlOriginal);
294
+ return;
295
+ }
269
296
  try {
270
297
  objectAssign(pageContext, await loadUserFilesClientSide(pageContext._pageId, pageContext._pageFilesAll, pageContext._pageConfigs));
271
298
  }
@@ -34,7 +34,7 @@ function isHashUrl(url) {
34
34
  return true;
35
35
  }
36
36
  const removeHash = (url) => url.split('#')[0];
37
- if (url.includes('#') && removeHash(url) === removeHash(window.location.href)) {
37
+ if (url.includes('#') && removeHash(url) === removeHash(window.location.pathname)) {
38
38
  return true;
39
39
  }
40
40
  return false;
@@ -22,3 +22,4 @@ export * from '../../utils/assertRoutingType.js';
22
22
  export * from '../../utils/onPageVisibilityChange.js';
23
23
  export * from '../../utils/augmentType.js';
24
24
  export * from '../../utils/PROJECT_VERSION.js';
25
+ export * from '../../utils/genPromise.js';
@@ -28,3 +28,4 @@ export * from '../../utils/assertRoutingType.js';
28
28
  export * from '../../utils/onPageVisibilityChange.js';
29
29
  export * from '../../utils/augmentType.js';
30
30
  export * from '../../utils/PROJECT_VERSION.js';
31
+ export * from '../../utils/genPromise.js';
@@ -1,105 +1,127 @@
1
1
  export { fileEnv };
2
- import { assert, assertUsage, assertWarning, capitalizeFirstLetter } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, capitalizeFirstLetter, joinEnglish } from '../utils.js';
3
3
  import { extractAssetsRE } from './extractAssetsPlugin.js';
4
4
  import { extractExportNamesRE } from './extractExportNamesPlugin.js';
5
5
  import pc from '@brillout/picocolors';
6
6
  import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
7
+ import { sourceMapRemove } from '../shared/rollupSourceMap.js';
8
+ import { getExportNames } from '../shared/parseEsModule.js';
7
9
  function fileEnv() {
8
10
  let config;
9
- let isDev = false;
11
+ let viteDevServer;
10
12
  return {
11
13
  name: 'vike:fileEnv',
12
- // - We need to set `enforce: 'pre'` because, otherwise, the resolvedId() hook of Vite's internal plugin `vite:resolve` is called before and it doesn't seem to call `this.resolve()` which means that the resolveId() hook below is never called.
13
- // - Vite's `vite:resolve` plugin: https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
14
- // - It's actually a good thing if the resolveId() hook below is the first one to be called because it doesn't actually resolve any ID, so all other resolveId() hooks will be called as normal. And with `this.resolve()` we get the information we want from all other resolvedId() hooks.
15
- // - Path aliases are already resolved, even when using `enforce: 'pre'`. For example:
16
- // ```js
17
- // // /pages/index/+Page.tsx
18
- //
19
- // // The value of `source` is `/home/rom/code/vike/examples/path-aliases/components/Counter` (instead of `#root/components/Counter`)
20
- // // The value of `importer` is `/home/rom/code/vike/examples/path-aliases/pages/index/+Page.tsx`
21
- // import { Counter } from '#root/components/Counter'
22
- // ```
23
- enforce: 'pre',
24
- resolveId: {
25
- /* I don't know why, but path aliases aren't resolved anymore when setting `order: 'pre'`. (In principle, I'd assume that `this.resolve()` would resolve the alias but it doesn't.)
26
- order: 'pre',
27
- */
28
- async handler(source, importer, options) {
29
- // It seems like Vite's scan doesn't apply transformers. (We need the `.telefunc.js` transformer to apply for our analysis to be correct.)
30
- // @ts-expect-error Vite's type is wrong
31
- if (options.scan)
32
- return;
33
- // TODO/v1-release: remove
34
- if (extractAssetsRE.test(source) || extractExportNamesRE.test(source))
35
- return;
36
- // Seems like Vite is doing some funky stuff here.
37
- if (importer?.endsWith('.html'))
38
- return;
39
- const resolved = await this.resolve(source, importer, {
40
- // Needed for old Vite plugins: https://vitejs.dev/guide/migration#rollup-4:~:text=For%20Vite%20plugins%2C%20this.resolve%20skipSelf%20option%20is%20now%20true%20by%20default.
41
- skipSelf: true,
42
- ...options
43
- });
44
- // resolved is null when import path is erroneous and doesn't actually point to a file
45
- if (!resolved)
46
- return;
47
- const moduleId = resolved.id;
48
- const modulePath = moduleId.split('?')[0];
49
- // `.server.js` and `.client.js` should only apply to user files
50
- if (modulePath.includes('/node_modules/'))
51
- return;
52
- // TODO/v1-release: remove
53
- // - I don't remember exactly, but I think I've added `TODO/v1-release: remove` because I vaguely remember that we can remove this after we remove the 0.4 design.
54
- if (modulePath.endsWith('.css'))
55
- return;
56
- const isServerSide = options?.ssr;
57
- const envActual = isServerSide ? 'server' : 'client';
58
- const envExpect = isServerSide ? 'client' : 'server';
59
- const suffix = `.${envExpect}.`;
60
- // Everything is good
61
- if (!modulePath.includes(suffix))
14
+ load(id, options) {
15
+ // In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
16
+ if (!viteDevServer)
17
+ return;
18
+ if (skip(id))
19
+ return;
20
+ const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
21
+ assert(moduleInfo);
22
+ const importers = Array.from(moduleInfo.importers)
23
+ .map((m) => m.id)
24
+ .filter((id) => id !== null);
25
+ assertFileEnv(id, !!options?.ssr, importers,
26
+ // In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
27
+ true);
28
+ },
29
+ // In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
30
+ async transform(code, id, options) {
31
+ // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
32
+ if (viteDevServer)
33
+ return;
34
+ if (skip(id))
35
+ return;
36
+ const isServerSide = !!options?.ssr;
37
+ if (!isWrongEnv(id, isServerSide))
38
+ return;
39
+ const { importers } = this.getModuleInfo(id);
40
+ // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code splitted.
41
+ const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
42
+ // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
43
+ const { exportNames } = await getExportNames(code);
44
+ return sourceMapRemove([
45
+ `throw new Error(${JSON.stringify(errMsg)});`,
46
+ ...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`)
47
+ ].join('\n'));
48
+ },
49
+ generateBundle() {
50
+ Array.from(this.getModuleIds())
51
+ .filter((id) => !skip(id))
52
+ .forEach((moduleId) => {
53
+ const { importers, dynamicImporters } = this.getModuleInfo(moduleId);
54
+ if (importers.length === 0) {
55
+ // Dynamic imports can only be verified at runtime
56
+ assert(dynamicImporters.length > 0);
62
57
  return;
63
- // Show error message
64
- let errMsg;
65
- let modulePathPretty = getModuleFilePathAbsolute(moduleId, config);
66
- modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
67
- errMsg = `${capitalizeFirstLetter(envExpect)}-only file ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
68
- if (importer &&
69
- // Don't show Vike's virtual modules that import the entry plus files such as /pages/about/+Page.js
70
- !importer.includes('virtual:vike:') &&
71
- // I don't know why and who sets importer to '<stdin>' (I guess Vite?)
72
- importer !== '<stdin>') {
73
- const importerPath = getModuleFilePathAbsolute(importer, config);
74
- errMsg += ` by ${importerPath}`;
75
- }
76
- if (isDev) {
77
- errMsg += ' and, therefore, Vike will prevent building your app for production.';
78
- assertWarning(false, errMsg, { onlyOnce: true });
79
- }
80
- else {
81
- assertUsage(false, errMsg);
82
58
  }
83
- }
59
+ assertFileEnv(moduleId, !!config.build.ssr, importers, false);
60
+ });
84
61
  },
85
62
  configResolved(config_) {
86
63
  config = config_;
87
64
  },
88
- configureServer() {
89
- isDev = true;
90
- },
91
- // Ensure this plugin works
92
- transform(_code, id, options) {
93
- if (isDev)
94
- return;
95
- // TODO/v1-release: remove
96
- if (extractAssetsRE.test(id) || extractExportNamesRE.test(id))
97
- return;
98
- if (id.split('?')[0].endsWith('.css'))
99
- return;
100
- const isServerSide = options?.ssr;
101
- const envWrong = isServerSide ? 'client' : 'server';
102
- assert(!id.includes(`.${envWrong}.`));
65
+ configureServer(viteDevServer_) {
66
+ viteDevServer = viteDevServer_;
103
67
  }
104
68
  };
69
+ function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
70
+ if (!isWrongEnv(moduleId, isServerSide))
71
+ return;
72
+ const errMsg = getErrorMessage(moduleId, isServerSide, importers, onlyWarn, false);
73
+ if (onlyWarn) {
74
+ assertWarning(false, errMsg, { onlyOnce: true });
75
+ }
76
+ else {
77
+ assertUsage(false, errMsg);
78
+ }
79
+ }
80
+ function getErrorMessage(moduleId, isServerSide, importers, onlyWarn, noColor) {
81
+ const modulePath = getModulePath(moduleId);
82
+ const envActual = isServerSide ? 'server' : 'client';
83
+ const envExpect = isServerSide ? 'client' : 'server';
84
+ let errMsg;
85
+ let modulePathPretty = getModuleFilePathAbsolute(modulePath, config);
86
+ if (!noColor) {
87
+ const suffix = getSuffix(envExpect);
88
+ modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
89
+ }
90
+ errMsg = `${capitalizeFirstLetter(envExpect)}-only file ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
91
+ if (importers.length > 0) {
92
+ const importPaths = importers.map((importer) => getModuleFilePathAbsolute(importer, config));
93
+ errMsg += ` by ${joinEnglish(importPaths, 'and')}`;
94
+ }
95
+ if (onlyWarn) {
96
+ errMsg += ' and, therefore, Vike will prevent building your app for production.';
97
+ }
98
+ return errMsg;
99
+ }
100
+ function isWrongEnv(moduleId, isServerSide) {
101
+ const modulePath = getModulePath(moduleId);
102
+ const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
103
+ return modulePath.includes(suffixWrong);
104
+ }
105
+ function skip(id) {
106
+ // TODO/v1-release: remove
107
+ if (extractAssetsRE.test(id) || extractExportNamesRE.test(id))
108
+ return true;
109
+ if (!id.includes(getSuffix('client')) && !id.includes(getSuffix('server')))
110
+ return true;
111
+ if (getModulePath(id).endsWith('.css'))
112
+ return true;
113
+ // Apply `.server.js` and `.client.js` only to user files
114
+ if (id.includes('/node_modules/'))
115
+ return true;
116
+ // Only user files
117
+ if (!id.startsWith(config.root))
118
+ return true;
119
+ return false;
120
+ }
121
+ function getSuffix(env) {
122
+ return `.${env}.`;
123
+ }
124
+ function getModulePath(moduleId) {
125
+ return moduleId.split('?')[0];
126
+ }
105
127
  }
@@ -72,7 +72,6 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
72
72
  fileTypes
73
73
  .filter((fileType) => fileType !== '.css')
74
74
  .forEach((fileType) => {
75
- assert(fileType !== '.css');
76
75
  const { includeImport, includeExportNames } = determineInjection({
77
76
  fileType,
78
77
  isForClientSide,
@@ -1,8 +1,8 @@
1
1
  export declare const debug: ((...msgs: unknown[]) => void) & {
2
2
  options: (optionsLocal: {
3
3
  serialization?: {
4
- emptyArray?: string | undefined;
5
- } | undefined;
4
+ emptyArray?: string;
5
+ };
6
6
  }) => (...msgs: unknown[]) => void;
7
7
  isActivated: boolean;
8
8
  };
@@ -28,7 +28,7 @@ const configDefinitionsBuiltIn = {
28
28
  env: { server: true, client: true }
29
29
  },
30
30
  passToClient: {
31
- env: { server: true, config: true },
31
+ env: { server: true },
32
32
  cumulative: true
33
33
  },
34
34
  route: {
@@ -76,7 +76,11 @@ const configDefinitionsBuiltIn = {
76
76
  meta: {
77
77
  env: { config: true }
78
78
  },
79
- clientEntryLoaded: {
79
+ // Whether the page loads:
80
+ // - Vike's client runtime
81
+ // - User's client hooks
82
+ // In other words, whether the page is "HTML-only" (https://vike.dev/render-modes). HTML-only pages shouldn't load the client runtime nor client hooks.
83
+ isClientRuntimeLoaded: {
80
84
  env: { server: true, client: true },
81
85
  eager: true,
82
86
  _computed: (configValueSources) => {
@@ -176,12 +176,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
176
176
  }
177
177
  if (debug.isActivated)
178
178
  debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
179
- pointerImports[importPathTranspiled] = isPointerImport;
180
179
  if (isExternal) {
180
+ pointerImports[importPathTranspiled] = isPointerImport;
181
181
  return { external: true, path: importPathTranspiled };
182
182
  }
183
183
  else {
184
- resolved.path = importPathTranspiled;
185
184
  return resolved;
186
185
  }
187
186
  });
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  export { processStream };
3
2
  export { streamToString };
4
3
  export { stampPipe };
@@ -13,5 +13,5 @@ export * from '../../types/index-dreprecated.js';
13
13
  * See https://vike.dev/render
14
14
  */
15
15
  export declare const RenderErrorPage: (args_0?: {
16
- pageContext?: Record<string, unknown> | undefined;
16
+ pageContext?: Record<string, unknown>;
17
17
  } | undefined) => Error;