vike 0.4.221-commit-937dbfb → 0.4.222-commit-207e079
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 +1 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +6 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +73 -39
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +37 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +2 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -14
- package/dist/cjs/node/runtime/globalContext.js +24 -8
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/cjs/node/runtime/renderPage.js +4 -8
- package/dist/cjs/node/shared/resolveBase.js +0 -13
- package/dist/cjs/shared/getPageConfigsRuntime.js +10 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +5 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +7 -0
- package/dist/esm/node/plugin/index.d.ts +4 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +6 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +4 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +73 -39
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +38 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +2 -37
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -14
- package/dist/esm/node/runtime/globalContext.d.ts +10 -7
- package/dist/esm/node/runtime/globalContext.js +24 -8
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +8 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/esm/node/runtime/renderPage.js +4 -8
- package/dist/esm/node/shared/resolveBase.d.ts +1 -9
- package/dist/esm/node/shared/resolveBase.js +0 -13
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +2 -1
- package/dist/esm/shared/getPageConfigsRuntime.js +10 -1
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +6 -0
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +9 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSingleInstance.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -4,21 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveBase = resolveBase;
|
|
7
|
-
exports.resolveBaseRuntime = resolveBaseRuntime;
|
|
8
|
-
exports.resolveBaseFromResolvedConfig = resolveBaseFromResolvedConfig;
|
|
9
7
|
const utils_js_1 = require("./utils.js");
|
|
10
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
-
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
12
|
-
let baseViteOriginal = config._baseViteOriginal;
|
|
13
|
-
(0, utils_js_1.assert)(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
14
|
-
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
15
|
-
}
|
|
16
|
-
function resolveBaseRuntime(globalContext) {
|
|
17
|
-
const baseViteOriginal = globalContext.viteConfigRuntime._baseViteOriginal;
|
|
18
|
-
const baseServerUnresolved = globalContext.config.baseServer ?? null;
|
|
19
|
-
const baseAssetsUnresolved = globalContext.config.baseAssets ?? null;
|
|
20
|
-
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
21
|
-
}
|
|
22
9
|
function resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved) {
|
|
23
10
|
if (baseViteOriginal === '/__UNSET__')
|
|
24
11
|
baseViteOriginal = null;
|
|
@@ -10,7 +10,16 @@ function getPageConfigsRuntime(virtualFileExports) {
|
|
|
10
10
|
const allPageIds = getAllPageIds(pageFilesAll, pageConfigs);
|
|
11
11
|
// TODO/now: re-use this call, instead of calling it twice
|
|
12
12
|
const globalConfig = (0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)(pageConfigGlobal);
|
|
13
|
-
|
|
13
|
+
// TODO/now DEDUPE
|
|
14
|
+
const pageConfigsUserFriendly = Object.fromEntries(pageConfigs.map((pageConfig) => {
|
|
15
|
+
const configValues = { ...pageConfigGlobal.configValues, ...pageConfig.configValues };
|
|
16
|
+
const page = {
|
|
17
|
+
...(0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)({ configValues }),
|
|
18
|
+
route: pageConfig.routeFilesystem?.routeString ?? null
|
|
19
|
+
};
|
|
20
|
+
return [pageConfig.pageId, page];
|
|
21
|
+
}));
|
|
22
|
+
return { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly };
|
|
14
23
|
}
|
|
15
24
|
function getAllPageIds(pageFilesAll, pageConfigs) {
|
|
16
25
|
const fileIds = pageFilesAll.filter(({ isDefaultPageFile }) => !isDefaultPageFile).map(({ pageId }) => pageId);
|
|
@@ -10,7 +10,7 @@ const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js")
|
|
|
10
10
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
11
11
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
12
12
|
async function loadPageRoutes(
|
|
13
|
-
// Remove all arguments and use
|
|
13
|
+
// Remove all arguments and use GlobalContextInternal instead?
|
|
14
14
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
15
15
|
// TODO/next-major: remove & make this function sync
|
|
16
16
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -27,7 +27,7 @@ function assertSingleInstance() {
|
|
|
27
27
|
const versions = (0, unique_js_1.unique)(globalObject.instances);
|
|
28
28
|
assertUsage(versions.length <= 1,
|
|
29
29
|
// DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
|
|
30
|
-
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but
|
|
30
|
+
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but it's forbidden to load different versions`);
|
|
31
31
|
}
|
|
32
32
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
33
33
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|
|
@@ -17,5 +17,10 @@ type RenderArgs = {
|
|
|
17
17
|
pageContextInitClient?: Record<string, unknown>;
|
|
18
18
|
};
|
|
19
19
|
declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
|
|
20
|
+
declare global {
|
|
21
|
+
var _vike: {
|
|
22
|
+
fullyRenderedUrl?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
20
25
|
declare function disableClientRouting(err: unknown, log: boolean): void;
|
|
21
26
|
declare function getRenderCount(): number;
|
|
@@ -484,8 +484,15 @@ async function renderPageClientSide(renderArgs) {
|
|
|
484
484
|
// Add link prefetch handlers
|
|
485
485
|
addLinkPrefetchHandlers_watch();
|
|
486
486
|
addLinkPrefetchHandlers();
|
|
487
|
+
stampFinished(urlOriginal);
|
|
487
488
|
}
|
|
488
489
|
}
|
|
490
|
+
// For Vike tests (but also potentially for Vike users)
|
|
491
|
+
// https://github.com/vikejs/vike/blob/ffbc5cf16407bcc075f414447e50d997c87c0c94/test/playground/pages/nested-layout/e2e-test.ts#L59
|
|
492
|
+
function stampFinished(urlOriginal) {
|
|
493
|
+
window._vike ?? (window._vike = {});
|
|
494
|
+
window._vike.fullyRenderedUrl = urlOriginal;
|
|
495
|
+
}
|
|
489
496
|
function changeUrl(url, overwriteLastHistoryEntry) {
|
|
490
497
|
if (getCurrentUrl() === url)
|
|
491
498
|
return;
|
|
@@ -4,7 +4,10 @@ export { plugin as ssr };
|
|
|
4
4
|
export type { VikeVitePluginOptions as UserConfig };
|
|
5
5
|
export type { VikeVitePluginOptions };
|
|
6
6
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
7
|
-
|
|
7
|
+
type PluginInterop = Record<string, unknown> & {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): PluginInterop[];
|
|
8
11
|
/** @deprecated Define Vike settings in +config.js instead of vite.config.js */
|
|
9
12
|
type VikeVitePluginOptions = {
|
|
10
13
|
/** @deprecated Define Vike settings in +config.js instead of vite.config.js */
|
|
@@ -29,7 +29,7 @@ import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegres
|
|
|
29
29
|
import { buildApp } from './plugins/buildApp.js';
|
|
30
30
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
31
31
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
32
|
-
// Return
|
|
32
|
+
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
33
33
|
function plugin(vikeVitePluginOptions = {}) {
|
|
34
34
|
const plugins = [
|
|
35
35
|
...commonConfig(vikeVitePluginOptions),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
|
-
import { resolveBase
|
|
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
5
|
function baseUrls() {
|
|
@@ -38,3 +38,8 @@ function baseUrls() {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
42
|
+
let baseViteOriginal = config._baseViteOriginal;
|
|
43
|
+
assert(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
44
|
+
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
45
|
+
}
|
|
@@ -30,7 +30,10 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
30
30
|
_isDev: isDev,
|
|
31
31
|
_root: root,
|
|
32
32
|
_vikeVitePluginOptions: vikeVitePluginOptions,
|
|
33
|
-
vike: {
|
|
33
|
+
vike: {
|
|
34
|
+
pages: vikeConfig.pages,
|
|
35
|
+
config: vikeConfig.global.config
|
|
36
|
+
},
|
|
34
37
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
35
38
|
configVikePromise: Promise.resolve({
|
|
36
39
|
prerender: isPrerenderEnabled(vikeConfig)
|
|
@@ -10,8 +10,8 @@ import { vikeConfigDependencies, reloadVikeConfig, isV1Design, getVikeConfig } f
|
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { logConfigInfo } from '../../shared/loggerNotProd.js';
|
|
12
12
|
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
13
|
-
import { getPlusFileValueConfigName } from './v1-design/getVikeConfig/getPlusFilesAll.js';
|
|
14
13
|
import { updateUserFiles } from '../../../runtime/globalContext.js';
|
|
14
|
+
import { isPlusFile } from './v1-design/getVikeConfig/crawlPlusFiles.js';
|
|
15
15
|
function importUserCode() {
|
|
16
16
|
let config;
|
|
17
17
|
let vikeConfig;
|
|
@@ -68,50 +68,55 @@ function handleFileAddRemove(server, config) {
|
|
|
68
68
|
return;
|
|
69
69
|
function listener(file, isRemove) {
|
|
70
70
|
file = normalizePath(file);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const virtualModules = getVirtualModules(server);
|
|
74
|
-
virtualModules.forEach((mod) => {
|
|
75
|
-
server.moduleGraph.invalidateModule(mod);
|
|
76
|
-
});
|
|
71
|
+
if (isPlusFile(file) || isVikeConfigDependency(file, server.moduleGraph)?.modifiesVikeVirtualFiles) {
|
|
72
|
+
invalidateVikeVirtualFiles(server);
|
|
77
73
|
reloadConfig(file, config, isRemove ? 'removed' : 'created');
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
76
|
}
|
|
77
|
+
function invalidateVikeVirtualFiles(server) {
|
|
78
|
+
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
79
|
+
vikeVirtualFiles.forEach((mod) => {
|
|
80
|
+
server.moduleGraph.invalidateModule(mod);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
81
83
|
function handleHotUpdate(ctx, config) {
|
|
82
84
|
const { file, server } = ctx;
|
|
83
|
-
const isVikeConfig =
|
|
84
|
-
const isViteModule = ctx.modules.length > 0;
|
|
85
|
-
/* Should we show this?
|
|
86
|
-
// - Can be useful for server files that aren't processed by Vite.
|
|
87
|
-
// - Can be annoying for files that obviously aren't processed by Vite.
|
|
88
|
-
if (!isVikeConfig && !isViteModule) {
|
|
89
|
-
logViteAny(
|
|
90
|
-
`${msg} — ${pc.cyan('no HMR')}, see https://vike.dev/on-demand-compiler`,
|
|
91
|
-
'info',
|
|
92
|
-
null,
|
|
93
|
-
true
|
|
94
|
-
)
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
//*/
|
|
98
|
-
// It can hide an error it shouldn't hide (because the error isn't shown again), but it's ok since users can reload the page and the error will be shown again (Vite transpilation errors are shown again upon a page reload).
|
|
99
|
-
if (!isVikeConfig && isViteModule) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
85
|
+
const isVikeConfig = isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
|
|
102
86
|
if (isVikeConfig) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
if (isVikeConfig.modifiesVikeVirtualFiles) {
|
|
88
|
+
/* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
|
|
89
|
+
const isViteModule = ctx.modules.length > 0
|
|
90
|
+
assert(!isViteModule)
|
|
91
|
+
*/
|
|
92
|
+
// Ensure server.ssrLoadModule() loads fresh Vike virtual files (`reloadConfig()` > `updateUserFiles()` > `server.ssrLoadModule()`)
|
|
93
|
+
invalidateVikeVirtualFiles(server);
|
|
94
|
+
reloadConfig(file, config, 'modified');
|
|
95
|
+
// Triggers a full page reload
|
|
96
|
+
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
97
|
+
return vikeVirtualFiles;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Ensure we invalidate `file` *before* server.ssrLoadModule() in updateUserFiles()
|
|
101
|
+
// Vite already invalidates it, but possibly *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
102
|
+
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
103
|
+
updateUserFiles();
|
|
104
|
+
}
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
|
-
function
|
|
107
|
+
function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
|
|
108
|
+
// Check config-only files, for example all pages/+config.js dependencies. (There aren't part of Vite's module graph.)
|
|
112
109
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
113
110
|
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
114
|
-
|
|
111
|
+
if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
|
|
112
|
+
return { modifiesVikeVirtualFiles: true };
|
|
113
|
+
// Check using Vite's module graph, for example all +htmlAttributes dependencies.
|
|
114
|
+
// Alternatively, simply call updateUserFiles() on every handleHotUpdate() call.
|
|
115
|
+
const importers = getImporters(filePathAbsoluteFilesystem, moduleGraph);
|
|
116
|
+
const isPlusValueFileDependency = Array.from(importers).some((importer) => importer.file && isPlusFile(importer.file));
|
|
117
|
+
if (isPlusValueFileDependency)
|
|
118
|
+
return { modifiesVikeVirtualFiles: false };
|
|
119
|
+
return null;
|
|
115
120
|
}
|
|
116
121
|
function reloadConfig(filePath, config, op) {
|
|
117
122
|
{
|
|
@@ -122,16 +127,45 @@ function reloadConfig(filePath, config, op) {
|
|
|
122
127
|
reloadVikeConfig(config);
|
|
123
128
|
updateUserFiles();
|
|
124
129
|
}
|
|
125
|
-
function
|
|
126
|
-
const
|
|
130
|
+
function getVikeVirtualFiles(server) {
|
|
131
|
+
const vikeVirtualFiles = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
127
132
|
.filter((url) => isVirtualFileIdPageConfigValuesAll(url) || isVirtualFileIdImportUserCode(url))
|
|
128
133
|
.map((url) => {
|
|
129
134
|
const mod = server.moduleGraph.urlToModuleMap.get(url);
|
|
130
135
|
assert(mod);
|
|
131
136
|
return mod;
|
|
132
137
|
});
|
|
133
|
-
return
|
|
138
|
+
return vikeVirtualFiles;
|
|
139
|
+
}
|
|
140
|
+
// Get all transitive importers (including the module itself)
|
|
141
|
+
function getImporters(file, moduleGraph) {
|
|
142
|
+
const importers = new Set();
|
|
143
|
+
const mods = moduleGraph.getModulesByFile(file);
|
|
144
|
+
if (!mods)
|
|
145
|
+
return importers;
|
|
146
|
+
for (const mod of mods) {
|
|
147
|
+
getModuleImporters(mod).forEach((importer) => {
|
|
148
|
+
if (importer)
|
|
149
|
+
importers.add(importer);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return importers;
|
|
134
153
|
}
|
|
135
|
-
function
|
|
136
|
-
|
|
154
|
+
function getModuleImporters(mod, seen = new Set()) {
|
|
155
|
+
if (seen.has(mod))
|
|
156
|
+
return new Set();
|
|
157
|
+
seen.add(mod);
|
|
158
|
+
const importers = new Set();
|
|
159
|
+
if (mod.id)
|
|
160
|
+
importers.add(mod);
|
|
161
|
+
// Traverse through the importers (modules that import this module)
|
|
162
|
+
for (const importer of mod.importers) {
|
|
163
|
+
if (importer.id)
|
|
164
|
+
importers.add(importer);
|
|
165
|
+
getModuleImporters(importer, seen).forEach((importerTransitive) => {
|
|
166
|
+
if (importerTransitive)
|
|
167
|
+
importers.add(importerTransitive);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return importers;
|
|
137
171
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
+
export { isPlusFile };
|
|
3
|
+
export { getPlusFileValueConfigName };
|
|
2
4
|
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string): Promise<{
|
|
3
5
|
filePathAbsoluteUserRootDir: string;
|
|
4
6
|
}[]>;
|
|
7
|
+
declare function isPlusFile(filePath: string): boolean;
|
|
8
|
+
declare function getPlusFileValueConfigName(filePath: string): string | null;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
|
|
2
|
+
export { isPlusFile };
|
|
3
|
+
export { getPlusFileValueConfigName };
|
|
4
|
+
import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile, scriptFileExtensionList, createDebugger, deepEqual, assertUsage } from '../../../../utils.js';
|
|
3
5
|
import path from 'path';
|
|
4
6
|
import glob from 'fast-glob';
|
|
5
7
|
import { exec } from 'child_process';
|
|
@@ -49,6 +51,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
49
51
|
assertPosixPath(filePath);
|
|
50
52
|
assert(!filePath.startsWith(userRootDir));
|
|
51
53
|
const filePathAbsoluteUserRootDir = path.posix.join('/', filePath);
|
|
54
|
+
assert(isPlusFile(filePathAbsoluteUserRootDir));
|
|
52
55
|
return { filePathAbsoluteUserRootDir };
|
|
53
56
|
});
|
|
54
57
|
return plusFiles;
|
|
@@ -223,3 +226,37 @@ function isGitCrawlDisabled() {
|
|
|
223
226
|
const crawSettings = getEnvVarObject('VIKE_CRAWL');
|
|
224
227
|
return crawSettings?.git === false;
|
|
225
228
|
}
|
|
229
|
+
function isPlusFile(filePath) {
|
|
230
|
+
assertPosixPath(filePath);
|
|
231
|
+
if (isTemporaryBuildFile(filePath))
|
|
232
|
+
return false;
|
|
233
|
+
const fileName = filePath.split('/').pop();
|
|
234
|
+
return fileName.startsWith('+');
|
|
235
|
+
}
|
|
236
|
+
function getPlusFileValueConfigName(filePath) {
|
|
237
|
+
if (!isPlusFile(filePath))
|
|
238
|
+
return null;
|
|
239
|
+
const fileName = path.posix.basename(filePath);
|
|
240
|
+
// assertNoUnexpectedPlusSign(filePath, fileName)
|
|
241
|
+
const basename = fileName.split('.')[0];
|
|
242
|
+
assert(basename.startsWith('+'));
|
|
243
|
+
const configName = basename.slice(1);
|
|
244
|
+
assertUsage(configName !== '', `${filePath} Invalid filename ${fileName}`);
|
|
245
|
+
return configName;
|
|
246
|
+
}
|
|
247
|
+
/* https://github.com/vikejs/vike/issues/1407
|
|
248
|
+
function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
249
|
+
const dirs = path.posix.dirname(filePath).split('/')
|
|
250
|
+
dirs.forEach((dir, i) => {
|
|
251
|
+
const dirPath = dirs.slice(0, i + 1).join('/')
|
|
252
|
+
assertUsage(
|
|
253
|
+
!dir.includes('+'),
|
|
254
|
+
`Character '+' is a reserved character: remove '+' from the directory name ${dirPath}/`
|
|
255
|
+
)
|
|
256
|
+
})
|
|
257
|
+
assertUsage(
|
|
258
|
+
!fileName.slice(1).includes('+'),
|
|
259
|
+
`Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
*/
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { getPlusFilesAll };
|
|
2
|
-
export { getPlusFileValueConfigName };
|
|
3
2
|
export type { PlusFileValue };
|
|
4
3
|
export type { PlusFile };
|
|
5
4
|
export type { PlusFilesByLocationId };
|
|
@@ -36,4 +35,3 @@ type PlusFileValue = PlusFileCommons & {
|
|
|
36
35
|
};
|
|
37
36
|
type PlusFilesByLocationId = Record<LocationId, PlusFile[]>;
|
|
38
37
|
declare function getPlusFilesAll(userRootDir: string, esbuildCache: EsbuildCache): Promise<PlusFilesByLocationId>;
|
|
39
|
-
declare function getPlusFileValueConfigName(filePath: string): string | null;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
export { getPlusFilesAll };
|
|
2
|
-
|
|
3
|
-
import { assert, assertPosixPath, assertUsage } from '../../../../utils.js';
|
|
2
|
+
import { assert } from '../../../../utils.js';
|
|
4
3
|
import { configDefinitionsBuiltIn } from './configDefinitionsBuiltIn.js';
|
|
5
4
|
import { getLocationId } from './filesystemRouting.js';
|
|
6
|
-
import {
|
|
7
|
-
import { crawlPlusFiles } from './crawlPlusFiles.js';
|
|
5
|
+
import { crawlPlusFiles, getPlusFileValueConfigName } from './crawlPlusFiles.js';
|
|
8
6
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
9
7
|
import { loadConfigFile, loadValueFile } from './loadFileAtConfigTime.js';
|
|
10
8
|
import { resolvePointerImport } from './resolvePointerImport.js';
|
|
11
9
|
import { getFilePathResolved } from '../../../../shared/getFilePath.js';
|
|
12
10
|
import { assertExtensionsConventions } from './assertExtensions.js';
|
|
13
|
-
import path from 'node:path';
|
|
14
11
|
async function getPlusFilesAll(userRootDir, esbuildCache) {
|
|
15
12
|
const plusFiles = await findPlusFiles(userRootDir, null);
|
|
16
13
|
const configFiles = [];
|
|
@@ -120,35 +117,3 @@ async function findPlusFiles(userRootDir, outDirRoot) {
|
|
|
120
117
|
const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
|
|
121
118
|
return plusFiles;
|
|
122
119
|
}
|
|
123
|
-
function getPlusFileValueConfigName(filePath) {
|
|
124
|
-
assertPosixPath(filePath);
|
|
125
|
-
if (isTemporaryBuildFile(filePath))
|
|
126
|
-
return null;
|
|
127
|
-
const fileName = path.posix.basename(filePath);
|
|
128
|
-
// assertNoUnexpectedPlusSign(filePath, fileName)
|
|
129
|
-
const basename = fileName.split('.')[0];
|
|
130
|
-
if (!basename.startsWith('+')) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
const configName = basename.slice(1);
|
|
135
|
-
assertUsage(configName !== '', `${filePath} Invalid filename ${fileName}`);
|
|
136
|
-
return configName;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/* https://github.com/vikejs/vike/issues/1407
|
|
140
|
-
function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
141
|
-
const dirs = path.posix.dirname(filePath).split('/')
|
|
142
|
-
dirs.forEach((dir, i) => {
|
|
143
|
-
const dirPath = dirs.slice(0, i + 1).join('/')
|
|
144
|
-
assertUsage(
|
|
145
|
-
!dir.includes('+'),
|
|
146
|
-
`Character '+' is a reserved character: remove '+' from the directory name ${dirPath}/`
|
|
147
|
-
)
|
|
148
|
-
})
|
|
149
|
-
assertUsage(
|
|
150
|
-
!fileName.slice(1).includes('+'),
|
|
151
|
-
`Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
*/
|
|
@@ -23,6 +23,7 @@ if (debugEsbuildResolve.isActivated)
|
|
|
23
23
|
debugEsbuildResolve('esbuild version', version);
|
|
24
24
|
async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig, esbuildCache) {
|
|
25
25
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
26
|
+
assert(filePathAbsoluteFilesystem);
|
|
26
27
|
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
27
28
|
if (esbuildCache[filePathAbsoluteFilesystem]) {
|
|
28
29
|
return await esbuildCache[filePathAbsoluteFilesystem];
|
|
@@ -49,6 +50,7 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
|
|
|
49
50
|
}
|
|
50
51
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
51
52
|
const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
|
|
53
|
+
assert(filePathAbsoluteFilesystem);
|
|
52
54
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
53
55
|
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
54
56
|
if (debug.isActivated)
|
|
@@ -9,12 +9,13 @@ export type { VikeConfigObject };
|
|
|
9
9
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
10
10
|
import { type ConfigDefinitions, type ConfigDefinitionInternal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
11
11
|
import type { ResolvedConfig } from 'vite';
|
|
12
|
-
import {
|
|
12
|
+
import { type ConfigUserFriendly, type PageConfigsUserFriendly } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
13
13
|
import { type PlusFile } from './getVikeConfig/getPlusFilesAll.js';
|
|
14
14
|
type VikeConfigObject = {
|
|
15
15
|
pageConfigs: PageConfigBuildTime[];
|
|
16
16
|
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
17
|
-
global:
|
|
17
|
+
global: ConfigUserFriendly;
|
|
18
|
+
pages: PageConfigsUserFriendly;
|
|
18
19
|
};
|
|
19
20
|
declare const vikeConfigDependencies: Set<string>;
|
|
20
21
|
declare function reloadVikeConfig(config: ResolvedConfig): void;
|
|
@@ -31,6 +31,7 @@ function reloadVikeConfig(config) {
|
|
|
31
31
|
const userRootDir = config.root;
|
|
32
32
|
const vikeVitePluginOptions = config._vikeVitePluginOptions;
|
|
33
33
|
assert(vikeVitePluginOptions);
|
|
34
|
+
// TODO/now: unify with esbuildCache
|
|
34
35
|
vikeConfigDependencies.clear();
|
|
35
36
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, vikeVitePluginOptions);
|
|
36
37
|
handleReloadSideEffects();
|
|
@@ -126,7 +127,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
126
127
|
configDefinitions: {},
|
|
127
128
|
configValueSources: {}
|
|
128
129
|
},
|
|
129
|
-
global: getPageConfigUserFriendlyNew({ configValues: {} })
|
|
130
|
+
global: getPageConfigUserFriendlyNew({ configValues: {} }),
|
|
131
|
+
pages: {}
|
|
130
132
|
};
|
|
131
133
|
return dummyData;
|
|
132
134
|
}
|
|
@@ -135,15 +137,26 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
135
137
|
async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
136
138
|
const esbuildCache = {};
|
|
137
139
|
const plusFilesAll = await getPlusFilesAll(userRootDir, esbuildCache);
|
|
138
|
-
// assertKnownConfigs(plusFilesAll)
|
|
139
140
|
const configDefinitionsResolved = await resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache);
|
|
141
|
+
assertKnownConfigs(configDefinitionsResolved, plusFilesAll);
|
|
140
142
|
const { pageConfigGlobal, pageConfigs } = getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRootDir);
|
|
141
143
|
// interop vike(options) in vite.config.js
|
|
142
144
|
temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, userRootDir);
|
|
143
145
|
// global
|
|
144
|
-
const
|
|
145
|
-
const global = getPageConfigUserFriendlyNew({ configValues });
|
|
146
|
-
|
|
146
|
+
const configValuesGlobal = getConfigValues(pageConfigGlobal);
|
|
147
|
+
const global = getPageConfigUserFriendlyNew({ configValues: configValuesGlobal });
|
|
148
|
+
// TODO/now DEDUPE
|
|
149
|
+
// pages
|
|
150
|
+
const pages = objectFromEntries(pageConfigs.map((pageConfig) => {
|
|
151
|
+
const configValuesLocal = getConfigValues(pageConfig, true);
|
|
152
|
+
const configValues = { ...configValuesGlobal, ...configValuesLocal };
|
|
153
|
+
const page = {
|
|
154
|
+
...getPageConfigUserFriendlyNew({ configValues }),
|
|
155
|
+
route: pageConfig.routeFilesystem?.routeString ?? null
|
|
156
|
+
};
|
|
157
|
+
return [pageConfig.pageId, page];
|
|
158
|
+
}));
|
|
159
|
+
return { pageConfigs, pageConfigGlobal, global, pages };
|
|
147
160
|
}
|
|
148
161
|
async function resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache) {
|
|
149
162
|
const configDefinitionsGlobal = getConfigDefinitions(
|
|
@@ -283,7 +296,7 @@ function assertOnBeforeRenderEnv(pageConfig) {
|
|
|
283
296
|
// When using Server Routing, loading a onBeforeRender() hook on the client-side hasn't any effect (the Server Routing's client runtime never calls it); it unnecessarily bloats client bundle sizes
|
|
284
297
|
assertUsage(!(onBeforeRenderEnv.client && !isClientRouting), `Page ${pageConfig.pageId} has an onBeforeRender() hook with env ${pc.cyan(JSON.stringify(onBeforeRenderEnv))} which doesn't make sense because the page is using Server Routing: onBeforeRender() can be run in the client only when using Client Routing.`);
|
|
285
298
|
}
|
|
286
|
-
function getConfigValues(pageConfig) {
|
|
299
|
+
function getConfigValues(pageConfig, tolerateMissingValue) {
|
|
287
300
|
const configValues = {};
|
|
288
301
|
getConfigValuesBase(pageConfig, (configEnv) => !!configEnv.config, null).forEach((entry) => {
|
|
289
302
|
if (entry.configValueBase.type === 'computed') {
|
|
@@ -294,7 +307,11 @@ function getConfigValues(pageConfig) {
|
|
|
294
307
|
if (entry.configValueBase.type === 'standard') {
|
|
295
308
|
assert('sourceRelevant' in entry); // Help TS
|
|
296
309
|
const { configValueBase, sourceRelevant, configName } = entry;
|
|
297
|
-
|
|
310
|
+
if (!sourceRelevant.valueIsLoaded) {
|
|
311
|
+
if (tolerateMissingValue)
|
|
312
|
+
return;
|
|
313
|
+
assert(false);
|
|
314
|
+
}
|
|
298
315
|
const { value } = sourceRelevant;
|
|
299
316
|
configValues[configName] = { ...configValueBase, value };
|
|
300
317
|
}
|
|
@@ -303,9 +320,18 @@ function getConfigValues(pageConfig) {
|
|
|
303
320
|
const { configValueBase, sourcesRelevant, configName } = entry;
|
|
304
321
|
const values = [];
|
|
305
322
|
sourcesRelevant.forEach((source) => {
|
|
306
|
-
|
|
323
|
+
if (!source.valueIsLoaded) {
|
|
324
|
+
if (tolerateMissingValue)
|
|
325
|
+
return;
|
|
326
|
+
assert(false);
|
|
327
|
+
}
|
|
307
328
|
values.push(source.value);
|
|
308
329
|
});
|
|
330
|
+
if (values.length === 0) {
|
|
331
|
+
if (tolerateMissingValue)
|
|
332
|
+
return;
|
|
333
|
+
assert(false);
|
|
334
|
+
}
|
|
309
335
|
configValues[configName] = { ...configValueBase, value: values };
|
|
310
336
|
}
|
|
311
337
|
});
|
|
@@ -350,7 +376,6 @@ function getPlusFilesRelevant(plusFilesAll, locationIdPage) {
|
|
|
350
376
|
return plusFilesRelevant;
|
|
351
377
|
}
|
|
352
378
|
function sortForGlobal(plusFilesAll) {
|
|
353
|
-
const locationIdsAll = objectKeys(plusFilesAll);
|
|
354
379
|
const plusFilesAllSorted = Object.fromEntries(objectEntries(plusFilesAll)
|
|
355
380
|
.sort(lowerFirst(([locationId]) => locationId.split('/').length))
|
|
356
381
|
.sort(makeFirst(([locationId]) => isGlobalLocation(locationId, plusFilesAll))));
|
|
@@ -747,13 +772,13 @@ function getComputed(configValueSources, configDefinitions) {
|
|
|
747
772
|
return configValuesComputed;
|
|
748
773
|
}
|
|
749
774
|
// Show error message upon unknown config
|
|
750
|
-
function assertKnownConfigs(plusFilesAll) {
|
|
775
|
+
function assertKnownConfigs(configDefinitionsResolved, plusFilesAll) {
|
|
751
776
|
const configDefinitionsAll = getConfigDefinitions(plusFilesAll);
|
|
752
777
|
const configNamesKnownAll = Object.keys(configDefinitionsAll);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
const configDefinitionsLocal =
|
|
756
|
-
const configNamesKnownLocal = Object.keys(configDefinitionsLocal);
|
|
778
|
+
const configNamesGlobal = Object.keys(configDefinitionsResolved.configDefinitionsGlobal);
|
|
779
|
+
objectEntries(configDefinitionsResolved.configDefinitionsLocal).forEach(([_locationId, { configDefinitions, plusFiles }]) => {
|
|
780
|
+
const configDefinitionsLocal = configDefinitions;
|
|
781
|
+
const configNamesKnownLocal = [...Object.keys(configDefinitionsLocal), ...configNamesGlobal];
|
|
757
782
|
plusFiles.forEach((plusFile) => {
|
|
758
783
|
const configNames = getDefiningConfigNames(plusFile);
|
|
759
784
|
configNames.forEach((configName) => {
|
|
@@ -16,23 +16,25 @@ export { assertBuildInfo };
|
|
|
16
16
|
export { getViteConfigRuntime };
|
|
17
17
|
export { updateUserFiles };
|
|
18
18
|
export type { BuildInfo };
|
|
19
|
-
export type {
|
|
19
|
+
export type { GlobalContextInternal };
|
|
20
20
|
export type { GlobalContextPublic };
|
|
21
21
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
22
22
|
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
23
|
-
import type { ConfigUserFriendly } from '../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
23
|
+
import type { ConfigUserFriendly, PageConfigsUserFriendly } from '../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
24
24
|
import type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
|
|
25
|
-
|
|
25
|
+
import { type BaseUrlsResolved } from '../shared/resolveBase.js';
|
|
26
|
+
type GlobalContextPublic = Pick<GlobalContext, 'assetsManifest' | 'config' | 'viteConfig' | 'pages' | 'baseAssets' | 'baseServer'>;
|
|
26
27
|
type PageRuntimeInfo = Awaited<ReturnType<typeof getUserFiles>>;
|
|
27
|
-
type
|
|
28
|
+
type GlobalContextInternal = GlobalContext & {
|
|
28
29
|
globalContext_public: GlobalContextPublic;
|
|
29
30
|
};
|
|
30
|
-
type
|
|
31
|
+
type GlobalContext = {
|
|
31
32
|
viteConfigRuntime: {
|
|
32
33
|
_baseViteOriginal: null | string;
|
|
33
34
|
};
|
|
34
35
|
config: ConfigUserFriendly['config'];
|
|
35
|
-
|
|
36
|
+
pages: PageConfigsUserFriendly;
|
|
37
|
+
} & BaseUrlsResolved & PageRuntimeInfo & ({
|
|
36
38
|
isProduction: false;
|
|
37
39
|
isPrerendering: false;
|
|
38
40
|
viteConfig: ResolvedConfig;
|
|
@@ -50,7 +52,7 @@ type GlobalContextWithoutPublicCopy = {
|
|
|
50
52
|
usesClientRouter: boolean;
|
|
51
53
|
viteConfig: ResolvedConfig;
|
|
52
54
|
})));
|
|
53
|
-
declare function getGlobalContextInternal(): Promise<
|
|
55
|
+
declare function getGlobalContextInternal(): Promise<GlobalContextInternal>;
|
|
54
56
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
55
57
|
declare function getGlobalContextSync(): GlobalContextPublic;
|
|
56
58
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
@@ -71,6 +73,7 @@ declare function getUserFiles(): Promise<{
|
|
|
71
73
|
allPageIds: string[];
|
|
72
74
|
pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
73
75
|
onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
76
|
+
pages: PageConfigsUserFriendly;
|
|
74
77
|
config: import("../../shared/page-configs/Config/PageContextConfig.js").ConfigResolved;
|
|
75
78
|
}>;
|
|
76
79
|
declare function setGlobalContext_buildEntry(buildEntry: unknown): Promise<void>;
|