@gtkx/cli 1.2.2 → 1.4.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 +6 -4
- package/dist/builder.d.ts +0 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +6 -6
- package/dist/builder.js.map +1 -1
- package/dist/codegen/freshness.js +1 -1
- package/dist/codegen/freshness.js.map +1 -1
- package/dist/codegen/run-codegen.d.ts +2 -2
- package/dist/codegen/run-codegen.d.ts.map +1 -1
- package/dist/codegen/run-codegen.js +28 -9
- package/dist/codegen/run-codegen.js.map +1 -1
- package/dist/commands/build.d.ts +0 -4
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +0 -5
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +1 -3
- package/dist/commands/codegen.js.map +1 -1
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +3 -0
- package/dist/commands/docs.js.map +1 -1
- package/dist/deploy/depends.d.ts +2 -2
- package/dist/deploy/depends.d.ts.map +1 -1
- package/dist/deploy/depends.js +30 -15
- package/dist/deploy/depends.js.map +1 -1
- package/dist/deploy/nfpm/config.js +1 -1
- package/dist/deploy/nfpm/config.js.map +1 -1
- package/dist/deploy/node-runtime/elf.d.ts +1 -1
- package/dist/deploy/node-runtime/elf.d.ts.map +1 -1
- package/dist/deploy/node-runtime/elf.js +2 -2
- package/dist/deploy/node-runtime/elf.js.map +1 -1
- package/dist/deploy/node-runtime/index.js +2 -2
- package/dist/deploy/node-runtime/index.js.map +1 -1
- package/dist/deploy/notices/collect.d.ts +3 -1
- package/dist/deploy/notices/collect.d.ts.map +1 -1
- package/dist/deploy/notices/collect.js +2 -2
- package/dist/deploy/notices/collect.js.map +1 -1
- package/dist/deploy/notices/packages.d.ts +2 -1
- package/dist/deploy/notices/packages.d.ts.map +1 -1
- package/dist/deploy/notices/packages.js +4 -27
- package/dist/deploy/notices/packages.js.map +1 -1
- package/dist/deploy/payload/icons.d.ts +7 -3
- package/dist/deploy/payload/icons.d.ts.map +1 -1
- package/dist/deploy/payload/icons.js +46 -28
- package/dist/deploy/payload/icons.js.map +1 -1
- package/dist/deploy/payload/stage.d.ts.map +1 -1
- package/dist/deploy/payload/stage.js +3 -2
- package/dist/deploy/payload/stage.js.map +1 -1
- package/dist/deploy/run-deploy.d.ts.map +1 -1
- package/dist/deploy/run-deploy.js +63 -11
- package/dist/deploy/run-deploy.js.map +1 -1
- package/dist/deploy/settings/build-manifest.d.ts +9 -0
- package/dist/deploy/settings/build-manifest.d.ts.map +1 -0
- package/dist/deploy/settings/build-manifest.js +80 -0
- package/dist/deploy/settings/build-manifest.js.map +1 -0
- package/dist/deploy/settings/index.d.ts.map +1 -1
- package/dist/deploy/settings/index.js +9 -3
- package/dist/deploy/settings/index.js.map +1 -1
- package/dist/deploy/settings/libraries.d.ts +8 -0
- package/dist/deploy/settings/libraries.d.ts.map +1 -0
- package/dist/deploy/settings/libraries.js +39 -0
- package/dist/deploy/settings/libraries.js.map +1 -0
- package/dist/deploy/settings/paths.d.ts +3 -0
- package/dist/deploy/settings/paths.d.ts.map +1 -1
- package/dist/deploy/settings/paths.js +6 -32
- package/dist/deploy/settings/paths.js.map +1 -1
- package/dist/deploy/targets/appimage.d.ts.map +1 -1
- package/dist/deploy/targets/appimage.js +19 -13
- package/dist/deploy/targets/appimage.js.map +1 -1
- package/dist/deploy/targets/flatpak-manifest.d.ts +2 -1
- package/dist/deploy/targets/flatpak-manifest.d.ts.map +1 -1
- package/dist/deploy/targets/flatpak-manifest.js +5 -1
- package/dist/deploy/targets/flatpak-manifest.js.map +1 -1
- package/dist/deploy/targets/flatpak-pnpm.js +4 -4
- package/dist/deploy/targets/flatpak-pnpm.js.map +1 -1
- package/dist/deploy/targets/flatpak-source.d.ts.map +1 -1
- package/dist/deploy/targets/flatpak-source.js +9 -6
- package/dist/deploy/targets/flatpak-source.js.map +1 -1
- package/dist/deploy/types.d.ts +4 -4
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/deploy/types.js.map +1 -1
- package/dist/dev/icon-dir.d.ts +1 -1
- package/dist/dev/icon-dir.d.ts.map +1 -1
- package/dist/dev/icon-dir.js +20 -7
- package/dist/dev/icon-dir.js.map +1 -1
- package/dist/dev/runner-deps.d.ts.map +1 -1
- package/dist/dev/runner-deps.js +5 -1
- package/dist/dev/runner-deps.js.map +1 -1
- package/dist/dev/runner-main.js +4 -4
- package/dist/dev/runner-main.js.map +1 -1
- package/dist/dev/runner.d.ts +1 -1
- package/dist/dev/runner.d.ts.map +1 -1
- package/dist/dev/runner.js +1 -1
- package/dist/dev/runner.js.map +1 -1
- package/dist/dev/schema-dir.d.ts +1 -1
- package/dist/dev/schema-dir.d.ts.map +1 -1
- package/dist/dev/schema-dir.js +3 -1
- package/dist/dev/schema-dir.js.map +1 -1
- package/dist/internal/build-manifest.d.ts +20 -0
- package/dist/internal/build-manifest.d.ts.map +1 -0
- package/dist/internal/build-manifest.js +6 -0
- package/dist/internal/build-manifest.js.map +1 -0
- package/dist/internal/icon-path.d.ts +13 -0
- package/dist/internal/icon-path.d.ts.map +1 -0
- package/dist/internal/icon-path.js +86 -0
- package/dist/internal/icon-path.js.map +1 -0
- package/dist/internal/source-imports.d.ts +8 -0
- package/dist/internal/source-imports.d.ts.map +1 -0
- package/dist/internal/source-imports.js +144 -0
- package/dist/internal/source-imports.js.map +1 -0
- package/dist/mcp/widget-properties.d.ts.map +1 -1
- package/dist/mcp/widget-properties.js +3 -12
- package/dist/mcp/widget-properties.js.map +1 -1
- package/dist/settings/render.d.ts +7 -1
- package/dist/settings/render.d.ts.map +1 -1
- package/dist/settings/render.js +69 -20
- package/dist/settings/render.js.map +1 -1
- package/dist/settings/schema.d.ts +4 -3
- package/dist/settings/schema.d.ts.map +1 -1
- package/dist/settings/schema.js +122 -15
- package/dist/settings/schema.js.map +1 -1
- package/dist/vite-plugins/asset-emitter.d.ts +1 -1
- package/dist/vite-plugins/asset-emitter.d.ts.map +1 -1
- package/dist/vite-plugins/asset-emitter.js.map +1 -1
- package/dist/vite-plugins/asset-extensions.d.ts.map +1 -1
- package/dist/vite-plugins/asset-extensions.js +1 -0
- package/dist/vite-plugins/asset-extensions.js.map +1 -1
- package/dist/vite-plugins/asset-imports.d.ts +2 -1
- package/dist/vite-plugins/asset-imports.d.ts.map +1 -1
- package/dist/vite-plugins/asset-imports.js +37 -16
- package/dist/vite-plugins/asset-imports.js.map +1 -1
- package/dist/vite-plugins/asset-specifier.d.ts +13 -1
- package/dist/vite-plugins/asset-specifier.d.ts.map +1 -1
- package/dist/vite-plugins/asset-specifier.js +39 -1
- package/dist/vite-plugins/asset-specifier.js.map +1 -1
- package/dist/vite-plugins/build-manifest.d.ts +5 -0
- package/dist/vite-plugins/build-manifest.d.ts.map +1 -0
- package/dist/vite-plugins/{bundled-packages.js → build-manifest.js} +20 -14
- package/dist/vite-plugins/build-manifest.js.map +1 -0
- package/dist/vite-plugins/built-url.d.ts +1 -1
- package/dist/vite-plugins/built-url.d.ts.map +1 -1
- package/dist/vite-plugins/built-url.js +37 -24
- package/dist/vite-plugins/built-url.js.map +1 -1
- package/dist/vite-plugins/icons.d.ts +2 -1
- package/dist/vite-plugins/icons.d.ts.map +1 -1
- package/dist/vite-plugins/icons.js +25 -12
- package/dist/vite-plugins/icons.js.map +1 -1
- package/dist/vite-plugins/index.d.ts +2 -1
- package/dist/vite-plugins/index.d.ts.map +1 -1
- package/dist/vite-plugins/index.js +7 -5
- package/dist/vite-plugins/index.js.map +1 -1
- package/dist/vite-plugins/native.d.ts.map +1 -1
- package/dist/vite-plugins/native.js +23 -4
- package/dist/vite-plugins/native.js.map +1 -1
- package/dist/vite-plugins/resource-init-module.d.ts +7 -3
- package/dist/vite-plugins/resource-init-module.d.ts.map +1 -1
- package/dist/vite-plugins/resource-init-module.js +39 -14
- package/dist/vite-plugins/resource-init-module.js.map +1 -1
- package/dist/vite-plugins/resource-shared.d.ts +3 -1
- package/dist/vite-plugins/resource-shared.d.ts.map +1 -1
- package/dist/vite-plugins/resource-shared.js +3 -1
- package/dist/vite-plugins/resource-shared.js.map +1 -1
- package/dist/vite-plugins/resources.d.ts +1 -1
- package/dist/vite-plugins/resources.d.ts.map +1 -1
- package/dist/vite-plugins/resources.js +922 -86
- package/dist/vite-plugins/resources.js.map +1 -1
- package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
- package/dist/vite-plugins/settings-worker-env.js +6 -3
- package/dist/vite-plugins/settings-worker-env.js.map +1 -1
- package/dist/vite-plugins/settings.d.ts +3 -1
- package/dist/vite-plugins/settings.d.ts.map +1 -1
- package/dist/vite-plugins/settings.js +63 -23
- package/dist/vite-plugins/settings.js.map +1 -1
- package/dist/vite-plugins/store-links.js +1 -1
- package/dist/vite-plugins/store-links.js.map +1 -1
- package/dist/vite-plugins/undeclared-library.d.ts.map +1 -1
- package/dist/vite-plugins/undeclared-library.js +25 -13
- package/dist/vite-plugins/undeclared-library.js.map +1 -1
- package/env.d.ts +11 -192
- package/package.json +14 -14
- package/src/builder.ts +6 -7
- package/src/codegen/freshness.ts +1 -1
- package/src/codegen/run-codegen.ts +33 -10
- package/src/commands/build.ts +0 -5
- package/src/commands/codegen.ts +1 -3
- package/src/commands/docs.ts +3 -0
- package/src/deploy/depends.ts +47 -18
- package/src/deploy/nfpm/config.ts +1 -1
- package/src/deploy/node-runtime/elf.ts +3 -3
- package/src/deploy/node-runtime/index.ts +2 -2
- package/src/deploy/notices/collect.ts +4 -2
- package/src/deploy/notices/packages.ts +5 -43
- package/src/deploy/payload/icons.ts +64 -34
- package/src/deploy/payload/stage.ts +5 -2
- package/src/deploy/run-deploy.ts +87 -12
- package/src/deploy/settings/build-manifest.ts +122 -0
- package/src/deploy/settings/index.ts +9 -4
- package/src/deploy/settings/libraries.ts +57 -0
- package/src/deploy/settings/paths.ts +10 -47
- package/src/deploy/targets/appimage.ts +32 -15
- package/src/deploy/targets/flatpak-manifest.ts +7 -1
- package/src/deploy/targets/flatpak-pnpm.ts +4 -4
- package/src/deploy/targets/flatpak-source.ts +9 -10
- package/src/deploy/types.ts +4 -4
- package/src/dev/icon-dir.ts +31 -7
- package/src/dev/runner-deps.ts +5 -1
- package/src/dev/runner-main.ts +4 -4
- package/src/dev/runner.ts +2 -2
- package/src/dev/schema-dir.ts +3 -1
- package/src/internal/build-manifest.ts +32 -0
- package/src/internal/icon-path.ts +127 -0
- package/src/internal/source-imports.ts +200 -0
- package/src/mcp/widget-properties.ts +3 -14
- package/src/settings/render.ts +99 -21
- package/src/settings/schema.ts +190 -17
- package/src/vite-plugins/asset-emitter.ts +1 -1
- package/src/vite-plugins/asset-extensions.ts +1 -0
- package/src/vite-plugins/asset-imports.ts +60 -19
- package/src/vite-plugins/asset-specifier.ts +73 -1
- package/src/vite-plugins/{bundled-packages.ts → build-manifest.ts} +30 -19
- package/src/vite-plugins/built-url.ts +49 -28
- package/src/vite-plugins/icons.ts +33 -14
- package/src/vite-plugins/index.ts +12 -5
- package/src/vite-plugins/native.ts +31 -4
- package/src/vite-plugins/resource-init-module.ts +44 -15
- package/src/vite-plugins/resource-shared.ts +4 -0
- package/src/vite-plugins/resources.ts +1459 -100
- package/src/vite-plugins/settings-worker-env.ts +7 -3
- package/src/vite-plugins/settings.ts +89 -21
- package/src/vite-plugins/store-links.ts +1 -1
- package/src/vite-plugins/undeclared-library.ts +31 -13
- package/dist/vite-plugins/bundled-packages.d.ts +0 -5
- package/dist/vite-plugins/bundled-packages.d.ts.map +0 -1
- package/dist/vite-plugins/bundled-packages.js.map +0 -1
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { UserConfig } from "vite";
|
|
2
2
|
import type { Plugin } from "vitest/config";
|
|
3
|
+
import { createConfigLoader } from "@gtkx/config/internal";
|
|
3
4
|
import { resolveDataDir } from "../internal/data-dir.js";
|
|
4
5
|
import { prependSchemaDir, stageAndCompileProjectSchemas } from "../settings/schema.js";
|
|
5
6
|
|
|
6
7
|
function gtkxSettingsWorkerEnv(): Plugin {
|
|
8
|
+
const loadConfig = createConfigLoader();
|
|
9
|
+
|
|
7
10
|
return {
|
|
8
11
|
name: "gtkx:settings-worker-env",
|
|
9
12
|
enforce: "pre",
|
|
10
13
|
|
|
11
|
-
config(config: UserConfig) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
+
async config(config: UserConfig) {
|
|
15
|
+
const loaded = await loadConfig.load(config.root ?? process.cwd());
|
|
16
|
+
const dataDir = loaded.config.future?.v2ResourceImports === true ? null : resolveDataDir(loaded.root);
|
|
17
|
+
const dir = stageAndCompileProjectSchemas(loaded.root, dataDir);
|
|
14
18
|
|
|
15
19
|
if (dir === null) {
|
|
16
20
|
return;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { ConfigLoader } from "@gtkx/config";
|
|
1
2
|
import type { ModuleNode, Plugin, ResolvedConfig, UserConfig, ViteDevServer } from "vite";
|
|
2
|
-
import { error, errorMessage, info } from "@gtkx/utils";
|
|
3
|
+
import { error, errorMessage, info, sortStrings } from "@gtkx/utils";
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
4
5
|
import { basename, join } from "node:path";
|
|
6
|
+
import type { BuildManifestCollector } from "../internal/build-manifest.js";
|
|
5
7
|
import type { AssetEmitter } from "./asset-emitter.js";
|
|
6
8
|
import { prependBanner } from "../internal/banner.js";
|
|
7
9
|
import { resolveDataDir } from "../internal/data-dir.js";
|
|
@@ -9,14 +11,23 @@ import { createRetainedStagingDir, type RetainedStagingDir, withStagingDir } fro
|
|
|
9
11
|
import { compileSchemas } from "../settings/compile.js";
|
|
10
12
|
import { parseSchemaXml, SchemaParseError } from "../settings/parser.js";
|
|
11
13
|
import { renderRuntimeModule } from "../settings/render.js";
|
|
12
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
assertUniqueSchemaBasenames,
|
|
16
|
+
emitSchemaEnv,
|
|
17
|
+
prependSchemaDir,
|
|
18
|
+
projectRelativeSchemaPath,
|
|
19
|
+
SCHEMA_SUFFIX,
|
|
20
|
+
stageSchema,
|
|
21
|
+
} from "../settings/schema.js";
|
|
13
22
|
import { createVirtualNamespace } from "./virtual-module.js";
|
|
14
23
|
|
|
15
24
|
type PluginState = {
|
|
16
25
|
schemaDir: RetainedStagingDir;
|
|
17
26
|
rootDir: string | null;
|
|
18
27
|
dataDir: string | null;
|
|
28
|
+
isV2ResourceImports: boolean;
|
|
19
29
|
isBuild: boolean;
|
|
30
|
+
schemaEnvTimer: ReturnType<typeof setTimeout> | null;
|
|
20
31
|
trackedSchemas: Map<string, string>;
|
|
21
32
|
buildSchemas: Set<string>;
|
|
22
33
|
};
|
|
@@ -27,6 +38,8 @@ type PluginContext = AssetEmitter & {
|
|
|
27
38
|
|
|
28
39
|
const VIRTUAL_PREFIX = "\0gtkx-settings:";
|
|
29
40
|
const SCHEMA_STAGING_PREFIX = "schemas";
|
|
41
|
+
const SOURCE_MODULE_RE = /\.[cm]?[jt]sx?$/;
|
|
42
|
+
const SCHEMA_ENV_DEBOUNCE_MS = 50;
|
|
30
43
|
const { isVirtual, fromVirtualId, resolveToVirtual } = createVirtualNamespace(VIRTUAL_PREFIX);
|
|
31
44
|
|
|
32
45
|
const SCHEMA_ENV_BANNER = [
|
|
@@ -67,14 +80,34 @@ const syncSchemaEnv = (state: PluginState): void => {
|
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
try {
|
|
70
|
-
emitSchemaEnv(state.rootDir, state.dataDir);
|
|
83
|
+
emitSchemaEnv(state.rootDir, state.dataDir, state.isV2ResourceImports);
|
|
71
84
|
} catch (error_) {
|
|
72
85
|
error(`Failed to generate GSettings schema types: ${errorMessage(error_)}`);
|
|
73
86
|
}
|
|
74
87
|
};
|
|
75
88
|
|
|
76
|
-
const
|
|
77
|
-
|
|
89
|
+
const cancelSchemaEnvSync = (state: PluginState): void => {
|
|
90
|
+
if (state.schemaEnvTimer === null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
clearTimeout(state.schemaEnvTimer);
|
|
95
|
+
state.schemaEnvTimer = null;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const scheduleSchemaEnvSync = (state: PluginState): void => {
|
|
99
|
+
cancelSchemaEnvSync(state);
|
|
100
|
+
|
|
101
|
+
state.schemaEnvTimer = setTimeout(() => {
|
|
102
|
+
state.schemaEnvTimer = null;
|
|
103
|
+
syncSchemaEnv(state);
|
|
104
|
+
}, SCHEMA_ENV_DEBOUNCE_MS);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const applyUserConfig = async (state: PluginState, config: UserConfig, loadConfig: ConfigLoader): Promise<void> => {
|
|
108
|
+
const loaded = await loadConfig.load(config.root ?? process.cwd());
|
|
109
|
+
state.isV2ResourceImports = loaded.config.future?.v2ResourceImports === true;
|
|
110
|
+
state.dataDir = state.isV2ResourceImports ? null : resolveDataDir(loaded.root);
|
|
78
111
|
};
|
|
79
112
|
|
|
80
113
|
const applyResolvedConfig = (state: PluginState, config: ResolvedConfig): void => {
|
|
@@ -128,13 +161,9 @@ const loadSchemaModule = (ctx: PluginContext, state: PluginState, id: string): s
|
|
|
128
161
|
return renderRuntimeModule(parsed);
|
|
129
162
|
};
|
|
130
163
|
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const compiled = withStagingDir("schemas-build", (dir) => {
|
|
137
|
-
for (const filePath of state.buildSchemas) {
|
|
164
|
+
const compileBuildSchemas = (schemaFiles: string[]): Buffer =>
|
|
165
|
+
withStagingDir("schemas-build", (dir) => {
|
|
166
|
+
for (const filePath of schemaFiles) {
|
|
138
167
|
stageSchema(dir, filePath);
|
|
139
168
|
}
|
|
140
169
|
|
|
@@ -143,18 +172,53 @@ const emitCompiledSchemas = (ctx: PluginContext, state: PluginState): void => {
|
|
|
143
172
|
return readFileSync(join(dir, "gschemas.compiled"));
|
|
144
173
|
});
|
|
145
174
|
|
|
175
|
+
const buildSchemaPaths = (rootDir: string, schemaFiles: string[]): string[] =>
|
|
176
|
+
schemaFiles.map((filePath) => {
|
|
177
|
+
const rel = projectRelativeSchemaPath(rootDir, filePath);
|
|
178
|
+
|
|
179
|
+
if (rel === null) {
|
|
180
|
+
throw new Error(`Cannot package the GSettings schema ${filePath}: it is outside ${rootDir}`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return rel;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const emitBuildSchemas = (
|
|
187
|
+
ctx: PluginContext,
|
|
188
|
+
state: PluginState,
|
|
189
|
+
buildManifest: BuildManifestCollector | undefined,
|
|
190
|
+
): void => {
|
|
191
|
+
if (!state.isBuild || state.rootDir === null) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const rootDir = state.rootDir;
|
|
196
|
+
const schemaFiles = sortStrings(state.buildSchemas);
|
|
197
|
+
assertUniqueSchemaBasenames(schemaFiles);
|
|
198
|
+
const schemas = buildSchemaPaths(rootDir, schemaFiles);
|
|
199
|
+
|
|
200
|
+
if (buildManifest !== undefined) {
|
|
201
|
+
buildManifest.schemas = schemas;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (schemaFiles.length === 0) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const compiled = compileBuildSchemas(schemaFiles);
|
|
209
|
+
|
|
146
210
|
ctx.emitFile({
|
|
147
211
|
type: "asset",
|
|
148
212
|
fileName: "gschemas.compiled",
|
|
149
213
|
source: compiled,
|
|
150
214
|
});
|
|
151
215
|
|
|
152
|
-
info(`Compiled ${String(
|
|
216
|
+
info(`Compiled ${String(schemaFiles.length)} GSettings schema(s)`);
|
|
153
217
|
};
|
|
154
218
|
|
|
155
219
|
const handleSchemaHotUpdate = (state: PluginState, file: string, server: ViteDevServer): ModuleNode[] | undefined => {
|
|
156
|
-
if (file.endsWith(SCHEMA_SUFFIX)) {
|
|
157
|
-
|
|
220
|
+
if (file.endsWith(SCHEMA_SUFFIX) || SOURCE_MODULE_RE.test(file)) {
|
|
221
|
+
scheduleSchemaEnvSync(state);
|
|
158
222
|
}
|
|
159
223
|
|
|
160
224
|
const virtualId = state.trackedSchemas.get(file);
|
|
@@ -180,6 +244,7 @@ const handleSchemaHotUpdate = (state: PluginState, file: string, server: ViteDev
|
|
|
180
244
|
|
|
181
245
|
const watchSchemaFiles = (state: PluginState, server: ViteDevServer): void => {
|
|
182
246
|
const onClose = (): void => {
|
|
247
|
+
cancelSchemaEnvSync(state);
|
|
183
248
|
state.schemaDir.release();
|
|
184
249
|
};
|
|
185
250
|
|
|
@@ -187,8 +252,8 @@ const watchSchemaFiles = (state: PluginState, server: ViteDevServer): void => {
|
|
|
187
252
|
server.watcher.once("close", onClose);
|
|
188
253
|
|
|
189
254
|
const refreshSchemaTypes = (file: string): void => {
|
|
190
|
-
if (file.endsWith(SCHEMA_SUFFIX)) {
|
|
191
|
-
|
|
255
|
+
if (file.endsWith(SCHEMA_SUFFIX) || SOURCE_MODULE_RE.test(file)) {
|
|
256
|
+
scheduleSchemaEnvSync(state);
|
|
192
257
|
}
|
|
193
258
|
};
|
|
194
259
|
|
|
@@ -196,12 +261,14 @@ const watchSchemaFiles = (state: PluginState, server: ViteDevServer): void => {
|
|
|
196
261
|
server.watcher.on("unlink", refreshSchemaTypes);
|
|
197
262
|
};
|
|
198
263
|
|
|
199
|
-
function gtkxSettings(): Plugin {
|
|
264
|
+
function gtkxSettings(loadConfig: ConfigLoader, buildManifest?: BuildManifestCollector): Plugin {
|
|
200
265
|
const state: PluginState = {
|
|
201
266
|
schemaDir: createRetainedStagingDir(SCHEMA_STAGING_PREFIX),
|
|
202
267
|
rootDir: null,
|
|
203
268
|
dataDir: null,
|
|
269
|
+
isV2ResourceImports: false,
|
|
204
270
|
isBuild: false,
|
|
271
|
+
schemaEnvTimer: null,
|
|
205
272
|
trackedSchemas: new Map(),
|
|
206
273
|
buildSchemas: new Set(),
|
|
207
274
|
};
|
|
@@ -210,8 +277,8 @@ function gtkxSettings(): Plugin {
|
|
|
210
277
|
name: "gtkx:settings",
|
|
211
278
|
enforce: "pre",
|
|
212
279
|
|
|
213
|
-
config(config: UserConfig) {
|
|
214
|
-
applyUserConfig(state, config);
|
|
280
|
+
async config(config: UserConfig) {
|
|
281
|
+
await applyUserConfig(state, config, loadConfig);
|
|
215
282
|
},
|
|
216
283
|
|
|
217
284
|
configResolved(config) {
|
|
@@ -243,10 +310,11 @@ function gtkxSettings(): Plugin {
|
|
|
243
310
|
},
|
|
244
311
|
|
|
245
312
|
buildEnd() {
|
|
246
|
-
|
|
313
|
+
emitBuildSchemas(this, state, buildManifest);
|
|
247
314
|
},
|
|
248
315
|
|
|
249
316
|
closeBundle() {
|
|
317
|
+
cancelSchemaEnvSync(state);
|
|
250
318
|
state.schemaDir.release();
|
|
251
319
|
},
|
|
252
320
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
2
|
import { ensureStoreLinks } from "@gtkx/codegen/internal";
|
|
3
3
|
|
|
4
|
-
const GENERATED_MODULE_PREFIX = /^@gtkx\/(?:gi
|
|
4
|
+
const GENERATED_MODULE_PREFIX = /^@gtkx\/(?:gi\/|jsx(?:\/|$))/;
|
|
5
5
|
|
|
6
6
|
function gtkxStoreLinks(): Plugin {
|
|
7
7
|
const state = { root: "" };
|
|
@@ -15,7 +15,7 @@ type PluginState = {
|
|
|
15
15
|
type GeneratedModule = {
|
|
16
16
|
source: string;
|
|
17
17
|
kind: string;
|
|
18
|
-
namespace: string;
|
|
18
|
+
namespace: string | null;
|
|
19
19
|
importer: string;
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -36,6 +36,10 @@ const findGirIdentifier = (girPath: string[], namespace: string): string | undef
|
|
|
36
36
|
discoverGirNamespaces(girPath).find((identifier) => getNamespace(identifier) === namespace);
|
|
37
37
|
|
|
38
38
|
const parseGeneratedModule = (source: string, importer: string | undefined): GeneratedModule | null => {
|
|
39
|
+
if (source === "@gtkx/jsx") {
|
|
40
|
+
return { source, kind: "jsx", namespace: null, importer: importer ?? "the project's sources" };
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
const matched = GENERATED_MODULE_PATTERN.exec(source);
|
|
40
44
|
const kind = matched?.[1];
|
|
41
45
|
const namespace = matched?.[2];
|
|
@@ -57,7 +61,7 @@ const getStoreOptions = (root: string, kind: string): StoreOptions | null => {
|
|
|
57
61
|
}
|
|
58
62
|
};
|
|
59
63
|
|
|
60
|
-
const
|
|
64
|
+
const hasStoreModule = (storeDir: string, exportKey: string): boolean => {
|
|
61
65
|
const manifest = join(storeDir, "package.json");
|
|
62
66
|
|
|
63
67
|
if (!existsSync(manifest)) {
|
|
@@ -66,43 +70,57 @@ const hasNamespaceModule = (storeDir: string, namespace: string): boolean => {
|
|
|
66
70
|
|
|
67
71
|
const { exports } = JSON.parse(readFileSync(manifest, "utf8")) as { exports?: Record<string, unknown> };
|
|
68
72
|
|
|
69
|
-
return exports?.[
|
|
73
|
+
return exports?.[exportKey] !== undefined;
|
|
70
74
|
};
|
|
71
75
|
|
|
72
|
-
const unreachableStoreError = (generated: GeneratedModule, options: StoreOptions): Error =>
|
|
73
|
-
|
|
76
|
+
const unreachableStoreError = (generated: GeneratedModule, options: StoreOptions): Error => {
|
|
77
|
+
const provided = generated.namespace === null ? "its index module" : `"${generated.namespace}"`;
|
|
78
|
+
|
|
79
|
+
return new Error(
|
|
74
80
|
`Cannot resolve "${generated.source}": the generated store in ${options.storeDir} does provide ` +
|
|
75
|
-
|
|
81
|
+
`${provided}, but its link at ${options.linkDir} is not on the module resolution path of ` +
|
|
76
82
|
`${generated.importer}. Codegen writes the store into the node_modules the installed @gtkx packages ` +
|
|
77
83
|
"resolve from; install them where the importing file reaches them, then run gtkx codegen again.",
|
|
78
84
|
);
|
|
85
|
+
};
|
|
79
86
|
|
|
80
|
-
const
|
|
81
|
-
|
|
87
|
+
const missingIndexError = (generated: GeneratedModule): Error =>
|
|
88
|
+
new Error(
|
|
89
|
+
`Cannot resolve "${generated.source}": the binding store has no index module. ` +
|
|
90
|
+
"Run gtkx codegen to regenerate the store.",
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const undeclaredLibraryError = (source: string, namespace: string, girPath: string[]): Error => {
|
|
94
|
+
const identifier = findGirIdentifier(girPath, namespace);
|
|
82
95
|
|
|
83
96
|
if (identifier === undefined) {
|
|
84
97
|
return new Error(
|
|
85
|
-
`Cannot resolve "${
|
|
86
|
-
`GIR data for it was found in [${girPath.join(", ")}]. If "${
|
|
98
|
+
`Cannot resolve "${source}": the binding store has no "${namespace}" module, and no ` +
|
|
99
|
+
`GIR data for it was found in [${girPath.join(", ")}]. If "${namespace}" is a library, ` +
|
|
87
100
|
"install its gobject-introspection data package and add its GIR identifier to `libraries` in " +
|
|
88
101
|
"gtkx.config.ts. Otherwise run gtkx codegen to regenerate the store.",
|
|
89
102
|
);
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
return new Error(
|
|
93
|
-
`Cannot resolve "${
|
|
106
|
+
`Cannot resolve "${source}": the "${identifier}" bindings have not been generated. ` +
|
|
94
107
|
`Add "${identifier}" to \`libraries\` in gtkx.config.ts, then run gtkx dev or gtkx build again.`,
|
|
95
108
|
);
|
|
96
109
|
};
|
|
97
110
|
|
|
98
111
|
const unresolvedModuleError = async (state: PluginState, generated: GeneratedModule): Promise<Error> => {
|
|
99
112
|
const options = getStoreOptions(state.root, generated.kind);
|
|
113
|
+
const exportKey = generated.namespace === null ? "." : `./${generated.namespace}`;
|
|
100
114
|
|
|
101
|
-
if (options !== null &&
|
|
115
|
+
if (options !== null && hasStoreModule(options.storeDir, exportKey)) {
|
|
102
116
|
return unreachableStoreError(generated, options);
|
|
103
117
|
}
|
|
104
118
|
|
|
105
|
-
|
|
119
|
+
if (generated.namespace === null) {
|
|
120
|
+
return missingIndexError(generated);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return undeclaredLibraryError(generated.source, generated.namespace, await girSearchPaths(state));
|
|
106
124
|
};
|
|
107
125
|
|
|
108
126
|
function gtkxUndeclaredLibrary(loadConfig: ConfigLoader = createConfigLoader()): Plugin {
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
declare const BUNDLED_PACKAGES_FILENAME = "gtkx-packages.json";
|
|
3
|
-
declare function gtkxBundledPackages(root: string): Plugin;
|
|
4
|
-
export { BUNDLED_PACKAGES_FILENAME, gtkxBundledPackages };
|
|
5
|
-
//# sourceMappingURL=bundled-packages.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundled-packages.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/bundled-packages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAmBnC,QAAA,MAAM,yBAAyB,uBAAuB,CAAC;AAoDvD,iBAAS,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBjD;AAED,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundled-packages.js","sourceRoot":"","sources":["../../src/vite-plugins/bundled-packages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAe9C,MAAM,yBAAyB,GAAG,oBAAoB,CAAC;AACvD,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,WAAW,GAAG,CAAC,CAAC;AAEt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AM;YACjB,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7D,CAAC;QAED,cAAc,CAAC,QAAQ,EAAE,MAAM;YAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAEzG,IAAI,CAAC,QAAQ,CAAC;gBACV,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,yBAAyB;gBACnC,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC;aAC5C,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;AACN,CAAC;AAED,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["import type { Plugin } from \"vite\";\nimport { isRecord, sortStringsBy } from \"@gtkx/utils\";\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { stripQuery } from \"./strip-query.js\";\n\ntype PackageIdentity = {\n name: string;\n version: string | null;\n};\n\ntype RecordedPackage = PackageIdentity & {\n dir: string;\n};\n\ntype PackagesState = {\n outDir: string;\n};\n\nconst BUNDLED_PACKAGES_FILENAME = \"gtkx-packages.json\";\nconst MANIFEST_FILENAME = \"package.json\";\nconst DEFAULT_OUT_DIR = \"dist\";\nconst JSON_INDENT = 4;\n\nconst identityIn = (dir: string): PackageIdentity | null => {\n try {\n const parsed: unknown = JSON.parse(readFileSync(join(dir, MANIFEST_FILENAME), \"utf8\"));\n\n if (!isRecord(parsed) || typeof parsed.name !== \"string\") {\n return null;\n }\n\n return { name: parsed.name, version: typeof parsed.version === \"string\" ? parsed.version : null };\n } catch {\n return null;\n }\n};\n\nconst packageIn = (dir: string): RecordedPackage | null => {\n const identity = identityIn(dir);\n\n if (identity !== null) {\n return { ...identity, dir };\n }\n\n const parent = dirname(dir);\n\n return parent === dir ? null : packageIn(parent);\n};\n\nconst packageForModule = (id: string): RecordedPackage | null => {\n const path = stripQuery(id);\n\n return path.startsWith(\"/\") ? packageIn(dirname(path)) : null;\n};\n\nconst keyFor = (entry: RecordedPackage): string => `${entry.name}@${entry.version ?? \"\"}`;\n\nconst relativeTo = (outDir: string, entry: RecordedPackage): RecordedPackage => ({\n ...entry,\n dir: relative(outDir, entry.dir),\n});\n\nconst renderPackages = (outDir: string, ids: string[]): string => {\n const found = ids.map((id) => packageForModule(id)).filter((entry) => entry !== null);\n const unique: Map<string, RecordedPackage> = new Map(found.map((entry) => [keyFor(entry), entry]));\n const packages = sortStringsBy(unique.values(), keyFor).map((entry) => relativeTo(outDir, entry));\n\n return `${JSON.stringify({ packages }, null, JSON_INDENT)}\\n`;\n};\n\nfunction gtkxBundledPackages(root: string): Plugin {\n const state: PackagesState = { outDir: join(root, DEFAULT_OUT_DIR) };\n\n return {\n name: \"gtkx:bundled-packages\",\n apply: \"build\",\n\n configResolved(config) {\n state.outDir = resolve(config.root, config.build.outDir);\n },\n\n generateBundle(_options, bundle) {\n const ids = Object.values(bundle).flatMap((output) => (output.type === \"chunk\" ? output.moduleIds : []));\n\n this.emitFile({\n type: \"asset\",\n fileName: BUNDLED_PACKAGES_FILENAME,\n source: renderPackages(state.outDir, ids),\n });\n },\n };\n}\n\nexport { BUNDLED_PACKAGES_FILENAME, gtkxBundledPackages };\n"]}
|