vike 0.4.167 → 0.4.168
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/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +0 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +121 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +27 -8
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +13 -1
- package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/history.js +23 -19
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +121 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +28 -9
- package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +13 -1
- package/dist/esm/shared/addUrlComputedProps.d.ts +2 -2
- package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -10,6 +10,7 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
11
|
const util_1 = require("util");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
+
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
13
14
|
const execA = (0, util_1.promisify)(child_process_1.exec);
|
|
14
15
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
15
16
|
(0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
|
|
@@ -34,6 +35,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
34
35
|
else {
|
|
35
36
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
36
37
|
}
|
|
38
|
+
files = files.filter((file) => !(0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(file));
|
|
37
39
|
{
|
|
38
40
|
const timeAfter = new Date().getTime();
|
|
39
41
|
const timeSpent = timeAfter - timeBefore;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -68,7 +68,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
68
68
|
const { importPath: importPathAbsolute } = importData;
|
|
69
69
|
const filePathAbsoluteFilesystem = (0, resolveImportPath_js_1.resolveImportPath)(importData, configFilePath);
|
|
70
70
|
(0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
71
|
-
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
72
71
|
const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
73
72
|
extendsConfigFiles.push(filePath);
|
|
74
73
|
});
|
|
@@ -81,13 +80,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
81
80
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
82
81
|
return { extendsConfigs, extendsFilePaths };
|
|
83
82
|
}
|
|
84
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
85
|
-
// We preserve this feature because we may need it for eject
|
|
86
|
-
(0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath, {
|
|
87
|
-
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
|
88
|
-
cannotBePathAlias: true
|
|
89
|
-
}) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
90
|
-
}
|
|
91
83
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
92
84
|
const { filePathToShowToUser } = configFilePath;
|
|
93
85
|
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
@@ -3,7 +3,7 @@ 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.isTemporaryBuildFile = exports.getConfigExecutionErrorIntroMsg = exports.getConfigBuildErrorFormatted = exports.transpileAndExecuteFile = void 0;
|
|
7
7
|
const esbuild_1 = require("esbuild");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -82,87 +82,96 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
82
82
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
83
83
|
treeShaking: false,
|
|
84
84
|
minify: false,
|
|
85
|
-
metafile:
|
|
86
|
-
bundle:
|
|
85
|
+
metafile: true,
|
|
86
|
+
bundle: true
|
|
87
87
|
};
|
|
88
|
-
let pointerImports;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
88
|
+
let pointerImports = {};
|
|
89
|
+
options.plugins = [
|
|
90
|
+
// Determine whether an import should be:
|
|
91
|
+
// - A pointer import
|
|
92
|
+
// - Externalized
|
|
93
|
+
{
|
|
94
|
+
name: 'vike-esbuild',
|
|
95
|
+
setup(build) {
|
|
96
|
+
// https://github.com/brillout/esbuild-playground
|
|
97
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
98
|
+
if (args.kind !== 'import-statement')
|
|
99
|
+
return;
|
|
100
|
+
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
101
101
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
103
|
+
return;
|
|
104
|
+
const { path, ...opts } = args;
|
|
105
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
106
|
+
const resolved = await build.resolve(path, opts);
|
|
107
|
+
if (resolved.errors.length > 0) {
|
|
108
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
|
|
109
|
+
pointerImports[args.path] = false
|
|
110
|
+
return { external: true }
|
|
111
|
+
*/
|
|
112
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
113
|
+
cleanEsbuildErrors(resolved.errors);
|
|
114
|
+
return resolved;
|
|
115
|
+
}
|
|
116
|
+
(0, utils_js_1.assert)(resolved.path);
|
|
117
|
+
resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
|
|
118
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
119
|
+
// - This is temporary, see comment below.
|
|
120
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
121
|
+
const isPointerImport = transformImports === 'all' ||
|
|
116
122
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
117
123
|
!(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
name: 'vike:dependency-tracker',
|
|
145
|
-
setup(b) {
|
|
146
|
-
b.onLoad({ filter: /./ }, (args) => {
|
|
147
|
-
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
148
|
-
let { path } = args;
|
|
149
|
-
path = (0, utils_js_1.toPosixPath)(path);
|
|
150
|
-
getVikeConfig_js_1.vikeConfigDependencies.add(path);
|
|
151
|
-
return undefined;
|
|
152
|
-
});
|
|
153
|
-
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
154
|
-
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
155
|
-
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
156
|
-
* ```bash
|
|
157
|
-
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
158
|
-
* ```
|
|
159
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
160
|
-
b.onResolve(...)
|
|
161
|
-
*/
|
|
162
|
-
}
|
|
124
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
125
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
126
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
127
|
+
isVikeExtensionConfigImport ||
|
|
128
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
129
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
130
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
131
|
+
resolved.errors.length > 0;
|
|
132
|
+
pointerImports[resolved.path] = isPointerImport;
|
|
133
|
+
(0, utils_js_1.assertPosixPath)(resolved.path);
|
|
134
|
+
const isExternal = isPointerImport ||
|
|
135
|
+
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
136
|
+
resolved.path.includes('/node_modules/');
|
|
137
|
+
if (debug.isActivated)
|
|
138
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
139
|
+
// We need esbuild to resolve path aliases so that we can use:
|
|
140
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
141
|
+
// assertIsNpmPackageImport()
|
|
142
|
+
(0, utils_js_1.assertPathIsFilesystemAbsolute)(resolved.path);
|
|
143
|
+
if (isExternal) {
|
|
144
|
+
return { external: true, path: resolved.path };
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
163
150
|
}
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
},
|
|
152
|
+
// Track dependencies
|
|
153
|
+
{
|
|
154
|
+
name: 'vike:dependency-tracker',
|
|
155
|
+
setup(b) {
|
|
156
|
+
b.onLoad({ filter: /./ }, (args) => {
|
|
157
|
+
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
158
|
+
let { path } = args;
|
|
159
|
+
path = (0, utils_js_1.toPosixPath)(path);
|
|
160
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(path);
|
|
161
|
+
return undefined;
|
|
162
|
+
});
|
|
163
|
+
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
164
|
+
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
165
|
+
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
166
|
+
* ```bash
|
|
167
|
+
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
168
|
+
* ```
|
|
169
|
+
* - But implementing a fix is complex and isn't worth it.
|
|
170
|
+
b.onResolve(...)
|
|
171
|
+
*/
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
];
|
|
166
175
|
let result;
|
|
167
176
|
try {
|
|
168
177
|
result = await (0, esbuild_1.build)(options);
|
|
@@ -172,15 +181,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
172
181
|
throw err;
|
|
173
182
|
}
|
|
174
183
|
// Track dependencies
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
+
(0, utils_js_1.assert)(result.metafile);
|
|
185
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
186
|
+
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
187
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
188
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
|
|
189
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
190
|
+
});
|
|
184
191
|
const code = result.outputFiles[0].text;
|
|
185
192
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
186
193
|
return { code, pointerImports };
|
|
@@ -189,7 +196,7 @@ async function executeTranspiledFile(filePath, code) {
|
|
|
189
196
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
190
197
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
191
198
|
// - But seems to break source maps, so I don't think it's worth it
|
|
192
|
-
const filePathTmp =
|
|
199
|
+
const filePathTmp = getTemporaryBuildFilePath(filePathAbsoluteFilesystem);
|
|
193
200
|
fs_1.default.writeFileSync(filePathTmp, code);
|
|
194
201
|
const clean = () => fs_1.default.unlinkSync(filePathTmp);
|
|
195
202
|
let fileExports = {};
|
|
@@ -248,22 +255,21 @@ function getConfigExecutionErrorIntroMsg(err) {
|
|
|
248
255
|
return errIntroMsg ?? null;
|
|
249
256
|
}
|
|
250
257
|
exports.getConfigExecutionErrorIntroMsg = getConfigExecutionErrorIntroMsg;
|
|
251
|
-
|
|
252
|
-
function getFilePathTmp(filePathAbsoluteFilesystem) {
|
|
258
|
+
function getTemporaryBuildFilePath(filePathAbsoluteFilesystem) {
|
|
253
259
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
254
260
|
const dirname = path_1.default.posix.dirname(filePathAbsoluteFilesystem);
|
|
255
261
|
const filename = path_1.default.posix.basename(filePathAbsoluteFilesystem);
|
|
256
|
-
// Syntax with semicolon `
|
|
257
|
-
const
|
|
258
|
-
|
|
262
|
+
// Syntax with semicolon `build:${/*...*/}` doesn't work on Windows: https://github.com/vikejs/vike/issues/800#issuecomment-1517329455
|
|
263
|
+
const filePathTmp = path_1.default.posix.join(dirname, `${filename}.build-${(0, utils_js_1.getRandomId)(12)}.mjs`);
|
|
264
|
+
(0, utils_js_1.assert)(isTemporaryBuildFile(filePathTmp));
|
|
259
265
|
return filePathTmp;
|
|
260
266
|
}
|
|
261
|
-
function
|
|
267
|
+
function isTemporaryBuildFile(filePath) {
|
|
262
268
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
263
269
|
const fileName = path_1.default.posix.basename(filePath);
|
|
264
|
-
return fileName
|
|
270
|
+
return /\.build-[a-z0-9]{12}\.mjs$/.test(fileName);
|
|
265
271
|
}
|
|
266
|
-
exports.
|
|
272
|
+
exports.isTemporaryBuildFile = isTemporaryBuildFile;
|
|
267
273
|
function isHeaderFile(filePath) {
|
|
268
274
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
269
275
|
const fileExtensions = getFileExtensions(filePath);
|
|
@@ -306,3 +312,23 @@ function getErrIntroMsg(operation, filePath) {
|
|
|
306
312
|
].join(' ');
|
|
307
313
|
return msg;
|
|
308
314
|
}
|
|
315
|
+
function cleanEsbuildErrors(errors) {
|
|
316
|
+
errors.forEach((e) => (e.notes = e.notes.filter((note) =>
|
|
317
|
+
// Remove note:
|
|
318
|
+
// ```shell
|
|
319
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
320
|
+
// ```
|
|
321
|
+
//
|
|
322
|
+
// From error:
|
|
323
|
+
// ```shell
|
|
324
|
+
// ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
|
|
325
|
+
//
|
|
326
|
+
// renderer/+config.h.js:1:29:
|
|
327
|
+
// 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
|
|
328
|
+
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
329
|
+
//
|
|
330
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
331
|
+
//
|
|
332
|
+
// ```
|
|
333
|
+
!note.text.includes('as external to exclude it from the bundle'))));
|
|
334
|
+
}
|
|
@@ -750,7 +750,7 @@ async function findPlusFiles(userRootDir, outDirRoot, isDev) {
|
|
|
750
750
|
}
|
|
751
751
|
function getConfigName(filePath) {
|
|
752
752
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
753
|
-
if ((0, transpileAndExecuteFile_js_1.
|
|
753
|
+
if ((0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(filePath))
|
|
754
754
|
return null;
|
|
755
755
|
const fileName = path_1.default.posix.basename(filePath);
|
|
756
756
|
// assertNoUnexpectedPlusSign(filePath, fileName)
|
|
@@ -781,7 +781,30 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
781
781
|
}
|
|
782
782
|
*/
|
|
783
783
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
784
|
-
|
|
784
|
+
{
|
|
785
|
+
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
786
|
+
const knownVikeExntensionConfigs = {
|
|
787
|
+
description: ui,
|
|
788
|
+
favicon: ui,
|
|
789
|
+
Head: ui,
|
|
790
|
+
Layout: ui,
|
|
791
|
+
onCreateApp: ['vike-vue'],
|
|
792
|
+
title: ui,
|
|
793
|
+
ssr: ui,
|
|
794
|
+
stream: ui,
|
|
795
|
+
Wrapper: ui
|
|
796
|
+
};
|
|
797
|
+
if (configName in knownVikeExntensionConfigs) {
|
|
798
|
+
const requiredVikeExtension = knownVikeExntensionConfigs[configName];
|
|
799
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
800
|
+
`${filePathToShowToUser} uses the config ${picocolors_1.default.cyan(configName)} (https://vike.dev/${configName})`,
|
|
801
|
+
`which requires the Vike extension ${requiredVikeExtension.map((e) => picocolors_1.default.bold(e)).join('/')}.`,
|
|
802
|
+
`Make sure to install the Vike extension,`,
|
|
803
|
+
`and make sure it applies to ${filePathToShowToUser} as explained at https://vike.dev/extends#inheritance.`
|
|
804
|
+
].join(' '));
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
let errMsg = `${filePathToShowToUser} sets an unknown config ${picocolors_1.default.cyan(configName)}`;
|
|
785
808
|
let configNameSimilar = null;
|
|
786
809
|
if (configName === 'page') {
|
|
787
810
|
configNameSimilar = 'Page';
|
|
@@ -789,17 +812,13 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
|
789
812
|
else {
|
|
790
813
|
configNameSimilar = (0, utils_js_1.getMostSimilar)(configName, configNames);
|
|
791
814
|
}
|
|
792
|
-
if (configNameSimilar
|
|
793
|
-
(0, utils_js_1.assert)(configNameSimilar);
|
|
815
|
+
if (configNameSimilar) {
|
|
794
816
|
(0, utils_js_1.assert)(configNameSimilar !== configName);
|
|
795
|
-
errMsg += `, did you mean to
|
|
817
|
+
errMsg += `, did you mean to set ${picocolors_1.default.cyan(configNameSimilar)} instead?`;
|
|
796
818
|
if (configName === 'page') {
|
|
797
819
|
errMsg += ` (The name of the config ${picocolors_1.default.cyan('Page')} starts with a capital letter ${picocolors_1.default.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
|
|
798
820
|
}
|
|
799
821
|
}
|
|
800
|
-
else {
|
|
801
|
-
errMsg += `, you need to define the config ${picocolors_1.default.cyan(configName)} by using ${picocolors_1.default.cyan('config.meta')} https://vike.dev/meta`;
|
|
802
|
-
}
|
|
803
822
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
804
823
|
}
|
|
805
824
|
function determineRouteFilesystem(locationId, configValueSources) {
|
|
@@ -15,7 +15,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
|
15
15
|
const clientDependencies = [];
|
|
16
16
|
clientDependencies.push({
|
|
17
17
|
id: (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageConfig.pageId, true),
|
|
18
|
-
onlyAssets: false,
|
|
18
|
+
onlyAssets: isClientSideRenderable ? false : true,
|
|
19
19
|
eagerlyImported: false
|
|
20
20
|
});
|
|
21
21
|
// In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
|
|
@@ -21,6 +21,10 @@ const knownErrors = [
|
|
|
21
21
|
// ```
|
|
22
22
|
errMsg: 'assets.json',
|
|
23
23
|
link: 'https://vike.dev/getGlobalContext'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
errMsg: /Named export.*not found/i,
|
|
27
|
+
link: 'https://vike.dev/broken-npm-package#named-export-not-found'
|
|
24
28
|
}
|
|
25
29
|
];
|
|
26
30
|
function logErrorHint(error) {
|
|
@@ -290,7 +294,15 @@ function extractFromNodeModulesPath(str) {
|
|
|
290
294
|
return packageName;
|
|
291
295
|
}
|
|
292
296
|
function includes(str1, str2) {
|
|
293
|
-
|
|
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;
|
|
294
306
|
}
|
|
295
307
|
function includesNodeModules(str) {
|
|
296
308
|
if (!str)
|
|
@@ -11,11 +11,11 @@ const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
|
11
11
|
function assertPathIsFilesystemAbsolute(p) {
|
|
12
12
|
(0, filesystemPathHandling_js_1.assertPosixPath)(p);
|
|
13
13
|
(0, assert_js_1.assert)(!p.startsWith('/@fs/'));
|
|
14
|
-
if (process.platform
|
|
15
|
-
(0, assert_js_1.assert)(
|
|
14
|
+
if (process.platform !== 'win32') {
|
|
15
|
+
(0, assert_js_1.assert)(p.startsWith('/'));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
(0, assert_js_1.assert)(
|
|
18
|
+
(0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.assertPathIsFilesystemAbsolute = assertPathIsFilesystemAbsolute;
|
|
@@ -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.
|
|
4
|
+
const PROJECT_VERSION = '0.4.168';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition, monkeyPatchHistoryPushState };
|
|
2
|
-
import { assert, assertUsage,
|
|
3
|
-
const globalObject = getGlobalObject('history.ts', {});
|
|
2
|
+
import { assert, assertUsage, hasProp, isObject } from './utils.js';
|
|
4
3
|
// Fill missing state information:
|
|
5
4
|
// - `history.state` can uninitialized (i.e. `null`):
|
|
6
5
|
// - The very first render
|
|
@@ -8,9 +7,10 @@ const globalObject = getGlobalObject('history.ts', {});
|
|
|
8
7
|
// - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `onLinkClick()` handler skips hash links).
|
|
9
8
|
// - State information may be incomplete if `history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
|
|
10
9
|
function initHistoryState() {
|
|
10
|
+
// No way found to add TypeScript types to `window.history.state`: https://github.com/microsoft/TypeScript/issues/36178
|
|
11
11
|
let state = window.history.state;
|
|
12
12
|
if (!state) {
|
|
13
|
-
state = {};
|
|
13
|
+
state = { _isVikeEnhanced: true };
|
|
14
14
|
}
|
|
15
15
|
let hasModifications = false;
|
|
16
16
|
if (!('timestamp' in state)) {
|
|
@@ -49,7 +49,7 @@ function saveScrollPosition() {
|
|
|
49
49
|
function pushHistory(url, overwriteLastHistoryEntry) {
|
|
50
50
|
if (!overwriteLastHistoryEntry) {
|
|
51
51
|
const timestamp = getTimestamp();
|
|
52
|
-
pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike' }, url);
|
|
52
|
+
pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike', _isVikeEnhanced: true }, url);
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
replaceHistoryState(getHistoryState(), url);
|
|
@@ -69,25 +69,29 @@ function assertState(state) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
function replaceHistoryState(state, url) {
|
|
72
|
-
|
|
72
|
+
const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
|
|
73
|
+
window.history.replaceState(state, '', url_);
|
|
73
74
|
}
|
|
74
75
|
function pushHistoryState(state, url) {
|
|
75
|
-
pushStateOriginal(
|
|
76
|
+
// Vike should call window.history.pushState() (and not the orignal `pushStateOriginal()`) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls, see https://github.com/vikejs/vike/issues/1582.
|
|
77
|
+
window.history.pushState(state, '', url);
|
|
76
78
|
}
|
|
77
79
|
function monkeyPatchHistoryPushState() {
|
|
78
|
-
|
|
79
|
-
window.history.pushState = (
|
|
80
|
-
assertUsage(
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
const pushStateOriginal = window.history.pushState.bind(window.history);
|
|
81
|
+
window.history.pushState = (stateOriginal = {}, ...rest) => {
|
|
82
|
+
assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), 'history.pushState(state) argument state must be an object');
|
|
83
|
+
const stateEnhanced = isVikeEnhanced(stateOriginal)
|
|
84
|
+
? stateOriginal
|
|
85
|
+
: {
|
|
86
|
+
_isVikeEnhanced: true,
|
|
87
|
+
scrollPosition: getScrollPosition(),
|
|
88
|
+
timestamp: getTimestamp(),
|
|
89
|
+
triggeredBy: 'user',
|
|
90
|
+
...stateOriginal
|
|
91
|
+
};
|
|
92
|
+
return pushStateOriginal(stateEnhanced, ...rest);
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
95
|
+
function isVikeEnhanced(state) {
|
|
96
|
+
return isObject(state) && '_isVikeEnhanced' in state;
|
|
93
97
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -5,6 +5,7 @@ import glob from 'fast-glob';
|
|
|
5
5
|
import { exec } from 'child_process';
|
|
6
6
|
import { promisify } from 'util';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
|
+
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
|
|
8
9
|
const execA = promisify(exec);
|
|
9
10
|
assertIsNotProductionRuntime();
|
|
10
11
|
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
@@ -29,6 +30,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
29
30
|
else {
|
|
30
31
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
31
32
|
}
|
|
33
|
+
files = files.filter((file) => !isTemporaryBuildFile(file));
|
|
32
34
|
{
|
|
33
35
|
const timeAfter = new Date().getTime();
|
|
34
36
|
const timeSpent = timeAfter - timeBefore;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { loadImportedFile };
|
|
3
3
|
export { loadValueFile };
|
|
4
4
|
export { loadConfigFile };
|
|
5
|
-
import { assert, assertUsage,
|
|
5
|
+
import { assert, assertUsage, hasProp, assertIsNotProductionRuntime } from '../../../../utils.js';
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
@@ -62,7 +62,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
62
62
|
const { importPath: importPathAbsolute } = importData;
|
|
63
63
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
64
64
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
65
|
-
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
66
65
|
const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
67
66
|
extendsConfigFiles.push(filePath);
|
|
68
67
|
});
|
|
@@ -75,13 +74,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
75
74
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
76
75
|
return { extendsConfigs, extendsFilePaths };
|
|
77
76
|
}
|
|
78
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
79
|
-
// We preserve this feature because we may need it for eject
|
|
80
|
-
assertWarning(isNpmPackageImport(importPath, {
|
|
81
|
-
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
|
82
|
-
cannotBePathAlias: true
|
|
83
|
-
}) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
84
|
-
}
|
|
85
77
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
86
78
|
const { filePathToShowToUser } = configFilePath;
|
|
87
79
|
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
@@ -2,7 +2,7 @@ export { transformFileImports };
|
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
export type { ImportData };
|
|
5
|
-
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports:
|
|
5
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
6
|
/**
|
|
7
7
|
* Data Structure holding info about import statement:
|
|
8
8
|
* `import { someExport as someImport } from './some-file'`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { transpileAndExecuteFile };
|
|
2
2
|
export { getConfigBuildErrorFormatted };
|
|
3
3
|
export { getConfigExecutionErrorIntroMsg };
|
|
4
|
-
export {
|
|
4
|
+
export { isTemporaryBuildFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
6
|
import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
7
|
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isConfigFile: boolean | 'is-extension-config'): Promise<{
|
|
@@ -9,4 +9,4 @@ declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir
|
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
11
11
|
declare function getConfigExecutionErrorIntroMsg(err: unknown): string | null;
|
|
12
|
-
declare function
|
|
12
|
+
declare function isTemporaryBuildFile(filePath: string): boolean;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { transpileAndExecuteFile };
|
|
2
2
|
export { getConfigBuildErrorFormatted };
|
|
3
3
|
export { getConfigExecutionErrorIntroMsg };
|
|
4
|
-
export {
|
|
4
|
+
export { isTemporaryBuildFile };
|
|
5
5
|
import { build, formatMessages } from 'esbuild';
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger } from '../../../../utils.js';
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger, assertPathIsFilesystemAbsolute } from '../../../../utils.js';
|
|
11
11
|
import { transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
@@ -79,87 +79,96 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
79
79
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
80
80
|
treeShaking: false,
|
|
81
81
|
minify: false,
|
|
82
|
-
metafile:
|
|
83
|
-
bundle:
|
|
82
|
+
metafile: true,
|
|
83
|
+
bundle: true
|
|
84
84
|
};
|
|
85
|
-
let pointerImports;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
85
|
+
let pointerImports = {};
|
|
86
|
+
options.plugins = [
|
|
87
|
+
// Determine whether an import should be:
|
|
88
|
+
// - A pointer import
|
|
89
|
+
// - Externalized
|
|
90
|
+
{
|
|
91
|
+
name: 'vike-esbuild',
|
|
92
|
+
setup(build) {
|
|
93
|
+
// https://github.com/brillout/esbuild-playground
|
|
94
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
95
|
+
if (args.kind !== 'import-statement')
|
|
96
|
+
return;
|
|
97
|
+
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
98
98
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
99
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
100
|
+
return;
|
|
101
|
+
const { path, ...opts } = args;
|
|
102
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
103
|
+
const resolved = await build.resolve(path, opts);
|
|
104
|
+
if (resolved.errors.length > 0) {
|
|
105
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
|
|
106
|
+
pointerImports[args.path] = false
|
|
107
|
+
return { external: true }
|
|
108
|
+
*/
|
|
109
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
110
|
+
cleanEsbuildErrors(resolved.errors);
|
|
111
|
+
return resolved;
|
|
112
|
+
}
|
|
113
|
+
assert(resolved.path);
|
|
114
|
+
resolved.path = toPosixPath(resolved.path);
|
|
115
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
116
|
+
// - This is temporary, see comment below.
|
|
117
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
118
|
+
const isPointerImport = transformImports === 'all' ||
|
|
113
119
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
114
120
|
!isJavaScriptFile(resolved.path) ||
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
name: 'vike:dependency-tracker',
|
|
142
|
-
setup(b) {
|
|
143
|
-
b.onLoad({ filter: /./ }, (args) => {
|
|
144
|
-
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
145
|
-
let { path } = args;
|
|
146
|
-
path = toPosixPath(path);
|
|
147
|
-
vikeConfigDependencies.add(path);
|
|
148
|
-
return undefined;
|
|
149
|
-
});
|
|
150
|
-
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
151
|
-
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
152
|
-
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
153
|
-
* ```bash
|
|
154
|
-
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
155
|
-
* ```
|
|
156
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
157
|
-
b.onResolve(...)
|
|
158
|
-
*/
|
|
159
|
-
}
|
|
121
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
122
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
123
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
124
|
+
isVikeExtensionConfigImport ||
|
|
125
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
126
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
127
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
128
|
+
resolved.errors.length > 0;
|
|
129
|
+
pointerImports[resolved.path] = isPointerImport;
|
|
130
|
+
assertPosixPath(resolved.path);
|
|
131
|
+
const isExternal = isPointerImport ||
|
|
132
|
+
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
133
|
+
resolved.path.includes('/node_modules/');
|
|
134
|
+
if (debug.isActivated)
|
|
135
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
136
|
+
// We need esbuild to resolve path aliases so that we can use:
|
|
137
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
138
|
+
// assertIsNpmPackageImport()
|
|
139
|
+
assertPathIsFilesystemAbsolute(resolved.path);
|
|
140
|
+
if (isExternal) {
|
|
141
|
+
return { external: true, path: resolved.path };
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return resolved;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
160
147
|
}
|
|
161
|
-
|
|
162
|
-
|
|
148
|
+
},
|
|
149
|
+
// Track dependencies
|
|
150
|
+
{
|
|
151
|
+
name: 'vike:dependency-tracker',
|
|
152
|
+
setup(b) {
|
|
153
|
+
b.onLoad({ filter: /./ }, (args) => {
|
|
154
|
+
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
155
|
+
let { path } = args;
|
|
156
|
+
path = toPosixPath(path);
|
|
157
|
+
vikeConfigDependencies.add(path);
|
|
158
|
+
return undefined;
|
|
159
|
+
});
|
|
160
|
+
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
161
|
+
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
162
|
+
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
163
|
+
* ```bash
|
|
164
|
+
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
165
|
+
* ```
|
|
166
|
+
* - But implementing a fix is complex and isn't worth it.
|
|
167
|
+
b.onResolve(...)
|
|
168
|
+
*/
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
];
|
|
163
172
|
let result;
|
|
164
173
|
try {
|
|
165
174
|
result = await build(options);
|
|
@@ -169,15 +178,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
169
178
|
throw err;
|
|
170
179
|
}
|
|
171
180
|
// Track dependencies
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
+
assert(result.metafile);
|
|
182
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
183
|
+
filePathRelative = toPosixPath(filePathRelative);
|
|
184
|
+
assertPosixPath(userRootDir);
|
|
185
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
|
|
186
|
+
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
187
|
+
});
|
|
181
188
|
const code = result.outputFiles[0].text;
|
|
182
189
|
assert(typeof code === 'string');
|
|
183
190
|
return { code, pointerImports };
|
|
@@ -186,7 +193,7 @@ async function executeTranspiledFile(filePath, code) {
|
|
|
186
193
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
187
194
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
188
195
|
// - But seems to break source maps, so I don't think it's worth it
|
|
189
|
-
const filePathTmp =
|
|
196
|
+
const filePathTmp = getTemporaryBuildFilePath(filePathAbsoluteFilesystem);
|
|
190
197
|
fs.writeFileSync(filePathTmp, code);
|
|
191
198
|
const clean = () => fs.unlinkSync(filePathTmp);
|
|
192
199
|
let fileExports = {};
|
|
@@ -243,20 +250,19 @@ function getConfigExecutionErrorIntroMsg(err) {
|
|
|
243
250
|
const errIntroMsg = execErrIntroMsg.get(err);
|
|
244
251
|
return errIntroMsg ?? null;
|
|
245
252
|
}
|
|
246
|
-
|
|
247
|
-
function getFilePathTmp(filePathAbsoluteFilesystem) {
|
|
253
|
+
function getTemporaryBuildFilePath(filePathAbsoluteFilesystem) {
|
|
248
254
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
249
255
|
const dirname = path.posix.dirname(filePathAbsoluteFilesystem);
|
|
250
256
|
const filename = path.posix.basename(filePathAbsoluteFilesystem);
|
|
251
|
-
// Syntax with semicolon `
|
|
252
|
-
const
|
|
253
|
-
|
|
257
|
+
// Syntax with semicolon `build:${/*...*/}` doesn't work on Windows: https://github.com/vikejs/vike/issues/800#issuecomment-1517329455
|
|
258
|
+
const filePathTmp = path.posix.join(dirname, `${filename}.build-${getRandomId(12)}.mjs`);
|
|
259
|
+
assert(isTemporaryBuildFile(filePathTmp));
|
|
254
260
|
return filePathTmp;
|
|
255
261
|
}
|
|
256
|
-
function
|
|
262
|
+
function isTemporaryBuildFile(filePath) {
|
|
257
263
|
assertPosixPath(filePath);
|
|
258
264
|
const fileName = path.posix.basename(filePath);
|
|
259
|
-
return fileName
|
|
265
|
+
return /\.build-[a-z0-9]{12}\.mjs$/.test(fileName);
|
|
260
266
|
}
|
|
261
267
|
function isHeaderFile(filePath) {
|
|
262
268
|
assertPosixPath(filePath);
|
|
@@ -300,3 +306,23 @@ function getErrIntroMsg(operation, filePath) {
|
|
|
300
306
|
].join(' ');
|
|
301
307
|
return msg;
|
|
302
308
|
}
|
|
309
|
+
function cleanEsbuildErrors(errors) {
|
|
310
|
+
errors.forEach((e) => (e.notes = e.notes.filter((note) =>
|
|
311
|
+
// Remove note:
|
|
312
|
+
// ```shell
|
|
313
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
314
|
+
// ```
|
|
315
|
+
//
|
|
316
|
+
// From error:
|
|
317
|
+
// ```shell
|
|
318
|
+
// ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
|
|
319
|
+
//
|
|
320
|
+
// renderer/+config.h.js:1:29:
|
|
321
|
+
// 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
|
|
322
|
+
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
323
|
+
//
|
|
324
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
325
|
+
//
|
|
326
|
+
// ```
|
|
327
|
+
!note.text.includes('as external to exclude it from the bundle'))));
|
|
328
|
+
}
|
|
@@ -7,7 +7,7 @@ import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEn
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
9
9
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
10
|
-
import {
|
|
10
|
+
import { isTemporaryBuildFile } from './getVikeConfig/transpileAndExecuteFile.js';
|
|
11
11
|
import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
|
|
12
12
|
import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
13
13
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
@@ -745,7 +745,7 @@ async function findPlusFiles(userRootDir, outDirRoot, isDev) {
|
|
|
745
745
|
}
|
|
746
746
|
function getConfigName(filePath) {
|
|
747
747
|
assertPosixPath(filePath);
|
|
748
|
-
if (
|
|
748
|
+
if (isTemporaryBuildFile(filePath))
|
|
749
749
|
return null;
|
|
750
750
|
const fileName = path.posix.basename(filePath);
|
|
751
751
|
// assertNoUnexpectedPlusSign(filePath, fileName)
|
|
@@ -776,7 +776,30 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
776
776
|
}
|
|
777
777
|
*/
|
|
778
778
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
779
|
-
|
|
779
|
+
{
|
|
780
|
+
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
781
|
+
const knownVikeExntensionConfigs = {
|
|
782
|
+
description: ui,
|
|
783
|
+
favicon: ui,
|
|
784
|
+
Head: ui,
|
|
785
|
+
Layout: ui,
|
|
786
|
+
onCreateApp: ['vike-vue'],
|
|
787
|
+
title: ui,
|
|
788
|
+
ssr: ui,
|
|
789
|
+
stream: ui,
|
|
790
|
+
Wrapper: ui
|
|
791
|
+
};
|
|
792
|
+
if (configName in knownVikeExntensionConfigs) {
|
|
793
|
+
const requiredVikeExtension = knownVikeExntensionConfigs[configName];
|
|
794
|
+
assertUsage(false, [
|
|
795
|
+
`${filePathToShowToUser} uses the config ${pc.cyan(configName)} (https://vike.dev/${configName})`,
|
|
796
|
+
`which requires the Vike extension ${requiredVikeExtension.map((e) => pc.bold(e)).join('/')}.`,
|
|
797
|
+
`Make sure to install the Vike extension,`,
|
|
798
|
+
`and make sure it applies to ${filePathToShowToUser} as explained at https://vike.dev/extends#inheritance.`
|
|
799
|
+
].join(' '));
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
let errMsg = `${filePathToShowToUser} sets an unknown config ${pc.cyan(configName)}`;
|
|
780
803
|
let configNameSimilar = null;
|
|
781
804
|
if (configName === 'page') {
|
|
782
805
|
configNameSimilar = 'Page';
|
|
@@ -784,17 +807,13 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
|
784
807
|
else {
|
|
785
808
|
configNameSimilar = getMostSimilar(configName, configNames);
|
|
786
809
|
}
|
|
787
|
-
if (configNameSimilar
|
|
788
|
-
assert(configNameSimilar);
|
|
810
|
+
if (configNameSimilar) {
|
|
789
811
|
assert(configNameSimilar !== configName);
|
|
790
|
-
errMsg += `, did you mean to
|
|
812
|
+
errMsg += `, did you mean to set ${pc.cyan(configNameSimilar)} instead?`;
|
|
791
813
|
if (configName === 'page') {
|
|
792
814
|
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
|
|
793
815
|
}
|
|
794
816
|
}
|
|
795
|
-
else {
|
|
796
|
-
errMsg += `, you need to define the config ${pc.cyan(configName)} by using ${pc.cyan('config.meta')} https://vike.dev/meta`;
|
|
797
|
-
}
|
|
798
817
|
assertUsage(false, errMsg);
|
|
799
818
|
}
|
|
800
819
|
function determineRouteFilesystem(locationId, configValueSources) {
|
|
@@ -13,7 +13,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
|
13
13
|
const clientDependencies = [];
|
|
14
14
|
clientDependencies.push({
|
|
15
15
|
id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
|
|
16
|
-
onlyAssets: false,
|
|
16
|
+
onlyAssets: isClientSideRenderable ? false : true,
|
|
17
17
|
eagerlyImported: false
|
|
18
18
|
});
|
|
19
19
|
// In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
|
|
@@ -20,6 +20,10 @@ const knownErrors = [
|
|
|
20
20
|
// ```
|
|
21
21
|
errMsg: 'assets.json',
|
|
22
22
|
link: 'https://vike.dev/getGlobalContext'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
errMsg: /Named export.*not found/i,
|
|
26
|
+
link: 'https://vike.dev/broken-npm-package#named-export-not-found'
|
|
23
27
|
}
|
|
24
28
|
];
|
|
25
29
|
function logErrorHint(error) {
|
|
@@ -285,7 +289,15 @@ function extractFromNodeModulesPath(str) {
|
|
|
285
289
|
return packageName;
|
|
286
290
|
}
|
|
287
291
|
function includes(str1, str2) {
|
|
288
|
-
|
|
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;
|
|
289
301
|
}
|
|
290
302
|
function includesNodeModules(str) {
|
|
291
303
|
if (!str)
|
|
@@ -18,14 +18,14 @@ type Url = {
|
|
|
18
18
|
searchAll: Record<string, string[]>;
|
|
19
19
|
/** The URL search parameterer string, e.g. `?details=yes` of `https://example.com/product/42?details=yes#reviews` */
|
|
20
20
|
searchOriginal: null | string;
|
|
21
|
-
/** @deprecated */
|
|
22
|
-
searchString: null | string;
|
|
23
21
|
/** The URL hash, e.g. `reviews` of `https://example.com/product/42?details=yes#reviews` */
|
|
24
22
|
hash: string;
|
|
25
23
|
/** The URL hash string, e.g. `#reviews` of `https://example.com/product/42?details=yes#reviews` */
|
|
26
24
|
hashOriginal: null | string;
|
|
27
25
|
/** @deprecated */
|
|
28
26
|
hashString: null | string;
|
|
27
|
+
/** @deprecated */
|
|
28
|
+
searchString: null | string;
|
|
29
29
|
};
|
|
30
30
|
type PageContextUrlComputedPropsClient = {
|
|
31
31
|
/** @deprecated */
|
|
@@ -6,10 +6,10 @@ import { assertPosixPath } from './filesystemPathHandling.js';
|
|
|
6
6
|
function assertPathIsFilesystemAbsolute(p) {
|
|
7
7
|
assertPosixPath(p);
|
|
8
8
|
assert(!p.startsWith('/@fs/'));
|
|
9
|
-
if (process.platform
|
|
10
|
-
assert(
|
|
9
|
+
if (process.platform !== 'win32') {
|
|
10
|
+
assert(p.startsWith('/'));
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
assert(
|
|
13
|
+
assert(path.win32.isAbsolute(p));
|
|
14
14
|
}
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.168",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@brillout/json-serializer": "^0.5.8",
|
|
17
17
|
"@brillout/picocolors": "^1.0.10",
|
|
18
18
|
"@brillout/require-shim": "^0.1.2",
|
|
19
|
-
"@brillout/vite-plugin-server-entry": "^0.4.
|
|
19
|
+
"@brillout/vite-plugin-server-entry": "^0.4.5",
|
|
20
20
|
"acorn": "^8.0.0",
|
|
21
21
|
"cac": "^6.0.0",
|
|
22
22
|
"es-module-lexer": "^1.0.0",
|