vike 0.4.216 → 0.4.217-commit-99ea561
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/build.js +4 -2
- package/dist/cjs/node/api/prepareViteApiCall.js +14 -4
- package/dist/cjs/node/plugin/index.js +5 -7
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/cjs/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +9 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +15 -102
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +128 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +42 -28
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -3
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +4 -1
- package/dist/cjs/node/prerender/runPrerender.js +2 -4
- package/dist/cjs/node/runtime/globalContext.js +16 -8
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/cjs/node/shared/resolveBase.js +41 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/api/build.js +4 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +1 -1
- package/dist/esm/node/api/prepareViteApiCall.js +14 -4
- package/dist/esm/node/plugin/index.d.ts +3 -3
- package/dist/esm/node/plugin/index.js +3 -5
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +15 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -15
- 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 +15 -102
- package/dist/esm/{shared/ConfigVike.d.ts → node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts} +14 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +123 -0
- 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 +43 -29
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +4 -3
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +5 -2
- package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +1 -1
- package/dist/esm/node/prerender/runPrerender.js +2 -4
- package/dist/esm/node/runtime/globalContext.d.ts +6 -2
- package/dist/esm/node/runtime/globalContext.js +16 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/shared/resolveBase.d.ts +11 -0
- package/dist/esm/node/shared/resolveBase.js +36 -0
- package/dist/esm/shared/page-configs/Config.d.ts +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +0 -75
- package/dist/cjs/node/plugin/plugins/config/index.js +0 -81
- package/dist/cjs/node/plugin/plugins/config/pickFirst.js +0 -6
- package/dist/cjs/node/plugin/plugins/config/resolveBase.js +0 -47
- package/dist/cjs/node/shared/getConfigVike.js +0 -10
- package/dist/cjs/shared/ConfigVike.js +0 -2
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.d.ts +0 -7
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +0 -73
- package/dist/esm/node/plugin/plugins/config/index.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +0 -76
- package/dist/esm/node/plugin/plugins/config/pickFirst.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/config/pickFirst.js +0 -3
- package/dist/esm/node/plugin/plugins/config/resolveBase.d.ts +0 -10
- package/dist/esm/node/plugin/plugins/config/resolveBase.js +0 -42
- package/dist/esm/node/shared/getConfigVike.d.ts +0 -4
- package/dist/esm/node/shared/getConfigVike.js +0 -8
- package/dist/esm/shared/ConfigVike.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
2
|
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VikeConfigGlobal } from './v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
|
|
4
4
|
declare function getVirtualFileImportUserCode(id: string, options: {
|
|
5
5
|
ssr?: boolean;
|
|
6
|
-
} | undefined,
|
|
6
|
+
} | undefined, vikeConfigGlobal: VikeConfigGlobal, config: ResolvedConfig, isDev: boolean): Promise<string>;
|
|
@@ -6,16 +6,16 @@ import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { getVirtualFilePageConfigs } from './v1-design/getVirtualFilePageConfigs.js';
|
|
8
8
|
import { isV1Design as isV1Design_ } from './v1-design/getVikeConfig.js';
|
|
9
|
-
async function getVirtualFileImportUserCode(id, options,
|
|
9
|
+
async function getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev) {
|
|
10
10
|
const idParsed = isVirtualFileIdImportUserCode(id);
|
|
11
11
|
assert(idParsed);
|
|
12
12
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
13
13
|
assert(isForClientSide === !viteIsSSR_options(options));
|
|
14
|
-
const isPrerendering = !!
|
|
15
|
-
const code = await getCode(config,
|
|
14
|
+
const isPrerendering = !!vikeConfigGlobal.prerender;
|
|
15
|
+
const code = await getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id);
|
|
16
16
|
return code;
|
|
17
17
|
}
|
|
18
|
-
async function getCode(config,
|
|
18
|
+
async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
|
|
19
19
|
const { command } = config;
|
|
20
20
|
assert(command === 'serve' || command === 'build');
|
|
21
21
|
const isBuild = command === 'build';
|
|
@@ -24,7 +24,7 @@ async function getCode(config, configVike, isForClientSide, isClientRouting, isP
|
|
|
24
24
|
{
|
|
25
25
|
const globRoots = getGlobRoots(config);
|
|
26
26
|
debugGlob('Glob roots: ', globRoots);
|
|
27
|
-
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
27
|
+
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id);
|
|
28
28
|
}
|
|
29
29
|
debugGlob(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
30
30
|
return content;
|
|
@@ -54,7 +54,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
57
|
+
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id) {
|
|
58
58
|
let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
|
|
59
59
|
|
|
60
60
|
export const pageFilesLazy = {};
|
|
@@ -68,7 +68,7 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
|
|
|
68
68
|
|
|
69
69
|
`;
|
|
70
70
|
// We still use import.meta.glob() when using th V1 design in order to not break the V1 design deprecation warning
|
|
71
|
-
const isV1Design = await isV1Design_(config
|
|
71
|
+
const isV1Design = await isV1Design_(config);
|
|
72
72
|
fileTypes
|
|
73
73
|
.filter((fileType) => fileType !== '.css')
|
|
74
74
|
.forEach((fileType) => {
|
|
@@ -86,7 +86,7 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
|
|
|
86
86
|
fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
-
if (
|
|
89
|
+
if (vikeConfigGlobal.includeAssetsImportedByServer && isForClientSide) {
|
|
90
90
|
fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
|
|
91
91
|
}
|
|
92
92
|
return fileContent;
|
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
export { importUserCode };
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
3
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
4
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath
|
|
5
|
+
import { assert, assertPosixPath } from '../../utils.js';
|
|
7
6
|
import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../../shared/virtual-files.js';
|
|
8
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
9
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
10
|
-
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile, isV1Design } from './v1-design/getVikeConfig.js';
|
|
9
|
+
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile, isV1Design, getVikeConfig } from './v1-design/getVikeConfig.js';
|
|
11
10
|
import pc from '@brillout/picocolors';
|
|
12
11
|
import { logConfigInfo } from '../../shared/loggerNotProd.js';
|
|
13
12
|
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
14
13
|
function importUserCode() {
|
|
15
14
|
let config;
|
|
16
|
-
let
|
|
17
|
-
let isDev;
|
|
15
|
+
let vikeConfigGlobal;
|
|
18
16
|
return {
|
|
19
17
|
name: 'vike:importUserCode',
|
|
20
|
-
config(_, env) {
|
|
21
|
-
isDev = isDevCheck(env);
|
|
22
|
-
},
|
|
23
18
|
async configResolved(config_) {
|
|
24
|
-
|
|
19
|
+
const vikeConfig = await getVikeConfig(config_);
|
|
20
|
+
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
25
21
|
config = config_;
|
|
26
22
|
// TODO/v1-release: remove
|
|
27
23
|
{
|
|
28
|
-
|
|
29
|
-
const isV1 = await isV1Design(config, isDev);
|
|
24
|
+
const isV1 = await isV1Design(config);
|
|
30
25
|
if (!isV1)
|
|
31
26
|
config.experimental.importGlobRestoreExtension = true;
|
|
32
27
|
}
|
|
@@ -50,13 +45,14 @@ function importUserCode() {
|
|
|
50
45
|
if (!isVirtualFileId(id))
|
|
51
46
|
return undefined;
|
|
52
47
|
id = getVirtualFileId(id);
|
|
48
|
+
const isDev = config._isDev;
|
|
53
49
|
assert(typeof isDev === 'boolean');
|
|
54
50
|
if (isVirtualFileIdPageConfigValuesAll(id)) {
|
|
55
51
|
const code = await getVirtualFilePageConfigValuesAll(id, isDev, config);
|
|
56
52
|
return code;
|
|
57
53
|
}
|
|
58
54
|
if (isVirtualFileIdImportUserCode(id)) {
|
|
59
|
-
const code = await getVirtualFileImportUserCode(id, options,
|
|
55
|
+
const code = await getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev);
|
|
60
56
|
return code;
|
|
61
57
|
}
|
|
62
58
|
},
|
|
@@ -83,8 +79,6 @@ function handleFileAddRemove(server, config) {
|
|
|
83
79
|
}
|
|
84
80
|
function handleHotUpdate(ctx, config) {
|
|
85
81
|
const { file, server } = ctx;
|
|
86
|
-
assertPosixPath(file);
|
|
87
|
-
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
88
82
|
const isVikeConfig = isVikeConfigModule(file);
|
|
89
83
|
const isViteModule = ctx.modules.length > 0;
|
|
90
84
|
/* Should we show this?
|
|
@@ -114,6 +108,8 @@ function handleHotUpdate(ctx, config) {
|
|
|
114
108
|
}
|
|
115
109
|
}
|
|
116
110
|
function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
111
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
112
|
+
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
117
113
|
return vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
118
114
|
}
|
|
119
115
|
function reloadConfig(filePath, config, op) {
|
|
@@ -122,7 +118,7 @@ function reloadConfig(filePath, config, op) {
|
|
|
122
118
|
const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
|
|
123
119
|
logConfigInfo(msg, 'info');
|
|
124
120
|
}
|
|
125
|
-
reloadVikeConfig(config
|
|
121
|
+
reloadVikeConfig(config);
|
|
126
122
|
}
|
|
127
123
|
function getVirtualModules(server) {
|
|
128
124
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
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:
|
|
2
|
+
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string): Promise<{
|
|
3
3
|
filePathAbsoluteUserRootDir: string;
|
|
4
4
|
}[]>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
2
|
import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import fs from 'fs/promises';
|
|
5
4
|
import glob from 'fast-glob';
|
|
6
5
|
import { exec } from 'child_process';
|
|
7
6
|
import { promisify } from 'util';
|
|
8
7
|
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
|
|
8
|
+
import { getEnvVarObject } from '../../../../shared/getEnvVarObject.js';
|
|
9
9
|
const execA = promisify(exec);
|
|
10
|
-
const TOO_MANY_UNTRACKED_FILES = 5;
|
|
11
10
|
assertIsNotProductionRuntime();
|
|
12
11
|
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
13
12
|
let gitIsNotUsable = false;
|
|
14
|
-
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem
|
|
13
|
+
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
15
14
|
assertPosixPath(userRootDir);
|
|
16
15
|
//*/
|
|
17
16
|
const outDirRelativeFromUserRootDir = null;
|
|
@@ -31,14 +30,13 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGi
|
|
|
31
30
|
//
|
|
32
31
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
33
32
|
// Crawl
|
|
34
|
-
let files
|
|
35
|
-
const res =
|
|
33
|
+
let files;
|
|
34
|
+
const res = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
36
35
|
if (res &&
|
|
37
36
|
// Fallback to fast-glob for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
|
|
38
|
-
res.
|
|
39
|
-
files = res
|
|
37
|
+
res.length > 0) {
|
|
38
|
+
files = res;
|
|
40
39
|
// We cannot find files inside symlink directories with `$ git ls-files` => we use fast-glob
|
|
41
|
-
files.push(...(await crawlSymlinkDirs(res.symlinkDirs, userRootDir, outDirRelativeFromUserRootDir)));
|
|
42
40
|
}
|
|
43
41
|
else {
|
|
44
42
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
@@ -80,14 +78,13 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
80
78
|
...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
|
|
81
79
|
// --others --exclude-standard => list untracked files (--others) while using .gitignore (--exclude-standard)
|
|
82
80
|
// --cached => list tracked files
|
|
83
|
-
|
|
84
|
-
'--others --exclude-standard --cached --stage'
|
|
81
|
+
'--others --exclude-standard --cached'
|
|
85
82
|
].join(' ');
|
|
86
|
-
let
|
|
83
|
+
let filesAll;
|
|
87
84
|
let filesDeleted;
|
|
88
85
|
try {
|
|
89
86
|
;
|
|
90
|
-
[
|
|
87
|
+
[filesAll, filesDeleted] = await Promise.all([
|
|
91
88
|
// Main command
|
|
92
89
|
runCmd1(cmd, userRootDir),
|
|
93
90
|
// Get tracked but deleted files
|
|
@@ -101,31 +98,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
101
98
|
}
|
|
102
99
|
throw err;
|
|
103
100
|
}
|
|
104
|
-
const filePaths = resultLines.map(parseGitLsResultLine);
|
|
105
|
-
// If there are too many files without mode we fallback to fast-glob
|
|
106
|
-
if (filePaths.filter((f) => !f.mode).length > TOO_MANY_UNTRACKED_FILES)
|
|
107
|
-
return null;
|
|
108
|
-
const symlinkDirs = [];
|
|
109
101
|
const files = [];
|
|
110
|
-
for (const
|
|
102
|
+
for (const filePath of filesAll) {
|
|
111
103
|
// Deleted?
|
|
112
104
|
if (filesDeleted.includes(filePath))
|
|
113
105
|
continue;
|
|
114
106
|
// We have to repeat the same exclusion logic here because the option --exclude of `$ git ls-files` only applies to untracked files. (We use --exclude only to speed up the `$ git ls-files` command.)
|
|
115
107
|
if (!ignoreAsFilterFn(filePath))
|
|
116
108
|
continue;
|
|
117
|
-
// Symlink directory?
|
|
118
|
-
{
|
|
119
|
-
const isSymlinkDir = await isSymlinkDirectory(mode, filePath, userRootDir);
|
|
120
|
-
if (isSymlinkDir) {
|
|
121
|
-
symlinkDirs.push(filePath);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
// Skip deleted files and non-symlink directories
|
|
125
|
-
if (isSymlinkDir === null) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
109
|
// + file?
|
|
130
110
|
if (!path.posix.basename(filePath).startsWith('+'))
|
|
131
111
|
continue;
|
|
@@ -134,7 +114,7 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
134
114
|
continue;
|
|
135
115
|
files.push(filePath);
|
|
136
116
|
}
|
|
137
|
-
return
|
|
117
|
+
return files;
|
|
138
118
|
}
|
|
139
119
|
// Same as gitLsFiles() but using fast-glob
|
|
140
120
|
async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
@@ -204,77 +184,6 @@ async function isGitNotUsable(userRootDir) {
|
|
|
204
184
|
return false;
|
|
205
185
|
}
|
|
206
186
|
}
|
|
207
|
-
async function crawlSymlinkDirs(symlinkDirs, userRootDir, outDirRelativeFromUserRootDir) {
|
|
208
|
-
const filesInSymlinkDirs = (await Promise.all(symlinkDirs.map(async (symlinkDir) => (await fastGlob(path.posix.join(userRootDir, symlinkDir), outDirRelativeFromUserRootDir)).map((filePath) => path.posix.join(symlinkDir, filePath))))).flat();
|
|
209
|
-
return filesInSymlinkDirs;
|
|
210
|
-
}
|
|
211
|
-
// Parse:
|
|
212
|
-
// ```
|
|
213
|
-
// some/not/tracked/path
|
|
214
|
-
// 100644 f6928073402b241b468b199893ff6f4aed0b7195 0\tpages/index/+Page.tsx
|
|
215
|
-
// ```
|
|
216
|
-
function parseGitLsResultLine(resultLine) {
|
|
217
|
-
const [part1, part2, ...rest] = resultLine.split('\t');
|
|
218
|
-
assert(part1);
|
|
219
|
-
assert(rest.length === 0);
|
|
220
|
-
// Git doesn't provide the mode for untracked paths.
|
|
221
|
-
// `resultLine` is:
|
|
222
|
-
// ```
|
|
223
|
-
// some/not/tracked/path
|
|
224
|
-
// ```
|
|
225
|
-
if (part2 === undefined) {
|
|
226
|
-
return { filePath: part1, mode: null };
|
|
227
|
-
}
|
|
228
|
-
assert(part2);
|
|
229
|
-
// `resultLine` is:
|
|
230
|
-
// ```
|
|
231
|
-
// 100644 f6928073402b241b468b199893ff6f4aed0b7195 0\tpages/index/+Page.tsx
|
|
232
|
-
// ```
|
|
233
|
-
const [mode, _, __, ...rest2] = part1.split(' ');
|
|
234
|
-
assert(mode && _ && __ && rest2.length === 0);
|
|
235
|
-
return { filePath: part2, mode };
|
|
236
|
-
}
|
|
237
|
-
async function isSymlinkDirectory(mode, filePath, userRootDir) {
|
|
238
|
-
const filePathAbsolute = path.posix.join(userRootDir, filePath);
|
|
239
|
-
let stats = null;
|
|
240
|
-
let isSymlink = false;
|
|
241
|
-
if (mode === '120000') {
|
|
242
|
-
isSymlink = true;
|
|
243
|
-
}
|
|
244
|
-
else if (mode === null) {
|
|
245
|
-
// `$ git ls-files` doesn't provide the mode when Git doesn't track the path
|
|
246
|
-
stats = await getFileStats(filePathAbsolute);
|
|
247
|
-
if (stats === null)
|
|
248
|
-
return null;
|
|
249
|
-
isSymlink = stats.isSymbolicLink();
|
|
250
|
-
if (!isSymlink && stats.isDirectory())
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
assert(mode);
|
|
255
|
-
}
|
|
256
|
-
if (!isSymlink)
|
|
257
|
-
return false;
|
|
258
|
-
if (!stats)
|
|
259
|
-
stats = await getFileStats(filePathAbsolute);
|
|
260
|
-
if (stats === null)
|
|
261
|
-
return null;
|
|
262
|
-
const isDirectory = stats.isDirectory();
|
|
263
|
-
return isDirectory;
|
|
264
|
-
}
|
|
265
|
-
async function getFileStats(filePathAbsolute) {
|
|
266
|
-
let stats;
|
|
267
|
-
try {
|
|
268
|
-
stats = await fs.lstat(filePathAbsolute);
|
|
269
|
-
}
|
|
270
|
-
catch (err) {
|
|
271
|
-
// File was deleted, usually a temporary file such as +config.js.build-j95xb988fpln.mjs
|
|
272
|
-
// ENOENT: no such file or directory
|
|
273
|
-
assert(err.code === 'ENOENT');
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
return stats;
|
|
277
|
-
}
|
|
278
187
|
async function runCmd1(cmd, cwd) {
|
|
279
188
|
const { stdout } = await execA(cmd, {
|
|
280
189
|
cwd,
|
|
@@ -299,3 +208,7 @@ async function runCmd2(cmd, cwd) {
|
|
|
299
208
|
stderr = stderr.toString().trim();
|
|
300
209
|
return { stdout, stderr };
|
|
301
210
|
}
|
|
211
|
+
function isGitCrawlDisabled() {
|
|
212
|
+
const crawSettings = getEnvVarObject('VIKE_CRAWL');
|
|
213
|
+
return crawSettings?.git === false;
|
|
214
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export type {
|
|
3
|
-
type
|
|
1
|
+
export { resolveVikeConfigGlobal };
|
|
2
|
+
export type { VikeConfigGlobal };
|
|
3
|
+
export type { VikeVitePluginOptions };
|
|
4
|
+
declare function resolveVikeConfigGlobal(vikeVitePluginOptions: unknown, pageConfigGlobalValues: Record<string, unknown>): VikeConfigGlobal;
|
|
5
|
+
type VikeConfigGlobal = {
|
|
4
6
|
prerender: false | {
|
|
5
7
|
noExtraDir: boolean;
|
|
6
8
|
parallel: boolean | number;
|
|
@@ -9,8 +11,8 @@ type ConfigVikeResolved = {
|
|
|
9
11
|
};
|
|
10
12
|
disableAutoFullBuild: boolean | 'prerender' | null;
|
|
11
13
|
includeAssetsImportedByServer: boolean;
|
|
12
|
-
baseAssets: string;
|
|
13
|
-
baseServer: string;
|
|
14
|
+
baseAssets: string | null;
|
|
15
|
+
baseServer: string | null;
|
|
14
16
|
redirects: Record<string, string>;
|
|
15
17
|
trailingSlash: boolean;
|
|
16
18
|
disableUrlNormalization: boolean;
|
|
@@ -18,7 +20,7 @@ type ConfigVikeResolved = {
|
|
|
18
20
|
git: null | boolean;
|
|
19
21
|
};
|
|
20
22
|
};
|
|
21
|
-
type
|
|
23
|
+
type VikeVitePluginOptions = {
|
|
22
24
|
/**
|
|
23
25
|
* Enable pre-rendering.
|
|
24
26
|
*
|
|
@@ -44,12 +46,12 @@ type ConfigVikeUserProvided = {
|
|
|
44
46
|
*/
|
|
45
47
|
parallel?: boolean | number;
|
|
46
48
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
* Allow only some of your pages to be pre-rendered.
|
|
50
|
+
*
|
|
51
|
+
* This setting doesn't affect the pre-rendering process: it merely suppresses the warnings when some of your pages cannot be pre-rendered.
|
|
52
|
+
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
53
55
|
partial?: boolean;
|
|
54
56
|
/**
|
|
55
57
|
* Disable the automatic initiation of the pre-rendering process when running `$ vike build`.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export { resolveVikeConfigGlobal };
|
|
2
|
+
import pc from '@brillout/picocolors';
|
|
3
|
+
import { assert, assertUsage, hasProp, isObject } from '../../../../utils.js';
|
|
4
|
+
function resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues) {
|
|
5
|
+
// TODO/v1-release: remove
|
|
6
|
+
assertVikeConfigGlobal(vikeVitePluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
|
|
7
|
+
const configs = [vikeVitePluginOptions];
|
|
8
|
+
assertVikeConfigGlobal(pageConfigGlobalValues, ({ prop, errMsg }) => {
|
|
9
|
+
// Can we add the config file path ?
|
|
10
|
+
return `config ${pc.cyan(prop)} ${errMsg}`;
|
|
11
|
+
});
|
|
12
|
+
configs.push(pageConfigGlobalValues);
|
|
13
|
+
const vikeConfigGlobal = {
|
|
14
|
+
disableAutoFullBuild: pickFirst(configs.map((c) => c.disableAutoFullBuild)) ?? null,
|
|
15
|
+
prerender: resolvePrerenderOptions(configs),
|
|
16
|
+
includeAssetsImportedByServer: pickFirst(configs.map((c) => c.includeAssetsImportedByServer)) ?? true,
|
|
17
|
+
baseServer: pickFirst(configs.map((c) => c.baseServer)) ?? null,
|
|
18
|
+
baseAssets: pickFirst(configs.map((c) => c.baseAssets)) ?? null,
|
|
19
|
+
redirects: merge(configs.map((c) => c.redirects)) ?? {},
|
|
20
|
+
disableUrlNormalization: pickFirst(configs.map((c) => c.disableUrlNormalization)) ?? false,
|
|
21
|
+
trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false,
|
|
22
|
+
crawl: {
|
|
23
|
+
git: vikeVitePluginOptions.crawl?.git ?? null
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return vikeConfigGlobal;
|
|
27
|
+
}
|
|
28
|
+
function resolvePrerenderOptions(configs) {
|
|
29
|
+
if (!configs.some((c) => c.prerender)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const configsPrerender = configs.map((c) => c.prerender).filter(isObject2);
|
|
33
|
+
return {
|
|
34
|
+
partial: pickFirst(configsPrerender.map((c) => c.partial)) ?? false,
|
|
35
|
+
noExtraDir: pickFirst(configsPrerender.map((c) => c.noExtraDir)) ?? false,
|
|
36
|
+
parallel: pickFirst(configsPrerender.map((c) => c.parallel)) ?? true,
|
|
37
|
+
disableAutoRun: pickFirst(configsPrerender.map((c) => c.disableAutoRun)) ?? false
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function isObject2(p) {
|
|
41
|
+
return typeof p === 'object';
|
|
42
|
+
}
|
|
43
|
+
function merge(objs) {
|
|
44
|
+
const obj = {};
|
|
45
|
+
objs.forEach((e) => {
|
|
46
|
+
Object.assign(obj, e);
|
|
47
|
+
});
|
|
48
|
+
return obj;
|
|
49
|
+
}
|
|
50
|
+
function pickFirst(arr) {
|
|
51
|
+
return arr.filter((v) => v !== undefined)[0];
|
|
52
|
+
}
|
|
53
|
+
function assertVikeConfigGlobal(vikeConfigGlobal, wrongUsageMsg) {
|
|
54
|
+
const wrongUsageError = check(vikeConfigGlobal);
|
|
55
|
+
if (wrongUsageError) {
|
|
56
|
+
assertUsage(false, wrongUsageMsg(wrongUsageError));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function check(vikeConfigGlobal) {
|
|
60
|
+
assert(isObject(vikeConfigGlobal));
|
|
61
|
+
{
|
|
62
|
+
const prop = 'disableUrlNormalization';
|
|
63
|
+
if (!hasProp(vikeConfigGlobal, prop, 'boolean') && !hasProp(vikeConfigGlobal, prop, 'undefined'))
|
|
64
|
+
return { prop, errMsg: 'should be a boolean' };
|
|
65
|
+
}
|
|
66
|
+
{
|
|
67
|
+
const prop = 'trailingSlash';
|
|
68
|
+
if (!hasProp(vikeConfigGlobal, prop, 'boolean') && !hasProp(vikeConfigGlobal, prop, 'undefined'))
|
|
69
|
+
return { prop, errMsg: 'should be a boolean' };
|
|
70
|
+
}
|
|
71
|
+
{
|
|
72
|
+
const prop = 'redirects';
|
|
73
|
+
const { redirects } = vikeConfigGlobal;
|
|
74
|
+
if (!(redirects === undefined ||
|
|
75
|
+
(isObject(redirects) && Object.values(redirects).every((v) => typeof v === 'string'))))
|
|
76
|
+
return { prop, errMsg: 'should be an object of strings' };
|
|
77
|
+
}
|
|
78
|
+
{
|
|
79
|
+
const prop = 'disableAutoFullBuild';
|
|
80
|
+
if (!hasProp(vikeConfigGlobal, prop, 'boolean') &&
|
|
81
|
+
!hasProp(vikeConfigGlobal, prop, 'undefined') &&
|
|
82
|
+
!(vikeConfigGlobal[prop] === 'prerender'))
|
|
83
|
+
return { prop, errMsg: "should be a boolean or 'prerender'" };
|
|
84
|
+
}
|
|
85
|
+
{
|
|
86
|
+
const prop = 'includeAssetsImportedByServer';
|
|
87
|
+
if (!hasProp(vikeConfigGlobal, prop, 'boolean') && !hasProp(vikeConfigGlobal, prop, 'undefined'))
|
|
88
|
+
return { prop, errMsg: 'should be a boolean' };
|
|
89
|
+
}
|
|
90
|
+
{
|
|
91
|
+
const prop = 'prerender';
|
|
92
|
+
if (!hasProp(vikeConfigGlobal, prop, 'object') &&
|
|
93
|
+
!hasProp(vikeConfigGlobal, prop, 'boolean') &&
|
|
94
|
+
!hasProp(vikeConfigGlobal, prop, 'undefined'))
|
|
95
|
+
return { prop, errMsg: 'should be an object or a boolean' };
|
|
96
|
+
}
|
|
97
|
+
const configVikePrerender = vikeConfigGlobal.prerender;
|
|
98
|
+
if (typeof configVikePrerender === 'object') {
|
|
99
|
+
{
|
|
100
|
+
const p = 'partial';
|
|
101
|
+
if (!hasProp(configVikePrerender, p, 'boolean') && !hasProp(configVikePrerender, p, 'undefined'))
|
|
102
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
103
|
+
}
|
|
104
|
+
{
|
|
105
|
+
const p = 'noExtraDir';
|
|
106
|
+
if (!hasProp(configVikePrerender, p, 'boolean') && !hasProp(configVikePrerender, p, 'undefined'))
|
|
107
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
108
|
+
}
|
|
109
|
+
{
|
|
110
|
+
const p = 'disableAutoRun';
|
|
111
|
+
if (!hasProp(configVikePrerender, p, 'boolean') && !hasProp(configVikePrerender, p, 'undefined'))
|
|
112
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
113
|
+
}
|
|
114
|
+
{
|
|
115
|
+
const p = 'parallel';
|
|
116
|
+
if (!hasProp(configVikePrerender, p, 'boolean') &&
|
|
117
|
+
!hasProp(configVikePrerender, p, 'number') &&
|
|
118
|
+
!hasProp(configVikePrerender, p, 'undefined'))
|
|
119
|
+
return { prop: `prerender.${p}`, errMsg: 'should be a boolean or a number' };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getVikeConfig };
|
|
2
|
+
export { getVikeConfig2 };
|
|
2
3
|
export { reloadVikeConfig };
|
|
3
4
|
export { vikeConfigDependencies };
|
|
4
5
|
export { isVikeConfigFile };
|
|
@@ -11,6 +12,7 @@ import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../..
|
|
|
11
12
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
12
13
|
import type { ResolvedConfig } from 'vite';
|
|
13
14
|
import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
|
|
15
|
+
import type { VikeConfigGlobal } from './getVikeConfig/resolveVikeConfigGlobal.js';
|
|
14
16
|
type InterfaceFile = InterfaceConfigFile | InterfaceValueFile;
|
|
15
17
|
type InterfaceFileCommons = {
|
|
16
18
|
locationId: LocationId;
|
|
@@ -34,14 +36,14 @@ type ConfigName = string;
|
|
|
34
36
|
type VikeConfigObject = {
|
|
35
37
|
pageConfigs: PageConfigBuildTime[];
|
|
36
38
|
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
37
|
-
|
|
39
|
+
vikeConfigGlobal: VikeConfigGlobal;
|
|
38
40
|
};
|
|
39
41
|
declare const vikeConfigDependencies: Set<string>;
|
|
40
|
-
declare function reloadVikeConfig(
|
|
41
|
-
declare function getVikeConfig(config: ResolvedConfig,
|
|
42
|
-
|
|
43
|
-
tolerateInvalidConfig?: true;
|
|
42
|
+
declare function reloadVikeConfig(config: ResolvedConfig): void;
|
|
43
|
+
declare function getVikeConfig(config: ResolvedConfig, { doNotRestartViteOnError }?: {
|
|
44
|
+
doNotRestartViteOnError?: true;
|
|
44
45
|
}): Promise<VikeConfigObject>;
|
|
45
|
-
declare function
|
|
46
|
+
declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePluginOptions: unknown): Promise<VikeConfigObject>;
|
|
47
|
+
declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
|
|
46
48
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
47
49
|
declare function getConfigValueInterfaceFile(interfaceFile: InterfaceFile, configName: string): unknown;
|