vike 0.4.214 → 0.4.216
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/__internal/index.js +2 -2
- package/dist/cjs/node/api/build.js +14 -3
- package/dist/cjs/node/api/context.js +20 -0
- package/dist/cjs/node/api/dev.js +11 -3
- package/dist/cjs/node/api/onLoad.js +9 -0
- package/dist/cjs/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
- package/dist/cjs/node/api/prerender.js +11 -3
- package/dist/cjs/node/api/preview.js +11 -3
- package/dist/cjs/node/api/utils.js +22 -0
- package/dist/cjs/node/cli/entry.js +8 -8
- package/dist/cjs/node/cli/onLoad.js +2 -0
- package/dist/cjs/node/plugin/index.js +2 -3
- package/dist/cjs/node/plugin/onLoad.js +2 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -3
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -5
- package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +23 -1
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +0 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
- package/dist/cjs/node/plugin/plugins/previewConfig.js +0 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +32 -17
- package/dist/cjs/node/prerender/runPrerender.js +5 -4
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +6 -6
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage.js +4 -2
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
- package/dist/cjs/node/runtime-dev/index.js +32 -0
- package/dist/cjs/shared/page-configs/getConfigValue.js +2 -31
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +4 -4
- package/dist/cjs/shared/page-configs/getConfigValueTyped.js +32 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +135 -0
- package/dist/cjs/utils/isDocker.js +2 -2
- package/dist/cjs/utils/requireResolve.js +2 -2
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/node/api/build.d.ts +10 -3
- package/dist/esm/node/api/build.js +14 -3
- package/dist/esm/node/api/context.d.ts +5 -0
- package/dist/esm/node/api/context.js +19 -0
- package/dist/esm/node/api/dev.d.ts +11 -2
- package/dist/esm/node/api/dev.js +11 -3
- package/dist/esm/node/api/onLoad.d.ts +2 -0
- package/dist/esm/node/api/onLoad.js +7 -0
- package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
- package/dist/esm/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
- package/dist/esm/node/api/prerender.d.ts +9 -1
- package/dist/esm/node/api/prerender.js +11 -3
- package/dist/esm/node/api/preview.d.ts +11 -2
- package/dist/esm/node/api/preview.js +11 -3
- package/dist/esm/node/api/{APIOptions.d.ts → types.d.ts} +3 -1
- package/dist/esm/node/api/utils.d.ts +2 -0
- package/dist/esm/node/api/utils.js +6 -0
- package/dist/esm/node/cli/entry.js +8 -8
- package/dist/esm/node/cli/onLoad.js +2 -0
- package/dist/esm/node/cli/parseCli.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +3 -4
- package/dist/esm/node/plugin/onLoad.js +1 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -3
- package/dist/esm/node/plugin/plugins/buildConfig.js +7 -6
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +23 -1
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -4
- 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 +10 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
- package/dist/esm/node/plugin/plugins/previewConfig.js +1 -2
- package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +34 -19
- package/dist/esm/node/prerender/runPrerender.d.ts +5 -3
- package/dist/esm/node/prerender/runPrerender.js +6 -5
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext.js +7 -7
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage.js +5 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
- package/dist/esm/node/runtime-dev/index.d.ts +3 -0
- package/dist/esm/node/runtime-dev/index.js +6 -0
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +2 -8
- package/dist/esm/shared/page-configs/getConfigValue.js +1 -27
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +2 -3
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/esm/shared/page-configs/getConfigValueTyped.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueTyped.js +27 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.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.d.ts +20 -0
- package/dist/esm/utils/assertSetup.js +130 -0
- package/dist/esm/utils/isDocker.js +1 -1
- 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/utils/assertIsNotProductionRuntime.js +0 -62
- package/dist/cjs/utils/assertNodeEnv.js +0 -106
- package/dist/esm/node/api/enhanceViteConfig.d.ts +0 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
- package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
- package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
- package/dist/esm/utils/assertNodeEnv.js +0 -103
- /package/dist/cjs/node/api/{APIOptions.js → types.js} +0 -0
- /package/dist/esm/node/api/{APIOptions.js → types.js} +0 -0
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export { prerender };
|
|
2
2
|
import { type PrerenderOptions } from '../prerender/runPrerender.js';
|
|
3
|
-
|
|
3
|
+
import type { ResolvedConfig } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike prerender`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#prerender
|
|
8
|
+
*/
|
|
9
|
+
declare function prerender(options?: PrerenderOptions): Promise<{
|
|
10
|
+
viteConfig: ResolvedConfig;
|
|
11
|
+
}>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export { prerender };
|
|
2
2
|
import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
|
|
3
|
-
import {
|
|
3
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike prerender`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#prerender
|
|
8
|
+
*/
|
|
4
9
|
async function prerender(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced } = await
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'prerender');
|
|
6
11
|
options.viteConfig = viteConfigEnhanced;
|
|
7
|
-
await runPrerenderFromAPI(options);
|
|
12
|
+
const { viteConfig } = await runPrerenderFromAPI(options);
|
|
13
|
+
return {
|
|
14
|
+
viteConfig
|
|
15
|
+
};
|
|
8
16
|
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
export { preview };
|
|
2
|
-
import type
|
|
3
|
-
|
|
2
|
+
import { type ResolvedConfig, type PreviewServer } from 'vite';
|
|
3
|
+
import type { APIOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike preview`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#preview
|
|
8
|
+
*/
|
|
9
|
+
declare function preview(options?: APIOptions): Promise<{
|
|
10
|
+
viteServer: PreviewServer;
|
|
11
|
+
viteConfig: ResolvedConfig;
|
|
12
|
+
}>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export { preview };
|
|
2
|
-
import {
|
|
2
|
+
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { preview as previewVite } from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Programmatically trigger `$ vike preview`
|
|
6
|
+
*
|
|
7
|
+
* https://vike.dev/api#preview
|
|
8
|
+
*/
|
|
4
9
|
async function preview(options = {}) {
|
|
5
|
-
const { viteConfigEnhanced } = await
|
|
10
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'preview');
|
|
6
11
|
const server = await previewVite(viteConfigEnhanced);
|
|
7
|
-
return
|
|
12
|
+
return {
|
|
13
|
+
viteServer: server,
|
|
14
|
+
viteConfig: server.config
|
|
15
|
+
};
|
|
8
16
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { APIOptions };
|
|
1
|
+
export type { APIOptions };
|
|
2
|
+
export type { Operation };
|
|
2
3
|
import type { InlineConfig } from 'vite';
|
|
3
4
|
type APIOptions = {
|
|
4
5
|
/**
|
|
@@ -8,3 +9,4 @@ type APIOptions = {
|
|
|
8
9
|
*/
|
|
9
10
|
viteConfig?: InlineConfig;
|
|
10
11
|
};
|
|
12
|
+
type Operation = 'build' | 'dev' | 'preview' | 'prerender';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Utils needed by Vike's API
|
|
2
|
+
// We call onLoad() here so that it's called even when only a subset of the API is loaded. (Making the assert() calls inside onLoad() a lot stronger.)
|
|
3
|
+
import { onLoad } from './onLoad.js';
|
|
4
|
+
onLoad();
|
|
5
|
+
export * from '../../utils/assert.js';
|
|
6
|
+
export * from '../../utils/getGlobalObject.js';
|
|
@@ -21,16 +21,16 @@ async function cli() {
|
|
|
21
21
|
async function cmdDev() {
|
|
22
22
|
const startTime = performance.now();
|
|
23
23
|
try {
|
|
24
|
-
const
|
|
25
|
-
await
|
|
26
|
-
const info =
|
|
24
|
+
const { viteServer } = await dev();
|
|
25
|
+
await viteServer.listen();
|
|
26
|
+
const info = viteServer.config.logger.info;
|
|
27
27
|
const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
|
|
28
28
|
const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
|
|
29
29
|
info(` ${pc.yellow(`${pc.bold(projectInfo.projectName)} v${projectInfo.projectVersion}`)} ${startupDurationString}\n`, {
|
|
30
30
|
clear: !hasExistingLogs
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
viteServer.printUrls();
|
|
33
|
+
viteServer.bindCLIShortcuts({ print: true });
|
|
34
34
|
}
|
|
35
35
|
catch (err) {
|
|
36
36
|
console.error(pc.red(`Error while starting dev server:`));
|
|
@@ -52,9 +52,9 @@ async function cmdBuild() {
|
|
|
52
52
|
}
|
|
53
53
|
async function cmdPreview() {
|
|
54
54
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const { viteServer } = await preview();
|
|
56
|
+
viteServer.printUrls();
|
|
57
|
+
viteServer.bindCLIShortcuts({ print: true });
|
|
58
58
|
}
|
|
59
59
|
catch (err) {
|
|
60
60
|
console.error(pc.red(`Error while starting preview server:`));
|
|
@@ -4,7 +4,7 @@ export { plugin };
|
|
|
4
4
|
export { plugin as ssr };
|
|
5
5
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
6
|
import { version } from 'vite';
|
|
7
|
-
import {
|
|
7
|
+
import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
|
|
8
8
|
import { buildConfig } from './plugins/buildConfig.js';
|
|
9
9
|
import { previewConfig } from './plugins/previewConfig.js';
|
|
10
10
|
import { autoFullBuild } from './plugins/autoFullBuild.js';
|
|
@@ -28,8 +28,7 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
|
|
|
28
28
|
import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
|
|
29
29
|
import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
|
|
30
30
|
import { vite6HmrRegressionWorkaround } from './plugins/vite6HmrRegressionWorkaround.js';
|
|
31
|
-
|
|
32
|
-
markEnvAsVikePluginLoaded();
|
|
31
|
+
markSetup_vikeVitePlugin();
|
|
33
32
|
assertViteVersion();
|
|
34
33
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
35
34
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
@@ -48,7 +47,7 @@ function plugin(vikeConfig) {
|
|
|
48
47
|
...extractAssetsPlugin(),
|
|
49
48
|
extractExportNamesPlugin(),
|
|
50
49
|
suppressRollupWarning(),
|
|
51
|
-
setGlobalContext(),
|
|
50
|
+
...setGlobalContext(),
|
|
52
51
|
...importBuild(),
|
|
53
52
|
baseUrls(vikeConfig),
|
|
54
53
|
envVarsPlugin(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { onLoad };
|
|
2
2
|
import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
|
|
3
|
-
import { assertIsNotProductionRuntime } from '../../utils/
|
|
3
|
+
import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
|
|
4
4
|
import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
|
|
5
5
|
function onLoad() {
|
|
6
6
|
assertIsNotBrowser();
|
|
@@ -9,9 +9,6 @@ import pc from '@brillout/picocolors';
|
|
|
9
9
|
import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
|
|
10
10
|
import { manifestTempFile } from './buildConfig.js';
|
|
11
11
|
let forceExit = false;
|
|
12
|
-
assertWarning(!isViteCliCall(), `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
|
|
13
|
-
onlyOnce: true
|
|
14
|
-
});
|
|
15
12
|
function autoFullBuild() {
|
|
16
13
|
let config;
|
|
17
14
|
let configVike;
|
|
@@ -2,7 +2,7 @@ export { buildConfig };
|
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
4
|
export { manifestTempFile };
|
|
5
|
-
import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs,
|
|
5
|
+
import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, onSetupBuild, assertIsNpmPackageImport } from '../utils.js';
|
|
6
6
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { findPageFiles } from '../shared/findPageFiles.js';
|
|
8
8
|
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
@@ -27,14 +27,14 @@ function buildConfig() {
|
|
|
27
27
|
let config;
|
|
28
28
|
return [
|
|
29
29
|
{
|
|
30
|
-
name: 'vike:buildConfig:
|
|
30
|
+
name: 'vike:buildConfig:post',
|
|
31
31
|
apply: 'build',
|
|
32
32
|
enforce: 'post',
|
|
33
33
|
configResolved: {
|
|
34
34
|
order: 'post',
|
|
35
35
|
async handler(config_) {
|
|
36
36
|
config = config_;
|
|
37
|
-
|
|
37
|
+
onSetupBuild();
|
|
38
38
|
assertRollupInput(config);
|
|
39
39
|
const entries = await getEntries(config);
|
|
40
40
|
assert(Object.keys(entries).length > 0);
|
|
@@ -57,7 +57,7 @@ function buildConfig() {
|
|
|
57
57
|
config: {
|
|
58
58
|
order: 'post',
|
|
59
59
|
handler(config) {
|
|
60
|
-
|
|
60
|
+
onSetupBuild();
|
|
61
61
|
isSsrBuild = viteIsSSR(config);
|
|
62
62
|
return {
|
|
63
63
|
build: {
|
|
@@ -69,14 +69,15 @@ function buildConfig() {
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
buildStart() {
|
|
72
|
-
|
|
72
|
+
onSetupBuild();
|
|
73
73
|
},
|
|
74
74
|
async closeBundle() {
|
|
75
|
+
onSetupBuild();
|
|
75
76
|
await fixServerAssets_assertCssTarget(config);
|
|
76
77
|
}
|
|
77
78
|
},
|
|
78
79
|
{
|
|
79
|
-
name: 'vike:buildConfig:
|
|
80
|
+
name: 'vike:buildConfig:pre',
|
|
80
81
|
apply: 'build',
|
|
81
82
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
82
83
|
// - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const pluginName = "vike:commonConfig
|
|
1
|
+
export declare const pluginName = "vike:commonConfig";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const pluginName = 'vike:commonConfig
|
|
1
|
+
export const pluginName = 'vike:commonConfig';
|
|
@@ -8,6 +8,8 @@ import path from 'path';
|
|
|
8
8
|
import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
|
|
9
9
|
import { pluginName } from './commonConfig/pluginName.js';
|
|
10
10
|
import { getEnvVarObject } from '../shared/getEnvVarObject.js';
|
|
11
|
+
import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
12
|
+
import { isVikeCliOrApi } from '../../api/context.js';
|
|
11
13
|
function commonConfig() {
|
|
12
14
|
return [
|
|
13
15
|
{
|
|
@@ -18,7 +20,7 @@ function commonConfig() {
|
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
{
|
|
21
|
-
name:
|
|
23
|
+
name: `${pluginName}:post`,
|
|
22
24
|
enforce: 'post',
|
|
23
25
|
configResolved: {
|
|
24
26
|
order: 'post',
|
|
@@ -30,6 +32,7 @@ function commonConfig() {
|
|
|
30
32
|
assertRollupInput(config);
|
|
31
33
|
assertResolveAlias(config);
|
|
32
34
|
assertEsm(config.root);
|
|
35
|
+
assertVikeCliOrApi(config);
|
|
33
36
|
}
|
|
34
37
|
},
|
|
35
38
|
config: {
|
|
@@ -93,3 +96,22 @@ function assertSingleInstance(config) {
|
|
|
93
96
|
const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
|
|
94
97
|
assertUsage(numberOfInstances === 1, `Vike's Vite plugin (${pc.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);
|
|
95
98
|
}
|
|
99
|
+
function assertVikeCliOrApi(config) {
|
|
100
|
+
if (isVikeCliOrApi())
|
|
101
|
+
return;
|
|
102
|
+
if (isViteCliCall()) {
|
|
103
|
+
assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
|
|
104
|
+
onlyOnce: true
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (config.server.middlewareMode) {
|
|
109
|
+
assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
110
|
+
onlyOnce: true
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
assertWarning(false, `Vite's JavaScript API is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
115
|
+
onlyOnce: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -3,7 +3,7 @@ export { logDockerHint };
|
|
|
3
3
|
import { determineOptimizeDeps } from './determineOptimizeDeps.js';
|
|
4
4
|
import { determineFsAllowList } from './determineFsAllowList.js';
|
|
5
5
|
import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
|
|
6
|
-
import { applyDev, assertWarning, isDocker
|
|
6
|
+
import { applyDev, assertWarning, isDocker } from '../../utils.js';
|
|
7
7
|
import { improveViteLogs } from '../../shared/loggerVite.js';
|
|
8
8
|
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
9
9
|
import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
|
|
@@ -65,9 +65,6 @@ function devConfig() {
|
|
|
65
65
|
improveViteLogs(config);
|
|
66
66
|
}
|
|
67
67
|
logDockerHint(config.server.host);
|
|
68
|
-
},
|
|
69
|
-
configureServer() {
|
|
70
|
-
markEnvAsViteDev();
|
|
71
68
|
}
|
|
72
69
|
},
|
|
73
70
|
{
|
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,
|
|
2
|
+
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, crawlWithGit: null | boolean): Promise<{
|
|
3
3
|
filePathAbsoluteUserRootDir: string;
|
|
4
4
|
}[]>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
import { assertPosixPath, assert,
|
|
2
|
+
import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs/promises';
|
|
5
5
|
import glob from 'fast-glob';
|
|
6
6
|
import { exec } from 'child_process';
|
|
7
7
|
import { promisify } from 'util';
|
|
8
|
-
import pc from '@brillout/picocolors';
|
|
9
8
|
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
|
|
10
9
|
const execA = promisify(exec);
|
|
11
10
|
const TOO_MANY_UNTRACKED_FILES = 5;
|
|
12
11
|
assertIsNotProductionRuntime();
|
|
13
12
|
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
14
13
|
let gitIsNotUsable = false;
|
|
15
|
-
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem,
|
|
14
|
+
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGit) {
|
|
16
15
|
assertPosixPath(userRootDir);
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
//*/
|
|
17
|
+
const outDirRelativeFromUserRootDir = null;
|
|
18
|
+
/*/
|
|
19
|
+
assertPosixPath(outDirAbsoluteFilesystem)
|
|
20
|
+
let outDirRelativeFromUserRootDir: string | null = path.posix.relative(userRootDir, outDirAbsoluteFilesystem)
|
|
19
21
|
if (outDirRelativeFromUserRootDir.startsWith('../')) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
23
|
+
outDirRelativeFromUserRootDir = null
|
|
22
24
|
}
|
|
25
|
+
//*/
|
|
23
26
|
assert(outDirRelativeFromUserRootDir === null ||
|
|
24
27
|
/* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
25
28
|
!outDirRelativeFromUserRootDir.startsWith('.') &&
|
|
@@ -27,7 +30,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
|
|
|
27
30
|
(!outDirRelativeFromUserRootDir.startsWith('./') &&
|
|
28
31
|
//
|
|
29
32
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
30
|
-
const timeBefore = new Date().getTime();
|
|
31
33
|
// Crawl
|
|
32
34
|
let files = [];
|
|
33
35
|
const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
@@ -43,18 +45,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
|
|
|
43
45
|
}
|
|
44
46
|
// Filter build files
|
|
45
47
|
files = files.filter((filePath) => !isTemporaryBuildFile(filePath));
|
|
46
|
-
// Check performance
|
|
47
|
-
{
|
|
48
|
-
const timeAfter = new Date().getTime();
|
|
49
|
-
const timeSpent = timeAfter - timeBefore;
|
|
50
|
-
if (isDev) {
|
|
51
|
-
// We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
|
|
52
|
-
// Although, in dev, it's also competing for resources e.g. with Vite's `optimizeDeps`.
|
|
53
|
-
assertWarning(timeSpent < 3 * 1000, `Crawling your ${pc.cyan('+')} files took an unexpected long time (${humanizeTime(timeSpent)}). If you consistently get this warning, then consider reaching out on GitHub.`, {
|
|
54
|
-
onlyOnce: 'slow-crawling'
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
48
|
// Normalize
|
|
59
49
|
const plusFiles = files.map((filePath) => {
|
|
60
50
|
// Both `$ git-ls files` and fast-glob return posix paths
|
|
@@ -80,8 +80,8 @@ async function isV1Design(config, isDev) {
|
|
|
80
80
|
const isV1Design = pageConfigs.length > 0;
|
|
81
81
|
return isV1Design;
|
|
82
82
|
}
|
|
83
|
-
async function loadInterfaceFiles(userRootDir, outDirRoot,
|
|
84
|
-
const plusFiles = await findPlusFiles(userRootDir, outDirRoot,
|
|
83
|
+
async function loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit) {
|
|
84
|
+
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, crawlWithGit);
|
|
85
85
|
const configFiles = [];
|
|
86
86
|
const valueFiles = [];
|
|
87
87
|
plusFiles.forEach((f) => {
|
|
@@ -195,7 +195,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
195
195
|
let ret;
|
|
196
196
|
let err;
|
|
197
197
|
try {
|
|
198
|
-
ret = await loadVikeConfig(userRootDir, outDirRoot,
|
|
198
|
+
ret = await loadVikeConfig(userRootDir, outDirRoot, crawlWithGit);
|
|
199
199
|
}
|
|
200
200
|
catch (err_) {
|
|
201
201
|
hasError = true;
|
|
@@ -232,8 +232,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
-
async function loadVikeConfig(userRootDir, outDirRoot,
|
|
236
|
-
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot,
|
|
235
|
+
async function loadVikeConfig(userRootDir, outDirRoot, crawlWithGit) {
|
|
236
|
+
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit);
|
|
237
237
|
const importedFilesLoaded = {};
|
|
238
238
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
239
239
|
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
@@ -779,8 +779,8 @@ function getComputed(configValueSources, configDefinitions) {
|
|
|
779
779
|
});
|
|
780
780
|
return configValuesComputed;
|
|
781
781
|
}
|
|
782
|
-
async function findPlusFiles(userRootDir, outDirRoot,
|
|
783
|
-
const files = await crawlPlusFiles(userRootDir, outDirRoot,
|
|
782
|
+
async function findPlusFiles(userRootDir, outDirRoot, crawlWithGit) {
|
|
783
|
+
const files = await crawlPlusFiles(userRootDir, outDirRoot, crawlWithGit);
|
|
784
784
|
const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
|
|
785
785
|
return plusFiles;
|
|
786
786
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { previewConfig };
|
|
2
|
-
import { assertUsage, getOutDirs, resolveOutDir,
|
|
2
|
+
import { assertUsage, getOutDirs, resolveOutDir, applyPreview } from '../utils.js';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
|
|
@@ -29,7 +29,6 @@ function previewConfig() {
|
|
|
29
29
|
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
30
30
|
config.appType = 'mpa'
|
|
31
31
|
*/
|
|
32
|
-
markEnvAsVitePreview();
|
|
33
32
|
return () => {
|
|
34
33
|
assertDist();
|
|
35
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'`.
|
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
export { setGlobalContext };
|
|
2
|
-
import {
|
|
3
|
-
import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck } from '../utils.js';
|
|
2
|
+
import { setGlobalContext_isViteDev, setGlobalContext_viteDevServer, setGlobalContext_viteConfig } from '../../runtime/globalContext.js';
|
|
3
|
+
import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck, markSetup_isViteDev, markSetup_viteDevServer, markSetup_vitePreviewServer } from '../utils.js';
|
|
4
4
|
function setGlobalContext() {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
name: 'vike:setGlobalContext:pre',
|
|
8
|
+
enforce: 'pre',
|
|
9
|
+
configureServer: {
|
|
10
|
+
order: 'pre',
|
|
11
|
+
handler(viteDevServer) {
|
|
12
|
+
setGlobalContext_viteDevServer(viteDevServer);
|
|
13
|
+
markSetup_viteDevServer();
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
configurePreviewServer() {
|
|
17
|
+
markSetup_vitePreviewServer();
|
|
18
|
+
},
|
|
19
|
+
config: {
|
|
20
|
+
order: 'pre',
|
|
21
|
+
handler(_, env) {
|
|
22
|
+
const isViteDev = isDevCheck(env);
|
|
23
|
+
setGlobalContext_isViteDev(isViteDev);
|
|
24
|
+
markSetup_isViteDev(isViteDev);
|
|
25
|
+
}
|
|
12
26
|
}
|
|
13
27
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
{
|
|
29
|
+
name: 'vike:setGlobalContext:post',
|
|
30
|
+
enforce: 'post',
|
|
31
|
+
configResolved: {
|
|
32
|
+
order: 'post',
|
|
33
|
+
handler(config) {
|
|
34
|
+
const { outDirRoot } = getOutDirs(config);
|
|
35
|
+
assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
36
|
+
setGlobalContext_viteConfig(config, outDirRoot);
|
|
37
|
+
}
|
|
18
38
|
}
|
|
19
|
-
},
|
|
20
|
-
configResolved(config) {
|
|
21
|
-
const { outDirRoot } = getOutDirs(config);
|
|
22
|
-
assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
23
|
-
setGlobalContext_viteConfig(config, outDirRoot);
|
|
24
39
|
}
|
|
25
|
-
|
|
40
|
+
];
|
|
26
41
|
}
|
|
@@ -4,8 +4,8 @@ export { runPrerenderFromAutoRun };
|
|
|
4
4
|
export { runPrerender_forceExit };
|
|
5
5
|
export type { PrerenderOptions };
|
|
6
6
|
import '../runtime/page-files/setup.js';
|
|
7
|
-
import type { InlineConfig } from 'vite';
|
|
8
|
-
import type { APIOptions } from '../api/
|
|
7
|
+
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
8
|
+
import type { APIOptions } from '../api/types.js';
|
|
9
9
|
type PrerenderOptions = APIOptions & {
|
|
10
10
|
/** Initial `pageContext` values */
|
|
11
11
|
pageContextInit?: Record<string, unknown>;
|
|
@@ -26,7 +26,9 @@ type PrerenderOptions = APIOptions & {
|
|
|
26
26
|
/** @deprecated */
|
|
27
27
|
base?: string;
|
|
28
28
|
};
|
|
29
|
-
declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<
|
|
29
|
+
declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<{
|
|
30
|
+
viteConfig: ResolvedConfig;
|
|
31
|
+
}>;
|
|
30
32
|
declare function runPrerenderFromCLIPrerenderCommand(): Promise<void>;
|
|
31
33
|
declare function runPrerenderFromAutoRun(viteConfig: InlineConfig, forceExit: boolean): Promise<void>;
|
|
32
34
|
declare function runPrerender_forceExit(): void;
|
|
@@ -5,7 +5,7 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject,
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, pLimit, isArray, changeEnumerable, onSetupPrerender } from './utils.js';
|
|
9
9
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { cpus } from 'os';
|
|
@@ -28,15 +28,15 @@ import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVik
|
|
|
28
28
|
import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
|
|
29
29
|
import { executeHook, isUserHookError } from '../../shared/hooks/executeHook.js';
|
|
30
30
|
import { getConfigValueBuildTime } from '../../shared/page-configs/getConfigValueBuildTime.js';
|
|
31
|
-
import {
|
|
31
|
+
import { prepareViteApiCall } from '../api/prepareViteApiCall.js';
|
|
32
32
|
async function runPrerenderFromAPI(options = {}) {
|
|
33
|
-
await runPrerender(options, 'prerender()');
|
|
33
|
+
return await runPrerender(options, 'prerender()');
|
|
34
34
|
// - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
|
|
35
35
|
// - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
|
|
36
36
|
}
|
|
37
37
|
async function runPrerenderFromCLIPrerenderCommand() {
|
|
38
38
|
try {
|
|
39
|
-
const { viteConfigEnhanced } = await
|
|
39
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(undefined, 'prerender');
|
|
40
40
|
await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
|
|
41
41
|
}
|
|
42
42
|
catch (err) {
|
|
@@ -61,13 +61,13 @@ async function runPrerenderFromAutoRun(viteConfig, forceExit) {
|
|
|
61
61
|
}
|
|
62
62
|
async function runPrerender(options = {}, standaloneTrigger) {
|
|
63
63
|
checkOutdatedOptions(options);
|
|
64
|
+
onSetupPrerender();
|
|
64
65
|
setGlobalContext_isPrerendering();
|
|
65
66
|
getHook_setIsPrerenderering();
|
|
66
67
|
const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
|
|
67
68
|
if (logLevel === 'info') {
|
|
68
69
|
console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
|
|
69
70
|
}
|
|
70
|
-
handleNodeEnv_prerender();
|
|
71
71
|
await disableReactStreaming();
|
|
72
72
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
73
73
|
assertLoadedConfig(viteConfig, options);
|
|
@@ -115,6 +115,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
115
115
|
console.log(`${pc.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
|
|
116
116
|
}
|
|
117
117
|
warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderContext, partial);
|
|
118
|
+
return { viteConfig };
|
|
118
119
|
}
|
|
119
120
|
async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
|
|
120
121
|
// V1 design
|
|
@@ -9,7 +9,7 @@ export * from '../../utils/isPropertyGetter.js';
|
|
|
9
9
|
export * from '../../utils/filesystemPathHandling.js';
|
|
10
10
|
export * from '../../utils/urlToFile.js';
|
|
11
11
|
export * from '../../utils/isPlainObject.js';
|
|
12
|
-
export * from '../../utils/
|
|
12
|
+
export * from '../../utils/assertSetup.js';
|
|
13
13
|
export * from '../../utils/pLimit.js';
|
|
14
14
|
export * from '../../utils/isFilePathAbsoluteFilesystem.js';
|
|
15
15
|
export * from '../../utils/isArray.js';
|
|
@@ -11,7 +11,7 @@ export * from '../../utils/isPropertyGetter.js';
|
|
|
11
11
|
export * from '../../utils/filesystemPathHandling.js';
|
|
12
12
|
export * from '../../utils/urlToFile.js';
|
|
13
13
|
export * from '../../utils/isPlainObject.js';
|
|
14
|
-
export * from '../../utils/
|
|
14
|
+
export * from '../../utils/assertSetup.js';
|
|
15
15
|
export * from '../../utils/pLimit.js';
|
|
16
16
|
export * from '../../utils/isFilePathAbsoluteFilesystem.js';
|
|
17
17
|
export * from '../../utils/isArray.js';
|
|
@@ -9,7 +9,7 @@ export { initGlobalContext_runPrerender };
|
|
|
9
9
|
export { initGlobalContext_getGlobalContextAsync };
|
|
10
10
|
export { setGlobalContext_viteDevServer };
|
|
11
11
|
export { setGlobalContext_viteConfig };
|
|
12
|
-
export {
|
|
12
|
+
export { setGlobalContext_isViteDev };
|
|
13
13
|
export { setGlobalContext_isPrerendering };
|
|
14
14
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
15
15
|
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
@@ -52,7 +52,7 @@ declare function getGlobalContextSync(): GlobalContextPublic;
|
|
|
52
52
|
declare function getGlobalContextAsync(isProduction: boolean): Promise<GlobalContextPublic>;
|
|
53
53
|
declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): void;
|
|
54
54
|
declare function setGlobalContext_viteConfig(viteConfig: ResolvedConfig, outDirRoot: string): void;
|
|
55
|
-
declare function
|
|
55
|
+
declare function setGlobalContext_isViteDev(isViteDev: boolean): void;
|
|
56
56
|
declare function setGlobalContext_isPrerendering(): void;
|
|
57
57
|
declare function getViteDevServer(): ViteDevServer | null;
|
|
58
58
|
declare function getViteConfig(): ResolvedConfig | null;
|