@gtkx/config 2.0.0-beta.10 → 2.0.0-beta.12
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 +11 -0
- package/dist/builtin-elements.d.ts.map +1 -0
- package/dist/builtin-elements.js +329 -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 +32 -0
- package/dist/config-source.js.map +1 -0
- package/dist/config.d.ts +63 -29
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +72 -12
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +67 -13
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +169 -12
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -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 +3 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +18 -35
- 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 +3 -4
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +2 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +4 -3
- 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 +338 -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 +48 -0
- package/src/config.ts +87 -18
- package/src/deploy.ts +207 -29
- package/src/index.ts +9 -2
- package/src/internal.ts +5 -2
- package/src/loader.ts +27 -52
- package/src/node-version.ts +2 -1
- package/src/virtual.ts +5 -6
- package/src/vite-plugin.ts +9 -4
package/src/loader.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { isPathInside, warn } from "@gtkx/utils";
|
|
2
2
|
import { loadConfig as loadConfigFile } from "c12";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
|
-
import {
|
|
4
|
+
import { relative, resolve } from "node:path";
|
|
5
5
|
import {
|
|
6
|
+
addConfigSource,
|
|
6
7
|
captureConfigDependencies,
|
|
8
|
+
createConfigImporter,
|
|
7
9
|
setConfigDependencies,
|
|
8
|
-
transformConfigModule,
|
|
9
10
|
} from "./config-dependencies.ts";
|
|
10
11
|
import { missingConfigFileError } from "./config-error.ts";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
graduatedFutureKeys,
|
|
14
|
-
resolveConfig,
|
|
15
|
-
type ResolvedConfig,
|
|
16
|
-
validateConfig,
|
|
17
|
-
} from "./config.ts";
|
|
12
|
+
import { type ConfigResolutionOptions, localConfigSourcePath } from "./config-source.ts";
|
|
13
|
+
import { type Config, graduatedFutureKeys, resolveConfig, type ResolvedConfig, validateConfig } from "./config.ts";
|
|
18
14
|
import { assertSupportedNodeVersion } from "./node-version.ts";
|
|
19
15
|
|
|
20
16
|
/** Result of loading a project's `gtkx.config.ts` file. */
|
|
@@ -34,6 +30,8 @@ type LoadConfigOptions = {
|
|
|
34
30
|
* top-level values, and the name is passed to a config authored as a function.
|
|
35
31
|
*/
|
|
36
32
|
mode?: string | undefined;
|
|
33
|
+
/** Whether to report graduated future flags; supervising processes can own these warnings. Defaults to true. */
|
|
34
|
+
shouldWarnGraduatedFuture?: boolean | undefined;
|
|
37
35
|
} & Partial<Record<"configFile", string | undefined>>;
|
|
38
36
|
|
|
39
37
|
/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */
|
|
@@ -44,35 +42,18 @@ type ConfigLoader = {
|
|
|
44
42
|
resolve: (cwd: string) => Promise<ResolvedConfig>;
|
|
45
43
|
};
|
|
46
44
|
|
|
47
|
-
const GRADUATED_FUTURE_ENV = "GTKX_GRADUATED_FUTURE_SHOWN";
|
|
48
45
|
const graduatedFutureWarnings: Map<string, string> = new Map();
|
|
49
46
|
|
|
50
|
-
|
|
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);
|
|
58
|
-
};
|
|
47
|
+
const rejectMissingLocalConfig = (source: string, options: ConfigResolutionOptions): undefined => {
|
|
48
|
+
const path = localConfigSourcePath(source, options);
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return undefined;
|
|
50
|
+
if (path === undefined) {
|
|
51
|
+
return;
|
|
63
52
|
}
|
|
64
53
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return isDirectoryConfigSource(source)
|
|
68
|
-
? resolve(cwd, source, options.configFile ?? "gtkx.config")
|
|
69
|
-
: resolve(cwd, source);
|
|
70
|
-
};
|
|
54
|
+
addConfigSource(path);
|
|
71
55
|
|
|
72
|
-
|
|
73
|
-
const path = localConfigSourcePath(source, options);
|
|
74
|
-
|
|
75
|
-
if (path !== undefined && !existsSync(path)) {
|
|
56
|
+
if (!existsSync(path)) {
|
|
76
57
|
throw new Error(`Extended configuration does not exist at ${path}`);
|
|
77
58
|
}
|
|
78
59
|
};
|
|
@@ -107,16 +88,11 @@ const warnGraduatedFuture = (config: unknown, root: string): void => {
|
|
|
107
88
|
const keys = graduatedFutureKeys(config);
|
|
108
89
|
const signature = keys.join(",");
|
|
109
90
|
|
|
110
|
-
if (
|
|
111
|
-
keys.length === 0 ||
|
|
112
|
-
graduatedFutureWarnings.get(root) === signature ||
|
|
113
|
-
process.env[GRADUATED_FUTURE_ENV] === signature
|
|
114
|
-
) {
|
|
91
|
+
if (keys.length === 0 || graduatedFutureWarnings.get(root) === signature) {
|
|
115
92
|
return;
|
|
116
93
|
}
|
|
117
94
|
|
|
118
95
|
graduatedFutureWarnings.set(root, signature);
|
|
119
|
-
process.env[GRADUATED_FUTURE_ENV] = signature;
|
|
120
96
|
warn(`GTKX 2 ignores graduated future flags: ${keys.join(", ")}. Remove them from gtkx.config.ts.`);
|
|
121
97
|
};
|
|
122
98
|
|
|
@@ -138,25 +114,22 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
138
114
|
rcFile: false,
|
|
139
115
|
globalRc: false,
|
|
140
116
|
packageJson: false,
|
|
117
|
+
omit$Keys: true,
|
|
141
118
|
context: { mode: options.mode },
|
|
142
|
-
|
|
119
|
+
jiti: createConfigImporter(),
|
|
143
120
|
resolve: rejectMissingLocalConfig,
|
|
144
121
|
...(requestedConfigFile !== undefined && { configFile: requestedConfigFile }),
|
|
145
|
-
...(
|
|
146
|
-
})
|
|
122
|
+
...(options.mode !== undefined && { envName: options.mode }),
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
147
125
|
const result = captured.value;
|
|
148
126
|
|
|
149
127
|
const configFile = result.configFile;
|
|
150
128
|
const root = result.cwd ?? searched;
|
|
151
|
-
const layerFiles = (result.layers ?? [])
|
|
152
|
-
.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const dependencies = [
|
|
156
|
-
...(configFile === undefined ? [] : [configFile]),
|
|
157
|
-
...layerFiles,
|
|
158
|
-
...captured.dependencies,
|
|
159
|
-
];
|
|
129
|
+
const layerFiles = (result.layers ?? []).flatMap((layer) =>
|
|
130
|
+
layer.configFile === undefined ? [] : [resolve(layer.cwd ?? root, layer.configFile)],
|
|
131
|
+
);
|
|
132
|
+
const dependencies = [...(configFile === undefined ? [] : [configFile]), ...layerFiles, ...captured.dependencies];
|
|
160
133
|
|
|
161
134
|
return withConfigDependencies(dependencies, () => {
|
|
162
135
|
if (configFile === undefined || !existsSync(resolve(searched, configFile))) {
|
|
@@ -165,7 +138,9 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
165
138
|
|
|
166
139
|
const config = result.config;
|
|
167
140
|
validateConfig(config, configFile);
|
|
168
|
-
|
|
141
|
+
if (options.shouldWarnGraduatedFuture !== false) {
|
|
142
|
+
warnGraduatedFuture(config, root);
|
|
143
|
+
}
|
|
169
144
|
|
|
170
145
|
const loaded = {
|
|
171
146
|
config,
|
|
@@ -198,4 +173,4 @@ const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {
|
|
|
198
173
|
};
|
|
199
174
|
};
|
|
200
175
|
|
|
201
|
-
export { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader };
|
|
176
|
+
export { loadConfig, createConfigLoader, type LoadedConfig, type ConfigLoader, type LoadConfigOptions };
|
package/src/node-version.ts
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.8.2";
|
|
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,22 @@ 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
|
-
|
|
16
|
-
|
|
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 localeDir = ${JSON.stringify(localeDir)};`,
|
|
23
22
|
`export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,
|
|
24
23
|
`export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
|
|
25
24
|
config.elements === null
|
package/src/vite-plugin.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
|
+
import { resolve } from "node:path";
|
|
2
3
|
import { type ConfigLoader, createConfigLoader } from "./loader.ts";
|
|
3
4
|
import { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from "./virtual.ts";
|
|
4
5
|
import { viteProjectRoot } from "./vite-root.ts";
|
|
5
6
|
|
|
6
|
-
/** State the plugin carries from Vite's `config` hook to the virtual module it serves. */
|
|
7
7
|
type PluginState = {
|
|
8
|
-
/** Project root taken from Vite's `config` hook, falling back to the working directory. */
|
|
9
8
|
root: string;
|
|
10
9
|
};
|
|
11
10
|
|
|
@@ -19,12 +18,16 @@ const loadVirtualModule = async (
|
|
|
19
18
|
id: string,
|
|
20
19
|
loadConfig: ConfigLoader,
|
|
21
20
|
state: PluginState,
|
|
21
|
+
localeDir: string | null | undefined,
|
|
22
22
|
): Promise<string | undefined> => {
|
|
23
23
|
if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {
|
|
24
24
|
return undefined;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
return renderConfigModule(
|
|
27
|
+
return renderConfigModule(
|
|
28
|
+
await loadConfig.resolve(state.root),
|
|
29
|
+
localeDir == null ? null : resolve(state.root, localeDir),
|
|
30
|
+
);
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
/**
|
|
@@ -36,6 +39,8 @@ const createConfigPlugin = (options: {
|
|
|
36
39
|
name: string;
|
|
37
40
|
/** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
|
|
38
41
|
loadConfig?: ConfigLoader;
|
|
42
|
+
/** Catalog directory for development or tests, resolved relative to the project root. */
|
|
43
|
+
localeDir?: string | null | undefined;
|
|
39
44
|
/** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */
|
|
40
45
|
config?: (config: UserConfig) => Omit<UserConfig, "plugins">;
|
|
41
46
|
}): Plugin => {
|
|
@@ -55,7 +60,7 @@ const createConfigPlugin = (options: {
|
|
|
55
60
|
},
|
|
56
61
|
load: {
|
|
57
62
|
filter: { id: RESOLVED_VIRTUAL_ID_RE },
|
|
58
|
-
handler: (id: string) => loadVirtualModule(id, loadConfig, state),
|
|
63
|
+
handler: (id: string) => loadVirtualModule(id, loadConfig, state, options.localeDir),
|
|
59
64
|
},
|
|
60
65
|
};
|
|
61
66
|
};
|