vike 0.4.240-commit-309067c → 0.4.240-commit-42b44bb

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.
@@ -241,7 +241,7 @@ async function renderPageClientSide(renderArgs) {
241
241
  // We don't swallow 404 errors:
242
242
  // - On the server-side, Vike swallows / doesn't show any 404 error log because it's expected that a user may go to some random non-existent URL. (We don't want to flood the app's error tracking with 404 logs.)
243
243
  // - On the client-side, if the user navigates to a 404 then it means that the UI has a broken link. (It isn't expected that users can go to some random URL using the client-side router, as it would require, for example, the user to manually change the URL of a link by manually manipulating the DOM which highly unlikely.)
244
- logError(err);
244
+ logErrorClient(err);
245
245
  }
246
246
  else {
247
247
  // We swallow throw redirect()/render() called by client-side hooks onBeforeRender()/data()/guard()
@@ -272,7 +272,7 @@ async function renderPageClientSide(renderArgs) {
272
272
  - An infinite reloading page is a even worse UX than a blank page.
273
273
  redirectHard(urlOriginal)
274
274
  */
275
- logError(err);
275
+ logErrorClient(err);
276
276
  };
277
277
  const errorPageId = getErrorPageId(pageContext._pageFilesAll, pageContext._globalContext._pageConfigs);
278
278
  if (!errorPageId)
@@ -384,7 +384,7 @@ async function renderPageClientSide(renderArgs) {
384
384
  await handleError({ err });
385
385
  }
386
386
  else {
387
- logError(err);
387
+ logErrorClient(err);
388
388
  }
389
389
  };
390
390
  // We use globalObject.onRenderClientPreviousPromise in order to ensure that there is never two concurrent onRenderClient() calls
@@ -665,7 +665,7 @@ if (import.meta.env.DEV && import.meta.hot)
665
665
  });
666
666
  }
667
667
  });
668
- function logError(err) {
668
+ function logErrorClient(err) {
669
669
  if (isObject(err) &&
670
670
  // Set by vike-react
671
671
  // https://github.com/vikejs/vike-react/blob/195a208c6b77e7f34496e1f637278a36c60fbe07/packages/vike-react/src/integration/onRenderClient.tsx#L109
@@ -6,7 +6,7 @@ const commands = [
6
6
  { name: 'dev', desc: 'Start development server' },
7
7
  { name: 'build', desc: 'Build for production' },
8
8
  { name: 'preview', desc: 'Start preview server using production build' },
9
- { name: 'prerender', desc: 'Pre-render pages (only needed when prerender.disableAutoRun is true)' },
9
+ { name: 'prerender', desc: 'Pre-render pages (only needed when +prerender.disableAutoRun is true)' },
10
10
  ];
11
11
  function parseCli() {
12
12
  const command = getCommand();
@@ -51,7 +51,7 @@ function getCliOptions() {
51
51
  return cliOptions;
52
52
  }
53
53
  function showHelp() {
54
- const TAB = ' '.repeat(3);
54
+ const TAB = ' '.repeat(2);
55
55
  const nameMaxLength = Math.max(...commands.map((c) => c.name.length));
56
56
  console.log([
57
57
  `vike@${PROJECT_VERSION}`,
@@ -60,13 +60,17 @@ function showHelp() {
60
60
  ...[...commands, { name: '-v', desc: "Print Vike's installed version" }].map((c) => ` ${pc.dim('$')} vike ${c.name.startsWith('-') ? pc.cyan(`${c.name}`) : pc.bold(`${c.name}`)}${' '.repeat(nameMaxLength - c.name.length)}${TAB}${pc.dim(`# ${c.desc}`)}`),
61
61
  '',
62
62
  'Common CLI options:',
63
- [`vike dev ${pc.cyan('--host')}`, `vike dev ${pc.cyan('--port')} 80`, `vike build ${pc.cyan('--mode')} staging`]
63
+ [
64
+ `vike dev ${pc.cyan('--host')} ${TAB}${pc.dim('# Make server available over LAN and public addresses')}`,
65
+ `vike dev ${pc.cyan('--port')} 80 ${TAB}${pc.dim('# Change the server port')}`,
66
+ `vike build ${pc.cyan('--mode')} staging${TAB}${pc.dim('# Set the mode to run in')}`,
67
+ `vike dev ${pc.cyan('--force')} ${TAB}${pc.dim("# Disable Vite's cache")}`,
68
+ ]
64
69
  .map((o) => ` ${pc.dim('$')} ${o}`)
65
70
  .join('\n'),
66
71
  '',
67
- `More Vike settings can be passed over the ${pc.cyan('VIKE_CONFIG')} environment variable or as ${pc.cyan('CLI options')}.`,
72
+ `More Vike settings can be passed over the ${pc.cyan('VIKE_CONFIG')} environment variable or as ${pc.cyan('CLI option')}.`,
68
73
  `More Vite settings can be passed over the ${pc.cyan('VITE_CONFIG')} environment variable.`,
69
- ``,
70
74
  `See ${pc.underline('https://vike.dev/cli')} for more information.`,
71
75
  ].join('\n'));
72
76
  process.exit(1);
@@ -64,11 +64,12 @@ async function renderPagePrepare(pageContextInit, httpRequestId) {
64
64
  await initGlobalContext_renderPage();
65
65
  }
66
66
  catch (err) {
67
- // Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
68
- // ```bash
69
- // Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
70
- // ```
71
- // initGlobalContext_renderPage() doesn't call any user hook => err isn't thrown from user code.
67
+ // Errors are expected:
68
+ // - assertUsage() such as:
69
+ // ```bash
70
+ // Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
71
+ // ```
72
+ // - initGlobalContext_renderPage() depends on +onCreateGlobalContext hooks
72
73
  assert(!isAbortError(err));
73
74
  logRuntimeError(err, httpRequestId);
74
75
  const pageContextWithError = getPageContextHttpResponseErrorWithoutGlobalContext(err, pageContextInit);
@@ -6,7 +6,7 @@ import { assertPosixPath, assert, assertUsage, isArray, isCallable } from '../..
6
6
  import path from 'node:path';
7
7
  import crypto from 'node:crypto';
8
8
  import { getAssetsDir } from '../../shared/getAssetsDir.js';
9
- import { assertModuleId, getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
9
+ import { assertModuleId, getFilePathToShowToUserModule } from '../../shared/getFilePath.js';
10
10
  function pluginDistFileNames() {
11
11
  return [
12
12
  {
@@ -63,7 +63,7 @@ function pluginDistFileNames() {
63
63
  name = isNodeModules[1];
64
64
  }
65
65
  else {
66
- const filePath = getModuleFilePathAbsolute(id, config);
66
+ const filePath = getFilePathToShowToUserModule(id, config);
67
67
  name = filePath;
68
68
  name = name.split('.').slice(0, -1).join('.'); // remove file extension
69
69
  name = name.split('/').filter(Boolean).join('_');
@@ -91,6 +91,11 @@ function pluginCommon(vikeVitePluginOptions) {
91
91
  // Set `--host` for Docker/Podman
92
92
  setDefault('host', true, configFromUser, configFromVike);
93
93
  }
94
+ // https://vike.dev/force
95
+ if (vikeConfig.config.force !== undefined && configFromUser.optimizeDeps?.force === undefined) {
96
+ configFromVike.optimizeDeps ?? (configFromVike.optimizeDeps = {});
97
+ configFromVike.optimizeDeps.force = vikeConfig.config.force;
98
+ }
94
99
  return configFromVike;
95
100
  },
96
101
  },
@@ -3,7 +3,7 @@ import { assert, assertUsage, assertWarning, capitalizeFirstLetter, isFilePathAb
3
3
  import { extractAssetsRE } from './pluginExtractAssets.js';
4
4
  import { extractExportNamesRE } from './pluginExtractExportNames.js';
5
5
  import pc from '@brillout/picocolors';
6
- import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
6
+ import { getFilePathToShowToUserModule } from '../shared/getFilePath.js';
7
7
  import { getExportNames } from '../shared/parseEsModule.js';
8
8
  import { normalizeId } from '../shared/normalizeId.js';
9
9
  import { isV1Design } from '../shared/resolveVikeConfigInternal.js';
@@ -42,8 +42,10 @@ function pluginFileEnv() {
42
42
  if (id.endsWith('?direct'))
43
43
  id = id.slice(0, -1 * '?direct'.length);
44
44
  const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
45
- assert(moduleInfo);
46
- const importers = Array.from(moduleInfo.importers)
45
+ /* It can fail, no clue why — https://github.com/vikejs/vike/issues/2740
46
+ assert(moduleInfo, { moduleId })
47
+ */
48
+ const importers = (!moduleInfo ? [] : Array.from(moduleInfo.importers))
47
49
  .map((m) => m.id)
48
50
  .filter((id) => id !== null);
49
51
  assertFileEnv(id, isViteServerSide_extraSafe(config, this.environment, options), importers,
@@ -122,7 +124,7 @@ function pluginFileEnv() {
122
124
  const envActual = isServerSide ? 'server' : 'client';
123
125
  const envExpect = isServerSide ? 'client' : 'server';
124
126
  let errMsg;
125
- let modulePathPretty = getModuleFilePathAbsolute(modulePath, config);
127
+ let modulePathPretty = getFilePathToShowToUserModule(modulePath, config);
126
128
  if (!noColor) {
127
129
  const suffix = getSuffix(envExpect);
128
130
  modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
@@ -133,13 +135,14 @@ function pluginFileEnv() {
133
135
  .filter((importer) =>
134
136
  // Can be Vike's virtual module: https://github.com/vikejs/vike/issues/2483
135
137
  isFilePathAbsolute(importer))
136
- .map((importer) => getModuleFilePathAbsolute(importer, config));
138
+ .map((importer) => getFilePathToShowToUserModule(importer, config))
139
+ .map((importPath) => pc.cyan(importPath));
137
140
  if (importPaths.length > 0) {
138
141
  errMsg += ` by ${joinEnglish(importPaths, 'and')}`;
139
142
  }
140
143
  }
141
144
  if (onlyWarn) {
142
- errMsg += ' and, therefore, Vike will prevent building your app for production.';
145
+ errMsg += ". This is potentially a security issue and Vike won't allow you to build your app for production.";
143
146
  }
144
147
  return errMsg;
145
148
  }
@@ -1,7 +1,7 @@
1
1
  export { pluginReplaceConstantsEnvVars };
2
2
  import { loadEnv } from 'vite';
3
3
  import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, isNotNullish, lowerFirst, } from '../utils.js';
4
- import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
4
+ import { getFilePathToShowToUserModule } from '../shared/getFilePath.js';
5
5
  import { normalizeId } from '../shared/normalizeId.js';
6
6
  import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
7
7
  import { getMagicString } from '../shared/getMagicString.js';
@@ -113,7 +113,7 @@ function assertNoClientSideLeak({ envName, envStatement, envStatementRegExpStr,
113
113
  // ❌ Security leak!
114
114
  // - Warning in dev
115
115
  // - assertUsage() and abort when building for production
116
- const modulePath = getModuleFilePathAbsolute(id, config);
116
+ const modulePath = getFilePathToShowToUserModule(id, config);
117
117
  const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
118
118
  const envNameFixed = `${PUBLIC_ENV_PREFIX}${envName}`;
119
119
  const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${envNameFixed}, see https://vike.dev/env`;
@@ -7,7 +7,7 @@ import { parseVirtualFileId } from '../../shared/virtualFileId.js';
7
7
  import { reloadVikeConfig, isV1Design, getVikeConfigInternalOptional } from '../shared/resolveVikeConfigInternal.js';
8
8
  import pc from '@brillout/picocolors';
9
9
  import { logConfigInfo } from '../shared/loggerNotProd.js';
10
- import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
10
+ import { getFilePathToShowToUserModule } from '../shared/getFilePath.js';
11
11
  import { isRunnable, updateUserFiles } from '../../runtime/globalContext.js';
12
12
  import { isPlusFile } from '../shared/resolveVikeConfigInternal/crawlPlusFiles.js';
13
13
  import { isTemporaryBuildFile } from '../shared/resolveVikeConfigInternal/transpileAndExecuteFile.js';
@@ -176,7 +176,7 @@ function reloadConfig(filePath, config, op, server) {
176
176
  // Ensure server.ssrLoadModule() loads fresh Vike virtual files (`reloadConfig()` > `updateUserFiles()` > `server.ssrLoadModule()`)
177
177
  invalidateVikeVirtualFiles(server);
178
178
  {
179
- const filePathToShowToUserResolved = getModuleFilePathAbsolute(filePath, config);
179
+ const filePathToShowToUserResolved = getFilePathToShowToUserModule(filePath, config);
180
180
  const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
181
181
  logConfigInfo(msg, 'info');
182
182
  }
@@ -1,9 +1,8 @@
1
1
  export { getFilePathResolved };
2
2
  export { getFilePathUnresolved };
3
3
  export { getFilePathAbsoluteUserRootDir };
4
- export { getFilePathToShowToUserFromUnknown };
5
- export { getModuleFilePathAbsolute };
6
- export { getModuleFilePathRelative };
4
+ export { getFilePathToShowToUserUnknown };
5
+ export { getFilePathToShowToUserModule };
7
6
  export { cleanFilePathUnknown };
8
7
  export { assertModuleId };
9
8
  import type { FilePathResolved, FilePathUnresolved } from '../../../types/FilePath.js';
@@ -24,8 +23,7 @@ declare function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, us
24
23
  filePathAbsoluteFilesystem: string;
25
24
  userRootDir: string;
26
25
  }): string | null;
27
- declare function getModuleFilePathAbsolute(moduleId: string, config: ResolvedConfig): string;
28
- declare function getModuleFilePathRelative(moduleId: string, config: ResolvedConfig): string;
26
+ declare function getFilePathToShowToUserModule(moduleId: string, config: ResolvedConfig): string;
29
27
  declare function assertModuleId(moduleId: string): void;
30
- declare function getFilePathToShowToUserFromUnknown(filePathUnknown: string, userRootDir: string): string;
28
+ declare function getFilePathToShowToUserUnknown(filePathUnknown: string, userRootDir: string): string;
31
29
  declare function cleanFilePathUnknown(filePathUnknown: string): string;
@@ -1,9 +1,8 @@
1
1
  export { getFilePathResolved };
2
2
  export { getFilePathUnresolved };
3
3
  export { getFilePathAbsoluteUserRootDir };
4
- export { getFilePathToShowToUserFromUnknown };
5
- export { getModuleFilePathAbsolute };
6
- export { getModuleFilePathRelative };
4
+ export { getFilePathToShowToUserUnknown };
5
+ export { getFilePathToShowToUserModule };
7
6
  export { cleanFilePathUnknown };
8
7
  export { assertModuleId };
9
8
  import path from 'node:path';
@@ -107,15 +106,11 @@ function getFilePathRelative({ filePathAbsoluteFilesystem, userRootDir, }) {
107
106
  return { filePathAbsoluteUserRootDir, filePathRelativeUserRootDir };
108
107
  }
109
108
  }
110
- function getModuleFilePathAbsolute(moduleId, config) {
111
- const { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem } = getModuleFilePath(moduleId, config);
109
+ function getFilePathToShowToUserModule(moduleId, config) {
110
+ const { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem } = getFilePathModule(moduleId, config);
112
111
  return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
113
112
  }
114
- function getModuleFilePathRelative(moduleId, config) {
115
- const { filePathRelativeUserRootDir } = getModuleFilePath(moduleId, config);
116
- return filePathRelativeUserRootDir;
117
- }
118
- function getModuleFilePath(moduleId, config) {
113
+ function getFilePathModule(moduleId, config) {
119
114
  const userRootDir = config.root;
120
115
  assertModuleId(moduleId);
121
116
  assertPosixPath(userRootDir);
@@ -132,7 +127,7 @@ function assertModuleId(moduleId) {
132
127
  assertPosixPath(moduleId);
133
128
  assertFilePathAbsoluteFilesystem(moduleId); // Can moduleId be something else than the filesystem absolute path?
134
129
  }
135
- function getFilePathToShowToUserFromUnknown(
130
+ function getFilePathToShowToUserUnknown(
136
131
  // We don't have any guarantee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
137
132
  filePathUnknown, userRootDir) {
138
133
  assertPosixPath(userRootDir);
@@ -8,7 +8,7 @@ export { getPrettyErrMessage };
8
8
  // Copied & adapted from https://github.com/vitejs/vite/blob/9c114c5c72a6af87e3330d5573362554b4511265/packages/vite/src/node/server/middlewares/error.ts
9
9
  import pc from '@brillout/picocolors';
10
10
  import { assert, escapeRegex, isObject, removeEmptyLines, stripAnsi } from '../../utils.js';
11
- import { cleanFilePathUnknown, getFilePathToShowToUserFromUnknown } from '../getFilePath.js';
11
+ import { cleanFilePathUnknown, getFilePathToShowToUserUnknown } from '../getFilePath.js';
12
12
  function isErrorWithCodeSnippet(err) {
13
13
  if (!isObject(err)) {
14
14
  return false;
@@ -47,7 +47,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
47
47
  let { id, frame } = err;
48
48
  const msgFirstLine = [
49
49
  pc.red('Failed to transpile'),
50
- pc.bold(pc.red(getFilePathToShowToUserFromUnknown(id, userRootDir))),
50
+ pc.bold(pc.red(getFilePathToShowToUserUnknown(id, userRootDir))),
51
51
  pc.red('because:'),
52
52
  ].join(' ');
53
53
  const errMsg = getPrettyErrMessage(err);
@@ -171,6 +171,10 @@ const configDefinitionsBuiltIn = {
171
171
  env: { config: true },
172
172
  global: true,
173
173
  },
174
+ force: {
175
+ env: { config: true },
176
+ global: true,
177
+ },
174
178
  csp: {
175
179
  env: { server: true },
176
180
  },
@@ -468,6 +468,12 @@ type ConfigBuiltIn = {
468
468
  * https://vike.dev/mode
469
469
  */
470
470
  mode?: string;
471
+ /**
472
+ * Disable Vite's cache.
473
+ *
474
+ * https://vike.dev/force
475
+ */
476
+ force?: boolean;
471
477
  /**
472
478
  * Content Security Policy (CSP).
473
479
  *
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.240-commit-309067c";
1
+ export declare const PROJECT_VERSION: "0.4.240-commit-42b44bb";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.240-commit-309067c';
2
+ export const PROJECT_VERSION = '0.4.240-commit-42b44bb';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.240-commit-309067c",
3
+ "version": "0.4.240-commit-42b44bb",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {