vike 0.4.220-commit-5c7810f → 0.4.220-commit-af5c91f
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/api/utils.js +1 -1
- package/dist/cjs/node/plugin/index.js +1 -1
- package/dist/cjs/node/plugin/onLoad.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +5 -3
- package/dist/cjs/node/plugin/plugins/buildConfig.js +7 -5
- package/dist/cjs/node/plugin/plugins/buildEntry/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +3 -2
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +32 -41
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +9 -64
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +281 -313
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -6
- package/dist/cjs/node/plugin/plugins/packageJsonFile.js +2 -2
- package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -3
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +2 -1
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/{getOutDirs.js → shared/getOutDirs.js} +24 -27
- package/dist/cjs/node/plugin/{resolveClientEntriesDev.js → shared/resolveClientEntriesDev.js} +5 -8
- package/dist/cjs/{utils → node/plugin/shared}/viteIsSSR.js +2 -2
- package/dist/cjs/node/plugin/utils.js +0 -1
- package/dist/cjs/node/prerender/context.js +8 -3
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +26 -5
- package/dist/cjs/node/prerender/runPrerender.js +6 -11
- package/dist/cjs/node/prerender/utils.js +1 -2
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +9 -4
- package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +2 -27
- package/dist/cjs/node/runtime/renderPage/isFontFallback.js +29 -0
- package/dist/cjs/node/runtime/utils.js +1 -3
- package/dist/cjs/shared/getPageFiles/fileTypes.js +0 -1
- package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +0 -3
- package/dist/cjs/shared/getPageFiles/getPageFileObject.js +0 -5
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +69 -18
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/findFile.js +3 -3
- package/dist/cjs/utils/isDev.js +2 -5
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
- package/dist/cjs/utils/path.js +48 -0
- package/dist/cjs/utils/requireResolve.js +3 -3
- package/dist/esm/node/api/utils.d.ts +1 -1
- package/dist/esm/node/api/utils.js +1 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +3 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -1
- package/dist/esm/node/plugin/plugins/buildEntry/index.js +2 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -3
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +2 -1
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +9 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +14 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +35 -44
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +8 -18
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +10 -65
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +6 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +12 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +284 -316
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -6
- package/dist/esm/node/plugin/plugins/packageJsonFile.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +2 -1
- package/dist/esm/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/esm/node/plugin/{getOutDirs.js → shared/getOutDirs.js} +2 -5
- package/dist/esm/node/plugin/{resolveClientEntriesDev.js → shared/resolveClientEntriesDev.js} +5 -8
- package/dist/esm/{utils → node/plugin/shared}/viteIsSSR.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +0 -1
- package/dist/esm/node/prerender/context.d.ts +2 -0
- package/dist/esm/node/prerender/context.js +8 -3
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +8 -1
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +26 -5
- package/dist/esm/node/prerender/runPrerender.js +7 -12
- package/dist/esm/node/prerender/utils.d.ts +1 -2
- package/dist/esm/node/prerender/utils.js +1 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +9 -4
- package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -26
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/isFontFallback.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/isFontFallback.js +27 -0
- package/dist/esm/node/runtime/utils.d.ts +1 -3
- package/dist/esm/node/runtime/utils.js +1 -3
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -2
- package/dist/esm/shared/getPageFiles/getAllPageIdFiles.js +0 -3
- package/dist/esm/shared/getPageFiles/getPageFileObject.js +0 -5
- package/dist/esm/shared/page-configs/PageConfig.d.ts +0 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +7 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +70 -19
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/isDev.js +3 -6
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/path.d.ts +14 -0
- package/dist/esm/utils/path.js +46 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/addImportStatement.js +0 -29
- package/dist/cjs/shared/assertPageFilePath.js +0 -11
- package/dist/cjs/utils/path-shim.js +0 -19
- package/dist/cjs/utils/toPosixPath.js +0 -18
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +0 -14
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.js +0 -27
- package/dist/esm/shared/assertPageFilePath.d.ts +0 -2
- package/dist/esm/shared/assertPageFilePath.js +0 -9
- package/dist/esm/utils/path-shim.d.ts +0 -2
- package/dist/esm/utils/path-shim.js +0 -17
- package/dist/esm/utils/toPosixPath.d.ts +0 -4
- package/dist/esm/utils/toPosixPath.js +0 -16
- /package/dist/esm/node/plugin/{getOutDirs.d.ts → shared/getOutDirs.d.ts} +0 -0
- /package/dist/esm/node/plugin/{resolveClientEntriesDev.d.ts → shared/resolveClientEntriesDev.d.ts} +0 -0
- /package/dist/esm/{utils → node/plugin/shared}/viteIsSSR.d.ts +0 -0
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -1,48 +1,45 @@
|
|
|
1
1
|
// Files loaded at config time:
|
|
2
|
-
export {
|
|
2
|
+
export { loadPointerImport };
|
|
3
3
|
export { loadValueFile };
|
|
4
|
-
export { loadValueFiles };
|
|
5
4
|
export { loadConfigFile };
|
|
6
|
-
import { assert, assertUsage, assertIsNotProductionRuntime, isArrayOfStrings, isObject
|
|
5
|
+
import { assert, assertUsage, assertIsNotProductionRuntime, isArrayOfStrings, isObject } from '../../../../utils.js';
|
|
7
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
8
|
-
import { getConfigDefinitionOptional
|
|
7
|
+
import { getConfigDefinitionOptional } from '../getVikeConfig.js';
|
|
9
8
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
10
9
|
import pc from '@brillout/picocolors';
|
|
11
10
|
import { parsePointerImportData } from './transformPointerImports.js';
|
|
12
11
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
13
|
-
import {
|
|
12
|
+
import { resolvePointerImportData } from './resolvePointerImport.js';
|
|
13
|
+
import { getConfigDefinedAt } from '../../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
14
14
|
assertIsNotProductionRuntime();
|
|
15
15
|
// Load pointer import
|
|
16
|
-
async function
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
async function loadPointerImport(pointerImport, userRootDir, configName, configDefinitions, esbuildCache) {
|
|
17
|
+
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
18
|
+
if (configName === 'extends')
|
|
19
|
+
return;
|
|
20
|
+
const configDef = getConfigDefinitionOptional(configDefinitions, configName);
|
|
21
|
+
// Only load pointer import if `env.config===true`
|
|
22
|
+
if (!configDef || !shouldBeLoadableAtBuildTime(configDef))
|
|
23
|
+
return;
|
|
24
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, pointerImport.fileExportPath);
|
|
25
|
+
assertUsage(pointerImport.fileExportPath.filePathAbsoluteFilesystem, `${configDefinedAt} cannot be defined over an aliased import`);
|
|
26
|
+
const { fileExports } = await transpileAndExecuteFile(pointerImport.fileExportPath, userRootDir, false, esbuildCache);
|
|
27
|
+
const fileExportValue = fileExports[pointerImport.fileExportPath.fileExportName];
|
|
28
|
+
pointerImport.fileExportValueLoaded = true;
|
|
29
|
+
assert(pointerImport.fileExportValueLoaded);
|
|
30
|
+
pointerImport.fileExportValue = fileExportValue;
|
|
24
31
|
}
|
|
25
32
|
// Load +{configName}.js
|
|
26
|
-
async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir) {
|
|
33
|
+
async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir, esbuildCache) {
|
|
27
34
|
const { configName } = interfaceValueFile;
|
|
28
35
|
const configDef = getConfigDefinitionOptional(configDefinitions, configName);
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
// Only load value files with `env.config===true`
|
|
37
|
+
if (!configDef || !shouldBeLoadableAtBuildTime(configDef))
|
|
31
38
|
return;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
await interfaceValueFile.isValueLoaded;
|
|
35
|
-
if (
|
|
36
|
-
// Help TS
|
|
37
|
-
true)
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const { promise, resolve } = genPromise();
|
|
41
|
-
interfaceValueFile.isValueLoaded = promise;
|
|
42
|
-
assert(interfaceValueFile.isValueLoaded);
|
|
39
|
+
interfaceValueFile.isValueFileLoaded = true;
|
|
40
|
+
assert(interfaceValueFile.isValueFileLoaded);
|
|
43
41
|
interfaceValueFile.fileExportsByConfigName = {};
|
|
44
|
-
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, userRootDir, false);
|
|
45
|
-
resolve();
|
|
42
|
+
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, userRootDir, false, esbuildCache);
|
|
46
43
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
47
44
|
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
48
45
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
@@ -50,21 +47,12 @@ async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir)
|
|
|
50
47
|
interfaceValueFile.fileExportsByConfigName[configName_] = configValue;
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
|
-
async function loadValueFiles(interfaceFiles, configDefinitions, userRootDir) {
|
|
54
|
-
await Promise.all(Object.values(interfaceFiles)
|
|
55
|
-
.flat(1)
|
|
56
|
-
.filter((interfaceFile) => interfaceFile.isValueFile)
|
|
57
|
-
.map(async (interfaceFile) => await loadValueFile(interfaceFile, configDefinitions, userRootDir)));
|
|
58
|
-
}
|
|
59
50
|
// Load +config.js, including all its extends pointer imports
|
|
60
|
-
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
51
|
+
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig, esbuildCache) {
|
|
61
52
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
62
53
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
63
|
-
const { fileExports } = await transpileAndExecuteFile(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true);
|
|
64
|
-
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
65
|
-
...visited,
|
|
66
|
-
filePathAbsoluteFilesystem
|
|
67
|
-
]);
|
|
54
|
+
const { fileExports } = await transpileAndExecuteFile(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true, esbuildCache);
|
|
55
|
+
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [...visited, filePathAbsoluteFilesystem], esbuildCache);
|
|
68
56
|
const configFile = {
|
|
69
57
|
fileExports,
|
|
70
58
|
filePath: configFilePath,
|
|
@@ -80,15 +68,15 @@ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
|
80
68
|
assert(loop[0] === filePathAbsoluteFilesystem);
|
|
81
69
|
assertUsage(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
82
70
|
}
|
|
83
|
-
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
71
|
+
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited, esbuildCache) {
|
|
84
72
|
const { extendsPointerImportData, extendsConfigs } = getExtendsPointerImportData(configFileExports, configFilePath);
|
|
85
73
|
const extendsConfigFiles = [];
|
|
86
74
|
extendsPointerImportData.map((pointerImportData) => {
|
|
87
|
-
const filePath =
|
|
75
|
+
const filePath = resolvePointerImportData(pointerImportData, configFilePath, userRootDir);
|
|
88
76
|
assert(filePath.filePathAbsoluteFilesystem);
|
|
89
77
|
extendsConfigFiles.push(filePath);
|
|
90
78
|
});
|
|
91
|
-
const results = await Promise.all(extendsConfigFiles.map(async (configFilePath) => await loadConfigFile(configFilePath, userRootDir, visited, true)));
|
|
79
|
+
const results = await Promise.all(extendsConfigFiles.map(async (configFilePath) => await loadConfigFile(configFilePath, userRootDir, visited, true, esbuildCache)));
|
|
92
80
|
results.forEach((result) => {
|
|
93
81
|
extendsConfigs.push(result.configFile);
|
|
94
82
|
extendsConfigs.push(...result.extendsConfigs);
|
|
@@ -131,3 +119,6 @@ function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
|
131
119
|
}
|
|
132
120
|
return { extendsPointerImportData, extendsConfigs };
|
|
133
121
|
}
|
|
122
|
+
function shouldBeLoadableAtBuildTime(configDef) {
|
|
123
|
+
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
124
|
+
}
|
|
@@ -1,22 +1,12 @@
|
|
|
1
|
-
export { resolvePointerImportOfConfig };
|
|
2
1
|
export { resolvePointerImport };
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
import type {
|
|
2
|
+
export { resolvePointerImportData };
|
|
3
|
+
export type { PointerImport };
|
|
4
|
+
import type { DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
6
5
|
import { type PointerImportData } from './transformPointerImports.js';
|
|
7
6
|
import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
declare function resolvePointerImportOfConfig(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | {
|
|
12
|
-
pointerImport: PointerImportResolved;
|
|
13
|
-
configEnvResolved: ConfigEnvInternal;
|
|
14
|
-
};
|
|
15
|
-
declare function resolvePointerImport(pointerImportData: PointerImportData, importerFilePath: FilePathResolved, userRootDir: string): FilePath;
|
|
16
|
-
declare function clearFilesEnvMap(): void;
|
|
17
|
-
declare function resolveConfigEnvWithFileName(configEnv: ConfigEnvInternal, filePath: FilePathResolved): {
|
|
18
|
-
server?: boolean | undefined;
|
|
19
|
-
config?: boolean | undefined;
|
|
20
|
-
client?: boolean | "if-client-routing";
|
|
21
|
-
production?: boolean;
|
|
7
|
+
type PointerImport = {
|
|
8
|
+
fileExportPath: FileExportPath;
|
|
22
9
|
};
|
|
10
|
+
type FileExportPath = DefinedAtFilePath & Required<Pick<DefinedAtFilePath, 'fileExportName'>>;
|
|
11
|
+
declare function resolvePointerImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configName: string): null | PointerImport;
|
|
12
|
+
declare function resolvePointerImportData(pointerImportData: PointerImportData, importerFilePath: FilePathResolved, userRootDir: string): FilePath;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
export { resolvePointerImportOfConfig };
|
|
2
1
|
export { resolvePointerImport };
|
|
3
|
-
export {
|
|
4
|
-
export { resolveConfigEnvWithFileName };
|
|
2
|
+
export { resolvePointerImportData };
|
|
5
3
|
import pc from '@brillout/picocolors';
|
|
6
|
-
import { assert, assertPosixPath, assertUsage,
|
|
4
|
+
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute, pathIsRelative, requireResolve } from '../../../../utils.js';
|
|
7
5
|
import { parsePointerImportData } from './transformPointerImports.js';
|
|
8
6
|
import path from 'path';
|
|
9
7
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
10
|
-
|
|
11
|
-
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
8
|
+
function resolvePointerImport(configValue, importerFilePath, userRootDir, configName) {
|
|
12
9
|
if (typeof configValue !== 'string')
|
|
13
10
|
return null;
|
|
14
11
|
const pointerImportData = parsePointerImportData(configValue);
|
|
15
12
|
if (!pointerImportData)
|
|
16
13
|
return null;
|
|
17
|
-
const {
|
|
18
|
-
const filePath =
|
|
14
|
+
const { exportName } = pointerImportData;
|
|
15
|
+
const filePath = resolvePointerImportData(pointerImportData, importerFilePath, userRootDir);
|
|
19
16
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
20
|
-
|
|
21
|
-
if (filePath.filePathAbsoluteFilesystem)
|
|
22
|
-
configEnvResolved = resolveConfigEnvWithFileName(configEnv, filePath);
|
|
23
|
-
assertUsageFileEnv(filePath, importPath, configEnvResolved, configName);
|
|
24
|
-
const pointerImport = {
|
|
17
|
+
const fileExportPath = {
|
|
25
18
|
...filePath,
|
|
26
19
|
fileExportName: exportName,
|
|
27
20
|
fileExportPathToShowToUser
|
|
28
21
|
};
|
|
29
|
-
return {
|
|
22
|
+
return { fileExportPath };
|
|
30
23
|
}
|
|
31
|
-
function
|
|
24
|
+
function resolvePointerImportData(pointerImportData, importerFilePath, userRootDir) {
|
|
32
25
|
// `importPath` should be one of the following:
|
|
33
26
|
// - A relative import path
|
|
34
27
|
// - A filesystem absolute path
|
|
@@ -39,7 +32,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
39
32
|
assertPosixPath(importPath);
|
|
40
33
|
if (importPath.startsWith('.') || isFilePathAbsolute(importPath)) {
|
|
41
34
|
if (importPath.startsWith('.')) {
|
|
42
|
-
assertUsage(
|
|
35
|
+
assertUsage(pathIsRelative(importPath), `Invalid relative import path ${pc.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
43
36
|
}
|
|
44
37
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
45
38
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
@@ -95,7 +88,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
95
88
|
: `The import ${pc.code(importString)} defined by ${filePathToShowToUser}`;
|
|
96
89
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
97
90
|
if (importPath.startsWith('.')) {
|
|
98
|
-
assert(
|
|
91
|
+
assert(pathIsRelative(importPath));
|
|
99
92
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
100
93
|
}
|
|
101
94
|
else {
|
|
@@ -103,51 +96,3 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
103
96
|
}
|
|
104
97
|
}
|
|
105
98
|
}
|
|
106
|
-
function assertUsageFileEnv(filePath, importPath, configEnvResolved, configName) {
|
|
107
|
-
let key;
|
|
108
|
-
if (filePath.filePathAbsoluteFilesystem) {
|
|
109
|
-
key = filePath.filePathAbsoluteFilesystem;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// Path alias
|
|
113
|
-
assert(!isRelativeImportPath(importPath));
|
|
114
|
-
key = importPath;
|
|
115
|
-
}
|
|
116
|
-
assertPosixPath(key);
|
|
117
|
-
if (!filesEnvMap.has(key)) {
|
|
118
|
-
filesEnvMap.set(key, []);
|
|
119
|
-
}
|
|
120
|
-
const fileEnv = filesEnvMap.get(key);
|
|
121
|
-
fileEnv.push({ configEnvResolved, configName });
|
|
122
|
-
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnvResolved, configEnvResolved))[0];
|
|
123
|
-
if (configDifferentEnv) {
|
|
124
|
-
assertUsage(false, [
|
|
125
|
-
`${key} defines the value of configs living in different environments:`,
|
|
126
|
-
...[configDifferentEnv, { configName, configEnvResolved }].map((c) => ` - config ${pc.code(c.configName)} which value lives in environment ${pc.code(JSON.stringify(c.configEnvResolved))}`),
|
|
127
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
128
|
-
].join('\n'));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function clearFilesEnvMap() {
|
|
132
|
-
filesEnvMap.clear();
|
|
133
|
-
}
|
|
134
|
-
function resolveConfigEnvWithFileName(configEnv, filePath) {
|
|
135
|
-
const { fileName } = filePath;
|
|
136
|
-
const configEnvResolved = { ...configEnv };
|
|
137
|
-
if (fileName.includes('.server.')) {
|
|
138
|
-
configEnvResolved.server = true;
|
|
139
|
-
configEnvResolved.client = false;
|
|
140
|
-
}
|
|
141
|
-
else if (fileName.includes('.client.')) {
|
|
142
|
-
configEnvResolved.client = true;
|
|
143
|
-
configEnvResolved.server = false;
|
|
144
|
-
}
|
|
145
|
-
else if (fileName.includes('.shared.')) {
|
|
146
|
-
configEnvResolved.server = true;
|
|
147
|
-
configEnvResolved.client = true;
|
|
148
|
-
}
|
|
149
|
-
return configEnvResolved;
|
|
150
|
-
}
|
|
151
|
-
function isRelativeImportPath(importPath) {
|
|
152
|
-
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
153
|
-
}
|
|
@@ -2,11 +2,15 @@ export { transpileAndExecuteFile };
|
|
|
2
2
|
export { getConfigBuildErrorFormatted };
|
|
3
3
|
export { getConfigExecutionErrorIntroMsg };
|
|
4
4
|
export { isTemporaryBuildFile };
|
|
5
|
+
export type { EsbuildCache };
|
|
5
6
|
import 'source-map-support/register.js';
|
|
6
7
|
import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
|
-
|
|
8
|
+
type FileExports = {
|
|
8
9
|
fileExports: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
+
};
|
|
11
|
+
type EsbuildCache = Record<string, // filePathAbsoluteFilesystem
|
|
12
|
+
Promise<FileExports>>;
|
|
13
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isConfigFile: boolean | 'is-extension-config', esbuildCache: EsbuildCache): Promise<FileExports>;
|
|
10
14
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
11
15
|
declare function getConfigExecutionErrorIntroMsg(err: unknown): string | null;
|
|
12
16
|
declare function isTemporaryBuildFile(filePath: string): boolean;
|
|
@@ -7,7 +7,7 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport } from '../../../../utils.js';
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport, genPromise } from '../../../../utils.js';
|
|
11
11
|
import { transformPointerImports } from './transformPointerImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
@@ -21,25 +21,31 @@ const debug = createDebugger('vike:pointer-imports');
|
|
|
21
21
|
const debugEsbuildResolve = createDebugger('vike:esbuild-resolve');
|
|
22
22
|
if (debugEsbuildResolve.isActivated)
|
|
23
23
|
debugEsbuildResolve('esbuild version', version);
|
|
24
|
-
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
24
|
+
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile, esbuildCache) {
|
|
25
25
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
26
26
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
27
|
+
if (esbuildCache[filePathAbsoluteFilesystem]) {
|
|
28
|
+
return await esbuildCache[filePathAbsoluteFilesystem];
|
|
29
|
+
}
|
|
30
|
+
const { promise, resolve } = genPromise();
|
|
31
|
+
esbuildCache[filePathAbsoluteFilesystem] = promise;
|
|
27
32
|
assertUsage(isPlainJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
28
33
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
29
34
|
if (isHeader) {
|
|
30
35
|
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${pc.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
31
36
|
}
|
|
37
|
+
let fileExports;
|
|
32
38
|
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
33
39
|
// This doesn't track dependencies => we should never use this for user land configs
|
|
34
|
-
|
|
35
|
-
return { fileExports };
|
|
40
|
+
fileExports = await executeFile(filePathAbsoluteFilesystem, filePath);
|
|
36
41
|
}
|
|
37
42
|
else {
|
|
38
43
|
const transformImports = isConfigFile && (isHeader ? 'all' : true);
|
|
39
44
|
const code = await transpileFile(filePath, transformImports, userRootDir);
|
|
40
|
-
|
|
41
|
-
return { fileExports };
|
|
45
|
+
fileExports = await executeTranspiledFile(filePath, code);
|
|
42
46
|
}
|
|
47
|
+
resolve({ fileExports });
|
|
48
|
+
return { fileExports };
|
|
43
49
|
}
|
|
44
50
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
45
51
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
@@ -6,7 +6,6 @@ export { isVikeConfigFile };
|
|
|
6
6
|
export { isV1Design };
|
|
7
7
|
export { getConfVal };
|
|
8
8
|
export { getConfigDefinitionOptional };
|
|
9
|
-
export { shouldBeLoadableAtBuildTime };
|
|
10
9
|
export type { VikeConfigObject };
|
|
11
10
|
export type { InterfaceValueFile };
|
|
12
11
|
export type { InterfaceFile };
|
|
@@ -15,6 +14,7 @@ import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../..
|
|
|
15
14
|
import { type ConfigDefinitions, type ConfigDefinitionInternal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
16
15
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
17
16
|
import type { ResolvedConfig } from 'vite';
|
|
17
|
+
import { type PointerImportLoaded } from './getVikeConfig/loadFileAtConfigTime.js';
|
|
18
18
|
import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
|
|
19
19
|
import { getPageConfigUserFriendlyNew } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
20
20
|
type InterfaceFile = InterfaceConfigFile | InterfaceValueFile;
|
|
@@ -26,21 +26,24 @@ type InterfaceConfigFile = InterfaceFileCommons & {
|
|
|
26
26
|
isConfigFile: true;
|
|
27
27
|
isValueFile: false;
|
|
28
28
|
extendsFilePaths: string[];
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
isConfigExtension: boolean;
|
|
30
|
+
isValueFileLoaded: true;
|
|
31
31
|
fileExportsByConfigName: Record<string, // configName
|
|
32
32
|
unknown>;
|
|
33
|
+
pointerImportsByConfigName: Record<string, // configValue
|
|
34
|
+
PointerImportLoaded>;
|
|
33
35
|
};
|
|
34
36
|
type InterfaceValueFile = InterfaceFileCommons & {
|
|
35
37
|
isConfigFile: false;
|
|
36
38
|
isValueFile: true;
|
|
39
|
+
isConfigExtension?: undefined;
|
|
37
40
|
configName: string;
|
|
38
41
|
} & ({
|
|
39
|
-
|
|
42
|
+
isValueFileLoaded: true;
|
|
40
43
|
fileExportsByConfigName: Record<string, // configName
|
|
41
44
|
unknown>;
|
|
42
45
|
} | {
|
|
43
|
-
|
|
46
|
+
isValueFileLoaded: false;
|
|
44
47
|
});
|
|
45
48
|
type InterfaceFilesByLocationId = Record<LocationId, InterfaceFile[]>;
|
|
46
49
|
type VikeConfigObject = {
|
|
@@ -57,7 +60,6 @@ declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePlu
|
|
|
57
60
|
declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
|
|
58
61
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
59
62
|
declare function getConfigDefinitionOptional(configDefinitions: ConfigDefinitions, configName: string): ConfigDefinitionInternal | null;
|
|
60
|
-
declare function shouldBeLoadableAtBuildTime(configDef: ConfigDefinitionInternal): boolean;
|
|
61
63
|
declare function getConfVal(interfaceFile: InterfaceFile, configName: string): null | {
|
|
62
64
|
configValue: unknown;
|
|
63
65
|
configValueLoaded: true;
|