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
|
@@ -22,6 +22,9 @@ function fileEnv() {
|
|
|
22
22
|
return;
|
|
23
23
|
if (skip(id))
|
|
24
24
|
return;
|
|
25
|
+
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
26
|
+
if (id.endsWith('?direct'))
|
|
27
|
+
id = id.slice(0, -1 * '?direct'.length);
|
|
25
28
|
const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
|
|
26
29
|
(0, utils_js_1.assert)(moduleInfo);
|
|
27
30
|
const importers = Array.from(moduleInfo.importers)
|
|
@@ -68,6 +68,11 @@ const configDefinitionsBuiltIn = {
|
|
|
68
68
|
hydrationCanBeAborted: {
|
|
69
69
|
env: { client: true }
|
|
70
70
|
},
|
|
71
|
+
prefetch: {
|
|
72
|
+
env: { client: true },
|
|
73
|
+
eager: true
|
|
74
|
+
},
|
|
75
|
+
// TODO/v1-release: remove
|
|
71
76
|
prefetchStaticAssets: {
|
|
72
77
|
env: { client: true }
|
|
73
78
|
},
|
|
@@ -101,10 +106,12 @@ const configDefinitionsBuiltIn = {
|
|
|
101
106
|
},
|
|
102
107
|
onBeforeRenderEnv: {
|
|
103
108
|
env: { client: true },
|
|
109
|
+
eager: true,
|
|
104
110
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
105
111
|
},
|
|
106
112
|
dataEnv: {
|
|
107
113
|
env: { client: true },
|
|
114
|
+
eager: true,
|
|
108
115
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data')
|
|
109
116
|
},
|
|
110
117
|
hooksTimeout: {
|
|
@@ -152,7 +159,13 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
152
159
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
153
160
|
if (!configValueSource)
|
|
154
161
|
return null;
|
|
155
|
-
|
|
162
|
+
const { configEnv } = configValueSource;
|
|
163
|
+
const env = {};
|
|
164
|
+
if (configEnv.client)
|
|
165
|
+
env.client = true;
|
|
166
|
+
if (configEnv.server)
|
|
167
|
+
env.server = true;
|
|
168
|
+
return env;
|
|
156
169
|
}
|
|
157
170
|
function isConfigSet(configValueSources, configName) {
|
|
158
171
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -11,7 +11,7 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
11
11
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
12
12
|
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
|
-
const
|
|
14
|
+
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
15
15
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
16
16
|
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
17
17
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -94,7 +94,7 @@ function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
|
94
94
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
95
95
|
}
|
|
96
96
|
const extendsPointerImportData = extendList.map((importString) => {
|
|
97
|
-
const pointerImportData = (0,
|
|
97
|
+
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(importString);
|
|
98
98
|
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
99
99
|
return pointerImportData;
|
|
100
100
|
});
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -8,20 +8,20 @@ exports.resolvePointerImport = resolvePointerImport;
|
|
|
8
8
|
exports.clearFilesEnvMap = clearFilesEnvMap;
|
|
9
9
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
10
|
const utils_js_1 = require("../../../../utils.js");
|
|
11
|
-
const
|
|
11
|
+
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
13
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
14
14
|
const filesEnvMap = new Map();
|
|
15
15
|
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
16
16
|
if (typeof configValue !== 'string')
|
|
17
17
|
return null;
|
|
18
|
-
const pointerImportData = (0,
|
|
18
|
+
const pointerImportData = (0, transformPointerImports_js_1.parsePointerImportData)(configValue);
|
|
19
19
|
if (!pointerImportData)
|
|
20
20
|
return null;
|
|
21
21
|
const { importPath, exportName } = pointerImportData;
|
|
22
22
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
23
23
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
24
|
-
|
|
24
|
+
assertUsageFileEnv(filePath.filePathAbsoluteFilesystem, importPath, configEnv, configName);
|
|
25
25
|
return {
|
|
26
26
|
...filePath,
|
|
27
27
|
fileExportName: exportName,
|
|
@@ -29,33 +29,36 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
32
|
+
// `importPath` should be one of the following:
|
|
33
|
+
// - A relative import path
|
|
34
|
+
// - A filesystem absolute path
|
|
35
|
+
// - An npm package import
|
|
32
36
|
const { importPath } = pointerImportData;
|
|
33
37
|
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath);
|
|
34
38
|
let filePath;
|
|
35
|
-
// - importPath is one of the following. (See `transpileAndExecuteFile()`.)
|
|
36
|
-
// - A relative import path
|
|
37
|
-
// - A filesystem absolute path
|
|
38
|
-
// - An npm package import
|
|
39
|
-
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
40
39
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
41
40
|
if (importPath.startsWith('.') || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
42
41
|
if (importPath.startsWith('.')) {
|
|
43
|
-
(0, utils_js_1.
|
|
42
|
+
(0, utils_js_1.assertUsage)(importPath.startsWith('./') || importPath.startsWith('../'), `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
45
|
+
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
46
|
+
// 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
|
|
47
|
+
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.`;
|
|
46
48
|
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({ filePathAbsoluteFilesystem, userRootDir });
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (importPath.startsWith('.')) {
|
|
50
|
+
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `The relative import ${picocolors_1.default.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
(0, utils_js_1.assert)((0, utils_js_1.isFilePathAbsolute)(importPath));
|
|
54
|
+
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `The import path ${importPath} defined by ${importerFilePath.filePathToShowToUser} is ${errSuffix}`);
|
|
55
|
+
}
|
|
56
|
+
// Forbid node_modules/ because it's brittle: if node_modules/ lives outside of userRootDir then it crashes.
|
|
57
|
+
(0, utils_js_1.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.`);
|
|
53
58
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
54
59
|
}
|
|
55
60
|
else {
|
|
56
61
|
const importPathAbsolute = importPath;
|
|
57
|
-
// importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
58
|
-
(0, utils_js_1.assertIsNpmPackageImport)(importPathAbsolute);
|
|
59
62
|
if (filePathAbsoluteFilesystem) {
|
|
60
63
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({
|
|
61
64
|
userRootDir,
|
|
@@ -81,14 +84,14 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
|
81
84
|
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(pointerImportData.importPath, cwd);
|
|
82
85
|
return filePathAbsoluteFilesystem;
|
|
83
86
|
}
|
|
84
|
-
function
|
|
87
|
+
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
85
88
|
const { importPath: importPath, importStringWasGenerated, importString } = pointerImportData;
|
|
86
89
|
const { filePathToShowToUser } = importerFilePath;
|
|
87
90
|
if (!filePathAbsoluteFilesystem) {
|
|
88
|
-
const importPathString = picocolors_1.default.
|
|
91
|
+
const importPathString = picocolors_1.default.code(`${importPath}`);
|
|
89
92
|
const errIntro = importStringWasGenerated
|
|
90
93
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
91
|
-
: `The import ${picocolors_1.default.
|
|
94
|
+
: `The import ${picocolors_1.default.code(importString)} defined by ${filePathToShowToUser}`;
|
|
92
95
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
93
96
|
if (importPath.startsWith('.')) {
|
|
94
97
|
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
@@ -99,7 +102,7 @@ function assertImportPath(filePathAbsoluteFilesystem, pointerImportData, importe
|
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
|
-
function
|
|
105
|
+
function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, configName) {
|
|
103
106
|
let key;
|
|
104
107
|
if (filePathAbsoluteFilesystem) {
|
|
105
108
|
key = filePathAbsoluteFilesystem;
|
|
@@ -118,7 +121,7 @@ function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, config
|
|
|
118
121
|
if (configDifferentEnv) {
|
|
119
122
|
(0, utils_js_1.assertUsage)(false, [
|
|
120
123
|
`${key} defines the value of configs living in different environments:`,
|
|
121
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.
|
|
124
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.code(c.configName)} which value lives in environment ${picocolors_1.default.code(JSON.stringify(c.configEnv))}`),
|
|
122
125
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
123
126
|
].join('\n'));
|
|
124
127
|
}
|
|
@@ -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.transformPointerImports = transformPointerImports;
|
|
7
7
|
exports.parsePointerImportData = parsePointerImportData;
|
|
8
8
|
exports.isPointerImportData = isPointerImportData;
|
|
9
9
|
// Playground: https://github.com/brillout/acorn-playground
|
|
@@ -24,9 +24,8 @@ exports.isPointerImportData = isPointerImportData;
|
|
|
24
24
|
const acorn_1 = require("acorn");
|
|
25
25
|
const utils_js_1 = require("../../../../utils.js");
|
|
26
26
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// For ./transformFileImports.spec.ts
|
|
27
|
+
function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
28
|
+
// For ./transformPointerImports.spec.ts
|
|
30
29
|
skipWarnings) {
|
|
31
30
|
const spliceOperations = [];
|
|
32
31
|
// Performance trick
|
|
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const import_1 = require("@brillout/import");
|
|
15
15
|
const utils_js_1 = require("../../../../utils.js");
|
|
16
|
-
const
|
|
16
|
+
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
17
17
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
18
18
|
require("source-map-support/register.js");
|
|
19
19
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
@@ -22,7 +22,7 @@ const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
|
22
22
|
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
23
23
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
24
24
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
25
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.
|
|
25
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
26
26
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
27
27
|
if (isHeader) {
|
|
28
28
|
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
@@ -50,17 +50,17 @@ async function transpileFile(filePath, transformImports, userRootDir) {
|
|
|
50
50
|
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
51
51
|
let isImportTransformed = false;
|
|
52
52
|
if (transformImports) {
|
|
53
|
-
const codeMod = (0,
|
|
53
|
+
const codeMod = (0, transformPointerImports_js_1.transformPointerImports)(code, filePathToShowToUserResolved, pointerImports);
|
|
54
54
|
if (codeMod) {
|
|
55
55
|
code = codeMod;
|
|
56
56
|
isImportTransformed = true;
|
|
57
57
|
if (debug.isActivated)
|
|
58
|
-
debug(`code, post
|
|
58
|
+
debug(`code, post pointer imports transform (${filePathToShowToUserResolved})`, code);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
if (!isImportTransformed) {
|
|
62
62
|
if (debug.isActivated)
|
|
63
|
-
debug(`code, no
|
|
63
|
+
debug(`code, no pointer imports (${filePathToShowToUserResolved})`);
|
|
64
64
|
}
|
|
65
65
|
return code;
|
|
66
66
|
}
|
|
@@ -108,12 +108,12 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
108
108
|
opts.pluginData = { [useEsbuildResolver]: true };
|
|
109
109
|
const resolved = await build.resolve(path, opts);
|
|
110
110
|
if (resolved.errors.length > 0) {
|
|
111
|
-
/* 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
|
|
111
|
+
/* 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.
|
|
112
112
|
pointerImports[args.path] = false
|
|
113
113
|
return { external: true }
|
|
114
114
|
*/
|
|
115
|
-
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
116
115
|
cleanEsbuildErrors(resolved.errors);
|
|
116
|
+
// Let esbuild throw the error
|
|
117
117
|
return resolved;
|
|
118
118
|
}
|
|
119
119
|
(0, utils_js_1.assert)(resolved.path);
|
|
@@ -121,73 +121,70 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
121
121
|
const importPathOriginal = args.path;
|
|
122
122
|
// Esbuild resolves path aliases.
|
|
123
123
|
// - Enabling us to use:
|
|
124
|
-
//
|
|
125
|
-
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
126
|
-
// assertIsNpmPackageImport()
|
|
127
|
-
// ```
|
|
124
|
+
// - assertIsNpmPackageImport()
|
|
125
|
+
// - isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
128
126
|
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(importPathResolved);
|
|
129
127
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
130
128
|
// - This is temporary, see comment below.
|
|
131
|
-
const
|
|
129
|
+
const isVikeExtensionImport = importPathResolved.endsWith('+config.js');
|
|
132
130
|
const isPointerImport = transformImports === 'all' ||
|
|
133
|
-
// .jsx, .vue, .svg, ... => obviously not config code
|
|
134
|
-
!(0, utils_js_1.
|
|
135
|
-
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a
|
|
136
|
-
// -
|
|
131
|
+
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
132
|
+
!(0, utils_js_1.isPlainJavaScriptFile)(importPathResolved) ||
|
|
133
|
+
// 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).
|
|
134
|
+
// - 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.
|
|
137
135
|
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
138
|
-
|
|
139
|
-
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
140
|
-
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
141
|
-
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
142
|
-
resolved.errors.length > 0;
|
|
136
|
+
isVikeExtensionImport;
|
|
143
137
|
(0, utils_js_1.assertPosixPath)(importPathResolved);
|
|
144
138
|
const isNodeModules = importPathResolved.includes('/node_modules/');
|
|
145
139
|
const isExternal = isPointerImport ||
|
|
146
|
-
// Performance: npm package imports
|
|
140
|
+
// 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.)
|
|
147
141
|
isNodeModules;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
if (!isExternal) {
|
|
143
|
+
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
144
|
+
(0, utils_js_1.assert)(!isPointerImport && !isNodeModules);
|
|
145
|
+
if (debug.isActivated)
|
|
146
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
152
149
|
let importPathTranspiled;
|
|
153
150
|
(0, utils_js_1.assertPosixPath)(importPathOriginal);
|
|
154
151
|
if (importPathOriginal.startsWith('./') || importPathOriginal.startsWith('../')) {
|
|
155
|
-
// - We need this assertUsage() because we didn't find a way (yet?) to use filesystem absolute import paths in virtual files.
|
|
156
|
-
// - Alternatively, we can again try one of the following for generating the imports of virtual files. (Last time we tried none of it worked.)
|
|
157
|
-
// - ~~~js
|
|
158
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
159
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
160
|
-
// ~~~
|
|
161
|
-
// - ~~~js
|
|
162
|
-
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
163
|
-
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
164
|
-
// ~~~
|
|
165
|
-
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `Import ${picocolors_1.default.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.`);
|
|
166
152
|
importPathTranspiled = importPathResolved;
|
|
167
153
|
}
|
|
168
154
|
else {
|
|
169
|
-
// importPathOriginal is either:
|
|
155
|
+
// `importPathOriginal` is either:
|
|
170
156
|
// - Npm package import
|
|
171
157
|
// - Path alias
|
|
158
|
+
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({
|
|
159
|
+
filePathAbsoluteFilesystem: importPathResolved,
|
|
160
|
+
userRootDir
|
|
161
|
+
});
|
|
162
|
+
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
172
163
|
if (filePathAbsoluteUserRootDir && !isNodeModules) {
|
|
173
|
-
// importPathOriginal is
|
|
164
|
+
// `importPathOriginal` is a path alias.
|
|
165
|
+
// - We have to use esbuild's path alias resolution, because:
|
|
166
|
+
// - Vike doesn't resolve path aliases at all.
|
|
167
|
+
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
168
|
+
// - Esbuild path alias resolution seems to be reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
174
169
|
importPathTranspiled = importPathResolved;
|
|
175
170
|
}
|
|
176
171
|
else {
|
|
177
|
-
// importPathOriginal is an npm package import.
|
|
172
|
+
// `importPathOriginal` is an npm package import.
|
|
178
173
|
(0, utils_js_1.assertIsNpmPackageImport)(importPathOriginal);
|
|
174
|
+
// For less confusing error messages, let the resolution be handled by Vike or Node.js.
|
|
179
175
|
importPathTranspiled = importPathOriginal;
|
|
180
176
|
}
|
|
181
177
|
}
|
|
182
178
|
if (debug.isActivated)
|
|
183
179
|
debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
180
|
+
(0, utils_js_1.assert)(isExternal);
|
|
181
|
+
(0, utils_js_1.assert)(
|
|
182
|
+
// Import of runtime code => handled by Vike
|
|
183
|
+
isPointerImport ||
|
|
184
|
+
// Import of config code => loaded by Node.js at build-time
|
|
185
|
+
isNodeModules);
|
|
186
|
+
pointerImports[importPathTranspiled] = isPointerImport;
|
|
187
|
+
return { external: true, path: importPathTranspiled };
|
|
191
188
|
});
|
|
192
189
|
}
|
|
193
190
|
},
|
|
@@ -838,6 +838,9 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
838
838
|
}
|
|
839
839
|
*/
|
|
840
840
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
841
|
+
const configNameColored = picocolors_1.default.cyan(configName);
|
|
842
|
+
let errMsg = `${filePathToShowToUser} sets an unknown config ${configNameColored}.`;
|
|
843
|
+
// vike-{react,vue,solid} hint
|
|
841
844
|
{
|
|
842
845
|
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
843
846
|
const knownVikeExntensionConfigs = {
|
|
@@ -854,14 +857,16 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
|
854
857
|
if (configName in knownVikeExntensionConfigs) {
|
|
855
858
|
const requiredVikeExtension = knownVikeExntensionConfigs[configName];
|
|
856
859
|
(0, utils_js_1.assertUsage)(false, [
|
|
857
|
-
|
|
858
|
-
`
|
|
859
|
-
|
|
860
|
-
|
|
860
|
+
errMsg,
|
|
861
|
+
`If you want to use the configuration documented at https://vike.dev/${configName} then make sure to install the Vike extension ${requiredVikeExtension
|
|
862
|
+
.map((e) => picocolors_1.default.bold(e))
|
|
863
|
+
.join('/')}.`,
|
|
864
|
+
`Also make sure it applies to ${filePathToShowToUser} (see https://vike.dev/extends#inheritance).`,
|
|
865
|
+
`Alternatively, if you don't want to use the aforementioned Vike extension, define it yourself by using ${picocolors_1.default.cyan('meta')} (https://vike.dev/meta).`
|
|
861
866
|
].join(' '));
|
|
862
867
|
}
|
|
863
868
|
}
|
|
864
|
-
|
|
869
|
+
// Similarity hint
|
|
865
870
|
let configNameSimilar = null;
|
|
866
871
|
if (configName === 'page') {
|
|
867
872
|
configNameSimilar = 'Page';
|
|
@@ -871,11 +876,15 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
|
871
876
|
}
|
|
872
877
|
if (configNameSimilar) {
|
|
873
878
|
(0, utils_js_1.assert)(configNameSimilar !== configName);
|
|
874
|
-
errMsg +=
|
|
879
|
+
errMsg += ` Did you mean to set ${picocolors_1.default.cyan(configNameSimilar)} instead?`;
|
|
875
880
|
if (configName === 'page') {
|
|
876
|
-
errMsg += ` (The name of the config ${picocolors_1.default.cyan('Page')} starts with a capital letter ${picocolors_1.default.cyan('P')} because it
|
|
881
|
+
errMsg += ` (The name of the config ${picocolors_1.default.cyan('Page')} starts with a capital letter ${picocolors_1.default.cyan('P')} because it defines a UI component: a ubiquitous JavaScript convention is that the name of UI components start with a capital letter.)`;
|
|
877
882
|
}
|
|
878
883
|
}
|
|
884
|
+
// `meta` hint
|
|
885
|
+
if (!configNameSimilar) {
|
|
886
|
+
errMsg += ` Make sure to define ${configNameColored} by using ${picocolors_1.default.cyan('meta')} (https://vike.dev/meta), and also make sure the meta configuration applies to ${filePathToShowToUser} (see https://vike.dev/config#inheritance).`;
|
|
887
|
+
}
|
|
879
888
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
880
889
|
}
|
|
881
890
|
function determineRouteFilesystem(locationId, configValueSources) {
|
|
@@ -185,7 +185,7 @@ function logErrorDebugNote() {
|
|
|
185
185
|
return;
|
|
186
186
|
store.errorDebugNoteAlreadyShown = true;
|
|
187
187
|
}
|
|
188
|
-
const msg = picocolors_1.default.dim((0, utils_js_1.formatHintLog)("Error isn't helpful? See https://vike.dev/
|
|
188
|
+
const msg = picocolors_1.default.dim((0, utils_js_1.formatHintLog)("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
189
189
|
(0, log_js_1.logDirectly)(msg, 'error');
|
|
190
190
|
}
|
|
191
191
|
function getCategory(httpRequestId = null) {
|
|
@@ -7,7 +7,7 @@ exports.serializeConfigValues = serializeConfigValues;
|
|
|
7
7
|
const assertIsNotProductionRuntime_js_1 = require("../../../utils/assertIsNotProductionRuntime.js");
|
|
8
8
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
9
9
|
const addImportStatement_js_1 = require("../../../node/plugin/plugins/importUserCode/addImportStatement.js");
|
|
10
|
-
const
|
|
10
|
+
const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
|
|
11
11
|
const helpers_js_1 = require("../helpers.js");
|
|
12
12
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
@@ -164,7 +164,7 @@ function valueToJson(value, configName, definedAtData, importStatements) {
|
|
|
164
164
|
// - https://github.com/vikejs/vike-react/pull/113
|
|
165
165
|
replacer(_, value) {
|
|
166
166
|
if (typeof value === 'string') {
|
|
167
|
-
const importData = (0,
|
|
167
|
+
const importData = (0, transformPointerImports_js_1.parsePointerImportData)(value);
|
|
168
168
|
if (importData) {
|
|
169
169
|
const { importName } = (0, addImportStatement_js_1.addImportStatement)(importStatements, importData.importPath, importData.exportName);
|
|
170
170
|
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNpmPackageImport = isNpmPackageImport;
|
|
4
|
+
exports.isNpmPackageImport_unreliable = isNpmPackageImport_unreliable;
|
|
4
5
|
exports.assertIsNpmPackageImport = assertIsNpmPackageImport;
|
|
5
6
|
exports.isValidPathAlias = isValidPathAlias;
|
|
6
7
|
exports.parse = parse;
|
|
@@ -11,6 +12,9 @@ const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
|
11
12
|
function isNpmPackageImport(str, { cannotBePathAlias }) {
|
|
12
13
|
// We cannot distinguish path alises that look like npm package imports
|
|
13
14
|
(0, assert_js_1.assert)(cannotBePathAlias);
|
|
15
|
+
return isNpmPackageImport_unreliable(str);
|
|
16
|
+
}
|
|
17
|
+
function isNpmPackageImport_unreliable(str) {
|
|
14
18
|
const res = parse(str);
|
|
15
19
|
return res !== null;
|
|
16
20
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scriptFileExtensionList = exports.scriptFileExtensions = void 0;
|
|
4
4
|
exports.isScriptFile = isScriptFile;
|
|
5
|
-
exports.
|
|
5
|
+
exports.isPlainJavaScriptFile = isPlainJavaScriptFile;
|
|
6
6
|
exports.isTemplateFile = isTemplateFile;
|
|
7
7
|
const assert_js_1 = require("./assert.js");
|
|
8
8
|
// We can't use a RegExp:
|
|
@@ -49,11 +49,11 @@ const scriptFileExtensions = '(' + scriptFileExtensionList.join('|') + ')';
|
|
|
49
49
|
exports.scriptFileExtensions = scriptFileExtensions;
|
|
50
50
|
function isScriptFile(filePath) {
|
|
51
51
|
const yes = scriptFileExtensionList.some((ext) => filePath.endsWith('.' + ext));
|
|
52
|
-
if (
|
|
52
|
+
if (isPlainJavaScriptFile(filePath))
|
|
53
53
|
(0, assert_js_1.assert)(yes);
|
|
54
54
|
return yes;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function isPlainJavaScriptFile(filePath) {
|
|
57
57
|
const yes1 = /\.(c|m)?(j|t)s$/.test(filePath);
|
|
58
58
|
const yes2 = extJavaScript.some((ext) => filePath.endsWith('.' + ext));
|
|
59
59
|
(0, assert_js_1.assert)(yes1 === yes2);
|
|
@@ -7,12 +7,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.parseUrl = parseUrl;
|
|
10
|
-
exports.assertUsageUrlPathname = assertUsageUrlPathname;
|
|
11
10
|
exports.assertUsageUrlPathnameAbsolute = assertUsageUrlPathnameAbsolute;
|
|
12
11
|
exports.assertUsageUrlRedirectTarget = assertUsageUrlRedirectTarget;
|
|
13
12
|
exports.isUrl = isUrl;
|
|
14
13
|
exports.isUri = isUri;
|
|
15
14
|
exports.isUrlRedirectTarget = isUrlRedirectTarget;
|
|
15
|
+
exports.isUrlPathnameRelative = isUrlPathnameRelative;
|
|
16
16
|
exports.isUrlExternal = isUrlExternal;
|
|
17
17
|
exports.isBaseServer = isBaseServer;
|
|
18
18
|
exports.assertUrlComponents = assertUrlComponents;
|
|
@@ -297,16 +297,13 @@ function isUri(uri) {
|
|
|
297
297
|
const { protocol } = parseProtocol(uri);
|
|
298
298
|
return !!protocol && !isUrlProtocol(uri);
|
|
299
299
|
}
|
|
300
|
-
function assertUsageUrlPathname(url, errPrefix) {
|
|
301
|
-
assertUsageUrl(url, errPrefix, { allowRelative: true });
|
|
302
|
-
}
|
|
303
300
|
function assertUsageUrlPathnameAbsolute(url, errPrefix) {
|
|
304
301
|
assertUsageUrl(url, errPrefix);
|
|
305
302
|
}
|
|
306
303
|
function assertUsageUrlRedirectTarget(url, errPrefix, isUnresolved) {
|
|
307
304
|
assertUsageUrl(url, errPrefix, { isRedirectTarget: isUnresolved ? 'unresolved' : true });
|
|
308
305
|
}
|
|
309
|
-
function assertUsageUrl(url, errPrefix, {
|
|
306
|
+
function assertUsageUrl(url, errPrefix, { isRedirectTarget } = {}) {
|
|
310
307
|
if (url.startsWith('/'))
|
|
311
308
|
return;
|
|
312
309
|
let errMsg = `${errPrefix} is ${picocolors_1.default.string(url)} but it should start with ${picocolors_1.default.string('/')}`;
|
|
@@ -320,10 +317,5 @@ function assertUsageUrl(url, errPrefix, { allowRelative, isRedirectTarget } = {}
|
|
|
320
317
|
errMsg += `, or be ${picocolors_1.default.string('*')}`;
|
|
321
318
|
}
|
|
322
319
|
}
|
|
323
|
-
if (allowRelative) {
|
|
324
|
-
if (isUrlPathnameRelative(url))
|
|
325
|
-
return;
|
|
326
|
-
errMsg += ', or be a relative URL';
|
|
327
|
-
}
|
|
328
320
|
(0, assert_js_1.assertUsage)(false, errMsg);
|
|
329
321
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertClientRouting } from '../../utils/assertRoutingType.js';
|
|
2
2
|
assertClientRouting();
|
|
3
3
|
import './pageFiles';
|
|
4
|
-
import {
|
|
4
|
+
import { initClientRouter } from './initClientRouter.js';
|
|
5
5
|
import { assertSingleInstance_onClientEntryClientRouting } from './utils.js';
|
|
6
6
|
import { removeFoucBuster } from '../shared/removeFoucBuster.js';
|
|
7
7
|
// @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
|
|
@@ -9,4 +9,4 @@ const isProd = import.meta.env.PROD;
|
|
|
9
9
|
assertSingleInstance_onClientEntryClientRouting(isProd);
|
|
10
10
|
if (import.meta.env.DEV)
|
|
11
11
|
removeFoucBuster();
|
|
12
|
-
|
|
12
|
+
initClientRouter();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { setPageContextCurrent };
|
|
2
|
+
export { getPageContextCurrent };
|
|
3
|
+
import type { PageContextExports } from '../../shared/getPageFiles.js';
|
|
4
|
+
type PageContextCurrent = PageContextExports & {
|
|
5
|
+
urlPathname: string;
|
|
6
|
+
};
|
|
7
|
+
declare function getPageContextCurrent(): null | PageContextCurrent;
|
|
8
|
+
declare function setPageContextCurrent(pageContextCurrent: PageContextCurrent): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { setPageContextCurrent };
|
|
2
|
+
export { getPageContextCurrent };
|
|
3
|
+
import { getGlobalObject } from './utils.js';
|
|
4
|
+
const globalObject = getGlobalObject('getPageContextCurrent.ts', {
|
|
5
|
+
pageContextCurrent: null
|
|
6
|
+
});
|
|
7
|
+
function getPageContextCurrent() {
|
|
8
|
+
const { pageContextCurrent } = globalObject;
|
|
9
|
+
return pageContextCurrent;
|
|
10
|
+
}
|
|
11
|
+
function setPageContextCurrent(pageContextCurrent) {
|
|
12
|
+
globalObject.pageContextCurrent = pageContextCurrent;
|
|
13
|
+
}
|