@komaci/esm-generator 260.39.0 → 260.40.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: '
|
|
366
|
+
namespace: 'lightning',
|
|
367
367
|
name: 'tsComponent',
|
|
368
368
|
type: 'internal',
|
|
369
369
|
namespaceMapping: {},
|
|
@@ -301,7 +301,7 @@ describe('Bundle processing', () => {
|
|
|
301
301
|
const input = {
|
|
302
302
|
moduleInfo: {
|
|
303
303
|
name: 'test',
|
|
304
|
-
namespace: '
|
|
304
|
+
namespace: 'lightning',
|
|
305
305
|
type: 'bundle',
|
|
306
306
|
files: bundleSrcFileMap,
|
|
307
307
|
},
|
|
@@ -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.
|
|
322
|
+
'subdir/test.js': {},
|
|
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.
|
|
334
|
+
'subdir/test.js': '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
|
|
349
|
+
const fooJsSource = `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.
|
|
360
|
+
{ fileName: 'foo.js', source: fooJsSource },
|
|
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.
|
|
381
|
+
'foo.js': fooJsSource,
|
|
382
382
|
'test.html': '<template><div>Test</div></template>',
|
|
383
383
|
'test.css': 'p { text-align: center; }',
|
|
384
384
|
},
|
|
@@ -389,5 +389,105 @@ 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
|
+
});
|
|
392
492
|
});
|
|
393
493
|
//# sourceMappingURL=index.spec.js.map
|
|
@@ -5,11 +5,12 @@ 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.
|
|
8
9
|
* @returns Returns raw source code as string for the js of a component if it exists in the srcFileMap
|
|
9
10
|
* Returns undefined if no JS source file (whose filename also matches the LWC module name) was included in the
|
|
10
11
|
* GeneratorState.GeneratorInput by lwc-platform, other calling code.
|
|
11
12
|
*/
|
|
12
|
-
export declare function getComponentSrcJs(generatorInput: GeneratorInput): string | undefined;
|
|
13
|
+
export declare function getComponentSrcJs(generatorInput: GeneratorInput, allowTypeScript?: boolean): string | undefined;
|
|
13
14
|
/**
|
|
14
15
|
* AST is traversed to see if they contain getter functions that are not valid. For each getter that is valid, we will
|
|
15
16
|
* update contextual information about the class and pass back info about the valid getters.
|
|
@@ -7,15 +7,17 @@ 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.
|
|
10
11
|
* @returns Returns raw source code as string for the js of a component if it exists in the srcFileMap
|
|
11
12
|
* Returns undefined if no JS source file (whose filename also matches the LWC module name) was included in the
|
|
12
13
|
* GeneratorState.GeneratorInput by lwc-platform, other calling code.
|
|
13
14
|
*/
|
|
14
|
-
function getComponentSrcJs(generatorInput) {
|
|
15
|
+
function getComponentSrcJs(generatorInput, allowTypeScript = true) {
|
|
15
16
|
let sourceCode;
|
|
16
17
|
const moduleName = generatorInput.moduleInfo.name;
|
|
17
18
|
if (generatorInput.srcFileMap) {
|
|
18
|
-
const filename = Object.keys(generatorInput.srcFileMap).find((filename) => (filename.endsWith('.js') ||
|
|
19
|
+
const filename = Object.keys(generatorInput.srcFileMap).find((filename) => (filename.endsWith('.js') ||
|
|
20
|
+
(filename.endsWith('.ts') && allowTypeScript)) &&
|
|
19
21
|
filename.startsWith(moduleName));
|
|
20
22
|
if (filename) {
|
|
21
23
|
sourceCode = generatorInput.srcFileMap[filename];
|
package/build/index.js
CHANGED
|
@@ -86,6 +86,15 @@ 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
|
+
}
|
|
89
98
|
/**
|
|
90
99
|
* Helper function to process and build the resolvable module based off the generator input and inital generator state.
|
|
91
100
|
* @param input the Generator input
|
|
@@ -97,14 +106,16 @@ function processGeneratorInputAndState(input) {
|
|
|
97
106
|
// Determine file type based on extension in file name.
|
|
98
107
|
const segments = (0, common_shared_1.getFilepathSegments)(input.moduleInfo.fileName);
|
|
99
108
|
const fileExt = segments[segments.length - 1];
|
|
109
|
+
const namespace = input.moduleInfo.namespace;
|
|
110
|
+
const isTypeScriptAllowed = shouldProcessTypeScriptForNamespace(namespace);
|
|
100
111
|
let sourceFile;
|
|
101
|
-
const source = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
112
|
+
const source = (0, componentAstProcessing_1.getComponentSrcJs)(input, isTypeScriptAllowed);
|
|
102
113
|
if (fileExt === 'html') {
|
|
103
114
|
const templateMap = {};
|
|
104
115
|
templateMap[input.moduleInfo.name] = input.moduleInfo.komaciDoc;
|
|
105
116
|
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, undefined, templateMap, source);
|
|
106
117
|
}
|
|
107
|
-
else if (fileExt === 'js' || fileExt === 'ts') {
|
|
118
|
+
else if (fileExt === 'js' || (fileExt === 'ts' && isTypeScriptAllowed)) {
|
|
108
119
|
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, input.moduleInfo.komaciDoc, undefined, source);
|
|
109
120
|
}
|
|
110
121
|
else {
|
|
@@ -116,6 +127,8 @@ function processGeneratorInputAndState(input) {
|
|
|
116
127
|
else if (input.moduleInfo.type === 'bundle') {
|
|
117
128
|
// code to process a bundle
|
|
118
129
|
let filename = '', fileExt;
|
|
130
|
+
const namespace = input.moduleInfo.namespace;
|
|
131
|
+
const isTypeScriptAllowed = shouldProcessTypeScriptForNamespace(namespace);
|
|
119
132
|
const scriptDocs = {}; // {'test.js' : { filename: 'test', komaciDoc: KomaciDoc1 }}
|
|
120
133
|
const htmlDocs = {};
|
|
121
134
|
let sourceFile;
|
|
@@ -127,14 +140,14 @@ function processGeneratorInputAndState(input) {
|
|
|
127
140
|
if (fileExt == 'html') {
|
|
128
141
|
htmlDocs[filename] = komaciDoc;
|
|
129
142
|
}
|
|
130
|
-
else if (fileExt === 'js' || fileExt === 'ts') {
|
|
143
|
+
else if (fileExt === 'js' || (fileExt === 'ts' && isTypeScriptAllowed)) {
|
|
131
144
|
scriptDocs[filePath] = { filename, komaciDoc };
|
|
132
145
|
}
|
|
133
146
|
else {
|
|
134
147
|
throw new Error(types_1.ERROR_PREFIX + 'unsupported file extension: ' + fileExt);
|
|
135
148
|
}
|
|
136
149
|
}
|
|
137
|
-
const source = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
150
|
+
const source = (0, componentAstProcessing_1.getComponentSrcJs)(input, isTypeScriptAllowed);
|
|
138
151
|
// Find the main component script file(s)
|
|
139
152
|
const mainComponentScriptFiles = Object.values(scriptDocs).filter(({ filename }) => filename === input.moduleInfo.name);
|
|
140
153
|
// For now we only support one main component script file.
|