vike 0.4.143-commit-f03b42d → 0.4.143-commit-dc6fea0

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.
@@ -2,6 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFilePathToShowToUser = void 0;
4
4
  const utils_js_1 = require("../../../utils.js");
5
+ /*
6
+ const f: FilePath = 1 as any
7
+ if (f.filePathRelativeToUserRootDir === null) {
8
+ f.importPathAbsolute
9
+ }
10
+ //*/
5
11
  function getFilePathToShowToUser(filePath) {
6
12
  const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsolute;
7
13
  (0, utils_js_1.assert)(filePathToShowToUser);
@@ -89,7 +89,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
89
89
  await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
90
90
  const configFilePath = {
91
91
  filePathAbsolute: filePathAbsolute,
92
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir
92
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
93
+ importPathAbsolute: null
93
94
  };
94
95
  const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
95
96
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
@@ -108,7 +109,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
108
109
  const interfaceFile = {
109
110
  filePath: {
110
111
  filePathRelativeToUserRootDir,
111
- filePathAbsolute
112
+ filePathAbsolute,
113
+ importPathAbsolute: null
112
114
  },
113
115
  configMap: {
114
116
  [configName]: {}
@@ -802,7 +804,7 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
802
804
  (0, utils_js_1.assertUsage)(!fileName.slice(1).includes('+'), `Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`);
803
805
  }
804
806
  async function loadConfigFile(configFilePath, userRootDir, visited) {
805
- const { filePathAbsolute, filePathRelativeToUserRootDir } = configFilePath;
807
+ const { filePathAbsolute } = configFilePath;
806
808
  assertNoInfiniteLoop(visited, filePathAbsolute);
807
809
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, false, userRootDir);
808
810
  const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
@@ -811,10 +813,7 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
811
813
  ]);
812
814
  const configFile = {
813
815
  fileExports,
814
- filePath: {
815
- filePathRelativeToUserRootDir,
816
- filePathAbsolute
817
- },
816
+ filePath: configFilePath,
818
817
  extendsFilePaths
819
818
  };
820
819
  return { configFile, extendsConfigs };
@@ -837,11 +836,14 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
837
836
  const filePathAbsolute = resolveImportPath(importData, configFilePath);
838
837
  assertImportPath(filePathAbsolute, importData, configFilePath);
839
838
  assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
839
+ // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
840
+ // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
841
+ const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir);
840
842
  extendsConfigFiles.push({
841
843
  filePathAbsolute,
842
- // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
843
- // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
844
- filePathRelativeToUserRootDir: determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir)
844
+ // TODO: fix type cast
845
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
846
+ importPathAbsolute: importPath
845
847
  });
846
848
  });
847
849
  const extendsConfigs = [];
@@ -111,7 +111,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
111
111
  if (!isHtmlOnly) {
112
112
  // Don't allow the user to manipulate with injectFilter(): injecting <script type="application/json"> before the stream can break the app when:
113
113
  // - using https://vike.dev/stream#initial-data-after-stream-end
114
- // - `pageContext` is modified during the stream, e.g. /examples/vue-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
114
+ // - `pageContext` is modified during the stream, e.g. https://github.com/brillout/vike-with-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
115
115
  // The <script> tags are handled separately by vike down below.
116
116
  htmlTags.push({
117
117
  // Needs to be called after `resolvePageContextPromise()`
@@ -72,8 +72,8 @@ function getPagesAndRoutesInfo(pageRoutes) {
72
72
  ...entries
73
73
  ];
74
74
  const terminalWidth = (0, utils_js_1.getTerminalWidth)() || 134;
75
- let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => routeTypeSrc.length));
76
- let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => routeDefinedBy.length));
75
+ let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => (0, utils_js_1.stripAnsi)(routeTypeSrc).length));
76
+ let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => (0, utils_js_1.stripAnsi)(routeDefinedBy).length));
77
77
  let width1 = terminalWidth - width3 - width2 - 10;
78
78
  linesContent.forEach((lineContent) => {
79
79
  let { routeStr } = lineContent;
@@ -88,9 +88,9 @@ function getPagesAndRoutesInfo(pageRoutes) {
88
88
  });
89
89
  width1 = Math.max(...linesContent.map(({ routeStr }) => (0, utils_js_1.stripAnsi)(routeStr).length));
90
90
  let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
91
- let cell1 = routeStr.padEnd(width1 + (routeStr.length - (0, utils_js_1.stripAnsi)(routeStr).length), ' ');
92
- let cell2 = routeTypeSrc.padEnd(width2, ' ');
93
- let cell3 = routeDefinedBy.padEnd(width3, ' ');
91
+ let cell1 = padEnd(routeStr, width1 + ((0, utils_js_1.stripAnsi)(routeStr).length - (0, utils_js_1.stripAnsi)(routeStr).length));
92
+ let cell2 = padEnd(routeTypeSrc, width2);
93
+ let cell3 = padEnd(routeDefinedBy, width3);
94
94
  const isHeader = i === 0;
95
95
  if (isHeader) {
96
96
  cell1 = picocolors_1.default.dim(cell1);
@@ -125,6 +125,11 @@ function truncateRouteFunction(routeStr, lenMax) {
125
125
  routeStr = (0, utils_js_1.truncateString)(routeStr, lenMax, (s) => picocolors_1.default.dim(s));
126
126
  return routeStr;
127
127
  }
128
+ /** Same as String.prototype.padEnd but with stripAnsi() */
129
+ function padEnd(str, width) {
130
+ const padWidth = Math.max(0, width - (0, utils_js_1.stripAnsi)(str).length);
131
+ return str + ''.padEnd(padWidth, ' ');
132
+ }
128
133
  function removeNonAscii(str) {
129
134
  // https://stackoverflow.com/questions/20856197/remove-non-ascii-character-in-string/20856346#20856346
130
135
  return str.replace(/[^\x00-\x7F]/g, '');
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.projectInfo = void 0;
4
4
  const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
5
- const PROJECT_VERSION = '0.4.143-commit-f03b42d';
5
+ const PROJECT_VERSION = '0.4.143-commit-dc6fea0';
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
8
8
  projectVersion: PROJECT_VERSION,
@@ -6,10 +6,19 @@ type FilePath = {
6
6
  * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
7
7
  */
8
8
  filePathAbsolute: string;
9
+ } & ({
9
10
  /** The file's path relative to the Vite's root (i.e. the user's project root directory).
10
11
  *
11
12
  * Example: `/pages/some-page/Page.js`
12
13
  */
13
- filePathRelativeToUserRootDir: null | string;
14
- };
14
+ filePathRelativeToUserRootDir: string;
15
+ importPathAbsolute: null;
16
+ } | {
17
+ filePathRelativeToUserRootDir: null;
18
+ /** The file's absolute import path.
19
+ *
20
+ * Example: `vike-react/config`
21
+ */
22
+ importPathAbsolute: string;
23
+ });
15
24
  declare function getFilePathToShowToUser(filePath: FilePath): string;
@@ -1,5 +1,11 @@
1
1
  export { getFilePathToShowToUser };
2
2
  import { assert } from '../../../utils.js';
3
+ /*
4
+ const f: FilePath = 1 as any
5
+ if (f.filePathRelativeToUserRootDir === null) {
6
+ f.importPathAbsolute
7
+ }
8
+ //*/
3
9
  function getFilePathToShowToUser(filePath) {
4
10
  const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsolute;
5
11
  assert(filePathToShowToUser);
@@ -31,17 +31,18 @@ type ConfigDefinition = {
31
31
  effect?: ConfigEffect;
32
32
  };
33
33
  type ConfigEffect = (config: {
34
- /** The resolved config value.
34
+ /** The config value.
35
35
  *
36
36
  * https://vike.dev/meta
37
37
  */
38
38
  configValue: unknown;
39
- /** Place where the resolved config value comes from.
39
+ /** Where the config value is defined.
40
40
  *
41
41
  * https://vike.dev/meta
42
42
  */
43
43
  configDefinedAt: `Config ${string}`;
44
44
  }) => Config | undefined;
45
+ /** For Vike internal use */
45
46
  type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
46
47
  _computed?: (pageConfig: PageConfigBuildTime) => unknown;
47
48
  _valueIsFilePath?: true;
@@ -84,7 +84,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
84
84
  await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
85
85
  const configFilePath = {
86
86
  filePathAbsolute: filePathAbsolute,
87
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir
87
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
88
+ importPathAbsolute: null
88
89
  };
89
90
  const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
90
91
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
@@ -103,7 +104,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
103
104
  const interfaceFile = {
104
105
  filePath: {
105
106
  filePathRelativeToUserRootDir,
106
- filePathAbsolute
107
+ filePathAbsolute,
108
+ importPathAbsolute: null
107
109
  },
108
110
  configMap: {
109
111
  [configName]: {}
@@ -797,7 +799,7 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
797
799
  assertUsage(!fileName.slice(1).includes('+'), `Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`);
798
800
  }
799
801
  async function loadConfigFile(configFilePath, userRootDir, visited) {
800
- const { filePathAbsolute, filePathRelativeToUserRootDir } = configFilePath;
802
+ const { filePathAbsolute } = configFilePath;
801
803
  assertNoInfiniteLoop(visited, filePathAbsolute);
802
804
  const { fileExports } = await transpileAndExecuteFile(configFilePath, false, userRootDir);
803
805
  const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
@@ -806,10 +808,7 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
806
808
  ]);
807
809
  const configFile = {
808
810
  fileExports,
809
- filePath: {
810
- filePathRelativeToUserRootDir,
811
- filePathAbsolute
812
- },
811
+ filePath: configFilePath,
813
812
  extendsFilePaths
814
813
  };
815
814
  return { configFile, extendsConfigs };
@@ -832,11 +831,14 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
832
831
  const filePathAbsolute = resolveImportPath(importData, configFilePath);
833
832
  assertImportPath(filePathAbsolute, importData, configFilePath);
834
833
  assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
834
+ // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
835
+ // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
836
+ const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir);
835
837
  extendsConfigFiles.push({
836
838
  filePathAbsolute,
837
- // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
838
- // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
839
- filePathRelativeToUserRootDir: determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir)
839
+ // TODO: fix type cast
840
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
841
+ importPathAbsolute: importPath
840
842
  });
841
843
  });
842
844
  const extendsConfigs = [];
@@ -106,7 +106,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
106
106
  if (!isHtmlOnly) {
107
107
  // Don't allow the user to manipulate with injectFilter(): injecting <script type="application/json"> before the stream can break the app when:
108
108
  // - using https://vike.dev/stream#initial-data-after-stream-end
109
- // - `pageContext` is modified during the stream, e.g. /examples/vue-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
109
+ // - `pageContext` is modified during the stream, e.g. https://github.com/brillout/vike-with-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
110
110
  // The <script> tags are handled separately by vike down below.
111
111
  htmlTags.push({
112
112
  // Needs to be called after `resolvePageContextPromise()`
@@ -67,8 +67,8 @@ function getPagesAndRoutesInfo(pageRoutes) {
67
67
  ...entries
68
68
  ];
69
69
  const terminalWidth = getTerminalWidth() || 134;
70
- let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => routeTypeSrc.length));
71
- let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => routeDefinedBy.length));
70
+ let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => stripAnsi(routeTypeSrc).length));
71
+ let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => stripAnsi(routeDefinedBy).length));
72
72
  let width1 = terminalWidth - width3 - width2 - 10;
73
73
  linesContent.forEach((lineContent) => {
74
74
  let { routeStr } = lineContent;
@@ -83,9 +83,9 @@ function getPagesAndRoutesInfo(pageRoutes) {
83
83
  });
84
84
  width1 = Math.max(...linesContent.map(({ routeStr }) => stripAnsi(routeStr).length));
85
85
  let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
86
- let cell1 = routeStr.padEnd(width1 + (routeStr.length - stripAnsi(routeStr).length), ' ');
87
- let cell2 = routeTypeSrc.padEnd(width2, ' ');
88
- let cell3 = routeDefinedBy.padEnd(width3, ' ');
86
+ let cell1 = padEnd(routeStr, width1 + (stripAnsi(routeStr).length - stripAnsi(routeStr).length));
87
+ let cell2 = padEnd(routeTypeSrc, width2);
88
+ let cell3 = padEnd(routeDefinedBy, width3);
89
89
  const isHeader = i === 0;
90
90
  if (isHeader) {
91
91
  cell1 = pc.dim(cell1);
@@ -119,6 +119,11 @@ function truncateRouteFunction(routeStr, lenMax) {
119
119
  routeStr = truncateString(routeStr, lenMax, (s) => pc.dim(s));
120
120
  return routeStr;
121
121
  }
122
+ /** Same as String.prototype.padEnd but with stripAnsi() */
123
+ function padEnd(str, width) {
124
+ const padWidth = Math.max(0, width - stripAnsi(str).length);
125
+ return str + ''.padEnd(padWidth, ' ');
126
+ }
122
127
  function removeNonAscii(str) {
123
128
  // https://stackoverflow.com/questions/20856197/remove-non-ascii-character-in-string/20856346#20856346
124
129
  return str.replace(/[^\x00-\x7F]/g, '');
@@ -4,7 +4,8 @@ export type { PageContextUrlComputedPropsInternal };
4
4
  export type { PageContextUrlComputedPropsClient };
5
5
  export type { PageContextUrlComputedPropsServer };
6
6
  export type { PageContextUrlSources };
7
- type UrlParsed = {
7
+ export type { Url };
8
+ type Url = {
8
9
  /** The URL origin, e.g. `https://example.com` of `https://example.com/product/42?details=yes#reviews` */
9
10
  origin: null | string;
10
11
  /** The URL pathname, e.g. `/product/42` of `https://example.com/product/42?details=yes#reviews` */
@@ -34,8 +35,9 @@ type PageContextUrlComputedPropsClient = {
34
35
  /** The URL pathname, e.g. `/product/42` of `https://example.com/product/42?details=yes#reviews` */
35
36
  urlPathname: string;
36
37
  /** Parsed information about the current URL */
37
- urlParsed: UrlParsed;
38
+ urlParsed: Url;
38
39
  };
40
+ /** For Vike internal use */
39
41
  type PageContextUrlComputedPropsInternal = PageContextUrlComputedPropsClient & {
40
42
  _urlRewrite: string | null;
41
43
  };
@@ -32,9 +32,7 @@ import type { ConfigVikeUserProvided } from '../ConfigVike.js';
32
32
  import type { Vike, VikePackages } from '../VikeNamespace.js';
33
33
  import type { PageContextClient, PageContextServer } from '../types.js';
34
34
  type HookName = 'onHydrationEnd' | 'onBeforePrerender' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onBeforeRoute' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onPrerenderStart' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'render';
35
- type ConfigNameBuiltInPublic = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender';
36
- type ConfigNameBuiltInInternal = 'isClientSideRenderable' | 'onBeforeRenderEnv';
37
- type ConfigNameBuiltIn = ConfigNameBuiltInPublic | ConfigNameBuiltInInternal;
35
+ type ConfigNameBuiltIn = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender' | 'isClientSideRenderable' | 'onBeforeRenderEnv';
38
36
  type Config = ConfigBuiltIn & Vike.Config & (VikePackages.ConfigVikeReact | VikePackages.ConfigVikeVue | VikePackages.ConfigVikeSolid | VikePackages.ConfigVikeSvelte);
39
37
  /** Protect page(s), e.g. forbid unauthorized access.
40
38
  *
@@ -61,6 +61,7 @@ type PageConfigGlobalBuildTime = {
61
61
  configValueSources: ConfigValueSources;
62
62
  };
63
63
  type ConfigEnv = 'client-only' | 'server-only' | 'server-and-client' | 'config-only';
64
+ /** For Vike internal use */
64
65
  type ConfigEnvInternal = ConfigEnv | '_routing-eager' | '_routing-lazy';
65
66
  type ConfigValueSource = {
66
67
  configEnv: ConfigEnvInternal;
@@ -22,6 +22,7 @@ type PageContextClientWithServerRouting = PageContextBuiltInClientWithServerRout
22
22
  * https://vike.dev/pageContext
23
23
  */
24
24
  type PageContextBuiltInServer<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsServer;
25
+ /** For Vike internal use */
25
26
  type PageContextBuiltInServerInternal<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsInternal;
26
27
  type PageContextBuiltInCommon<Page = [never]> = {
27
28
  /** The `export { Page }` of your `.page.js` file.
@@ -10,6 +10,7 @@ export type { Config, ConfigMeta as Meta, GuardAsync, GuardSync, OnBeforePrerend
10
10
  export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
11
11
  export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
12
12
  export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
13
+ export type { Url } from '../shared/addUrlComputedProps.js';
13
14
  export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
14
15
  export { defineConfig } from './defineConfig.js';
15
16
  import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
5
5
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
6
6
  declare const projectInfo: {
7
7
  projectName: "Vike";
8
- projectVersion: "0.4.143-commit-f03b42d";
8
+ projectVersion: "0.4.143-commit-dc6fea0";
9
9
  npmPackageName: "vike";
10
10
  githubRepository: "https://github.com/vikejs/vike";
11
11
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  import { onProjectInfo } from './assertSingleInstance.js';
3
- const PROJECT_VERSION = '0.4.143-commit-f03b42d';
3
+ const PROJECT_VERSION = '0.4.143-commit-dc6fea0';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.143-commit-f03b42d",
3
+ "version": "0.4.143-commit-dc6fea0",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",