vike 0.4.167 → 0.4.168-commit-7678a7d

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.
Files changed (40) hide show
  1. package/dist/cjs/node/plugin/plugins/buildConfig.js +8 -0
  2. package/dist/cjs/node/plugin/plugins/distFileNames.js +6 -0
  3. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -3
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -1
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +0 -8
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +14 -35
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +121 -95
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +27 -8
  10. package/dist/cjs/node/plugin/shared/getFilePath.js +6 -1
  11. package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
  12. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +13 -1
  13. package/dist/cjs/node/shared/prependEntriesDir.js +1 -0
  14. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +3 -3
  15. package/dist/cjs/utils/isDev.js +12 -4
  16. package/dist/cjs/utils/projectInfo.js +1 -1
  17. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -0
  18. package/dist/esm/client/client-routing-runtime/history.js +23 -19
  19. package/dist/esm/node/plugin/plugins/buildConfig.js +8 -0
  20. package/dist/esm/node/plugin/plugins/distFileNames.js +6 -0
  21. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
  22. package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -4
  23. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -1
  24. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -9
  25. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +14 -35
  26. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -1
  27. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +2 -2
  28. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +121 -95
  29. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +28 -9
  30. package/dist/esm/node/plugin/shared/getFilePath.js +6 -1
  31. package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
  32. package/dist/esm/node/runtime/renderPage/logErrorHint.js +13 -1
  33. package/dist/esm/node/shared/prependEntriesDir.js +1 -0
  34. package/dist/esm/shared/addUrlComputedProps.d.ts +2 -2
  35. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +3 -3
  36. package/dist/esm/utils/isDev.d.ts +3 -0
  37. package/dist/esm/utils/isDev.js +11 -3
  38. package/dist/esm/utils/projectInfo.d.ts +2 -2
  39. package/dist/esm/utils/projectInfo.js +1 -1
  40. package/package.json +2 -2
@@ -1,13 +1,13 @@
1
1
  export { transpileAndExecuteFile };
2
2
  export { getConfigBuildErrorFormatted };
3
3
  export { getConfigExecutionErrorIntroMsg };
4
- export { isTmpFile };
4
+ export { isTemporaryBuildFile };
5
5
  import { build, formatMessages } from 'esbuild';
6
6
  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,87 +79,96 @@ 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 what import should be externalized (and then transformed to a pointer/fake import)
94
- {
95
- name: 'vike:externalize-heuristic',
96
- setup(build) {
97
- // https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
85
+ let pointerImports = {};
86
+ options.plugins = [
87
+ // Determine whether an import should be:
88
+ // - A pointer import
89
+ // - Externalized
90
+ {
91
+ name: 'vike-esbuild',
92
+ setup(build) {
93
+ // https://github.com/brillout/esbuild-playground
94
+ build.onResolve({ filter: /.*/ }, async (args) => {
95
+ if (args.kind !== 'import-statement')
96
+ return;
97
+ // Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
98
98
  const useEsbuildResolver = 'useEsbuildResolver';
99
- // https://github.com/brillout/esbuild-playground
100
- build.onResolve({ filter: /.*/ }, async (args) => {
101
- if (args.kind !== 'import-statement')
102
- return;
103
- if (args.pluginData?.[useEsbuildResolver])
104
- return;
105
- const { path, ...opts } = args;
106
- opts.pluginData = { [useEsbuildResolver]: true };
107
- const resolved = await build.resolve(path, opts);
108
- resolved.path = toPosixPath(resolved.path);
109
- // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
110
- // - This is temporary, see comment below.
111
- const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
112
- const isPointerImport =
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
+ cleanEsbuildErrors(resolved.errors);
111
+ return resolved;
112
+ }
113
+ assert(resolved.path);
114
+ resolved.path = toPosixPath(resolved.path);
115
+ // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
116
+ // - This is temporary, see comment below.
117
+ const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
118
+ const isPointerImport = transformImports === 'all' ||
113
119
  // .jsx, .vue, .svg, ... => obviously not config code
114
120
  !isJavaScriptFile(resolved.path) ||
115
- // 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).
116
- // - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
117
- // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
118
- isVikeExtensionConfigImport ||
119
- // Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
120
- // - For example if esbuild cannot resolve a path alias while Vite can.
121
- // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
122
- resolved.errors.length > 0;
123
- pointerImports_[resolved.path] = isPointerImport;
124
- assertPosixPath(resolved.path);
125
- const isExternal = isPointerImport ||
126
- // npm package imports that aren't pointer imports (e.g. importing a Vite plugin)
127
- resolved.path.includes('/node_modules/');
128
- if (debug.isActivated)
129
- debug('onResolved()', { args, resolved, isPointerImport, isExternal });
130
- if (isExternal) {
131
- return { external: true, path: resolved.path };
132
- }
133
- else {
134
- return resolved;
135
- }
136
- });
137
- }
138
- },
139
- // Track dependencies
140
- {
141
- name: 'vike:dependency-tracker',
142
- setup(b) {
143
- b.onLoad({ filter: /./ }, (args) => {
144
- // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
145
- let { path } = args;
146
- path = toPosixPath(path);
147
- vikeConfigDependencies.add(path);
148
- return undefined;
149
- });
150
- /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
151
- * - Because onLoad() isn't call if the config dependency can't be resolved.
152
- * - 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):
153
- * ```bash
154
- * mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
155
- * ```
156
- * - But implementing a fix is complex and isn't worth it.
157
- b.onResolve(...)
158
- */
159
- }
121
+ // 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).
122
+ // - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
123
+ // - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
124
+ isVikeExtensionConfigImport ||
125
+ // Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
126
+ // - For example if esbuild cannot resolve a path alias while Vite can.
127
+ // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
128
+ resolved.errors.length > 0;
129
+ pointerImports[resolved.path] = isPointerImport;
130
+ assertPosixPath(resolved.path);
131
+ const isExternal = isPointerImport ||
132
+ // 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.)
133
+ resolved.path.includes('/node_modules/');
134
+ if (debug.isActivated)
135
+ debug('onResolved()', { args, resolved, isPointerImport, isExternal });
136
+ // We need esbuild to resolve path aliases so that we can use:
137
+ // isNpmPackageImport(str, { cannotBePathAlias: true })
138
+ // assertIsNpmPackageImport()
139
+ assertPathIsFilesystemAbsolute(resolved.path);
140
+ if (isExternal) {
141
+ return { external: true, path: resolved.path };
142
+ }
143
+ else {
144
+ return resolved;
145
+ }
146
+ });
160
147
  }
161
- ];
162
- }
148
+ },
149
+ // Track dependencies
150
+ {
151
+ name: 'vike:dependency-tracker',
152
+ setup(b) {
153
+ b.onLoad({ filter: /./ }, (args) => {
154
+ // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
155
+ let { path } = args;
156
+ path = toPosixPath(path);
157
+ vikeConfigDependencies.add(path);
158
+ return undefined;
159
+ });
160
+ /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
161
+ * - Because onLoad() isn't call if the config dependency can't be resolved.
162
+ * - 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):
163
+ * ```bash
164
+ * mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
165
+ * ```
166
+ * - But implementing a fix is complex and isn't worth it.
167
+ b.onResolve(...)
168
+ */
169
+ }
170
+ }
171
+ ];
163
172
  let result;
164
173
  try {
165
174
  result = await build(options);
@@ -169,15 +178,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
169
178
  throw err;
170
179
  }
171
180
  // Track dependencies
172
- if (transformImports !== 'all') {
173
- assert(result.metafile);
174
- Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
175
- filePathRelative = toPosixPath(filePathRelative);
176
- assertPosixPath(userRootDir);
177
- const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
178
- vikeConfigDependencies.add(filePathAbsoluteFilesystem);
179
- });
180
- }
181
+ assert(result.metafile);
182
+ Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
183
+ filePathRelative = toPosixPath(filePathRelative);
184
+ assertPosixPath(userRootDir);
185
+ const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
186
+ vikeConfigDependencies.add(filePathAbsoluteFilesystem);
187
+ });
181
188
  const code = result.outputFiles[0].text;
182
189
  assert(typeof code === 'string');
183
190
  return { code, pointerImports };
@@ -186,7 +193,7 @@ async function executeTranspiledFile(filePath, code) {
186
193
  const { filePathAbsoluteFilesystem } = filePath;
187
194
  // Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
188
195
  // - But seems to break source maps, so I don't think it's worth it
189
- const filePathTmp = getFilePathTmp(filePathAbsoluteFilesystem);
196
+ const filePathTmp = getTemporaryBuildFilePath(filePathAbsoluteFilesystem);
190
197
  fs.writeFileSync(filePathTmp, code);
191
198
  const clean = () => fs.unlinkSync(filePathTmp);
192
199
  let fileExports = {};
@@ -243,20 +250,19 @@ function getConfigExecutionErrorIntroMsg(err) {
243
250
  const errIntroMsg = execErrIntroMsg.get(err);
244
251
  return errIntroMsg ?? null;
245
252
  }
246
- const tmpPrefix = `[build-`;
247
- function getFilePathTmp(filePathAbsoluteFilesystem) {
253
+ function getTemporaryBuildFilePath(filePathAbsoluteFilesystem) {
248
254
  assertPosixPath(filePathAbsoluteFilesystem);
249
255
  const dirname = path.posix.dirname(filePathAbsoluteFilesystem);
250
256
  const filename = path.posix.basename(filePathAbsoluteFilesystem);
251
- // Syntax with semicolon `[build:${/*...*/}]` doesn't work on Windows: https://github.com/vikejs/vike/issues/800#issuecomment-1517329455
252
- const tag = `${tmpPrefix}${getRandomId(12)}]`;
253
- const filePathTmp = path.posix.join(dirname, `${tag}${filename}.mjs`);
257
+ // Syntax with semicolon `build:${/*...*/}` doesn't work on Windows: https://github.com/vikejs/vike/issues/800#issuecomment-1517329455
258
+ const filePathTmp = path.posix.join(dirname, `${filename}.build-${getRandomId(12)}.mjs`);
259
+ assert(isTemporaryBuildFile(filePathTmp));
254
260
  return filePathTmp;
255
261
  }
256
- function isTmpFile(filePath) {
262
+ function isTemporaryBuildFile(filePath) {
257
263
  assertPosixPath(filePath);
258
264
  const fileName = path.posix.basename(filePath);
259
- return fileName.startsWith(tmpPrefix);
265
+ return /\.build-[a-z0-9]{12}\.mjs$/.test(fileName);
260
266
  }
261
267
  function isHeaderFile(filePath) {
262
268
  assertPosixPath(filePath);
@@ -300,3 +306,23 @@ function getErrIntroMsg(operation, filePath) {
300
306
  ].join(' ');
301
307
  return msg;
302
308
  }
309
+ function cleanEsbuildErrors(errors) {
310
+ errors.forEach((e) => (e.notes = e.notes.filter((note) =>
311
+ // Remove note:
312
+ // ```shell
313
+ // You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
314
+ // ```
315
+ //
316
+ // From error:
317
+ // ```shell
318
+ // ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
319
+ //
320
+ // renderer/+config.h.js:1:29:
321
+ // 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
322
+ // ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323
+ //
324
+ // You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
325
+ //
326
+ // ```
327
+ !note.text.includes('as external to exclude it from the bundle'))));
328
+ }
@@ -7,7 +7,7 @@ import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEn
7
7
  import path from 'path';
8
8
  import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
9
9
  import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
10
- import { isTmpFile } from './getVikeConfig/transpileAndExecuteFile.js';
10
+ import { isTemporaryBuildFile } from './getVikeConfig/transpileAndExecuteFile.js';
11
11
  import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
12
12
  import { getViteDevServer } from '../../../../runtime/globalContext.js';
13
13
  import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
@@ -745,7 +745,7 @@ async function findPlusFiles(userRootDir, outDirRoot, isDev) {
745
745
  }
746
746
  function getConfigName(filePath) {
747
747
  assertPosixPath(filePath);
748
- if (isTmpFile(filePath))
748
+ if (isTemporaryBuildFile(filePath))
749
749
  return null;
750
750
  const fileName = path.posix.basename(filePath);
751
751
  // assertNoUnexpectedPlusSign(filePath, fileName)
@@ -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) {
@@ -87,7 +87,12 @@ function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDi
87
87
  assert(filePathRelative.startsWith('../'));
88
88
  return null;
89
89
  }
90
- assert(!filePathRelative.startsWith('.') && !filePathRelative.startsWith('/'));
90
+ assert(!filePathRelative.startsWith('/') &&
91
+ /* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
92
+ !filePathRelative.startsWith('.') &&
93
+ */
94
+ !filePathRelative.startsWith('./') &&
95
+ !filePathRelative.startsWith('../'));
91
96
  const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
92
97
  assert(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
93
98
  return filePathAbsoluteUserRootDir;
@@ -13,7 +13,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
13
13
  const clientDependencies = [];
14
14
  clientDependencies.push({
15
15
  id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
16
- onlyAssets: false,
16
+ onlyAssets: isClientSideRenderable ? false : true,
17
17
  eagerlyImported: false
18
18
  });
19
19
  // In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
@@ -20,6 +20,10 @@ const knownErrors = [
20
20
  // ```
21
21
  errMsg: 'assets.json',
22
22
  link: 'https://vike.dev/getGlobalContext'
23
+ },
24
+ {
25
+ errMsg: /Named export.*not found/i,
26
+ link: 'https://vike.dev/broken-npm-package#named-export-not-found'
23
27
  }
24
28
  ];
25
29
  function logErrorHint(error) {
@@ -285,7 +289,15 @@ function extractFromNodeModulesPath(str) {
285
289
  return packageName;
286
290
  }
287
291
  function includes(str1, str2) {
288
- return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
292
+ if (!str1)
293
+ return false;
294
+ if (str2 instanceof RegExp) {
295
+ return str2.test(str1.toLowerCase());
296
+ }
297
+ if (typeof str2 === 'string') {
298
+ return str1.toLowerCase().includes(str2.toLowerCase());
299
+ }
300
+ return false;
289
301
  }
290
302
  function includesNodeModules(str) {
291
303
  if (!str)
@@ -5,6 +5,7 @@ function prependEntriesDir(entryName) {
5
5
  entryName = entryName.slice(1);
6
6
  }
7
7
  assert(!entryName.startsWith('/'));
8
+ assert(entryName);
8
9
  entryName = `entries/${entryName}`;
9
10
  return entryName;
10
11
  }
@@ -18,14 +18,14 @@ type Url = {
18
18
  searchAll: Record<string, string[]>;
19
19
  /** The URL search parameterer string, e.g. `?details=yes` of `https://example.com/product/42?details=yes#reviews` */
20
20
  searchOriginal: null | string;
21
- /** @deprecated */
22
- searchString: null | string;
23
21
  /** The URL hash, e.g. `reviews` of `https://example.com/product/42?details=yes#reviews` */
24
22
  hash: string;
25
23
  /** The URL hash string, e.g. `#reviews` of `https://example.com/product/42?details=yes#reviews` */
26
24
  hashOriginal: null | string;
27
25
  /** @deprecated */
28
26
  hashString: null | string;
27
+ /** @deprecated */
28
+ searchString: null | string;
29
29
  };
30
30
  type PageContextUrlComputedPropsClient = {
31
31
  /** @deprecated */
@@ -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,6 +1,9 @@
1
1
  export { isDev1 };
2
2
  export { isDev1_onConfigureServer };
3
3
  export { isDev2 };
4
+ export { isDev3 };
5
+ import type { ConfigEnv } from 'vite';
6
+ declare function isDev3(configEnv: ConfigEnv): null | boolean;
4
7
  declare function isDev1(): boolean;
5
8
  declare function isDev1_onConfigureServer(): void | undefined;
6
9
  import type { ResolvedConfig } from 'vite';
@@ -1,10 +1,18 @@
1
1
  export { isDev1 };
2
2
  export { isDev1_onConfigureServer };
3
3
  export { isDev2 };
4
- // There isn't any reliable way to test whether Vite is ran as dev/build/preview/optimizeDep
5
- // - Failed attempt to make a PR: https://github.com/brillout/vite/tree/fix/config-operation
4
+ export { isDev3 };
5
+ function isDev3(configEnv) {
6
+ const { isPreview, command } = configEnv;
7
+ if (command !== 'serve')
8
+ return false;
9
+ if (typeof isPreview === 'boolean')
10
+ return !isPreview;
11
+ // isPreview is undefined in older Vite versions, see https://github.com/vitejs/vite/commit/93fce55
12
+ return null;
13
+ }
6
14
  // ********
7
- // Method 1 - most reliable
15
+ // Method 1 - reliable
8
16
  // ********
9
17
  import { assert } from './assert.js';
10
18
  import { getGlobalObject } from './getGlobalObject.js';
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.167";
3
+ declare const PROJECT_VERSION: "0.4.168-commit-7678a7d";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.167";
6
+ projectVersion: "0.4.168-commit-7678a7d";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.167';
3
+ const PROJECT_VERSION = '0.4.168-commit-7678a7d';
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",
3
+ "version": "0.4.168-commit-7678a7d",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -16,7 +16,7 @@
16
16
  "@brillout/json-serializer": "^0.5.8",
17
17
  "@brillout/picocolors": "^1.0.10",
18
18
  "@brillout/require-shim": "^0.1.2",
19
- "@brillout/vite-plugin-server-entry": "^0.4.4",
19
+ "@brillout/vite-plugin-server-entry": "^0.4.5",
20
20
  "acorn": "^8.0.0",
21
21
  "cac": "^6.0.0",
22
22
  "es-module-lexer": "^1.0.0",