@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,14 +1,12 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
import {
|
|
1
|
+
import type { Plugin, UserConfig } from "vite";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { isAbsolute } from "node:path";
|
|
4
|
+
import { stripQuery } from "./strip-query.js";
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
type PluginState = { isBuild: boolean };
|
|
7
|
+
type WatchContext = { addWatchFile: (file: string) => void };
|
|
6
8
|
|
|
7
|
-
const
|
|
8
|
-
const specifier = JSON.stringify(target.replace(LEADING_SLASHES, "./"));
|
|
9
|
-
|
|
10
|
-
return `decodeURIComponent(new URL(${specifier}, ${EXECUTABLE_URL_BASE}).pathname)`;
|
|
11
|
-
};
|
|
9
|
+
const URL_QUERY_RE = /\?url(?:&t=\d+)?$/;
|
|
12
10
|
|
|
13
11
|
const bundleRelativeUrl = (filename: string): string => {
|
|
14
12
|
const specifier = JSON.stringify(`./${filename}`);
|
|
@@ -19,36 +17,59 @@ const bundleRelativeUrl = (filename: string): string => {
|
|
|
19
17
|
const renderAssetUrl = (
|
|
20
18
|
filename: string,
|
|
21
19
|
type: string,
|
|
22
|
-
assetBase: string | undefined,
|
|
23
20
|
): { runtime: string } | undefined => {
|
|
24
21
|
if (type !== "asset") {
|
|
25
22
|
return undefined;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
return { runtime: bundleRelativeUrl(filename) };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const configureBuiltUrl = (userConfig: UserConfig, command: string): UserConfig | undefined => {
|
|
29
|
+
if (command !== "build" || userConfig.experimental?.renderBuiltUrl) {
|
|
30
|
+
return undefined;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
return {
|
|
33
|
+
return {
|
|
34
|
+
experimental: {
|
|
35
|
+
renderBuiltUrl(filename, { type }) {
|
|
36
|
+
return renderAssetUrl(filename, type);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
33
40
|
};
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
const loadDevFileUrl = (ctx: WatchContext, state: PluginState, id: string): string | undefined => {
|
|
43
|
+
if (state.isBuild || !URL_QUERY_RE.test(id)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const file = stripQuery(id);
|
|
48
|
+
|
|
49
|
+
if (!isAbsolute(file) || !existsSync(file)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ctx.addWatchFile(file);
|
|
54
|
+
|
|
55
|
+
return `export default ${JSON.stringify(file)};`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function gtkxBuiltUrl(): Plugin {
|
|
59
|
+
const state: PluginState = { isBuild: false };
|
|
60
|
+
|
|
36
61
|
return {
|
|
37
62
|
name: "gtkx:built-url",
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
config(userConfig)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return renderAssetUrl(filename, type, assetBase);
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
};
|
|
63
|
+
enforce: "pre",
|
|
64
|
+
|
|
65
|
+
config: (userConfig, { command }) => configureBuiltUrl(userConfig, command),
|
|
66
|
+
|
|
67
|
+
configResolved(config) {
|
|
68
|
+
state.isBuild = config.command === "build";
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
load(id) {
|
|
72
|
+
return loadDevFileUrl(this, state, id);
|
|
52
73
|
},
|
|
53
74
|
};
|
|
54
75
|
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
import type { ConfigLoader } from "@gtkx/config";
|
|
1
2
|
import type { Plugin, UserConfig } from "vite";
|
|
3
|
+
import { createConfigLoader } from "@gtkx/config/internal";
|
|
2
4
|
import { info } from "@gtkx/utils";
|
|
3
5
|
import { readFileSync } from "node:fs";
|
|
4
6
|
import { join } from "node:path";
|
|
5
7
|
import type { AssetEmitter } from "./asset-emitter.js";
|
|
6
8
|
import { prependBanner } from "../internal/banner.js";
|
|
7
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
relativeIconPath,
|
|
11
|
+
resolveApplicationIcon,
|
|
12
|
+
type ResolvedApplicationIcon,
|
|
13
|
+
} from "../internal/icon-path.js";
|
|
8
14
|
import { type ListedFile, listFilesRecursive } from "../internal/list-files.js";
|
|
9
15
|
|
|
10
16
|
type PluginState = {
|
|
11
|
-
|
|
17
|
+
applicationId: string;
|
|
18
|
+
source: ResolvedApplicationIcon;
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
const ICONS_DIR = "icons";
|
|
@@ -20,14 +27,25 @@ const XDG_ENV_BANNER = [
|
|
|
20
27
|
"].join(\":\");",
|
|
21
28
|
].join("\n");
|
|
22
29
|
|
|
23
|
-
const findIconFiles = (
|
|
24
|
-
|
|
30
|
+
const findIconFiles = (state: PluginState): ListedFile[] => {
|
|
31
|
+
if (state.source.kind === "theme") {
|
|
32
|
+
return listFilesRecursive(state.source.path);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (state.source.kind === "none") {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
return [{
|
|
40
|
+
absPath: state.source.path,
|
|
41
|
+
rel: relativeIconPath(state.applicationId, state.source.path),
|
|
42
|
+
}];
|
|
43
|
+
};
|
|
29
44
|
|
|
30
|
-
|
|
45
|
+
const applyUserConfig = async (state: PluginState, config: UserConfig, loadConfig: ConfigLoader): Promise<void> => {
|
|
46
|
+
const { config: gtkxConfig, root } = await loadConfig.load(config.root ?? process.cwd());
|
|
47
|
+
state.applicationId = gtkxConfig.applicationId;
|
|
48
|
+
state.source = resolveApplicationIcon(root, gtkxConfig.applicationId, gtkxConfig.applicationIcon);
|
|
31
49
|
};
|
|
32
50
|
|
|
33
51
|
const emitIcons = (ctx: AssetEmitter, icons: ListedFile[]): void => {
|
|
@@ -40,9 +58,10 @@ const emitIcons = (ctx: AssetEmitter, icons: ListedFile[]): void => {
|
|
|
40
58
|
}
|
|
41
59
|
};
|
|
42
60
|
|
|
43
|
-
function gtkxIcons(): Plugin {
|
|
61
|
+
function gtkxIcons(loadConfig: ConfigLoader = createConfigLoader()): Plugin {
|
|
44
62
|
const state: PluginState = {
|
|
45
|
-
|
|
63
|
+
applicationId: "",
|
|
64
|
+
source: { kind: "none" },
|
|
46
65
|
};
|
|
47
66
|
|
|
48
67
|
return {
|
|
@@ -50,12 +69,12 @@ function gtkxIcons(): Plugin {
|
|
|
50
69
|
enforce: "pre",
|
|
51
70
|
apply: "build",
|
|
52
71
|
|
|
53
|
-
config(config: UserConfig) {
|
|
54
|
-
state
|
|
72
|
+
async config(config: UserConfig) {
|
|
73
|
+
await applyUserConfig(state, config, loadConfig);
|
|
55
74
|
},
|
|
56
75
|
|
|
57
76
|
outputOptions(options) {
|
|
58
|
-
if (findIconFiles(state
|
|
77
|
+
if (findIconFiles(state).length === 0) {
|
|
59
78
|
return;
|
|
60
79
|
}
|
|
61
80
|
|
|
@@ -63,7 +82,7 @@ function gtkxIcons(): Plugin {
|
|
|
63
82
|
},
|
|
64
83
|
|
|
65
84
|
buildEnd() {
|
|
66
|
-
emitIcons(this, findIconFiles(state
|
|
85
|
+
emitIcons(this, findIconFiles(state));
|
|
67
86
|
},
|
|
68
87
|
};
|
|
69
88
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import { createConfigLoader } from "@gtkx/config/internal";
|
|
3
3
|
import createConfigPlugin from "@gtkx/config/vite-plugin";
|
|
4
|
+
import type { BuildManifestCollector } from "../internal/build-manifest.js";
|
|
4
5
|
import { gtkxAssetImports } from "./asset-imports.js";
|
|
6
|
+
import { gtkxBuiltUrl } from "./built-url.js";
|
|
5
7
|
import { gtkxCss } from "./css.js";
|
|
6
8
|
import { gtkxIcons } from "./icons.js";
|
|
7
9
|
import { gtkxReactCompiler } from "./react-compiler.js";
|
|
@@ -10,17 +12,22 @@ import { gtkxSettings } from "./settings.js";
|
|
|
10
12
|
import { gtkxStoreLinks } from "./store-links.js";
|
|
11
13
|
import { gtkxUndeclaredLibrary } from "./undeclared-library.js";
|
|
12
14
|
|
|
13
|
-
const gtkxVitePlugins = (
|
|
15
|
+
const gtkxVitePlugins = (
|
|
16
|
+
mode?: string,
|
|
17
|
+
entryPath?: string,
|
|
18
|
+
buildManifest?: BuildManifestCollector,
|
|
19
|
+
): Plugin[] => {
|
|
14
20
|
const loadConfig = createConfigLoader(mode === undefined ? {} : { mode });
|
|
15
21
|
|
|
16
22
|
return [
|
|
17
23
|
createConfigPlugin({ name: "gtkx:config", loadConfig }),
|
|
18
24
|
gtkxStoreLinks(),
|
|
19
25
|
gtkxUndeclaredLibrary(loadConfig),
|
|
20
|
-
gtkxSettings(),
|
|
21
|
-
gtkxIcons(),
|
|
22
|
-
gtkxAssetImports(),
|
|
23
|
-
|
|
26
|
+
gtkxSettings(loadConfig, buildManifest),
|
|
27
|
+
gtkxIcons(loadConfig),
|
|
28
|
+
gtkxAssetImports(loadConfig),
|
|
29
|
+
gtkxBuiltUrl(),
|
|
30
|
+
gtkxResources(loadConfig, entryPath),
|
|
24
31
|
gtkxCss(),
|
|
25
32
|
gtkxReactCompiler(loadConfig),
|
|
26
33
|
];
|
|
@@ -6,6 +6,7 @@ import { dirname, join } from "node:path";
|
|
|
6
6
|
import { stripQuery } from "./strip-query.js";
|
|
7
7
|
|
|
8
8
|
const EMITTED_BINDING_SPECIFIER = "./gtkx.node";
|
|
9
|
+
const BINDING_FILENAME = "gtkx.node";
|
|
9
10
|
|
|
10
11
|
function resolveBinaryPath(projectRequire: ReturnType<typeof createRequire>, currentArch: string): string {
|
|
11
12
|
const nativeRoot = dirname(projectRequire.resolve("@gtkx/native/package.json"));
|
|
@@ -30,7 +31,7 @@ function resolvePlatformBinary(projectRequire: ReturnType<typeof createRequire>)
|
|
|
30
31
|
return readFileSync(resolveBinaryPath(projectRequire, currentArch));
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function rewriteLoader(code: string): string {
|
|
34
|
+
function rewriteLoader(code: string, bindingReferenceId: string): string {
|
|
34
35
|
const idents: string[] = [];
|
|
35
36
|
|
|
36
37
|
for (const match of code.matchAll(/export\s*\{\s*([A-Za-z0-9_$]+)\s*\}/g)) {
|
|
@@ -45,15 +46,37 @@ function rewriteLoader(code: string): string {
|
|
|
45
46
|
|
|
46
47
|
return [
|
|
47
48
|
"import { createRequire as __gtkxCreateRequire } from \"node:module\";",
|
|
48
|
-
|
|
49
|
+
"import { fileURLToPath as __gtkxFileURLToPath } from \"node:url\";",
|
|
50
|
+
`const __gtkxNativeLocation = import.meta.ROLLUP_FILE_URL_${bindingReferenceId};`,
|
|
51
|
+
"const __gtkxNativePath = __gtkxNativeLocation.startsWith(\"file:\") " +
|
|
52
|
+
"? __gtkxFileURLToPath(__gtkxNativeLocation) : __gtkxNativeLocation;",
|
|
53
|
+
"const __gtkxNative = __gtkxCreateRequire(import.meta.url)(__gtkxNativePath);",
|
|
49
54
|
`const { ${bindings} } = __gtkxNative;`,
|
|
50
55
|
`export { ${bindings} };`,
|
|
51
56
|
].join("\n");
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
const transformLoader = (
|
|
60
|
+
code: string,
|
|
61
|
+
id: string,
|
|
62
|
+
loaderPath: string,
|
|
63
|
+
bindingReferenceId: string | null,
|
|
64
|
+
): string | null => {
|
|
65
|
+
if (stripQuery(id) !== loaderPath) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (bindingReferenceId === null) {
|
|
70
|
+
throw new Error("Cannot render the native loader before its binary has been emitted");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return rewriteLoader(code, bindingReferenceId);
|
|
74
|
+
};
|
|
75
|
+
|
|
54
76
|
function gtkxNative(root: string): Plugin {
|
|
55
77
|
const projectRequire = createRequire(join(root, "package.json"));
|
|
56
78
|
let cachedLoaderPath: string | undefined;
|
|
79
|
+
let bindingReferenceId: string | null = null;
|
|
57
80
|
|
|
58
81
|
const loaderPath = (): string => {
|
|
59
82
|
cachedLoaderPath ??= join(dirname(projectRequire.resolve("@gtkx/native/package.json")), "index.js");
|
|
@@ -67,7 +90,11 @@ function gtkxNative(root: string): Plugin {
|
|
|
67
90
|
apply: "build",
|
|
68
91
|
|
|
69
92
|
buildStart() {
|
|
70
|
-
this.emitFile({
|
|
93
|
+
bindingReferenceId = this.emitFile({
|
|
94
|
+
type: "asset",
|
|
95
|
+
fileName: BINDING_FILENAME,
|
|
96
|
+
source: resolvePlatformBinary(projectRequire),
|
|
97
|
+
});
|
|
71
98
|
},
|
|
72
99
|
|
|
73
100
|
resolveId(id) {
|
|
@@ -75,7 +102,7 @@ function gtkxNative(root: string): Plugin {
|
|
|
75
102
|
},
|
|
76
103
|
|
|
77
104
|
transform(code, id) {
|
|
78
|
-
return
|
|
105
|
+
return transformLoader(code, id, loaderPath(), bindingReferenceId);
|
|
79
106
|
},
|
|
80
107
|
};
|
|
81
108
|
}
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { REFRESH_EXPORT, REGISTER_REFRESH_EXPORT } from "./resource-shared.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type InitModuleOptions = { isBuild: true; bundleReferenceId: string } |
|
|
4
|
+
{ isBuild: false; devBundlePath: string };
|
|
5
|
+
|
|
6
|
+
const refreshCallbackSource = (): string[] => [
|
|
7
|
+
"const refreshCallbacks = new Map();",
|
|
8
|
+
"",
|
|
9
|
+
`export function ${REGISTER_REFRESH_EXPORT}(key, callback) {`,
|
|
10
|
+
" refreshCallbacks.set(key, callback);",
|
|
11
|
+
" callback();",
|
|
12
|
+
"}",
|
|
13
|
+
"",
|
|
14
|
+
"function runRefreshCallbacks() {",
|
|
15
|
+
" for (const callback of refreshCallbacks.values()) callback();",
|
|
16
|
+
"}",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const buildInitModuleSource = (bundleReferenceId: string): string =>
|
|
4
20
|
[
|
|
5
|
-
"import { dirname, join } from \"node:path\";",
|
|
6
21
|
"import { fileURLToPath } from \"node:url\";",
|
|
7
22
|
"import { Resource, resourcesRegister } from \"@gtkx/gi/gio\";",
|
|
8
23
|
"",
|
|
9
|
-
|
|
10
|
-
|
|
24
|
+
`const bundleLocation = import.meta.ROLLUP_FILE_URL_${bundleReferenceId};`,
|
|
25
|
+
"const bundlePath = bundleLocation.startsWith(\"file:\") ? fileURLToPath(bundleLocation) : bundleLocation;",
|
|
26
|
+
"const resource = Resource.load(bundlePath);",
|
|
11
27
|
"resourcesRegister(resource);",
|
|
12
28
|
"",
|
|
29
|
+
...refreshCallbackSource(),
|
|
30
|
+
"",
|
|
13
31
|
"export function ensureRegistered() {}",
|
|
14
32
|
`export function ${REFRESH_EXPORT}() {}`,
|
|
15
33
|
].join("\n");
|
|
@@ -31,27 +49,38 @@ const devInitModuleSource = (bundlePath: string): string => {
|
|
|
31
49
|
" current = next;",
|
|
32
50
|
"}",
|
|
33
51
|
"",
|
|
52
|
+
"function unregister() {",
|
|
53
|
+
" if (!current) return;",
|
|
54
|
+
" resourcesUnregister(current);",
|
|
55
|
+
" current = null;",
|
|
56
|
+
" lastSig = \"\";",
|
|
57
|
+
"}",
|
|
58
|
+
"",
|
|
59
|
+
...refreshCallbackSource(),
|
|
60
|
+
"",
|
|
34
61
|
"export function ensureRegistered() {",
|
|
35
|
-
` if (!existsSync(${bundlePathLiteral}))
|
|
62
|
+
` if (!existsSync(${bundlePathLiteral})) {`,
|
|
63
|
+
" unregister();",
|
|
64
|
+
" return;",
|
|
65
|
+
" }",
|
|
36
66
|
` const { size, mtimeMs } = statSync(${bundlePathLiteral});`,
|
|
37
67
|
" const sig = size + \":\" + mtimeMs;",
|
|
38
|
-
" if (sig
|
|
39
|
-
"
|
|
40
|
-
"
|
|
68
|
+
" if (sig !== lastSig) {",
|
|
69
|
+
" register();",
|
|
70
|
+
" lastSig = sig;",
|
|
71
|
+
" }",
|
|
41
72
|
"}",
|
|
42
73
|
"",
|
|
43
74
|
"ensureRegistered();",
|
|
44
75
|
"",
|
|
45
76
|
`export function ${REFRESH_EXPORT}() {`,
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
` const { size, mtimeMs } = statSync(${bundlePathLiteral});`,
|
|
49
|
-
" lastSig = size + \":\" + mtimeMs;",
|
|
77
|
+
" ensureRegistered();",
|
|
78
|
+
" runRefreshCallbacks();",
|
|
50
79
|
"}",
|
|
51
80
|
].join("\n");
|
|
52
81
|
};
|
|
53
82
|
|
|
54
|
-
const renderInitModule = (options:
|
|
55
|
-
options.isBuild ? buildInitModuleSource() : devInitModuleSource(options.devBundlePath);
|
|
83
|
+
const renderInitModule = (options: InitModuleOptions): string =>
|
|
84
|
+
options.isBuild ? buildInitModuleSource(options.bundleReferenceId) : devInitModuleSource(options.devBundlePath);
|
|
56
85
|
|
|
57
86
|
export { renderInitModule };
|
|
@@ -4,7 +4,9 @@ const VIRTUAL_PREFIX = "\0gtkx-resources:";
|
|
|
4
4
|
const VIRTUAL_INIT = "\0gtkx-resources-init";
|
|
5
5
|
const BUNDLE_FILENAME = "gtkx.gresource";
|
|
6
6
|
const REL_SEPARATOR = "\0rel=";
|
|
7
|
+
const ICON_NAME_SEPARATOR = "\0icon=";
|
|
7
8
|
const REFRESH_EXPORT = "__refresh";
|
|
9
|
+
const REGISTER_REFRESH_EXPORT = "__registerRefresh";
|
|
8
10
|
const RESOURCE_PATH_EXPORT = "path";
|
|
9
11
|
const { isVirtual, toVirtualId, fromVirtualId } = createVirtualNamespace(VIRTUAL_PREFIX);
|
|
10
12
|
|
|
@@ -33,7 +35,9 @@ export {
|
|
|
33
35
|
VIRTUAL_INIT,
|
|
34
36
|
BUNDLE_FILENAME,
|
|
35
37
|
REL_SEPARATOR,
|
|
38
|
+
ICON_NAME_SEPARATOR,
|
|
36
39
|
REFRESH_EXPORT,
|
|
40
|
+
REGISTER_REFRESH_EXPORT,
|
|
37
41
|
RESOURCE_PATH_EXPORT,
|
|
38
42
|
escapeXml,
|
|
39
43
|
isVirtual,
|