@agentuity/cli 0.0.67 → 0.0.69

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 (63) hide show
  1. package/bin/cli.ts +20 -8
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +16 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cmd/ai/prompt/agent.d.ts.map +1 -1
  6. package/dist/cmd/ai/prompt/agent.js +24 -25
  7. package/dist/cmd/ai/prompt/agent.js.map +1 -1
  8. package/dist/cmd/ai/prompt/api.d.ts.map +1 -1
  9. package/dist/cmd/ai/prompt/api.js +12 -9
  10. package/dist/cmd/ai/prompt/api.js.map +1 -1
  11. package/dist/cmd/build/ast.js +4 -4
  12. package/dist/cmd/build/ast.js.map +1 -1
  13. package/dist/cmd/build/bundler.js +2 -2
  14. package/dist/cmd/build/bundler.js.map +1 -1
  15. package/dist/cmd/build/plugin.d.ts.map +1 -1
  16. package/dist/cmd/build/plugin.js +9 -14
  17. package/dist/cmd/build/plugin.js.map +1 -1
  18. package/dist/cmd/dev/index.js +2 -2
  19. package/dist/cmd/dev/index.js.map +1 -1
  20. package/dist/cmd/dev/templates.d.ts.map +1 -1
  21. package/dist/cmd/dev/templates.js +10 -3
  22. package/dist/cmd/dev/templates.js.map +1 -1
  23. package/dist/cmd/project/download.js +10 -10
  24. package/dist/cmd/project/download.js.map +1 -1
  25. package/dist/config.d.ts.map +1 -1
  26. package/dist/config.js +48 -87
  27. package/dist/config.js.map +1 -1
  28. package/dist/keychain.d.ts +31 -0
  29. package/dist/keychain.d.ts.map +1 -0
  30. package/dist/keychain.js +135 -0
  31. package/dist/keychain.js.map +1 -0
  32. package/dist/utils/detectSubagent.d.ts +1 -1
  33. package/dist/utils/detectSubagent.js +3 -3
  34. package/dist/utils/detectSubagent.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/cli.ts +19 -0
  37. package/src/cmd/ai/prompt/agent.ts +24 -25
  38. package/src/cmd/ai/prompt/api.ts +12 -9
  39. package/src/cmd/build/ast.ts +4 -4
  40. package/src/cmd/build/bundler.ts +2 -2
  41. package/src/cmd/build/plugin.ts +9 -14
  42. package/src/cmd/dev/index.ts +2 -2
  43. package/src/cmd/dev/templates.ts +10 -3
  44. package/src/cmd/project/download.ts +10 -10
  45. package/src/config.ts +54 -97
  46. package/src/keychain.ts +176 -0
  47. package/src/utils/detectSubagent.ts +3 -3
  48. package/dist/cmd/build/ast.test.d.ts +0 -2
  49. package/dist/cmd/build/ast.test.d.ts.map +0 -1
  50. package/dist/cmd/build/ast.test.js +0 -339
  51. package/dist/cmd/build/ast.test.js.map +0 -1
  52. package/dist/cmd/build/fix-duplicate-exports.test.d.ts +0 -2
  53. package/dist/cmd/build/fix-duplicate-exports.test.d.ts.map +0 -1
  54. package/dist/cmd/build/fix-duplicate-exports.test.js +0 -300
  55. package/dist/cmd/build/fix-duplicate-exports.test.js.map +0 -1
  56. package/dist/crypto/box.test.d.ts +0 -2
  57. package/dist/crypto/box.test.d.ts.map +0 -1
  58. package/dist/crypto/box.test.js +0 -317
  59. package/dist/crypto/box.test.js.map +0 -1
  60. package/dist/env-util.test.d.ts +0 -2
  61. package/dist/env-util.test.d.ts.map +0 -1
  62. package/dist/env-util.test.js +0 -146
  63. package/dist/env-util.test.js.map +0 -1
@@ -1,339 +0,0 @@
1
- import { describe, test, expect } from 'bun:test';
2
- import { parseRoute, parseAgentMetadata } from './ast';
3
- import { writeFileSync, mkdirSync, rmSync } from 'node:fs';
4
- import { join } from 'node:path';
5
- const TEST_DIR = '/tmp/agentuity-cli-test-routes';
6
- describe('parseRoute - Crash Prevention Scenarios', () => {
7
- const setup = () => {
8
- rmSync(TEST_DIR, { recursive: true, force: true });
9
- mkdirSync(TEST_DIR, { recursive: true });
10
- };
11
- const cleanup = () => {
12
- rmSync(TEST_DIR, { recursive: true, force: true });
13
- };
14
- test('should handle files with interface definitions', async () => {
15
- setup();
16
- const routeFile = join(TEST_DIR, 'route.ts');
17
- const code = `
18
- import { createRouter } from '@agentuity/runtime';
19
- const router = createRouter();
20
-
21
- interface SomeInterface {
22
- foo: string;
23
- bar: string;
24
- }
25
-
26
- router.get('/', (c) => c.json({ status: 'ok' }));
27
-
28
- export default router;
29
- `;
30
- writeFileSync(routeFile, code);
31
- const routes = await parseRoute(TEST_DIR, routeFile, 'proj_1', 'dep_1');
32
- expect(routes).toHaveLength(1);
33
- expect(routes[0].method).toBe('get');
34
- cleanup();
35
- });
36
- test('should handle non-call expression statements', async () => {
37
- setup();
38
- const routeFile = join(TEST_DIR, 'route.ts');
39
- const code = `
40
- import { createRouter } from '@agentuity/runtime';
41
- const router = createRouter();
42
-
43
- 1 + 1;
44
- "string literal";
45
- true;
46
-
47
- router.get('/', (c) => c.text('ok'));
48
-
49
- export default router;
50
- `;
51
- writeFileSync(routeFile, code);
52
- const routes = await parseRoute(TEST_DIR, routeFile, 'proj_1', 'dep_1');
53
- expect(routes).toHaveLength(1);
54
- cleanup();
55
- });
56
- test('should handle variable access identifiers', async () => {
57
- setup();
58
- const routeFile = join(TEST_DIR, 'route.ts');
59
- const code = `
60
- import { createRouter } from '@agentuity/runtime';
61
- const router = createRouter();
62
-
63
- router; // Just accessing the variable
64
-
65
- router.get('/', (c) => c.text('ok'));
66
-
67
- export default router;
68
- `;
69
- writeFileSync(routeFile, code);
70
- const routes = await parseRoute(TEST_DIR, routeFile, 'proj_1', 'dep_1');
71
- expect(routes).toHaveLength(1);
72
- cleanup();
73
- });
74
- test('should handle direct function calls (not member expressions)', async () => {
75
- setup();
76
- const routeFile = join(TEST_DIR, 'route.ts');
77
- const code = `
78
- import { createRouter } from '@agentuity/runtime';
79
- const router = createRouter();
80
-
81
- console.log("logging");
82
- (function() { })();
83
-
84
- router.get('/', (c) => c.text('ok'));
85
-
86
- export default router;
87
- `;
88
- writeFileSync(routeFile, code);
89
- const routes = await parseRoute(TEST_DIR, routeFile, 'proj_1', 'dep_1');
90
- expect(routes).toHaveLength(1);
91
- cleanup();
92
- });
93
- test('should handle mixed complex scenarios', async () => {
94
- setup();
95
- const routeFile = join(TEST_DIR, 'route.ts');
96
- const code = `
97
- import { createRouter } from '@agentuity/runtime';
98
-
99
- // Variable declarations
100
- const router = createRouter();
101
- const someVar = "test";
102
-
103
- // Interface
104
- interface User {
105
- id: string;
106
- }
107
-
108
- // Function declaration
109
- function helper() {
110
- return true;
111
- }
112
-
113
- // Direct call
114
- helper();
115
-
116
- // Non-route member expression
117
- console.log(someVar);
118
-
119
- // Valid route
120
- router.post('/users', (c) => c.json({ id: '1' }));
121
-
122
- // Another expression type
123
- if (true) {
124
- console.log("block");
125
- }
126
-
127
- export default router;
128
- `;
129
- writeFileSync(routeFile, code);
130
- const routes = await parseRoute(TEST_DIR, routeFile, 'proj_1', 'dep_1');
131
- expect(routes).toHaveLength(1);
132
- expect(routes[0].method).toBe('post');
133
- cleanup();
134
- });
135
- test('should reject invalid router method', async () => {
136
- setup();
137
- const routeFile = join(TEST_DIR, 'route.ts');
138
- const code = `
139
- import { createRouter } from '@agentuity/runtime';
140
-
141
- // Variable declarations
142
- const router = createRouter();
143
-
144
- // Invalid route with unknown method
145
- router.foo('/users', (c) => c.json({ id: '1' }));
146
-
147
- export default router;
148
- `;
149
- writeFileSync(routeFile, code);
150
- await expect(parseRoute(TEST_DIR, routeFile, 'proj_1', 'dep_1')).rejects.toThrow();
151
- cleanup();
152
- });
153
- });
154
- describe('parseAgentMetadata - Schema Code Extraction', () => {
155
- const setup = () => {
156
- rmSync(TEST_DIR, { recursive: true, force: true });
157
- mkdirSync(TEST_DIR, { recursive: true });
158
- };
159
- const cleanup = () => {
160
- rmSync(TEST_DIR, { recursive: true, force: true });
161
- };
162
- test('should extract input and output schema code', async () => {
163
- setup();
164
- const agentFile = join(TEST_DIR, 'agent.ts');
165
- const code = `
166
- import { createAgent } from '@agentuity/runtime';
167
- import { z } from 'zod';
168
-
169
- const agent = createAgent({
170
- metadata: {
171
- name: 'test-agent',
172
- description: 'Test agent',
173
- },
174
- schema: {
175
- input: z.object({
176
- name: z.string(),
177
- age: z.number(),
178
- }),
179
- output: z.object({
180
- result: z.string(),
181
- }),
182
- },
183
- handler: async (ctx, input) => {
184
- return { result: 'success' };
185
- },
186
- });
187
-
188
- export default agent;
189
- `;
190
- writeFileSync(agentFile, code);
191
- const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'bun' });
192
- const contents = transpiler.transformSync(code);
193
- const [, metadata] = await parseAgentMetadata(TEST_DIR, agentFile, contents, 'proj_1', 'dep_1');
194
- expect(metadata.has('inputSchemaCode')).toBe(true);
195
- expect(metadata.has('outputSchemaCode')).toBe(true);
196
- const inputSchemaCode = metadata.get('inputSchemaCode');
197
- const outputSchemaCode = metadata.get('outputSchemaCode');
198
- expect(inputSchemaCode).toContain('z.object');
199
- expect(inputSchemaCode).toContain('name');
200
- expect(inputSchemaCode).toContain('age');
201
- expect(outputSchemaCode).toContain('z.object');
202
- expect(outputSchemaCode).toContain('result');
203
- cleanup();
204
- });
205
- test('should extract only input schema code when output is missing', async () => {
206
- setup();
207
- const agentFile = join(TEST_DIR, 'agent.ts');
208
- const code = `
209
- import { createAgent } from '@agentuity/runtime';
210
- import { z } from 'zod';
211
-
212
- const agent = createAgent({
213
- metadata: {
214
- name: 'test-agent',
215
- },
216
- schema: {
217
- input: z.string(),
218
- },
219
- handler: async (ctx, input) => {
220
- return 'success';
221
- },
222
- });
223
-
224
- export default agent;
225
- `;
226
- writeFileSync(agentFile, code);
227
- const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'bun' });
228
- const contents = transpiler.transformSync(code);
229
- const [, metadata] = await parseAgentMetadata(TEST_DIR, agentFile, contents, 'proj_1', 'dep_1');
230
- expect(metadata.has('inputSchemaCode')).toBe(true);
231
- expect(metadata.has('outputSchemaCode')).toBe(false);
232
- const inputSchemaCode = metadata.get('inputSchemaCode');
233
- expect(inputSchemaCode).toContain('z.string');
234
- cleanup();
235
- });
236
- test('should extract only output schema code when input is missing', async () => {
237
- setup();
238
- const agentFile = join(TEST_DIR, 'agent.ts');
239
- const code = `
240
- import { createAgent } from '@agentuity/runtime';
241
- import { z } from 'zod';
242
-
243
- const agent = createAgent({
244
- metadata: {
245
- name: 'test-agent',
246
- },
247
- schema: {
248
- output: z.array(z.string()),
249
- },
250
- handler: async (ctx) => {
251
- return ['item1', 'item2'];
252
- },
253
- });
254
-
255
- export default agent;
256
- `;
257
- writeFileSync(agentFile, code);
258
- const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'bun' });
259
- const contents = transpiler.transformSync(code);
260
- const [, metadata] = await parseAgentMetadata(TEST_DIR, agentFile, contents, 'proj_1', 'dep_1');
261
- expect(metadata.has('inputSchemaCode')).toBe(false);
262
- expect(metadata.has('outputSchemaCode')).toBe(true);
263
- const outputSchemaCode = metadata.get('outputSchemaCode');
264
- expect(outputSchemaCode).toContain('z.array');
265
- expect(outputSchemaCode).toContain('z.string');
266
- cleanup();
267
- });
268
- test('should handle complex nested schemas', async () => {
269
- setup();
270
- const agentFile = join(TEST_DIR, 'agent.ts');
271
- const code = `
272
- import { createAgent } from '@agentuity/runtime';
273
- import { z } from 'zod';
274
-
275
- const agent = createAgent({
276
- metadata: {
277
- name: 'test-agent',
278
- },
279
- schema: {
280
- input: z.object({
281
- user: z.object({
282
- name: z.string(),
283
- email: z.string().email(),
284
- }),
285
- tags: z.array(z.string()),
286
- }),
287
- output: z.union([
288
- z.object({ success: z.boolean() }),
289
- z.object({ error: z.string() }),
290
- ]),
291
- },
292
- handler: async (ctx, input) => {
293
- return { success: true };
294
- },
295
- });
296
-
297
- export default agent;
298
- `;
299
- writeFileSync(agentFile, code);
300
- const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'bun' });
301
- const contents = transpiler.transformSync(code);
302
- const [, metadata] = await parseAgentMetadata(TEST_DIR, agentFile, contents, 'proj_1', 'dep_1');
303
- expect(metadata.has('inputSchemaCode')).toBe(true);
304
- expect(metadata.has('outputSchemaCode')).toBe(true);
305
- const inputSchemaCode = metadata.get('inputSchemaCode');
306
- const outputSchemaCode = metadata.get('outputSchemaCode');
307
- expect(inputSchemaCode).toContain('z.object');
308
- expect(inputSchemaCode).toContain('user');
309
- expect(inputSchemaCode).toContain('tags');
310
- expect(outputSchemaCode).toContain('z.union');
311
- cleanup();
312
- });
313
- test('should handle agent without schema property', async () => {
314
- setup();
315
- const agentFile = join(TEST_DIR, 'agent.ts');
316
- const code = `
317
- import { createAgent } from '@agentuity/runtime';
318
-
319
- const agent = createAgent({
320
- metadata: {
321
- name: 'test-agent',
322
- },
323
- handler: async (ctx) => {
324
- return 'success';
325
- },
326
- });
327
-
328
- export default agent;
329
- `;
330
- writeFileSync(agentFile, code);
331
- const transpiler = new Bun.Transpiler({ loader: 'ts', target: 'bun' });
332
- const contents = transpiler.transformSync(code);
333
- const [, metadata] = await parseAgentMetadata(TEST_DIR, agentFile, contents, 'proj_1', 'dep_1');
334
- expect(metadata.has('inputSchemaCode')).toBe(false);
335
- expect(metadata.has('outputSchemaCode')).toBe(false);
336
- cleanup();
337
- });
338
- });
339
- //# sourceMappingURL=ast.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast.test.js","sourceRoot":"","sources":["../../../src/cmd/build/ast.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,QAAQ,GAAG,gCAAgC,CAAC;AAElD,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACxD,MAAM,KAAK,GAAG,GAAG,EAAE;QAClB,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAA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5C,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,CACP,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAErD,OAAO,EAAE,CAAC;IACX,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=fix-duplicate-exports.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fix-duplicate-exports.test.d.ts","sourceRoot":"","sources":["../../../src/cmd/build/fix-duplicate-exports.test.ts"],"names":[],"mappings":""}
@@ -1,300 +0,0 @@
1
- import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
2
- import { join } from 'node:path';
3
- import { mkdtemp, rm } from 'node:fs/promises';
4
- import { tmpdir } from 'node:os';
5
- import { fixDuplicateExportsInDirectory } from './fix-duplicate-exports';
6
- describe('fix-duplicate-exports', () => {
7
- let tempDir;
8
- beforeEach(async () => {
9
- tempDir = await mkdtemp(join(tmpdir(), 'fix-duplicate-exports-test-'));
10
- });
11
- afterEach(async () => {
12
- await rm(tempDir, { recursive: true, force: true });
13
- });
14
- describe('export alias syntax preservation', () => {
15
- test('preserves "qux as baz" when removing duplicate foo', async () => {
16
- // This is the critical bug case from the feedback
17
- const code = `export { foo };
18
- export { qux as baz, foo };`;
19
- const expected = `export { foo };
20
- export { qux as baz };`;
21
- const testFile = join(tempDir, 'test.js');
22
- await Bun.write(testFile, code);
23
- await fixDuplicateExportsInDirectory(tempDir, false);
24
- const result = await Bun.file(testFile).text();
25
- expect(result).toBe(expected);
26
- });
27
- test('preserves "foo as bar" when it is not duplicate', async () => {
28
- const code = `export { foo as bar };
29
- export { baz };`;
30
- const testFile = join(tempDir, 'test.js');
31
- await Bun.write(testFile, code);
32
- await fixDuplicateExportsInDirectory(tempDir, false);
33
- const result = await Bun.file(testFile).text();
34
- // Should not change - no duplicates
35
- expect(result).toBe(code);
36
- });
37
- test('handles multiple aliases in same export statement', async () => {
38
- const code = `export { foo as bar, baz as qux };
39
- export { bar, simple };`;
40
- // "bar" is duplicate (exported in both statements)
41
- const expected = `export { foo as bar, baz as qux };
42
- export { simple };`;
43
- const testFile = join(tempDir, 'test.js');
44
- await Bun.write(testFile, code);
45
- await fixDuplicateExportsInDirectory(tempDir, false);
46
- const result = await Bun.file(testFile).text();
47
- expect(result).toBe(expected);
48
- });
49
- test('preserves alias when removing from middle of export list', async () => {
50
- const code = `export { alpha, beta };
51
- export { alpha, gamma as delta, epsilon };`;
52
- const expected = `export { alpha, beta };
53
- export { gamma as delta, epsilon };`;
54
- const testFile = join(tempDir, 'test.js');
55
- await Bun.write(testFile, code);
56
- await fixDuplicateExportsInDirectory(tempDir, false);
57
- const result = await Bun.file(testFile).text();
58
- expect(result).toBe(expected);
59
- });
60
- test('handles exported name being the duplicate (alias target)', async () => {
61
- const code = `export { foo as bar };
62
- export { bar };`;
63
- // "bar" from first export and "bar" from second export are DIFFERENT
64
- // First one exports the identifier "foo" with the name "bar"
65
- // Second one exports the identifier "bar" with the name "bar"
66
- // These are duplicates from export name perspective
67
- const expected = `export { foo as bar };
68
- `;
69
- const testFile = join(tempDir, 'test.js');
70
- await Bun.write(testFile, code);
71
- await fixDuplicateExportsInDirectory(tempDir, false);
72
- const result = await Bun.file(testFile).text();
73
- expect(result).toBe(expected);
74
- });
75
- });
76
- describe('duplicate removal', () => {
77
- test('removes entire duplicate export statement', async () => {
78
- const code = `export { foo, bar };
79
- export { foo, bar };`;
80
- const expected = `export { foo, bar };
81
- `;
82
- const testFile = join(tempDir, 'test.js');
83
- await Bun.write(testFile, code);
84
- await fixDuplicateExportsInDirectory(tempDir, false);
85
- const result = await Bun.file(testFile).text();
86
- expect(result).toBe(expected);
87
- });
88
- test('removes only duplicate names from partial duplicate', async () => {
89
- const code = `export { foo, bar };
90
- export { foo, baz };`;
91
- const expected = `export { foo, bar };
92
- export { baz };`;
93
- const testFile = join(tempDir, 'test.js');
94
- await Bun.write(testFile, code);
95
- await fixDuplicateExportsInDirectory(tempDir, false);
96
- const result = await Bun.file(testFile).text();
97
- expect(result).toBe(expected);
98
- });
99
- test('handles three-way duplicates', async () => {
100
- const code = `export { foo };
101
- export { bar };
102
- export { foo };`;
103
- const expected = `export { foo };
104
- export { bar };
105
- `;
106
- const testFile = join(tempDir, 'test.js');
107
- await Bun.write(testFile, code);
108
- await fixDuplicateExportsInDirectory(tempDir, false);
109
- const result = await Bun.file(testFile).text();
110
- expect(result).toBe(expected);
111
- });
112
- test('preserves non-duplicate exports', async () => {
113
- const code = `export { foo };
114
- export { bar };
115
- export { baz };`;
116
- const testFile = join(tempDir, 'test.js');
117
- await Bun.write(testFile, code);
118
- await fixDuplicateExportsInDirectory(tempDir, false);
119
- const result = await Bun.file(testFile).text();
120
- // Should not change - no duplicates
121
- expect(result).toBe(code);
122
- });
123
- });
124
- describe('__INVALID__REF__ removal', () => {
125
- test('removes __INVALID__REF__ at start with comma', async () => {
126
- const code = `export { __INVALID__REF__, foo, bar };`;
127
- const expected = `export { foo, bar };`;
128
- const testFile = join(tempDir, 'test.js');
129
- await Bun.write(testFile, code);
130
- await fixDuplicateExportsInDirectory(tempDir, false);
131
- const result = await Bun.file(testFile).text();
132
- expect(result).toBe(expected);
133
- });
134
- test('removes __INVALID__REF__ at end with comma', async () => {
135
- const code = `export { foo, bar, __INVALID__REF__ };`;
136
- const expected = `export { foo, bar };`;
137
- const testFile = join(tempDir, 'test.js');
138
- await Bun.write(testFile, code);
139
- await fixDuplicateExportsInDirectory(tempDir, false);
140
- const result = await Bun.file(testFile).text();
141
- expect(result).toBe(expected);
142
- });
143
- test('removes __INVALID__REF__ in middle', async () => {
144
- const code = `export { foo, __INVALID__REF__, bar };`;
145
- const expected = `export { foo, bar };`;
146
- const testFile = join(tempDir, 'test.js');
147
- await Bun.write(testFile, code);
148
- await fixDuplicateExportsInDirectory(tempDir, false);
149
- const result = await Bun.file(testFile).text();
150
- expect(result).toBe(expected);
151
- });
152
- test('removes __INVALID__REF__ from imports', async () => {
153
- const code = `import { __INVALID__REF__, foo } from 'bar';
154
- export { foo };`;
155
- const expected = `import { foo } from 'bar';
156
- export { foo };`;
157
- const testFile = join(tempDir, 'test.js');
158
- await Bun.write(testFile, code);
159
- await fixDuplicateExportsInDirectory(tempDir, false);
160
- const result = await Bun.file(testFile).text();
161
- expect(result).toBe(expected);
162
- });
163
- });
164
- describe('complex scenarios', () => {
165
- test('handles combination of aliases and duplicates', async () => {
166
- const code = `export { foo as exportedFoo, bar };
167
- export { baz as exportedBaz };
168
- export { bar, qux };`;
169
- const expected = `export { foo as exportedFoo, bar };
170
- export { baz as exportedBaz };
171
- export { qux };`;
172
- const testFile = join(tempDir, 'test.js');
173
- await Bun.write(testFile, code);
174
- await fixDuplicateExportsInDirectory(tempDir, false);
175
- const result = await Bun.file(testFile).text();
176
- expect(result).toBe(expected);
177
- });
178
- test('handles whitespace variations', async () => {
179
- const code = `export { foo };
180
- export { bar as baz , foo };`;
181
- const expected = `export { foo };
182
- export { bar as baz };`;
183
- const testFile = join(tempDir, 'test.js');
184
- await Bun.write(testFile, code);
185
- await fixDuplicateExportsInDirectory(tempDir, false);
186
- const result = await Bun.file(testFile).text();
187
- expect(result).toBe(expected);
188
- });
189
- test('does not modify non-matching export patterns', async () => {
190
- const code = `export default function foo() {}
191
- export const bar = 1;
192
- export { baz };
193
- export * from './other';`;
194
- const testFile = join(tempDir, 'test.js');
195
- await Bun.write(testFile, code);
196
- await fixDuplicateExportsInDirectory(tempDir, false);
197
- const result = await Bun.file(testFile).text();
198
- // Should only process export { ... } statements
199
- expect(result).toBe(code);
200
- });
201
- test('handles multiple files in directory', async () => {
202
- const file1 = join(tempDir, 'file1.js');
203
- const file2 = join(tempDir, 'file2.js');
204
- await Bun.write(file1, `export { foo };\nexport { foo };`);
205
- await Bun.write(file2, `export { qux as baz };\nexport { baz };`);
206
- await fixDuplicateExportsInDirectory(tempDir, false);
207
- const result1 = await Bun.file(file1).text();
208
- const result2 = await Bun.file(file2).text();
209
- expect(result1).toBe(`export { foo };
210
- `);
211
- expect(result2).toBe(`export { qux as baz };
212
- `);
213
- });
214
- });
215
- describe('patch order edge cases', () => {
216
- test('handles partial duplicate followed by full duplicate', async () => {
217
- // This tests the scenario where modification shifts indices for subsequent removal
218
- const code = `export { foo };
219
- export { foo, bar };
220
- export { foo };`;
221
- // Expected: first foo kept, second becomes just bar, third removed
222
- const expected = `export { foo };
223
- export { bar };
224
- `;
225
- const testFile = join(tempDir, 'test.js');
226
- await Bun.write(testFile, code);
227
- await fixDuplicateExportsInDirectory(tempDir, false);
228
- const result = await Bun.file(testFile).text();
229
- expect(result).toBe(expected);
230
- });
231
- test('handles multiple partial duplicates with full duplicate at end', async () => {
232
- const code = `export { foo };
233
- export { foo, bar };
234
- export { foo, baz };
235
- export { foo };`;
236
- // First foo kept, second becomes bar only, third becomes baz only, fourth removed
237
- const expected = `export { foo };
238
- export { bar };
239
- export { baz };
240
- `;
241
- const testFile = join(tempDir, 'test.js');
242
- await Bun.write(testFile, code);
243
- await fixDuplicateExportsInDirectory(tempDir, false);
244
- const result = await Bun.file(testFile).text();
245
- expect(result).toBe(expected);
246
- });
247
- test('handles full duplicate followed by partial duplicate', async () => {
248
- const code = `export { foo, bar };
249
- export { foo, bar };
250
- export { bar, baz };`;
251
- // First kept, second removed (full dup - leaves blank line), third becomes just baz
252
- const expected = `export { foo, bar };
253
-
254
- export { baz };`;
255
- const testFile = join(tempDir, 'test.js');
256
- await Bun.write(testFile, code);
257
- await fixDuplicateExportsInDirectory(tempDir, false);
258
- const result = await Bun.file(testFile).text();
259
- expect(result).toBe(expected);
260
- });
261
- });
262
- describe('edge cases', () => {
263
- test('handles empty file', async () => {
264
- const code = '';
265
- const testFile = join(tempDir, 'test.js');
266
- await Bun.write(testFile, code);
267
- await fixDuplicateExportsInDirectory(tempDir, false);
268
- const result = await Bun.file(testFile).text();
269
- expect(result).toBe(code);
270
- });
271
- test('handles file with no exports', async () => {
272
- const code = `const foo = 1;\nconst bar = 2;`;
273
- const testFile = join(tempDir, 'test.js');
274
- await Bun.write(testFile, code);
275
- await fixDuplicateExportsInDirectory(tempDir, false);
276
- const result = await Bun.file(testFile).text();
277
- expect(result).toBe(code);
278
- });
279
- test('handles single export with alias', async () => {
280
- const code = `export { foo as bar };`;
281
- const testFile = join(tempDir, 'test.js');
282
- await Bun.write(testFile, code);
283
- await fixDuplicateExportsInDirectory(tempDir, false);
284
- const result = await Bun.file(testFile).text();
285
- expect(result).toBe(code);
286
- });
287
- test('handles export with semicolon vs without', async () => {
288
- const code = `export { foo }
289
- export { foo };`;
290
- const expected = `export { foo }
291
- `;
292
- const testFile = join(tempDir, 'test.js');
293
- await Bun.write(testFile, code);
294
- await fixDuplicateExportsInDirectory(tempDir, false);
295
- const result = await Bun.file(testFile).text();
296
- expect(result).toBe(expected);
297
- });
298
- });
299
- });
300
- //# sourceMappingURL=fix-duplicate-exports.test.js.map