@komaci/esm-generator 260.30.0 → 262.3.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.
@@ -376,6 +376,26 @@ export default class Component extends LightningElement {
376
376
  expect(metadata.files.length).toBeGreaterThan(0);
377
377
  const tsFile = metadata.files.find((f) => f.fileName === 'component.ts');
378
378
  expect(tsFile).toBeDefined();
379
+ expect(tsFile?.komaciDoc).toBeDefined();
380
+ // Now verify the full ADG generation path works with TypeScript bundle
381
+ const srcFileMap = bundleFiles.reduce((map, { fileName, source }) => ({ ...map, [fileName]: source }), {});
382
+ const inputFiles = Object.fromEntries(metadata.files
383
+ .map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
384
+ .filter(([, komaciDoc]) => !!komaciDoc));
385
+ const generatorInput = {
386
+ moduleInfo: {
387
+ name: bundleConfig.name,
388
+ namespace: bundleConfig.namespace,
389
+ type: 'bundle',
390
+ files: inputFiles,
391
+ },
392
+ srcFileMap,
393
+ };
394
+ // This exercises the full code path including the fix at line ~134
395
+ const result = (0, index_1.generateKomaciModule)(generatorInput);
396
+ // The result should be valid JavaScript and not an error
397
+ expect(result).not.toContain('ErrorFunction');
398
+ expect(result).not.toContain('unsupported file extension');
379
399
  }).not.toThrow();
380
400
  });
381
401
  // Test that verifies the file extension is properly detected
@@ -290,4 +290,212 @@ describe('normalizeSrcFileKeys', () => {
290
290
  expect(input.srcFileMap['templates/test2.html']).not.toBeUndefined();
291
291
  });
292
292
  });
293
+ describe('TypeScript Bundle Processing', () => {
294
+ it('should process bundles containing TypeScript files', () => {
295
+ // Create a proper KomaciDocument structure for TypeScript file
296
+ const komaciDoc = {
297
+ adgs: [{}],
298
+ exports: {
299
+ default: {
300
+ type: 'AdgReference',
301
+ value: 0,
302
+ },
303
+ },
304
+ };
305
+ const input = {
306
+ moduleInfo: {
307
+ name: 'tsComponent',
308
+ namespace: 'c',
309
+ type: 'bundle',
310
+ files: {
311
+ 'tsComponent.ts': komaciDoc,
312
+ 'tsComponent.html': {},
313
+ },
314
+ },
315
+ srcFileMap: {
316
+ 'tsComponent.ts': `
317
+ import { LightningElement, api } from 'lwc';
318
+
319
+ export default class TsComponent extends LightningElement {
320
+ @api recordId: string;
321
+
322
+ get displayName(): string {
323
+ return 'TypeScript Component';
324
+ }
325
+ }`,
326
+ 'tsComponent.html': '<template><div>{displayName}</div></template>',
327
+ },
328
+ };
329
+ // This should NOT throw an error
330
+ expect(() => {
331
+ const result = (0, __1.generateKomaciModule)(input);
332
+ expect(result).toContain('registerAdgFunction');
333
+ expect(result).not.toContain('ErrorFunction');
334
+ }).not.toThrow();
335
+ });
336
+ it('should handle bundle with only TypeScript file (no HTML)', () => {
337
+ const komaciDoc = {
338
+ adgs: [{}],
339
+ exports: {
340
+ default: {
341
+ type: 'AdgReference',
342
+ value: 0,
343
+ },
344
+ },
345
+ };
346
+ const input = {
347
+ moduleInfo: {
348
+ name: 'tsOnly',
349
+ namespace: 'c',
350
+ type: 'bundle',
351
+ files: {
352
+ 'tsOnly.ts': komaciDoc,
353
+ },
354
+ },
355
+ srcFileMap: {
356
+ 'tsOnly.ts': `
357
+ import { LightningElement } from 'lwc';
358
+
359
+ export default class TsOnly extends LightningElement {
360
+ message: string = 'Hello TypeScript';
361
+ }`,
362
+ },
363
+ };
364
+ expect(() => {
365
+ const result = (0, __1.generateKomaciModule)(input);
366
+ expect(result).toContain('registerAdgFunction');
367
+ }).not.toThrow();
368
+ });
369
+ it('should handle TypeScript with complex type annotations', () => {
370
+ const komaciDoc = {
371
+ adgs: [{}],
372
+ exports: {
373
+ default: {
374
+ type: 'AdgReference',
375
+ value: 0,
376
+ },
377
+ },
378
+ };
379
+ const input = {
380
+ moduleInfo: {
381
+ name: 'complexTs',
382
+ namespace: 'c',
383
+ type: 'bundle',
384
+ files: {
385
+ 'complexTs.ts': komaciDoc,
386
+ },
387
+ },
388
+ srcFileMap: {
389
+ 'complexTs.ts': `
390
+ import { LightningElement, api } from 'lwc';
391
+
392
+ interface User {
393
+ id: string;
394
+ name: string;
395
+ }
396
+
397
+ export default class ComplexTs extends LightningElement {
398
+ @api recordId: string;
399
+ private users: User[] = [];
400
+
401
+ get userCount(): number {
402
+ return this.users.length;
403
+ }
404
+ }`,
405
+ },
406
+ };
407
+ expect(() => {
408
+ const result = (0, __1.generateKomaciModule)(input);
409
+ expect(result).toContain('registerAdgFunction');
410
+ }).not.toThrow();
411
+ });
412
+ it('should handle mixed bundle with both .js and .ts files', () => {
413
+ const jsDoc = {
414
+ adgs: [{}],
415
+ exports: {
416
+ default: {
417
+ type: 'AdgReference',
418
+ value: 0,
419
+ },
420
+ },
421
+ };
422
+ const tsDoc = {
423
+ adgs: [{}],
424
+ exports: {
425
+ helper: {
426
+ type: 'AdgReference',
427
+ value: 0,
428
+ },
429
+ },
430
+ };
431
+ const input = {
432
+ moduleInfo: {
433
+ name: 'mixedComponent',
434
+ namespace: 'c',
435
+ type: 'bundle',
436
+ files: {
437
+ 'mixedComponent.js': jsDoc,
438
+ 'helper.ts': tsDoc,
439
+ 'mixedComponent.html': {},
440
+ },
441
+ },
442
+ srcFileMap: {
443
+ 'mixedComponent.js': `
444
+ import { LightningElement } from 'lwc';
445
+ export default class MixedComponent extends LightningElement {}`,
446
+ 'helper.ts': `
447
+ export function helperFunction(data: string): string {
448
+ return data.toUpperCase();
449
+ }`,
450
+ 'mixedComponent.html': '<template><div>Mixed</div></template>',
451
+ },
452
+ };
453
+ expect(() => {
454
+ const result = (0, __1.generateKomaciModule)(input);
455
+ expect(result).toContain('registerAdgFunction');
456
+ }).not.toThrow();
457
+ });
458
+ it('should throw error with unsupported file extension in bundle', () => {
459
+ const input = {
460
+ moduleInfo: {
461
+ name: 'badComponent',
462
+ namespace: 'c',
463
+ type: 'bundle',
464
+ files: {
465
+ 'badComponent.xyz': {},
466
+ },
467
+ },
468
+ srcFileMap: {
469
+ 'badComponent.xyz': 'some content',
470
+ },
471
+ };
472
+ const result = (0, __1.generateKomaciModule)(input);
473
+ // Should generate an error ADG
474
+ expect(result).toContain('ErrorFunction');
475
+ expect(result).toContain('unsupported file extension: xyz');
476
+ });
477
+ it('should normalize TypeScript file paths in bundles', () => {
478
+ const bundleSrcFileMap = {
479
+ 'c/tsComponent/tsComponent.ts': {},
480
+ 'c/tsComponent/tsComponent.html': {},
481
+ };
482
+ const input = {
483
+ moduleInfo: {
484
+ name: 'tsComponent',
485
+ namespace: 'c',
486
+ type: 'bundle',
487
+ files: bundleSrcFileMap,
488
+ },
489
+ srcFileMap: {
490
+ 'c/tsComponent/tsComponent.ts': 'export default class TsComponent {}',
491
+ 'c/tsComponent/tsComponent.html': '<template><div>TS</div></template>',
492
+ },
493
+ };
494
+ (0, __1.normalizeSrcFileKeys)(input);
495
+ expect(input.moduleInfo.files['tsComponent.ts']).not.toBeUndefined();
496
+ expect(input.moduleInfo.files['tsComponent.html']).not.toBeUndefined();
497
+ expect(input.srcFileMap['tsComponent.ts']).not.toBeUndefined();
498
+ expect(input.srcFileMap['tsComponent.html']).not.toBeUndefined();
499
+ });
500
+ });
293
501
  //# sourceMappingURL=index.spec.js.map
package/build/index.js CHANGED
@@ -134,7 +134,7 @@ function processGeneratorInputAndState(input) {
134
134
  if (fileExt == 'html') {
135
135
  filesMap['html'] = filesObj;
136
136
  }
137
- else if (fileExt === 'js') {
137
+ else if (fileExt === 'js' || fileExt === 'ts') {
138
138
  filesMap['js'] = filesObj;
139
139
  }
140
140
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "260.30.0",
3
+ "version": "262.3.0",
4
4
  "description": "Komaci generator for ADG ES modules",
5
5
  "homepage": "https://komaci.dev/",
6
6
  "repository": {