vike 0.4.228-commit-84954ae → 0.4.228-commit-0e9e0f2
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/shared/createGetGlobalContext.js +8 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +11 -1
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +6 -0
- package/dist/cjs/shared/createPageContextShared.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/requireResolve.js +85 -63
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +5 -2
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +6 -2
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +4 -1
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +3 -0
- package/dist/esm/client/shared/createGetGlobalContext.d.ts +9 -1
- package/dist/esm/client/shared/createGetGlobalContext.js +8 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +16 -2
- package/dist/esm/node/runtime/globalContext.d.ts +32 -2
- package/dist/esm/node/runtime/globalContext.js +11 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +8 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +16 -2
- package/dist/esm/node/runtime/renderPage.d.ts +8 -1
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/createGlobalContextShared.d.ts +13 -1
- package/dist/esm/shared/createGlobalContextShared.js +6 -0
- package/dist/esm/shared/createPageContextShared.d.ts +1 -1
- package/dist/esm/shared/createPageContextShared.js +1 -1
- package/dist/esm/shared/types.d.ts +8 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/objectAssign.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -2
- package/dist/esm/utils/requireResolve.js +85 -63
- package/package.json +3 -3
|
@@ -20,7 +20,14 @@ function createGetGlobalContext(virtualFileExports, isClientRouting, addGlobalCo
|
|
|
20
20
|
}
|
|
21
21
|
// Create
|
|
22
22
|
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, async (globalContext) => {
|
|
23
|
-
const globalContextAddendum = {
|
|
23
|
+
const globalContextAddendum = {
|
|
24
|
+
/**
|
|
25
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
26
|
+
*
|
|
27
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
28
|
+
*/
|
|
29
|
+
isClientSide: true
|
|
30
|
+
};
|
|
24
31
|
(0, utils_js_1.objectAssign)(globalContextAddendum, (0, getJsonSerializedInHtml_js_1.getGlobalContextSerializedInHtml)());
|
|
25
32
|
(0, utils_js_1.objectAssign)(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
26
33
|
return globalContextAddendum;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -73,7 +73,7 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath, userRoot
|
|
|
73
73
|
// filePathAbsoluteFilesystem is null when pointerImportData.importPath is a path alias that Node.js doesn't know about
|
|
74
74
|
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolveOptional)({
|
|
75
75
|
importPath: pointerImportData.importPath,
|
|
76
|
-
|
|
76
|
+
importerFilePath: importerFilePathAbsolute,
|
|
77
77
|
userRootDir
|
|
78
78
|
});
|
|
79
79
|
if (!filePathAbsoluteFilesystem) {
|
|
@@ -113,7 +113,16 @@ function getGlobalContextSync() {
|
|
|
113
113
|
return globalContext_public;
|
|
114
114
|
}
|
|
115
115
|
function makePublic(globalContext) {
|
|
116
|
-
const globalContextPublic = (0, utils_js_1.getPublicProxy)(globalContext, 'globalContext', [
|
|
116
|
+
const globalContextPublic = (0, utils_js_1.getPublicProxy)(globalContext, 'globalContext', [
|
|
117
|
+
'assetsManifest',
|
|
118
|
+
'config',
|
|
119
|
+
'viteConfig',
|
|
120
|
+
'viteConfigRuntime',
|
|
121
|
+
'pages',
|
|
122
|
+
'baseServer',
|
|
123
|
+
'baseAssets',
|
|
124
|
+
'isClientSide'
|
|
125
|
+
], true);
|
|
117
126
|
return globalContextPublic;
|
|
118
127
|
}
|
|
119
128
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
@@ -338,6 +347,7 @@ async function setGlobalContext(virtualFileExports) {
|
|
|
338
347
|
async function addGlobalContext(globalContext) {
|
|
339
348
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
340
349
|
const globalContextBase = {
|
|
350
|
+
isClientSide: false,
|
|
341
351
|
_pageRoutes: pageRoutes,
|
|
342
352
|
_onBeforeRouteHook: onBeforeRouteHook
|
|
343
353
|
};
|
|
@@ -9,7 +9,7 @@ function preparePageContextForUserConsumptionServerSide(pageContext) {
|
|
|
9
9
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(pageContext.routeParams));
|
|
10
10
|
(0, utils_js_1.assert)('Page' in pageContext);
|
|
11
11
|
(0, utils_js_1.assert)(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
12
|
-
(0, utils_js_1.assert)(pageContext.
|
|
12
|
+
(0, utils_js_1.assert)(pageContext.isPageContext);
|
|
13
13
|
(0, utils_js_1.assert)(pageContext.isClientSide === false);
|
|
14
14
|
(0, utils_js_1.assert)(typeof pageContext.isPrerendering === 'boolean');
|
|
15
15
|
(0, preparePageContextForUserConsumption_js_1.preparePageContextForUserConsumption)(pageContext);
|
|
@@ -12,7 +12,7 @@ function assertPageContextProvidedByUser(pageContextProvidedByUser, { hookName,
|
|
|
12
12
|
(0, utils_js_1.assert)(!hookName.endsWith(')'));
|
|
13
13
|
const errPrefix = `The ${picocolors_1.default.cyan('pageContext')} object provided by the ${hookName}() hook defined by ${hookFilePath}`;
|
|
14
14
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(pageContextProvidedByUser), `${errPrefix} should be an object (but it's ${picocolors_1.default.cyan(`typeof pageContext === ${JSON.stringify(typeof pageContextProvidedByUser)}`)} instead)`);
|
|
15
|
-
(0, utils_js_1.assertUsage)(!('
|
|
15
|
+
(0, utils_js_1.assertUsage)(!('isPageContext' in pageContextProvidedByUser), `${errPrefix} shouldn't be the whole ${picocolors_1.default.cyan('pageContext')} object, see https://vike.dev/pageContext-manipulation#do-not-return-entire-pagecontext`);
|
|
16
16
|
// In principle, it's possible to use onBeforeRoute()` to override and define the whole routing.
|
|
17
17
|
// Is that a good idea to allow users to do this? Beyond deep integration with Vue Router or React Router, is there a use case for this?
|
|
18
18
|
(0, utils_js_1.assertWarning)(!('pageId' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext.pageId')} which means that Vike's routing is overriden. This is an experimental feature: make sure to contact a vike maintainer before using this.`, { onlyOnce: true });
|
|
@@ -33,6 +33,12 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
|
|
|
33
33
|
function createGlobalContextBase(virtualFileExports) {
|
|
34
34
|
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly } = (0, getPageConfigsRuntime_js_1.getPageConfigsRuntime)(virtualFileExports);
|
|
35
35
|
const globalContext = {
|
|
36
|
+
/**
|
|
37
|
+
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
38
|
+
*
|
|
39
|
+
* https://vike.dev/globalContext#typescript
|
|
40
|
+
*/
|
|
41
|
+
isGlobalContext: true,
|
|
36
42
|
_virtualFileExports: virtualFileExports,
|
|
37
43
|
_pageFilesAll: pageFilesAll,
|
|
38
44
|
_pageConfigs: pageConfigs,
|
|
@@ -9,7 +9,7 @@ async function createPageContextShared(pageContextCreated, pageConfigGlobal) {
|
|
|
9
9
|
pageConfigGlobalValues: pageConfigGlobal.configValues
|
|
10
10
|
});
|
|
11
11
|
(0, utils_js_1.objectAssign)(pageContextCreated, {
|
|
12
|
-
|
|
12
|
+
isPageContext: true,
|
|
13
13
|
...pageConfigGlobalUserFriendly
|
|
14
14
|
}, true);
|
|
15
15
|
await (0, executeHookGeneric_js_1.executeHookGenericGlobalCumulative)('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated);
|
|
@@ -9,6 +9,6 @@ function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
|
|
|
9
9
|
if (!objAddendum)
|
|
10
10
|
return;
|
|
11
11
|
if (!objAddendumCanBePageContextObject)
|
|
12
|
-
(0, assert_js_1.assert)(!('
|
|
12
|
+
(0, assert_js_1.assert)(!('isPageContext' in objAddendum));
|
|
13
13
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
14
14
|
}
|
|
@@ -16,93 +16,117 @@ const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
|
16
16
|
const node_module_1 = require("node:module");
|
|
17
17
|
const node_path_1 = __importDefault(require("node:path"));
|
|
18
18
|
const parseNpmPackage_js_1 = require("./parseNpmPackage.js");
|
|
19
|
+
const isNullish_js_1 = require("./isNullish.js");
|
|
19
20
|
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
20
21
|
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
22
|
+
(0, path_js_1.assertPosixPath)(importMetaUrl);
|
|
21
23
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
22
24
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
// - We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
26
|
+
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
27
|
+
// - Passing context to createRequire(context) isn't equivalent to passing it to the `paths` argument of require.resolve()
|
|
28
|
+
// - https://github.com/brillout/require-test
|
|
29
|
+
// - In practice, I guess it doesn't make a difference? It just seems to be small Node.js weirdness.
|
|
30
|
+
// - The argument createRequire(argument) seems to be overriden by the `paths` argument require.resolve()
|
|
31
|
+
// - For example, passing an empty array to `paths` kills the argument passed to `createRequire()`
|
|
32
|
+
// - Thus, when `paths` is defined, then the context needs to be passed to both createRequire() as well as the `paths` argument of require.resolve()
|
|
33
|
+
function requireResolve_(importPath, importerFilePath, { userRootDir, doNotHandleFileExtension } = {}) {
|
|
25
34
|
(0, path_js_1.assertPosixPath)(importPath);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
const contexts = importerFilePath
|
|
36
|
+
? [importerFilePath]
|
|
37
|
+
: [userRootDir ? getFakeImporterFile(userRootDir) : importMetaUrl];
|
|
38
|
+
addExtraContextForNpmPackageImport(contexts, { importPath, userRootDir });
|
|
39
|
+
let importPathResolvedFilePath;
|
|
40
|
+
let failure;
|
|
41
|
+
for (const context of contexts) {
|
|
42
|
+
(0, path_js_1.assertPosixPath)(context);
|
|
43
|
+
const require_ = (0, node_module_1.createRequire)(ensureFilePrefix(context));
|
|
44
|
+
if (!doNotHandleFileExtension) {
|
|
45
|
+
addFileExtensionsToRequireResolve(require_);
|
|
46
|
+
importPath = removeFileExtention(importPath);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
importPathResolvedFilePath = require_.resolve(importPath);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
/* DEBUG
|
|
53
|
+
console.log('err', err)
|
|
54
|
+
console.log('importPath', importPath)
|
|
55
|
+
console.log('importerFilePath', importerFilePath)
|
|
56
|
+
console.log('context', context)
|
|
57
|
+
console.log('importMetaUrl', importMetaUrl)
|
|
58
|
+
console.log('paths', paths)
|
|
59
|
+
//*/
|
|
60
|
+
failure ?? (failure = { err });
|
|
61
|
+
}
|
|
62
|
+
if (importPathResolvedFilePath)
|
|
63
|
+
break;
|
|
33
64
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
:
|
|
37
|
-
// Seems like `importerPath` gets overriden by the `paths` argument, so we add it to `paths`. (For example, passing an empty array to `paths` kills the argument passed to `createRequire()`.)
|
|
38
|
-
toDirPath(importerFile),
|
|
39
|
-
...(options?.paths || [])
|
|
40
|
-
];
|
|
41
|
-
let importedFile;
|
|
42
|
-
try {
|
|
43
|
-
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
44
|
-
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
45
|
-
importedFile = require_.resolve(importPath, { paths });
|
|
65
|
+
if (!importPathResolvedFilePath) {
|
|
66
|
+
(0, assert_js_1.assert)(failure);
|
|
67
|
+
return { importPathResolvedFilePath: undefined, err: failure.err, hasFailed: true };
|
|
46
68
|
}
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
else {
|
|
70
|
+
(0, assert_js_1.assert)(importPathResolvedFilePath);
|
|
71
|
+
importPathResolvedFilePath = (0, path_js_1.toPosixPath)(importPathResolvedFilePath);
|
|
72
|
+
return { importPathResolvedFilePath, err: undefined, hasFailed: false };
|
|
49
73
|
}
|
|
50
|
-
importedFile = (0, path_js_1.toPosixPath)(importedFile);
|
|
51
|
-
return { importedFile, err: undefined, hasFailed: false };
|
|
52
74
|
}
|
|
53
|
-
function requireResolveOptional({ importPath,
|
|
54
|
-
const
|
|
55
|
-
const res = requireResolve_(importPath, importerFile, { paths });
|
|
75
|
+
function requireResolveOptional({ importPath, importerFilePath, userRootDir }) {
|
|
76
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
56
77
|
if (res.hasFailed)
|
|
57
78
|
return null;
|
|
58
|
-
return res.
|
|
79
|
+
return res.importPathResolvedFilePath;
|
|
59
80
|
}
|
|
60
81
|
function requireResolveOptionalDir({ importPath, importerDir, userRootDir }) {
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const res = requireResolve_(importPath, importerFile, { paths });
|
|
82
|
+
const importerFilePath = getFakeImporterFile(importerDir);
|
|
83
|
+
const res = requireResolve_(importPath, importerFilePath, { userRootDir });
|
|
64
84
|
if (res.hasFailed)
|
|
65
85
|
return null;
|
|
66
|
-
return res.
|
|
86
|
+
return res.importPathResolvedFilePath;
|
|
67
87
|
}
|
|
68
88
|
function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }) {
|
|
69
89
|
(0, parseNpmPackage_js_1.assertIsImportPathNpmPackage)(importPathNpmPackage);
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const res = requireResolve_(importPathNpmPackage, importerFile, { paths });
|
|
90
|
+
const importerFilePath = getFakeImporterFile(userRootDir);
|
|
91
|
+
const res = requireResolve_(importPathNpmPackage, importerFilePath, { userRootDir });
|
|
73
92
|
if (res.hasFailed)
|
|
74
93
|
throw res.err;
|
|
75
|
-
return res.
|
|
94
|
+
return res.importPathResolvedFilePath;
|
|
76
95
|
}
|
|
77
96
|
function requireResolveVikeDistFile(vikeDistFile) {
|
|
78
97
|
const vikeNodeModulesRoot = getVikeNodeModulesRoot();
|
|
79
98
|
(0, path_js_1.assertPosixPath)(vikeNodeModulesRoot);
|
|
80
99
|
(0, path_js_1.assertPosixPath)(vikeDistFile);
|
|
81
|
-
const
|
|
100
|
+
const importPathResolvedFilePath = node_path_1.default.posix.join(vikeNodeModulesRoot, vikeDistFile);
|
|
82
101
|
// Double check
|
|
83
102
|
{
|
|
84
|
-
const res = requireResolve_(
|
|
85
|
-
//
|
|
86
|
-
|
|
103
|
+
const res = requireResolve_(importPathResolvedFilePath,
|
|
104
|
+
// No context needed: importPathResolvedFilePath is already resolved and absolute
|
|
105
|
+
null, { doNotHandleFileExtension: true });
|
|
87
106
|
if (res.hasFailed)
|
|
88
107
|
throw res.err;
|
|
89
|
-
(0, assert_js_1.assert)(res.
|
|
108
|
+
(0, assert_js_1.assert)(res.importPathResolvedFilePath === importPathResolvedFilePath);
|
|
90
109
|
}
|
|
91
|
-
return
|
|
110
|
+
return importPathResolvedFilePath;
|
|
92
111
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const paths = [
|
|
112
|
+
function addExtraContextForNpmPackageImport(contexts, { importPath, userRootDir }) {
|
|
113
|
+
// We should add extra context only for npm packages, but unfortunately we cannot always disambiguate between npm package imports and path aliases.
|
|
114
|
+
if (!(0, parseNpmPackage_js_1.isImportPathNpmPackageOrPathAlias)(importPath))
|
|
115
|
+
return;
|
|
116
|
+
const userRootDirFakeFile = userRootDir && getFakeImporterFile(userRootDir);
|
|
117
|
+
[
|
|
100
118
|
// Workaround for monorepo resolve issue: https://github.com/vikejs/vike-react/pull/161/commits/dbaa6643e78015ac2797c237552800fef29b72a7
|
|
101
|
-
|
|
102
|
-
// I can't think of a use case where this would be needed, but let's add
|
|
103
|
-
|
|
104
|
-
]
|
|
105
|
-
|
|
119
|
+
userRootDirFakeFile,
|
|
120
|
+
// I can't think of a use case where this would be needed, but let's add one extra last chance to sucessfully resolve some complex monorepo setups
|
|
121
|
+
importMetaUrl
|
|
122
|
+
]
|
|
123
|
+
.filter(isNullish_js_1.isNotNullish)
|
|
124
|
+
.forEach((context) => {
|
|
125
|
+
const alreadyHasContext = contexts.includes(context) || contexts.includes(ensureFilePrefix(context));
|
|
126
|
+
if (alreadyHasContext)
|
|
127
|
+
return;
|
|
128
|
+
contexts.push(context);
|
|
129
|
+
});
|
|
106
130
|
}
|
|
107
131
|
function removeFileExtention(importPath) {
|
|
108
132
|
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
@@ -137,16 +161,14 @@ function getVikeNodeModulesRoot() {
|
|
|
137
161
|
const vikeNodeModulesRoot = node_path_1.default.posix.join(removeFilePrefix(importMetaUrl), '../../../../');
|
|
138
162
|
return vikeNodeModulesRoot;
|
|
139
163
|
}
|
|
140
|
-
function
|
|
141
|
-
return node_path_1.default.posix.dirname(removeFilePrefix(filePath));
|
|
142
|
-
}
|
|
143
|
-
function getFakeFilePath(dirPath) {
|
|
164
|
+
function getFakeImporterFile(dirPath) {
|
|
144
165
|
(0, path_js_1.assertPosixPath)(dirPath);
|
|
145
|
-
(0, assert_js_1.assert)(!dirPath.startsWith('file')); // The file:// prefix is bogus with path.join
|
|
146
|
-
const
|
|
147
|
-
return
|
|
166
|
+
(0, assert_js_1.assert)(!dirPath.startsWith('file')); // The file:// prefix is bogus when used with path.posix.join()
|
|
167
|
+
const importerFilePath = node_path_1.default.posix.join(dirPath, 'fakeFileForNodeResolve.js');
|
|
168
|
+
return importerFilePath;
|
|
148
169
|
}
|
|
149
|
-
function
|
|
170
|
+
function ensureFilePrefix(filePath) {
|
|
171
|
+
(0, path_js_1.assertPosixPath)(filePath);
|
|
150
172
|
const filePrefix = getFilePrefix();
|
|
151
173
|
if (!filePath.startsWith(filePrefix)) {
|
|
152
174
|
(0, assert_js_1.assert)(!filePath.startsWith('file'));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createPageContextClientSide };
|
|
2
2
|
declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
3
3
|
globalContext: {
|
|
4
|
+
isGlobalContext: true;
|
|
4
5
|
_virtualFileExports: unknown;
|
|
5
6
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
6
7
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -8,7 +9,9 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
8
9
|
_allPageIds: string[];
|
|
9
10
|
config: import("../../types/index.js").ConfigResolved;
|
|
10
11
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
11
|
-
} &
|
|
12
|
+
} & {
|
|
13
|
+
isClientSide: true;
|
|
14
|
+
} & {
|
|
12
15
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
13
16
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
14
17
|
};
|
|
@@ -33,5 +36,5 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
33
36
|
_source: import("../../shared/page-configs/getPageConfigUserFriendly.js").Source;
|
|
34
37
|
_sources: import("../../shared/page-configs/getPageConfigUserFriendly.js").Sources;
|
|
35
38
|
_from: import("../../shared/page-configs/getPageConfigUserFriendly.js").From;
|
|
36
|
-
|
|
39
|
+
isPageContext: true;
|
|
37
40
|
}>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { getGlobalContext };
|
|
2
2
|
export type { GlobalContextClient };
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
|
-
type GlobalContextClient = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
4
|
+
type GlobalContextClient = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
+
type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContext>>;
|
|
5
6
|
declare const getGlobalContext: () => Promise<{
|
|
7
|
+
isGlobalContext: true;
|
|
6
8
|
_virtualFileExports: unknown;
|
|
7
9
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
8
10
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -10,7 +12,9 @@ declare const getGlobalContext: () => Promise<{
|
|
|
10
12
|
_allPageIds: string[];
|
|
11
13
|
config: import("../../types/index.js").ConfigResolved;
|
|
12
14
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
13
|
-
} &
|
|
15
|
+
} & {
|
|
16
|
+
isClientSide: true;
|
|
17
|
+
} & {
|
|
14
18
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
15
19
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
16
20
|
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createPageContextClientSide };
|
|
2
2
|
declare function createPageContextClientSide(): Promise<{
|
|
3
3
|
globalContext: {
|
|
4
|
+
isGlobalContext: true;
|
|
4
5
|
_virtualFileExports: unknown;
|
|
5
6
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
6
7
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -8,6 +9,8 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
8
9
|
_allPageIds: string[];
|
|
9
10
|
config: import("../../types/index.js").ConfigResolved;
|
|
10
11
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
12
|
+
} & {
|
|
13
|
+
isClientSide: true;
|
|
11
14
|
} & object;
|
|
12
15
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
13
16
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -29,5 +32,5 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
29
32
|
_source: import("../../shared/page-configs/getPageConfigUserFriendly.js").Source;
|
|
30
33
|
_sources: import("../../shared/page-configs/getPageConfigUserFriendly.js").Sources;
|
|
31
34
|
_from: import("../../shared/page-configs/getPageConfigUserFriendly.js").From;
|
|
32
|
-
|
|
35
|
+
isPageContext: true;
|
|
33
36
|
}>;
|
|
@@ -3,6 +3,7 @@ export type { GlobalContextClientWithServerRouting };
|
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
4
|
type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
5
|
declare const getGlobalContext: () => Promise<{
|
|
6
|
+
isGlobalContext: true;
|
|
6
7
|
_virtualFileExports: unknown;
|
|
7
8
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
8
9
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -10,4 +11,6 @@ declare const getGlobalContext: () => Promise<{
|
|
|
10
11
|
_allPageIds: string[];
|
|
11
12
|
config: import("../../types/index.js").ConfigResolved;
|
|
12
13
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
14
|
+
} & {
|
|
15
|
+
isClientSide: true;
|
|
13
16
|
} & object>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createGetGlobalContext };
|
|
2
2
|
import { type GlobalContextShared } from '../../shared/createGlobalContextShared.js';
|
|
3
3
|
declare function createGetGlobalContext<GlobalContextAddendum extends object>(virtualFileExports: unknown, isClientRouting: boolean, addGlobalContext?: (globalContext: GlobalContextShared) => Promise<GlobalContextAddendum>): () => Promise<{
|
|
4
|
+
isGlobalContext: true;
|
|
4
5
|
_virtualFileExports: unknown;
|
|
5
6
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
6
7
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
@@ -8,4 +9,11 @@ declare function createGetGlobalContext<GlobalContextAddendum extends object>(vi
|
|
|
8
9
|
_allPageIds: string[];
|
|
9
10
|
config: import("../../types/index.js").ConfigResolved;
|
|
10
11
|
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
11
|
-
} & Awaited<
|
|
12
|
+
} & Awaited<{
|
|
13
|
+
/**
|
|
14
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
15
|
+
*
|
|
16
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
17
|
+
*/
|
|
18
|
+
isClientSide: true;
|
|
19
|
+
} & Awaited<GlobalContextAddendum>>>;
|
|
@@ -18,7 +18,14 @@ function createGetGlobalContext(virtualFileExports, isClientRouting, addGlobalCo
|
|
|
18
18
|
}
|
|
19
19
|
// Create
|
|
20
20
|
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, async (globalContext) => {
|
|
21
|
-
const globalContextAddendum = {
|
|
21
|
+
const globalContextAddendum = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
24
|
+
*
|
|
25
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
26
|
+
*/
|
|
27
|
+
isClientSide: true
|
|
28
|
+
};
|
|
22
29
|
objectAssign(globalContextAddendum, getGlobalContextSerializedInHtml());
|
|
23
30
|
objectAssign(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
24
31
|
return globalContextAddendum;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -68,7 +68,7 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath, userRoot
|
|
|
68
68
|
// filePathAbsoluteFilesystem is null when pointerImportData.importPath is a path alias that Node.js doesn't know about
|
|
69
69
|
const filePathAbsoluteFilesystem = requireResolveOptional({
|
|
70
70
|
importPath: pointerImportData.importPath,
|
|
71
|
-
|
|
71
|
+
importerFilePath: importerFilePathAbsolute,
|
|
72
72
|
userRootDir
|
|
73
73
|
});
|
|
74
74
|
if (!filePathAbsoluteFilesystem) {
|
|
@@ -75,6 +75,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
75
75
|
} & {
|
|
76
76
|
globalContext: GlobalContextServer;
|
|
77
77
|
_globalContext: {
|
|
78
|
+
isGlobalContext: true;
|
|
78
79
|
_virtualFileExports: unknown;
|
|
79
80
|
_pageFilesAll: PageFile[];
|
|
80
81
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -100,8 +101,10 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
100
101
|
};
|
|
101
102
|
baseServer: string;
|
|
102
103
|
baseAssets: string;
|
|
104
|
+
isClientSide: false;
|
|
103
105
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
104
106
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
107
|
+
isGlobalContext: true;
|
|
105
108
|
_virtualFileExports: unknown;
|
|
106
109
|
_pageFilesAll: PageFile[];
|
|
107
110
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -128,8 +131,10 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
128
131
|
_usesClientRouter: boolean;
|
|
129
132
|
baseServer: string;
|
|
130
133
|
baseAssets: string;
|
|
134
|
+
isClientSide: false;
|
|
131
135
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
132
136
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
137
|
+
isGlobalContext: true;
|
|
133
138
|
_virtualFileExports: unknown;
|
|
134
139
|
_pageFilesAll: PageFile[];
|
|
135
140
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -156,8 +161,10 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
156
161
|
_usesClientRouter: boolean;
|
|
157
162
|
baseServer: string;
|
|
158
163
|
baseAssets: string;
|
|
164
|
+
isClientSide: false;
|
|
159
165
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
160
166
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
167
|
+
isGlobalContext: true;
|
|
161
168
|
_virtualFileExports: unknown;
|
|
162
169
|
_pageFilesAll: PageFile[];
|
|
163
170
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -190,7 +197,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
190
197
|
_source: import("../../shared/page-configs/getPageConfigUserFriendly.js").Source;
|
|
191
198
|
_sources: import("../../shared/page-configs/getPageConfigUserFriendly.js").Sources;
|
|
192
199
|
_from: import("../../shared/page-configs/getPageConfigUserFriendly.js").From;
|
|
193
|
-
|
|
200
|
+
isPageContext: true;
|
|
194
201
|
} & {
|
|
195
202
|
_urlHandler: null;
|
|
196
203
|
_httpRequestId: null;
|
|
@@ -209,6 +216,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
209
216
|
} & {
|
|
210
217
|
globalContext: GlobalContextServer;
|
|
211
218
|
_globalContext: {
|
|
219
|
+
isGlobalContext: true;
|
|
212
220
|
_virtualFileExports: unknown;
|
|
213
221
|
_pageFilesAll: PageFile[];
|
|
214
222
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -234,8 +242,10 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
234
242
|
};
|
|
235
243
|
baseServer: string;
|
|
236
244
|
baseAssets: string;
|
|
245
|
+
isClientSide: false;
|
|
237
246
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
238
247
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
248
|
+
isGlobalContext: true;
|
|
239
249
|
_virtualFileExports: unknown;
|
|
240
250
|
_pageFilesAll: PageFile[];
|
|
241
251
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -262,8 +272,10 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
262
272
|
_usesClientRouter: boolean;
|
|
263
273
|
baseServer: string;
|
|
264
274
|
baseAssets: string;
|
|
275
|
+
isClientSide: false;
|
|
265
276
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
266
277
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
278
|
+
isGlobalContext: true;
|
|
267
279
|
_virtualFileExports: unknown;
|
|
268
280
|
_pageFilesAll: PageFile[];
|
|
269
281
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -290,8 +302,10 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
290
302
|
_usesClientRouter: boolean;
|
|
291
303
|
baseServer: string;
|
|
292
304
|
baseAssets: string;
|
|
305
|
+
isClientSide: false;
|
|
293
306
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
294
307
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
308
|
+
isGlobalContext: true;
|
|
295
309
|
_virtualFileExports: unknown;
|
|
296
310
|
_pageFilesAll: PageFile[];
|
|
297
311
|
_pageConfigs: import("../../shared/page-configs/PageConfig.js").PageConfigRuntime[];
|
|
@@ -324,7 +338,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
324
338
|
_source: import("../../shared/page-configs/getPageConfigUserFriendly.js").Source;
|
|
325
339
|
_sources: import("../../shared/page-configs/getPageConfigUserFriendly.js").Sources;
|
|
326
340
|
_from: import("../../shared/page-configs/getPageConfigUserFriendly.js").From;
|
|
327
|
-
|
|
341
|
+
isPageContext: true;
|
|
328
342
|
} & {
|
|
329
343
|
_urlHandler: null;
|
|
330
344
|
_httpRequestId: null;
|