@apollo/client-ai-apps 0.2.4 → 0.3.1
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/.git-blame-ignore-revs +2 -0
- package/.github/workflows/compare-build-output.yml +28 -0
- package/.github/workflows/pr.yaml +23 -15
- package/.github/workflows/release.yaml +46 -46
- package/.prettierrc +9 -0
- package/config/compare-build-output-to.sh +90 -0
- package/dist/core/ApolloClient.d.ts +14 -0
- package/dist/index.d.ts +17 -10
- package/dist/index.js +164 -62
- package/dist/link/ToolCallLink.d.ts +26 -0
- package/dist/react/ApolloProvider.d.ts +9 -0
- package/dist/react/context/ToolUseContext.d.ts +15 -0
- package/dist/{hooks → react/hooks}/useOpenAiGlobal.d.ts +1 -1
- package/dist/react/hooks/useOpenExternal.d.ts +3 -0
- package/dist/{hooks → react/hooks}/useRequestDisplayMode.d.ts +1 -1
- package/dist/{hooks → react/hooks}/useToolEffect.d.ts +0 -4
- package/dist/react/hooks/useToolOutput.d.ts +1 -0
- package/dist/react/hooks/useToolResponseMetadata.d.ts +1 -0
- package/dist/react/hooks/useWidgetState.d.ts +4 -0
- package/dist/types/openai.d.ts +1 -2
- package/dist/vite/index.js +74 -21
- package/package.json +9 -2
- package/scripts/dev.mjs +3 -1
- package/src/core/ApolloClient.ts +108 -0
- package/src/{apollo_client/client.test.ts → core/__tests__/ApolloClient.test.ts} +232 -20
- package/src/index.ts +36 -10
- package/src/link/ToolCallLink.ts +49 -0
- package/src/{apollo_client/provider.tsx → react/ApolloProvider.tsx} +19 -9
- package/src/{apollo_client/provider.test.tsx → react/__tests__/ApolloProvider.test.tsx} +9 -9
- package/src/react/context/ToolUseContext.tsx +30 -0
- package/src/{hooks → react/hooks/__tests__}/useCallTool.test.ts +1 -1
- package/src/{hooks → react/hooks/__tests__}/useOpenAiGlobal.test.ts +5 -3
- package/src/react/hooks/__tests__/useOpenExternal.test.tsx +24 -0
- package/src/{hooks → react/hooks/__tests__}/useRequestDisplayMode.test.ts +2 -2
- package/src/{hooks → react/hooks/__tests__}/useSendFollowUpMessage.test.ts +4 -2
- package/src/{hooks → react/hooks/__tests__}/useToolEffect.test.tsx +27 -10
- package/src/{hooks → react/hooks/__tests__}/useToolInput.test.ts +1 -1
- package/src/{hooks → react/hooks/__tests__}/useToolName.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolOutput.test.tsx +49 -0
- package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +49 -0
- package/src/react/hooks/__tests__/useWidgetState.test.tsx +158 -0
- package/src/react/hooks/useCallTool.ts +13 -0
- package/src/{hooks → react/hooks}/useOpenAiGlobal.ts +11 -5
- package/src/react/hooks/useOpenExternal.ts +11 -0
- package/src/{hooks → react/hooks}/useRequestDisplayMode.ts +1 -1
- package/src/react/hooks/useToolEffect.tsx +37 -0
- package/src/{hooks → react/hooks}/useToolName.ts +1 -1
- package/src/react/hooks/useToolOutput.ts +5 -0
- package/src/react/hooks/useToolResponseMetadata.ts +5 -0
- package/src/react/hooks/useWidgetState.ts +48 -0
- package/src/testing/internal/index.ts +2 -0
- package/src/testing/internal/matchers/index.d.ts +9 -0
- package/src/testing/internal/matchers/index.ts +1 -0
- package/src/testing/internal/matchers/toRerender.ts +49 -0
- package/src/testing/internal/openai/dispatchStateChange.ts +9 -0
- package/src/testing/internal/openai/stubOpenAiGlobals.ts +13 -0
- package/src/types/openai.ts +6 -3
- package/src/vite/{absolute_asset_imports_plugin.test.ts → __tests__/absolute_asset_imports_plugin.test.ts} +4 -2
- package/src/vite/{application_manifest_plugin.test.ts → __tests__/application_manifest_plugin.test.ts} +176 -53
- package/src/vite/absolute_asset_imports_plugin.ts +3 -1
- package/src/vite/application_manifest_plugin.ts +84 -24
- package/vitest-setup.ts +1 -0
- package/dist/apollo_client/client.d.ts +0 -14
- package/dist/apollo_client/provider.d.ts +0 -5
- package/src/apollo_client/client.ts +0 -90
- package/src/hooks/useCallTool.ts +0 -8
- package/src/hooks/useToolEffect.tsx +0 -41
- /package/dist/{hooks → react/hooks}/useSendFollowUpMessage.d.ts +0 -0
- /package/dist/{hooks → react/hooks}/useToolInput.d.ts +0 -0
- /package/dist/{hooks → react/hooks}/useToolName.d.ts +0 -0
- /package/src/{hooks → react/hooks}/useSendFollowUpMessage.ts +0 -0
- /package/src/{hooks → react/hooks}/useToolInput.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test, vi, describe, beforeEach, Mock } from "vitest";
|
|
2
|
-
import { ApplicationManifestPlugin } from "
|
|
2
|
+
import { ApplicationManifestPlugin } from "../application_manifest_plugin";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import * as glob from "glob";
|
|
5
5
|
import path from "path";
|
|
@@ -23,7 +23,9 @@ vi.mock(import("path"), async (importOriginal) => {
|
|
|
23
23
|
return {
|
|
24
24
|
default: {
|
|
25
25
|
...actual.default,
|
|
26
|
-
resolve: vi.fn((...args) =>
|
|
26
|
+
resolve: vi.fn((...args) =>
|
|
27
|
+
args.map((a, i) => (i === 0 ? a : a.replace(/^\//, ""))).join("/")
|
|
28
|
+
),
|
|
27
29
|
dirname: vi.fn(),
|
|
28
30
|
},
|
|
29
31
|
};
|
|
@@ -55,11 +57,17 @@ describe("buildStart", () => {
|
|
|
55
57
|
`;
|
|
56
58
|
}
|
|
57
59
|
});
|
|
58
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
60
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
61
|
+
Promise.resolve(["my-component.tsx"])
|
|
62
|
+
);
|
|
59
63
|
vi.spyOn(fs, "writeFileSync");
|
|
60
64
|
|
|
61
65
|
const plugin = ApplicationManifestPlugin();
|
|
62
|
-
plugin.configResolved({
|
|
66
|
+
plugin.configResolved({
|
|
67
|
+
command: "serve",
|
|
68
|
+
server: {},
|
|
69
|
+
build: { outDir: "/dist" },
|
|
70
|
+
});
|
|
63
71
|
await plugin.buildStart();
|
|
64
72
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
65
73
|
|
|
@@ -120,7 +128,9 @@ describe("buildStart", () => {
|
|
|
120
128
|
`;
|
|
121
129
|
}
|
|
122
130
|
});
|
|
123
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
131
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
132
|
+
Promise.resolve(["my-component.tsx"])
|
|
133
|
+
);
|
|
124
134
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
125
135
|
vi.spyOn(fs, "writeFileSync");
|
|
126
136
|
|
|
@@ -141,11 +151,17 @@ describe("buildStart", () => {
|
|
|
141
151
|
`;
|
|
142
152
|
}
|
|
143
153
|
});
|
|
144
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
154
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
155
|
+
Promise.resolve(["my-component.tsx"])
|
|
156
|
+
);
|
|
145
157
|
vi.spyOn(fs, "writeFileSync");
|
|
146
158
|
|
|
147
159
|
const plugin = ApplicationManifestPlugin();
|
|
148
|
-
plugin.configResolved({
|
|
160
|
+
plugin.configResolved({
|
|
161
|
+
command: "serve",
|
|
162
|
+
server: {},
|
|
163
|
+
build: { outDir: "/dist" },
|
|
164
|
+
});
|
|
149
165
|
await plugin.buildStart();
|
|
150
166
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
151
167
|
|
|
@@ -180,11 +196,17 @@ describe("buildStart", () => {
|
|
|
180
196
|
`;
|
|
181
197
|
}
|
|
182
198
|
});
|
|
183
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
199
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
200
|
+
Promise.resolve(["my-component.tsx"])
|
|
201
|
+
);
|
|
184
202
|
vi.spyOn(fs, "writeFileSync");
|
|
185
203
|
|
|
186
204
|
const plugin = ApplicationManifestPlugin();
|
|
187
|
-
plugin.configResolved({
|
|
205
|
+
plugin.configResolved({
|
|
206
|
+
command: "serve",
|
|
207
|
+
server: {},
|
|
208
|
+
build: { outDir: "/dist" },
|
|
209
|
+
});
|
|
188
210
|
await plugin.buildStart();
|
|
189
211
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
190
212
|
|
|
@@ -231,11 +253,17 @@ describe("buildStart", () => {
|
|
|
231
253
|
`;
|
|
232
254
|
}
|
|
233
255
|
});
|
|
234
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
256
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
257
|
+
Promise.resolve(["my-component.tsx"])
|
|
258
|
+
);
|
|
235
259
|
vi.spyOn(fs, "writeFileSync");
|
|
236
260
|
|
|
237
261
|
const plugin = ApplicationManifestPlugin();
|
|
238
|
-
plugin.configResolved({
|
|
262
|
+
plugin.configResolved({
|
|
263
|
+
command: "serve",
|
|
264
|
+
server: {},
|
|
265
|
+
build: { outDir: "/dist" },
|
|
266
|
+
});
|
|
239
267
|
await plugin.buildStart();
|
|
240
268
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
241
269
|
|
|
@@ -284,13 +312,17 @@ describe("buildStart", () => {
|
|
|
284
312
|
`;
|
|
285
313
|
}
|
|
286
314
|
});
|
|
287
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
315
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
316
|
+
Promise.resolve(["my-component.tsx"])
|
|
317
|
+
);
|
|
288
318
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
289
319
|
vi.spyOn(fs, "writeFileSync");
|
|
290
320
|
|
|
291
321
|
const plugin = ApplicationManifestPlugin();
|
|
292
322
|
plugin.configResolved({ command: "serve", server: {} });
|
|
293
|
-
await expect(
|
|
323
|
+
await expect(
|
|
324
|
+
async () => await plugin.buildStart()
|
|
325
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
294
326
|
`[Error: Found multiple operations marked as \`@prefetch\`. You can only mark 1 operation with \`@prefetch\`.]`
|
|
295
327
|
);
|
|
296
328
|
});
|
|
@@ -305,11 +337,17 @@ describe("buildStart", () => {
|
|
|
305
337
|
`;
|
|
306
338
|
}
|
|
307
339
|
});
|
|
308
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
340
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
341
|
+
Promise.resolve(["my-component.tsx"])
|
|
342
|
+
);
|
|
309
343
|
vi.spyOn(fs, "writeFileSync");
|
|
310
344
|
|
|
311
345
|
const plugin = ApplicationManifestPlugin();
|
|
312
|
-
plugin.configResolved({
|
|
346
|
+
plugin.configResolved({
|
|
347
|
+
command: "serve",
|
|
348
|
+
server: {},
|
|
349
|
+
build: { outDir: "/dist" },
|
|
350
|
+
});
|
|
313
351
|
await plugin.buildStart();
|
|
314
352
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
315
353
|
|
|
@@ -361,14 +399,18 @@ describe("buildStart", () => {
|
|
|
361
399
|
`;
|
|
362
400
|
}
|
|
363
401
|
});
|
|
364
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
402
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
403
|
+
Promise.resolve(["my-component.tsx"])
|
|
404
|
+
);
|
|
365
405
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
366
406
|
vi.spyOn(fs, "writeFileSync");
|
|
367
407
|
|
|
368
408
|
const plugin = ApplicationManifestPlugin();
|
|
369
409
|
plugin.configResolved({ command: "serve", server: {} });
|
|
370
410
|
|
|
371
|
-
await expect(
|
|
411
|
+
await expect(
|
|
412
|
+
async () => await plugin.buildStart()
|
|
413
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
372
414
|
`[Error: Found an unsupported operation type. Only Query and Mutation are supported.]`
|
|
373
415
|
);
|
|
374
416
|
});
|
|
@@ -387,12 +429,19 @@ describe("buildStart", () => {
|
|
|
387
429
|
`;
|
|
388
430
|
}
|
|
389
431
|
});
|
|
390
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
432
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
433
|
+
Promise.resolve(["my-component.tsx"])
|
|
434
|
+
);
|
|
391
435
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
392
436
|
vi.spyOn(fs, "writeFileSync");
|
|
393
437
|
|
|
394
438
|
const plugin = ApplicationManifestPlugin();
|
|
395
|
-
plugin.configResolved({
|
|
439
|
+
plugin.configResolved({
|
|
440
|
+
command: "serve",
|
|
441
|
+
mode: "staging",
|
|
442
|
+
server: {},
|
|
443
|
+
build: { outDir: "/dist" },
|
|
444
|
+
});
|
|
396
445
|
await plugin.buildStart();
|
|
397
446
|
|
|
398
447
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
@@ -411,12 +460,18 @@ describe("buildStart", () => {
|
|
|
411
460
|
`;
|
|
412
461
|
}
|
|
413
462
|
});
|
|
414
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
463
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
464
|
+
Promise.resolve(["my-component.tsx"])
|
|
465
|
+
);
|
|
415
466
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
416
467
|
vi.spyOn(fs, "writeFileSync");
|
|
417
468
|
|
|
418
469
|
const plugin = ApplicationManifestPlugin();
|
|
419
|
-
plugin.configResolved({
|
|
470
|
+
plugin.configResolved({
|
|
471
|
+
command: "serve",
|
|
472
|
+
server: { https: {}, port: "5678" },
|
|
473
|
+
build: { outDir: "/dist" },
|
|
474
|
+
});
|
|
420
475
|
await plugin.buildStart();
|
|
421
476
|
|
|
422
477
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
@@ -435,7 +490,9 @@ describe("buildStart", () => {
|
|
|
435
490
|
`;
|
|
436
491
|
}
|
|
437
492
|
});
|
|
438
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
493
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
494
|
+
Promise.resolve(["my-component.tsx"])
|
|
495
|
+
);
|
|
439
496
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
440
497
|
vi.spyOn(fs, "writeFileSync");
|
|
441
498
|
|
|
@@ -463,14 +520,18 @@ describe("buildStart", () => {
|
|
|
463
520
|
`;
|
|
464
521
|
}
|
|
465
522
|
});
|
|
466
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
523
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
524
|
+
Promise.resolve(["my-component.tsx"])
|
|
525
|
+
);
|
|
467
526
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
468
527
|
vi.spyOn(fs, "writeFileSync");
|
|
469
528
|
|
|
470
529
|
const plugin = ApplicationManifestPlugin();
|
|
471
530
|
plugin.configResolved({ command: "serve", server: {} });
|
|
472
531
|
|
|
473
|
-
await expect(
|
|
532
|
+
await expect(
|
|
533
|
+
async () => await plugin.buildStart()
|
|
534
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
474
535
|
`[Error: 'name' argument must be supplied for @tool]`
|
|
475
536
|
);
|
|
476
537
|
});
|
|
@@ -485,14 +546,18 @@ describe("buildStart", () => {
|
|
|
485
546
|
`;
|
|
486
547
|
}
|
|
487
548
|
});
|
|
488
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
549
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
550
|
+
Promise.resolve(["my-component.tsx"])
|
|
551
|
+
);
|
|
489
552
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
490
553
|
vi.spyOn(fs, "writeFileSync");
|
|
491
554
|
|
|
492
555
|
const plugin = ApplicationManifestPlugin();
|
|
493
556
|
plugin.configResolved({ command: "serve", server: {} });
|
|
494
557
|
|
|
495
|
-
await expect(
|
|
558
|
+
await expect(
|
|
559
|
+
async () => await plugin.buildStart()
|
|
560
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
496
561
|
`[Error: 'description' argument must be supplied for @tool]`
|
|
497
562
|
);
|
|
498
563
|
});
|
|
@@ -507,14 +572,18 @@ describe("buildStart", () => {
|
|
|
507
572
|
`;
|
|
508
573
|
}
|
|
509
574
|
});
|
|
510
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
575
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
576
|
+
Promise.resolve(["my-component.tsx"])
|
|
577
|
+
);
|
|
511
578
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
512
579
|
vi.spyOn(fs, "writeFileSync");
|
|
513
580
|
|
|
514
581
|
const plugin = ApplicationManifestPlugin();
|
|
515
582
|
plugin.configResolved({ command: "serve", server: {} });
|
|
516
583
|
|
|
517
|
-
await expect(
|
|
584
|
+
await expect(
|
|
585
|
+
async () => await plugin.buildStart()
|
|
586
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
518
587
|
`[Error: Expected argument 'name' to be of type 'StringValue' but found 'BooleanValue' instead.]`
|
|
519
588
|
);
|
|
520
589
|
});
|
|
@@ -529,14 +598,18 @@ describe("buildStart", () => {
|
|
|
529
598
|
`;
|
|
530
599
|
}
|
|
531
600
|
});
|
|
532
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
601
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
602
|
+
Promise.resolve(["my-component.tsx"])
|
|
603
|
+
);
|
|
533
604
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
534
605
|
vi.spyOn(fs, "writeFileSync");
|
|
535
606
|
|
|
536
607
|
const plugin = ApplicationManifestPlugin();
|
|
537
608
|
plugin.configResolved({ command: "serve", server: {} });
|
|
538
609
|
|
|
539
|
-
await expect(
|
|
610
|
+
await expect(
|
|
611
|
+
async () => await plugin.buildStart()
|
|
612
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
540
613
|
`[Error: Expected argument 'description' to be of type 'StringValue' but found 'BooleanValue' instead.]`
|
|
541
614
|
);
|
|
542
615
|
});
|
|
@@ -551,14 +624,18 @@ describe("buildStart", () => {
|
|
|
551
624
|
`;
|
|
552
625
|
}
|
|
553
626
|
});
|
|
554
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
627
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
628
|
+
Promise.resolve(["my-component.tsx"])
|
|
629
|
+
);
|
|
555
630
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
556
631
|
vi.spyOn(fs, "writeFileSync");
|
|
557
632
|
|
|
558
633
|
const plugin = ApplicationManifestPlugin();
|
|
559
634
|
plugin.configResolved({ command: "serve", server: {} });
|
|
560
635
|
|
|
561
|
-
await expect(
|
|
636
|
+
await expect(
|
|
637
|
+
async () => await plugin.buildStart()
|
|
638
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
562
639
|
`[Error: Expected argument 'extraInputs' to be of type 'ListValue' but found 'BooleanValue' instead.]`
|
|
563
640
|
);
|
|
564
641
|
});
|
|
@@ -575,14 +652,18 @@ describe("buildStart", () => {
|
|
|
575
652
|
`;
|
|
576
653
|
}
|
|
577
654
|
});
|
|
578
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
655
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
656
|
+
Promise.resolve(["my-component.tsx"])
|
|
657
|
+
);
|
|
579
658
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
580
659
|
vi.spyOn(fs, "writeFileSync");
|
|
581
660
|
|
|
582
661
|
const plugin = ApplicationManifestPlugin();
|
|
583
662
|
plugin.configResolved({ command: "serve", server: {} });
|
|
584
663
|
|
|
585
|
-
await expect(
|
|
664
|
+
await expect(
|
|
665
|
+
async () => await plugin.buildStart()
|
|
666
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
586
667
|
`[Error: Error when parsing directive values: unexpected type 'FloatValue']`
|
|
587
668
|
);
|
|
588
669
|
});
|
|
@@ -594,25 +675,31 @@ describe("buildStart", () => {
|
|
|
594
675
|
} else if (path === root + "/my-component.tsx") {
|
|
595
676
|
return `
|
|
596
677
|
const MY_QUERY = gql\`
|
|
597
|
-
fragment A on User { firstName }
|
|
598
|
-
fragment B on User { lastName }
|
|
599
|
-
query HelloWorldQuery @tool(name: "hello-world", description: "This is an awesome tool!") {
|
|
678
|
+
fragment A on User { firstName }
|
|
679
|
+
fragment B on User { lastName }
|
|
680
|
+
query HelloWorldQuery @tool(name: "hello-world", description: "This is an awesome tool!") {
|
|
600
681
|
helloWorld {
|
|
601
682
|
...B
|
|
602
683
|
...A
|
|
603
684
|
...C
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
fragment C on User { middleName }
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
fragment C on User { middleName }
|
|
607
688
|
}\`;
|
|
608
689
|
`;
|
|
609
690
|
}
|
|
610
691
|
});
|
|
611
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
692
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
693
|
+
Promise.resolve(["my-component.tsx"])
|
|
694
|
+
);
|
|
612
695
|
vi.spyOn(fs, "writeFileSync");
|
|
613
696
|
|
|
614
697
|
const plugin = ApplicationManifestPlugin();
|
|
615
|
-
plugin.configResolved({
|
|
698
|
+
plugin.configResolved({
|
|
699
|
+
command: "serve",
|
|
700
|
+
server: {},
|
|
701
|
+
build: { outDir: "/dist" },
|
|
702
|
+
});
|
|
616
703
|
await plugin.buildStart();
|
|
617
704
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
618
705
|
|
|
@@ -692,13 +779,20 @@ describe("writeBundle", () => {
|
|
|
692
779
|
`;
|
|
693
780
|
}
|
|
694
781
|
});
|
|
695
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
782
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
783
|
+
Promise.resolve(["my-component.tsx"])
|
|
784
|
+
);
|
|
696
785
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
697
786
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
698
787
|
vi.spyOn(fs, "writeFileSync");
|
|
699
788
|
|
|
700
789
|
const plugin = ApplicationManifestPlugin();
|
|
701
|
-
plugin.configResolved({
|
|
790
|
+
plugin.configResolved({
|
|
791
|
+
command: "build",
|
|
792
|
+
mode: "staging",
|
|
793
|
+
server: {},
|
|
794
|
+
build: { outDir: "/dist/" },
|
|
795
|
+
});
|
|
702
796
|
await plugin.buildStart();
|
|
703
797
|
await plugin.writeBundle();
|
|
704
798
|
|
|
@@ -718,13 +812,20 @@ describe("writeBundle", () => {
|
|
|
718
812
|
`;
|
|
719
813
|
}
|
|
720
814
|
});
|
|
721
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
815
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
816
|
+
Promise.resolve(["my-component.tsx"])
|
|
817
|
+
);
|
|
722
818
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
723
819
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
724
820
|
vi.spyOn(fs, "writeFileSync");
|
|
725
821
|
|
|
726
822
|
const plugin = ApplicationManifestPlugin();
|
|
727
|
-
plugin.configResolved({
|
|
823
|
+
plugin.configResolved({
|
|
824
|
+
command: "build",
|
|
825
|
+
mode: "production",
|
|
826
|
+
server: {},
|
|
827
|
+
build: { outDir: "/dist/" },
|
|
828
|
+
});
|
|
728
829
|
await plugin.buildStart();
|
|
729
830
|
await plugin.writeBundle();
|
|
730
831
|
|
|
@@ -744,16 +845,25 @@ describe("writeBundle", () => {
|
|
|
744
845
|
`;
|
|
745
846
|
}
|
|
746
847
|
});
|
|
747
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
848
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
849
|
+
Promise.resolve(["my-component.tsx"])
|
|
850
|
+
);
|
|
748
851
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
749
852
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
750
853
|
vi.spyOn(fs, "writeFileSync");
|
|
751
854
|
|
|
752
855
|
const plugin = ApplicationManifestPlugin();
|
|
753
|
-
plugin.configResolved({
|
|
856
|
+
plugin.configResolved({
|
|
857
|
+
command: "build",
|
|
858
|
+
mode: "staging",
|
|
859
|
+
server: {},
|
|
860
|
+
build: { outDir: "/dist/" },
|
|
861
|
+
});
|
|
754
862
|
await plugin.buildStart();
|
|
755
863
|
|
|
756
|
-
await expect(
|
|
864
|
+
await expect(
|
|
865
|
+
async () => await plugin.writeBundle()
|
|
866
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
757
867
|
`[Error: No entry point found for mode "staging". Entry points other than "development" and "production" must be defined in package.json file.]`
|
|
758
868
|
);
|
|
759
869
|
});
|
|
@@ -768,13 +878,20 @@ describe("writeBundle", () => {
|
|
|
768
878
|
`;
|
|
769
879
|
}
|
|
770
880
|
});
|
|
771
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
881
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
882
|
+
Promise.resolve(["my-component.tsx"])
|
|
883
|
+
);
|
|
772
884
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
773
885
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
774
886
|
vi.spyOn(fs, "writeFileSync");
|
|
775
887
|
|
|
776
888
|
const plugin = ApplicationManifestPlugin();
|
|
777
|
-
plugin.configResolved({
|
|
889
|
+
plugin.configResolved({
|
|
890
|
+
command: "build",
|
|
891
|
+
mode: "production",
|
|
892
|
+
server: {},
|
|
893
|
+
build: { outDir: "/dist/" },
|
|
894
|
+
});
|
|
778
895
|
await plugin.buildStart();
|
|
779
896
|
await plugin.writeBundle();
|
|
780
897
|
|
|
@@ -797,7 +914,9 @@ describe("configureServer", () => {
|
|
|
797
914
|
`;
|
|
798
915
|
}
|
|
799
916
|
});
|
|
800
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
917
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
918
|
+
Promise.resolve(["my-component.tsx"])
|
|
919
|
+
);
|
|
801
920
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
802
921
|
vi.spyOn(fs, "writeFileSync");
|
|
803
922
|
|
|
@@ -819,7 +938,11 @@ describe("configureServer", () => {
|
|
|
819
938
|
server.watcher.init();
|
|
820
939
|
|
|
821
940
|
const plugin = ApplicationManifestPlugin();
|
|
822
|
-
plugin.configResolved({
|
|
941
|
+
plugin.configResolved({
|
|
942
|
+
command: "serve",
|
|
943
|
+
server: {},
|
|
944
|
+
build: { outDir: "/dist" },
|
|
945
|
+
});
|
|
823
946
|
await plugin.buildStart();
|
|
824
947
|
await plugin.configureServer(server);
|
|
825
948
|
await server.watcher.trigger("package.json");
|
|
@@ -5,7 +5,9 @@ export const AbsoluteAssetImportsPlugin = () => {
|
|
|
5
5
|
transformIndexHtml(html: string, ctx: any) {
|
|
6
6
|
if (!ctx.server) return html;
|
|
7
7
|
|
|
8
|
-
let baseUrl = (
|
|
8
|
+
let baseUrl = (
|
|
9
|
+
ctx.server.config?.server?.origin ?? ctx.server.resolvedUrls?.local[0]
|
|
10
|
+
).replace(/\/$/, "");
|
|
9
11
|
baseUrl = baseUrl.replace(/\/$/, "");
|
|
10
12
|
|
|
11
13
|
return (
|