vike 0.4.253-commit-aa63f56 → 0.4.253-commit-332f31b

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.
@@ -36,6 +36,7 @@ import { pluginModuleBanner } from './plugins/build/pluginModuleBanner.js';
36
36
  import { pluginReplaceConstantsNonRunnableDev } from './plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js';
37
37
  import { isVikeCliOrApi } from '../../shared-server-node/api-context.js';
38
38
  import { pluginViteConfigVikeExtensions } from './plugins/pluginViteConfigVikeExtensions.js';
39
+ import { pluginStripPointerImportAttribute } from './plugins/pluginStripPointerImportAttribute.js';
39
40
  import { getVikeConfigInternalEarly, isOnlyResolvingUserConfig } from '../api/resolveViteConfigFromUser.js';
40
41
  import './assertEnvVite.js';
41
42
  // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
@@ -67,6 +68,7 @@ function plugin(vikeVitePluginOptions = {}) {
67
68
  ...pluginReplaceConstantsGlobalThis(),
68
69
  ...pluginStaticReplace(vikeConfig),
69
70
  ...pluginNonRunnabeDev(),
71
+ ...pluginStripPointerImportAttribute(),
70
72
  ...(await pluginViteConfigVikeExtensions(vikeConfig)),
71
73
  ];
72
74
  Object.assign(plugin, pluginAddendum);
@@ -181,7 +181,7 @@ async function getPageDeps(config, pageConfigs) {
181
181
  };
182
182
  const sourcesRelevant = getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig);
183
183
  sourcesRelevant.forEach((configValueSource) => {
184
- if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
184
+ if (!configValueSource.valueLoadedViaImport && !configValueSource.valueIsFilePath)
185
185
  return;
186
186
  const { definedAt } = configValueSource;
187
187
  if (definedAt.definedBy)
@@ -0,0 +1,4 @@
1
+ export { pluginStripPointerImportAttribute };
2
+ import type { Plugin } from 'vite';
3
+ import '../assertEnvVite.js';
4
+ declare function pluginStripPointerImportAttribute(): Plugin[];
@@ -0,0 +1,31 @@
1
+ export { pluginStripPointerImportAttribute };
2
+ import { getMagicString } from '../shared/getMagicString.js';
3
+ import '../assertEnvVite.js';
4
+ // Match `with { type: 'vike-pointer' }` (with optional whitespace variations)
5
+ const runtimeAttrRE = /\bwith\s*\{\s*type\s*:\s*['"]vike-pointer['"]\s*\}/g;
6
+ function pluginStripPointerImportAttribute() {
7
+ return [
8
+ {
9
+ name: 'vike:pluginStripPointerImportAttribute',
10
+ transform: {
11
+ filter: {
12
+ code: {
13
+ include: 'vike-pointer',
14
+ },
15
+ },
16
+ handler(code, id) {
17
+ runtimeAttrRE.lastIndex = 0;
18
+ if (!runtimeAttrRE.test(code))
19
+ return;
20
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
21
+ runtimeAttrRE.lastIndex = 0;
22
+ let match;
23
+ while ((match = runtimeAttrRE.exec(code)) !== null) {
24
+ magicString.remove(match.index, match.index + match[0].length);
25
+ }
26
+ return getMagicStringResult();
27
+ },
28
+ },
29
+ },
30
+ ];
31
+ }
@@ -1,2 +1,2 @@
1
1
  import '../../../assertEnvVite.js';
2
- export declare const ignorePatternsBuiltIn: readonly ["**/node_modules/**", "**/ejected/**", "**/*.telefunc.*", "**/.history/**", "**/*.generated.*"];
2
+ export declare const ignorePatternsBuiltIn: readonly ["**/node_modules/**", "**/ejected/**", "**/*.telefunc.*", "**/.history/**", "**/*.generated.*", "**/*.spec.*", "**/*.test.*"];
@@ -13,4 +13,7 @@ export const ignorePatternsBuiltIn = [
13
13
  '**/.history/**',
14
14
  // https://github.com/vikejs/vike/discussions/2222
15
15
  '**/*.generated.*',
16
+ // https://github.com/vikejs/vike/issues/2347
17
+ '**/*.spec.*',
18
+ '**/*.test.*',
16
19
  ];
@@ -14,6 +14,7 @@ type PlusFileCommon = {
14
14
  };
15
15
  /** +config.js */
16
16
  type PlusFileConfig = PlusFileCommon & {
17
+ /** Whether file is `+config.js` or `+{configName}.js` */
17
18
  isConfigFile: true;
18
19
  fileExportsByConfigName: Record<string, // configName
19
20
  unknown>;
@@ -25,6 +26,7 @@ type PlusFileConfig = PlusFileCommon & {
25
26
  };
26
27
  /** +{configName}.js */
27
28
  type PlusFileValue = PlusFileCommon & {
29
+ /** Whether file is `+config.js` or `+{configName}.js` */
28
30
  isConfigFile: false;
29
31
  configName: string;
30
32
  } & ({
@@ -15,7 +15,7 @@ import { genPromise } from '../../../../utils/genPromise.js';
15
15
  import { assertFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
16
16
  import { isImportPathRelative } from '../../../../utils/isImportPath.js';
17
17
  import { isObject } from '../../../../utils/isObject.js';
18
- import { isPlainScriptFile, isScriptFile } from '../../../../utils/isScriptFile.js';
18
+ import { isPlainScriptFile } from '../../../../utils/isScriptFile.js';
19
19
  import { isVitest } from '../../../../utils/isVitest.js';
20
20
  import { assertIsImportPathNpmPackage, isImportPathNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
21
21
  import { assertPosixPath, toPosixPath } from '../../../../utils/path.js';
@@ -182,19 +182,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
182
182
  // - assertIsImportPathNpmPackage()
183
183
  // - isImportPathNpmPackage(str, { cannotBePathAlias: true })
184
184
  assertFilePathAbsoluteFilesystem(importPathResolved);
185
- // Non-script file (e.g. .svg, .css) => resolve to constant string so that files with
186
- // `env: { config: true, client: true }` can also be loaded in Node.js
187
- if (!isScriptFile(importPathResolved)) {
188
- esbuildCache.vikeConfigDependencies.add(importPathResolved);
189
- return {
190
- path: importPathResolved,
191
- namespace: 'vike-static-file',
192
- };
193
- }
194
185
  // Should be remove this? See comment below.
195
186
  const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
196
187
  const isPointerImport = transformImports === 'all' ||
197
- // .jsx, .tsx, .vue, .svelte, ... => template/JSX files => pointer import
188
+ // .jsx, .vue, .svg, ... => obviously not config code => pointer import
198
189
  !isPlainScriptFile(importPathResolved) ||
199
190
  // Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a config has been set by the user or by a Vike extension).
200
191
  // - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
@@ -202,8 +193,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
202
193
  // - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
203
194
  // - In practice, it seems like it requires some (non-trivial?) refactoring.
204
195
  isVikeExtensionImport ||
205
- // Explicitly tagged as runtime code => pointer import
206
- args.with?.['type'] === 'runtime';
196
+ args.with?.['type'] === 'vike-pointer';
207
197
  assertPosixPath(importPathResolved);
208
198
  // `isNpmPkgImport` => `importPathOriginal` is most likely an npm package import, but it can also be a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir`.
209
199
  const isNpmPkgImport = (() => {
@@ -272,12 +262,6 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
272
262
  pointerImports[importPathTranspiled] = isPointerImport;
273
263
  return { external: true, path: importPathTranspiled };
274
264
  });
275
- build.onLoad({ filter: /.*/, namespace: 'vike-static-file' }, (args) => {
276
- return {
277
- contents: `export default 'STATIC_FILE_NOT_AVAILABLE:${args.path}'`,
278
- loader: 'js',
279
- };
280
- });
281
265
  },
282
266
  },
283
267
  // Track dependencies
@@ -513,7 +513,7 @@ function getSourceNonConfigFile(configName, value, definedAt) {
513
513
  definedAt,
514
514
  locationId: '/',
515
515
  plusFile: null,
516
- valueIsLoadedWithImport: false,
516
+ valueLoadedViaImport: false,
517
517
  valueIsDefinedByPlusValueFile: false,
518
518
  };
519
519
  return source;
@@ -667,7 +667,7 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
667
667
  value: valueFilePath,
668
668
  valueIsFilePath: true,
669
669
  configEnv: configDef.env,
670
- valueIsLoadedWithImport: false,
670
+ valueLoadedViaImport: false,
671
671
  valueIsDefinedByPlusValueFile: false,
672
672
  definedAt: definedAtFilePath,
673
673
  };
@@ -692,7 +692,7 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
692
692
  ...configValueSourceCommon,
693
693
  ...value,
694
694
  configEnv: resolveConfigEnv(configDef.env, pointerImport.fileExportPath),
695
- valueIsLoadedWithImport: true,
695
+ valueLoadedViaImport: true,
696
696
  valueIsDefinedByPlusValueFile: false,
697
697
  definedAt: pointerImport.fileExportPath,
698
698
  };
@@ -705,7 +705,7 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
705
705
  valueIsLoaded: true,
706
706
  value: confVal.value,
707
707
  configEnv: configDef.env,
708
- valueIsLoadedWithImport: false,
708
+ valueLoadedViaImport: false,
709
709
  valueIsDefinedByPlusValueFile: false,
710
710
  definedAt: definedAtFilePath_,
711
711
  };
@@ -719,7 +719,14 @@ function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
719
719
  ...configValueSourceCommon,
720
720
  ...confVal,
721
721
  configEnv: configEnvResolved,
722
- valueIsLoadedWithImport: !confVal.valueIsLoaded || !isJsonValue(confVal.value),
722
+ valueLoadedViaImport:
723
+ // If +{configName}.js is (also) runtime code => always load it via import (not strictly required, but seems to be a good default)
724
+ !!configEnvResolved.client ||
725
+ !!configEnvResolved.server ||
726
+ // No choice: value isn't loaded at config-time
727
+ !confVal.valueIsLoaded ||
728
+ // No choice: value isn't serializable
729
+ !isJsonValue(confVal.value),
723
730
  valueIsDefinedByPlusValueFile: true,
724
731
  definedAt: {
725
732
  ...plusFile.filePath,
@@ -903,7 +910,7 @@ function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSource
903
910
  plusFile: sourceEffect.plusFile,
904
911
  locationId: sourceEffect.locationId,
905
912
  configEnv: configDef.env,
906
- valueIsLoadedWithImport: false,
913
+ valueLoadedViaImport: false,
907
914
  valueIsDefinedByPlusValueFile: false,
908
915
  valueIsLoaded: true,
909
916
  value: configValue,
@@ -16,7 +16,18 @@ async function loadAndParseVirtualFilePageEntry(pageConfig, isDev) {
16
16
  // Catch @cloudflare/vite-plugin bug
17
17
  assertVirtualFileExports(moduleExports, () => 'configValuesSerialized' in moduleExports, moduleId);
18
18
  const virtualFileExportsPageEntry = moduleExports;
19
- const configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
19
+ let configValues;
20
+ try {
21
+ configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
22
+ }
23
+ catch (e) {
24
+ if (!(e instanceof ReferenceError))
25
+ throw e;
26
+ // Safari WebKit bug: dynamic import() may resolve before the module body executes,
27
+ // https://github.com/vikejs/vike/issues/3121
28
+ await new Promise((resolve) => setTimeout(resolve));
29
+ configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
30
+ }
20
31
  Object.assign(pageConfig.configValues, configValues);
21
32
  objectAssign(pageConfig, { isPageEntryLoaded: true });
22
33
  return pageConfig;
@@ -52,7 +52,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, runtimeEn
52
52
  }
53
53
  function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
54
54
  let valueData;
55
- if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
55
+ if (configValueSource.valueIsLoaded && !configValueSource.valueLoadedViaImport) {
56
56
  valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAt, importStatements, filesEnv, configValueSource.configEnv);
57
57
  }
58
58
  else {
@@ -98,7 +98,7 @@ type ConfigValueSource = {
98
98
  plusFile: PlusFile | null;
99
99
  locationId: LocationId;
100
100
  /** Whether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
101
- valueIsLoadedWithImport: boolean;
101
+ valueLoadedViaImport: boolean;
102
102
  /** Whether the config value is a file path, this is currently only true for +client */
103
103
  valueIsFilePath?: true;
104
104
  /** Whether the config value is defined by a +{configName}.js file */
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.253-commit-aa63f56";
1
+ export declare const PROJECT_VERSION: "0.4.253-commit-332f31b";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.253-commit-aa63f56';
2
+ export const PROJECT_VERSION = '0.4.253-commit-332f31b';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.253-commit-aa63f56",
3
+ "version": "0.4.253-commit-332f31b",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {