vike 0.4.195-commit-3f77496 → 0.4.195-commit-c68b18f

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 (269) hide show
  1. package/dist/cjs/__internal/index.js +3 -4
  2. package/dist/cjs/node/cli/onLoad.js +1 -2
  3. package/dist/cjs/node/createPageRenderer.js +1 -2
  4. package/dist/cjs/node/plugin/index.js +3 -3
  5. package/dist/cjs/node/plugin/onLoad.js +1 -2
  6. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +1 -2
  7. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -2
  8. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +2 -3
  9. package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -4
  10. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -2
  11. package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -2
  12. package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +1 -2
  13. package/dist/cjs/node/plugin/plugins/config/index.js +1 -2
  14. package/dist/cjs/node/plugin/plugins/config/pickFirst.js +1 -2
  15. package/dist/cjs/node/plugin/plugins/config/resolveBase.js +2 -3
  16. package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -2
  17. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -2
  18. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -2
  19. package/dist/cjs/node/plugin/plugins/distFileNames.js +1 -2
  20. package/dist/cjs/node/plugin/plugins/envVars.js +1 -2
  21. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
  22. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +3 -3
  23. package/dist/cjs/node/plugin/plugins/fileEnv.js +109 -88
  24. package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -2
  25. package/dist/cjs/node/plugin/plugins/importBuild/index.js +2 -3
  26. package/dist/cjs/node/plugin/plugins/importUserCode/addImportStatement.js +1 -2
  27. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -3
  28. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -2
  29. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +2 -3
  30. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +1 -2
  31. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -2
  32. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +8 -9
  33. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -4
  34. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +3 -4
  35. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +3 -4
  36. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +5 -7
  37. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +6 -6
  38. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -2
  39. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -2
  40. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +1 -2
  41. package/dist/cjs/node/plugin/plugins/packageJsonFile.js +1 -2
  42. package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -2
  43. package/dist/cjs/node/plugin/plugins/removeRequireHookPlugin.js +1 -2
  44. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -2
  45. package/dist/cjs/node/plugin/plugins/suppressRollupWarning.js +1 -2
  46. package/dist/cjs/node/plugin/plugins/workaroundCssModuleHmr.js +1 -2
  47. package/dist/cjs/node/plugin/resolveClientEntriesDev.js +1 -2
  48. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +1 -2
  49. package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -2
  50. package/dist/cjs/node/plugin/shared/getAssetsDir.js +1 -2
  51. package/dist/cjs/node/plugin/shared/getFilePath.js +8 -9
  52. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +2 -3
  53. package/dist/cjs/node/plugin/shared/isAsset.js +1 -2
  54. package/dist/cjs/node/plugin/shared/isViteCliCall.js +2 -3
  55. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -5
  56. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +4 -5
  57. package/dist/cjs/node/plugin/shared/loggerNotProd.js +6 -7
  58. package/dist/cjs/node/plugin/shared/loggerVite/removeSuperfluousViteLog.js +3 -4
  59. package/dist/cjs/node/plugin/shared/loggerVite.js +1 -2
  60. package/dist/cjs/node/plugin/shared/parseEsModule.js +2 -3
  61. package/dist/cjs/node/plugin/shared/rollupIsEsm.js +1 -2
  62. package/dist/cjs/node/plugin/shared/rollupSourceMap.js +2 -3
  63. package/dist/cjs/node/prerender/runPrerender.js +4 -5
  64. package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +2 -3
  65. package/dist/cjs/node/runtime/globalContext.js +13 -14
  66. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -2
  67. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +1 -2
  68. package/dist/cjs/node/runtime/html/injectAssets/inferHtmlTags.js +4 -4
  69. package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -2
  70. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +6 -7
  71. package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +1 -2
  72. package/dist/cjs/node/runtime/html/injectAssets/sanitizeJson.js +1 -2
  73. package/dist/cjs/node/runtime/html/injectAssets.js +2 -3
  74. package/dist/cjs/node/runtime/html/renderHtml.js +5 -6
  75. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -3
  76. package/dist/cjs/node/runtime/html/stream/react-streaming.js +3 -4
  77. package/dist/cjs/node/runtime/html/stream.js +21 -22
  78. package/dist/cjs/node/runtime/onLoad.js +1 -2
  79. package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +1 -2
  80. package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -2
  81. package/dist/cjs/node/runtime/renderPage/assertArguments.js +1 -2
  82. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -2
  83. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -2
  84. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +5 -6
  85. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +1 -2
  86. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -2
  87. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
  88. package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -2
  89. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -3
  90. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -2
  91. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -2
  92. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -2
  93. package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +1 -2
  94. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +2 -3
  95. package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -2
  96. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -2
  97. package/dist/cjs/node/runtime/renderPage/inferMediaType.js +1 -2
  98. package/dist/cjs/node/runtime/renderPage/isNewError.js +2 -3
  99. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -2
  100. package/dist/cjs/node/runtime/renderPage/log404/index.js +2 -3
  101. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +2 -3
  102. package/dist/cjs/node/runtime/renderPage/loggerProd.js +2 -3
  103. package/dist/cjs/node/runtime/renderPage/loggerRuntime.js +2 -2
  104. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -2
  105. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -6
  106. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +2 -3
  107. package/dist/cjs/node/runtime/renderPage.js +2 -2
  108. package/dist/cjs/node/shared/assertPluginManifest.js +1 -2
  109. package/dist/cjs/node/shared/assertRuntimeManifest.js +1 -2
  110. package/dist/cjs/node/shared/assertV1Design.js +1 -2
  111. package/dist/cjs/node/shared/extractAssetsQuery.js +2 -3
  112. package/dist/cjs/node/shared/getConfigVike.js +1 -2
  113. package/dist/cjs/node/shared/isErrorDebug.js +1 -2
  114. package/dist/cjs/node/shared/prependEntriesDir.js +1 -2
  115. package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +2 -2
  116. package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +2 -3
  117. package/dist/cjs/shared/addIs404ToPageProps.js +1 -2
  118. package/dist/cjs/shared/assertHookReturnedObject.js +1 -2
  119. package/dist/cjs/shared/assertOnBeforeRenderHookReturn.js +1 -2
  120. package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -2
  121. package/dist/cjs/shared/assertPageFilePath.js +1 -2
  122. package/dist/cjs/shared/determinePageIdOld.js +1 -2
  123. package/dist/cjs/shared/error-page.js +3 -4
  124. package/dist/cjs/shared/getPageContextRequestUrl.js +2 -2
  125. package/dist/cjs/shared/getPageContextUrlComputed.js +2 -3
  126. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +1 -2
  127. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +1 -2
  128. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +2 -3
  129. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/getExportNames.js +1 -2
  130. package/dist/cjs/shared/getPageFiles/analyzePageClientSide.js +2 -3
  131. package/dist/cjs/shared/getPageFiles/analyzePageServerSide.js +1 -2
  132. package/dist/cjs/shared/getPageFiles/assert_exports_old_design.js +3 -3
  133. package/dist/cjs/shared/getPageFiles/fileTypes.js +3 -3
  134. package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +2 -3
  135. package/dist/cjs/shared/getPageFiles/getExports.js +1 -2
  136. package/dist/cjs/shared/getPageFiles/getPageFileObject.js +1 -2
  137. package/dist/cjs/shared/getPageFiles/parseGlobResults.js +1 -2
  138. package/dist/cjs/shared/getPageFiles/setPageFiles.js +3 -4
  139. package/dist/cjs/shared/hooks/executeHook.js +4 -5
  140. package/dist/cjs/shared/hooks/getHook.js +6 -7
  141. package/dist/cjs/shared/modifyUrl.js +1 -2
  142. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -2
  143. package/dist/cjs/shared/page-configs/findPageConfig.js +1 -2
  144. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +3 -4
  145. package/dist/cjs/shared/page-configs/getConfigValue.js +2 -3
  146. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +1 -2
  147. package/dist/cjs/shared/page-configs/getExportPath.js +1 -2
  148. package/dist/cjs/shared/page-configs/helpers.js +3 -4
  149. package/dist/cjs/shared/page-configs/loadConfigValues.js +1 -2
  150. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -3
  151. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -2
  152. package/dist/cjs/shared/route/abort.js +9 -10
  153. package/dist/cjs/shared/route/debug.js +1 -2
  154. package/dist/cjs/shared/route/deduceRouteStringFromFilesystemPath.js +1 -2
  155. package/dist/cjs/shared/route/executeGuardHook.js +1 -2
  156. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -2
  157. package/dist/cjs/shared/route/index.js +1 -2
  158. package/dist/cjs/shared/route/loadPageRoutes.js +1 -2
  159. package/dist/cjs/shared/route/resolvePrecedence.js +1 -2
  160. package/dist/cjs/shared/route/resolveRoute.js +1 -2
  161. package/dist/cjs/shared/route/resolveRouteFunction.js +4 -5
  162. package/dist/cjs/shared/route/resolveRouteString.js +6 -7
  163. package/dist/cjs/shared/route/resolveUrlPathname.js +1 -2
  164. package/dist/cjs/shared/sortPageContext.js +1 -2
  165. package/dist/cjs/types/defineConfig.js +1 -2
  166. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  167. package/dist/cjs/utils/assert.js +10 -11
  168. package/dist/cjs/utils/assertIsBrowser.js +1 -2
  169. package/dist/cjs/utils/assertIsNotBrowser.js +1 -2
  170. package/dist/cjs/utils/assertIsNotProductionRuntime.js +6 -6
  171. package/dist/cjs/utils/assertKeys.js +1 -2
  172. package/dist/cjs/utils/assertNodeEnv.js +5 -6
  173. package/dist/cjs/utils/assertNodeVersion.js +1 -2
  174. package/dist/cjs/utils/assertRoutingType.js +3 -4
  175. package/dist/cjs/utils/assertSingleInstance.js +3 -4
  176. package/dist/cjs/utils/assertVersion.js +2 -3
  177. package/dist/cjs/utils/augmentType.js +1 -2
  178. package/dist/cjs/utils/capitalizeFirstLetter.js +1 -2
  179. package/dist/cjs/utils/cast.js +2 -3
  180. package/dist/cjs/utils/changeEnumerable.js +1 -2
  181. package/dist/cjs/utils/checkType.js +2 -3
  182. package/dist/cjs/utils/compareString.js +1 -2
  183. package/dist/cjs/utils/createErrorWithCleanStackTrace.js +1 -2
  184. package/dist/cjs/utils/debug.js +2 -3
  185. package/dist/cjs/utils/deepEqual.js +1 -2
  186. package/dist/cjs/utils/escapeHtml.js +1 -2
  187. package/dist/cjs/utils/escapeRegex.js +1 -2
  188. package/dist/cjs/utils/filesystemPathHandling.js +2 -3
  189. package/dist/cjs/utils/findFile.js +1 -2
  190. package/dist/cjs/utils/findPackageJson.js +1 -2
  191. package/dist/cjs/utils/formatHintLog.js +1 -2
  192. package/dist/cjs/utils/freezePartial.js +1 -2
  193. package/dist/cjs/utils/genPromise.js +1 -2
  194. package/dist/cjs/utils/getCurrentUrl.js +1 -2
  195. package/dist/cjs/utils/getFileExtension.js +1 -2
  196. package/dist/cjs/utils/getGlobalObject.js +2 -3
  197. package/dist/cjs/utils/getMostSimilar.js +1 -2
  198. package/dist/cjs/utils/getOutDirs.js +2 -3
  199. package/dist/cjs/utils/getPropAccessNotation.js +1 -2
  200. package/dist/cjs/utils/getRandomId.js +1 -2
  201. package/dist/cjs/utils/getTerminWidth.js +1 -2
  202. package/dist/cjs/utils/getValuePrintable.js +1 -2
  203. package/dist/cjs/utils/hasProp.js +1 -2
  204. package/dist/cjs/utils/humanizeTime.js +1 -2
  205. package/dist/cjs/utils/includes.js +1 -2
  206. package/dist/cjs/utils/injectRollupInputs.js +2 -3
  207. package/dist/cjs/utils/isArray.js +1 -2
  208. package/dist/cjs/utils/isArrayOfStrings.js +1 -2
  209. package/dist/cjs/utils/isBrowser.js +1 -2
  210. package/dist/cjs/utils/isCallable.js +1 -2
  211. package/dist/cjs/utils/isDev.js +2 -3
  212. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -3
  213. package/dist/cjs/utils/isHtml.js +1 -2
  214. package/dist/cjs/utils/isNodeJS.js +1 -2
  215. package/dist/cjs/utils/isNpmPackage.js +5 -6
  216. package/dist/cjs/utils/isObject.js +1 -2
  217. package/dist/cjs/utils/isObjectOfStrings.js +1 -2
  218. package/dist/cjs/utils/isObjectWithKeys.js +1 -2
  219. package/dist/cjs/utils/isPlainObject.js +1 -2
  220. package/dist/cjs/utils/isPromise.js +1 -2
  221. package/dist/cjs/utils/isPropertyGetter.js +1 -2
  222. package/dist/cjs/utils/isReact.js +1 -2
  223. package/dist/cjs/utils/isSameErrorMessage.js +1 -2
  224. package/dist/cjs/utils/isScriptFile.js +4 -4
  225. package/dist/cjs/utils/isVikeReactApp.js +1 -2
  226. package/dist/cjs/utils/isVitest.js +1 -2
  227. package/dist/cjs/utils/joinEnglish.js +1 -2
  228. package/dist/cjs/utils/normalizeHeaders.js +1 -2
  229. package/dist/cjs/utils/objectAssign.js +1 -2
  230. package/dist/cjs/utils/objectDefineProperty.js +1 -2
  231. package/dist/cjs/utils/objectEntries.js +1 -2
  232. package/dist/cjs/utils/objectEntriesForEach.js +1 -2
  233. package/dist/cjs/utils/objectFromEntries.js +1 -2
  234. package/dist/cjs/utils/objectKeys.js +1 -2
  235. package/dist/cjs/utils/onPageVisibilityChange.js +2 -3
  236. package/dist/cjs/utils/pLimit.js +1 -2
  237. package/dist/cjs/utils/parseUrl-extras.js +8 -9
  238. package/dist/cjs/utils/parseUrl.js +11 -12
  239. package/dist/cjs/utils/path-shim.js +1 -2
  240. package/dist/cjs/utils/redirectHard.js +1 -2
  241. package/dist/cjs/utils/removeEmptyLines.js +1 -2
  242. package/dist/cjs/utils/removeFileExtention.js +1 -2
  243. package/dist/cjs/utils/requireResolve.js +1 -2
  244. package/dist/cjs/utils/sleep.js +1 -2
  245. package/dist/cjs/utils/slice.js +1 -2
  246. package/dist/cjs/utils/sorter.js +5 -6
  247. package/dist/cjs/utils/stringifyStringArray.js +1 -2
  248. package/dist/cjs/utils/stripAnsi.js +1 -2
  249. package/dist/cjs/utils/throttle.js +1 -2
  250. package/dist/cjs/utils/trimWithAnsi.js +2 -3
  251. package/dist/cjs/utils/truncateString.js +1 -2
  252. package/dist/cjs/utils/unique.js +1 -2
  253. package/dist/cjs/utils/urlToFile.js +2 -2
  254. package/dist/cjs/utils/virtual-files.js +3 -4
  255. package/dist/cjs/utils/viteIsSSR.js +2 -3
  256. package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -2
  257. package/dist/esm/node/plugin/plugins/fileEnv.js +109 -87
  258. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
  259. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +2 -2
  260. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +1 -2
  261. package/dist/esm/node/runtime/html/stream.d.ts +0 -1
  262. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -1
  263. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +0 -1
  264. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +6 -6
  265. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  266. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  267. package/dist/esm/utils/debugGlob.d.ts +2 -2
  268. package/dist/esm/utils/projectInfo.d.ts +1 -1
  269. package/package.json +2 -2
@@ -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;
@@ -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
  };
@@ -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;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  export { getHttpResponseBody };
3
2
  export { getHttpResponseBodyStreamHandlers };
4
3
  export type { HttpResponseBody };
@@ -78,7 +78,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
78
78
  _urlRewrite: null;
79
79
  _httpRequestId: number | null;
80
80
  _usesClientRouter: boolean;
81
- _pageContextAlreadyProvidedByOnPrerenderHook?: true | undefined;
81
+ _pageContextAlreadyProvidedByOnPrerenderHook?: true;
82
82
  is404: null | boolean;
83
83
  } & {
84
84
  isClientSideNavigation: boolean;
@@ -129,7 +129,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
129
129
  _urlRewrite: null;
130
130
  _httpRequestId: number | null;
131
131
  _usesClientRouter: boolean;
132
- _pageContextAlreadyProvidedByOnPrerenderHook?: true | undefined;
132
+ _pageContextAlreadyProvidedByOnPrerenderHook?: true;
133
133
  is404: null | boolean;
134
134
  } & {
135
135
  isClientSideNavigation: boolean;
@@ -181,8 +181,8 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
181
181
  _urlRewrite: null;
182
182
  _httpRequestId: number | null;
183
183
  _usesClientRouter: boolean;
184
- _pageContextAlreadyProvidedByOnPrerenderHook?: true | undefined;
185
- is404: boolean | null;
184
+ _pageContextAlreadyProvidedByOnPrerenderHook?: true;
185
+ is404: null | boolean;
186
186
  } & {
187
187
  isClientSideNavigation: boolean;
188
188
  _urlHandler: null;
@@ -232,8 +232,8 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
232
232
  _urlRewrite: null;
233
233
  _httpRequestId: number | null;
234
234
  _usesClientRouter: boolean;
235
- _pageContextAlreadyProvidedByOnPrerenderHook?: true | undefined;
236
- is404: boolean | null;
235
+ _pageContextAlreadyProvidedByOnPrerenderHook?: true;
236
+ is404: null | boolean;
237
237
  } & {
238
238
  isClientSideNavigation: boolean;
239
239
  _urlHandler: null;
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.195-commit-3f77496";
1
+ export declare const PROJECT_VERSION: "0.4.195-commit-c68b18f";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.195-commit-3f77496';
2
+ export const PROJECT_VERSION = '0.4.195-commit-c68b18f';
@@ -1,8 +1,8 @@
1
1
  export declare const debugGlob: ((...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
  };
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.195-commit-3f77496";
3
+ projectVersion: "0.4.195-commit-c68b18f";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.195-commit-3f77496",
3
+ "version": "0.4.195-commit-c68b18f",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -242,7 +242,7 @@
242
242
  "semver": "^7.6.3",
243
243
  "sirv": "^2.0.4",
244
244
  "source-map-support": "^0.5.21",
245
- "typescript": "^5.4.5",
245
+ "typescript": "^5.6.2",
246
246
  "vite": "^5.4.0"
247
247
  },
248
248
  "scripts": {