vike 0.4.143 → 0.4.144-commit-e40e9b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +19 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +228 -186
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -35
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +2 -3
- package/dist/cjs/node/prerender/runPrerender.js +18 -20
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/getExports.js +8 -11
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +10 -44
- package/dist/cjs/shared/hooks/getHook.js +3 -1
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/getExportPath.js +9 -10
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigs.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +56 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +65 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +58 -0
- package/dist/cjs/shared/page-configs/utils.js +65 -42
- package/dist/cjs/shared/route/loadPageRoutes.js +12 -15
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/getOutDirs.js +25 -18
- package/dist/cjs/utils/getValuePrintable.js +1 -1
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/{resolve.js → requireResolve.js} +3 -3
- package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -1
- package/dist/esm/__internal/index.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/index.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/index.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +20 -11
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +19 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +229 -187
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -32
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +2 -3
- package/dist/esm/node/prerender/runPrerender.js +20 -22
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/error-page.d.ts +3 -3
- package/dist/esm/shared/error-page.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/getExports.d.ts +3 -4
- package/dist/esm/shared/getPageFiles/getExports.js +7 -10
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +3 -1
- package/dist/esm/shared/page-configs/Config.d.ts +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +80 -73
- package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertExports.js +54 -0
- package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +9 -10
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +32 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.js +1 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +50 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +7 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +62 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +8 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +52 -0
- package/dist/esm/shared/page-configs/utils.d.ts +21 -14
- package/dist/esm/shared/page-configs/utils.js +64 -41
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +13 -16
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/types.d.ts +8 -6
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utils/getOutDirs.d.ts +0 -2
- package/dist/esm/utils/getOutDirs.js +24 -17
- package/dist/esm/utils/getValuePrintable.js +1 -1
- package/dist/esm/utils/objectAssign.js +3 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -0
- package/dist/esm/utils/{resolve.js → requireResolve.js} +2 -2
- package/dist/esm/utils/warnIfErrorIsNotObject.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +0 -19
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +0 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +0 -16
- package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
- package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- package/dist/esm/utils/resolve.d.ts +0 -2
- /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
|
@@ -3,7 +3,7 @@ import { isErrorPageId } from '../error-page.js';
|
|
|
3
3
|
import { assert, assertUsage, hasProp, slice } from './utils.js';
|
|
4
4
|
import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
|
|
5
5
|
import { isCallable } from '../utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/utils.js';
|
|
7
7
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
8
8
|
async function loadPageRoutes(
|
|
9
9
|
// TODO: remove all arguments and use GlobalContext instead
|
|
@@ -30,9 +30,8 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
30
30
|
const configName = 'route';
|
|
31
31
|
const configValue = getConfigValue(pageConfig, configName);
|
|
32
32
|
if (configValue) {
|
|
33
|
-
const definedAtInfo = getConfigDefinedAtInfo(pageConfig, configName);
|
|
34
33
|
const route = configValue.value;
|
|
35
|
-
const definedAt = getDefinedAtString(
|
|
34
|
+
const definedAt = getDefinedAtString(configValue, configName);
|
|
36
35
|
if (typeof route === 'string') {
|
|
37
36
|
pageRoute = {
|
|
38
37
|
pageId,
|
|
@@ -137,19 +136,17 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
137
136
|
function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
138
137
|
// V1 Design
|
|
139
138
|
if (pageConfigs.length > 0) {
|
|
140
|
-
if (pageConfigGlobal.onBeforeRoute) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return { onBeforeRouteHook, filesystemRoots: null };
|
|
152
|
-
}
|
|
139
|
+
if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
|
|
140
|
+
const configValue = pageConfigGlobal.configValues.onBeforeRoute;
|
|
141
|
+
const { value: hookFn } = configValue;
|
|
142
|
+
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
143
|
+
// TODO: use getConfigDefinedAtString()
|
|
144
|
+
assertUsage(isCallable(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
|
|
145
|
+
const onBeforeRouteHook = {
|
|
146
|
+
hookFilePath: hookFilePath,
|
|
147
|
+
onBeforeRoute: hookFn
|
|
148
|
+
};
|
|
149
|
+
return { onBeforeRouteHook, filesystemRoots: null };
|
|
153
150
|
}
|
|
154
151
|
return { onBeforeRouteHook: null, filesystemRoots: null };
|
|
155
152
|
}
|
|
@@ -7,7 +7,7 @@ import { assertRouteString, resolveRouteString } from './resolveRouteString.js';
|
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
assertIsNotBrowser(); // Don't bloat the client
|
|
9
9
|
// TODO/v1-release: update
|
|
10
|
-
const configSrc = '[vite.config.js >
|
|
10
|
+
const configSrc = '[vite.config.js > vike({ redirects })]';
|
|
11
11
|
function resolveRedirects(redirects, urlPathname) {
|
|
12
12
|
for (const [urlSource, urlTarget] of Object.entries(redirects)) {
|
|
13
13
|
const urlResolved = resolveRouteStringRedirect(urlSource, urlTarget, urlPathname);
|
|
@@ -20,6 +20,7 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAt)
|
|
|
20
20
|
result = {};
|
|
21
21
|
}
|
|
22
22
|
assertUsage(isPlainObject(result), `The Route Function ${routeDefinedAt} should return a boolean or a plain JavaScript object (but it's ${pc.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
|
|
23
|
+
// AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
|
|
23
24
|
if ('match' in result) {
|
|
24
25
|
const { match } = result;
|
|
25
26
|
assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${routeDefinedAt} should be a boolean.`);
|
|
@@ -12,18 +12,17 @@ import type { ConfigEntries, ExportsAll } from './getPageFiles/getExports.js';
|
|
|
12
12
|
import type { Config } from './page-configs/Config.js';
|
|
13
13
|
import type { PageContextConfig } from './page-configs/Config/PageContextConfig.js';
|
|
14
14
|
import type { AbortStatusCode } from './route/abort.js';
|
|
15
|
-
type PageContext = PageContextWithClientRouting;
|
|
16
|
-
type PageContextClient = PageContextClientWithClientRouting;
|
|
17
|
-
type PageContextWithClientRouting = PageContextClientWithClientRouting | PageContextServer;
|
|
18
|
-
type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
|
|
19
15
|
type PageContextServer = PageContextBuiltInServer & Vike.PageContext;
|
|
20
|
-
type
|
|
16
|
+
type PageContext = PageContextClient | PageContextServer;
|
|
17
|
+
type PageContextClient = PageContextBuiltInClientWithClientRouting & Vike.PageContext;
|
|
18
|
+
type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
|
|
21
19
|
type PageContextClientWithServerRouting = PageContextBuiltInClientWithServerRouting & Vike.PageContext;
|
|
22
20
|
/** Built-in `pageContext` properties set by vike.
|
|
23
21
|
*
|
|
24
22
|
* https://vike.dev/pageContext
|
|
25
23
|
*/
|
|
26
24
|
type PageContextBuiltInServer<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsServer;
|
|
25
|
+
/** For Vike internal use */
|
|
27
26
|
type PageContextBuiltInServerInternal<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsInternal;
|
|
28
27
|
type PageContextBuiltInCommon<Page = [never]> = {
|
|
29
28
|
/** The `export { Page }` of your `.page.js` file.
|
|
@@ -57,7 +56,10 @@ type PageContextBuiltInCommon<Page = [never]> = {
|
|
|
57
56
|
* https://vike.dev/exports
|
|
58
57
|
*/
|
|
59
58
|
exportsAll: ExportsAll;
|
|
60
|
-
/** The URL
|
|
59
|
+
/** The URL you provided to Vike when calling `renderPage({ urlOriginal })` in your server middleware.
|
|
60
|
+
*
|
|
61
|
+
* https://vike.dev/renderPage
|
|
62
|
+
*/
|
|
61
63
|
urlOriginal: string;
|
|
62
64
|
/** If an error occurs, whether the error is a `404 Page Not Found`.
|
|
63
65
|
*
|
|
@@ -18,7 +18,6 @@ export * from '../utils/projectInfo.js';
|
|
|
18
18
|
export * from '../utils/hasPropertyGetter.js';
|
|
19
19
|
export * from '../utils/isPromise.js';
|
|
20
20
|
export * from '../utils/checkType.js';
|
|
21
|
-
export * from '../utils/assertDefaultExport.js';
|
|
22
21
|
export * from '../utils/objectEntries.js';
|
|
23
22
|
export * from '../utils/getValuePrintable.js';
|
|
24
23
|
export * from '../utils/escapeRegex.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -22,7 +22,6 @@ export * from '../utils/projectInfo.js';
|
|
|
22
22
|
export * from '../utils/hasPropertyGetter.js';
|
|
23
23
|
export * from '../utils/isPromise.js';
|
|
24
24
|
export * from '../utils/checkType.js';
|
|
25
|
-
export * from '../utils/assertDefaultExport.js';
|
|
26
25
|
export * from '../utils/objectEntries.js';
|
|
27
26
|
export * from '../utils/getValuePrintable.js';
|
|
28
27
|
export * from '../utils/escapeRegex.js';
|
|
@@ -6,10 +6,11 @@ export type { PageContextClientWithServerRouting } from '../shared/types.js';
|
|
|
6
6
|
export type { PageContextBuiltInServer } from '../shared/types.js';
|
|
7
7
|
export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
|
|
8
8
|
export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
|
|
9
|
-
export type { Config, ConfigMeta as Meta } from '../shared/page-configs/Config.js';
|
|
9
|
+
export type { Config, ConfigMeta as Meta, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
|
|
10
10
|
export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
|
11
11
|
export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
12
12
|
export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
|
|
13
|
+
export type { Url } from '../shared/addUrlComputedProps.js';
|
|
13
14
|
export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
|
|
14
15
|
export { defineConfig } from './defineConfig.js';
|
|
15
16
|
import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { getOutDirs };
|
|
2
|
-
export { getOutDirs_prerender };
|
|
3
2
|
export { resolveOutDir };
|
|
4
3
|
import type { UserConfig, ResolvedConfig } from 'vite';
|
|
5
4
|
type OutDirs = {
|
|
@@ -11,6 +10,5 @@ type OutDirs = {
|
|
|
11
10
|
outDirServer: string;
|
|
12
11
|
};
|
|
13
12
|
declare function getOutDirs(config: ResolvedConfig): OutDirs;
|
|
14
|
-
declare function getOutDirs_prerender(config: ResolvedConfig): OutDirs;
|
|
15
13
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
16
14
|
declare function resolveOutDir(config: UserConfig): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { getOutDirs };
|
|
2
|
-
export { getOutDirs_prerender };
|
|
3
2
|
export { resolveOutDir };
|
|
4
3
|
import { viteIsSSR } from './viteIsSSR.js';
|
|
5
4
|
import { assert, assertUsage } from './assert.js';
|
|
@@ -7,21 +6,24 @@ import { pathJoin } from './path-shim.js';
|
|
|
7
6
|
import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
|
|
8
7
|
import pc from '@brillout/picocolors';
|
|
9
8
|
function getOutDirs(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
let outDirRoot;
|
|
10
|
+
{
|
|
11
|
+
const outDir = getOutDirFromViteResolvedConfig(config);
|
|
12
|
+
if (isOutDirRoot(outDir)) {
|
|
13
|
+
outDirRoot = outDir;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
assertOutDirResolved(outDir, config);
|
|
17
|
+
assert(outDir.endsWith('/server') || outDir.endsWith('/client'));
|
|
18
|
+
assert('/client'.length === '/server'.length);
|
|
19
|
+
outDirRoot = outDir.slice(0, -1 * '/client'.length);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
20
22
|
return getOutDirsAll(outDirRoot, config.root);
|
|
21
23
|
}
|
|
22
24
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
23
25
|
function resolveOutDir(config) {
|
|
24
|
-
const outDir =
|
|
26
|
+
const outDir = getOutDirFromViteUserConfig(config) || 'dist';
|
|
25
27
|
// outDir may already be resolved when using Telefunc + vike (because both Telefunc and vike use this logic)
|
|
26
28
|
if (!isOutDirRoot(outDir)) {
|
|
27
29
|
assertOutDirResolved(outDir, config);
|
|
@@ -39,6 +41,7 @@ function resolveOutDir(config) {
|
|
|
39
41
|
}
|
|
40
42
|
function determineOutDirs(outDirRoot) {
|
|
41
43
|
assertPosixPath(outDirRoot);
|
|
44
|
+
assert(!outDirRoot.endsWith('/'));
|
|
42
45
|
assert(isOutDirRoot(outDirRoot));
|
|
43
46
|
const outDirClient = pathJoin(outDirRoot, 'client');
|
|
44
47
|
const outDirServer = pathJoin(outDirRoot, 'server');
|
|
@@ -89,18 +92,22 @@ function assertOutDirResolved(outDir, config) {
|
|
|
89
92
|
assertUsage(outDir.endsWith('/client'), wrongUsage);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
|
-
function
|
|
95
|
+
function getOutDirFromViteUserConfig(config) {
|
|
93
96
|
let outDir = config.build?.outDir;
|
|
94
97
|
if (outDir === undefined)
|
|
95
98
|
return undefined;
|
|
96
|
-
|
|
97
|
-
outDir = toPosixPath(outDir);
|
|
99
|
+
outDir = normalize(outDir);
|
|
98
100
|
return outDir;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function getOutDirFromViteResolvedConfig(config) {
|
|
101
103
|
let outDir = config.build.outDir;
|
|
102
|
-
|
|
104
|
+
assert(outDir);
|
|
105
|
+
outDir = normalize(outDir);
|
|
106
|
+
return outDir;
|
|
107
|
+
}
|
|
108
|
+
function normalize(outDir) {
|
|
103
109
|
outDir = toPosixPath(outDir);
|
|
110
|
+
outDir = outDir.replace(/\/+$/, ''); // remove trailing slashes
|
|
104
111
|
return outDir;
|
|
105
112
|
}
|
|
106
113
|
function outDirIsAbsolutePath(outDir) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function getValuePrintable(value) {
|
|
2
2
|
if ([null, undefined].includes(value))
|
|
3
3
|
return String(value);
|
|
4
|
-
if (['
|
|
4
|
+
if (['boolean', 'number', 'string'].includes(typeof value))
|
|
5
5
|
return JSON.stringify(value);
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
@@ -3,5 +3,7 @@ export { objectAssign };
|
|
|
3
3
|
// - With type inference
|
|
4
4
|
// - Preserves property descriptors, which we need for preserving the getters added by addUrlComputedProps()
|
|
5
5
|
function objectAssign(obj, objAddendum) {
|
|
6
|
-
|
|
6
|
+
if (objAddendum) {
|
|
7
|
+
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
8
|
+
}
|
|
7
9
|
}
|
|
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
|
|
|
5
5
|
type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
|
|
6
6
|
declare const projectInfo: {
|
|
7
7
|
projectName: "Vike";
|
|
8
|
-
projectVersion: "0.4.
|
|
8
|
+
projectVersion: "0.4.144-commit-e40e9b1";
|
|
9
9
|
npmPackageName: "vike";
|
|
10
10
|
githubRepository: "https://github.com/vikejs/vike";
|
|
11
11
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { requireResolve };
|
|
2
2
|
import { assert } from './assert.js';
|
|
3
3
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
4
4
|
import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
|
|
@@ -10,7 +10,7 @@ const importMetaUrl = import.meta.url;
|
|
|
10
10
|
const require_ = createRequire(importMetaUrl);
|
|
11
11
|
assertIsNotBrowser();
|
|
12
12
|
assertIsNotProductionRuntime();
|
|
13
|
-
function
|
|
13
|
+
function requireResolve(importPath, cwd) {
|
|
14
14
|
assertPosixPath(cwd);
|
|
15
15
|
const clean = addFileExtensionsToRequireResolve();
|
|
16
16
|
importPath = removeFileExtention(importPath);
|
|
@@ -7,7 +7,7 @@ assertIsNotBrowser();
|
|
|
7
7
|
// It would be cleaner to:
|
|
8
8
|
// - Call assertUsageErrorIsObject() right after calling the user's hook
|
|
9
9
|
// - Attach the original error: assertUsageError.originalErrorValue = err
|
|
10
|
-
// - Show the original error in
|
|
10
|
+
// - Show the original error in Vike's error handling
|
|
11
11
|
// - Use assertErrorIsObject() throughout Vike's source code
|
|
12
12
|
function warnIfErrorIsNotObject(err) {
|
|
13
13
|
if (!isObject(err)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.144-commit-e40e9b1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
},
|
|
164
164
|
"devDependencies": {
|
|
165
165
|
"@brillout/part-regex": "^0.1.2",
|
|
166
|
-
"@brillout/release-me": "^0.1.
|
|
166
|
+
"@brillout/release-me": "^0.1.8",
|
|
167
167
|
"@types/estree": "^1.0.0",
|
|
168
168
|
"@types/jest": "^27.4.1",
|
|
169
169
|
"@types/node": "^20.1.0",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isConfigEnvMatch = void 0;
|
|
4
|
-
function isConfigEnvMatch(configEnv, isForClientSide, isClientRouting) {
|
|
5
|
-
if (configEnv === '_routing-eager' || configEnv === 'config-only')
|
|
6
|
-
return false;
|
|
7
|
-
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
8
|
-
return false;
|
|
9
|
-
if (configEnv === '_routing-lazy' && isForClientSide && !isClientRouting)
|
|
10
|
-
return false;
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
exports.isConfigEnvMatch = isConfigEnvMatch;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertPageConfigGlobal = exports.assertPageConfigs = void 0;
|
|
4
|
-
const utils_js_1 = require("../utils.js");
|
|
5
|
-
function assertPageConfigs(pageConfigs) {
|
|
6
|
-
(0, utils_js_1.assert)(Array.isArray(pageConfigs));
|
|
7
|
-
pageConfigs.forEach((pageConfig) => {
|
|
8
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfig));
|
|
9
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfig, 'pageId', 'string'));
|
|
10
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfig, 'routeFilesystem'));
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
exports.assertPageConfigs = assertPageConfigs;
|
|
14
|
-
function assertPageConfigGlobal(pageConfigGlobal) {
|
|
15
|
-
(0, utils_js_1.assert)(pageConfigGlobal);
|
|
16
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobal, 'onBeforeRoute'));
|
|
17
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobal, 'onPrerenderStart'));
|
|
18
|
-
}
|
|
19
|
-
exports.assertPageConfigGlobal = assertPageConfigGlobal;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadPageCode = void 0;
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
-
async function loadPageCode(pageConfig, isDev) {
|
|
10
|
-
if (pageConfig.isLoaded &&
|
|
11
|
-
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
12
|
-
!isDev) {
|
|
13
|
-
return pageConfig;
|
|
14
|
-
}
|
|
15
|
-
const codeFiles = await pageConfig.loadConfigValuesAll();
|
|
16
|
-
// TODO: remove?
|
|
17
|
-
// pageConfig.configValuesOld = pageConfig.configValuesOld.filter((val) => !val.definedByCodeFile)
|
|
18
|
-
const addConfigValue = (configName, value, filePath, exportName) => {
|
|
19
|
-
/* TODO
|
|
20
|
-
assert(!isAlreadyDefined(val.configName), val.configName) // Conflicts are resolved upstream
|
|
21
|
-
*/
|
|
22
|
-
pageConfig.configValues[configName] = {
|
|
23
|
-
value,
|
|
24
|
-
definedAtInfo: {
|
|
25
|
-
filePath,
|
|
26
|
-
fileExportPath: [exportName]
|
|
27
|
-
}
|
|
28
|
-
/* TODO: remove?
|
|
29
|
-
definedByCodeFile: true
|
|
30
|
-
*/
|
|
31
|
-
};
|
|
32
|
-
assertIsNotNull(value, configName, filePath);
|
|
33
|
-
};
|
|
34
|
-
codeFiles.forEach((codeFile) => {
|
|
35
|
-
if (codeFile.isPlusFile) {
|
|
36
|
-
const { importFileExports, importFilePath } = codeFile;
|
|
37
|
-
if (codeFile.configName !== 'client') {
|
|
38
|
-
(0, utils_js_1.assertDefaultExportUnknown)(importFileExports, importFilePath);
|
|
39
|
-
}
|
|
40
|
-
Object.entries(importFileExports).forEach(([exportName, exportValue]) => {
|
|
41
|
-
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
42
|
-
const configName = isSideExport ? exportName : codeFile.configName;
|
|
43
|
-
if (isSideExport && configName in pageConfig.configValues) {
|
|
44
|
-
// We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
|
|
45
|
-
// Side-exports have the lowest priority.
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
addConfigValue(configName, exportValue, importFilePath, exportName);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const { configName, importFilePath, importFileExportValue, importFileExportName } = codeFile;
|
|
53
|
-
addConfigValue(configName, importFileExportValue, importFilePath, importFileExportName);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
(0, utils_js_1.objectAssign)(pageConfig, { isLoaded: true });
|
|
57
|
-
return pageConfig;
|
|
58
|
-
}
|
|
59
|
-
exports.loadPageCode = loadPageCode;
|
|
60
|
-
function assertIsNotNull(configValue, configName, importFilePath) {
|
|
61
|
-
(0, utils_js_1.assert)(!importFilePath.includes('+config.'));
|
|
62
|
-
(0, utils_js_1.assertUsage)(configValue !== null, `Set ${picocolors_1.default.cyan(configName)} to ${picocolors_1.default.cyan('null')} in a +config.h.js file instead of ${importFilePath}`);
|
|
63
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertDefaultExportObject = exports.assertDefaultExportUnknown = void 0;
|
|
7
|
-
const assert_js_1 = require("./assert.js");
|
|
8
|
-
const isObject_js_1 = require("./isObject.js");
|
|
9
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
-
const IGNORE = [
|
|
11
|
-
// vite-plugin-solid adds `export { $$registrations }`
|
|
12
|
-
'$$registrations',
|
|
13
|
-
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
14
|
-
'_rerender_only'
|
|
15
|
-
];
|
|
16
|
-
// support `export { frontmatter }` in .mdx files
|
|
17
|
-
const FILES_WITH_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
18
|
-
function assertDefaultExportUnknown(fileExports, filePath) {
|
|
19
|
-
assertSingleDefaultExport(fileExports, filePath, true);
|
|
20
|
-
}
|
|
21
|
-
exports.assertDefaultExportUnknown = assertDefaultExportUnknown;
|
|
22
|
-
function assertDefaultExportObject(fileExports, filePath) {
|
|
23
|
-
assertSingleDefaultExport(fileExports, filePath, false);
|
|
24
|
-
const exportDefault = fileExports.default;
|
|
25
|
-
(0, assert_js_1.assertUsage)((0, isObject_js_1.isObject)(exportDefault), `The ${picocolors_1.default.cyan('export default')} of ${filePath} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
26
|
-
}
|
|
27
|
-
exports.assertDefaultExportObject = assertDefaultExportObject;
|
|
28
|
-
function assertSingleDefaultExport(fileExports, filePath, defaultExportValueIsUnknown) {
|
|
29
|
-
const exportsAll = Object.keys(fileExports);
|
|
30
|
-
const exportsRelevant = exportsAll.filter((exportName) => !IGNORE.includes(exportName));
|
|
31
|
-
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default');
|
|
32
|
-
const exportsHasDefault = exportsRelevant.includes('default');
|
|
33
|
-
if (exportsInvalid.length === 0) {
|
|
34
|
-
if (exportsHasDefault) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
(0, assert_js_1.assert)(exportsRelevant.length === 0);
|
|
39
|
-
(0, assert_js_1.assertUsage)(false, `${filePath} doesn't export any value, but it should have a ${picocolors_1.default.cyan('export default')} instead`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else if (!FILES_WITH_SIDE_EXPORTS.some((ext) => filePath.endsWith(ext))) {
|
|
43
|
-
if (defaultExportValueIsUnknown) {
|
|
44
|
-
exportsInvalid.forEach((exportInvalid) => {
|
|
45
|
-
(0, assert_js_1.assertWarning)(exportsInvalid.length === 0, `${filePath} should only have a default export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
50
|
-
(0, assert_js_1.assertWarning)(exportsInvalid.length === 0, `${filePath} replace ${picocolors_1.default.cyan(`export { ${exportsInvalidStr} }`)} with ${picocolors_1.default.cyan(`export default { ${exportsInvalidStr} }`)}`, { onlyOnce: true });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { isConfigEnvMatch };
|
|
2
|
-
function isConfigEnvMatch(configEnv, isForClientSide, isClientRouting) {
|
|
3
|
-
if (configEnv === '_routing-eager' || configEnv === 'config-only')
|
|
4
|
-
return false;
|
|
5
|
-
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
6
|
-
return false;
|
|
7
|
-
if (configEnv === '_routing-lazy' && isForClientSide && !isClientRouting)
|
|
8
|
-
return false;
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { assertPageConfigs };
|
|
2
|
-
export { assertPageConfigGlobal };
|
|
3
|
-
import type { PageConfig, PageConfigGlobal } from '../page-configs/PageConfig.js';
|
|
4
|
-
declare function assertPageConfigs(pageConfigs: unknown): asserts pageConfigs is PageConfig[];
|
|
5
|
-
declare function assertPageConfigGlobal(pageConfigGlobal: unknown): asserts pageConfigGlobal is PageConfigGlobal;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { assertPageConfigs };
|
|
2
|
-
export { assertPageConfigGlobal };
|
|
3
|
-
import { assert, isObject, hasProp } from '../utils.js';
|
|
4
|
-
function assertPageConfigs(pageConfigs) {
|
|
5
|
-
assert(Array.isArray(pageConfigs));
|
|
6
|
-
pageConfigs.forEach((pageConfig) => {
|
|
7
|
-
assert(isObject(pageConfig));
|
|
8
|
-
assert(hasProp(pageConfig, 'pageId', 'string'));
|
|
9
|
-
assert(hasProp(pageConfig, 'routeFilesystem'));
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
function assertPageConfigGlobal(pageConfigGlobal) {
|
|
13
|
-
assert(pageConfigGlobal);
|
|
14
|
-
assert(hasProp(pageConfigGlobal, 'onBeforeRoute'));
|
|
15
|
-
assert(hasProp(pageConfigGlobal, 'onPrerenderStart'));
|
|
16
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export { loadPageCode };
|
|
2
|
-
import { assert, assertDefaultExportUnknown, assertUsage, objectAssign } from '../utils.js';
|
|
3
|
-
import pc from '@brillout/picocolors';
|
|
4
|
-
async function loadPageCode(pageConfig, isDev) {
|
|
5
|
-
if (pageConfig.isLoaded &&
|
|
6
|
-
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
7
|
-
!isDev) {
|
|
8
|
-
return pageConfig;
|
|
9
|
-
}
|
|
10
|
-
const codeFiles = await pageConfig.loadConfigValuesAll();
|
|
11
|
-
// TODO: remove?
|
|
12
|
-
// pageConfig.configValuesOld = pageConfig.configValuesOld.filter((val) => !val.definedByCodeFile)
|
|
13
|
-
const addConfigValue = (configName, value, filePath, exportName) => {
|
|
14
|
-
/* TODO
|
|
15
|
-
assert(!isAlreadyDefined(val.configName), val.configName) // Conflicts are resolved upstream
|
|
16
|
-
*/
|
|
17
|
-
pageConfig.configValues[configName] = {
|
|
18
|
-
value,
|
|
19
|
-
definedAtInfo: {
|
|
20
|
-
filePath,
|
|
21
|
-
fileExportPath: [exportName]
|
|
22
|
-
}
|
|
23
|
-
/* TODO: remove?
|
|
24
|
-
definedByCodeFile: true
|
|
25
|
-
*/
|
|
26
|
-
};
|
|
27
|
-
assertIsNotNull(value, configName, filePath);
|
|
28
|
-
};
|
|
29
|
-
codeFiles.forEach((codeFile) => {
|
|
30
|
-
if (codeFile.isPlusFile) {
|
|
31
|
-
const { importFileExports, importFilePath } = codeFile;
|
|
32
|
-
if (codeFile.configName !== 'client') {
|
|
33
|
-
assertDefaultExportUnknown(importFileExports, importFilePath);
|
|
34
|
-
}
|
|
35
|
-
Object.entries(importFileExports).forEach(([exportName, exportValue]) => {
|
|
36
|
-
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
37
|
-
const configName = isSideExport ? exportName : codeFile.configName;
|
|
38
|
-
if (isSideExport && configName in pageConfig.configValues) {
|
|
39
|
-
// We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
|
|
40
|
-
// Side-exports have the lowest priority.
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
addConfigValue(configName, exportValue, importFilePath, exportName);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const { configName, importFilePath, importFileExportValue, importFileExportName } = codeFile;
|
|
48
|
-
addConfigValue(configName, importFileExportValue, importFilePath, importFileExportName);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
objectAssign(pageConfig, { isLoaded: true });
|
|
52
|
-
return pageConfig;
|
|
53
|
-
}
|
|
54
|
-
function assertIsNotNull(configValue, configName, importFilePath) {
|
|
55
|
-
assert(!importFilePath.includes('+config.'));
|
|
56
|
-
assertUsage(configValue !== null, `Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.h.js file instead of ${importFilePath}`);
|
|
57
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { assertDefaultExportUnknown };
|
|
2
|
-
export { assertDefaultExportObject };
|
|
3
|
-
declare function assertDefaultExportUnknown(fileExports: Record<string, unknown>, filePath: string): asserts fileExports is Record<string, unknown> & {
|
|
4
|
-
default: unknown;
|
|
5
|
-
};
|
|
6
|
-
declare function assertDefaultExportObject(fileExports: Record<string, unknown>, filePath: string): asserts fileExports is {
|
|
7
|
-
default: Record<string, unknown>;
|
|
8
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export { assertDefaultExportUnknown };
|
|
2
|
-
export { assertDefaultExportObject };
|
|
3
|
-
import { assert, assertUsage, assertWarning } from './assert.js';
|
|
4
|
-
import { isObject } from './isObject.js';
|
|
5
|
-
import pc from '@brillout/picocolors';
|
|
6
|
-
const IGNORE = [
|
|
7
|
-
// vite-plugin-solid adds `export { $$registrations }`
|
|
8
|
-
'$$registrations',
|
|
9
|
-
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
10
|
-
'_rerender_only'
|
|
11
|
-
];
|
|
12
|
-
// support `export { frontmatter }` in .mdx files
|
|
13
|
-
const FILES_WITH_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
14
|
-
function assertDefaultExportUnknown(fileExports, filePath) {
|
|
15
|
-
assertSingleDefaultExport(fileExports, filePath, true);
|
|
16
|
-
}
|
|
17
|
-
function assertDefaultExportObject(fileExports, filePath) {
|
|
18
|
-
assertSingleDefaultExport(fileExports, filePath, false);
|
|
19
|
-
const exportDefault = fileExports.default;
|
|
20
|
-
assertUsage(isObject(exportDefault), `The ${pc.cyan('export default')} of ${filePath} should be an object (but it's ${pc.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
21
|
-
}
|
|
22
|
-
function assertSingleDefaultExport(fileExports, filePath, defaultExportValueIsUnknown) {
|
|
23
|
-
const exportsAll = Object.keys(fileExports);
|
|
24
|
-
const exportsRelevant = exportsAll.filter((exportName) => !IGNORE.includes(exportName));
|
|
25
|
-
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default');
|
|
26
|
-
const exportsHasDefault = exportsRelevant.includes('default');
|
|
27
|
-
if (exportsInvalid.length === 0) {
|
|
28
|
-
if (exportsHasDefault) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
assert(exportsRelevant.length === 0);
|
|
33
|
-
assertUsage(false, `${filePath} doesn't export any value, but it should have a ${pc.cyan('export default')} instead`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else if (!FILES_WITH_SIDE_EXPORTS.some((ext) => filePath.endsWith(ext))) {
|
|
37
|
-
if (defaultExportValueIsUnknown) {
|
|
38
|
-
exportsInvalid.forEach((exportInvalid) => {
|
|
39
|
-
assertWarning(exportsInvalid.length === 0, `${filePath} should only have a default export: move ${pc.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
44
|
-
assertWarning(exportsInvalid.length === 0, `${filePath} replace ${pc.cyan(`export { ${exportsInvalidStr} }`)} with ${pc.cyan(`export default { ${exportsInvalidStr} }`)}`, { onlyOnce: true });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|