vike 0.4.172 → 0.4.174
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 +3 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -8
- package/dist/cjs/node/plugin/plugins/config/index.js +9 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +135 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +22 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +19 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +22 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/cjs/node/plugin/plugins/previewConfig.js +2 -2
- package/dist/cjs/node/plugin/resolveClientEntriesDev.js +59 -0
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +7 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerVite.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -1
- package/dist/cjs/node/runtime/onLoad.js +4 -0
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +4 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +9 -59
- package/dist/cjs/node/runtime/renderPage.js +7 -4
- package/dist/cjs/node/{plugin/shared → shared}/isErrorDebug.js +1 -1
- package/dist/cjs/node/shared/utils.js +1 -0
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/cjs/utils/assert.js +9 -3
- package/dist/cjs/utils/findFile.js +5 -3
- package/dist/cjs/utils/findPackageJson.js +19 -0
- package/dist/cjs/utils/joinEnglish.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +2 -2
- package/dist/esm/node/plugin/index.js +3 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +5 -9
- package/dist/esm/node/plugin/plugins/config/index.js +9 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +129 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +23 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +20 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -41
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
- package/dist/esm/node/plugin/resolveClientEntriesDev.d.ts +4 -0
- package/dist/esm/node/plugin/resolveClientEntriesDev.js +56 -0
- package/dist/esm/node/plugin/shared/addSsrMiddleware.d.ts +2 -2
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +7 -1
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/plugin/shared/loggerVite.js +1 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -1
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -1
- package/dist/esm/node/runtime/onLoad.js +4 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +4 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +9 -59
- package/dist/esm/node/runtime/renderPage.js +7 -4
- package/dist/esm/node/{plugin/shared → shared}/isErrorDebug.js +1 -1
- package/dist/esm/node/shared/utils.d.ts +1 -0
- package/dist/esm/node/shared/utils.js +1 -0
- package/dist/esm/shared/ConfigVike.d.ts +7 -0
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +5 -2
- package/dist/esm/shared/page-configs/Config.d.ts +13 -1
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/assert.d.ts +2 -0
- package/dist/esm/utils/assert.js +8 -2
- package/dist/esm/utils/findFile.js +5 -3
- package/dist/esm/utils/findPackageJson.d.ts +5 -0
- package/dist/esm/utils/findPackageJson.js +16 -0
- package/dist/esm/utils/joinEnglish.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +5 -4
- /package/dist/esm/node/{plugin/shared → shared}/isErrorDebug.d.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { configDefinitionsBuiltIn };
|
|
2
2
|
export { configDefinitionsBuiltInGlobal };
|
|
3
|
-
import { assert } from '../../../../utils.js';
|
|
3
|
+
import { assert, assertUsage } from '../../../../utils.js';
|
|
4
|
+
import { getConfigDefinedAt } from '../../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
4
5
|
const configDefinitionsBuiltIn = {
|
|
5
6
|
onRenderHtml: {
|
|
6
7
|
env: { server: true }
|
|
@@ -54,6 +55,9 @@ const configDefinitionsBuiltIn = {
|
|
|
54
55
|
// We could make it { client: false } but we don't yet because of some legacy V0.4 design code
|
|
55
56
|
env: { server: true, client: true, config: true, eager: true }
|
|
56
57
|
},
|
|
58
|
+
clientHooks: {
|
|
59
|
+
env: { config: true }
|
|
60
|
+
},
|
|
57
61
|
prerender: {
|
|
58
62
|
env: { config: true }
|
|
59
63
|
},
|
|
@@ -69,11 +73,22 @@ const configDefinitionsBuiltIn = {
|
|
|
69
73
|
meta: {
|
|
70
74
|
env: { config: true }
|
|
71
75
|
},
|
|
72
|
-
|
|
76
|
+
clientEntryLoaded: {
|
|
73
77
|
env: { server: true, client: true, eager: true },
|
|
74
|
-
_computed: (configValueSources) =>
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
_computed: (configValueSources) => {
|
|
79
|
+
{
|
|
80
|
+
const source = getConfigValueSource(configValueSources, 'clientHooks');
|
|
81
|
+
if (source && source.value !== null) {
|
|
82
|
+
const { value } = source;
|
|
83
|
+
const definedAt = getConfigDefinedAt('Config', 'clientHooks', source.definedAtFilePath);
|
|
84
|
+
assertUsage(typeof value === 'boolean', `${definedAt} should be a boolean`);
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return (isConfigSet(configValueSources, 'onRenderClient') &&
|
|
89
|
+
isConfigSet(configValueSources, 'Page') &&
|
|
90
|
+
!!getConfigEnv(configValueSources, 'Page')?.client);
|
|
91
|
+
}
|
|
77
92
|
},
|
|
78
93
|
onBeforeRenderEnv: {
|
|
79
94
|
env: { client: true },
|
|
@@ -91,6 +106,9 @@ const configDefinitionsBuiltIn = {
|
|
|
91
106
|
},
|
|
92
107
|
name: {
|
|
93
108
|
env: { config: true }
|
|
109
|
+
},
|
|
110
|
+
require: {
|
|
111
|
+
env: { config: true }
|
|
94
112
|
}
|
|
95
113
|
};
|
|
96
114
|
const configDefinitionsBuiltInGlobal = {
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean): Promise<{
|
|
2
|
+
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean, crawlWithGit: null | boolean): Promise<{
|
|
3
3
|
filePathAbsoluteUserRootDir: string;
|
|
4
4
|
}[]>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
import { assertPosixPath, assert,
|
|
2
|
+
import { assertPosixPath, assert, assertWarning, scriptFileExtensionList, scriptFileExtensions, humanizeTime, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import glob from 'fast-glob';
|
|
5
5
|
import { exec } from 'child_process';
|
|
@@ -10,7 +10,7 @@ const execA = promisify(exec);
|
|
|
10
10
|
assertIsNotProductionRuntime();
|
|
11
11
|
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
12
12
|
let gitIsNotUsable = false;
|
|
13
|
-
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
13
|
+
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, crawlWithGit) {
|
|
14
14
|
assertPosixPath(userRootDir);
|
|
15
15
|
assertPosixPath(outDirAbsoluteFilesystem);
|
|
16
16
|
let outDirRelativeFromUserRootDir = path.posix.relative(userRootDir, outDirAbsoluteFilesystem);
|
|
@@ -26,8 +26,9 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
26
26
|
//
|
|
27
27
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
28
28
|
const timeBefore = new Date().getTime();
|
|
29
|
+
// Crawl
|
|
29
30
|
let files = [];
|
|
30
|
-
const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
|
|
31
|
+
const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
31
32
|
if (res &&
|
|
32
33
|
// Fallback to fast-glob for users that dynamically generate plus files. (Assuming all (generetad) plus files to be skipped because users usually included them in `.gitignore`.)
|
|
33
34
|
res.length > 0) {
|
|
@@ -36,7 +37,9 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
36
37
|
else {
|
|
37
38
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
38
39
|
}
|
|
40
|
+
// Filter build files
|
|
39
41
|
files = files.filter((file) => !isTemporaryBuildFile(file));
|
|
42
|
+
// Check performance
|
|
40
43
|
{
|
|
41
44
|
const timeAfter = new Date().getTime();
|
|
42
45
|
const timeSpent = timeAfter - timeBefore;
|
|
@@ -48,10 +51,12 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
// Normalize
|
|
55
|
+
const plusFiles = files.map((filePath) => {
|
|
56
|
+
// Both `$ git-ls files` and fast-glob return posix paths
|
|
57
|
+
assertPosixPath(filePath);
|
|
58
|
+
assert(!filePath.startsWith(userRootDir));
|
|
59
|
+
const filePathAbsoluteUserRootDir = path.posix.join('/', filePath);
|
|
55
60
|
return { filePathAbsoluteUserRootDir };
|
|
56
61
|
});
|
|
57
62
|
return plusFiles;
|
|
@@ -60,10 +65,17 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
60
65
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
61
66
|
if (gitIsNotUsable)
|
|
62
67
|
return null;
|
|
68
|
+
// Preserve UTF-8 file paths.
|
|
69
|
+
// https://github.com/vikejs/vike/issues/1658
|
|
70
|
+
// https://stackoverflow.com/questions/22827239/how-to-make-git-properly-display-utf-8-encoded-pathnames-in-the-console-window/22828826#22828826
|
|
71
|
+
// https://stackoverflow.com/questions/15884180/how-do-i-override-git-configuration-options-by-command-line-parameters/15884261#15884261
|
|
72
|
+
const preserveUTF8 = '-c core.quotepath=off';
|
|
63
73
|
const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
|
|
64
74
|
const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
|
|
65
75
|
const cmd = [
|
|
66
|
-
'git
|
|
76
|
+
'git',
|
|
77
|
+
preserveUTF8,
|
|
78
|
+
'ls-files',
|
|
67
79
|
...scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
|
|
68
80
|
...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
|
|
69
81
|
// --others lists untracked files only (but using .gitignore because --exclude-standard)
|
|
@@ -3,12 +3,15 @@ export { reloadVikeConfig };
|
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
5
|
export { isV1Design };
|
|
6
|
+
export { getConfigValueInterfaceFile };
|
|
6
7
|
export type { VikeConfigObject };
|
|
7
8
|
export type { InterfaceValueFile };
|
|
9
|
+
export type { InterfaceFile };
|
|
8
10
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
9
11
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
10
12
|
import type { ResolvedConfig } from 'vite';
|
|
11
13
|
import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
|
|
14
|
+
type InterfaceFile = InterfaceConfigFile | InterfaceValueFile;
|
|
12
15
|
type InterfaceFileCommons = {
|
|
13
16
|
locationId: LocationId;
|
|
14
17
|
filePath: FilePathResolved;
|
|
@@ -16,6 +19,12 @@ type InterfaceFileCommons = {
|
|
|
16
19
|
configValue?: unknown;
|
|
17
20
|
}>;
|
|
18
21
|
};
|
|
22
|
+
type InterfaceConfigFile = InterfaceFileCommons & {
|
|
23
|
+
isConfigFile: true;
|
|
24
|
+
isValueFile: false;
|
|
25
|
+
extendsFilePaths: string[];
|
|
26
|
+
isConfigExtend: boolean;
|
|
27
|
+
};
|
|
19
28
|
type InterfaceValueFile = InterfaceFileCommons & {
|
|
20
29
|
isConfigFile: false;
|
|
21
30
|
isValueFile: true;
|
|
@@ -29,6 +38,10 @@ type VikeConfigObject = {
|
|
|
29
38
|
};
|
|
30
39
|
declare const vikeConfigDependencies: Set<string>;
|
|
31
40
|
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string): void;
|
|
32
|
-
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?:
|
|
41
|
+
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, { crawlWithGit, tolerateInvalidConfig }?: {
|
|
42
|
+
crawlWithGit?: null | boolean;
|
|
43
|
+
tolerateInvalidConfig?: true;
|
|
44
|
+
}): Promise<VikeConfigObject>;
|
|
33
45
|
declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
|
|
34
46
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
47
|
+
declare function getConfigValueInterfaceFile(interfaceFile: InterfaceFile, configName: string): unknown;
|
|
@@ -3,6 +3,7 @@ export { reloadVikeConfig };
|
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
5
|
export { isV1Design };
|
|
6
|
+
export { getConfigValueInterfaceFile };
|
|
6
7
|
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, getOutDirs, assertKeys, objectKeys, objectFromEntries, makeFirst, isNpmPackageImport, reverse } from '../../../utils.js';
|
|
7
8
|
import path from 'path';
|
|
8
9
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
@@ -20,6 +21,8 @@ import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig
|
|
|
20
21
|
import { clearFilesEnvMap, resolvePointerImportOfConfig } from './getVikeConfig/resolvePointerImport.js';
|
|
21
22
|
import { getFilePathResolved } from '../../../shared/getFilePath.js';
|
|
22
23
|
import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
24
|
+
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
25
|
+
import { assertExtensionsPeerDependencies, assertExtensionsConventions } from './assertExtensions.js';
|
|
23
26
|
assertIsNotProductionRuntime();
|
|
24
27
|
let devServerIsCorrupt = false;
|
|
25
28
|
let wasConfigInvalid = null;
|
|
@@ -62,11 +65,12 @@ async function handleReloadSideEffects() {
|
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
|
-
async function getVikeConfig(config, isDev, tolerateInvalidConfig) {
|
|
68
|
+
async function getVikeConfig(config, isDev, { crawlWithGit, tolerateInvalidConfig } = {}) {
|
|
66
69
|
const { outDirRoot } = getOutDirs(config);
|
|
67
70
|
const userRootDir = config.root;
|
|
68
71
|
if (!vikeConfigPromise) {
|
|
69
|
-
|
|
72
|
+
const crawlWithGit_ = crawlWithGit !== undefined ? crawlWithGit : (await getConfigVike(config)).crawl.git;
|
|
73
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, crawlWithGit_, tolerateInvalidConfig);
|
|
70
74
|
}
|
|
71
75
|
return await vikeConfigPromise;
|
|
72
76
|
}
|
|
@@ -76,8 +80,8 @@ async function isV1Design(config, isDev) {
|
|
|
76
80
|
const isV1Design = pageConfigs.length > 0;
|
|
77
81
|
return isV1Design;
|
|
78
82
|
}
|
|
79
|
-
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
80
|
-
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev);
|
|
83
|
+
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
84
|
+
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
|
|
81
85
|
const configFiles = [];
|
|
82
86
|
const valueFiles = [];
|
|
83
87
|
plusFiles.forEach((f) => {
|
|
@@ -118,29 +122,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
|
118
122
|
```
|
|
119
123
|
*/
|
|
120
124
|
const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
|
|
121
|
-
|
|
122
|
-
const alreadyMigrated = [
|
|
123
|
-
'vike-react',
|
|
124
|
-
'vike-react-query',
|
|
125
|
-
'vike-react-zustand',
|
|
126
|
-
'vike-vue',
|
|
127
|
-
'vike-pinia',
|
|
128
|
-
'vike-solid'
|
|
129
|
-
];
|
|
130
|
-
assert(extendsConfig.filePath.importPathAbsolute);
|
|
131
|
-
const extensionName = extendsConfig.filePath.importPathAbsolute.split('/')[0];
|
|
132
|
-
const warnMsg = alreadyMigrated.includes(extensionName)
|
|
133
|
-
? `You're using a deprecated version of the Vike extension ${extensionName}, update ${extensionName} to its latest version.`
|
|
134
|
-
: `The config of the Vike extension ${extensionName} should set a ${pc.cyan('name')} value`;
|
|
135
|
-
const isNameDefined = interfaceFile.fileExportsByConfigName.name?.configValue;
|
|
136
|
-
if (alreadyMigrated) {
|
|
137
|
-
// Eventually always make it a assertUsage()
|
|
138
|
-
assertWarning(isNameDefined, warnMsg, { onlyOnce: true });
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
assertUsage(isNameDefined, warnMsg);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
125
|
+
assertExtensionsConventions(interfaceFile);
|
|
144
126
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
145
127
|
});
|
|
146
128
|
}),
|
|
@@ -208,12 +190,12 @@ function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
|
208
190
|
});
|
|
209
191
|
});
|
|
210
192
|
}
|
|
211
|
-
async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig) {
|
|
193
|
+
async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, crawlWithGit, tolerateInvalidConfig) {
|
|
212
194
|
let hasError = false;
|
|
213
195
|
let ret;
|
|
214
196
|
let err;
|
|
215
197
|
try {
|
|
216
|
-
ret = await loadVikeConfig(userRootDir, outDirRoot, isDev);
|
|
198
|
+
ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit);
|
|
217
199
|
}
|
|
218
200
|
catch (err_) {
|
|
219
201
|
hasError = true;
|
|
@@ -250,17 +232,19 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
250
232
|
}
|
|
251
233
|
}
|
|
252
234
|
}
|
|
253
|
-
async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
254
|
-
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev);
|
|
235
|
+
async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
236
|
+
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
|
|
255
237
|
const importedFilesLoaded = {};
|
|
256
238
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
257
239
|
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
258
240
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
259
241
|
.map(async ([locationId]) => {
|
|
260
242
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
243
|
+
const interfaceFilesRelevantList = Object.values(interfaceFilesByLocationId).flat(1);
|
|
244
|
+
assertExtensionsPeerDependencies(interfaceFilesRelevantList);
|
|
261
245
|
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
262
246
|
// Load value files of custom config-only configs
|
|
263
|
-
await Promise.all(
|
|
247
|
+
await Promise.all(interfaceFilesRelevantList.map(async (interfaceFile) => {
|
|
264
248
|
if (!interfaceFile.isValueFile)
|
|
265
249
|
return;
|
|
266
250
|
const { configName } = interfaceFile;
|
|
@@ -348,13 +332,6 @@ function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
|
348
332
|
.sort(([locationId1], [locationId2]) => sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage)));
|
|
349
333
|
return interfaceFilesRelevant;
|
|
350
334
|
}
|
|
351
|
-
function getInterfaceFileList(interfaceFilesByLocationId) {
|
|
352
|
-
const interfaceFiles = [];
|
|
353
|
-
Object.values(interfaceFilesByLocationId).forEach((interfaceFiles_) => {
|
|
354
|
-
interfaceFiles.push(...interfaceFiles_);
|
|
355
|
-
});
|
|
356
|
-
return interfaceFiles;
|
|
357
|
-
}
|
|
358
335
|
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
359
336
|
const locationIds = objectKeys(interfaceFilesByLocationId);
|
|
360
337
|
const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
@@ -765,8 +742,8 @@ function getComputed(configValueSources, configDefinitions) {
|
|
|
765
742
|
});
|
|
766
743
|
return configValuesComputed;
|
|
767
744
|
}
|
|
768
|
-
async function findPlusFiles(userRootDir, outDirRoot, isDev) {
|
|
769
|
-
const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
|
|
745
|
+
async function findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
746
|
+
const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
|
|
770
747
|
const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
|
|
771
748
|
return plusFiles;
|
|
772
749
|
}
|
|
@@ -967,3 +944,6 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
|
967
944
|
// Sort after the filesystem inheritance of the config value
|
|
968
945
|
.sort(([, [source1]], [, [source2]]) => reverse(sortAfterInheritanceOrder(source1.locationId, source2.locationId, locationIdPage))));
|
|
969
946
|
}
|
|
947
|
+
function getConfigValueInterfaceFile(interfaceFile, configName) {
|
|
948
|
+
return interfaceFile.fileExportsByConfigName[configName]?.configValue;
|
|
949
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -19,7 +19,7 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
|
19
19
|
}
|
|
20
20
|
*/
|
|
21
21
|
const { pageId, isForClientSide } = result;
|
|
22
|
-
const { pageConfigs } = await getVikeConfig(config, isDev, true);
|
|
22
|
+
const { pageConfigs } = await getVikeConfig(config, isDev, { tolerateInvalidConfig: true });
|
|
23
23
|
const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
|
|
24
24
|
assert(pageConfig);
|
|
25
25
|
const configVike = await getConfigVike(config);
|
|
@@ -5,7 +5,7 @@ import { getVikeConfig } from './getVikeConfig.js';
|
|
|
5
5
|
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
6
6
|
import { serializeConfigValues } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
7
7
|
async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
|
|
8
|
-
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, isDev, true);
|
|
8
|
+
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, isDev, { tolerateInvalidConfig: true });
|
|
9
9
|
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
10
10
|
}
|
|
11
11
|
function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
|
|
@@ -33,10 +33,10 @@ function previewConfig() {
|
|
|
33
33
|
assertDist();
|
|
34
34
|
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
35
35
|
if (!configVike.prerender || configVike.prerender.partial) {
|
|
36
|
-
addSsrMiddleware(server.middlewares)
|
|
36
|
+
addSsrMiddleware(server.middlewares, config, true)
|
|
37
37
|
}
|
|
38
38
|
/*/
|
|
39
|
-
addSsrMiddleware(server.middlewares);
|
|
39
|
+
addSsrMiddleware(server.middlewares, config, true);
|
|
40
40
|
//*/
|
|
41
41
|
addStatic404Middleware(server.middlewares);
|
|
42
42
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export { resolveClientEntriesDev };
|
|
2
|
+
import { assert, assertPosixPath, toPosixPath, pathJoin, assertIsNpmPackageImport, assertIsNotProductionRuntime } from './utils.js';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
7
|
+
const importMetaUrl = import.meta.url;
|
|
8
|
+
const require_ = createRequire(importMetaUrl);
|
|
9
|
+
const __dirname_ = dirname(fileURLToPath(importMetaUrl));
|
|
10
|
+
assertIsNotProductionRuntime();
|
|
11
|
+
async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
12
|
+
let root = viteDevServer.config.root;
|
|
13
|
+
assert(root);
|
|
14
|
+
root = toPosixPath(root);
|
|
15
|
+
// The `?import` suffix is needed for MDX to be transpiled:
|
|
16
|
+
// - Not transpiled: `/pages/markdown.page.mdx`
|
|
17
|
+
// - Transpiled: `/pages/markdown.page.mdx?import`
|
|
18
|
+
// But `?import` doesn't work with `/@fs/`:
|
|
19
|
+
// - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx
|
|
20
|
+
// - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx?import
|
|
21
|
+
if (clientEntry.endsWith('?import')) {
|
|
22
|
+
assert(clientEntry.startsWith('/'));
|
|
23
|
+
return clientEntry;
|
|
24
|
+
}
|
|
25
|
+
assertPosixPath(clientEntry);
|
|
26
|
+
let filePath;
|
|
27
|
+
if (clientEntry.startsWith('/')) {
|
|
28
|
+
filePath = pathJoin(root, clientEntry);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (clientEntry.startsWith('@@vike/')) {
|
|
32
|
+
assert(clientEntry.endsWith('.js'));
|
|
33
|
+
try {
|
|
34
|
+
// For Vitest (which doesn't resolve vike to its dist but to its source files)
|
|
35
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/plugin/resolveClientEntriesDev.js
|
|
36
|
+
filePath = toPosixPath(require_.resolve(clientEntry.replace('@@vike/dist/esm/client/', '../../client/').replace('.js', '.ts')));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// For users
|
|
40
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/resolveClientEntriesDev.js
|
|
41
|
+
filePath = toPosixPath(require_.resolve(clientEntry.replace('@@vike/dist/esm/client/', '../../../../dist/esm/client/')));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
assertIsNpmPackageImport(clientEntry);
|
|
46
|
+
filePath = require_.resolve(clientEntry);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!filePath.startsWith('/')) {
|
|
50
|
+
assert(process.platform === 'win32');
|
|
51
|
+
filePath = '/' + filePath;
|
|
52
|
+
}
|
|
53
|
+
filePath = '/@fs' + filePath;
|
|
54
|
+
assertPosixPath(filePath);
|
|
55
|
+
return filePath;
|
|
56
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { addSsrMiddleware };
|
|
2
|
-
import type { ViteDevServer } from 'vite';
|
|
2
|
+
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
3
3
|
type ConnectServer = ViteDevServer['middlewares'];
|
|
4
|
-
declare function addSsrMiddleware(middlewares: ConnectServer): void;
|
|
4
|
+
declare function addSsrMiddleware(middlewares: ConnectServer, config: ResolvedConfig, isPreview: boolean): void;
|
|
@@ -2,7 +2,7 @@ export { addSsrMiddleware };
|
|
|
2
2
|
import { renderPage } from '../../runtime/renderPage.js';
|
|
3
3
|
import { assertWarning } from '../utils.js';
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
|
-
function addSsrMiddleware(middlewares) {
|
|
5
|
+
function addSsrMiddleware(middlewares, config, isPreview) {
|
|
6
6
|
middlewares.use(async (req, res, next) => {
|
|
7
7
|
if (res.headersSent)
|
|
8
8
|
return next();
|
|
@@ -37,6 +37,12 @@ function addSsrMiddleware(middlewares) {
|
|
|
37
37
|
// - We purposely don't use next(err) to align behavior: we use our own/copied implementation of buildErrorMessage() regardless of whether the user uses Vite's dev middleware or Vite's standalone dev server
|
|
38
38
|
return next();
|
|
39
39
|
}
|
|
40
|
+
const configHeaders = (isPreview && config?.preview?.headers) || config?.server?.headers;
|
|
41
|
+
if (configHeaders) {
|
|
42
|
+
for (const [name, value] of Object.entries(configHeaders))
|
|
43
|
+
if (value)
|
|
44
|
+
res.setHeader(name, value);
|
|
45
|
+
}
|
|
40
46
|
if (!pageContext.httpResponse) {
|
|
41
47
|
return next();
|
|
42
48
|
}
|
|
@@ -7,7 +7,7 @@ export { screenHasErrors };
|
|
|
7
7
|
export { applyViteSourceMapToStackTrace };
|
|
8
8
|
import { assert, projectInfo, stripAnsi, hasProp, assertIsNotProductionRuntime } from '../../utils.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
|
-
import { isErrorDebug } from '
|
|
10
|
+
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
11
11
|
import { getViteDevServer } from '../../../runtime/globalContext.js';
|
|
12
12
|
assertIsNotProductionRuntime();
|
|
13
13
|
let isFirstLog = true;
|
|
@@ -16,7 +16,7 @@ import { getViteConfig } from '../../runtime/globalContext.js';
|
|
|
16
16
|
import { overwriteRuntimeProductionLogger } from '../../runtime/renderPage/loggerRuntime.js';
|
|
17
17
|
import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, overwriteAssertProductionLogger, stripAnsi, warnIfErrorIsNotObject } from '../utils.js';
|
|
18
18
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
19
|
-
import { isErrorDebug } from '
|
|
19
|
+
import { isErrorDebug } from '../../shared/isErrorDebug.js';
|
|
20
20
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
21
21
|
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
22
22
|
import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen, applyViteSourceMapToStackTrace } from './loggerNotProd/log.js';
|
|
@@ -3,7 +3,7 @@ import { assert, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly } from '.
|
|
|
3
3
|
import { logViteError, logViteAny, clearLogs } from './loggerNotProd.js';
|
|
4
4
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
5
5
|
import { removeSuperfluousViteLog } from './loggerVite/removeSuperfluousViteLog.js';
|
|
6
|
-
import { isErrorDebug } from '
|
|
6
|
+
import { isErrorDebug } from '../../shared/isErrorDebug.js';
|
|
7
7
|
function improveViteLogs(config) {
|
|
8
8
|
intercept('info', config);
|
|
9
9
|
intercept('warn', config);
|
|
@@ -10,7 +10,7 @@ export * from '../../utils/escapeRegex.js';
|
|
|
10
10
|
export * from '../../utils/stripAnsi.js';
|
|
11
11
|
export * from '../../utils/trimWithAnsi.js';
|
|
12
12
|
export * from '../../utils/removeEmptyLines.js';
|
|
13
|
-
export * from '../../utils/
|
|
13
|
+
export * from '../../utils/findPackageJson.js';
|
|
14
14
|
export * from '../../utils/getPropAccessNotation.js';
|
|
15
15
|
export * from '../../utils/deepEqual.js';
|
|
16
16
|
export * from '../../utils/assertKeys.js';
|
|
@@ -16,7 +16,7 @@ export * from '../../utils/escapeRegex.js';
|
|
|
16
16
|
export * from '../../utils/stripAnsi.js';
|
|
17
17
|
export * from '../../utils/trimWithAnsi.js';
|
|
18
18
|
export * from '../../utils/removeEmptyLines.js';
|
|
19
|
-
export * from '../../utils/
|
|
19
|
+
export * from '../../utils/findPackageJson.js';
|
|
20
20
|
export * from '../../utils/getPropAccessNotation.js';
|
|
21
21
|
export * from '../../utils/deepEqual.js';
|
|
22
22
|
export * from '../../utils/assertKeys.js';
|
|
@@ -31,7 +31,7 @@ function serializePageContextClientSide(pageContext) {
|
|
|
31
31
|
pageContextClient[prop] = pageContext[prop];
|
|
32
32
|
});
|
|
33
33
|
if (Object.keys(pageContext._pageContextInit).some((p) => passToClient.includes(p))) {
|
|
34
|
-
pageContextClient
|
|
34
|
+
pageContextClient[pageContextInitIsPassedToClient] = true;
|
|
35
35
|
}
|
|
36
36
|
let pageContextSerialized;
|
|
37
37
|
try {
|
|
@@ -2,8 +2,12 @@ export { onLoad };
|
|
|
2
2
|
import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
|
|
3
3
|
import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
|
|
4
4
|
import { installRequireShim } from '@brillout/require-shim';
|
|
5
|
+
import { setAlwaysShowStackTrace } from './utils.js';
|
|
6
|
+
import { isErrorDebug } from '../shared/isErrorDebug.js';
|
|
5
7
|
function onLoad() {
|
|
6
8
|
assertIsNotBrowser();
|
|
7
9
|
assertNodeVersion();
|
|
8
10
|
installRequireShim();
|
|
11
|
+
if (isErrorDebug())
|
|
12
|
+
setAlwaysShowStackTrace();
|
|
9
13
|
}
|
|
@@ -7,17 +7,17 @@ import { getGlobalContext } from '../globalContext.js';
|
|
|
7
7
|
import { getConfigValueRuntime } from '../../../shared/page-configs/getConfigValue.js';
|
|
8
8
|
function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
9
9
|
if (pageConfig) {
|
|
10
|
-
const {
|
|
10
|
+
const { clientEntryLoaded, isClientRouting } = analyzeClientSide(pageConfig, pageFilesAll, pageId);
|
|
11
11
|
const clientEntries = [];
|
|
12
12
|
const clientFilePath = getConfigValueRuntime(pageConfig, 'client', 'string')?.value ?? null;
|
|
13
13
|
if (clientFilePath)
|
|
14
14
|
clientEntries.push(clientFilePath);
|
|
15
|
-
if (
|
|
15
|
+
if (clientEntryLoaded)
|
|
16
16
|
clientEntries.push(getVikeClientEntry(isClientRouting));
|
|
17
17
|
const clientDependencies = [];
|
|
18
18
|
clientDependencies.push({
|
|
19
19
|
id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
|
|
20
|
-
onlyAssets:
|
|
20
|
+
onlyAssets: clientEntryLoaded ? false : true,
|
|
21
21
|
eagerlyImported: false
|
|
22
22
|
});
|
|
23
23
|
// In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
|
|
@@ -53,7 +53,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
return {
|
|
56
|
-
isHtmlOnly: !
|
|
56
|
+
isHtmlOnly: !clientEntryLoaded,
|
|
57
57
|
isClientRouting,
|
|
58
58
|
clientEntries,
|
|
59
59
|
clientDependencies,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { getPageAssets };
|
|
2
|
+
export { setResolveClientEntriesDev };
|
|
2
3
|
export type { PageAsset };
|
|
3
4
|
export type { GetPageAssets };
|
|
4
5
|
export type { PageContextGetPageAssets };
|
|
5
6
|
import { type MediaType } from './inferMediaType.js';
|
|
6
7
|
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
8
|
+
import type { ResolveClientEntriesDev } from '../../plugin/resolveClientEntriesDev.js';
|
|
7
9
|
type PageAsset = {
|
|
8
10
|
src: string;
|
|
9
11
|
assetType: null | NonNullable<MediaType>['assetType'];
|
|
@@ -17,3 +19,4 @@ type PageContextGetPageAssets = {
|
|
|
17
19
|
_includeAssetsImportedByServer: boolean;
|
|
18
20
|
};
|
|
19
21
|
declare function getPageAssets(pageContext: PageContextGetPageAssets, clientDependencies: ClientDependency[], clientEntries: string[]): Promise<PageAsset[]>;
|
|
22
|
+
declare function setResolveClientEntriesDev(resolveClientEntriesDev: ResolveClientEntriesDev): void;
|