@gtkx/config 2.0.0-beta.12 → 2.0.0-beta.13
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/dist/builtin-elements.d.ts +13 -1
- package/dist/builtin-elements.d.ts.map +1 -1
- package/dist/builtin-elements.js +47 -10
- package/dist/builtin-elements.js.map +1 -1
- package/dist/config-source.d.ts +2 -2
- package/dist/config-source.d.ts.map +1 -1
- package/dist/config-source.js +10 -7
- package/dist/config-source.js.map +1 -1
- package/dist/config.d.ts +147 -57
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +27 -72
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +370 -50
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +6 -161
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +20 -4
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +51 -18
- package/dist/loader.js.map +1 -1
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +1 -0
- package/dist/virtual.js.map +1 -1
- package/package.json +4 -4
- package/src/builtin-elements.ts +49 -10
- package/src/config-source.ts +11 -7
- package/src/config.ts +180 -91
- package/src/deploy.ts +431 -194
- package/src/index.ts +34 -2
- package/src/internal.ts +1 -0
- package/src/loader.ts +96 -22
- package/src/virtual.ts +1 -0
package/src/index.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
|
-
export { type Config, defineConfig, type ElementConfigOptions, mergeConfig, type ResolvedConfig } from "./config.ts";
|
|
2
1
|
export {
|
|
2
|
+
type AgentsOptions,
|
|
3
|
+
type ApplicationConfig,
|
|
4
|
+
type Config,
|
|
5
|
+
defineConfig,
|
|
6
|
+
type DeprecationsOptions,
|
|
7
|
+
type ElementConfigOptions,
|
|
8
|
+
type ElementPropsExport,
|
|
9
|
+
type ElementsOptions,
|
|
10
|
+
type McpOptions,
|
|
11
|
+
mergeConfig,
|
|
12
|
+
type ModuleExport,
|
|
13
|
+
type ReactCompilerOptions,
|
|
14
|
+
type ResolvedConfig,
|
|
15
|
+
} from "./config.ts";
|
|
16
|
+
export {
|
|
17
|
+
type DeployAppImageOptions,
|
|
18
|
+
type DeployAppImageSigningOptions,
|
|
19
|
+
type DeployBrandingOptions,
|
|
20
|
+
type DeployDebOptions,
|
|
21
|
+
type DeployDebPackageRelationOptions,
|
|
22
|
+
type DeployDebSigningOptions,
|
|
3
23
|
type DeployDesktopActionOptions,
|
|
24
|
+
type DeployDeveloperOptions,
|
|
4
25
|
type DeployExtraFileOptions,
|
|
5
26
|
type DeployFileAssociationOptions,
|
|
27
|
+
type DeployFlatpakOptions,
|
|
28
|
+
type DeployFlatpakSigningOptions,
|
|
29
|
+
type DeployFlatpakSourceOptions,
|
|
6
30
|
type DeployNodeOptions,
|
|
31
|
+
type DeployOptions,
|
|
32
|
+
type DeployPackageRelationOptions,
|
|
33
|
+
type DeployRelationsOptions,
|
|
7
34
|
type DeployReleaseOptions,
|
|
35
|
+
type DeployRpmOptions,
|
|
36
|
+
type DeployRpmSigningOptions,
|
|
8
37
|
type DeployScreenshotOptions,
|
|
38
|
+
type DeployScriptsOptions,
|
|
39
|
+
type DeploySigningOptions,
|
|
40
|
+
type DeployToolsOptions,
|
|
9
41
|
} from "./deploy.ts";
|
|
10
|
-
export { type ConfigLoader, type LoadedConfig, loadConfig } from "./loader.ts";
|
|
42
|
+
export { type ConfigLoader, type LoadConfigOptions, type LoadedConfig, loadConfig } from "./loader.ts";
|
package/src/internal.ts
CHANGED
package/src/loader.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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
5
|
import { relative, resolve } from "node:path";
|
|
5
6
|
import {
|
|
@@ -8,19 +9,36 @@ import {
|
|
|
8
9
|
createConfigImporter,
|
|
9
10
|
setConfigDependencies,
|
|
10
11
|
} from "./config-dependencies.ts";
|
|
11
|
-
import { missingConfigFileError } from "./config-error.ts";
|
|
12
|
-
import { type ConfigResolutionOptions,
|
|
13
|
-
import {
|
|
12
|
+
import { isRecord, missingConfigFileError } from "./config-error.ts";
|
|
13
|
+
import { configCandidatePaths, type ConfigResolutionOptions, localConfigSourcePaths } from "./config-source.ts";
|
|
14
|
+
import {
|
|
15
|
+
type ApplicationConfig,
|
|
16
|
+
type Config,
|
|
17
|
+
graduatedFutureKeys,
|
|
18
|
+
resolveConfig,
|
|
19
|
+
type ResolvedConfig,
|
|
20
|
+
validateConfig,
|
|
21
|
+
} from "./config.ts";
|
|
14
22
|
import { assertSupportedNodeVersion } from "./node-version.ts";
|
|
15
23
|
|
|
16
24
|
/** Result of loading a project's `gtkx.config.ts` file. */
|
|
17
25
|
type LoadedConfig = {
|
|
18
|
-
/** The parsed and validated configuration. */
|
|
19
|
-
config:
|
|
20
|
-
/**
|
|
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
|
+
*/
|
|
21
34
|
configFile: string;
|
|
22
35
|
/** Absolute path of the project root the configuration was resolved against. */
|
|
23
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;
|
|
24
42
|
};
|
|
25
43
|
|
|
26
44
|
/** How a configuration file is read, shared by {@link loadConfig} and `createConfigLoader`. */
|
|
@@ -32,6 +50,12 @@ type LoadConfigOptions = {
|
|
|
32
50
|
mode?: string | undefined;
|
|
33
51
|
/** Whether to report graduated future flags; supervising processes can own these warnings. Defaults to true. */
|
|
34
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;
|
|
35
59
|
} & Partial<Record<"configFile", string | undefined>>;
|
|
36
60
|
|
|
37
61
|
/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */
|
|
@@ -43,18 +67,53 @@ type ConfigLoader = {
|
|
|
43
67
|
};
|
|
44
68
|
|
|
45
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";
|
|
46
73
|
|
|
47
|
-
const
|
|
48
|
-
const path = localConfigSourcePath(source, options);
|
|
74
|
+
const recordOrEmpty = (value: unknown): Record<string, unknown> => (isRecord(value) ? value : {});
|
|
49
75
|
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
}
|
|
52
91
|
}
|
|
53
92
|
|
|
54
|
-
|
|
93
|
+
return merged;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const productionApplicationId = (layers: Record<string, unknown>[], config: ApplicationConfig): string => {
|
|
97
|
+
const { applicationId } = configForMode(layers, PRODUCTION_MODE);
|
|
98
|
+
|
|
99
|
+
return typeof applicationId === "string" ? applicationId : config.applicationId;
|
|
100
|
+
};
|
|
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 };
|
|
55
107
|
|
|
56
|
-
|
|
57
|
-
|
|
108
|
+
const rejectMissingLocalConfig = (source: string, options: ConfigResolutionOptions): undefined => {
|
|
109
|
+
const paths = localConfigSourcePaths(source, options);
|
|
110
|
+
|
|
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()}`);
|
|
58
117
|
}
|
|
59
118
|
};
|
|
60
119
|
|
|
@@ -84,6 +143,11 @@ const selectedConfigFile = (root: string, configured: string | undefined): strin
|
|
|
84
143
|
return relative(root, path);
|
|
85
144
|
};
|
|
86
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
|
+
|
|
87
151
|
const warnGraduatedFuture = (config: unknown, root: string): void => {
|
|
88
152
|
const keys = graduatedFutureKeys(config);
|
|
89
153
|
const signature = keys.join(",");
|
|
@@ -106,6 +170,7 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
106
170
|
assertSupportedNodeVersion();
|
|
107
171
|
const searched = resolve(cwd);
|
|
108
172
|
const requestedConfigFile = selectedConfigFile(searched, options.configFile);
|
|
173
|
+
const c12ConfigFile = explicitConfigFile(searched, requestedConfigFile);
|
|
109
174
|
|
|
110
175
|
const captured = await captureConfigDependencies(() =>
|
|
111
176
|
loadConfigFile<Config>({
|
|
@@ -114,12 +179,11 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
114
179
|
rcFile: false,
|
|
115
180
|
globalRc: false,
|
|
116
181
|
packageJson: false,
|
|
117
|
-
|
|
182
|
+
envName: false,
|
|
118
183
|
context: { mode: options.mode },
|
|
119
184
|
jiti: createConfigImporter(),
|
|
120
185
|
resolve: rejectMissingLocalConfig,
|
|
121
|
-
...(
|
|
122
|
-
...(options.mode !== undefined && { envName: options.mode }),
|
|
186
|
+
...(c12ConfigFile !== undefined && { configFile: c12ConfigFile }),
|
|
123
187
|
}),
|
|
124
188
|
);
|
|
125
189
|
const result = captured.value;
|
|
@@ -130,22 +194,32 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
130
194
|
layer.configFile === undefined ? [] : [resolve(layer.cwd ?? root, layer.configFile)],
|
|
131
195
|
);
|
|
132
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);
|
|
133
202
|
|
|
134
203
|
return withConfigDependencies(dependencies, () => {
|
|
135
|
-
if (
|
|
204
|
+
if (foundConfigFile === undefined && !isConfigFileOptional) {
|
|
136
205
|
throw missingConfigFileError(searched, requestedConfigFile);
|
|
137
206
|
}
|
|
138
207
|
|
|
139
|
-
const
|
|
140
|
-
|
|
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);
|
|
141
213
|
if (options.shouldWarnGraduatedFuture !== false) {
|
|
142
214
|
warnGraduatedFuture(config, root);
|
|
143
215
|
}
|
|
144
216
|
|
|
145
217
|
const loaded = {
|
|
146
218
|
config,
|
|
147
|
-
|
|
219
|
+
isApplication: authored.applicationId !== undefined,
|
|
220
|
+
configFile: loadedConfigFile,
|
|
148
221
|
root,
|
|
222
|
+
translationDomain: productionApplicationId(layers, config),
|
|
149
223
|
};
|
|
150
224
|
setConfigDependencies(loaded, dependencies);
|
|
151
225
|
|
|
@@ -162,9 +236,9 @@ const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {
|
|
|
162
236
|
loaded.getOrInsertComputed(resolve(cwd), (root) => loadConfig(root, options));
|
|
163
237
|
|
|
164
238
|
const resolveAt = async (root: string): Promise<ResolvedConfig> => {
|
|
165
|
-
const { config, root: configRoot } = await load(root);
|
|
239
|
+
const { config, root: configRoot, translationDomain } = await load(root);
|
|
166
240
|
|
|
167
|
-
return resolveConfig(config, configRoot);
|
|
241
|
+
return resolveConfig(config, translationDomain, configRoot);
|
|
168
242
|
};
|
|
169
243
|
|
|
170
244
|
return {
|
package/src/virtual.ts
CHANGED
|
@@ -18,6 +18,7 @@ const renderConfigModule = (config: ResolvedConfig, localeDir: string | null = n
|
|
|
18
18
|
return [
|
|
19
19
|
...behaviorImports,
|
|
20
20
|
`export const applicationId = ${JSON.stringify(config.applicationId)};`,
|
|
21
|
+
`export const translationDomain = ${JSON.stringify(config.translationDomain)};`,
|
|
21
22
|
`export const localeDir = ${JSON.stringify(localeDir)};`,
|
|
22
23
|
`export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,
|
|
23
24
|
`export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
|