vike 0.4.227-commit-ff6dcd9 → 0.4.227-commit-77128be

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.
@@ -111,8 +111,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
111
111
  build.onResolve({ filter: /.*/ }, async (args) => {
112
112
  if (args.kind !== 'import-statement')
113
113
  return;
114
- if (debugEsbuildResolve.isActivated)
115
- debugEsbuildResolve('args', args);
116
114
  // Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
117
115
  const useEsbuildResolver = 'useEsbuildResolver';
118
116
  if (args.pluginData?.[useEsbuildResolver])
@@ -120,6 +118,8 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
120
118
  const { path, ...opts } = args;
121
119
  opts.pluginData = { [useEsbuildResolver]: true };
122
120
  let resolved = await build.resolve(path, opts);
121
+ if (debugEsbuildResolve.isActivated)
122
+ debugEsbuildResolve('args', args);
123
123
  if (debugEsbuildResolve.isActivated)
124
124
  debugEsbuildResolve('resolved', resolved);
125
125
  // Temporary workaround for https://github.com/evanw/esbuild/issues/3973
@@ -160,11 +160,25 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
160
160
  // - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
161
161
  // - In practice, it seems like it requires some (non-trivial?) refactoring.
162
162
  isVikeExtensionImport;
163
- // Externalize npm package imports
164
163
  (0, utils_js_1.assertPosixPath)(importPathResolved);
165
- const isNpmPkgImport = importPathResolved.includes('/node_modules/') ||
164
+ // `isNpmPkgImport` => `importPathOriginal` is most likely an npm package import, but it can also be a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir`.
165
+ const isNpmPkgImport = (() => {
166
+ if (importPathResolved.includes('/node_modules/')) {
167
+ // So far I can't think of a use case where this assertion would fail, but let's eventually remove it to avoid artificially restricting the user.
168
+ (0, utils_js_1.assert)((0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal));
169
+ return true;
170
+ }
166
171
  // Linked npm packages
167
- !importPathResolved.startsWith(userRootDir);
172
+ if (
173
+ // Assuming path aliases usually resolve inside `userRootDir`.
174
+ // - This isn't always the case: https://github.com/vikejs/vike/issues/2326
175
+ !importPathResolved.startsWith(userRootDir) &&
176
+ // False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
177
+ (0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal)) {
178
+ return true;
179
+ }
180
+ return false;
181
+ })();
168
182
  const isExternal = isPointerImport ||
169
183
  // Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
170
184
  isNpmPkgImport;
@@ -188,19 +202,19 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
188
202
  filePathAbsoluteFilesystem: importPathResolved,
189
203
  userRootDir
190
204
  });
191
- // We assuming that path aliases always resolve inside `userRootDir`.
192
205
  if (filePathAbsoluteUserRootDir && !isNpmPkgImport) {
193
- // `importPathOriginal` is a path alias.
206
+ // `importPathOriginal` is most likely a path alias.
194
207
  // - We have to use esbuild's path alias resolution, because:
195
208
  // - Vike doesn't resolve path aliases at all.
196
209
  // - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
197
- // - Esbuild path alias resolution seems to be reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
210
+ // - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
211
+ (0, utils_js_1.assert)(!(0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal));
198
212
  importPathTranspiled = importPathResolved;
199
213
  }
200
214
  else {
201
- // `importPathOriginal` is an npm package import.
215
+ // `importPathOriginal` is most likely an npm package import.
202
216
  (0, utils_js_1.assertIsNpmPackageImport)(importPathOriginal);
203
- // For less confusing error messages, let the resolution be handled by Vike or Node.js.
217
+ // For improved error messages, let the resolution be handled by Vike or Node.js.
204
218
  importPathTranspiled = importPathOriginal;
205
219
  }
206
220
  }
@@ -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.227-commit-ff6dcd9';
5
+ exports.PROJECT_VERSION = '0.4.227-commit-77128be';
@@ -24,8 +24,8 @@ function assertFilePathAbsoluteFilesystem(filePath) {
24
24
  // - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
25
25
  // - But that's okay because the assertion will eventually fail for Windows users.
26
26
  // - On Linux there doesn't seem to be a way to distinguish between an absolute path starting from the filesystem root or starting from the user root directory, see comment at isFilePathAbsoluteFilesystem()
27
- (0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
28
27
  (0, path_js_1.assertPosixPath)(filePath);
28
+ (0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
29
29
  }
30
30
  /**
31
31
  * Whether `filePath` is an absolute file path starting from the filesystem root.
@@ -10,10 +10,10 @@ const assert_js_1 = require("./assert.js");
10
10
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
11
11
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
12
12
  function isNpmPackageImport(str, { cannotBePathAlias }) {
13
- // We cannot distinguish path alises that look like npm package imports
14
13
  (0, assert_js_1.assert)(cannotBePathAlias);
15
14
  return isNpmPackageImport_unreliable(str);
16
15
  }
16
+ // We cannot distinguish path aliases that look like npm package imports
17
17
  function isNpmPackageImport_unreliable(str) {
18
18
  const res = parse(str);
19
19
  return res !== null;
@@ -7,7 +7,7 @@ import fs from 'fs';
7
7
  import path from 'path';
8
8
  import pc from '@brillout/picocolors';
9
9
  import { import_ } from '@brillout/import';
10
- import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport, genPromise, isVitest, requireResolveOptional } from '../../../../utils.js';
10
+ import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport, genPromise, isVitest, requireResolveOptional, isNpmPackageImport_unreliable } from '../../../../utils.js';
11
11
  import { transformPointerImports } from './transformPointerImports.js';
12
12
  import sourceMapSupport from 'source-map-support';
13
13
  import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
@@ -106,8 +106,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
106
106
  build.onResolve({ filter: /.*/ }, async (args) => {
107
107
  if (args.kind !== 'import-statement')
108
108
  return;
109
- if (debugEsbuildResolve.isActivated)
110
- debugEsbuildResolve('args', args);
111
109
  // Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
112
110
  const useEsbuildResolver = 'useEsbuildResolver';
113
111
  if (args.pluginData?.[useEsbuildResolver])
@@ -115,6 +113,8 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
115
113
  const { path, ...opts } = args;
116
114
  opts.pluginData = { [useEsbuildResolver]: true };
117
115
  let resolved = await build.resolve(path, opts);
116
+ if (debugEsbuildResolve.isActivated)
117
+ debugEsbuildResolve('args', args);
118
118
  if (debugEsbuildResolve.isActivated)
119
119
  debugEsbuildResolve('resolved', resolved);
120
120
  // Temporary workaround for https://github.com/evanw/esbuild/issues/3973
@@ -155,11 +155,25 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
155
155
  // - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
156
156
  // - In practice, it seems like it requires some (non-trivial?) refactoring.
157
157
  isVikeExtensionImport;
158
- // Externalize npm package imports
159
158
  assertPosixPath(importPathResolved);
160
- const isNpmPkgImport = importPathResolved.includes('/node_modules/') ||
159
+ // `isNpmPkgImport` => `importPathOriginal` is most likely an npm package import, but it can also be a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir`.
160
+ const isNpmPkgImport = (() => {
161
+ if (importPathResolved.includes('/node_modules/')) {
162
+ // So far I can't think of a use case where this assertion would fail, but let's eventually remove it to avoid artificially restricting the user.
163
+ assert(isNpmPackageImport_unreliable(importPathOriginal));
164
+ return true;
165
+ }
161
166
  // Linked npm packages
162
- !importPathResolved.startsWith(userRootDir);
167
+ if (
168
+ // Assuming path aliases usually resolve inside `userRootDir`.
169
+ // - This isn't always the case: https://github.com/vikejs/vike/issues/2326
170
+ !importPathResolved.startsWith(userRootDir) &&
171
+ // False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
172
+ isNpmPackageImport_unreliable(importPathOriginal)) {
173
+ return true;
174
+ }
175
+ return false;
176
+ })();
163
177
  const isExternal = isPointerImport ||
164
178
  // Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
165
179
  isNpmPkgImport;
@@ -183,19 +197,19 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
183
197
  filePathAbsoluteFilesystem: importPathResolved,
184
198
  userRootDir
185
199
  });
186
- // We assuming that path aliases always resolve inside `userRootDir`.
187
200
  if (filePathAbsoluteUserRootDir && !isNpmPkgImport) {
188
- // `importPathOriginal` is a path alias.
201
+ // `importPathOriginal` is most likely a path alias.
189
202
  // - We have to use esbuild's path alias resolution, because:
190
203
  // - Vike doesn't resolve path aliases at all.
191
204
  // - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
192
- // - Esbuild path alias resolution seems to be reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
205
+ // - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
206
+ assert(!isNpmPackageImport_unreliable(importPathOriginal));
193
207
  importPathTranspiled = importPathResolved;
194
208
  }
195
209
  else {
196
- // `importPathOriginal` is an npm package import.
210
+ // `importPathOriginal` is most likely an npm package import.
197
211
  assertIsNpmPackageImport(importPathOriginal);
198
- // For less confusing error messages, let the resolution be handled by Vike or Node.js.
212
+ // For improved error messages, let the resolution be handled by Vike or Node.js.
199
213
  importPathTranspiled = importPathOriginal;
200
214
  }
201
215
  }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.227-commit-ff6dcd9";
1
+ export declare const PROJECT_VERSION: "0.4.227-commit-77128be";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.227-commit-ff6dcd9';
2
+ export const PROJECT_VERSION = '0.4.227-commit-77128be';
@@ -19,8 +19,8 @@ function assertFilePathAbsoluteFilesystem(filePath) {
19
19
  // - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
20
20
  // - But that's okay because the assertion will eventually fail for Windows users.
21
21
  // - On Linux there doesn't seem to be a way to distinguish between an absolute path starting from the filesystem root or starting from the user root directory, see comment at isFilePathAbsoluteFilesystem()
22
- assert(isFilePathAbsoluteFilesystem(filePath));
23
22
  assertPosixPath(filePath);
23
+ assert(isFilePathAbsoluteFilesystem(filePath));
24
24
  }
25
25
  /**
26
26
  * Whether `filePath` is an absolute file path starting from the filesystem root.
@@ -14,10 +14,10 @@ import { assert } from './assert.js';
14
14
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
15
15
  assertIsNotBrowser();
16
16
  function isNpmPackageImport(str, { cannotBePathAlias }) {
17
- // We cannot distinguish path alises that look like npm package imports
18
17
  assert(cannotBePathAlias);
19
18
  return isNpmPackageImport_unreliable(str);
20
19
  }
20
+ // We cannot distinguish path aliases that look like npm package imports
21
21
  function isNpmPackageImport_unreliable(str) {
22
22
  const res = parse(str);
23
23
  return res !== null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.227-commit-ff6dcd9",
3
+ "version": "0.4.227-commit-77128be",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {