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
|
@@ -28,7 +28,8 @@ const baseUrls_js_1 = require("./plugins/baseUrls.js");
|
|
|
28
28
|
const envVars_js_1 = require("./plugins/envVars.js");
|
|
29
29
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
30
30
|
const fileEnv_js_1 = require("./plugins/fileEnv.js");
|
|
31
|
-
(
|
|
31
|
+
assertNodeEnv();
|
|
32
|
+
(0, utils_js_2.markEnvAsVikePluginLoaded)();
|
|
32
33
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
33
34
|
function plugin(vikeConfig) {
|
|
34
35
|
const plugins = [
|
|
@@ -70,3 +71,21 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
70
71
|
(0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
71
72
|
}
|
|
72
73
|
});
|
|
74
|
+
function assertNodeEnv() {
|
|
75
|
+
const nodeEnv = (0, utils_js_2.getNodeEnv)();
|
|
76
|
+
if (nodeEnv === 'test')
|
|
77
|
+
return;
|
|
78
|
+
// We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
|
|
79
|
+
(0, utils_js_2.assertUsage)(
|
|
80
|
+
/* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
|
|
81
|
+
isNodeEnvDev() || isVikeCliBuild(),
|
|
82
|
+
/*/
|
|
83
|
+
(0, utils_js_2.isNodeEnvDev)() || true,
|
|
84
|
+
///*/
|
|
85
|
+
[
|
|
86
|
+
picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
|
|
87
|
+
'(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
|
|
88
|
+
'while the vike/plugin module is loaded.',
|
|
89
|
+
utils_js_2.vikeVitePluginLoadedInProductionError
|
|
90
|
+
].join(' '));
|
|
91
|
+
}
|
|
@@ -10,7 +10,7 @@ const runPrerender_js_1 = require("../../prerender/runPrerender.js");
|
|
|
10
10
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
11
11
|
const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
const
|
|
13
|
+
const logErrorHint_js_1 = require("../../runtime/renderPage/logErrorHint.js");
|
|
14
14
|
let forceExit = false;
|
|
15
15
|
function autoFullBuild() {
|
|
16
16
|
let config;
|
|
@@ -88,7 +88,7 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
90
|
console.error(err);
|
|
91
|
-
(0,
|
|
91
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
92
92
|
process.exit(1);
|
|
93
93
|
}
|
|
94
94
|
if (configVike.prerender && !configVike.prerender.disableAutoRun) {
|
|
@@ -28,6 +28,7 @@ function buildConfig() {
|
|
|
28
28
|
configResolved: {
|
|
29
29
|
order: 'post',
|
|
30
30
|
async handler(config) {
|
|
31
|
+
assertNodeEnv();
|
|
31
32
|
assertRollupInput(config);
|
|
32
33
|
const entries = await getEntries(config);
|
|
33
34
|
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
@@ -36,6 +37,7 @@ function buildConfig() {
|
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
39
|
config(config) {
|
|
40
|
+
assertNodeEnv();
|
|
39
41
|
generateManifest = !(0, utils_js_1.viteIsSSR)(config);
|
|
40
42
|
return {
|
|
41
43
|
build: {
|
|
@@ -45,7 +47,11 @@ function buildConfig() {
|
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
},
|
|
50
|
+
buildStart() {
|
|
51
|
+
assertNodeEnv();
|
|
52
|
+
},
|
|
48
53
|
async writeBundle(options, bundle) {
|
|
54
|
+
assertNodeEnv();
|
|
49
55
|
const manifestEntry = bundle[manifestTempFile];
|
|
50
56
|
/* Fails with @vitejs/plugin-legacy because writeBundle() is called twice during the client build (once for normal client assets and a second time for legacy assets), see reproduction at https://github.com/vikejs/vike/issues/1154
|
|
51
57
|
assert(generateManifest === !!manifestEntry)
|
|
@@ -230,3 +236,6 @@ function assertRollupInput(config) {
|
|
|
230
236
|
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
231
237
|
}
|
|
232
238
|
exports.assertRollupInput = assertRollupInput;
|
|
239
|
+
function assertNodeEnv() {
|
|
240
|
+
(0, utils_js_1.assertNodeEnvIsNotDev)('building');
|
|
241
|
+
}
|
|
@@ -76,7 +76,7 @@ function workaroundCI(config) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
function assertEsm(userViteRoot) {
|
|
79
|
-
const packageJsonPath = (0, utils_js_1.
|
|
79
|
+
const packageJsonPath = (0, utils_js_1.findFile)('package.json', userViteRoot);
|
|
80
80
|
if (!packageJsonPath)
|
|
81
81
|
return;
|
|
82
82
|
const packageJson = require_(packageJsonPath);
|
|
@@ -54,7 +54,7 @@ async function getStemPackages(userAppRootDir) {
|
|
|
54
54
|
}
|
|
55
55
|
exports.getStemPackages = getStemPackages;
|
|
56
56
|
function findUserRootDir(userAppRootDir) {
|
|
57
|
-
const userPkgJsonPath = (0, utils_js_1.
|
|
57
|
+
const userPkgJsonPath = (0, utils_js_1.findFile)('package.json', userAppRootDir);
|
|
58
58
|
(0, utils_js_1.assertUsage)(userPkgJsonPath, `Couldn't find package.json in any parent directory starting from ${userAppRootDir}`);
|
|
59
59
|
return (0, utils_js_1.toPosixPath)(path_1.default.dirname(userPkgJsonPath));
|
|
60
60
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfigFileExport = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
|
+
const assertPlusFileExport_js_1 = require("../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
9
|
+
const utils_js_1 = require("../../../utils.js");
|
|
10
|
+
function getConfigFileExport(fileExports, filePathToShowToUser) {
|
|
11
|
+
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, 'config');
|
|
12
|
+
const fileExport = fileExports.default || fileExports.config;
|
|
13
|
+
(0, utils_js_1.assert)('default' in fileExports !== 'config' in fileExports);
|
|
14
|
+
const exportName = picocolors_1.default.cyan('default' in fileExports ? 'export default' : 'export { config }');
|
|
15
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(fileExport), `The ${exportName} of ${filePathToShowToUser} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportedValue === ${JSON.stringify(typeof fileExport)}`)} instead)`);
|
|
16
|
+
return fileExport;
|
|
17
|
+
}
|
|
18
|
+
exports.getConfigFileExport = getConfigFileExport;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -49,11 +49,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
49
49
|
p = (0, utils_js_1.toPosixPath)(p);
|
|
50
50
|
(0, utils_js_1.assert)(!p.startsWith(userRootDir));
|
|
51
51
|
const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
filePathRelativeToUserRootDir,
|
|
55
|
-
filePathAbsoluteFilesystem
|
|
56
|
-
};
|
|
52
|
+
return { filePathRelativeToUserRootDir };
|
|
57
53
|
});
|
|
58
54
|
return plusFiles;
|
|
59
55
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -3,34 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLogicalPath = exports.applyFilesystemRoutingRootEffect = exports.isGlobalLocation = exports.sortAfterInheritanceOrder = exports.getLocationId = exports.isInherited = exports.getFilesystemRouteDefinedBy = exports.getFilesystemRouteString = void 0;
|
|
4
4
|
const utils_js_1 = require("../../../../utils.js");
|
|
5
5
|
/**
|
|
6
|
-
* getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
|
|
7
|
-
* getLocationId('/
|
|
8
|
-
*
|
|
6
|
+
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
7
|
+
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
8
|
+
*
|
|
9
|
+
* 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/**`).
|
|
9
10
|
*/
|
|
10
|
-
function getLocationId(
|
|
11
|
-
|
|
11
|
+
function getLocationId(
|
|
12
|
+
// 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.
|
|
13
|
+
filePathRelativeToUserRootDir) {
|
|
14
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
15
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
16
|
+
const locationId = removeFilename(filePathRelativeToUserRootDir);
|
|
12
17
|
assertLocationId(locationId);
|
|
13
18
|
return locationId;
|
|
14
19
|
}
|
|
15
20
|
exports.getLocationId = getLocationId;
|
|
16
|
-
/**
|
|
21
|
+
/** Filesystem Routing: get the URL */
|
|
17
22
|
function getFilesystemRouteString(locationId) {
|
|
18
23
|
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
19
24
|
}
|
|
20
25
|
exports.getFilesystemRouteString = getFilesystemRouteString;
|
|
21
|
-
/**
|
|
22
|
-
function getInheritanceRoot(
|
|
23
|
-
return getLogicalPath(
|
|
26
|
+
/** Filesystem Inheritance: get the apply root */
|
|
27
|
+
function getInheritanceRoot(locationId) {
|
|
28
|
+
return getLogicalPath(locationId, ['renderer']);
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
27
|
-
* getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
|
|
28
32
|
*/
|
|
29
|
-
function getLogicalPath(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return someDir;
|
|
33
|
+
function getLogicalPath(locationId, removeDirs) {
|
|
34
|
+
let logicalPath = removeDirectories(locationId, removeDirs);
|
|
35
|
+
assertIsPath(logicalPath);
|
|
36
|
+
return logicalPath;
|
|
34
37
|
}
|
|
35
38
|
exports.getLogicalPath = getLogicalPath;
|
|
36
39
|
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
@@ -39,6 +42,10 @@ function isGlobalLocation(locationId, locationIds) {
|
|
|
39
42
|
}
|
|
40
43
|
exports.isGlobalLocation = isGlobalLocation;
|
|
41
44
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
45
|
+
assertLocationId(locationId1);
|
|
46
|
+
assertLocationId(locationId2);
|
|
47
|
+
if (locationId1 === locationId2)
|
|
48
|
+
return 0;
|
|
42
49
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
43
50
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
44
51
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
@@ -54,15 +61,10 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
54
61
|
(0, utils_js_1.assert)(inheritanceRoot1.length !== inheritanceRoot2.length);
|
|
55
62
|
return (0, utils_js_1.higherFirst)((inheritanceRoot) => inheritanceRoot.length)(inheritanceRoot1, inheritanceRoot2);
|
|
56
63
|
}
|
|
57
|
-
// Should be true since we aggregate interface files by locationId
|
|
58
|
-
(0, utils_js_1.assert)(locationId1 !== locationId2);
|
|
59
64
|
// locationId1 first, i.e. `indexOf(locationId1) < indexOf(locationId2)`
|
|
60
65
|
const locationId1First = -1;
|
|
61
66
|
// locationId2 first, i.e. `indexOf(locationId2) < indexOf(locationId1)`
|
|
62
67
|
const locationId2First = 1;
|
|
63
|
-
if (locationIsNpmPackage(locationId1) !== locationIsNpmPackage(locationId2)) {
|
|
64
|
-
return locationIsNpmPackage(locationId1) ? locationId2First : locationId1First;
|
|
65
|
-
}
|
|
66
68
|
if (locationIsRendererDir(locationId1) !== locationIsRendererDir(locationId2)) {
|
|
67
69
|
return locationIsRendererDir(locationId1) ? locationId2First : locationId1First;
|
|
68
70
|
}
|
|
@@ -74,9 +76,6 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
74
76
|
return locationId1 > locationId2 ? locationId1First : locationId2First;
|
|
75
77
|
}
|
|
76
78
|
exports.sortAfterInheritanceOrder = sortAfterInheritanceOrder;
|
|
77
|
-
function locationIsNpmPackage(locationId) {
|
|
78
|
-
return !locationId.startsWith('/');
|
|
79
|
-
}
|
|
80
79
|
function locationIsRendererDir(locationId) {
|
|
81
80
|
return locationId.split('/').includes('renderer');
|
|
82
81
|
}
|
|
@@ -87,19 +86,6 @@ function isInherited(locationId1, locationId2) {
|
|
|
87
86
|
return startsWith(inheritanceRoot2, inheritanceRoot1);
|
|
88
87
|
}
|
|
89
88
|
exports.isInherited = isInherited;
|
|
90
|
-
function removeNpmPackageName(somePath) {
|
|
91
|
-
if (!(0, utils_js_1.isNpmPackageImport)(somePath)) {
|
|
92
|
-
(0, utils_js_1.assert)(somePath.startsWith('/'));
|
|
93
|
-
return somePath;
|
|
94
|
-
}
|
|
95
|
-
const importPath = (0, utils_js_1.getNpmPackageImportPath)(somePath);
|
|
96
|
-
if (!importPath)
|
|
97
|
-
return '/';
|
|
98
|
-
(0, utils_js_1.assertPosixPath)(importPath);
|
|
99
|
-
(0, utils_js_1.assert)(!importPath.startsWith('/'));
|
|
100
|
-
somePath = '/' + importPath;
|
|
101
|
-
return somePath;
|
|
102
|
-
}
|
|
103
89
|
function removeDirectories(somePath, removeDirs) {
|
|
104
90
|
(0, utils_js_1.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
|
-
(0, utils_js_1.assert)(filePathAbsoluteVite.startsWith('/') || (0, utils_js_1.isNpmPackageImport)(filePathAbsoluteVite));
|
|
99
|
+
function removeFilename(filePathRelativeToUserRootDir) {
|
|
100
|
+
const filePathParts = filePathRelativeToUserRootDir.split('/');
|
|
116
101
|
{
|
|
117
|
-
const filename =
|
|
118
|
-
|
|
119
|
-
(0, utils_js_1.assert)(optional);
|
|
120
|
-
return filePathAbsoluteVite;
|
|
121
|
-
}
|
|
102
|
+
const filename = filePathParts.slice(-1)[0];
|
|
103
|
+
(0, utils_js_1.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);
|
|
@@ -144,7 +126,7 @@ function applyFilesystemRoutingRootEffect(routeFilesystem, filesystemRoutingRoot
|
|
|
144
126
|
}
|
|
145
127
|
exports.applyFilesystemRoutingRootEffect = applyFilesystemRoutingRootEffect;
|
|
146
128
|
function assertLocationId(locationId) {
|
|
147
|
-
(0, utils_js_1.assert)(locationId.startsWith('/')
|
|
129
|
+
(0, utils_js_1.assert)(locationId.startsWith('/'));
|
|
148
130
|
(0, utils_js_1.assert)(!locationId.endsWith('/') || locationId === '/');
|
|
149
131
|
}
|
|
150
132
|
function assertIsPath(logicalPath) {
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Files loadded at config time:
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.loadConfigFile = exports.loadValueFile = exports.loadImportedFile = void 0;
|
|
8
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
10
|
+
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
11
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
|
+
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
13
|
+
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
14
|
+
const resolveImportPath_js_1 = require("./resolveImportPath.js");
|
|
15
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
16
|
+
// Load fake import
|
|
17
|
+
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
18
|
+
const f = import_.filePathAbsoluteFilesystem;
|
|
19
|
+
if (!importedFilesLoaded[f]) {
|
|
20
|
+
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(import_, false, userRootDir).then((r) => r.fileExports);
|
|
21
|
+
}
|
|
22
|
+
const fileExports = await importedFilesLoaded[f];
|
|
23
|
+
const fileExport = fileExports[import_.fileExportName];
|
|
24
|
+
return fileExport;
|
|
25
|
+
}
|
|
26
|
+
exports.loadImportedFile = loadImportedFile;
|
|
27
|
+
// Load +{configName}.js
|
|
28
|
+
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
29
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, false, userRootDir);
|
|
30
|
+
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
31
|
+
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
32
|
+
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
33
|
+
const configName_ = exportName === 'default' ? configName : exportName;
|
|
34
|
+
interfaceValueFile.fileExportsByConfigName[configName_] = { configValue };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.loadValueFile = loadValueFile;
|
|
38
|
+
// Load +config.js, including all its extends fake imports
|
|
39
|
+
async function loadConfigFile(configFilePath, userRootDir, visited, isConfigOfExtension) {
|
|
40
|
+
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
41
|
+
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
42
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, !isConfigOfExtension, userRootDir, isConfigOfExtension);
|
|
43
|
+
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
44
|
+
...visited,
|
|
45
|
+
filePathAbsoluteFilesystem
|
|
46
|
+
]);
|
|
47
|
+
const configFile = {
|
|
48
|
+
fileExports,
|
|
49
|
+
filePath: configFilePath,
|
|
50
|
+
extendsFilePaths
|
|
51
|
+
};
|
|
52
|
+
return { configFile, extendsConfigs };
|
|
53
|
+
}
|
|
54
|
+
exports.loadConfigFile = loadConfigFile;
|
|
55
|
+
function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
56
|
+
const idx = visited.indexOf(filePathAbsoluteFilesystem);
|
|
57
|
+
if (idx === -1)
|
|
58
|
+
return;
|
|
59
|
+
const loop = visited.slice(idx);
|
|
60
|
+
(0, utils_js_1.assert)(loop[0] === filePathAbsoluteFilesystem);
|
|
61
|
+
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
62
|
+
}
|
|
63
|
+
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
64
|
+
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
65
|
+
const extendsConfigFiles = [];
|
|
66
|
+
extendsImportData.map((importData) => {
|
|
67
|
+
const { importPath: importPath } = importData;
|
|
68
|
+
const filePathAbsoluteFilesystem = (0, resolveImportPath_js_1.resolveImportPath)(importData, configFilePath);
|
|
69
|
+
(0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
70
|
+
warnUserLandExtension(importPath, configFilePath);
|
|
71
|
+
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
72
|
+
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
73
|
+
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
74
|
+
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
75
|
+
extendsConfigFiles.push({
|
|
76
|
+
filePathAbsoluteFilesystem,
|
|
77
|
+
filePathAbsoluteVite,
|
|
78
|
+
filePathRelativeToUserRootDir,
|
|
79
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
80
|
+
importPathAbsolute: importPath
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
const extendsConfigs = [];
|
|
84
|
+
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
85
|
+
const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
|
|
86
|
+
extendsConfigs.push(result.configFile);
|
|
87
|
+
extendsConfigs.push(...result.extendsConfigs);
|
|
88
|
+
}));
|
|
89
|
+
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
90
|
+
return { extendsConfigs, extendsFilePaths };
|
|
91
|
+
}
|
|
92
|
+
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
93
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
94
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
95
|
+
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
99
|
+
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
100
|
+
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
101
|
+
return filePathRelativeToUserRootDir;
|
|
102
|
+
}
|
|
103
|
+
function warnUserLandExtension(importPath, configFilePath) {
|
|
104
|
+
(0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.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 });
|
|
105
|
+
}
|
|
106
|
+
function getExtendsImportData(configFileExports, configFilePath) {
|
|
107
|
+
const { filePathToShowToUser } = configFilePath;
|
|
108
|
+
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
109
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
110
|
+
let extendList;
|
|
111
|
+
if (!('extends' in configFileExport)) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string')) {
|
|
115
|
+
extendList = [configFileExport.extends];
|
|
116
|
+
}
|
|
117
|
+
else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string[]')) {
|
|
118
|
+
extendList = configFileExport.extends;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
122
|
+
}
|
|
123
|
+
const extendsImportData = extendList.map((importDataSerialized) => {
|
|
124
|
+
const importData = (0, transformFileImports_js_1.parseImportData)(importDataSerialized);
|
|
125
|
+
(0, utils_js_1.assertUsage)(importData, wrongUsage);
|
|
126
|
+
return importData;
|
|
127
|
+
});
|
|
128
|
+
return extendsImportData;
|
|
129
|
+
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveFilePathAbsoluteFilesystem = exports.resolveFilePathRelativeToUserRootDir = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
|
|
10
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
11
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
12
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelativeToUserRootDir);
|
|
13
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
14
|
+
}
|
|
15
|
+
exports.resolveFilePathRelativeToUserRootDir = resolveFilePathRelativeToUserRootDir;
|
|
16
|
+
function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
|
|
17
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
18
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
19
|
+
let filePathRelativeToUserRootDir = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
20
|
+
(0, utils_js_1.assert)(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
|
|
21
|
+
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
22
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
23
|
+
}
|
|
24
|
+
exports.resolveFilePathAbsoluteFilesystem = resolveFilePathAbsoluteFilesystem;
|
|
25
|
+
function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
|
|
26
|
+
return {
|
|
27
|
+
filePathRelativeToUserRootDir,
|
|
28
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
29
|
+
filePathAbsoluteFilesystem,
|
|
30
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
31
|
+
importPathAbsolute: null
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.clearFilesEnvMap = exports.assertImportPath = exports.resolveImportPath = exports.resolveImport = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
9
|
+
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const filesEnvMap = new Map();
|
|
12
|
+
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
13
|
+
if (typeof configValue !== 'string')
|
|
14
|
+
return null;
|
|
15
|
+
const importData = (0, transformFileImports_js_1.parseImportData)(configValue);
|
|
16
|
+
if (!importData)
|
|
17
|
+
return null;
|
|
18
|
+
const { importPath, exportName } = importData;
|
|
19
|
+
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
20
|
+
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
21
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
22
|
+
if (importPath.startsWith('.')) {
|
|
23
|
+
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
24
|
+
// ```
|
|
25
|
+
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
26
|
+
// ```
|
|
27
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
28
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
29
|
+
const filePath = {
|
|
30
|
+
filePathAbsoluteFilesystem,
|
|
31
|
+
filePathRelativeToUserRootDir,
|
|
32
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
33
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
34
|
+
importPathAbsolute: null
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
...filePath,
|
|
38
|
+
fileExportName: exportName,
|
|
39
|
+
fileExportPathToShowToUser
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// importPath can be:
|
|
44
|
+
// - an npm package import
|
|
45
|
+
// - a path alias
|
|
46
|
+
const filePath = {
|
|
47
|
+
filePathAbsoluteFilesystem,
|
|
48
|
+
filePathRelativeToUserRootDir: null,
|
|
49
|
+
filePathAbsoluteVite: importPath,
|
|
50
|
+
filePathToShowToUser: importPath,
|
|
51
|
+
importPathAbsolute: importPath
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
...filePath,
|
|
55
|
+
fileExportName: exportName,
|
|
56
|
+
fileExportPathToShowToUser
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.resolveImport = resolveImport;
|
|
61
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
62
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
63
|
+
let filePathRelativeToUserRootDir;
|
|
64
|
+
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
65
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
(0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.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`);
|
|
69
|
+
// None of the following works. Seems to be a Vite bug?
|
|
70
|
+
// /*
|
|
71
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
72
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
73
|
+
// /*/
|
|
74
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
75
|
+
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
76
|
+
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
77
|
+
// //*/
|
|
78
|
+
}
|
|
79
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
80
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
81
|
+
return filePathRelativeToUserRootDir;
|
|
82
|
+
}
|
|
83
|
+
function resolveImportPath(importData, importerFilePath) {
|
|
84
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
85
|
+
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
86
|
+
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
87
|
+
// 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
|
|
88
|
+
// filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
|
|
89
|
+
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
|
|
90
|
+
return filePathAbsoluteFilesystem;
|
|
91
|
+
}
|
|
92
|
+
exports.resolveImportPath = resolveImportPath;
|
|
93
|
+
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
94
|
+
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
95
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
96
|
+
if (!filePathAbsoluteFilesystem) {
|
|
97
|
+
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
98
|
+
const errIntro = importStringWasGenerated
|
|
99
|
+
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
100
|
+
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
101
|
+
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
102
|
+
if (importPath.startsWith('.')) {
|
|
103
|
+
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
(0, utils_js_1.assertUsage)(false, `${errIntro2} exist?`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.assertImportPath = assertImportPath;
|
|
111
|
+
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
112
|
+
(0, utils_js_1.assertPosixPath)(filePathForEnvCheck);
|
|
113
|
+
if (!filesEnvMap.has(filePathForEnvCheck)) {
|
|
114
|
+
filesEnvMap.set(filePathForEnvCheck, []);
|
|
115
|
+
}
|
|
116
|
+
const fileEnv = filesEnvMap.get(filePathForEnvCheck);
|
|
117
|
+
fileEnv.push({ configEnv, configName });
|
|
118
|
+
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnv, configEnv))[0];
|
|
119
|
+
if (configDifferentEnv) {
|
|
120
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
121
|
+
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
122
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(JSON.stringify(c.configEnv))}`),
|
|
123
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
|
|
124
|
+
].join('\n'));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function clearFilesEnvMap() {
|
|
128
|
+
filesEnvMap.clear();
|
|
129
|
+
}
|
|
130
|
+
exports.clearFilesEnvMap = clearFilesEnvMap;
|
|
131
|
+
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
132
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
133
|
+
(0, utils_js_1.assertPosixPath)(root);
|
|
134
|
+
(0, utils_js_1.assert)(filePathAbsoluteFilesystem.startsWith(root));
|
|
135
|
+
let vitePath = path_1.default.posix.relative(root, filePathAbsoluteFilesystem);
|
|
136
|
+
(0, utils_js_1.assert)(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
137
|
+
vitePath = '/' + vitePath;
|
|
138
|
+
return vitePath;
|
|
139
|
+
}
|