vike 0.4.160 → 0.4.161

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 (121) hide show
  1. package/dist/cjs/node/cli/bin.js +5 -0
  2. package/dist/cjs/node/client/router.js +4 -2
  3. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
  4. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +148 -0
  5. package/dist/cjs/node/plugin/plugins/buildConfig.js +42 -15
  6. package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -13
  7. package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
  8. package/dist/cjs/node/plugin/plugins/distFileNames.js +9 -1
  9. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +7 -2
  10. package/dist/cjs/node/plugin/plugins/importBuild/index.js +4 -7
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +155 -111
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
  20. package/dist/cjs/node/plugin/utils.js +3 -2
  21. package/dist/cjs/node/prerender/runPrerender.js +12 -5
  22. package/dist/cjs/node/runtime/globalContext.js +7 -4
  23. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  24. package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
  25. package/dist/cjs/node/runtime/html/stream.js +2 -2
  26. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  27. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
  28. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  29. package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
  30. package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
  31. package/dist/cjs/node/runtime/utils.js +1 -1
  32. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
  33. package/dist/cjs/shared/route/executeGuardHook.js +3 -2
  34. package/dist/cjs/shared/utils.js +0 -1
  35. package/dist/cjs/utils/assertNodeVersion.js +2 -2
  36. package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
  37. package/dist/cjs/utils/isVersionOrAbove.js +29 -0
  38. package/dist/cjs/utils/nodeEnv.js +23 -1
  39. package/dist/cjs/utils/objectKeys.js +19 -3
  40. package/dist/cjs/utils/projectInfo.js +1 -1
  41. package/dist/cjs/utils/sorter.js +62 -1
  42. package/dist/esm/client/client-routing-runtime/index.d.ts +1 -1
  43. package/dist/esm/client/client-routing-runtime/index.js +1 -1
  44. package/dist/esm/node/cli/bin.js +3 -1
  45. package/dist/esm/node/client/router.d.ts +2 -0
  46. package/dist/esm/node/client/router.js +3 -1
  47. package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
  48. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +13 -0
  49. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +142 -0
  50. package/dist/esm/node/plugin/plugins/buildConfig.d.ts +2 -0
  51. package/dist/esm/node/plugin/plugins/buildConfig.js +43 -16
  52. package/dist/esm/node/plugin/plugins/commonConfig.js +6 -14
  53. package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
  54. package/dist/esm/node/plugin/plugins/distFileNames.js +9 -1
  55. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +8 -3
  56. package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
  57. package/dist/esm/node/plugin/plugins/importBuild/index.js +4 -7
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
  60. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
  61. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
  62. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
  63. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
  64. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
  65. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
  66. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -0
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +153 -109
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
  75. package/dist/esm/node/plugin/utils.d.ts +3 -2
  76. package/dist/esm/node/plugin/utils.js +3 -2
  77. package/dist/esm/node/prerender/runPrerender.js +13 -6
  78. package/dist/esm/node/runtime/globalContext.js +8 -5
  79. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  80. package/dist/esm/node/runtime/html/renderHtml.js +1 -1
  81. package/dist/esm/node/runtime/html/stream.js +2 -2
  82. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  83. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +6 -5
  84. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +39 -39
  85. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  86. package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
  87. package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
  88. package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
  89. package/dist/esm/node/runtime/utils.d.ts +1 -1
  90. package/dist/esm/node/runtime/utils.js +1 -1
  91. package/dist/esm/shared/page-configs/Config.d.ts +1 -1
  92. package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
  93. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
  94. package/dist/esm/shared/route/executeGuardHook.js +3 -2
  95. package/dist/esm/shared/utils.d.ts +0 -1
  96. package/dist/esm/shared/utils.js +0 -1
  97. package/dist/esm/utils/assertNodeVersion.js +2 -2
  98. package/dist/esm/utils/findFile.d.ts +3 -0
  99. package/dist/esm/utils/findFile.js +21 -0
  100. package/dist/esm/utils/getOutDirs.d.ts +1 -0
  101. package/dist/esm/utils/isVersionOrAbove.d.ts +2 -0
  102. package/dist/esm/utils/isVersionOrAbove.js +26 -0
  103. package/dist/esm/utils/nodeEnv.d.ts +4 -0
  104. package/dist/esm/utils/nodeEnv.js +19 -0
  105. package/dist/esm/utils/objectKeys.d.ts +10 -1
  106. package/dist/esm/utils/objectKeys.js +20 -3
  107. package/dist/esm/utils/projectInfo.d.ts +2 -2
  108. package/dist/esm/utils/projectInfo.js +1 -1
  109. package/dist/esm/utils/sorter.d.ts +59 -0
  110. package/dist/esm/utils/sorter.js +61 -0
  111. package/package.json +1 -1
  112. package/dist/cjs/utils/objectEntries.js +0 -8
  113. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
  114. package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
  115. package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
  116. package/dist/esm/utils/objectEntries.d.ts +0 -4
  117. package/dist/esm/utils/objectEntries.js +0 -5
  118. /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
  119. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
  120. /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
  121. /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
@@ -44,11 +44,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
44
44
  p = toPosixPath(p);
45
45
  assert(!p.startsWith(userRootDir));
46
46
  const filePathRelativeToUserRootDir = path.posix.join('/', p);
47
- const filePathAbsoluteFilesystem = path.posix.join(userRootDir, p);
48
- return {
49
- filePathRelativeToUserRootDir,
50
- filePathAbsoluteFilesystem
51
- };
47
+ return { filePathRelativeToUserRootDir };
52
48
  });
53
49
  return plusFiles;
54
50
  }
@@ -5,26 +5,53 @@ export { getLocationId };
5
5
  export { sortAfterInheritanceOrder };
6
6
  export { isGlobalLocation };
7
7
  export { applyFilesystemRoutingRootEffect };
8
+ export type { LocationId };
8
9
  export { getLogicalPath };
9
10
  /**
10
- * getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
11
- * getLocationId('/pages/some-page') => '/pages/some-page'
12
- * getLocationId('/renderer/+config.js') => '/renderer'
11
+ * The `locationId` value is used for filesystem inheritance.
12
+ *
13
+ * Each config value is assigned with a `locationId` value. That's the source-of-truth for determining inheritance between config values.
14
+ *
15
+ * For Vike extensions, `locationId` is different than the config value's `definedAt`, for example the `onRenderHtml()` hook of `vike-react`:
16
+ * - `locationId === '/pages'` (the directory of `/pages/+config.h.js` which extends `vike-react`)
17
+ * - `definedAt.filePathAbsoluteFilesystem === '/home/rom/code/my-vike-app/node_modules/vike-react/dist/renderer/onRenderHtml.js'` (the file where the value is defined)
18
+ *
19
+ * This is an important distinction because the Vike extension's config should only apply to where it's being extended from, for example:
20
+ * ```js
21
+ * // /pages/admin/+config.h.js
22
+ * import vikeVue from 'vike-vue/config'
23
+ * // Should only apply to /pages/admin/**
24
+ * export default { extends: [vikeVue] }
25
+ * ```
26
+ * ```js
27
+ * // /pages/marketing/+config.h.js
28
+ * import vikeReact from 'vike-react/config'
29
+ * // Should only apply to /pages/marketing/**
30
+ * export default { extends: [vikeReact] }
31
+ * ```
13
32
  */
14
- declare function getLocationId(filePathAbsoluteVite: string): string;
15
- /** Get URL determined by filesystem path */
16
- declare function getFilesystemRouteString(locationId: string): string;
33
+ type LocationId = string & {
34
+ __brand: 'LocationId';
35
+ };
36
+ /**
37
+ * `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
38
+ * `getLocationId('/renderer/+config.js')` => `'/renderer'`
39
+ *
40
+ * The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
41
+ */
42
+ declare function getLocationId(filePathRelativeToUserRootDir: string): LocationId;
43
+ /** Filesystem Routing: get the URL */
44
+ declare function getFilesystemRouteString(locationId: LocationId): string;
17
45
  /**
18
46
  * getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
19
- * getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
20
47
  */
21
- declare function getLogicalPath(someDir: string, removeDirs: string[]): string;
48
+ declare function getLogicalPath(locationId: LocationId, removeDirs: string[]): string;
22
49
  /** Whether configs defined in `locationId` apply in every `locationIds` */
23
- declare function isGlobalLocation(locationId: string, locationIds: string[]): boolean;
24
- declare function sortAfterInheritanceOrder(locationId1: string, locationId2: string, locationIdPage: string): -1 | 1 | 0;
50
+ declare function isGlobalLocation(locationId: LocationId, locationIds: LocationId[]): boolean;
51
+ declare function sortAfterInheritanceOrder(locationId1: LocationId, locationId2: LocationId, locationIdPage: LocationId): -1 | 1 | 0;
25
52
  /** Whether configs defined at `locationId1` also apply at `locationId2` */
26
- declare function isInherited(locationId1: string, locationId2: string): boolean;
27
- declare function getFilesystemRouteDefinedBy(locationId: string): string;
53
+ declare function isInherited(locationId1: LocationId, locationId2: LocationId): boolean;
54
+ declare function getFilesystemRouteDefinedBy(locationId: LocationId): string;
28
55
  declare function applyFilesystemRoutingRootEffect(routeFilesystem: string, filesystemRoutingRootEffect: {
29
56
  before: string;
30
57
  after: string;
@@ -7,40 +7,47 @@ export { isGlobalLocation };
7
7
  export { applyFilesystemRoutingRootEffect };
8
8
  // For ./filesystemRouting.spec.ts
9
9
  export { getLogicalPath };
10
- import { assert, assertPosixPath, getNpmPackageImportPath, isNpmPackageImport, higherFirst } from '../../../../utils.js';
10
+ import { assert, assertPosixPath, higherFirst } from '../../../../utils.js';
11
11
  /**
12
- * getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
13
- * getLocationId('/pages/some-page') => '/pages/some-page'
14
- * getLocationId('/renderer/+config.js') => '/renderer'
12
+ * `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
13
+ * `getLocationId('/renderer/+config.js')` => `'/renderer'`
14
+ *
15
+ * The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
15
16
  */
16
- function getLocationId(filePathAbsoluteVite) {
17
- const locationId = removeFilename(filePathAbsoluteVite, true);
17
+ function getLocationId(
18
+ // We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.h.js` that extends the Vike extension.
19
+ filePathRelativeToUserRootDir) {
20
+ assertPosixPath(filePathRelativeToUserRootDir);
21
+ assert(filePathRelativeToUserRootDir.startsWith('/'));
22
+ const locationId = removeFilename(filePathRelativeToUserRootDir);
18
23
  assertLocationId(locationId);
19
24
  return locationId;
20
25
  }
21
- /** Get URL determined by filesystem path */
26
+ /** Filesystem Routing: get the URL */
22
27
  function getFilesystemRouteString(locationId) {
23
28
  return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
24
29
  }
25
- /** Get apply root for config inheritance */
26
- function getInheritanceRoot(someDir) {
27
- return getLogicalPath(someDir, ['renderer']);
30
+ /** Filesystem Inheritance: get the apply root */
31
+ function getInheritanceRoot(locationId) {
32
+ return getLogicalPath(locationId, ['renderer']);
28
33
  }
29
34
  /**
30
35
  * getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
31
- * getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
32
36
  */
33
- function getLogicalPath(someDir, removeDirs) {
34
- someDir = removeNpmPackageName(someDir);
35
- someDir = removeDirectories(someDir, removeDirs);
36
- assertIsPath(someDir);
37
- return someDir;
37
+ function getLogicalPath(locationId, removeDirs) {
38
+ let logicalPath = removeDirectories(locationId, removeDirs);
39
+ assertIsPath(logicalPath);
40
+ return logicalPath;
38
41
  }
39
42
  /** Whether configs defined in `locationId` apply in every `locationIds` */
40
43
  function isGlobalLocation(locationId, locationIds) {
41
44
  return locationIds.every((locId) => isInherited(locationId, locId) || locationIsRendererDir(locId));
42
45
  }
43
46
  function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
47
+ assertLocationId(locationId1);
48
+ assertLocationId(locationId2);
49
+ if (locationId1 === locationId2)
50
+ return 0;
44
51
  const inheritanceRoot1 = getInheritanceRoot(locationId1);
45
52
  const inheritanceRoot2 = getInheritanceRoot(locationId2);
46
53
  const inheritanceRootPage = getInheritanceRoot(locationIdPage);
@@ -56,15 +63,10 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
56
63
  assert(inheritanceRoot1.length !== inheritanceRoot2.length);
57
64
  return higherFirst((inheritanceRoot) => inheritanceRoot.length)(inheritanceRoot1, inheritanceRoot2);
58
65
  }
59
- // Should be true since we aggregate interface files by locationId
60
- assert(locationId1 !== locationId2);
61
66
  // locationId1 first, i.e. `indexOf(locationId1) < indexOf(locationId2)`
62
67
  const locationId1First = -1;
63
68
  // locationId2 first, i.e. `indexOf(locationId2) < indexOf(locationId1)`
64
69
  const locationId2First = 1;
65
- if (locationIsNpmPackage(locationId1) !== locationIsNpmPackage(locationId2)) {
66
- return locationIsNpmPackage(locationId1) ? locationId2First : locationId1First;
67
- }
68
70
  if (locationIsRendererDir(locationId1) !== locationIsRendererDir(locationId2)) {
69
71
  return locationIsRendererDir(locationId1) ? locationId2First : locationId1First;
70
72
  }
@@ -75,9 +77,6 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
75
77
  }
76
78
  return locationId1 > locationId2 ? locationId1First : locationId2First;
77
79
  }
78
- function locationIsNpmPackage(locationId) {
79
- return !locationId.startsWith('/');
80
- }
81
80
  function locationIsRendererDir(locationId) {
82
81
  return locationId.split('/').includes('renderer');
83
82
  }
@@ -87,19 +86,6 @@ function isInherited(locationId1, locationId2) {
87
86
  const inheritanceRoot2 = getInheritanceRoot(locationId2);
88
87
  return startsWith(inheritanceRoot2, inheritanceRoot1);
89
88
  }
90
- function removeNpmPackageName(somePath) {
91
- if (!isNpmPackageImport(somePath)) {
92
- assert(somePath.startsWith('/'));
93
- return somePath;
94
- }
95
- const importPath = getNpmPackageImportPath(somePath);
96
- if (!importPath)
97
- return '/';
98
- assertPosixPath(importPath);
99
- assert(!importPath.startsWith('/'));
100
- somePath = '/' + importPath;
101
- return somePath;
102
- }
103
89
  function removeDirectories(somePath, removeDirs) {
104
90
  assertPosixPath(somePath);
105
91
  somePath = somePath
@@ -110,17 +96,13 @@ function removeDirectories(somePath, removeDirs) {
110
96
  somePath = '/';
111
97
  return somePath;
112
98
  }
113
- function removeFilename(filePathAbsoluteVite, optional) {
114
- assertPosixPath(filePathAbsoluteVite);
115
- assert(filePathAbsoluteVite.startsWith('/') || isNpmPackageImport(filePathAbsoluteVite));
99
+ function removeFilename(filePathRelativeToUserRootDir) {
100
+ const filePathParts = filePathRelativeToUserRootDir.split('/');
116
101
  {
117
- const filename = filePathAbsoluteVite.split('/').slice(-1)[0];
118
- if (!filename.includes('.')) {
119
- assert(optional);
120
- return filePathAbsoluteVite;
121
- }
102
+ const filename = filePathParts.slice(-1)[0];
103
+ assert(filename.includes('.'));
122
104
  }
123
- let locationId = filePathAbsoluteVite.split('/').slice(0, -1).join('/');
105
+ let locationId = filePathParts.slice(0, -1).join('/');
124
106
  if (locationId === '')
125
107
  locationId = '/';
126
108
  assertLocationId(locationId);
@@ -142,7 +124,7 @@ function applyFilesystemRoutingRootEffect(routeFilesystem, filesystemRoutingRoot
142
124
  return routeFilesystem;
143
125
  }
144
126
  function assertLocationId(locationId) {
145
- assert(locationId.startsWith('/') || isNpmPackageImport(locationId));
127
+ assert(locationId.startsWith('/'));
146
128
  assert(!locationId.endsWith('/') || locationId === '/');
147
129
  }
148
130
  function assertIsPath(logicalPath) {
@@ -6,7 +6,7 @@ import { assertPosixPath, assert, assertUsage, assertWarning, hasProp, assertIsN
6
6
  import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
7
7
  import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
8
8
  import pc from '@brillout/picocolors';
9
- import { parseImportData } from './transformImports.js';
9
+ import { parseImportData } from './transformFileImports.js';
10
10
  import { getConfigFileExport } from '../getConfigFileExport.js';
11
11
  import { assertImportPath, resolveImportPath } from './resolveImportPath.js';
12
12
  assertIsNotProductionRuntime();
@@ -14,7 +14,7 @@ assertIsNotProductionRuntime();
14
14
  async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
15
15
  const f = import_.filePathAbsoluteFilesystem;
16
16
  if (!importedFilesLoaded[f]) {
17
- importedFilesLoaded[f] = transpileAndExecuteFile(import_, true, userRootDir).then((r) => r.fileExports);
17
+ importedFilesLoaded[f] = transpileAndExecuteFile(import_, false, userRootDir).then((r) => r.fileExports);
18
18
  }
19
19
  const fileExports = await importedFilesLoaded[f];
20
20
  const fileExport = fileExports[import_.fileExportName];
@@ -22,7 +22,7 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
22
22
  }
23
23
  // Load +{configName}.js
24
24
  async function loadValueFile(interfaceValueFile, configName, userRootDir) {
25
- const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
25
+ const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, false, userRootDir);
26
26
  const { filePathToShowToUser } = interfaceValueFile.filePath;
27
27
  assertPlusFileExport(fileExports, filePathToShowToUser, configName);
28
28
  Object.entries(fileExports).forEach(([exportName, configValue]) => {
@@ -34,7 +34,7 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
34
34
  async function loadConfigFile(configFilePath, userRootDir, visited, isConfigOfExtension) {
35
35
  const { filePathAbsoluteFilesystem } = configFilePath;
36
36
  assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
37
- const { fileExports } = await transpileAndExecuteFile(configFilePath, false, userRootDir, isConfigOfExtension);
37
+ const { fileExports } = await transpileAndExecuteFile(configFilePath, !isConfigOfExtension, userRootDir, isConfigOfExtension);
38
38
  const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
39
39
  ...visited,
40
40
  filePathAbsoluteFilesystem
@@ -0,0 +1,5 @@
1
+ export { resolveFilePathRelativeToUserRootDir };
2
+ export { resolveFilePathAbsoluteFilesystem };
3
+ import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
4
+ declare function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir: string, userRootDir: string): FilePathResolved;
5
+ declare function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem: string, userRootDir: string): FilePathResolved;
@@ -0,0 +1,27 @@
1
+ export { resolveFilePathRelativeToUserRootDir };
2
+ export { resolveFilePathAbsoluteFilesystem };
3
+ import path from 'path';
4
+ import { assert, assertPosixPath } from '../../../../utils.js';
5
+ function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
6
+ assertPosixPath(filePathRelativeToUserRootDir);
7
+ assertPosixPath(userRootDir);
8
+ const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelativeToUserRootDir);
9
+ return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
10
+ }
11
+ function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
12
+ assertPosixPath(filePathAbsoluteFilesystem);
13
+ assertPosixPath(userRootDir);
14
+ let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
15
+ assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
16
+ filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
17
+ return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
18
+ }
19
+ function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
20
+ return {
21
+ filePathRelativeToUserRootDir,
22
+ filePathAbsoluteVite: filePathRelativeToUserRootDir,
23
+ filePathAbsoluteFilesystem,
24
+ filePathToShowToUser: filePathRelativeToUserRootDir,
25
+ importPathAbsolute: null
26
+ };
27
+ }
@@ -3,7 +3,7 @@ export { resolveImportPath };
3
3
  export { assertImportPath };
4
4
  export { clearFilesEnvMap };
5
5
  import type { ConfigEnvInternal, DefinedAtFileFullInfo, FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
6
- import { type ImportData } from './transformImports.js';
6
+ import { type ImportData } from './transformFileImports.js';
7
7
  declare function resolveImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | (DefinedAtFileFullInfo & {
8
8
  fileExportName: string;
9
9
  });
@@ -4,7 +4,7 @@ export { assertImportPath };
4
4
  export { clearFilesEnvMap };
5
5
  import pc from '@brillout/picocolors';
6
6
  import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
7
- import { parseImportData } from './transformImports.js';
7
+ import { parseImportData } from './transformFileImports.js';
8
8
  import path from 'path';
9
9
  const filesEnvMap = new Map();
10
10
  function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
@@ -1,4 +1,4 @@
1
- export { transformImports };
1
+ export { transformFileImports };
2
2
  export { parseImportData };
3
3
  export { isImportData };
4
4
  export type { FileImport };
@@ -8,7 +8,7 @@ type FileImport = {
8
8
  importString: string;
9
9
  importLocalName: string;
10
10
  };
11
- declare function transformImports(code: string, filePathToShowToUser2: string, skipWarnings?: true): {
11
+ declare function transformFileImports(code: string, filePathToShowToUser2: string, skipWarnings?: true): {
12
12
  noTransformation: true;
13
13
  } | {
14
14
  noTransformation: false;
@@ -1,4 +1,4 @@
1
- export { transformImports };
1
+ export { transformFileImports };
2
2
  export { parseImportData };
3
3
  export { isImportData };
4
4
  // Playground: https://github.com/brillout/acorn-playground
@@ -7,8 +7,8 @@ export { isImportData };
7
7
  import { parse } from 'acorn';
8
8
  import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
9
9
  import pc from '@brillout/picocolors';
10
- function transformImports(code, filePathToShowToUser2,
11
- // For ./transformImports.spec.ts
10
+ function transformFileImports(code, filePathToShowToUser2,
11
+ // For ./transformFileImports.spec.ts
12
12
  skipWarnings) {
13
13
  const spliceOperations = [];
14
14
  const fileImportsTransformed = [];
@@ -23,8 +23,8 @@ skipWarnings) {
23
23
  return;
24
24
  const importPath = node.source.value;
25
25
  assert(typeof importPath === 'string');
26
- // - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript => transformImports() => esbuild for bundling.
27
- // - Or we use an esbuild plugin to apply transformImports(). Maybe we can completely skip the need for acorn?
26
+ // - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript => transformFileImports() => esbuild for bundling.
27
+ // - Or we use an esbuild plugin to apply transformFileImports(). Maybe we can completely skip the need for acorn?
28
28
  // - ?real breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
29
29
  // - Import attributes would be the best.
30
30
  // - But it only works with Node.js >=21: https://nodejs.org/api/esm.html#import-attributes
@@ -32,7 +32,7 @@ skipWarnings) {
32
32
  // - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
33
33
  // - Esbuid seems to support it: https://esbuild.github.io/plugins/#on-load-arguments:~:text=This%20contains%20a%20map%20of%20the%20import%20attributes%20that
34
34
  // - acorn supports it over an acorn plugin: https://github.com/acornjs/acorn/issues/983
35
- // - Maybe we can use an esbuild plugin instead of acorn to apply transformImports()?
35
+ // - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
36
36
  // - Using a magic comment `// @vike-real-import` is tricky:
37
37
  // - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
38
38
  // - Using source maps to track these magic comments is brittle (source maps can easily break)
@@ -4,7 +4,7 @@ export { getConfigExecutionErrorIntroMsg };
4
4
  export { isTmpFile };
5
5
  import 'source-map-support/register.js';
6
6
  import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
7
- declare function transpileAndExecuteFile(filePath: FilePathResolved, isValueFile: boolean, userRootDir: string, isConfigOfExtension?: boolean): Promise<{
7
+ declare function transpileAndExecuteFile(filePath: FilePathResolved, transformImports: boolean, userRootDir: string, doNotTranspile?: boolean): Promise<{
8
8
  fileExports: Record<string, unknown>;
9
9
  }>;
10
10
  declare function getConfigBuildErrorFormatted(err: unknown): null | string;
@@ -8,13 +8,14 @@ import path from 'path';
8
8
  import pc from '@brillout/picocolors';
9
9
  import { import_ } from '@brillout/import';
10
10
  import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, unique, assertWarning, isObject, toPosixPath } from '../../../../utils.js';
11
- import { isImportData, transformImports } from './transformImports.js';
11
+ import { isImportData, transformFileImports } from './transformFileImports.js';
12
12
  import { vikeConfigDependencies } from '../getVikeConfig.js';
13
13
  import 'source-map-support/register.js';
14
14
  import { getConfigFileExport } from '../getConfigFileExport.js';
15
15
  assertIsNotProductionRuntime();
16
- async function transpileAndExecuteFile(filePath, isValueFile, userRootDir, isConfigOfExtension = false) {
17
- if (isConfigOfExtension) {
16
+ async function transpileAndExecuteFile(filePath, transformImports, userRootDir, doNotTranspile = false) {
17
+ if (doNotTranspile) {
18
+ assert(!transformImports);
18
19
  const fileExports = await executeFile(filePath.filePathAbsoluteFilesystem, filePath);
19
20
  if (isHeaderFile(filePath.filePathAbsoluteFilesystem)) {
20
21
  const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
@@ -23,21 +24,20 @@ async function transpileAndExecuteFile(filePath, isValueFile, userRootDir, isCon
23
24
  return { fileExports };
24
25
  }
25
26
  else {
26
- const { code, fileImportsTransformed } = await transpileFile(filePath, isValueFile, userRootDir);
27
- const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed, isValueFile);
27
+ const { code, fileImportsTransformed } = await transpileFile(filePath, transformImports, userRootDir);
28
+ const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed);
28
29
  return { fileExports };
29
30
  }
30
31
  }
31
- async function transpileFile(filePath, isValueFile, userRootDir) {
32
+ async function transpileFile(filePath, transformImports, userRootDir) {
32
33
  const { filePathAbsoluteFilesystem } = filePath;
33
34
  const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
34
35
  assertPosixPath(filePathAbsoluteFilesystem);
35
36
  vikeConfigDependencies.add(filePathAbsoluteFilesystem);
36
- const importsAreTransformed = !isValueFile;
37
- let code = await transpileWithEsbuild(filePath, userRootDir, importsAreTransformed, isValueFile);
37
+ let code = await transpileWithEsbuild(filePath, userRootDir, transformImports);
38
38
  let fileImportsTransformed = null;
39
- if (importsAreTransformed) {
40
- const res = transformImports_(code, filePath);
39
+ if (transformImports) {
40
+ const res = transformFileImports_(code, filePath);
41
41
  if (res) {
42
42
  code = res.code;
43
43
  fileImportsTransformed = res.fileImportsTransformed;
@@ -45,21 +45,16 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
45
45
  }
46
46
  else {
47
47
  if (isHeaderFile(filePathAbsoluteFilesystem)) {
48
- if (isValueFile) {
49
- assertWarning(false, `${filePathToShowToUser2} is a JavaScript header file (.h.js), but JavaScript header files only apply to +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
50
- }
51
- else {
52
- assert(false);
53
- }
48
+ assertWarning(false, `${filePathToShowToUser2} is a JavaScript header file (.h.js), but JavaScript header files only apply to +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
54
49
  }
55
50
  }
56
51
  return { code, fileImportsTransformed };
57
52
  }
58
- function transformImports_(codeOriginal, filePath) {
53
+ function transformFileImports_(codeOriginal, filePath) {
59
54
  const { filePathAbsoluteFilesystem } = filePath;
60
55
  const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
61
56
  // Replace import statements with import strings
62
- const res = transformImports(codeOriginal, filePathToShowToUser2);
57
+ const res = transformFileImports(codeOriginal, filePathToShowToUser2);
63
58
  if (res.noTransformation) {
64
59
  return null;
65
60
  }
@@ -72,8 +67,7 @@ function transformImports_(codeOriginal, filePath) {
72
67
  }
73
68
  return { code, fileImportsTransformed };
74
69
  }
75
- async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed, isValueFile) {
76
- const isConfigFile = !isValueFile;
70
+ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
77
71
  const entryFilePath = filePath.filePathAbsoluteFilesystem;
78
72
  const entryFileDir = path.posix.dirname(entryFilePath);
79
73
  const options = {
@@ -94,12 +88,12 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
94
88
  // Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
95
89
  treeShaking: false,
96
90
  minify: false,
97
- metafile: isConfigFile,
91
+ metafile: !transformImports,
98
92
  // We cannot bundle imports that are meant to be transformed
99
- bundle: !importsAreTransformed
93
+ bundle: !transformImports
100
94
  };
101
95
  // Track dependencies
102
- if (isConfigFile) {
96
+ if (!transformImports) {
103
97
  options.packages = 'external';
104
98
  options.plugins = [
105
99
  {
@@ -134,7 +128,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
134
128
  throw err;
135
129
  }
136
130
  // Track dependencies
137
- if (isConfigFile) {
131
+ if (!transformImports) {
138
132
  assert(result.metafile);
139
133
  Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
140
134
  filePathRelative = toPosixPath(filePathRelative);
@@ -147,7 +141,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
147
141
  assert(typeof code === 'string');
148
142
  return code;
149
143
  }
150
- async function executeTranspiledFile(filePath, code, fileImportsTransformed, isValueFile) {
144
+ async function executeTranspiledFile(filePath, code, fileImportsTransformed) {
151
145
  const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
152
146
  // Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
153
147
  // - But seems to break source maps, so I don't think it's worth it
@@ -161,7 +155,7 @@ async function executeTranspiledFile(filePath, code, fileImportsTransformed, isV
161
155
  finally {
162
156
  clean();
163
157
  }
164
- if (fileImportsTransformed && !isValueFile) {
158
+ if (fileImportsTransformed) {
165
159
  assert(filePathRelativeToUserRootDir !== undefined);
166
160
  const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
167
161
  assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2);
@@ -2,11 +2,14 @@ export { getVikeConfig };
2
2
  export { reloadVikeConfig };
3
3
  export { vikeConfigDependencies };
4
4
  export { isVikeConfigFile };
5
+ export { isV1Design };
5
6
  export type { InterfaceValueFile };
6
7
  import type { PageConfigGlobalBuildTime, PageConfigBuildTime, FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
7
8
  import type { ExtensionResolved } from '../../../../../shared/ConfigVike.js';
9
+ import { type LocationId } from './getVikeConfig/filesystemRouting.js';
8
10
  import type { ResolvedConfig } from 'vite';
9
11
  type InterfaceFileCommons = {
12
+ locationId: LocationId;
10
13
  filePath: FilePathResolved;
11
14
  fileExportsByConfigName: Record<ConfigName, {
12
15
  configValue?: unknown;
@@ -26,4 +29,5 @@ type VikeConfig = {
26
29
  declare const vikeConfigDependencies: Set<string>;
27
30
  declare function reloadVikeConfig(userRootDir: string, outDirRoot: string, extensions: ExtensionResolved[]): void;
28
31
  declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: boolean, extensions?: ExtensionResolved[]): Promise<VikeConfig>;
32
+ declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
29
33
  declare function isVikeConfigFile(filePath: string): boolean;