@gtkx/config 2.0.0-beta.8 → 2.0.0

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 (69) hide show
  1. package/README.md +11 -169
  2. package/dist/builtin-elements.d.ts +23 -0
  3. package/dist/builtin-elements.d.ts.map +1 -0
  4. package/dist/builtin-elements.js +366 -0
  5. package/dist/builtin-elements.js.map +1 -0
  6. package/dist/config-dependencies.d.ts +5 -3
  7. package/dist/config-dependencies.d.ts.map +1 -1
  8. package/dist/config-dependencies.js +57 -24
  9. package/dist/config-dependencies.js.map +1 -1
  10. package/dist/config-error.d.ts.map +1 -1
  11. package/dist/config-error.js.map +1 -1
  12. package/dist/config-reloader.d.ts +8 -0
  13. package/dist/config-reloader.d.ts.map +1 -0
  14. package/dist/config-reloader.js +32 -0
  15. package/dist/config-reloader.js.map +1 -0
  16. package/dist/config-source.d.ts +9 -0
  17. package/dist/config-source.d.ts.map +1 -0
  18. package/dist/config-source.js +35 -0
  19. package/dist/config-source.js.map +1 -0
  20. package/dist/config.d.ts +286 -53
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +42 -27
  23. package/dist/config.js.map +1 -1
  24. package/dist/deploy.d.ts +949 -20
  25. package/dist/deploy.d.ts.map +1 -1
  26. package/dist/deploy.js +17 -15
  27. package/dist/deploy.js.map +1 -1
  28. package/dist/index.d.ts +8 -3
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +6 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/internal.d.ts +5 -3
  33. package/dist/internal.d.ts.map +1 -1
  34. package/dist/internal.js +5 -3
  35. package/dist/internal.js.map +1 -1
  36. package/dist/loader.d.ts +23 -5
  37. package/dist/loader.d.ts.map +1 -1
  38. package/dist/loader.js +58 -42
  39. package/dist/loader.js.map +1 -1
  40. package/dist/node-version.d.ts +2 -1
  41. package/dist/node-version.d.ts.map +1 -1
  42. package/dist/node-version.js +2 -1
  43. package/dist/node-version.js.map +1 -1
  44. package/dist/resource-base-path.d.ts.map +1 -1
  45. package/dist/schema-text.d.ts.map +1 -1
  46. package/dist/user-event-signals.d.ts.map +1 -1
  47. package/dist/virtual.d.ts +1 -1
  48. package/dist/virtual.d.ts.map +1 -1
  49. package/dist/virtual.js +4 -4
  50. package/dist/virtual.js.map +1 -1
  51. package/dist/vite-plugin.d.ts +7 -0
  52. package/dist/vite-plugin.d.ts.map +1 -1
  53. package/dist/vite-plugin.js +13 -4
  54. package/dist/vite-plugin.js.map +1 -1
  55. package/dist/vite-root.d.ts.map +1 -1
  56. package/package.json +15 -16
  57. package/src/builtin-elements.ts +377 -0
  58. package/src/config-dependencies.ts +65 -29
  59. package/src/config-error.ts +5 -3
  60. package/src/config-reloader.ts +45 -0
  61. package/src/config-source.ts +52 -0
  62. package/src/config.ts +316 -49
  63. package/src/deploy.ts +1029 -59
  64. package/src/index.ts +47 -3
  65. package/src/internal.ts +6 -2
  66. package/src/loader.ts +103 -54
  67. package/src/node-version.ts +2 -1
  68. package/src/virtual.ts +6 -6
  69. package/src/vite-plugin.ts +24 -5
package/src/index.ts CHANGED
@@ -1,3 +1,47 @@
1
- export { type Config, defineConfig, mergeConfig, type ResolvedConfig } from "./config.ts";
2
- export { type DeployExtraFileOptions, type DeployNodeOptions } from "./deploy.ts";
3
- export { type ConfigLoader, type LoadedConfig, loadConfig } from "./loader.ts";
1
+ /**
2
+ * Defines and merges a project's `gtkx.config.ts`.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export {
7
+ type AgentsOptions,
8
+ type ApplicationConfig,
9
+ type Config,
10
+ defineConfig,
11
+ type DeprecationsOptions,
12
+ type ElementConfigOptions,
13
+ type ElementPropsExport,
14
+ type ElementsOptions,
15
+ type McpOptions,
16
+ mergeConfig,
17
+ type ModuleExport,
18
+ type ReactCompilerOptions,
19
+ type ResolvedConfig,
20
+ } from "./config.ts";
21
+ export {
22
+ type DeployAppImageOptions,
23
+ type DeployAppImageSigningOptions,
24
+ type DeployBrandingOptions,
25
+ type DeployDebOptions,
26
+ type DeployDebPackageRelationOptions,
27
+ type DeployDebSigningOptions,
28
+ type DeployDesktopActionOptions,
29
+ type DeployDeveloperOptions,
30
+ type DeployExtraFileOptions,
31
+ type DeployFileAssociationOptions,
32
+ type DeployFlatpakOptions,
33
+ type DeployFlatpakSigningOptions,
34
+ type DeployFlatpakSourceOptions,
35
+ type DeployNodeOptions,
36
+ type DeployOptions,
37
+ type DeployPackageRelationOptions,
38
+ type DeployRelationsOptions,
39
+ type DeployReleaseOptions,
40
+ type DeployRpmOptions,
41
+ type DeployRpmSigningOptions,
42
+ type DeployScreenshotOptions,
43
+ type DeployScriptsOptions,
44
+ type DeploySigningOptions,
45
+ type DeployToolsOptions,
46
+ } from "./deploy.ts";
47
+ export { type ConfigLoader, type LoadConfigOptions, type LoadedConfig, loadConfig } from "./loader.ts";
package/src/internal.ts CHANGED
@@ -1,10 +1,14 @@
1
- export { configDependenciesFor } from "./config-dependencies.ts";
1
+ export { configDependenciesFor, loadConfigModule } from "./config-dependencies.ts";
2
+ export { createConfigReloader } from "./config-reloader.ts";
3
+ export { configCandidatePaths } from "./config-source.ts";
2
4
  export type { McpSettings, ResolvedReactCompilerOptions } from "./config.ts";
3
5
  export {
4
6
  APPLICATION_ID_MAX_LENGTH,
5
7
  isAgentReferenceEnabled,
6
8
  isAgentRulesEnabled,
7
9
  isValidApplicationId,
10
+ LIBRARY_APPLICATION_ID,
11
+ resolveAcceptedChildTypes,
8
12
  resolveElementComponents,
9
13
  resolveElementProps,
10
14
  resolveLazyElements,
@@ -12,6 +16,6 @@ export {
12
16
  resolveOmittedProps,
13
17
  } from "./config.ts";
14
18
  export { createConfigLoader } from "./loader.ts";
15
- export { assertSupportedNodeVersion, MINIMUM_NODE_VERSION } from "./node-version.ts";
19
+ export { assertSupportedNodeVersion, DEFAULT_NODE_VERSION, MINIMUM_NODE_VERSION } from "./node-version.ts";
16
20
  export { resourceBasePath } from "./resource-base-path.ts";
17
21
  export { viteProjectRoot } from "./vite-root.ts";
package/src/loader.ts CHANGED
@@ -1,14 +1,18 @@
1
1
  import { isPathInside, warn } from "@gtkx/utils";
2
2
  import { loadConfig as loadConfigFile } from "c12";
3
+ import { defu } from "defu";
3
4
  import { existsSync } from "node:fs";
4
- import { basename, extname, isAbsolute, relative, resolve } from "node:path";
5
+ import { relative, resolve } from "node:path";
5
6
  import {
7
+ addConfigSource,
6
8
  captureConfigDependencies,
9
+ createConfigImporter,
7
10
  setConfigDependencies,
8
- transformConfigModule,
9
11
  } from "./config-dependencies.ts";
10
- import { missingConfigFileError } from "./config-error.ts";
12
+ import { isRecord, missingConfigFileError } from "./config-error.ts";
13
+ import { configCandidatePaths, type ConfigResolutionOptions, localConfigSourcePaths } from "./config-source.ts";
11
14
  import {
15
+ type ApplicationConfig,
12
16
  type Config,
13
17
  graduatedFutureKeys,
14
18
  resolveConfig,
@@ -19,12 +23,22 @@ import { assertSupportedNodeVersion } from "./node-version.ts";
19
23
 
20
24
  /** Result of loading a project's `gtkx.config.ts` file. */
21
25
  type LoadedConfig = {
22
- /** The parsed and validated configuration. */
23
- config: Config;
24
- /** Absolute path of the configuration file that was loaded. */
26
+ /** The parsed and validated configuration, with the default application ID filled in when one stood in. */
27
+ config: ApplicationConfig;
28
+ /** Whether the configuration names its own `applicationId`, rather than a default standing in for it. */
29
+ isApplication: boolean;
30
+ /**
31
+ * Absolute path of the configuration file that was loaded, or of `gtkx.config.ts` in the project root
32
+ * when a default application ID stood in for a missing file.
33
+ */
25
34
  configFile: string;
26
35
  /** Absolute path of the project root the configuration was resolved against. */
27
36
  root: string;
37
+ /**
38
+ * The gettext domain: the `applicationId` production builds use, so a `$development` application ID
39
+ * shares the production catalogs.
40
+ */
41
+ translationDomain: string;
28
42
  };
29
43
 
30
44
  /** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */
@@ -34,6 +48,14 @@ type LoadConfigOptions = {
34
48
  * top-level values, and the name is passed to a config authored as a function.
35
49
  */
36
50
  mode?: string | undefined;
51
+ /** Whether to report graduated future flags; supervising processes can own these warnings. Defaults to true. */
52
+ shouldWarnGraduatedFuture?: boolean | undefined;
53
+ /**
54
+ * Application ID for a project that is not an application, such as a component library running its
55
+ * tests: it stands in for a missing `applicationId`, and for a missing configuration file unless
56
+ * `configFile` names a file other than `gtkx.config.ts` in the project root.
57
+ */
58
+ defaultApplicationId?: string | undefined;
37
59
  } & Partial<Record<"configFile", string | undefined>>;
38
60
 
39
61
  /** Reads a project's configuration once per directory, caching what it loads and what it resolves. */
@@ -44,36 +66,54 @@ type ConfigLoader = {
44
66
  resolve: (cwd: string) => Promise<ResolvedConfig>;
45
67
  };
46
68
 
47
- const GRADUATED_FUTURE_ENV = "GTKX_GRADUATED_FUTURE_SHOWN";
48
69
  const graduatedFutureWarnings: Map<string, string> = new Map();
70
+ const PRODUCTION_MODE = "production";
71
+ const EXTEND_KEY = "extends";
72
+ const DEFAULT_CONFIG_FILE_NAME = "gtkx.config.ts";
73
+
74
+ const recordOrEmpty = (value: unknown): Record<string, unknown> => (isRecord(value) ? value : {});
75
+
76
+ const modeOverrides = (layer: Record<string, unknown>, mode: string): Record<string, unknown> => ({
77
+ ...recordOrEmpty(layer[`$${mode}`]),
78
+ ...recordOrEmpty(recordOrEmpty(layer.$env)[mode]),
79
+ });
80
+
81
+ const configForMode = (layers: Record<string, unknown>[], mode: string | undefined): Record<string, unknown> => {
82
+ const merged: Record<string, unknown> = defu(
83
+ {},
84
+ ...layers.map((layer) => (mode ? defu(modeOverrides(layer, mode), layer) : layer)),
85
+ );
86
+
87
+ for (const key of Object.keys(merged)) {
88
+ if (key === EXTEND_KEY || key.startsWith("$")) {
89
+ Reflect.deleteProperty(merged, key);
90
+ }
91
+ }
49
92
 
50
- type ConfigResolutionOptions = { configFile?: string | undefined; cwd?: string | undefined };
51
-
52
- const isLocalConfigSource = (source: string): boolean => source.startsWith(".") || isAbsolute(source);
53
-
54
- const isDirectoryConfigSource = (source: string): boolean => {
55
- const extension = extname(source);
56
-
57
- return extension.length === 0 || extension === basename(source);
93
+ return merged;
58
94
  };
59
95
 
60
- const localConfigSourcePath = (source: string, options: ConfigResolutionOptions): string | undefined => {
61
- if (source === "." || !isLocalConfigSource(source)) {
62
- return undefined;
63
- }
96
+ const productionApplicationId = (layers: Record<string, unknown>[], config: ApplicationConfig): string => {
97
+ const { applicationId } = configForMode(layers, PRODUCTION_MODE);
64
98
 
65
- const cwd = options.cwd ?? process.cwd();
66
-
67
- return isDirectoryConfigSource(source)
68
- ? resolve(cwd, source, options.configFile ?? "gtkx.config")
69
- : resolve(cwd, source);
99
+ return typeof applicationId === "string" ? applicationId : config.applicationId;
70
100
  };
71
101
 
102
+ const withDefaultApplicationId = (
103
+ config: Record<string, unknown>,
104
+ applicationId: string | undefined,
105
+ ): Record<string, unknown> =>
106
+ applicationId === undefined || config.applicationId !== undefined ? config : { ...config, applicationId };
107
+
72
108
  const rejectMissingLocalConfig = (source: string, options: ConfigResolutionOptions): undefined => {
73
- const path = localConfigSourcePath(source, options);
109
+ const paths = localConfigSourcePaths(source, options);
74
110
 
75
- if (path !== undefined && !existsSync(path)) {
76
- throw new Error(`Extended configuration does not exist at ${path}`);
111
+ for (const path of paths) {
112
+ addConfigSource(path);
113
+ }
114
+
115
+ if (paths.length > 0 && !paths.some((path) => existsSync(path))) {
116
+ throw new Error(`Extended configuration ${source} does not exist in ${options.cwd ?? process.cwd()}`);
77
117
  }
78
118
  };
79
119
 
@@ -103,20 +143,20 @@ const selectedConfigFile = (root: string, configured: string | undefined): strin
103
143
  return relative(root, path);
104
144
  };
105
145
 
146
+ const explicitConfigFile = (root: string, selected: string | undefined): string | undefined =>
147
+ selected !== undefined && configCandidatePaths(root).find((path) => existsSync(path)) === resolve(root, selected)
148
+ ? undefined
149
+ : selected;
150
+
106
151
  const warnGraduatedFuture = (config: unknown, root: string): void => {
107
152
  const keys = graduatedFutureKeys(config);
108
153
  const signature = keys.join(",");
109
154
 
110
- if (
111
- keys.length === 0 ||
112
- graduatedFutureWarnings.get(root) === signature ||
113
- process.env[GRADUATED_FUTURE_ENV] === signature
114
- ) {
155
+ if (keys.length === 0 || graduatedFutureWarnings.get(root) === signature) {
115
156
  return;
116
157
  }
117
158
 
118
159
  graduatedFutureWarnings.set(root, signature);
119
- process.env[GRADUATED_FUTURE_ENV] = signature;
120
160
  warn(`GTKX 2 ignores graduated future flags: ${keys.join(", ")}. Remove them from gtkx.config.ts.`);
121
161
  };
122
162
 
@@ -130,6 +170,7 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
130
170
  assertSupportedNodeVersion();
131
171
  const searched = resolve(cwd);
132
172
  const requestedConfigFile = selectedConfigFile(searched, options.configFile);
173
+ const c12ConfigFile = explicitConfigFile(searched, requestedConfigFile);
133
174
 
134
175
  const captured = await captureConfigDependencies(() =>
135
176
  loadConfigFile<Config>({
@@ -138,39 +179,47 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
138
179
  rcFile: false,
139
180
  globalRc: false,
140
181
  packageJson: false,
182
+ envName: false,
141
183
  context: { mode: options.mode },
142
- jitiOptions: { fsCache: false, transform: transformConfigModule },
184
+ jiti: createConfigImporter(),
143
185
  resolve: rejectMissingLocalConfig,
144
- ...(requestedConfigFile !== undefined && { configFile: requestedConfigFile }),
145
- ...((options.mode !== undefined) && { envName: options.mode }),
146
- }));
186
+ ...(c12ConfigFile !== undefined && { configFile: c12ConfigFile }),
187
+ }),
188
+ );
147
189
  const result = captured.value;
148
190
 
149
191
  const configFile = result.configFile;
150
192
  const root = result.cwd ?? searched;
151
- const layerFiles = (result.layers ?? [])
152
- .flatMap((layer) => layer.configFile === undefined
153
- ? []
154
- : [resolve(layer.cwd ?? root, layer.configFile)]);
155
- const dependencies = [
156
- ...(configFile === undefined ? [] : [configFile]),
157
- ...layerFiles,
158
- ...captured.dependencies,
159
- ];
193
+ const layerFiles = (result.layers ?? []).flatMap((layer) =>
194
+ layer.configFile === undefined ? [] : [resolve(layer.cwd ?? root, layer.configFile)],
195
+ );
196
+ const dependencies = [...(configFile === undefined ? [] : [configFile]), ...layerFiles, ...captured.dependencies];
197
+ const foundConfigFile =
198
+ configFile !== undefined && existsSync(resolve(searched, configFile)) ? configFile : undefined;
199
+ const isConfigFileOptional =
200
+ options.defaultApplicationId !== undefined &&
201
+ (requestedConfigFile === undefined || requestedConfigFile === DEFAULT_CONFIG_FILE_NAME);
160
202
 
161
203
  return withConfigDependencies(dependencies, () => {
162
- if (configFile === undefined || !existsSync(resolve(searched, configFile))) {
204
+ if (foundConfigFile === undefined && !isConfigFileOptional) {
163
205
  throw missingConfigFileError(searched, requestedConfigFile);
164
206
  }
165
207
 
166
- const config = result.config;
167
- validateConfig(config, configFile);
168
- warnGraduatedFuture(config, root);
208
+ const layers = (result.layers ?? []).flatMap((layer) => (isRecord(layer.config) ? [layer.config] : []));
209
+ const authored = configForMode(layers, options.mode ?? process.env.NODE_ENV);
210
+ const config = withDefaultApplicationId(authored, options.defaultApplicationId);
211
+ const loadedConfigFile = foundConfigFile ?? resolve(searched, DEFAULT_CONFIG_FILE_NAME);
212
+ validateConfig(config, loadedConfigFile);
213
+ if (options.shouldWarnGraduatedFuture !== false) {
214
+ warnGraduatedFuture(config, root);
215
+ }
169
216
 
170
217
  const loaded = {
171
218
  config,
172
- configFile,
219
+ isApplication: authored.applicationId !== undefined,
220
+ configFile: loadedConfigFile,
173
221
  root,
222
+ translationDomain: productionApplicationId(layers, config),
174
223
  };
175
224
  setConfigDependencies(loaded, dependencies);
176
225
 
@@ -187,9 +236,9 @@ const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {
187
236
  loaded.getOrInsertComputed(resolve(cwd), (root) => loadConfig(root, options));
188
237
 
189
238
  const resolveAt = async (root: string): Promise<ResolvedConfig> => {
190
- const { config, root: configRoot } = await load(root);
239
+ const { config, root: configRoot, translationDomain } = await load(root);
191
240
 
192
- return resolveConfig(config, configRoot);
241
+ return resolveConfig(config, translationDomain, configRoot);
193
242
  };
194
243
 
195
244
  return {
@@ -198,4 +247,4 @@ const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {
198
247
  };
199
248
  };
200
249
 
201
- export { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader };
250
+ export { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader, type LoadConfigOptions };
@@ -1,6 +1,7 @@
1
1
  const MINIMUM_NODE_MAJOR = 26;
2
2
  const MINIMUM_NODE_MINOR = 7;
3
3
  const MINIMUM_NODE_VERSION = "26.7.0";
4
+ const DEFAULT_NODE_VERSION = "26.13.1";
4
5
 
5
6
  const assertSupportedNodeVersion = (): void => {
6
7
  const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
@@ -13,4 +14,4 @@ const assertSupportedNodeVersion = (): void => {
13
14
  }
14
15
  };
15
16
 
16
- export { assertSupportedNodeVersion, MINIMUM_NODE_VERSION };
17
+ export { assertSupportedNodeVersion, DEFAULT_NODE_VERSION, MINIMUM_NODE_VERSION };
package/src/virtual.ts CHANGED
@@ -3,23 +3,23 @@ import { resourceBasePath } from "./resource-base-path.ts";
3
3
 
4
4
  const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
5
5
  const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\0${GTKX_CONFIG_VIRTUAL_ID}`;
6
- const METADATA_SPECIFIER = "@gtkx/jsx/metadata";
7
6
 
8
- const renderConfigModule = (config: ResolvedConfig): string => {
7
+ const renderConfigModule = (config: ResolvedConfig, localeDir: string | null = null): string => {
9
8
  const lazyJson = JSON.stringify(Object.fromEntries(config.lazyElements.map((type) => [type, { isLazy: true }])));
10
9
 
11
10
  const behaviorImports =
12
11
  config.elements === null
13
12
  ? []
14
13
  : [
15
- "import { mergeElementConfigs } from \"@gtkx/react/config\";",
16
- `import __elementBehaviors from ${JSON.stringify(config.elements)};`,
17
- ];
14
+ 'import { mergeElementConfigs } from "@gtkx/react/config";',
15
+ `import __elementBehaviors from ${JSON.stringify(config.elements)};`,
16
+ ];
18
17
 
19
18
  return [
20
19
  ...behaviorImports,
21
- `export * from ${JSON.stringify(METADATA_SPECIFIER)};`,
22
20
  `export const applicationId = ${JSON.stringify(config.applicationId)};`,
21
+ `export const translationDomain = ${JSON.stringify(config.translationDomain)};`,
22
+ `export const localeDir = ${JSON.stringify(localeDir)};`,
23
23
  `export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,
24
24
  `export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
25
25
  config.elements === null
@@ -1,14 +1,21 @@
1
+ /**
2
+ * Vite plugin that serves the project's resolved `gtkx.config.ts` as `virtual:gtkx-config`.
3
+ *
4
+ * @packageDocumentation
5
+ */
1
6
  import type { Plugin, UserConfig } from "vite";
7
+ import { resolve } from "node:path";
2
8
  import { type ConfigLoader, createConfigLoader } from "./loader.ts";
3
9
  import { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from "./virtual.ts";
4
10
  import { viteProjectRoot } from "./vite-root.ts";
5
11
 
6
- /** State the plugin carries from Vite's `config` hook to the virtual module it serves. */
7
12
  type PluginState = {
8
- /** Project root taken from Vite's `config` hook, falling back to the working directory. */
9
13
  root: string;
10
14
  };
11
15
 
16
+ const VIRTUAL_ID_RE = new RegExp(`^${GTKX_CONFIG_VIRTUAL_ID}$`);
17
+ const RESOLVED_VIRTUAL_ID_RE = new RegExp(`^${RESOLVED_GTKX_CONFIG_VIRTUAL_ID}$`);
18
+
12
19
  const resolveVirtualId = (id: string): string | null =>
13
20
  id === GTKX_CONFIG_VIRTUAL_ID ? RESOLVED_GTKX_CONFIG_VIRTUAL_ID : null;
14
21
 
@@ -16,12 +23,16 @@ const loadVirtualModule = async (
16
23
  id: string,
17
24
  loadConfig: ConfigLoader,
18
25
  state: PluginState,
26
+ localeDir: string | null | undefined,
19
27
  ): Promise<string | undefined> => {
20
28
  if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {
21
29
  return undefined;
22
30
  }
23
31
 
24
- return renderConfigModule(await loadConfig.resolve(state.root));
32
+ return renderConfigModule(
33
+ await loadConfig.resolve(state.root),
34
+ localeDir == null ? null : resolve(state.root, localeDir),
35
+ );
25
36
  };
26
37
 
27
38
  /**
@@ -33,6 +44,8 @@ const createConfigPlugin = (options: {
33
44
  name: string;
34
45
  /** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
35
46
  loadConfig?: ConfigLoader;
47
+ /** Catalog directory for development or tests, resolved relative to the project root. */
48
+ localeDir?: string | null | undefined;
36
49
  /** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */
37
50
  config?: (config: UserConfig) => Omit<UserConfig, "plugins">;
38
51
  }): Plugin => {
@@ -46,8 +59,14 @@ const createConfigPlugin = (options: {
46
59
 
47
60
  return options.config?.(config);
48
61
  },
49
- resolveId: (id: string) => resolveVirtualId(id),
50
- load: (id: string) => loadVirtualModule(id, loadConfig, state),
62
+ resolveId: {
63
+ filter: { id: VIRTUAL_ID_RE },
64
+ handler: (id: string) => resolveVirtualId(id),
65
+ },
66
+ load: {
67
+ filter: { id: RESOLVED_VIRTUAL_ID_RE },
68
+ handler: (id: string) => loadVirtualModule(id, loadConfig, state, options.localeDir),
69
+ },
51
70
  };
52
71
  };
53
72