vike 0.4.236-commit-85d361d → 0.4.236-commit-64431e7
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 +2 -2
- package/dist/cjs/node/runtime/globalContext.js +83 -21
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -12
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +2 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginViteRPC.js +42 -0
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +14 -6
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +3 -0
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
- package/dist/esm/node/runtime/globalContext.d.ts +32 -52
- package/dist/esm/node/runtime/globalContext.js +84 -22
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +10 -33
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -13
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +20 -66
- package/dist/esm/node/runtime/renderPage.d.ts +10 -33
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/node/vite/index.js +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +2 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/esm/node/vite/plugins/pluginViteRPC.d.ts +25 -0
- package/dist/esm/node/vite/plugins/pluginViteRPC.js +40 -0
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +14 -6
- 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 +3 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/package.json +10 -1
|
@@ -27,12 +27,12 @@ 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.
|
|
34
34
|
*
|
|
35
|
-
* We recommend using `
|
|
35
|
+
* We recommend using `({}).SSR` instead, see https://vike.dev/globalContext
|
|
36
36
|
*/
|
|
37
37
|
isClientSide: true,
|
|
38
38
|
};
|
|
@@ -155,6 +155,9 @@ function setGlobalContext_isPrerendering() {
|
|
|
155
155
|
setIsProduction(true);
|
|
156
156
|
}
|
|
157
157
|
function setGlobalContext_isProduction(isProduction, tolerateContraditction = false) {
|
|
158
|
+
// TODO/now: try to remove globalObject.isProduction ?
|
|
159
|
+
// TODO/now: `rename tolerateContraditction tolerateContradiction`
|
|
160
|
+
tolerateContraditction = true;
|
|
158
161
|
if (debug.isActivated)
|
|
159
162
|
debug('setGlobalContext_isProduction()', { isProduction, tolerateContraditction });
|
|
160
163
|
if (globalObject.isProduction === undefined) {
|
|
@@ -205,7 +208,12 @@ async function initGlobalContext() {
|
|
|
205
208
|
const { isProduction } = globalObject;
|
|
206
209
|
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
207
210
|
if (!isProduction) {
|
|
208
|
-
|
|
211
|
+
if (isProcessSharedWithVite()) {
|
|
212
|
+
await globalObject.viteDevServerPromise;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
await updateUserFiles();
|
|
216
|
+
}
|
|
209
217
|
(0, utils_js_1.assert)(globalObject.waitForUserFilesUpdate);
|
|
210
218
|
await globalObject.waitForUserFilesUpdate;
|
|
211
219
|
}
|
|
@@ -339,16 +347,27 @@ async function updateUserFiles() {
|
|
|
339
347
|
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
340
348
|
viteDevServer !== globalObject.viteDevServer;
|
|
341
349
|
const { viteDevServer } = globalObject;
|
|
342
|
-
(0, utils_js_1.assert)(viteDevServer);
|
|
343
350
|
let hasError = false;
|
|
344
351
|
let virtualFileExports;
|
|
345
352
|
let err;
|
|
346
|
-
|
|
347
|
-
|
|
353
|
+
if (viteDevServer) {
|
|
354
|
+
try {
|
|
355
|
+
virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileEntry_js_1.virtualFileIdEntryServer);
|
|
356
|
+
}
|
|
357
|
+
catch (err_) {
|
|
358
|
+
hasError = true;
|
|
359
|
+
err = err_;
|
|
360
|
+
}
|
|
348
361
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
362
|
+
else {
|
|
363
|
+
try {
|
|
364
|
+
// We don't directly use import() to workaround what seems to be a Vite HMR bug: using import() breaks the HMR of normal non-worker apps.
|
|
365
|
+
virtualFileExports = await __VIKE__DYNAMIC_IMPORT('virtual:vike:entry:server');
|
|
366
|
+
}
|
|
367
|
+
catch (err_) {
|
|
368
|
+
hasError = true;
|
|
369
|
+
err = err_;
|
|
370
|
+
}
|
|
352
371
|
}
|
|
353
372
|
if (isOutdated())
|
|
354
373
|
return { success: false };
|
|
@@ -374,7 +393,7 @@ async function updateUserFiles() {
|
|
|
374
393
|
async function setGlobalContext(virtualFileExports) {
|
|
375
394
|
debug('setGlobalContext()');
|
|
376
395
|
(0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
|
|
377
|
-
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject,
|
|
396
|
+
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
378
397
|
(0, assertV1Design_js_1.assertV1Design)(
|
|
379
398
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
380
399
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
@@ -384,13 +403,13 @@ async function setGlobalContext(virtualFileExports) {
|
|
|
384
403
|
// Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
|
|
385
404
|
return globalContext;
|
|
386
405
|
}
|
|
387
|
-
async function
|
|
388
|
-
debug('
|
|
406
|
+
async function addGlobalContextTmp(globalContext) {
|
|
407
|
+
debug('addGlobalContextTmp()');
|
|
389
408
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
390
409
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
391
410
|
}
|
|
392
|
-
function
|
|
393
|
-
debug('
|
|
411
|
+
function addGlobalContext(globalContext) {
|
|
412
|
+
debug('addGlobalContext()');
|
|
394
413
|
const { pageRoutes, onBeforeRouteHook } = (0, loadPageRoutes_js_1.loadPageRoutesSync)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
395
414
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
396
415
|
}
|
|
@@ -400,23 +419,18 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
400
419
|
_pageRoutes: pageRoutes,
|
|
401
420
|
_onBeforeRouteHook: onBeforeRouteHook,
|
|
402
421
|
};
|
|
403
|
-
const { viteDevServer, viteConfig,
|
|
422
|
+
const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
|
|
404
423
|
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
405
424
|
if (!isProduction) {
|
|
406
|
-
(0, utils_js_1.assert)(viteDevServer);
|
|
407
425
|
(0, utils_js_1.assert)(globalContext); // main common requirement
|
|
408
|
-
(0, utils_js_1.assert)(viteConfig);
|
|
409
|
-
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
410
426
|
(0, utils_js_1.assert)(!isPrerendering);
|
|
411
427
|
return {
|
|
412
428
|
...globalContextBase,
|
|
413
|
-
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
414
429
|
_isProduction: false,
|
|
415
430
|
_isPrerendering: false,
|
|
416
431
|
assetsManifest: null,
|
|
417
432
|
_viteDevServer: viteDevServer,
|
|
418
433
|
viteConfig,
|
|
419
|
-
viteConfigRuntime,
|
|
420
434
|
};
|
|
421
435
|
}
|
|
422
436
|
else {
|
|
@@ -427,11 +441,9 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
427
441
|
(0, utils_js_1.assert)(assetsManifest);
|
|
428
442
|
const globalContextBase2 = {
|
|
429
443
|
...globalContextBase,
|
|
430
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
|
|
431
444
|
_isProduction: true,
|
|
432
445
|
assetsManifest,
|
|
433
446
|
_viteDevServer: null,
|
|
434
|
-
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
435
447
|
_usesClientRouter: buildInfo.usesClientRouter,
|
|
436
448
|
};
|
|
437
449
|
if (isPrerendering) {
|
|
@@ -451,14 +463,45 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
451
463
|
}
|
|
452
464
|
}
|
|
453
465
|
}
|
|
466
|
+
async function addGlobalContextAsync(globalContext) {
|
|
467
|
+
debug('addGlobalContextAsync()');
|
|
468
|
+
let { viteConfigRuntime, buildInfo } = globalObject;
|
|
469
|
+
if (!viteConfigRuntime) {
|
|
470
|
+
if (buildInfo) {
|
|
471
|
+
viteConfigRuntime = buildInfo.viteConfigRuntime;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
if (!isProcessSharedWithVite()) {
|
|
475
|
+
if (!globalObject.isProduction) {
|
|
476
|
+
const rpc = (0, utils_js_1.getViteRPC)();
|
|
477
|
+
viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
(0, utils_js_1.assert)(false); // production => globalObject.buildInfo should be set
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
(0, utils_js_1.assert)(false); // process shared with Vite => globalObject.viteConfigRuntime should be set
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
489
|
+
return {
|
|
490
|
+
viteConfigRuntime,
|
|
491
|
+
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
454
494
|
function clearGlobalContext() {
|
|
455
495
|
debug('clearGlobalContext()');
|
|
456
496
|
(0, utils_js_1.objectReplace)(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
|
|
457
497
|
}
|
|
458
498
|
function getInitialGlobalObject() {
|
|
459
|
-
|
|
499
|
+
const isProduction = getIsProductionStatic();
|
|
500
|
+
if (debug.isActivated)
|
|
501
|
+
debug('getInitialGlobalObject()', { isProduction });
|
|
460
502
|
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = (0, utils_js_1.genPromise)();
|
|
461
503
|
return {
|
|
504
|
+
isProduction,
|
|
462
505
|
viteDevServerPromise,
|
|
463
506
|
viteDevServerPromiseResolve,
|
|
464
507
|
};
|
|
@@ -469,3 +512,22 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
|
469
512
|
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
470
513
|
return (0, resolveBase_js_1.resolveBase)(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
471
514
|
}
|
|
515
|
+
function getIsProductionStatic() {
|
|
516
|
+
// TODO/now add @ts-ignore comments
|
|
517
|
+
// @ts-ignore
|
|
518
|
+
if (!({}))
|
|
519
|
+
return undefined;
|
|
520
|
+
// @ts-ignore
|
|
521
|
+
const PROD = ({}).PROD;
|
|
522
|
+
return PROD;
|
|
523
|
+
}
|
|
524
|
+
function isProcessSharedWithVite() {
|
|
525
|
+
const ret = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE;
|
|
526
|
+
if (globalObject.isProcessSharedWithVite !== undefined) {
|
|
527
|
+
(0, utils_js_1.assert)(globalObject.isProcessSharedWithVite === ret);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
globalObject.isProcessSharedWithVite = ret;
|
|
531
|
+
}
|
|
532
|
+
return ret;
|
|
533
|
+
}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getViteDevScript = getViteDevScript;
|
|
7
|
+
const getViteRPC_js_1 = require("../../../../utils/getViteRPC.js");
|
|
7
8
|
const utils_js_1 = require("../../utils.js");
|
|
8
9
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
10
|
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
@@ -16,7 +17,13 @@ async function getViteDevScript(pageContext) {
|
|
|
16
17
|
const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
|
|
17
18
|
const fakeHtmlEnd = '</head><body></body></html>';
|
|
18
19
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
19
|
-
|
|
20
|
+
if (viteDevServer) {
|
|
21
|
+
fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const rpc = (0, getViteRPC_js_1.getViteRPC)();
|
|
25
|
+
fakeHtml = await rpc.transformIndexHtmlRPC(fakeHtml);
|
|
26
|
+
}
|
|
20
27
|
(0, utils_js_1.assertUsage)(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${picocolors_1.default.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
|
|
21
28
|
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
|
|
22
29
|
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
|
|
@@ -16,18 +16,11 @@ 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
|
-
|
|
23
|
-
|
|
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
|
+
? !globalContext._viteDevServer
|
|
21
|
+
? await (0, utils_js_1.getViteRPC)().retrievePageAssetsDevRPC(clientDependencies, clientEntries)
|
|
22
|
+
: await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
|
|
23
|
+
: retrievePageAssetsProd(globalContext.assetsManifest, clientDependencies, clientEntries, resolveIncludeAssetsImportedByServer(globalContext.config));
|
|
31
24
|
let pageAssets = [];
|
|
32
25
|
(0, utils_js_1.unique)([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
|
|
33
26
|
const { mediaType = null, assetType = null } = (0, inferMediaType_js_1.inferMediaType)(src) || {};
|
|
@@ -61,6 +54,16 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
61
54
|
await (0, sortPageAssetsForEarlyHintsHeader_js_1.sortPageAssetsForEarlyHintsHeader)(pageAssets, isProduction);
|
|
62
55
|
return pageAssets;
|
|
63
56
|
}
|
|
57
|
+
async function retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries) {
|
|
58
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
59
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
60
|
+
return { clientEntriesSrc, assetUrls };
|
|
61
|
+
}
|
|
62
|
+
function retrievePageAssetsProd(assetsManifest, clientDependencies, clientEntries, includeAssetsImportedByServer) {
|
|
63
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
64
|
+
const assetUrls = (0, retrieveAssetsProd_js_1.retrieveAssetsProd)(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(includeAssetsImportedByServer));
|
|
65
|
+
return { clientEntriesSrc, assetUrls };
|
|
66
|
+
}
|
|
64
67
|
function resolveClientEntriesProd(clientEntry, assetsManifest) {
|
|
65
68
|
const { manifestEntry } = (0, getManifestEntry_js_1.getManifestEntry)(clientEntry, assetsManifest);
|
|
66
69
|
(0, utils_js_1.assert)(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
|
|
@@ -76,3 +76,4 @@ __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
|
76
76
|
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
77
77
|
__exportStar(require("../../utils/augmentType.js"), exports);
|
|
78
78
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
79
|
+
__exportStar(require("../../utils/getViteRPC.js"), exports);
|
|
@@ -29,6 +29,7 @@ const resolveClientEntriesDev_js_1 = require("./shared/resolveClientEntriesDev.j
|
|
|
29
29
|
const pluginWorkaroundCssModuleHmr_js_1 = require("./plugins/pluginWorkaroundCssModuleHmr.js");
|
|
30
30
|
const pluginWorkaroundVite6HmrRegression_js_1 = require("./plugins/pluginWorkaroundVite6HmrRegression.js");
|
|
31
31
|
const pluginReplaceConstants_js_1 = require("./plugins/pluginReplaceConstants.js");
|
|
32
|
+
const pluginViteRPC_js_1 = require("./plugins/pluginViteRPC.js");
|
|
32
33
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
33
34
|
(0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
|
|
34
35
|
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
@@ -48,6 +49,7 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
48
49
|
(0, pluginWorkaroundCssModuleHmr_js_1.pluginWorkaroundCssModuleHmr)(),
|
|
49
50
|
(0, pluginWorkaroundVite6HmrRegression_js_1.pluginWorkaroundVite6HmrRegression)(),
|
|
50
51
|
(0, pluginReplaceConstants_js_1.pluginReplaceConstants)(),
|
|
52
|
+
(0, pluginViteRPC_js_1.pluginViteRPC)(),
|
|
51
53
|
];
|
|
52
54
|
Object.assign(plugins, { _vikeVitePluginOptions: vikeVitePluginOptions });
|
|
53
55
|
return plugins;
|
|
@@ -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
|
}
|
|
@@ -16,7 +16,8 @@ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
|
16
16
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
17
17
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
18
18
|
const getPageAssets_js_1 = require("../../../runtime/renderPage/getPageAssets.js");
|
|
19
|
-
|
|
19
|
+
// TODO/now: stop setting `manifest` altogether and use the resolved value instead? So that other tools can easily read the manifest (e.g. @cloudflare/plugin-vite reads the manifest).
|
|
20
|
+
const manifestTempFile = '.vite/manifest.json';
|
|
20
21
|
exports.manifestTempFile = manifestTempFile;
|
|
21
22
|
function pluginBuildConfig() {
|
|
22
23
|
let config;
|
|
@@ -18,6 +18,8 @@ function pluginDistFileNames() {
|
|
|
18
18
|
apply: 'build',
|
|
19
19
|
enforce: 'post',
|
|
20
20
|
configResolved(config) {
|
|
21
|
+
// TODO/now remove
|
|
22
|
+
// if (true as boolean) return
|
|
21
23
|
const rollupOutputs = getRollupOutputs(config);
|
|
22
24
|
// We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
|
|
23
25
|
rollupOutputs.forEach((rollupOutput) => {
|
|
@@ -106,6 +108,7 @@ function getIdHash(id) {
|
|
|
106
108
|
return node_crypto_1.default.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
107
109
|
}
|
|
108
110
|
function getAssetFileName(assetInfo, config) {
|
|
111
|
+
const userRootDir = config.root;
|
|
109
112
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
110
113
|
const dir = assetsDir + '/static';
|
|
111
114
|
let { name } = assetInfo;
|
|
@@ -123,11 +126,11 @@ function getAssetFileName(assetInfo, config) {
|
|
|
123
126
|
// Vite 3
|
|
124
127
|
name?.endsWith('?extractAssets&lang.css')) {
|
|
125
128
|
name = name.split('.').slice(0, -2).join('.');
|
|
126
|
-
name = clean(name);
|
|
129
|
+
name = clean(name, userRootDir);
|
|
127
130
|
return `${dir}/${name}.[hash][extname]`;
|
|
128
131
|
}
|
|
129
132
|
name = name.split('.').slice(0, -1).join('.');
|
|
130
|
-
name = clean(name);
|
|
133
|
+
name = clean(name, userRootDir);
|
|
131
134
|
return `${dir}/${name}.[hash][extname]`;
|
|
132
135
|
}
|
|
133
136
|
function getChunkFileName(_chunkInfo, config) {
|
|
@@ -140,11 +143,12 @@ function getChunkFileName(_chunkInfo, config) {
|
|
|
140
143
|
return name;
|
|
141
144
|
}
|
|
142
145
|
function getEntryFileName(chunkInfo, config, isEntry) {
|
|
146
|
+
const userRootDir = config.root;
|
|
143
147
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
144
148
|
const isForClientSide = !config.build.ssr;
|
|
145
149
|
let { name } = chunkInfo;
|
|
146
150
|
(0, utils_js_1.assertPosixPath)(name);
|
|
147
|
-
name = clean(name, true,
|
|
151
|
+
name = clean(name, userRootDir, true,
|
|
148
152
|
// Not needed for client-side because dist/ filenames contain `.[hash].js`
|
|
149
153
|
!isForClientSide);
|
|
150
154
|
if (isForClientSide) {
|
|
@@ -154,9 +158,14 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
154
158
|
return `${name}.${isEntry ? 'mjs' : 'js'}`;
|
|
155
159
|
}
|
|
156
160
|
}
|
|
157
|
-
function removePathSeparators(name) {
|
|
161
|
+
function removePathSeparators(name, userRootDir) {
|
|
158
162
|
(0, utils_js_1.assertPosixPath)(name);
|
|
159
|
-
|
|
163
|
+
if (name.startsWith(userRootDir)) {
|
|
164
|
+
name = name.slice(userRootDir.length);
|
|
165
|
+
if (name.startsWith('/'))
|
|
166
|
+
name = name.slice(1);
|
|
167
|
+
}
|
|
168
|
+
(0, utils_js_1.assert)(!name.startsWith('/'), { name });
|
|
160
169
|
const entryDir = 'entries/';
|
|
161
170
|
const hasEntryDir = name.startsWith(entryDir);
|
|
162
171
|
if (hasEntryDir) {
|
|
@@ -169,14 +178,14 @@ function removePathSeparators(name) {
|
|
|
169
178
|
}
|
|
170
179
|
return name;
|
|
171
180
|
}
|
|
172
|
-
function clean(name, removePathSep, fixGlob) {
|
|
181
|
+
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
173
182
|
name = fixExtractAssetsQuery(name);
|
|
174
183
|
if (fixGlob) {
|
|
175
184
|
name = workaroundGlob(name);
|
|
176
185
|
}
|
|
177
186
|
name = replaceNonLatinCharacters(name);
|
|
178
187
|
if (removePathSep) {
|
|
179
|
-
name = removePathSeparators(name);
|
|
188
|
+
name = removePathSeparators(name, userRootDir);
|
|
180
189
|
}
|
|
181
190
|
name = removeLeadingUnderscoreInFilename(name);
|
|
182
191
|
name = removeUnderscoreDoublets(name);
|
|
@@ -16,6 +16,7 @@ const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInter
|
|
|
16
16
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
17
17
|
const context_js_2 = require("../../prerender/context.js");
|
|
18
18
|
const pluginName = 'vike:pluginCommon';
|
|
19
|
+
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
19
20
|
function pluginCommon(vikeVitePluginOptions) {
|
|
20
21
|
return [
|
|
21
22
|
{
|
|
@@ -12,7 +12,7 @@ const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
|
12
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
13
13
|
const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
|
|
14
14
|
// TO-DO/eventually:
|
|
15
|
-
// - Make
|
|
15
|
+
// - Make ({}) work inside +config.js
|
|
16
16
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
17
17
|
// - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
18
18
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
@@ -39,7 +39,7 @@ function pluginEnvVars() {
|
|
|
39
39
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
40
40
|
if (!id.startsWith(config.root))
|
|
41
41
|
return;
|
|
42
|
-
if (!code.includes('
|
|
42
|
+
if (!code.includes('({}).'))
|
|
43
43
|
return;
|
|
44
44
|
const isBuild = config.command === 'build';
|
|
45
45
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
@@ -52,7 +52,7 @@ function pluginEnvVars() {
|
|
|
52
52
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
53
53
|
})
|
|
54
54
|
.map(([envName, envVal]) => {
|
|
55
|
-
const envStatement = `
|
|
55
|
+
const envStatement = `({}).${envName}`;
|
|
56
56
|
const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
57
57
|
// Security check
|
|
58
58
|
{
|
|
@@ -81,12 +81,12 @@ function injectHmr(code, isClientSide, isProduction) {
|
|
|
81
81
|
}
|
|
82
82
|
if (isClientSide) {
|
|
83
83
|
code += '\n';
|
|
84
|
-
code += `if (
|
|
84
|
+
code += `if ((undefined)) (undefined).accept((mod) => { exportNames.length=0; exportNames.push(...mod.exportNames); });`;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
// Ensure Vite considers the module as `isSelfAccepting`. (Needed because Vite's module graph erroneously conflates the Vite server-side modules with their client-side counterparts.)
|
|
88
88
|
code += '\n';
|
|
89
|
-
code += 'if(false){
|
|
89
|
+
code += 'if(false){(undefined).accept(()=>{})};';
|
|
90
90
|
}
|
|
91
91
|
return code;
|
|
92
92
|
}
|
|
@@ -26,7 +26,7 @@ function pluginReplaceConstants() {
|
|
|
26
26
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
27
27
|
if (!id.startsWith(config.root))
|
|
28
28
|
return;
|
|
29
|
-
if (!code.includes('
|
|
29
|
+
if (!code.includes('({}).'))
|
|
30
30
|
return;
|
|
31
31
|
const isBuild = config.command === 'build';
|
|
32
32
|
(0, utils_js_1.assert)(isBuild);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginViteRPC = pluginViteRPC;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const resolveClientEntriesDev_js_1 = require("../shared/resolveClientEntriesDev.js");
|
|
6
|
+
const retrieveAssetsDev_js_1 = require("../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js");
|
|
7
|
+
const getViteConfigRuntime_js_1 = require("../shared/getViteConfigRuntime.js");
|
|
8
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
9
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
10
|
+
return {
|
|
11
|
+
async transformIndexHtmlRPC(html) {
|
|
12
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
13
|
+
},
|
|
14
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
15
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => (0, resolveClientEntriesDev_js_1.resolveClientEntriesDev)(clientEntry, viteDevServer));
|
|
16
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
17
|
+
return { clientEntriesSrc, assetUrls };
|
|
18
|
+
},
|
|
19
|
+
async getViteConfigRuntimeRPC() {
|
|
20
|
+
const viteConfigRuntime = (0, getViteConfigRuntime_js_1.getViteConfigRuntime)(viteDevServer.config);
|
|
21
|
+
return viteConfigRuntime;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function pluginViteRPC() {
|
|
26
|
+
const runtimeFileWithDynamicImport = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/node/runtime/globalContext.js');
|
|
27
|
+
return {
|
|
28
|
+
name: 'vike:pluginViteRPC',
|
|
29
|
+
configureServer(viteDevServer) {
|
|
30
|
+
(0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
|
|
31
|
+
},
|
|
32
|
+
transform(code, id) {
|
|
33
|
+
if (id !== runtimeFileWithDynamicImport)
|
|
34
|
+
return;
|
|
35
|
+
const envName = this.environment?.name;
|
|
36
|
+
if (!envName || ['client', 'ssr'].includes(envName))
|
|
37
|
+
return;
|
|
38
|
+
// TODO/now use magic-string
|
|
39
|
+
return code.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyRegExpWithMagicString = applyRegExpWithMagicString;
|
|
4
|
+
// TODO/now: replace with .replaceAll() ?
|
|
4
5
|
function applyRegExpWithMagicString(magicString, regExp, replacement) {
|
|
5
6
|
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
|
|
6
7
|
let match;
|
|
@@ -10,25 +10,33 @@ 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, addGlobalContextAsync) {
|
|
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);
|
|
36
|
+
}
|
|
37
|
+
{
|
|
38
|
+
const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
|
|
39
|
+
(0, utils_js_1.objectAssign)(globalContext, globalContextAddedAsync);
|
|
32
40
|
}
|
|
33
41
|
const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
34
42
|
let hooksCalled = false;
|
|
@@ -43,8 +43,8 @@ function onInternalProp(propStr, objName) {
|
|
|
43
43
|
// - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
44
44
|
// - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
|
|
45
45
|
// - Where import.meta.CLIENT is defined by Vike
|
|
46
|
-
// - Using
|
|
47
|
-
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use
|
|
46
|
+
// - Using ({}).CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_({})
|
|
47
|
+
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use ({}).SSR
|
|
48
48
|
if ((0, utils_js_1.isBrowser)())
|
|
49
49
|
return;
|
|
50
50
|
// TO-DO/soon/proxy: remove this and only warn on built-in access instead
|