vike 0.4.228-commit-84954ae → 0.4.228-commit-1bb55f1
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/__internal/index.js +1 -1
- package/dist/cjs/client/client-routing-runtime/globalContext.js +4 -4
- package/dist/cjs/client/server-routing-runtime/globalContext.js +4 -4
- package/dist/cjs/client/shared/{createGetGlobalContext.js → createGetGlobalContextClient.js} +31 -4
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +0 -1
- package/dist/cjs/node/prerender/runPrerender.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +17 -6
- package/dist/cjs/node/runtime/index-deprecated.js +9 -38
- package/dist/cjs/node/runtime/index.js +56 -2
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +9 -0
- package/dist/cjs/shared/createPageContextShared.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.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/__internal/index.js +2 -2
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +5 -2
- package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -2
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +8 -4
- package/dist/esm/client/client-routing-runtime/globalContext.js +3 -3
- package/dist/esm/client/index.d.ts +1 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/node.js +1 -3
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +4 -1
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +2 -2
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +7 -3
- package/dist/esm/client/server-routing-runtime/globalContext.js +3 -3
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +23 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.js +58 -0
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +0 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +18 -4
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +39 -8
- package/dist/esm/node/runtime/globalContext.js +18 -7
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -16
- package/dist/esm/node/runtime/index-deprecated.js +9 -36
- package/dist/esm/node/runtime/index.d.ts +23 -1
- package/dist/esm/node/runtime/index.js +38 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +10 -3
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- 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 +10 -3
- package/dist/esm/node/runtime/renderPage.js +2 -2
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/createGlobalContextShared.d.ts +15 -1
- package/dist/esm/shared/createGlobalContextShared.js +8 -0
- package/dist/esm/shared/createPageContextShared.d.ts +1 -1
- package/dist/esm/shared/createPageContextShared.js +1 -1
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +36 -13
- 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 +12 -11
- package/dist/cjs/node/runtime/index-common.js +0 -27
- package/dist/esm/client/shared/createGetGlobalContext.d.ts +0 -11
- package/dist/esm/client/shared/createGetGlobalContext.js +0 -29
- package/dist/esm/node/runtime/index-common.d.ts +0 -8
- package/dist/esm/node/runtime/index-common.js +0 -10
|
@@ -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'));
|
|
@@ -3,7 +3,7 @@ export { setGlobalContext_buildEntry } from '../node/runtime/globalContext.js';
|
|
|
3
3
|
// Needed by vite-plugin-vercel
|
|
4
4
|
export { route, getPagesAndRoutes };
|
|
5
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getGlobalContextServerInternal, initGlobalContext_getPagesAndRoutes } from '../node/runtime/globalContext.js';
|
|
7
7
|
import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
8
8
|
/**
|
|
9
9
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
@@ -13,7 +13,7 @@ import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
|
13
13
|
async function getPagesAndRoutes() {
|
|
14
14
|
setNodeEnvProduction();
|
|
15
15
|
await initGlobalContext_getPagesAndRoutes();
|
|
16
|
-
const { globalContext } = await
|
|
16
|
+
const { globalContext } = await getGlobalContextServerInternal();
|
|
17
17
|
const {
|
|
18
18
|
//
|
|
19
19
|
_pageRoutes: pageRoutes, _pageFilesAll: pageFilesAll, _pageConfigs: pageConfigs, _allPageIds: allPageIds } = globalContext;
|
|
@@ -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
|
}>;
|
|
@@ -2,10 +2,10 @@ export { createPageContextClientSide };
|
|
|
2
2
|
import { createPageContextShared } from '../../shared/createPageContextShared.js';
|
|
3
3
|
import { getPageContextUrlComputed } from '../../shared/getPageContextUrlComputed.js';
|
|
4
4
|
import { getBaseServer } from './getBaseServer.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getGlobalContextClientInternal } from './globalContext.js';
|
|
6
6
|
import { assert, augmentType, isBaseServer, objectAssign } from './utils.js';
|
|
7
7
|
async function createPageContextClientSide(urlOriginal) {
|
|
8
|
-
const globalContext = await
|
|
8
|
+
const globalContext = await getGlobalContextClientInternal();
|
|
9
9
|
const baseServer = getBaseServer();
|
|
10
10
|
assert(isBaseServer(baseServer));
|
|
11
11
|
const pageContextCreated = {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
2
|
export type { GlobalContextClient };
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
|
-
type GlobalContextClient = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
-
|
|
4
|
+
type GlobalContextClient = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
+
type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
|
|
6
|
+
declare const getGlobalContextClientInternal: () => 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,9 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
|
+
import { createGetGlobalContextClient } from '../shared/createGetGlobalContextClient.js';
|
|
3
3
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
import * as virtualFileExports from 'virtual:vike:importUserCode:client:client-routing';
|
|
6
|
-
const
|
|
6
|
+
const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExports, true, addGlobalContext);
|
|
7
7
|
async function addGlobalContext(globalContext) {
|
|
8
8
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
9
9
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getGlobalContext, getGlobalContext as getGlobalContextAsync, getGlobalContextSync } from './shared/createGetGlobalContextClient.js';
|
package/dist/esm/client/node.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { assertUsage } from './server-routing-runtime/utils.js';
|
|
2
2
|
assertUsage(false, [
|
|
3
|
-
'
|
|
3
|
+
'Server imports are forbidden on the client-side:',
|
|
4
4
|
" import { something } from 'vike/server'",
|
|
5
|
-
// TODO/v1-release: remove this line (also remove s above in `s/Following imports/Following import/`)
|
|
6
|
-
" import { something } from 'vike'",
|
|
7
5
|
'Did you mean the following instead?',
|
|
8
6
|
" import { something } from 'vike/client/router'"
|
|
9
7
|
].join('\n'), { showStackTrace: true });
|
|
@@ -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
|
}>;
|
|
@@ -4,10 +4,10 @@ import { getPageContextSerializedInHtml } from '../shared/getJsonSerializedInHtm
|
|
|
4
4
|
import { loadUserFilesClientSide } from '../shared/loadUserFilesClientSide.js';
|
|
5
5
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
6
6
|
import { createPageContextShared } from '../../shared/createPageContextShared.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getGlobalContextClientInternal } from './globalContext.js';
|
|
8
8
|
const urlFirst = getCurrentUrl({ withoutHash: true });
|
|
9
9
|
async function createPageContextClientSide() {
|
|
10
|
-
const globalContext = await
|
|
10
|
+
const globalContext = await getGlobalContextClientInternal();
|
|
11
11
|
const pageContextCreated = {
|
|
12
12
|
/* Don't spread globalContext for now? Or never spread it as it leads to confusion? The convenience isn't worth the added confusion?
|
|
13
13
|
...globalContext, // least precedence
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
2
|
export type { GlobalContextClientWithServerRouting };
|
|
3
3
|
import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
|
|
4
|
-
type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
-
|
|
4
|
+
type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
|
|
5
|
+
type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
|
|
6
|
+
declare const getGlobalContextClientInternal: () => 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,4 +12,6 @@ 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;
|
|
15
|
+
} & {
|
|
16
|
+
isClientSide: true;
|
|
13
17
|
} & object>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import {
|
|
1
|
+
export { getGlobalContextClientInternal };
|
|
2
|
+
import { createGetGlobalContextClient } from '../shared/createGetGlobalContextClient.js';
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import * as virtualFileExports from 'virtual:vike:importUserCode:client:server-routing';
|
|
5
|
-
const
|
|
5
|
+
const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExports, false);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { getGlobalContext };
|
|
2
|
+
export { getGlobalContextSync };
|
|
3
|
+
export { createGetGlobalContextClient };
|
|
4
|
+
import { type GlobalContextShared } from '../../shared/createGlobalContextShared.js';
|
|
5
|
+
declare function createGetGlobalContextClient<GlobalContextAddendum extends object>(virtualFileExports: unknown, isClientRouting: boolean, addGlobalContext?: (globalContext: GlobalContextShared) => Promise<GlobalContextAddendum>): () => Promise<{
|
|
6
|
+
isGlobalContext: true;
|
|
7
|
+
_virtualFileExports: unknown;
|
|
8
|
+
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
9
|
+
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
10
|
+
_pageConfigGlobal: import("../../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
|
|
11
|
+
_allPageIds: string[];
|
|
12
|
+
config: import("../../types/index.js").ConfigResolved;
|
|
13
|
+
pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
|
|
14
|
+
} & Awaited<{
|
|
15
|
+
/**
|
|
16
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
17
|
+
*
|
|
18
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
19
|
+
*/
|
|
20
|
+
isClientSide: true;
|
|
21
|
+
} & Awaited<GlobalContextAddendum>>>;
|
|
22
|
+
declare function getGlobalContext(): Promise<never>;
|
|
23
|
+
declare function getGlobalContextSync(): never;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Public usage
|
|
2
|
+
export { getGlobalContext };
|
|
3
|
+
export { getGlobalContextSync };
|
|
4
|
+
// Internal usage
|
|
5
|
+
export { createGetGlobalContextClient };
|
|
6
|
+
import { createGlobalContextShared, getGlobalContextSyncErrMsg } from '../../shared/createGlobalContextShared.js';
|
|
7
|
+
import { getGlobalContextSerializedInHtml } from './getJsonSerializedInHtml.js';
|
|
8
|
+
import { assert, assertUsage, genPromise, getGlobalObject, objectAssign } from './utils.js';
|
|
9
|
+
const globalObject = getGlobalObject('createGetGlobalContextClient.ts', (() => {
|
|
10
|
+
const { promise: globalContextPromise, resolve: globalContextPromiseResolve } = genPromise();
|
|
11
|
+
return {
|
|
12
|
+
globalContextPromise,
|
|
13
|
+
globalContextPromiseResolve
|
|
14
|
+
};
|
|
15
|
+
})());
|
|
16
|
+
function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGlobalContext) {
|
|
17
|
+
assert(globalObject.isClientRouting === undefined || globalObject.isClientRouting === isClientRouting);
|
|
18
|
+
globalObject.isClientRouting = isClientRouting;
|
|
19
|
+
// Eagerly call onCreateGlobalContext() hook
|
|
20
|
+
getGlobalContext();
|
|
21
|
+
return getGlobalContext;
|
|
22
|
+
async function getGlobalContext() {
|
|
23
|
+
// Cache
|
|
24
|
+
if (globalObject.globalContext &&
|
|
25
|
+
// Don't break HMR
|
|
26
|
+
globalObject.globalContext._virtualFileExports !== virtualFileExports) {
|
|
27
|
+
return globalObject.globalContext;
|
|
28
|
+
}
|
|
29
|
+
// Create
|
|
30
|
+
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, async (globalContext) => {
|
|
31
|
+
const globalContextAddendum = {
|
|
32
|
+
/**
|
|
33
|
+
* Whether the environment is client-side or server-side / pre-rendering.
|
|
34
|
+
*
|
|
35
|
+
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
36
|
+
*/
|
|
37
|
+
isClientSide: true
|
|
38
|
+
};
|
|
39
|
+
objectAssign(globalContextAddendum, getGlobalContextSerializedInHtml());
|
|
40
|
+
objectAssign(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
41
|
+
return globalContextAddendum;
|
|
42
|
+
});
|
|
43
|
+
assert(globalObject.globalContext);
|
|
44
|
+
globalObject.globalContextPromiseResolve(globalObject.globalContext);
|
|
45
|
+
// Return
|
|
46
|
+
return globalContext;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// The type is never used: it's the type of the server-side getGlobalContext() that is used.
|
|
50
|
+
async function getGlobalContext() {
|
|
51
|
+
const globalContext = await globalObject.globalContextPromise;
|
|
52
|
+
return globalContext;
|
|
53
|
+
}
|
|
54
|
+
function getGlobalContextSync() {
|
|
55
|
+
const { globalContext } = globalObject;
|
|
56
|
+
assertUsage(globalContext, getGlobalContextSyncErrMsg);
|
|
57
|
+
return globalContext;
|
|
58
|
+
}
|
|
@@ -153,14 +153,17 @@ function assertSingleInstance(config) {
|
|
|
153
153
|
function assertVikeCliOrApi(config) {
|
|
154
154
|
if (isVikeCliOrApi())
|
|
155
155
|
return;
|
|
156
|
-
if (isVitest())
|
|
157
|
-
return;
|
|
158
156
|
if (isViteCliCall()) {
|
|
157
|
+
assert(!isVitest());
|
|
159
158
|
assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
|
|
160
159
|
onlyOnce: true
|
|
161
160
|
});
|
|
162
161
|
return;
|
|
163
162
|
}
|
|
163
|
+
if (isVitest()) {
|
|
164
|
+
assertWarning(false, `Unexpected Vitest setup: you seem to be using Vitest together with Vike's Vite plugin but without using Vike's JavaScript API which is unexpected, see ${pc.underline('https://vike.dev/vitest')}`, { onlyOnce: true });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
164
167
|
if (config.server.middlewareMode) {
|
|
165
168
|
assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
|
|
166
169
|
onlyOnce: true
|
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) {
|
|
@@ -207,7 +207,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
207
207
|
// - Vike doesn't resolve path aliases at all.
|
|
208
208
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
209
209
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
210
|
-
assert(!isImportPathNpmPackageOrPathAlias(importPathOriginal));
|
|
211
210
|
importPathTranspiled = importPathResolved;
|
|
212
211
|
}
|
|
213
212
|
else {
|