vike 0.4.150-commit-d9acc70 → 0.4.150-commit-d0822a3
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 +0 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +3 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +17 -36
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +38 -0
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +50 -18
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -0
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -1
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +33 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/cjs/utils/getDependencyPackageJson.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +1 -1
- package/dist/cjs/utils/injectRollupInputs.js +29 -0
- package/dist/cjs/utils/isPlainObject.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/requireResolve.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +105 -66
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/node/plugin/index.js +0 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +17 -36
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +1 -1
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +32 -0
- package/dist/esm/node/plugin/plugins/importBuild/index.js +52 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -0
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +2 -1
- package/dist/esm/node/runtime/renderPage/{executeOnBeforeRenderHook.d.ts → executeOnBeforeRenderAndDataHooks.d.ts} +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +30 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/esm/shared/VikeNamespace.d.ts +2 -1
- package/dist/esm/shared/page-configs/Config.d.ts +22 -5
- package/dist/esm/shared/types.d.ts +5 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/getDependencyPackageJson.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +1 -1
- package/dist/esm/utils/injectRollupInputs.d.ts +7 -0
- package/dist/esm/utils/injectRollupInputs.js +26 -0
- package/dist/esm/utils/isPlainObject.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +9 -2
- package/dist/cjs/node/plugin/plugins/manifest.js +0 -59
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -23
- package/dist/esm/node/plugin/plugins/manifest.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/manifest.js +0 -53
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -20
|
@@ -12,7 +12,6 @@ const buildConfig_js_1 = require("./plugins/buildConfig.js");
|
|
|
12
12
|
const previewConfig_js_1 = require("./plugins/previewConfig.js");
|
|
13
13
|
const autoFullBuild_js_1 = require("./plugins/autoFullBuild.js");
|
|
14
14
|
const index_js_1 = require("./plugins/devConfig/index.js");
|
|
15
|
-
const manifest_js_1 = require("./plugins/manifest.js");
|
|
16
15
|
const packageJsonFile_js_1 = require("./plugins/packageJsonFile.js");
|
|
17
16
|
const removeRequireHookPlugin_js_1 = require("./plugins/removeRequireHookPlugin.js");
|
|
18
17
|
const index_js_2 = require("./plugins/importUserCode/index.js");
|
|
@@ -39,7 +38,6 @@ function plugin(vikeConfig) {
|
|
|
39
38
|
(0, buildConfig_js_1.buildConfig)(),
|
|
40
39
|
(0, previewConfig_js_1.previewConfig)(),
|
|
41
40
|
...(0, autoFullBuild_js_1.autoFullBuild)(),
|
|
42
|
-
...(0, manifest_js_1.manifest)(),
|
|
43
41
|
(0, packageJsonFile_js_1.packageJsonFile)(),
|
|
44
42
|
(0, removeRequireHookPlugin_js_1.removeRequireHookPlugin)(),
|
|
45
43
|
(0, distFileNames_js_1.distFileNames)(),
|
|
@@ -63,9 +63,10 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
63
63
|
return; // already triggered
|
|
64
64
|
if (isDisabled(configVike))
|
|
65
65
|
return;
|
|
66
|
+
/* Is this @vitejs/plugin-legacy workaround still needed? Should we re-implement it?
|
|
66
67
|
// vike.json missing => it isn't a `$ vite build` call (e.g. @vitejs/plugin-legacy calls Vite's build() API) => skip
|
|
67
|
-
if (!bundle['vike.json'])
|
|
68
|
-
|
|
68
|
+
if (!bundle['vike.json']) return
|
|
69
|
+
*/
|
|
69
70
|
const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
|
|
70
71
|
const configInline = {
|
|
71
72
|
...configFromCli,
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
9
8
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
10
9
|
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
11
10
|
const findPageFiles_js_1 = require("../shared/findPageFiles.js");
|
|
@@ -16,7 +15,7 @@ const module_1 = require("module");
|
|
|
16
15
|
const getClientEntryFilePath_js_1 = require("../../shared/getClientEntryFilePath.js");
|
|
17
16
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
17
|
const path_1 = __importDefault(require("path"));
|
|
19
|
-
// @ts-ignore
|
|
18
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
20
19
|
const importMetaUrl = `file://${__filename}`;
|
|
21
20
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
22
21
|
const manifestTempFile = '_temp_manifest.json';
|
|
@@ -30,14 +29,9 @@ function buildConfig() {
|
|
|
30
29
|
order: 'post',
|
|
31
30
|
async handler(config) {
|
|
32
31
|
assertRollupInput(config);
|
|
33
|
-
const userInputs = normalizeRollupInput(config.build.rollupOptions.input);
|
|
34
32
|
const entries = await getEntries(config);
|
|
35
33
|
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
36
|
-
|
|
37
|
-
...entries,
|
|
38
|
-
...userInputs
|
|
39
|
-
};
|
|
40
|
-
config.build.rollupOptions.input = input;
|
|
34
|
+
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)(entries, config);
|
|
41
35
|
addLogHook();
|
|
42
36
|
}
|
|
43
37
|
},
|
|
@@ -76,12 +70,12 @@ async function getEntries(config) {
|
|
|
76
70
|
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, false);
|
|
77
71
|
(0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
78
72
|
if ((0, utils_js_1.viteIsSSR)(config)) {
|
|
79
|
-
const
|
|
73
|
+
const pageEntries = getPageEntries(pageConfigs);
|
|
80
74
|
const entries = {
|
|
81
|
-
|
|
82
|
-
importBuild: resolve('dist/esm/node/importBuild.js'),
|
|
75
|
+
// importBuild: resolve('dist/esm/node/importBuild.js'), // TODO/next-major-release: remove
|
|
83
76
|
...pageFileEntries,
|
|
84
|
-
|
|
77
|
+
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
78
|
+
...pageEntries
|
|
85
79
|
};
|
|
86
80
|
return entries;
|
|
87
81
|
}
|
|
@@ -106,6 +100,14 @@ async function getEntries(config) {
|
|
|
106
100
|
return entries;
|
|
107
101
|
}
|
|
108
102
|
}
|
|
103
|
+
function getPageEntries(pageConfigs) {
|
|
104
|
+
const pageEntries = {};
|
|
105
|
+
pageConfigs.forEach((pageConfig) => {
|
|
106
|
+
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, false);
|
|
107
|
+
pageEntries[entryName] = entryTarget;
|
|
108
|
+
});
|
|
109
|
+
return pageEntries;
|
|
110
|
+
}
|
|
109
111
|
function analyzeClientEntries(pageConfigs, config) {
|
|
110
112
|
let hasClientRouting = false;
|
|
111
113
|
let hasServerRouting = false;
|
|
@@ -120,6 +122,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
120
122
|
hasServerRouting = true;
|
|
121
123
|
}
|
|
122
124
|
{
|
|
125
|
+
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
123
126
|
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, true);
|
|
124
127
|
clientEntries[entryName] = entryTarget;
|
|
125
128
|
}
|
|
@@ -138,14 +141,6 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
138
141
|
return { hasClientRouting, hasServerRouting, clientEntries };
|
|
139
142
|
}
|
|
140
143
|
exports.analyzeClientEntries = analyzeClientEntries;
|
|
141
|
-
function analyzeServerEntries(pageConfigs) {
|
|
142
|
-
const serverEntries = {};
|
|
143
|
-
pageConfigs.forEach((pageConfig) => {
|
|
144
|
-
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, false);
|
|
145
|
-
serverEntries[entryName] = entryTarget;
|
|
146
|
-
});
|
|
147
|
-
return serverEntries;
|
|
148
|
-
}
|
|
149
144
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
150
145
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
151
146
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
@@ -201,20 +196,6 @@ function resolve(filePath) {
|
|
|
201
196
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/
|
|
202
197
|
return require_.resolve(`../../../../../${filePath}`);
|
|
203
198
|
}
|
|
204
|
-
function normalizeRollupInput(input) {
|
|
205
|
-
if (!input) {
|
|
206
|
-
return {};
|
|
207
|
-
}
|
|
208
|
-
// Usually `input` is an oject, but the user can set it as a `string` or `string[]`
|
|
209
|
-
if (typeof input === 'string') {
|
|
210
|
-
input = [input];
|
|
211
|
-
}
|
|
212
|
-
if (Array.isArray(input)) {
|
|
213
|
-
return Object.fromEntries(input.map((input) => [input, input]));
|
|
214
|
-
}
|
|
215
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(input));
|
|
216
|
-
return input;
|
|
217
|
-
}
|
|
218
199
|
function addLogHook() {
|
|
219
200
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|
|
220
201
|
if (!tty)
|
|
@@ -243,9 +224,9 @@ function addLogHook() {
|
|
|
243
224
|
});
|
|
244
225
|
}
|
|
245
226
|
function assertRollupInput(config) {
|
|
246
|
-
const userInputs = normalizeRollupInput(config.build.rollupOptions.input);
|
|
227
|
+
const userInputs = (0, utils_js_1.normalizeRollupInput)(config.build.rollupOptions.input);
|
|
247
228
|
const htmlInputs = Object.values(userInputs).filter((entry) => entry.endsWith('.html') || entry.endsWith('.htm'));
|
|
248
229
|
const htmlInput = htmlInputs[0];
|
|
249
|
-
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using
|
|
230
|
+
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
250
231
|
}
|
|
251
232
|
exports.assertRollupInput = assertRollupInput;
|
|
@@ -11,7 +11,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
const module_1 = require("module");
|
|
13
13
|
const assertResolveAlias_js_1 = require("./commonConfig/assertResolveAlias.js");
|
|
14
|
-
// @ts-ignore
|
|
14
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
15
15
|
const importMetaUrl = `file://${__filename}`;
|
|
16
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
17
17
|
function commonConfig() {
|
|
@@ -10,7 +10,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const fileTypes_js_1 = require("../../../../shared/getPageFiles/fileTypes.js");
|
|
11
11
|
const module_1 = require("module");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
// @ts-ignore
|
|
13
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
14
14
|
const importMetaUrl = `file://${__filename}`;
|
|
15
15
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
16
16
|
function resolveExtensions(configs, config) {
|
|
@@ -9,7 +9,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const utils_js_1 = require("../../utils.js");
|
|
10
10
|
const import_1 = require("@brillout/import");
|
|
11
11
|
const module_1 = require("module");
|
|
12
|
-
// @ts-ignore
|
|
12
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
13
13
|
const importMetaUrl = `file://${__filename}`;
|
|
14
14
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
15
15
|
async function getStemPackages(userAppRootDir) {
|
|
@@ -11,7 +11,7 @@ const utils_js_1 = require("../../utils.js");
|
|
|
11
11
|
const module_1 = require("module");
|
|
12
12
|
const path_2 = require("path");
|
|
13
13
|
const url_1 = require("url");
|
|
14
|
-
// @ts-ignore
|
|
14
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
15
15
|
const importMetaUrl = `file://${__filename}`;
|
|
16
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
17
17
|
const __dirname_ = (0, path_2.dirname)((0, url_1.fileURLToPath)(importMetaUrl));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getVikeManifest = void 0;
|
|
7
|
+
const utils_js_1 = require("../../utils.js");
|
|
8
|
+
const assertPluginManifest_js_1 = require("../../../shared/assertPluginManifest.js");
|
|
9
|
+
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
12
|
+
function getVikeManifest(config, configVike) {
|
|
13
|
+
const runtimeManifest = (0, globalContext_js_1.getRuntimeManifest)(configVike);
|
|
14
|
+
const manifest = {
|
|
15
|
+
version: utils_js_1.projectInfo.projectVersion,
|
|
16
|
+
usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(),
|
|
17
|
+
manifestKeyMap: getManifestKeyMap(configVike, config),
|
|
18
|
+
...runtimeManifest
|
|
19
|
+
};
|
|
20
|
+
(0, assertPluginManifest_js_1.assertPluginManifest)(manifest);
|
|
21
|
+
return manifest;
|
|
22
|
+
}
|
|
23
|
+
exports.getVikeManifest = getVikeManifest;
|
|
24
|
+
function getManifestKeyMap(configVike, config) {
|
|
25
|
+
const manifestKeyMap = {};
|
|
26
|
+
configVike.extensions
|
|
27
|
+
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
28
|
+
.flat()
|
|
29
|
+
.filter(utils_js_1.isNotNullish)
|
|
30
|
+
.forEach(({ importPath, filePath }) => {
|
|
31
|
+
// Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
|
|
32
|
+
const filePathRelative = path_1.default.posix.relative(config.root, (0, utils_js_1.toPosixPath)(filePath));
|
|
33
|
+
(0, utils_js_1.assertPosixPath)(filePathRelative);
|
|
34
|
+
(0, utils_js_1.assertPosixPath)(importPath);
|
|
35
|
+
manifestKeyMap[importPath] = filePathRelative;
|
|
36
|
+
});
|
|
37
|
+
return manifestKeyMap;
|
|
38
|
+
}
|
|
@@ -8,53 +8,85 @@ const plugin_js_1 = require("@brillout/vite-plugin-import-build/plugin.js");
|
|
|
8
8
|
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const module_1 = require("module");
|
|
11
|
-
|
|
11
|
+
const getConfigVike_js_1 = require("../../../shared/getConfigVike.js");
|
|
12
|
+
const getVikeManifest_js_1 = require("./getVikeManifest.js");
|
|
13
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
14
|
+
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
15
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
12
16
|
const importMetaUrl = `file://${__filename}`;
|
|
13
17
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
18
|
+
const ASSETS_MAP = '__VITE_ASSETS_MAP__';
|
|
14
19
|
function importBuild() {
|
|
15
20
|
let config;
|
|
21
|
+
let configVike;
|
|
16
22
|
return [
|
|
17
23
|
{
|
|
18
24
|
name: 'vike:importBuild:config',
|
|
19
25
|
enforce: 'post',
|
|
20
|
-
configResolved(config_) {
|
|
26
|
+
async configResolved(config_) {
|
|
21
27
|
config = config_;
|
|
28
|
+
configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
29
|
+
},
|
|
30
|
+
async writeBundle(options, bundle) {
|
|
31
|
+
if (!(0, utils_js_1.viteIsSSR)(config))
|
|
32
|
+
return;
|
|
33
|
+
await replace_ASSETS_MAP(options, bundle);
|
|
22
34
|
}
|
|
23
35
|
},
|
|
24
36
|
(0, plugin_js_1.importBuild)({
|
|
25
|
-
getImporterCode: (
|
|
26
|
-
|
|
27
|
-
return getImporterCode(config, pageFilesEntry);
|
|
37
|
+
getImporterCode: () => {
|
|
38
|
+
return getEntryCode(config, configVike);
|
|
28
39
|
},
|
|
29
40
|
libraryName: utils_js_1.projectInfo.projectName
|
|
30
41
|
})
|
|
31
42
|
];
|
|
32
43
|
}
|
|
33
44
|
exports.importBuild = importBuild;
|
|
34
|
-
function
|
|
45
|
+
function getEntryCode(config, configVike) {
|
|
35
46
|
const importPath = getImportPath(config);
|
|
36
|
-
|
|
47
|
+
const vikeManifest = (0, getVikeManifest_js_1.getVikeManifest)(config, configVike);
|
|
37
48
|
const importerCode = [
|
|
38
|
-
|
|
39
|
-
`
|
|
49
|
+
` import { setImportBuildGetters } from '${importPath}';`,
|
|
50
|
+
` import * as pageFiles from '${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer}';`,
|
|
40
51
|
' setImportBuildGetters({',
|
|
41
|
-
` pageFiles: () =>
|
|
52
|
+
` pageFiles: () => pageFiles,`,
|
|
42
53
|
// TODO: rename clientManifest -> assetManifest
|
|
43
|
-
|
|
44
|
-
// TODO:
|
|
45
|
-
|
|
46
|
-
" pluginManifest: () => require('../client/vike.json'),",
|
|
54
|
+
` clientManifest: () => { return ${ASSETS_MAP} },`,
|
|
55
|
+
// TODO: rename pluginManifest -> vikeManifest
|
|
56
|
+
` pluginManifest: () => (${JSON.stringify(vikeManifest, null, 2)}),`,
|
|
47
57
|
' });',
|
|
48
|
-
'})()',
|
|
49
58
|
''
|
|
50
59
|
].join('\n');
|
|
51
60
|
return importerCode;
|
|
52
61
|
}
|
|
62
|
+
async function replace_ASSETS_MAP(options, bundle) {
|
|
63
|
+
const { dir } = options;
|
|
64
|
+
(0, utils_js_1.assert)(dir);
|
|
65
|
+
// I guess importBuild won't be found in the bundle when using @vitejs/plugin-legacy
|
|
66
|
+
const importBuildEntry = (0, plugin_js_1.findImportBuildBundleEntry)(bundle);
|
|
67
|
+
const importBuildFilePath = path_1.default.join(dir, importBuildEntry.fileName);
|
|
68
|
+
const assetsJsonFilePath = path_1.default.join(dir, '..', 'assets.json');
|
|
69
|
+
const [assetsJsonString, importBuildFileContent] = await Promise.all([
|
|
70
|
+
await promises_1.default.readFile(assetsJsonFilePath, 'utf8'),
|
|
71
|
+
await promises_1.default.readFile(importBuildFilePath, 'utf8')
|
|
72
|
+
]);
|
|
73
|
+
const importBuildFileContentFixed = importBuildFileContent.replace(ASSETS_MAP, assetsJsonString);
|
|
74
|
+
(0, utils_js_1.assert)(importBuildFileContentFixed !== importBuildFileContent);
|
|
75
|
+
await promises_1.default.writeFile(importBuildFilePath, importBuildFileContentFixed);
|
|
76
|
+
}
|
|
53
77
|
function getImportPath(config) {
|
|
78
|
+
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
54
79
|
const filePathAbsolute = (0, utils_js_1.toPosixPath)(
|
|
55
80
|
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
|
|
56
81
|
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
if (
|
|
83
|
+
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal/loadImportBuild' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
|
|
84
|
+
true) {
|
|
85
|
+
return 'vike/__internal/loadImportBuild';
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const { outDirServer } = (0, utils_js_1.getOutDirs)(config);
|
|
89
|
+
const filePathRelative = path_1.default.posix.relative(outDirServer, filePathAbsolute);
|
|
90
|
+
return filePathRelative;
|
|
91
|
+
}
|
|
60
92
|
}
|
|
@@ -37,6 +37,9 @@ const configDefinitionsBuiltIn = {
|
|
|
37
37
|
guard: {
|
|
38
38
|
env: { server: true, client: 'if-client-routing' }
|
|
39
39
|
},
|
|
40
|
+
data: {
|
|
41
|
+
env: { server: true }
|
|
42
|
+
},
|
|
40
43
|
iKnowThePerformanceRisksOfAsyncRouteFunctions: {
|
|
41
44
|
env: { server: true, client: 'if-client-routing', eager: true }
|
|
42
45
|
},
|
|
@@ -77,6 +80,10 @@ const configDefinitionsBuiltIn = {
|
|
|
77
80
|
env: { client: true },
|
|
78
81
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
79
82
|
},
|
|
83
|
+
dataEnv: {
|
|
84
|
+
env: { client: true },
|
|
85
|
+
_computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data')
|
|
86
|
+
},
|
|
80
87
|
hooksTimeout: {
|
|
81
88
|
env: { server: true, client: true }
|
|
82
89
|
}
|
|
@@ -40,3 +40,4 @@ __exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
|
40
40
|
__exportStar(require("../../utils/mergeCumulativeValues.js"), exports);
|
|
41
41
|
__exportStar(require("../../utils/deepEqual.js"), exports);
|
|
42
42
|
__exportStar(require("../../utils/assertKeys.js"), exports);
|
|
43
|
+
__exportStar(require("../../utils/injectRollupInputs.js"), exports);
|
|
@@ -20,7 +20,8 @@ const PASS_TO_CLIENT = [
|
|
|
20
20
|
'_abortCaller',
|
|
21
21
|
*/
|
|
22
22
|
'_pageContextInitHasClientData',
|
|
23
|
-
'_pageId'
|
|
23
|
+
'_pageId',
|
|
24
|
+
'data' // for data() hook
|
|
24
25
|
];
|
|
25
26
|
const PASS_TO_CLIENT_ERROR_PAGE = ['pageProps', 'is404', '_isError'];
|
|
26
27
|
function serializePageContextClientSide(pageContext) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeOnBeforeRenderAndDataHooks = void 0;
|
|
4
|
+
const getHook_js_1 = require("../../../shared/hooks/getHook.js");
|
|
5
|
+
const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePageContextForUserConsumptionServerSide.js");
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
7
|
+
const assertOnBeforeRenderHookReturn_js_1 = require("../../../shared/assertOnBeforeRenderHookReturn.js");
|
|
8
|
+
async function executeOnBeforeRenderAndDataHooks(pageContext) {
|
|
9
|
+
if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const dataHook = (0, getHook_js_1.getHook)(pageContext, 'data');
|
|
13
|
+
const onBeforeRenderHook = (0, getHook_js_1.getHook)(pageContext, 'onBeforeRender');
|
|
14
|
+
if (!dataHook && !onBeforeRenderHook) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
(0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext);
|
|
18
|
+
if (dataHook) {
|
|
19
|
+
const hookResult = await (0, utils_js_1.executeHook)(() => dataHook.hookFn(pageContext), dataHook);
|
|
20
|
+
// Note: hookResult can be anything (e.g. an object) and is to be assigned to pageContext.data
|
|
21
|
+
const pageContextFromHook = {
|
|
22
|
+
data: hookResult
|
|
23
|
+
};
|
|
24
|
+
Object.assign(pageContext, pageContextFromHook);
|
|
25
|
+
}
|
|
26
|
+
if (onBeforeRenderHook) {
|
|
27
|
+
const hookResult = await (0, utils_js_1.executeHook)(() => onBeforeRenderHook.hookFn(pageContext), onBeforeRenderHook);
|
|
28
|
+
(0, assertOnBeforeRenderHookReturn_js_1.assertOnBeforeRenderHookReturn)(hookResult, onBeforeRenderHook.hookFilePath);
|
|
29
|
+
const pageContextFromHook = hookResult?.pageContext;
|
|
30
|
+
Object.assign(pageContext, pageContextFromHook);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.executeOnBeforeRenderAndDataHooks = executeOnBeforeRenderAndDataHooks;
|
|
@@ -85,7 +85,7 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer, configVike) {
|
|
|
85
85
|
const { createRequire } = (await (0, import_1.import_)('module')).default;
|
|
86
86
|
const { dirname } = (await (0, import_1.import_)('path')).default;
|
|
87
87
|
const { fileURLToPath } = (await (0, import_1.import_)('url')).default;
|
|
88
|
-
// @ts-ignore
|
|
88
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
89
89
|
const importMetaUrl = `file://${__filename}`;
|
|
90
90
|
const require_ = createRequire(importMetaUrl);
|
|
91
91
|
const __dirname_ = dirname(fileURLToPath(importMetaUrl));
|
|
@@ -14,7 +14,7 @@ const globalContext_js_1 = require("../globalContext.js");
|
|
|
14
14
|
const createHttpResponseObject_js_1 = require("./createHttpResponseObject.js");
|
|
15
15
|
const loadPageFilesServerSide_js_1 = require("./loadPageFilesServerSide.js");
|
|
16
16
|
const executeOnRenderHtmlHook_js_1 = require("./executeOnRenderHtmlHook.js");
|
|
17
|
-
const
|
|
17
|
+
const executeOnBeforeRenderAndDataHooks_js_1 = require("./executeOnBeforeRenderAndDataHooks.js");
|
|
18
18
|
const loggerRuntime_js_1 = require("./loggerRuntime.js");
|
|
19
19
|
const isNewError_js_1 = require("./isNewError.js");
|
|
20
20
|
const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePageContextForUserConsumptionServerSide.js");
|
|
@@ -34,11 +34,11 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
34
34
|
await (0, executeGuardHook_js_1.executeGuardHook)(pageContext, (pageContext) => (0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext));
|
|
35
35
|
}
|
|
36
36
|
if (!isError) {
|
|
37
|
-
await (0,
|
|
37
|
+
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
try {
|
|
41
|
-
await (0,
|
|
41
|
+
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
42
42
|
}
|
|
43
43
|
catch (err) {
|
|
44
44
|
if ((0, isNewError_js_1.isNewError)(err, pageContext.errorWhileRendering)) {
|
|
@@ -77,7 +77,7 @@ async function prerenderPage(pageContext) {
|
|
|
77
77
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
78
78
|
await executeGuardHook(pageContext, (pageContext) => preparePageContextForUserConsumptionServerSide(pageContext))
|
|
79
79
|
*/
|
|
80
|
-
await (0,
|
|
80
|
+
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
81
81
|
const { htmlRender, renderHook } = await (0, executeOnRenderHtmlHook_js_1.executeOnRenderHtmlHook)(pageContext);
|
|
82
82
|
(0, utils_js_1.assertUsage)(htmlRender !== null, `Cannot pre-render ${picocolors_1.default.cyan(pageContext.urlOriginal)} because the ${renderHook.hookName}() hook defined by ${renderHook.hookFilePath} didn't return an HTML string.`);
|
|
83
83
|
(0, utils_js_1.assert)(pageContext.isClientSideNavigation === false);
|
|
@@ -17,7 +17,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
18
|
const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntime.js");
|
|
19
19
|
const module_1 = require("module");
|
|
20
|
-
// @ts-ignore
|
|
20
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
21
21
|
const importMetaUrl = `file://${__filename}`;
|
|
22
22
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
23
23
|
(0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
|
|
@@ -11,7 +11,7 @@ const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntim
|
|
|
11
11
|
const isNpmPackage_js_1 = require("./isNpmPackage.js");
|
|
12
12
|
const assertPathIsFilesystemAbsolute_js_1 = require("./assertPathIsFilesystemAbsolute.js");
|
|
13
13
|
const module_1 = require("module");
|
|
14
|
-
// @ts-ignore
|
|
14
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
15
15
|
const importMetaUrl = `file://${__filename}`;
|
|
16
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
17
17
|
(0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeRollupInput = exports.injectRollupInputs = void 0;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
5
|
+
const isObject_js_1 = require("./isObject.js");
|
|
6
|
+
function injectRollupInputs(inputsNew, config) {
|
|
7
|
+
const inputsCurrent = normalizeRollupInput(config.build.rollupOptions.input);
|
|
8
|
+
const input = {
|
|
9
|
+
...inputsNew,
|
|
10
|
+
...inputsCurrent
|
|
11
|
+
};
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
14
|
+
exports.injectRollupInputs = injectRollupInputs;
|
|
15
|
+
function normalizeRollupInput(input) {
|
|
16
|
+
if (!input) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
// Usually `input` is an oject, but the user can set it as a `string` or `string[]`
|
|
20
|
+
if (typeof input === 'string') {
|
|
21
|
+
input = [input];
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(input)) {
|
|
24
|
+
return Object.fromEntries(input.map((input) => [input, input]));
|
|
25
|
+
}
|
|
26
|
+
(0, assert_js_1.assert)((0, isObject_js_1.isObject)(input));
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
exports.normalizeRollupInput = normalizeRollupInput;
|
|
@@ -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.150-commit-
|
|
5
|
+
const PROJECT_VERSION = '0.4.150-commit-d0822a3';
|
|
6
6
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
7
7
|
const projectInfo = {
|
|
8
8
|
projectName: 'Vike',
|
|
@@ -7,7 +7,7 @@ const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntim
|
|
|
7
7
|
const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
8
8
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
9
9
|
const module_1 = require("module");
|
|
10
|
-
// @ts-ignore
|
|
10
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
11
11
|
const importMetaUrl = `file://${__filename}`;
|
|
12
12
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
13
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|