vike 0.4.266 → 0.4.267

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 (29) hide show
  1. package/dist/client/runtime-client-routing/history.d.ts +19 -19
  2. package/dist/client/runtime-client-routing/history.js +89 -83
  3. package/dist/client/runtime-client-routing/renderPageClient.js +1 -6
  4. package/dist/client/runtime-client-routing/setScrollPosition.js +6 -5
  5. package/dist/node/prerender/runPrerender.js +11 -0
  6. package/dist/node/vite/assertEnvVite.js +1 -1
  7. package/dist/node/vite/plugins/build/handleAssetsManifest.js +2 -1
  8. package/dist/node/vite/plugins/pluginDev/logSkillHint.js +6 -4
  9. package/dist/node/vite/plugins/pluginUniversalDeploy.js +3 -2
  10. package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFiles.d.ts +2 -2
  11. package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFiles.js +3 -3
  12. package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.d.ts +4 -4
  13. package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.js +9 -9
  14. package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +4 -0
  15. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +3 -1
  16. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +18 -46
  17. package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.d.ts +3 -3
  18. package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +333 -212
  19. package/dist/node/vite/shared/resolveVikeConfigInternal.js +15 -15
  20. package/dist/types/Config.d.ts +8 -0
  21. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  22. package/dist/utils/PROJECT_VERSION.js +1 -1
  23. package/dist/utils/assertNodeVersion.d.ts +2 -0
  24. package/dist/utils/assertNodeVersion.js +4 -1
  25. package/dist/utils/debug.d.ts +1 -1
  26. package/dist/utils/debug.js +1 -1
  27. package/dist/utils/requireResolve.d.ts +0 -6
  28. package/dist/utils/requireResolve.js +0 -8
  29. package/package.json +5 -6
@@ -1,6 +1,7 @@
1
1
  export { transformPointerImports };
2
2
  export { parsePointerImportData };
3
3
  export { assertPointerImportPath };
4
+ export { pointerImportAttributeSuffix };
4
5
  // Playground: https://github.com/brillout/acorn-playground
5
6
  // Notes about `with { type: 'pointer' }`
6
7
  // - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
@@ -10,24 +11,23 @@ export { assertPointerImportPath };
10
11
  // - Isn't stage 4 yet: https://github.com/tc39/proposal-import-attributes
11
12
  // - Using a import path suffix such as `import { Layout } from './Layout?real` breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
12
13
  // - Node.js >=21 supports import attributes: https://nodejs.org/api/esm.html#import-attributes
13
- // - Esbuid supports
14
- // - Blocker: https://github.com/evanw/esbuild/issues/3646
15
- // - Ugly hack to make it work: https://github.com/brillout/esbuild-playground/tree/experiment/import-attribute
16
- // - Discussion with esbuild maintainer: https://github.com/evanw/esbuild/issues/3384
14
+ // - Rolldown doesn't pass import attributes to plugins => we parse import attributes ourselves and mark the import path with pointerImportAttributeSuffix, see transpileFile()
17
15
  // - Using a magic comment `// @vike-real-import` is probably a bad idea:
18
- // - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
16
+ // - Bundlers usually remove comments, e.g. esbuild: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
19
17
  // - Using source maps to track these magic comments is brittle (source maps can easily break)
20
18
  import { parseSync } from '@babel/core';
21
- import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
19
+ import { assert, assertUsage } from '../../../../utils/assert.js';
22
20
  import { isFilePathAbsolute } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
23
21
  import { isImportPath } from '../../../../utils/isImportPath.js';
24
- import { styleFileRE } from '../../../../utils/styleFileRE.js';
25
22
  import pc from '@brillout/picocolors';
26
23
  import { parseImportString, isImportString, serializeImportString } from '../importString.js';
27
24
  import '../../assertEnvVite.js';
28
- function transformPointerImports(code, filePathToShowToUser2, pointerImports,
29
- // For ./transformPointerImports.spec.ts
30
- skipWarnings) {
25
+ // Appended to the import path of imports with the import attribute `with { type: 'vike:pointer' }`, see transpileFile()
26
+ const pointerImportAttributeSuffix = '?vike:pointer';
27
+ function removePointerImportAttributeSuffix(str) {
28
+ return str.split(pointerImportAttributeSuffix).join('');
29
+ }
30
+ function transformPointerImports(code, pointerImports) {
31
31
  const spliceOperations = [];
32
32
  // Collect all const declarations to prepend at the top, so that they are
33
33
  // available before any code runs (import declarations are hoisted but const
@@ -53,34 +53,8 @@ skipWarnings) {
53
53
  }
54
54
  const { start, end } = node;
55
55
  const importStatementCode = code.slice(start, end);
56
- /* Pointer import without importing any value => doesn't make sense and doesn't have any effect.
57
- ```js
58
- // Useless
59
- import './some.css'
60
- // Useless
61
- import './Layout.jsx'
62
- ``` */
63
- if (node.specifiers.length === 0) {
64
- const isWarning = !styleFileRE.test(importPath);
65
- let quote = indent(importStatementCode);
66
- if (isWarning) {
67
- quote = pc.cyan(quote);
68
- }
69
- else {
70
- quote = pc.bold(pc.red(quote));
71
- }
72
- const errMsg = [
73
- `The following import in ${filePathToShowToUser2} has no effect:`,
74
- quote,
75
- 'See https://vike.dev/config#pointer-imports',
76
- ].join('\n');
77
- if (!skipWarnings) {
78
- if (!isWarning) {
79
- assertUsage(false, errMsg);
80
- }
81
- assertWarning(false, errMsg, { onlyOnce: true });
82
- }
83
- }
56
+ // Pointer import without importing any value, e.g. `import './some.css'` => we remove it (it doesn't have any effect).
57
+ // - Rolldown transforms unused imports `import { unused } from './some.js'` into `import './some.js'`
84
58
  let constDeclaration = '';
85
59
  node.specifiers.forEach((specifier) => {
86
60
  assert(specifier.type === 'ImportSpecifier' ||
@@ -99,7 +73,11 @@ skipWarnings) {
99
73
  }
100
74
  return importLocalName;
101
75
  })();
102
- const importString = serializePointerImportData({ importPath, exportName, importStringWasGenerated: true });
76
+ const importString = serializePointerImportData({
77
+ importPath: removePointerImportAttributeSuffix(importPath),
78
+ exportName,
79
+ importStringWasGenerated: true,
80
+ });
103
81
  constDeclaration += `const ${importLocalName} = '${importString}';`;
104
82
  });
105
83
  if (constDeclaration)
@@ -162,7 +140,7 @@ function parsePointerImportData(importString) {
162
140
  // `importPath` is one of the following:
163
141
  // - A relative import path
164
142
  // - An npm package import
165
- // - A filesystem absolute path, see transpileWithEsbuild()
143
+ // - A filesystem absolute path, see transpileFile()
166
144
  function assertPointerImportPath(importPath) {
167
145
  return isImportPath(importPath) || isFilePathAbsolute(importPath);
168
146
  }
@@ -189,9 +167,3 @@ function spliceMany(str, operations) {
189
167
  strMod += str.slice(endPrev, str.length);
190
168
  return strMod;
191
169
  }
192
- function indent(str) {
193
- return str
194
- .split('\n')
195
- .map((s) => ` ${s}`)
196
- .join('\n');
197
- }
@@ -2,18 +2,18 @@ export { transpileAndExecuteFile };
2
2
  export { getConfigBuildErrorFormatted };
3
3
  export { getConfigExecutionErrorIntroMsg };
4
4
  export { isTemporaryBuildFile };
5
- export type { EsbuildCache };
5
+ export type { VikeTranspileCache };
6
6
  import type { FilePathResolved } from '../../../../types/FilePath.js';
7
7
  import '../../assertEnvVite.js';
8
8
  type FileExports = {
9
9
  fileExports: Record<string, unknown>;
10
10
  };
11
- type EsbuildCache = {
11
+ type VikeTranspileCache = {
12
12
  transpileCache: Record<string, // filePathAbsoluteFilesystem
13
13
  Promise<FileExports>>;
14
14
  vikeConfigDependencies: Set<string>;
15
15
  };
16
- declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isExtensionConfig: boolean, esbuildCache: EsbuildCache): Promise<FileExports>;
16
+ declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isExtensionConfig: boolean, vikeTranspileCache: VikeTranspileCache): Promise<FileExports>;
17
17
  declare function getConfigBuildErrorFormatted(err: unknown): `Failed to transpile ${string} because:
18
18
  ${string}` | null;
19
19
  declare function getConfigExecutionErrorIntroMsg(err: unknown): `Failed to execute ${string} because:` | null;