vike 0.4.146-commit-701e2e5 → 0.4.147-commit-2fa53b2

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 (80) hide show
  1. package/dist/cjs/node/plugin/index.js +6 -4
  2. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +76 -0
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +61 -40
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +104 -0
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +62 -75
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +12 -70
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
  10. package/dist/cjs/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +3 -3
  11. package/dist/cjs/node/plugin/utils.js +2 -0
  12. package/dist/cjs/node/prerender/runPrerender.js +75 -67
  13. package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
  14. package/dist/cjs/node/runtime/index-common.js +3 -1
  15. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
  16. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
  17. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +3 -3
  18. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
  19. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  20. package/dist/cjs/node/runtime/renderPage.js +8 -5
  21. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
  22. package/dist/cjs/shared/page-configs/loadConfigValues.js +12 -3
  23. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +19 -0
  24. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -12
  25. package/dist/cjs/utils/assertKeys.js +28 -0
  26. package/dist/cjs/utils/joinEnglish.js +3 -3
  27. package/dist/cjs/utils/parseUrl.js +24 -16
  28. package/dist/cjs/utils/projectInfo.js +3 -2
  29. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +25 -11
  30. package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
  31. package/dist/esm/client/client-routing-runtime/index.js +1 -0
  32. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +2 -2
  33. package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
  34. package/dist/esm/node/plugin/index.d.ts +1 -0
  35. package/dist/esm/node/plugin/index.js +1 -0
  36. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
  37. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +5 -0
  38. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +70 -0
  39. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +58 -37
  40. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +5 -0
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +98 -0
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +63 -76
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +0 -3
  45. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -68
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
  47. package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +5 -0
  48. package/dist/esm/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +2 -2
  49. package/dist/esm/node/plugin/utils.d.ts +2 -0
  50. package/dist/esm/node/plugin/utils.js +2 -0
  51. package/dist/esm/node/prerender/runPrerender.js +75 -67
  52. package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
  53. package/dist/esm/node/runtime/index-common.d.ts +1 -0
  54. package/dist/esm/node/runtime/index-common.js +1 -0
  55. package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
  56. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.d.ts +1 -1
  57. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
  58. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +1 -1
  59. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +3 -3
  60. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
  61. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  62. package/dist/esm/node/runtime/renderPage.js +9 -6
  63. package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
  64. package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -4
  65. package/dist/esm/shared/page-configs/loadConfigValues.js +12 -3
  66. package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +4 -0
  67. package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +16 -0
  68. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +4 -13
  69. package/dist/esm/utils/assertKeys.d.ts +4 -0
  70. package/dist/esm/utils/assertKeys.js +22 -0
  71. package/dist/esm/utils/joinEnglish.d.ts +1 -1
  72. package/dist/esm/utils/joinEnglish.js +3 -3
  73. package/dist/esm/utils/parseUrl.js +24 -16
  74. package/dist/esm/utils/projectInfo.d.ts +3 -1
  75. package/dist/esm/utils/projectInfo.js +2 -1
  76. package/package.json +3 -3
  77. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -28
  78. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +0 -5
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -25
  80. package/dist/esm/node/plugin/shared/getConfigValueSourcesRelevant.d.ts +0 -5
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ssr = exports.plugin = void 0;
6
+ exports.version = exports.ssr = exports.plugin = void 0;
7
7
  exports.default = plugin;
8
- const utils_js_1 = require("./utils.js");
8
+ var utils_js_1 = require("./utils.js");
9
+ Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
10
+ const utils_js_2 = require("./utils.js");
9
11
  const buildConfig_js_1 = require("./plugins/buildConfig.js");
10
12
  const previewConfig_js_1 = require("./plugins/previewConfig.js");
11
13
  const autoFullBuild_js_1 = require("./plugins/autoFullBuild.js");
@@ -26,7 +28,7 @@ const extensionsAssets_js_1 = require("./plugins/extensionsAssets.js");
26
28
  const baseUrls_js_1 = require("./plugins/baseUrls.js");
27
29
  const envVars_js_1 = require("./plugins/envVars.js");
28
30
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
29
- (0, utils_js_1.markEnvAsVite)();
31
+ (0, utils_js_2.markEnvAsVite)();
30
32
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
31
33
  function plugin(vikeConfig) {
32
34
  const plugins = [
@@ -65,6 +67,6 @@ catch { }
65
67
  Object.defineProperty(plugin, 'apply', {
66
68
  enumerable: true,
67
69
  get: () => {
68
- (0, utils_js_1.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
70
+ (0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
69
71
  }
70
72
  });
@@ -4,7 +4,7 @@ exports.determineOptimizeDeps = void 0;
4
4
  const findPageFiles_js_1 = require("../../shared/findPageFiles.js");
5
5
  const utils_js_1 = require("../../utils.js");
6
6
  const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
7
- const getConfigValueSourcesRelevant_js_1 = require("../../shared/getConfigValueSourcesRelevant.js");
7
+ const getConfigValueSourcesNotOverriden_js_1 = require("../../shared/getConfigValueSourcesNotOverriden.js");
8
8
  const buildConfig_js_1 = require("../buildConfig.js");
9
9
  const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
10
10
  async function determineOptimizeDeps(config, configVike, isDev) {
@@ -33,12 +33,11 @@ async function getPageDeps(config, pageConfigs, isDev) {
33
33
  // V1 design
34
34
  {
35
35
  pageConfigs.forEach((pageConfig) => {
36
- const configValueSourcesRelevant = (0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(pageConfig);
37
- configValueSourcesRelevant.forEach((configValueSource) => {
36
+ (0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
38
37
  if (!configValueSource.valueIsImportedAtRuntime)
39
38
  return;
40
39
  const { definedAt, configEnv } = configValueSource;
41
- if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
40
+ if (!configEnv.client)
42
41
  return;
43
42
  if (definedAt.filePathRelativeToUserRootDir !== null) {
44
43
  const { filePathAbsoluteFilesystem } = definedAt;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assertConfigValueIsSerializable = exports.getConfigValuesSerialized = void 0;
7
+ const utils_js_1 = require("../../../utils.js");
8
+ const stringify_1 = require("@brillout/json-serializer/stringify");
9
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
+ const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
11
+ const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
12
+ const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
13
+ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
14
+ const lines = [];
15
+ Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
16
+ const { value, configEnv } = configValuesComputed;
17
+ if (!isEnvMatch(configEnv))
18
+ return;
19
+ // configValeSources has higher precedence
20
+ if (pageConfig.configValueSources[configName])
21
+ return;
22
+ const configValue = pageConfig.configValues[configName];
23
+ (0, utils_js_1.assert)(configValue);
24
+ const { definedAt } = configValue;
25
+ const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
26
+ (0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
27
+ });
28
+ (0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
29
+ const { configName, configEnv } = configValueSource;
30
+ const configValue = pageConfig.configValues[configName];
31
+ if (!configValue)
32
+ return;
33
+ if (!isEnvMatch(configEnv, configValueSource)) {
34
+ return;
35
+ }
36
+ const { value, definedAt } = configValue;
37
+ const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
38
+ (0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
39
+ });
40
+ const code = lines.join('\n');
41
+ return code;
42
+ }
43
+ exports.getConfigValuesSerialized = getConfigValuesSerialized;
44
+ function assertConfigValueIsSerializable(value, configName, definedAt) {
45
+ // Contains asserts
46
+ getConfigValueSerialized(value, configName, definedAt);
47
+ }
48
+ exports.assertConfigValueIsSerializable = assertConfigValueIsSerializable;
49
+ function getConfigValueSerialized(value, configName, definedAt) {
50
+ const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
51
+ let configValueSerialized;
52
+ try {
53
+ configValueSerialized = (0, stringify_1.stringify)(value, { valueName, forbidReactElements: true });
54
+ }
55
+ catch (err) {
56
+ let serializationErrMsg = '';
57
+ if ((0, stringify_1.isJsonSerializerError)(err)) {
58
+ serializationErrMsg = err.messageCore;
59
+ }
60
+ else {
61
+ // When a property getter throws an error
62
+ console.error('Serialization error:');
63
+ console.error(err);
64
+ serializationErrMsg = 'see serialization error printed above';
65
+ }
66
+ const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)({ definedAt });
67
+ (0, utils_js_1.assert)(configValueFilePathToShowToUser);
68
+ (0, utils_js_1.assertUsage)(false, [
69
+ `The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
70
+ `its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
71
+ `Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
72
+ ].join(' '));
73
+ }
74
+ configValueSerialized = JSON.stringify(configValueSerialized);
75
+ return configValueSerialized;
76
+ }
@@ -1,101 +1,122 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configDefinitionsBuiltInGlobal = exports.configDefinitionsBuiltIn = void 0;
4
- const helpers_js_1 = require("../helpers.js");
4
+ const utils_js_1 = require("../../../../utils.js");
5
5
  const configDefinitionsBuiltIn = {
6
6
  onRenderHtml: {
7
- env: 'server-only'
7
+ env: { server: true }
8
8
  },
9
9
  onRenderClient: {
10
- env: 'client-only'
10
+ env: { client: true }
11
11
  },
12
12
  onHydrationEnd: {
13
- env: 'client-only'
13
+ env: { client: true }
14
14
  },
15
15
  onPageTransitionStart: {
16
- env: 'client-only'
16
+ env: { client: true }
17
17
  },
18
18
  onPageTransitionEnd: {
19
- env: 'client-only'
19
+ env: { client: true }
20
20
  },
21
21
  onBeforeRender: {
22
- env: 'server-only'
22
+ env: { server: true }
23
23
  },
24
24
  onBeforePrerenderStart: {
25
- env: 'server-only'
25
+ env: { server: true }
26
26
  },
27
27
  Page: {
28
- env: 'server-and-client'
28
+ env: { server: true, client: true }
29
29
  },
30
30
  passToClient: {
31
- env: 'server-only',
31
+ env: { server: true, config: true },
32
32
  cumulative: true
33
33
  },
34
34
  route: {
35
- env: '_routing-eager'
35
+ env: { server: true, client: 'if-client-routing', eager: true }
36
36
  },
37
37
  guard: {
38
- env: '_routing-lazy'
38
+ env: { server: true, client: 'if-client-routing' }
39
39
  },
40
40
  iKnowThePerformanceRisksOfAsyncRouteFunctions: {
41
- env: '_routing-eager'
41
+ env: { server: true, client: 'if-client-routing', eager: true }
42
42
  },
43
43
  filesystemRoutingRoot: {
44
- env: 'config-only'
44
+ env: { config: true }
45
45
  },
46
46
  client: {
47
47
  // The value of the client config is merely the file path to the client entry file, which is only needed on the sever-side
48
- env: 'server-only',
48
+ env: { server: true },
49
49
  _valueIsFilePath: true
50
50
  },
51
51
  clientRouting: {
52
- // We could make it 'server-only' (we don't yet because of some legacy V0.4 design code)
53
- env: 'server-and-client'
52
+ // We could make it { client: false } but we don't yet because of some legacy V0.4 design code
53
+ env: { server: true, client: true, config: true, eager: true }
54
54
  },
55
55
  prerender: {
56
- env: 'config-only'
56
+ env: { config: true }
57
57
  },
58
58
  hydrationCanBeAborted: {
59
- env: 'client-only'
59
+ env: { client: true }
60
60
  },
61
61
  prefetchStaticAssets: {
62
- env: 'client-only'
62
+ env: { client: true }
63
63
  },
64
64
  extends: {
65
- env: 'config-only'
65
+ env: { config: true }
66
66
  },
67
67
  meta: {
68
- env: 'config-only'
68
+ env: { config: true }
69
69
  },
70
70
  isClientSideRenderable: {
71
- env: 'server-and-client',
72
- _computed: (configValueSources) => (0, helpers_js_1.isConfigSet)(configValueSources, 'onRenderClient') &&
73
- (0, helpers_js_1.isConfigSet)(configValueSources, 'Page') &&
74
- (0, helpers_js_1.getConfigEnv)(configValueSources, 'Page') !== 'server-only'
71
+ env: { server: true, client: true, eager: true },
72
+ _computed: (configValueSources) => isConfigSet(configValueSources, 'onRenderClient') &&
73
+ isConfigSet(configValueSources, 'Page') &&
74
+ !!getConfigEnv(configValueSources, 'Page')?.client
75
75
  },
76
76
  onBeforeRenderEnv: {
77
- env: 'client-only',
78
- _computed: (configValueSources) => !(0, helpers_js_1.isConfigSet)(configValueSources, 'onBeforeRender') ? null : (0, helpers_js_1.getConfigEnv)(configValueSources, 'onBeforeRender')
77
+ env: { client: true },
78
+ _computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
79
79
  }
80
80
  };
81
81
  exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
82
82
  const configDefinitionsBuiltInGlobal = {
83
83
  onPrerenderStart: {
84
- env: 'server-only'
84
+ env: { server: true }
85
85
  },
86
86
  onBeforeRoute: {
87
- env: '_routing-eager'
87
+ env: { server: true, client: 'if-client-routing', eager: true }
88
88
  },
89
89
  prerender: {
90
- env: 'config-only'
91
- },
92
- extensions: { env: 'config-only' },
93
- disableAutoFullBuild: { env: 'config-only' },
94
- includeAssetsImportedByServer: { env: 'config-only' },
95
- baseAssets: { env: 'config-only' },
96
- baseServer: { env: 'config-only' },
97
- redirects: { env: 'server-only' },
98
- trailingSlash: { env: 'server-only' },
99
- disableUrlNormalization: { env: 'server-only' }
90
+ env: { config: true }
91
+ },
92
+ extensions: { env: { config: true } },
93
+ disableAutoFullBuild: { env: { config: true } },
94
+ includeAssetsImportedByServer: { env: { config: true } },
95
+ baseAssets: { env: { config: true } },
96
+ baseServer: { env: { config: true } },
97
+ redirects: { env: { server: true } },
98
+ trailingSlash: { env: { server: true } },
99
+ disableUrlNormalization: { env: { server: true } }
100
100
  };
101
101
  exports.configDefinitionsBuiltInGlobal = configDefinitionsBuiltInGlobal;
102
+ function getConfigEnv(configValueSources, configName) {
103
+ const configValueSource = getConfigValueSource(configValueSources, configName);
104
+ if (!configValueSource)
105
+ return null;
106
+ return configValueSource.configEnv;
107
+ }
108
+ function isConfigSet(configValueSources, configName) {
109
+ const configValueSource = getConfigValueSource(configValueSources, configName);
110
+ // Enable users to suppress global config values by overriding the config's value to null
111
+ if (configValueSource?.value === null)
112
+ return false;
113
+ return !!configValueSource;
114
+ }
115
+ function getConfigValueSource(configValueSources, configName) {
116
+ const sources = configValueSources[configName];
117
+ if (!sources)
118
+ return null;
119
+ const configValueSource = sources[0];
120
+ (0, utils_js_1.assert)(configValueSource);
121
+ return configValueSource;
122
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.crawlPlusFiles = void 0;
7
+ const utils_js_1 = require("../../../../utils.js");
8
+ const path_1 = __importDefault(require("path"));
9
+ const fast_glob_1 = __importDefault(require("fast-glob"));
10
+ const child_process_1 = require("child_process");
11
+ const util_1 = require("util");
12
+ const execA = (0, util_1.promisify)(child_process_1.exec);
13
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
14
+ (0, utils_js_1.assertPosixPath)(userRootDir);
15
+ (0, utils_js_1.assertPosixPath)(outDirAbsoluteFilesystem);
16
+ (0, utils_js_1.assert)(outDirAbsoluteFilesystem.startsWith(userRootDir));
17
+ const outDir = path_1.default.posix.relative(userRootDir, outDirAbsoluteFilesystem);
18
+ (0, utils_js_1.assert)(!outDir.startsWith('.'));
19
+ const timeBase = new Date().getTime();
20
+ let files = [];
21
+ const res = await gitLsFiles(userRootDir, outDir);
22
+ if (res &&
23
+ // Fallback to fast-glob for users that dynamically generate plus files (we assume generetad plus files to be skipped because they are usually included in .gitignore)
24
+ res.length > 0) {
25
+ files = res;
26
+ }
27
+ else {
28
+ files = await fastGlob(userRootDir, outDir);
29
+ }
30
+ {
31
+ const time = new Date().getTime() - timeBase;
32
+ if (isDev) {
33
+ // We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
34
+ (0, utils_js_1.assertWarning)(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on Vike's GitHub.`, {
35
+ onlyOnce: 'slow-page-files-search'
36
+ });
37
+ }
38
+ }
39
+ const plusFiles = files.map((p) => {
40
+ p = (0, utils_js_1.toPosixPath)(p);
41
+ (0, utils_js_1.assert)(!p.startsWith(userRootDir));
42
+ const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
43
+ const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, p);
44
+ return {
45
+ filePathRelativeToUserRootDir,
46
+ filePathAbsoluteFilesystem
47
+ };
48
+ });
49
+ return plusFiles;
50
+ }
51
+ exports.crawlPlusFiles = crawlPlusFiles;
52
+ // Same as fastGlob() but using `$ git ls-files`
53
+ async function gitLsFiles(userRootDir, outDir) {
54
+ const cmd = [
55
+ 'git ls-files',
56
+ ...utils_js_1.scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
57
+ ...getIgnorePatterns(outDir).map((pattern) => `--exclude="${pattern}"`),
58
+ // --others lists untracked files only (but using .gitignore because --exclude-standard)
59
+ // --cached adds the tracked files to the output
60
+ '--others --cached --exclude-standard'
61
+ ].join(' ');
62
+ let stdout;
63
+ try {
64
+ const res = await execA(cmd, { cwd: userRootDir });
65
+ stdout = res.stdout;
66
+ }
67
+ catch (err) {
68
+ if (err.message.includes('not a git repository'))
69
+ return null;
70
+ throw err;
71
+ }
72
+ let files = stdout.split('\n').filter(Boolean);
73
+ (0, utils_js_1.assert)(!outDir.startsWith('/'));
74
+ files = files.filter(
75
+ // We have to repeat the same exclusion logic here because the `git ls-files` option --exclude only applies to untracked files. (We use --exclude only to speed up the command.)
76
+ (file) => getIgnoreFilter(file, outDir));
77
+ return files;
78
+ }
79
+ // Same as gitLsFiles() but using fast-glob
80
+ async function fastGlob(userRootDir, outDir) {
81
+ const files = await (0, fast_glob_1.default)(`**/+*.${utils_js_1.scriptFileExtensions}`, {
82
+ ignore: getIgnorePatterns(outDir),
83
+ cwd: userRootDir,
84
+ dot: false
85
+ });
86
+ return files;
87
+ }
88
+ // Same as getIgnoreFilter() but as glob pattern
89
+ function getIgnorePatterns(outDir) {
90
+ return [
91
+ '**/node_modules/**',
92
+ `${outDir}/**`,
93
+ // Allow:
94
+ // ```
95
+ // +Page.js
96
+ // +Page.telefunc.js
97
+ // ```
98
+ '**/*.telefunc.*'
99
+ ];
100
+ }
101
+ // Same as getIgnorePatterns() but for Array.filter()
102
+ function getIgnoreFilter(file, outDir) {
103
+ return !file.includes('node_modules/') && !file.includes('.telefunc.') && !file.startsWith(`${outDir}/`);
104
+ }
@@ -7,7 +7,6 @@ exports.isVikeConfigFile = exports.vikeConfigDependencies = exports.reloadVikeCo
7
7
  const utils_js_1 = require("../../../utils.js");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
10
- const fast_glob_1 = __importDefault(require("fast-glob"));
11
10
  const filesystemRouting_js_1 = require("./getVikeConfig/filesystemRouting.js");
12
11
  const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
13
12
  const replaceImportStatements_js_1 = require("./replaceImportStatements.js");
@@ -18,8 +17,9 @@ const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/remove
18
17
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
19
18
  const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
20
19
  const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
21
- const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
22
20
  const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
21
+ const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
22
+ const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
23
23
  (0, utils_js_1.assertIsNotProductionRuntime)();
24
24
  let devServerIsCorrupt = false;
25
25
  let wasConfigInvalid = null;
@@ -75,7 +75,7 @@ async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, exten
75
75
  }
76
76
  exports.getVikeConfig = getVikeConfig;
77
77
  async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
78
- const plusFiles = await findPlusFiles(userRootDir, [outDirRoot], isDev, extensions);
78
+ const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, extensions);
79
79
  const configFiles = [];
80
80
  const valueFiles = [];
81
81
  plusFiles.forEach((f) => {
@@ -156,12 +156,12 @@ async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
156
156
  return fileExports;
157
157
  }
158
158
  function isConfigEnv(configDef, configName) {
159
- if (configDef.cumulative)
160
- return true;
161
- if (configDef.env === 'config-only')
162
- return true;
163
- // TODO: replace with proper `env: { config: boolean }` implementation
164
- return configName === 'clientRouting';
159
+ const configEnv = configDef.env;
160
+ if (configDef.cumulative) {
161
+ // In principle we could lift that requirement (but it requires non-trivial modifications)
162
+ (0, utils_js_1.assertUsage)(configEnv.config, `Config ${picocolors_1.default.cyan(configName)} needs its ${picocolors_1.default.cyan('env')} to have ${picocolors_1.default.cyan('{ config: true }')} (because ${picocolors_1.default.cyan(configName)} is a ${picocolors_1.default.cyan('cumulative')} config)`);
163
+ }
164
+ return !!configEnv.config;
165
165
  }
166
166
  function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
167
167
  const { fileExports, filePath, extendsFilePaths } = configFile;
@@ -514,6 +514,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
514
514
  }
515
515
  else if (interfaceFile.isValueFile) {
516
516
  const valueAlreadyLoaded = 'configValue' in conf;
517
+ (0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnv.config);
517
518
  const configValueSource = {
518
519
  configEnv,
519
520
  valueIsImportedAtRuntime: !valueAlreadyLoaded,
@@ -528,9 +529,6 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
528
529
  if (valueAlreadyLoaded) {
529
530
  configValueSource.value = conf.configValue;
530
531
  }
531
- else {
532
- (0, utils_js_1.assert)(configEnv !== 'config-only');
533
- }
534
532
  return configValueSource;
535
533
  }
536
534
  (0, utils_js_1.assert)(false);
@@ -542,12 +540,12 @@ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
542
540
  }
543
541
  const fileEnv = filesEnv.get(filePathForEnvCheck);
544
542
  fileEnv.push({ configEnv, configName });
545
- const configDifferentEnv = fileEnv.filter((c) => c.configEnv !== configEnv)[0];
543
+ const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnv, configEnv))[0];
546
544
  if (configDifferentEnv) {
547
545
  (0, utils_js_1.assertUsage)(false, [
548
546
  `${filePathForEnvCheck} defines the value of configs living in different environments:`,
549
- ...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(c.configEnv)}`),
550
- 'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file/import-from-same-file'
547
+ ...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(JSON.stringify(c.configEnv))}`),
548
+ 'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
551
549
  ].join('\n'));
552
550
  }
553
551
  }
@@ -683,30 +681,17 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
683
681
  (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}`)} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
684
682
  }
685
683
  // env
684
+ let configEnv;
686
685
  {
687
- const envValues = [
688
- 'client-only',
689
- 'server-only',
690
- 'server-and-client',
691
- 'config-only'
692
- ];
693
- const fix = [
694
- `Set the value of ${picocolors_1.default.cyan(`meta.${configName}.env`)} to `,
695
- (0, utils_js_1.joinEnglish)(envValues.map((s) => picocolors_1.default.cyan(`'${s}'`)), 'or'),
696
- '.'
697
- ].join('');
686
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
698
687
  if (!('env' in def)) {
699
- (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
700
- (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
701
- }
702
- if (!(0, utils_js_1.hasProp)(def, 'env', 'string')) {
703
- (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
704
- (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${fix}`);
705
- }
706
- if (!envValues.includes(def.env)) {
707
- (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
708
- (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an unknown value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${fix}`);
688
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required.`);
709
689
  }
690
+ configEnv = getConfigEnvValue(def.env, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to`);
691
+ // Overwrite deprecated value with valid value
692
+ // TODO/v1-release: remove once support for the deprecated values is removed
693
+ if (typeof def.env === 'string')
694
+ def.env = configEnv;
710
695
  }
711
696
  // effect
712
697
  if ('effect' in def) {
@@ -714,9 +699,9 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
714
699
  (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
715
700
  (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
716
701
  }
717
- if (def.env !== 'config-only') {
702
+ if (!configEnv.config) {
718
703
  (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
719
- (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env is ${picocolors_1.default.cyan('config-only')} (but it's ${picocolors_1.default.cyan(def.env)} instead)`);
704
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env has ${picocolors_1.default.cyan('{ config: true }')} (but it's ${picocolors_1.default.cyan(JSON.stringify(configEnv))} instead)`);
720
705
  }
721
706
  }
722
707
  });
@@ -727,8 +712,8 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
727
712
  return;
728
713
  // The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
729
714
  // (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
730
- (0, utils_js_1.assertUsage)(configDef.env === 'config-only', [
731
- `Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} value of ${picocolors_1.default.cyan('config-only')}.`
715
+ (0, utils_js_1.assertUsage)(configDef.env.config, [
716
+ `Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(JSON.stringify(configDef.env))}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} with ${picocolors_1.default.cyan('{ config: true }')}.`
732
717
  ].join(' '));
733
718
  const source = configValueSources[configName]?.[0];
734
719
  if (!source)
@@ -796,39 +781,9 @@ function getComputed(configValueSources, configDefinitionsRelevant) {
796
781
  });
797
782
  return configValuesComputed;
798
783
  }
799
- async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
800
- const timeBase = new Date().getTime();
801
- (0, utils_js_1.assertPosixPath)(userRootDir);
802
- const ignorePatterns = [];
803
- for (const dir of ignoreDirs) {
804
- (0, utils_js_1.assertPosixPath)(dir);
805
- ignorePatterns.push(`${path_1.default.posix.relative(userRootDir, dir)}/**`);
806
- }
807
- const result = await (0, fast_glob_1.default)(`**/+*.${utils_js_1.scriptFileExtensions}`, {
808
- ignore: [
809
- '**/node_modules/**',
810
- // Allow:
811
- // ```
812
- // +Page.js
813
- // +Page.telefunc.js
814
- // ```
815
- '**/*.telefunc.*',
816
- ...ignorePatterns
817
- ],
818
- cwd: userRootDir,
819
- dot: false
820
- });
821
- const time = new Date().getTime() - timeBase;
822
- if (isDev) {
823
- // We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
824
- (0, utils_js_1.assertWarning)(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on Vike's GitHub.`, {
825
- onlyOnce: 'slow-page-files-search'
826
- });
827
- }
828
- const plusFiles = result.map((p) => {
829
- p = (0, utils_js_1.toPosixPath)(p);
830
- const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
831
- const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, p);
784
+ async function findPlusFiles(userRootDir, outDirRoot, isDev, extensions) {
785
+ const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev);
786
+ const plusFiles = files.map(({ filePathRelativeToUserRootDir, filePathAbsoluteFilesystem }) => {
832
787
  return {
833
788
  filePathRelativeToUserRootDir,
834
789
  filePathAbsoluteVite: filePathRelativeToUserRootDir,
@@ -1046,7 +1001,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
1046
1001
  return { routeFilesystem, isErrorPage: undefined };
1047
1002
  }
1048
1003
  function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
1049
- (0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv === 'config-only');
1004
+ (0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv.config);
1050
1005
  // Eagerly loaded since it's config-only
1051
1006
  (0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
1052
1007
  const { value } = configFilesystemRoutingRoot;
@@ -1143,7 +1098,7 @@ function mergeCumulative(configName, configValueSources) {
1143
1098
  // We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
1144
1099
  (0, utils_js_1.assert)('value' in configValueSource);
1145
1100
  // Make sure configValueSource.value is serializable
1146
- (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, getDefinedAt(configValueSource));
1101
+ (0, getConfigValuesSerialized_js_1.assertConfigValueIsSerializable)(configValueSource.value, configName, getDefinedAt(configValueSource));
1147
1102
  const assertNoMixing = (isSet) => {
1148
1103
  const vals1 = isSet ? valuesSet : valuesArr;
1149
1104
  const t1 = isSet ? 'a Set' : 'an array';
@@ -1184,3 +1139,35 @@ function mergeCumulative(configName, configValueSources) {
1184
1139
  }
1185
1140
  (0, utils_js_1.assert)(false);
1186
1141
  }
1142
+ function getConfigEnvValue(val, errMsgIntro) {
1143
+ const errInvalidValue = `${errMsgIntro} an invalid value ${picocolors_1.default.cyan(JSON.stringify(val))}`;
1144
+ // Legacy outdated values
1145
+ if (typeof val === 'string') {
1146
+ const valConverted = (() => {
1147
+ if (val === 'client-only')
1148
+ return { client: true };
1149
+ if (val === 'server-only')
1150
+ return { server: true };
1151
+ if (val === 'server-and-client')
1152
+ return { server: true, client: true };
1153
+ if (val === 'config-only')
1154
+ return { config: true };
1155
+ if (val === '_routing-lazy')
1156
+ return { server: true, client: 'if-client-routing' };
1157
+ if (val === '_routing-eager')
1158
+ return { server: true, client: 'if-client-routing', eager: true };
1159
+ (0, utils_js_1.assertUsage)(false, errInvalidValue);
1160
+ })();
1161
+ (0, utils_js_1.assertWarning)(false, `${errMsgIntro} ${picocolors_1.default.cyan(val)} which is deprecated and will be removed in the next major release`, { onlyOnce: true });
1162
+ return valConverted;
1163
+ }
1164
+ (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(val), `${errMsgIntro} an invalid type ${picocolors_1.default.cyan(typeof val)}`);
1165
+ (0, utils_js_1.assertKeys)(val, ['config', 'server', 'client'], `${errInvalidValue}:`);
1166
+ (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(val, 'config', 'undefined') || (0, utils_js_1.hasProp)(val, 'config', 'boolean'), errInvalidValue);
1167
+ (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(val, 'server', 'undefined') || (0, utils_js_1.hasProp)(val, 'server', 'boolean'), errInvalidValue);
1168
+ (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(val, 'client', 'undefined') || (0, utils_js_1.hasProp)(val, 'client', 'boolean'), errInvalidValue);
1169
+ /* Uncomment to allow users to set an eager config. Same for `{ client: 'if-client-routing' }`.
1170
+ assertUsage(hasProp(val, 'eager', 'undefined') || hasProp(val, 'eager', 'boolean'), errInvalidValue)
1171
+ */
1172
+ return val;
1173
+ }