vike 0.4.171-commit-6e37128 → 0.4.171-commit-2876124
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/devConfig/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- 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/renderPage/logErrorHint.js +91 -282
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +15 -8
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +0 -17
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +18 -10
- 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/importUserCode/getVirtualFileImportUserCode.js +0 -1
- 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/renderPage/logErrorHint.d.ts +2 -6
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +92 -283
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +14 -7
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.d.ts +1 -5
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -15
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
|
@@ -75,7 +75,8 @@ function devConfig() {
|
|
|
75
75
|
configureServer: {
|
|
76
76
|
order: 'post',
|
|
77
77
|
handler(server) {
|
|
78
|
-
|
|
78
|
+
const hasHonoViteDevServer = !!config.plugins.find((p) => p.name === '@hono/vite-dev-server');
|
|
79
|
+
if (config.server.middlewareMode || hasHonoViteDevServer)
|
|
79
80
|
return;
|
|
80
81
|
return () => {
|
|
81
82
|
(0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares);
|
|
@@ -50,7 +50,8 @@ function envVarsPlugin() {
|
|
|
50
50
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
// Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`)
|
|
53
|
+
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
54
|
+
// - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
54
55
|
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -69,7 +69,6 @@ export const pageFilesExportNamesLazy = {};
|
|
|
69
69
|
export const pageFilesExportNamesEager = {};
|
|
70
70
|
export const pageFilesList = [];
|
|
71
71
|
export const neverLoaded = {};
|
|
72
|
-
export const isGeneratedFile = true;
|
|
73
72
|
|
|
74
73
|
${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(isForClientSide, isDev, id, isClientRouting, config)}
|
|
75
74
|
|
|
@@ -112,7 +112,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
// The JavaScript entry <script> tag
|
|
115
|
-
const scriptEntry = await mergeScriptEntries(pageAssets
|
|
115
|
+
const scriptEntry = await mergeScriptEntries(pageAssets);
|
|
116
116
|
if (scriptEntry) {
|
|
117
117
|
htmlTags.push({
|
|
118
118
|
htmlTag: scriptEntry,
|
|
@@ -134,11 +134,11 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
134
134
|
return htmlTags;
|
|
135
135
|
}
|
|
136
136
|
exports.getHtmlTags = getHtmlTags;
|
|
137
|
-
async function mergeScriptEntries(pageAssets
|
|
137
|
+
async function mergeScriptEntries(pageAssets) {
|
|
138
138
|
const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
|
|
139
139
|
const viteScripts = await (0, getViteDevScripts_js_1.getViteDevScripts)();
|
|
140
140
|
const scriptTagsHtml = `${viteScripts}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset)).join('')}`;
|
|
141
|
-
const scriptTag = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptTagsHtml
|
|
141
|
+
const scriptTag = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptTagsHtml);
|
|
142
142
|
return scriptTag;
|
|
143
143
|
}
|
|
144
144
|
function getPageContextJsonScriptTag(pageContext) {
|
|
@@ -21,7 +21,8 @@ async function getViteDevScripts() {
|
|
|
21
21
|
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), 'Vite plugins that minify the HTML are not supported by vike, see https://github.com/vikejs/vike/issues/224');
|
|
22
22
|
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), 'You are using a Vite Plugin that transforms the HTML in a way that conflicts with vike. Create a new GitHub ticket to discuss a solution.');
|
|
23
23
|
const viteInjection = fakeHtml.slice(fakeHtmlBegin.length, -1 * fakeHtmlEnd.length);
|
|
24
|
-
(0, utils_js_1.assert)(viteInjection.includes('script')
|
|
24
|
+
(0, utils_js_1.assert)(viteInjection.includes('script'));
|
|
25
|
+
(0, utils_js_1.assertWarning)(!viteInjection.includes('import('), 'Unexpected Vite HMR code. Reach out to a Vike maintainer on GitHub.', { onlyOnce: true });
|
|
25
26
|
const scriptTags = viteInjection;
|
|
26
27
|
return scriptTags;
|
|
27
28
|
}
|
|
@@ -6,7 +6,7 @@ const inferHtmlTags_js_1 = require("./inferHtmlTags.js");
|
|
|
6
6
|
const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims;
|
|
7
7
|
const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
8
8
|
const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
9
|
-
function mergeScriptTags(scriptTagsHtml
|
|
9
|
+
function mergeScriptTags(scriptTagsHtml) {
|
|
10
10
|
let scriptTag = '';
|
|
11
11
|
const scripts = parseScripts(scriptTagsHtml);
|
|
12
12
|
// We need to merge module scripts to ensure execution order
|
|
@@ -21,13 +21,7 @@ function mergeScriptTags(scriptTagsHtml, isProduction) {
|
|
|
21
21
|
const hasInnerHtml = !!innerHtml.trim();
|
|
22
22
|
if (src) {
|
|
23
23
|
(0, utils_js_1.assert)(!hasInnerHtml);
|
|
24
|
-
|
|
25
|
-
contents.push(`import ${JSON.stringify(src)};`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// Ensure HMR preamble code is executed before client entries
|
|
29
|
-
contents.push(`import(${JSON.stringify(src)});`);
|
|
30
|
-
}
|
|
24
|
+
contents.push(`import ${JSON.stringify(src)};`);
|
|
31
25
|
}
|
|
32
26
|
else if (hasInnerHtml) {
|
|
33
27
|
innerHtml = innerHtml.split('\n').filter(Boolean).join('\n');
|
|
@@ -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
|
'{',
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseGlobResults = void 0;
|
|
4
|
+
// TODO/v1-release: remove old design code, and remove all assertions.
|
|
4
5
|
const utils_js_1 = require("../utils.js");
|
|
5
6
|
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
6
7
|
const getPageFileObject_js_1 = require("./getPageFileObject.js");
|
|
7
8
|
const fileTypes_js_1 = require("./fileTypes.js");
|
|
8
|
-
const assertPageConfigsSerialized_js_1 = require("../page-configs/serialize/assertPageConfigsSerialized.js");
|
|
9
9
|
const parsePageConfigs_js_1 = require("../page-configs/serialize/parsePageConfigs.js");
|
|
10
10
|
function parseGlobResults(pageFilesExports) {
|
|
11
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'isGeneratedFile'));
|
|
12
|
-
(0, utils_js_1.assert)(pageFilesExports.isGeneratedFile !== false, `vike was re-installed(/re-built). Restart your app.`);
|
|
13
|
-
(0, utils_js_1.assert)(pageFilesExports.isGeneratedFile === true, `\`isGeneratedFile === ${pageFilesExports.isGeneratedFile}\``);
|
|
14
11
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesLazy', 'object'));
|
|
15
12
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesEager', 'object'));
|
|
16
13
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesExportNamesLazy', 'object'));
|
|
@@ -21,8 +18,8 @@ function parseGlobResults(pageFilesExports) {
|
|
|
21
18
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigsSerialized'));
|
|
22
19
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigGlobalSerialized'));
|
|
23
20
|
const { pageConfigsSerialized, pageConfigGlobalSerialized } = pageFilesExports;
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
assertPageConfigsSerialized(pageConfigsSerialized);
|
|
22
|
+
assertPageConfigGlobalSerialized(pageConfigGlobalSerialized);
|
|
26
23
|
const { pageConfigs, pageConfigGlobal } = (0, parsePageConfigs_js_1.parsePageConfigs)(pageConfigsSerialized, pageConfigGlobalSerialized);
|
|
27
24
|
const pageFilesMap = {};
|
|
28
25
|
parseGlobResult(pageFilesExports.pageFilesLazy).forEach(({ filePath, pageFile, globValue }) => {
|
|
@@ -43,8 +40,6 @@ function parseGlobResults(pageFilesExports) {
|
|
|
43
40
|
pageFile.loadExportNames = async () => {
|
|
44
41
|
if (!('exportNames' in pageFile)) {
|
|
45
42
|
const moduleExports = await loadModule();
|
|
46
|
-
// Vite 2 seems to choke following assertion: https://github.com/vikejs/vike/issues/455
|
|
47
|
-
(0, utils_js_1.assertUsage)('exportNames' in moduleExports, 'You seem to be using Vite 2 but the latest vike versions only work with Vite 3');
|
|
48
43
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(moduleExports, 'exportNames', 'string[]'), pageFile.filePath);
|
|
49
44
|
pageFile.exportNames = moduleExports.exportNames;
|
|
50
45
|
}
|
|
@@ -91,3 +86,15 @@ function parseGlobResult(globObject) {
|
|
|
91
86
|
function assertLoadModule(globValue) {
|
|
92
87
|
(0, utils_js_1.assert)((0, utils_js_1.isCallable)(globValue));
|
|
93
88
|
}
|
|
89
|
+
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
90
|
+
(0, utils_js_1.assert)((0, utils_js_1.isArray)(pageConfigsSerialized));
|
|
91
|
+
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
92
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
|
|
93
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
|
|
94
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
|
|
95
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
99
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
100
|
+
}
|
|
@@ -1,18 +1 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertPageConfigGlobalSerialized = exports.assertPageConfigsSerialized = void 0;
|
|
4
|
-
const utils_js_1 = require("../../utils.js");
|
|
5
|
-
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
6
|
-
(0, utils_js_1.assert)((0, utils_js_1.isArray)(pageConfigsSerialized));
|
|
7
|
-
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
8
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
|
|
9
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
|
|
10
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
|
|
11
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
exports.assertPageConfigsSerialized = assertPageConfigsSerialized;
|
|
15
|
-
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
16
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
17
|
-
}
|
|
18
|
-
exports.assertPageConfigGlobalSerialized = assertPageConfigGlobalSerialized;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.171-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.171-commit-2876124';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -7,22 +7,30 @@ import { onLinkClick } from './onLinkClick.js';
|
|
|
7
7
|
import { setupNativeScrollRestoration } from './scrollRestoration.js';
|
|
8
8
|
import { autoSaveScrollPosition } from './setScrollPosition.js';
|
|
9
9
|
async function installClientRouter() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//
|
|
10
|
+
// Init navigation history and scroll restoration
|
|
11
|
+
initHistoryAndScroll();
|
|
12
|
+
// Render initial page
|
|
13
|
+
const renderPromise = render();
|
|
14
|
+
// Intercept <a> clicks
|
|
15
|
+
onLinkClick();
|
|
16
|
+
// Preserve stack track
|
|
17
|
+
await renderPromise;
|
|
18
|
+
}
|
|
19
|
+
function render() {
|
|
15
20
|
assert(getRenderCount() === 0);
|
|
16
|
-
const
|
|
21
|
+
const renderPromise = renderPageClientSide({
|
|
17
22
|
scrollTarget: 'preserve-scroll',
|
|
18
23
|
isBackwardNavigation: null,
|
|
19
24
|
isClientSideNavigation: false
|
|
20
25
|
});
|
|
21
26
|
assert(getRenderCount() === 1);
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
return renderPromise;
|
|
28
|
+
}
|
|
29
|
+
function initHistoryAndScroll() {
|
|
30
|
+
setupNativeScrollRestoration();
|
|
31
|
+
initHistoryState();
|
|
32
|
+
autoSaveScrollPosition();
|
|
33
|
+
monkeyPatchHistoryPushState();
|
|
24
34
|
// Handle back-/forward navigation
|
|
25
35
|
onBrowserHistoryNavigation();
|
|
26
|
-
// Only for full stack straces
|
|
27
|
-
await promise;
|
|
28
36
|
}
|
|
@@ -73,7 +73,8 @@ function devConfig() {
|
|
|
73
73
|
configureServer: {
|
|
74
74
|
order: 'post',
|
|
75
75
|
handler(server) {
|
|
76
|
-
|
|
76
|
+
const hasHonoViteDevServer = !!config.plugins.find((p) => p.name === '@hono/vite-dev-server');
|
|
77
|
+
if (config.server.middlewareMode || hasHonoViteDevServer)
|
|
77
78
|
return;
|
|
78
79
|
return () => {
|
|
79
80
|
addSsrMiddleware(server.middlewares);
|
|
@@ -50,7 +50,8 @@ function envVarsPlugin() {
|
|
|
50
50
|
assertUsage(false, errMsg);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
// Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`)
|
|
53
|
+
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
54
|
+
// - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
54
55
|
assertWarning(false, errMsg, { onlyOnce: true });
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -63,7 +63,6 @@ export const pageFilesExportNamesLazy = {};
|
|
|
63
63
|
export const pageFilesExportNamesEager = {};
|
|
64
64
|
export const pageFilesList = [];
|
|
65
65
|
export const neverLoaded = {};
|
|
66
|
-
export const isGeneratedFile = true;
|
|
67
66
|
|
|
68
67
|
${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config)}
|
|
69
68
|
|
|
@@ -107,7 +107,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
// The JavaScript entry <script> tag
|
|
110
|
-
const scriptEntry = await mergeScriptEntries(pageAssets
|
|
110
|
+
const scriptEntry = await mergeScriptEntries(pageAssets);
|
|
111
111
|
if (scriptEntry) {
|
|
112
112
|
htmlTags.push({
|
|
113
113
|
htmlTag: scriptEntry,
|
|
@@ -128,11 +128,11 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
128
128
|
});
|
|
129
129
|
return htmlTags;
|
|
130
130
|
}
|
|
131
|
-
async function mergeScriptEntries(pageAssets
|
|
131
|
+
async function mergeScriptEntries(pageAssets) {
|
|
132
132
|
const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
|
|
133
133
|
const viteScripts = await getViteDevScripts();
|
|
134
134
|
const scriptTagsHtml = `${viteScripts}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
|
|
135
|
-
const scriptTag = mergeScriptTags(scriptTagsHtml
|
|
135
|
+
const scriptTag = mergeScriptTags(scriptTagsHtml);
|
|
136
136
|
return scriptTag;
|
|
137
137
|
}
|
|
138
138
|
function getPageContextJsonScriptTag(pageContext) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getViteDevScripts };
|
|
2
2
|
import { getGlobalContext } from '../../globalContext.js';
|
|
3
|
-
import { assert, assertUsage } from '../../utils.js';
|
|
3
|
+
import { assert, assertUsage, assertWarning } from '../../utils.js';
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
5
|
async function getViteDevScripts() {
|
|
6
6
|
const globalContext = getGlobalContext();
|
|
@@ -16,7 +16,8 @@ async function getViteDevScripts() {
|
|
|
16
16
|
assertUsage(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), 'Vite plugins that minify the HTML are not supported by vike, see https://github.com/vikejs/vike/issues/224');
|
|
17
17
|
assertUsage(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), 'You are using a Vite Plugin that transforms the HTML in a way that conflicts with vike. Create a new GitHub ticket to discuss a solution.');
|
|
18
18
|
const viteInjection = fakeHtml.slice(fakeHtmlBegin.length, -1 * fakeHtmlEnd.length);
|
|
19
|
-
assert(viteInjection.includes('script')
|
|
19
|
+
assert(viteInjection.includes('script'));
|
|
20
|
+
assertWarning(!viteInjection.includes('import('), 'Unexpected Vite HMR code. Reach out to a Vike maintainer on GitHub.', { onlyOnce: true });
|
|
20
21
|
const scriptTags = viteInjection;
|
|
21
22
|
return scriptTags;
|
|
22
23
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { mergeScriptTags };
|
|
2
|
-
declare function mergeScriptTags(scriptTagsHtml: string
|
|
2
|
+
declare function mergeScriptTags(scriptTagsHtml: string): string;
|
|
@@ -4,7 +4,7 @@ import { scriptAttrs } from './inferHtmlTags.js';
|
|
|
4
4
|
const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims;
|
|
5
5
|
const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
6
6
|
const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
7
|
-
function mergeScriptTags(scriptTagsHtml
|
|
7
|
+
function mergeScriptTags(scriptTagsHtml) {
|
|
8
8
|
let scriptTag = '';
|
|
9
9
|
const scripts = parseScripts(scriptTagsHtml);
|
|
10
10
|
// We need to merge module scripts to ensure execution order
|
|
@@ -19,13 +19,7 @@ function mergeScriptTags(scriptTagsHtml, isProduction) {
|
|
|
19
19
|
const hasInnerHtml = !!innerHtml.trim();
|
|
20
20
|
if (src) {
|
|
21
21
|
assert(!hasInnerHtml);
|
|
22
|
-
|
|
23
|
-
contents.push(`import ${JSON.stringify(src)};`);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// Ensure HMR preamble code is executed before client entries
|
|
27
|
-
contents.push(`import(${JSON.stringify(src)});`);
|
|
28
|
-
}
|
|
22
|
+
contents.push(`import ${JSON.stringify(src)};`);
|
|
29
23
|
}
|
|
30
24
|
else if (hasInnerHtml) {
|
|
31
25
|
innerHtml = innerHtml.split('\n').filter(Boolean).join('\n');
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export { logErrorHint };
|
|
2
|
-
export {
|
|
3
|
-
export { isKnownError };
|
|
4
|
-
export { getHint };
|
|
2
|
+
export { getErrorHint };
|
|
5
3
|
declare function logErrorHint(error: unknown): void;
|
|
6
|
-
declare function
|
|
7
|
-
declare function isKnownError(error: unknown): false | string;
|
|
8
|
-
declare function isCjsEsmError(error: unknown): boolean | string[];
|
|
4
|
+
declare function getErrorHint(error: unknown): null | string;
|
|
@@ -1,49 +1,89 @@
|
|
|
1
1
|
export { logErrorHint };
|
|
2
|
-
// For ./logErrorHint
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
export { getHint };
|
|
6
|
-
import { assert, formatHintLog, isArray, isNotNullish, isObject, unique } from '../utils.js';
|
|
2
|
+
// For ./logErrorHint/getErrorHint.spec.ts
|
|
3
|
+
export { getErrorHint };
|
|
4
|
+
import { assert, formatHintLog, isObject } from '../utils.js';
|
|
7
5
|
import pc from '@brillout/picocolors';
|
|
8
|
-
const
|
|
6
|
+
const hintDefault = 'The error could be a CJS/ESM issue, see https://vike.dev/broken-npm-package';
|
|
7
|
+
const hintLinkPrefix = 'To fix this error, see ';
|
|
8
|
+
const errorsMisc = [
|
|
9
9
|
{
|
|
10
10
|
errMsg: 'jsxDEV is not a function',
|
|
11
|
-
link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096'
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
15
|
-
link: 'https://vike.dev/broken-npm-package#react-invalid-component'
|
|
11
|
+
link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096',
|
|
12
|
+
shouldMentionNodeModules: false
|
|
16
13
|
},
|
|
17
14
|
{
|
|
18
15
|
// ```
|
|
19
16
|
// Error [RollupError]: Could not resolve "../dist/client/assets.json" from "renderer/+onRenderHtml.tsx"
|
|
20
17
|
// ```
|
|
21
18
|
errMsg: 'assets.json',
|
|
22
|
-
link: 'https://vike.dev/getGlobalContext'
|
|
19
|
+
link: 'https://vike.dev/getGlobalContext',
|
|
20
|
+
shouldMentionNodeModules: false
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
const errorsReact = [
|
|
24
|
+
{
|
|
25
|
+
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
26
|
+
link: 'https://vike.dev/broken-npm-package#react-invalid-component',
|
|
27
|
+
// The stack trace can be user-land while the import is coming from node_modules
|
|
28
|
+
shouldMentionNodeModules: false
|
|
23
29
|
},
|
|
24
30
|
{
|
|
31
|
+
// React's "Invalid hook call.", see https://github.com/vikejs/vike/discussions/1637#discussioncomment-9424712
|
|
32
|
+
errMsg: "Cannot read properties of null (reading 'useContext')"
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
const errorsCjsEsm_withPreciseLink = [
|
|
36
|
+
{
|
|
37
|
+
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
25
38
|
errMsg: /Named export.*not found/i,
|
|
26
|
-
link: 'https://vike.dev/broken-npm-package#named-export-not-found'
|
|
39
|
+
link: 'https://vike.dev/broken-npm-package#named-export-not-found',
|
|
40
|
+
// It seems that this always points to an npm package import.
|
|
41
|
+
shouldMentionNodeModules: false
|
|
27
42
|
}
|
|
28
43
|
];
|
|
44
|
+
const errorsCjsEsm = [
|
|
45
|
+
{ errMsg: 'ERR_UNSUPPORTED_DIR_IMPORT' },
|
|
46
|
+
{ errMsg: 'ERR_REQUIRE_ESM' },
|
|
47
|
+
{ errMsg: 'Must use import' },
|
|
48
|
+
{ errMsg: /Cannot find \S+ '(\S+)' imported from (\S+)/ },
|
|
49
|
+
{ errMsg: 'ERR_UNKNOWN_FILE_EXTENSION' },
|
|
50
|
+
{ errMsg: /Unknown file extension "\S+" for (\S+)/ },
|
|
51
|
+
// `SyntaxError: Cannot use import statement outside a module`.
|
|
52
|
+
{
|
|
53
|
+
errMsg: 'Cannot use import statement',
|
|
54
|
+
// Since user code is always ESM, this error must always originate from an npm package.
|
|
55
|
+
shouldMentionNodeModules: false
|
|
56
|
+
},
|
|
57
|
+
{ errMsg: 'is not exported' },
|
|
58
|
+
{ errMsg: 'Cannot read properties of undefined' },
|
|
59
|
+
{ errMsg: '.default is not' },
|
|
60
|
+
// Using CJS inside ESM modules.
|
|
61
|
+
{ errMsg: 'require is not a function' },
|
|
62
|
+
{ errMsg: 'exports is not defined' },
|
|
63
|
+
{ errMsg: 'module is not defined' },
|
|
64
|
+
{ errMsg: 'window is not defined' },
|
|
65
|
+
{ errMsg: 'not defined in ES' },
|
|
66
|
+
{ errMsg: "Unexpected token 'export'" }
|
|
67
|
+
];
|
|
29
68
|
function logErrorHint(error) {
|
|
30
69
|
/* Collect errors for ./logErrorHint.spec.ts
|
|
31
70
|
collectError(error)
|
|
32
71
|
//*/
|
|
33
|
-
const hint =
|
|
72
|
+
const hint = getErrorHint(error);
|
|
34
73
|
if (hint)
|
|
35
74
|
logHint(hint);
|
|
36
75
|
}
|
|
37
|
-
function
|
|
76
|
+
function getErrorHint(error) {
|
|
38
77
|
{
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
const knownErr = isKnownError(error);
|
|
79
|
+
if (knownErr) {
|
|
80
|
+
if (knownErr.link) {
|
|
81
|
+
return hintLinkPrefix + knownErr.link;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return hintDefault;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
47
87
|
}
|
|
48
88
|
return null;
|
|
49
89
|
}
|
|
@@ -54,266 +94,42 @@ function logHint(hint) {
|
|
|
54
94
|
}
|
|
55
95
|
function isKnownError(error) {
|
|
56
96
|
const anywhere = getAnywhere(error);
|
|
57
|
-
const knownErr =
|
|
58
|
-
|
|
97
|
+
const knownErr = [
|
|
98
|
+
//
|
|
99
|
+
...errorsMisc,
|
|
100
|
+
...errorsReact,
|
|
101
|
+
...errorsCjsEsm_withPreciseLink,
|
|
102
|
+
...errorsCjsEsm
|
|
103
|
+
].find((knownErorr) => {
|
|
104
|
+
if (!includesLowercase(anywhere, knownErorr.errMsg))
|
|
105
|
+
return false;
|
|
106
|
+
if (knownErorr.shouldMentionNodeModules !== false && !includesLowercase(anywhere, 'node_modules'))
|
|
107
|
+
return false;
|
|
108
|
+
return true;
|
|
59
109
|
});
|
|
60
110
|
if (!knownErr)
|
|
61
111
|
return false;
|
|
62
|
-
return knownErr
|
|
63
|
-
}
|
|
64
|
-
// `false` -> noop
|
|
65
|
-
// `true` -> generic message
|
|
66
|
-
// `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
67
|
-
function isCjsEsmError(error) {
|
|
68
|
-
const res = check(error);
|
|
69
|
-
if (res === true || res === false)
|
|
70
|
-
return res;
|
|
71
|
-
const packageNames = normalizeRes(res);
|
|
72
|
-
if (packageNames === false)
|
|
73
|
-
return packageNames;
|
|
74
|
-
packageNames.forEach((packageName) => {
|
|
75
|
-
assert(!['vite', 'vike'].includes(packageName));
|
|
76
|
-
});
|
|
77
|
-
// We don't use this anymore: we could return `true` instead. Shall we remove returning a list of npm packages?
|
|
78
|
-
return packageNames;
|
|
79
|
-
}
|
|
80
|
-
function normalizeRes(res) {
|
|
81
|
-
let packageNames = isArray(res) ? res : [res];
|
|
82
|
-
packageNames = unique(packageNames.filter(isNotNullish).filter((packageName) => packageName !== '@brillout/import'));
|
|
83
|
-
if (packageNames.length === 0)
|
|
84
|
-
return false;
|
|
85
|
-
return packageNames;
|
|
112
|
+
return knownErr;
|
|
86
113
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const relatedNpmPackages = normalizeArray([
|
|
95
|
-
packageName_stack1 || null,
|
|
96
|
-
packageName_stack2 || null,
|
|
97
|
-
(message && extractFromNodeModulesPath(message)) || null
|
|
98
|
-
])
|
|
99
|
-
*/
|
|
100
|
-
// ERR_UNSUPPORTED_DIR_IMPORT
|
|
101
|
-
{
|
|
102
|
-
const packageName = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
|
|
103
|
-
if (packageName)
|
|
104
|
-
return packageName;
|
|
105
|
-
}
|
|
106
|
-
// ERR_UNKNOWN_FILE_EXTENSION
|
|
107
|
-
{
|
|
108
|
-
const packageName = parseUnkownFileExtensionMessage(anywhere);
|
|
109
|
-
if (packageName)
|
|
110
|
-
return packageName;
|
|
111
|
-
}
|
|
112
|
-
{
|
|
113
|
-
const packageName = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
|
|
114
|
-
if (packageName)
|
|
115
|
-
return packageName;
|
|
114
|
+
function includesLowercase(str, substr) {
|
|
115
|
+
if (substr instanceof RegExp) {
|
|
116
|
+
let { flags } = substr;
|
|
117
|
+
if (!flags.includes('i'))
|
|
118
|
+
flags += 'i';
|
|
119
|
+
const regex = new RegExp(substr.source, flags);
|
|
120
|
+
return regex.test(str);
|
|
116
121
|
}
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
if (packageName)
|
|
120
|
-
return packageName;
|
|
121
|
-
}
|
|
122
|
-
// Using CJS inside ESM modules.
|
|
123
|
-
if (includes(anywhere, 'require is not a function') ||
|
|
124
|
-
includes(anywhere, 'exports is not defined') ||
|
|
125
|
-
includes(anywhere, 'module is not defined') ||
|
|
126
|
-
includes(anywhere, 'window is not defined') ||
|
|
127
|
-
includes(anywhere, 'not defined in ES')) {
|
|
128
|
-
if (packageName_stack1)
|
|
129
|
-
return packageName_stack1;
|
|
130
|
-
}
|
|
131
|
-
if (includes(anywhere, "Unexpected token 'export'")) {
|
|
132
|
-
if (packageName_stack2)
|
|
133
|
-
return packageName_stack2;
|
|
134
|
-
if (packageName_stack1)
|
|
135
|
-
return packageName_stack1;
|
|
136
|
-
}
|
|
137
|
-
// ERR_REQUIRE_ESM
|
|
138
|
-
if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
|
|
139
|
-
/* The issue is the importer, not the importee.
|
|
140
|
-
if (relatedNpmPackages) return relatedNpmPackages
|
|
141
|
-
*/
|
|
142
|
-
{
|
|
143
|
-
if (packageName_stack1)
|
|
144
|
-
return packageName_stack1;
|
|
145
|
-
}
|
|
146
|
-
if (isRelatedToNodeModules)
|
|
147
|
-
return true;
|
|
122
|
+
if (typeof substr === 'string') {
|
|
123
|
+
return str.toLowerCase().includes(substr.toLowerCase());
|
|
148
124
|
}
|
|
149
|
-
|
|
150
|
-
{
|
|
151
|
-
const packageNames = parseNodeModulesPath('ERR_REQUIRE_ESM', anywhere)
|
|
152
|
-
if (packageNames) return packageNames
|
|
153
|
-
}
|
|
154
|
-
{
|
|
155
|
-
const packageNames = parseNodeModulesPath('Must use import', anywhere)
|
|
156
|
-
if (packageNames) return packageNames
|
|
157
|
-
}
|
|
158
|
-
*/
|
|
159
|
-
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
160
|
-
{
|
|
161
|
-
const packageName = parseImportFrom(anywhere);
|
|
162
|
-
if (packageName)
|
|
163
|
-
return packageName;
|
|
164
|
-
}
|
|
165
|
-
if (includes(anywhere, 'Cannot read properties of undefined')) {
|
|
166
|
-
if (isRelatedToNodeModules) {
|
|
167
|
-
/* We return true because relatedNpmPackages points to the importer but the problematic npm package is the importee
|
|
168
|
-
if (relatedNpmPackages) return relatedNpmPackages
|
|
169
|
-
*/
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// ERR_MODULE_NOT_FOUND
|
|
174
|
-
{
|
|
175
|
-
const packageNames = parseCannotFindMessage(anywhere);
|
|
176
|
-
if (packageNames)
|
|
177
|
-
return packageNames;
|
|
178
|
-
}
|
|
179
|
-
if (
|
|
180
|
-
// `SyntaxError: Cannot use import statement outside a module`.
|
|
181
|
-
// Since user code is always ESM, this error must always originate from an npm package.
|
|
182
|
-
includes(anywhere, 'Cannot use import statement') ||
|
|
183
|
-
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
184
|
-
// It seems that this always points to an npm package import.
|
|
185
|
-
/Named export.*not found/i.test(anywhere)) {
|
|
186
|
-
/* We return true even if fromNodeModules is false because the errors always relate to npm packages.
|
|
187
|
-
if (fromNodeModules) return true
|
|
188
|
-
*/
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
function parseCannotFindMessage(str) {
|
|
194
|
-
const match = /Cannot find \S+ '(\S+)' imported from (\S+)/.exec(str);
|
|
195
|
-
if (!match)
|
|
196
|
-
return false;
|
|
197
|
-
// const packageNameCannotFind = extractFromPath(match[1]!)
|
|
198
|
-
const packageNameFrom = extractFromPath(match[2]);
|
|
199
|
-
return normalizeArray([
|
|
200
|
-
// packageNameCannotFind,
|
|
201
|
-
packageNameFrom
|
|
202
|
-
]);
|
|
203
|
-
}
|
|
204
|
-
function parseUnkownFileExtensionMessage(str) {
|
|
205
|
-
const match = /Unknown file extension "\S+" for (\S+)/.exec(str);
|
|
206
|
-
if (!match)
|
|
207
|
-
return false;
|
|
208
|
-
const filePath = match[1];
|
|
209
|
-
const packageName = extractFromPath(filePath);
|
|
210
|
-
return packageName;
|
|
211
|
-
}
|
|
212
|
-
function parseImportFrom(str) {
|
|
213
|
-
const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
|
|
214
|
-
if (!match)
|
|
215
|
-
return false;
|
|
216
|
-
const importPath = match[1];
|
|
217
|
-
const packageName = extractFromPath(importPath);
|
|
218
|
-
return packageName;
|
|
219
|
-
}
|
|
220
|
-
function parseNodeModulesPathMessage(begin, str) {
|
|
221
|
-
str = str.replaceAll('\\', '/');
|
|
222
|
-
const regex = new RegExp(`${begin}.*(node_modules\\/\\S+)`);
|
|
223
|
-
const match = regex.exec(str);
|
|
224
|
-
if (!match)
|
|
225
|
-
return false;
|
|
226
|
-
const importPath = match[1];
|
|
227
|
-
return extractFromNodeModulesPath(importPath);
|
|
228
|
-
}
|
|
229
|
-
function getPackageName_stack1(err) {
|
|
230
|
-
const errStack = getErrStack(err);
|
|
231
|
-
if (!errStack)
|
|
232
|
-
return false;
|
|
233
|
-
const firstLineStackTrace = errStack.split('\n').filter((line) => line.startsWith(' at '))[0];
|
|
234
|
-
if (!firstLineStackTrace)
|
|
235
|
-
return false;
|
|
236
|
-
return extractFromNodeModulesPath(firstLineStackTrace);
|
|
237
|
-
}
|
|
238
|
-
/** See https://github.com/brillout/repro_node-syntax-error#nodejs-behavior */
|
|
239
|
-
function getPackageName_stack2(err) {
|
|
240
|
-
const errStack = getErrStack(err);
|
|
241
|
-
if (!errStack)
|
|
242
|
-
return false;
|
|
243
|
-
const firstLine = errStack.trim().split('\n')[0];
|
|
244
|
-
return extractFromNodeModulesPath(firstLine);
|
|
245
|
-
}
|
|
246
|
-
function extractFromPath(filePath) {
|
|
247
|
-
assert(filePath);
|
|
248
|
-
filePath = clean(filePath);
|
|
249
|
-
filePath = filePath.replaceAll('\\', '/');
|
|
250
|
-
let packageName;
|
|
251
|
-
if (!filePath.includes('node_modules/')) {
|
|
252
|
-
packageName = filePath;
|
|
253
|
-
if (packageName.startsWith('/'))
|
|
254
|
-
return null;
|
|
255
|
-
if (packageName.startsWith('.'))
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
packageName = filePath.split('node_modules/').pop();
|
|
260
|
-
// This assert is fairly risk, we should eventually remove it
|
|
261
|
-
assert(!packageName.startsWith('.'));
|
|
262
|
-
// This assert is fairly risk, we should eventually remove it
|
|
263
|
-
assert(!packageName.startsWith('/'));
|
|
264
|
-
}
|
|
265
|
-
if (!packageName)
|
|
266
|
-
return null;
|
|
267
|
-
packageName = packageName.split('/').slice(0, 2).join('/');
|
|
268
|
-
if (!packageName.startsWith('@')) {
|
|
269
|
-
packageName = packageName.split('/')[0];
|
|
270
|
-
}
|
|
271
|
-
packageName = clean(packageName);
|
|
272
|
-
return packageName;
|
|
273
|
-
}
|
|
274
|
-
function clean(packageName) {
|
|
275
|
-
const b = ['"', "'", '(', ')'];
|
|
276
|
-
if (b.includes(packageName[0])) {
|
|
277
|
-
packageName = packageName.slice(1);
|
|
278
|
-
}
|
|
279
|
-
if (b.includes(packageName[packageName.length - 1])) {
|
|
280
|
-
packageName = packageName.slice(0, -1);
|
|
281
|
-
}
|
|
282
|
-
return packageName;
|
|
125
|
+
assert(false);
|
|
283
126
|
}
|
|
284
|
-
function
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
return
|
|
290
|
-
}
|
|
291
|
-
function includes(str1, str2) {
|
|
292
|
-
if (!str1)
|
|
293
|
-
return false;
|
|
294
|
-
if (str2 instanceof RegExp) {
|
|
295
|
-
return str2.test(str1.toLowerCase());
|
|
296
|
-
}
|
|
297
|
-
if (typeof str2 === 'string') {
|
|
298
|
-
return str1.toLowerCase().includes(str2.toLowerCase());
|
|
299
|
-
}
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
function includesNodeModules(str) {
|
|
303
|
-
if (!str)
|
|
304
|
-
return false;
|
|
305
|
-
str = str.replaceAll('\\', '/');
|
|
306
|
-
if (!str.includes('node_modules/'))
|
|
307
|
-
return false;
|
|
308
|
-
if (str.includes('node_modules/vite/'))
|
|
309
|
-
return false;
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
function normalizeArray(arr) {
|
|
313
|
-
const arrNormalized = arr.filter(isNotNullish);
|
|
314
|
-
if (arrNormalized.length === 0)
|
|
315
|
-
return null;
|
|
316
|
-
return arrNormalized;
|
|
127
|
+
function getAnywhere(error) {
|
|
128
|
+
const code = getErrCode(error);
|
|
129
|
+
const message = getErrMessage(error);
|
|
130
|
+
const stack = getErrStack(error);
|
|
131
|
+
const anywhere = [code, message, stack].filter(Boolean).join('\n');
|
|
132
|
+
return anywhere;
|
|
317
133
|
}
|
|
318
134
|
function getErrMessage(err) {
|
|
319
135
|
if (!isObject(err))
|
|
@@ -342,13 +158,6 @@ function getErrStack(err) {
|
|
|
342
158
|
return null;
|
|
343
159
|
return err.stack;
|
|
344
160
|
}
|
|
345
|
-
function getAnywhere(error) {
|
|
346
|
-
const code = getErrCode(error);
|
|
347
|
-
const message = getErrMessage(error);
|
|
348
|
-
const stack = getErrStack(error);
|
|
349
|
-
const anywhere = [code, message, stack].filter(Boolean).join('\n');
|
|
350
|
-
return anywhere;
|
|
351
|
-
}
|
|
352
161
|
function collectError(err) {
|
|
353
162
|
console.log([
|
|
354
163
|
'{',
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
export { parseGlobResults };
|
|
2
|
-
|
|
2
|
+
// TODO/v1-release: remove old design code, and remove all assertions.
|
|
3
|
+
import { assert, hasProp, isCallable, isObject, cast, isArray } from '../utils.js';
|
|
3
4
|
import { assertExportValues } from './assert_exports_old_design.js';
|
|
4
5
|
import { getPageFileObject } from './getPageFileObject.js';
|
|
5
6
|
import { fileTypes } from './fileTypes.js';
|
|
6
|
-
import { assertPageConfigGlobalSerialized, assertPageConfigsSerialized } from '../page-configs/serialize/assertPageConfigsSerialized.js';
|
|
7
7
|
import { parsePageConfigs } from '../page-configs/serialize/parsePageConfigs.js';
|
|
8
8
|
function parseGlobResults(pageFilesExports) {
|
|
9
|
-
assert(hasProp(pageFilesExports, 'isGeneratedFile'));
|
|
10
|
-
assert(pageFilesExports.isGeneratedFile !== false, `vike was re-installed(/re-built). Restart your app.`);
|
|
11
|
-
assert(pageFilesExports.isGeneratedFile === true, `\`isGeneratedFile === ${pageFilesExports.isGeneratedFile}\``);
|
|
12
9
|
assert(hasProp(pageFilesExports, 'pageFilesLazy', 'object'));
|
|
13
10
|
assert(hasProp(pageFilesExports, 'pageFilesEager', 'object'));
|
|
14
11
|
assert(hasProp(pageFilesExports, 'pageFilesExportNamesLazy', 'object'));
|
|
@@ -41,8 +38,6 @@ function parseGlobResults(pageFilesExports) {
|
|
|
41
38
|
pageFile.loadExportNames = async () => {
|
|
42
39
|
if (!('exportNames' in pageFile)) {
|
|
43
40
|
const moduleExports = await loadModule();
|
|
44
|
-
// Vite 2 seems to choke following assertion: https://github.com/vikejs/vike/issues/455
|
|
45
|
-
assertUsage('exportNames' in moduleExports, 'You seem to be using Vite 2 but the latest vike versions only work with Vite 3');
|
|
46
41
|
assert(hasProp(moduleExports, 'exportNames', 'string[]'), pageFile.filePath);
|
|
47
42
|
pageFile.exportNames = moduleExports.exportNames;
|
|
48
43
|
}
|
|
@@ -88,3 +83,15 @@ function parseGlobResult(globObject) {
|
|
|
88
83
|
function assertLoadModule(globValue) {
|
|
89
84
|
assert(isCallable(globValue));
|
|
90
85
|
}
|
|
86
|
+
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
87
|
+
assert(isArray(pageConfigsSerialized));
|
|
88
|
+
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
89
|
+
assert(isObject(pageConfigSerialized));
|
|
90
|
+
assert(hasProp(pageConfigSerialized, 'pageId', 'string'));
|
|
91
|
+
assert(hasProp(pageConfigSerialized, 'routeFilesystem'));
|
|
92
|
+
assert(hasProp(pageConfigSerialized, 'configValuesSerialized'));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
96
|
+
assert(hasProp(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
97
|
+
}
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { assertPageConfigGlobalSerialized };
|
|
3
|
-
import type { PageConfigGlobalRuntimeSerialized, PageConfigRuntimeSerialized } from './PageConfigSerialized.js';
|
|
4
|
-
declare function assertPageConfigsSerialized(pageConfigsSerialized: unknown): asserts pageConfigsSerialized is PageConfigRuntimeSerialized[];
|
|
5
|
-
declare function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized: unknown): asserts pageConfigGlobalSerialized is PageConfigGlobalRuntimeSerialized;
|
|
1
|
+
export {};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { assertPageConfigGlobalSerialized };
|
|
3
|
-
import { assert, isObject, hasProp, isArray } from '../../utils.js';
|
|
4
|
-
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
5
|
-
assert(isArray(pageConfigsSerialized));
|
|
6
|
-
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
7
|
-
assert(isObject(pageConfigSerialized));
|
|
8
|
-
assert(hasProp(pageConfigSerialized, 'pageId', 'string'));
|
|
9
|
-
assert(hasProp(pageConfigSerialized, 'routeFilesystem'));
|
|
10
|
-
assert(hasProp(pageConfigSerialized, 'configValuesSerialized'));
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
14
|
-
assert(hasProp(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
15
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.171-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.171-commit-2876124";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.171-commit-
|
|
6
|
+
projectVersion: "0.4.171-commit-2876124";
|
|
7
7
|
};
|