vike 0.4.197 → 0.4.198-commit-081c85f
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/client/client-routing-runtime/prefetch/PrefetchSetting.js +2 -0
- package/dist/cjs/node/plugin/plugins/fileEnv.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +14 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +26 -23
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformFileImports.js → transformPointerImports.js} +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +44 -47
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +16 -7
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isNpmPackage.js +4 -0
- package/dist/cjs/utils/isScriptFile.js +3 -3
- package/dist/cjs/utils/parseUrl.js +2 -10
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +13 -0
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +26 -16
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +34 -30
- package/dist/esm/client/client-routing-runtime/history.js +1 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/{installClientRouter.js → initClientRouter.js} +11 -8
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/{onLinkClick.js → initOnLinkClick.js} +2 -2
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +1 -0
- package/dist/esm/client/client-routing-runtime/navigate.js +3 -2
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +14 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
- package/dist/esm/client/client-routing-runtime/prefetch/PrefetchSetting.d.ts +7 -0
- package/dist/esm/client/client-routing-runtime/prefetch/PrefetchSetting.js +1 -0
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +8 -7
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.js +75 -67
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +29 -5
- package/dist/esm/client/client-routing-runtime/prefetch.js +196 -68
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +71 -24
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +25 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformFileImports.d.ts → transformPointerImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformFileImports.js → transformPointerImports.js} +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +45 -48
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +16 -7
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +10 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/shared/types.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isNpmPackage.d.ts +2 -0
- package/dist/esm/utils/isNpmPackage.js +4 -0
- package/dist/esm/utils/isScriptFile.d.ts +2 -2
- package/dist/esm/utils/isScriptFile.js +3 -3
- package/dist/esm/utils/parseUrl.d.ts +2 -2
- package/dist/esm/utils/parseUrl.js +2 -10
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/prefetch/alreadyPrefetched.d.ts +0 -4
- package/dist/esm/client/client-routing-runtime/prefetch/alreadyPrefetched.js +0 -16
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -3,7 +3,7 @@ export { resolvePointerImport };
|
|
|
3
3
|
export { clearFilesEnvMap };
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
5
|
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual, isFilePathAbsolute, requireResolve } from '../../../../utils.js';
|
|
6
|
-
import { parsePointerImportData } from './
|
|
6
|
+
import { parsePointerImportData } from './transformPointerImports.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
9
9
|
const filesEnvMap = new Map();
|
|
@@ -16,7 +16,7 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
16
16
|
const { importPath, exportName } = pointerImportData;
|
|
17
17
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
18
18
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
19
|
-
|
|
19
|
+
assertUsageFileEnv(filePath.filePathAbsoluteFilesystem, importPath, configEnv, configName);
|
|
20
20
|
return {
|
|
21
21
|
...filePath,
|
|
22
22
|
fileExportName: exportName,
|
|
@@ -24,33 +24,36 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
27
|
+
// `importPath` should be one of the following:
|
|
28
|
+
// - A relative import path
|
|
29
|
+
// - A filesystem absolute path
|
|
30
|
+
// - An npm package import
|
|
27
31
|
const { importPath } = pointerImportData;
|
|
28
32
|
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath);
|
|
29
33
|
let filePath;
|
|
30
|
-
// - importPath is one of the following. (See `transpileAndExecuteFile()`.)
|
|
31
|
-
// - A relative import path
|
|
32
|
-
// - A filesystem absolute path
|
|
33
|
-
// - An npm package import
|
|
34
|
-
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
35
34
|
assertPosixPath(importPath);
|
|
36
35
|
if (importPath.startsWith('.') || isFilePathAbsolute(importPath)) {
|
|
37
36
|
if (importPath.startsWith('.')) {
|
|
38
|
-
|
|
37
|
+
assertUsage(importPath.startsWith('./') || importPath.startsWith('../'), `Invalid relative import path ${pc.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
40
|
+
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
41
|
+
// Pointer imports are included in virtual files, and we need filePathAbsoluteUserRootDir because we didn't find a way to have filesystem absolute import paths in virtual files: https://gist.github.com/brillout/2315231c9a8164f950c64b4b4a7bbd39
|
|
42
|
+
const errSuffix = `outside of the ${userRootDir} directory which is forbidden: make sure your import paths resolve inside the ${userRootDir} directory, or import from an npm package.`;
|
|
41
43
|
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
if (importPath.startsWith('.')) {
|
|
45
|
+
assertUsage(filePathAbsoluteUserRootDir, `The relative import ${pc.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
assert(isFilePathAbsolute(importPath));
|
|
49
|
+
assertUsage(filePathAbsoluteUserRootDir, `The import path ${importPath} defined by ${importerFilePath.filePathToShowToUser} is ${errSuffix}`);
|
|
50
|
+
}
|
|
51
|
+
// Forbid node_modules/ because it's brittle: if node_modules/ lives outside of userRootDir then it crashes.
|
|
52
|
+
assertUsage(!filePathAbsoluteUserRootDir.includes('/node_modules/'), `The import path ${importPath} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} inside of node_modules/ which is forbbiden: use an npm package import instead.`);
|
|
48
53
|
filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
49
54
|
}
|
|
50
55
|
else {
|
|
51
56
|
const importPathAbsolute = importPath;
|
|
52
|
-
// importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
53
|
-
assertIsNpmPackageImport(importPathAbsolute);
|
|
54
57
|
if (filePathAbsoluteFilesystem) {
|
|
55
58
|
filePath = getFilePathResolved({
|
|
56
59
|
userRootDir,
|
|
@@ -76,14 +79,14 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
|
76
79
|
const filePathAbsoluteFilesystem = requireResolve(pointerImportData.importPath, cwd);
|
|
77
80
|
return filePathAbsoluteFilesystem;
|
|
78
81
|
}
|
|
79
|
-
function
|
|
82
|
+
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
80
83
|
const { importPath: importPath, importStringWasGenerated, importString } = pointerImportData;
|
|
81
84
|
const { filePathToShowToUser } = importerFilePath;
|
|
82
85
|
if (!filePathAbsoluteFilesystem) {
|
|
83
|
-
const importPathString = pc.
|
|
86
|
+
const importPathString = pc.code(`${importPath}`);
|
|
84
87
|
const errIntro = importStringWasGenerated
|
|
85
88
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
86
|
-
: `The import ${pc.
|
|
89
|
+
: `The import ${pc.code(importString)} defined by ${filePathToShowToUser}`;
|
|
87
90
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
88
91
|
if (importPath.startsWith('.')) {
|
|
89
92
|
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
@@ -94,7 +97,7 @@ function assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importe
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
|
-
function
|
|
100
|
+
function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, configName) {
|
|
98
101
|
let key;
|
|
99
102
|
if (filePathAbsoluteFilesystem) {
|
|
100
103
|
key = filePathAbsoluteFilesystem;
|
|
@@ -113,7 +116,7 @@ function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, config
|
|
|
113
116
|
if (configDifferentEnv) {
|
|
114
117
|
assertUsage(false, [
|
|
115
118
|
`${key} defines the value of configs living in different environments:`,
|
|
116
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.
|
|
119
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.code(c.configName)} which value lives in environment ${pc.code(JSON.stringify(c.configEnv))}`),
|
|
117
120
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
118
121
|
].join('\n'));
|
|
119
122
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
4
|
export type { PointerImportData };
|
|
5
|
-
declare function
|
|
5
|
+
declare function transformPointerImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
6
|
/**
|
|
7
7
|
* Data Structure for [pointer imports](https://vike.dev/config#pointer-imports):
|
|
8
8
|
* `import { someExport as someImport } from './some-file'`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
@@ -19,9 +19,8 @@ export { isPointerImportData };
|
|
|
19
19
|
import { parse } from 'acorn';
|
|
20
20
|
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
21
21
|
import pc from '@brillout/picocolors';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// For ./transformFileImports.spec.ts
|
|
22
|
+
function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
23
|
+
// For ./transformPointerImports.spec.ts
|
|
25
24
|
skipWarnings) {
|
|
26
25
|
const spliceOperations = [];
|
|
27
26
|
// Performance trick
|
|
@@ -7,8 +7,8 @@ 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,
|
|
11
|
-
import {
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport } from '../../../../utils.js';
|
|
11
|
+
import { transformPointerImports } from './transformPointerImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
14
|
import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
|
|
@@ -17,7 +17,7 @@ const debug = createDebugger('vike:pointer-imports');
|
|
|
17
17
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
18
18
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
19
19
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
20
|
-
assertUsage(
|
|
20
|
+
assertUsage(isPlainJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
21
21
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
22
22
|
if (isHeader) {
|
|
23
23
|
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${pc.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
@@ -45,17 +45,17 @@ async function transpileFile(filePath, transformImports, userRootDir) {
|
|
|
45
45
|
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
46
46
|
let isImportTransformed = false;
|
|
47
47
|
if (transformImports) {
|
|
48
|
-
const codeMod =
|
|
48
|
+
const codeMod = transformPointerImports(code, filePathToShowToUserResolved, pointerImports);
|
|
49
49
|
if (codeMod) {
|
|
50
50
|
code = codeMod;
|
|
51
51
|
isImportTransformed = true;
|
|
52
52
|
if (debug.isActivated)
|
|
53
|
-
debug(`code, post
|
|
53
|
+
debug(`code, post pointer imports transform (${filePathToShowToUserResolved})`, code);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
if (!isImportTransformed) {
|
|
57
57
|
if (debug.isActivated)
|
|
58
|
-
debug(`code, no
|
|
58
|
+
debug(`code, no pointer imports (${filePathToShowToUserResolved})`);
|
|
59
59
|
}
|
|
60
60
|
return code;
|
|
61
61
|
}
|
|
@@ -103,12 +103,12 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
103
103
|
opts.pluginData = { [useEsbuildResolver]: true };
|
|
104
104
|
const resolved = await build.resolve(path, opts);
|
|
105
105
|
if (resolved.errors.length > 0) {
|
|
106
|
-
/* 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
|
|
106
|
+
/* 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 whereas esbuild refers to the source +config.ts file.
|
|
107
107
|
pointerImports[args.path] = false
|
|
108
108
|
return { external: true }
|
|
109
109
|
*/
|
|
110
|
-
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
111
110
|
cleanEsbuildErrors(resolved.errors);
|
|
111
|
+
// Let esbuild throw the error
|
|
112
112
|
return resolved;
|
|
113
113
|
}
|
|
114
114
|
assert(resolved.path);
|
|
@@ -116,73 +116,70 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
116
116
|
const importPathOriginal = args.path;
|
|
117
117
|
// Esbuild resolves path aliases.
|
|
118
118
|
// - Enabling us to use:
|
|
119
|
-
//
|
|
120
|
-
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
121
|
-
// assertIsNpmPackageImport()
|
|
122
|
-
// ```
|
|
119
|
+
// - assertIsNpmPackageImport()
|
|
120
|
+
// - isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
123
121
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
124
122
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
125
123
|
// - This is temporary, see comment below.
|
|
126
|
-
const
|
|
124
|
+
const isVikeExtensionImport = importPathResolved.endsWith('+config.js');
|
|
127
125
|
const isPointerImport = transformImports === 'all' ||
|
|
128
|
-
// .jsx, .vue, .svg, ... => obviously not config code
|
|
129
|
-
!
|
|
130
|
-
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a
|
|
131
|
-
// -
|
|
126
|
+
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
127
|
+
!isPlainJavaScriptFile(importPathResolved) ||
|
|
128
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a config has been set by the user or by a Vike extension).
|
|
129
|
+
// - TODO/eventually: stop doing this and, instead, let Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
132
130
|
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
133
|
-
|
|
134
|
-
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
135
|
-
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
136
|
-
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
137
|
-
resolved.errors.length > 0;
|
|
131
|
+
isVikeExtensionImport;
|
|
138
132
|
assertPosixPath(importPathResolved);
|
|
139
133
|
const isNodeModules = importPathResolved.includes('/node_modules/');
|
|
140
134
|
const isExternal = isPointerImport ||
|
|
141
|
-
// Performance: npm package imports
|
|
135
|
+
// Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
|
|
142
136
|
isNodeModules;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
if (!isExternal) {
|
|
138
|
+
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
139
|
+
assert(!isPointerImport && !isNodeModules);
|
|
140
|
+
if (debug.isActivated)
|
|
141
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
142
|
+
return resolved;
|
|
143
|
+
}
|
|
147
144
|
let importPathTranspiled;
|
|
148
145
|
assertPosixPath(importPathOriginal);
|
|
149
146
|
if (importPathOriginal.startsWith('./') || importPathOriginal.startsWith('../')) {
|
|
150
|
-
// - We need this assertUsage() because we didn't find a way (yet?) to use filesystem absolute import paths in virtual files.
|
|
151
|
-
// - Alternatively, we can again try one of the following for generating the imports of virtual files. (Last time we tried none of it worked.)
|
|
152
|
-
// - ~~~js
|
|
153
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
154
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
155
|
-
// ~~~
|
|
156
|
-
// - ~~~js
|
|
157
|
-
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
158
|
-
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
159
|
-
// ~~~
|
|
160
|
-
assertUsage(filePathAbsoluteUserRootDir, `Import ${pc.cyan(importPathOriginal)} resolves to ${importPathResolved} outside of ${userRootDir} which is forbidden: make sure your relative import paths resolve inside ${userRootDir}, or import from an npm package.`);
|
|
161
147
|
importPathTranspiled = importPathResolved;
|
|
162
148
|
}
|
|
163
149
|
else {
|
|
164
|
-
// importPathOriginal is either:
|
|
150
|
+
// `importPathOriginal` is either:
|
|
165
151
|
// - Npm package import
|
|
166
152
|
// - Path alias
|
|
153
|
+
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({
|
|
154
|
+
filePathAbsoluteFilesystem: importPathResolved,
|
|
155
|
+
userRootDir
|
|
156
|
+
});
|
|
157
|
+
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
167
158
|
if (filePathAbsoluteUserRootDir && !isNodeModules) {
|
|
168
|
-
// importPathOriginal is
|
|
159
|
+
// `importPathOriginal` is a path alias.
|
|
160
|
+
// - We have to use esbuild's path alias resolution, because:
|
|
161
|
+
// - Vike doesn't resolve path aliases at all.
|
|
162
|
+
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
163
|
+
// - Esbuild path alias resolution seems to be reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
169
164
|
importPathTranspiled = importPathResolved;
|
|
170
165
|
}
|
|
171
166
|
else {
|
|
172
|
-
// importPathOriginal is an npm package import.
|
|
167
|
+
// `importPathOriginal` is an npm package import.
|
|
173
168
|
assertIsNpmPackageImport(importPathOriginal);
|
|
169
|
+
// For less confusing error messages, let the resolution be handled by Vike or Node.js.
|
|
174
170
|
importPathTranspiled = importPathOriginal;
|
|
175
171
|
}
|
|
176
172
|
}
|
|
177
173
|
if (debug.isActivated)
|
|
178
174
|
debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
175
|
+
assert(isExternal);
|
|
176
|
+
assert(
|
|
177
|
+
// Import of runtime code => handled by Vike
|
|
178
|
+
isPointerImport ||
|
|
179
|
+
// Import of config code => loaded by Node.js at build-time
|
|
180
|
+
isNodeModules);
|
|
181
|
+
pointerImports[importPathTranspiled] = isPointerImport;
|
|
182
|
+
return { external: true, path: importPathTranspiled };
|
|
186
183
|
});
|
|
187
184
|
}
|
|
188
185
|
},
|
|
@@ -832,6 +832,9 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
832
832
|
}
|
|
833
833
|
*/
|
|
834
834
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
835
|
+
const configNameColored = pc.cyan(configName);
|
|
836
|
+
let errMsg = `${filePathToShowToUser} sets an unknown config ${configNameColored}.`;
|
|
837
|
+
// vike-{react,vue,solid} hint
|
|
835
838
|
{
|
|
836
839
|
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
837
840
|
const knownVikeExntensionConfigs = {
|
|
@@ -848,14 +851,16 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
|
848
851
|
if (configName in knownVikeExntensionConfigs) {
|
|
849
852
|
const requiredVikeExtension = knownVikeExntensionConfigs[configName];
|
|
850
853
|
assertUsage(false, [
|
|
851
|
-
|
|
852
|
-
`
|
|
853
|
-
|
|
854
|
-
|
|
854
|
+
errMsg,
|
|
855
|
+
`If you want to use the configuration documented at https://vike.dev/${configName} then make sure to install the Vike extension ${requiredVikeExtension
|
|
856
|
+
.map((e) => pc.bold(e))
|
|
857
|
+
.join('/')}.`,
|
|
858
|
+
`Also make sure it applies to ${filePathToShowToUser} (see https://vike.dev/extends#inheritance).`,
|
|
859
|
+
`Alternatively, if you don't want to use the aforementioned Vike extension, define it yourself by using ${pc.cyan('meta')} (https://vike.dev/meta).`
|
|
855
860
|
].join(' '));
|
|
856
861
|
}
|
|
857
862
|
}
|
|
858
|
-
|
|
863
|
+
// Similarity hint
|
|
859
864
|
let configNameSimilar = null;
|
|
860
865
|
if (configName === 'page') {
|
|
861
866
|
configNameSimilar = 'Page';
|
|
@@ -865,11 +870,15 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
|
865
870
|
}
|
|
866
871
|
if (configNameSimilar) {
|
|
867
872
|
assert(configNameSimilar !== configName);
|
|
868
|
-
errMsg +=
|
|
873
|
+
errMsg += ` Did you mean to set ${pc.cyan(configNameSimilar)} instead?`;
|
|
869
874
|
if (configName === 'page') {
|
|
870
|
-
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.cyan('P')} because it
|
|
875
|
+
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.cyan('P')} because it defines a UI component: a ubiquitous JavaScript convention is that the name of UI components start with a capital letter.)`;
|
|
871
876
|
}
|
|
872
877
|
}
|
|
878
|
+
// `meta` hint
|
|
879
|
+
if (!configNameSimilar) {
|
|
880
|
+
errMsg += ` Make sure to define ${configNameColored} by using ${pc.cyan('meta')} (https://vike.dev/meta), and also make sure the meta configuration applies to ${filePathToShowToUser} (see https://vike.dev/config#inheritance).`;
|
|
881
|
+
}
|
|
873
882
|
assertUsage(false, errMsg);
|
|
874
883
|
}
|
|
875
884
|
function determineRouteFilesystem(locationId, configValueSources) {
|
|
@@ -180,7 +180,7 @@ function logErrorDebugNote() {
|
|
|
180
180
|
return;
|
|
181
181
|
store.errorDebugNoteAlreadyShown = true;
|
|
182
182
|
}
|
|
183
|
-
const msg = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/
|
|
183
|
+
const msg = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
184
184
|
logDirectly(msg, 'error');
|
|
185
185
|
}
|
|
186
186
|
function getCategory(httpRequestId = null) {
|
|
@@ -31,13 +31,13 @@ export type { OnRenderHtmlSync };
|
|
|
31
31
|
export type { RouteAsync };
|
|
32
32
|
export type { RouteSync };
|
|
33
33
|
export type { KeepScrollPosition };
|
|
34
|
+
import type { PrefetchSetting, PrefetchStaticAssets } from '../../client/client-routing-runtime/prefetch/PrefetchSetting.js';
|
|
34
35
|
import type { ConfigDefinition } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
35
36
|
import type { DocumentHtml } from '../../node/runtime/html/renderHtml.js';
|
|
36
37
|
import type { ConfigVikeUserProvided } from '../ConfigVike.js';
|
|
37
38
|
import type { Vike, VikePackages } from '../VikeNamespace.js';
|
|
38
39
|
import type { HooksTimeoutProvidedByUser } from '../hooks/getHook.js';
|
|
39
40
|
import type { PageContextClient, PageContextServer } from '../types.js';
|
|
40
|
-
import type { PrefetchStaticAssets } from '../types/PrefetchStaticAssets.js';
|
|
41
41
|
type HookName = HookNamePage | HookNameGlobal | HookNameOldDesign;
|
|
42
42
|
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data';
|
|
43
43
|
type HookNameGlobal = 'onBeforePrerender' | 'onBeforeRoute' | 'onPrerenderStart';
|
|
@@ -344,6 +344,15 @@ type ConfigBuiltIn = {
|
|
|
344
344
|
* https://vike.dev/meta
|
|
345
345
|
*/
|
|
346
346
|
meta?: ConfigMeta | ImportString;
|
|
347
|
+
/**
|
|
348
|
+
* @experimental: DON'T USE: the API *will* have breaking changes upon any minor version release.
|
|
349
|
+
*
|
|
350
|
+
* Prefetch pages/links.
|
|
351
|
+
*
|
|
352
|
+
* https://vike.dev/prefetch
|
|
353
|
+
*/
|
|
354
|
+
prefetch?: PrefetchSetting | ImportString;
|
|
355
|
+
/** @deprecated Use `prefetch` setting (https://vike.dev/prefetch) instead. */
|
|
347
356
|
/** Prefetch links.
|
|
348
357
|
*
|
|
349
358
|
* https://vike.dev/prefetchStaticAssets
|
|
@@ -2,7 +2,7 @@ export { serializeConfigValues };
|
|
|
2
2
|
import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
|
|
3
3
|
import { assert, assertUsage, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
4
4
|
import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
|
|
5
|
-
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/
|
|
5
|
+
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js';
|
|
6
6
|
import { getConfigValueFilePathToShowToUser } from '../helpers.js';
|
|
7
7
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.198-commit-081c85f";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.198-commit-081c85f';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { isNpmPackageImport };
|
|
2
|
+
export { isNpmPackageImport_unreliable };
|
|
2
3
|
export { assertIsNpmPackageImport };
|
|
3
4
|
export { isValidPathAlias };
|
|
4
5
|
export { parse };
|
|
@@ -6,6 +7,7 @@ export { isDistinguishable };
|
|
|
6
7
|
declare function isNpmPackageImport(str: string, { cannotBePathAlias }: {
|
|
7
8
|
cannotBePathAlias: true;
|
|
8
9
|
}): boolean;
|
|
10
|
+
declare function isNpmPackageImport_unreliable(str: string): boolean;
|
|
9
11
|
declare function assertIsNpmPackageImport(str: string): void;
|
|
10
12
|
declare function isValidPathAlias(alias: string): boolean;
|
|
11
13
|
declare function isDistinguishable(alias: string): boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { isNpmPackageImport };
|
|
2
|
+
export { isNpmPackageImport_unreliable };
|
|
2
3
|
export { assertIsNpmPackageImport };
|
|
3
4
|
export { isValidPathAlias };
|
|
4
5
|
/* Currently not used
|
|
@@ -15,6 +16,9 @@ assertIsNotBrowser();
|
|
|
15
16
|
function isNpmPackageImport(str, { cannotBePathAlias }) {
|
|
16
17
|
// We cannot distinguish path alises that look like npm package imports
|
|
17
18
|
assert(cannotBePathAlias);
|
|
19
|
+
return isNpmPackageImport_unreliable(str);
|
|
20
|
+
}
|
|
21
|
+
function isNpmPackageImport_unreliable(str) {
|
|
18
22
|
const res = parse(str);
|
|
19
23
|
return res !== null;
|
|
20
24
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { isScriptFile };
|
|
2
|
-
export {
|
|
2
|
+
export { isPlainJavaScriptFile };
|
|
3
3
|
export { isTemplateFile };
|
|
4
4
|
export { scriptFileExtensions };
|
|
5
5
|
export { scriptFileExtensionList };
|
|
6
6
|
declare const scriptFileExtensionList: readonly [...string[], "jsx", "tsx", "cjsx", "ctsx", "mjsx", "mtsx", "vue", "svelte", "marko", "md", "mdx"];
|
|
7
7
|
declare const scriptFileExtensions: string;
|
|
8
8
|
declare function isScriptFile(filePath: string): boolean;
|
|
9
|
-
declare function
|
|
9
|
+
declare function isPlainJavaScriptFile(filePath: string): boolean;
|
|
10
10
|
declare function isTemplateFile(filePath: string): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { isScriptFile };
|
|
2
|
-
export {
|
|
2
|
+
export { isPlainJavaScriptFile };
|
|
3
3
|
export { isTemplateFile };
|
|
4
4
|
export { scriptFileExtensions };
|
|
5
5
|
export { scriptFileExtensionList };
|
|
@@ -46,11 +46,11 @@ const scriptFileExtensionList = [...extJavaScript, ...extJsx, ...extTemplates];
|
|
|
46
46
|
const scriptFileExtensions = '(' + scriptFileExtensionList.join('|') + ')';
|
|
47
47
|
function isScriptFile(filePath) {
|
|
48
48
|
const yes = scriptFileExtensionList.some((ext) => filePath.endsWith('.' + ext));
|
|
49
|
-
if (
|
|
49
|
+
if (isPlainJavaScriptFile(filePath))
|
|
50
50
|
assert(yes);
|
|
51
51
|
return yes;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function isPlainJavaScriptFile(filePath) {
|
|
54
54
|
const yes1 = /\.(c|m)?(j|t)s$/.test(filePath);
|
|
55
55
|
const yes2 = extJavaScript.some((ext) => filePath.endsWith('.' + ext));
|
|
56
56
|
assert(yes1 === yes2);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { parseUrl };
|
|
2
|
-
export { assertUsageUrlPathname };
|
|
3
2
|
export { assertUsageUrlPathnameAbsolute };
|
|
4
3
|
export { assertUsageUrlRedirectTarget };
|
|
5
4
|
export { isUrl };
|
|
6
5
|
export { isUri };
|
|
7
6
|
export { isUrlRedirectTarget };
|
|
7
|
+
export { isUrlPathnameRelative };
|
|
8
8
|
export { isUrlExternal };
|
|
9
9
|
export { isBaseServer };
|
|
10
10
|
export { assertUrlComponents };
|
|
@@ -50,8 +50,8 @@ declare function assertUrlComponents(url: string, origin: string | null, pathnam
|
|
|
50
50
|
declare function createUrlFromComponents(origin: string | null, pathname: string, search: string | null, hash: string | null): string;
|
|
51
51
|
declare function isUrl(url: string): boolean;
|
|
52
52
|
declare function isUrlRedirectTarget(url: string): boolean;
|
|
53
|
+
declare function isUrlPathnameRelative(url: string): boolean;
|
|
53
54
|
declare function isUrlExternal(url: string): boolean;
|
|
54
55
|
declare function isUri(uri: string): boolean;
|
|
55
|
-
declare function assertUsageUrlPathname(url: string, errPrefix: string): void;
|
|
56
56
|
declare function assertUsageUrlPathnameAbsolute(url: string, errPrefix: string): void;
|
|
57
57
|
declare function assertUsageUrlRedirectTarget(url: string, errPrefix: string, isUnresolved?: true): void;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
// - It doesn't support the tauri:// protocol
|
|
4
4
|
// Unit tests at ./parseUrl.spec.ts
|
|
5
5
|
export { parseUrl };
|
|
6
|
-
export { assertUsageUrlPathname };
|
|
7
6
|
export { assertUsageUrlPathnameAbsolute };
|
|
8
7
|
export { assertUsageUrlRedirectTarget };
|
|
9
8
|
export { isUrl };
|
|
10
9
|
export { isUri };
|
|
11
10
|
export { isUrlRedirectTarget };
|
|
11
|
+
export { isUrlPathnameRelative };
|
|
12
12
|
export { isUrlExternal };
|
|
13
13
|
export { isBaseServer };
|
|
14
14
|
export { assertUrlComponents };
|
|
@@ -293,16 +293,13 @@ function isUri(uri) {
|
|
|
293
293
|
const { protocol } = parseProtocol(uri);
|
|
294
294
|
return !!protocol && !isUrlProtocol(uri);
|
|
295
295
|
}
|
|
296
|
-
function assertUsageUrlPathname(url, errPrefix) {
|
|
297
|
-
assertUsageUrl(url, errPrefix, { allowRelative: true });
|
|
298
|
-
}
|
|
299
296
|
function assertUsageUrlPathnameAbsolute(url, errPrefix) {
|
|
300
297
|
assertUsageUrl(url, errPrefix);
|
|
301
298
|
}
|
|
302
299
|
function assertUsageUrlRedirectTarget(url, errPrefix, isUnresolved) {
|
|
303
300
|
assertUsageUrl(url, errPrefix, { isRedirectTarget: isUnresolved ? 'unresolved' : true });
|
|
304
301
|
}
|
|
305
|
-
function assertUsageUrl(url, errPrefix, {
|
|
302
|
+
function assertUsageUrl(url, errPrefix, { isRedirectTarget } = {}) {
|
|
306
303
|
if (url.startsWith('/'))
|
|
307
304
|
return;
|
|
308
305
|
let errMsg = `${errPrefix} is ${pc.string(url)} but it should start with ${pc.string('/')}`;
|
|
@@ -316,10 +313,5 @@ function assertUsageUrl(url, errPrefix, { allowRelative, isRedirectTarget } = {}
|
|
|
316
313
|
errMsg += `, or be ${pc.string('*')}`;
|
|
317
314
|
}
|
|
318
315
|
}
|
|
319
|
-
if (allowRelative) {
|
|
320
|
-
if (isUrlPathnameRelative(url))
|
|
321
|
-
return;
|
|
322
|
-
errMsg += ', or be a relative URL';
|
|
323
|
-
}
|
|
324
316
|
assertUsage(false, errMsg);
|
|
325
317
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { isAlreadyPrefetched };
|
|
2
|
-
export { markAsAlreadyPrefetched };
|
|
3
|
-
import { parseUrl } from '../utils.js';
|
|
4
|
-
const linkAlreadyPrefetched = new Map();
|
|
5
|
-
function isAlreadyPrefetched(url) {
|
|
6
|
-
const urlPathname = getUrlPathname(url);
|
|
7
|
-
return linkAlreadyPrefetched.has(urlPathname);
|
|
8
|
-
}
|
|
9
|
-
function markAsAlreadyPrefetched(url) {
|
|
10
|
-
const urlPathname = getUrlPathname(url);
|
|
11
|
-
linkAlreadyPrefetched.set(urlPathname, true);
|
|
12
|
-
}
|
|
13
|
-
function getUrlPathname(url) {
|
|
14
|
-
const urlPathname = parseUrl(url, '/').pathname;
|
|
15
|
-
return urlPathname;
|
|
16
|
-
}
|