vike 0.4.236-commit-85d361d → 0.4.236-commit-e752d12
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/createGetGlobalContextClient.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +5 -5
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +13 -12
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +14 -7
- package/dist/cjs/shared/createGlobalContextShared.js +10 -6
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/runtime-client-routing/history.d.ts +2 -4
- package/dist/esm/client/runtime-client-routing/history.js +35 -13
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/shared/createGetGlobalContextClient.js +1 -1
- package/dist/esm/node/runtime/globalContext.js +5 -5
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +13 -12
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +14 -7
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +10 -6
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGl
|
|
|
27
27
|
return globalObject.globalContext;
|
|
28
28
|
}
|
|
29
29
|
// Create
|
|
30
|
-
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, async (globalContext) => {
|
|
30
|
+
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, undefined, async (globalContext) => {
|
|
31
31
|
const globalContextAddendum = {
|
|
32
32
|
/**
|
|
33
33
|
* Whether the environment is client-side or server-side / pre-rendering.
|
|
@@ -374,7 +374,7 @@ async function updateUserFiles() {
|
|
|
374
374
|
async function setGlobalContext(virtualFileExports) {
|
|
375
375
|
debug('setGlobalContext()');
|
|
376
376
|
(0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
|
|
377
|
-
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject,
|
|
377
|
+
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp);
|
|
378
378
|
(0, assertV1Design_js_1.assertV1Design)(
|
|
379
379
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
380
380
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
@@ -384,13 +384,13 @@ async function setGlobalContext(virtualFileExports) {
|
|
|
384
384
|
// Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
|
|
385
385
|
return globalContext;
|
|
386
386
|
}
|
|
387
|
-
async function
|
|
388
|
-
debug('
|
|
387
|
+
async function addGlobalContextTmp(globalContext) {
|
|
388
|
+
debug('addGlobalContextTmp()');
|
|
389
389
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
390
390
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
391
391
|
}
|
|
392
|
-
function
|
|
393
|
-
debug('
|
|
392
|
+
function addGlobalContext(globalContext) {
|
|
393
|
+
debug('addGlobalContext()');
|
|
394
394
|
const { pageRoutes, onBeforeRouteHook } = (0, loadPageRoutes_js_1.loadPageRoutesSync)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
395
395
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
396
396
|
}
|
|
@@ -16,18 +16,9 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
16
16
|
const globalContext = pageContext._globalContext;
|
|
17
17
|
const { _isProduction: isProduction } = globalContext;
|
|
18
18
|
const isDev = !isProduction;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const { _viteDevServer: viteDevServer } = globalContext;
|
|
23
|
-
clientEntriesSrc = clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
24
|
-
assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const { assetsManifest } = globalContext;
|
|
28
|
-
clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
29
|
-
assetUrls = (0, retrieveAssetsProd_js_1.retrieveAssetsProd)(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(pageContext._globalContext.config));
|
|
30
|
-
}
|
|
19
|
+
const { assetUrls, clientEntriesSrc } = isDev
|
|
20
|
+
? await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
|
|
21
|
+
: retrievePageAssetsProd(globalContext.assetsManifest, clientDependencies, clientEntries, resolveIncludeAssetsImportedByServer(globalContext.config));
|
|
31
22
|
let pageAssets = [];
|
|
32
23
|
(0, utils_js_1.unique)([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
|
|
33
24
|
const { mediaType = null, assetType = null } = (0, inferMediaType_js_1.inferMediaType)(src) || {};
|
|
@@ -61,6 +52,16 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
61
52
|
await (0, sortPageAssetsForEarlyHintsHeader_js_1.sortPageAssetsForEarlyHintsHeader)(pageAssets, isProduction);
|
|
62
53
|
return pageAssets;
|
|
63
54
|
}
|
|
55
|
+
async function retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries) {
|
|
56
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
57
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
58
|
+
return { clientEntriesSrc, assetUrls };
|
|
59
|
+
}
|
|
60
|
+
function retrievePageAssetsProd(assetsManifest, clientDependencies, clientEntries, includeAssetsImportedByServer) {
|
|
61
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
62
|
+
const assetUrls = (0, retrieveAssetsProd_js_1.retrieveAssetsProd)(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(includeAssetsImportedByServer));
|
|
63
|
+
return { clientEntriesSrc, assetUrls };
|
|
64
|
+
}
|
|
64
65
|
function resolveClientEntriesProd(clientEntry, assetsManifest) {
|
|
65
66
|
const { manifestEntry } = (0, getManifestEntry_js_1.getManifestEntry)(clientEntry, assetsManifest);
|
|
66
67
|
(0, utils_js_1.assert)(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
|
|
@@ -300,8 +300,8 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
303
|
+
const isSsrEnv = (0, isViteServerBuild_js_1.isViteServerBuild_onlySsrEnv)(config, viteEnv);
|
|
304
|
+
if (isSsrEnv) {
|
|
305
305
|
(0, utils_js_1.assert)(!assetsJsonFilePath);
|
|
306
306
|
const outDirs = (0, getOutDirs_js_1.getOutDirs)(config, viteEnv);
|
|
307
307
|
assetsJsonFilePath = node_path_1.default.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
@@ -315,7 +315,7 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
315
315
|
// - Also in some other server builds such as dist/vercel/ from vike-vercel
|
|
316
316
|
// - Don't replace it in dist/rsc/ from vike-react-rsc since __VITE_ASSETS_MANIFEST__ doesn't exist there
|
|
317
317
|
const noop = await (0, pluginBuildEntry_js_1.set_macro_ASSETS_MANIFEST)(assetsJsonFilePath, bundle, outDir);
|
|
318
|
-
if (
|
|
318
|
+
if (isSsrEnv)
|
|
319
319
|
(0, utils_js_1.assert)(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
|
|
320
320
|
}
|
|
321
321
|
}
|
|
@@ -106,6 +106,7 @@ function getIdHash(id) {
|
|
|
106
106
|
return node_crypto_1.default.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
107
107
|
}
|
|
108
108
|
function getAssetFileName(assetInfo, config) {
|
|
109
|
+
const userRootDir = config.root;
|
|
109
110
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
110
111
|
const dir = assetsDir + '/static';
|
|
111
112
|
let { name } = assetInfo;
|
|
@@ -123,11 +124,11 @@ function getAssetFileName(assetInfo, config) {
|
|
|
123
124
|
// Vite 3
|
|
124
125
|
name?.endsWith('?extractAssets&lang.css')) {
|
|
125
126
|
name = name.split('.').slice(0, -2).join('.');
|
|
126
|
-
name = clean(name);
|
|
127
|
+
name = clean(name, userRootDir);
|
|
127
128
|
return `${dir}/${name}.[hash][extname]`;
|
|
128
129
|
}
|
|
129
130
|
name = name.split('.').slice(0, -1).join('.');
|
|
130
|
-
name = clean(name);
|
|
131
|
+
name = clean(name, userRootDir);
|
|
131
132
|
return `${dir}/${name}.[hash][extname]`;
|
|
132
133
|
}
|
|
133
134
|
function getChunkFileName(_chunkInfo, config) {
|
|
@@ -140,11 +141,12 @@ function getChunkFileName(_chunkInfo, config) {
|
|
|
140
141
|
return name;
|
|
141
142
|
}
|
|
142
143
|
function getEntryFileName(chunkInfo, config, isEntry) {
|
|
144
|
+
const userRootDir = config.root;
|
|
143
145
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
144
146
|
const isForClientSide = !config.build.ssr;
|
|
145
147
|
let { name } = chunkInfo;
|
|
146
148
|
(0, utils_js_1.assertPosixPath)(name);
|
|
147
|
-
name = clean(name, true,
|
|
149
|
+
name = clean(name, userRootDir, true,
|
|
148
150
|
// Not needed for client-side because dist/ filenames contain `.[hash].js`
|
|
149
151
|
!isForClientSide);
|
|
150
152
|
if (isForClientSide) {
|
|
@@ -154,9 +156,14 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
154
156
|
return `${name}.${isEntry ? 'mjs' : 'js'}`;
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
|
-
function removePathSeparators(name) {
|
|
159
|
+
function removePathSeparators(name, userRootDir) {
|
|
158
160
|
(0, utils_js_1.assertPosixPath)(name);
|
|
159
|
-
|
|
161
|
+
if (name.startsWith(userRootDir)) {
|
|
162
|
+
name = name.slice(userRootDir.length);
|
|
163
|
+
if (name.startsWith('/'))
|
|
164
|
+
name = name.slice(1);
|
|
165
|
+
}
|
|
166
|
+
(0, utils_js_1.assert)(!name.startsWith('/'), { name });
|
|
160
167
|
const entryDir = 'entries/';
|
|
161
168
|
const hasEntryDir = name.startsWith(entryDir);
|
|
162
169
|
if (hasEntryDir) {
|
|
@@ -169,14 +176,14 @@ function removePathSeparators(name) {
|
|
|
169
176
|
}
|
|
170
177
|
return name;
|
|
171
178
|
}
|
|
172
|
-
function clean(name, removePathSep, fixGlob) {
|
|
179
|
+
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
173
180
|
name = fixExtractAssetsQuery(name);
|
|
174
181
|
if (fixGlob) {
|
|
175
182
|
name = workaroundGlob(name);
|
|
176
183
|
}
|
|
177
184
|
name = replaceNonLatinCharacters(name);
|
|
178
185
|
if (removePathSep) {
|
|
179
|
-
name = removePathSeparators(name);
|
|
186
|
+
name = removePathSeparators(name, userRootDir);
|
|
180
187
|
}
|
|
181
188
|
name = removeLeadingUnderscoreInFilename(name);
|
|
182
189
|
name = removeUnderscoreDoublets(name);
|
|
@@ -10,25 +10,29 @@ const prepareGlobalContextForPublicUsage_js_1 = require("./prepareGlobalContextF
|
|
|
10
10
|
const getHook_js_1 = require("./hooks/getHook.js");
|
|
11
11
|
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
12
12
|
exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
|
|
13
|
-
async function createGlobalContextShared(virtualFileExports, globalObject,
|
|
13
|
+
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
|
|
14
|
+
// TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
|
|
15
|
+
addGlobalContextTmp) {
|
|
14
16
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
15
17
|
let isNewGlobalContext;
|
|
16
18
|
if (!globalObject.globalContext) {
|
|
19
|
+
// We set globalObject.globalContext early and before any async operations, so that getGlobalContextSync() can be used early.
|
|
20
|
+
// - Required by vike-vercel
|
|
17
21
|
globalObject.globalContext = globalContext;
|
|
18
22
|
isNewGlobalContext = false;
|
|
19
23
|
}
|
|
20
24
|
else {
|
|
21
25
|
isNewGlobalContext = true;
|
|
22
26
|
}
|
|
23
|
-
if (
|
|
27
|
+
if (addGlobalContext &&
|
|
24
28
|
// TODO/next-major-release: remove
|
|
25
29
|
globalContext._pageConfigs.length > 0) {
|
|
26
|
-
const
|
|
27
|
-
(0, utils_js_1.objectAssign)(globalContext,
|
|
30
|
+
const globalContextAdded = addGlobalContext?.(globalContext);
|
|
31
|
+
(0, utils_js_1.objectAssign)(globalContext, globalContextAdded);
|
|
28
32
|
}
|
|
29
33
|
else {
|
|
30
|
-
const
|
|
31
|
-
(0, utils_js_1.objectAssign)(globalContext,
|
|
34
|
+
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
35
|
+
(0, utils_js_1.objectAssign)(globalContext, globalContextAdded);
|
|
32
36
|
}
|
|
33
37
|
const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
34
38
|
let hooksCalled = false;
|
|
@@ -2,8 +2,7 @@ export { pushHistoryState };
|
|
|
2
2
|
export { replaceHistoryStateOriginal };
|
|
3
3
|
export { onPopStateBegin };
|
|
4
4
|
export { saveScrollPosition };
|
|
5
|
-
export {
|
|
6
|
-
export { monkeyPatchHistoryAPI };
|
|
5
|
+
export { initHistory };
|
|
7
6
|
export type { HistoryInfo };
|
|
8
7
|
export type { ScrollPosition };
|
|
9
8
|
type StateEnhanced = {
|
|
@@ -19,7 +18,6 @@ type ScrollPosition = {
|
|
|
19
18
|
declare function saveScrollPosition(): void;
|
|
20
19
|
declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
|
|
21
20
|
declare function replaceHistoryStateOriginal(state: unknown, url: string): void;
|
|
22
|
-
declare function monkeyPatchHistoryAPI(): void;
|
|
23
21
|
type HistoryInfo = {
|
|
24
22
|
url: `/${string}`;
|
|
25
23
|
state: StateEnhanced;
|
|
@@ -29,4 +27,4 @@ declare function onPopStateBegin(): {
|
|
|
29
27
|
previous: HistoryInfo;
|
|
30
28
|
current: HistoryInfo;
|
|
31
29
|
};
|
|
32
|
-
declare function
|
|
30
|
+
declare function initHistory(): void;
|
|
@@ -2,12 +2,15 @@ export { pushHistoryState };
|
|
|
2
2
|
export { replaceHistoryStateOriginal };
|
|
3
3
|
export { onPopStateBegin };
|
|
4
4
|
export { saveScrollPosition };
|
|
5
|
-
export {
|
|
6
|
-
export { monkeyPatchHistoryAPI };
|
|
5
|
+
export { initHistory };
|
|
7
6
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
8
7
|
import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const globalObject = getGlobalObject('history.ts', {
|
|
9
|
+
monkeyPatched: false,
|
|
10
|
+
previous: undefined,
|
|
11
|
+
});
|
|
12
|
+
initHistory(); // we redundantly call initHistory() to ensure it's called early
|
|
13
|
+
globalObject.previous = getHistoryInfo();
|
|
11
14
|
// `window.history.state === null` when:
|
|
12
15
|
// - The very first render
|
|
13
16
|
// - Click on `<a href="#some-hash" />`
|
|
@@ -41,7 +44,7 @@ function enhance(stateNotEnhanced) {
|
|
|
41
44
|
_isVikeEnhanced: true,
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
assertIsVikeEnhanced(stateVikeEnhanced);
|
|
45
48
|
return stateVikeEnhanced;
|
|
46
49
|
}
|
|
47
50
|
function getState() {
|
|
@@ -51,7 +54,7 @@ function getState() {
|
|
|
51
54
|
// - Therefore, we have to monkey patch history.pushState() and history.replaceState()
|
|
52
55
|
// - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
|
|
53
56
|
// - If users stumble upon this assert() then let's make it a assertUsage()
|
|
54
|
-
|
|
57
|
+
assertIsVikeEnhanced(state);
|
|
55
58
|
return state;
|
|
56
59
|
}
|
|
57
60
|
function getStateNotEnhanced() {
|
|
@@ -90,6 +93,7 @@ function pushHistoryState(url, overwriteLastHistoryEntry) {
|
|
|
90
93
|
function replaceHistoryState(state, url) {
|
|
91
94
|
const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
|
|
92
95
|
window.history.replaceState(state, '', url_);
|
|
96
|
+
assertIsVikeEnhanced(getState());
|
|
93
97
|
}
|
|
94
98
|
function replaceHistoryStateOriginal(state, url) {
|
|
95
99
|
// Bypass all monkey patches.
|
|
@@ -100,7 +104,11 @@ function replaceHistoryStateOriginal(state, url) {
|
|
|
100
104
|
// - history.pushState()
|
|
101
105
|
// - history.replaceState()
|
|
102
106
|
function monkeyPatchHistoryAPI() {
|
|
103
|
-
|
|
107
|
+
if (globalObject.monkeyPatched)
|
|
108
|
+
return;
|
|
109
|
+
globalObject.monkeyPatched = true;
|
|
110
|
+
// Ensure Vike's monkey patch is the first.
|
|
111
|
+
assert(window.history.pushState === History.prototype.pushState);
|
|
104
112
|
['pushState', 'replaceState'].forEach((funcName) => {
|
|
105
113
|
const funcOriginal = window.history[funcName].bind(window.history);
|
|
106
114
|
window.history[funcName] = (stateOriginal = {}, ...rest) => {
|
|
@@ -114,11 +122,14 @@ function monkeyPatchHistoryAPI() {
|
|
|
114
122
|
triggeredBy: 'user',
|
|
115
123
|
...stateOriginal,
|
|
116
124
|
};
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
assertIsVikeEnhanced(stateEnhanced);
|
|
126
|
+
funcOriginal(stateEnhanced, ...rest);
|
|
127
|
+
assertIsVikeEnhanced(getState());
|
|
119
128
|
globalObject.previous = getHistoryInfo();
|
|
120
|
-
return ret;
|
|
121
129
|
};
|
|
130
|
+
window.history[funcName]._isVikeMonkeyPatch = true;
|
|
131
|
+
// Ensure assert() above isn't a false positive
|
|
132
|
+
assert(window.history.pushState !== History.prototype.pushState);
|
|
122
133
|
});
|
|
123
134
|
}
|
|
124
135
|
function isVikeEnhanced(state) {
|
|
@@ -136,6 +147,16 @@ function isVikeEnhanced(state) {
|
|
|
136
147
|
}
|
|
137
148
|
return false;
|
|
138
149
|
}
|
|
150
|
+
function assertIsVikeEnhanced(state) {
|
|
151
|
+
if (isVikeEnhanced(state))
|
|
152
|
+
return;
|
|
153
|
+
assert(false, {
|
|
154
|
+
state,
|
|
155
|
+
// TO-DO/eventually: remove _isVikeMonkeyPatch debug info to save KBs
|
|
156
|
+
pushStateIsVikeMonkeyPatch: window.history.pushState._isVikeMonkeyPatch,
|
|
157
|
+
replaceStateIsVikeMonkeyPatch: window.history.replaceState._isVikeMonkeyPatch,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
139
160
|
function getHistoryInfo() {
|
|
140
161
|
return {
|
|
141
162
|
url: getCurrentUrl(),
|
|
@@ -147,11 +168,12 @@ function onPopStateBegin() {
|
|
|
147
168
|
const isHistoryStateEnhanced = window.history.state !== null;
|
|
148
169
|
if (!isHistoryStateEnhanced)
|
|
149
170
|
enhanceHistoryState();
|
|
150
|
-
|
|
171
|
+
assertIsVikeEnhanced(window.history.state);
|
|
151
172
|
const current = getHistoryInfo();
|
|
152
173
|
globalObject.previous = current;
|
|
153
174
|
return { isHistoryStateEnhanced, previous, current };
|
|
154
175
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
176
|
+
function initHistory() {
|
|
177
|
+
monkeyPatchHistoryAPI(); // the earlier we call it the better (Vike can workaround erroneous library monkey patches if Vike is the last one in the monkey patch chain)
|
|
178
|
+
enhanceHistoryState(); // enhance very first window.history.state which is `null`
|
|
157
179
|
}
|
|
@@ -6,7 +6,7 @@ import { initOnLinkClick } from './initOnLinkClick.js';
|
|
|
6
6
|
import { scrollRestoration_init } from './scrollRestoration.js';
|
|
7
7
|
import { autoSaveScrollPosition } from './setScrollPosition.js';
|
|
8
8
|
import { initLinkPrefetchHandlers } from './prefetch.js';
|
|
9
|
-
import {
|
|
9
|
+
import { initHistory } from './history.js';
|
|
10
10
|
async function initClientRouter() {
|
|
11
11
|
// Init navigation history and scroll restoration
|
|
12
12
|
initHistoryAndScroll();
|
|
@@ -29,8 +29,7 @@ async function renderFirstPage() {
|
|
|
29
29
|
}
|
|
30
30
|
function initHistoryAndScroll() {
|
|
31
31
|
scrollRestoration_init();
|
|
32
|
-
|
|
33
|
-
initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
|
|
32
|
+
initHistory(); // we redundantly call initHistory() to ensure it's called early
|
|
34
33
|
autoSaveScrollPosition();
|
|
35
34
|
// Handle back-/forward navigation
|
|
36
35
|
initOnPopState();
|
|
@@ -27,7 +27,7 @@ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGl
|
|
|
27
27
|
return globalObject.globalContext;
|
|
28
28
|
}
|
|
29
29
|
// Create
|
|
30
|
-
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, async (globalContext) => {
|
|
30
|
+
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, undefined, async (globalContext) => {
|
|
31
31
|
const globalContextAddendum = {
|
|
32
32
|
/**
|
|
33
33
|
* Whether the environment is client-side or server-side / pre-rendering.
|
|
@@ -370,7 +370,7 @@ async function updateUserFiles() {
|
|
|
370
370
|
async function setGlobalContext(virtualFileExports) {
|
|
371
371
|
debug('setGlobalContext()');
|
|
372
372
|
assert(!getVikeConfigErrorBuild());
|
|
373
|
-
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject,
|
|
373
|
+
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp);
|
|
374
374
|
assertV1Design(
|
|
375
375
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
376
376
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
@@ -380,13 +380,13 @@ async function setGlobalContext(virtualFileExports) {
|
|
|
380
380
|
// Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
|
|
381
381
|
return globalContext;
|
|
382
382
|
}
|
|
383
|
-
async function
|
|
384
|
-
debug('
|
|
383
|
+
async function addGlobalContextTmp(globalContext) {
|
|
384
|
+
debug('addGlobalContextTmp()');
|
|
385
385
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
386
386
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
387
387
|
}
|
|
388
|
-
function
|
|
389
|
-
debug('
|
|
388
|
+
function addGlobalContext(globalContext) {
|
|
389
|
+
debug('addGlobalContext()');
|
|
390
390
|
const { pageRoutes, onBeforeRouteHook } = loadPageRoutesSync(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
391
391
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
392
392
|
}
|
|
@@ -14,18 +14,9 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
14
14
|
const globalContext = pageContext._globalContext;
|
|
15
15
|
const { _isProduction: isProduction } = globalContext;
|
|
16
16
|
const isDev = !isProduction;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const { _viteDevServer: viteDevServer } = globalContext;
|
|
21
|
-
clientEntriesSrc = clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
22
|
-
assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const { assetsManifest } = globalContext;
|
|
26
|
-
clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
27
|
-
assetUrls = retrieveAssetsProd(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(pageContext._globalContext.config));
|
|
28
|
-
}
|
|
17
|
+
const { assetUrls, clientEntriesSrc } = isDev
|
|
18
|
+
? await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
|
|
19
|
+
: retrievePageAssetsProd(globalContext.assetsManifest, clientDependencies, clientEntries, resolveIncludeAssetsImportedByServer(globalContext.config));
|
|
29
20
|
let pageAssets = [];
|
|
30
21
|
unique([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
|
|
31
22
|
const { mediaType = null, assetType = null } = inferMediaType(src) || {};
|
|
@@ -59,6 +50,16 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
59
50
|
await sortPageAssetsForEarlyHintsHeader(pageAssets, isProduction);
|
|
60
51
|
return pageAssets;
|
|
61
52
|
}
|
|
53
|
+
async function retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries) {
|
|
54
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
55
|
+
const assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
|
|
56
|
+
return { clientEntriesSrc, assetUrls };
|
|
57
|
+
}
|
|
58
|
+
function retrievePageAssetsProd(assetsManifest, clientDependencies, clientEntries, includeAssetsImportedByServer) {
|
|
59
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
60
|
+
const assetUrls = retrieveAssetsProd(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(includeAssetsImportedByServer));
|
|
61
|
+
return { clientEntriesSrc, assetUrls };
|
|
62
|
+
}
|
|
62
63
|
function resolveClientEntriesProd(clientEntry, assetsManifest) {
|
|
63
64
|
const { manifestEntry } = getManifestEntry(clientEntry, assetsManifest);
|
|
64
65
|
assert(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
|
|
@@ -295,8 +295,8 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
297
|
async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
298
|
+
const isSsrEnv = isViteServerBuild_onlySsrEnv(config, viteEnv);
|
|
299
|
+
if (isSsrEnv) {
|
|
300
300
|
assert(!assetsJsonFilePath);
|
|
301
301
|
const outDirs = getOutDirs(config, viteEnv);
|
|
302
302
|
assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
@@ -310,7 +310,7 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
310
310
|
// - Also in some other server builds such as dist/vercel/ from vike-vercel
|
|
311
311
|
// - Don't replace it in dist/rsc/ from vike-react-rsc since __VITE_ASSETS_MANIFEST__ doesn't exist there
|
|
312
312
|
const noop = await set_macro_ASSETS_MANIFEST(assetsJsonFilePath, bundle, outDir);
|
|
313
|
-
if (
|
|
313
|
+
if (isSsrEnv)
|
|
314
314
|
assert(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -101,6 +101,7 @@ function getIdHash(id) {
|
|
|
101
101
|
return crypto.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
102
102
|
}
|
|
103
103
|
function getAssetFileName(assetInfo, config) {
|
|
104
|
+
const userRootDir = config.root;
|
|
104
105
|
const assetsDir = getAssetsDir(config);
|
|
105
106
|
const dir = assetsDir + '/static';
|
|
106
107
|
let { name } = assetInfo;
|
|
@@ -118,11 +119,11 @@ function getAssetFileName(assetInfo, config) {
|
|
|
118
119
|
// Vite 3
|
|
119
120
|
name?.endsWith('?extractAssets&lang.css')) {
|
|
120
121
|
name = name.split('.').slice(0, -2).join('.');
|
|
121
|
-
name = clean(name);
|
|
122
|
+
name = clean(name, userRootDir);
|
|
122
123
|
return `${dir}/${name}.[hash][extname]`;
|
|
123
124
|
}
|
|
124
125
|
name = name.split('.').slice(0, -1).join('.');
|
|
125
|
-
name = clean(name);
|
|
126
|
+
name = clean(name, userRootDir);
|
|
126
127
|
return `${dir}/${name}.[hash][extname]`;
|
|
127
128
|
}
|
|
128
129
|
function getChunkFileName(_chunkInfo, config) {
|
|
@@ -135,11 +136,12 @@ function getChunkFileName(_chunkInfo, config) {
|
|
|
135
136
|
return name;
|
|
136
137
|
}
|
|
137
138
|
function getEntryFileName(chunkInfo, config, isEntry) {
|
|
139
|
+
const userRootDir = config.root;
|
|
138
140
|
const assetsDir = getAssetsDir(config);
|
|
139
141
|
const isForClientSide = !config.build.ssr;
|
|
140
142
|
let { name } = chunkInfo;
|
|
141
143
|
assertPosixPath(name);
|
|
142
|
-
name = clean(name, true,
|
|
144
|
+
name = clean(name, userRootDir, true,
|
|
143
145
|
// Not needed for client-side because dist/ filenames contain `.[hash].js`
|
|
144
146
|
!isForClientSide);
|
|
145
147
|
if (isForClientSide) {
|
|
@@ -149,9 +151,14 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
149
151
|
return `${name}.${isEntry ? 'mjs' : 'js'}`;
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
|
-
function removePathSeparators(name) {
|
|
154
|
+
function removePathSeparators(name, userRootDir) {
|
|
153
155
|
assertPosixPath(name);
|
|
154
|
-
|
|
156
|
+
if (name.startsWith(userRootDir)) {
|
|
157
|
+
name = name.slice(userRootDir.length);
|
|
158
|
+
if (name.startsWith('/'))
|
|
159
|
+
name = name.slice(1);
|
|
160
|
+
}
|
|
161
|
+
assert(!name.startsWith('/'), { name });
|
|
155
162
|
const entryDir = 'entries/';
|
|
156
163
|
const hasEntryDir = name.startsWith(entryDir);
|
|
157
164
|
if (hasEntryDir) {
|
|
@@ -164,14 +171,14 @@ function removePathSeparators(name) {
|
|
|
164
171
|
}
|
|
165
172
|
return name;
|
|
166
173
|
}
|
|
167
|
-
function clean(name, removePathSep, fixGlob) {
|
|
174
|
+
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
168
175
|
name = fixExtractAssetsQuery(name);
|
|
169
176
|
if (fixGlob) {
|
|
170
177
|
name = workaroundGlob(name);
|
|
171
178
|
}
|
|
172
179
|
name = replaceNonLatinCharacters(name);
|
|
173
180
|
if (removePathSep) {
|
|
174
|
-
name = removePathSeparators(name);
|
|
181
|
+
name = removePathSeparators(name, userRootDir);
|
|
175
182
|
}
|
|
176
183
|
name = removeLeadingUnderscoreInFilename(name);
|
|
177
184
|
name = removeUnderscoreDoublets(name);
|
|
@@ -9,10 +9,10 @@ import type { GlobalContextServerInternal } from '../node/runtime/globalContext.
|
|
|
9
9
|
import type { GlobalContextClientInternal } from '../client/runtime-client-routing/globalContext.js';
|
|
10
10
|
import { type Hook } from './hooks/getHook.js';
|
|
11
11
|
declare const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
12
|
-
declare function createGlobalContextShared<
|
|
12
|
+
declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>>(virtualFileExports: unknown, globalObject: {
|
|
13
13
|
globalContext?: Record<string, unknown>;
|
|
14
14
|
onCreateGlobalContextHooks?: Hook[];
|
|
15
|
-
},
|
|
15
|
+
}, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>): Promise<{
|
|
16
16
|
/**
|
|
17
17
|
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
18
18
|
*
|
|
@@ -35,7 +35,7 @@ declare function createGlobalContextShared<GlobalContextAddendum extends Record<
|
|
|
35
35
|
pages: {
|
|
36
36
|
[k: string]: import("./page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEager;
|
|
37
37
|
};
|
|
38
|
-
} &
|
|
38
|
+
} & GlobalContextAdded>;
|
|
39
39
|
type GlobalContextBasePublic = Pick<GlobalContextBase, 'config' | 'pages' | 'isGlobalContext'>;
|
|
40
40
|
type GlobalContextBase = ReturnType<typeof createGlobalContextBase>;
|
|
41
41
|
declare function createGlobalContextBase(virtualFileExports: unknown): {
|
|
@@ -7,25 +7,29 @@ import { execHookGlobal } from './hooks/execHook.js';
|
|
|
7
7
|
import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
|
|
8
8
|
import { getHookFromPageConfigGlobalCumulative } from './hooks/getHook.js';
|
|
9
9
|
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
10
|
-
async function createGlobalContextShared(virtualFileExports, globalObject,
|
|
10
|
+
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
|
|
11
|
+
// TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
|
|
12
|
+
addGlobalContextTmp) {
|
|
11
13
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
12
14
|
let isNewGlobalContext;
|
|
13
15
|
if (!globalObject.globalContext) {
|
|
16
|
+
// We set globalObject.globalContext early and before any async operations, so that getGlobalContextSync() can be used early.
|
|
17
|
+
// - Required by vike-vercel
|
|
14
18
|
globalObject.globalContext = globalContext;
|
|
15
19
|
isNewGlobalContext = false;
|
|
16
20
|
}
|
|
17
21
|
else {
|
|
18
22
|
isNewGlobalContext = true;
|
|
19
23
|
}
|
|
20
|
-
if (
|
|
24
|
+
if (addGlobalContext &&
|
|
21
25
|
// TODO/next-major-release: remove
|
|
22
26
|
globalContext._pageConfigs.length > 0) {
|
|
23
|
-
const
|
|
24
|
-
objectAssign(globalContext,
|
|
27
|
+
const globalContextAdded = addGlobalContext?.(globalContext);
|
|
28
|
+
objectAssign(globalContext, globalContextAdded);
|
|
25
29
|
}
|
|
26
30
|
else {
|
|
27
|
-
const
|
|
28
|
-
objectAssign(globalContext,
|
|
31
|
+
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
32
|
+
objectAssign(globalContext, globalContextAdded);
|
|
29
33
|
}
|
|
30
34
|
const onCreateGlobalContextHooks = getHookFromPageConfigGlobalCumulative(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
31
35
|
let hooksCalled = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.236-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.236-commit-e752d12";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.236-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.236-commit-e752d12';
|