vike 0.4.167-commit-4996ef0 → 0.4.167-commit-aa83fde

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.
@@ -82,95 +82,98 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
82
82
  // Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
83
83
  treeShaking: false,
84
84
  minify: false,
85
- metafile: true,
86
- bundle: true
85
+ metafile: transformImports !== 'all',
86
+ bundle: transformImports !== 'all'
87
87
  };
88
- let pointerImports = {};
89
- options.plugins = [
90
- // Determine whether an import should be:
91
- // - A pointer import
92
- // - Externalized
93
- {
94
- name: 'vike-esbuild-plugin',
95
- setup(build) {
96
- // https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
97
- const useEsbuildResolver = 'useEsbuildResolver';
98
- // https://github.com/brillout/esbuild-playground
99
- build.onResolve({ filter: /.*/ }, async (args) => {
100
- if (args.kind !== 'import-statement')
101
- return;
102
- if (args.pluginData?.[useEsbuildResolver])
103
- return;
104
- const { path, ...opts } = args;
105
- opts.pluginData = { [useEsbuildResolver]: true };
106
- const resolved = await build.resolve(path, opts);
107
- if (resolved.errors.length > 0) {
108
- /* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
109
- pointerImports[args.path] = false
110
- return { external: true }
111
- */
112
- // Let esbuild throw the error. (It throws a nice & pretty error.)
113
- return resolved;
114
- }
115
- (0, utils_js_1.assert)(resolved.path);
116
- resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
117
- // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
118
- // - This is temporary, see comment below.
119
- const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
120
- const isPointerImport = transformImports === 'all' ||
88
+ let pointerImports;
89
+ if (transformImports === 'all') {
90
+ pointerImports = 'all';
91
+ options.packages = 'external';
92
+ }
93
+ else {
94
+ const pointerImports_ = (pointerImports = {});
95
+ options.plugins = [
96
+ // Determine whether an import should be:
97
+ // - A pointer import
98
+ // - Externalized
99
+ {
100
+ name: 'vike-esbuild-plugin',
101
+ setup(build) {
102
+ // https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
103
+ const useEsbuildResolver = 'useEsbuildResolver';
104
+ // https://github.com/brillout/esbuild-playground
105
+ build.onResolve({ filter: /.*/ }, async (args) => {
106
+ if (args.kind !== 'import-statement')
107
+ return;
108
+ if (args.pluginData?.[useEsbuildResolver])
109
+ return;
110
+ const { path, ...opts } = args;
111
+ opts.pluginData = { [useEsbuildResolver]: true };
112
+ const resolved = await build.resolve(path, opts);
113
+ if (resolved.errors.length > 0) {
114
+ /* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
115
+ pointerImports_[args.path] = false
116
+ return { external: true }
117
+ */
118
+ // Let esbuild throw the error. (It throws a nice & pretty error.)
119
+ return resolved;
120
+ }
121
+ (0, utils_js_1.assert)(resolved.path);
122
+ resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
123
+ // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
124
+ // - This is temporary, see comment below.
125
+ const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
126
+ const isPointerImport =
121
127
  // .jsx, .vue, .svg, ... => obviously not config code
122
128
  !(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
123
- // Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
124
- // - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
125
- // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
126
- isVikeExtensionConfigImport ||
127
- // Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
128
- // - For example if esbuild cannot resolve a path alias while Vite can.
129
- // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
130
- resolved.errors.length > 0;
131
- pointerImports[resolved.path] = isPointerImport;
132
- (0, utils_js_1.assertPosixPath)(resolved.path);
133
- const isExternal = isPointerImport ||
134
- // Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
135
- resolved.path.includes('/node_modules/');
136
- if (debug.isActivated)
137
- debug('onResolved()', { args, resolved, isPointerImport, isExternal });
138
- // We need esbuild to resolve path aliases so that we can use:
139
- // isNpmPackageImport(str, { cannotBePathAlias: true })
140
- // assertIsNpmPackageImport()
141
- (0, utils_js_1.assertPathIsFilesystemAbsolute)(resolved.path);
142
- if (isExternal) {
143
- return { external: true, path: resolved.path };
144
- }
145
- else {
146
- return resolved;
147
- }
148
- });
149
- }
150
- },
151
- // Track dependencies
152
- {
153
- name: 'vike:dependency-tracker',
154
- setup(b) {
155
- b.onLoad({ filter: /./ }, (args) => {
156
- // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
157
- let { path } = args;
158
- path = (0, utils_js_1.toPosixPath)(path);
159
- getVikeConfig_js_1.vikeConfigDependencies.add(path);
160
- return undefined;
161
- });
162
- /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
163
- * - Because onLoad() isn't call if the config dependency can't be resolved.
164
- * - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
165
- * ```bash
166
- * mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
167
- * ```
168
- * - But implementing a fix is complex and isn't worth it.
169
- b.onResolve(...)
170
- */
129
+ // Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
130
+ // - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
131
+ // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
132
+ isVikeExtensionConfigImport ||
133
+ // Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
134
+ // - For example if esbuild cannot resolve a path alias while Vite can.
135
+ // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
136
+ resolved.errors.length > 0;
137
+ pointerImports_[resolved.path] = isPointerImport;
138
+ (0, utils_js_1.assertPosixPath)(resolved.path);
139
+ const isExternal = isPointerImport ||
140
+ // Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
141
+ resolved.path.includes('/node_modules/');
142
+ if (debug.isActivated)
143
+ debug('onResolved()', { args, resolved, isPointerImport, isExternal });
144
+ if (isExternal) {
145
+ return { external: true, path: resolved.path };
146
+ }
147
+ else {
148
+ return resolved;
149
+ }
150
+ });
151
+ }
152
+ },
153
+ // Track dependencies
154
+ {
155
+ name: 'vike:dependency-tracker',
156
+ setup(b) {
157
+ b.onLoad({ filter: /./ }, (args) => {
158
+ // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
159
+ let { path } = args;
160
+ path = (0, utils_js_1.toPosixPath)(path);
161
+ getVikeConfig_js_1.vikeConfigDependencies.add(path);
162
+ return undefined;
163
+ });
164
+ /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
165
+ * - Because onLoad() isn't call if the config dependency can't be resolved.
166
+ * - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
167
+ * ```bash
168
+ * mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
169
+ * ```
170
+ * - But implementing a fix is complex and isn't worth it.
171
+ b.onResolve(...)
172
+ */
173
+ }
171
174
  }
172
- }
173
- ];
175
+ ];
176
+ }
174
177
  let result;
175
178
  try {
176
179
  result = await (0, esbuild_1.build)(options);
@@ -180,13 +183,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
180
183
  throw err;
181
184
  }
182
185
  // Track dependencies
183
- (0, utils_js_1.assert)(result.metafile);
184
- Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
185
- filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
186
- (0, utils_js_1.assertPosixPath)(userRootDir);
187
- const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
188
- getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
189
- });
186
+ if (transformImports !== 'all') {
187
+ (0, utils_js_1.assert)(result.metafile);
188
+ Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
189
+ filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
190
+ (0, utils_js_1.assertPosixPath)(userRootDir);
191
+ const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
192
+ getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
193
+ });
194
+ }
190
195
  const code = result.outputFiles[0].text;
191
196
  (0, utils_js_1.assert)(typeof code === 'string');
192
197
  return { code, pointerImports };
@@ -11,11 +11,11 @@ const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
11
11
  function assertPathIsFilesystemAbsolute(p) {
12
12
  (0, filesystemPathHandling_js_1.assertPosixPath)(p);
13
13
  (0, assert_js_1.assert)(!p.startsWith('/@fs/'));
14
- if (process.platform !== 'win32') {
15
- (0, assert_js_1.assert)(p.startsWith('/'));
14
+ if (process.platform === 'win32') {
15
+ (0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
16
16
  }
17
17
  else {
18
- (0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
18
+ (0, assert_js_1.assert)(p.startsWith('/'));
19
19
  }
20
20
  }
21
21
  exports.assertPathIsFilesystemAbsolute = assertPathIsFilesystemAbsolute;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.167-commit-4996ef0';
4
+ const PROJECT_VERSION = '0.4.167-commit-aa83fde';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -3,6 +3,7 @@ type HistoryState = {
3
3
  timestamp?: number;
4
4
  scrollPosition?: null | ScrollPosition;
5
5
  triggeredBy?: 'user' | 'vike' | 'browser';
6
+ _isVikeEnhanced: true;
6
7
  };
7
8
  type ScrollPosition = {
8
9
  x: number;
@@ -1,6 +1,5 @@
1
1
  export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition, monkeyPatchHistoryPushState };
2
- import { assert, assertUsage, getGlobalObject, hasProp, isObject } from './utils.js';
3
- const globalObject = getGlobalObject('history.ts', {});
2
+ import { assert, assertUsage, hasProp, isObject } from './utils.js';
4
3
  // Fill missing state information:
5
4
  // - `history.state` can uninitialized (i.e. `null`):
6
5
  // - The very first render
@@ -8,9 +7,10 @@ const globalObject = getGlobalObject('history.ts', {});
8
7
  // - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `onLinkClick()` handler skips hash links).
9
8
  // - State information may be incomplete if `history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
10
9
  function initHistoryState() {
10
+ // No way found to add TypeScript types to `window.history.state`: https://github.com/microsoft/TypeScript/issues/36178
11
11
  let state = window.history.state;
12
12
  if (!state) {
13
- state = {};
13
+ state = { _isVikeEnhanced: true };
14
14
  }
15
15
  let hasModifications = false;
16
16
  if (!('timestamp' in state)) {
@@ -49,7 +49,7 @@ function saveScrollPosition() {
49
49
  function pushHistory(url, overwriteLastHistoryEntry) {
50
50
  if (!overwriteLastHistoryEntry) {
51
51
  const timestamp = getTimestamp();
52
- pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike' }, url);
52
+ pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike', _isVikeEnhanced: true }, url);
53
53
  }
54
54
  else {
55
55
  replaceHistoryState(getHistoryState(), url);
@@ -69,25 +69,29 @@ function assertState(state) {
69
69
  }
70
70
  }
71
71
  function replaceHistoryState(state, url) {
72
- window.history.replaceState(state, '', url ?? /* Passing `undefined` chokes older Edge versions */ null);
72
+ const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
73
+ window.history.replaceState(state, '', url_);
73
74
  }
74
75
  function pushHistoryState(state, url) {
75
- pushStateOriginal(state, '', url);
76
+ // Vike should call window.history.pushState() (and not the orignal `pushStateOriginal()`) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls, see https://github.com/vikejs/vike/issues/1582.
77
+ window.history.pushState(state, '', url);
76
78
  }
77
79
  function monkeyPatchHistoryPushState() {
78
- globalObject.pushStateOriginal = globalObject.pushStateOriginal ?? window.history.pushState;
79
- window.history.pushState = (stateFromUser = {}, ...rest) => {
80
- assertUsage(null === stateFromUser || undefined === stateFromUser || isObject(stateFromUser), 'history.pushState(state) argument state must be an object');
81
- const state = {
82
- scrollPosition: getScrollPosition(),
83
- timestamp: getTimestamp(),
84
- ...stateFromUser,
85
- // Don't allow user to overwrite triggeredBy as it would break Vike's handling of the 'popstate' event
86
- triggeredBy: 'user'
87
- };
88
- return pushStateOriginal(state, ...rest);
80
+ const pushStateOriginal = window.history.pushState;
81
+ window.history.pushState = (stateOriginal = {}, ...rest) => {
82
+ assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), 'history.pushState(state) argument state must be an object');
83
+ const stateEnhanced = isVikeEnhanced(stateOriginal)
84
+ ? stateOriginal
85
+ : {
86
+ _isVikeEnhanced: true,
87
+ scrollPosition: getScrollPosition(),
88
+ timestamp: getTimestamp(),
89
+ triggeredBy: 'user',
90
+ ...stateOriginal
91
+ };
92
+ return pushStateOriginal(stateEnhanced, ...rest);
89
93
  };
90
94
  }
91
- function pushStateOriginal(...args) {
92
- globalObject.pushStateOriginal.apply(history, args);
95
+ function isVikeEnhanced(state) {
96
+ return isObject(state) && '_isVikeEnhanced' in state;
93
97
  }
@@ -2,7 +2,7 @@ export { transformFileImports };
2
2
  export { parseImportData };
3
3
  export { isImportData };
4
4
  export type { ImportData };
5
- declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
5
+ declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: 'all' | Record<string, boolean>, skipWarnings?: true): string | null;
6
6
  /**
7
7
  * Data Structure holding info about import statement:
8
8
  * `import { someExport as someImport } from './some-file'`
@@ -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, isJavaScriptFile, createDebugger, assertPathIsFilesystemAbsolute } from '../../../../utils.js';
10
+ import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger } from '../../../../utils.js';
11
11
  import { transformFileImports } from './transformFileImports.js';
12
12
  import { vikeConfigDependencies } from '../getVikeConfig.js';
13
13
  import 'source-map-support/register.js';
@@ -79,95 +79,98 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
79
79
  // Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
80
80
  treeShaking: false,
81
81
  minify: false,
82
- metafile: true,
83
- bundle: true
82
+ metafile: transformImports !== 'all',
83
+ bundle: transformImports !== 'all'
84
84
  };
85
- let pointerImports = {};
86
- options.plugins = [
87
- // Determine whether an import should be:
88
- // - A pointer import
89
- // - Externalized
90
- {
91
- name: 'vike-esbuild-plugin',
92
- setup(build) {
93
- // https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
94
- const useEsbuildResolver = 'useEsbuildResolver';
95
- // https://github.com/brillout/esbuild-playground
96
- build.onResolve({ filter: /.*/ }, async (args) => {
97
- if (args.kind !== 'import-statement')
98
- return;
99
- if (args.pluginData?.[useEsbuildResolver])
100
- return;
101
- const { path, ...opts } = args;
102
- opts.pluginData = { [useEsbuildResolver]: true };
103
- const resolved = await build.resolve(path, opts);
104
- if (resolved.errors.length > 0) {
105
- /* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
106
- pointerImports[args.path] = false
107
- return { external: true }
108
- */
109
- // Let esbuild throw the error. (It throws a nice & pretty error.)
110
- return resolved;
111
- }
112
- assert(resolved.path);
113
- resolved.path = toPosixPath(resolved.path);
114
- // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
115
- // - This is temporary, see comment below.
116
- const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
117
- const isPointerImport = transformImports === 'all' ||
85
+ let pointerImports;
86
+ if (transformImports === 'all') {
87
+ pointerImports = 'all';
88
+ options.packages = 'external';
89
+ }
90
+ else {
91
+ const pointerImports_ = (pointerImports = {});
92
+ options.plugins = [
93
+ // Determine whether an import should be:
94
+ // - A pointer import
95
+ // - Externalized
96
+ {
97
+ name: 'vike-esbuild-plugin',
98
+ setup(build) {
99
+ // https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
100
+ const useEsbuildResolver = 'useEsbuildResolver';
101
+ // https://github.com/brillout/esbuild-playground
102
+ build.onResolve({ filter: /.*/ }, async (args) => {
103
+ if (args.kind !== 'import-statement')
104
+ return;
105
+ if (args.pluginData?.[useEsbuildResolver])
106
+ return;
107
+ const { path, ...opts } = args;
108
+ opts.pluginData = { [useEsbuildResolver]: true };
109
+ const resolved = await build.resolve(path, opts);
110
+ if (resolved.errors.length > 0) {
111
+ /* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
112
+ pointerImports_[args.path] = false
113
+ return { external: true }
114
+ */
115
+ // Let esbuild throw the error. (It throws a nice & pretty error.)
116
+ return resolved;
117
+ }
118
+ assert(resolved.path);
119
+ resolved.path = toPosixPath(resolved.path);
120
+ // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
121
+ // - This is temporary, see comment below.
122
+ const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
123
+ const isPointerImport =
118
124
  // .jsx, .vue, .svg, ... => obviously not config code
119
125
  !isJavaScriptFile(resolved.path) ||
120
- // Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
121
- // - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
122
- // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
123
- isVikeExtensionConfigImport ||
124
- // Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
125
- // - For example if esbuild cannot resolve a path alias while Vite can.
126
- // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
127
- resolved.errors.length > 0;
128
- pointerImports[resolved.path] = isPointerImport;
129
- assertPosixPath(resolved.path);
130
- const isExternal = isPointerImport ||
131
- // Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
132
- resolved.path.includes('/node_modules/');
133
- if (debug.isActivated)
134
- debug('onResolved()', { args, resolved, isPointerImport, isExternal });
135
- // We need esbuild to resolve path aliases so that we can use:
136
- // isNpmPackageImport(str, { cannotBePathAlias: true })
137
- // assertIsNpmPackageImport()
138
- assertPathIsFilesystemAbsolute(resolved.path);
139
- if (isExternal) {
140
- return { external: true, path: resolved.path };
141
- }
142
- else {
143
- return resolved;
144
- }
145
- });
146
- }
147
- },
148
- // Track dependencies
149
- {
150
- name: 'vike:dependency-tracker',
151
- setup(b) {
152
- b.onLoad({ filter: /./ }, (args) => {
153
- // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
154
- let { path } = args;
155
- path = toPosixPath(path);
156
- vikeConfigDependencies.add(path);
157
- return undefined;
158
- });
159
- /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
160
- * - Because onLoad() isn't call if the config dependency can't be resolved.
161
- * - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
162
- * ```bash
163
- * mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
164
- * ```
165
- * - But implementing a fix is complex and isn't worth it.
166
- b.onResolve(...)
167
- */
126
+ // Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
127
+ // - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
128
+ // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
129
+ isVikeExtensionConfigImport ||
130
+ // Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
131
+ // - For example if esbuild cannot resolve a path alias while Vite can.
132
+ // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
133
+ resolved.errors.length > 0;
134
+ pointerImports_[resolved.path] = isPointerImport;
135
+ assertPosixPath(resolved.path);
136
+ const isExternal = isPointerImport ||
137
+ // Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
138
+ resolved.path.includes('/node_modules/');
139
+ if (debug.isActivated)
140
+ debug('onResolved()', { args, resolved, isPointerImport, isExternal });
141
+ if (isExternal) {
142
+ return { external: true, path: resolved.path };
143
+ }
144
+ else {
145
+ return resolved;
146
+ }
147
+ });
148
+ }
149
+ },
150
+ // Track dependencies
151
+ {
152
+ name: 'vike:dependency-tracker',
153
+ setup(b) {
154
+ b.onLoad({ filter: /./ }, (args) => {
155
+ // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
156
+ let { path } = args;
157
+ path = toPosixPath(path);
158
+ vikeConfigDependencies.add(path);
159
+ return undefined;
160
+ });
161
+ /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
162
+ * - Because onLoad() isn't call if the config dependency can't be resolved.
163
+ * - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
164
+ * ```bash
165
+ * mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
166
+ * ```
167
+ * - But implementing a fix is complex and isn't worth it.
168
+ b.onResolve(...)
169
+ */
170
+ }
168
171
  }
169
- }
170
- ];
172
+ ];
173
+ }
171
174
  let result;
172
175
  try {
173
176
  result = await build(options);
@@ -177,13 +180,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
177
180
  throw err;
178
181
  }
179
182
  // Track dependencies
180
- assert(result.metafile);
181
- Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
182
- filePathRelative = toPosixPath(filePathRelative);
183
- assertPosixPath(userRootDir);
184
- const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
185
- vikeConfigDependencies.add(filePathAbsoluteFilesystem);
186
- });
183
+ if (transformImports !== 'all') {
184
+ assert(result.metafile);
185
+ Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
186
+ filePathRelative = toPosixPath(filePathRelative);
187
+ assertPosixPath(userRootDir);
188
+ const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
189
+ vikeConfigDependencies.add(filePathAbsoluteFilesystem);
190
+ });
191
+ }
187
192
  const code = result.outputFiles[0].text;
188
193
  assert(typeof code === 'string');
189
194
  return { code, pointerImports };
@@ -6,10 +6,10 @@ import { assertPosixPath } from './filesystemPathHandling.js';
6
6
  function assertPathIsFilesystemAbsolute(p) {
7
7
  assertPosixPath(p);
8
8
  assert(!p.startsWith('/@fs/'));
9
- if (process.platform !== 'win32') {
10
- assert(p.startsWith('/'));
9
+ if (process.platform === 'win32') {
10
+ assert(path.win32.isAbsolute(p));
11
11
  }
12
12
  else {
13
- assert(path.win32.isAbsolute(p));
13
+ assert(p.startsWith('/'));
14
14
  }
15
15
  }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.167-commit-4996ef0";
3
+ declare const PROJECT_VERSION: "0.4.167-commit-aa83fde";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.167-commit-4996ef0";
6
+ projectVersion: "0.4.167-commit-aa83fde";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.167-commit-4996ef0';
3
+ const PROJECT_VERSION = '0.4.167-commit-aa83fde';
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.167-commit-4996ef0",
3
+ "version": "0.4.167-commit-aa83fde",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",