vike 0.4.222-commit-fab3841 → 0.4.223-commit-6f064ad
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/index.js +5 -3
- package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -1
- package/dist/cjs/node/plugin/plugins/buildApp.js +5 -2
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +49 -19
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +17 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +10 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +8 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +24 -52
- package/dist/cjs/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/cjs/node/prerender/runPrerender.js +3 -1
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/cjs/shared/getPageContextUrlComputed.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +16 -6
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/findFile.js +1 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +10 -1
- package/dist/esm/node/plugin/index.d.ts +2 -1
- package/dist/esm/node/plugin/index.js +1 -0
- package/dist/esm/node/plugin/plugins/baseUrls.js +3 -1
- package/dist/esm/node/plugin/plugins/buildApp.js +5 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +49 -19
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +14 -6
- package/dist/esm/node/plugin/plugins/commonConfig.js +17 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +8 -5
- 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 +25 -53
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/esm/node/prerender/runPrerender.js +3 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/esm/shared/getPageContextUrlComputed.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +16 -6
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +2 -2
|
@@ -39,7 +39,7 @@ function getUrlParsed(pageContext) {
|
|
|
39
39
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
40
40
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
41
41
|
// Determine logical URL
|
|
42
|
-
const assertUrlResolved = (src) => (0, utils_js_1.assert)(
|
|
42
|
+
const assertUrlResolved = (src) => (0, utils_js_1.assert)(typeof urlResolved === 'string',
|
|
43
43
|
// TODO/eventually: remove debug logs, see:
|
|
44
44
|
// - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
45
45
|
// - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
|
|
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serializeConfigValues = serializeConfigValues;
|
|
7
7
|
exports.getConfigValuesBase = getConfigValuesBase;
|
|
8
|
+
exports.isJsonValue = isJsonValue;
|
|
8
9
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
9
10
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
10
11
|
const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
|
|
11
12
|
const helpers_js_1 = require("../helpers.js");
|
|
12
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
13
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
|
+
const stringifyOptions = { forbidReactElements: true };
|
|
14
16
|
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
15
17
|
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
16
18
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
@@ -49,7 +51,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
49
51
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
50
52
|
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
51
53
|
let valueData;
|
|
52
|
-
if ('value' in configValueSource) {
|
|
54
|
+
if ('value' in configValueSource && !configValueSource.valueIsLoadedWithImport) {
|
|
53
55
|
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements, filesEnv, configValueSource.configEnv);
|
|
54
56
|
}
|
|
55
57
|
else {
|
|
@@ -101,14 +103,13 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
101
103
|
}
|
|
102
104
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
103
105
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
104
|
-
const {
|
|
105
|
-
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
106
|
+
const { valueIsDefinedByPlusValueFile, definedAtFilePath, configEnv } = configValueSource;
|
|
106
107
|
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
107
|
-
if (
|
|
108
|
+
if (valueIsDefinedByPlusValueFile)
|
|
108
109
|
(0, utils_js_1.assert)(fileExportName === undefined);
|
|
109
110
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
110
111
|
return {
|
|
111
|
-
type:
|
|
112
|
+
type: valueIsDefinedByPlusValueFile ? 'plus-file' : 'pointer-import',
|
|
112
113
|
valueAsJsCode: importName
|
|
113
114
|
};
|
|
114
115
|
}
|
|
@@ -125,7 +126,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
125
126
|
try {
|
|
126
127
|
configValueSerialized = (0, stringify_1.stringify)(value, {
|
|
127
128
|
valueName,
|
|
128
|
-
|
|
129
|
+
...stringifyOptions,
|
|
129
130
|
// Replace import strings with import variables.
|
|
130
131
|
// - We don't need this anymore and could remove it.
|
|
131
132
|
// - We temporarily needed it for nested document configs (`config.document.{title,description,favicon}`), but we finally decided to go for flat document configs instead (`config.{title,description,favicon}`).
|
|
@@ -152,6 +153,15 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
152
153
|
(0, utils_js_1.assert)(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
153
154
|
return configValueSerialized;
|
|
154
155
|
}
|
|
156
|
+
function isJsonValue(value) {
|
|
157
|
+
try {
|
|
158
|
+
(0, stringify_1.stringify)(value, stringifyOptions);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
155
165
|
function logJsonSerializeError(err, configName, definedAtData) {
|
|
156
166
|
/*
|
|
157
167
|
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
@@ -8,7 +8,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const isArray_js_1 = require("./isArray.js");
|
|
10
10
|
const path_js_1 = require("./path.js");
|
|
11
|
-
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the
|
|
11
|
+
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the tinyglobby fallback).
|
|
12
12
|
function findFile(arg, cwd) {
|
|
13
13
|
(0, path_js_1.assertPosixPath)(cwd);
|
|
14
14
|
const filenames = (0, isArray_js_1.isArray)(arg) ? arg : [arg];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { navigate, reload } from './navigate.js';
|
|
2
2
|
export { prefetch } from './prefetch.js';
|
|
3
|
+
export { getPageContextClient } from './renderPageClientSide.js';
|
|
3
4
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
4
5
|
import type { PageContextBuiltInClientWithClientRouting } from '../../shared/types.js';
|
|
5
6
|
/** @deprecated
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
// Use package.json#exports to make the imports isomorphic.
|
|
6
6
|
export { navigate, reload } from './navigate.js';
|
|
7
7
|
export { prefetch } from './prefetch.js';
|
|
8
|
+
export { getPageContextClient } from './renderPageClientSide.js';
|
|
8
9
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
@@ -2,8 +2,10 @@ export { renderPageClientSide };
|
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
4
|
export { firstRenderStartPromise };
|
|
5
|
+
export { getPageContextClient };
|
|
5
6
|
import { type PageContextFromRewrite } from '../../shared/route/abort.js';
|
|
6
7
|
import { type ScrollTarget } from './setScrollPosition.js';
|
|
8
|
+
import type { PageContextClient } from '../../shared/types.js';
|
|
7
9
|
declare const firstRenderStartPromise: Promise<void>;
|
|
8
10
|
type RenderArgs = {
|
|
9
11
|
scrollTarget: ScrollTarget;
|
|
@@ -24,3 +26,9 @@ declare global {
|
|
|
24
26
|
}
|
|
25
27
|
declare function disableClientRouting(err: unknown, log: boolean): void;
|
|
26
28
|
declare function getRenderCount(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get the `pageContext` object on the client-side.
|
|
31
|
+
*
|
|
32
|
+
* https://vike.dev/getPageContextClient
|
|
33
|
+
*/
|
|
34
|
+
declare function getPageContextClient(): PageContextClient | null;
|
|
@@ -2,6 +2,7 @@ export { renderPageClientSide };
|
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
4
|
export { firstRenderStartPromise };
|
|
5
|
+
export { getPageContextClient };
|
|
5
6
|
import { assert, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType, genPromise, isCallable, catchInfiniteLoop } from './utils.js';
|
|
6
7
|
import { getPageContextFromClientHooks, getPageContextFromServerHooks, getPageContextFromHooks_isHydration, getPageContextFromHooks_serialized, setPageContextInitIsPassedToClient } from './getPageContextFromHooks.js';
|
|
7
8
|
import { createPageContext } from './createPageContext.js';
|
|
@@ -23,7 +24,6 @@ import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
|
23
24
|
const globalObject = getGlobalObject('client-routing-runtime/renderPageClientSide.ts', (() => {
|
|
24
25
|
const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
|
|
25
26
|
return {
|
|
26
|
-
previousPageContext: null,
|
|
27
27
|
renderCounter: 0,
|
|
28
28
|
firstRenderStartPromise,
|
|
29
29
|
firstRenderStartPromiseResolve
|
|
@@ -484,6 +484,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
484
484
|
// Add link prefetch handlers
|
|
485
485
|
addLinkPrefetchHandlers_watch();
|
|
486
486
|
addLinkPrefetchHandlers();
|
|
487
|
+
globalObject.renderedPageContext = pageContext;
|
|
487
488
|
stampFinished(urlOriginal);
|
|
488
489
|
}
|
|
489
490
|
}
|
|
@@ -595,3 +596,11 @@ function areKeysEqual(key1, key2) {
|
|
|
595
596
|
return false;
|
|
596
597
|
return key1.length === key2.length && key1.every((_, i) => key1[i] === key2[i]);
|
|
597
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Get the `pageContext` object on the client-side.
|
|
601
|
+
*
|
|
602
|
+
* https://vike.dev/getPageContextClient
|
|
603
|
+
*/
|
|
604
|
+
function getPageContextClient() {
|
|
605
|
+
return globalObject.renderedPageContext ?? null;
|
|
606
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export default plugin;
|
|
2
2
|
export { plugin };
|
|
3
3
|
export { plugin as ssr };
|
|
4
|
+
export { getVikeConfigPublic as getVikeConfig } from './plugins/commonConfig.js';
|
|
5
|
+
export { PROJECT_VERSION as version } from './utils.js';
|
|
4
6
|
export type { VikeVitePluginOptions as UserConfig };
|
|
5
7
|
export type { VikeVitePluginOptions };
|
|
6
|
-
export { PROJECT_VERSION as version } from './utils.js';
|
|
7
8
|
type PluginInterop = Record<string, unknown> & {
|
|
8
9
|
name: string;
|
|
9
10
|
};
|
|
@@ -2,6 +2,7 @@ export default plugin;
|
|
|
2
2
|
export { plugin };
|
|
3
3
|
// TODO/v1-release: remove
|
|
4
4
|
export { plugin as ssr };
|
|
5
|
+
export { getVikeConfigPublic as getVikeConfig } from './plugins/commonConfig.js';
|
|
5
6
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
7
|
import { assertUsage } from './utils.js';
|
|
7
8
|
import { buildConfig } from './plugins/buildConfig.js';
|
|
@@ -2,6 +2,7 @@ export { baseUrls };
|
|
|
2
2
|
import { resolveBase } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
4
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
|
+
import { getVikeConfigPublic } from './commonConfig.js';
|
|
5
6
|
function baseUrls() {
|
|
6
7
|
let basesResolved;
|
|
7
8
|
return {
|
|
@@ -11,7 +12,8 @@ function baseUrls() {
|
|
|
11
12
|
const isDev = config._isDev;
|
|
12
13
|
assert(typeof isDev === 'boolean');
|
|
13
14
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
14
|
-
|
|
15
|
+
const vike = getVikeConfigPublic(config);
|
|
16
|
+
basesResolved = resolveBase(baseViteOriginal, vike.config.baseServer ?? null, vike.config.baseAssets ?? null);
|
|
15
17
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
16
18
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
17
19
|
process.env.BASE_ASSETS = basesResolved.baseAssets;
|
|
@@ -5,6 +5,7 @@ import { resolveOutDir } from '../shared/getOutDirs.js';
|
|
|
5
5
|
import { assert } from '../utils.js';
|
|
6
6
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { getFullBuildInlineConfig } from '../shared/getFullBuildInlineConfig.js';
|
|
8
|
+
import { getVikeConfigPublic } from './commonConfig.js';
|
|
8
9
|
function buildApp() {
|
|
9
10
|
let config;
|
|
10
11
|
// `builder.buildApp` can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
@@ -15,7 +16,8 @@ function buildApp() {
|
|
|
15
16
|
name: 'vike:buildApp',
|
|
16
17
|
apply: 'build',
|
|
17
18
|
config(config) {
|
|
18
|
-
|
|
19
|
+
const vike = getVikeConfigPublic(config);
|
|
20
|
+
if (!vike.config.viteEnvironmentAPI)
|
|
19
21
|
return;
|
|
20
22
|
return {
|
|
21
23
|
builder: {
|
|
@@ -60,7 +62,8 @@ function buildApp() {
|
|
|
60
62
|
config = _config;
|
|
61
63
|
},
|
|
62
64
|
async writeBundle() {
|
|
63
|
-
|
|
65
|
+
const vike = getVikeConfigPublic(config);
|
|
66
|
+
if (!vike.config.viteEnvironmentAPI)
|
|
64
67
|
return;
|
|
65
68
|
const vikeConfig = await getVikeConfig(config);
|
|
66
69
|
if (!isPrerenderAutoRunEnabled(vikeConfig))
|
|
@@ -30,8 +30,8 @@ async function fixServerAssets(config) {
|
|
|
30
30
|
const outDirs = getOutDirs(config);
|
|
31
31
|
const clientManifest = await loadManifest(outDirs.outDirClient);
|
|
32
32
|
const serverManifest = await loadManifest(outDirs.outDirServer);
|
|
33
|
-
const { clientManifestMod, serverManifestMod,
|
|
34
|
-
await copyAssets(
|
|
33
|
+
const { clientManifestMod, serverManifestMod, filesToMove, filesToRemove } = addServerAssets(clientManifest, serverManifest);
|
|
34
|
+
await copyAssets(filesToMove, filesToRemove, config);
|
|
35
35
|
return { clientManifestMod, serverManifestMod };
|
|
36
36
|
}
|
|
37
37
|
async function loadManifest(outDir) {
|
|
@@ -42,15 +42,15 @@ async function loadManifest(outDir) {
|
|
|
42
42
|
assert(manifest);
|
|
43
43
|
return manifest;
|
|
44
44
|
}
|
|
45
|
-
async function copyAssets(
|
|
45
|
+
async function copyAssets(filesToMove, filesToRemove, config) {
|
|
46
46
|
const { outDirClient, outDirServer } = getOutDirs(config);
|
|
47
47
|
const assetsDir = getAssetsDir(config);
|
|
48
48
|
const assetsDirServer = path.posix.join(outDirServer, assetsDir);
|
|
49
|
-
if (!
|
|
49
|
+
if (!filesToMove.length && !filesToRemove.length && !existsSync(assetsDirServer))
|
|
50
50
|
return;
|
|
51
51
|
assert(existsSync(assetsDirServer));
|
|
52
52
|
const concurrencyLimit = pLimit(10);
|
|
53
|
-
await Promise.all(
|
|
53
|
+
await Promise.all(filesToMove.map((file) => concurrencyLimit(async () => {
|
|
54
54
|
const source = path.posix.join(outDirServer, file);
|
|
55
55
|
const target = path.posix.join(outDirClient, file);
|
|
56
56
|
await fs.mkdir(path.posix.dirname(target), { recursive: true });
|
|
@@ -86,19 +86,20 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
86
86
|
assert(!entriesServer.has(pageId));
|
|
87
87
|
entriesServer.set(pageId, { key, ...resources });
|
|
88
88
|
}
|
|
89
|
-
let
|
|
89
|
+
let filesToMove = [];
|
|
90
90
|
let filesToRemove = [];
|
|
91
|
+
// Copy page assets
|
|
91
92
|
for (const [pageId, entryClient] of entriesClient.entries()) {
|
|
92
93
|
const entryServer = entriesServer.get(pageId);
|
|
93
94
|
if (!entryServer)
|
|
94
95
|
continue;
|
|
95
|
-
const
|
|
96
|
+
const cssToMove = [];
|
|
96
97
|
const cssToRemove = [];
|
|
97
|
-
const
|
|
98
|
+
const assetsToMove = [];
|
|
98
99
|
const assetsToRemove = [];
|
|
99
100
|
entryServer.css.forEach((cssServer) => {
|
|
100
101
|
if (!entryClient.css.some((cssClient) => cssServer.hash === cssClient.hash)) {
|
|
101
|
-
|
|
102
|
+
cssToMove.push(cssServer.src);
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
105
|
cssToRemove.push(cssServer.src);
|
|
@@ -106,17 +107,17 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
106
107
|
});
|
|
107
108
|
entryServer.assets.forEach((assetServer) => {
|
|
108
109
|
if (!entryClient.assets.some((assetClient) => assetServer.hash === assetClient.hash)) {
|
|
109
|
-
|
|
110
|
+
assetsToMove.push(assetServer.src);
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
112
113
|
assetsToRemove.push(assetServer.src);
|
|
113
114
|
}
|
|
114
115
|
});
|
|
115
|
-
if (
|
|
116
|
+
if (cssToMove.length) {
|
|
116
117
|
const { key } = entryClient;
|
|
117
|
-
|
|
118
|
+
filesToMove.push(...cssToMove);
|
|
118
119
|
(_a = clientManifest[key]).css ?? (_a.css = []);
|
|
119
|
-
clientManifest[key].css?.push(...
|
|
120
|
+
clientManifest[key].css?.push(...cssToMove);
|
|
120
121
|
}
|
|
121
122
|
if (cssToRemove.length) {
|
|
122
123
|
const { key } = entryServer;
|
|
@@ -124,11 +125,11 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
124
125
|
(_b = serverManifest[key]).css ?? (_b.css = []);
|
|
125
126
|
serverManifest[key].css = serverManifest[key].css.filter((entry) => !cssToRemove.includes(entry));
|
|
126
127
|
}
|
|
127
|
-
if (
|
|
128
|
+
if (assetsToMove.length) {
|
|
128
129
|
const { key } = entryClient;
|
|
129
|
-
|
|
130
|
+
filesToMove.push(...assetsToMove);
|
|
130
131
|
(_c = clientManifest[key]).assets ?? (_c.assets = []);
|
|
131
|
-
clientManifest[key].assets?.push(...
|
|
132
|
+
clientManifest[key].assets?.push(...assetsToMove);
|
|
132
133
|
}
|
|
133
134
|
if (assetsToRemove.length) {
|
|
134
135
|
const { key } = entryServer;
|
|
@@ -137,11 +138,40 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
137
138
|
serverManifest[key].assets = serverManifest[key].assets.filter((entry) => !assetsToRemove.includes(entry));
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
// Also copy assets of virtual:@brillout/vite-plugin-server-entry:serverEntry
|
|
142
|
+
{
|
|
143
|
+
const filesClientAll = [];
|
|
144
|
+
for (const key in clientManifest) {
|
|
145
|
+
const entry = clientManifest[key];
|
|
146
|
+
filesClientAll.push(entry.file);
|
|
147
|
+
filesClientAll.push(...(entry.assets ?? []));
|
|
148
|
+
filesClientAll.push(...(entry.css ?? []));
|
|
149
|
+
}
|
|
150
|
+
for (const key in serverManifest) {
|
|
151
|
+
const entry = serverManifest[key];
|
|
152
|
+
if (!entry.isEntry)
|
|
153
|
+
continue;
|
|
154
|
+
const resources = collectResources(entry, serverManifest);
|
|
155
|
+
const css = resources.css.map((css) => css.src).filter((file) => !filesClientAll.includes(file));
|
|
156
|
+
const assets = resources.assets.map((asset) => asset.src).filter((file) => !filesClientAll.includes(file));
|
|
157
|
+
filesToMove.push(...css, ...assets);
|
|
158
|
+
if (css.length > 0 || assets.length > 0) {
|
|
159
|
+
assert(!clientManifest[key]);
|
|
160
|
+
clientManifest[key] = {
|
|
161
|
+
...entry,
|
|
162
|
+
css,
|
|
163
|
+
assets,
|
|
164
|
+
dynamicImports: undefined,
|
|
165
|
+
imports: undefined
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
140
170
|
const clientManifestMod = clientManifest;
|
|
141
171
|
const serverManifestMod = serverManifest;
|
|
142
|
-
|
|
143
|
-
filesToRemove = unique(filesToRemove).filter((file) => !
|
|
144
|
-
return { clientManifestMod, serverManifestMod,
|
|
172
|
+
filesToMove = unique(filesToMove);
|
|
173
|
+
filesToRemove = unique(filesToRemove).filter((file) => !filesToMove.includes(file));
|
|
174
|
+
return { clientManifestMod, serverManifestMod, filesToMove, filesToRemove };
|
|
145
175
|
}
|
|
146
176
|
function getPageId(key) {
|
|
147
177
|
// Normalize from:
|
|
@@ -17,6 +17,7 @@ import { getFilePathResolved } from '../shared/getFilePath.js';
|
|
|
17
17
|
import { getConfigValueBuildTime } from '../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
18
18
|
import { getOutDirs, resolveOutDir } from '../shared/getOutDirs.js';
|
|
19
19
|
import { viteIsSSR } from '../shared/viteIsSSR.js';
|
|
20
|
+
import { getVikeConfigPublic } from './commonConfig.js';
|
|
20
21
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
21
22
|
const importMetaUrl = import.meta.url;
|
|
22
23
|
const require_ = createRequire(importMetaUrl);
|
|
@@ -57,11 +58,12 @@ function buildConfig() {
|
|
|
57
58
|
order: 'post',
|
|
58
59
|
handler(config) {
|
|
59
60
|
onSetupBuild();
|
|
61
|
+
const vike = getVikeConfigPublic(config);
|
|
60
62
|
return {
|
|
61
63
|
build: {
|
|
62
64
|
outDir: resolveOutDir(config),
|
|
63
65
|
manifest: manifestTempFile,
|
|
64
|
-
copyPublicDir:
|
|
66
|
+
copyPublicDir: vike.config.viteEnvironmentAPI
|
|
65
67
|
? // Already set by buildApp() plugin
|
|
66
68
|
undefined
|
|
67
69
|
: !viteIsSSR(config)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
|
-
|
|
2
|
+
export { getVikeConfigPublic };
|
|
3
|
+
import { type InlineConfig, type Plugin, type ResolvedConfig, type UserConfig } from 'vite';
|
|
3
4
|
import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
|
|
4
5
|
import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
|
|
5
6
|
declare module 'vite' {
|
|
@@ -9,11 +10,18 @@ declare module 'vite' {
|
|
|
9
10
|
_root?: string;
|
|
10
11
|
_baseViteOriginal?: string;
|
|
11
12
|
_viteConfigEnhanced?: InlineConfig;
|
|
12
|
-
|
|
13
|
-
config: VikeConfigObject['global']['config'];
|
|
14
|
-
pages: VikeConfigObject['pages'];
|
|
15
|
-
prerenderContext?: PrerenderContextPublic;
|
|
16
|
-
};
|
|
13
|
+
_vike?: VikeConfigPublic;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
16
|
+
type VikeConfigPublic = {
|
|
17
|
+
config: VikeConfigObject['global']['config'];
|
|
18
|
+
pages: VikeConfigObject['pages'];
|
|
19
|
+
prerenderContext?: PrerenderContextPublic;
|
|
20
|
+
};
|
|
19
21
|
declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
|
|
22
|
+
/**
|
|
23
|
+
* Get all the information Vike knows about the app in your Vite plugin.
|
|
24
|
+
*
|
|
25
|
+
* https://vike.dev/getVikeConfig
|
|
26
|
+
*/
|
|
27
|
+
declare function getVikeConfigPublic(config: ResolvedConfig | UserConfig): VikeConfigPublic;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
|
+
export { getVikeConfigPublic };
|
|
2
3
|
import { mergeConfig } from 'vite';
|
|
3
4
|
import { assert, assertUsage, assertWarning, findPackageJson, hasProp, isDevCheck, isDocker, isObject } from '../utils.js';
|
|
4
5
|
import { assertRollupInput } from './buildConfig.js';
|
|
@@ -30,7 +31,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
30
31
|
_isDev: isDev,
|
|
31
32
|
_root: root,
|
|
32
33
|
_vikeVitePluginOptions: vikeVitePluginOptions,
|
|
33
|
-
|
|
34
|
+
_vike: {
|
|
34
35
|
pages: vikeConfig.pages,
|
|
35
36
|
config: vikeConfig.global.config
|
|
36
37
|
},
|
|
@@ -168,3 +169,18 @@ function temp_supportOldInterface(config) {
|
|
|
168
169
|
}
|
|
169
170
|
assert(false);
|
|
170
171
|
}
|
|
172
|
+
// TODO/soon rename:
|
|
173
|
+
// - `getVikeConfig()` => `resolveVikeConfig()` ?
|
|
174
|
+
// - `getVikeConfigPublic()` => `getVikeConfig()`
|
|
175
|
+
// - `VikeConfigPublic` => `VikeConfig` ?
|
|
176
|
+
// - `VikeConfigObject` => `VikeConfigInternal` ?
|
|
177
|
+
/**
|
|
178
|
+
* Get all the information Vike knows about the app in your Vite plugin.
|
|
179
|
+
*
|
|
180
|
+
* https://vike.dev/getVikeConfig
|
|
181
|
+
*/
|
|
182
|
+
function getVikeConfigPublic(config) {
|
|
183
|
+
const vikeConfig = config._vike;
|
|
184
|
+
assert(vikeConfig);
|
|
185
|
+
return vikeConfig;
|
|
186
|
+
}
|
|
@@ -48,7 +48,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
48
48
|
sources
|
|
49
49
|
.filter((c) => !c.isOverriden)
|
|
50
50
|
.forEach((configValueSource) => {
|
|
51
|
-
if (!configValueSource.
|
|
51
|
+
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
52
52
|
return;
|
|
53
53
|
const { definedAtFilePath, configEnv } = configValueSource;
|
|
54
54
|
if (!configEnv.client)
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js
CHANGED
|
@@ -63,8 +63,8 @@ function getConfigRequireValue(plusFile) {
|
|
|
63
63
|
const confVal = getConfVal(plusFile, 'require');
|
|
64
64
|
if (!confVal)
|
|
65
65
|
return null;
|
|
66
|
-
assert(confVal.
|
|
67
|
-
const require = confVal.
|
|
66
|
+
assert(confVal.valueIsLoaded);
|
|
67
|
+
const require = confVal.value;
|
|
68
68
|
const { filePathToShowToUserResolved } = plusFile.filePath;
|
|
69
69
|
assert(filePathToShowToUserResolved);
|
|
70
70
|
assertUsage(isObjectOfStrings(require), `The setting ${pc.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${pc.bold('Record<string, string>')}).`);
|
|
@@ -74,8 +74,8 @@ function getNameValue(plusFile) {
|
|
|
74
74
|
const confVal = getConfVal(plusFile, 'name');
|
|
75
75
|
if (!confVal)
|
|
76
76
|
return null;
|
|
77
|
-
assert(confVal.
|
|
78
|
-
const name = confVal.
|
|
77
|
+
assert(confVal.valueIsLoaded);
|
|
78
|
+
const name = confVal.value;
|
|
79
79
|
const filePathToShowToUser = getFilePathToShowToUser(plusFile);
|
|
80
80
|
assertUsage(typeof name === 'string', `The setting ${pc.bold('name')} defined at ${filePathToShowToUser} should be a string.`);
|
|
81
81
|
return name;
|
|
@@ -31,7 +31,12 @@ const configDefinitionsBuiltIn = {
|
|
|
31
31
|
cumulative: true
|
|
32
32
|
},
|
|
33
33
|
route: {
|
|
34
|
-
env: {
|
|
34
|
+
env: {
|
|
35
|
+
server: true,
|
|
36
|
+
client: 'if-client-routing',
|
|
37
|
+
// For vite-plugin-vercel
|
|
38
|
+
config: true
|
|
39
|
+
},
|
|
35
40
|
eager: true
|
|
36
41
|
},
|
|
37
42
|
guard: {
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -3,7 +3,7 @@ export { isPlusFile };
|
|
|
3
3
|
export { getPlusFileValueConfigName };
|
|
4
4
|
import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile, scriptFileExtensionList, createDebugger, deepEqual, assertUsage } from '../../../../utils.js';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import glob from '
|
|
6
|
+
import { glob } from 'tinyglobby';
|
|
7
7
|
import { exec } from 'child_process';
|
|
8
8
|
import { promisify } from 'util';
|
|
9
9
|
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
|
|
@@ -35,10 +35,10 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
35
35
|
// Crawl
|
|
36
36
|
const filesGit = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
37
37
|
const filesGitNothingFound = !filesGit || filesGit.length === 0;
|
|
38
|
-
const filesGlob = (filesGitNothingFound || debug.isActivated) && (await
|
|
38
|
+
const filesGlob = (filesGitNothingFound || debug.isActivated) && (await tinyglobby(userRootDir, outDirRelativeFromUserRootDir));
|
|
39
39
|
let files = !filesGitNothingFound
|
|
40
40
|
? filesGit
|
|
41
|
-
: // Fallback to
|
|
41
|
+
: // Fallback to tinyglobby for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
|
|
42
42
|
filesGlob;
|
|
43
43
|
assert(files);
|
|
44
44
|
if (debug.isActivated)
|
|
@@ -47,7 +47,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
47
47
|
files = files.filter((filePath) => !isTemporaryBuildFile(filePath));
|
|
48
48
|
// Normalize
|
|
49
49
|
const plusFiles = files.map((filePath) => {
|
|
50
|
-
// Both `$ git-ls files` and
|
|
50
|
+
// Both `$ git-ls files` and tinyglobby return posix paths
|
|
51
51
|
assertPosixPath(filePath);
|
|
52
52
|
assert(!filePath.startsWith(userRootDir));
|
|
53
53
|
const filePathAbsoluteUserRootDir = path.posix.join('/', filePath);
|
|
@@ -56,7 +56,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
56
56
|
});
|
|
57
57
|
return plusFiles;
|
|
58
58
|
}
|
|
59
|
-
// Same as
|
|
59
|
+
// Same as tinyglobby() but using `$ git ls-files`
|
|
60
60
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
61
61
|
if (gitIsNotUsable)
|
|
62
62
|
return null;
|
|
@@ -123,13 +123,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
123
123
|
}
|
|
124
124
|
return files;
|
|
125
125
|
}
|
|
126
|
-
// Same as gitLsFiles() but using
|
|
127
|
-
async function
|
|
126
|
+
// Same as gitLsFiles() but using tinyglobby
|
|
127
|
+
async function tinyglobby(userRootDir, outDirRelativeFromUserRootDir) {
|
|
128
128
|
const pattern = `**/+*.${scriptFileExtensions}`;
|
|
129
129
|
const options = {
|
|
130
130
|
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
|
|
131
131
|
cwd: userRootDir,
|
|
132
|
-
dot: false
|
|
132
|
+
dot: false,
|
|
133
|
+
expandDirectories: false
|
|
133
134
|
};
|
|
134
135
|
const files = await glob(pattern, options);
|
|
135
136
|
// Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
|
|
@@ -163,14 +163,17 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
163
163
|
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
164
164
|
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
165
165
|
isVikeExtensionImport;
|
|
166
|
+
// Externalize npm package imports
|
|
166
167
|
assertPosixPath(importPathResolved);
|
|
167
|
-
const
|
|
168
|
+
const isNpmPkgImport = importPathResolved.includes('/node_modules/') ||
|
|
169
|
+
// Linked npm packages
|
|
170
|
+
!importPathResolved.startsWith(userRootDir);
|
|
168
171
|
const isExternal = isPointerImport ||
|
|
169
172
|
// Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
|
|
170
|
-
|
|
173
|
+
isNpmPkgImport;
|
|
171
174
|
if (!isExternal) {
|
|
172
175
|
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
173
|
-
assert(!isPointerImport && !
|
|
176
|
+
assert(!isPointerImport && !isNpmPkgImport);
|
|
174
177
|
if (debug.isActivated)
|
|
175
178
|
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
176
179
|
return resolved;
|
|
@@ -189,7 +192,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
189
192
|
userRootDir
|
|
190
193
|
});
|
|
191
194
|
// We assuming that path aliases always resolve inside `userRootDir`.
|
|
192
|
-
if (filePathAbsoluteUserRootDir && !
|
|
195
|
+
if (filePathAbsoluteUserRootDir && !isNpmPkgImport) {
|
|
193
196
|
// `importPathOriginal` is a path alias.
|
|
194
197
|
// - We have to use esbuild's path alias resolution, because:
|
|
195
198
|
// - Vike doesn't resolve path aliases at all.
|
|
@@ -211,7 +214,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
211
214
|
// Import of runtime code => handled by Vike
|
|
212
215
|
isPointerImport ||
|
|
213
216
|
// Import of config code => loaded by Node.js at build-time
|
|
214
|
-
|
|
217
|
+
isNpmPkgImport);
|
|
215
218
|
pointerImports[importPathTranspiled] = isPointerImport;
|
|
216
219
|
return { external: true, path: importPathTranspiled };
|
|
217
220
|
});
|
|
@@ -26,8 +26,8 @@ declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePlu
|
|
|
26
26
|
declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
|
|
27
27
|
declare function getConfigDefinitionOptional(configDefinitions: ConfigDefinitions, configName: string): ConfigDefinitionInternal | null;
|
|
28
28
|
declare function getConfVal(plusFile: PlusFile, configName: string): null | {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
value: unknown;
|
|
30
|
+
valueIsLoaded: true;
|
|
31
31
|
} | {
|
|
32
|
-
|
|
32
|
+
valueIsLoaded: false;
|
|
33
33
|
};
|