vike 0.4.220-commit-af5c91f → 0.4.221-commit-8577456

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 (162) hide show
  1. package/dist/cjs/__internal/index.js +5 -23
  2. package/dist/cjs/node/api/build.js +55 -11
  3. package/dist/cjs/node/api/prepareViteApiCall.js +20 -17
  4. package/dist/cjs/node/api/prerender.js +1 -0
  5. package/dist/cjs/node/api/utils.js +1 -0
  6. package/dist/cjs/node/plugin/index.js +2 -0
  7. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +9 -20
  8. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  9. package/dist/cjs/node/plugin/plugins/buildApp.js +72 -0
  10. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -10
  11. package/dist/cjs/node/plugin/plugins/buildConfig.js +5 -5
  12. package/dist/cjs/node/plugin/plugins/buildEntry/index.js +2 -2
  13. package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
  14. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  15. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -2
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{assertExtensions.js → getVikeConfig/assertExtensions.js} +31 -31
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +53 -21
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.js → getVikeConfig/getConfigFileExport.js} +2 -2
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +159 -0
  20. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
  21. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +205 -343
  22. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{debug.js → virtual-files/debug.js} +1 -1
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.js → virtual-files/getVirtualFilePageConfigValuesAll.js} +7 -7
  24. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.js → virtual-files/getVirtualFilePageConfigs.js} +3 -3
  25. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -4
  26. package/dist/cjs/node/plugin/shared/getFullBuildInlineConfig.js +20 -0
  27. package/dist/cjs/node/plugin/shared/getOutDirs.js +50 -38
  28. package/dist/cjs/node/prerender/runPrerender.js +29 -30
  29. package/dist/cjs/node/runtime/globalContext.js +186 -100
  30. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -3
  31. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -3
  32. package/dist/cjs/node/runtime/html/injectAssets.js +4 -4
  33. package/dist/cjs/node/runtime/html/renderHtml.js +4 -5
  34. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -3
  35. package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +2 -4
  36. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +4 -4
  37. package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +3 -5
  38. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +5 -4
  39. package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -2
  40. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +10 -9
  41. package/dist/cjs/node/runtime/renderPage.js +27 -30
  42. package/dist/cjs/node/runtime/utils.js +1 -0
  43. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +5 -3
  44. package/dist/cjs/node/shared/resolveBase.js +3 -5
  45. package/dist/cjs/shared/getPageConfigsRuntime.js +20 -0
  46. package/dist/cjs/shared/getPageFiles/parseGlobResults.js +4 -3
  47. package/dist/cjs/shared/getPageFiles.js +1 -3
  48. package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +13 -4
  49. package/dist/cjs/shared/route/loadPageRoutes.js +1 -0
  50. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  51. package/dist/cjs/utils/assertSetup.js +1 -1
  52. package/dist/cjs/utils/debug.js +8 -6
  53. package/dist/cjs/utils/findFile.js +1 -0
  54. package/dist/cjs/utils/objectAssignSafe.js +7 -0
  55. package/dist/esm/__internal/index.d.ts +2 -2
  56. package/dist/esm/__internal/index.js +7 -26
  57. package/dist/esm/client/client-routing-runtime/createPageContext.js +5 -9
  58. package/dist/esm/client/server-routing-runtime/getPageContext.js +3 -4
  59. package/dist/esm/client/shared/loadUserFilesClientSide.js +3 -2
  60. package/dist/esm/node/api/build.js +23 -12
  61. package/dist/esm/node/api/prepareViteApiCall.d.ts +4 -2
  62. package/dist/esm/node/api/prepareViteApiCall.js +20 -17
  63. package/dist/esm/node/api/prerender.js +1 -0
  64. package/dist/esm/node/api/utils.d.ts +1 -0
  65. package/dist/esm/node/api/utils.js +1 -0
  66. package/dist/esm/node/plugin/index.js +2 -0
  67. package/dist/esm/node/plugin/plugins/autoFullBuild.js +10 -21
  68. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  69. package/dist/esm/node/plugin/plugins/buildApp.d.ts +3 -0
  70. package/dist/esm/node/plugin/plugins/buildApp.js +70 -0
  71. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +0 -2
  72. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -10
  73. package/dist/esm/node/plugin/plugins/buildConfig.js +6 -6
  74. package/dist/esm/node/plugin/plugins/buildEntry/index.js +2 -2
  75. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
  76. package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
  77. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  78. package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -2
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.d.ts +6 -0
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{assertExtensions.js → getVikeConfig/assertExtensions.js} +31 -31
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +52 -20
  83. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.js → getVikeConfig/getConfigFileExport.js} +2 -2
  84. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts +39 -0
  85. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +154 -0
  86. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +2 -2
  87. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
  88. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -38
  89. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +208 -346
  90. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{debug.js → virtual-files/debug.js} +1 -1
  91. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.js → virtual-files/getVirtualFilePageConfigValuesAll.js} +7 -7
  92. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.js → virtual-files/getVirtualFilePageConfigs.js} +3 -3
  93. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.d.ts → virtual-files/isRuntimeEnvMatch.d.ts} +1 -1
  94. package/dist/esm/node/plugin/plugins/setGlobalContext.js +2 -5
  95. package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.d.ts +2 -0
  96. package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.js +17 -0
  97. package/dist/esm/node/plugin/shared/getOutDirs.d.ts +1 -1
  98. package/dist/esm/node/plugin/shared/getOutDirs.js +50 -38
  99. package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +2 -5
  100. package/dist/esm/node/prerender/runPrerender.d.ts +2 -2
  101. package/dist/esm/node/prerender/runPrerender.js +30 -31
  102. package/dist/esm/node/runtime/globalContext.d.ts +31 -29
  103. package/dist/esm/node/runtime/globalContext.js +186 -100
  104. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +1 -1
  105. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -3
  106. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +4 -1
  107. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -3
  108. package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -0
  109. package/dist/esm/node/runtime/html/injectAssets.js +4 -4
  110. package/dist/esm/node/runtime/html/renderHtml.js +4 -5
  111. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -1
  112. package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -3
  113. package/dist/esm/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.d.ts +1 -1
  114. package/dist/esm/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +2 -4
  115. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -0
  116. package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -4
  117. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -0
  118. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +3 -5
  119. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -0
  120. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +6 -5
  121. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -0
  122. package/dist/esm/node/runtime/renderPage/log404/index.js +1 -2
  123. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -0
  124. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +21 -5
  125. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +10 -9
  126. package/dist/esm/node/runtime/renderPage.js +28 -31
  127. package/dist/esm/node/runtime/utils.d.ts +1 -0
  128. package/dist/esm/node/runtime/utils.js +1 -0
  129. package/dist/esm/node/runtime-dev/createDevMiddleware.js +5 -3
  130. package/dist/esm/node/shared/resolveBase.d.ts +2 -1
  131. package/dist/esm/node/shared/resolveBase.js +3 -5
  132. package/dist/esm/shared/getPageConfigsRuntime.d.ts +13 -0
  133. package/dist/esm/shared/getPageConfigsRuntime.js +18 -0
  134. package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +1 -1
  135. package/dist/esm/shared/getPageFiles/parseGlobResults.js +4 -3
  136. package/dist/esm/shared/getPageFiles.d.ts +0 -1
  137. package/dist/esm/shared/getPageFiles.js +0 -1
  138. package/dist/esm/shared/page-configs/Config.d.ts +7 -0
  139. package/dist/esm/shared/page-configs/PageConfig.d.ts +9 -5
  140. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +5 -7
  141. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +13 -4
  142. package/dist/esm/shared/route/loadPageRoutes.js +1 -0
  143. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  144. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  145. package/dist/esm/utils/assertSetup.js +1 -1
  146. package/dist/esm/utils/debug.d.ts +1 -1
  147. package/dist/esm/utils/debug.js +8 -6
  148. package/dist/esm/utils/findFile.js +1 -0
  149. package/dist/esm/utils/objectAssignSafe.d.ts +1 -0
  150. package/dist/esm/utils/objectAssignSafe.js +4 -0
  151. package/dist/esm/utils/projectInfo.d.ts +1 -1
  152. package/package.json +2 -2
  153. package/dist/cjs/shared/getPageFiles/getPageFiles.js +0 -48
  154. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +0 -6
  155. package/dist/esm/shared/getPageFiles/getPageFiles.d.ts +0 -15
  156. package/dist/esm/shared/getPageFiles/getPageFiles.js +0 -46
  157. /package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.js → virtual-files/isRuntimeEnvMatch.js} +0 -0
  158. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.d.ts → getVikeConfig/getConfigFileExport.d.ts} +0 -0
  159. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{debug.d.ts → virtual-files/debug.d.ts} +0 -0
  160. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.d.ts → virtual-files/getVirtualFilePageConfigValuesAll.d.ts} +0 -0
  161. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.d.ts → virtual-files/getVirtualFilePageConfigs.d.ts} +0 -0
  162. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.js → virtual-files/isRuntimeEnvMatch.js} +0 -0
@@ -2,64 +2,94 @@
2
2
  export { getGlobalContextSync };
3
3
  export { getGlobalContextAsync };
4
4
  // Internal use
5
- export { getGlobalContext };
5
+ export { getGlobalContextInternal };
6
6
  export { getViteDevServer };
7
7
  export { getViteConfig };
8
8
  export { initGlobalContext_renderPage };
9
9
  export { initGlobalContext_runPrerender };
10
- export { initGlobalContext_getGlobalContextAsync };
10
+ export { initGlobalContext_getPagesAndRoutes };
11
11
  export { setGlobalContext_viteDevServer };
12
12
  export { setGlobalContext_viteConfig };
13
- export { setGlobalContext_vikeConfig };
14
- export { setGlobalContext_isViteDev };
15
13
  export { setGlobalContext_isPrerendering };
14
+ export { setGlobalContext_isProduction };
16
15
  export { setGlobalContext_buildEntry };
17
16
  export { clearGlobalContext };
18
17
  export { assertBuildInfo };
19
18
  export { getViteConfigRuntime };
19
+ export { updateUserFiles };
20
+ // The core logic revolves around:
21
+ // - globalObject.userFiles which is the main requirement for assembleGlobalContext()
22
+ // - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
23
+ // - loadBuildEntry() sets globalObject.buildEntry and then sets globalObject.userFiles
24
+ // - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_buildEntry()
25
+ // - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
26
+ // - In development: globalObject.viteDevServer which is Vite's development server
27
+ // - globalObject.viteDevServer is used by updateUserFiles() which then sets globalConfig.userFiles
20
28
  import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectAssign, objectReplace, isObject, hasProp, debugGlob, getGlobalObject, genPromise, createDebugger, makePublicCopy, projectInfo, checkType } from './utils.js';
21
29
  import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
22
30
  import { virtualFileIdImportUserCodeServer } from '../shared/virtual-files/virtualFileImportUserCode.js';
23
- import { getPageFilesAll, setPageFiles, setPageFilesAsync } from '../../shared/getPageFiles/getPageFiles.js';
24
31
  import pc from '@brillout/picocolors';
25
32
  import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
26
33
  import { assertV1Design } from '../shared/assertV1Design.js';
34
+ import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
27
35
  const debug = createDebugger('vike:globalContext');
28
36
  const globalObject = getGlobalObject('globalContext.ts', getInitialGlobalContext());
29
- initDevEntry();
30
- function getGlobalContext() {
31
- if (!globalObject.globalContext) {
32
- debug('getGlobalContext()', new Error().stack);
37
+ async function getGlobalContextInternal() {
38
+ // getGlobalContextInternal() should always be called after initGlobalContext()
39
+ assert(globalObject.isInitialized);
40
+ assertGlobalContextIsDefined();
41
+ if (globalObject.isProduction !== true)
42
+ await globalObject.waitForUserFilesUpdate;
43
+ const { globalContext } = globalObject;
44
+ assertIsDefined(globalContext);
45
+ return globalContext;
46
+ }
47
+ function assertIsDefined(globalContext) {
48
+ if (!globalContext) {
49
+ debug('globalContext', globalContext);
50
+ debug('assertIsDefined()', new Error().stack);
33
51
  assert(false);
34
52
  }
35
- return globalObject.globalContext;
53
+ }
54
+ function assertGlobalContextIsDefined() {
55
+ assertIsDefined(globalObject.globalContext);
56
+ assert(globalObject.globalContext_public);
36
57
  }
37
58
  /** @experimental https://vike.dev/getGlobalContext */
38
59
  function getGlobalContextSync() {
39
- assertUsage(globalObject.globalContext, "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContextAsync() instead.");
40
- return makePublic(globalObject.globalContext);
60
+ const { globalContext_public } = globalObject;
61
+ assertUsage(globalContext_public, "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContextAsync() instead.");
62
+ return globalContext_public;
41
63
  }
42
64
  /** @experimental https://vike.dev/getGlobalContext */
43
65
  async function getGlobalContextAsync(isProduction) {
44
66
  assertUsage(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${pc.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${pc.cyan('true')} or ${pc.cyan('false')}`}`);
45
- await initGlobalContext_getGlobalContextAsync(isProduction);
46
- const { globalContext } = globalObject;
47
- assert(globalContext);
48
- return makePublic(globalContext);
67
+ setIsProduction(isProduction);
68
+ if (!globalObject.globalContext)
69
+ await initGlobalContext_getGlobalContextAsync();
70
+ if (!isProduction)
71
+ await globalObject.waitForUserFilesUpdate;
72
+ assertGlobalContextIsDefined();
73
+ const { globalContext_public } = globalObject;
74
+ assert(globalContext_public);
75
+ return globalContext_public;
49
76
  }
50
77
  function makePublic(globalContext) {
51
- // TODO/now: add viteConfig and vikeConfig
52
- const globalContextPublic = makePublicCopy(globalContext, 'globalContext', ['assetsManifest']);
78
+ // TODO/soon: add `pages`
79
+ const globalContextPublic = makePublicCopy(globalContext, 'globalContext', ['assetsManifest', 'config', 'viteConfig']);
53
80
  return globalContextPublic;
54
81
  }
55
- function setGlobalContext_viteDevServer(viteDevServer) {
82
+ async function setGlobalContext_viteDevServer(viteDevServer) {
83
+ debug('setGlobalContext_viteDevServer()');
84
+ setIsProduction(false);
56
85
  if (globalObject.viteDevServer)
57
86
  return;
58
87
  assertIsNotInitilizedYet();
59
88
  assert(globalObject.viteConfig);
60
89
  globalObject.viteDevServer = viteDevServer;
90
+ await updateUserFiles();
91
+ assertGlobalContextIsDefined();
61
92
  globalObject.viteDevServerPromiseResolve(viteDevServer);
62
- eagerlyLoadUserFiles();
63
93
  }
64
94
  function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
65
95
  if (globalObject.viteConfig)
@@ -68,21 +98,16 @@ function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
68
98
  globalObject.viteConfig = viteConfig;
69
99
  globalObject.outDirRoot = outDirRoot;
70
100
  }
71
- function setGlobalContext_vikeConfig(vikeConfig) {
72
- if (globalObject.vikeConfig)
73
- return;
74
- assertIsNotInitilizedYet();
75
- globalObject.vikeConfig = vikeConfig;
76
- }
77
101
  function assertIsNotInitilizedYet() {
78
- // In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
102
+ // In development, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
79
103
  assert(!globalObject.globalContext);
80
104
  }
81
- function setGlobalContext_isViteDev(isViteDev) {
82
- globalObject.isViteDev = isViteDev;
83
- }
84
105
  function setGlobalContext_isPrerendering() {
85
106
  globalObject.isPrerendering = true;
107
+ setIsProduction(true);
108
+ }
109
+ function setGlobalContext_isProduction(isProduction) {
110
+ setIsProduction(isProduction);
86
111
  }
87
112
  function getViteDevServer() {
88
113
  return globalObject.viteDevServer ?? null;
@@ -92,10 +117,15 @@ function getViteConfig() {
92
117
  }
93
118
  async function initGlobalContext_renderPage() {
94
119
  debug('initGlobalContext_renderPage()');
95
- await initGlobalContext(!globalObject.isViteDev);
120
+ // globalObject.isProduction isn't set upon production server without vike-server (there isn't any signal we can use)
121
+ if (globalObject.isProduction === undefined)
122
+ setIsProduction(true);
123
+ await initGlobalContext();
96
124
  }
97
125
  async function initGlobalContext_runPrerender() {
98
126
  debug('initGlobalContext_runPrerender()');
127
+ assert(globalObject.isPrerendering === true);
128
+ assert(globalObject.isProduction === true);
99
129
  if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
100
130
  return;
101
131
  globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
@@ -105,65 +135,93 @@ async function initGlobalContext_runPrerender() {
105
135
  // We assume initGlobalContext_runPrerender() to be called before:
106
136
  // - initGlobalContext_renderPage()
107
137
  // - initGlobalContext_getGlobalContextAsync()
108
- assert(!globalObject.globalContext);
109
- await initGlobalContext(true);
138
+ assertIsNotInitilizedYet();
139
+ await initGlobalContext();
110
140
  }
111
- async function initGlobalContext_getGlobalContextAsync(isProduction) {
141
+ async function initGlobalContext_getGlobalContextAsync() {
112
142
  debug('initGlobalContext_getGlobalContextAsync()');
143
+ await initGlobalContext();
144
+ }
145
+ async function initGlobalContext_getPagesAndRoutes() {
146
+ debug('initGlobalContext_getPagesAndRoutes()');
147
+ setIsProduction(true);
148
+ await initGlobalContext();
149
+ }
150
+ async function waitForViteDevServer() {
151
+ debug('waitForViteDevServer()');
152
+ const waitFor = 20;
153
+ const timeout = setTimeout(() => {
154
+ assertWarning(false, `Vite's development server still not created after ${waitFor} seconds.`, {
155
+ onlyOnce: false,
156
+ showStackTrace: true
157
+ });
158
+ }, waitFor * 1000);
159
+ await globalObject.viteDevServerPromise;
160
+ clearTimeout(timeout);
161
+ assertGlobalContextIsDefined();
162
+ }
163
+ async function initGlobalContext() {
164
+ const { isProduction } = globalObject;
165
+ assert(typeof isProduction === 'boolean');
113
166
  if (!isProduction) {
114
- const waitFor = 20;
115
- const timeout = setTimeout(() => {
116
- assertWarning(false, `Vite's development server still not created after ${waitFor} seconds.`, {
117
- onlyOnce: false,
118
- showStackTrace: true
119
- });
120
- }, waitFor * 1000);
121
- await globalObject.viteDevServerPromise;
122
- clearTimeout(timeout);
167
+ await waitForViteDevServer();
123
168
  }
124
- await initGlobalContext(isProduction);
125
- }
126
- // TODO/now: refactor: move this to the top of the file
127
- async function initGlobalContext(isProduction) {
128
- if (globalObject.globalContext) {
129
- assert(globalObject.globalContext.isProduction === isProduction);
130
- // We assume setGlobalContext_isPrerendering() is called before initGlobalContext()
131
- assert(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
132
- return;
169
+ else {
170
+ await loadBuildEntry(globalObject.outDirRoot);
133
171
  }
134
- const { viteDevServer, viteConfig, vikeConfig, isPrerendering } = globalObject;
172
+ assertGlobalContextIsDefined();
173
+ globalObject.isInitialized = true;
174
+ }
175
+ function setIsProduction(isProduction) {
176
+ debug('setIsProduction', isProduction);
177
+ assert(typeof isProduction === 'boolean');
178
+ if (globalObject.isProduction !== undefined)
179
+ assert(globalObject.isProduction === isProduction);
180
+ globalObject.isProduction = isProduction;
181
+ }
182
+ function defineGlobalContext() {
183
+ const globalContext = assembleGlobalContext();
184
+ assertIsDefined(globalContext);
185
+ const globalContext_public = makePublic(globalContext);
186
+ objectAssign(globalContext, { globalContext_public });
187
+ globalObject.globalContext = globalContext;
188
+ globalObject.globalContext_public = globalContext_public;
189
+ assertGlobalContextIsDefined();
135
190
  onSetupRuntime();
191
+ }
192
+ function assembleGlobalContext() {
193
+ const { viteDevServer, viteConfig, isPrerendering, isProduction, userFiles } = globalObject;
194
+ assert(typeof isProduction === 'boolean');
195
+ let globalContext;
136
196
  if (!isProduction) {
197
+ // Requires globalObject.viteDevServer
198
+ if (!viteDevServer)
199
+ return null;
200
+ assert(userFiles); // main common requiement
137
201
  assert(viteConfig);
138
- assert(vikeConfig);
139
- assert(viteDevServer);
140
202
  assert(!isPrerendering);
141
- const { globalConfig, userFiles } = await getPageRuntimeInfo(isProduction);
142
203
  const viteConfigRuntime = getViteConfigRuntime(viteConfig);
143
- globalObject.globalContext = {
204
+ globalContext = {
144
205
  isProduction: false,
145
206
  isPrerendering: false,
146
207
  assetsManifest: null,
147
208
  viteDevServer,
148
209
  viteConfig,
149
- vikeConfig: {
150
- global: globalConfig
151
- },
152
210
  ...userFiles,
153
211
  viteConfigRuntime
154
212
  };
155
213
  }
156
214
  else {
157
- const buildEntry = await getBuildEntry(globalObject.outDirRoot, isPrerendering);
158
- const { assetsManifest, buildInfo } = buildEntry;
159
- setPageFiles(buildEntry.pageFiles);
160
- const { globalConfig, userFiles } = await getPageRuntimeInfo(isProduction);
161
- const globalContext = {
215
+ // Requires globalObject.buildEntry
216
+ if (!globalObject.buildEntry)
217
+ return null;
218
+ assert(userFiles); // main common requiement
219
+ const { buildInfo, assetsManifest } = globalObject;
220
+ assert(buildInfo);
221
+ assert(assetsManifest);
222
+ const globalContext_ = {
162
223
  isProduction: true,
163
224
  assetsManifest,
164
- vikeConfig: {
165
- global: globalConfig
166
- },
167
225
  ...userFiles,
168
226
  viteDevServer: null,
169
227
  viteConfigRuntime: buildInfo.viteConfigRuntime,
@@ -171,23 +229,28 @@ async function initGlobalContext(isProduction) {
171
229
  };
172
230
  if (isPrerendering) {
173
231
  assert(viteConfig);
174
- objectAssign(globalContext, {
232
+ objectAssign(globalContext_, {
175
233
  isPrerendering: true,
176
234
  viteConfig
177
235
  });
178
- globalObject.globalContext = globalContext;
236
+ globalContext = globalContext_;
179
237
  }
180
238
  else {
181
- objectAssign(globalContext, {
239
+ objectAssign(globalContext_, {
182
240
  isPrerendering: false,
183
241
  viteConfig: null
184
242
  });
185
- globalObject.globalContext = globalContext;
243
+ globalContext = globalContext_;
186
244
  }
187
245
  }
246
+ return globalContext;
188
247
  }
189
- async function getPageRuntimeInfo(isProduction) {
190
- const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig } = await getPageFilesAll(false, isProduction);
248
+ async function getUserFiles() {
249
+ // Help TypeScript resolve what TypeScript (wrongfully) believes to be cyclic dependency
250
+ const globalObject_ = globalObject;
251
+ const { pageConfigsRuntime } = globalObject_;
252
+ assert(pageConfigsRuntime);
253
+ const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig } = pageConfigsRuntime;
191
254
  const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
192
255
  const userFiles = {
193
256
  pageFilesAll,
@@ -195,12 +258,13 @@ async function getPageRuntimeInfo(isProduction) {
195
258
  pageConfigGlobal,
196
259
  allPageIds,
197
260
  pageRoutes,
198
- onBeforeRouteHook
261
+ onBeforeRouteHook,
262
+ config: globalConfig.config
199
263
  };
200
264
  assertV1Design(
201
265
  // pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
202
266
  pageConfigs.length > 0, pageFilesAll);
203
- return { userFiles, globalConfig };
267
+ return userFiles;
204
268
  }
205
269
  function assertViteManifest(manifest) {
206
270
  assert(isPlainObject(manifest));
@@ -215,45 +279,56 @@ function assertViteManifest(manifest) {
215
279
  })
216
280
  */
217
281
  }
218
- function eagerlyLoadUserFiles() {
219
- // Other than here, the getPageFilesExports() function is only called only upon calling the renderPage() function.
220
- // We call it as early as possible here for better performance.
221
- getPageFilesExports();
222
- }
223
- async function getBuildEntry(outDir, isPrerendering) {
224
- debug('getBuildEntry()');
282
+ async function loadBuildEntry(outDir) {
283
+ debug('loadBuildEntry()');
284
+ if (globalObject.userFiles) {
285
+ assert(globalObject.buildInfo);
286
+ assert(globalObject.assetsManifest);
287
+ assert(globalObject.buildEntry);
288
+ return;
289
+ }
225
290
  if (!globalObject.buildEntry) {
226
291
  debug('importServerProductionEntry()');
227
292
  // importServerProductionEntry() loads dist/server/entry.mjs which calls setGlobalContext_buildEntry()
228
- await importServerProductionEntry({ outDir, doNotLoadServer: isPrerendering });
293
+ await importServerProductionEntry({ outDir });
229
294
  if (!globalObject.buildEntry) {
230
295
  debug('globalObject.buildEntryPrevious');
231
296
  // Needed, for example, when calling the API prerender() then preview() because both trigger a importServerProductionEntry() call but only the first only is applied because of the import() cache. (A proper implementation would be to clear the import() cache, but it probably isn't possible on platforms such as Cloudflare Workers.)
232
297
  globalObject.buildEntry = globalObject.buildEntryPrevious;
233
298
  }
234
299
  assert(globalObject.buildEntry);
300
+ assertWarning(!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
301
+ // TODO/soon: show precise path
302
+ // TODO/soon: make this warning work on test/vike-node/
303
+ `Run the server production build (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of running the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
235
304
  }
236
305
  const { buildEntry } = globalObject;
237
306
  assertBuildEntry(buildEntry);
238
- return buildEntry;
307
+ globalObject.assetsManifest = buildEntry.assetsManifest;
308
+ globalObject.buildInfo = buildEntry.buildInfo;
309
+ await setUserFiles(buildEntry.virtualFileExports);
239
310
  }
240
- function setGlobalContext_buildEntry(buildEntry) {
311
+ async function setGlobalContext_buildEntry(buildEntry) {
241
312
  debug('setGlobalContext_buildEntry()');
313
+ setIsProduction(true);
242
314
  assertBuildEntry(buildEntry);
243
315
  globalObject.buildEntry = buildEntry;
244
316
  globalObject.buildEntryPrevious = buildEntry;
317
+ assert(globalObject.buildEntry); // ensure no infinite loop
318
+ await loadBuildEntry();
319
+ assertGlobalContextIsDefined();
245
320
  }
246
321
  function assertBuildEntry(buildEntry) {
247
322
  assert(isObject(buildEntry));
248
- assert(hasProp(buildEntry, 'pageFiles', 'object'));
249
- const { pageFiles } = buildEntry;
323
+ assert(hasProp(buildEntry, 'virtualFileExports', 'object'));
324
+ const { virtualFileExports } = buildEntry;
250
325
  assert(hasProp(buildEntry, 'assetsManifest', 'object'));
251
326
  const { assetsManifest } = buildEntry;
252
327
  assertViteManifest(assetsManifest);
253
328
  assert(hasProp(buildEntry, 'buildInfo', 'object'));
254
329
  const { buildInfo } = buildEntry;
255
330
  assertBuildInfo(buildInfo);
256
- checkType({ pageFiles, assetsManifest, buildInfo });
331
+ checkType({ virtualFileExports, assetsManifest, buildInfo });
257
332
  }
258
333
  function assertBuildInfo(buildInfo) {
259
334
  assert(isObject(buildInfo));
@@ -261,6 +336,7 @@ function assertBuildInfo(buildInfo) {
261
336
  assertVersionAtBuildTime(buildInfo.versionAtBuildTime);
262
337
  assert(hasProp(buildInfo, 'viteConfigRuntime', 'object'));
263
338
  assert(hasProp(buildInfo.viteConfigRuntime, '_baseViteOriginal', 'string'));
339
+ assert(hasProp(buildInfo.viteConfigRuntime, 'vitePluginServerEntry', 'object'));
264
340
  assert(hasProp(buildInfo, 'usesClientRouter', 'boolean'));
265
341
  checkType({ ...buildInfo, viteConfigRuntime: buildInfo.viteConfigRuntime });
266
342
  }
@@ -272,28 +348,38 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
272
348
  function getViteConfigRuntime(viteConfig) {
273
349
  assert(hasProp(viteConfig, '_baseViteOriginal', 'string'));
274
350
  const viteConfigRuntime = {
275
- _baseViteOriginal: viteConfig._baseViteOriginal
351
+ _baseViteOriginal: viteConfig._baseViteOriginal,
352
+ vitePluginServerEntry: {
353
+ inject: viteConfig.vitePluginServerEntry?.inject
354
+ }
276
355
  };
277
356
  return viteConfigRuntime;
278
357
  }
279
- function initDevEntry() {
280
- setPageFilesAsync(getPageFilesExports);
281
- }
282
- async function getPageFilesExports() {
358
+ async function updateUserFiles() {
359
+ const { promise, resolve } = genPromise();
360
+ assert(!globalObject.isProduction);
361
+ globalObject.waitForUserFilesUpdate = promise;
283
362
  const viteDevServer = getViteDevServer();
284
363
  assert(viteDevServer);
285
- let moduleExports;
364
+ let virtualFileExports;
286
365
  try {
287
- moduleExports = await viteDevServer.ssrLoadModule(virtualFileIdImportUserCodeServer);
366
+ virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileIdImportUserCodeServer);
288
367
  }
289
368
  catch (err) {
290
369
  debugGlob(`Glob error: ${virtualFileIdImportUserCodeServer} transpile error: `, err);
291
370
  throw err;
292
371
  }
293
- moduleExports = moduleExports.default || moduleExports;
294
- debugGlob('Glob result: ', moduleExports);
295
- assert(isObject(moduleExports));
296
- return moduleExports;
372
+ virtualFileExports = virtualFileExports.default || virtualFileExports;
373
+ debugGlob('Glob result: ', virtualFileExports);
374
+ await setUserFiles(virtualFileExports);
375
+ resolve();
376
+ }
377
+ async function setUserFiles(virtualFileExports) {
378
+ globalObject.pageConfigsRuntime = getPageConfigsRuntime(virtualFileExports);
379
+ const userFiles = await getUserFiles();
380
+ globalObject.userFiles = userFiles;
381
+ defineGlobalContext();
382
+ assertGlobalContextIsDefined();
297
383
  }
298
384
  function clearGlobalContext() {
299
385
  debug('clearGlobalContext()');
@@ -29,4 +29,4 @@ type HtmlTag = {
29
29
  };
30
30
  declare function getHtmlTags(pageContext: {
31
31
  _isStream: boolean;
32
- } & PageContextInjectAssets, streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage, injectFilter: PreloadFilter, pageAssets: PageAsset[], viteDevScript: string, isStream: boolean): HtmlTag[];
32
+ } & PageContextInjectAssets, streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage, injectFilter: PreloadFilter, pageAssets: PageAsset[], viteDevScript: string, isStream: boolean): Promise<HtmlTag[]>;
@@ -7,14 +7,13 @@ import { inferAssetTag, inferPreloadTag } from './inferHtmlTags.js';
7
7
  import { mergeScriptTags } from './mergeScriptTags.js';
8
8
  import { getPageConfig } from '../../../../shared/page-configs/helpers.js';
9
9
  import { getConfigValueRuntime } from '../../../../shared/page-configs/getConfigValueRuntime.js';
10
- import { getGlobalContext } from '../../globalContext.js';
11
10
  import pc from '@brillout/picocolors';
12
11
  import { getConfigDefinedAt } from '../../../../shared/page-configs/getConfigDefinedAt.js';
13
12
  const stamp = '__injectFilterEntry';
14
- function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
13
+ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
15
14
  assert([true, false].includes(pageContext._isHtmlOnly));
16
15
  const isHtmlOnly = pageContext._isHtmlOnly;
17
- const { isProduction } = getGlobalContext();
16
+ const { isProduction } = pageContext._globalContext;
18
17
  const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
19
18
  const injectFilterEntries = [];
20
19
  pageAssets
@@ -1,2 +1,5 @@
1
1
  export { getViteDevScript };
2
- declare function getViteDevScript(): Promise<string>;
2
+ import type { GlobalContext } from '../../globalContext.js';
3
+ declare function getViteDevScript(pageContext: {
4
+ _globalContext: GlobalContext;
5
+ }): Promise<string>;
@@ -1,9 +1,8 @@
1
1
  export { getViteDevScript };
2
- import { getGlobalContext } from '../../globalContext.js';
3
2
  import { assert, assertUsage, assertWarning } from '../../utils.js';
4
3
  import pc from '@brillout/picocolors';
5
- async function getViteDevScript() {
6
- const globalContext = getGlobalContext();
4
+ async function getViteDevScript(pageContext) {
5
+ const globalContext = pageContext._globalContext;
7
6
  if (globalContext.isProduction) {
8
7
  return '';
9
8
  }
@@ -8,6 +8,7 @@ import { type PreloadFilter } from './injectAssets/getHtmlTags.js';
8
8
  import type { StreamFromReactStreamingPackage } from './stream/react-streaming.js';
9
9
  import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
10
10
  import type { PageContextSerialization } from './serializePageContextClientSide.js';
11
+ import type { GlobalContext } from '../globalContext.js';
11
12
  type PageContextInjectAssets = {
12
13
  urlPathname: string;
13
14
  __getPageAssets: () => Promise<PageAsset[]>;
@@ -21,6 +22,7 @@ type PageContextInjectAssets = {
21
22
  _baseServer: string;
22
23
  _pageConfigs: PageConfigRuntime[];
23
24
  is404: null | boolean;
25
+ _globalContext: GlobalContext;
24
26
  } & PageContextSerialization;
25
27
  declare function injectHtmlTagsToString(htmlParts: HtmlPart[], pageContext: PageContextInjectAssets & {
26
28
  _isStream: false;
@@ -7,8 +7,8 @@ import { getHtmlTags } from './injectAssets/getHtmlTags.js';
7
7
  import { getViteDevScript } from './injectAssets/getViteDevScript.js';
8
8
  async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
9
9
  const pageAssets = await pageContext.__getPageAssets();
10
- const viteDevScript = await getViteDevScript();
11
- const htmlTags = getHtmlTags(pageContext, null, injectFilter, pageAssets, viteDevScript, false);
10
+ const viteDevScript = await getViteDevScript(pageContext);
11
+ const htmlTags = await getHtmlTags(pageContext, null, injectFilter, pageAssets, viteDevScript, false);
12
12
  let htmlString = htmlPartsToString(htmlParts, pageAssets);
13
13
  htmlString = injectToHtmlBegin(htmlString, htmlTags);
14
14
  htmlString = injectToHtmlEnd(htmlString, htmlTags);
@@ -24,8 +24,8 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
24
24
  };
25
25
  async function injectAtStreamBegin(htmlPartsBegin) {
26
26
  const pageAssets = await pageContext.__getPageAssets();
27
- const viteDevScript = await getViteDevScript();
28
- htmlTags = getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, true);
27
+ const viteDevScript = await getViteDevScript(pageContext);
28
+ htmlTags = await getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, true);
29
29
  let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
30
30
  htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
31
31
  if (streamFromReactStreamingPackage) {
@@ -7,7 +7,6 @@ import { assert, assertUsage, assertWarning, checkType, escapeHtml, hasProp, isH
7
7
  import { injectHtmlTagsToString, injectHtmlTagsToStream } from './injectAssets.js';
8
8
  import { processStream, isStream, streamToString } from './stream.js';
9
9
  import { isStreamFromReactStreamingPackage } from './stream/react-streaming.js';
10
- import { getGlobalContext } from '../globalContext.js';
11
10
  import pc from '@brillout/picocolors';
12
11
  function isDocumentHtml(something) {
13
12
  if (isTemplateWrapped(something) || isEscapedString(something) || isStream(something)) {
@@ -31,7 +30,7 @@ async function renderDocumentHtml(documentHtml, pageContext, onErrorWhileStreami
31
30
  }
32
31
  if (isTemplateWrapped(documentHtml)) {
33
32
  const templateContent = documentHtml._template;
34
- const render = await renderTemplate(templateContent, pageContext);
33
+ const render = renderTemplate(templateContent, pageContext);
35
34
  if (!('htmlStream' in render)) {
36
35
  objectAssign(pageContext, { _isStream: false });
37
36
  const { htmlPartsAll } = render;
@@ -120,7 +119,7 @@ function _dangerouslySkipEscape(arg) {
120
119
  });
121
120
  return { _escaped: String(arg) };
122
121
  }
123
- async function renderTemplate(templateContent, pageContext) {
122
+ function renderTemplate(templateContent, pageContext) {
124
123
  const htmlPartsBegin = [];
125
124
  const htmlPartsEnd = [];
126
125
  let htmlStream = null;
@@ -151,7 +150,7 @@ async function renderTemplate(templateContent, pageContext) {
151
150
  // Process `escapeInject` fragments
152
151
  if (isTemplateWrapped(templateVar)) {
153
152
  const templateContentInner = templateVar._template;
154
- const result = await renderTemplate(templateContentInner, pageContext);
153
+ const result = renderTemplate(templateContentInner, pageContext);
155
154
  if (!('htmlStream' in result)) {
156
155
  result.htmlPartsAll.forEach(addHtmlPart);
157
156
  }
@@ -193,7 +192,7 @@ async function renderTemplate(templateContent, pageContext) {
193
192
  }
194
193
  }
195
194
  {
196
- const { isProduction } = getGlobalContext();
195
+ const { isProduction } = pageContext._globalContext;
197
196
  if (isHtml(templateVar) &&
198
197
  // We don't show this warning in production because it's expected that some users may (un)willingly do some XSS injection: we avoid flooding the production logs.
199
198
  !isProduction) {
@@ -2,4 +2,5 @@ export { analyzePage };
2
2
  import type { PageFile } from '../../../shared/getPageFiles/getPageFileObject.js';
3
3
  import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
4
4
  import { type AnalysisResult } from '../../../shared/getPageFiles/analyzePageClientSide.js';
5
- declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string): AnalysisResult;
5
+ import type { GlobalContext } from '../globalContext.js';
6
+ declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string, globalContext: GlobalContext): Promise<AnalysisResult>;
@@ -3,9 +3,8 @@ import { getVikeClientEntry } from '../../../shared/getPageFiles/analyzePageClie
3
3
  import { analyzePageClientSide } from '../../../shared/getPageFiles/analyzePageClientSide.js';
4
4
  import { getVirtualFileIdPageConfigValuesAll } from '../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
5
5
  import { analyzeClientSide } from '../../../shared/getPageFiles/analyzeClientSide.js';
6
- import { getGlobalContext } from '../globalContext.js';
7
6
  import { getConfigValueRuntime } from '../../../shared/page-configs/getConfigValueRuntime.js';
8
- function analyzePage(pageFilesAll, pageConfig, pageId) {
7
+ async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) {
9
8
  if (pageConfig) {
10
9
  const { isClientRuntimeLoaded, isClientRouting } = analyzeClientSide(pageConfig, pageFilesAll, pageId);
11
10
  const clientEntries = [];
@@ -21,7 +20,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
21
20
  eagerlyImported: false
22
21
  });
23
22
  // In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
24
- if (!getGlobalContext().isProduction) {
23
+ if (!globalContext.isProduction) {
25
24
  clientDependencies.push({
26
25
  id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, false),
27
26
  onlyAssets: true,
@@ -1,3 +1,3 @@
1
1
  export { sortPageAssetsForEarlyHintsHeader };
2
2
  import type { PageAsset } from '../getPageAssets.js';
3
- declare function sortPageAssetsForEarlyHintsHeader(pageAssets: PageAsset[]): void;
3
+ declare function sortPageAssetsForEarlyHintsHeader(pageAssets: PageAsset[], isProduction: boolean): Promise<void>;
@@ -1,11 +1,9 @@
1
1
  export { sortPageAssetsForEarlyHintsHeader };
2
- import { getGlobalContext } from '../../globalContext.js';
3
2
  import { higherFirst } from '../../utils.js';
4
- function sortPageAssetsForEarlyHintsHeader(pageAssets) {
5
- const globalContext = getGlobalContext();
3
+ async function sortPageAssetsForEarlyHintsHeader(pageAssets, isProduction) {
6
4
  pageAssets.sort(higherFirst(({ assetType }) => {
7
5
  // In dev, we load scripts first in order to parallelize I/O and CPU
8
- if (!globalContext.isProduction && assetType === 'script') {
6
+ if (!isProduction && assetType === 'script') {
9
7
  return 1;
10
8
  }
11
9
  let priority = 0;