vike 0.4.219 → 0.4.220-commit-9a798ce
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 +23 -58
- package/dist/cjs/node/api/context.js +6 -8
- package/dist/cjs/node/api/prepareViteApiCall.js +6 -7
- package/dist/cjs/node/api/utils.js +1 -1
- package/dist/cjs/node/cli/context.js +16 -0
- package/dist/cjs/node/cli/entry.js +2 -0
- package/dist/cjs/node/cli/utils.js +1 -0
- package/dist/cjs/{utils → node/plugin}/getOutDirs.js +11 -11
- package/dist/cjs/node/plugin/index.js +1 -7
- package/dist/cjs/node/plugin/onLoad.js +6 -1
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +43 -31
- package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -3
- package/dist/cjs/node/plugin/plugins/buildEntry/index.js +24 -21
- package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -8
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +158 -176
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
- package/dist/cjs/node/plugin/plugins/previewConfig.js +3 -4
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/prerender/context.js +26 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -0
- package/dist/cjs/node/prerender/runPrerender.js +64 -37
- package/dist/cjs/node/prerender/utils.js +3 -2
- package/dist/cjs/node/runtime/globalContext.js +44 -58
- package/dist/cjs/node/runtime/page-files/setup.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
- package/dist/cjs/node/runtime/renderPage.js +10 -5
- package/dist/cjs/node/runtime/utils.js +3 -2
- package/dist/cjs/node/shared/resolveBase.js +9 -0
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +15 -1
- package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
- package/dist/cjs/utils/findFile.js +3 -3
- package/dist/cjs/utils/isDev.js +4 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- package/dist/cjs/utils/requireResolve.js +3 -3
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +23 -18
- package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/index.js +0 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +3 -4
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -62
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +15 -15
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/normalizeClientSideUrl.js +2 -3
- package/dist/esm/node/api/build.d.ts +1 -6
- package/dist/esm/node/api/build.js +20 -25
- package/dist/esm/node/api/context.d.ts +4 -4
- package/dist/esm/node/api/context.js +6 -9
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
- package/dist/esm/node/api/prepareViteApiCall.js +7 -8
- package/dist/esm/node/api/utils.d.ts +1 -1
- package/dist/esm/node/api/utils.js +1 -1
- package/dist/esm/node/cli/context.d.ts +5 -0
- package/dist/esm/node/cli/context.js +14 -0
- package/dist/esm/node/cli/entry.js +2 -0
- package/dist/esm/node/cli/parseCli.d.ts +3 -1
- package/dist/esm/node/cli/utils.d.ts +1 -0
- package/dist/esm/node/cli/utils.js +1 -0
- package/dist/esm/{utils → node/plugin}/getOutDirs.js +5 -5
- package/dist/esm/node/plugin/index.d.ts +29 -1
- package/dist/esm/node/plugin/index.js +2 -8
- package/dist/esm/node/plugin/onLoad.js +7 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +43 -31
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +7 -4
- package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/buildEntry/index.js +25 -22
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +8 -2
- package/dist/esm/node/plugin/plugins/commonConfig.js +9 -6
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +159 -177
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
- package/dist/esm/node/plugin/plugins/previewConfig.js +3 -4
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/prerender/context.d.ts +9 -0
- package/dist/esm/node/prerender/context.js +24 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +5 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +23 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -1
- package/dist/esm/node/prerender/runPrerender.js +65 -38
- package/dist/esm/node/prerender/utils.d.ts +3 -2
- package/dist/esm/node/prerender/utils.js +3 -2
- package/dist/esm/node/runtime/globalContext.d.ts +15 -9
- package/dist/esm/node/runtime/globalContext.js +45 -59
- package/dist/esm/node/runtime/page-files/setup.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
- package/dist/esm/node/runtime/renderPage.js +10 -5
- package/dist/esm/node/runtime/utils.d.ts +3 -2
- package/dist/esm/node/runtime/utils.js +3 -2
- package/dist/esm/node/shared/resolveBase.d.ts +4 -1
- package/dist/esm/node/shared/resolveBase.js +9 -0
- package/dist/esm/shared/page-configs/Config.d.ts +76 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -16
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +1 -1
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +15 -1
- package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
- package/dist/esm/utils/catchInfiniteLoop.js +32 -0
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/isDev.js +4 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/makePublicCopy.d.ts +3 -0
- package/dist/esm/utils/makePublicCopy.js +30 -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/buildEntry/getVikeManifest.js +0 -17
- package/dist/cjs/node/prerender/isPrerenderAutoRunEnabled.js +0 -16
- package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
- package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
- package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.d.ts +0 -5
- package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.js +0 -14
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
- package/dist/esm/node/shared/assertPluginManifest.js +0 -18
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
- package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
- /package/dist/cjs/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
- /package/dist/esm/{utils → node/plugin}/getOutDirs.d.ts +0 -0
- /package/dist/esm/utils/{filesystemPathHandling.d.ts → toPosixPath.d.ts} +0 -0
- /package/dist/esm/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
|
@@ -1,79 +1,82 @@
|
|
|
1
1
|
export { buildEntry };
|
|
2
|
-
export {
|
|
2
|
+
export { set_ASSETS_MANIFEST };
|
|
3
3
|
import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
4
|
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
5
|
-
import {
|
|
6
|
-
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
7
|
-
import { assert, getOutDirs, toPosixPath } from '../../utils.js';
|
|
5
|
+
import { assert, getOutDirs, projectInfo, toPosixPath } from '../../utils.js';
|
|
8
6
|
import fs from 'fs/promises';
|
|
9
7
|
import path from 'path';
|
|
10
8
|
import { createRequire } from 'module';
|
|
11
9
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
12
10
|
const importMetaUrl = import.meta.url;
|
|
13
11
|
const require_ = createRequire(importMetaUrl);
|
|
14
|
-
|
|
12
|
+
import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
|
|
13
|
+
import { assertBuildInfo, getViteConfigRuntime } from '../../../runtime/globalContext.js';
|
|
14
|
+
const ASSETS_MANIFEST = '__VITE_ASSETS_MANIFEST__';
|
|
15
15
|
function buildEntry() {
|
|
16
16
|
let config;
|
|
17
|
-
let vikeConfigGlobal;
|
|
18
17
|
return [
|
|
19
18
|
{
|
|
20
19
|
name: 'vike:buildEntry',
|
|
21
20
|
enforce: 'post',
|
|
22
21
|
async configResolved(config_) {
|
|
23
22
|
config = config_;
|
|
24
|
-
const vikeConfig = await getVikeConfig(config);
|
|
25
|
-
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
26
23
|
}
|
|
27
24
|
},
|
|
28
25
|
...serverProductionEntryPlugin({
|
|
29
26
|
getServerProductionEntry: () => {
|
|
30
|
-
return getServerProductionEntryCode(config
|
|
27
|
+
return getServerProductionEntryCode(config);
|
|
31
28
|
},
|
|
32
29
|
libraryName: 'Vike'
|
|
33
30
|
})
|
|
34
31
|
];
|
|
35
32
|
}
|
|
36
|
-
function getServerProductionEntryCode(config
|
|
33
|
+
function getServerProductionEntryCode(config) {
|
|
37
34
|
const importPath = getImportPath(config);
|
|
38
|
-
const
|
|
39
|
-
|
|
35
|
+
const buildInfo = {
|
|
36
|
+
versionAtBuildTime: projectInfo.projectVersion,
|
|
37
|
+
usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
|
|
38
|
+
viteConfigRuntime: getViteConfigRuntime(config)
|
|
39
|
+
};
|
|
40
|
+
assertBuildInfo(buildInfo);
|
|
41
|
+
// After the old design is removed, let's maybe simplify and move everything into a single virtual module
|
|
40
42
|
const importerCode = [
|
|
41
43
|
` import { setGlobalContext_buildEntry } from '${importPath}';`,
|
|
42
44
|
` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
|
|
43
45
|
` {`,
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
` const
|
|
46
|
+
// Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to setGlobalContext_buildEntry()
|
|
47
|
+
// - This workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
|
|
48
|
+
` const assetsManifest = ${ASSETS_MANIFEST};`,
|
|
49
|
+
` const buildInfo = ${JSON.stringify(buildInfo, null, 2)};`,
|
|
47
50
|
' setGlobalContext_buildEntry({',
|
|
48
51
|
` pageFiles,`,
|
|
49
52
|
` assetsManifest,`,
|
|
50
|
-
`
|
|
53
|
+
` buildInfo,`,
|
|
51
54
|
' });',
|
|
52
55
|
` }`,
|
|
53
56
|
''
|
|
54
57
|
].join('\n');
|
|
55
58
|
return importerCode;
|
|
56
59
|
}
|
|
57
|
-
/** Set the value of the
|
|
58
|
-
async function
|
|
60
|
+
/** Set the value of the ASSETS_MANIFEST constant inside dist/server/entry.js (or dist/server/index.js) */
|
|
61
|
+
async function set_ASSETS_MANIFEST(options, bundle) {
|
|
59
62
|
const { dir } = options;
|
|
60
63
|
assert(dir);
|
|
61
|
-
const chunkPath =
|
|
64
|
+
const chunkPath = find_ASSETS_MANIFEST(bundle);
|
|
62
65
|
const chunkFilePath = path.join(dir, chunkPath);
|
|
63
66
|
const assetsJsonFilePath = path.join(dir, '..', 'assets.json');
|
|
64
67
|
const [assetsJsonString, chunkFileContent] = await Promise.all([
|
|
65
68
|
await fs.readFile(assetsJsonFilePath, 'utf8'),
|
|
66
69
|
await fs.readFile(chunkFilePath, 'utf8')
|
|
67
70
|
]);
|
|
68
|
-
const serverEntryFileContentPatched = chunkFileContent.replace(
|
|
71
|
+
const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MANIFEST, assetsJsonString);
|
|
69
72
|
assert(serverEntryFileContentPatched !== chunkFileContent);
|
|
70
73
|
await fs.writeFile(chunkFilePath, serverEntryFileContentPatched);
|
|
71
74
|
}
|
|
72
|
-
function
|
|
75
|
+
function find_ASSETS_MANIFEST(bundle) {
|
|
73
76
|
let chunkPath;
|
|
74
77
|
for (const filePath in bundle) {
|
|
75
78
|
const chunk = bundle[filePath];
|
|
76
|
-
if ('code' in chunk && chunk.code.includes(
|
|
79
|
+
if ('code' in chunk && chunk.code.includes(ASSETS_MANIFEST)) {
|
|
77
80
|
assert(!chunkPath);
|
|
78
81
|
chunkPath = filePath;
|
|
79
82
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
|
-
import { type Plugin } from 'vite';
|
|
2
|
+
import { type InlineConfig, type Plugin } from 'vite';
|
|
3
3
|
import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
|
|
4
|
+
import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
|
|
4
5
|
declare module 'vite' {
|
|
5
6
|
interface UserConfig {
|
|
6
7
|
_isDev?: boolean;
|
|
7
8
|
_vikeVitePluginOptions?: unknown;
|
|
8
9
|
_root?: string;
|
|
9
|
-
|
|
10
|
+
_baseViteOriginal?: string;
|
|
11
|
+
_viteConfigEnhanced?: InlineConfig;
|
|
12
|
+
vike?: {
|
|
13
|
+
global: VikeConfigObject['global'];
|
|
14
|
+
prerenderContext?: PrerenderContextPublic;
|
|
15
|
+
};
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
18
|
declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
|
|
@@ -11,7 +11,8 @@ import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
|
11
11
|
import { isVikeCliOrApi } from '../../api/context.js';
|
|
12
12
|
import { getVikeConfig2 } from './importUserCode/v1-design/getVikeConfig.js';
|
|
13
13
|
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
|
|
14
|
-
import { temp_disablePrerenderAutoRun } from '../../prerender/
|
|
14
|
+
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
15
|
+
import { resolvePrerenderConfig } from '../../prerender/resolvePrerenderConfig.js';
|
|
15
16
|
const pluginName = 'vike:commonConfig';
|
|
16
17
|
function commonConfig(vikeVitePluginOptions) {
|
|
17
18
|
return [
|
|
@@ -30,9 +31,11 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
30
31
|
_isDev: isDev,
|
|
31
32
|
_root: root,
|
|
32
33
|
_vikeVitePluginOptions: vikeVitePluginOptions,
|
|
33
|
-
vike: vikeConfig,
|
|
34
|
-
// TODO/v1-release: remove
|
|
35
|
-
configVikePromise: Promise.resolve(
|
|
34
|
+
vike: { global: vikeConfig.global },
|
|
35
|
+
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
36
|
+
configVikePromise: Promise.resolve({
|
|
37
|
+
prerender: !!resolvePrerenderConfig(vikeConfig.global.config.prerender)
|
|
38
|
+
})
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -75,7 +78,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
75
78
|
// VITE_CONFIG
|
|
76
79
|
const configFromEnvVar = getEnvVarObject('VITE_CONFIG');
|
|
77
80
|
if (configFromEnvVar)
|
|
78
|
-
configFromVike = mergeConfig(
|
|
81
|
+
configFromVike = mergeConfig(configFromVike, configFromEnvVar);
|
|
79
82
|
return configFromVike;
|
|
80
83
|
}
|
|
81
84
|
}
|
|
@@ -142,7 +145,7 @@ function assertVikeCliOrApi(config) {
|
|
|
142
145
|
onlyOnce: true
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
|
-
// TODO/v1-release: remove
|
|
148
|
+
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
146
149
|
function temp_supportOldInterface(config) {
|
|
147
150
|
if (!('vitePluginSsr' in config))
|
|
148
151
|
return;
|
|
@@ -43,7 +43,8 @@ function extractAssetsPlugin() {
|
|
|
43
43
|
assertV1Design(vikeConfig.pageConfigs, true);
|
|
44
44
|
assert(false);
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// TODO/now: add meta.default
|
|
47
|
+
assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
47
48
|
assert(!viteIsSSR_options(options));
|
|
48
49
|
const importStatements = await getImportStatements(src);
|
|
49
50
|
const moduleNames = getImportedModules(importStatements);
|
|
@@ -76,7 +77,8 @@ function extractAssetsPlugin() {
|
|
|
76
77
|
if (!extractAssetsRE.test(importer)) {
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
// TODO/now: add meta.default
|
|
81
|
+
assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
80
82
|
let resolution = null;
|
|
81
83
|
try {
|
|
82
84
|
resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
2
|
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VikeConfigObject } from './v1-design/getVikeConfig.js';
|
|
4
4
|
declare function getVirtualFileImportUserCode(id: string, options: {
|
|
5
5
|
ssr?: boolean;
|
|
6
|
-
} | undefined,
|
|
6
|
+
} | undefined, vikeConfig: VikeConfigObject, config: ResolvedConfig, isDev: boolean): Promise<string>;
|
|
@@ -6,16 +6,17 @@ 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
|
-
|
|
9
|
+
import { resolvePrerenderConfig } from '../../../prerender/resolvePrerenderConfig.js';
|
|
10
|
+
async function getVirtualFileImportUserCode(id, options, vikeConfig, config, isDev) {
|
|
10
11
|
const idParsed = isVirtualFileIdImportUserCode(id);
|
|
11
12
|
assert(idParsed);
|
|
12
13
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
13
14
|
assert(isForClientSide === !viteIsSSR_options(options));
|
|
14
|
-
const isPrerendering = !!
|
|
15
|
-
const code = await getCode(config,
|
|
15
|
+
const isPrerendering = !!resolvePrerenderConfig(vikeConfig.global.config.prerender);
|
|
16
|
+
const code = await getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id);
|
|
16
17
|
return code;
|
|
17
18
|
}
|
|
18
|
-
async function getCode(config,
|
|
19
|
+
async function getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
|
|
19
20
|
const { command } = config;
|
|
20
21
|
assert(command === 'serve' || command === 'build');
|
|
21
22
|
const isBuild = command === 'build';
|
|
@@ -24,7 +25,7 @@ async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRoutin
|
|
|
24
25
|
{
|
|
25
26
|
const globRoots = getGlobRoots(config);
|
|
26
27
|
debugGlob('Glob roots: ', globRoots);
|
|
27
|
-
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
28
|
+
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, isPrerendering, config, isDev, id);
|
|
28
29
|
}
|
|
29
30
|
debugGlob(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
30
31
|
return content;
|
|
@@ -54,7 +55,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
58
|
+
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, isPrerendering, config, isDev, id) {
|
|
58
59
|
let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
|
|
59
60
|
|
|
60
61
|
export const pageFilesLazy = {};
|
|
@@ -86,7 +87,9 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
|
|
|
86
87
|
fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
|
-
|
|
90
|
+
// TODO/now: add meta.default
|
|
91
|
+
const includeAssetsImportedByServer = vikeConfig.global.config.includeAssetsImportedByServer ?? true;
|
|
92
|
+
if (includeAssetsImportedByServer && isForClientSide) {
|
|
90
93
|
fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
|
|
91
94
|
}
|
|
92
95
|
return fileContent;
|
|
@@ -12,12 +12,11 @@ import { logConfigInfo } from '../../shared/loggerNotProd.js';
|
|
|
12
12
|
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
13
13
|
function importUserCode() {
|
|
14
14
|
let config;
|
|
15
|
-
let
|
|
15
|
+
let vikeConfig;
|
|
16
16
|
return {
|
|
17
17
|
name: 'vike:importUserCode',
|
|
18
18
|
async configResolved(config_) {
|
|
19
|
-
|
|
20
|
-
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
19
|
+
vikeConfig = await getVikeConfig(config_);
|
|
21
20
|
config = config_;
|
|
22
21
|
// TODO/v1-release: remove
|
|
23
22
|
{
|
|
@@ -52,7 +51,7 @@ function importUserCode() {
|
|
|
52
51
|
return code;
|
|
53
52
|
}
|
|
54
53
|
if (isVirtualFileIdImportUserCode(id)) {
|
|
55
|
-
const code = await getVirtualFileImportUserCode(id, options,
|
|
54
|
+
const code = await getVirtualFileImportUserCode(id, options, vikeConfig, config, isDev);
|
|
56
55
|
return code;
|
|
57
56
|
}
|
|
58
57
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
|
-
export {
|
|
2
|
+
export { assertExtensionsRequire };
|
|
3
3
|
import { type InterfaceFile } from './getVikeConfig.js';
|
|
4
|
+
import { PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
4
5
|
declare function assertExtensionsConventions(interfaceFile: InterfaceFile): void;
|
|
5
|
-
declare function
|
|
6
|
+
declare function assertExtensionsRequire(pageConfig: PageConfigBuildTime): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
|
-
export {
|
|
2
|
+
export { assertExtensionsRequire };
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
4
|
import { isObjectOfStrings } from '../../../../../utils/isObjectOfStrings.js';
|
|
5
5
|
import { PROJECT_VERSION, assert, assertUsage, assertWarning, findPackageJson } from '../../../utils.js';
|
|
@@ -18,32 +18,33 @@ function assertConfigExportPath(interfaceFile) {
|
|
|
18
18
|
assert(!p.includes('node_modules'));
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
const name =
|
|
21
|
+
const name = getNameValue(interfaceFile);
|
|
22
22
|
assert(name); // already asserted in assertExtensionName()
|
|
23
23
|
const importPathAbsoluteExpected = `${name}/config`;
|
|
24
24
|
assertWarning(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${pc.bold(name)} is exported at ${pc.bold(importPathAbsolute)}, but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
|
|
25
25
|
}
|
|
26
26
|
function assertExtensionName(interfaceFile) {
|
|
27
27
|
const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
|
|
28
|
-
const name =
|
|
28
|
+
const name = getNameValue(interfaceFile);
|
|
29
29
|
assertUsage(name, `Vike extension name missing: the config ${filePathToShowToUser} must define the setting ${pc.cyan('name')}`);
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
31
|
+
function assertExtensionsRequire(pageConfig) {
|
|
32
|
+
const interfaceFilesRelevantList = Object.values(pageConfig.interfaceFiles).flat(1);
|
|
33
|
+
// Collect extensions
|
|
33
34
|
const extensions = {};
|
|
34
35
|
interfaceFilesRelevantList.forEach((interfaceFile) => {
|
|
35
|
-
const name =
|
|
36
|
+
const name = getNameValue(interfaceFile);
|
|
36
37
|
if (name) {
|
|
37
38
|
const version = getExtensionVersion(name, interfaceFile);
|
|
38
39
|
extensions[name] = version;
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
// Enforce
|
|
42
|
+
// Enforce `require`
|
|
42
43
|
interfaceFilesRelevantList.forEach((interfaceFile) => {
|
|
43
44
|
const require = getConfigRequireValue(interfaceFile);
|
|
44
45
|
if (!require)
|
|
45
46
|
return;
|
|
46
|
-
const name =
|
|
47
|
+
const name = getNameValue(interfaceFile);
|
|
47
48
|
const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
|
|
48
49
|
assertUsage(name, `Setting ${pc.bold('name')} is required for being able to use setting ${pc.bold('require')} in ${filePathToShowToUser}.`);
|
|
49
50
|
Object.entries(require).forEach(([reqName, reqVersion]) => {
|
|
@@ -67,7 +68,7 @@ function getConfigRequireValue(interfaceFile) {
|
|
|
67
68
|
assertUsage(isObjectOfStrings(require), `The setting ${pc.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${pc.bold('Record<string, string>')}).`);
|
|
68
69
|
return require;
|
|
69
70
|
}
|
|
70
|
-
function
|
|
71
|
+
function getNameValue(interfaceFile) {
|
|
71
72
|
const name = getConfigValueInterfaceFile(interfaceFile, 'name');
|
|
72
73
|
if (!name)
|
|
73
74
|
return null;
|
|
@@ -139,7 +139,12 @@ const configDefinitionsBuiltInAll = {
|
|
|
139
139
|
eager: true,
|
|
140
140
|
global: true
|
|
141
141
|
},
|
|
142
|
-
prerender: {
|
|
142
|
+
prerender: {
|
|
143
|
+
env: { config: true },
|
|
144
|
+
global: (value) => typeof value === 'object',
|
|
145
|
+
type: ['boolean', 'object'],
|
|
146
|
+
cumulative: true
|
|
147
|
+
},
|
|
143
148
|
vite: { env: { config: true }, global: true, cumulative: true, type: 'object' },
|
|
144
149
|
disableAutoFullBuild: {
|
|
145
150
|
env: { config: true },
|
|
@@ -151,8 +156,8 @@ const configDefinitionsBuiltInAll = {
|
|
|
151
156
|
]
|
|
152
157
|
},
|
|
153
158
|
includeAssetsImportedByServer: { env: { config: true }, global: true, type: 'boolean' },
|
|
154
|
-
baseAssets: { env: { config: true }, global: true, type: 'string' },
|
|
155
|
-
baseServer: { env: { config: true }, global: true, type: 'string' },
|
|
159
|
+
baseAssets: { env: { config: true, server: true }, global: true, type: 'string' },
|
|
160
|
+
baseServer: { env: { config: true, server: true }, global: true, type: 'string' },
|
|
156
161
|
redirects: { env: { server: true }, global: true, type: 'string{}', cumulative: true },
|
|
157
162
|
trailingSlash: { env: { server: true }, global: true, type: 'boolean' },
|
|
158
163
|
disableUrlNormalization: { env: { server: true }, global: true, type: 'boolean' }
|
|
@@ -8,8 +8,7 @@ export { getConfigValueInterfaceFile };
|
|
|
8
8
|
export type { VikeConfigObject };
|
|
9
9
|
export type { InterfaceValueFile };
|
|
10
10
|
export type { InterfaceFile };
|
|
11
|
-
export type {
|
|
12
|
-
export type { VikeVitePluginOptions };
|
|
11
|
+
export type { InterfaceFilesByLocationId };
|
|
13
12
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
14
13
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
15
14
|
import type { ResolvedConfig } from 'vite';
|
|
@@ -35,10 +34,10 @@ type InterfaceValueFile = InterfaceFileCommons & {
|
|
|
35
34
|
configName: string;
|
|
36
35
|
};
|
|
37
36
|
type ConfigName = string;
|
|
37
|
+
type InterfaceFilesByLocationId = Record<LocationId, InterfaceFile[]>;
|
|
38
38
|
type VikeConfigObject = {
|
|
39
39
|
pageConfigs: PageConfigBuildTime[];
|
|
40
40
|
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
41
|
-
vikeConfigGlobal: VikeConfigGlobal;
|
|
42
41
|
global: ReturnType<typeof getPageConfigUserFriendlyNew>;
|
|
43
42
|
};
|
|
44
43
|
declare const vikeConfigDependencies: Set<string>;
|
|
@@ -50,95 +49,3 @@ declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePlu
|
|
|
50
49
|
declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
|
|
51
50
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
52
51
|
declare function getConfigValueInterfaceFile(interfaceFile: InterfaceFile, configName: string): unknown;
|
|
53
|
-
type VikeConfigGlobal = {
|
|
54
|
-
prerender: false | {
|
|
55
|
-
noExtraDir: boolean;
|
|
56
|
-
parallel: boolean | number;
|
|
57
|
-
partial: boolean;
|
|
58
|
-
disableAutoRun: boolean;
|
|
59
|
-
};
|
|
60
|
-
disableAutoFullBuild: boolean | 'prerender' | null;
|
|
61
|
-
includeAssetsImportedByServer: boolean;
|
|
62
|
-
baseAssets: string | null;
|
|
63
|
-
baseServer: string | null;
|
|
64
|
-
trailingSlash: boolean;
|
|
65
|
-
disableUrlNormalization: boolean;
|
|
66
|
-
};
|
|
67
|
-
type VikeVitePluginOptions = {
|
|
68
|
-
/**
|
|
69
|
-
* Enable pre-rendering.
|
|
70
|
-
*
|
|
71
|
-
* https://vike.dev/pre-rendering
|
|
72
|
-
*
|
|
73
|
-
* @default false
|
|
74
|
-
*/
|
|
75
|
-
prerender?: boolean | {
|
|
76
|
-
/**
|
|
77
|
-
* Don't create a new directory for each HTML file.
|
|
78
|
-
*
|
|
79
|
-
* For example, generate `dist/client/about.html` instead of `dist/client/about/index.html`.
|
|
80
|
-
*
|
|
81
|
-
* @default false
|
|
82
|
-
*/
|
|
83
|
-
noExtraDir?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Number of concurrent pre-render jobs.
|
|
86
|
-
*
|
|
87
|
-
* Set to `false` to disable concurrency.
|
|
88
|
-
*
|
|
89
|
-
* @default os.cpus().length
|
|
90
|
-
*/
|
|
91
|
-
parallel?: boolean | number;
|
|
92
|
-
/**
|
|
93
|
-
* Allow only some of your pages to be pre-rendered.
|
|
94
|
-
*
|
|
95
|
-
* This setting doesn't affect the pre-rendering process: it merely suppresses the warnings when some of your pages cannot be pre-rendered.
|
|
96
|
-
|
|
97
|
-
* @default false
|
|
98
|
-
*/
|
|
99
|
-
partial?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Disable the automatic initiation of the pre-rendering process when running `$ vike build`.
|
|
102
|
-
*
|
|
103
|
-
* Use this if you want to programmatically initiate the pre-rendering process instead.
|
|
104
|
-
*
|
|
105
|
-
* https://vike.dev/api#prerender
|
|
106
|
-
*
|
|
107
|
-
* @default false
|
|
108
|
-
*/
|
|
109
|
-
disableAutoRun?: boolean;
|
|
110
|
-
};
|
|
111
|
-
/** @deprecated See https://vike.dev/disableAutoFullBuild */
|
|
112
|
-
disableAutoFullBuild?: boolean | 'prerender';
|
|
113
|
-
/** The Base URL of your server.
|
|
114
|
-
*
|
|
115
|
-
* https://vike.dev/base-url
|
|
116
|
-
*/
|
|
117
|
-
baseServer?: string;
|
|
118
|
-
/** The Base URL of your static assets.
|
|
119
|
-
*
|
|
120
|
-
* https://vike.dev/base-url
|
|
121
|
-
*/
|
|
122
|
-
baseAssets?: string;
|
|
123
|
-
/** @deprecated It's now `true` by default. You can remove this option. */
|
|
124
|
-
includeAssetsImportedByServer?: boolean;
|
|
125
|
-
/** Permanent redirections (HTTP status code 301)
|
|
126
|
-
*
|
|
127
|
-
* https://vike.dev/redirects
|
|
128
|
-
*/
|
|
129
|
-
redirects?: Record<string, string>;
|
|
130
|
-
/** Whether URLs should end with a trailing slash.
|
|
131
|
-
*
|
|
132
|
-
* https://vike.dev/url-normalization
|
|
133
|
-
*
|
|
134
|
-
* @default false
|
|
135
|
-
*/
|
|
136
|
-
trailingSlash?: boolean;
|
|
137
|
-
/** Disable automatic URL normalization.
|
|
138
|
-
*
|
|
139
|
-
* https://vike.dev/url-normalization
|
|
140
|
-
*
|
|
141
|
-
* @default false
|
|
142
|
-
*/
|
|
143
|
-
disableUrlNormalization?: boolean;
|
|
144
|
-
};
|