@gjsify/rolldown-plugin-gjsify 0.64.2 → 0.64.3-next.259

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 CHANGED
@@ -53,7 +53,7 @@ For a GJS build the bundle records the addon's **package identity**, not a path
53
53
 
54
54
  ## `.gresource.xml` imports
55
55
 
56
- `import bytes from './data/app.data.gresource.xml'` yields the compiled GResource as a `Uint8Array` ([ADR 0116](../../../docs/adr/0116-app-gresources-are-embedded-at-build-time-for-web-and-nativescript.md)). To type it, add `"@gjsify/rolldown-plugin-gjsify/types"` to your `tsconfig.json` `compilerOptions.types`.
56
+ `import bytes from './data/app.data.gresource.xml'` yields the compiled GResource as a `Uint8Array` ([ADR 0116](../../../docs/adr/0116-app-gresources-are-embedded-at-build-time-for-web-and-nativescript.md)). To type it, add `"@gjsify/rolldown-plugin-gjsify/types"` to your `tsconfig.json` `compilerOptions.types`. The same entry declares `*.gschema.xml?schema` ([ADR 0099](../../../docs/adr/0099-gio-settings-runs-on-the-browser-and-nativescript.md) § 1).
57
57
 
58
58
  ## License
59
59
 
@@ -31,7 +31,7 @@ import { giRendererPlugin } from '../plugins/gi-renderer.js';
31
31
  import { blueprintTemplateExit } from '../utils/blueprint-template-exit.js';
32
32
  import { cssAsStringPlugin } from '../plugins/css-as-string.js';
33
33
  import { unresolvedWorkspaceImportPlugin } from '../plugins/unresolved-workspace-import.js';
34
- import { gschemaPlugin } from '../plugins/gschema.js';
34
+ import { GSCHEMA_REGISTER, gschemaPlugin } from '../plugins/gschema.js';
35
35
  import { gresourcePlugin } from '../plugins/gresource.js';
36
36
  import { implicitGlobalAssignPlugin } from '../plugins/implicit-global-assign.js';
37
37
  export const setupForBrowser = async (input) => {
@@ -145,7 +145,7 @@ export const setupForBrowser = async (input) => {
145
145
  // readily as a read, so `window = {…}` would emit `globalThis = {…}` — code that
146
146
  // replaces the whole global object. This transform runs first and leaves the define
147
147
  // nothing to rewrite; the guarded branch stays unreachable on a page either way.
148
- gschemaPlugin({ mode: 'emit' }),
148
+ gschemaPlugin({ mode: 'emit', register: GSCHEMA_REGISTER.browser }),
149
149
  gresourcePlugin({ compressed: 'strip' }),
150
150
  implicitGlobalAssignPlugin(),
151
151
  cssAsStringPlugin(),
@@ -47,7 +47,7 @@ import { giRendererPlugin } from '../plugins/gi-renderer.js';
47
47
  import { blueprintTemplateExit } from '../utils/blueprint-template-exit.js';
48
48
  import { platformResolvePlugin, nativescriptSuffixChain, detectNativescriptPlatform, nativescriptPlatformDefines, } from '../plugins/platform-resolve.js';
49
49
  import { unresolvedWorkspaceImportPlugin } from '../plugins/unresolved-workspace-import.js';
50
- import { gschemaPlugin } from '../plugins/gschema.js';
50
+ import { GSCHEMA_REGISTER, gschemaPlugin } from '../plugins/gschema.js';
51
51
  import { gresourcePlugin } from '../plugins/gresource.js';
52
52
  import { implicitGlobalAssignPlugin } from '../plugins/implicit-global-assign.js';
53
53
  // Never bundled: an app works only with the ONE core instance the runtime boots, and what
@@ -188,7 +188,7 @@ export const setupForNativescript = async (input) => {
188
188
  // a NativeScript app gates on the absence of `window`, but a WRITE to it is a
189
189
  // `ReferenceError` in a strict module body, not a gate. `globalThis.window = …`
190
190
  // holds the author's intent; the guard and the absence are untouched.
191
- gschemaPlugin({ mode: 'emit' }),
191
+ gschemaPlugin({ mode: 'emit', register: GSCHEMA_REGISTER.nativescript }),
192
192
  gresourcePlugin({ compressed: 'strip' }),
193
193
  implicitGlobalAssignPlugin(),
194
194
  // NO cssAsStringPlugin — NS ships its own CSS pipeline via
package/lib/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export type { GiSystemProbe } from './plugins/gi-runtime-paths.js';
13
13
  export type { ProcessStubPluginOptions } from './plugins/process-stub.js';
14
14
  export { findImplicitGlobalAssignments, rewriteImplicitGlobalAssignments, implicitGlobalAssignPlugin, IMPLICIT_GLOBAL_ASSIGN_PLUGIN, } from './plugins/implicit-global-assign.js';
15
15
  export type { ImplicitGlobalAssignment } from './plugins/implicit-global-assign.js';
16
- export { gschemaPlugin, parseGschema, GSCHEMA_PLUGIN } from './plugins/gschema.js';
16
+ export { gschemaPlugin, parseGschema, GSCHEMA_PLUGIN, GSCHEMA_REGISTER } from './plugins/gschema.js';
17
17
  export type { GschemaOut, GschemaKey, GschemaPluginOptions } from './plugins/gschema.js';
18
18
  export { gresourcePlugin, compileGresource, prepareGresourceXml, gresourceModuleSource, GRESOURCE_PLUGIN, } from './plugins/gresource.js';
19
19
  export type { GresourcePluginOptions } from './plugins/gresource.js';
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ export { giRuntimePathsStub } from './plugins/gi-runtime-paths.js';
9
9
  export { giOptionalPlugin, giOptionalShimSource, giOptionalNodeShimSource, giOptionalMarkerSource, parseOptionalGiSpecifier, GI_OPTIONAL_FLAG, GI_OPTIONAL_MARKER, } from './plugins/gi-optional.js';
10
10
  export { bindConsoleLocally, consoleAssignPlugin, freeConsoleAssignmentInsertion, CONSOLE_LOCAL_BINDING, } from './plugins/console-assign.js';
11
11
  export { findImplicitGlobalAssignments, rewriteImplicitGlobalAssignments, implicitGlobalAssignPlugin, IMPLICIT_GLOBAL_ASSIGN_PLUGIN, } from './plugins/implicit-global-assign.js';
12
- export { gschemaPlugin, parseGschema, GSCHEMA_PLUGIN } from './plugins/gschema.js';
12
+ export { gschemaPlugin, parseGschema, GSCHEMA_PLUGIN, GSCHEMA_REGISTER } from './plugins/gschema.js';
13
13
  export { gresourcePlugin, compileGresource, prepareGresourceXml, gresourceModuleSource, GRESOURCE_PLUGIN, } from './plugins/gresource.js';
14
14
  export { cssAsStringPlugin } from './plugins/css-as-string.js';
15
15
  export { textLoaderPlugin } from './plugins/text-loader.js';
@@ -1,8 +1,10 @@
1
1
  import type { Plugin } from 'rolldown';
2
2
  export declare const GSCHEMA_PLUGIN = "gjsify-gschema";
3
+ type BasicType = 'b' | 'i' | 'u' | 'd' | 's';
4
+ type BasicValue = boolean | number | string;
3
5
  export interface GschemaKey {
4
- type: 'b' | 'i' | 'u' | 'd' | 's';
5
- default: boolean | number | string;
6
+ type: BasicType | `a${BasicType}`;
7
+ default: BasicValue | BasicValue[];
6
8
  }
7
9
  export interface GschemaOut {
8
10
  id: string;
@@ -13,5 +15,17 @@ export declare function parseGschema(xml: string, file: string): GschemaOut;
13
15
  export interface GschemaPluginOptions {
14
16
  /** `emit`: the schema object (browser, NativeScript). `ignore`: the file path, for GJS/Node. */
15
17
  mode: 'emit' | 'ignore';
18
+ /**
19
+ * `emit` only: the module whose `Settings` the schema registers with, so the import alone is
20
+ * the registration and the app keeps to GIO's names. The port's `Gio` barrel re-exports the
21
+ * same `Settings`, so `new Gio.Settings(...)` finds the schema.
22
+ */
23
+ register?: string;
16
24
  }
17
- export declare function gschemaPlugin({ mode }: GschemaPluginOptions): Plugin;
25
+ /** The `Settings` each port's `Gio` barrel re-exports (ADR 0099). */
26
+ export declare const GSCHEMA_REGISTER: {
27
+ readonly browser: "@gjsify/app-settings/browser";
28
+ readonly nativescript: "@gjsify/app-settings/nativescript";
29
+ };
30
+ export declare function gschemaPlugin({ mode, register }: GschemaPluginOptions): Plugin;
31
+ export {};
@@ -3,16 +3,17 @@
3
3
  // The `.gschema.xml` stays the single source. On the targets with no Gio.Settings (browser,
4
4
  // NativeScript) the build reads it and emits `{ id, path, keys: { name: { type, default } } }`;
5
5
  // the runtime never parses XML. On GJS and Node the compiled schema is what GSettings reads
6
- // (`gjsify gsettings` builds it), so the import evaluates to the file's path and is ignored by
7
- // the no-op `Settings.register`.
6
+ // (`gjsify gsettings` builds it), so the import evaluates to the file's path. The app builds
7
+ // register the schema as the module evaluates (`register`), so importing it once, before the first
8
+ // `new Gio.Settings`, is all an app does on every target.
8
9
  //
9
10
  // What the subset cannot honour is refused HERE, naming the key and the line, rather than
10
- // compiled into a schema that behaves differently from GNOME's: a key type outside `b i u d s`,
11
- // `<range>`, `<choices>`, `<enum>`, `<flags>`, `<child>`, `<override>`, and a schema without
11
+ // compiled into a schema that behaves differently from GNOME's: a key type outside `b i u d s`
12
+ // and the arrays of them (`ab ai au ad as`, ADR 0118 § 3), `<range>`, `<choices>`, `<enum>`, `<flags>`, `<child>`, `<override>`, and a schema without
12
13
  // `path` (the storage key is `<path><key>`).
13
14
  import { readFile } from 'node:fs/promises';
14
15
  export const GSCHEMA_PLUGIN = 'gjsify-gschema';
15
- const KEY_TYPES = new Set(['b', 'i', 'u', 'd', 's']);
16
+ const KEY_TYPES = new Set(['b', 'i', 'u', 'd', 's', 'ab', 'ai', 'au', 'ad', 'as']);
16
17
  const REFUSED_TAGS = ['range', 'choices', 'enum', 'flags', 'child', 'override'];
17
18
  function lineOf(xml, index) {
18
19
  return xml.slice(0, index).split('\n').length;
@@ -31,9 +32,54 @@ function unescapeXml(s) {
31
32
  .replace(/&apos;/g, "'")
32
33
  .replace(/&amp;/g, '&');
33
34
  }
34
- /** GVariant text format for the five supported types. */
35
+ /**
36
+ * The elements of an array default: `[]`, `@ai []` or `[a, b, …]`. Restricted to what a schema
37
+ * default of `ab ai au ad as` holds; the runtime reads stored values with adwaita-core's
38
+ * `GLibVariant.parseText`, which this build step cannot depend on.
39
+ */
40
+ function splitArray(text, type) {
41
+ const body = text.replace(new RegExp(`^@${type}\\s+`), '');
42
+ if (!body.startsWith('[') || !body.endsWith(']'))
43
+ return undefined;
44
+ const inner = body.slice(1, -1).trim();
45
+ if (inner === '')
46
+ return [];
47
+ const items = [];
48
+ let start = 0;
49
+ let quote = '';
50
+ for (let i = 0; i < inner.length; i++) {
51
+ const c = inner[i];
52
+ if (quote) {
53
+ if (c === '\\')
54
+ i++;
55
+ else if (c === quote)
56
+ quote = '';
57
+ }
58
+ else if (c === "'" || c === '"')
59
+ quote = c;
60
+ else if (c === ',') {
61
+ items.push(inner.slice(start, i).trim());
62
+ start = i + 1;
63
+ }
64
+ }
65
+ if (quote)
66
+ return undefined;
67
+ items.push(inner.slice(start).trim());
68
+ return items.includes('') ? undefined : items;
69
+ }
70
+ /** GVariant text format for the supported types. */
35
71
  function parseDefault(raw, type, where) {
36
72
  const text = unescapeXml(raw.trim());
73
+ if (type.length === 2) {
74
+ const items = splitArray(text, type);
75
+ const element = type[1];
76
+ if (items)
77
+ return items.map((item) => parseBasic(item, element, where));
78
+ throw new Error(`${where}: default '${text}' is not a valid '${type}' value`);
79
+ }
80
+ return parseBasic(text, type, where);
81
+ }
82
+ function parseBasic(text, type, where) {
37
83
  if (type === 'b') {
38
84
  if (text === 'true' || text === 'false')
39
85
  return text === 'true';
@@ -79,7 +125,7 @@ export function parseGschema(xml, file) {
79
125
  if (!name)
80
126
  throw new Error(`${where}: <key> has no name`);
81
127
  if (!type || !KEY_TYPES.has(type)) {
82
- throw new Error(`${where}: key '${name}' has type '${type}'; the subset supports b, i, u, d, s`);
128
+ throw new Error(`${where}: key '${name}' has type '${type}'; the subset supports b, i, u, d, s and arrays of them`);
83
129
  }
84
130
  const def = /<default\b[^>]*>([\s\S]*?)<\/default>/.exec(m[2]);
85
131
  if (!def)
@@ -92,7 +138,12 @@ export function parseGschema(xml, file) {
92
138
  return { id, path, keys };
93
139
  }
94
140
  const SUFFIX = /\.gschema\.xml\?schema(?:&|$)/;
95
- export function gschemaPlugin({ mode }) {
141
+ /** The `Settings` each port's `Gio` barrel re-exports (ADR 0099). */
142
+ export const GSCHEMA_REGISTER = {
143
+ browser: '@gjsify/app-settings/browser',
144
+ nativescript: '@gjsify/app-settings/nativescript',
145
+ };
146
+ export function gschemaPlugin({ mode, register }) {
96
147
  return {
97
148
  name: GSCHEMA_PLUGIN,
98
149
  async resolveId(source, importer) {
@@ -110,7 +161,14 @@ export function gschemaPlugin({ mode }) {
110
161
  return `export default ${JSON.stringify(file)};`;
111
162
  const schema = parseGschema(await readFile(file, 'utf8'), file);
112
163
  this.addWatchFile(file);
113
- return `export default ${JSON.stringify(schema)};`;
164
+ if (register === undefined)
165
+ return `export default ${JSON.stringify(schema)};`;
166
+ return [
167
+ `import { Settings } from ${JSON.stringify(register)};`,
168
+ `const schema = ${JSON.stringify(schema)};`,
169
+ 'Settings.register(schema);',
170
+ 'export default schema;',
171
+ ].join('\n');
114
172
  },
115
173
  };
116
174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/rolldown-plugin-gjsify",
3
- "version": "0.64.2",
3
+ "version": "0.64.3-next.259",
4
4
  "description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -20,7 +20,7 @@
20
20
  "default": "./lib/utils/runtime.js"
21
21
  },
22
22
  "./types": {
23
- "types": "./types/gresource.d.ts"
23
+ "types": "./types/index.d.ts"
24
24
  },
25
25
  "./shims/console-gjs": {
26
26
  "default": "./lib/shims/console-gjs.js"
@@ -67,12 +67,12 @@
67
67
  ],
68
68
  "license": "MIT",
69
69
  "dependencies": {
70
- "@gjsify/console": "^0.64.2",
71
- "@gjsify/resolve-npm": "^0.64.2",
72
- "@gjsify/rolldown-plugin-deepkit": "^0.64.2",
73
- "@gjsify/rolldown-plugin-pnp": "^0.64.2",
74
- "@gjsify/utils": "^0.64.2",
75
- "@gjsify/vite-plugin-blueprint": "^0.64.2",
70
+ "@gjsify/console": "0.64.3-next.259",
71
+ "@gjsify/resolve-npm": "0.64.3-next.259",
72
+ "@gjsify/rolldown-plugin-deepkit": "0.64.3-next.259",
73
+ "@gjsify/rolldown-plugin-pnp": "0.64.3-next.259",
74
+ "@gjsify/utils": "0.64.3-next.259",
75
+ "@gjsify/vite-plugin-blueprint": "0.64.3-next.259",
76
76
  "@rollup/pluginutils": "^5.4.0",
77
77
  "acorn": "^8.17.0",
78
78
  "acorn-typescript": "^1.4.13",
@@ -82,7 +82,7 @@
82
82
  "sass": "^1.101.0"
83
83
  },
84
84
  "peerDependencies": {
85
- "@gjsify/lightningcss-native": "^0.64.2",
85
+ "@gjsify/lightningcss-native": "0.64.3-next.259",
86
86
  "rolldown": "^1.1.4"
87
87
  },
88
88
  "peerDependenciesMeta": {
@@ -94,8 +94,8 @@
94
94
  }
95
95
  },
96
96
  "devDependencies": {
97
- "@gjsify/cli": "^0.64.2",
98
- "@gjsify/unit": "^0.64.2",
97
+ "@gjsify/cli": "0.64.3-next.259",
98
+ "@gjsify/unit": "0.64.3-next.259",
99
99
  "@types/node": "^25.9.2",
100
100
  "rolldown": "^1.1.4",
101
101
  "typescript": "^6.0.3"
@@ -107,5 +107,6 @@
107
107
  "darwin": "supported",
108
108
  "win32": "supported"
109
109
  }
110
- }
110
+ },
111
+ "gitHead": "84f8ece003be30456a8ace70115e480bf3220d47"
111
112
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `import bytes from './data/<app-id>.data.gresource.xml'` (ADR 0116 § 1): the loader in
3
+ * `plugins/gresource.ts` compiles the descriptor with `glib-compile-resources` and the module's
4
+ * default export is the compiled GResource, for `Gio.Resource.new_from_data(bytes)`.
5
+ */
6
+ declare module '*.gresource.xml' {
7
+ const bytes: Uint8Array;
8
+ export default bytes;
9
+ }
10
+
11
+ /**
12
+ * `import './<app-id>.gschema.xml?schema'` (ADR 0099 § 1): on the browser and NativeScript the
13
+ * loader in `plugins/gschema.ts` parses the schema at build time and registers it with the
14
+ * `Gio.Settings` subset; on GJS and Node the import is the file's path and GSettings reads the
15
+ * compiled schema.
16
+ */
17
+ declare module '*.gschema.xml?schema' {
18
+ const schema: unknown;
19
+ export default schema;
20
+ }
@@ -1,9 +0,0 @@
1
- /**
2
- * `import bytes from './data/<app-id>.data.gresource.xml'` (ADR 0116 § 1): the loader in
3
- * `plugins/gresource.ts` compiles the descriptor with `glib-compile-resources` and the module's
4
- * default export is the compiled GResource, for `Gio.Resource.new_from_data(bytes)`.
5
- */
6
- declare module '*.gresource.xml' {
7
- const bytes: Uint8Array;
8
- export default bytes;
9
- }