vike 0.4.237-commit-cc7f0f6 → 0.4.237-commit-33e34e7
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 +3 -3
- package/dist/cjs/node/api/context.js +13 -12
- package/dist/cjs/node/api/dev.js +0 -2
- package/dist/cjs/node/api/index.js +0 -2
- package/dist/cjs/node/api/onLoad.js +2 -2
- package/dist/cjs/node/api/prepareViteApiCall.js +2 -2
- package/dist/cjs/node/api/preview.js +1 -2
- package/dist/cjs/node/api/utils.js +1 -0
- package/dist/cjs/node/cli/index.js +2 -2
- package/dist/cjs/node/cli/onLoad.js +2 -2
- package/dist/cjs/node/runtime/globalContext.js +108 -96
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +0 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/{pluginBuildEntry.js → pluginProdBuildEntry.js} +6 -6
- package/dist/cjs/node/vite/plugins/pluginBuild.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +9 -5
- package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +3 -3
- package/dist/cjs/shared/createGlobalContextShared.js +5 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +2 -3
- package/dist/cjs/utils/isNonRunnableDev.js +12 -0
- package/dist/esm/__internal/index.d.ts +1 -1
- package/dist/esm/__internal/index.js +3 -3
- package/dist/esm/node/api/build.d.ts +2 -2
- package/dist/esm/node/api/context.d.ts +10 -10
- package/dist/esm/node/api/context.js +13 -12
- package/dist/esm/node/api/dev.d.ts +2 -2
- package/dist/esm/node/api/dev.js +0 -2
- package/dist/esm/node/api/index.js +0 -2
- package/dist/esm/node/api/onLoad.js +1 -1
- package/dist/esm/node/api/prepareViteApiCall.d.ts +3 -3
- package/dist/esm/node/api/prepareViteApiCall.js +3 -3
- package/dist/esm/node/api/preview.d.ts +2 -2
- package/dist/esm/node/api/preview.js +1 -2
- package/dist/esm/node/api/types.d.ts +4 -4
- package/dist/esm/node/api/utils.d.ts +1 -0
- package/dist/esm/node/api/utils.js +1 -0
- package/dist/esm/node/cli/index.js +1 -1
- package/dist/esm/node/cli/onLoad.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +4 -4
- package/dist/esm/node/runtime/globalContext.js +105 -93
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +2 -2
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/{pluginBuildEntry.d.ts → pluginProdBuildEntry.d.ts} +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/{pluginBuildEntry.js → pluginProdBuildEntry.js} +6 -6
- package/dist/esm/node/vite/plugins/pluginBuild.js +2 -2
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +9 -5
- package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +4 -4
- package/dist/esm/shared/createGlobalContextShared.d.ts +1 -1
- package/dist/esm/shared/createGlobalContextShared.js +5 -7
- package/dist/esm/types/PageConfig.d.ts +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +2 -3
- package/dist/esm/utils/isNonRunnableDev.d.ts +2 -0
- package/dist/esm/utils/isNonRunnableDev.js +10 -0
- package/package.json +1 -1
|
@@ -12,27 +12,21 @@ export { initGlobalContext_getPagesAndRoutes };
|
|
|
12
12
|
export { setGlobalContext_viteDevServer };
|
|
13
13
|
export { setGlobalContext_viteConfig };
|
|
14
14
|
export { setGlobalContext_isPrerendering };
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
15
|
+
export { setGlobalContext_isProductionAccordingToVite };
|
|
16
|
+
export { setGlobalContext_prodBuildEntry }; // production entry
|
|
17
17
|
export { clearGlobalContext };
|
|
18
18
|
export { assertBuildInfo };
|
|
19
19
|
export { updateUserFiles };
|
|
20
20
|
export { vikeConfigErrorRecoverMsg };
|
|
21
|
-
// TODO/now: use isProductionEnvironment() instead of globalObject.isProduction
|
|
22
|
-
// TODO/now: rename:
|
|
23
|
-
// - isProduction => isProductionEnvironment
|
|
24
|
-
// - setIsProduction => setIsProductionEnvironment
|
|
25
|
-
// - setGlobalContext_isProduction => setGlobalContext_isProductionEnvironment
|
|
26
|
-
// - sProductionEnvironment => sDevEnv
|
|
27
21
|
// The core logic revolves around:
|
|
28
22
|
// - virtualFileExportsGlobalEntry is the main requirement
|
|
29
|
-
// - In production: globalObject.
|
|
30
|
-
// -
|
|
31
|
-
// - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls
|
|
23
|
+
// - In production: globalObject.prodBuildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
24
|
+
// - loadProdBuildEntry() sets globalObject.prodBuildEntry and then sets virtualFileExportsGlobalEntry
|
|
25
|
+
// - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_prodBuildEntry()
|
|
32
26
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
33
27
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
34
28
|
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExportsGlobalEntry
|
|
35
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, } from './utils.js';
|
|
29
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDev, } from './utils.js';
|
|
36
30
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
37
31
|
import { virtualFileIdGlobalEntryServer } from '../shared/virtualFileId.js';
|
|
38
32
|
import pc from '@brillout/picocolors';
|
|
@@ -44,6 +38,7 @@ import { prepareGlobalContextForPublicUsage } from '../../shared/prepareGlobalCo
|
|
|
44
38
|
import { logRuntimeError, logRuntimeInfo } from './loggerRuntime.js';
|
|
45
39
|
import { getVikeConfigErrorBuild, setVikeConfigError } from '../shared/getVikeConfigError.js';
|
|
46
40
|
import { hasAlreadyLogged } from './renderPage/isNewError.js';
|
|
41
|
+
import { getVikeApiOperation } from '../api/context.js';
|
|
47
42
|
const debug = createDebugger('vike:globalContext');
|
|
48
43
|
const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalObject());
|
|
49
44
|
// Trick to break down TypeScript circular dependency
|
|
@@ -55,7 +50,7 @@ async function getGlobalContextServerInternal() {
|
|
|
55
50
|
// getGlobalContextServerInternal() should always be called after initGlobalContext()
|
|
56
51
|
assert(globalObject.isInitialized);
|
|
57
52
|
assertGlobalContextIsDefined();
|
|
58
|
-
if (
|
|
53
|
+
if (!isProd())
|
|
59
54
|
await globalObject.waitForUserFilesUpdate;
|
|
60
55
|
const { globalContext } = globalObjectTyped;
|
|
61
56
|
assertIsDefined(globalContext);
|
|
@@ -80,10 +75,9 @@ function assertGlobalContextIsDefined() {
|
|
|
80
75
|
*/
|
|
81
76
|
async function getGlobalContext() {
|
|
82
77
|
debug('getGlobalContext()');
|
|
83
|
-
const
|
|
78
|
+
const isProduction = isProdOptional();
|
|
84
79
|
// This assertion cannot fail for vike-server users (because when using vike-server it's guaranteed that globalObject.isProduction is set before executing any user-land code and any Vike extension code).
|
|
85
|
-
assertUsage(isProduction !==
|
|
86
|
-
assert(typeof globalObject.isProduction === 'boolean');
|
|
80
|
+
assertUsage(isProduction !== null, "The global context isn't set yet, use getGlobalContextAsync() instead.");
|
|
87
81
|
return await getGlobalContextAsync(isProduction);
|
|
88
82
|
}
|
|
89
83
|
/**
|
|
@@ -94,7 +88,7 @@ async function getGlobalContext() {
|
|
|
94
88
|
async function getGlobalContextAsync(isProduction) {
|
|
95
89
|
debug('getGlobalContextAsync()');
|
|
96
90
|
assertUsage(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${pc.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${pc.cyan('true')} or ${pc.cyan('false')}`}`);
|
|
97
|
-
|
|
91
|
+
globalObject.isProductionAccordingToUser = isProduction;
|
|
98
92
|
if (!globalObject.globalContext)
|
|
99
93
|
await initGlobalContext_getGlobalContextAsync();
|
|
100
94
|
if (!isProduction)
|
|
@@ -111,9 +105,7 @@ function getGlobalContextSync() {
|
|
|
111
105
|
debug('getGlobalContextSync()');
|
|
112
106
|
const { globalContext } = globalObjectTyped;
|
|
113
107
|
assertUsage(globalContext, getGlobalContextSyncErrMsg);
|
|
114
|
-
|
|
115
|
-
assert(typeof isProd === 'boolean');
|
|
116
|
-
assertWarning(isProd,
|
|
108
|
+
assertWarning(isProd(),
|
|
117
109
|
// - We discourage users from using it in development because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
|
|
118
110
|
// - I don't see any issues with getGlobalContextSync() in production.
|
|
119
111
|
// - getGlobalContextSync() is used in production by vike-vercel
|
|
@@ -129,7 +121,6 @@ function getGlobalContextForPublicUsage() {
|
|
|
129
121
|
}
|
|
130
122
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
131
123
|
debug('setGlobalContext_viteDevServer()');
|
|
132
|
-
setIsProduction(false);
|
|
133
124
|
// We cannot cache globalObject.viteDevServer because it's fully replaced when the user modifies vite.config.js => Vite's dev server is fully reloaded and a new viteDevServer replaces the previous one.
|
|
134
125
|
if (!globalObject.viteDevServer) {
|
|
135
126
|
assertIsNotInitializedYet();
|
|
@@ -157,17 +148,9 @@ function assertIsNotInitializedYet() {
|
|
|
157
148
|
}
|
|
158
149
|
function setGlobalContext_isPrerendering() {
|
|
159
150
|
globalObject.isPrerendering = true;
|
|
160
|
-
setIsProduction(true);
|
|
161
151
|
}
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
debug('setGlobalContext_isProduction()', { isProduction, tolerateContradiction });
|
|
165
|
-
if (globalObject.isProduction === undefined) {
|
|
166
|
-
setIsProduction(isProduction);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
assert(globalObject.isProduction === isProduction || tolerateContradiction);
|
|
170
|
-
}
|
|
152
|
+
function setGlobalContext_isProductionAccordingToVite(isProductionAccordingToVite) {
|
|
153
|
+
globalObject.isProductionAccordingToVite = isProductionAccordingToVite;
|
|
171
154
|
}
|
|
172
155
|
function getViteDevServer() {
|
|
173
156
|
return globalObject.viteDevServer ?? null;
|
|
@@ -177,15 +160,13 @@ function getViteConfig() {
|
|
|
177
160
|
}
|
|
178
161
|
async function initGlobalContext_renderPage() {
|
|
179
162
|
debug('initGlobalContext_renderPage()');
|
|
180
|
-
|
|
181
|
-
if (globalObject.isProduction === undefined)
|
|
182
|
-
setIsProduction(true);
|
|
163
|
+
globalObject.isAfterFirstRenderPageCall = true;
|
|
183
164
|
await initGlobalContext();
|
|
184
165
|
}
|
|
185
166
|
async function initGlobalContext_runPrerender() {
|
|
186
167
|
debug('initGlobalContext_runPrerender()');
|
|
187
168
|
assert(globalObject.isPrerendering === true);
|
|
188
|
-
assert(
|
|
169
|
+
assert(isProd());
|
|
189
170
|
if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
|
|
190
171
|
return;
|
|
191
172
|
globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
|
|
@@ -203,12 +184,11 @@ async function initGlobalContext_getGlobalContextAsync() {
|
|
|
203
184
|
}
|
|
204
185
|
async function initGlobalContext_getPagesAndRoutes() {
|
|
205
186
|
debug('initGlobalContext_getPagesAndRoutes()');
|
|
206
|
-
|
|
187
|
+
globalObject.isProductionAccordingToPhotonVercel = true;
|
|
207
188
|
await initGlobalContext();
|
|
208
189
|
}
|
|
209
190
|
async function initGlobalContext() {
|
|
210
|
-
const
|
|
211
|
-
assert(typeof isProduction === 'boolean');
|
|
191
|
+
const isProduction = isProd();
|
|
212
192
|
if (!isProduction) {
|
|
213
193
|
if (isProcessSharedWithVite()) {
|
|
214
194
|
await globalObject.viteDevServerPromise;
|
|
@@ -221,18 +201,11 @@ async function initGlobalContext() {
|
|
|
221
201
|
await globalObject.waitForUserFilesUpdate;
|
|
222
202
|
}
|
|
223
203
|
else {
|
|
224
|
-
await
|
|
204
|
+
await loadProdBuildEntry(globalObject.viteConfigRuntime?.build.outDir);
|
|
225
205
|
}
|
|
226
206
|
assertGlobalContextIsDefined();
|
|
227
207
|
globalObject.isInitialized = true;
|
|
228
208
|
}
|
|
229
|
-
function setIsProduction(isProduction) {
|
|
230
|
-
debug('setIsProduction', isProduction);
|
|
231
|
-
assert(typeof isProduction === 'boolean');
|
|
232
|
-
if (globalObject.isProduction !== undefined)
|
|
233
|
-
assert(globalObject.isProduction === isProduction);
|
|
234
|
-
globalObject.isProduction = isProduction;
|
|
235
|
-
}
|
|
236
209
|
function assertViteManifest(manifest) {
|
|
237
210
|
assert(isPlainObject(manifest));
|
|
238
211
|
/* We should include these assertions but we don't as a workaround for PWA manifests: https://github.com/vikejs/vike/issues/769
|
|
@@ -246,57 +219,56 @@ function assertViteManifest(manifest) {
|
|
|
246
219
|
})
|
|
247
220
|
*/
|
|
248
221
|
}
|
|
249
|
-
async function
|
|
250
|
-
debug('
|
|
222
|
+
async function loadProdBuildEntry(outDir) {
|
|
223
|
+
debug('loadProdBuildEntry()');
|
|
251
224
|
if (globalObject.globalContext) {
|
|
252
|
-
debug('
|
|
225
|
+
debug('loadProdBuildEntry() - already done');
|
|
253
226
|
return;
|
|
254
227
|
}
|
|
255
|
-
if (!globalObject.
|
|
228
|
+
if (!globalObject.prodBuildEntry) {
|
|
256
229
|
debug('importServerProductionEntry()');
|
|
257
|
-
// importServerProductionEntry() loads dist/server/entry.mjs which calls
|
|
230
|
+
// importServerProductionEntry() loads dist/server/entry.mjs which calls setGlobalContext_prodBuildEntry()
|
|
258
231
|
await importServerProductionEntry({ outDir });
|
|
259
|
-
if (!globalObject.
|
|
260
|
-
debug('globalObject.
|
|
232
|
+
if (!globalObject.prodBuildEntry) {
|
|
233
|
+
debug('globalObject.prodBuildEntryPrevious');
|
|
261
234
|
// Needed, for example, when calling the API prerender() then preview() because both trigger a importServerProductionEntry() call but only the first only is applied because of the import() cache. (A proper implementation would be to clear the import() cache, but it probably isn't possible on platforms such as Cloudflare Workers.)
|
|
262
|
-
globalObject.
|
|
235
|
+
globalObject.prodBuildEntry = globalObject.prodBuildEntryPrevious;
|
|
263
236
|
}
|
|
264
|
-
assert(globalObject.
|
|
265
|
-
// If using `inject` then dist/server/index.js imports dist/server/entry.js and
|
|
237
|
+
assert(globalObject.prodBuildEntry);
|
|
238
|
+
// If using `inject` then dist/server/index.js imports dist/server/entry.js and loadProdBuildEntry() isn't needed.
|
|
266
239
|
// If dist/server/entry.js isn't imported then this means the user is running the original server entry `$ ts-node server/index.ts`.
|
|
267
240
|
assertWarning(
|
|
268
241
|
// vike-server => `inject === true`
|
|
269
242
|
// vike-node => `inject === [ 'index' ]` => we don't show the warning to vike-node users (I don't remember why).
|
|
270
243
|
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true || globalObject.isPrerendering, `Run the built server entry (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
271
244
|
}
|
|
272
|
-
const {
|
|
273
|
-
|
|
274
|
-
globalObject.assetsManifest =
|
|
275
|
-
globalObject.buildInfo =
|
|
276
|
-
await createGlobalContext(
|
|
245
|
+
const { prodBuildEntry } = globalObject;
|
|
246
|
+
assertProdBuildEntry(prodBuildEntry);
|
|
247
|
+
globalObject.assetsManifest = prodBuildEntry.assetsManifest;
|
|
248
|
+
globalObject.buildInfo = prodBuildEntry.buildInfo;
|
|
249
|
+
await createGlobalContext(prodBuildEntry.virtualFileExportsGlobalEntry);
|
|
277
250
|
}
|
|
278
251
|
// This is the production entry, see:
|
|
279
|
-
// https://github.com/vikejs/vike/blob/
|
|
280
|
-
async function
|
|
281
|
-
debug('
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
globalObject.
|
|
285
|
-
globalObject.
|
|
286
|
-
|
|
287
|
-
await loadBuildEntry();
|
|
252
|
+
// https://github.com/vikejs/vike/blob/8c350e8105a626469e87594d983090919e82099b/packages/vike/node/vite/plugins/pluginBuild/pluginProdBuildEntry.ts#L47
|
|
253
|
+
async function setGlobalContext_prodBuildEntry(prodBuildEntry) {
|
|
254
|
+
debug('setGlobalContext_prodBuildEntry()');
|
|
255
|
+
assertProdBuildEntry(prodBuildEntry);
|
|
256
|
+
globalObject.prodBuildEntry = prodBuildEntry;
|
|
257
|
+
globalObject.prodBuildEntryPrevious = prodBuildEntry;
|
|
258
|
+
assert(globalObject.prodBuildEntry); // ensure no infinite loop
|
|
259
|
+
await loadProdBuildEntry();
|
|
288
260
|
assertGlobalContextIsDefined();
|
|
289
|
-
debug('
|
|
290
|
-
}
|
|
291
|
-
function
|
|
292
|
-
assert(isObject(
|
|
293
|
-
assert(hasProp(
|
|
294
|
-
const { virtualFileExportsGlobalEntry } =
|
|
295
|
-
assert(hasProp(
|
|
296
|
-
const { assetsManifest } =
|
|
261
|
+
debug('setGlobalContext_prodBuildEntry() - done');
|
|
262
|
+
}
|
|
263
|
+
function assertProdBuildEntry(prodBuildEntry) {
|
|
264
|
+
assert(isObject(prodBuildEntry));
|
|
265
|
+
assert(hasProp(prodBuildEntry, 'virtualFileExportsGlobalEntry', 'object'));
|
|
266
|
+
const { virtualFileExportsGlobalEntry } = prodBuildEntry;
|
|
267
|
+
assert(hasProp(prodBuildEntry, 'assetsManifest', 'object'));
|
|
268
|
+
const { assetsManifest } = prodBuildEntry;
|
|
297
269
|
assertViteManifest(assetsManifest);
|
|
298
|
-
assert(hasProp(
|
|
299
|
-
const { buildInfo } =
|
|
270
|
+
assert(hasProp(prodBuildEntry, 'buildInfo', 'object'));
|
|
271
|
+
const { buildInfo } = prodBuildEntry;
|
|
300
272
|
assertBuildInfo(buildInfo);
|
|
301
273
|
checkType({ virtualFileExportsGlobalEntry, assetsManifest, buildInfo });
|
|
302
274
|
}
|
|
@@ -319,7 +291,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
319
291
|
}
|
|
320
292
|
async function updateUserFiles() {
|
|
321
293
|
debug('updateUserFiles()');
|
|
322
|
-
assert(!
|
|
294
|
+
assert(!isProd());
|
|
323
295
|
const { promise, resolve } = genPromise();
|
|
324
296
|
globalObject.waitForUserFilesUpdate = promise;
|
|
325
297
|
globalObject.waitForUserFilesUpdateResolve ?? (globalObject.waitForUserFilesUpdateResolve = []);
|
|
@@ -422,12 +394,12 @@ async function createGlobalContext(virtualFileExportsGlobalEntry) {
|
|
|
422
394
|
// - Required by vike-vercel
|
|
423
395
|
assert(globalObject.globalContext);
|
|
424
396
|
const globalContext = await globalContextPromise;
|
|
397
|
+
debug('createGlobalContext() - done [async]');
|
|
425
398
|
assertV1Design(
|
|
426
399
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
427
400
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
428
401
|
assertGlobalContextIsDefined();
|
|
429
402
|
onSetupRuntime();
|
|
430
|
-
debug('createGlobalContext() - done [async]');
|
|
431
403
|
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
432
404
|
return globalContext;
|
|
433
405
|
}
|
|
@@ -447,8 +419,8 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
447
419
|
_pageRoutes: pageRoutes,
|
|
448
420
|
_onBeforeRouteHook: onBeforeRouteHook,
|
|
449
421
|
};
|
|
450
|
-
const { viteDevServer, viteConfig, isPrerendering
|
|
451
|
-
|
|
422
|
+
const { viteDevServer, viteConfig, isPrerendering } = globalObject;
|
|
423
|
+
const isProduction = isProd();
|
|
452
424
|
if (!isProduction) {
|
|
453
425
|
assert(globalContext); // main common requirement
|
|
454
426
|
assert(!isPrerendering);
|
|
@@ -462,7 +434,7 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
462
434
|
};
|
|
463
435
|
}
|
|
464
436
|
else {
|
|
465
|
-
assert(globalObject.
|
|
437
|
+
assert(globalObject.prodBuildEntry);
|
|
466
438
|
assert(globalContext); // main common requiement
|
|
467
439
|
const { buildInfo, assetsManifest } = globalObject;
|
|
468
440
|
assert(buildInfo);
|
|
@@ -500,7 +472,7 @@ async function addGlobalContextAsync(globalContext) {
|
|
|
500
472
|
}
|
|
501
473
|
else {
|
|
502
474
|
assert(!isProcessSharedWithVite()); // process shared with Vite => globalObject.viteConfigRuntime should be set
|
|
503
|
-
assert(!
|
|
475
|
+
assert(!isProd()); // production => globalObject.buildInfo.viteConfigRuntime should be set
|
|
504
476
|
assert(isNonRunnableDev());
|
|
505
477
|
const rpc = getViteRPC();
|
|
506
478
|
viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
|
|
@@ -514,13 +486,12 @@ async function addGlobalContextAsync(globalContext) {
|
|
|
514
486
|
}
|
|
515
487
|
function clearGlobalContext() {
|
|
516
488
|
debug('clearGlobalContext()');
|
|
517
|
-
objectReplace(globalObject, getInitialGlobalObject(), ['
|
|
489
|
+
objectReplace(globalObject, getInitialGlobalObject(), ['prodBuildEntryPrevious']);
|
|
518
490
|
}
|
|
519
491
|
function getInitialGlobalObject() {
|
|
520
492
|
debug('getInitialGlobalObject()');
|
|
521
493
|
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
|
|
522
494
|
return {
|
|
523
|
-
isProduction: isNonRunnableDev() ? false : undefined,
|
|
524
495
|
viteDevServerPromise,
|
|
525
496
|
viteDevServerPromiseResolve,
|
|
526
497
|
};
|
|
@@ -547,10 +518,51 @@ function isRunnable(viteDevServer) {
|
|
|
547
518
|
assert(!isNonRunnableDev());
|
|
548
519
|
return yes;
|
|
549
520
|
}
|
|
550
|
-
function
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
521
|
+
function isProd() {
|
|
522
|
+
const isProduction = isProdOptional();
|
|
523
|
+
if (isProduction === null) {
|
|
524
|
+
if (globalObject.isAfterFirstRenderPageCall) {
|
|
525
|
+
// When using a production server without vike-server, there isn't any reliable signal we can use to determine early whether the environment is production or development. If renderPage() was called then some non-negligible amount of time passed — it's likely that, in dev, one of the Vite hooks should have already sent a signal we can use to determine prod/dev.
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
assert(false);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return isProduction;
|
|
533
|
+
}
|
|
534
|
+
function isProdOptional() {
|
|
535
|
+
const vikeApiOperation = getVikeApiOperation()?.operation ?? null;
|
|
536
|
+
const yes =
|
|
537
|
+
// setGlobalContext_prodBuildEntry() was called
|
|
538
|
+
!!globalObject.prodBuildEntry ||
|
|
539
|
+
globalObject.isPrerendering === true ||
|
|
540
|
+
// Vike CLI & Vike API
|
|
541
|
+
(!!vikeApiOperation && vikeApiOperation !== 'dev') ||
|
|
542
|
+
// Vite command
|
|
543
|
+
globalObject.isProductionAccordingToVite === true ||
|
|
544
|
+
// getGlobalContextAsync(isProduction)
|
|
545
|
+
globalObject.isProductionAccordingToUser === true ||
|
|
546
|
+
// vite-plugin-vercel
|
|
547
|
+
globalObject.isProductionAccordingToPhotonVercel === true;
|
|
554
548
|
assert(typeof yes === 'boolean');
|
|
555
|
-
|
|
549
|
+
const no = !!globalObject.viteDevServer ||
|
|
550
|
+
// Vike CLI & Vike API
|
|
551
|
+
vikeApiOperation === 'dev' ||
|
|
552
|
+
// Vite command
|
|
553
|
+
globalObject.isProductionAccordingToVite === false ||
|
|
554
|
+
// getGlobalContextAsync(isProduction)
|
|
555
|
+
globalObject.isProductionAccordingToUser === false ||
|
|
556
|
+
// @cloudflare/vite-plugin
|
|
557
|
+
isNonRunnableDev() === true;
|
|
558
|
+
assert(typeof no === 'boolean');
|
|
559
|
+
if (yes) {
|
|
560
|
+
assert(no === false);
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
if (no) {
|
|
564
|
+
assert(yes === false);
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
return null;
|
|
556
568
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { createDevMiddleware };
|
|
2
2
|
import type { ResolvedConfig, Connect, ViteDevServer } from 'vite';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ApiOptions } from '../api/types.js';
|
|
4
4
|
declare function createDevMiddleware(options?: {
|
|
5
5
|
root?: string;
|
|
6
|
-
} &
|
|
6
|
+
} & ApiOptions): Promise<{
|
|
7
7
|
devMiddleware: Connect.Server;
|
|
8
8
|
viteServer: ViteDevServer;
|
|
9
9
|
viteConfig: ResolvedConfig;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
export { createDevMiddleware };
|
|
2
2
|
import { createServer } from 'vite';
|
|
3
3
|
import { prepareViteApiCall } from '../api/prepareViteApiCall.js';
|
|
4
|
-
import { setGlobalContext_isProduction } from '../runtime/globalContext.js';
|
|
5
4
|
/*
|
|
6
5
|
* Create server middleware for development with HMR and lazy-transpiling.
|
|
7
6
|
*
|
|
8
7
|
* https://vike.dev/createDevMiddleware
|
|
9
8
|
*/
|
|
10
9
|
async function createDevMiddleware(options = {}) {
|
|
11
|
-
setGlobalContext_isProduction(false, true);
|
|
12
10
|
const optionsMod = {
|
|
13
11
|
...options,
|
|
14
12
|
viteConfig: {
|
|
@@ -14,7 +14,7 @@ import pc from '@brillout/picocolors';
|
|
|
14
14
|
import { isV1Design } from '../../shared/resolveVikeConfigInternal.js';
|
|
15
15
|
import { getOutDirs } from '../../shared/getOutDirs.js';
|
|
16
16
|
import { isViteServerSide_onlySsrEnv, isViteServerSide } from '../../shared/isViteServerSide.js';
|
|
17
|
-
import { set_macro_ASSETS_MANIFEST } from './
|
|
17
|
+
import { set_macro_ASSETS_MANIFEST } from './pluginProdBuildEntry.js';
|
|
18
18
|
import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
|
|
19
19
|
const globalObject = getGlobalObject('build/handleAssetsManifest.ts', {
|
|
20
20
|
assetsJsonFilePath: undefined,
|
package/dist/esm/node/vite/plugins/pluginBuild/{pluginBuildEntry.d.ts → pluginProdBuildEntry.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { pluginProdBuildEntry };
|
|
2
2
|
export { set_macro_ASSETS_MANIFEST };
|
|
3
3
|
import type { Plugin, Rollup } from 'vite';
|
|
4
4
|
type Bundle = Rollup.OutputBundle;
|
|
5
|
-
declare function
|
|
5
|
+
declare function pluginProdBuildEntry(): Plugin[];
|
|
6
6
|
declare function set_macro_ASSETS_MANIFEST(assetsJsonFilePath: string | undefined, bundle: Bundle, outDir: string): Promise<boolean>;
|
package/dist/esm/node/vite/plugins/pluginBuild/{pluginBuildEntry.js → pluginProdBuildEntry.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { pluginProdBuildEntry };
|
|
2
2
|
export { set_macro_ASSETS_MANIFEST };
|
|
3
3
|
import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
4
|
import { virtualFileIdGlobalEntryServer } from '../../../shared/virtualFileId.js';
|
|
@@ -10,11 +10,11 @@ import { assertBuildInfo } from '../../../runtime/globalContext.js';
|
|
|
10
10
|
import { getOutDirs } from '../../shared/getOutDirs.js';
|
|
11
11
|
import { getViteConfigRuntime } from '../../shared/getViteConfigRuntime.js';
|
|
12
12
|
const ASSETS_MANIFEST = '__VITE_ASSETS_MANIFEST__';
|
|
13
|
-
function
|
|
13
|
+
function pluginProdBuildEntry() {
|
|
14
14
|
let config;
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
|
-
name: 'vike:build:
|
|
17
|
+
name: 'vike:build:pluginProdBuildEntry',
|
|
18
18
|
apply: 'build',
|
|
19
19
|
enforce: 'post',
|
|
20
20
|
async configResolved(config_) {
|
|
@@ -39,14 +39,14 @@ function getServerProductionEntryCode(config) {
|
|
|
39
39
|
assertBuildInfo(buildInfo);
|
|
40
40
|
// After the old design is removed, let's maybe simplify and move everything into a single virtual module
|
|
41
41
|
const importerCode = [
|
|
42
|
-
` import {
|
|
42
|
+
` import { setGlobalContext_prodBuildEntry } from '${importPath}';`,
|
|
43
43
|
` import * as virtualFileExportsGlobalEntry from '${virtualFileIdGlobalEntryServer}';`,
|
|
44
44
|
` {`,
|
|
45
|
-
// Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to
|
|
45
|
+
// Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to setGlobalContext_prodBuildEntry()
|
|
46
46
|
// - This workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
|
|
47
47
|
` const assetsManifest = ${ASSETS_MANIFEST};`,
|
|
48
48
|
` const buildInfo = ${JSON.stringify(buildInfo, null, 2)};`,
|
|
49
|
-
'
|
|
49
|
+
' setGlobalContext_prodBuildEntry({',
|
|
50
50
|
` virtualFileExportsGlobalEntry,`,
|
|
51
51
|
` assetsManifest,`,
|
|
52
52
|
` buildInfo,`,
|
|
@@ -3,14 +3,14 @@ import { pluginBuildApp } from './pluginBuild/pluginBuildApp.js';
|
|
|
3
3
|
import { pluginDistPackageJsonFile } from './pluginBuild/pluginDistPackageJsonFile.js';
|
|
4
4
|
import { pluginSuppressRollupWarning } from './pluginBuild/pluginSuppressRollupWarning.js';
|
|
5
5
|
import { pluginDistFileNames } from './pluginBuild/pluginDistFileNames.js';
|
|
6
|
-
import {
|
|
6
|
+
import { pluginProdBuildEntry } from './pluginBuild/pluginProdBuildEntry.js';
|
|
7
7
|
import { pluginBuildConfig } from './pluginBuild/pluginBuildConfig.js';
|
|
8
8
|
import { pluginModuleBanner } from './pluginBuild/pluginModuleBanner.js';
|
|
9
9
|
function pluginBuild() {
|
|
10
10
|
return [
|
|
11
11
|
...pluginBuildConfig(),
|
|
12
12
|
...pluginBuildApp(),
|
|
13
|
-
...
|
|
13
|
+
...pluginProdBuildEntry(),
|
|
14
14
|
pluginDistPackageJsonFile(),
|
|
15
15
|
pluginSuppressRollupWarning(),
|
|
16
16
|
pluginDistFileNames(),
|
|
@@ -18,7 +18,8 @@ function getViteRpcFunctions(viteDevServer) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
function pluginNonRunnableDev() {
|
|
21
|
-
const
|
|
21
|
+
const distFileIsNonRunnableDev = requireResolveDistFile('dist/esm/utils/isNonRunnableDev.js');
|
|
22
|
+
const distFileGlobalContext = requireResolveDistFile('dist/esm/node/runtime/globalContext.js');
|
|
22
23
|
let config;
|
|
23
24
|
return {
|
|
24
25
|
name: 'vike:pluginNonRunnableDev',
|
|
@@ -31,14 +32,17 @@ function pluginNonRunnableDev() {
|
|
|
31
32
|
transform(code, id) {
|
|
32
33
|
if (!config._isDev)
|
|
33
34
|
return;
|
|
34
|
-
if (id !==
|
|
35
|
+
if (id !== distFileIsNonRunnableDev && id !== distFileGlobalContext)
|
|
36
|
+
return;
|
|
37
|
+
if (isRunnableDevEnvironment(this.environment))
|
|
35
38
|
return;
|
|
36
|
-
const isNonRunnableDev = !isRunnableDevEnvironment(this.environment);
|
|
37
39
|
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
38
|
-
if (
|
|
40
|
+
if (id === distFileIsNonRunnableDev) {
|
|
41
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
|
|
42
|
+
}
|
|
43
|
+
if (id === distFileGlobalContext) {
|
|
39
44
|
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
40
45
|
}
|
|
41
|
-
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(isNonRunnableDev));
|
|
42
46
|
return getMagicStringResult();
|
|
43
47
|
},
|
|
44
48
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { pluginSetGlobalContext };
|
|
2
|
-
import { setGlobalContext_viteDevServer, setGlobalContext_viteConfig,
|
|
2
|
+
import { setGlobalContext_viteDevServer, setGlobalContext_viteConfig, setGlobalContext_isProductionAccordingToVite, } from '../../runtime/globalContext.js';
|
|
3
3
|
import { isDevCheck, markSetup_isViteDev, markSetup_viteDevServer, markSetup_vitePreviewServer } from '../utils.js';
|
|
4
4
|
import { reloadVikeConfig } from '../shared/resolveVikeConfigInternal.js';
|
|
5
5
|
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
@@ -27,7 +27,7 @@ function pluginSetGlobalContext() {
|
|
|
27
27
|
order: 'pre',
|
|
28
28
|
handler(_, env) {
|
|
29
29
|
const isViteDev = isDevCheck(env);
|
|
30
|
-
|
|
30
|
+
setGlobalContext_isProductionAccordingToVite(!isViteDev);
|
|
31
31
|
markSetup_isViteDev(isViteDev);
|
|
32
32
|
},
|
|
33
33
|
},
|
|
@@ -26,7 +26,7 @@ import { resolveVikeConfigPublicGlobal, resolveVikeConfigPublicPageEagerLoaded,
|
|
|
26
26
|
import { getConfigValuesBase, isJsonValue } from '../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
27
27
|
import { getPlusFilesAll, } from './resolveVikeConfigInternal/getPlusFilesAll.js';
|
|
28
28
|
import { getEnvVarObject } from './getEnvVarObject.js';
|
|
29
|
-
import {
|
|
29
|
+
import { getVikeApiOperation } from '../../api/context.js';
|
|
30
30
|
import { getCliOptions } from '../../cli/context.js';
|
|
31
31
|
import { resolvePrerenderConfigGlobal } from '../../prerender/resolvePrerenderConfig.js';
|
|
32
32
|
import { getProxyForPublicUsage } from '../../../shared/getProxyForPublicUsage.js';
|
|
@@ -416,9 +416,9 @@ function temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, use
|
|
|
416
416
|
}
|
|
417
417
|
function setCliAndApiOptions(pageConfigGlobal, configDefinitionsResolved) {
|
|
418
418
|
// Vike API — passed options [lowest precedence]
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
addSources(
|
|
419
|
+
const vikeApiOperation = getVikeApiOperation();
|
|
420
|
+
if (vikeApiOperation?.options.vikeConfig) {
|
|
421
|
+
addSources(vikeApiOperation.options.vikeConfig, { definedBy: 'api', operation: vikeApiOperation.operation }, false);
|
|
422
422
|
}
|
|
423
423
|
const { configFromCliOptions, configFromEnvVar } = getVikeConfigFromCliOrEnv();
|
|
424
424
|
// Vike CLI options
|
|
@@ -12,7 +12,7 @@ declare const getGlobalContextSyncErrMsg = "The global context isn't set yet, ca
|
|
|
12
12
|
declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>, GlobalContextAddedAsync extends Record<string, any>>(virtualFileExportsGlobalEntry: unknown, globalObject: {
|
|
13
13
|
globalContext?: Record<string, unknown>;
|
|
14
14
|
onCreateGlobalContextHooks?: Hook[];
|
|
15
|
-
|
|
15
|
+
previousCreateGlobalContextPromise?: Promise<void>;
|
|
16
16
|
}, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>, addGlobalContextAsync?: (globalContext: GlobalContextBase) => Promise<GlobalContextAddedAsync>): Promise<{
|
|
17
17
|
/**
|
|
18
18
|
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
@@ -8,12 +8,10 @@ import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPub
|
|
|
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
10
|
// TO-DO/eventually use flat globalContext — like flat pageContext
|
|
11
|
-
async function createGlobalContextShared(virtualFileExportsGlobalEntry,
|
|
12
|
-
// TODO/now rename previousCallPromise to previousCreateGlobalContextPromise
|
|
13
|
-
globalObject, addGlobalContext,
|
|
11
|
+
async function createGlobalContextShared(virtualFileExportsGlobalEntry, globalObject, addGlobalContext,
|
|
14
12
|
// 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
13
|
addGlobalContextTmp, addGlobalContextAsync) {
|
|
16
|
-
const {
|
|
14
|
+
const { previousCreateGlobalContextPromise } = globalObject;
|
|
17
15
|
const { promise, resolve } = genPromise({
|
|
18
16
|
// Avoid this Cloudflare Worker error:
|
|
19
17
|
// ```console
|
|
@@ -21,10 +19,10 @@ addGlobalContextTmp, addGlobalContextAsync) {
|
|
|
21
19
|
// ```
|
|
22
20
|
timeout: null,
|
|
23
21
|
});
|
|
24
|
-
globalObject.
|
|
25
|
-
if (
|
|
22
|
+
globalObject.previousCreateGlobalContextPromise = promise;
|
|
23
|
+
if (previousCreateGlobalContextPromise) {
|
|
26
24
|
assert(globalObject.globalContext);
|
|
27
|
-
await
|
|
25
|
+
await previousCreateGlobalContextPromise;
|
|
28
26
|
}
|
|
29
27
|
const globalContext = createGlobalContextBase(virtualFileExportsGlobalEntry);
|
|
30
28
|
let isNewGlobalContext;
|
|
@@ -26,7 +26,7 @@ import type { LocationId } from '../node/vite/shared/resolveVikeConfigInternal/f
|
|
|
26
26
|
import type { FilePath } from './FilePath.js';
|
|
27
27
|
import type { ConfigDefinitionsInternal } from '../node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
|
|
28
28
|
import type { PlusFile } from '../node/vite/shared/resolveVikeConfigInternal/getPlusFilesAll.js';
|
|
29
|
-
import type {
|
|
29
|
+
import type { ApiOperation } from '../node/api/types.js';
|
|
30
30
|
type PageConfigCommon = {
|
|
31
31
|
pageId: string;
|
|
32
32
|
} & PageConfigRoute;
|
|
@@ -144,7 +144,7 @@ type DefinedBy = {
|
|
|
144
144
|
definedBy: 'cli' | 'env';
|
|
145
145
|
} | {
|
|
146
146
|
definedBy: 'api';
|
|
147
|
-
operation:
|
|
147
|
+
operation: ApiOperation;
|
|
148
148
|
};
|
|
149
149
|
type DefinedAtFile = {
|
|
150
150
|
filePathToShowToUser: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.237-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.237-commit-33e34e7";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.237-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.237-commit-33e34e7';
|