vike 0.4.171 → 0.4.172-commit-ea2b76c
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/plugins/buildConfig.js +3 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +8 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +17 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +17 -2
- package/dist/cjs/node/prerender/runPrerender.js +35 -15
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScripts.js +2 -1
- package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/cjs/node/runtime/html/renderHtml.js +19 -20
- package/dist/cjs/node/runtime/html/stream.js +9 -9
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +91 -282
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +30 -10
- package/dist/cjs/node/runtime/renderPage.js +24 -17
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/getPageContext.js +5 -0
- package/dist/cjs/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/getPageFiles/getExports.js +49 -1
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +15 -8
- package/dist/cjs/shared/hooks/executeHook.js +22 -3
- package/dist/cjs/shared/hooks/getHook.js +2 -2
- package/dist/cjs/shared/page-configs/getConfigValue.js +14 -17
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +70 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +0 -18
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +110 -16
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +198 -0
- package/dist/cjs/shared/route/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/shared/route/index.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/shared/route/resolveRouteFunction.js +2 -2
- package/dist/cjs/shared/sortPageContext.js +4 -8
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertNodeVersion.js +1 -1
- package/dist/cjs/utils/changeEnumerable.js +9 -0
- package/dist/cjs/utils/escapeHtml.js +14 -0
- package/dist/cjs/utils/getPropAccessNotation.js +1 -4
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/normalizeHeaders.js +13 -0
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/objectDefineProperty.js +8 -0
- package/dist/cjs/utils/objectKeys.js +8 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +6 -4
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +16 -12
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +18 -10
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/executeOnRenderClientHook.js +1 -1
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +3 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +35 -48
- package/dist/esm/client/shared/loadUserFilesClientSide.js +4 -4
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +14 -0
- package/dist/esm/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +7 -9
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +18 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +14 -2
- package/dist/esm/node/prerender/runPrerender.js +37 -17
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.js +3 -2
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/esm/node/runtime/html/renderHtml.js +19 -20
- package/dist/esm/node/runtime/html/stream.d.ts +1 -1
- package/dist/esm/node/runtime/html/stream.js +9 -9
- package/dist/esm/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -6
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +2 -6
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +92 -283
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +65 -39
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +31 -11
- package/dist/esm/node/runtime/renderPage.js +24 -17
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/VikeNamespace.d.ts +9 -0
- package/dist/esm/shared/getPageContext.d.ts +1 -0
- package/dist/esm/shared/getPageContext.js +1 -0
- package/dist/esm/shared/{addUrlComputedProps.d.ts → getPageContextUrlComputed.d.ts} +23 -21
- package/dist/esm/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/getPageFiles/getExports.d.ts +36 -0
- package/dist/esm/shared/getPageFiles/getExports.js +50 -2
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +14 -7
- package/dist/esm/shared/hooks/executeHook.d.ts +10 -1
- package/dist/esm/shared/hooks/executeHook.js +21 -2
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -3
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -8
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +12 -12
- package/dist/esm/shared/page-configs/getConfigValue.js +13 -16
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +67 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +17 -21
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.d.ts +1 -5
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -16
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +4 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +109 -15
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +192 -0
- package/dist/esm/shared/route/executeGuardHook.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/index.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +3 -3
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +2 -2
- package/dist/esm/shared/sortPageContext.js +4 -8
- package/dist/esm/shared/types.d.ts +32 -6
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/assert.js +1 -1
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/changeEnumerable.d.ts +2 -0
- package/dist/esm/utils/changeEnumerable.js +5 -0
- package/dist/esm/utils/escapeHtml.d.ts +1 -0
- package/dist/esm/utils/escapeHtml.js +10 -0
- package/dist/esm/utils/getPropAccessNotation.d.ts +1 -2
- package/dist/esm/utils/getPropAccessNotation.js +2 -6
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/normalizeHeaders.d.ts +1 -0
- package/dist/esm/utils/normalizeHeaders.js +9 -0
- package/dist/esm/utils/objectAssign.js +1 -1
- package/dist/esm/utils/objectDefineProperty.d.ts +4 -0
- package/dist/esm/utils/objectDefineProperty.js +4 -0
- package/dist/esm/utils/objectKeys.d.ts +1 -3
- package/dist/esm/utils/objectKeys.js +8 -4
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +21 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -76
- package/dist/cjs/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -14
- package/dist/cjs/node/shared/getClientEntry.js +0 -12
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +0 -85
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -24
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +0 -50
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +0 -16
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -70
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +0 -5
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -11
- package/dist/esm/node/shared/getClientEntry.d.ts +0 -3
- package/dist/esm/node/shared/getClientEntry.js +0 -9
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +0 -82
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -21
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +0 -8
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -47
|
@@ -3,53 +3,95 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getErrorHint = exports.logErrorHint = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
-
const
|
|
9
|
+
const hintDefault = 'The error could be a CJS/ESM issue, see https://vike.dev/broken-npm-package';
|
|
10
|
+
const hintLinkPrefix = 'To fix this error, see ';
|
|
11
|
+
const errorsMisc = [
|
|
10
12
|
{
|
|
11
13
|
errMsg: 'jsxDEV is not a function',
|
|
12
|
-
link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096'
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
16
|
-
link: 'https://vike.dev/broken-npm-package#react-invalid-component'
|
|
14
|
+
link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096',
|
|
15
|
+
shouldMentionNodeModules: false
|
|
17
16
|
},
|
|
18
17
|
{
|
|
19
18
|
// ```
|
|
20
19
|
// Error [RollupError]: Could not resolve "../dist/client/assets.json" from "renderer/+onRenderHtml.tsx"
|
|
21
20
|
// ```
|
|
22
21
|
errMsg: 'assets.json',
|
|
23
|
-
link: 'https://vike.dev/getGlobalContext'
|
|
22
|
+
link: 'https://vike.dev/getGlobalContext',
|
|
23
|
+
shouldMentionNodeModules: false
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
const errorsReact = [
|
|
27
|
+
{
|
|
28
|
+
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
29
|
+
link: 'https://vike.dev/broken-npm-package#react-invalid-component',
|
|
30
|
+
// The stack trace can be user-land while the import is coming from node_modules
|
|
31
|
+
shouldMentionNodeModules: false
|
|
24
32
|
},
|
|
25
33
|
{
|
|
34
|
+
// React's "Invalid hook call.", see https://github.com/vikejs/vike/discussions/1637#discussioncomment-9424712
|
|
35
|
+
errMsg: "Cannot read properties of null (reading 'useContext')"
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
const errorsCjsEsm_withPreciseLink = [
|
|
39
|
+
{
|
|
40
|
+
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
26
41
|
errMsg: /Named export.*not found/i,
|
|
27
|
-
link: 'https://vike.dev/broken-npm-package#named-export-not-found'
|
|
42
|
+
link: 'https://vike.dev/broken-npm-package#named-export-not-found',
|
|
43
|
+
// It seems that this always points to an npm package import.
|
|
44
|
+
shouldMentionNodeModules: false
|
|
28
45
|
}
|
|
29
46
|
];
|
|
47
|
+
const errorsCjsEsm = [
|
|
48
|
+
{ errMsg: 'ERR_UNSUPPORTED_DIR_IMPORT' },
|
|
49
|
+
{ errMsg: 'ERR_REQUIRE_ESM' },
|
|
50
|
+
{ errMsg: 'Must use import' },
|
|
51
|
+
{ errMsg: /Cannot find \S+ '(\S+)' imported from (\S+)/ },
|
|
52
|
+
{ errMsg: 'ERR_UNKNOWN_FILE_EXTENSION' },
|
|
53
|
+
{ errMsg: /Unknown file extension "\S+" for (\S+)/ },
|
|
54
|
+
// `SyntaxError: Cannot use import statement outside a module`.
|
|
55
|
+
{
|
|
56
|
+
errMsg: 'Cannot use import statement',
|
|
57
|
+
// Since user code is always ESM, this error must always originate from an npm package.
|
|
58
|
+
shouldMentionNodeModules: false
|
|
59
|
+
},
|
|
60
|
+
{ errMsg: 'is not exported' },
|
|
61
|
+
{ errMsg: 'Cannot read properties of undefined' },
|
|
62
|
+
{ errMsg: '.default is not' },
|
|
63
|
+
// Using CJS inside ESM modules.
|
|
64
|
+
{ errMsg: 'require is not a function' },
|
|
65
|
+
{ errMsg: 'exports is not defined' },
|
|
66
|
+
{ errMsg: 'module is not defined' },
|
|
67
|
+
{ errMsg: 'window is not defined' },
|
|
68
|
+
{ errMsg: 'not defined in ES' },
|
|
69
|
+
{ errMsg: "Unexpected token 'export'" }
|
|
70
|
+
];
|
|
30
71
|
function logErrorHint(error) {
|
|
31
72
|
/* Collect errors for ./logErrorHint.spec.ts
|
|
32
73
|
collectError(error)
|
|
33
74
|
//*/
|
|
34
|
-
const hint =
|
|
75
|
+
const hint = getErrorHint(error);
|
|
35
76
|
if (hint)
|
|
36
77
|
logHint(hint);
|
|
37
78
|
}
|
|
38
79
|
exports.logErrorHint = logErrorHint;
|
|
39
|
-
function
|
|
80
|
+
function getErrorHint(error) {
|
|
40
81
|
{
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
82
|
+
const knownErr = isKnownError(error);
|
|
83
|
+
if (knownErr) {
|
|
84
|
+
if (knownErr.link) {
|
|
85
|
+
return hintLinkPrefix + knownErr.link;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return hintDefault;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
49
91
|
}
|
|
50
92
|
return null;
|
|
51
93
|
}
|
|
52
|
-
exports.
|
|
94
|
+
exports.getErrorHint = getErrorHint;
|
|
53
95
|
function logHint(hint) {
|
|
54
96
|
hint = (0, utils_js_1.formatHintLog)(hint);
|
|
55
97
|
hint = picocolors_1.default.bold(hint);
|
|
@@ -57,268 +99,42 @@ function logHint(hint) {
|
|
|
57
99
|
}
|
|
58
100
|
function isKnownError(error) {
|
|
59
101
|
const anywhere = getAnywhere(error);
|
|
60
|
-
const knownErr =
|
|
61
|
-
|
|
102
|
+
const knownErr = [
|
|
103
|
+
//
|
|
104
|
+
...errorsMisc,
|
|
105
|
+
...errorsReact,
|
|
106
|
+
...errorsCjsEsm_withPreciseLink,
|
|
107
|
+
...errorsCjsEsm
|
|
108
|
+
].find((knownErorr) => {
|
|
109
|
+
if (!includesLowercase(anywhere, knownErorr.errMsg))
|
|
110
|
+
return false;
|
|
111
|
+
if (knownErorr.shouldMentionNodeModules !== false && !includesLowercase(anywhere, 'node_modules'))
|
|
112
|
+
return false;
|
|
113
|
+
return true;
|
|
62
114
|
});
|
|
63
115
|
if (!knownErr)
|
|
64
116
|
return false;
|
|
65
|
-
return knownErr
|
|
66
|
-
}
|
|
67
|
-
exports.isKnownError = isKnownError;
|
|
68
|
-
// `false` -> noop
|
|
69
|
-
// `true` -> generic message
|
|
70
|
-
// `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
71
|
-
function isCjsEsmError(error) {
|
|
72
|
-
const res = check(error);
|
|
73
|
-
if (res === true || res === false)
|
|
74
|
-
return res;
|
|
75
|
-
const packageNames = normalizeRes(res);
|
|
76
|
-
if (packageNames === false)
|
|
77
|
-
return packageNames;
|
|
78
|
-
packageNames.forEach((packageName) => {
|
|
79
|
-
(0, utils_js_1.assert)(!['vite', 'vike'].includes(packageName));
|
|
80
|
-
});
|
|
81
|
-
// We don't use this anymore: we could return `true` instead. Shall we remove returning a list of npm packages?
|
|
82
|
-
return packageNames;
|
|
83
|
-
}
|
|
84
|
-
exports.isCjsEsmError = isCjsEsmError;
|
|
85
|
-
function normalizeRes(res) {
|
|
86
|
-
let packageNames = (0, utils_js_1.isArray)(res) ? res : [res];
|
|
87
|
-
packageNames = (0, utils_js_1.unique)(packageNames.filter(utils_js_1.isNotNullish).filter((packageName) => packageName !== '@brillout/import'));
|
|
88
|
-
if (packageNames.length === 0)
|
|
89
|
-
return false;
|
|
90
|
-
return packageNames;
|
|
117
|
+
return knownErr;
|
|
91
118
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const relatedNpmPackages = normalizeArray([
|
|
100
|
-
packageName_stack1 || null,
|
|
101
|
-
packageName_stack2 || null,
|
|
102
|
-
(message && extractFromNodeModulesPath(message)) || null
|
|
103
|
-
])
|
|
104
|
-
*/
|
|
105
|
-
// ERR_UNSUPPORTED_DIR_IMPORT
|
|
106
|
-
{
|
|
107
|
-
const packageName = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
|
|
108
|
-
if (packageName)
|
|
109
|
-
return packageName;
|
|
110
|
-
}
|
|
111
|
-
// ERR_UNKNOWN_FILE_EXTENSION
|
|
112
|
-
{
|
|
113
|
-
const packageName = parseUnkownFileExtensionMessage(anywhere);
|
|
114
|
-
if (packageName)
|
|
115
|
-
return packageName;
|
|
116
|
-
}
|
|
117
|
-
{
|
|
118
|
-
const packageName = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
|
|
119
|
-
if (packageName)
|
|
120
|
-
return packageName;
|
|
119
|
+
function includesLowercase(str, substr) {
|
|
120
|
+
if (substr instanceof RegExp) {
|
|
121
|
+
let { flags } = substr;
|
|
122
|
+
if (!flags.includes('i'))
|
|
123
|
+
flags += 'i';
|
|
124
|
+
const regex = new RegExp(substr.source, flags);
|
|
125
|
+
return regex.test(str);
|
|
121
126
|
}
|
|
122
|
-
{
|
|
123
|
-
|
|
124
|
-
if (packageName)
|
|
125
|
-
return packageName;
|
|
126
|
-
}
|
|
127
|
-
// Using CJS inside ESM modules.
|
|
128
|
-
if (includes(anywhere, 'require is not a function') ||
|
|
129
|
-
includes(anywhere, 'exports is not defined') ||
|
|
130
|
-
includes(anywhere, 'module is not defined') ||
|
|
131
|
-
includes(anywhere, 'window is not defined') ||
|
|
132
|
-
includes(anywhere, 'not defined in ES')) {
|
|
133
|
-
if (packageName_stack1)
|
|
134
|
-
return packageName_stack1;
|
|
135
|
-
}
|
|
136
|
-
if (includes(anywhere, "Unexpected token 'export'")) {
|
|
137
|
-
if (packageName_stack2)
|
|
138
|
-
return packageName_stack2;
|
|
139
|
-
if (packageName_stack1)
|
|
140
|
-
return packageName_stack1;
|
|
141
|
-
}
|
|
142
|
-
// ERR_REQUIRE_ESM
|
|
143
|
-
if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
|
|
144
|
-
/* The issue is the importer, not the importee.
|
|
145
|
-
if (relatedNpmPackages) return relatedNpmPackages
|
|
146
|
-
*/
|
|
147
|
-
{
|
|
148
|
-
if (packageName_stack1)
|
|
149
|
-
return packageName_stack1;
|
|
150
|
-
}
|
|
151
|
-
if (isRelatedToNodeModules)
|
|
152
|
-
return true;
|
|
127
|
+
if (typeof substr === 'string') {
|
|
128
|
+
return str.toLowerCase().includes(substr.toLowerCase());
|
|
153
129
|
}
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
const packageNames = parseNodeModulesPath('ERR_REQUIRE_ESM', anywhere)
|
|
157
|
-
if (packageNames) return packageNames
|
|
158
|
-
}
|
|
159
|
-
{
|
|
160
|
-
const packageNames = parseNodeModulesPath('Must use import', anywhere)
|
|
161
|
-
if (packageNames) return packageNames
|
|
162
|
-
}
|
|
163
|
-
*/
|
|
164
|
-
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
165
|
-
{
|
|
166
|
-
const packageName = parseImportFrom(anywhere);
|
|
167
|
-
if (packageName)
|
|
168
|
-
return packageName;
|
|
169
|
-
}
|
|
170
|
-
if (includes(anywhere, 'Cannot read properties of undefined')) {
|
|
171
|
-
if (isRelatedToNodeModules) {
|
|
172
|
-
/* We return true because relatedNpmPackages points to the importer but the problematic npm package is the importee
|
|
173
|
-
if (relatedNpmPackages) return relatedNpmPackages
|
|
174
|
-
*/
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// ERR_MODULE_NOT_FOUND
|
|
179
|
-
{
|
|
180
|
-
const packageNames = parseCannotFindMessage(anywhere);
|
|
181
|
-
if (packageNames)
|
|
182
|
-
return packageNames;
|
|
183
|
-
}
|
|
184
|
-
if (
|
|
185
|
-
// `SyntaxError: Cannot use import statement outside a module`.
|
|
186
|
-
// Since user code is always ESM, this error must always originate from an npm package.
|
|
187
|
-
includes(anywhere, 'Cannot use import statement') ||
|
|
188
|
-
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
189
|
-
// It seems that this always points to an npm package import.
|
|
190
|
-
/Named export.*not found/i.test(anywhere)) {
|
|
191
|
-
/* We return true even if fromNodeModules is false because the errors always relate to npm packages.
|
|
192
|
-
if (fromNodeModules) return true
|
|
193
|
-
*/
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
function parseCannotFindMessage(str) {
|
|
199
|
-
const match = /Cannot find \S+ '(\S+)' imported from (\S+)/.exec(str);
|
|
200
|
-
if (!match)
|
|
201
|
-
return false;
|
|
202
|
-
// const packageNameCannotFind = extractFromPath(match[1]!)
|
|
203
|
-
const packageNameFrom = extractFromPath(match[2]);
|
|
204
|
-
return normalizeArray([
|
|
205
|
-
// packageNameCannotFind,
|
|
206
|
-
packageNameFrom
|
|
207
|
-
]);
|
|
208
|
-
}
|
|
209
|
-
function parseUnkownFileExtensionMessage(str) {
|
|
210
|
-
const match = /Unknown file extension "\S+" for (\S+)/.exec(str);
|
|
211
|
-
if (!match)
|
|
212
|
-
return false;
|
|
213
|
-
const filePath = match[1];
|
|
214
|
-
const packageName = extractFromPath(filePath);
|
|
215
|
-
return packageName;
|
|
216
|
-
}
|
|
217
|
-
function parseImportFrom(str) {
|
|
218
|
-
const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
|
|
219
|
-
if (!match)
|
|
220
|
-
return false;
|
|
221
|
-
const importPath = match[1];
|
|
222
|
-
const packageName = extractFromPath(importPath);
|
|
223
|
-
return packageName;
|
|
224
|
-
}
|
|
225
|
-
function parseNodeModulesPathMessage(begin, str) {
|
|
226
|
-
str = str.replaceAll('\\', '/');
|
|
227
|
-
const regex = new RegExp(`${begin}.*(node_modules\\/\\S+)`);
|
|
228
|
-
const match = regex.exec(str);
|
|
229
|
-
if (!match)
|
|
230
|
-
return false;
|
|
231
|
-
const importPath = match[1];
|
|
232
|
-
return extractFromNodeModulesPath(importPath);
|
|
233
|
-
}
|
|
234
|
-
function getPackageName_stack1(err) {
|
|
235
|
-
const errStack = getErrStack(err);
|
|
236
|
-
if (!errStack)
|
|
237
|
-
return false;
|
|
238
|
-
const firstLineStackTrace = errStack.split('\n').filter((line) => line.startsWith(' at '))[0];
|
|
239
|
-
if (!firstLineStackTrace)
|
|
240
|
-
return false;
|
|
241
|
-
return extractFromNodeModulesPath(firstLineStackTrace);
|
|
242
|
-
}
|
|
243
|
-
/** See https://github.com/brillout/repro_node-syntax-error#nodejs-behavior */
|
|
244
|
-
function getPackageName_stack2(err) {
|
|
245
|
-
const errStack = getErrStack(err);
|
|
246
|
-
if (!errStack)
|
|
247
|
-
return false;
|
|
248
|
-
const firstLine = errStack.trim().split('\n')[0];
|
|
249
|
-
return extractFromNodeModulesPath(firstLine);
|
|
250
|
-
}
|
|
251
|
-
function extractFromPath(filePath) {
|
|
252
|
-
(0, utils_js_1.assert)(filePath);
|
|
253
|
-
filePath = clean(filePath);
|
|
254
|
-
filePath = filePath.replaceAll('\\', '/');
|
|
255
|
-
let packageName;
|
|
256
|
-
if (!filePath.includes('node_modules/')) {
|
|
257
|
-
packageName = filePath;
|
|
258
|
-
if (packageName.startsWith('/'))
|
|
259
|
-
return null;
|
|
260
|
-
if (packageName.startsWith('.'))
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
packageName = filePath.split('node_modules/').pop();
|
|
265
|
-
// This assert is fairly risk, we should eventually remove it
|
|
266
|
-
(0, utils_js_1.assert)(!packageName.startsWith('.'));
|
|
267
|
-
// This assert is fairly risk, we should eventually remove it
|
|
268
|
-
(0, utils_js_1.assert)(!packageName.startsWith('/'));
|
|
269
|
-
}
|
|
270
|
-
if (!packageName)
|
|
271
|
-
return null;
|
|
272
|
-
packageName = packageName.split('/').slice(0, 2).join('/');
|
|
273
|
-
if (!packageName.startsWith('@')) {
|
|
274
|
-
packageName = packageName.split('/')[0];
|
|
275
|
-
}
|
|
276
|
-
packageName = clean(packageName);
|
|
277
|
-
return packageName;
|
|
278
|
-
}
|
|
279
|
-
function clean(packageName) {
|
|
280
|
-
const b = ['"', "'", '(', ')'];
|
|
281
|
-
if (b.includes(packageName[0])) {
|
|
282
|
-
packageName = packageName.slice(1);
|
|
283
|
-
}
|
|
284
|
-
if (b.includes(packageName[packageName.length - 1])) {
|
|
285
|
-
packageName = packageName.slice(0, -1);
|
|
286
|
-
}
|
|
287
|
-
return packageName;
|
|
130
|
+
(0, utils_js_1.assert)(false);
|
|
288
131
|
}
|
|
289
|
-
function
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
return
|
|
295
|
-
}
|
|
296
|
-
function includes(str1, str2) {
|
|
297
|
-
if (!str1)
|
|
298
|
-
return false;
|
|
299
|
-
if (str2 instanceof RegExp) {
|
|
300
|
-
return str2.test(str1.toLowerCase());
|
|
301
|
-
}
|
|
302
|
-
if (typeof str2 === 'string') {
|
|
303
|
-
return str1.toLowerCase().includes(str2.toLowerCase());
|
|
304
|
-
}
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
function includesNodeModules(str) {
|
|
308
|
-
if (!str)
|
|
309
|
-
return false;
|
|
310
|
-
str = str.replaceAll('\\', '/');
|
|
311
|
-
if (!str.includes('node_modules/'))
|
|
312
|
-
return false;
|
|
313
|
-
if (str.includes('node_modules/vite/'))
|
|
314
|
-
return false;
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
function normalizeArray(arr) {
|
|
318
|
-
const arrNormalized = arr.filter(utils_js_1.isNotNullish);
|
|
319
|
-
if (arrNormalized.length === 0)
|
|
320
|
-
return null;
|
|
321
|
-
return arrNormalized;
|
|
132
|
+
function getAnywhere(error) {
|
|
133
|
+
const code = getErrCode(error);
|
|
134
|
+
const message = getErrMessage(error);
|
|
135
|
+
const stack = getErrStack(error);
|
|
136
|
+
const anywhere = [code, message, stack].filter(Boolean).join('\n');
|
|
137
|
+
return anywhere;
|
|
322
138
|
}
|
|
323
139
|
function getErrMessage(err) {
|
|
324
140
|
if (!(0, utils_js_1.isObject)(err))
|
|
@@ -347,13 +163,6 @@ function getErrStack(err) {
|
|
|
347
163
|
return null;
|
|
348
164
|
return err.stack;
|
|
349
165
|
}
|
|
350
|
-
function getAnywhere(error) {
|
|
351
|
-
const code = getErrCode(error);
|
|
352
|
-
const message = getErrMessage(error);
|
|
353
|
-
const stack = getErrStack(error);
|
|
354
|
-
const anywhere = [code, message, stack].filter(Boolean).join('\n');
|
|
355
|
-
return anywhere;
|
|
356
|
-
}
|
|
357
166
|
function collectError(err) {
|
|
358
167
|
console.log([
|
|
359
168
|
'{',
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.preparePageContextForUserConsumptionServerSide = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
const sortPageContext_js_1 = require("../../../shared/sortPageContext.js");
|
|
6
|
-
const
|
|
6
|
+
const getPageContextUrlComputed_js_1 = require("../../../shared/getPageContextUrlComputed.js");
|
|
7
7
|
const addIs404ToPageProps_js_1 = require("../../../shared/addIs404ToPageProps.js");
|
|
8
8
|
function preparePageContextForUserConsumptionServerSide(pageContext) {
|
|
9
|
-
(0,
|
|
9
|
+
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(pageContext);
|
|
10
10
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(pageContext.routeParams));
|
|
11
11
|
(0, utils_js_1.assert)('Page' in pageContext);
|
|
12
12
|
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageContext.pageExports));
|
|
@@ -9,7 +9,7 @@ const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
|
9
9
|
const getPageFiles_js_1 = require("../../../shared/getPageFiles.js");
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
11
|
const serializePageContextClientSide_js_1 = require("../html/serializePageContextClientSide.js");
|
|
12
|
-
const
|
|
12
|
+
const getPageContextUrlComputed_js_1 = require("../../../shared/getPageContextUrlComputed.js");
|
|
13
13
|
const globalContext_js_1 = require("../globalContext.js");
|
|
14
14
|
const createHttpResponseObject_js_1 = require("./createHttpResponseObject.js");
|
|
15
15
|
const loadUserFilesServerSide_js_1 = require("./loadUserFilesServerSide.js");
|
|
@@ -22,7 +22,6 @@ const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js
|
|
|
22
22
|
const loadPageRoutes_js_1 = require("../../../shared/route/loadPageRoutes.js");
|
|
23
23
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
24
24
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
25
|
-
const assertV1Design_js_1 = require("../../shared/assertV1Design.js");
|
|
26
25
|
async function renderPageAlreadyRouted(pageContext) {
|
|
27
26
|
// pageContext._pageId can either be the:
|
|
28
27
|
// - ID of the page matching the routing, or the
|
|
@@ -109,9 +108,9 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
109
108
|
_debugRouteMatches: []
|
|
110
109
|
};
|
|
111
110
|
const pageContextInit = {
|
|
112
|
-
urlOriginal: '/fake-404-url'
|
|
113
|
-
...pageContextInit_
|
|
111
|
+
urlOriginal: '/fake-404-url' // A URL is needed for `applyViteHtmlTransform`
|
|
114
112
|
};
|
|
113
|
+
(0, utils_js_1.objectAssign)(pageContextInit, pageContextInit_);
|
|
115
114
|
{
|
|
116
115
|
const pageContextInitEnhanced = getPageContextInitEnhanced(pageContextInit, renderContext);
|
|
117
116
|
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
@@ -120,15 +119,16 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
120
119
|
return prerenderPage(pageContext);
|
|
121
120
|
}
|
|
122
121
|
exports.prerender404Page = prerender404Page;
|
|
123
|
-
function getPageContextInitEnhanced(pageContextInit, renderContext, {
|
|
122
|
+
function getPageContextInitEnhanced(pageContextInit, renderContext, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } = {
|
|
124
123
|
urlRewrite: null,
|
|
125
124
|
urlHandler: null,
|
|
126
125
|
isClientSideNavigation: false
|
|
127
126
|
} } = {}) {
|
|
128
127
|
(0, utils_js_1.assert)(pageContextInit.urlOriginal);
|
|
129
128
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
130
|
-
const pageContextInitEnhanced = {
|
|
131
|
-
|
|
129
|
+
const pageContextInitEnhanced = {};
|
|
130
|
+
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, pageContextInit);
|
|
131
|
+
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, {
|
|
132
132
|
_objectCreatedByVike: true,
|
|
133
133
|
// The following is defined on `pageContext` because we can eventually make these non-global (e.g. sot that two pages can have different includeAssetsImportedByServer settings)
|
|
134
134
|
_baseServer: globalContext.baseServer,
|
|
@@ -145,8 +145,27 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { urlCompute
|
|
|
145
145
|
_urlRewrite: urlRewrite,
|
|
146
146
|
_urlHandler: urlHandler,
|
|
147
147
|
isClientSideNavigation
|
|
148
|
-
};
|
|
149
|
-
|
|
148
|
+
});
|
|
149
|
+
// pageContext.urlParsed
|
|
150
|
+
const pageContextUrlComputed = (0, getPageContextUrlComputed_js_1.getPageContextUrlComputed)(pageContextInitEnhanced);
|
|
151
|
+
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, pageContextUrlComputed);
|
|
152
|
+
// pageContext.headers
|
|
153
|
+
{
|
|
154
|
+
let headers;
|
|
155
|
+
if (pageContextInit.headersOriginal) {
|
|
156
|
+
headers = (0, utils_js_1.normalizeHeaders)(pageContextInit.headersOriginal);
|
|
157
|
+
(0, utils_js_1.assertUsage)(!('headers' in pageContextInit), "You're defining pageContextInit.headersOriginal as well as pageContextInit.headers but you should only define pageContextInit.headersOriginal instead, see https://vike.dev/headers");
|
|
158
|
+
}
|
|
159
|
+
else if (pageContextInit.headers) {
|
|
160
|
+
headers = pageContextInit.headers;
|
|
161
|
+
// TODO/next-major-release: assertUsage() instead of assertWarning()
|
|
162
|
+
(0, utils_js_1.assertWarning)(false, 'Setting pageContextInit.headers is deprecated: set pageContextInit.headersOriginal instead, see https://vike.dev/headers', { onlyOnce: true });
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
headers = null;
|
|
166
|
+
}
|
|
167
|
+
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, { headers });
|
|
168
|
+
}
|
|
150
169
|
return pageContextInitEnhanced;
|
|
151
170
|
}
|
|
152
171
|
exports.getPageContextInitEnhanced = getPageContextInitEnhanced;
|
|
@@ -156,7 +175,8 @@ async function getRenderContext() {
|
|
|
156
175
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
157
176
|
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = await (0, getPageFiles_js_1.getPageFilesAll)(false, globalContext.isProduction);
|
|
158
177
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
159
|
-
|
|
178
|
+
// We assume assertV1Design() was already called at build-time
|
|
179
|
+
(0, utils_js_1.assert)(pageFilesAll.length === 0 || pageConfigs.length === 0);
|
|
160
180
|
const renderContext = {
|
|
161
181
|
pageFilesAll: pageFilesAll,
|
|
162
182
|
pageConfigs,
|
|
@@ -205,7 +205,7 @@ function logHttpRequest(urlOriginal, httpRequestId) {
|
|
|
205
205
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info', clearErrors);
|
|
206
206
|
}
|
|
207
207
|
function getRequestInfoMessage(urlOriginal) {
|
|
208
|
-
return `HTTP request: ${
|
|
208
|
+
return `HTTP request: ${prettyUrl(urlOriginal)}`;
|
|
209
209
|
}
|
|
210
210
|
function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
211
211
|
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
|
|
@@ -221,7 +221,7 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
221
221
|
// - We should show `HTTP response ${urlOriginal} ERR` instead.
|
|
222
222
|
// - Maybe we can/should make the error available at pageContext.errorWhileRendering
|
|
223
223
|
(0, utils_js_1.assert)(errorWhileRendering === null || errorWhileRendering === undefined);
|
|
224
|
-
msg = `HTTP response ${
|
|
224
|
+
msg = `HTTP response ${prettyUrl(urlOriginal)} ${picocolors_1.default.dim('null')}`;
|
|
225
225
|
// Erroneous value (it shoud sometimes be `false`) but it's fine as it doesn't seem to have much of an impact.
|
|
226
226
|
isNominal = true;
|
|
227
227
|
}
|
|
@@ -241,7 +241,7 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
241
241
|
const urlRedirect = headerRedirect[1];
|
|
242
242
|
urlOriginal = urlRedirect;
|
|
243
243
|
}
|
|
244
|
-
msg = `HTTP ${type} ${
|
|
244
|
+
msg = `HTTP ${type} ${prettyUrl(urlOriginal)} ${color(statusCode ?? 'ERR')}`;
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(msg, httpRequestId, isNominal ? 'info' : 'error');
|
|
@@ -289,12 +289,13 @@ async function renderPageNominal(pageContext) {
|
|
|
289
289
|
async function getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPagePartial, renderContext, httpRequestId) {
|
|
290
290
|
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit, renderContext, null, httpRequestId);
|
|
291
291
|
(0, utils_js_1.assert)(errNominalPage);
|
|
292
|
-
const pageContext = {
|
|
293
|
-
|
|
292
|
+
const pageContext = {};
|
|
293
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
294
|
+
(0, utils_js_1.objectAssign)(pageContext, {
|
|
294
295
|
is404: false,
|
|
295
296
|
errorWhileRendering: errNominalPage,
|
|
296
297
|
routeParams: {}
|
|
297
|
-
};
|
|
298
|
+
});
|
|
298
299
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
299
300
|
_debugRouteMatches: pageContextNominalPagePartial._debugRouteMatches || 'ROUTING_ERROR'
|
|
300
301
|
});
|
|
@@ -346,7 +347,9 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
346
347
|
return null;
|
|
347
348
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
348
349
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
349
|
-
const pageContextHttpResponse = {
|
|
350
|
+
const pageContextHttpResponse = {};
|
|
351
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, pageContextInit);
|
|
352
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
350
353
|
return pageContextHttpResponse;
|
|
351
354
|
}
|
|
352
355
|
function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
@@ -381,7 +384,9 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
381
384
|
}
|
|
382
385
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
383
386
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
384
|
-
const pageContextHttpResponse = {
|
|
387
|
+
const pageContextHttpResponse = {};
|
|
388
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, pageContextInit);
|
|
389
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
385
390
|
return pageContextHttpResponse;
|
|
386
391
|
}
|
|
387
392
|
async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
|
|
@@ -397,11 +402,11 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
397
402
|
(0, utils_js_1.assert)(abortCall);
|
|
398
403
|
(0, utils_js_1.assertUsage)(errorPageId, `You called ${picocolors_1.default.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
399
404
|
const pageContext = {
|
|
400
|
-
_pageId: errorPageId
|
|
401
|
-
...pageContextAbort,
|
|
402
|
-
...pageContextErrorPageInit,
|
|
403
|
-
...renderContext
|
|
405
|
+
_pageId: errorPageId
|
|
404
406
|
};
|
|
407
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
408
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit);
|
|
409
|
+
(0, utils_js_1.objectAssign)(pageContext, renderContext);
|
|
405
410
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
406
411
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
407
412
|
pageContextSerialized = (0, serializePageContextClientSide_js_1.serializePageContextClientSide)(pageContext);
|
|
@@ -422,10 +427,9 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
422
427
|
return { pageContextReturn };
|
|
423
428
|
}
|
|
424
429
|
if (pageContextAbort._urlRedirect) {
|
|
425
|
-
const pageContextReturn = {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
};
|
|
430
|
+
const pageContextReturn = {};
|
|
431
|
+
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextInit);
|
|
432
|
+
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextAbort);
|
|
429
433
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)(pageContextAbort._urlRedirect, (() => {
|
|
430
434
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
431
435
|
const urlLogical = (0, utils_js_1.createUrlFromComponents)(null, pathname, searchOriginal,
|
|
@@ -445,9 +449,12 @@ function checkBaseUrl(pageContextInit, httpRequestId) {
|
|
|
445
449
|
const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
446
450
|
const { hasBaseServer } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
|
|
447
451
|
if (!hasBaseServer) {
|
|
448
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`${getRequestInfoMessage(urlOriginal)} skipped because URL ${
|
|
452
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`${getRequestInfoMessage(urlOriginal)} skipped because URL ${prettyUrl(urlOriginal)} doesn't start with Base URL ${prettyUrl(baseServer)} (https://vike.dev/base-url)`, httpRequestId, 'info');
|
|
449
453
|
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
450
454
|
return pageContextHttpResponseNull;
|
|
451
455
|
}
|
|
452
456
|
return null;
|
|
453
457
|
}
|
|
458
|
+
function prettyUrl(url) {
|
|
459
|
+
return picocolors_1.default.bold(decodeURI(url));
|
|
460
|
+
}
|
|
@@ -68,3 +68,5 @@ __exportStar(require("../../utils/truncateString.js"), exports);
|
|
|
68
68
|
__exportStar(require("../../utils/formatHintLog.js"), exports);
|
|
69
69
|
__exportStar(require("../../utils/joinEnglish.js"), exports);
|
|
70
70
|
__exportStar(require("../../utils/isArrayOfStrings.js"), exports);
|
|
71
|
+
__exportStar(require("../../utils/escapeHtml.js"), exports);
|
|
72
|
+
__exportStar(require("../../utils/normalizeHeaders.js"), exports);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertV1Design = void 0;
|
|
4
|
-
const helpers_js_1 = require("../../shared/page-configs/helpers.js");
|
|
5
4
|
const utils_js_1 = require("./utils.js");
|
|
6
5
|
function assertV1Design(isOldDesign, pageConfigs, pageFilesAll) {
|
|
7
6
|
const isV1Design = pageConfigs.length > 0;
|
|
@@ -11,10 +10,10 @@ function assertV1Design(isOldDesign, pageConfigs, pageFilesAll) {
|
|
|
11
10
|
(0, utils_js_1.assert)(pageFilesAll.length > 0);
|
|
12
11
|
const indent = '- ';
|
|
13
12
|
const filesV1 = (0, utils_js_1.unique)(pageConfigs
|
|
14
|
-
.map((p) => Object.values(p.
|
|
15
|
-
.map((c) =>
|
|
13
|
+
.map((p) => Object.values(p.configValueSources).map((sources) => sources
|
|
14
|
+
.map((c) => c.definedAtFilePath.filePathAbsoluteUserRootDir)
|
|
16
15
|
.filter(utils_js_1.isNotNullish)
|
|
17
|
-
.map((filePathToShowToUser) => indent + filePathToShowToUser))
|
|
16
|
+
.map((filePathToShowToUser) => indent + filePathToShowToUser)))
|
|
18
17
|
.flat(2));
|
|
19
18
|
const filesOld = pageFilesAll.map((p) => indent + p.filePath);
|
|
20
19
|
lines.push(...['V1 design files:', ...filesV1, 'Old design files:', ...filesOld]);
|