@gtkx/cli 2.0.0-beta.6 → 2.0.0-beta.8
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 +43 -40
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/codegen/freshness.d.ts.map +1 -1
- package/dist/codegen/freshness.js +5 -1
- package/dist/codegen/freshness.js.map +1 -1
- package/dist/commands/deploy.d.ts +4 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +6 -0
- package/dist/commands/deploy.js.map +1 -1
- package/dist/deploy/download.d.ts +7 -3
- package/dist/deploy/download.d.ts.map +1 -1
- package/dist/deploy/download.js +19 -15
- package/dist/deploy/download.js.map +1 -1
- package/dist/deploy/native-addon.d.ts +5 -0
- package/dist/deploy/native-addon.d.ts.map +1 -0
- package/dist/deploy/native-addon.js +134 -0
- package/dist/deploy/native-addon.js.map +1 -0
- package/dist/deploy/node-runtime/download.js +2 -2
- package/dist/deploy/node-runtime/download.js.map +1 -1
- package/dist/deploy/node-runtime/elf.d.ts +3 -1
- package/dist/deploy/node-runtime/elf.d.ts.map +1 -1
- package/dist/deploy/node-runtime/elf.js +3 -1
- package/dist/deploy/node-runtime/elf.js.map +1 -1
- package/dist/deploy/node-runtime/index.d.ts.map +1 -1
- package/dist/deploy/node-runtime/index.js +14 -2
- package/dist/deploy/node-runtime/index.js.map +1 -1
- package/dist/deploy/payload/stage.d.ts +2 -1
- package/dist/deploy/payload/stage.d.ts.map +1 -1
- package/dist/deploy/payload/stage.js +22 -2
- package/dist/deploy/payload/stage.js.map +1 -1
- package/dist/deploy/run-deploy.d.ts +1 -0
- package/dist/deploy/run-deploy.d.ts.map +1 -1
- package/dist/deploy/run-deploy.js +135 -79
- package/dist/deploy/run-deploy.js.map +1 -1
- package/dist/deploy/settings/arch.d.ts +9 -3
- package/dist/deploy/settings/arch.d.ts.map +1 -1
- package/dist/deploy/settings/arch.js +27 -6
- package/dist/deploy/settings/arch.js.map +1 -1
- package/dist/deploy/settings/index.d.ts +2 -1
- package/dist/deploy/settings/index.d.ts.map +1 -1
- package/dist/deploy/settings/index.js +2 -1
- package/dist/deploy/settings/index.js.map +1 -1
- package/dist/deploy/settings/libraries.d.ts.map +1 -1
- package/dist/deploy/settings/libraries.js +2 -1
- package/dist/deploy/settings/libraries.js.map +1 -1
- package/dist/deploy/settings/paths.d.ts +2 -1
- package/dist/deploy/settings/paths.d.ts.map +1 -1
- package/dist/deploy/settings/paths.js +6 -5
- 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 +1 -0
- package/dist/deploy/targets/appimage.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 +2 -0
- package/dist/deploy/targets/flatpak-source.js.map +1 -1
- package/dist/deploy/targets/flatpak.d.ts.map +1 -1
- package/dist/deploy/targets/flatpak.js +1 -0
- package/dist/deploy/targets/flatpak.js.map +1 -1
- package/dist/deploy/targets/nfpm-target.d.ts.map +1 -1
- package/dist/deploy/targets/nfpm-target.js +1 -0
- package/dist/deploy/targets/nfpm-target.js.map +1 -1
- package/dist/deploy/types.d.ts +4 -2
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/deploy/types.js.map +1 -1
- package/dist/deploy/vendored/appimagetool.js +2 -2
- package/dist/deploy/vendored/appimagetool.js.map +1 -1
- package/dist/deploy/vendored/nfpm.js +1 -1
- package/dist/deploy/vendored/nfpm.js.map +1 -1
- package/dist/dev/font-dir.d.ts +3 -0
- package/dist/dev/font-dir.d.ts.map +1 -0
- package/dist/dev/font-dir.js +9 -0
- package/dist/dev/font-dir.js.map +1 -0
- package/dist/dev/runner-main.d.ts.map +1 -1
- package/dist/dev/runner-main.js +2 -0
- package/dist/dev/runner-main.js.map +1 -1
- package/dist/dev/runner.d.ts.map +1 -1
- package/dist/dev/runner.js +19 -6
- package/dist/dev/runner.js.map +1 -1
- package/dist/internal/agent-rules.d.ts.map +1 -1
- package/dist/internal/agent-rules.js +6 -2
- package/dist/internal/agent-rules.js.map +1 -1
- package/dist/internal/banner.d.ts.map +1 -1
- package/dist/internal/banner.js +3 -0
- package/dist/internal/banner.js.map +1 -1
- package/dist/internal/font-path.d.ts +4 -0
- package/dist/internal/font-path.d.ts.map +1 -0
- package/dist/internal/font-path.js +12 -0
- package/dist/internal/font-path.js.map +1 -0
- package/dist/internal/font-staging.d.ts +6 -0
- package/dist/internal/font-staging.d.ts.map +1 -0
- package/dist/internal/font-staging.js +92 -0
- package/dist/internal/font-staging.js.map +1 -0
- package/dist/internal/source-imports.d.ts +2 -1
- package/dist/internal/source-imports.d.ts.map +1 -1
- package/dist/internal/source-imports.js +8 -3
- package/dist/internal/source-imports.js.map +1 -1
- package/dist/internal/xdg-banner.d.ts +4 -0
- package/dist/internal/xdg-banner.d.ts.map +1 -0
- package/dist/internal/xdg-banner.js +11 -0
- package/dist/internal/xdg-banner.js.map +1 -0
- package/dist/internal/xdg-data-dirs.d.ts +2 -1
- package/dist/internal/xdg-data-dirs.d.ts.map +1 -1
- package/dist/internal/xdg-data-dirs.js +1 -1
- package/dist/internal/xdg-data-dirs.js.map +1 -1
- package/dist/settings/schema.d.ts.map +1 -1
- package/dist/settings/schema.js +1 -6
- package/dist/settings/schema.js.map +1 -1
- package/dist/vite-plugins/asset-extensions.d.ts.map +1 -1
- package/dist/vite-plugins/asset-extensions.js +2 -0
- package/dist/vite-plugins/asset-extensions.js.map +1 -1
- package/dist/vite-plugins/asset-imports.d.ts.map +1 -1
- package/dist/vite-plugins/asset-imports.js +7 -2
- package/dist/vite-plugins/asset-imports.js.map +1 -1
- package/dist/vite-plugins/asset-specifier.d.ts +5 -1
- package/dist/vite-plugins/asset-specifier.d.ts.map +1 -1
- package/dist/vite-plugins/asset-specifier.js +10 -1
- package/dist/vite-plugins/asset-specifier.js.map +1 -1
- package/dist/vite-plugins/css.d.ts.map +1 -1
- package/dist/vite-plugins/css.js +3 -2
- package/dist/vite-plugins/css.js.map +1 -1
- package/dist/vite-plugins/font-name.d.ts +3 -0
- package/dist/vite-plugins/font-name.d.ts.map +1 -0
- package/dist/vite-plugins/font-name.js +406 -0
- package/dist/vite-plugins/font-name.js.map +1 -0
- package/dist/vite-plugins/font-worker-env.d.ts +4 -0
- package/dist/vite-plugins/font-worker-env.d.ts.map +1 -0
- package/dist/vite-plugins/font-worker-env.js +19 -0
- package/dist/vite-plugins/font-worker-env.js.map +1 -0
- package/dist/vite-plugins/font.d.ts +4 -0
- package/dist/vite-plugins/font.d.ts.map +1 -0
- package/dist/vite-plugins/font.js +99 -0
- package/dist/vite-plugins/font.js.map +1 -0
- package/dist/vite-plugins/icons.d.ts.map +1 -1
- package/dist/vite-plugins/icons.js +5 -10
- package/dist/vite-plugins/icons.js.map +1 -1
- package/dist/vite-plugins/index.d.ts.map +1 -1
- package/dist/vite-plugins/index.js +2 -0
- package/dist/vite-plugins/index.js.map +1 -1
- package/dist/vite-plugins/react-compiler.js +2 -2
- package/dist/vite-plugins/react-compiler.js.map +1 -1
- package/dist/vite-plugins/resources.js +3 -3
- package/dist/vite-plugins/resources.js.map +1 -1
- package/dist/vite-plugins/settings-worker-env.js +2 -2
- package/dist/vite-plugins/settings-worker-env.js.map +1 -1
- package/dist/vite-plugins/store-links.d.ts.map +1 -1
- package/dist/vite-plugins/store-links.js +2 -1
- package/dist/vite-plugins/store-links.js.map +1 -1
- package/dist/vite-plugins/undeclared-library.js +5 -5
- package/dist/vite-plugins/undeclared-library.js.map +1 -1
- package/dist/vitest-plugin.d.ts.map +1 -1
- package/dist/vitest-plugin.js +2 -0
- package/dist/vitest-plugin.js.map +1 -1
- package/env.d.ts +9 -0
- package/package.json +17 -15
- package/src/cli.ts +1 -1
- package/src/codegen/freshness.ts +5 -1
- package/src/commands/deploy.ts +6 -0
- package/src/deploy/download.ts +33 -17
- package/src/deploy/native-addon.ts +183 -0
- package/src/deploy/node-runtime/download.ts +2 -2
- package/src/deploy/node-runtime/elf.ts +4 -1
- package/src/deploy/node-runtime/index.ts +24 -4
- package/src/deploy/payload/stage.ts +34 -2
- package/src/deploy/run-deploy.ts +203 -93
- package/src/deploy/settings/arch.ts +40 -8
- package/src/deploy/settings/index.ts +4 -1
- package/src/deploy/settings/libraries.ts +2 -1
- package/src/deploy/settings/paths.ts +8 -6
- package/src/deploy/targets/appimage.ts +1 -0
- package/src/deploy/targets/flatpak-pnpm.ts +4 -4
- package/src/deploy/targets/flatpak-source.ts +2 -0
- package/src/deploy/targets/flatpak.ts +1 -0
- package/src/deploy/targets/nfpm-target.ts +1 -0
- package/src/deploy/types.ts +4 -1
- package/src/deploy/vendored/appimagetool.ts +2 -2
- package/src/deploy/vendored/nfpm.ts +1 -1
- package/src/dev/font-dir.ts +11 -0
- package/src/dev/runner-main.ts +2 -0
- package/src/dev/runner.ts +24 -6
- package/src/internal/agent-rules.ts +6 -2
- package/src/internal/banner.ts +4 -0
- package/src/internal/font-path.ts +15 -0
- package/src/internal/font-staging.ts +129 -0
- package/src/internal/source-imports.ts +18 -3
- package/src/internal/xdg-banner.ts +13 -0
- package/src/internal/xdg-data-dirs.ts +1 -1
- package/src/settings/schema.ts +1 -8
- package/src/vite-plugins/asset-extensions.ts +2 -0
- package/src/vite-plugins/asset-imports.ts +9 -1
- package/src/vite-plugins/asset-specifier.ts +17 -0
- package/src/vite-plugins/css.ts +4 -2
- package/src/vite-plugins/font-name.ts +582 -0
- package/src/vite-plugins/font-worker-env.ts +25 -0
- package/src/vite-plugins/font.ts +165 -0
- package/src/vite-plugins/icons.ts +6 -12
- package/src/vite-plugins/index.ts +2 -0
- package/src/vite-plugins/react-compiler.ts +2 -2
- package/src/vite-plugins/resources.ts +3 -3
- package/src/vite-plugins/settings-worker-env.ts +2 -2
- package/src/vite-plugins/store-links.ts +2 -1
- package/src/vite-plugins/undeclared-library.ts +5 -5
- package/src/vitest-plugin.ts +2 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Plugin, Rollup } from "vite";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { parseSync } from "vite";
|
|
4
|
+
import type { AssetEmitter } from "./asset-emitter.js";
|
|
5
|
+
import { prependBanner } from "../internal/banner.js";
|
|
6
|
+
import { fontFileName, FONTS_DIR } from "../internal/font-path.js";
|
|
7
|
+
import { stagedFontStatus } from "../internal/font-staging.js";
|
|
8
|
+
import { sourceLanguage } from "../internal/source-imports.js";
|
|
9
|
+
import { xdgDataDirsBanner } from "../internal/xdg-banner.js";
|
|
10
|
+
import { parseFontSpecifier } from "./asset-specifier.js";
|
|
11
|
+
import { fontFamilyNames } from "./font-name.js";
|
|
12
|
+
import { stripQuery } from "./strip-query.js";
|
|
13
|
+
import { createVirtualNamespace } from "./virtual-module.js";
|
|
14
|
+
|
|
15
|
+
type PluginState = {
|
|
16
|
+
isBuild: boolean;
|
|
17
|
+
root: string;
|
|
18
|
+
emitted: Set<string>;
|
|
19
|
+
importers: Map<string, string>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type ResolveContext = Parameters<typeof resolveToVirtual>[0];
|
|
23
|
+
type ResolveRequest = Parameters<typeof resolveToVirtual>[1];
|
|
24
|
+
|
|
25
|
+
type RetainedFontModuleId = {
|
|
26
|
+
id: string;
|
|
27
|
+
moduleSideEffects: true;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type LoadContext = AssetEmitter & {
|
|
31
|
+
addWatchFile: (file: string) => void;
|
|
32
|
+
error: (message: string) => never;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const VIRTUAL_PREFIX = "\0gtkx-font:";
|
|
36
|
+
const { isVirtual, fromVirtualId, resolveToVirtual } = createVirtualNamespace(VIRTUAL_PREFIX);
|
|
37
|
+
|
|
38
|
+
const unreadableFontError = (filePath: string): string =>
|
|
39
|
+
`Cannot read a font family name from ${filePath}; ?font expects a TrueType, OpenType, ` +
|
|
40
|
+
"TrueType Collection, WOFF, or WOFF2 font";
|
|
41
|
+
|
|
42
|
+
const unstagedFontError = (filePath: string, importer: string): string =>
|
|
43
|
+
`${filePath} was not staged before the toolkit started, so ${importer} would resolve its family to a ` +
|
|
44
|
+
"fallback font. Fonts are staged from ?font imports found in source files under the project root; move " +
|
|
45
|
+
"the import there, or restart to pick it up.";
|
|
46
|
+
|
|
47
|
+
const resolveFontId = async (
|
|
48
|
+
ctx: ResolveContext,
|
|
49
|
+
state: PluginState,
|
|
50
|
+
request: ResolveRequest,
|
|
51
|
+
): Promise<RetainedFontModuleId | undefined> => {
|
|
52
|
+
if (parseFontSpecifier(request.source) === null) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const virtualId = await resolveToVirtual(ctx, request);
|
|
57
|
+
|
|
58
|
+
if (virtualId === undefined) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
state.importers.set(virtualId, request.importer ?? state.root);
|
|
63
|
+
|
|
64
|
+
return { id: virtualId, moduleSideEffects: true };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const emitFont = (ctx: LoadContext, state: PluginState, filePath: string, content: Buffer): void => {
|
|
68
|
+
const fileName = `${FONTS_DIR}/${fontFileName(filePath, content)}`;
|
|
69
|
+
|
|
70
|
+
if (state.emitted.has(fileName)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
state.emitted.add(fileName);
|
|
75
|
+
ctx.emitFile({ type: "asset", fileName, source: content });
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const loadFontModule = (ctx: LoadContext, state: PluginState, id: string): string | undefined => {
|
|
79
|
+
if (!isVirtual(id)) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const filePath = stripQuery(fromVirtualId(id));
|
|
84
|
+
const content = readFileSync(filePath);
|
|
85
|
+
const [family] = fontFamilyNames(content);
|
|
86
|
+
|
|
87
|
+
if (family === undefined) {
|
|
88
|
+
return ctx.error(unreadableFontError(filePath));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ctx.addWatchFile(filePath);
|
|
92
|
+
|
|
93
|
+
if (state.isBuild) {
|
|
94
|
+
emitFont(ctx, state, filePath, content);
|
|
95
|
+
} else if (stagedFontStatus(filePath, content) === "absent") {
|
|
96
|
+
return ctx.error(unstagedFontError(filePath, state.importers.get(id) ?? state.root));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return `export default ${JSON.stringify(family)};`;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const hasSideEffectFontImport = (code: string, id: string): boolean => {
|
|
103
|
+
const lang = sourceLanguage(stripQuery(id));
|
|
104
|
+
|
|
105
|
+
if (lang === undefined || !code.includes("?font")) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const parsed = parseSync(id, code, { lang });
|
|
110
|
+
|
|
111
|
+
if (parsed.errors.length > 0) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return parsed.module.staticImports.some(
|
|
116
|
+
(statement) => statement.entries.length === 0 && parseFontSpecifier(statement.moduleRequest.value) !== null,
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const retainSideEffectFontImport = (
|
|
121
|
+
code: string,
|
|
122
|
+
id: string,
|
|
123
|
+
): { code: string; moduleSideEffects: true } | null =>
|
|
124
|
+
hasSideEffectFontImport(code, id)
|
|
125
|
+
? { code, moduleSideEffects: true }
|
|
126
|
+
: null;
|
|
127
|
+
|
|
128
|
+
const fontBanner = (state: PluginState) => (chunk: Rollup.RenderedChunk): string =>
|
|
129
|
+
state.emitted.size === 0 ? "" : xdgDataDirsBanner(chunk);
|
|
130
|
+
|
|
131
|
+
function gtkxFont(): Plugin {
|
|
132
|
+
const state: PluginState = { isBuild: false, root: "", emitted: new Set(), importers: new Map() };
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
name: "gtkx:font",
|
|
136
|
+
enforce: "pre",
|
|
137
|
+
|
|
138
|
+
configResolved(config) {
|
|
139
|
+
state.isBuild = config.command === "build";
|
|
140
|
+
state.root = config.root;
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
resolveId(source, importer, options) {
|
|
144
|
+
return resolveFontId(this, state, { source, importer, options });
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
load(id) {
|
|
148
|
+
return loadFontModule(this, state, id);
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
transform(code, id) {
|
|
152
|
+
return retainSideEffectFontImport(code, id);
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
outputOptions(options) {
|
|
156
|
+
if (!state.isBuild) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return prependBanner(options, fontBanner(state));
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { gtkxFont };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type { ConfigLoader } from "@gtkx/config";
|
|
2
|
-
import type { Plugin,
|
|
3
|
-
import { createConfigLoader } from "@gtkx/config/internal";
|
|
2
|
+
import type { Plugin, UserConfig } from "vite";
|
|
3
|
+
import { createConfigLoader, viteProjectRoot } from "@gtkx/config/internal";
|
|
4
4
|
import { info } from "@gtkx/utils";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import type { AssetEmitter } from "./asset-emitter.js";
|
|
8
|
-
import {
|
|
8
|
+
import { prependBanner } from "../internal/banner.js";
|
|
9
9
|
import {
|
|
10
10
|
relativeIconPath,
|
|
11
11
|
resolveApplicationIcon,
|
|
12
12
|
type ResolvedApplicationIcon,
|
|
13
13
|
} from "../internal/icon-path.js";
|
|
14
14
|
import { type ListedFile, listFilesRecursive } from "../internal/list-files.js";
|
|
15
|
+
import { xdgDataDirsBanner } from "../internal/xdg-banner.js";
|
|
15
16
|
|
|
16
17
|
type PluginState = {
|
|
17
18
|
applicationId: string;
|
|
@@ -20,13 +21,6 @@ type PluginState = {
|
|
|
20
21
|
|
|
21
22
|
const ICONS_DIR = "icons";
|
|
22
23
|
|
|
23
|
-
const xdgEnvBanner = (chunk: Rollup.RenderedChunk): string => [
|
|
24
|
-
"globalThis.process.env.XDG_DATA_DIRS = [",
|
|
25
|
-
` ${outputRootUrlExpression(chunk)},`,
|
|
26
|
-
" globalThis.process.env.XDG_DATA_DIRS || \"/usr/local/share:/usr/share\",",
|
|
27
|
-
"].join(\":\");",
|
|
28
|
-
].join("\n");
|
|
29
|
-
|
|
30
24
|
const findIconFiles = (state: PluginState): ListedFile[] => {
|
|
31
25
|
if (state.source.kind === "theme") {
|
|
32
26
|
return listFilesRecursive(state.source.path);
|
|
@@ -43,7 +37,7 @@ const findIconFiles = (state: PluginState): ListedFile[] => {
|
|
|
43
37
|
};
|
|
44
38
|
|
|
45
39
|
const applyUserConfig = async (state: PluginState, config: UserConfig, loadConfig: ConfigLoader): Promise<void> => {
|
|
46
|
-
const { config: gtkxConfig, root } = await loadConfig.load(config
|
|
40
|
+
const { config: gtkxConfig, root } = await loadConfig.load(viteProjectRoot(config));
|
|
47
41
|
state.applicationId = gtkxConfig.applicationId;
|
|
48
42
|
state.source = resolveApplicationIcon(root, gtkxConfig.applicationId, gtkxConfig.applicationIcon);
|
|
49
43
|
};
|
|
@@ -78,7 +72,7 @@ function gtkxIcons(loadConfig: ConfigLoader = createConfigLoader()): Plugin {
|
|
|
78
72
|
return;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
return prependBanner(options,
|
|
75
|
+
return prependBanner(options, xdgDataDirsBanner);
|
|
82
76
|
},
|
|
83
77
|
|
|
84
78
|
buildEnd() {
|
|
@@ -5,6 +5,7 @@ import type { BuildManifestCollector } from "../internal/build-manifest.js";
|
|
|
5
5
|
import { gtkxAssetImports } from "./asset-imports.js";
|
|
6
6
|
import { gtkxBuiltUrl } from "./built-url.js";
|
|
7
7
|
import { gtkxCss } from "./css.js";
|
|
8
|
+
import { gtkxFont } from "./font.js";
|
|
8
9
|
import { type CatalogWriteListener, gtkxI18n } from "./i18n.js";
|
|
9
10
|
import { gtkxIcons } from "./icons.js";
|
|
10
11
|
import { gtkxReactCompiler } from "./react-compiler.js";
|
|
@@ -53,6 +54,7 @@ const gtkxVitePlugins = (options: GtkxVitePluginOptions = {}): Plugin[] => {
|
|
|
53
54
|
gtkxIcons(loadConfig),
|
|
54
55
|
gtkxAssetImports(),
|
|
55
56
|
gtkxBuiltUrl(),
|
|
57
|
+
gtkxFont(),
|
|
56
58
|
gtkxResources(loadConfig, entryPath),
|
|
57
59
|
gtkxCss(),
|
|
58
60
|
gtkxReactCompiler(loadConfig),
|
|
@@ -3,7 +3,7 @@ import type { ResolvedReactCompilerOptions } from "@gtkx/config/internal";
|
|
|
3
3
|
import type { Plugin, ResolvedConfig, UserConfig } from "vite";
|
|
4
4
|
import { transformAsync } from "@babel/core";
|
|
5
5
|
import babelPresetTypescriptNs from "@babel/preset-typescript";
|
|
6
|
-
import { createConfigLoader } from "@gtkx/config/internal";
|
|
6
|
+
import { createConfigLoader, viteProjectRoot } from "@gtkx/config/internal";
|
|
7
7
|
import babelPluginReactCompilerNs from "babel-plugin-react-compiler";
|
|
8
8
|
|
|
9
9
|
type ReactCompilerState = {
|
|
@@ -62,7 +62,7 @@ function gtkxReactCompiler(loadConfig: ConfigLoader = createConfigLoader()): Plu
|
|
|
62
62
|
enforce: "pre",
|
|
63
63
|
|
|
64
64
|
async config(config: UserConfig) {
|
|
65
|
-
const resolved = await loadConfig.resolve(config
|
|
65
|
+
const resolved = await loadConfig.resolve(viteProjectRoot(config));
|
|
66
66
|
state.options = resolved.reactCompiler;
|
|
67
67
|
},
|
|
68
68
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConfigLoader } from "@gtkx/config";
|
|
2
2
|
import type { ModuleNode, Plugin, ResolvedConfig, Rolldown, UserConfig, ViteDevServer } from "vite";
|
|
3
|
-
import { createConfigLoader, resourceBasePath } from "@gtkx/config/internal";
|
|
3
|
+
import { createConfigLoader, resourceBasePath, viteProjectRoot } from "@gtkx/config/internal";
|
|
4
4
|
import { error, info, isPathInside, isRecord, sortStrings, toPosixPath } from "@gtkx/utils";
|
|
5
5
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { basename, dirname, extname, isAbsolute, join, posix, relative, sep } from "node:path";
|
|
@@ -1283,7 +1283,7 @@ const reconcileImporter = async (ctx: ResolveContext, state: PluginState, id: st
|
|
|
1283
1283
|
};
|
|
1284
1284
|
|
|
1285
1285
|
const resolveResourceConfig = async (state: PluginState, config: UserConfig, loadConfig: ConfigLoader) => {
|
|
1286
|
-
const loaded = await loadConfig.load(config
|
|
1286
|
+
const loaded = await loadConfig.load(viteProjectRoot(config));
|
|
1287
1287
|
state.prefix = resourceBasePath(loaded.config.applicationId);
|
|
1288
1288
|
state.root = loaded.root;
|
|
1289
1289
|
|
|
@@ -1383,7 +1383,7 @@ const rejectInvalidSpecifier = (source: string): void => {
|
|
|
1383
1383
|
if (isBareRelativeAsset(source)) {
|
|
1384
1384
|
throw new Error(
|
|
1385
1385
|
`${JSON.stringify(source)} must choose ?resource for a GResource, ?icon for a themed icon, ` +
|
|
1386
|
-
"or ?url for an emitted file",
|
|
1386
|
+
"?font for a bundled font, or ?url for an emitted file",
|
|
1387
1387
|
);
|
|
1388
1388
|
}
|
|
1389
1389
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UserConfig } from "vite";
|
|
2
2
|
import type { Plugin } from "vitest/config";
|
|
3
|
-
import { createConfigLoader } from "@gtkx/config/internal";
|
|
3
|
+
import { createConfigLoader, viteProjectRoot } from "@gtkx/config/internal";
|
|
4
4
|
import { prependSchemaDir, stageAndCompileProjectSchemas } from "../settings/schema.js";
|
|
5
5
|
|
|
6
6
|
function gtkxSettingsWorkerEnv(configFile?: string): Plugin {
|
|
@@ -11,7 +11,7 @@ function gtkxSettingsWorkerEnv(configFile?: string): Plugin {
|
|
|
11
11
|
enforce: "pre",
|
|
12
12
|
|
|
13
13
|
async config(config: UserConfig) {
|
|
14
|
-
const loaded = await loadConfig.load(config
|
|
14
|
+
const loaded = await loadConfig.load(viteProjectRoot(config));
|
|
15
15
|
const dir = stageAndCompileProjectSchemas(loaded.root);
|
|
16
16
|
|
|
17
17
|
if (dir === null) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
2
|
import { ensureStoreLinks } from "@gtkx/codegen/internal";
|
|
3
|
+
import { viteProjectRoot } from "@gtkx/config/internal";
|
|
3
4
|
|
|
4
5
|
const GENERATED_MODULE_PREFIX = /^@gtkx\/(?:gi\/|jsx(?:\/|$))/;
|
|
5
6
|
|
|
@@ -11,7 +12,7 @@ function gtkxStoreLinks(): Plugin {
|
|
|
11
12
|
enforce: "pre",
|
|
12
13
|
|
|
13
14
|
config(config: UserConfig) {
|
|
14
|
-
state.root = config
|
|
15
|
+
state.root = viteProjectRoot(config);
|
|
15
16
|
},
|
|
16
17
|
|
|
17
18
|
resolveId(source) {
|
|
@@ -2,7 +2,7 @@ import type { StoreOptions } from "@gtkx/codegen";
|
|
|
2
2
|
import type { ConfigLoader } from "@gtkx/config";
|
|
3
3
|
import type { Plugin, UserConfig } from "vite";
|
|
4
4
|
import { discoverGirNamespaces, resolveGirPath, resolveStore } from "@gtkx/codegen";
|
|
5
|
-
import { createConfigLoader } from "@gtkx/config/internal";
|
|
5
|
+
import { createConfigLoader, viteProjectRoot } from "@gtkx/config/internal";
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
|
|
@@ -20,7 +20,7 @@ type GeneratedModule = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const GENERATED_MODULE_PATTERN = /^@gtkx\/(gi|jsx)\/([a-z0-9]+)$/;
|
|
23
|
-
const DEFAULT_LIBRARY_NAMESPACES: Set<string> = new Set(["
|
|
23
|
+
const DEFAULT_LIBRARY_NAMESPACES: Set<string> = new Set(["adw", "gtk"]);
|
|
24
24
|
|
|
25
25
|
const girSearchPaths = async (state: PluginState): Promise<string[]> => {
|
|
26
26
|
if (state.girPath === null) {
|
|
@@ -88,7 +88,7 @@ const undeclaredLibraryError = (source: string, namespace: string, girPath: stri
|
|
|
88
88
|
return new Error(
|
|
89
89
|
`Cannot resolve "${source}": the binding store has no "${namespace}" module, and no ` +
|
|
90
90
|
`GIR data for it was found in [${girPath.join(", ")}]. If "${namespace}" is a library, install ` +
|
|
91
|
-
"its gobject-introspection data package.
|
|
91
|
+
"its gobject-introspection data package. Adw-1 is bound by default and pulls in Gtk-4.0; add only other " +
|
|
92
92
|
"GIR identifiers to `libraries` in gtkx.config.ts. Otherwise run gtkx codegen to regenerate the store.",
|
|
93
93
|
);
|
|
94
94
|
}
|
|
@@ -96,7 +96,7 @@ const undeclaredLibraryError = (source: string, namespace: string, girPath: stri
|
|
|
96
96
|
if (DEFAULT_LIBRARY_NAMESPACES.has(namespace)) {
|
|
97
97
|
return new Error(
|
|
98
98
|
`Cannot resolve "${source}": the "${identifier}" bindings have not been generated. ` +
|
|
99
|
-
"The
|
|
99
|
+
"The Adwaita and GTK namespaces are generated implicitly; run gtkx dev or gtkx build again.",
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -129,7 +129,7 @@ function gtkxUndeclaredLibrary(loadConfig: ConfigLoader = createConfigLoader()):
|
|
|
129
129
|
enforce: "pre",
|
|
130
130
|
|
|
131
131
|
config(config: UserConfig) {
|
|
132
|
-
state.root = config
|
|
132
|
+
state.root = viteProjectRoot(config);
|
|
133
133
|
},
|
|
134
134
|
|
|
135
135
|
async resolveId(source, importer, options) {
|
package/src/vitest-plugin.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import gtkxVitest, { type PluginOptions } from "@gtkx/vitest";
|
|
3
3
|
import { gtkxEnsureStore } from "./vite-plugins/ensure-store.js";
|
|
4
|
+
import { gtkxFontWorkerEnv } from "./vite-plugins/font-worker-env.js";
|
|
4
5
|
import { gtkxVitePlugins } from "./vite-plugins/index.js";
|
|
5
6
|
import { gtkxSettingsWorkerEnv } from "./vite-plugins/settings-worker-env.js";
|
|
6
7
|
|
|
@@ -15,6 +16,7 @@ const gtkx = (options: PluginOptions = {}): Plugin[] => [
|
|
|
15
16
|
gtkxEnsureStore(options.configFile),
|
|
16
17
|
...gtkxVitePlugins({ configFile: options.configFile }),
|
|
17
18
|
gtkxSettingsWorkerEnv(options.configFile),
|
|
19
|
+
gtkxFontWorkerEnv(options.configFile),
|
|
18
20
|
gtkxVitest(options),
|
|
19
21
|
];
|
|
20
22
|
|