vike 0.4.162 → 0.4.163-commit-407cb5c
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/node/plugin/plugins/autoFullBuild.js +7 -4
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +9 -5
- package/dist/cjs/node/plugin/plugins/buildConfig.js +24 -18
- package/dist/cjs/node/plugin/plugins/commonConfig.js +8 -2
- package/dist/cjs/node/plugin/plugins/distFileNames.js +4 -9
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +2 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +6 -1
- package/dist/cjs/node/plugin/shared/getAssetsDir.js +11 -0
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +3 -3
- package/dist/cjs/node/runtime/globalContext.js +47 -6
- package/dist/cjs/node/runtime/index-common.js +4 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +19 -19
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +12 -12
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +5 -5
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +9 -13
- package/dist/cjs/node/runtime/renderPage.js +3 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +4 -11
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +20 -14
- package/dist/esm/client/shared/getPageContextProxyForUser.js +19 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +7 -4
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +10 -6
- package/dist/esm/node/plugin/plugins/buildConfig.js +24 -18
- package/dist/esm/node/plugin/plugins/commonConfig.js +9 -3
- package/dist/esm/node/plugin/plugins/distFileNames.js +1 -6
- package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +6 -1
- package/dist/esm/node/plugin/shared/getAssetsDir.d.ts +3 -0
- package/dist/esm/node/plugin/shared/getAssetsDir.js +8 -0
- package/dist/esm/node/runtime/globalContext/loadImportBuild.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +3 -3
- package/dist/esm/node/runtime/globalContext.d.ts +11 -2
- package/dist/esm/node/runtime/globalContext.js +49 -6
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +19 -19
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +12 -12
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +5 -5
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +10 -11
- package/dist/esm/node/runtime/renderPage.js +3 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +5 -9
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -1
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getHint = exports.isKnownError = exports.isCjsEsmError = exports.logErrorHint = void 0;
|
|
7
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
4
|
const utils_js_1 = require("../utils.js");
|
|
9
5
|
const knownErrors = [
|
|
10
6
|
{
|
|
@@ -14,6 +10,13 @@ const knownErrors = [
|
|
|
14
10
|
{
|
|
15
11
|
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
16
12
|
link: 'https://vike.dev/broken-npm-package#react-invalid-component'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
// ```
|
|
16
|
+
// Error [RollupError]: Could not resolve "../dist/client/assets.json" from "renderer/+onRenderHtml.tsx"
|
|
17
|
+
// ```
|
|
18
|
+
errMsg: 'assets.json',
|
|
19
|
+
link: 'https://vike.dev/getGlobalContext'
|
|
17
20
|
}
|
|
18
21
|
];
|
|
19
22
|
function logErrorHint(error) {
|
|
@@ -33,15 +36,7 @@ function getHint(error) {
|
|
|
33
36
|
}
|
|
34
37
|
const res = isCjsEsmError(error);
|
|
35
38
|
if (res) {
|
|
36
|
-
const
|
|
37
|
-
const hint = [
|
|
38
|
-
'Error could be a CJS/ESM issue, consider ',
|
|
39
|
-
!packageNames || packageNames.length === 0
|
|
40
|
-
? 'using'
|
|
41
|
-
: `adding ${(0, utils_js_1.joinEnglish)(packageNames.map((p) => picocolors_1.default.cyan(p)), 'or')} to`,
|
|
42
|
-
` ${picocolors_1.default.cyan('ssr.noExternal')}`,
|
|
43
|
-
', see https://vike.dev/broken-npm-package'
|
|
44
|
-
].join('');
|
|
39
|
+
const hint = 'The error seems to be a CJS/ESM issue, see https://vike.dev/broken-npm-package';
|
|
45
40
|
return hint;
|
|
46
41
|
}
|
|
47
42
|
return null;
|
|
@@ -74,6 +69,7 @@ function isCjsEsmError(error) {
|
|
|
74
69
|
packageNames.forEach((packageName) => {
|
|
75
70
|
(0, utils_js_1.assert)(!['vite', 'vike'].includes(packageName));
|
|
76
71
|
});
|
|
72
|
+
// We don't use this anymore: we could return `true` instead. Shall we remove returning a list of npm packages?
|
|
77
73
|
return packageNames;
|
|
78
74
|
}
|
|
79
75
|
exports.isCjsEsmError = isCjsEsmError;
|
|
@@ -327,6 +327,9 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
327
327
|
if (disableUrlNormalization)
|
|
328
328
|
return null;
|
|
329
329
|
const { urlOriginal } = pageContextInit;
|
|
330
|
+
const { isPageContextRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
331
|
+
if (isPageContextRequest)
|
|
332
|
+
return null;
|
|
330
333
|
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash, baseServer);
|
|
331
334
|
if (!urlNormalized)
|
|
332
335
|
return null;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.serializeConfigValueImported = exports.serializeConfigValue = void 0;
|
|
7
4
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with:
|
|
@@ -10,7 +7,6 @@ exports.serializeConfigValueImported = exports.serializeConfigValue = void 0;
|
|
|
10
7
|
// Both parsePageConfigs() parseConfigValuesImported() and are loaded on the client-side and server-side
|
|
11
8
|
const assertIsNotProductionRuntime_js_1 = require("../../../utils/assertIsNotProductionRuntime.js");
|
|
12
9
|
(0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
10
|
const utils_js_1 = require("../../utils.js");
|
|
15
11
|
const generateEagerImport_js_1 = require("../../../node/plugin/plugins/importUserCode/generateEagerImport.js");
|
|
16
12
|
function serializeConfigValue(lines, configName, configValueSerialized) {
|
|
@@ -28,13 +24,10 @@ exports.serializeConfigValue = serializeConfigValue;
|
|
|
28
24
|
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
29
25
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
30
26
|
(0, utils_js_1.assert)(whitespace.replaceAll(' ', '').length === 0);
|
|
31
|
-
const { valueIsImportedAtRuntime, definedAt } = configValueSource;
|
|
27
|
+
const { valueIsImportedAtRuntime, valueIsDefinedByValueFile, definedAt } = configValueSource;
|
|
32
28
|
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
33
29
|
const { filePathAbsoluteVite, fileExportName } = definedAt;
|
|
34
|
-
|
|
35
|
-
const fileName = path_1.default.posix.basename(filePathAbsoluteVite);
|
|
36
|
-
const isValueFile = fileName.startsWith('+');
|
|
37
|
-
if (isValueFile)
|
|
30
|
+
if (valueIsDefinedByValueFile)
|
|
38
31
|
(0, utils_js_1.assert)(fileExportName === undefined);
|
|
39
32
|
const { importName, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(filePathAbsoluteVite, varCounterContainer.varCounter++, fileExportName);
|
|
40
33
|
importStatements.push(importStatement);
|
|
@@ -42,8 +35,8 @@ function serializeConfigValueImported(configValueSource, configName, whitespace,
|
|
|
42
35
|
lines.push(` {`);
|
|
43
36
|
lines.push(` configName: '${configName}',`);
|
|
44
37
|
lines.push(` importPath: '${filePathAbsoluteVite}',`);
|
|
45
|
-
lines.push(` isValueFile: ${JSON.stringify(
|
|
46
|
-
if (
|
|
38
|
+
lines.push(` isValueFile: ${JSON.stringify(valueIsDefinedByValueFile)},`);
|
|
39
|
+
if (valueIsDefinedByValueFile) {
|
|
47
40
|
lines.push(` exportValues: ${importName},`);
|
|
48
41
|
}
|
|
49
42
|
else {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
4
|
const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
5
|
-
const PROJECT_VERSION = '0.4.
|
|
5
|
+
const PROJECT_VERSION = '0.4.163-commit-407cb5c';
|
|
6
6
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
7
7
|
const projectInfo = {
|
|
8
8
|
projectName: 'Vike',
|
|
@@ -308,35 +308,41 @@ async function renderPageClientSide(renderArgs) {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
};
|
|
311
|
-
// We use globalObject.
|
|
312
|
-
if (globalObject.
|
|
311
|
+
// We use globalObject.onRenderClientPromise in order to ensure that there is never two concurrent onRenderClient() calls
|
|
312
|
+
if (globalObject.onRenderClientPromise) {
|
|
313
313
|
// Make sure that the previous render has finished
|
|
314
|
-
await globalObject.
|
|
315
|
-
assert(globalObject.
|
|
314
|
+
await globalObject.onRenderClientPromise;
|
|
315
|
+
assert(globalObject.onRenderClientPromise === undefined);
|
|
316
316
|
if (isRenderOutdated())
|
|
317
317
|
return;
|
|
318
318
|
}
|
|
319
319
|
changeUrl(urlOriginal, overwriteLastHistoryEntry);
|
|
320
320
|
globalObject.previousPageContext = pageContext;
|
|
321
|
-
assert(globalObject.
|
|
322
|
-
globalObject.
|
|
321
|
+
assert(globalObject.onRenderClientPromise === undefined);
|
|
322
|
+
globalObject.onRenderClientPromise = (async () => {
|
|
323
|
+
let onRenderClientError;
|
|
323
324
|
try {
|
|
324
325
|
await executeOnRenderClientHook(pageContext, true);
|
|
325
326
|
}
|
|
326
327
|
catch (err) {
|
|
327
|
-
|
|
328
|
-
return;
|
|
328
|
+
onRenderClientError = err;
|
|
329
329
|
}
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
globalObject.onRenderClientPromise = undefined;
|
|
331
|
+
return onRenderClientError;
|
|
332
332
|
})();
|
|
333
|
-
await globalObject.
|
|
334
|
-
assert(globalObject.
|
|
333
|
+
const onRenderClientError = await globalObject.onRenderClientPromise;
|
|
334
|
+
assert(globalObject.onRenderClientPromise === undefined);
|
|
335
|
+
if (onRenderClientError) {
|
|
336
|
+
await onError(onRenderClientError);
|
|
337
|
+
if (!isErrorPage)
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
335
340
|
/* We don't abort in order to ensure that onHydrationEnd() is called: we abort only after onHydrationEnd() is called.
|
|
336
341
|
if (isRenderOutdated(true)) return
|
|
337
342
|
*/
|
|
343
|
+
addLinkPrefetchHandlers(pageContext);
|
|
338
344
|
// onHydrationEnd()
|
|
339
|
-
if (isHydrationRender) {
|
|
345
|
+
if (isHydrationRender && !onRenderClientError) {
|
|
340
346
|
assertHook(pageContext, 'onHydrationEnd');
|
|
341
347
|
const hook = getHook(pageContext, 'onHydrationEnd');
|
|
342
348
|
if (hook) {
|
|
@@ -353,7 +359,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
353
359
|
return;
|
|
354
360
|
}
|
|
355
361
|
}
|
|
356
|
-
// We abort *after* onHydrationEnd() is called
|
|
362
|
+
// We purposely abort *after* onHydrationEnd() is called (see comment above).
|
|
357
363
|
if (isRenderOutdated(true))
|
|
358
364
|
return;
|
|
359
365
|
// onPageTransitionEnd()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getPageContextProxyForUser };
|
|
2
|
-
import { assert, assertUsage, getGlobalObject } from '../server-routing-runtime/utils.js';
|
|
2
|
+
import { assert, assertUsage, assertWarning, getGlobalObject } from '../server-routing-runtime/utils.js';
|
|
3
3
|
import { notSerializable } from '../../shared/notSerializable.js';
|
|
4
4
|
const globalObject = getGlobalObject('getPageContextProxyForUser.ts', {});
|
|
5
5
|
/**
|
|
@@ -30,6 +30,10 @@ function assertIsDefined(pageContext, prop) {
|
|
|
30
30
|
return;
|
|
31
31
|
if (isExpected(prop))
|
|
32
32
|
return;
|
|
33
|
+
// - If no pageContext was fetchd from the server, then adding props to passToClient is useless.
|
|
34
|
+
// - Showing a warning, even though no pageContext was fetched from the server, is actually erroneous as the client runtime cannot deduce the passToClient list.
|
|
35
|
+
if (!pageContext._hasPageContextFromServer)
|
|
36
|
+
return;
|
|
33
37
|
const propName = JSON.stringify(prop);
|
|
34
38
|
/* This handling would be the clearest but, unfortunately, it's fundamentally problematic:
|
|
35
39
|
* - It would force the pageContext value consumer to be synchronized with the pageContext value provider. For example, if vike-react wants to conditionally do something dependening on wehther some optional pageContext value was provided by some optional vike-react-* integration package.
|
|
@@ -37,7 +41,7 @@ function assertIsDefined(pageContext, prop) {
|
|
|
37
41
|
const errMsg = `pageContext[${propName}] is \`undefined\` on the client-side. If it's defined on the server-side then add ${propName} to passToClient (https://vike.dev/passToClient), otherwise make sure your client-side hooks always define it (e.g. set it to \`null\` instead of \`undefined\`).`
|
|
38
42
|
assertUsage(false, errMsg)
|
|
39
43
|
*/
|
|
40
|
-
if (
|
|
44
|
+
if (!pageContext._hasPageContextFromClient) {
|
|
41
45
|
// We can safely assume that the property is missing in passToClient, because the server-side defines all passToClient properties even if they have an undefined value:
|
|
42
46
|
// ```
|
|
43
47
|
// <script id="vike_pageContext" type="application/json">{"_pageId":"/pages/admin","user":"!undefined","pageProps":"!undefined","title":"!undefined","abortReason":"!undefined","_urlRewrite":null}</script>
|
|
@@ -47,6 +51,19 @@ function assertIsDefined(pageContext, prop) {
|
|
|
47
51
|
}
|
|
48
52
|
else {
|
|
49
53
|
// Do nothing, not even a warning, because we don't know whether the user expects that the pageContext value can be undefined. (E.g. a pageContext value that is defined by an optional hook.)
|
|
54
|
+
// TODO/next-major-release make it an assertUsage()
|
|
55
|
+
assertWarning(false, [
|
|
56
|
+
`pageContext[${propName}] isn't defined on the client-side:`,
|
|
57
|
+
`1. if it's defined by the server-side then add ${propName} to passToClient (https://vike.dev/passToClient), or`,
|
|
58
|
+
`2. if it's expected that it may not be defined:`,
|
|
59
|
+
' ```js',
|
|
60
|
+
' // ❌ Replace code like this:',
|
|
61
|
+
` const val = pageContext[${propName}] ?? someDefaultValue`,
|
|
62
|
+
' // ✅ With that:',
|
|
63
|
+
` const val = ${propName} in pageContext ? pageContext[${propName}] : someDefaultValue`,
|
|
64
|
+
' ```',
|
|
65
|
+
`See stack track below to find where pageContext[${propName}] is being accessed.`
|
|
66
|
+
].join('\n'), { showStackTrace: true, onlyOnce: false });
|
|
50
67
|
}
|
|
51
68
|
}
|
|
52
69
|
const IGNORE_LIST = [
|
|
@@ -6,6 +6,7 @@ import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
|
6
6
|
import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
|
|
9
|
+
import { manifestTempFile } from './buildConfig.js';
|
|
9
10
|
let forceExit = false;
|
|
10
11
|
function autoFullBuild() {
|
|
11
12
|
let config;
|
|
@@ -58,10 +59,12 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
58
59
|
return; // already triggered
|
|
59
60
|
if (isDisabled(configVike))
|
|
60
61
|
return;
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
// Workaround for @vitejs/plugin-legacy
|
|
63
|
+
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
64
|
+
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
65
|
+
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
66
|
+
if (!bundle[manifestTempFile])
|
|
67
|
+
return;
|
|
65
68
|
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
66
69
|
const configInline = {
|
|
67
70
|
...configFromCli,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { fixServerAssets };
|
|
2
2
|
export { fixServerAssets_isEnabled };
|
|
3
3
|
import { ViteManifest } from '../../../shared/ViteManifest.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ResolvedConfig } from 'vite';
|
|
5
5
|
/**
|
|
6
6
|
* true => use workaround config.build.ssrEmitAssets
|
|
7
7
|
* false => use workaround extractAssets plugin
|
|
@@ -10,4 +10,4 @@ import { OutDirs } from '../../utils.js';
|
|
|
10
10
|
*/
|
|
11
11
|
declare function fixServerAssets_isEnabled(): boolean;
|
|
12
12
|
/** https://github.com/vikejs/vike/issues/1339 */
|
|
13
|
-
declare function fixServerAssets(
|
|
13
|
+
declare function fixServerAssets(config: ResolvedConfig): Promise<ViteManifest>;
|
|
@@ -3,9 +3,10 @@ export { fixServerAssets_isEnabled };
|
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { existsSync } from 'fs';
|
|
6
|
-
import { assert, pLimit, unique } from '../../utils.js';
|
|
6
|
+
import { assert, getOutDirs, pLimit, unique } from '../../utils.js';
|
|
7
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
8
8
|
import { manifestTempFile } from '../buildConfig.js';
|
|
9
|
+
import { getAssetsDir } from '../../shared/getAssetsDir.js';
|
|
9
10
|
/**
|
|
10
11
|
* true => use workaround config.build.ssrEmitAssets
|
|
11
12
|
* false => use workaround extractAssets plugin
|
|
@@ -18,11 +19,12 @@ function fixServerAssets_isEnabled() {
|
|
|
18
19
|
return true;
|
|
19
20
|
}
|
|
20
21
|
/** https://github.com/vikejs/vike/issues/1339 */
|
|
21
|
-
async function fixServerAssets(
|
|
22
|
+
async function fixServerAssets(config) {
|
|
23
|
+
const outDirs = getOutDirs(config);
|
|
22
24
|
const clientManifest = await loadManifest(outDirs.outDirClient);
|
|
23
25
|
const serverManifest = await loadManifest(outDirs.outDirServer);
|
|
24
26
|
const { clientManifestMod, filesToCopy } = addServerAssets(clientManifest, serverManifest);
|
|
25
|
-
await copyAssets(filesToCopy,
|
|
27
|
+
await copyAssets(filesToCopy, config);
|
|
26
28
|
return clientManifestMod;
|
|
27
29
|
}
|
|
28
30
|
async function loadManifest(outDir) {
|
|
@@ -33,11 +35,13 @@ async function loadManifest(outDir) {
|
|
|
33
35
|
assert(manifest);
|
|
34
36
|
return manifest;
|
|
35
37
|
}
|
|
36
|
-
async function copyAssets(filesToCopy,
|
|
37
|
-
const
|
|
38
|
+
async function copyAssets(filesToCopy, config) {
|
|
39
|
+
const { outDirClient, outDirServer } = getOutDirs(config);
|
|
40
|
+
const assetsDir = getAssetsDir(config);
|
|
41
|
+
const assetsDirServer = path.posix.join(outDirServer, assetsDir);
|
|
42
|
+
assert(existsSync(assetsDirServer));
|
|
38
43
|
if (!filesToCopy.length)
|
|
39
44
|
return;
|
|
40
|
-
assert(existsSync(assetsDirServer));
|
|
41
45
|
const concurrencyLimit = pLimit(10);
|
|
42
46
|
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() => fs.cp(path.posix.join(outDirServer, file), path.posix.join(outDirClient, file), {
|
|
43
47
|
recursive: true
|
|
@@ -24,13 +24,15 @@ function buildConfig() {
|
|
|
24
24
|
let isServerAssetsFixEnabled;
|
|
25
25
|
let isSsrBuild;
|
|
26
26
|
let outDirs;
|
|
27
|
+
let config;
|
|
27
28
|
return {
|
|
28
29
|
name: 'vike:buildConfig',
|
|
29
30
|
apply: 'build',
|
|
30
31
|
enforce: 'post',
|
|
31
32
|
configResolved: {
|
|
32
33
|
order: 'post',
|
|
33
|
-
async handler(
|
|
34
|
+
async handler(config_) {
|
|
35
|
+
config = config_;
|
|
34
36
|
assertNodeEnv();
|
|
35
37
|
assertRollupInput(config);
|
|
36
38
|
const entries = await getEntries(config);
|
|
@@ -63,24 +65,28 @@ function buildConfig() {
|
|
|
63
65
|
buildStart() {
|
|
64
66
|
assertNodeEnv();
|
|
65
67
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
writeBundle: {
|
|
69
|
+
order: 'post',
|
|
70
|
+
sequential: true,
|
|
71
|
+
async handler(options, bundle) {
|
|
72
|
+
if (isSsrBuild) {
|
|
73
|
+
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
74
|
+
// - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
|
|
75
|
+
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
76
|
+
const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
77
|
+
const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
78
|
+
const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
79
|
+
if (!isServerAssetsFixEnabled) {
|
|
80
|
+
await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const clientManifestMod = await fixServerAssets(config);
|
|
84
|
+
await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
85
|
+
}
|
|
86
|
+
await fs.rm(clientManifestFilePath);
|
|
87
|
+
await fs.rm(serverManifestFilePath);
|
|
88
|
+
await set_constant_ASSETS_MAP(options, bundle);
|
|
80
89
|
}
|
|
81
|
-
await fs.rm(clientManifestFilePath);
|
|
82
|
-
await fs.rm(serverManifestFilePath);
|
|
83
|
-
await set_constant_ASSETS_MAP(options, bundle);
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
|
-
import { assert, assertWarning, findFile } from '../utils.js';
|
|
2
|
+
import { assert, assertUsage, assertWarning, findFile } from '../utils.js';
|
|
3
3
|
import { assertRollupInput } from './buildConfig.js';
|
|
4
4
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
@@ -9,16 +9,18 @@ import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
|
|
|
9
9
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
10
10
|
const importMetaUrl = import.meta.url;
|
|
11
11
|
const require_ = createRequire(importMetaUrl);
|
|
12
|
+
const pluginName = 'vike:commonConfig-1';
|
|
12
13
|
function commonConfig() {
|
|
13
14
|
return [
|
|
14
15
|
{
|
|
15
|
-
name:
|
|
16
|
+
name: pluginName,
|
|
16
17
|
configResolved(config) {
|
|
18
|
+
assertSingleInstance(config);
|
|
17
19
|
installRequireShim_setUserRootDir(config.root);
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
{
|
|
21
|
-
name: 'vike
|
|
23
|
+
name: 'vike:commonConfig-2',
|
|
22
24
|
enforce: 'post',
|
|
23
25
|
configResolved: {
|
|
24
26
|
order: 'post',
|
|
@@ -75,3 +77,7 @@ function assertEsm(userViteRoot) {
|
|
|
75
77
|
dir = pc.dim(dir);
|
|
76
78
|
assertWarning(packageJson.type === 'module', `We recommend setting ${dir}package.json#type to "module", see https://vike.dev/CJS`, { onlyOnce: true });
|
|
77
79
|
}
|
|
80
|
+
function assertSingleInstance(config) {
|
|
81
|
+
const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
|
|
82
|
+
assertUsage(numberOfInstances === 1, `Vike's Vite plugin (${pc.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);
|
|
83
|
+
}
|
|
@@ -4,6 +4,7 @@ export { distFileNames };
|
|
|
4
4
|
// - Blocker: https://github.com/rollup/rollup/issues/4724
|
|
5
5
|
import { assertPosixPath, assert, assertUsage } from '../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
|
+
import { getAssetsDir } from '../shared/getAssetsDir.js';
|
|
7
8
|
function distFileNames() {
|
|
8
9
|
return {
|
|
9
10
|
name: 'vike:distFileNames',
|
|
@@ -163,9 +164,3 @@ function getRollupOutputs(config) {
|
|
|
163
164
|
}
|
|
164
165
|
return output;
|
|
165
166
|
}
|
|
166
|
-
function getAssetsDir(config) {
|
|
167
|
-
let { assetsDir } = config.build;
|
|
168
|
-
assertUsage(assetsDir, `${assetsDir} cannot be an empty string`);
|
|
169
|
-
assetsDir = assetsDir.split(/\/|\\/).filter(Boolean).join('/');
|
|
170
|
-
return assetsDir;
|
|
171
|
-
}
|
|
@@ -40,12 +40,11 @@ function getEntryCode(config, configVike) {
|
|
|
40
40
|
` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
|
|
41
41
|
` {`,
|
|
42
42
|
// We first set the values to a variable because of a Rollup bug, and this workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
|
|
43
|
-
` const
|
|
43
|
+
` const assetsManifest = ${ASSETS_MAP};`,
|
|
44
44
|
` const pluginManifest = ${JSON.stringify(vikeManifest, null, 2)};`,
|
|
45
45
|
' setImportBuildGetters({',
|
|
46
46
|
` pageFiles: () => pageFiles,`,
|
|
47
|
-
|
|
48
|
-
` clientManifest: () => clientManifest,`,
|
|
47
|
+
` getAssetsManifest: () => assetsManifest,`,
|
|
49
48
|
// TODO: rename pluginManifest -> vikeManifest
|
|
50
49
|
` pluginManifest: () => pluginManifest,`,
|
|
51
50
|
' });',
|
|
@@ -3,7 +3,7 @@ export { reloadVikeConfig };
|
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
5
|
export { isV1Design };
|
|
6
|
-
export type {
|
|
6
|
+
export type { VikeConfigObject };
|
|
7
7
|
export type { InterfaceValueFile };
|
|
8
8
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime, FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
9
9
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
@@ -21,13 +21,13 @@ type InterfaceValueFile = InterfaceFileCommons & {
|
|
|
21
21
|
configName: string;
|
|
22
22
|
};
|
|
23
23
|
type ConfigName = string;
|
|
24
|
-
type
|
|
24
|
+
type VikeConfigObject = {
|
|
25
25
|
pageConfigs: PageConfigBuildTime[];
|
|
26
26
|
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
27
27
|
globalVikeConfig: Record<string, unknown>;
|
|
28
28
|
};
|
|
29
29
|
declare const vikeConfigDependencies: Set<string>;
|
|
30
30
|
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string): void;
|
|
31
|
-
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: boolean): Promise<
|
|
31
|
+
declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: boolean): Promise<VikeConfigObject>;
|
|
32
32
|
declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
|
|
33
33
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
@@ -469,7 +469,8 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
|
|
|
469
469
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
470
470
|
const loserFilePath = interfaceFileLoser.filePath.filePathToShowToUser;
|
|
471
471
|
const winnerFilePath = interfaceFileWinner.filePath.filePathToShowToUser;
|
|
472
|
-
|
|
472
|
+
const confName = pc.cyan(configName);
|
|
473
|
+
assertWarning(false, `The value of the config ${confName} defined at ${loserFilePath} is always overwritten by the value defined at ${winnerFilePath}, remove the superfluous value defined at ${loserFilePath}`, { onlyOnce: true });
|
|
473
474
|
});
|
|
474
475
|
}
|
|
475
476
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
@@ -510,6 +511,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
510
511
|
valueIsFilePath: true,
|
|
511
512
|
configEnv,
|
|
512
513
|
valueIsImportedAtRuntime: true,
|
|
514
|
+
valueIsDefinedByValueFile: false,
|
|
513
515
|
definedAt
|
|
514
516
|
};
|
|
515
517
|
return configValueSource;
|
|
@@ -525,6 +527,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
525
527
|
locationId,
|
|
526
528
|
configEnv,
|
|
527
529
|
valueIsImportedAtRuntime: true,
|
|
530
|
+
valueIsDefinedByValueFile: false,
|
|
528
531
|
definedAt: import_
|
|
529
532
|
};
|
|
530
533
|
// Load fake import
|
|
@@ -549,6 +552,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
549
552
|
value: configValue,
|
|
550
553
|
configEnv,
|
|
551
554
|
valueIsImportedAtRuntime: false,
|
|
555
|
+
valueIsDefinedByValueFile: false,
|
|
552
556
|
definedAt: definedAtConfigFile
|
|
553
557
|
};
|
|
554
558
|
return configValueSource;
|
|
@@ -561,6 +565,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
561
565
|
locationId,
|
|
562
566
|
configEnv,
|
|
563
567
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
568
|
+
valueIsDefinedByValueFile: true,
|
|
564
569
|
definedAt: {
|
|
565
570
|
...interfaceFile.filePath,
|
|
566
571
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { getAssetsDir };
|
|
2
|
+
import { assertUsage } from '../utils.js';
|
|
3
|
+
function getAssetsDir(config) {
|
|
4
|
+
let { assetsDir } = config.build;
|
|
5
|
+
assertUsage(assetsDir, `${assetsDir} cannot be an empty string`);
|
|
6
|
+
assetsDir = assetsDir.split(/\/|\\/).filter(Boolean).join('/');
|
|
7
|
+
return assetsDir;
|
|
8
|
+
}
|
|
@@ -2,13 +2,13 @@ export { loadImportBuild };
|
|
|
2
2
|
export { setImportBuildGetters };
|
|
3
3
|
type BuildGetters = null | {
|
|
4
4
|
pageFiles: () => Promise<Record<string, unknown>>;
|
|
5
|
-
|
|
5
|
+
getAssetsManifest: () => Promise<Record<string, unknown>>;
|
|
6
6
|
pluginManifest: () => Promise<Record<string, unknown>>;
|
|
7
7
|
};
|
|
8
8
|
declare function setImportBuildGetters(getters: BuildGetters): void;
|
|
9
9
|
declare function loadImportBuild(outDir?: string): Promise<{
|
|
10
10
|
pageFiles: Record<string, unknown>;
|
|
11
|
-
|
|
11
|
+
assetsManifest: Record<string, unknown>;
|
|
12
12
|
pluginManifest: Record<string, unknown>;
|
|
13
13
|
}>;
|
|
14
14
|
declare global {
|
|
@@ -13,11 +13,11 @@ async function loadImportBuild(outDir) {
|
|
|
13
13
|
await importServerEntry(outDir);
|
|
14
14
|
assert(buildGetters.getters);
|
|
15
15
|
}
|
|
16
|
-
const [pageFiles,
|
|
16
|
+
const [pageFiles, assetsManifest, pluginManifest] = await Promise.all([
|
|
17
17
|
buildGetters.getters.pageFiles(),
|
|
18
|
-
buildGetters.getters.
|
|
18
|
+
buildGetters.getters.getAssetsManifest(),
|
|
19
19
|
buildGetters.getters.pluginManifest()
|
|
20
20
|
]);
|
|
21
|
-
const buildEntries = { pageFiles,
|
|
21
|
+
const buildEntries = { pageFiles, assetsManifest, pluginManifest };
|
|
22
22
|
return buildEntries;
|
|
23
23
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { getGlobalContextSync };
|
|
2
|
+
export { getGlobalContextAsync };
|
|
1
3
|
export { initGlobalContext };
|
|
2
4
|
export { getGlobalContext };
|
|
3
5
|
export { getViteDevServer };
|
|
@@ -10,6 +12,9 @@ import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
|
10
12
|
import { PluginManifest } from '../shared/assertPluginManifest.js';
|
|
11
13
|
import type { ConfigVikeResolved } from '../../shared/ConfigVike.js';
|
|
12
14
|
import { type RuntimeManifest } from '../shared/assertRuntimeManifest.js';
|
|
15
|
+
type GlobalContextPublic = {
|
|
16
|
+
assetsManifest: null | ViteManifest;
|
|
17
|
+
};
|
|
13
18
|
type GlobalContext = {
|
|
14
19
|
baseServer: string;
|
|
15
20
|
baseAssets: null | string;
|
|
@@ -22,11 +27,11 @@ type GlobalContext = {
|
|
|
22
27
|
isPrerendering: false;
|
|
23
28
|
viteConfig: ResolvedConfig;
|
|
24
29
|
viteDevServer: ViteDevServer;
|
|
25
|
-
|
|
30
|
+
assetsManifest: null;
|
|
26
31
|
pluginManifest: null;
|
|
27
32
|
} | ({
|
|
28
33
|
isProduction: true;
|
|
29
|
-
|
|
34
|
+
assetsManifest: ViteManifest;
|
|
30
35
|
pluginManifest: PluginManifest;
|
|
31
36
|
viteDevServer: null;
|
|
32
37
|
} & ({
|
|
@@ -37,6 +42,10 @@ type GlobalContext = {
|
|
|
37
42
|
viteConfig: ResolvedConfig;
|
|
38
43
|
})));
|
|
39
44
|
declare function getGlobalContext(): GlobalContext;
|
|
45
|
+
/** @experimental https://vike.dev/getGlobalContext */
|
|
46
|
+
declare function getGlobalContextSync(): GlobalContextPublic;
|
|
47
|
+
/** @experimental https://vike.dev/getGlobalContext */
|
|
48
|
+
declare function getGlobalContextAsync(): Promise<GlobalContextPublic>;
|
|
40
49
|
declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): void;
|
|
41
50
|
declare function getViteDevServer(): ViteDevServer | null;
|
|
42
51
|
declare function setGlobalContext_prerender(viteConfig: ResolvedConfig): void;
|