vike 0.4.181 → 0.4.182
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/plugins/envVars.js +7 -12
- package/dist/cjs/node/plugin/plugins/fileEnv.js +7 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +47 -0
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/shared/route/utils.js +0 -1
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +5 -0
- package/dist/cjs/utils/projectInfo.js +4 -6
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +16 -14
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/utils.js +1 -1
- package/dist/esm/client/server-routing-runtime/utils.d.ts +0 -1
- package/dist/esm/client/server-routing-runtime/utils.js +0 -1
- package/dist/esm/node/plugin/plugins/envVars.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/envVars.js +6 -12
- package/dist/esm/node/plugin/plugins/fileEnv.js +7 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +8 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +47 -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/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/shared/route/utils.d.ts +0 -1
- package/dist/esm/shared/route/utils.js +0 -1
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -0
- package/dist/esm/utils/PROJECT_VERSION.js +2 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -5
- package/dist/esm/utils/projectInfo.js +2 -4
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.envVarsPlugin = void 0;
|
|
4
4
|
const vite_1 = require("vite");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
@@ -43,12 +43,13 @@ function envVarsPlugin() {
|
|
|
43
43
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
44
44
|
})
|
|
45
45
|
.forEach(([envName, envVal]) => {
|
|
46
|
+
const envStatement = `import.meta.env.${envName}`;
|
|
47
|
+
const envStatementRegEx = new RegExp((0, utils_js_1.escapeRegex)(envStatement) + '\\b', 'g');
|
|
46
48
|
// Security check
|
|
47
49
|
{
|
|
48
|
-
const envStatement = getEnvStatement(envName);
|
|
49
50
|
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
|
|
50
51
|
if (isPrivate && isClientSide) {
|
|
51
|
-
if (!
|
|
52
|
+
if (!envStatementRegEx.test(code))
|
|
52
53
|
return;
|
|
53
54
|
const modulePath = (0, getFilePath_js_1.getModuleFilePath)(id, config);
|
|
54
55
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -67,7 +68,7 @@ function envVarsPlugin() {
|
|
|
67
68
|
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
68
69
|
}
|
|
69
70
|
// Apply
|
|
70
|
-
code = applyEnvVar(
|
|
71
|
+
code = applyEnvVar(envStatementRegEx, envVal, code);
|
|
71
72
|
});
|
|
72
73
|
// Line numbers didn't change.
|
|
73
74
|
// - We only break the column number of a couple of lines, wich is acceptable.
|
|
@@ -78,14 +79,8 @@ function envVarsPlugin() {
|
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
exports.envVarsPlugin = envVarsPlugin;
|
|
81
|
-
function applyEnvVar(
|
|
82
|
-
|
|
83
|
-
const regex = new RegExp((0, utils_js_1.escapeRegex)(envStatement) + '\\b', 'g');
|
|
84
|
-
return code.replace(regex, JSON.stringify(envVal));
|
|
85
|
-
}
|
|
86
|
-
exports.applyEnvVar = applyEnvVar;
|
|
87
|
-
function getEnvStatement(envName) {
|
|
88
|
-
return `import.meta.env.${envName}`;
|
|
82
|
+
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
83
|
+
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
89
84
|
}
|
|
90
85
|
function getIsClientSide(config, options) {
|
|
91
86
|
const isBuild = config.command === 'build';
|
|
@@ -31,6 +31,10 @@ function fileEnv() {
|
|
|
31
31
|
order: 'pre',
|
|
32
32
|
*/
|
|
33
33
|
async handler(source, importer, options) {
|
|
34
|
+
// It seems like Vite's scan doesn't apply transformers. (We need the `.telefunc.js` transformer to apply for our analysis to be correct.)
|
|
35
|
+
// @ts-expect-error Vite's type is wrong
|
|
36
|
+
if (options.scan)
|
|
37
|
+
return;
|
|
34
38
|
// TODO/v1-release: remove
|
|
35
39
|
if (extractAssetsPlugin_js_1.extractAssetsRE.test(source) || extractExportNamesPlugin_js_1.extractExportNamesRE.test(source))
|
|
36
40
|
return;
|
|
@@ -58,14 +62,14 @@ function fileEnv() {
|
|
|
58
62
|
const envActual = isServerSide ? 'server' : 'client';
|
|
59
63
|
const envExpect = isServerSide ? 'client' : 'server';
|
|
60
64
|
const suffix = `.${envExpect}.`;
|
|
61
|
-
// Everything
|
|
65
|
+
// Everything is good
|
|
62
66
|
if (!modulePath.includes(suffix))
|
|
63
67
|
return;
|
|
64
68
|
// Show error message
|
|
65
69
|
let errMsg;
|
|
66
70
|
let modulePathPretty = (0, getFilePath_js_1.getModuleFilePath)(moduleId, config);
|
|
67
71
|
modulePathPretty = modulePathPretty.replaceAll(suffix, picocolors_1.default.bold(suffix));
|
|
68
|
-
errMsg = `${(0, utils_js_1.capitalizeFirstLetter)(envExpect)}-only
|
|
72
|
+
errMsg = `${(0, utils_js_1.capitalizeFirstLetter)(envExpect)}-only file ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
69
73
|
if (importer &&
|
|
70
74
|
// Don't show Vike's virtual modules that import the entry plus files such as /pages/about/+Page.js
|
|
71
75
|
!importer.includes('virtual:vike:') &&
|
|
@@ -75,10 +79,7 @@ function fileEnv() {
|
|
|
75
79
|
errMsg += ` by ${importerPath}`;
|
|
76
80
|
}
|
|
77
81
|
if (isDev) {
|
|
78
|
-
errMsg += '
|
|
79
|
-
}
|
|
80
|
-
errMsg += '.';
|
|
81
|
-
if (isDev) {
|
|
82
|
+
errMsg += ' and, therefore, Vike will prevent building your app for production.';
|
|
82
83
|
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
@@ -277,6 +277,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
277
277
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
278
278
|
applyEffectsAll(configValueSources, configDefinitions);
|
|
279
279
|
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
280
|
+
assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId);
|
|
280
281
|
const pageConfig = {
|
|
281
282
|
pageId: locationId,
|
|
282
283
|
isErrorPage,
|
|
@@ -290,6 +291,52 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
290
291
|
assertPageConfigs(pageConfigs);
|
|
291
292
|
return { pageConfigs, pageConfigGlobal, globalVikeConfig };
|
|
292
293
|
}
|
|
294
|
+
// TODO/soon: refactor
|
|
295
|
+
// - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
|
|
296
|
+
// - This assertUsage() message is slightly better: use this one for getGlobalConfigs()
|
|
297
|
+
// Global configs should be defined at global locations
|
|
298
|
+
function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId) {
|
|
299
|
+
interfaceFilesRelevantList.forEach(async (interfaceFile) => {
|
|
300
|
+
const configNames = [];
|
|
301
|
+
if (interfaceFile.isValueFile) {
|
|
302
|
+
configNames.push(interfaceFile.configName);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
|
|
306
|
+
}
|
|
307
|
+
configNames.forEach((configName) => {
|
|
308
|
+
if (isGlobalConfig(configName))
|
|
309
|
+
return;
|
|
310
|
+
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
311
|
+
if (configDef.global) {
|
|
312
|
+
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
313
|
+
if (!(0, filesystemRouting_js_1.isGlobalLocation)(interfaceFile.locationId, locationIds)) {
|
|
314
|
+
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
315
|
+
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
316
|
+
}));
|
|
317
|
+
const configFilesGlobal = [];
|
|
318
|
+
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
319
|
+
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
320
|
+
interfaceFiles.forEach((interfaceFile) => {
|
|
321
|
+
if (!interfaceFile.isConfigFile)
|
|
322
|
+
return;
|
|
323
|
+
const { filePath: { filePathAbsoluteUserRootDir } } = interfaceFile;
|
|
324
|
+
if (filePathAbsoluteUserRootDir) {
|
|
325
|
+
configFilesGlobal.push(filePathAbsoluteUserRootDir);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
330
|
+
`${interfaceFile.filePath.filePathToShowToUser} sets the config ${picocolors_1.default.cyan(configName)} but it's a global config:`,
|
|
331
|
+
configFilesGlobal.length > 0
|
|
332
|
+
? `define ${picocolors_1.default.cyan(configName)} at ${(0, utils_js_1.joinEnglish)(configFilesGlobal, 'or')} instead.`
|
|
333
|
+
: `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead.`
|
|
334
|
+
].join(' '));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
}
|
|
293
340
|
function deriveConfigEnvFromFileName(env, fileName) {
|
|
294
341
|
env = { ...env };
|
|
295
342
|
if (fileName.includes('.server.')) {
|
|
@@ -42,3 +42,4 @@ __exportStar(require("../../utils/pLimit.js"), exports);
|
|
|
42
42
|
__exportStar(require("../../utils/assertVersion.js"), exports);
|
|
43
43
|
__exportStar(require("../../utils/assertPathFilesystemAbsolute.js"), exports);
|
|
44
44
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
45
|
+
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
@@ -72,3 +72,4 @@ __exportStar(require("../../utils/escapeHtml.js"), exports);
|
|
|
72
72
|
__exportStar(require("../../utils/normalizeHeaders.js"), exports);
|
|
73
73
|
__exportStar(require("../../utils/isVikeReactApp.js"), exports);
|
|
74
74
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
75
|
+
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
@@ -36,6 +36,5 @@ __exportStar(require("../../utils/isBrowser.js"), exports);
|
|
|
36
36
|
__exportStar(require("../../utils/parseUrl.js"), exports);
|
|
37
37
|
__exportStar(require("../../utils/checkType.js"), exports);
|
|
38
38
|
__exportStar(require("../../utils/joinEnglish.js"), exports);
|
|
39
|
-
__exportStar(require("../../utils/projectInfo.js"), exports);
|
|
40
39
|
__exportStar(require("../../utils/truncateString.js"), exports);
|
|
41
40
|
__exportStar(require("../../utils/isCallable.js"), exports);
|
package/dist/cjs/shared/utils.js
CHANGED
|
@@ -34,7 +34,6 @@ __exportStar(require("../utils/isNotNullish.js"), exports);
|
|
|
34
34
|
__exportStar(require("../utils/stringifyStringArray.js"), exports);
|
|
35
35
|
__exportStar(require("../utils/filesystemPathHandling.js"), exports);
|
|
36
36
|
__exportStar(require("../utils/cast.js"), exports);
|
|
37
|
-
__exportStar(require("../utils/projectInfo.js"), exports);
|
|
38
37
|
__exportStar(require("../utils/isPropertyGetter.js"), exports);
|
|
39
38
|
__exportStar(require("../utils/isPromise.js"), exports);
|
|
40
39
|
__exportStar(require("../utils/checkType.js"), exports);
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
exports.
|
|
6
|
-
const projectInfo = {
|
|
3
|
+
exports.projectInfo = void 0;
|
|
4
|
+
const PROJECT_VERSION_js_1 = require("./PROJECT_VERSION.js");
|
|
5
|
+
exports.projectInfo = {
|
|
7
6
|
projectName: 'Vike',
|
|
8
|
-
projectVersion: PROJECT_VERSION
|
|
7
|
+
projectVersion: PROJECT_VERSION_js_1.PROJECT_VERSION
|
|
9
8
|
};
|
|
10
|
-
exports.projectInfo = projectInfo;
|
|
@@ -20,9 +20,11 @@ import { getErrorPageId } from '../../shared/error-page.js';
|
|
|
20
20
|
const globalObject = getGlobalObject('renderPageClientSide.ts', { renderCounter: 0 });
|
|
21
21
|
async function renderPageClientSide(renderArgs) {
|
|
22
22
|
const { scrollTarget, urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, isUserLandPushStateNavigation, isClientSideNavigation = true } = renderArgs;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const { isRenderOutdated, setHydrationCanBeAborted, isFirstRender } = getIsRenderOutdated();
|
|
24
|
+
// Note that pageContext.isHydration isn't equivalent to isFirstRender
|
|
25
|
+
// - Thus pageContext.isHydration isn't equivalent to !pageContext.isClientSideNavigation
|
|
26
|
+
// - `pageContext.isHydration === !isFirstRender && !isErrorPage`
|
|
27
|
+
assert(isClientSideNavigation === !isFirstRender);
|
|
26
28
|
assertNoInfiniteAbortLoop(pageContextsFromRewrite.length, redirectCount);
|
|
27
29
|
if (globalObject.clientRoutingIsDisabled) {
|
|
28
30
|
redirectHard(urlOriginal);
|
|
@@ -64,7 +66,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
64
66
|
}
|
|
65
67
|
// Route
|
|
66
68
|
let pageContextRouted;
|
|
67
|
-
if (
|
|
69
|
+
if (isFirstRender) {
|
|
68
70
|
const pageContextSerialized = getPageContextFromHooks_serialized();
|
|
69
71
|
pageContextRouted = pageContextSerialized;
|
|
70
72
|
}
|
|
@@ -108,7 +110,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
108
110
|
objectAssign(pageContext, await loadUserFilesClientSide(pageContext._pageId, pageContext._pageFilesAll, pageContext._pageConfigs));
|
|
109
111
|
}
|
|
110
112
|
catch (err) {
|
|
111
|
-
if (handleErrorFetchingStaticAssets(err, pageContext,
|
|
113
|
+
if (handleErrorFetchingStaticAssets(err, pageContext, isFirstRender)) {
|
|
112
114
|
return;
|
|
113
115
|
}
|
|
114
116
|
else {
|
|
@@ -130,7 +132,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
130
132
|
if (isRenderOutdated())
|
|
131
133
|
return;
|
|
132
134
|
// Get pageContext from hooks (fetched from server, and/or directly called on the client-side)
|
|
133
|
-
if (
|
|
135
|
+
if (isFirstRender) {
|
|
134
136
|
assert(hasProp(pageContext, '_hasPageContextFromServer', 'true'));
|
|
135
137
|
let pageContextAugmented;
|
|
136
138
|
try {
|
|
@@ -267,7 +269,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
267
269
|
objectAssign(pageContext, await loadUserFilesClientSide(pageContext._pageId, pageContext._pageFilesAll, pageContext._pageConfigs));
|
|
268
270
|
}
|
|
269
271
|
catch (err) {
|
|
270
|
-
if (handleErrorFetchingStaticAssets(err, pageContext,
|
|
272
|
+
if (handleErrorFetchingStaticAssets(err, pageContext, isFirstRender)) {
|
|
271
273
|
return;
|
|
272
274
|
}
|
|
273
275
|
else {
|
|
@@ -341,7 +343,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
341
343
|
*/
|
|
342
344
|
addLinkPrefetchHandlers(pageContext);
|
|
343
345
|
// onHydrationEnd()
|
|
344
|
-
if (
|
|
346
|
+
if (isFirstRender && !onRenderClientError) {
|
|
345
347
|
assertHook(pageContext, 'onHydrationEnd');
|
|
346
348
|
const hook = getHook(pageContext, 'onHydrationEnd');
|
|
347
349
|
if (hook) {
|
|
@@ -395,11 +397,11 @@ function changeUrl(url, overwriteLastHistoryEntry) {
|
|
|
395
397
|
pushHistory(url, overwriteLastHistoryEntry);
|
|
396
398
|
updateState();
|
|
397
399
|
}
|
|
398
|
-
function handleErrorFetchingStaticAssets(err, pageContext,
|
|
400
|
+
function handleErrorFetchingStaticAssets(err, pageContext, isFirstRender) {
|
|
399
401
|
if (!isErrorFetchingStaticAssets(err)) {
|
|
400
402
|
return false;
|
|
401
403
|
}
|
|
402
|
-
if (
|
|
404
|
+
if (isFirstRender) {
|
|
403
405
|
disableClientRouting(err, false);
|
|
404
406
|
// This may happen if the frontend was newly deployed during hydration.
|
|
405
407
|
// Ideally: re-try a couple of times by reloading the page (not entirely trivial to implement since `localStorage` is needed.)
|
|
@@ -438,10 +440,10 @@ function getIsRenderOutdated() {
|
|
|
438
440
|
};
|
|
439
441
|
/** Whether the rendering should be aborted because a new rendering has started. We should call this after each `await`. */
|
|
440
442
|
const isRenderOutdated = (isRenderCleanup) => {
|
|
441
|
-
// Never abort
|
|
443
|
+
// Never abort first render if `hydrationCanBeAborted` isn't `true`
|
|
442
444
|
{
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
+
const isFirstRender = renderNumber === 1;
|
|
446
|
+
if (isFirstRender && !hydrationCanBeAborted && !isRenderCleanup) {
|
|
445
447
|
return false;
|
|
446
448
|
}
|
|
447
449
|
}
|
|
@@ -451,7 +453,7 @@ function getIsRenderOutdated() {
|
|
|
451
453
|
return {
|
|
452
454
|
isRenderOutdated,
|
|
453
455
|
setHydrationCanBeAborted,
|
|
454
|
-
|
|
456
|
+
isFirstRender: renderNumber === 1
|
|
455
457
|
};
|
|
456
458
|
}
|
|
457
459
|
function getRenderCount() {
|
|
@@ -13,7 +13,6 @@ export * from '../../utils/isReact.js';
|
|
|
13
13
|
export * from '../../utils/isSameErrorMessage.js';
|
|
14
14
|
export * from '../../utils/objectAssign.js';
|
|
15
15
|
export * from '../../utils/parseUrl.js';
|
|
16
|
-
export * from '../../utils/projectInfo.js';
|
|
17
16
|
export * from '../../utils/PromiseType.js';
|
|
18
17
|
export * from '../../utils/redirectHard.js';
|
|
19
18
|
export * from '../../utils/sleep.js';
|
|
@@ -22,3 +21,4 @@ export * from '../../utils/throttle.js';
|
|
|
22
21
|
export * from '../../utils/assertRoutingType.js';
|
|
23
22
|
export * from '../../utils/onPageVisibilityChange.js';
|
|
24
23
|
export * from '../../utils/augmentType.js';
|
|
24
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
|
@@ -19,7 +19,6 @@ export * from '../../utils/isReact.js';
|
|
|
19
19
|
export * from '../../utils/isSameErrorMessage.js';
|
|
20
20
|
export * from '../../utils/objectAssign.js';
|
|
21
21
|
export * from '../../utils/parseUrl.js';
|
|
22
|
-
export * from '../../utils/projectInfo.js';
|
|
23
22
|
export * from '../../utils/PromiseType.js';
|
|
24
23
|
export * from '../../utils/redirectHard.js';
|
|
25
24
|
export * from '../../utils/sleep.js';
|
|
@@ -28,3 +27,4 @@ export * from '../../utils/throttle.js';
|
|
|
28
27
|
export * from '../../utils/assertRoutingType.js';
|
|
29
28
|
export * from '../../utils/onPageVisibilityChange.js';
|
|
30
29
|
export * from '../../utils/augmentType.js';
|
|
30
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
|
@@ -9,7 +9,6 @@ export * from '../../utils/isCallable.js';
|
|
|
9
9
|
export * from '../../utils/isObject.js';
|
|
10
10
|
export * from '../../utils/objectAssign.js';
|
|
11
11
|
export * from '../../utils/parseUrl.js';
|
|
12
|
-
export * from '../../utils/projectInfo.js';
|
|
13
12
|
export * from '../../utils/slice.js';
|
|
14
13
|
export * from '../../utils/unique.js';
|
|
15
14
|
export * from '../../utils/getPropAccessNotation.js';
|
|
@@ -13,7 +13,6 @@ export * from '../../utils/isCallable.js';
|
|
|
13
13
|
export * from '../../utils/isObject.js';
|
|
14
14
|
export * from '../../utils/objectAssign.js';
|
|
15
15
|
export * from '../../utils/parseUrl.js';
|
|
16
|
-
export * from '../../utils/projectInfo.js';
|
|
17
16
|
export * from '../../utils/slice.js';
|
|
18
17
|
export * from '../../utils/unique.js'; // Only used by Server Routing (not needed for Client Routing)
|
|
19
18
|
export * from '../../utils/getPropAccessNotation.js';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export { envVarsPlugin };
|
|
2
|
-
// For ./envVars.spec.ts
|
|
3
|
-
export { applyEnvVar };
|
|
4
2
|
import { loadEnv } from 'vite';
|
|
5
3
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
6
4
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
@@ -43,12 +41,13 @@ function envVarsPlugin() {
|
|
|
43
41
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
44
42
|
})
|
|
45
43
|
.forEach(([envName, envVal]) => {
|
|
44
|
+
const envStatement = `import.meta.env.${envName}`;
|
|
45
|
+
const envStatementRegEx = new RegExp(escapeRegex(envStatement) + '\\b', 'g');
|
|
46
46
|
// Security check
|
|
47
47
|
{
|
|
48
|
-
const envStatement = getEnvStatement(envName);
|
|
49
48
|
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
|
|
50
49
|
if (isPrivate && isClientSide) {
|
|
51
|
-
if (!
|
|
50
|
+
if (!envStatementRegEx.test(code))
|
|
52
51
|
return;
|
|
53
52
|
const modulePath = getModuleFilePath(id, config);
|
|
54
53
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -67,7 +66,7 @@ function envVarsPlugin() {
|
|
|
67
66
|
assert(!(isPrivate && isClientSide) || !isBuild);
|
|
68
67
|
}
|
|
69
68
|
// Apply
|
|
70
|
-
code = applyEnvVar(
|
|
69
|
+
code = applyEnvVar(envStatementRegEx, envVal, code);
|
|
71
70
|
});
|
|
72
71
|
// Line numbers didn't change.
|
|
73
72
|
// - We only break the column number of a couple of lines, wich is acceptable.
|
|
@@ -77,13 +76,8 @@ function envVarsPlugin() {
|
|
|
77
76
|
}
|
|
78
77
|
};
|
|
79
78
|
}
|
|
80
|
-
function applyEnvVar(
|
|
81
|
-
|
|
82
|
-
const regex = new RegExp(escapeRegex(envStatement) + '\\b', 'g');
|
|
83
|
-
return code.replace(regex, JSON.stringify(envVal));
|
|
84
|
-
}
|
|
85
|
-
function getEnvStatement(envName) {
|
|
86
|
-
return `import.meta.env.${envName}`;
|
|
79
|
+
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
80
|
+
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
87
81
|
}
|
|
88
82
|
function getIsClientSide(config, options) {
|
|
89
83
|
const isBuild = config.command === 'build';
|
|
@@ -26,6 +26,10 @@ function fileEnv() {
|
|
|
26
26
|
order: 'pre',
|
|
27
27
|
*/
|
|
28
28
|
async handler(source, importer, options) {
|
|
29
|
+
// It seems like Vite's scan doesn't apply transformers. (We need the `.telefunc.js` transformer to apply for our analysis to be correct.)
|
|
30
|
+
// @ts-expect-error Vite's type is wrong
|
|
31
|
+
if (options.scan)
|
|
32
|
+
return;
|
|
29
33
|
// TODO/v1-release: remove
|
|
30
34
|
if (extractAssetsRE.test(source) || extractExportNamesRE.test(source))
|
|
31
35
|
return;
|
|
@@ -53,14 +57,14 @@ function fileEnv() {
|
|
|
53
57
|
const envActual = isServerSide ? 'server' : 'client';
|
|
54
58
|
const envExpect = isServerSide ? 'client' : 'server';
|
|
55
59
|
const suffix = `.${envExpect}.`;
|
|
56
|
-
// Everything
|
|
60
|
+
// Everything is good
|
|
57
61
|
if (!modulePath.includes(suffix))
|
|
58
62
|
return;
|
|
59
63
|
// Show error message
|
|
60
64
|
let errMsg;
|
|
61
65
|
let modulePathPretty = getModuleFilePath(moduleId, config);
|
|
62
66
|
modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
|
|
63
|
-
errMsg = `${capitalizeFirstLetter(envExpect)}-only
|
|
67
|
+
errMsg = `${capitalizeFirstLetter(envExpect)}-only file ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
64
68
|
if (importer &&
|
|
65
69
|
// Don't show Vike's virtual modules that import the entry plus files such as /pages/about/+Page.js
|
|
66
70
|
!importer.includes('virtual:vike:') &&
|
|
@@ -70,10 +74,7 @@ function fileEnv() {
|
|
|
70
74
|
errMsg += ` by ${importerPath}`;
|
|
71
75
|
}
|
|
72
76
|
if (isDev) {
|
|
73
|
-
errMsg += '
|
|
74
|
-
}
|
|
75
|
-
errMsg += '.';
|
|
76
|
-
if (isDev) {
|
|
77
|
+
errMsg += ' and, therefore, Vike will prevent building your app for production.';
|
|
77
78
|
assertWarning(false, errMsg, { onlyOnce: true });
|
|
78
79
|
}
|
|
79
80
|
else {
|
|
@@ -31,6 +31,14 @@ type ConfigDefinition = {
|
|
|
31
31
|
* https://vike.dev/meta
|
|
32
32
|
*/
|
|
33
33
|
effect?: ConfigEffect;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the configuration always applies to all pages (no config inheritance).
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*
|
|
39
|
+
* https://vike.dev/extends#inheritance
|
|
40
|
+
*/
|
|
41
|
+
global?: boolean;
|
|
34
42
|
};
|
|
35
43
|
/**
|
|
36
44
|
* Function called when the config value is defined.
|
|
@@ -273,6 +273,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
273
273
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
274
274
|
applyEffectsAll(configValueSources, configDefinitions);
|
|
275
275
|
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
276
|
+
assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId);
|
|
276
277
|
const pageConfig = {
|
|
277
278
|
pageId: locationId,
|
|
278
279
|
isErrorPage,
|
|
@@ -286,6 +287,52 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
286
287
|
assertPageConfigs(pageConfigs);
|
|
287
288
|
return { pageConfigs, pageConfigGlobal, globalVikeConfig };
|
|
288
289
|
}
|
|
290
|
+
// TODO/soon: refactor
|
|
291
|
+
// - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
|
|
292
|
+
// - This assertUsage() message is slightly better: use this one for getGlobalConfigs()
|
|
293
|
+
// Global configs should be defined at global locations
|
|
294
|
+
function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId) {
|
|
295
|
+
interfaceFilesRelevantList.forEach(async (interfaceFile) => {
|
|
296
|
+
const configNames = [];
|
|
297
|
+
if (interfaceFile.isValueFile) {
|
|
298
|
+
configNames.push(interfaceFile.configName);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
|
|
302
|
+
}
|
|
303
|
+
configNames.forEach((configName) => {
|
|
304
|
+
if (isGlobalConfig(configName))
|
|
305
|
+
return;
|
|
306
|
+
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
307
|
+
if (configDef.global) {
|
|
308
|
+
const locationIds = objectKeys(interfaceFilesByLocationId);
|
|
309
|
+
if (!isGlobalLocation(interfaceFile.locationId, locationIds)) {
|
|
310
|
+
const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
311
|
+
return isGlobalLocation(locationId, locationIds);
|
|
312
|
+
}));
|
|
313
|
+
const configFilesGlobal = [];
|
|
314
|
+
objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
315
|
+
assert(isGlobalLocation(locationId, locationIds));
|
|
316
|
+
interfaceFiles.forEach((interfaceFile) => {
|
|
317
|
+
if (!interfaceFile.isConfigFile)
|
|
318
|
+
return;
|
|
319
|
+
const { filePath: { filePathAbsoluteUserRootDir } } = interfaceFile;
|
|
320
|
+
if (filePathAbsoluteUserRootDir) {
|
|
321
|
+
configFilesGlobal.push(filePathAbsoluteUserRootDir);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
assertUsage(false, [
|
|
326
|
+
`${interfaceFile.filePath.filePathToShowToUser} sets the config ${pc.cyan(configName)} but it's a global config:`,
|
|
327
|
+
configFilesGlobal.length > 0
|
|
328
|
+
? `define ${pc.cyan(configName)} at ${joinEnglish(configFilesGlobal, 'or')} instead.`
|
|
329
|
+
: `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead.`
|
|
330
|
+
].join(' '));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
289
336
|
function deriveConfigEnvFromFileName(env, fileName) {
|
|
290
337
|
env = { ...env };
|
|
291
338
|
if (fileName.includes('.server.')) {
|
|
@@ -11,6 +11,5 @@ export * from '../../utils/isBrowser.js';
|
|
|
11
11
|
export * from '../../utils/parseUrl.js';
|
|
12
12
|
export * from '../../utils/checkType.js';
|
|
13
13
|
export * from '../../utils/joinEnglish.js';
|
|
14
|
-
export * from '../../utils/projectInfo.js';
|
|
15
14
|
export * from '../../utils/truncateString.js';
|
|
16
15
|
export * from '../../utils/isCallable.js';
|
|
@@ -20,6 +20,5 @@ export * from '../../utils/isBrowser.js';
|
|
|
20
20
|
export * from '../../utils/parseUrl.js';
|
|
21
21
|
export * from '../../utils/checkType.js';
|
|
22
22
|
export * from '../../utils/joinEnglish.js';
|
|
23
|
-
export * from '../../utils/projectInfo.js';
|
|
24
23
|
export * from '../../utils/truncateString.js';
|
|
25
24
|
export * from '../../utils/isCallable.js';
|
|
@@ -14,7 +14,6 @@ export * from '../utils/isNotNullish.js';
|
|
|
14
14
|
export * from '../utils/stringifyStringArray.js';
|
|
15
15
|
export * from '../utils/filesystemPathHandling.js';
|
|
16
16
|
export * from '../utils/cast.js';
|
|
17
|
-
export * from '../utils/projectInfo.js';
|
|
18
17
|
export * from '../utils/isPropertyGetter.js';
|
|
19
18
|
export * from '../utils/isPromise.js';
|
|
20
19
|
export * from '../utils/checkType.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -18,7 +18,6 @@ export * from '../utils/isNotNullish.js';
|
|
|
18
18
|
export * from '../utils/stringifyStringArray.js';
|
|
19
19
|
export * from '../utils/filesystemPathHandling.js';
|
|
20
20
|
export * from '../utils/cast.js';
|
|
21
|
-
export * from '../utils/projectInfo.js';
|
|
22
21
|
export * from '../utils/isPropertyGetter.js';
|
|
23
22
|
export * from '../utils/isPromise.js';
|
|
24
23
|
export * from '../utils/checkType.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.182";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
const PROJECT_VERSION = '0.4.181';
|
|
4
|
-
const projectInfo = {
|
|
1
|
+
import { PROJECT_VERSION } from './PROJECT_VERSION.js';
|
|
2
|
+
export const projectInfo = {
|
|
5
3
|
projectName: 'Vike',
|
|
6
4
|
projectVersion: PROJECT_VERSION
|
|
7
5
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.182",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
"@brillout/import": "^0.2.3",
|
|
212
212
|
"@brillout/json-serializer": "^0.5.8",
|
|
213
213
|
"@brillout/picocolors": "^1.0.13",
|
|
214
|
-
"@brillout/release-me": "^0.
|
|
214
|
+
"@brillout/release-me": "^0.4.0",
|
|
215
215
|
"@brillout/require-shim": "^0.1.2",
|
|
216
216
|
"@brillout/vite-plugin-server-entry": "^0.4.0",
|
|
217
217
|
"@types/estree": "^1.0.5",
|
|
@@ -229,7 +229,7 @@
|
|
|
229
229
|
"sirv": "^2.0.4",
|
|
230
230
|
"source-map-support": "^0.5.21",
|
|
231
231
|
"typescript": "^5.4.5",
|
|
232
|
-
"vite": "
|
|
232
|
+
"vite": "^5.3.5"
|
|
233
233
|
},
|
|
234
234
|
"engines": {
|
|
235
235
|
"node": ">=18.0.0"
|