@gtkx/config 2.0.0-beta.9 → 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.
- package/README.md +11 -169
- package/dist/builtin-elements.d.ts +23 -0
- package/dist/builtin-elements.d.ts.map +1 -0
- package/dist/builtin-elements.js +366 -0
- package/dist/builtin-elements.js.map +1 -0
- package/dist/config-dependencies.d.ts +5 -3
- package/dist/config-dependencies.d.ts.map +1 -1
- package/dist/config-dependencies.js +57 -24
- package/dist/config-dependencies.js.map +1 -1
- package/dist/config-error.d.ts.map +1 -1
- package/dist/config-error.js.map +1 -1
- package/dist/config-reloader.d.ts +8 -0
- package/dist/config-reloader.d.ts.map +1 -0
- package/dist/config-reloader.js +32 -0
- package/dist/config-reloader.js.map +1 -0
- package/dist/config-source.d.ts +9 -0
- package/dist/config-source.d.ts.map +1 -0
- package/dist/config-source.js +35 -0
- package/dist/config-source.js.map +1 -0
- package/dist/config.d.ts +286 -53
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +42 -27
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +949 -20
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +17 -15
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +5 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -3
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +23 -5
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +58 -42
- package/dist/loader.js.map +1 -1
- package/dist/node-version.d.ts +2 -1
- package/dist/node-version.d.ts.map +1 -1
- package/dist/node-version.js +2 -1
- package/dist/node-version.js.map +1 -1
- package/dist/resource-base-path.d.ts.map +1 -1
- package/dist/schema-text.d.ts.map +1 -1
- package/dist/user-event-signals.d.ts.map +1 -1
- package/dist/virtual.d.ts +1 -1
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +4 -4
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +7 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +13 -4
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-root.d.ts.map +1 -1
- package/package.json +15 -16
- package/src/builtin-elements.ts +377 -0
- package/src/config-dependencies.ts +65 -29
- package/src/config-error.ts +5 -3
- package/src/config-reloader.ts +45 -0
- package/src/config-source.ts +52 -0
- package/src/config.ts +316 -49
- package/src/deploy.ts +1029 -59
- package/src/index.ts +47 -3
- package/src/internal.ts +6 -2
- package/src/loader.ts +103 -54
- package/src/node-version.ts +2 -1
- package/src/virtual.ts +6 -6
- package/src/vite-plugin.ts +24 -5
package/dist/loader.js
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
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 {
|
|
5
|
-
import { captureConfigDependencies,
|
|
6
|
-
import { missingConfigFileError } from "./config-error.js";
|
|
5
|
+
import { relative, resolve } from "node:path";
|
|
6
|
+
import { addConfigSource, captureConfigDependencies, createConfigImporter, setConfigDependencies, } from "./config-dependencies.js";
|
|
7
|
+
import { isRecord, missingConfigFileError } from "./config-error.js";
|
|
8
|
+
import { configCandidatePaths, localConfigSourcePaths } from "./config-source.js";
|
|
7
9
|
import { graduatedFutureKeys, resolveConfig, validateConfig, } from "./config.js";
|
|
8
10
|
import { assertSupportedNodeVersion } from "./node-version.js";
|
|
9
|
-
const GRADUATED_FUTURE_ENV = "GTKX_GRADUATED_FUTURE_SHOWN";
|
|
10
11
|
const graduatedFutureWarnings = new Map();
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const PRODUCTION_MODE = "production";
|
|
13
|
+
const EXTEND_KEY = "extends";
|
|
14
|
+
const DEFAULT_CONFIG_FILE_NAME = "gtkx.config.ts";
|
|
15
|
+
const recordOrEmpty = (value) => (isRecord(value) ? value : {});
|
|
16
|
+
const modeOverrides = (layer, mode) => ({
|
|
17
|
+
...recordOrEmpty(layer[`$${mode}`]),
|
|
18
|
+
...recordOrEmpty(recordOrEmpty(layer.$env)[mode]),
|
|
19
|
+
});
|
|
20
|
+
const configForMode = (layers, mode) => {
|
|
21
|
+
const merged = defu({}, ...layers.map((layer) => (mode ? defu(modeOverrides(layer, mode), layer) : layer)));
|
|
22
|
+
for (const key of Object.keys(merged)) {
|
|
23
|
+
if (key === EXTEND_KEY || key.startsWith("$")) {
|
|
24
|
+
Reflect.deleteProperty(merged, key);
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
return isDirectoryConfigSource(source)
|
|
22
|
-
? resolve(cwd, source, options.configFile ?? "gtkx.config")
|
|
23
|
-
: resolve(cwd, source);
|
|
27
|
+
return merged;
|
|
24
28
|
};
|
|
29
|
+
const productionApplicationId = (layers, config) => {
|
|
30
|
+
const { applicationId } = configForMode(layers, PRODUCTION_MODE);
|
|
31
|
+
return typeof applicationId === "string" ? applicationId : config.applicationId;
|
|
32
|
+
};
|
|
33
|
+
const withDefaultApplicationId = (config, applicationId) => applicationId === undefined || config.applicationId !== undefined ? config : { ...config, applicationId };
|
|
25
34
|
const rejectMissingLocalConfig = (source, options) => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const paths = localConfigSourcePaths(source, options);
|
|
36
|
+
for (const path of paths) {
|
|
37
|
+
addConfigSource(path);
|
|
38
|
+
}
|
|
39
|
+
if (paths.length > 0 && !paths.some((path) => existsSync(path))) {
|
|
40
|
+
throw new Error(`Extended configuration ${source} does not exist in ${options.cwd ?? process.cwd()}`);
|
|
29
41
|
}
|
|
30
42
|
};
|
|
31
43
|
const withConfigDependencies = (dependencies, operation) => {
|
|
@@ -49,16 +61,16 @@ const selectedConfigFile = (root, configured) => {
|
|
|
49
61
|
}
|
|
50
62
|
return relative(root, path);
|
|
51
63
|
};
|
|
64
|
+
const explicitConfigFile = (root, selected) => selected !== undefined && configCandidatePaths(root).find((path) => existsSync(path)) === resolve(root, selected)
|
|
65
|
+
? undefined
|
|
66
|
+
: selected;
|
|
52
67
|
const warnGraduatedFuture = (config, root) => {
|
|
53
68
|
const keys = graduatedFutureKeys(config);
|
|
54
69
|
const signature = keys.join(",");
|
|
55
|
-
if (keys.length === 0 ||
|
|
56
|
-
graduatedFutureWarnings.get(root) === signature ||
|
|
57
|
-
process.env[GRADUATED_FUTURE_ENV] === signature) {
|
|
70
|
+
if (keys.length === 0 || graduatedFutureWarnings.get(root) === signature) {
|
|
58
71
|
return;
|
|
59
72
|
}
|
|
60
73
|
graduatedFutureWarnings.set(root, signature);
|
|
61
|
-
process.env[GRADUATED_FUTURE_ENV] = signature;
|
|
62
74
|
warn(`GTKX 2 ignores graduated future flags: ${keys.join(", ")}. Remove them from gtkx.config.ts.`);
|
|
63
75
|
};
|
|
64
76
|
/**
|
|
@@ -71,41 +83,45 @@ const loadConfig = async (cwd, options = {}) => {
|
|
|
71
83
|
assertSupportedNodeVersion();
|
|
72
84
|
const searched = resolve(cwd);
|
|
73
85
|
const requestedConfigFile = selectedConfigFile(searched, options.configFile);
|
|
86
|
+
const c12ConfigFile = explicitConfigFile(searched, requestedConfigFile);
|
|
74
87
|
const captured = await captureConfigDependencies(() => loadConfigFile({
|
|
75
88
|
name: "gtkx",
|
|
76
89
|
cwd: searched,
|
|
77
90
|
rcFile: false,
|
|
78
91
|
globalRc: false,
|
|
79
92
|
packageJson: false,
|
|
93
|
+
envName: false,
|
|
80
94
|
context: { mode: options.mode },
|
|
81
|
-
|
|
95
|
+
jiti: createConfigImporter(),
|
|
82
96
|
resolve: rejectMissingLocalConfig,
|
|
83
|
-
...(
|
|
84
|
-
...((options.mode !== undefined) && { envName: options.mode }),
|
|
97
|
+
...(c12ConfigFile !== undefined && { configFile: c12ConfigFile }),
|
|
85
98
|
}));
|
|
86
99
|
const result = captured.value;
|
|
87
100
|
const configFile = result.configFile;
|
|
88
101
|
const root = result.cwd ?? searched;
|
|
89
|
-
const layerFiles = (result.layers ?? [])
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
...(configFile === undefined ? [] : [configFile]),
|
|
95
|
-
...layerFiles,
|
|
96
|
-
...captured.dependencies,
|
|
97
|
-
];
|
|
102
|
+
const layerFiles = (result.layers ?? []).flatMap((layer) => layer.configFile === undefined ? [] : [resolve(layer.cwd ?? root, layer.configFile)]);
|
|
103
|
+
const dependencies = [...(configFile === undefined ? [] : [configFile]), ...layerFiles, ...captured.dependencies];
|
|
104
|
+
const foundConfigFile = configFile !== undefined && existsSync(resolve(searched, configFile)) ? configFile : undefined;
|
|
105
|
+
const isConfigFileOptional = options.defaultApplicationId !== undefined &&
|
|
106
|
+
(requestedConfigFile === undefined || requestedConfigFile === DEFAULT_CONFIG_FILE_NAME);
|
|
98
107
|
return withConfigDependencies(dependencies, () => {
|
|
99
|
-
if (
|
|
108
|
+
if (foundConfigFile === undefined && !isConfigFileOptional) {
|
|
100
109
|
throw missingConfigFileError(searched, requestedConfigFile);
|
|
101
110
|
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
const layers = (result.layers ?? []).flatMap((layer) => (isRecord(layer.config) ? [layer.config] : []));
|
|
112
|
+
const authored = configForMode(layers, options.mode ?? process.env.NODE_ENV);
|
|
113
|
+
const config = withDefaultApplicationId(authored, options.defaultApplicationId);
|
|
114
|
+
const loadedConfigFile = foundConfigFile ?? resolve(searched, DEFAULT_CONFIG_FILE_NAME);
|
|
115
|
+
validateConfig(config, loadedConfigFile);
|
|
116
|
+
if (options.shouldWarnGraduatedFuture !== false) {
|
|
117
|
+
warnGraduatedFuture(config, root);
|
|
118
|
+
}
|
|
105
119
|
const loaded = {
|
|
106
120
|
config,
|
|
107
|
-
|
|
121
|
+
isApplication: authored.applicationId !== undefined,
|
|
122
|
+
configFile: loadedConfigFile,
|
|
108
123
|
root,
|
|
124
|
+
translationDomain: productionApplicationId(layers, config),
|
|
109
125
|
};
|
|
110
126
|
setConfigDependencies(loaded, dependencies);
|
|
111
127
|
return loaded;
|
|
@@ -117,8 +133,8 @@ const createConfigLoader = (options = {}) => {
|
|
|
117
133
|
const resolved = new Map();
|
|
118
134
|
const load = (cwd) => loaded.getOrInsertComputed(resolve(cwd), (root) => loadConfig(root, options));
|
|
119
135
|
const resolveAt = async (root) => {
|
|
120
|
-
const { config, root: configRoot } = await load(root);
|
|
121
|
-
return resolveConfig(config, configRoot);
|
|
136
|
+
const { config, root: configRoot, translationDomain } = await load(root);
|
|
137
|
+
return resolveConfig(config, translationDomain, configRoot);
|
|
122
138
|
};
|
|
123
139
|
return {
|
|
124
140
|
load,
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAEH,mBAAmB,EACnB,aAAa,EAEb,cAAc,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,0BAA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AAmB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAElF,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAA2B,EAAE;QAC9D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtD,OAAO,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,OAAO;QACH,IAAI;QACJ,OAAO,EAAE,CAAC,GAAW,EAA2B,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC;KAC3G,CAAC;AACN,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAwC,CAAC","sourcesContent":["import { isPathInside, warn } from \"@gtkx/utils\";\nimport { loadConfig as loadConfigFile } from \"c12\";\nimport { existsSync } from \"node:fs\";\nimport { basename, extname, isAbsolute, relative, resolve } from \"node:path\";\nimport {\n captureConfigDependencies,\n setConfigDependencies,\n transformConfigModule,\n} from \"./config-dependencies.ts\";\nimport { missingConfigFileError } from \"./config-error.ts\";\nimport {\n type Config,\n graduatedFutureKeys,\n resolveConfig,\n type ResolvedConfig,\n validateConfig,\n} from \"./config.ts\";\nimport { assertSupportedNodeVersion } from \"./node-version.ts\";\n\n/** Result of loading a project's `gtkx.config.ts` file. */\ntype LoadedConfig = {\n /** The parsed and validated configuration. */\n config: Config;\n /** Absolute path of the configuration file that was loaded. */\n configFile: string;\n /** Absolute path of the project root the configuration was resolved against. */\n root: string;\n};\n\n/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */\ntype LoadConfigOptions = {\n /**\n * Environment name such as `development`: the config's matching `$<mode>` block is layered over the\n * top-level values, and the name is passed to a config authored as a function.\n */\n mode?: string | undefined;\n} & Partial<Record<\"configFile\", string | undefined>>;\n\n/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */\ntype ConfigLoader = {\n /** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */\n load: (cwd: string) => Promise<LoadedConfig>;\n /** Loads the configuration for the given directory and reduces it to what the build and the app need. */\n resolve: (cwd: string) => Promise<ResolvedConfig>;\n};\n\nconst GRADUATED_FUTURE_ENV = \"GTKX_GRADUATED_FUTURE_SHOWN\";\nconst graduatedFutureWarnings: Map<string, string> = new Map();\n\ntype ConfigResolutionOptions = { configFile?: string | undefined; cwd?: string | undefined };\n\nconst isLocalConfigSource = (source: string): boolean => source.startsWith(\".\") || isAbsolute(source);\n\nconst isDirectoryConfigSource = (source: string): boolean => {\n const extension = extname(source);\n\n return extension.length === 0 || extension === basename(source);\n};\n\nconst localConfigSourcePath = (source: string, options: ConfigResolutionOptions): string | undefined => {\n if (source === \".\" || !isLocalConfigSource(source)) {\n return undefined;\n }\n\n const cwd = options.cwd ?? process.cwd();\n\n return isDirectoryConfigSource(source)\n ? resolve(cwd, source, options.configFile ?? \"gtkx.config\")\n : resolve(cwd, source);\n};\n\nconst rejectMissingLocalConfig = (source: string, options: ConfigResolutionOptions): undefined => {\n const path = localConfigSourcePath(source, options);\n\n if (path !== undefined && !existsSync(path)) {\n throw new Error(`Extended configuration does not exist at ${path}`);\n }\n};\n\nconst withConfigDependencies = <T>(dependencies: string[], operation: () => T): T => {\n try {\n return operation();\n } catch (error) {\n if (typeof error === \"object\" && error !== null) {\n setConfigDependencies(error, dependencies);\n }\n\n throw error;\n }\n};\n\nconst selectedConfigFile = (root: string, configured: string | undefined): string | undefined => {\n if (configured === undefined) {\n return undefined;\n }\n\n const path = resolve(root, configured);\n\n if (!isPathInside(root, path)) {\n throw new Error(`Configuration file ${configured} must be inside the project root ${root}`);\n }\n\n return relative(root, path);\n};\n\nconst warnGraduatedFuture = (config: unknown, root: string): void => {\n const keys = graduatedFutureKeys(config);\n const signature = keys.join(\",\");\n\n if (\n keys.length === 0 ||\n graduatedFutureWarnings.get(root) === signature ||\n process.env[GRADUATED_FUTURE_ENV] === signature\n ) {\n return;\n }\n\n graduatedFutureWarnings.set(root, signature);\n process.env[GRADUATED_FUTURE_ENV] = signature;\n warn(`GTKX 2 ignores graduated future flags: ${keys.join(\", \")}. Remove them from gtkx.config.ts.`);\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project.\n * @param cwd Directory the configuration file is looked up in; parent directories are not searched.\n * @param options Loading options, such as the environment mode whose overrides are applied.\n * @throws When that directory holds no configuration file, or when the configuration fails validation.\n */\nconst loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n assertSupportedNodeVersion();\n const searched = resolve(cwd);\n const requestedConfigFile = selectedConfigFile(searched, options.configFile);\n\n const captured = await captureConfigDependencies(() =>\n loadConfigFile<Config>({\n name: \"gtkx\",\n cwd: searched,\n rcFile: false,\n globalRc: false,\n packageJson: false,\n context: { mode: options.mode },\n jitiOptions: { fsCache: false, transform: transformConfigModule },\n resolve: rejectMissingLocalConfig,\n ...(requestedConfigFile !== undefined && { configFile: requestedConfigFile }),\n ...((options.mode !== undefined) && { envName: options.mode }),\n }));\n const result = captured.value;\n\n const configFile = result.configFile;\n const root = result.cwd ?? searched;\n const layerFiles = (result.layers ?? [])\n .flatMap((layer) => layer.configFile === undefined\n ? []\n : [resolve(layer.cwd ?? root, layer.configFile)]);\n const dependencies = [\n ...(configFile === undefined ? [] : [configFile]),\n ...layerFiles,\n ...captured.dependencies,\n ];\n\n return withConfigDependencies(dependencies, () => {\n if (configFile === undefined || !existsSync(resolve(searched, configFile))) {\n throw missingConfigFileError(searched, requestedConfigFile);\n }\n\n const config = result.config;\n validateConfig(config, configFile);\n warnGraduatedFuture(config, root);\n\n const loaded = {\n config,\n configFile,\n root,\n };\n setConfigDependencies(loaded, dependencies);\n\n return loaded;\n });\n};\n\nconst createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {\n assertSupportedNodeVersion();\n const loaded: Map<string, Promise<LoadedConfig>> = new Map();\n const resolved: Map<string, Promise<ResolvedConfig>> = new Map();\n\n const load = (cwd: string): Promise<LoadedConfig> =>\n loaded.getOrInsertComputed(resolve(cwd), (root) => loadConfig(root, options));\n\n const resolveAt = async (root: string): Promise<ResolvedConfig> => {\n const { config, root: configRoot } = await load(root);\n\n return resolveConfig(config, configRoot);\n };\n\n return {\n load,\n resolve: (cwd: string): Promise<ResolvedConfig> => resolved.getOrInsertComputed(resolve(cwd), resolveAt),\n };\n};\n\nexport { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader };\n"]}
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACH,eAAe,EACf,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAgC,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAChH,OAAO,EAGH,mBAAmB,EACnB,aAAa,EAEb,cAAc,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AA+C/D,MAAM,uBAAuB,GAAwB,IAAI,GAAG,EAAE,CAAC;AAC/D,MAAM,eAAe,GAAG,YAAY,CAAC;AACrC,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM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from \"@gtkx/utils\";\nimport { loadConfig as loadConfigFile } from \"c12\";\nimport { defu } from \"defu\";\nimport { existsSync } from \"node:fs\";\nimport { relative, resolve } from \"node:path\";\nimport {\n addConfigSource,\n captureConfigDependencies,\n createConfigImporter,\n setConfigDependencies,\n} from \"./config-dependencies.ts\";\nimport { isRecord, missingConfigFileError } from \"./config-error.ts\";\nimport { configCandidatePaths, type ConfigResolutionOptions, localConfigSourcePaths } from \"./config-source.ts\";\nimport {\n type ApplicationConfig,\n type Config,\n graduatedFutureKeys,\n resolveConfig,\n type ResolvedConfig,\n validateConfig,\n} from \"./config.ts\";\nimport { assertSupportedNodeVersion } from \"./node-version.ts\";\n\n/** Result of loading a project's `gtkx.config.ts` file. */\ntype LoadedConfig = {\n /** The parsed and validated configuration, with the default application ID filled in when one stood in. */\n config: ApplicationConfig;\n /** Whether the configuration names its own `applicationId`, rather than a default standing in for it. */\n isApplication: boolean;\n /**\n * Absolute path of the configuration file that was loaded, or of `gtkx.config.ts` in the project root\n * when a default application ID stood in for a missing file.\n */\n configFile: string;\n /** Absolute path of the project root the configuration was resolved against. */\n root: string;\n /**\n * The gettext domain: the `applicationId` production builds use, so a `$development` application ID\n * shares the production catalogs.\n */\n translationDomain: string;\n};\n\n/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */\ntype LoadConfigOptions = {\n /**\n * Environment name such as `development`: the config's matching `$<mode>` block is layered over the\n * top-level values, and the name is passed to a config authored as a function.\n */\n mode?: string | undefined;\n /** Whether to report graduated future flags; supervising processes can own these warnings. Defaults to true. */\n shouldWarnGraduatedFuture?: boolean | undefined;\n /**\n * Application ID for a project that is not an application, such as a component library running its\n * tests: it stands in for a missing `applicationId`, and for a missing configuration file unless\n * `configFile` names a file other than `gtkx.config.ts` in the project root.\n */\n defaultApplicationId?: string | undefined;\n} & Partial<Record<\"configFile\", string | undefined>>;\n\n/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */\ntype ConfigLoader = {\n /** Loads the configuration file the given directory resolves to, as {@link loadConfig} does. */\n load: (cwd: string) => Promise<LoadedConfig>;\n /** Loads the configuration for the given directory and reduces it to what the build and the app need. */\n resolve: (cwd: string) => Promise<ResolvedConfig>;\n};\n\nconst graduatedFutureWarnings: Map<string, string> = new Map();\nconst PRODUCTION_MODE = \"production\";\nconst EXTEND_KEY = \"extends\";\nconst DEFAULT_CONFIG_FILE_NAME = \"gtkx.config.ts\";\n\nconst recordOrEmpty = (value: unknown): Record<string, unknown> => (isRecord(value) ? value : {});\n\nconst modeOverrides = (layer: Record<string, unknown>, mode: string): Record<string, unknown> => ({\n ...recordOrEmpty(layer[`$${mode}`]),\n ...recordOrEmpty(recordOrEmpty(layer.$env)[mode]),\n});\n\nconst configForMode = (layers: Record<string, unknown>[], mode: string | undefined): Record<string, unknown> => {\n const merged: Record<string, unknown> = defu(\n {},\n ...layers.map((layer) => (mode ? defu(modeOverrides(layer, mode), layer) : layer)),\n );\n\n for (const key of Object.keys(merged)) {\n if (key === EXTEND_KEY || key.startsWith(\"$\")) {\n Reflect.deleteProperty(merged, key);\n }\n }\n\n return merged;\n};\n\nconst productionApplicationId = (layers: Record<string, unknown>[], config: ApplicationConfig): string => {\n const { applicationId } = configForMode(layers, PRODUCTION_MODE);\n\n return typeof applicationId === \"string\" ? applicationId : config.applicationId;\n};\n\nconst withDefaultApplicationId = (\n config: Record<string, unknown>,\n applicationId: string | undefined,\n): Record<string, unknown> =>\n applicationId === undefined || config.applicationId !== undefined ? config : { ...config, applicationId };\n\nconst rejectMissingLocalConfig = (source: string, options: ConfigResolutionOptions): undefined => {\n const paths = localConfigSourcePaths(source, options);\n\n for (const path of paths) {\n addConfigSource(path);\n }\n\n if (paths.length > 0 && !paths.some((path) => existsSync(path))) {\n throw new Error(`Extended configuration ${source} does not exist in ${options.cwd ?? process.cwd()}`);\n }\n};\n\nconst withConfigDependencies = <T>(dependencies: string[], operation: () => T): T => {\n try {\n return operation();\n } catch (error) {\n if (typeof error === \"object\" && error !== null) {\n setConfigDependencies(error, dependencies);\n }\n\n throw error;\n }\n};\n\nconst selectedConfigFile = (root: string, configured: string | undefined): string | undefined => {\n if (configured === undefined) {\n return undefined;\n }\n\n const path = resolve(root, configured);\n\n if (!isPathInside(root, path)) {\n throw new Error(`Configuration file ${configured} must be inside the project root ${root}`);\n }\n\n return relative(root, path);\n};\n\nconst explicitConfigFile = (root: string, selected: string | undefined): string | undefined =>\n selected !== undefined && configCandidatePaths(root).find((path) => existsSync(path)) === resolve(root, selected)\n ? undefined\n : selected;\n\nconst warnGraduatedFuture = (config: unknown, root: string): void => {\n const keys = graduatedFutureKeys(config);\n const signature = keys.join(\",\");\n\n if (keys.length === 0 || graduatedFutureWarnings.get(root) === signature) {\n return;\n }\n\n graduatedFutureWarnings.set(root, signature);\n warn(`GTKX 2 ignores graduated future flags: ${keys.join(\", \")}. Remove them from gtkx.config.ts.`);\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project.\n * @param cwd Directory the configuration file is looked up in; parent directories are not searched.\n * @param options Loading options, such as the environment mode whose overrides are applied.\n * @throws When that directory holds no configuration file, or when the configuration fails validation.\n */\nconst loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n assertSupportedNodeVersion();\n const searched = resolve(cwd);\n const requestedConfigFile = selectedConfigFile(searched, options.configFile);\n const c12ConfigFile = explicitConfigFile(searched, requestedConfigFile);\n\n const captured = await captureConfigDependencies(() =>\n loadConfigFile<Config>({\n name: \"gtkx\",\n cwd: searched,\n rcFile: false,\n globalRc: false,\n packageJson: false,\n envName: false,\n context: { mode: options.mode },\n jiti: createConfigImporter(),\n resolve: rejectMissingLocalConfig,\n ...(c12ConfigFile !== undefined && { configFile: c12ConfigFile }),\n }),\n );\n const result = captured.value;\n\n const configFile = result.configFile;\n const root = result.cwd ?? searched;\n const layerFiles = (result.layers ?? []).flatMap((layer) =>\n layer.configFile === undefined ? [] : [resolve(layer.cwd ?? root, layer.configFile)],\n );\n const dependencies = [...(configFile === undefined ? [] : [configFile]), ...layerFiles, ...captured.dependencies];\n const foundConfigFile =\n configFile !== undefined && existsSync(resolve(searched, configFile)) ? configFile : undefined;\n const isConfigFileOptional =\n options.defaultApplicationId !== undefined &&\n (requestedConfigFile === undefined || requestedConfigFile === DEFAULT_CONFIG_FILE_NAME);\n\n return withConfigDependencies(dependencies, () => {\n if (foundConfigFile === undefined && !isConfigFileOptional) {\n throw missingConfigFileError(searched, requestedConfigFile);\n }\n\n const layers = (result.layers ?? []).flatMap((layer) => (isRecord(layer.config) ? [layer.config] : []));\n const authored = configForMode(layers, options.mode ?? process.env.NODE_ENV);\n const config = withDefaultApplicationId(authored, options.defaultApplicationId);\n const loadedConfigFile = foundConfigFile ?? resolve(searched, DEFAULT_CONFIG_FILE_NAME);\n validateConfig(config, loadedConfigFile);\n if (options.shouldWarnGraduatedFuture !== false) {\n warnGraduatedFuture(config, root);\n }\n\n const loaded = {\n config,\n isApplication: authored.applicationId !== undefined,\n configFile: loadedConfigFile,\n root,\n translationDomain: productionApplicationId(layers, config),\n };\n setConfigDependencies(loaded, dependencies);\n\n return loaded;\n });\n};\n\nconst createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {\n assertSupportedNodeVersion();\n const loaded: Map<string, Promise<LoadedConfig>> = new Map();\n const resolved: Map<string, Promise<ResolvedConfig>> = new Map();\n\n const load = (cwd: string): Promise<LoadedConfig> =>\n loaded.getOrInsertComputed(resolve(cwd), (root) => loadConfig(root, options));\n\n const resolveAt = async (root: string): Promise<ResolvedConfig> => {\n const { config, root: configRoot, translationDomain } = await load(root);\n\n return resolveConfig(config, translationDomain, configRoot);\n };\n\n return {\n load,\n resolve: (cwd: string): Promise<ResolvedConfig> => resolved.getOrInsertComputed(resolve(cwd), resolveAt),\n };\n};\n\nexport { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader, type LoadConfigOptions };\n"]}
|
package/dist/node-version.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare const MINIMUM_NODE_VERSION = "26.7.0";
|
|
2
|
+
declare const DEFAULT_NODE_VERSION = "26.13.1";
|
|
2
3
|
declare const assertSupportedNodeVersion: () => void;
|
|
3
|
-
export { assertSupportedNodeVersion, MINIMUM_NODE_VERSION };
|
|
4
|
+
export { assertSupportedNodeVersion, DEFAULT_NODE_VERSION, MINIMUM_NODE_VERSION };
|
|
4
5
|
//# sourceMappingURL=node-version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-version.d.ts","sourceRoot":"","sources":["../src/node-version.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,oBAAoB,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"node-version.d.ts","sourceRoot":"","sources":["../src/node-version.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,oBAAoB,WAAW,CAAC;AACtC,QAAA,MAAM,oBAAoB,YAAY,CAAC;AAEvC,QAAA,MAAM,0BAA0B,QAAO,IAStC,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/node-version.js
CHANGED
|
@@ -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
|
const assertSupportedNodeVersion = () => {
|
|
5
6
|
const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
|
|
6
7
|
const isSupported = major > MINIMUM_NODE_MAJOR || (major === MINIMUM_NODE_MAJOR && minor >= MINIMUM_NODE_MINOR);
|
|
@@ -8,5 +9,5 @@ const assertSupportedNodeVersion = () => {
|
|
|
8
9
|
throw new Error(`GTKX requires Node.js ${MINIMUM_NODE_VERSION} or newer. Current version: ${process.versions.node}.`);
|
|
9
10
|
}
|
|
10
11
|
};
|
|
11
|
-
export { assertSupportedNodeVersion, MINIMUM_NODE_VERSION };
|
|
12
|
+
export { assertSupportedNodeVersion, DEFAULT_NODE_VERSION, MINIMUM_NODE_VERSION };
|
|
12
13
|
//# sourceMappingURL=node-version.js.map
|
package/dist/node-version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-version.js","sourceRoot":"","sources":["../src/node-version.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,oBAAoB,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"node-version.js","sourceRoot":"","sources":["../src/node-version.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAEvC,MAAM,0BAA0B,GAAG,GAAS,EAAE;IAC1C,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5E,MAAM,WAAW,GAAG,KAAK,GAAG,kBAAkB,IAAI,CAAC,KAAK,KAAK,kBAAkB,IAAI,KAAK,IAAI,kBAAkB,CAAC,CAAC;IAEhH,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACX,yBAAyB,oBAAoB,+BAA+B,OAAO,CAAC,QAAQ,CAAC,IAAI,GAAG,CACvG,CAAC;IACN,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["const MINIMUM_NODE_MAJOR = 26;\nconst MINIMUM_NODE_MINOR = 7;\nconst MINIMUM_NODE_VERSION = \"26.7.0\";\nconst DEFAULT_NODE_VERSION = \"26.13.1\";\n\nconst assertSupportedNodeVersion = (): void => {\n const [major = 0, minor = 0] = process.versions.node.split(\".\").map(Number);\n const isSupported = major > MINIMUM_NODE_MAJOR || (major === MINIMUM_NODE_MAJOR && minor >= MINIMUM_NODE_MINOR);\n\n if (!isSupported) {\n throw new Error(\n `GTKX requires Node.js ${MINIMUM_NODE_VERSION} or newer. Current version: ${process.versions.node}.`,\n );\n }\n};\n\nexport { assertSupportedNodeVersion, DEFAULT_NODE_VERSION, MINIMUM_NODE_VERSION };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-base-path.d.ts","sourceRoot":"","sources":["../src/resource-base-path.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"resource-base-path.d.ts","sourceRoot":"","sources":["../src/resource-base-path.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,kBAAmB,MAAM,KAAG,MAAkD,CAAC;AAErG,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-text.d.ts","sourceRoot":"","sources":["../src/schema-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,QAAA,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"schema-text.d.ts","sourceRoot":"","sources":["../src/schema-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,QAAA,MAAM,IAAI,YAAa,MAAM,KAAG,CAAC,CAAC,SAAoE,CAAC;AAEvG,QAAA,MAAM,QAAQ,aAAc,MAAM,eAAe,MAAM,KAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CACJ,CAAC;AAE7E,QAAA,MAAM,GAAG,YAAa,MAAM,KAAG,CAAC,CAAC,MAAmC,CAAC;AACrE,QAAA,MAAM,IAAI,YAAa,MAAM,KAAG,CAAC,CAAC,UAA2C,CAAC;AAE9E,QAAA,MAAM,UAAU,iBAAkB,MAAM,iBAAiB,MAAM,KAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAChC,CAAC;AAEvE,QAAA,MAAM,aAAa,YAAa,MAAM,KAAG,CAAC,CAAC,SACuD,CAAC;AAEnG,QAAA,MAAM,UAAU,YAAa,MAAM,KAAG,CAAC,CAAC,SACmD,CAAC;AAK5F,QAAA,MAAM,kBAAkB,GAAI,KAAK,SAAS,CAAC,CAAC,OAAO,cACnC,MAAM,SACX,KAAK,iBACG,MAAM,KACtB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAwE,CAAC;AAE1G,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-event-signals.d.ts","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAuCA,QAAA,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"user-event-signals.d.ts","sourceRoot":"","sources":["../src/user-event-signals.ts"],"names":[],"mappings":"AAuCA,QAAA,MAAM,uBAAuB,cAAe,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CASzG,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/virtual.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "./config.ts";
|
|
2
2
|
declare const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
|
|
3
3
|
declare const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = "\0virtual:gtkx-config";
|
|
4
|
-
declare const renderConfigModule: (config: ResolvedConfig) => string;
|
|
4
|
+
declare const renderConfigModule: (config: ResolvedConfig, localeDir?: string | null) => string;
|
|
5
5
|
export { GTKX_CONFIG_VIRTUAL_ID, RESOLVED_GTKX_CONFIG_VIRTUAL_ID, renderConfigModule };
|
|
6
6
|
//# sourceMappingURL=virtual.d.ts.map
|
package/dist/virtual.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,QAAA,MAAM,sBAAsB,wBAAwB,CAAC;AACrD,QAAA,MAAM,+BAA+B,0BAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,QAAA,MAAM,sBAAsB,wBAAwB,CAAC;AACrD,QAAA,MAAM,+BAA+B,0BAAgC,CAAC;AAEtE,QAAA,MAAM,kBAAkB,WAAY,cAAc,cAAa,MAAM,GAAG,IAAI,KAAU,MAsBrF,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/virtual.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { resourceBasePath } from "./resource-base-path.js";
|
|
2
2
|
const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
|
|
3
3
|
const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\0${GTKX_CONFIG_VIRTUAL_ID}`;
|
|
4
|
-
const
|
|
5
|
-
const renderConfigModule = (config) => {
|
|
4
|
+
const renderConfigModule = (config, localeDir = null) => {
|
|
6
5
|
const lazyJson = JSON.stringify(Object.fromEntries(config.lazyElements.map((type) => [type, { isLazy: true }])));
|
|
7
6
|
const behaviorImports = config.elements === null
|
|
8
7
|
? []
|
|
9
8
|
: [
|
|
10
|
-
|
|
9
|
+
'import { mergeElementConfigs } from "@gtkx/react/config";',
|
|
11
10
|
`import __elementBehaviors from ${JSON.stringify(config.elements)};`,
|
|
12
11
|
];
|
|
13
12
|
return [
|
|
14
13
|
...behaviorImports,
|
|
15
|
-
`export * from ${JSON.stringify(METADATA_SPECIFIER)};`,
|
|
16
14
|
`export const applicationId = ${JSON.stringify(config.applicationId)};`,
|
|
15
|
+
`export const translationDomain = ${JSON.stringify(config.translationDomain)};`,
|
|
16
|
+
`export const localeDir = ${JSON.stringify(localeDir)};`,
|
|
17
17
|
`export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,
|
|
18
18
|
`export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
|
|
19
19
|
config.elements === null
|
package/dist/virtual.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual.js","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,+BAA+B,GAAG,KAAK,sBAAsB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual.js","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,+BAA+B,GAAG,KAAK,sBAAsB,EAAE,CAAC;AAEtE,MAAM,kBAAkB,GAAG,CAAC,MAAsB,EAAE,SAAS,GAAkB,IAAI,EAAU,EAAE;IAC3F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjH,MAAM,eAAe,GACjB,MAAM,CAAC,QAAQ,KAAK,IAAI;QACpB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;YACI,2DAA2D;YAC3D,kCAAkC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;SACvE,CAAC;IAEZ,OAAO;QACH,GAAG,eAAe;QAClB,gCAAgC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG;QACvE,oCAAoC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,GAAG;QAC/E,4BAA4B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG;QACxD,mCAAmC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG;QAC5F,mCAAmC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG;QAC7E,MAAM,CAAC,QAAQ,KAAK,IAAI;YACpB,CAAC,CAAC,2BAA2B,QAAQ,GAAG;YACxC,CAAC,CAAC,mEAAmE,QAAQ,IAAI;KACxF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import type { ResolvedConfig } from \"./config.ts\";\nimport { resourceBasePath } from \"./resource-base-path.ts\";\n\nconst GTKX_CONFIG_VIRTUAL_ID = \"virtual:gtkx-config\";\nconst RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\\0${GTKX_CONFIG_VIRTUAL_ID}`;\n\nconst renderConfigModule = (config: ResolvedConfig, localeDir: string | null = null): string => {\n const lazyJson = JSON.stringify(Object.fromEntries(config.lazyElements.map((type) => [type, { isLazy: true }])));\n\n const behaviorImports =\n config.elements === null\n ? []\n : [\n 'import { mergeElementConfigs } from \"@gtkx/react/config\";',\n `import __elementBehaviors from ${JSON.stringify(config.elements)};`,\n ];\n\n return [\n ...behaviorImports,\n `export const applicationId = ${JSON.stringify(config.applicationId)};`,\n `export const translationDomain = ${JSON.stringify(config.translationDomain)};`,\n `export const localeDir = ${JSON.stringify(localeDir)};`,\n `export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,\n `export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,\n config.elements === null\n ? `export const elements = ${lazyJson};`\n : `export const elements = mergeElementConfigs(__elementBehaviors, ${lazyJson});`,\n ].join(\"\\n\");\n};\n\nexport { GTKX_CONFIG_VIRTUAL_ID, RESOLVED_GTKX_CONFIG_VIRTUAL_ID, renderConfigModule };\n"]}
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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";
|
|
2
7
|
import { type ConfigLoader } from "./loader.ts";
|
|
3
8
|
/**
|
|
@@ -9,6 +14,8 @@ declare const createConfigPlugin: (options: {
|
|
|
9
14
|
name: string;
|
|
10
15
|
/** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
|
|
11
16
|
loadConfig?: ConfigLoader;
|
|
17
|
+
/** Catalog directory for development or tests, resolved relative to the project root. */
|
|
18
|
+
localeDir?: string | null | undefined;
|
|
12
19
|
/** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */
|
|
13
20
|
config?: (config: UserConfig) => Omit<UserConfig, "plugins">;
|
|
14
21
|
}) => Plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAE/C,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,aAAa,CAAC;AA8BpE;;;GAGG;AACH,QAAA,MAAM,kBAAkB,YAAa;IACjC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACtC,gHAAgH;IAChH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;CAChE,KAAG,MAoBH,CAAC;eAEa,kBAAkB"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
1
2
|
import { createConfigLoader } from "./loader.js";
|
|
2
3
|
import { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from "./virtual.js";
|
|
3
4
|
import { viteProjectRoot } from "./vite-root.js";
|
|
5
|
+
const VIRTUAL_ID_RE = new RegExp(`^${GTKX_CONFIG_VIRTUAL_ID}$`);
|
|
6
|
+
const RESOLVED_VIRTUAL_ID_RE = new RegExp(`^${RESOLVED_GTKX_CONFIG_VIRTUAL_ID}$`);
|
|
4
7
|
const resolveVirtualId = (id) => id === GTKX_CONFIG_VIRTUAL_ID ? RESOLVED_GTKX_CONFIG_VIRTUAL_ID : null;
|
|
5
|
-
const loadVirtualModule = async (id, loadConfig, state) => {
|
|
8
|
+
const loadVirtualModule = async (id, loadConfig, state, localeDir) => {
|
|
6
9
|
if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {
|
|
7
10
|
return undefined;
|
|
8
11
|
}
|
|
9
|
-
return renderConfigModule(await loadConfig.resolve(state.root));
|
|
12
|
+
return renderConfigModule(await loadConfig.resolve(state.root), localeDir == null ? null : resolve(state.root, localeDir));
|
|
10
13
|
};
|
|
11
14
|
/**
|
|
12
15
|
* Creates a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved
|
|
@@ -21,8 +24,14 @@ const createConfigPlugin = (options) => {
|
|
|
21
24
|
state.root = viteProjectRoot(config);
|
|
22
25
|
return options.config?.(config);
|
|
23
26
|
},
|
|
24
|
-
resolveId:
|
|
25
|
-
|
|
27
|
+
resolveId: {
|
|
28
|
+
filter: { id: VIRTUAL_ID_RE },
|
|
29
|
+
handler: (id) => resolveVirtualId(id),
|
|
30
|
+
},
|
|
31
|
+
load: {
|
|
32
|
+
filter: { id: RESOLVED_VIRTUAL_ID_RE },
|
|
33
|
+
handler: (id) => loadVirtualModule(id, loadConfig, state, options.localeDir),
|
|
34
|
+
},
|
|
26
35
|
};
|
|
27
36
|
};
|
|
28
37
|
export default createConfigPlugin;
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC3G,OAAO,EAAE,eA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,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC;SAChD;QACD,IAAI,EAAE;YACF,MAAM,EAAE,EAAE,EAAE,EAAE,sBAAsB,EAAE;YACtC,OAAO,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC;SACvF;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["/**\n * Vite plugin that serves the project's resolved `gtkx.config.ts` as `virtual:gtkx-config`.\n *\n * @packageDocumentation\n */\nimport type { Plugin, UserConfig } from \"vite\";\nimport { resolve } from \"node:path\";\nimport { type ConfigLoader, createConfigLoader } from \"./loader.ts\";\nimport { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from \"./virtual.ts\";\nimport { viteProjectRoot } from \"./vite-root.ts\";\n\ntype PluginState = {\n root: string;\n};\n\nconst VIRTUAL_ID_RE = new RegExp(`^${GTKX_CONFIG_VIRTUAL_ID}$`);\nconst RESOLVED_VIRTUAL_ID_RE = new RegExp(`^${RESOLVED_GTKX_CONFIG_VIRTUAL_ID}$`);\n\nconst resolveVirtualId = (id: string): string | null =>\n id === GTKX_CONFIG_VIRTUAL_ID ? RESOLVED_GTKX_CONFIG_VIRTUAL_ID : null;\n\nconst loadVirtualModule = async (\n id: string,\n loadConfig: ConfigLoader,\n state: PluginState,\n localeDir: string | null | undefined,\n): Promise<string | undefined> => {\n if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {\n return undefined;\n }\n\n return renderConfigModule(\n await loadConfig.resolve(state.root),\n localeDir == null ? null : resolve(state.root, localeDir),\n );\n};\n\n/**\n * Creates a Vite plugin serving `virtual:gtkx-config`, the module carrying the project's resolved\n * `gtkx.config.ts`.\n */\nconst createConfigPlugin = (options: {\n /** Name the plugin is registered under in Vite. */\n name: string;\n /** Loader the configuration is resolved through, defaulting to a fresh caching loader. */\n loadConfig?: ConfigLoader;\n /** Catalog directory for development or tests, resolved relative to the project root. */\n localeDir?: string | null | undefined;\n /** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */\n config?: (config: UserConfig) => Omit<UserConfig, \"plugins\">;\n}): Plugin => {\n const loadConfig = options.loadConfig ?? createConfigLoader();\n const state: PluginState = { root: process.cwd() };\n\n return {\n name: options.name,\n config(config: UserConfig) {\n state.root = viteProjectRoot(config);\n\n return options.config?.(config);\n },\n resolveId: {\n filter: { id: VIRTUAL_ID_RE },\n handler: (id: string) => resolveVirtualId(id),\n },\n load: {\n filter: { id: RESOLVED_VIRTUAL_ID_RE },\n handler: (id: string) => loadVirtualModule(id, loadConfig, state, options.localeDir),\n },\n };\n};\n\nexport default createConfigPlugin;\n"]}
|
package/dist/vite-root.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-root.d.ts","sourceRoot":"","sources":["../src/vite-root.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF,QAAA,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"vite-root.d.ts","sourceRoot":"","sources":["../src/vite-root.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF,QAAA,MAAM,eAAe,WAAY,UAAU,KAAG,MAA2D,CAAC;AAE1G,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/config",
|
|
3
|
-
"version": "2.0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Typed configuration for GTK apps built with GTKX.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
7
7
|
"gtk",
|
|
@@ -45,6 +45,12 @@
|
|
|
45
45
|
"import": "./dist/vite-plugin.js",
|
|
46
46
|
"require": null,
|
|
47
47
|
"default": "./dist/vite-plugin.js"
|
|
48
|
+
},
|
|
49
|
+
"./elements": {
|
|
50
|
+
"types": "./dist/builtin-elements.d.ts",
|
|
51
|
+
"import": "./dist/builtin-elements.js",
|
|
52
|
+
"require": null,
|
|
53
|
+
"default": "./dist/builtin-elements.js"
|
|
48
54
|
}
|
|
49
55
|
},
|
|
50
56
|
"sideEffects": false,
|
|
@@ -52,28 +58,21 @@
|
|
|
52
58
|
"dist",
|
|
53
59
|
"src"
|
|
54
60
|
],
|
|
55
|
-
"nx": {
|
|
56
|
-
"targets": {
|
|
57
|
-
"lint": {
|
|
58
|
-
"options": {
|
|
59
|
-
"cwd": ".",
|
|
60
|
-
"command": "eslint {projectRoot}"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
61
|
"engines": {
|
|
66
62
|
"node": ">=26.7.0"
|
|
67
63
|
},
|
|
68
64
|
"dependencies": {
|
|
69
|
-
"@gtkx/utils": "2.0.0
|
|
65
|
+
"@gtkx/utils": "^2.0.0",
|
|
70
66
|
"c12": "^3.3.4",
|
|
71
67
|
"defu": "^6.1.7",
|
|
72
68
|
"jiti": "^2.7.0",
|
|
73
|
-
"vite": "^8.
|
|
74
|
-
"zod": "^4.
|
|
69
|
+
"vite": "^8.4.0",
|
|
70
|
+
"zod": "^4.6.7"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"vitest": "5.1.2"
|
|
75
74
|
},
|
|
76
75
|
"scripts": {
|
|
77
|
-
"release": "
|
|
76
|
+
"release": "node ../../scripts/release/publish-package.ts"
|
|
78
77
|
}
|
|
79
78
|
}
|