@gtkx/cli 2.0.0-beta.8 → 2.0.0-beta.9

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.
Files changed (42) hide show
  1. package/dist/deploy/depends.d.ts.map +1 -1
  2. package/dist/deploy/depends.js +24 -2
  3. package/dist/deploy/depends.js.map +1 -1
  4. package/dist/deploy/node-runtime/guard.d.ts.map +1 -1
  5. package/dist/deploy/node-runtime/guard.js +7 -14
  6. package/dist/deploy/node-runtime/guard.js.map +1 -1
  7. package/dist/deploy/node-runtime/index.d.ts +2 -1
  8. package/dist/deploy/node-runtime/index.d.ts.map +1 -1
  9. package/dist/deploy/node-runtime/index.js +15 -4
  10. package/dist/deploy/node-runtime/index.js.map +1 -1
  11. package/dist/deploy/node-runtime/sonames.d.ts +5 -0
  12. package/dist/deploy/node-runtime/sonames.d.ts.map +1 -0
  13. package/dist/deploy/node-runtime/sonames.js +13 -0
  14. package/dist/deploy/node-runtime/sonames.js.map +1 -0
  15. package/dist/deploy/run-deploy.d.ts.map +1 -1
  16. package/dist/deploy/run-deploy.js +4 -1
  17. package/dist/deploy/run-deploy.js.map +1 -1
  18. package/dist/internal/icon-staging.d.ts +3 -0
  19. package/dist/internal/icon-staging.d.ts.map +1 -0
  20. package/dist/internal/icon-staging.js +40 -0
  21. package/dist/internal/icon-staging.js.map +1 -0
  22. package/dist/vite-plugins/icon-worker-env.d.ts +4 -0
  23. package/dist/vite-plugins/icon-worker-env.d.ts.map +1 -0
  24. package/dist/vite-plugins/icon-worker-env.js +23 -0
  25. package/dist/vite-plugins/icon-worker-env.js.map +1 -0
  26. package/dist/vite-plugins/worker.d.ts.map +1 -1
  27. package/dist/vite-plugins/worker.js +21 -13
  28. package/dist/vite-plugins/worker.js.map +1 -1
  29. package/dist/vitest-plugin.d.ts +2 -2
  30. package/dist/vitest-plugin.d.ts.map +1 -1
  31. package/dist/vitest-plugin.js +4 -2
  32. package/dist/vitest-plugin.js.map +1 -1
  33. package/package.json +10 -10
  34. package/src/deploy/depends.ts +30 -3
  35. package/src/deploy/node-runtime/guard.ts +10 -14
  36. package/src/deploy/node-runtime/index.ts +19 -4
  37. package/src/deploy/node-runtime/sonames.ts +17 -0
  38. package/src/deploy/run-deploy.ts +6 -1
  39. package/src/internal/icon-staging.ts +58 -0
  40. package/src/vite-plugins/icon-worker-env.ts +36 -0
  41. package/src/vite-plugins/worker.ts +31 -15
  42. package/src/vitest-plugin.ts +4 -2
@@ -7,12 +7,17 @@ import { stripQuery } from "./strip-query.js";
7
7
  type WorkerReplacement = {
8
8
  start: number;
9
9
  end: number;
10
- fileName: string;
10
+ referenceId: string;
11
+ };
12
+
13
+ type WorkerReferences = {
14
+ byModule: Map<string, string>;
15
+ claimed: Set<string>;
11
16
  };
12
17
 
13
18
  type EmitContext = {
14
19
  context: Rollup.PluginContext;
15
- emitted: Map<string, string>;
20
+ references: WorkerReferences;
16
21
  };
17
22
 
18
23
  type SourceRange = {
@@ -83,10 +88,12 @@ const isWorkerConstruction = (code: string, matchIndex: number): boolean =>
83
88
 
84
89
  const hasWorkerCandidate = (code: string): boolean => code.includes("import.meta.url") && code.includes("Worker");
85
90
 
86
- const workerUrlExpression = (fileName: string): string => {
87
- const specifier = JSON.stringify(`./${fileName}`);
91
+ const workerUrlReference = (referenceId: string): string => `import.meta.ROLLUP_FILE_URL_${referenceId}`;
92
+
93
+ const workerUrlExpression = (relativePath: string): string => {
94
+ const specifier = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
88
95
 
89
- return `new URL(${specifier}, import.meta.url)`;
96
+ return `new URL(${JSON.stringify(specifier)}, import.meta.url)`;
90
97
  };
91
98
 
92
99
  const inlineWorkerExample = (specifier: string): string =>
@@ -125,17 +132,22 @@ const suggestionFor = async (emit: EmitContext, scan: ScanContext, specifier: st
125
132
  };
126
133
 
127
134
  const claimWorker = (emit: EmitContext, resolvedId: string): string => {
128
- const existing = emit.emitted.get(resolvedId);
135
+ const existing = emit.references.byModule.get(resolvedId);
129
136
 
130
137
  if (existing !== undefined) {
131
138
  return existing;
132
139
  }
133
140
 
134
- const fileName = workerFileName(resolvedId);
135
- emit.emitted.set(resolvedId, fileName);
136
- emit.context.emitFile({ type: "chunk", id: resolvedId, fileName });
141
+ const referenceId = emit.context.emitFile({
142
+ type: "chunk",
143
+ id: resolvedId,
144
+ fileName: workerFileName(resolvedId),
145
+ });
137
146
 
138
- return fileName;
147
+ emit.references.byModule.set(resolvedId, referenceId);
148
+ emit.references.claimed.add(referenceId);
149
+
150
+ return referenceId;
139
151
  };
140
152
 
141
153
  const isRewritableUrl = (scan: ScanContext, match: RegExpExecArray): boolean =>
@@ -158,7 +170,7 @@ const replacementFor = async (
158
170
  throw unresolvedWorkerError(scan, specifier, await suggestionFor(emit, scan, specifier));
159
171
  }
160
172
 
161
- return { start: match.index, end: match.index + match[0].length, fileName: claimWorker(emit, resolved.id) };
173
+ return { start: match.index, end: match.index + match[0].length, referenceId: claimWorker(emit, resolved.id) };
162
174
  };
163
175
 
164
176
  const collectReplacements = async (emit: EmitContext, scan: ScanContext): Promise<WorkerReplacement[]> => {
@@ -196,8 +208,8 @@ const applyReplacements = (code: string, replacements: WorkerReplacement[]): str
196
208
  let output = "";
197
209
  let cursor = 0;
198
210
 
199
- for (const { start, end, fileName } of replacements) {
200
- output += code.slice(cursor, start) + workerUrlExpression(fileName);
211
+ for (const { start, end, referenceId } of replacements) {
212
+ output += code.slice(cursor, start) + workerUrlReference(referenceId);
201
213
  cursor = end;
202
214
  }
203
215
 
@@ -222,14 +234,18 @@ const transformWorkerUrls = async (emit: EmitContext, code: string, id: string):
222
234
  };
223
235
 
224
236
  function gtkxWorker(): Plugin {
225
- const emitted: Map<string, string> = new Map();
237
+ const references: WorkerReferences = { byModule: new Map(), claimed: new Set() };
226
238
 
227
239
  return {
228
240
  name: "gtkx:worker",
229
241
  apply: "build",
230
242
 
231
243
  transform(code, id) {
232
- return transformWorkerUrls({ context: this, emitted }, code, id);
244
+ return transformWorkerUrls({ context: this, references }, code, id);
245
+ },
246
+
247
+ resolveFileUrl({ referenceId, relativePath }) {
248
+ return references.claimed.has(referenceId) ? workerUrlExpression(relativePath) : null;
233
249
  },
234
250
  };
235
251
  }
@@ -2,13 +2,14 @@ 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
4
  import { gtkxFontWorkerEnv } from "./vite-plugins/font-worker-env.js";
5
+ import { gtkxIconWorkerEnv } from "./vite-plugins/icon-worker-env.js";
5
6
  import { gtkxVitePlugins } from "./vite-plugins/index.js";
6
7
  import { gtkxSettingsWorkerEnv } from "./vite-plugins/settings-worker-env.js";
7
8
 
8
9
  /**
9
10
  * Vite plugin stack for testing a GTKX application: the generated bindings the tests import,
10
- * the plugins the app is built with, the project's compiled GSettings schemas exposed to every
11
- * test worker, and a headless display per worker.
11
+ * the plugins the app is built with, the project's compiled GSettings schemas and its configured
12
+ * application icon exposed to every test worker, and a headless display per worker.
12
13
  *
13
14
  * @returns The plugins to spread into a Vitest config.
14
15
  */
@@ -17,6 +18,7 @@ const gtkx = (options: PluginOptions = {}): Plugin[] => [
17
18
  ...gtkxVitePlugins({ configFile: options.configFile }),
18
19
  gtkxSettingsWorkerEnv(options.configFile),
19
20
  gtkxFontWorkerEnv(options.configFile),
21
+ gtkxIconWorkerEnv(options.configFile),
20
22
  gtkxVitest(options),
21
23
  ];
22
24