vike 0.4.142 → 0.4.143-commit-dc6fea0

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 (170) hide show
  1. package/dist/cjs/node/plugin/index.js +2 -2
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
  3. package/dist/cjs/node/plugin/plugins/commonConfig.js +2 -7
  4. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
  5. package/dist/cjs/node/plugin/plugins/envVars.js +3 -5
  6. package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
  7. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
  8. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +122 -124
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +37 -27
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +50 -80
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -3
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
  16. package/dist/cjs/node/plugin/plugins/suppressRollupWarning.js +16 -3
  17. package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
  18. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
  19. package/dist/cjs/node/plugin/shared/loggerNotProd.js +3 -3
  20. package/dist/cjs/node/plugin/utils.js +1 -2
  21. package/dist/cjs/node/prerender/runPrerender.js +13 -16
  22. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  23. package/dist/cjs/node/runtime/html/stream.js +4 -1
  24. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
  25. package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
  26. package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
  27. package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
  28. package/dist/cjs/shared/error-page.js +1 -1
  29. package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +13 -13
  30. package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
  31. package/dist/cjs/shared/getPageFiles/parseGlobResults.js +9 -43
  32. package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +62 -0
  33. package/dist/cjs/shared/page-configs/assertExports.js +60 -0
  34. package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
  35. package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +50 -0
  36. package/dist/cjs/shared/page-configs/utils.js +1 -1
  37. package/dist/cjs/shared/route/loadPageRoutes.js +11 -13
  38. package/dist/cjs/shared/route/resolvePrecedence.js +32 -11
  39. package/dist/cjs/shared/route/resolveRedirects.js +1 -1
  40. package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
  41. package/dist/cjs/shared/route/resolveRouteString.js +99 -43
  42. package/dist/cjs/shared/utils.js +1 -1
  43. package/dist/cjs/types/defineConfig.js +7 -0
  44. package/dist/cjs/types/index.js +3 -0
  45. package/dist/cjs/utils/getFilePathAbsolute.js +16 -12
  46. package/dist/cjs/utils/objectAssign.js +3 -1
  47. package/dist/cjs/utils/parseUrl.js +6 -1
  48. package/dist/cjs/utils/projectInfo.js +1 -1
  49. package/dist/cjs/utils/requireResolve.js +60 -0
  50. package/dist/esm/__internal/index.d.ts +3 -3
  51. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
  52. package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
  53. package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
  54. package/dist/esm/client/client-routing-runtime/prefetch.js +3 -1
  55. package/dist/esm/client/client-routing-runtime/useClientRouter.js +2 -2
  56. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
  57. package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
  58. package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
  59. package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
  60. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  61. package/dist/esm/node/plugin/index.js +3 -2
  62. package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
  63. package/dist/esm/node/plugin/plugins/commonConfig.js +2 -7
  64. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
  65. package/dist/esm/node/plugin/plugins/envVars.js +4 -6
  66. package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
  67. package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
  68. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
  69. package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +19 -2
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -2
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +123 -125
  75. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +5 -0
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +35 -25
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -0
  78. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +49 -79
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +10 -1
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  83. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
  84. package/dist/esm/node/plugin/plugins/suppressRollupWarning.js +16 -3
  85. package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
  86. package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
  87. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
  88. package/dist/esm/node/plugin/shared/loggerNotProd.js +4 -4
  89. package/dist/esm/node/plugin/utils.d.ts +1 -2
  90. package/dist/esm/node/plugin/utils.js +1 -2
  91. package/dist/esm/node/prerender/runPrerender.js +13 -16
  92. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  93. package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
  94. package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
  95. package/dist/esm/node/runtime/html/stream.js +4 -1
  96. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
  97. package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
  98. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
  99. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
  100. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
  101. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
  102. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
  103. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
  104. package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
  105. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
  106. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
  107. package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
  108. package/dist/esm/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
  109. package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
  110. package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
  111. package/dist/esm/shared/error-page.d.ts +3 -3
  112. package/dist/esm/shared/error-page.js +1 -1
  113. package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
  114. package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +5 -5
  115. package/dist/esm/shared/getPageFiles/assertPageConfigs.js +12 -12
  116. package/dist/esm/shared/getPageFiles/getExports.d.ts +2 -2
  117. package/dist/esm/shared/getPageFiles/getExports.js +1 -1
  118. package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
  119. package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
  120. package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.d.ts +6 -0
  121. package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +59 -0
  122. package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
  123. package/dist/esm/shared/page-configs/Config.d.ts +201 -14
  124. package/dist/esm/shared/page-configs/PageConfig.d.ts +60 -39
  125. package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
  126. package/dist/esm/shared/page-configs/assertExports.js +54 -0
  127. package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
  128. package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
  129. package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
  130. package/dist/esm/shared/page-configs/parseConfigValuesImported.d.ts +3 -0
  131. package/dist/esm/shared/page-configs/parseConfigValuesImported.js +44 -0
  132. package/dist/esm/shared/page-configs/utils.d.ts +3 -2
  133. package/dist/esm/shared/page-configs/utils.js +1 -1
  134. package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
  135. package/dist/esm/shared/route/index.d.ts +3 -3
  136. package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
  137. package/dist/esm/shared/route/loadPageRoutes.js +11 -13
  138. package/dist/esm/shared/route/resolvePrecedence.js +33 -12
  139. package/dist/esm/shared/route/resolveRedirects.js +1 -1
  140. package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
  141. package/dist/esm/shared/route/resolveRouteString.d.ts +21 -4
  142. package/dist/esm/shared/route/resolveRouteString.js +98 -42
  143. package/dist/esm/shared/types.d.ts +8 -6
  144. package/dist/esm/shared/utils.d.ts +1 -1
  145. package/dist/esm/shared/utils.js +1 -1
  146. package/dist/esm/types/defineConfig.d.ts +3 -0
  147. package/dist/esm/types/defineConfig.js +4 -0
  148. package/dist/esm/types/index.d.ts +3 -1
  149. package/dist/esm/types/index.js +1 -1
  150. package/dist/esm/utils/getFilePathAbsolute.d.ts +2 -2
  151. package/dist/esm/utils/getFilePathAbsolute.js +15 -11
  152. package/dist/esm/utils/objectAssign.js +3 -1
  153. package/dist/esm/utils/parseUrl.js +6 -1
  154. package/dist/esm/utils/projectInfo.d.ts +1 -1
  155. package/dist/esm/utils/projectInfo.js +1 -1
  156. package/dist/esm/utils/requireResolve.d.ts +2 -0
  157. package/dist/esm/utils/requireResolve.js +57 -0
  158. package/package.json +3 -3
  159. package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
  160. package/dist/cjs/utils/addFileExtensionsToRequireResolve.js +0 -23
  161. package/dist/cjs/utils/assertDefaultExport.js +0 -53
  162. package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
  163. package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
  164. package/dist/esm/utils/addFileExtensionsToRequireResolve.d.ts +0 -2
  165. package/dist/esm/utils/addFileExtensionsToRequireResolve.js +0 -20
  166. package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
  167. package/dist/esm/utils/assertDefaultExport.js +0 -47
  168. /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
  169. /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
  170. /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  export { executeGuardHook };
2
2
  import type { PageContextExports, PageFile } from '../getPageFiles.js';
3
- import type { PageConfig } from '../page-configs/PageConfig.js';
3
+ import type { PageConfigRuntime } from '../page-configs/PageConfig.js';
4
4
  declare function executeGuardHook<T extends PageContextExports & {
5
5
  _pageId: string;
6
6
  _pageFilesAll: PageFile[];
7
- _pageConfigs: PageConfig[];
7
+ _pageConfigs: PageConfigRuntime[];
8
8
  }>(pageContext: T, prepareForUserConsumption: (pageConfig: T) => T | void): Promise<void>;
@@ -4,12 +4,12 @@ import type { PageFile } from '../getPageFiles.js';
4
4
  import { PageContextUrlComputedPropsInternal, PageContextUrlSources } from '../addUrlComputedProps.js';
5
5
  import { type OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
6
6
  import type { PageRoutes, RouteType } from './loadPageRoutes.js';
7
- import type { PageConfig, PageConfigGlobal } from '../page-configs/PageConfig.js';
7
+ import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
8
8
  type PageContextForRoute = PageContextUrlComputedPropsInternal & {
9
9
  _pageFilesAll: PageFile[];
10
- _pageConfigs: PageConfig[];
10
+ _pageConfigs: PageConfigRuntime[];
11
11
  _allPageIds: string[];
12
- _pageConfigGlobal: PageConfigGlobal;
12
+ _pageConfigGlobal: PageConfigGlobalRuntime;
13
13
  _pageRoutes: PageRoutes;
14
14
  _onBeforeRouteHook: OnBeforeRouteHook | null;
15
15
  } & PageContextUrlSources;
@@ -3,7 +3,7 @@ export type { PageRoutes };
3
3
  export type { RouteType };
4
4
  import type { PageFile } from '../getPageFiles.js';
5
5
  import type { OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
6
- import type { PageConfig, PageConfigGlobal } from '../page-configs/PageConfig.js';
6
+ import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
7
7
  type PageRoute = {
8
8
  pageId: string;
9
9
  comesFromV1PageConfig: boolean;
@@ -23,7 +23,7 @@ type PageRoute = {
23
23
  });
24
24
  type PageRoutes = PageRoute[];
25
25
  type RouteType = 'STRING' | 'FUNCTION' | 'FILESYSTEM';
26
- declare function loadPageRoutes(pageFilesAll: PageFile[], pageConfigs: PageConfig[], pageConfigGlobal: PageConfigGlobal, allPageIds: string[]): Promise<{
26
+ declare function loadPageRoutes(pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[], pageConfigGlobal: PageConfigGlobalRuntime, allPageIds: string[]): Promise<{
27
27
  pageRoutes: PageRoutes;
28
28
  onBeforeRouteHook: null | OnBeforeRouteHook;
29
29
  }>;
@@ -137,19 +137,17 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
137
137
  function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
138
138
  // V1 Design
139
139
  if (pageConfigs.length > 0) {
140
- if (pageConfigGlobal.onBeforeRoute) {
141
- const hookFn = pageConfigGlobal.onBeforeRoute.value;
142
- if (hookFn) {
143
- assert(!pageConfigGlobal.onBeforeRoute.isComputed);
144
- const hookFilePath = pageConfigGlobal.onBeforeRoute.definedAtInfo.filePath;
145
- assert(hookFilePath);
146
- assertUsage(isCallable(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
147
- const onBeforeRouteHook = {
148
- hookFilePath: hookFilePath,
149
- onBeforeRoute: hookFn
150
- };
151
- return { onBeforeRouteHook, filesystemRoots: null };
152
- }
140
+ if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
141
+ const { value: hookFn, definedAtInfo } = pageConfigGlobal.configValues.onBeforeRoute;
142
+ // config.onBeforeRoute isn't a computed nor a cumulative config => definedAtInfo should always be defined
143
+ assert(definedAtInfo);
144
+ const hookFilePath = definedAtInfo.filePath;
145
+ assertUsage(isCallable(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
146
+ const onBeforeRouteHook = {
147
+ hookFilePath: hookFilePath,
148
+ onBeforeRoute: hookFn
149
+ };
150
+ return { onBeforeRouteHook, filesystemRoots: null };
153
151
  }
154
152
  return { onBeforeRouteHook: null, filesystemRoots: null };
155
153
  }
@@ -1,7 +1,7 @@
1
1
  export { resolvePrecendence };
2
2
  // export type { RouteMatch }
3
3
  import { analyzeRouteString } from './resolveRouteString.js';
4
- import { higherFirst } from './utils.js';
4
+ import { higherFirst, lowerFirst } from './utils.js';
5
5
  import { makeFirst } from './utils.js';
6
6
  import { isStaticRouteString } from './resolveRouteString.js';
7
7
  // See https://vike.dev/route-function#precedence
@@ -32,37 +32,58 @@ function sortMatches(routeMatch1, routeMatch2) {
32
32
  if (!routeMatch1.routeString) {
33
33
  return 0;
34
34
  }
35
+ /* DEBUG
36
+ console.log('routeMatch1.routeString', routeMatch1.routeString)
37
+ console.log('routeMatch2.routeString', routeMatch2.routeString)
38
+ console.log('parseRouteString(routeMatch1.routeString)', parseRouteString(routeMatch1.routeString))
39
+ console.log('parseRouteString(routeMatch2.routeString)', parseRouteString(routeMatch2.routeString))
40
+ //*/
35
41
  // Return route with highest number of static path segments at beginning first
36
42
  {
37
- const getValue = (routeString) => analyzeRouteString(routeString).numberOfStaticSegmentsBeginning;
43
+ const getValue = (routeString) => analyzeRouteString(routeString).numberOfStaticPartsBeginning;
38
44
  const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
39
45
  if (result !== 0) {
46
+ /* DEBUG
47
+ console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticPartsBeginning', getValue(routeMatch1.routeString))
48
+ console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticPartsBeginning', getValue(routeMatch2.routeString))
49
+ //*/
40
50
  return result;
41
51
  }
42
52
  }
43
53
  // Return route with highest number of static path segments in total first
44
54
  {
45
- const getValue = (routeString) => analyzeRouteString(routeString).numberOfStaticSegements;
55
+ const getValue = (routeString) => analyzeRouteString(routeString).numberOfStaticParts;
46
56
  const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
47
57
  if (result !== 0) {
58
+ /* DEBUG
59
+ console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticParts', getValue(routeMatch1.routeString))
60
+ console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticParts', getValue(routeMatch2.routeString))
61
+ //*/
48
62
  return result;
49
63
  }
50
64
  }
51
- // Return route with most parameter segements first
65
+ // Return route with least amount of globs first
52
66
  {
53
- const getValue = (routeString) => analyzeRouteString(routeString).numberOfParameterSegments;
54
- const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
67
+ const getValue = (routeString) => analyzeRouteString(routeString).numberOfGlobs;
68
+ const result = lowerFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
55
69
  if (result !== 0) {
70
+ /* DEBUG
71
+ console.log('analyzeRouteString(routeMatch1.routeString).numberOfGlobs', getValue(routeMatch1.routeString))
72
+ console.log('analyzeRouteString(routeMatch2.routeString).numberOfGlobs', getValue(routeMatch2.routeString))
73
+ //*/
56
74
  return result;
57
75
  }
58
76
  }
59
- // Return catch-all routes last
77
+ // Return route with highest number of parameters first
60
78
  {
61
- if (analyzeRouteString(routeMatch2.routeString).isCatchAll) {
62
- return -1;
63
- }
64
- if (analyzeRouteString(routeMatch1.routeString).isCatchAll) {
65
- return 1;
79
+ const getValue = (routeString) => analyzeRouteString(routeString).numberOfParams;
80
+ const result = higherFirst(getValue)(routeMatch1.routeString, routeMatch2.routeString);
81
+ if (result !== 0) {
82
+ /* DEBUG
83
+ console.log('analyzeRouteString(routeMatch1.routeString).numberOfParams', getValue(routeMatch1.routeString))
84
+ console.log('analyzeRouteString(routeMatch2.routeString).numberOfParams', getValue(routeMatch2.routeString))
85
+ //*/
86
+ return result;
66
87
  }
67
88
  }
68
89
  return 0;
@@ -7,7 +7,7 @@ import { assertRouteString, resolveRouteString } from './resolveRouteString.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  assertIsNotBrowser(); // Don't bloat the client
9
9
  // TODO/v1-release: update
10
- const configSrc = '[vite.config.js > ssr({ redirects })]';
10
+ const configSrc = '[vite.config.js > vike({ redirects })]';
11
11
  function resolveRedirects(redirects, urlPathname) {
12
12
  for (const [urlSource, urlTarget] of Object.entries(redirects)) {
13
13
  const urlResolved = resolveRouteStringRedirect(urlSource, urlTarget, urlPathname);
@@ -20,6 +20,7 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAt)
20
20
  result = {};
21
21
  }
22
22
  assertUsage(isPlainObject(result), `The Route Function ${routeDefinedAt} should return a boolean or a plain JavaScript object (but it's ${pc.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
23
+ // AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
23
24
  if ('match' in result) {
24
25
  const { match } = result;
25
26
  assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${routeDefinedAt} should be a boolean.`);
@@ -3,15 +3,32 @@ export { getUrlFromRouteString };
3
3
  export { isStaticRouteString };
4
4
  export { analyzeRouteString };
5
5
  export { assertRouteString };
6
+ export { parseRouteString };
6
7
  declare function assertRouteString(routeString: string, errPrefix?: `${string}Invalid` | `${string}invalid`): void;
7
8
  declare function resolveRouteString(routeString: string, urlPathname: string): null | {
8
9
  routeParams: Record<string, string>;
9
10
  };
11
+ type Segment = {
12
+ glob: true;
13
+ /** Make route /a/* match URL /a */
14
+ isLastDir?: true;
15
+ static?: undefined;
16
+ param?: undefined;
17
+ } | {
18
+ glob?: undefined;
19
+ static: string;
20
+ param?: undefined;
21
+ } | {
22
+ glob?: undefined;
23
+ static?: undefined;
24
+ param: string;
25
+ };
26
+ declare function parseRouteString(routeString: string): Segment[];
10
27
  declare function getUrlFromRouteString(routeString: string): null | string;
11
28
  declare function analyzeRouteString(routeString: string): {
12
- numberOfParameterSegments: number;
13
- numberOfStaticSegmentsBeginning: number;
14
- numberOfStaticSegements: number;
15
- isCatchAll: boolean;
29
+ numberOfStaticPartsBeginning: number;
30
+ numberOfStaticParts: number;
31
+ numberOfParams: number;
32
+ numberOfGlobs: number;
16
33
  };
17
34
  declare function isStaticRouteString(routeString: string): boolean;
@@ -3,48 +3,109 @@ export { getUrlFromRouteString };
3
3
  export { isStaticRouteString };
4
4
  export { analyzeRouteString };
5
5
  export { assertRouteString };
6
- import { assertWarning, isBrowser } from '../utils.js';
6
+ export { parseRouteString };
7
+ import { assertWarning, isBrowser, escapeRegex } from '../utils.js';
7
8
  import { assert, assertUsage } from './utils.js';
8
9
  import pc from '@brillout/picocolors';
9
10
  const PARAM_TOKEN_NEW = '@';
10
11
  // TODO/v1-release: remove
11
12
  const PARAM_TOKEN_OLD = ':';
12
13
  function assertRouteString(routeString, errPrefix = 'Invalid') {
13
- assert(errPrefix.endsWith('Invalid') || errPrefix.endsWith('invalid'));
14
- assertUsage(routeString !== '', `${errPrefix} Route String ${highlight(routeString)} (empty string): set it to ${highlight('/')} instead`);
15
- assertUsage(routeString.startsWith('/') || routeString === '*', `${errPrefix} Route String ${highlight(routeString)}: Route Strings should start with a leading slash ${highlight('/')} (or be ${highlight('*')})`);
14
+ let errPrefix2 = `${errPrefix} Route String ${highlight(routeString)}`;
15
+ assertUsage(routeString !== '', `${errPrefix2} (empty string): set it to ${highlight('/')} instead`);
16
+ assertUsage(['/', '*'].includes(routeString[0]), `${errPrefix2}: it should start with ${highlight('/')} or ${highlight('*')}`);
17
+ assertUsage(!routeString.includes('**'), `${errPrefix2}: set it to ${highlight(routeString.split('**').join('*'))} instead`);
16
18
  }
17
19
  function resolveRouteString(routeString, urlPathname) {
18
20
  assertRouteString(routeString);
19
- assert(urlPathname.startsWith('/'));
20
- const routeSegments = routeString.split('/');
21
- const urlSegments = urlPathname.split('/');
22
- const routeParams = {};
23
- assertGlob(routeString);
24
- if (routeString === '*') {
25
- routeString = '/*';
26
- }
27
- for (let i = 0; i < Math.max(routeSegments.length, urlSegments.length); i++) {
28
- const routeSegment = routeSegments[i];
29
- const urlSegment = urlSegments[i];
30
- if (routeSegment === '*') {
31
- routeParams['*'] = urlSegments.slice(Math.max(1, i)).join('/');
32
- return { routeParams };
21
+ const segments = parseRouteString(routeString);
22
+ const routeRegexStrInner = segments
23
+ .map((segment) => {
24
+ if (segment.param) {
25
+ return '[^/]+';
33
26
  }
34
- else if (routeSegment && isParam(routeSegment)) {
35
- assertWarning(!routeSegment.startsWith(PARAM_TOKEN_OLD), `Outdated Route String ${pc.cyan(routeString)}, use ${pc.cyan(routeString.split(PARAM_TOKEN_OLD).join(PARAM_TOKEN_NEW))} instead.`, { onlyOnce: true });
36
- if (!urlSegment) {
37
- return null;
27
+ if (segment.glob) {
28
+ if (segment.isLastDir) {
29
+ return '|/.*';
30
+ }
31
+ else {
32
+ return '.*';
38
33
  }
39
- routeParams[routeSegment.slice(1)] = urlSegment;
34
+ }
35
+ // segment.static
36
+ return escapeRegex(segment.static);
37
+ })
38
+ .map((s) => `(${s})`)
39
+ .join('');
40
+ const routeRegex = new RegExp(`^${routeRegexStrInner}/?$`);
41
+ const routeRegexMatch = urlPathname.match(routeRegex);
42
+ /* DEBUG
43
+ console.log()
44
+ console.log('routeString', routeString)
45
+ console.log('urlPathname', urlPathname)
46
+ console.log('routeSegments', segments)
47
+ console.log('routeRegex', routeRegex)
48
+ console.log('routeRegexMatch', routeRegexMatch)
49
+ //*/
50
+ if (!routeRegexMatch)
51
+ return null;
52
+ const routeParams = {};
53
+ const [_, ...segmentsValue] = routeRegexMatch;
54
+ let globIdx = 0;
55
+ const hasMultipleGlobs = segments.filter((segment) => segment.glob).length > 1;
56
+ segments.forEach((segment, i) => {
57
+ let val = segmentsValue[i];
58
+ if (segment.param) {
59
+ routeParams[segment.param] = val;
60
+ }
61
+ if (segment.glob) {
62
+ const param = `*${hasMultipleGlobs ? ++globIdx : ''}`;
63
+ if (segment.isLastDir)
64
+ val = val.slice(1);
65
+ routeParams[param] = val;
66
+ }
67
+ });
68
+ return { routeParams };
69
+ }
70
+ function parseRouteString(routeString) {
71
+ const segments = [];
72
+ const pushStatic = (s) => {
73
+ const segmentLast = segments[segments.length - 1];
74
+ if (segmentLast?.static) {
75
+ segmentLast.static += s;
40
76
  }
41
77
  else {
42
- if ((routeSegment || '') !== (urlSegment || '')) {
43
- return null;
78
+ segments.push({ static: s });
79
+ }
80
+ };
81
+ const parts = routeString.split('/');
82
+ parts.forEach((s, i) => {
83
+ const isFirst = i === 0;
84
+ const isLast = i === parts.length - 1;
85
+ if (isParam(s)) {
86
+ assertWarning(!s.startsWith(PARAM_TOKEN_OLD), `Outdated Route String ${highlight(routeString)}, use ${highlight(routeString.split(PARAM_TOKEN_OLD).join(PARAM_TOKEN_NEW))} instead`, { onlyOnce: true });
87
+ if (!isFirst)
88
+ pushStatic('/');
89
+ segments.push({ param: s.slice(1) });
90
+ }
91
+ else {
92
+ if (s === '*' && isLast && routeString !== '*' && routeString !== '/*') {
93
+ segments.push({ glob: true, isLastDir: true });
94
+ }
95
+ else {
96
+ if (!isFirst)
97
+ pushStatic('/');
98
+ s.split('*').forEach((s, i) => {
99
+ if (i !== 0)
100
+ segments.push({ glob: true });
101
+ if (s !== '') {
102
+ pushStatic(s);
103
+ }
104
+ });
44
105
  }
45
106
  }
46
- }
47
- return { routeParams };
107
+ });
108
+ return segments;
48
109
  }
49
110
  function getUrlFromRouteString(routeString) {
50
111
  assert(routeString.startsWith('/'));
@@ -54,24 +115,19 @@ function getUrlFromRouteString(routeString) {
54
115
  }
55
116
  return null;
56
117
  }
57
- function assertGlob(routeString) {
58
- const numberOfGlobChars = routeString.split('*').length - 1;
59
- assertUsage(numberOfGlobChars <= 1, `Invalid Route String ${highlight(routeString)}: Route Strings aren't allowed to contain more than one glob ${highlight('*')} (use a Route Function instead)`);
60
- assertUsage(numberOfGlobChars === 0 || (numberOfGlobChars === 1 && routeString.endsWith('*')), `Invalid Route String ${highlight(routeString)}: make sure it ends with ${highlight('*')} or use a Route Function`);
61
- }
62
118
  function analyzeRouteString(routeString) {
63
- const routeSegments = routeString.split('/').filter((routeSegment) => routeSegment !== '' && routeSegment !== '*');
64
- let numberOfStaticSegmentsBeginning = 0;
65
- for (const routeSegment of routeSegments) {
66
- if (isParam(routeSegment)) {
119
+ const segments = parseRouteString(routeString);
120
+ const countStaticParts = (s) => s?.split('/').filter(Boolean).length || 0;
121
+ let numberOfStaticPartsBeginning = 0;
122
+ for (const segment of segments) {
123
+ if (!segment.static)
67
124
  break;
68
- }
69
- numberOfStaticSegmentsBeginning++;
125
+ numberOfStaticPartsBeginning += countStaticParts(segment.static);
70
126
  }
71
- const numberOfStaticSegements = routeSegments.filter((s) => !isParam(s)).length;
72
- const numberOfParameterSegments = routeSegments.filter((s) => isParam(s)).length;
73
- const isCatchAll = routeString.endsWith('*');
74
- return { numberOfParameterSegments, numberOfStaticSegmentsBeginning, numberOfStaticSegements, isCatchAll };
127
+ const numberOfStaticParts = segments.map((s) => countStaticParts(s.static)).reduce((sum, a) => sum + a, 0);
128
+ const numberOfParams = segments.filter((s) => s.param).length;
129
+ const numberOfGlobs = segments.filter((s) => s.glob).length;
130
+ return { numberOfStaticPartsBeginning, numberOfStaticParts, numberOfParams, numberOfGlobs };
75
131
  }
76
132
  function isParam(routeSegment) {
77
133
  return routeSegment.startsWith(PARAM_TOKEN_NEW) || routeSegment.startsWith(PARAM_TOKEN_OLD);
@@ -12,18 +12,17 @@ import type { ConfigEntries, ExportsAll } from './getPageFiles/getExports.js';
12
12
  import type { Config } from './page-configs/Config.js';
13
13
  import type { PageContextConfig } from './page-configs/Config/PageContextConfig.js';
14
14
  import type { AbortStatusCode } from './route/abort.js';
15
- type PageContext = PageContextWithClientRouting;
16
- type PageContextClient = PageContextClientWithClientRouting;
17
- type PageContextWithClientRouting = PageContextClientWithClientRouting | PageContextServer;
18
- type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
19
15
  type PageContextServer = PageContextBuiltInServer & Vike.PageContext;
20
- type PageContextClientWithClientRouting = PageContextBuiltInClientWithClientRouting & Vike.PageContext;
16
+ type PageContext = PageContextClient | PageContextServer;
17
+ type PageContextClient = PageContextBuiltInClientWithClientRouting & Vike.PageContext;
18
+ type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
21
19
  type PageContextClientWithServerRouting = PageContextBuiltInClientWithServerRouting & Vike.PageContext;
22
20
  /** Built-in `pageContext` properties set by vike.
23
21
  *
24
22
  * https://vike.dev/pageContext
25
23
  */
26
24
  type PageContextBuiltInServer<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsServer;
25
+ /** For Vike internal use */
27
26
  type PageContextBuiltInServerInternal<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsInternal;
28
27
  type PageContextBuiltInCommon<Page = [never]> = {
29
28
  /** The `export { Page }` of your `.page.js` file.
@@ -57,7 +56,10 @@ type PageContextBuiltInCommon<Page = [never]> = {
57
56
  * https://vike.dev/exports
58
57
  */
59
58
  exportsAll: ExportsAll;
60
- /** The URL of the current page */
59
+ /** The URL you provided to Vike when calling `renderPage({ urlOriginal })` in your server middleware.
60
+ *
61
+ * https://vike.dev/renderPage
62
+ */
61
63
  urlOriginal: string;
62
64
  /** If an error occurs, whether the error is a `404 Page Not Found`.
63
65
  *
@@ -18,6 +18,6 @@ export * from '../utils/projectInfo.js';
18
18
  export * from '../utils/hasPropertyGetter.js';
19
19
  export * from '../utils/isPromise.js';
20
20
  export * from '../utils/checkType.js';
21
- export * from '../utils/assertDefaultExport.js';
22
21
  export * from '../utils/objectEntries.js';
23
22
  export * from '../utils/getValuePrintable.js';
23
+ export * from '../utils/escapeRegex.js';
@@ -22,6 +22,6 @@ export * from '../utils/projectInfo.js';
22
22
  export * from '../utils/hasPropertyGetter.js';
23
23
  export * from '../utils/isPromise.js';
24
24
  export * from '../utils/checkType.js';
25
- export * from '../utils/assertDefaultExport.js';
26
25
  export * from '../utils/objectEntries.js';
27
26
  export * from '../utils/getValuePrintable.js';
27
+ export * from '../utils/escapeRegex.js';
@@ -0,0 +1,3 @@
1
+ export { defineConfig };
2
+ import type { Config } from '../shared/page-configs/Config.js';
3
+ declare function defineConfig(config: Config): Config;
@@ -0,0 +1,4 @@
1
+ export { defineConfig };
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
@@ -6,11 +6,13 @@ export type { PageContextClientWithServerRouting } from '../shared/types.js';
6
6
  export type { PageContextBuiltInServer } from '../shared/types.js';
7
7
  export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
8
8
  export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
9
- export type { Config, ConfigMeta as Meta } from '../shared/page-configs/Config.js';
9
+ export type { Config, ConfigMeta as Meta, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
10
10
  export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
11
11
  export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
12
12
  export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
13
+ export type { Url } from '../shared/addUrlComputedProps.js';
13
14
  export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
15
+ export { defineConfig } from './defineConfig.js';
14
16
  import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
15
17
  /** @deprecated Replace:
16
18
  * `import type { Env } from 'vike/types'`
@@ -1 +1 @@
1
- export {};
1
+ export { defineConfig } from './defineConfig.js';
@@ -1,5 +1,5 @@
1
1
  export { getFilePathAbsolute };
2
- export { getFilePathVite };
2
+ export { getFilePathRelativeToUserRootDir };
3
3
  import type { ResolvedConfig } from 'vite';
4
4
  declare function getFilePathAbsolute(filePath: string, config: ResolvedConfig): string;
5
- declare function getFilePathVite(filePath: string, userRootDir: string, alwaysRelativeToRoot?: boolean): string;
5
+ declare function getFilePathRelativeToUserRootDir(filePathAbsolute: string, userRootDir: string, alwaysRelative?: boolean): string;
@@ -1,5 +1,5 @@
1
1
  export { getFilePathAbsolute };
2
- export { getFilePathVite };
2
+ export { getFilePathRelativeToUserRootDir };
3
3
  import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
4
4
  import { assert } from './assert.js';
5
5
  import path from 'path';
@@ -42,19 +42,23 @@ function getFilePathAbsolute(filePath, config) {
42
42
  assertPathIsFilesystemAbsolute(filePathAbsolute);
43
43
  return filePathAbsolute;
44
44
  }
45
- function getFilePathVite(filePath, userRootDir, alwaysRelativeToRoot = false) {
46
- assertPosixPath(filePath);
45
+ function getFilePathRelativeToUserRootDir(filePathAbsolute, userRootDir, alwaysRelative = false) {
46
+ assertPosixPath(filePathAbsolute);
47
47
  assertPosixPath(userRootDir);
48
- const filePathRelativeToRoot = path.posix.relative(userRootDir, filePath);
49
- if (!filePath.startsWith(userRootDir)) {
50
- if (alwaysRelativeToRoot) {
51
- return filePathRelativeToRoot;
48
+ let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute);
49
+ if (filePathAbsolute.startsWith(userRootDir)) {
50
+ assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'),
51
+ // Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
52
+ { filePathRelativeToUserRootDir, filePathAbsolute, userRootDir });
53
+ filePathRelativeToUserRootDir = `/${filePathRelativeToUserRootDir}`;
54
+ return filePathRelativeToUserRootDir;
55
+ }
56
+ else {
57
+ if (alwaysRelative) {
58
+ return filePathRelativeToUserRootDir;
52
59
  }
53
60
  else {
54
- return filePath;
61
+ return filePathAbsolute;
55
62
  }
56
63
  }
57
- assert(!filePathRelativeToRoot.startsWith('.') && !filePathRelativeToRoot.startsWith('/'));
58
- const filePathVite = `/${filePathRelativeToRoot}`;
59
- return filePathVite;
60
64
  }
@@ -3,5 +3,7 @@ export { objectAssign };
3
3
  // - With type inference
4
4
  // - Preserves property descriptors, which we need for preserving the getters added by addUrlComputedProps()
5
5
  function objectAssign(obj, objAddendum) {
6
- Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
6
+ if (objAddendum) {
7
+ Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
8
+ }
7
9
  }
@@ -110,7 +110,10 @@ function parsePathname(urlWithoutHashNorSearch, baseServer) {
110
110
  else {
111
111
  // In the browser, this is the Base URL of the current URL
112
112
  // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
113
- const base = (typeof window !== 'undefined' && window?.document?.baseURI) || baseServer;
113
+ let baseURI = typeof window !== 'undefined' && window?.document?.baseURI;
114
+ if (baseURI)
115
+ baseURI = parseOrigin(baseURI).pathname;
116
+ const base = baseURI || baseServer;
114
117
  const pathname = resolveUrlPathnameRelative(urlWithoutHashNorSearch, base);
115
118
  // We need to parse the origin in case `base === window.document.baseURI`
116
119
  const parsed = parseOrigin(pathname);
@@ -153,6 +156,8 @@ function resolveUrlPathnameRelative(pathnameRelative, base) {
153
156
  let pathnameAbsolute = stack.join('/');
154
157
  if (baseRestoreTrailingSlash && !pathnameAbsolute.endsWith('/'))
155
158
  pathnameAbsolute += '/';
159
+ if (!pathnameAbsolute.startsWith('/'))
160
+ pathnameAbsolute = '/' + pathnameAbsolute;
156
161
  return pathnameAbsolute;
157
162
  }
158
163
  /* Not needed anymore?
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
5
5
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
6
6
  declare const projectInfo: {
7
7
  projectName: "Vike";
8
- projectVersion: "0.4.142";
8
+ projectVersion: "0.4.143-commit-dc6fea0";
9
9
  npmPackageName: "vike";
10
10
  githubRepository: "https://github.com/vikejs/vike";
11
11
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  import { onProjectInfo } from './assertSingleInstance.js';
3
- const PROJECT_VERSION = '0.4.142';
3
+ const PROJECT_VERSION = '0.4.143-commit-dc6fea0';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION,
@@ -0,0 +1,2 @@
1
+ export { requireResolve };
2
+ declare function requireResolve(importPath: string, cwd: string): string | null;
@@ -0,0 +1,57 @@
1
+ export { requireResolve };
2
+ import { assert } from './assert.js';
3
+ import { assertIsNotBrowser } from './assertIsNotBrowser.js';
4
+ import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
5
+ import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
6
+ import { scriptFileExtensionList } from './isScriptFile.js';
7
+ import { createRequire } from 'module';
8
+ // @ts-ignore Shimed by dist-cjs-fixup.js for CJS build.
9
+ const importMetaUrl = import.meta.url;
10
+ const require_ = createRequire(importMetaUrl);
11
+ assertIsNotBrowser();
12
+ assertIsNotProductionRuntime();
13
+ function requireResolve(importPath, cwd) {
14
+ assertPosixPath(cwd);
15
+ const clean = addFileExtensionsToRequireResolve();
16
+ importPath = removeFileExtention(importPath);
17
+ let importedFile;
18
+ try {
19
+ importedFile = require_.resolve(importPath, { paths: [cwd] });
20
+ }
21
+ catch {
22
+ importedFile = null;
23
+ }
24
+ finally {
25
+ clean();
26
+ }
27
+ if (importedFile) {
28
+ importedFile = toPosixPath(importedFile);
29
+ }
30
+ return importedFile;
31
+ }
32
+ function removeFileExtention(importPath) {
33
+ for (const ext of scriptFileExtensionList) {
34
+ const suffix = `.${ext}`;
35
+ if (importPath.endsWith(suffix)) {
36
+ return importPath.slice(0, -1 * suffix.length);
37
+ }
38
+ }
39
+ return importPath;
40
+ }
41
+ function addFileExtensionsToRequireResolve() {
42
+ const added = [];
43
+ scriptFileExtensionList.forEach((ext) => {
44
+ assert(!ext.includes('.'));
45
+ ext = `.${ext}`;
46
+ if (!require.extensions[ext]) {
47
+ require.extensions[ext] = require.extensions['.js'];
48
+ added.push(ext);
49
+ }
50
+ });
51
+ const clean = () => {
52
+ added.forEach((ext) => {
53
+ delete require.extensions[ext];
54
+ });
55
+ };
56
+ return clean;
57
+ }