vike 0.4.219 → 0.4.220-commit-a9f46b8
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/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/node/plugin/plugins/autoFullBuild.js +32 -19
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +10 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
- package/dist/cjs/node/prerender/{isPrerenderAutoRunEnabled.js → context.js} +9 -1
- package/dist/cjs/node/prerender/runPrerender.js +55 -33
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +2 -22
- package/dist/cjs/node/runtime/page-files/setup.js +1 -1
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -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/isDev.js +2 -0
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- 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/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/node/plugin/plugins/autoFullBuild.js +31 -18
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +8 -2
- package/dist/esm/node/plugin/plugins/commonConfig.js +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
- package/dist/esm/node/prerender/{isPrerenderAutoRunEnabled.d.ts → context.d.ts} +4 -0
- package/dist/esm/node/prerender/{isPrerenderAutoRunEnabled.js → context.js} +9 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -1
- package/dist/esm/node/prerender/runPrerender.js +56 -34
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/globalContext.js +3 -23
- package/dist/esm/node/runtime/page-files/setup.js +1 -1
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +6 -3
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- 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/isDev.js +2 -0
- 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/package.json +1 -1
|
@@ -4,7 +4,7 @@ export { runPrerenderFromAutoRun };
|
|
|
4
4
|
export { runPrerender_forceExit };
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { route } from '../../shared/route/index.js';
|
|
7
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, pLimit, isArray, changeEnumerable, onSetupPrerender, isObject } from './utils.js';
|
|
7
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, pLimit, isArray, changeEnumerable, onSetupPrerender, isObject, makePublicCopy } from './utils.js';
|
|
8
8
|
import { prerenderPage, prerender404Page, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { cpus } from 'os';
|
|
@@ -27,6 +27,7 @@ import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
|
|
|
27
27
|
import { executeHook, isUserHookError } from '../../shared/hooks/executeHook.js';
|
|
28
28
|
import { getConfigValueBuildTime } from '../../shared/page-configs/getConfigValueBuildTime.js';
|
|
29
29
|
import { prepareViteApiCall } from '../api/prepareViteApiCall.js';
|
|
30
|
+
import { setContextIsPrerendering } from './context.js';
|
|
30
31
|
async function runPrerenderFromAPI(options = {}) {
|
|
31
32
|
return await runPrerender(options, 'prerender()');
|
|
32
33
|
// - 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.
|
|
@@ -46,16 +47,20 @@ async function runPrerenderFromCLIPrerenderCommand() {
|
|
|
46
47
|
runPrerender_forceExit();
|
|
47
48
|
}
|
|
48
49
|
async function runPrerenderFromAutoRun(viteConfig) {
|
|
50
|
+
let prerenderContextPublic;
|
|
49
51
|
try {
|
|
50
|
-
await runPrerender({ viteConfig });
|
|
52
|
+
const ret = await runPrerender({ viteConfig });
|
|
53
|
+
prerenderContextPublic = ret.prerenderContextPublic;
|
|
51
54
|
}
|
|
52
55
|
catch (err) {
|
|
53
56
|
console.error(err);
|
|
54
57
|
logErrorHint(err);
|
|
55
58
|
process.exit(1);
|
|
56
59
|
}
|
|
60
|
+
return { prerenderContextPublic };
|
|
57
61
|
}
|
|
58
62
|
async function runPrerender(options = {}, standaloneTrigger) {
|
|
63
|
+
setContextIsPrerendering();
|
|
59
64
|
checkOutdatedOptions(options);
|
|
60
65
|
onSetupPrerender();
|
|
61
66
|
setGlobalContext_isPrerendering();
|
|
@@ -82,35 +87,36 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
82
87
|
await initGlobalContext_runPrerender();
|
|
83
88
|
const globalContext = getGlobalContext();
|
|
84
89
|
globalContext.pageFilesAll.forEach(assertExportNames);
|
|
85
|
-
const prerenderContext = {
|
|
86
|
-
|
|
87
|
-
_urlHandler: null,
|
|
88
|
-
_noExtraDir: noExtraDir ?? false,
|
|
90
|
+
const prerenderContext = {
|
|
91
|
+
noExtraDir: noExtraDir ?? false,
|
|
89
92
|
pageContexts: [],
|
|
90
|
-
pageContextInit: options.pageContextInit ?? null
|
|
91
|
-
|
|
93
|
+
pageContextInit: options.pageContextInit ?? null,
|
|
94
|
+
prerenderedPageContexts: {},
|
|
95
|
+
output: []
|
|
96
|
+
};
|
|
92
97
|
const doNotPrerenderList = [];
|
|
93
98
|
await collectDoNoPrerenderList(vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit);
|
|
94
99
|
await callOnBeforePrerenderStartHooks(prerenderContext, concurrencyLimit, doNotPrerenderList);
|
|
95
100
|
await handlePagesWithStaticRoutes(prerenderContext, doNotPrerenderList, concurrencyLimit);
|
|
96
101
|
await callOnPrerenderStartHook(prerenderContext);
|
|
97
|
-
const prerenderedPageContexts = {};
|
|
98
102
|
let prerenderedCount = 0;
|
|
103
|
+
// Write files as soon as pages finish rendering (instead of writing all files at once only after all pages have rendered).
|
|
99
104
|
const onComplete = async (htmlFile) => {
|
|
100
105
|
prerenderedCount++;
|
|
101
106
|
if (htmlFile.pageId) {
|
|
102
|
-
prerenderedPageContexts[htmlFile.pageId] = htmlFile.pageContext;
|
|
107
|
+
prerenderContext.prerenderedPageContexts[htmlFile.pageId] = htmlFile.pageContext;
|
|
103
108
|
}
|
|
104
|
-
await writeFiles(htmlFile, root, outDirClient, options.onPagePrerender, logLevel);
|
|
109
|
+
await writeFiles(htmlFile, root, outDirClient, options.onPagePrerender, prerenderContext.output, logLevel);
|
|
105
110
|
};
|
|
106
111
|
await routeAndPrerender(prerenderContext, concurrencyLimit, onComplete);
|
|
107
|
-
warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerenderList);
|
|
108
|
-
await prerender404(
|
|
112
|
+
warnContradictoryNoPrerenderList(prerenderContext.prerenderedPageContexts, doNotPrerenderList);
|
|
113
|
+
await prerender404(prerenderContext, onComplete);
|
|
109
114
|
if (logLevel === 'info') {
|
|
110
115
|
console.log(`${pc.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
|
|
111
116
|
}
|
|
112
|
-
warnMissingPages(prerenderedPageContexts, doNotPrerenderList, partial);
|
|
113
|
-
|
|
117
|
+
warnMissingPages(prerenderContext.prerenderedPageContexts, doNotPrerenderList, partial);
|
|
118
|
+
const prerenderContextPublic = makePublic(prerenderContext);
|
|
119
|
+
return { viteConfig, prerenderContextPublic };
|
|
114
120
|
}
|
|
115
121
|
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, concurrencyLimit) {
|
|
116
122
|
// V1 design
|
|
@@ -301,7 +307,7 @@ function createPageContext(urlOriginal, prerenderContext) {
|
|
|
301
307
|
const pageContext = {
|
|
302
308
|
_urlHandler: null,
|
|
303
309
|
_urlRewrite: null,
|
|
304
|
-
_noExtraDir: prerenderContext.
|
|
310
|
+
_noExtraDir: prerenderContext.noExtraDir,
|
|
305
311
|
_prerenderContext: prerenderContext
|
|
306
312
|
};
|
|
307
313
|
const pageContextInit = {
|
|
@@ -387,17 +393,20 @@ async function callOnPrerenderStartHook(prerenderContext) {
|
|
|
387
393
|
const docLink = 'https://vike.dev/i18n#pre-rendering';
|
|
388
394
|
// Set `enumerable` to `false` to avoid computed URL properties from being iterated & copied in onPrerenderStart() hook, e.g. /examples/i18n/
|
|
389
395
|
const { restoreEnumerable, addPageContextComputedUrl } = makePageContextComputedUrlNonEnumerable(prerenderContext.pageContexts);
|
|
390
|
-
let result = await executeHook(() =>
|
|
391
|
-
|
|
396
|
+
let result = await executeHook(() => {
|
|
397
|
+
const prerenderContextPublic = makePublic(prerenderContext);
|
|
392
398
|
// TODO/v1-release: remove warning
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
399
|
+
Object.defineProperty(prerenderContextPublic, 'prerenderPageContexts', {
|
|
400
|
+
get() {
|
|
401
|
+
assertWarning(false, `prerenderPageContexts has been renamed pageContexts, see ${docLink}`, {
|
|
402
|
+
showStackTrace: true,
|
|
403
|
+
onlyOnce: true
|
|
404
|
+
});
|
|
405
|
+
return prerenderContext.pageContexts;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
return hookFn(prerenderContextPublic);
|
|
409
|
+
}, onPrerenderStartHook, null);
|
|
401
410
|
restoreEnumerable();
|
|
402
411
|
if (result === null || result === undefined) {
|
|
403
412
|
return;
|
|
@@ -504,7 +513,7 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
504
513
|
pageContext,
|
|
505
514
|
htmlString: documentHtml,
|
|
506
515
|
pageContextSerialized,
|
|
507
|
-
doNotCreateExtraDirectory: prerenderContext.
|
|
516
|
+
doNotCreateExtraDirectory: prerenderContext.noExtraDir,
|
|
508
517
|
pageId
|
|
509
518
|
});
|
|
510
519
|
})));
|
|
@@ -539,8 +548,8 @@ function warnMissingPages(prerenderedPageContexts, doNotPrerenderList, partial)
|
|
|
539
548
|
assertWarning(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, while no ${hookName}() hook returned any URL matching the page's route. You need to use a ${hookName}() hook (https://vike.dev/${hookName}) providing a list of URLs for ${pageAt} that should be pre-rendered. If you don't want to pre-render ${pageAt} then use the option prerender.partial (https://vike.dev/prerender#partial) to suppress this warning.`, { onlyOnce: true });
|
|
540
549
|
});
|
|
541
550
|
}
|
|
542
|
-
async function prerender404(
|
|
543
|
-
if (!Object.values(prerenderedPageContexts).find(({ urlOriginal }) => urlOriginal === '/404')) {
|
|
551
|
+
async function prerender404(prerenderContext, onComplete) {
|
|
552
|
+
if (!Object.values(prerenderContext.prerenderedPageContexts).find(({ urlOriginal }) => urlOriginal === '/404')) {
|
|
544
553
|
let result;
|
|
545
554
|
try {
|
|
546
555
|
result = await prerender404Page(prerenderContext.pageContextInit);
|
|
@@ -563,22 +572,23 @@ async function prerender404(prerenderedPageContexts, prerenderContext, onComplet
|
|
|
563
572
|
}
|
|
564
573
|
}
|
|
565
574
|
}
|
|
566
|
-
async function writeFiles({ urlOriginal, pageContext, htmlString, pageContextSerialized, doNotCreateExtraDirectory }, root, outDirClient, onPagePrerender, logLevel) {
|
|
575
|
+
async function writeFiles({ urlOriginal, pageContext, htmlString, pageContextSerialized, doNotCreateExtraDirectory }, root, outDirClient, onPagePrerender, output, logLevel) {
|
|
567
576
|
assert(urlOriginal.startsWith('/'));
|
|
568
577
|
const writeJobs = [
|
|
569
|
-
write(urlOriginal, pageContext, '
|
|
578
|
+
write(urlOriginal, pageContext, 'HTML', htmlString, root, outDirClient, doNotCreateExtraDirectory, onPagePrerender, output, logLevel)
|
|
570
579
|
];
|
|
571
580
|
if (pageContextSerialized !== null) {
|
|
572
|
-
writeJobs.push(write(urlOriginal, pageContext, '
|
|
581
|
+
writeJobs.push(write(urlOriginal, pageContext, 'JSON', pageContextSerialized, root, outDirClient, doNotCreateExtraDirectory, onPagePrerender, output, logLevel));
|
|
573
582
|
}
|
|
574
583
|
await Promise.all(writeJobs);
|
|
575
584
|
}
|
|
576
|
-
async function write(urlOriginal, pageContext,
|
|
585
|
+
async function write(urlOriginal, pageContext, fileType, fileContent, root, outDirClient, doNotCreateExtraDirectory, onPagePrerender, output, logLevel) {
|
|
577
586
|
let fileUrl;
|
|
578
|
-
if (
|
|
587
|
+
if (fileType === 'HTML') {
|
|
579
588
|
fileUrl = urlToFile(urlOriginal, '.html', doNotCreateExtraDirectory);
|
|
580
589
|
}
|
|
581
590
|
else {
|
|
591
|
+
assert(fileType === 'JSON');
|
|
582
592
|
fileUrl = getPageContextRequestUrl(urlOriginal);
|
|
583
593
|
}
|
|
584
594
|
assertPosixPath(fileUrl);
|
|
@@ -590,6 +600,12 @@ async function write(urlOriginal, pageContext, fileExtension, fileContent, root,
|
|
|
590
600
|
assertPosixPath(outDirClient);
|
|
591
601
|
assertPosixPath(filePathRelative);
|
|
592
602
|
const filePath = path.posix.join(outDirClient, filePathRelative);
|
|
603
|
+
output.push({
|
|
604
|
+
filePath,
|
|
605
|
+
fileType,
|
|
606
|
+
fileContent,
|
|
607
|
+
pageContext
|
|
608
|
+
});
|
|
593
609
|
if (onPagePrerender) {
|
|
594
610
|
const prerenderPageContext = {};
|
|
595
611
|
objectAssign(prerenderPageContext, pageContext);
|
|
@@ -758,3 +774,9 @@ prerenderConfig) {
|
|
|
758
774
|
assertUsage(false, `Setting ${pc.cyan(`prerender.${prop}`)} ${errMsg}`);
|
|
759
775
|
}
|
|
760
776
|
}
|
|
777
|
+
function makePublic(prerenderContext) {
|
|
778
|
+
const prerenderContextPublic = makePublicCopy(prerenderContext, 'prerenderContext', [
|
|
779
|
+
'pageContexts'
|
|
780
|
+
]);
|
|
781
|
+
return prerenderContextPublic;
|
|
782
|
+
}
|
|
@@ -16,7 +16,7 @@ export { setGlobalContext_isViteDev };
|
|
|
16
16
|
export { setGlobalContext_isPrerendering };
|
|
17
17
|
export { setGlobalContext_buildEntry };
|
|
18
18
|
export { clearGlobalContext };
|
|
19
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectAssign, objectReplace,
|
|
19
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectAssign, objectReplace, isObject, hasProp, debugGlob, getGlobalObject, genPromise, createDebugger, makePublicCopy } from './utils.js';
|
|
20
20
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
21
21
|
import { virtualFileIdImportUserCodeServer } from '../shared/virtual-files/virtualFileImportUserCode.js';
|
|
22
22
|
import { getPageFilesAll, setPageFiles, setPageFilesAsync } from '../../shared/getPageFiles/getPageFiles.js';
|
|
@@ -50,28 +50,8 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
50
50
|
return makePublic(globalContext);
|
|
51
51
|
}
|
|
52
52
|
function makePublic(globalContext) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
assetsManifest: globalContext.assetsManifest
|
|
56
|
-
};
|
|
57
|
-
// Add internals (and prepended _ prefix to their keys)
|
|
58
|
-
{
|
|
59
|
-
const publicKeys = Object.keys(globalContextPublic);
|
|
60
|
-
objectKeys(globalContext)
|
|
61
|
-
.filter((key) => !publicKeys.includes(key))
|
|
62
|
-
.forEach((key) => {
|
|
63
|
-
const keyPublic = `_${key}`;
|
|
64
|
-
Object.defineProperty(globalContextPublic, keyPublic, {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get() {
|
|
67
|
-
assertWarning(false, `Using internal globalContext.${keyPublic} which is discouraged: it may break in any minor version update. Instead, reach out on GitHub and elaborate your use case.`, {
|
|
68
|
-
onlyOnce: true
|
|
69
|
-
});
|
|
70
|
-
return globalContext[key];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
53
|
+
// TODO/now: add viteConfig and vikeConfig
|
|
54
|
+
const globalContextPublic = makePublicCopy(globalContext, 'globalContext', ['assetsManifest']);
|
|
75
55
|
return globalContextPublic;
|
|
76
56
|
}
|
|
77
57
|
function setGlobalContext_viteDevServer(viteDevServer) {
|
|
@@ -32,9 +32,12 @@ type PageConfigBase = {
|
|
|
32
32
|
type PageConfigRuntime = PageConfigBase & {
|
|
33
33
|
configValues: ConfigValues;
|
|
34
34
|
/** Load config values that are lazily loaded such as config.Page */
|
|
35
|
-
loadConfigValuesAll: () =>
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
loadConfigValuesAll: () => {
|
|
36
|
+
moduleId: string;
|
|
37
|
+
moduleExports: Promise<{
|
|
38
|
+
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
38
41
|
};
|
|
39
42
|
/** Same as PageConfigRuntime but also contains all lazily loaded config values such as config.Page */
|
|
40
43
|
type PageConfigRuntimeLoaded = PageConfigRuntime & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { loadConfigValues };
|
|
2
|
-
import { objectAssign } from '../utils.js';
|
|
2
|
+
import { assert, objectAssign } from '../utils.js';
|
|
3
3
|
import { parseConfigValuesSerialized } from './serialize/parsePageConfigs.js';
|
|
4
4
|
async function loadConfigValues(pageConfig, isDev) {
|
|
5
5
|
if ('isAllLoaded' in pageConfig &&
|
|
@@ -7,7 +7,11 @@ async function loadConfigValues(pageConfig, isDev) {
|
|
|
7
7
|
!isDev) {
|
|
8
8
|
return pageConfig;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const { moduleId, moduleExports } = pageConfig.loadConfigValuesAll();
|
|
11
|
+
const configValuesLoaded = await moduleExports;
|
|
12
|
+
// `configValuesLoaded` is sometimes `undefined` https://github.com/vikejs/vike/discussions/2092
|
|
13
|
+
if (!configValuesLoaded)
|
|
14
|
+
assert(false, { moduleExports, configValuesLoaded, moduleId });
|
|
11
15
|
const configValues = parseConfigValuesSerialized(configValuesLoaded.configValuesSerialized);
|
|
12
16
|
Object.assign(pageConfig.configValues, configValues);
|
|
13
17
|
objectAssign(pageConfig, { isAllLoaded: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.220-commit-a9f46b8";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.220-commit-a9f46b8';
|
|
@@ -116,7 +116,7 @@ function getEnvDescription() {
|
|
|
116
116
|
// https://github.com/cloudflare/workers-sdk/issues/7886
|
|
117
117
|
function assertNodeEnvIsNotUndefinedString() {
|
|
118
118
|
const nodeEnv = getNodeEnv();
|
|
119
|
-
assertWarning(nodeEnv !== 'undefined', `${pc.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${pc.cyan('process.env.NODE_ENV')}
|
|
119
|
+
assertWarning(nodeEnv !== 'undefined', `${pc.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${pc.cyan('process.env.NODE_ENV')} is allowed to be the *value* ${pc.cyan('undefined')} (i.e. ${pc.cyan('process.env.NODE_ENV===undefined')}) but it shouldn't be the *string* ${pc.cyan('"undefined"')} ${pc.underline('https://vike.dev/NODE_ENV')}`, { onlyOnce: true });
|
|
120
120
|
}
|
|
121
121
|
function isNodeEnvDev() {
|
|
122
122
|
const nodeEnv = getNodeEnv();
|
|
@@ -136,6 +136,20 @@ function getNodeEnv() {
|
|
|
136
136
|
catch {
|
|
137
137
|
return undefined;
|
|
138
138
|
}
|
|
139
|
+
/*
|
|
140
|
+
// Should we show the following warning? So far I don't think so because of the following. Maybe we can show it once we enable users to disable warnings.
|
|
141
|
+
// - The warning isn't always actionable, e.g. if it's a tool that dynamically sets `process.env.NODE_ENV`.
|
|
142
|
+
// - We assume that tools use `process.env.NODE_ENV` and not someting like `const { env } = process; env.NODE_ENV`. Thus, in practice, `val` overrides `val2` so having `val!==val2` isn't an issue.
|
|
143
|
+
{
|
|
144
|
+
const val2 = process.env['NODE' + '_ENV']
|
|
145
|
+
if (val2)
|
|
146
|
+
assertWarning(
|
|
147
|
+
val === val2,
|
|
148
|
+
`Dynamically setting process.env.NODE_ENV to ${val2} hasn't any effect because process.env.NODE_ENV is being statically replaced to ${val}.`,
|
|
149
|
+
{ onlyOnce: true }
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
//*/
|
|
139
153
|
return val;
|
|
140
154
|
}
|
|
141
155
|
function setNodeEnvProduction() {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { catchInfiniteLoop };
|
|
2
|
+
import { assert, assertWarning } from './assert.js';
|
|
3
|
+
const trackers = {};
|
|
4
|
+
function catchInfiniteLoop(functionName, maxNumberOfCalls = 100, withinSeconds = 5) {
|
|
5
|
+
// Init
|
|
6
|
+
const now = new Date();
|
|
7
|
+
let tracker = (trackers[functionName] ?? (trackers[functionName] = createTracker(now)));
|
|
8
|
+
// Reset
|
|
9
|
+
const elapsedTime = now.getTime() - tracker.start.getTime();
|
|
10
|
+
if (elapsedTime > withinSeconds * 1000)
|
|
11
|
+
tracker = trackers[functionName] = createTracker(now);
|
|
12
|
+
// Count
|
|
13
|
+
tracker.count++;
|
|
14
|
+
// Error
|
|
15
|
+
const msg = `[Infinite Loop] ${functionName} called ${tracker.count} times within ${withinSeconds} seconds`;
|
|
16
|
+
if (tracker.count > maxNumberOfCalls) {
|
|
17
|
+
assert(false, msg);
|
|
18
|
+
}
|
|
19
|
+
// Warning, at 50% threshold
|
|
20
|
+
if (!tracker.warned && tracker.count > maxNumberOfCalls * 0.5) {
|
|
21
|
+
// Warning is shown upon 10 calls a second, on average during 5 seconds, given the default parameters
|
|
22
|
+
assertWarning(false, msg, { onlyOnce: false });
|
|
23
|
+
tracker.warned = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function createTracker(now) {
|
|
27
|
+
const tracker = {
|
|
28
|
+
count: 0,
|
|
29
|
+
start: now
|
|
30
|
+
};
|
|
31
|
+
return tracker;
|
|
32
|
+
}
|
package/dist/esm/utils/isDev.js
CHANGED
|
@@ -5,6 +5,8 @@ import { assert } from './assert.js';
|
|
|
5
5
|
function isDevCheck(configEnv) {
|
|
6
6
|
const { isPreview, command } = configEnv;
|
|
7
7
|
// Released at vite@5.1.0 which is guaranteed with `assertVersion('Vite', version, '5.1.0')`
|
|
8
|
+
// - Release: https://github.com/vitejs/vite/blob/6f7466e6211027686f40ad7e4ce6ec8477414546/packages/vite/CHANGELOG.md#510-beta4-2024-01-26:~:text=fix(preview)%3A-,set%20isPreview%20true,-(%2315695)%20(93fce55
|
|
9
|
+
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/2120
|
|
8
10
|
assert(typeof isPreview === 'boolean');
|
|
9
11
|
return command === 'serve' && !isPreview;
|
|
10
12
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { makePublicCopy };
|
|
2
|
+
/** Prefix internal properties with `_` + show warning */
|
|
3
|
+
declare function makePublicCopy<Obj extends Record<string, unknown>, PropsPublic extends readonly (keyof Obj)[]>(obj: Obj, objName: string, propsPublic: PropsPublic, propsInternalNoWarning?: (keyof Obj)[]): Pick<Obj, PropsPublic[number]>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { makePublicCopy };
|
|
2
|
+
import { assertWarning } from './assert.js';
|
|
3
|
+
import { objectKeys } from './objectKeys.js';
|
|
4
|
+
/** Prefix internal properties with `_` + show warning */
|
|
5
|
+
function makePublicCopy(obj, objName, propsPublic, propsInternalNoWarning) {
|
|
6
|
+
const objPublic = {};
|
|
7
|
+
objectKeys(obj).forEach((key) => {
|
|
8
|
+
const val = obj[key];
|
|
9
|
+
if (propsPublic.includes(key)) {
|
|
10
|
+
objPublic[key] = val;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const keyPublic = key.startsWith('_') ? key : `_${key}`;
|
|
14
|
+
if (propsInternalNoWarning?.includes(key)) {
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
objPublic[keyPublic] = val;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
Object.defineProperty(objPublic, keyPublic, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get() {
|
|
22
|
+
assertWarning(false, `Using internal ${objName}.${keyPublic} which may break in any minor version update. Reach out on GitHub and elaborate your use case so that the Vike team can add official support for your use case.`, { onlyOnce: true });
|
|
23
|
+
return val;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return objPublic;
|
|
30
|
+
}
|