vike 0.4.159 → 0.4.160-commit-30d535e
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.
- package/dist/cjs/node/plugin/index.js +20 -1
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +129 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +139 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformFileImports.js} +44 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +105 -78
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +201 -382
- package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -3
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +54 -27
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assert.js +5 -6
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/nodeEnv.js +33 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +2 -4
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/node/plugin/index.js +21 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +8 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +21 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +133 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.d.ts → getVikeConfig/transformFileImports.d.ts} +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformFileImports.js} +43 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.d.ts → getVikeConfig/transpileAndExecuteFile.d.ts} +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +105 -78
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +16 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +199 -380
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -4
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertPlusFileExport.d.ts +2 -0
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +38 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +54 -27
- package/dist/esm/shared/route/abort.js +2 -2
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/assert.js +5 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +8 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/nodeEnv.d.ts +6 -0
- package/dist/esm/utils/nodeEnv.js +29 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -8
- package/dist/esm/utils/projectInfo.js +2 -4
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +1 -1
- package/dist/cjs/shared/page-configs/assertExports.js +0 -67
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
- package/dist/esm/shared/page-configs/assertExports.js +0 -61
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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(
|
|
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:
|
|
24
|
-
declare function sortAfterInheritanceOrder(locationId1:
|
|
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:
|
|
27
|
-
declare function getFilesystemRouteDefinedBy(locationId:
|
|
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;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -7,40 +7,47 @@ export { isGlobalLocation };
|
|
|
7
7
|
export { applyFilesystemRoutingRootEffect };
|
|
8
8
|
// For ./filesystemRouting.spec.ts
|
|
9
9
|
export { getLogicalPath };
|
|
10
|
-
import { assert, assertPosixPath,
|
|
10
|
+
import { assert, assertPosixPath, higherFirst } from '../../../../utils.js';
|
|
11
11
|
/**
|
|
12
|
-
* getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
|
|
13
|
-
* getLocationId('/
|
|
14
|
-
*
|
|
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(
|
|
17
|
-
|
|
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
|
-
/**
|
|
26
|
+
/** Filesystem Routing: get the URL */
|
|
22
27
|
function getFilesystemRouteString(locationId) {
|
|
23
28
|
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
24
29
|
}
|
|
25
|
-
/**
|
|
26
|
-
function getInheritanceRoot(
|
|
27
|
-
return getLogicalPath(
|
|
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(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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(
|
|
114
|
-
|
|
115
|
-
assert(filePathAbsoluteVite.startsWith('/') || isNpmPackageImport(filePathAbsoluteVite));
|
|
99
|
+
function removeFilename(filePathRelativeToUserRootDir) {
|
|
100
|
+
const filePathParts = filePathRelativeToUserRootDir.split('/');
|
|
116
101
|
{
|
|
117
|
-
const filename =
|
|
118
|
-
|
|
119
|
-
assert(optional);
|
|
120
|
-
return filePathAbsoluteVite;
|
|
121
|
-
}
|
|
102
|
+
const filename = filePathParts.slice(-1)[0];
|
|
103
|
+
assert(filename.includes('.'));
|
|
122
104
|
}
|
|
123
|
-
let locationId =
|
|
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('/')
|
|
127
|
+
assert(locationId.startsWith('/'));
|
|
146
128
|
assert(!locationId.endsWith('/') || locationId === '/');
|
|
147
129
|
}
|
|
148
130
|
function assertIsPath(logicalPath) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { loadImportedFile };
|
|
2
|
+
export { loadValueFile };
|
|
3
|
+
export { loadConfigFile };
|
|
4
|
+
export type { ImportedFilesLoaded };
|
|
5
|
+
export type { ConfigFile };
|
|
6
|
+
import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
+
import type { InterfaceValueFile } from '../getVikeConfig.js';
|
|
8
|
+
type ImportedFilesLoaded = Record<string, Promise<Record<string, unknown>>>;
|
|
9
|
+
type ConfigFile = {
|
|
10
|
+
fileExports: Record<string, unknown>;
|
|
11
|
+
filePath: FilePathResolved;
|
|
12
|
+
extendsFilePaths: string[];
|
|
13
|
+
};
|
|
14
|
+
declare function loadImportedFile(import_: FilePathResolved & {
|
|
15
|
+
fileExportName: string;
|
|
16
|
+
}, userRootDir: string, importedFilesLoaded: ImportedFilesLoaded): Promise<unknown>;
|
|
17
|
+
declare function loadValueFile(interfaceValueFile: InterfaceValueFile, configName: string, userRootDir: string): Promise<void>;
|
|
18
|
+
declare function loadConfigFile(configFilePath: FilePathResolved, userRootDir: string, visited: string[], isConfigOfExtension: boolean): Promise<{
|
|
19
|
+
configFile: ConfigFile;
|
|
20
|
+
extendsConfigs: ConfigFile[];
|
|
21
|
+
}>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Files loadded at config time:
|
|
2
|
+
export { loadImportedFile };
|
|
3
|
+
export { loadValueFile };
|
|
4
|
+
export { loadConfigFile };
|
|
5
|
+
import { assertPosixPath, assert, assertUsage, assertWarning, hasProp, assertIsNotProductionRuntime, isNpmPackageImport } from '../../../../utils.js';
|
|
6
|
+
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
|
+
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
|
+
import pc from '@brillout/picocolors';
|
|
9
|
+
import { parseImportData } from './transformFileImports.js';
|
|
10
|
+
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
11
|
+
import { assertImportPath, resolveImportPath } from './resolveImportPath.js';
|
|
12
|
+
assertIsNotProductionRuntime();
|
|
13
|
+
// Load fake import
|
|
14
|
+
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
15
|
+
const f = import_.filePathAbsoluteFilesystem;
|
|
16
|
+
if (!importedFilesLoaded[f]) {
|
|
17
|
+
importedFilesLoaded[f] = transpileAndExecuteFile(import_, false, userRootDir).then((r) => r.fileExports);
|
|
18
|
+
}
|
|
19
|
+
const fileExports = await importedFilesLoaded[f];
|
|
20
|
+
const fileExport = fileExports[import_.fileExportName];
|
|
21
|
+
return fileExport;
|
|
22
|
+
}
|
|
23
|
+
// Load +{configName}.js
|
|
24
|
+
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
25
|
+
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, false, userRootDir);
|
|
26
|
+
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
27
|
+
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
28
|
+
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
29
|
+
const configName_ = exportName === 'default' ? configName : exportName;
|
|
30
|
+
interfaceValueFile.fileExportsByConfigName[configName_] = { configValue };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Load +config.js, including all its extends fake imports
|
|
34
|
+
async function loadConfigFile(configFilePath, userRootDir, visited, isConfigOfExtension) {
|
|
35
|
+
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
36
|
+
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
37
|
+
const { fileExports } = await transpileAndExecuteFile(configFilePath, !isConfigOfExtension, userRootDir, isConfigOfExtension);
|
|
38
|
+
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
39
|
+
...visited,
|
|
40
|
+
filePathAbsoluteFilesystem
|
|
41
|
+
]);
|
|
42
|
+
const configFile = {
|
|
43
|
+
fileExports,
|
|
44
|
+
filePath: configFilePath,
|
|
45
|
+
extendsFilePaths
|
|
46
|
+
};
|
|
47
|
+
return { configFile, extendsConfigs };
|
|
48
|
+
}
|
|
49
|
+
function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
50
|
+
const idx = visited.indexOf(filePathAbsoluteFilesystem);
|
|
51
|
+
if (idx === -1)
|
|
52
|
+
return;
|
|
53
|
+
const loop = visited.slice(idx);
|
|
54
|
+
assert(loop[0] === filePathAbsoluteFilesystem);
|
|
55
|
+
assertUsage(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
56
|
+
}
|
|
57
|
+
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
58
|
+
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
59
|
+
const extendsConfigFiles = [];
|
|
60
|
+
extendsImportData.map((importData) => {
|
|
61
|
+
const { importPath: importPath } = importData;
|
|
62
|
+
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
63
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
64
|
+
warnUserLandExtension(importPath, configFilePath);
|
|
65
|
+
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
66
|
+
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
67
|
+
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
68
|
+
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
69
|
+
extendsConfigFiles.push({
|
|
70
|
+
filePathAbsoluteFilesystem,
|
|
71
|
+
filePathAbsoluteVite,
|
|
72
|
+
filePathRelativeToUserRootDir,
|
|
73
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
74
|
+
importPathAbsolute: importPath
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const extendsConfigs = [];
|
|
78
|
+
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
79
|
+
const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
|
|
80
|
+
extendsConfigs.push(result.configFile);
|
|
81
|
+
extendsConfigs.push(...result.extendsConfigs);
|
|
82
|
+
}));
|
|
83
|
+
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
84
|
+
return { extendsConfigs, extendsFilePaths };
|
|
85
|
+
}
|
|
86
|
+
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
87
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
88
|
+
assertPosixPath(userRootDir);
|
|
89
|
+
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
93
|
+
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
94
|
+
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
95
|
+
return filePathRelativeToUserRootDir;
|
|
96
|
+
}
|
|
97
|
+
function warnUserLandExtension(importPath, configFilePath) {
|
|
98
|
+
assertWarning(isNpmPackageImport(importPath), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
99
|
+
}
|
|
100
|
+
function getExtendsImportData(configFileExports, configFilePath) {
|
|
101
|
+
const { filePathToShowToUser } = configFilePath;
|
|
102
|
+
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
103
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
104
|
+
let extendList;
|
|
105
|
+
if (!('extends' in configFileExport)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
else if (hasProp(configFileExport, 'extends', 'string')) {
|
|
109
|
+
extendList = [configFileExport.extends];
|
|
110
|
+
}
|
|
111
|
+
else if (hasProp(configFileExport, 'extends', 'string[]')) {
|
|
112
|
+
extendList = configFileExport.extends;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
assertUsage(false, wrongUsage);
|
|
116
|
+
}
|
|
117
|
+
const extendsImportData = extendList.map((importDataSerialized) => {
|
|
118
|
+
const importData = parseImportData(importDataSerialized);
|
|
119
|
+
assertUsage(importData, wrongUsage);
|
|
120
|
+
return importData;
|
|
121
|
+
});
|
|
122
|
+
return extendsImportData;
|
|
123
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts
ADDED
|
@@ -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;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js
ADDED
|
@@ -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
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { resolveImport };
|
|
2
|
+
export { resolveImportPath };
|
|
3
|
+
export { assertImportPath };
|
|
4
|
+
export { clearFilesEnvMap };
|
|
5
|
+
import type { ConfigEnvInternal, DefinedAtFileFullInfo, FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
6
|
+
import { type ImportData } from './transformFileImports.js';
|
|
7
|
+
declare function resolveImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | (DefinedAtFileFullInfo & {
|
|
8
|
+
fileExportName: string;
|
|
9
|
+
});
|
|
10
|
+
declare function resolveImportPath(importData: ImportData, importerFilePath: FilePathResolved): string | null;
|
|
11
|
+
declare function assertImportPath(filePathAbsoluteFilesystem: string | null, importData: ImportData, importerFilePath: FilePathResolved): asserts filePathAbsoluteFilesystem is string;
|
|
12
|
+
declare function clearFilesEnvMap(): void;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export { resolveImport };
|
|
2
|
+
export { resolveImportPath };
|
|
3
|
+
export { assertImportPath };
|
|
4
|
+
export { clearFilesEnvMap };
|
|
5
|
+
import pc from '@brillout/picocolors';
|
|
6
|
+
import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
|
|
7
|
+
import { parseImportData } from './transformFileImports.js';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
const filesEnvMap = new Map();
|
|
10
|
+
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
11
|
+
if (typeof configValue !== 'string')
|
|
12
|
+
return null;
|
|
13
|
+
const importData = parseImportData(configValue);
|
|
14
|
+
if (!importData)
|
|
15
|
+
return null;
|
|
16
|
+
const { importPath, exportName } = importData;
|
|
17
|
+
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
18
|
+
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
19
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
20
|
+
if (importPath.startsWith('.')) {
|
|
21
|
+
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
22
|
+
// ```
|
|
23
|
+
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
24
|
+
// ```
|
|
25
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
26
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
27
|
+
const filePath = {
|
|
28
|
+
filePathAbsoluteFilesystem,
|
|
29
|
+
filePathRelativeToUserRootDir,
|
|
30
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
31
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
32
|
+
importPathAbsolute: null
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
...filePath,
|
|
36
|
+
fileExportName: exportName,
|
|
37
|
+
fileExportPathToShowToUser
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// importPath can be:
|
|
42
|
+
// - an npm package import
|
|
43
|
+
// - a path alias
|
|
44
|
+
const filePath = {
|
|
45
|
+
filePathAbsoluteFilesystem,
|
|
46
|
+
filePathRelativeToUserRootDir: null,
|
|
47
|
+
filePathAbsoluteVite: importPath,
|
|
48
|
+
filePathToShowToUser: importPath,
|
|
49
|
+
importPathAbsolute: importPath
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...filePath,
|
|
53
|
+
fileExportName: exportName,
|
|
54
|
+
fileExportPathToShowToUser
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
59
|
+
assertPosixPath(userRootDir);
|
|
60
|
+
let filePathRelativeToUserRootDir;
|
|
61
|
+
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
62
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
assertUsage(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${pc.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
66
|
+
// None of the following works. Seems to be a Vite bug?
|
|
67
|
+
// /*
|
|
68
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
69
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
70
|
+
// /*/
|
|
71
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
72
|
+
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
73
|
+
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
74
|
+
// //*/
|
|
75
|
+
}
|
|
76
|
+
assertPosixPath(filePathRelativeToUserRootDir);
|
|
77
|
+
assert(filePathRelativeToUserRootDir.startsWith('/'));
|
|
78
|
+
return filePathRelativeToUserRootDir;
|
|
79
|
+
}
|
|
80
|
+
function resolveImportPath(importData, importerFilePath) {
|
|
81
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
82
|
+
assertPosixPath(importerFilePathAbsolute);
|
|
83
|
+
const cwd = path.posix.dirname(importerFilePathAbsolute);
|
|
84
|
+
// We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer): https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment137174954_62272600:~:text=But%20the%20argument%20parent%20(aka%20cwd)%20still%20requires%20a%20flag
|
|
85
|
+
// filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
|
|
86
|
+
const filePathAbsoluteFilesystem = requireResolve(importData.importPath, cwd);
|
|
87
|
+
return filePathAbsoluteFilesystem;
|
|
88
|
+
}
|
|
89
|
+
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
90
|
+
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
91
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
92
|
+
if (!filePathAbsoluteFilesystem) {
|
|
93
|
+
const importPathString = pc.cyan(`'${importPath}'`);
|
|
94
|
+
const errIntro = importStringWasGenerated
|
|
95
|
+
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
96
|
+
: `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
97
|
+
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
98
|
+
if (importPath.startsWith('.')) {
|
|
99
|
+
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
assertUsage(false, `${errIntro2} exist?`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
107
|
+
assertPosixPath(filePathForEnvCheck);
|
|
108
|
+
if (!filesEnvMap.has(filePathForEnvCheck)) {
|
|
109
|
+
filesEnvMap.set(filePathForEnvCheck, []);
|
|
110
|
+
}
|
|
111
|
+
const fileEnv = filesEnvMap.get(filePathForEnvCheck);
|
|
112
|
+
fileEnv.push({ configEnv, configName });
|
|
113
|
+
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnv, configEnv))[0];
|
|
114
|
+
if (configDifferentEnv) {
|
|
115
|
+
assertUsage(false, [
|
|
116
|
+
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
117
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(JSON.stringify(c.configEnv))}`),
|
|
118
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
|
|
119
|
+
].join('\n'));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function clearFilesEnvMap() {
|
|
123
|
+
filesEnvMap.clear();
|
|
124
|
+
}
|
|
125
|
+
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
126
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
127
|
+
assertPosixPath(root);
|
|
128
|
+
assert(filePathAbsoluteFilesystem.startsWith(root));
|
|
129
|
+
let vitePath = path.posix.relative(root, filePathAbsoluteFilesystem);
|
|
130
|
+
assert(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
131
|
+
vitePath = '/' + vitePath;
|
|
132
|
+
return vitePath;
|
|
133
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformFileImports };
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
export type { FileImport };
|
|
@@ -8,12 +8,12 @@ type FileImport = {
|
|
|
8
8
|
importString: string;
|
|
9
9
|
importLocalName: string;
|
|
10
10
|
};
|
|
11
|
-
declare function
|
|
12
|
-
|
|
11
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, skipWarnings?: true): {
|
|
12
|
+
noTransformation: true;
|
|
13
13
|
} | {
|
|
14
|
-
|
|
14
|
+
noTransformation: false;
|
|
15
15
|
code: string;
|
|
16
|
-
|
|
16
|
+
fileImportsTransformed: FileImport[];
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Data Structure holding info about import statement:
|