@komaci/esm-generator 262.20.0 → 262.22.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.
@@ -363,7 +363,7 @@ export default class Component extends LightningElement {
363
363
  // Test that bundles with .ts files are processed correctly
364
364
  expect(() => {
365
365
  const bundleConfig = {
366
- namespace: 'lightning',
366
+ namespace: 'c',
367
367
  name: 'tsComponent',
368
368
  type: 'internal',
369
369
  namespaceMapping: {},
@@ -319,7 +319,7 @@ describe('Bundle processing', () => {
319
319
  it('can handle multiple script files with the same name in different directories', () => {
320
320
  const bundleSrcFileMap = {
321
321
  'test.js': {},
322
- 'subdir/test.js': {},
322
+ 'subdir/test.ts': {},
323
323
  'test.html': {},
324
324
  };
325
325
  const input = {
@@ -331,7 +331,7 @@ describe('Bundle processing', () => {
331
331
  },
332
332
  srcFileMap: {
333
333
  'test.js': 'export default class Test {}',
334
- 'subdir/test.js': 'export default class Test {}',
334
+ 'subdir/test.ts': 'export default class Test {}',
335
335
  'test.html': '<template><div>Test</div></template>',
336
336
  'test.css': 'p { text-align: center; }',
337
337
  },
@@ -346,7 +346,7 @@ describe('Bundle processing', () => {
346
346
  return 'test';
347
347
  }
348
348
  }`;
349
- const fooJsSource = `export default class Foo {
349
+ const fooTsSource = `export default class Foo {
350
350
  get fooProp() {
351
351
  return 'foo';
352
352
  }
@@ -357,7 +357,7 @@ describe('Bundle processing', () => {
357
357
  type: 'internal',
358
358
  files: [
359
359
  { fileName: 'test.js', source: testJsSource },
360
- { fileName: 'foo.js', source: fooJsSource },
360
+ { fileName: 'foo.ts', source: fooTsSource },
361
361
  { fileName: 'test.html', source: '<template><div>Test</div></template>' },
362
362
  { fileName: 'test.css', source: 'p { text-align: center; }' },
363
363
  ],
@@ -378,7 +378,7 @@ describe('Bundle processing', () => {
378
378
  },
379
379
  srcFileMap: {
380
380
  'test.js': testJsSource,
381
- 'foo.js': fooJsSource,
381
+ 'foo.ts': fooTsSource,
382
382
  'test.html': '<template><div>Test</div></template>',
383
383
  'test.css': 'p { text-align: center; }',
384
384
  },
@@ -389,105 +389,5 @@ describe('Bundle processing', () => {
389
389
  expect(res).toContain('testProp');
390
390
  expect(res).not.toContain('fooProp');
391
391
  });
392
- it('can process typescript files in the lightning namespace', () => {
393
- const testTsSource = `import { LightningElement } from 'lwc';
394
-
395
- export default class TestComponent extends LightningElement {
396
- private count: number = 0;
397
-
398
- get doubleCount(): number {
399
- return this.count * 2;
400
- }
401
-
402
- increment(): void {
403
- this.count++;
404
- }
405
- }`;
406
- const bundleConfig = {
407
- namespace: 'lightning',
408
- name: 'testComponent',
409
- type: 'internal',
410
- files: [
411
- { fileName: 'testComponent.ts', source: testTsSource },
412
- {
413
- fileName: 'testComponent.html',
414
- source: '<template><div>Test</div></template>',
415
- },
416
- ],
417
- enableKomaci: true,
418
- namespaceMapping: {},
419
- npmModuleMapping: {},
420
- };
421
- const metadata = (0, metadata_1.collectBundleMetadata)(bundleConfig);
422
- const inputFiles = Object.fromEntries(metadata.files
423
- .map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
424
- .filter(([, komaciDoc]) => !!komaciDoc));
425
- const input = {
426
- moduleInfo: {
427
- name: 'testComponent',
428
- namespace: 'lightning',
429
- type: 'bundle',
430
- files: inputFiles,
431
- },
432
- srcFileMap: {
433
- 'testComponent.ts': testTsSource,
434
- 'testComponent.html': '<template><div>Test</div></template>',
435
- },
436
- };
437
- const res = (0, __1.generateKomaciModule)(input);
438
- expect(res).not.toContain('ErrorFunction');
439
- expect(res).toContain('registerAdgFunction');
440
- expect(res).toContain('doubleCount');
441
- });
442
- it('throws error for typescript files in non-lightning namespace', () => {
443
- const testTsSource = `import { LightningElement } from 'lwc';
444
-
445
- export default class TestComponent extends LightningElement {
446
- private count: number = 0;
447
-
448
- get doubleCount(): number {
449
- return this.count * 2;
450
- }
451
-
452
- increment(): void {
453
- this.count++;
454
- }
455
- }`;
456
- const bundleConfig = {
457
- namespace: 'c',
458
- name: 'testComponent',
459
- type: 'internal',
460
- files: [
461
- { fileName: 'testComponent.ts', source: testTsSource },
462
- {
463
- fileName: 'testComponent.html',
464
- source: '<template><div>Test</div></template>',
465
- },
466
- ],
467
- enableKomaci: true,
468
- namespaceMapping: {},
469
- npmModuleMapping: {},
470
- };
471
- const metadata = (0, metadata_1.collectBundleMetadata)(bundleConfig);
472
- const inputFiles = Object.fromEntries(metadata.files
473
- .map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
474
- .filter(([, komaciDoc]) => !!komaciDoc));
475
- const input = {
476
- moduleInfo: {
477
- name: 'testComponent',
478
- namespace: 'c',
479
- type: 'bundle',
480
- files: inputFiles,
481
- },
482
- srcFileMap: {
483
- 'testComponent.ts': testTsSource,
484
- 'testComponent.html': '<template><div>Test</div></template>',
485
- },
486
- };
487
- const res = (0, __1.generateKomaciModule)(input);
488
- // TypeScript files in non-lightning namespaces should now throw an error
489
- expect(res).toContain('ErrorFunction');
490
- expect(res).toContain('unsupported file extension: ts');
491
- });
492
392
  });
493
393
  //# sourceMappingURL=index.spec.js.map
@@ -5,12 +5,11 @@ import { ModuleContext, ModuleMetadata, HoistedFunctionMetadata } from '@komaci/
5
5
  /**
6
6
  * Retrieve the file path for the js of a component
7
7
  * @param generatorState GeneratorState containg the GeneratorInput, which in turn contains the JS raw source file
8
- * @param allowTypeScript Optional parameter to control whether TypeScript files should be considered. Defaults to true for backward compatibility.
9
8
  * @returns Returns raw source code as string for the js of a component if it exists in the srcFileMap
10
9
  * Returns undefined if no JS source file (whose filename also matches the LWC module name) was included in the
11
10
  * GeneratorState.GeneratorInput by lwc-platform, other calling code.
12
11
  */
13
- export declare function getComponentSrcJs(generatorInput: GeneratorInput, allowTypeScript?: boolean): string | undefined;
12
+ export declare function getComponentSrcJs(generatorInput: GeneratorInput): string | undefined;
14
13
  /**
15
14
  * AST is traversed to see if they contain getter functions that are not valid. For each getter that is valid, we will
16
15
  * update contextual information about the class and pass back info about the valid getters.
@@ -7,17 +7,15 @@ const common_shared_1 = require("@komaci/common-shared");
7
7
  /**
8
8
  * Retrieve the file path for the js of a component
9
9
  * @param generatorState GeneratorState containg the GeneratorInput, which in turn contains the JS raw source file
10
- * @param allowTypeScript Optional parameter to control whether TypeScript files should be considered. Defaults to true for backward compatibility.
11
10
  * @returns Returns raw source code as string for the js of a component if it exists in the srcFileMap
12
11
  * Returns undefined if no JS source file (whose filename also matches the LWC module name) was included in the
13
12
  * GeneratorState.GeneratorInput by lwc-platform, other calling code.
14
13
  */
15
- function getComponentSrcJs(generatorInput, allowTypeScript = true) {
14
+ function getComponentSrcJs(generatorInput) {
16
15
  let sourceCode;
17
16
  const moduleName = generatorInput.moduleInfo.name;
18
17
  if (generatorInput.srcFileMap) {
19
- const filename = Object.keys(generatorInput.srcFileMap).find((filename) => (filename.endsWith('.js') ||
20
- (filename.endsWith('.ts') && allowTypeScript)) &&
18
+ const filename = Object.keys(generatorInput.srcFileMap).find((filename) => (filename.endsWith('.js') || filename.endsWith('.ts')) &&
21
19
  filename.startsWith(moduleName));
22
20
  if (filename) {
23
21
  sourceCode = generatorInput.srcFileMap[filename];
package/build/index.js CHANGED
@@ -86,15 +86,6 @@ function normalizeSrcFileKeys(input) {
86
86
  }
87
87
  }
88
88
  exports.normalizeSrcFileKeys = normalizeSrcFileKeys;
89
- /**
90
- * Determines if TypeScript files should be processed for the given namespace.
91
- * TypeScript files are only processed for lightning and lightning/interop namespaces.
92
- * @param namespace the module namespace
93
- * @returns true if TypeScript files should be processed
94
- */
95
- function shouldProcessTypeScriptForNamespace(namespace) {
96
- return namespace === 'lightning' || namespace.startsWith('lightning/interop');
97
- }
98
89
  /**
99
90
  * Helper function to process and build the resolvable module based off the generator input and inital generator state.
100
91
  * @param input the Generator input
@@ -106,16 +97,14 @@ function processGeneratorInputAndState(input) {
106
97
  // Determine file type based on extension in file name.
107
98
  const segments = (0, common_shared_1.getFilepathSegments)(input.moduleInfo.fileName);
108
99
  const fileExt = segments[segments.length - 1];
109
- const namespace = input.moduleInfo.namespace;
110
- const isTypeScriptAllowed = shouldProcessTypeScriptForNamespace(namespace);
111
100
  let sourceFile;
112
- const source = (0, componentAstProcessing_1.getComponentSrcJs)(input, isTypeScriptAllowed);
101
+ const source = (0, componentAstProcessing_1.getComponentSrcJs)(input);
113
102
  if (fileExt === 'html') {
114
103
  const templateMap = {};
115
104
  templateMap[input.moduleInfo.name] = input.moduleInfo.komaciDoc;
116
105
  sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, undefined, templateMap, source);
117
106
  }
118
- else if (fileExt === 'js' || (fileExt === 'ts' && isTypeScriptAllowed)) {
107
+ else if (fileExt === 'js' || fileExt === 'ts') {
119
108
  sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, input.moduleInfo.komaciDoc, undefined, source);
120
109
  }
121
110
  else {
@@ -127,8 +116,6 @@ function processGeneratorInputAndState(input) {
127
116
  else if (input.moduleInfo.type === 'bundle') {
128
117
  // code to process a bundle
129
118
  let filename = '', fileExt;
130
- const namespace = input.moduleInfo.namespace;
131
- const isTypeScriptAllowed = shouldProcessTypeScriptForNamespace(namespace);
132
119
  const scriptDocs = {}; // {'test.js' : { filename: 'test', komaciDoc: KomaciDoc1 }}
133
120
  const htmlDocs = {};
134
121
  let sourceFile;
@@ -140,14 +127,14 @@ function processGeneratorInputAndState(input) {
140
127
  if (fileExt == 'html') {
141
128
  htmlDocs[filename] = komaciDoc;
142
129
  }
143
- else if (fileExt === 'js' || (fileExt === 'ts' && isTypeScriptAllowed)) {
130
+ else if (fileExt === 'js' || fileExt === 'ts') {
144
131
  scriptDocs[filePath] = { filename, komaciDoc };
145
132
  }
146
133
  else {
147
134
  throw new Error(types_1.ERROR_PREFIX + 'unsupported file extension: ' + fileExt);
148
135
  }
149
136
  }
150
- const source = (0, componentAstProcessing_1.getComponentSrcJs)(input, isTypeScriptAllowed);
137
+ const source = (0, componentAstProcessing_1.getComponentSrcJs)(input);
151
138
  // Find the main component script file(s)
152
139
  const mainComponentScriptFiles = Object.values(scriptDocs).filter(({ filename }) => filename === input.moduleInfo.name);
153
140
  // For now we only support one main component script file.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@komaci/esm-generator",
3
- "version": "262.20.0",
3
+ "version": "262.22.0",
4
4
  "description": "Komaci generator for ADG ES modules",
5
5
  "homepage": "https://komaci.dev/",
6
6
  "repository": {