vike 0.4.225-commit-b8fc36e → 0.4.225-commit-6fc12fc

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 (59) hide show
  1. package/dist/cjs/node/api/prepareViteApiCall.js +4 -2
  2. package/dist/cjs/node/api/prerender.js +0 -1
  3. package/dist/cjs/node/api/preview.js +25 -6
  4. package/dist/cjs/node/cli/entry.js +4 -2
  5. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +51 -0
  6. package/dist/cjs/node/plugin/plugins/build.js +3 -1
  7. package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -0
  8. package/dist/cjs/node/prerender/utils.js +1 -1
  9. package/dist/cjs/node/runtime/globalContext.js +8 -4
  10. package/dist/cjs/node/runtime/utils.js +1 -1
  11. package/dist/cjs/node/shared/utils.js +1 -1
  12. package/dist/cjs/node/shared/virtual-files.js +14 -10
  13. package/dist/cjs/shared/modifyUrl.js +3 -5
  14. package/dist/cjs/shared/modifyUrlSameOrigin.js +42 -0
  15. package/dist/cjs/shared/utils.js +2 -1
  16. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  17. package/dist/cjs/utils/isNullish.js +16 -0
  18. package/dist/cjs/utils/objectFilter.js +10 -0
  19. package/dist/esm/client/client-routing-runtime/navigate.d.ts +6 -5
  20. package/dist/esm/client/client-routing-runtime/navigate.js +6 -2
  21. package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +1 -1
  22. package/dist/esm/node/api/prepareViteApiCall.d.ts +1 -0
  23. package/dist/esm/node/api/prepareViteApiCall.js +4 -2
  24. package/dist/esm/node/api/prerender.js +0 -1
  25. package/dist/esm/node/api/preview.d.ts +1 -1
  26. package/dist/esm/node/api/preview.js +22 -6
  27. package/dist/esm/node/cli/entry.js +4 -2
  28. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.d.ts +3 -0
  29. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +49 -0
  30. package/dist/esm/node/plugin/plugins/build.js +3 -1
  31. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
  32. package/dist/esm/node/plugin/plugins/commonConfig.js +4 -0
  33. package/dist/esm/node/prerender/utils.d.ts +1 -1
  34. package/dist/esm/node/prerender/utils.js +1 -1
  35. package/dist/esm/node/runtime/globalContext.d.ts +2 -3
  36. package/dist/esm/node/runtime/globalContext.js +8 -4
  37. package/dist/esm/node/runtime/utils.d.ts +1 -1
  38. package/dist/esm/node/runtime/utils.js +1 -1
  39. package/dist/esm/node/shared/utils.d.ts +1 -1
  40. package/dist/esm/node/shared/utils.js +1 -1
  41. package/dist/esm/node/shared/virtual-files.d.ts +2 -0
  42. package/dist/esm/node/shared/virtual-files.js +14 -10
  43. package/dist/esm/shared/modifyUrl.d.ts +2 -2
  44. package/dist/esm/shared/modifyUrl.js +3 -5
  45. package/dist/esm/shared/modifyUrlSameOrigin.d.ts +9 -0
  46. package/dist/esm/shared/modifyUrlSameOrigin.js +40 -0
  47. package/dist/esm/shared/utils.d.ts +2 -1
  48. package/dist/esm/shared/utils.js +2 -1
  49. package/dist/esm/types/index.d.ts +0 -1
  50. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  51. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  52. package/dist/esm/utils/isNullish.d.ts +3 -0
  53. package/dist/esm/utils/isNullish.js +11 -0
  54. package/dist/esm/utils/objectFilter.d.ts +1 -0
  55. package/dist/esm/utils/objectFilter.js +7 -0
  56. package/package.json +2 -2
  57. package/dist/cjs/utils/isNotNullish.js +0 -5
  58. package/dist/esm/utils/isNotNullish.d.ts +0 -1
  59. package/dist/esm/utils/isNotNullish.js +0 -1
@@ -62,11 +62,12 @@ function clear() {
62
62
  }
63
63
  async function resolveConfigs(viteConfigFromUserApiOptions, operation) {
64
64
  const viteInfo = await getViteInfo(viteConfigFromUserApiOptions, operation);
65
- await assertViteRoot2(viteInfo.root, viteInfo.viteConfigFromUserEnhanced, operation);
65
+ const { viteConfigResolved } = await assertViteRoot2(viteInfo.root, viteInfo.viteConfigFromUserEnhanced, operation);
66
66
  const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
67
67
  const viteConfigFromUserEnhanced = applyVikeViteConfig(viteInfo.viteConfigFromUserEnhanced, vikeConfig);
68
68
  return {
69
69
  vikeConfig,
70
+ viteConfigResolved, // ONLY USE if strictly necessary. (We plan to remove assertViteRoot2() as explained in the comments of that function.)
70
71
  viteConfigFromUserEnhanced
71
72
  };
72
73
  }
@@ -189,9 +190,10 @@ function normalizeViteRoot(root) {
189
190
  const errMsg = `A Vite plugin is modifying Vite's setting ${picocolors_1.default.cyan('root')} which is forbidden`;
190
191
  async function assertViteRoot2(root, viteConfigFromUserEnhanced, operation) {
191
192
  const args = getResolveConfigArgs(viteConfigFromUserEnhanced, operation);
192
- // We can eventually this resolveConfig() call (along with removing the whole assertViteRoot2() function which is redundant with the assertViteRoot() function) so that Vike doesn't make any resolveConfig() (except for pre-rendering which is required). But let's keep it for now, just to see whether calling resolveConfig() can be problematic.
193
+ // We can eventually remove this resolveConfig() call (along with removing the whole assertViteRoot2() function which is redundant with the assertViteRoot() function) so that Vike doesn't make any resolveConfig() (except for pre-rendering and preview which is required). But let's keep it for now, just to see whether calling resolveConfig() can be problematic.
193
194
  const viteConfigResolved = await (0, vite_1.resolveConfig)(...args);
194
195
  (0, utils_js_1.assertUsage)(normalizeViteRoot(viteConfigResolved.root) === normalizeViteRoot(root), errMsg);
196
+ return { viteConfigResolved };
195
197
  }
196
198
  function assertViteRoot(root, config) {
197
199
  if (globalObject.root)
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prerender = prerender;
4
4
  const runPrerender_js_1 = require("../prerender/runPrerender.js");
5
5
  const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
6
- // TODO/soon use importServerProductionIndex()
7
6
  /**
8
7
  * Programmatically trigger `$ vike prerender`
9
8
  *
@@ -1,18 +1,37 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.preview = preview;
4
7
  const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
5
8
  const vite_1 = require("vite");
9
+ const runtime_1 = require("@brillout/vite-plugin-server-entry/runtime");
10
+ const getOutDirs_js_1 = require("../plugin/shared/getOutDirs.js");
11
+ const utils_js_1 = require("./utils.js");
12
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
+ const node_path_1 = __importDefault(require("node:path"));
6
14
  /**
7
15
  * Programmatically trigger `$ vike preview`
8
16
  *
9
17
  * https://vike.dev/api#preview
10
18
  */
11
19
  async function preview(options = {}) {
12
- const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'preview');
13
- const server = await (0, vite_1.preview)(viteConfigFromUserEnhanced);
14
- return {
15
- viteServer: server,
16
- viteConfig: server.config
17
- };
20
+ const { viteConfigFromUserEnhanced, viteConfigResolved } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'preview');
21
+ if (viteConfigResolved.vitePluginServerEntry?.inject) {
22
+ const outDir = (0, getOutDirs_js_1.getOutDirs)(viteConfigResolved).outDirRoot;
23
+ const { outServerIndex } = await (0, runtime_1.importServerProductionIndex)({ outDir });
24
+ const outServerIndexRelative = node_path_1.default.relative(viteConfigResolved.root, outServerIndex);
25
+ (0, utils_js_1.assertWarning)(false, `Never run ${picocolors_1.default.cyan('$ vike preview')} in production, run ${picocolors_1.default.cyan(`$ node ${outServerIndexRelative}`)} instead.`, { onlyOnce: true });
26
+ return {
27
+ viteConfig: viteConfigResolved
28
+ };
29
+ }
30
+ else {
31
+ const server = await (0, vite_1.preview)(viteConfigFromUserEnhanced);
32
+ return {
33
+ viteServer: server,
34
+ viteConfig: server.config
35
+ };
36
+ }
18
37
  }
@@ -95,8 +95,10 @@ async function cmdBuild() {
95
95
  async function cmdPreview() {
96
96
  try {
97
97
  const { viteServer } = await (0, index_js_1.preview)();
98
- viteServer.printUrls();
99
- viteServer.bindCLIShortcuts({ print: true });
98
+ if (viteServer) {
99
+ viteServer.printUrls();
100
+ viteServer.bindCLIShortcuts({ print: true });
101
+ }
100
102
  }
101
103
  catch (err) {
102
104
  console.error(picocolors_1.default.red(`Error while starting preview server:`));
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginModuleBanner = pluginModuleBanner;
4
+ const utils_js_1 = require("../../utils.js");
5
+ const virtual_files_js_1 = require("../../../shared/virtual-files.js");
6
+ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
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
+ const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
10
+ function pluginModuleBanner() {
11
+ let config;
12
+ return {
13
+ name: 'vike:pluginModuleBanner',
14
+ enforce: 'post',
15
+ apply: 'build',
16
+ configResolved(config_) {
17
+ config = config_;
18
+ },
19
+ generateBundle: {
20
+ order: 'post',
21
+ handler(_options, bundle) {
22
+ for (const module of Object.values(bundle)) {
23
+ if (module.type === 'chunk') {
24
+ if ((0, isViteServerBuild_js_1.isViteServerBuild)(config)) {
25
+ const codeOld = module.code;
26
+ const codeNew = codeOld.replace(/vikeModuleBannerPlaceholder\("([^"]*)"\);/g, '/* $1 [vike:pluginModuleBanner] */');
27
+ (0, utils_js_1.assert)(!codeNew.includes(vikeModuleBannerPlaceholder));
28
+ module.code = codeNew;
29
+ }
30
+ else {
31
+ (0, utils_js_1.assert)(!module.code.includes(vikeModuleBannerPlaceholder));
32
+ }
33
+ }
34
+ }
35
+ }
36
+ },
37
+ transform: {
38
+ order: 'post',
39
+ handler(code, id, options) {
40
+ if (!(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options))
41
+ return;
42
+ if (id.startsWith('\0'))
43
+ id = id;
44
+ id = (0, virtual_files_js_1.removeVirtualIdTag)(id);
45
+ if (id.startsWith(config.root))
46
+ id = id.slice(config.root.length + 1);
47
+ return `${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); ${code}`;
48
+ }
49
+ }
50
+ };
51
+ }
@@ -8,6 +8,7 @@ const pluginDistFileNames_js_1 = require("./build/pluginDistFileNames.js");
8
8
  const pluginAutoFullBuild_js_1 = require("./build/pluginAutoFullBuild.js");
9
9
  const pluginBuildEntry_js_1 = require("./build/pluginBuildEntry.js");
10
10
  const pluginBuildConfig_js_1 = require("./build/pluginBuildConfig.js");
11
+ const pluginModuleBanner_js_1 = require("./build/pluginModuleBanner.js");
11
12
  function build() {
12
13
  return [
13
14
  ...(0, pluginBuildConfig_js_1.pluginBuildConfig)(),
@@ -16,6 +17,7 @@ function build() {
16
17
  ...(0, pluginBuildEntry_js_1.pluginBuildEntry)(),
17
18
  (0, pluginDistPackageJsonFile_js_1.pluginDistPackageJsonFile)(),
18
19
  (0, pluginSuppressRollupWarning_js_1.pluginSuppressRollupWarning)(),
19
- (0, pluginDistFileNames_js_1.pluginDistFileNames)()
20
+ (0, pluginDistFileNames_js_1.pluginDistFileNames)(),
21
+ (0, pluginModuleBanner_js_1.pluginModuleBanner)()
20
22
  ];
21
23
  }
@@ -71,6 +71,10 @@ function commonConfig(vikeVitePluginOptions) {
71
71
  assertEsm(config.root);
72
72
  assertVikeCliOrApi(config);
73
73
  temp_supportOldInterface(config);
74
+ // Only emit dist/server/entry.mjs if necessary
75
+ if (config.vitePluginServerEntry?.inject &&
76
+ !(0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(config._vikeConfigObject).isPrerenderingEnabled)
77
+ config.vitePluginServerEntry.disableServerEntryEmit = true;
74
78
  }
75
79
  },
76
80
  config: {
@@ -33,4 +33,4 @@ __exportStar(require("../../utils/isArray.js"), exports);
33
33
  __exportStar(require("../../utils/isObject.js"), exports);
34
34
  __exportStar(require("../../utils/changeEnumerable.js"), exports);
35
35
  __exportStar(require("../../utils/makePublicCopy.js"), exports);
36
- __exportStar(require("../../utils/isNotNullish.js"), exports);
36
+ __exportStar(require("../../utils/isNullish.js"), exports);
@@ -311,10 +311,14 @@ async function loadBuildEntry(outDir) {
311
311
  globalObject.buildEntry = globalObject.buildEntryPrevious;
312
312
  }
313
313
  (0, utils_js_1.assert)(globalObject.buildEntry);
314
- (0, utils_js_1.assertWarning)(!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
315
- // TODO/soon: show precise path
316
- // TODO/soon: make this warning work on test/vike-node/
317
- `Run the server production build (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of running the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
314
+ (0, utils_js_1.assertWarning)(
315
+ // vike-server => `vitePluginServerEntry.inject === true`
316
+ // vike-node => `vitePluginServerEntry.inject === [ 'index' ]`
317
+ globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true,
318
+ /* TO-DO/eventually:
319
+ !!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
320
+ */
321
+ `Run the built server entry (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
318
322
  }
319
323
  const { buildEntry } = globalObject;
320
324
  assertBuildEntry(buildEntry);
@@ -51,7 +51,7 @@ __exportStar(require("../../utils/urlToFile.js"), exports);
51
51
  __exportStar(require("../../utils/getGlobalObject.js"), exports);
52
52
  __exportStar(require("../../utils/freezePartial.js"), exports);
53
53
  __exportStar(require("../../utils/isNpmPackage.js"), exports);
54
- __exportStar(require("../../utils/isNotNullish.js"), exports);
54
+ __exportStar(require("../../utils/isNullish.js"), exports);
55
55
  __exportStar(require("../../utils/isScriptFile.js"), exports);
56
56
  __exportStar(require("../../utils/removeFileExtention.js"), exports);
57
57
  __exportStar(require("../../utils/objectKeys.js"), exports);
@@ -28,6 +28,6 @@ __exportStar(require("../../utils/parseUrl.js"), exports);
28
28
  __exportStar(require("../../utils/parseUrl-extras.js"), exports);
29
29
  __exportStar(require("../../utils/isObject.js"), exports);
30
30
  __exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
31
- __exportStar(require("../../utils/isNotNullish.js"), exports);
31
+ __exportStar(require("../../utils/isNullish.js"), exports);
32
32
  __exportStar(require("../../utils/unique.js"), exports);
33
33
  __exportStar(require("../../utils/debug.js"), exports);
@@ -6,32 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isVirtualFileId = isVirtualFileId;
7
7
  exports.getVirtualFileId = getVirtualFileId;
8
8
  exports.resolveVirtualFileId = resolveVirtualFileId;
9
+ exports.removeVirtualIdTag = removeVirtualIdTag;
9
10
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
11
  const utils_js_1 = require("./utils.js");
11
12
  const idBase = 'virtual:vike:';
12
13
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
13
- const tag = '\0';
14
+ const virtualIdTag = '\0';
14
15
  function isVirtualFileId(id) {
15
16
  if (id.startsWith(idBase))
16
17
  return true;
17
- if (id.startsWith(tag + idBase))
18
+ if (id.startsWith(virtualIdTag + idBase))
18
19
  return true;
19
20
  // https://github.com/vikejs/vike/issues/1985
20
21
  (0, utils_js_1.assertUsage)(!id.includes(idBase), `Encountered a module ID ${picocolors_1.default.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
21
22
  return false;
22
23
  }
23
24
  function getVirtualFileId(id) {
24
- if (id.startsWith(tag)) {
25
- id = id.slice(tag.length);
26
- }
27
- (0, utils_js_1.assert)(!id.startsWith(tag));
28
- return id;
25
+ return removeVirtualIdTag(id);
29
26
  }
30
27
  function resolveVirtualFileId(id) {
31
28
  (0, utils_js_1.assert)(isVirtualFileId(id));
32
- if (!id.startsWith(tag)) {
33
- id = tag + id;
29
+ if (!id.startsWith(virtualIdTag)) {
30
+ id = virtualIdTag + id;
31
+ }
32
+ (0, utils_js_1.assert)(id.startsWith(virtualIdTag));
33
+ return id;
34
+ }
35
+ function removeVirtualIdTag(id) {
36
+ if (id.startsWith(virtualIdTag)) {
37
+ id = id.slice(virtualIdTag.length);
34
38
  }
35
- (0, utils_js_1.assert)(id.startsWith(tag));
39
+ (0, utils_js_1.assert)(!id.startsWith(virtualIdTag));
36
40
  return id;
37
41
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.modifyUrl = modifyUrl;
4
+ const modifyUrlSameOrigin_js_1 = require("./modifyUrlSameOrigin.js");
4
5
  const utils_js_1 = require("./utils.js");
5
6
  /**
6
7
  * Modify a URL.
@@ -10,9 +11,8 @@ const utils_js_1 = require("./utils.js");
10
11
  * https://vike.dev/modifyUrl
11
12
  */
12
13
  function modifyUrl(url, modify) {
14
+ url = (0, modifyUrlSameOrigin_js_1.modifyUrlSameOrigin)(url, modify);
13
15
  const urlParsed = (0, utils_js_1.parseUrl)(url, '/');
14
- // Pathname
15
- const pathname = modify.pathname ?? urlParsed.pathname;
16
16
  // Origin
17
17
  const originParts = [
18
18
  modify.protocol ?? urlParsed.protocol ?? '',
@@ -23,8 +23,6 @@ function modifyUrl(url, modify) {
23
23
  originParts.push(`:${port}`);
24
24
  }
25
25
  const origin = originParts.join('');
26
- const urlModified = (0, utils_js_1.createUrlFromComponents)(origin, pathname,
27
- // Should we also support modifying search and hash?
28
- urlParsed.searchOriginal, urlParsed.hashOriginal);
26
+ const urlModified = (0, utils_js_1.createUrlFromComponents)(origin, urlParsed.pathname, urlParsed.searchOriginal, urlParsed.hashOriginal);
29
27
  return urlModified;
30
28
  }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modifyUrlSameOrigin = modifyUrlSameOrigin;
4
+ const utils_js_1 = require("./utils.js");
5
+ function modifyUrlSameOrigin(url, modify) {
6
+ const urlParsed = (0, utils_js_1.parseUrl)(url, '/');
7
+ // Pathname
8
+ const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
9
+ (0, utils_js_1.assertUsageUrlPathnameAbsolute)(pathname, 'modify.pathname');
10
+ // Search
11
+ let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
12
+ if (search === '?')
13
+ search = '';
14
+ // Hash
15
+ let hash;
16
+ if (modify.hash === null) {
17
+ hash = '';
18
+ }
19
+ else if (modify.hash === undefined) {
20
+ hash = urlParsed.hashOriginal ?? '';
21
+ }
22
+ else {
23
+ hash = modify.hash;
24
+ if (!hash.startsWith('#'))
25
+ hash = '#' + hash;
26
+ }
27
+ const urlModified = (0, utils_js_1.createUrlFromComponents)(urlParsed.origin, pathname, search, hash);
28
+ return urlModified;
29
+ }
30
+ function resolveSearch(urlParsed, search) {
31
+ let searchParams;
32
+ if (search instanceof URLSearchParams) {
33
+ // Overwrite
34
+ searchParams = search;
35
+ }
36
+ else {
37
+ // Merge
38
+ const searchMap = (0, utils_js_1.objectFilter)({ ...urlParsed.search, ...search }, (utils_js_1.isNotNullish_keyVal));
39
+ searchParams = new URLSearchParams(searchMap);
40
+ }
41
+ return '?' + searchParams.toString();
42
+ }
@@ -30,7 +30,7 @@ __exportStar(require("../utils/isBrowser.js"), exports);
30
30
  __exportStar(require("../utils/hasProp.js"), exports);
31
31
  __exportStar(require("../utils/isPlainObject.js"), exports);
32
32
  __exportStar(require("../utils/compareString.js"), exports);
33
- __exportStar(require("../utils/isNotNullish.js"), exports);
33
+ __exportStar(require("../utils/isNullish.js"), exports);
34
34
  __exportStar(require("../utils/stringifyStringArray.js"), exports);
35
35
  __exportStar(require("../utils/cast.js"), exports);
36
36
  __exportStar(require("../utils/isPropertyGetter.js"), exports);
@@ -42,3 +42,4 @@ __exportStar(require("../utils/isArray.js"), exports);
42
42
  __exportStar(require("../utils/changeEnumerable.js"), exports);
43
43
  __exportStar(require("../utils/objectDefineProperty.js"), exports);
44
44
  __exportStar(require("../utils/isScriptFile.js"), exports);
45
+ __exportStar(require("../utils/objectFilter.js"), exports);
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.225-commit-b8fc36e';
5
+ exports.PROJECT_VERSION = '0.4.225-commit-6fc12fc';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNullish = isNullish;
4
+ exports.isNotNullish = isNotNullish;
5
+ exports.isNotNullish_keyVal = isNotNullish_keyVal;
6
+ function isNullish(val) {
7
+ return val === null || val === undefined;
8
+ }
9
+ // someArray.filter(isNotNullish)
10
+ function isNotNullish(p) {
11
+ return !isNullish(p);
12
+ }
13
+ // objectFilter(obj).filter(isNotNullish_keyVal)
14
+ function isNotNullish_keyVal(arg) {
15
+ return !isNullish(arg[1]);
16
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectFilter = objectFilter;
4
+ // Type inference for:
5
+ // ```js
6
+ // Object.fromEntries(Object.entries(obj).filter(someFilter))
7
+ // ```
8
+ function objectFilter(obj, filter) {
9
+ return Object.fromEntries(Object.entries(obj).filter(filter));
10
+ }
@@ -1,5 +1,10 @@
1
1
  export { navigate };
2
2
  export { reload };
3
+ type Options = {
4
+ keepScrollPosition?: boolean;
5
+ overwriteLastHistoryEntry?: boolean;
6
+ pageContext?: Record<string, unknown>;
7
+ };
3
8
  /** Programmatically navigate to a new page.
4
9
  *
5
10
  * https://vike.dev/navigate
@@ -8,9 +13,5 @@ export { reload };
8
13
  * @param keepScrollPosition - Don't scroll to the top of the page, instead keep the current scroll position.
9
14
  * @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
10
15
  */
11
- declare function navigate(url: string, { keepScrollPosition, overwriteLastHistoryEntry, pageContext }?: {
12
- keepScrollPosition?: boolean;
13
- overwriteLastHistoryEntry?: boolean;
14
- pageContext?: Record<string, unknown>;
15
- }): Promise<void>;
16
+ declare function navigate(url: string, options?: Options): Promise<void>;
16
17
  declare function reload(): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  export { navigate };
2
2
  export { reload };
3
+ // import { modifyUrlSameOrigin, ModifyUrlSameOriginOptions } from '../../shared/modifyUrlSameOrigin.js'
3
4
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
4
5
  import { normalizeUrlArgument } from './normalizeUrlArgument.js';
5
6
  import { firstRenderStartPromise, renderPageClientSide } from './renderPageClientSide.js';
@@ -13,11 +14,14 @@ assertClientRouting();
13
14
  * @param keepScrollPosition - Don't scroll to the top of the page, instead keep the current scroll position.
14
15
  * @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
15
16
  */
16
- async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryEntry = false, pageContext } = {}) {
17
+ async function navigate(url, options) {
18
+ // let url = normalizeUrlArgument(options.url ?? getCurrentUrl(), 'navigate')
19
+ // url = modifyUrlSameOrigin(url, options)
17
20
  normalizeUrlArgument(url, 'navigate');
18
21
  // If `hydrationCanBeAborted === false` (e.g. Vue) then we can apply navigate() only after hydration is done
19
22
  await firstRenderStartPromise;
20
- const scrollTarget = { preserveScroll: keepScrollPosition };
23
+ const { keepScrollPosition, overwriteLastHistoryEntry, pageContext } = options ?? {};
24
+ const scrollTarget = { preserveScroll: keepScrollPosition ?? false };
21
25
  await renderPageClientSide({
22
26
  scrollTarget,
23
27
  urlOriginal: url,
@@ -2,7 +2,7 @@ export { normalizeUrlArgument };
2
2
  import { assertUsage, isUrl, isUrlRelative } from './utils.js';
3
3
  function normalizeUrlArgument(url, fnName) {
4
4
  // Succinct error message to save client-side KBs
5
- const errMsg = `[${fnName}(url)] Invalid URL ${url}`;
5
+ const errMsg = `URL ${url} passed to ${fnName}() is invalid`;
6
6
  assertUsage(isUrl(url), errMsg);
7
7
  if (url.startsWith(location.origin)) {
8
8
  // Use normalizeClientSideUrl() instead?
@@ -7,6 +7,7 @@ import type { APIOptions, Operation } from './types.js';
7
7
  import { type VikeConfigObject } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
8
8
  declare function prepareViteApiCall(options: APIOptions, operation: Operation): Promise<{
9
9
  vikeConfig: VikeConfigObject;
10
+ viteConfigResolved: ResolvedConfig;
10
11
  viteConfigFromUserEnhanced: InlineConfig | undefined;
11
12
  }>;
12
13
  declare function getViteRoot(operation: Operation): Promise<string>;
@@ -24,11 +24,12 @@ function clear() {
24
24
  }
25
25
  async function resolveConfigs(viteConfigFromUserApiOptions, operation) {
26
26
  const viteInfo = await getViteInfo(viteConfigFromUserApiOptions, operation);
27
- await assertViteRoot2(viteInfo.root, viteInfo.viteConfigFromUserEnhanced, operation);
27
+ const { viteConfigResolved } = await assertViteRoot2(viteInfo.root, viteInfo.viteConfigFromUserEnhanced, operation);
28
28
  const vikeConfig = await getVikeConfig2(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
29
29
  const viteConfigFromUserEnhanced = applyVikeViteConfig(viteInfo.viteConfigFromUserEnhanced, vikeConfig);
30
30
  return {
31
31
  vikeConfig,
32
+ viteConfigResolved, // ONLY USE if strictly necessary. (We plan to remove assertViteRoot2() as explained in the comments of that function.)
32
33
  viteConfigFromUserEnhanced
33
34
  };
34
35
  }
@@ -151,9 +152,10 @@ function normalizeViteRoot(root) {
151
152
  const errMsg = `A Vite plugin is modifying Vite's setting ${pc.cyan('root')} which is forbidden`;
152
153
  async function assertViteRoot2(root, viteConfigFromUserEnhanced, operation) {
153
154
  const args = getResolveConfigArgs(viteConfigFromUserEnhanced, operation);
154
- // We can eventually this resolveConfig() call (along with removing the whole assertViteRoot2() function which is redundant with the assertViteRoot() function) so that Vike doesn't make any resolveConfig() (except for pre-rendering which is required). But let's keep it for now, just to see whether calling resolveConfig() can be problematic.
155
+ // We can eventually remove this resolveConfig() call (along with removing the whole assertViteRoot2() function which is redundant with the assertViteRoot() function) so that Vike doesn't make any resolveConfig() (except for pre-rendering and preview which is required). But let's keep it for now, just to see whether calling resolveConfig() can be problematic.
155
156
  const viteConfigResolved = await resolveConfig(...args);
156
157
  assertUsage(normalizeViteRoot(viteConfigResolved.root) === normalizeViteRoot(root), errMsg);
158
+ return { viteConfigResolved };
157
159
  }
158
160
  function assertViteRoot(root, config) {
159
161
  if (globalObject.root)
@@ -1,7 +1,6 @@
1
1
  export { prerender };
2
2
  import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
3
3
  import { prepareViteApiCall } from './prepareViteApiCall.js';
4
- // TODO/soon use importServerProductionIndex()
5
4
  /**
6
5
  * Programmatically trigger `$ vike prerender`
7
6
  *
@@ -7,6 +7,6 @@ import type { APIOptions } from './types.js';
7
7
  * https://vike.dev/api#preview
8
8
  */
9
9
  declare function preview(options?: APIOptions): Promise<{
10
- viteServer: PreviewServer;
10
+ viteServer?: PreviewServer;
11
11
  viteConfig: ResolvedConfig;
12
12
  }>;
@@ -1,16 +1,32 @@
1
1
  export { preview };
2
2
  import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
+ import { importServerProductionIndex } from '@brillout/vite-plugin-server-entry/runtime';
5
+ import { getOutDirs } from '../plugin/shared/getOutDirs.js';
6
+ import { assertWarning } from './utils.js';
7
+ import pc from '@brillout/picocolors';
8
+ import path from 'node:path';
4
9
  /**
5
10
  * Programmatically trigger `$ vike preview`
6
11
  *
7
12
  * https://vike.dev/api#preview
8
13
  */
9
14
  async function preview(options = {}) {
10
- const { viteConfigFromUserEnhanced } = await prepareViteApiCall(options, 'preview');
11
- const server = await previewVite(viteConfigFromUserEnhanced);
12
- return {
13
- viteServer: server,
14
- viteConfig: server.config
15
- };
15
+ const { viteConfigFromUserEnhanced, viteConfigResolved } = await prepareViteApiCall(options, 'preview');
16
+ if (viteConfigResolved.vitePluginServerEntry?.inject) {
17
+ const outDir = getOutDirs(viteConfigResolved).outDirRoot;
18
+ const { outServerIndex } = await importServerProductionIndex({ outDir });
19
+ const outServerIndexRelative = path.relative(viteConfigResolved.root, outServerIndex);
20
+ assertWarning(false, `Never run ${pc.cyan('$ vike preview')} in production, run ${pc.cyan(`$ node ${outServerIndexRelative}`)} instead.`, { onlyOnce: true });
21
+ return {
22
+ viteConfig: viteConfigResolved
23
+ };
24
+ }
25
+ else {
26
+ const server = await previewVite(viteConfigFromUserEnhanced);
27
+ return {
28
+ viteServer: server,
29
+ viteConfig: server.config
30
+ };
31
+ }
16
32
  }
@@ -57,8 +57,10 @@ async function cmdBuild() {
57
57
  async function cmdPreview() {
58
58
  try {
59
59
  const { viteServer } = await preview();
60
- viteServer.printUrls();
61
- viteServer.bindCLIShortcuts({ print: true });
60
+ if (viteServer) {
61
+ viteServer.printUrls();
62
+ viteServer.bindCLIShortcuts({ print: true });
63
+ }
62
64
  }
63
65
  catch (err) {
64
66
  console.error(pc.red(`Error while starting preview server:`));
@@ -0,0 +1,3 @@
1
+ export { pluginModuleBanner };
2
+ import type { Plugin } from 'vite';
3
+ declare function pluginModuleBanner(): Plugin;
@@ -0,0 +1,49 @@
1
+ export { pluginModuleBanner };
2
+ import { assert } from '../../utils.js';
3
+ import { removeVirtualIdTag } from '../../../shared/virtual-files.js';
4
+ import { isViteServerBuild, isViteServerBuild_safe } from '../../shared/isViteServerBuild.js';
5
+ // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
6
+ // 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).
7
+ const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
8
+ function pluginModuleBanner() {
9
+ let config;
10
+ return {
11
+ name: 'vike:pluginModuleBanner',
12
+ enforce: 'post',
13
+ apply: 'build',
14
+ configResolved(config_) {
15
+ config = config_;
16
+ },
17
+ generateBundle: {
18
+ order: 'post',
19
+ handler(_options, bundle) {
20
+ for (const module of Object.values(bundle)) {
21
+ if (module.type === 'chunk') {
22
+ if (isViteServerBuild(config)) {
23
+ const codeOld = module.code;
24
+ const codeNew = codeOld.replace(/vikeModuleBannerPlaceholder\("([^"]*)"\);/g, '/* $1 [vike:pluginModuleBanner] */');
25
+ assert(!codeNew.includes(vikeModuleBannerPlaceholder));
26
+ module.code = codeNew;
27
+ }
28
+ else {
29
+ assert(!module.code.includes(vikeModuleBannerPlaceholder));
30
+ }
31
+ }
32
+ }
33
+ }
34
+ },
35
+ transform: {
36
+ order: 'post',
37
+ handler(code, id, options) {
38
+ if (!isViteServerBuild_safe(config, options))
39
+ return;
40
+ if (id.startsWith('\0'))
41
+ id = id;
42
+ id = removeVirtualIdTag(id);
43
+ if (id.startsWith(config.root))
44
+ id = id.slice(config.root.length + 1);
45
+ return `${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); ${code}`;
46
+ }
47
+ }
48
+ };
49
+ }
@@ -6,6 +6,7 @@ import { pluginDistFileNames } from './build/pluginDistFileNames.js';
6
6
  import { pluginAutoFullBuild } from './build/pluginAutoFullBuild.js';
7
7
  import { pluginBuildEntry } from './build/pluginBuildEntry.js';
8
8
  import { pluginBuildConfig } from './build/pluginBuildConfig.js';
9
+ import { pluginModuleBanner } from './build/pluginModuleBanner.js';
9
10
  function build() {
10
11
  return [
11
12
  ...pluginBuildConfig(),
@@ -14,6 +15,7 @@ function build() {
14
15
  ...pluginBuildEntry(),
15
16
  pluginDistPackageJsonFile(),
16
17
  pluginSuppressRollupWarning(),
17
- pluginDistFileNames()
18
+ pluginDistFileNames(),
19
+ pluginModuleBanner()
18
20
  ];
19
21
  }
@@ -4,10 +4,12 @@ export type { VikeConfigPublic };
4
4
  import { type InlineConfig, type Plugin, type ResolvedConfig, type UserConfig } from 'vite';
5
5
  import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
6
6
  import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
7
+ import type { VitePluginServerEntryOptions } from '@brillout/vite-plugin-server-entry/plugin';
7
8
  declare module 'vite' {
8
9
  interface UserConfig {
9
10
  _isDev?: boolean;
10
11
  _vikeVitePluginOptions?: unknown;
12
+ vitePluginServerEntry?: VitePluginServerEntryOptions;
11
13
  _root?: string;
12
14
  _baseViteOriginal?: string;
13
15
  _viteConfigFromUserEnhanced?: InlineConfig;
@@ -66,6 +66,10 @@ function commonConfig(vikeVitePluginOptions) {
66
66
  assertEsm(config.root);
67
67
  assertVikeCliOrApi(config);
68
68
  temp_supportOldInterface(config);
69
+ // Only emit dist/server/entry.mjs if necessary
70
+ if (config.vitePluginServerEntry?.inject &&
71
+ !resolvePrerenderConfigGlobal(config._vikeConfigObject).isPrerenderingEnabled)
72
+ config.vitePluginServerEntry.disableServerEntryEmit = true;
69
73
  }
70
74
  },
71
75
  config: {
@@ -15,4 +15,4 @@ export * from '../../utils/isArray.js';
15
15
  export * from '../../utils/isObject.js';
16
16
  export * from '../../utils/changeEnumerable.js';
17
17
  export * from '../../utils/makePublicCopy.js';
18
- export * from '../../utils/isNotNullish.js';
18
+ export * from '../../utils/isNullish.js';
@@ -17,4 +17,4 @@ export * from '../../utils/isArray.js';
17
17
  export * from '../../utils/isObject.js';
18
18
  export * from '../../utils/changeEnumerable.js';
19
19
  export * from '../../utils/makePublicCopy.js';
20
- export * from '../../utils/isNotNullish.js';
20
+ export * from '../../utils/isNullish.js';
@@ -21,7 +21,6 @@ export type { GlobalContextPublic };
21
21
  import type { ViteManifest } from '../shared/ViteManifest.js';
22
22
  import type { ResolvedConfig, ViteDevServer } from 'vite';
23
23
  import type { PageConfigUserFriendly, PageConfigsUserFriendly } from '../../shared/page-configs/getPageConfigUserFriendly.js';
24
- import type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
25
24
  import { type BaseUrlsResolved } from '../shared/resolveBase.js';
26
25
  type PageRuntimeInfo = Awaited<ReturnType<typeof getUserFiles>>;
27
26
  type GlobalContextInternal = GlobalContext & {
@@ -84,11 +83,11 @@ type BuildInfo = {
84
83
  viteConfigRuntime: {
85
84
  _baseViteOriginal: string;
86
85
  vitePluginServerEntry: {
87
- inject?: NonNullable<ConfigVitePluginServerEntry['vitePluginServerEntry']>['inject'];
86
+ inject?: boolean;
88
87
  };
89
88
  };
90
89
  };
91
90
  declare function assertBuildInfo(buildInfo: unknown): asserts buildInfo is BuildInfo;
92
- declare function getViteConfigRuntime(viteConfig: ResolvedConfig & ConfigVitePluginServerEntry): BuildInfo['viteConfigRuntime'];
91
+ declare function getViteConfigRuntime(viteConfig: ResolvedConfig): BuildInfo['viteConfigRuntime'];
93
92
  declare function updateUserFiles(): Promise<void>;
94
93
  declare function clearGlobalContext(): void;
@@ -308,10 +308,14 @@ async function loadBuildEntry(outDir) {
308
308
  globalObject.buildEntry = globalObject.buildEntryPrevious;
309
309
  }
310
310
  assert(globalObject.buildEntry);
311
- assertWarning(!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
312
- // TODO/soon: show precise path
313
- // TODO/soon: make this warning work on test/vike-node/
314
- `Run the server production build (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of running the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
311
+ assertWarning(
312
+ // vike-server => `vitePluginServerEntry.inject === true`
313
+ // vike-node => `vitePluginServerEntry.inject === [ 'index' ]`
314
+ globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true,
315
+ /* TO-DO/eventually:
316
+ !!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
317
+ */
318
+ `Run the built server entry (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
315
319
  }
316
320
  const { buildEntry } = globalObject;
317
321
  assertBuildEntry(buildEntry);
@@ -31,7 +31,7 @@ export * from '../../utils/urlToFile.js';
31
31
  export * from '../../utils/getGlobalObject.js';
32
32
  export * from '../../utils/freezePartial.js';
33
33
  export * from '../../utils/isNpmPackage.js';
34
- export * from '../../utils/isNotNullish.js';
34
+ export * from '../../utils/isNullish.js';
35
35
  export * from '../../utils/isScriptFile.js';
36
36
  export * from '../../utils/removeFileExtention.js';
37
37
  export * from '../../utils/objectKeys.js';
@@ -35,7 +35,7 @@ export * from '../../utils/urlToFile.js';
35
35
  export * from '../../utils/getGlobalObject.js';
36
36
  export * from '../../utils/freezePartial.js';
37
37
  export * from '../../utils/isNpmPackage.js';
38
- export * from '../../utils/isNotNullish.js';
38
+ export * from '../../utils/isNullish.js';
39
39
  export * from '../../utils/isScriptFile.js';
40
40
  export * from '../../utils/removeFileExtention.js';
41
41
  export * from '../../utils/objectKeys.js';
@@ -10,6 +10,6 @@ export * from '../../utils/parseUrl.js';
10
10
  export * from '../../utils/parseUrl-extras.js';
11
11
  export * from '../../utils/isObject.js';
12
12
  export * from '../../utils/assertIsNotBrowser.js';
13
- export * from '../../utils/isNotNullish.js';
13
+ export * from '../../utils/isNullish.js';
14
14
  export * from '../../utils/unique.js';
15
15
  export * from '../../utils/debug.js';
@@ -12,6 +12,6 @@ export * from '../../utils/parseUrl.js';
12
12
  export * from '../../utils/parseUrl-extras.js';
13
13
  export * from '../../utils/isObject.js';
14
14
  export * from '../../utils/assertIsNotBrowser.js';
15
- export * from '../../utils/isNotNullish.js';
15
+ export * from '../../utils/isNullish.js';
16
16
  export * from '../../utils/unique.js';
17
17
  export * from '../../utils/debug.js';
@@ -1,6 +1,8 @@
1
1
  export { isVirtualFileId };
2
2
  export { getVirtualFileId };
3
3
  export { resolveVirtualFileId };
4
+ export { removeVirtualIdTag };
4
5
  declare function isVirtualFileId(id: string): boolean;
5
6
  declare function getVirtualFileId(id: string): string;
6
7
  declare function resolveVirtualFileId(id: string): string;
8
+ declare function removeVirtualIdTag(id: string): string;
@@ -1,32 +1,36 @@
1
1
  export { isVirtualFileId };
2
2
  export { getVirtualFileId };
3
3
  export { resolveVirtualFileId };
4
+ export { removeVirtualIdTag };
4
5
  import pc from '@brillout/picocolors';
5
6
  import { assert, assertUsage } from './utils.js';
6
7
  const idBase = 'virtual:vike:';
7
8
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
8
- const tag = '\0';
9
+ const virtualIdTag = '\0';
9
10
  function isVirtualFileId(id) {
10
11
  if (id.startsWith(idBase))
11
12
  return true;
12
- if (id.startsWith(tag + idBase))
13
+ if (id.startsWith(virtualIdTag + idBase))
13
14
  return true;
14
15
  // https://github.com/vikejs/vike/issues/1985
15
16
  assertUsage(!id.includes(idBase), `Encountered a module ID ${pc.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
16
17
  return false;
17
18
  }
18
19
  function getVirtualFileId(id) {
19
- if (id.startsWith(tag)) {
20
- id = id.slice(tag.length);
21
- }
22
- assert(!id.startsWith(tag));
23
- return id;
20
+ return removeVirtualIdTag(id);
24
21
  }
25
22
  function resolveVirtualFileId(id) {
26
23
  assert(isVirtualFileId(id));
27
- if (!id.startsWith(tag)) {
28
- id = tag + id;
24
+ if (!id.startsWith(virtualIdTag)) {
25
+ id = virtualIdTag + id;
26
+ }
27
+ assert(id.startsWith(virtualIdTag));
28
+ return id;
29
+ }
30
+ function removeVirtualIdTag(id) {
31
+ if (id.startsWith(virtualIdTag)) {
32
+ id = id.slice(virtualIdTag.length);
29
33
  }
30
- assert(id.startsWith(tag));
34
+ assert(!id.startsWith(virtualIdTag));
31
35
  return id;
32
36
  }
@@ -1,4 +1,5 @@
1
1
  export { modifyUrl };
2
+ import { type ModifyUrlSameOriginOptions } from './modifyUrlSameOrigin.js';
2
3
  /**
3
4
  * Modify a URL.
4
5
  *
@@ -6,8 +7,7 @@ export { modifyUrl };
6
7
  *
7
8
  * https://vike.dev/modifyUrl
8
9
  */
9
- declare function modifyUrl(url: string, modify: {
10
- pathname?: string;
10
+ declare function modifyUrl(url: string, modify: ModifyUrlSameOriginOptions & {
11
11
  hostname?: string;
12
12
  port?: number;
13
13
  protocol?: string;
@@ -1,4 +1,5 @@
1
1
  export { modifyUrl };
2
+ import { modifyUrlSameOrigin } from './modifyUrlSameOrigin.js';
2
3
  import { createUrlFromComponents, parseUrl } from './utils.js';
3
4
  /**
4
5
  * Modify a URL.
@@ -8,9 +9,8 @@ import { createUrlFromComponents, parseUrl } from './utils.js';
8
9
  * https://vike.dev/modifyUrl
9
10
  */
10
11
  function modifyUrl(url, modify) {
12
+ url = modifyUrlSameOrigin(url, modify);
11
13
  const urlParsed = parseUrl(url, '/');
12
- // Pathname
13
- const pathname = modify.pathname ?? urlParsed.pathname;
14
14
  // Origin
15
15
  const originParts = [
16
16
  modify.protocol ?? urlParsed.protocol ?? '',
@@ -21,8 +21,6 @@ function modifyUrl(url, modify) {
21
21
  originParts.push(`:${port}`);
22
22
  }
23
23
  const origin = originParts.join('');
24
- const urlModified = createUrlFromComponents(origin, pathname,
25
- // Should we also support modifying search and hash?
26
- urlParsed.searchOriginal, urlParsed.hashOriginal);
24
+ const urlModified = createUrlFromComponents(origin, urlParsed.pathname, urlParsed.searchOriginal, urlParsed.hashOriginal);
27
25
  return urlModified;
28
26
  }
@@ -0,0 +1,9 @@
1
+ export { modifyUrlSameOrigin };
2
+ export { ModifyUrlSameOriginOptions };
3
+ type ModifyUrlSameOriginOptions = {
4
+ hash?: string | null;
5
+ search?: Search | null;
6
+ pathname?: string;
7
+ };
8
+ type Search = Record<string, string | null> | URLSearchParams;
9
+ declare function modifyUrlSameOrigin(url: string, modify: ModifyUrlSameOriginOptions): string;
@@ -0,0 +1,40 @@
1
+ export { modifyUrlSameOrigin };
2
+ import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathnameAbsolute } from './utils.js';
3
+ function modifyUrlSameOrigin(url, modify) {
4
+ const urlParsed = parseUrl(url, '/');
5
+ // Pathname
6
+ const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
7
+ assertUsageUrlPathnameAbsolute(pathname, 'modify.pathname');
8
+ // Search
9
+ let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
10
+ if (search === '?')
11
+ search = '';
12
+ // Hash
13
+ let hash;
14
+ if (modify.hash === null) {
15
+ hash = '';
16
+ }
17
+ else if (modify.hash === undefined) {
18
+ hash = urlParsed.hashOriginal ?? '';
19
+ }
20
+ else {
21
+ hash = modify.hash;
22
+ if (!hash.startsWith('#'))
23
+ hash = '#' + hash;
24
+ }
25
+ const urlModified = createUrlFromComponents(urlParsed.origin, pathname, search, hash);
26
+ return urlModified;
27
+ }
28
+ function resolveSearch(urlParsed, search) {
29
+ let searchParams;
30
+ if (search instanceof URLSearchParams) {
31
+ // Overwrite
32
+ searchParams = search;
33
+ }
34
+ else {
35
+ // Merge
36
+ const searchMap = objectFilter({ ...urlParsed.search, ...search }, (isNotNullish_keyVal));
37
+ searchParams = new URLSearchParams(searchMap);
38
+ }
39
+ return '?' + searchParams.toString();
40
+ }
@@ -10,7 +10,7 @@ export * from '../utils/isBrowser.js';
10
10
  export * from '../utils/hasProp.js';
11
11
  export * from '../utils/isPlainObject.js';
12
12
  export * from '../utils/compareString.js';
13
- export * from '../utils/isNotNullish.js';
13
+ export * from '../utils/isNullish.js';
14
14
  export * from '../utils/stringifyStringArray.js';
15
15
  export * from '../utils/cast.js';
16
16
  export * from '../utils/isPropertyGetter.js';
@@ -22,3 +22,4 @@ export * from '../utils/isArray.js';
22
22
  export * from '../utils/changeEnumerable.js';
23
23
  export * from '../utils/objectDefineProperty.js';
24
24
  export * from '../utils/isScriptFile.js';
25
+ export * from '../utils/objectFilter.js';
@@ -14,7 +14,7 @@ export * from '../utils/isBrowser.js';
14
14
  export * from '../utils/hasProp.js';
15
15
  export * from '../utils/isPlainObject.js';
16
16
  export * from '../utils/compareString.js';
17
- export * from '../utils/isNotNullish.js';
17
+ export * from '../utils/isNullish.js';
18
18
  export * from '../utils/stringifyStringArray.js';
19
19
  export * from '../utils/cast.js';
20
20
  export * from '../utils/isPropertyGetter.js';
@@ -26,3 +26,4 @@ export * from '../utils/isArray.js';
26
26
  export * from '../utils/changeEnumerable.js';
27
27
  export * from '../utils/objectDefineProperty.js';
28
28
  export * from '../utils/isScriptFile.js';
29
+ export * from '../utils/objectFilter.js';
@@ -3,7 +3,6 @@ export type { PageContextServer } from '../shared/types.js';
3
3
  export type { PageContextClient } from '../shared/types.js';
4
4
  export type { PageContextWithServerRouting } from '../shared/types.js';
5
5
  export type { PageContextClientWithServerRouting } from '../shared/types.js';
6
- export type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
7
6
  export type { PageContextBuiltInServer } from '../shared/types.js';
8
7
  export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
9
8
  export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.225-commit-b8fc36e";
1
+ export declare const PROJECT_VERSION: "0.4.225-commit-6fc12fc";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.225-commit-b8fc36e';
2
+ export const PROJECT_VERSION = '0.4.225-commit-6fc12fc';
@@ -0,0 +1,3 @@
1
+ export declare function isNullish(val: unknown): val is null | undefined;
2
+ export declare function isNotNullish<T>(p: T | null | undefined): p is T;
3
+ export declare function isNotNullish_keyVal<T>(arg: [string, T | null | undefined]): arg is [string, T];
@@ -0,0 +1,11 @@
1
+ export function isNullish(val) {
2
+ return val === null || val === undefined;
3
+ }
4
+ // someArray.filter(isNotNullish)
5
+ export function isNotNullish(p) {
6
+ return !isNullish(p);
7
+ }
8
+ // objectFilter(obj).filter(isNotNullish_keyVal)
9
+ export function isNotNullish_keyVal(arg) {
10
+ return !isNullish(arg[1]);
11
+ }
@@ -0,0 +1 @@
1
+ export declare function objectFilter<Val, Val2 extends Val, Obj extends Record<string, Val>>(obj: Obj, filter: (arg: [string, Val]) => arg is [string, Val2]): Record<string, Val2>;
@@ -0,0 +1,7 @@
1
+ // Type inference for:
2
+ // ```js
3
+ // Object.fromEntries(Object.entries(obj).filter(someFilter))
4
+ // ```
5
+ export function objectFilter(obj, filter) {
6
+ return Object.fromEntries(Object.entries(obj).filter(filter));
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.225-commit-b8fc36e",
3
+ "version": "0.4.225-commit-6fc12fc",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -123,7 +123,7 @@
123
123
  "@brillout/json-serializer": "^0.5.15",
124
124
  "@brillout/picocolors": "^1.0.26",
125
125
  "@brillout/require-shim": "^0.1.2",
126
- "@brillout/vite-plugin-server-entry": "^0.6.3",
126
+ "@brillout/vite-plugin-server-entry": "0.6.3-commit-0c67c6a",
127
127
  "acorn": "^8.0.0",
128
128
  "cac": "^6.0.0",
129
129
  "es-module-lexer": "^1.0.0",
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNotNullish = void 0;
4
- const isNotNullish = (p) => p !== null && p !== undefined;
5
- exports.isNotNullish = isNotNullish;
@@ -1 +0,0 @@
1
- export declare const isNotNullish: <T>(p: T | null | undefined) => p is T;
@@ -1 +0,0 @@
1
- export const isNotNullish = (p) => p !== null && p !== undefined;