vike 0.4.142-commit-6eb0dd3 → 0.4.142-commit-937cb3b

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.
@@ -43,11 +43,9 @@ function envVarsPlugin() {
43
43
  if (isPrivate && isClientSide) {
44
44
  if (!code.includes(varName))
45
45
  return;
46
- const filePathVite = (0, utils_js_1.getFilePathVite)(id, config.root);
47
- const errMsgAddendum = isBuild
48
- ? ''
49
- : ' (vike will prevent your app from building for production)';
50
- const errMsg = `${varName} used in ${filePathVite} and therefore included in client-side bundle which can be be a security leak${errMsgAddendum}, remove ${varName} or rename ${key} to ${keyPublic}, see https://vike.dev/env`;
46
+ const filePathToShowToUser = (0, utils_js_1.getFilePathRelativeToUserRootDir)(id, config.root);
47
+ const errMsgAddendum = isBuild ? '' : ' (vike will prevent your app from building for production)';
48
+ const errMsg = `${varName} used in ${filePathToShowToUser} and therefore included in client-side bundle which can be be a security leak${errMsgAddendum}, remove ${varName} or rename ${key} to ${keyPublic}, see https://vike.dev/env`;
51
49
  if (isBuild) {
52
50
  (0, utils_js_1.assertUsage)(false, errMsg);
53
51
  }
@@ -122,7 +122,7 @@ function isVikeConfigModule(filePathAbsolute) {
122
122
  }
123
123
  function reloadConfig(filePath, config, configVike, op) {
124
124
  {
125
- const filePathToShowToUser = picocolors_1.default.dim((0, utils_js_1.getFilePathVite)(filePath, config.root, true));
125
+ const filePathToShowToUser = picocolors_1.default.dim((0, utils_js_1.getFilePathRelativeToUserRootDir)(filePath, config.root, true));
126
126
  const msg = `${op} ${filePathToShowToUser}`;
127
127
  (0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
128
128
  }
@@ -48,7 +48,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
48
48
  let { id, frame } = err;
49
49
  const msgFirstLine = [
50
50
  picocolors_1.default.red('Failed to transpile'),
51
- picocolors_1.default.bold(picocolors_1.default.red((0, utils_js_1.getFilePathVite)(normalizeId(id), userRootDir))),
51
+ picocolors_1.default.bold(picocolors_1.default.red((0, utils_js_1.getFilePathRelativeToUserRootDir)(normalizeId(id), userRootDir))),
52
52
  picocolors_1.default.red('because:')
53
53
  ].join(' ');
54
54
  const errMsg = getPrettyErrMessage(err);
@@ -199,9 +199,9 @@ function logErrorDebugNote() {
199
199
  store.errorDebugNoteAlreadyShown = true;
200
200
  }
201
201
  const msg = picocolors_1.default.dim([
202
- '┌─────────────────────────────────────────────────────────────────────┐',
202
+ '┌──────────────────────────────────────────────────────────┐',
203
203
  "│ Error isn't helpful? See https://vike.dev/errors#verbose │",
204
- '└─────────────────────────────────────────────────────────────────────┘'
204
+ '└──────────────────────────────────────────────────────────┘'
205
205
  ].join('\n'));
206
206
  (0, log_js_1.logDirectly)(msg, 'error');
207
207
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFilePathVite = exports.getFilePathAbsolute = void 0;
6
+ exports.getFilePathRelativeToUserRootDir = exports.getFilePathAbsolute = void 0;
7
7
  const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
8
8
  const assert_js_1 = require("./assert.js");
9
9
  const path_1 = __importDefault(require("path"));
@@ -47,20 +47,24 @@ function getFilePathAbsolute(filePath, config) {
47
47
  return filePathAbsolute;
48
48
  }
49
49
  exports.getFilePathAbsolute = getFilePathAbsolute;
50
- function getFilePathVite(filePath, userRootDir, alwaysRelativeToRoot = false) {
51
- (0, filesystemPathHandling_js_1.assertPosixPath)(filePath);
50
+ function getFilePathRelativeToUserRootDir(filePathAbsolute, userRootDir, alwaysRelative = false) {
51
+ (0, filesystemPathHandling_js_1.assertPosixPath)(filePathAbsolute);
52
52
  (0, filesystemPathHandling_js_1.assertPosixPath)(userRootDir);
53
- const filePathRelativeToRoot = path_1.default.posix.relative(userRootDir, filePath);
54
- if (!filePath.startsWith(userRootDir)) {
55
- if (alwaysRelativeToRoot) {
56
- return filePathRelativeToRoot;
53
+ let filePathRelativeToUserRootDir = path_1.default.posix.relative(userRootDir, filePathAbsolute);
54
+ if (filePathAbsolute.startsWith(userRootDir)) {
55
+ (0, assert_js_1.assert)(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'),
56
+ // Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
57
+ { filePathRelativeToUserRootDir, filePathAbsolute, userRootDir });
58
+ filePathRelativeToUserRootDir = `/${filePathRelativeToUserRootDir}`;
59
+ return filePathRelativeToUserRootDir;
60
+ }
61
+ else {
62
+ if (alwaysRelative) {
63
+ return filePathRelativeToUserRootDir;
57
64
  }
58
65
  else {
59
- return filePath;
66
+ return filePathAbsolute;
60
67
  }
61
68
  }
62
- (0, assert_js_1.assert)(!filePathRelativeToRoot.startsWith('.') && !filePathRelativeToRoot.startsWith('/'));
63
- const filePathVite = `/${filePathRelativeToRoot}`;
64
- return filePathVite;
65
69
  }
66
- exports.getFilePathVite = getFilePathVite;
70
+ exports.getFilePathRelativeToUserRootDir = getFilePathRelativeToUserRootDir;
@@ -112,7 +112,10 @@ function parsePathname(urlWithoutHashNorSearch, baseServer) {
112
112
  else {
113
113
  // In the browser, this is the Base URL of the current URL
114
114
  // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
115
- const base = (typeof window !== 'undefined' && window?.document?.baseURI) || baseServer;
115
+ let baseURI = typeof window !== 'undefined' && window?.document?.baseURI;
116
+ if (baseURI)
117
+ baseURI = parseOrigin(baseURI).pathname;
118
+ const base = baseURI || baseServer;
116
119
  const pathname = resolveUrlPathnameRelative(urlWithoutHashNorSearch, base);
117
120
  // We need to parse the origin in case `base === window.document.baseURI`
118
121
  const parsed = parseOrigin(pathname);
@@ -155,6 +158,8 @@ function resolveUrlPathnameRelative(pathnameRelative, base) {
155
158
  let pathnameAbsolute = stack.join('/');
156
159
  if (baseRestoreTrailingSlash && !pathnameAbsolute.endsWith('/'))
157
160
  pathnameAbsolute += '/';
161
+ if (!pathnameAbsolute.startsWith('/'))
162
+ pathnameAbsolute = '/' + pathnameAbsolute;
158
163
  return pathnameAbsolute;
159
164
  }
160
165
  /* Not needed anymore?
@@ -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.142-commit-6eb0dd3';
5
+ const PROJECT_VERSION = '0.4.142-commit-937cb3b';
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
8
8
  projectVersion: PROJECT_VERSION,
@@ -1,6 +1,6 @@
1
1
  export { envVarsPlugin };
2
2
  import { loadEnv } from 'vite';
3
- import { assert, assertPosixPath, assertUsage, assertWarning, getFilePathVite, lowerFirst } from '../utils.js';
3
+ import { assert, assertPosixPath, assertUsage, assertWarning, getFilePathRelativeToUserRootDir, lowerFirst } from '../utils.js';
4
4
  function envVarsPlugin() {
5
5
  let envsAll;
6
6
  let config;
@@ -41,11 +41,9 @@ function envVarsPlugin() {
41
41
  if (isPrivate && isClientSide) {
42
42
  if (!code.includes(varName))
43
43
  return;
44
- const filePathVite = getFilePathVite(id, config.root);
45
- const errMsgAddendum = isBuild
46
- ? ''
47
- : ' (vike will prevent your app from building for production)';
48
- const errMsg = `${varName} used in ${filePathVite} and therefore included in client-side bundle which can be be a security leak${errMsgAddendum}, remove ${varName} or rename ${key} to ${keyPublic}, see https://vike.dev/env`;
44
+ const filePathToShowToUser = getFilePathRelativeToUserRootDir(id, config.root);
45
+ const errMsgAddendum = isBuild ? '' : ' (vike will prevent your app from building for production)';
46
+ const errMsg = `${varName} used in ${filePathToShowToUser} and therefore included in client-side bundle which can be be a security leak${errMsgAddendum}, remove ${varName} or rename ${key} to ${keyPublic}, see https://vike.dev/env`;
49
47
  if (isBuild) {
50
48
  assertUsage(false, errMsg);
51
49
  }
@@ -3,7 +3,7 @@ import { normalizePath } from 'vite';
3
3
  import { getConfigVike } from '../../../shared/getConfigVike.js';
4
4
  import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
5
5
  import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
6
- import { assert, assertPosixPath, getFilePathVite, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
6
+ import { assert, assertPosixPath, getFilePathRelativeToUserRootDir, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
7
7
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
8
8
  import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
9
9
  import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
@@ -116,7 +116,7 @@ function isVikeConfigModule(filePathAbsolute) {
116
116
  }
117
117
  function reloadConfig(filePath, config, configVike, op) {
118
118
  {
119
- const filePathToShowToUser = pc.dim(getFilePathVite(filePath, config.root, true));
119
+ const filePathToShowToUser = pc.dim(getFilePathRelativeToUserRootDir(filePath, config.root, true));
120
120
  const msg = `${op} ${filePathToShowToUser}`;
121
121
  logConfigInfo(msg, 'info');
122
122
  }
@@ -7,7 +7,7 @@ export { isEquivalentErrorWithCodeSnippet };
7
7
  export { getPrettyErrMessage };
8
8
  // Copied & adapted from https://github.com/vitejs/vite/blob/9c114c5c72a6af87e3330d5573362554b4511265/packages/vite/src/node/server/middlewares/error.ts
9
9
  import pc from '@brillout/picocolors';
10
- import { assert, escapeRegex, getFilePathVite, isObject, removeEmptyLines, stripAnsi, toPosixPath } from '../../utils.js';
10
+ import { assert, escapeRegex, getFilePathRelativeToUserRootDir, isObject, removeEmptyLines, stripAnsi, toPosixPath } from '../../utils.js';
11
11
  function isErrorWithCodeSnippet(err) {
12
12
  if (!isObject(err)) {
13
13
  return false;
@@ -46,7 +46,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
46
46
  let { id, frame } = err;
47
47
  const msgFirstLine = [
48
48
  pc.red('Failed to transpile'),
49
- pc.bold(pc.red(getFilePathVite(normalizeId(id), userRootDir))),
49
+ pc.bold(pc.red(getFilePathRelativeToUserRootDir(normalizeId(id), userRootDir))),
50
50
  pc.red('because:')
51
51
  ].join(' ');
52
52
  const errMsg = getPrettyErrMessage(err);
@@ -194,9 +194,9 @@ function logErrorDebugNote() {
194
194
  store.errorDebugNoteAlreadyShown = true;
195
195
  }
196
196
  const msg = pc.dim([
197
- '┌─────────────────────────────────────────────────────────────────────┐',
197
+ '┌──────────────────────────────────────────────────────────┐',
198
198
  "│ Error isn't helpful? See https://vike.dev/errors#verbose │",
199
- '└─────────────────────────────────────────────────────────────────────┘'
199
+ '└──────────────────────────────────────────────────────────┘'
200
200
  ].join('\n'));
201
201
  logDirectly(msg, 'error');
202
202
  }
@@ -1,5 +1,5 @@
1
1
  export { getFilePathAbsolute };
2
- export { getFilePathVite };
2
+ export { getFilePathRelativeToUserRootDir };
3
3
  import type { ResolvedConfig } from 'vite';
4
4
  declare function getFilePathAbsolute(filePath: string, config: ResolvedConfig): string;
5
- declare function getFilePathVite(filePath: string, userRootDir: string, alwaysRelativeToRoot?: boolean): string;
5
+ declare function getFilePathRelativeToUserRootDir(filePathAbsolute: string, userRootDir: string, alwaysRelative?: boolean): string;
@@ -1,5 +1,5 @@
1
1
  export { getFilePathAbsolute };
2
- export { getFilePathVite };
2
+ export { getFilePathRelativeToUserRootDir };
3
3
  import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
4
4
  import { assert } from './assert.js';
5
5
  import path from 'path';
@@ -42,19 +42,23 @@ function getFilePathAbsolute(filePath, config) {
42
42
  assertPathIsFilesystemAbsolute(filePathAbsolute);
43
43
  return filePathAbsolute;
44
44
  }
45
- function getFilePathVite(filePath, userRootDir, alwaysRelativeToRoot = false) {
46
- assertPosixPath(filePath);
45
+ function getFilePathRelativeToUserRootDir(filePathAbsolute, userRootDir, alwaysRelative = false) {
46
+ assertPosixPath(filePathAbsolute);
47
47
  assertPosixPath(userRootDir);
48
- const filePathRelativeToRoot = path.posix.relative(userRootDir, filePath);
49
- if (!filePath.startsWith(userRootDir)) {
50
- if (alwaysRelativeToRoot) {
51
- return filePathRelativeToRoot;
48
+ let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute);
49
+ if (filePathAbsolute.startsWith(userRootDir)) {
50
+ assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'),
51
+ // Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
52
+ { filePathRelativeToUserRootDir, filePathAbsolute, userRootDir });
53
+ filePathRelativeToUserRootDir = `/${filePathRelativeToUserRootDir}`;
54
+ return filePathRelativeToUserRootDir;
55
+ }
56
+ else {
57
+ if (alwaysRelative) {
58
+ return filePathRelativeToUserRootDir;
52
59
  }
53
60
  else {
54
- return filePath;
61
+ return filePathAbsolute;
55
62
  }
56
63
  }
57
- assert(!filePathRelativeToRoot.startsWith('.') && !filePathRelativeToRoot.startsWith('/'));
58
- const filePathVite = `/${filePathRelativeToRoot}`;
59
- return filePathVite;
60
64
  }
@@ -110,7 +110,10 @@ function parsePathname(urlWithoutHashNorSearch, baseServer) {
110
110
  else {
111
111
  // In the browser, this is the Base URL of the current URL
112
112
  // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
113
- const base = (typeof window !== 'undefined' && window?.document?.baseURI) || baseServer;
113
+ let baseURI = typeof window !== 'undefined' && window?.document?.baseURI;
114
+ if (baseURI)
115
+ baseURI = parseOrigin(baseURI).pathname;
116
+ const base = baseURI || baseServer;
114
117
  const pathname = resolveUrlPathnameRelative(urlWithoutHashNorSearch, base);
115
118
  // We need to parse the origin in case `base === window.document.baseURI`
116
119
  const parsed = parseOrigin(pathname);
@@ -153,6 +156,8 @@ function resolveUrlPathnameRelative(pathnameRelative, base) {
153
156
  let pathnameAbsolute = stack.join('/');
154
157
  if (baseRestoreTrailingSlash && !pathnameAbsolute.endsWith('/'))
155
158
  pathnameAbsolute += '/';
159
+ if (!pathnameAbsolute.startsWith('/'))
160
+ pathnameAbsolute = '/' + pathnameAbsolute;
156
161
  return pathnameAbsolute;
157
162
  }
158
163
  /* Not needed anymore?
@@ -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.142-commit-6eb0dd3";
8
+ projectVersion: "0.4.142-commit-937cb3b";
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.142-commit-6eb0dd3';
3
+ const PROJECT_VERSION = '0.4.142-commit-937cb3b';
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.142-commit-6eb0dd3",
3
+ "version": "0.4.142-commit-937cb3b",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",