vike 0.4.167-commit-14e4b5e → 0.4.167-commit-4996ef0

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,98 +82,95 @@ 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: transformImports !== 'all',
86
- bundle: transformImports !== 'all'
85
+ metafile: true,
86
+ bundle: true
87
87
  };
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 =
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' ||
127
121
  // .jsx, .vue, .svg, ... => obviously not config code
128
122
  !(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
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
- }
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
+ });
174
149
  }
175
- ];
176
- }
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
+ */
171
+ }
172
+ }
173
+ ];
177
174
  let result;
178
175
  try {
179
176
  result = await (0, esbuild_1.build)(options);
@@ -183,15 +180,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
183
180
  throw err;
184
181
  }
185
182
  // Track dependencies
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
- }
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
+ });
195
190
  const code = result.outputFiles[0].text;
196
191
  (0, utils_js_1.assert)(typeof code === 'string');
197
192
  return { code, pointerImports };
@@ -781,7 +781,30 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
781
781
  }
782
782
  */
783
783
  function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
784
- let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
784
+ {
785
+ const ui = ['vike-react', 'vike-vue', 'vike-solid'];
786
+ const knownVikeExntensionConfigs = {
787
+ description: ui,
788
+ favicon: ui,
789
+ Head: ui,
790
+ Layout: ui,
791
+ onCreateApp: ['vike-vue'],
792
+ title: ui,
793
+ ssr: ui,
794
+ stream: ui,
795
+ Wrapper: ui
796
+ };
797
+ if (configName in knownVikeExntensionConfigs) {
798
+ const requiredVikeExtension = knownVikeExntensionConfigs[configName];
799
+ (0, utils_js_1.assertUsage)(false, [
800
+ `${filePathToShowToUser} uses the config ${picocolors_1.default.cyan(configName)} (https://vike.dev/${configName})`,
801
+ `which requires the Vike extension ${requiredVikeExtension.map((e) => picocolors_1.default.bold(e)).join('/')}.`,
802
+ `Make sure to install the Vike extension,`,
803
+ `and make sure it applies to ${filePathToShowToUser} as explained at https://vike.dev/extends#inheritance.`
804
+ ].join(' '));
805
+ }
806
+ }
807
+ let errMsg = `${filePathToShowToUser} sets an unknown config ${picocolors_1.default.cyan(configName)}`;
785
808
  let configNameSimilar = null;
786
809
  if (configName === 'page') {
787
810
  configNameSimilar = 'Page';
@@ -789,17 +812,13 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
789
812
  else {
790
813
  configNameSimilar = (0, utils_js_1.getMostSimilar)(configName, configNames);
791
814
  }
792
- if (configNameSimilar || configName === 'page') {
793
- (0, utils_js_1.assert)(configNameSimilar);
815
+ if (configNameSimilar) {
794
816
  (0, utils_js_1.assert)(configNameSimilar !== configName);
795
- errMsg += `, did you mean to define ${picocolors_1.default.cyan(configNameSimilar)} instead?`;
817
+ errMsg += `, did you mean to set ${picocolors_1.default.cyan(configNameSimilar)} instead?`;
796
818
  if (configName === 'page') {
797
819
  errMsg += ` (The name of the config ${picocolors_1.default.cyan('Page')} starts with a capital letter ${picocolors_1.default.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
798
820
  }
799
821
  }
800
- else {
801
- errMsg += `, you need to define the config ${picocolors_1.default.cyan(configName)} by using ${picocolors_1.default.cyan('config.meta')} https://vike.dev/meta`;
802
- }
803
822
  (0, utils_js_1.assertUsage)(false, errMsg);
804
823
  }
805
824
  function determineRouteFilesystem(locationId, configValueSources) {
@@ -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)(path_1.default.win32.isAbsolute(p));
14
+ if (process.platform !== 'win32') {
15
+ (0, assert_js_1.assert)(p.startsWith('/'));
16
16
  }
17
17
  else {
18
- (0, assert_js_1.assert)(p.startsWith('/'));
18
+ (0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
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-14e4b5e';
4
+ const PROJECT_VERSION = '0.4.167-commit-4996ef0';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -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: 'all' | Record<string, boolean>, skipWarnings?: true): string | null;
5
+ declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', 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 } from '../../../../utils.js';
10
+ import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger, assertPathIsFilesystemAbsolute } 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,98 +79,95 @@ 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: transformImports !== 'all',
83
- bundle: transformImports !== 'all'
82
+ metafile: true,
83
+ bundle: true
84
84
  };
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 =
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' ||
124
118
  // .jsx, .vue, .svg, ... => obviously not config code
125
119
  !isJavaScriptFile(resolved.path) ||
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
- }
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
+ });
171
146
  }
172
- ];
173
- }
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
+ */
168
+ }
169
+ }
170
+ ];
174
171
  let result;
175
172
  try {
176
173
  result = await build(options);
@@ -180,15 +177,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
180
177
  throw err;
181
178
  }
182
179
  // Track dependencies
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
- }
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
+ });
192
187
  const code = result.outputFiles[0].text;
193
188
  assert(typeof code === 'string');
194
189
  return { code, pointerImports };
@@ -776,7 +776,30 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
776
776
  }
777
777
  */
778
778
  function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
779
- let errMsg = `${filePathToShowToUser} defines an unknown config ${pc.cyan(configName)}`;
779
+ {
780
+ const ui = ['vike-react', 'vike-vue', 'vike-solid'];
781
+ const knownVikeExntensionConfigs = {
782
+ description: ui,
783
+ favicon: ui,
784
+ Head: ui,
785
+ Layout: ui,
786
+ onCreateApp: ['vike-vue'],
787
+ title: ui,
788
+ ssr: ui,
789
+ stream: ui,
790
+ Wrapper: ui
791
+ };
792
+ if (configName in knownVikeExntensionConfigs) {
793
+ const requiredVikeExtension = knownVikeExntensionConfigs[configName];
794
+ assertUsage(false, [
795
+ `${filePathToShowToUser} uses the config ${pc.cyan(configName)} (https://vike.dev/${configName})`,
796
+ `which requires the Vike extension ${requiredVikeExtension.map((e) => pc.bold(e)).join('/')}.`,
797
+ `Make sure to install the Vike extension,`,
798
+ `and make sure it applies to ${filePathToShowToUser} as explained at https://vike.dev/extends#inheritance.`
799
+ ].join(' '));
800
+ }
801
+ }
802
+ let errMsg = `${filePathToShowToUser} sets an unknown config ${pc.cyan(configName)}`;
780
803
  let configNameSimilar = null;
781
804
  if (configName === 'page') {
782
805
  configNameSimilar = 'Page';
@@ -784,17 +807,13 @@ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
784
807
  else {
785
808
  configNameSimilar = getMostSimilar(configName, configNames);
786
809
  }
787
- if (configNameSimilar || configName === 'page') {
788
- assert(configNameSimilar);
810
+ if (configNameSimilar) {
789
811
  assert(configNameSimilar !== configName);
790
- errMsg += `, did you mean to define ${pc.cyan(configNameSimilar)} instead?`;
812
+ errMsg += `, did you mean to set ${pc.cyan(configNameSimilar)} instead?`;
791
813
  if (configName === 'page') {
792
814
  errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
793
815
  }
794
816
  }
795
- else {
796
- errMsg += `, you need to define the config ${pc.cyan(configName)} by using ${pc.cyan('config.meta')} https://vike.dev/meta`;
797
- }
798
817
  assertUsage(false, errMsg);
799
818
  }
800
819
  function determineRouteFilesystem(locationId, configValueSources) {
@@ -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(path.win32.isAbsolute(p));
9
+ if (process.platform !== 'win32') {
10
+ assert(p.startsWith('/'));
11
11
  }
12
12
  else {
13
- assert(p.startsWith('/'));
13
+ assert(path.win32.isAbsolute(p));
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-14e4b5e";
3
+ declare const PROJECT_VERSION: "0.4.167-commit-4996ef0";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.167-commit-14e4b5e";
6
+ projectVersion: "0.4.167-commit-4996ef0";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.167-commit-14e4b5e';
3
+ const PROJECT_VERSION = '0.4.167-commit-4996ef0';
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-14e4b5e",
3
+ "version": "0.4.167-commit-4996ef0",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",