vike 0.4.247-commit-e331796 → 0.4.247-commit-87e5f2f

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.
@@ -1,4 +1,5 @@
1
1
  export { dev };
2
+ export { startupLog };
2
3
  import { type ResolvedConfig, type ViteDevServer } from 'vite';
3
4
  import type { ApiOptions } from './types.js';
4
5
  /**
@@ -13,3 +14,8 @@ declare function dev(options?: ApiOptions & {
13
14
  viteConfig: ResolvedConfig;
14
15
  viteVersion: string;
15
16
  }>;
17
+ declare function startupLog(resolvedUrls: ResolvedServerUrls, viteServer: ViteDevServer): Promise<void>;
18
+ interface ResolvedServerUrls {
19
+ local: string[];
20
+ network: string[];
21
+ }
@@ -1,8 +1,9 @@
1
1
  export { dev };
2
+ // TO-DO/eventually: remove if it doesn't end up being used
3
+ export { startupLog };
2
4
  import { prepareViteApiCall } from './prepareViteApiCall.js';
3
- import { createServer, version as viteVersionVike } from 'vite';
4
- import { viteVersionUser } from '../vite/plugins/pluginCommon.js';
5
- import { colorVike, colorVite, PROJECT_VERSION } from './utils.js';
5
+ import { createServer } from 'vite';
6
+ import { assert, colorVike, colorVite, PROJECT_VERSION } from './utils.js';
6
7
  import pc from '@brillout/picocolors';
7
8
  import { processStartupLog } from '../vite/shared/loggerVite.js';
8
9
  /**
@@ -11,23 +12,35 @@ import { processStartupLog } from '../vite/shared/loggerVite.js';
11
12
  * https://vike.dev/api#dev
12
13
  */
13
14
  async function dev(options = {}) {
14
- const startTime = performance.now();
15
15
  const { viteConfigFromUserResolved } = await prepareViteApiCall(options, 'dev');
16
16
  const server = await createServer(viteConfigFromUserResolved);
17
- const viteVersion = viteVersionUser ?? viteVersionVike;
18
17
  const viteServer = server;
19
18
  const viteConfig = server.config;
19
+ const viteVersion = viteConfig._viteVersionResolved;
20
+ assert(viteVersion);
20
21
  if (viteServer.httpServer)
21
22
  await viteServer.listen();
22
- if (options.startupLog)
23
- printStartupLog(viteServer, viteConfig, viteVersion, startTime);
23
+ if (options.startupLog) {
24
+ if (viteServer.resolvedUrls) {
25
+ startupLog(viteServer.resolvedUrls, viteServer);
26
+ }
27
+ else {
28
+ // TO-DO/eventually: remove if it doesn't end up being used
29
+ ;
30
+ viteConfig.server.startupLog = (resolvedUrls) => startupLog(resolvedUrls, viteServer);
31
+ }
32
+ }
24
33
  return {
25
34
  viteServer,
26
35
  viteConfig,
27
36
  viteVersion,
28
37
  };
29
38
  }
30
- async function printStartupLog(viteServer, viteConfig, viteVersion, startTime) {
39
+ const startTime = performance.now();
40
+ async function startupLog(resolvedUrls, viteServer) {
41
+ const viteConfig = viteServer.config;
42
+ const viteVersion = viteConfig._viteVersionResolved;
43
+ assert(viteVersion);
31
44
  const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
32
45
  const sep = pc.dim('·');
33
46
  const firstLine = `\n ${colorVike('Vike')} ${pc.yellow(`v${PROJECT_VERSION}`)} ${sep} ${colorVite('Vite')} ${pc.cyan(`v${viteVersion}`)} ${sep} ${startupDurationString}\n`;
@@ -36,7 +49,7 @@ async function printStartupLog(viteServer, viteConfig, viteVersion, startTime) {
36
49
  const { isCompact } = ret;
37
50
  // We don't call viteServer.printUrls() because Vite throws an error if `resolvedUrls` is missing:
38
51
  // https://github.com/vitejs/vite/blob/df5a30d2690a2ebc4824a79becdcef30538dc602/packages/vite/src/node/server/index.ts#L745
39
- printServerUrls(viteServer.resolvedUrls || { local: ['http://localhost:3000'], network: [] }, viteConfig.server.host);
52
+ printServerUrls(resolvedUrls, viteConfig.server.host);
40
53
  viteServer.bindCLIShortcuts({ print: true });
41
54
  if (!isCompact)
42
55
  console.log();
@@ -1,8 +1,12 @@
1
1
  export { pluginModuleBanner };
2
2
  import { assert, removeVirtualFileIdPrefix } from '../../utils.js';
3
3
  import { getMagicString } from '../../shared/getMagicString.js';
4
- // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
5
- // But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
4
+ // Misusing legal comments so that esbuild doesn't remove them.
5
+ // - Legal comments: https://esbuild.github.io/api/#legal-comments
6
+ // - Terser removes legal comments, but I guess users use terser to minify JavaScript so I guess it's a good thing that comment is removed.
7
+ // - Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
8
+ // - But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
9
+ // - Potential alternative: https://github.com/vitejs/vite/issues/21228#issuecomment-3627899741
6
10
  function pluginModuleBanner() {
7
11
  let config;
8
12
  let isEnabled = false;
@@ -39,9 +43,6 @@ function pluginModuleBanner() {
39
43
  id = id.slice(config.root.length + 1);
40
44
  id = id.replaceAll('*/', '*\\/'); // https://github.com/vikejs/vike/issues/2377
41
45
  const { magicString, getMagicStringResult } = getMagicString(code, id);
42
- // Use legal comment so that esbuild doesn't remove it.
43
- // - Terser still removes the comment, but I guess users use terser to minify JavaScript so I guess it's a good thing that comment is removed.
44
- // - https://esbuild.github.io/api/#legal-comments
45
46
  magicString.prepend(`/*! ${id} [vike:pluginModuleBanner] */\n`);
46
47
  return getMagicStringResult();
47
48
  },
@@ -1,5 +1,4 @@
1
1
  export { pluginCommon };
2
- export declare let viteVersionUser: string | null | undefined;
3
2
  import { type InlineConfig, type Plugin } from 'vite';
4
3
  import type { VitePluginServerEntryOptions } from '@brillout/vite-plugin-server-entry/plugin';
5
4
  declare module 'vite' {
@@ -9,6 +8,7 @@ declare module 'vite' {
9
8
  _rootResolvedEarly?: string;
10
9
  _baseViteOriginal?: string;
11
10
  _viteConfigFromUserResolved?: InlineConfig;
11
+ _viteVersionResolved?: string;
12
12
  }
13
13
  }
14
14
  declare global {
@@ -1,5 +1,4 @@
1
1
  export { pluginCommon };
2
- export let viteVersionUser = null;
3
2
  import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isExactlyOneTruthy, isObject, isVitest, } from '../utils.js';
4
3
  import { assertRollupInput } from './build/pluginBuildConfig.js';
5
4
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
@@ -10,6 +9,7 @@ import { isVikeCliOrApi } from '../../../shared-server-node/api-context.js';
10
9
  import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVikeConfigInternal.js';
11
10
  import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/resolveViteConfigFromUser.js';
12
11
  import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
12
+ import { version as viteVersionVike } from 'vite';
13
13
  const pluginName = 'vike:pluginCommon';
14
14
  globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
15
15
  function pluginCommon(vikeVitePluginOptions) {
@@ -20,7 +20,7 @@ function pluginCommon(vikeVitePluginOptions) {
20
20
  config: {
21
21
  order: 'pre',
22
22
  async handler(configFromUser, env) {
23
- viteVersionUser = this?.meta?.viteVersion; // is `undefined` on old Vite versions
23
+ const viteVersionUser = this?.meta?.viteVersion; // is `undefined` on old Vite versions
24
24
  const isDev = isDevCheck(env);
25
25
  const isBuild = env.command === 'build';
26
26
  const isPreview = env.isPreview;
@@ -34,6 +34,7 @@ function pluginCommon(vikeVitePluginOptions) {
34
34
  const vikeConfig = await getVikeConfigInternal();
35
35
  return {
36
36
  _isDev: isDev,
37
+ _viteVersionResolved: viteVersionUser || viteVersionVike,
37
38
  _rootResolvedEarly: rootResolvedEarly,
38
39
  // TO-DO/next-major-release: remove https://github.com/vikejs/vike/issues/2122
39
40
  configVikePromise: Promise.resolve({
@@ -0,0 +1 @@
1
+ export { startupLog } from '../../node/api/dev.js';
@@ -0,0 +1 @@
1
+ export { startupLog } from '../../node/api/dev.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.247-commit-e331796";
1
+ export declare const PROJECT_VERSION: "0.4.247-commit-87e5f2f";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.247-commit-e331796';
2
+ export const PROJECT_VERSION = '0.4.247-commit-87e5f2f';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.247-commit-e331796",
3
+ "version": "0.4.247-commit-87e5f2f",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -104,6 +104,10 @@
104
104
  "types": "./dist/server/runtime/page-files/setup.d.ts",
105
105
  "default": "./dist/server/runtime/page-files/setup.js"
106
106
  },
107
+ "./__internal/vite": {
108
+ "types": "./dist/server/__internal/vite.d.ts",
109
+ "default": "./dist/server/__internal/vite.js"
110
+ },
107
111
  ".": {
108
112
  "worker": "./dist/server/runtime/index.js",
109
113
  "workerd": "./dist/server/runtime/index.js",