vike 0.4.241 → 0.4.242-commit-4a9fae0

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.
Files changed (44) hide show
  1. package/dist/esm/node/api/build.js +6 -6
  2. package/dist/esm/node/api/dev.js +2 -2
  3. package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -9
  4. package/dist/esm/node/api/prepareViteApiCall.js +4 -156
  5. package/dist/esm/node/api/prerender.js +2 -2
  6. package/dist/esm/node/api/preview.js +2 -2
  7. package/dist/esm/node/api/resolveViteConfigFromUser.d.ts +20 -0
  8. package/dist/esm/node/api/resolveViteConfigFromUser.js +207 -0
  9. package/dist/esm/node/prerender/runPrerenderEntry.js +4 -4
  10. package/dist/esm/node/runtime/logErrorServer.js +8 -1
  11. package/dist/esm/node/runtime-dev/createDevMiddleware.js +2 -2
  12. package/dist/esm/node/vite/index.d.ts +1 -1
  13. package/dist/esm/node/vite/index.js +52 -21
  14. package/dist/esm/node/vite/plugins/build/handleAssetsManifest.d.ts +2 -4
  15. package/dist/esm/node/vite/plugins/build/handleAssetsManifest.js +7 -11
  16. package/dist/esm/node/vite/plugins/build/pluginBuildApp.js +6 -9
  17. package/dist/esm/node/vite/plugins/build/pluginBuildConfig.js +3 -16
  18. package/dist/esm/node/vite/plugins/pluginCommon.d.ts +1 -1
  19. package/dist/esm/node/vite/plugins/pluginCommon.js +9 -7
  20. package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +1 -0
  21. package/dist/esm/node/vite/plugins/pluginViteConfigVikeExtensions.d.ts +3 -0
  22. package/dist/esm/node/vite/plugins/pluginViteConfigVikeExtensions.js +32 -0
  23. package/dist/esm/node/vite/shared/isViteCli.d.ts +13 -0
  24. package/dist/esm/node/vite/shared/isViteCli.js +143 -0
  25. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +11 -2
  26. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +2 -0
  27. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +4 -0
  28. package/dist/esm/node/vite/utils.d.ts +1 -0
  29. package/dist/esm/node/vite/utils.js +1 -0
  30. package/dist/esm/shared/modifyUrlSameOrigin.js +2 -2
  31. package/dist/esm/shared/route/abort.js +2 -2
  32. package/dist/esm/shared/route/execHookOnBeforeRoute.js +3 -3
  33. package/dist/esm/types/index.d.ts +1 -0
  34. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  35. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  36. package/dist/esm/utils/isExactlyOneTruthy.d.ts +1 -0
  37. package/dist/esm/utils/isExactlyOneTruthy.js +4 -0
  38. package/dist/esm/utils/parseUrl.d.ts +4 -2
  39. package/dist/esm/utils/parseUrl.js +32 -25
  40. package/dist/esm/utils/unique.d.ts +1 -2
  41. package/dist/esm/utils/unique.js +1 -2
  42. package/package.json +2 -2
  43. package/dist/esm/node/vite/shared/isViteCliCall.d.ts +0 -10
  44. package/dist/esm/node/vite/shared/isViteCliCall.js +0 -81
@@ -3,14 +3,12 @@ export { handleAssetsManifest_getBuildConfig };
3
3
  export { handleAssetsManifest_isFixEnabled };
4
4
  export { handleAssetsManifest_assertUsageCssCodeSplit };
5
5
  export { handleAssetsManifest_assertUsageCssTarget };
6
- export { handleAssetsManifest_workaroundCssTarget_part1 };
7
- export { handleAssetsManifest_workaroundCssTarget_part2 };
6
+ export { handleAssetsManifest_alignCssTarget };
8
7
  import type { Environment, ResolvedConfig, Rollup } from 'vite';
9
8
  type Bundle = Rollup.OutputBundle;
10
9
  declare function handleAssetsManifest_isFixEnabled(): boolean;
11
10
  declare function handleAssetsManifest_assertUsageCssCodeSplit(config: ResolvedConfig): void;
12
- declare function handleAssetsManifest_workaroundCssTarget_part1(config: ResolvedConfig): void;
13
- declare function handleAssetsManifest_workaroundCssTarget_part2(): void;
11
+ declare function handleAssetsManifest_alignCssTarget(config: ResolvedConfig): void;
14
12
  declare function handleAssetsManifest_assertUsageCssTarget(config: ResolvedConfig, env: Environment): void;
15
13
  declare function handleAssetsManifest_getBuildConfig(): Promise<{
16
14
  readonly ssrEmitAssets: true | undefined;
@@ -3,8 +3,7 @@ export { handleAssetsManifest_getBuildConfig };
3
3
  export { handleAssetsManifest_isFixEnabled };
4
4
  export { handleAssetsManifest_assertUsageCssCodeSplit };
5
5
  export { handleAssetsManifest_assertUsageCssTarget };
6
- export { handleAssetsManifest_workaroundCssTarget_part1 };
7
- export { handleAssetsManifest_workaroundCssTarget_part2 };
6
+ export { handleAssetsManifest_alignCssTarget };
8
7
  import fs from 'node:fs/promises';
9
8
  import fs_sync from 'node:fs';
10
9
  import path from 'node:path';
@@ -20,7 +19,6 @@ import { set_macro_ASSETS_MANIFEST } from './pluginProdBuildEntry.js';
20
19
  import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
21
20
  const globalObject = getGlobalObject('handleAssetsManifest.ts', {
22
21
  assetsJsonFilePath: undefined,
23
- cssTarget: '__VIKE__UNSET',
24
22
  targetsAll: [],
25
23
  configsAll: [],
26
24
  });
@@ -221,15 +219,13 @@ function handleAssetsManifest_assertUsageCssCodeSplit(config) {
221
219
  return;
222
220
  assertWarning(config.build.cssCodeSplit, `${pc.cyan('build.cssCodeSplit')} shouldn't be set to ${pc.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
223
221
  }
224
- function handleAssetsManifest_workaroundCssTarget_part1(config) {
222
+ function handleAssetsManifest_alignCssTarget(config) {
225
223
  globalObject.configsAll.push(config);
226
- if (!isViteServerSide_viteEnvOptional(config, undefined)) {
227
- globalObject.cssTarget = config.build.cssTarget;
228
- }
229
- }
230
- function handleAssetsManifest_workaroundCssTarget_part2() {
231
- assert(globalObject.cssTarget !== '__VIKE__UNSET');
232
- globalObject.configsAll.forEach((c) => (c.build.cssTarget = globalObject.cssTarget));
224
+ const { cssTarget } = globalObject.configsAll
225
+ .filter((c) => !isViteServerSide_viteEnvOptional(c, undefined))
226
+ .at(-1).build;
227
+ assert(cssTarget);
228
+ globalObject.configsAll.forEach((c) => (c.build.cssTarget = cssTarget));
233
229
  }
234
230
  function handleAssetsManifest_assertUsageCssTarget(config, env) {
235
231
  if (!handleAssetsManifest_isFixEnabled())
@@ -3,7 +3,7 @@ import { runPrerender_forceExit } from '../../../prerender/runPrerenderEntry.js'
3
3
  import { resolveOutDir } from '../../shared/getOutDirs.js';
4
4
  import { assert, assertWarning, getGlobalObject, onSetupBuild } from '../../utils.js';
5
5
  import { isPrerenderAutoRunEnabled, wasPrerenderRun } from '../../../prerender/context.js';
6
- import { isViteCliCall, getViteConfigFromCli } from '../../shared/isViteCliCall.js';
6
+ import { isViteCli, getViteConfigForBuildFromCli } from '../../shared/isViteCli.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  import { logErrorHint } from '../../../runtime/renderPage/logErrorHint.js';
9
9
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
@@ -113,9 +113,6 @@ function pluginBuildApp() {
113
113
  handler() {
114
114
  onSetupBuild();
115
115
  handleAssetsManifest_assertUsageCssTarget(config, this.environment);
116
- /* Let vike:build:pluginBuildApp force exit
117
- runPrerender_forceExit()
118
- */
119
116
  },
120
117
  },
121
118
  },
@@ -142,7 +139,7 @@ async function triggerPrerendering(config, viteEnv, bundle) {
142
139
  }
143
140
  async function abortViteBuildSsr() {
144
141
  const vikeConfig = await getVikeConfigInternal();
145
- if (vikeConfig.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
142
+ if (vikeConfig.config.disableAutoFullBuild !== true && isViteCli() && getViteConfigForBuildFromCli()?.build.ssr) {
146
143
  assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
147
144
  process.exit(0);
148
145
  }
@@ -150,7 +147,7 @@ async function abortViteBuildSsr() {
150
147
  function isDisabled(vikeConfig) {
151
148
  const { disableAutoFullBuild } = vikeConfig.config;
152
149
  if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
153
- const isUserUsingViteApi = !isViteCliCall() && !isVikeCliOrApi();
150
+ const isUserUsingViteApi = !isViteCli() && !isVikeCliOrApi();
154
151
  return isUserUsingViteApi;
155
152
  }
156
153
  else {
@@ -161,9 +158,9 @@ function isPrerenderForceExit() {
161
158
  return globalObject.forceExit;
162
159
  }
163
160
  function getFullBuildInlineConfig(config) {
164
- const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
165
- if (config._viteConfigFromUserEnhanced) {
166
- return config._viteConfigFromUserEnhanced;
161
+ const configFromCli = !isViteCli() ? null : getViteConfigForBuildFromCli();
162
+ if (config._viteConfigFromUserResolved) {
163
+ return config._viteConfigFromUserResolved;
167
164
  }
168
165
  else {
169
166
  return {
@@ -10,31 +10,18 @@ import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
10
10
  import { getFilePathResolved } from '../../shared/getFilePath.js';
11
11
  import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
12
12
  import { isViteServerSide_viteEnvOptional } from '../../shared/isViteServerSide.js';
13
- import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, handleAssetsManifest_workaroundCssTarget_part1, handleAssetsManifest_workaroundCssTarget_part2, } from './handleAssetsManifest.js';
13
+ import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, handleAssetsManifest_alignCssTarget, } from './handleAssetsManifest.js';
14
14
  import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
15
15
  function pluginBuildConfig() {
16
- let config;
17
16
  return [
18
- {
19
- name: 'vike:build:pluginBuildConfig:post1',
20
- apply: 'build',
21
- enforce: 'post',
22
- configResolved: {
23
- order: 'post',
24
- handler(config_) {
25
- config = config_;
26
- handleAssetsManifest_workaroundCssTarget_part1(config);
27
- },
28
- },
29
- },
30
17
  {
31
18
  name: 'vike:build:pluginBuildConfig:post2',
32
19
  apply: 'build',
33
20
  enforce: 'post',
34
21
  configResolved: {
35
22
  order: 'post',
36
- async handler() {
37
- handleAssetsManifest_workaroundCssTarget_part2();
23
+ async handler(config) {
24
+ handleAssetsManifest_alignCssTarget(config);
38
25
  onSetupBuild();
39
26
  assertRollupInput(config);
40
27
  const entries = await getEntries(config);
@@ -7,7 +7,7 @@ declare module 'vite' {
7
7
  _isDev?: boolean;
8
8
  _rootResolvedEarly?: string;
9
9
  _baseViteOriginal?: string;
10
- _viteConfigFromUserEnhanced?: InlineConfig;
10
+ _viteConfigFromUserResolved?: InlineConfig;
11
11
  }
12
12
  }
13
13
  declare global {
@@ -1,13 +1,13 @@
1
1
  export { pluginCommon };
2
- import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isObject, isVitest } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isExactlyOneTruthy, isObject, isVitest, } from '../utils.js';
3
3
  import { assertRollupInput } from './build/pluginBuildConfig.js';
4
4
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
5
5
  import pc from '@brillout/picocolors';
6
6
  import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
7
- import { isViteCliCall } from '../shared/isViteCliCall.js';
7
+ import { isViteCli } from '../shared/isViteCli.js';
8
8
  import { isVikeCliOrApi } from '../../api/context.js';
9
9
  import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVikeConfigInternal.js';
10
- import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
10
+ import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/resolveViteConfigFromUser.js';
11
11
  import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
12
12
  const pluginName = 'vike:pluginCommon';
13
13
  globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
@@ -20,12 +20,14 @@ function pluginCommon(vikeVitePluginOptions) {
20
20
  order: 'pre',
21
21
  async handler(configFromUser, env) {
22
22
  const isDev = isDevCheck(env);
23
- const operation = env.command === 'build' ? 'build' : env.isPreview ? 'preview' : 'dev';
23
+ const isBuild = env.command === 'build';
24
+ const isPreview = env.isPreview;
25
+ assert(isExactlyOneTruthy(isDev, isBuild, isPreview));
26
+ const viteContext = isBuild ? 'build' : isPreview ? 'preview' : 'dev';
24
27
  const rootResolvedEarly = configFromUser.root
25
28
  ? normalizeViteRoot(configFromUser.root)
26
- : await getViteRoot(operation);
29
+ : await getViteRoot(viteContext);
27
30
  assert(rootResolvedEarly);
28
- // TO-DO/next-major-release: we can remove setVikeConfigContext() call here since with Vike's CLI it's already called at vike/node/api/prepareViteApiCall.ts
29
31
  setVikeConfigContext({ userRootDir: rootResolvedEarly, isDev, vikeVitePluginOptions });
30
32
  const vikeConfig = await getVikeConfigInternal();
31
33
  return {
@@ -132,7 +134,7 @@ function assertSingleInstance(config) {
132
134
  function assertVikeCliOrApi(config) {
133
135
  if (isVikeCliOrApi())
134
136
  return;
135
- if (isViteCliCall()) {
137
+ if (isViteCli()) {
136
138
  assert(!isVitest());
137
139
  return;
138
140
  }
@@ -1,4 +1,5 @@
1
1
  export { pluginReplaceConstantsGlobalThis };
2
+ export type _LoadDeclareGlobal__VIKE__IS = never;
2
3
  import type { Plugin } from 'vite';
3
4
  declare global {
4
5
  /** Like `import.meta.env.DEV` but works for `node_modules/` packages with `ssr.external` */
@@ -0,0 +1,3 @@
1
+ export { pluginViteConfigVikeExtensions };
2
+ import type { Plugin } from 'vite';
3
+ declare function pluginViteConfigVikeExtensions(): Promise<Plugin[]>;
@@ -0,0 +1,32 @@
1
+ export { pluginViteConfigVikeExtensions };
2
+ import { mergeConfig } from 'vite';
3
+ import { assertUsage, isObject } from '../utils.js';
4
+ import { getVikeConfigInternalEarly } from '../../api/resolveViteConfigFromUser.js';
5
+ // Apply +vite
6
+ // - For example, Vike extensions adding Vite plugins
7
+ async function pluginViteConfigVikeExtensions() {
8
+ const vikeConfig = await getVikeConfigInternalEarly();
9
+ if (vikeConfig === null)
10
+ return [];
11
+ let viteConfigFromExtensions = {};
12
+ const viteConfigsExtensions = vikeConfig._from.configsCumulative.vite;
13
+ if (!viteConfigsExtensions)
14
+ return [];
15
+ viteConfigsExtensions.values.forEach((v) => {
16
+ assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
17
+ viteConfigFromExtensions = mergeConfig(viteConfigFromExtensions, v.value);
18
+ });
19
+ const pluginsFromExtensions = (viteConfigFromExtensions.plugins ?? []);
20
+ delete viteConfigFromExtensions.plugins;
21
+ return [
22
+ ...pluginsFromExtensions,
23
+ {
24
+ name: 'vike:pluginViteConfigVikeExtensions',
25
+ config: {
26
+ handler(_config) {
27
+ return viteConfigFromExtensions;
28
+ },
29
+ },
30
+ },
31
+ ];
32
+ }
@@ -0,0 +1,13 @@
1
+ export { isViteCli };
2
+ export { getViteConfigForBuildFromCli };
3
+ export { getViteCommandFromCli };
4
+ declare function isViteCli(): boolean;
5
+ type ConfigFromCli = {
6
+ root: undefined | string;
7
+ configFile: undefined | string;
8
+ } & Record<string, unknown> & {
9
+ build: Record<string, unknown>;
10
+ };
11
+ type ViteCommand = 'dev' | 'build' | 'optimize' | 'preview';
12
+ declare function getViteCommandFromCli(): ViteCommand | null;
13
+ declare function getViteConfigForBuildFromCli(): null | ConfigFromCli;
@@ -0,0 +1,143 @@
1
+ export { isViteCli };
2
+ export { getViteConfigForBuildFromCli };
3
+ export { getViteCommandFromCli };
4
+ import { assert, isObject, toPosixPath } from '../utils.js';
5
+ import { cac } from 'cac';
6
+ const desc = 'vike:vite-cli-simulation';
7
+ function isViteCli() {
8
+ let execPath = process.argv[1];
9
+ assert(execPath);
10
+ execPath = toPosixPath(execPath);
11
+ return (
12
+ // pnpm
13
+ execPath.endsWith('/bin/vite.js') ||
14
+ // npm & yarn
15
+ execPath.endsWith('/.bin/vite') ||
16
+ // Global install
17
+ execPath.endsWith('/bin/vite'));
18
+ }
19
+ function getViteCommandFromCli() {
20
+ if (!isViteCli())
21
+ return null;
22
+ let command;
23
+ const setCommand = (cmd) => {
24
+ assert(command === undefined);
25
+ command = cmd;
26
+ };
27
+ // Copied & adapted from Vite
28
+ // https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L186-L188
29
+ const cli = cac(desc);
30
+ // dev
31
+ cli
32
+ .command('[root]', desc)
33
+ .alias('serve')
34
+ .alias('dev')
35
+ .action(() => {
36
+ setCommand('dev');
37
+ });
38
+ // build
39
+ cli.command('build [root]', desc).action(() => {
40
+ setCommand('build');
41
+ });
42
+ // optimize
43
+ cli.command('optimize [root]', desc).action(() => {
44
+ setCommand('optimize');
45
+ });
46
+ // preview
47
+ cli.command('preview [root]', desc).action(() => {
48
+ setCommand('preview');
49
+ });
50
+ cli.parse();
51
+ assert(command);
52
+ return command;
53
+ }
54
+ function getViteConfigForBuildFromCli() {
55
+ if (!isViteCli())
56
+ return null;
57
+ // Copied & adapted from Vite
58
+ const cli = cac(desc);
59
+ // Common configs
60
+ // https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L169-L182
61
+ cli
62
+ .option('-c, --config <file>', desc)
63
+ .option('--base <path>', desc)
64
+ .option('-l, --logLevel <level>', desc)
65
+ .option('--clearScreen', desc)
66
+ .option('--configLoader <loader>', desc)
67
+ .option('-d, --debug [feat]', desc)
68
+ .option('-f, --filter <filter>', desc)
69
+ .option('-m, --mode <mode>', desc);
70
+ // Build configs
71
+ // https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L286-L322
72
+ cli
73
+ .command('build [root]', desc)
74
+ .option('--target <target>', desc)
75
+ .option('--outDir <dir>', desc)
76
+ .option('--assetsDir <dir>', desc)
77
+ .option('--assetsInlineLimit <number>', desc)
78
+ .option('--ssr [entry]', desc)
79
+ .option('--sourcemap', desc)
80
+ .option('--minify [minifier]', desc)
81
+ .option('--manifest [name]', desc)
82
+ .option('--ssrManifest [name]', desc)
83
+ .option('--emptyOutDir', desc)
84
+ .option('-w, --watch', desc)
85
+ .option('--app', desc)
86
+ .action((root, options) => {
87
+ assert(isObject(options));
88
+ assert(root === undefined || typeof root === 'string');
89
+ assert(options.config === undefined || typeof options.config === 'string');
90
+ // https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L331-L346
91
+ const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
92
+ configFromCli = {
93
+ root,
94
+ base: options.base,
95
+ mode: options.mode,
96
+ configFile: options.config,
97
+ configLoader: options.configLoader,
98
+ logLevel: options.logLevel,
99
+ clearScreen: options.clearScreen,
100
+ build: buildOptions,
101
+ ...(options.app ? { builder: {} } : {}),
102
+ };
103
+ });
104
+ let configFromCli = null;
105
+ cli.parse();
106
+ return configFromCli;
107
+ // https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L99
108
+ function cleanGlobalCLIOptions(options) {
109
+ const ret = { ...options };
110
+ delete ret['--'];
111
+ delete ret.c;
112
+ delete ret.config;
113
+ delete ret.base;
114
+ delete ret.l;
115
+ delete ret.logLevel;
116
+ delete ret.clearScreen;
117
+ delete ret.configLoader;
118
+ delete ret.d;
119
+ delete ret.debug;
120
+ delete ret.f;
121
+ delete ret.filter;
122
+ delete ret.m;
123
+ delete ret.mode;
124
+ delete ret.force;
125
+ delete ret.w;
126
+ // convert the sourcemap option to a boolean if necessary
127
+ if ('sourcemap' in ret) {
128
+ const sourcemap = ret.sourcemap;
129
+ ret.sourcemap = sourcemap === 'true' ? true : sourcemap === 'false' ? false : ret.sourcemap;
130
+ }
131
+ if ('watch' in ret) {
132
+ const watch = ret.watch;
133
+ ret.watch = watch ? {} : undefined;
134
+ }
135
+ return ret;
136
+ }
137
+ // https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L141
138
+ function cleanBuilderCLIOptions(options) {
139
+ const ret = { ...options };
140
+ delete ret.app;
141
+ return ret;
142
+ }
143
+ }
@@ -141,6 +141,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
141
141
  return resolved;
142
142
  }
143
143
  assert(resolved.path);
144
+ // Built-in modules e.g. node:fs
145
+ if (resolved.path === args.path) {
146
+ const isPointerImport = false;
147
+ pointerImports[args.path] = isPointerImport;
148
+ if (debug.isActivated)
149
+ debug('onResolve() [built-in module]', { args, resolved });
150
+ assert(resolved.external);
151
+ return resolved;
152
+ }
144
153
  const importPathResolved = toPosixPath(resolved.path);
145
154
  const importPathOriginal = args.path;
146
155
  // Esbuild resolves path aliases.
@@ -185,7 +194,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
185
194
  // User-land config code (i.e. not runtime code) => let esbuild transpile it
186
195
  assert(!isPointerImport && !isNpmPkgImport);
187
196
  if (debug.isActivated)
188
- debug('onResolved()', { args, resolved, isPointerImport, isExternal });
197
+ debug('onResolve() [non-external]', { args, resolved, isPointerImport, isExternal });
189
198
  return resolved;
190
199
  }
191
200
  let importPathTranspiled;
@@ -217,7 +226,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
217
226
  }
218
227
  }
219
228
  if (debug.isActivated)
220
- debug('onResolved()', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
229
+ debug('onResolve() [external]', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
221
230
  assert(isExternal);
222
231
  assert(
223
232
  // Import of runtime code => handled by Vike
@@ -4,6 +4,7 @@ export { getVikeConfigInternal };
4
4
  export { getVikeConfigInternalOptional };
5
5
  export { getVikeConfigInternalSync };
6
6
  export { setVikeConfigContext };
7
+ export { isVikeConfigContextSet };
7
8
  export { reloadVikeConfig };
8
9
  export { isV1Design };
9
10
  export { getConfVal };
@@ -45,6 +46,7 @@ declare function getVikeConfigInternalSync(): VikeConfigInternal;
45
46
  declare function getVikeConfig(config: ResolvedConfig | UserConfig): VikeConfig;
46
47
  type VikeConfig = Pick<VikeConfigInternal, 'config' | 'pages' | 'prerenderContext'>;
47
48
  declare function setVikeConfigContext(vikeConfigCtx_: VikeConfigContext): void;
49
+ declare function isVikeConfigContextSet(): boolean;
48
50
  declare function getVikeConfigInternalOptional(): Promise<null | VikeConfigInternal>;
49
51
  declare function isV1Design(): boolean;
50
52
  declare function getVikeConfigFromCliOrEnv(): {
@@ -5,6 +5,7 @@ export { getVikeConfigInternal };
5
5
  export { getVikeConfigInternalOptional };
6
6
  export { getVikeConfigInternalSync };
7
7
  export { setVikeConfigContext };
8
+ export { isVikeConfigContextSet };
8
9
  export { reloadVikeConfig };
9
10
  export { isV1Design };
10
11
  export { getConfVal };
@@ -83,6 +84,9 @@ function setVikeConfigContext(vikeConfigCtx_) {
83
84
  // If the user changes Vite's `config.root` => Vite completely reloads itself => setVikeConfigContext() is called again
84
85
  globalObject.vikeConfigCtx = vikeConfigCtx_;
85
86
  }
87
+ function isVikeConfigContextSet() {
88
+ return !!globalObject.vikeConfigCtx;
89
+ }
86
90
  async function getOrResolveVikeConfig(userRootDir, isDev, vikeVitePluginOptions, doNotRestartViteOnError) {
87
91
  if (!globalObject.vikeConfigPromise) {
88
92
  resolveVikeConfigInternal_withErrorHandling(userRootDir, isDev, vikeVitePluginOptions, doNotRestartViteOnError);
@@ -20,3 +20,4 @@ export * from '../../utils/isVitest.js';
20
20
  export * from '../../utils/rollupSourceMap.js';
21
21
  export * from '../../utils/isImportPath.js';
22
22
  export * from '../../utils/virtualFileId.js';
23
+ export * from '../../utils/isExactlyOneTruthy.js';
@@ -27,3 +27,4 @@ export * from '../../utils/isVitest.js';
27
27
  export * from '../../utils/rollupSourceMap.js';
28
28
  export * from '../../utils/isImportPath.js';
29
29
  export * from '../../utils/virtualFileId.js';
30
+ export * from '../../utils/isExactlyOneTruthy.js';
@@ -1,12 +1,12 @@
1
1
  export { modifyUrlSameOrigin };
2
2
  // We don't move modifyUrlSameOrigin() to the modifyUrl.ts file because we plan to use modifyUrlSameOrigin() on the client-side:
3
3
  // https://github.com/vikejs/vike/blob/c5a2de5e85262771f97851767c00ac35da69c64b/packages/vike/client/runtime-client-routing/navigate.ts#L4
4
- import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathnameAbsolute, } from './utils.js';
4
+ import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathAbsolute, } from './utils.js';
5
5
  function modifyUrlSameOrigin(url, modify) {
6
6
  const urlParsed = parseUrl(url, '/');
7
7
  // Pathname
8
8
  const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
9
- assertUsageUrlPathnameAbsolute(pathname, 'modify.pathname');
9
+ assertUsageUrlPathAbsolute(pathname, 'modify.pathname');
10
10
  // Search
11
11
  let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
12
12
  if (search === '?')
@@ -8,7 +8,7 @@ export { getPageContextFromAllRewrites };
8
8
  export { AbortRender };
9
9
  export { assertNoInfiniteAbortLoop };
10
10
  import { isUserHookError } from '../hooks/execHook.js';
11
- import { assert, assertInfo, assertUsage, assertUsageUrlPathnameAbsolute, assertUsageUrlRedirectTarget, assertWarning, checkType, hasProp, isBrowser, joinEnglish, objectAssign, truncateString, } from './utils.js';
11
+ import { assert, assertInfo, assertUsage, assertUsageUrlPathAbsolute, assertUsageUrlRedirectTarget, assertWarning, checkType, hasProp, isBrowser, joinEnglish, objectAssign, truncateString, } from './utils.js';
12
12
  import pc from '@brillout/picocolors';
13
13
  /**
14
14
  * Abort the rendering of the current page, and redirect the user to another URL instead.
@@ -66,7 +66,7 @@ function render_(urlOrStatusCode, abortReason, abortCall, abortCaller, pageConte
66
66
  }
67
67
  if (typeof urlOrStatusCode === 'string') {
68
68
  const url = urlOrStatusCode;
69
- assertUsageUrlPathnameAbsolute(url, getErrPrefix(abortCaller));
69
+ assertUsageUrlPathAbsolute(url, getErrPrefix(abortCaller));
70
70
  objectAssign(pageContextAbort, {
71
71
  _urlRewrite: url,
72
72
  });
@@ -1,6 +1,6 @@
1
1
  export { execHookOnBeforeRoute };
2
2
  import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByUser.js';
3
- import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrlPathnameAbsolute, joinEnglish, assert, } from './utils.js';
3
+ import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrlAbsolute, joinEnglish, assert, } from './utils.js';
4
4
  import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
5
5
  import pc from '@brillout/picocolors';
6
6
  import { execHookDirectSync } from '../hooks/execHook.js';
@@ -65,8 +65,8 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
65
65
  delete hookReturn.pageContext.urlOriginal;
66
66
  }
67
67
  if (hasProp(hookReturn.pageContext, 'urlLogical')) {
68
- assertUsageUrlPathnameAbsolute(
69
- // We skip validation and type-cast instead of assertUsage() in order to save client-side KBs
68
+ assertUsageUrlAbsolute(
69
+ // We type-cast instead of assertUsage() validation in order to save client-side KBs
70
70
  hookReturn.pageContext.urlLogical, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlLogical } }')} and ${pc.cyan('urlLogical')}`);
71
71
  }
72
72
  assertPageContextProvidedByUser(hookReturn.pageContext, {
@@ -13,6 +13,7 @@ export type { VikeConfig } from '../node/vite/shared/resolveVikeConfigInternal.j
13
13
  export type { UrlPublic as Url } from '../utils/parseUrl.js';
14
14
  export type { InjectFilterEntry } from '../node/runtime/renderPage/html/injectAssets/getHtmlTags.js';
15
15
  export { defineConfig } from './defineConfig.js';
16
+ export type { _LoadDeclareGlobal__VIKE__IS } from '../node/vite/plugins/pluginReplaceConstantsGlobalThis.js';
16
17
  import type { ConfigEnv } from './PageConfig.js';
17
18
  /** @deprecated Replace:
18
19
  * `import type { Env } from 'vike/types'`
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.241";
1
+ export declare const PROJECT_VERSION: "0.4.242-commit-4a9fae0";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.241';
2
+ export const PROJECT_VERSION = '0.4.242-commit-4a9fae0';
@@ -0,0 +1 @@
1
+ export declare function isExactlyOneTruthy(...values: unknown[]): boolean;
@@ -0,0 +1,4 @@
1
+ // Aka XOR
2
+ export function isExactlyOneTruthy(...values) {
3
+ return values.filter(Boolean).length === 1;
4
+ }
@@ -1,5 +1,6 @@
1
1
  export { parseUrl };
2
- export { assertUsageUrlPathnameAbsolute };
2
+ export { assertUsageUrlAbsolute };
3
+ export { assertUsageUrlPathAbsolute };
3
4
  export { assertUsageUrlRedirectTarget };
4
5
  export { isUrl };
5
6
  export { isUri };
@@ -52,5 +53,6 @@ declare function isUrlRedirectTarget(url: string): boolean;
52
53
  declare function isUrlRelative(url: string): boolean;
53
54
  declare function isUrlExternal(url: string): boolean;
54
55
  declare function isUri(uri: string): boolean;
55
- declare function assertUsageUrlPathnameAbsolute(url: string, errPrefix: string): void;
56
+ declare function assertUsageUrlAbsolute(url: string, errPrefix: string): void;
57
+ declare function assertUsageUrlPathAbsolute(url: string, errPrefix: string): void;
56
58
  declare function assertUsageUrlRedirectTarget(url: string, errPrefix: string, isUnresolved?: true): void;