@komaci/esm-generator 264.5.0 → 266.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.
- package/build/genericAstGeneration.js +80 -34
- package/package.json +1 -1
- package/build/__tests__/adgAstGeneration.spec.d.ts +0 -2
- package/build/__tests__/adgAstGeneration.spec.js +0 -447
- package/build/__tests__/compile-generated-module-fixtures.spec.d.ts +0 -2
- package/build/__tests__/compile-generated-module-fixtures.spec.js +0 -49
- package/build/__tests__/compilerConfigs.d.ts +0 -24
- package/build/__tests__/compilerConfigs.js +0 -126
- package/build/__tests__/compositionAstGeneration.spec.d.ts +0 -2
- package/build/__tests__/compositionAstGeneration.spec.js +0 -676
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.d.ts +0 -6
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.js +0 -28
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.d.ts +0 -29
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +0 -148
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.d.ts +0 -9
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.js +0 -35
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.d.ts +0 -10
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.js +0 -39
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.d.ts +0 -7
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.js +0 -34
- package/build/__tests__/fixtures-combined-files/image-type/actual.d.ts +0 -13
- package/build/__tests__/fixtures-combined-files/image-type/actual.js +0 -41
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.d.ts +0 -14
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +0 -79
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.d.ts +0 -18
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +0 -103
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.d.ts +0 -6
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.js +0 -28
- package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-imports/actual.d.ts +0 -6
- package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-imports/actual.js +0 -16
- package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-nonAnalyzable-imports/actual.d.ts +0 -4
- package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-nonAnalyzable-imports/actual.js +0 -18
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.d.ts +0 -10
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.js +0 -41
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.d.ts +0 -9
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.js +0 -38
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.d.ts +0 -7
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.js +0 -34
- package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.d.ts +0 -1
- package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.js +0 -2
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.d.ts +0 -6
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.js +0 -19
- package/build/__tests__/fixtures-combined-files-multiple-templates/invalid-renderFunc-no-valid-imports/c/component/component.d.ts +0 -5
- package/build/__tests__/fixtures-combined-files-multiple-templates/invalid-renderFunc-no-valid-imports/c/component/component.js +0 -14
- package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-complex/lightning/component/component.d.ts +0 -6
- package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-complex/lightning/component/component.js +0 -31
- package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-simple/lightning/component/component.d.ts +0 -6
- package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-simple/lightning/component/component.js +0 -27
- package/build/__tests__/fixtures-gql/multipleGqlQueries/c/component/component.d.ts +0 -15
- package/build/__tests__/fixtures-gql/multipleGqlQueries/c/component/component.js +0 -104
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.d.ts +0 -8
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.js +0 -17
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.d.ts +0 -4
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.js +0 -13
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.d.ts +0 -4
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.js +0 -10
- package/build/__tests__/fixtures-script-files/class-props/actual.d.ts +0 -30
- package/build/__tests__/fixtures-script-files/class-props/actual.js +0 -103
- package/build/__tests__/fixtures-script-files/empty-class/actual.d.ts +0 -4
- package/build/__tests__/fixtures-script-files/empty-class/actual.js +0 -7
- package/build/__tests__/fixtures-script-files/empty-doc/actual.d.ts +0 -1
- package/build/__tests__/fixtures-script-files/empty-doc/actual.js +0 -2
- package/build/__tests__/fixtures-script-files/empty-wire/actual.d.ts +0 -5
- package/build/__tests__/fixtures-script-files/empty-wire/actual.js +0 -16
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.d.ts +0 -7
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.js +0 -34
- package/build/__tests__/fixtures-script-files/exports/actual.d.ts +0 -22
- package/build/__tests__/fixtures-script-files/exports/actual.js +0 -63
- package/build/__tests__/fixtures-script-files/imports/actual.d.ts +0 -11
- package/build/__tests__/fixtures-script-files/imports/actual.js +0 -80
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.d.ts +0 -10
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +0 -63
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.d.ts +0 -7
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.js +0 -34
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.d.ts +0 -3
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.js +0 -10
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.d.ts +0 -9
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.js +0 -24
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.d.ts +0 -4
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.js +0 -17
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.d.ts +0 -4
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.js +0 -17
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.d.ts +0 -6
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.js +0 -19
- package/build/__tests__/fixtures-script-files/wire-basic/actual.d.ts +0 -8
- package/build/__tests__/fixtures-script-files/wire-basic/actual.js +0 -30
- package/build/__tests__/fixtures-script-files/wire-functions/actual.d.ts +0 -13
- package/build/__tests__/fixtures-script-files/wire-functions/actual.js +0 -46
- package/build/__tests__/fixtures-script-files/wire-imports/actual.d.ts +0 -11
- package/build/__tests__/fixtures-script-files/wire-imports/actual.js +0 -63
- package/build/__tests__/fixtures-source-code/badImportRef.d.ts +0 -4
- package/build/__tests__/fixtures-source-code/badImportRef.js +0 -31
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.d.ts +0 -8
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.js +0 -127
- package/build/__tests__/fixtures-source-code/gqlMockSource.d.ts +0 -3
- package/build/__tests__/fixtures-source-code/gqlMockSource.js +0 -95
- package/build/__tests__/functionAstGeneration.spec.d.ts +0 -2
- package/build/__tests__/functionAstGeneration.spec.js +0 -727
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.d.ts +0 -10
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.js +0 -41
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.d.ts +0 -7
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.js +0 -31
- package/build/__tests__/general-komaci-docs/import-types/source.d.ts +0 -18
- package/build/__tests__/general-komaci-docs/import-types/source.js +0 -108
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.d.ts +0 -18
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.js +0 -63
- package/build/__tests__/general-komaci-docs/template-component/source.d.ts +0 -8
- package/build/__tests__/general-komaci-docs/template-component/source.js +0 -34
- package/build/__tests__/generated-module/compile-graphql-with-scoped-import.spec.d.ts +0 -2
- package/build/__tests__/generated-module/compile-graphql-with-scoped-import.spec.js +0 -20
- package/build/__tests__/generated-module/lightning/component/component.d.ts +0 -18
- package/build/__tests__/generated-module/lightning/component/component.js +0 -168
- package/build/__tests__/genericAstGeneration.spec.d.ts +0 -2
- package/build/__tests__/genericAstGeneration.spec.js +0 -1052
- package/build/__tests__/index.spec.d.ts +0 -2
- package/build/__tests__/index.spec.js +0 -393
- package/build/__tests__/komaci-ast-unit.spec.d.ts +0 -2
- package/build/__tests__/komaci-ast-unit.spec.js +0 -422
- package/build/__tests__/komaci-bundle-module.fixtures.spec.d.ts +0 -2
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +0 -76
- package/build/__tests__/komaci-bundle-multiple-templates-module.fixtures.spec.d.ts +0 -2
- package/build/__tests__/komaci-bundle-multiple-templates-module.fixtures.spec.js +0 -117
- package/build/__tests__/komaci-gql.fixtures.spec.d.ts +0 -2
- package/build/__tests__/komaci-gql.fixtures.spec.js +0 -51
- package/build/__tests__/komaci-script-module.fixtures.spec.d.ts +0 -2
- package/build/__tests__/komaci-script-module.fixtures.spec.js +0 -70
- package/build/__tests__/komaci-template-module.fixtures.spec.d.ts +0 -2
- package/build/__tests__/komaci-template-module.fixtures.spec.js +0 -57
- package/build/__tests__/readAndParseBundle.d.ts +0 -22
- package/build/__tests__/readAndParseBundle.js +0 -80
|
@@ -1,422 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const componentAstProcessing_1 = require("../componentAstProcessing");
|
|
4
|
-
const generalMockSourceCode_1 = require("./fixtures-source-code/generalMockSourceCode");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const common_shared_1 = require("@komaci/common-shared");
|
|
8
|
-
const initGeneratorState = (input) => ({
|
|
9
|
-
input,
|
|
10
|
-
adgImportSuffix: 0,
|
|
11
|
-
importAliasSuffix: 0,
|
|
12
|
-
scriptGenState: {
|
|
13
|
-
importRefsMap: {},
|
|
14
|
-
requiredFactoryFunctions: new Set([]),
|
|
15
|
-
importInfosForWireAdapter: new Set([]),
|
|
16
|
-
primingAdapterImportDeclarations: [],
|
|
17
|
-
},
|
|
18
|
-
templateGenState: {
|
|
19
|
-
importRefsMap: {},
|
|
20
|
-
requiredFactoryFunctions: new Set(),
|
|
21
|
-
refProps: new Set(),
|
|
22
|
-
},
|
|
23
|
-
iterationContext: [],
|
|
24
|
-
defaultCompImported: true,
|
|
25
|
-
adgNameMap: {},
|
|
26
|
-
isDefaultExportFound: true,
|
|
27
|
-
});
|
|
28
|
-
describe('getAstFromGenStateRawSrc', () => {
|
|
29
|
-
it('should handle LWC modules with multiple file types and multiple JS files', () => {
|
|
30
|
-
const filesMap = {};
|
|
31
|
-
filesMap['test.js'] = {
|
|
32
|
-
exports: { 'test.js': { type: 'AdgReference', value: 0 } },
|
|
33
|
-
};
|
|
34
|
-
filesMap['test.html'] = {
|
|
35
|
-
exports: { 'test.html': { type: 'CompositionReference', value: 0 } },
|
|
36
|
-
};
|
|
37
|
-
filesMap['test.css'] = {
|
|
38
|
-
exports: { 'test.css': { type: 'CompositionReference', value: 0 } },
|
|
39
|
-
};
|
|
40
|
-
filesMap['somethingElse.js'] = {
|
|
41
|
-
exports: { 'somethingElse.js': { type: 'AdgReference', value: 0 } },
|
|
42
|
-
};
|
|
43
|
-
const input = {
|
|
44
|
-
moduleInfo: {
|
|
45
|
-
name: 'test',
|
|
46
|
-
namespace: 'c',
|
|
47
|
-
type: 'bundle',
|
|
48
|
-
files: filesMap,
|
|
49
|
-
},
|
|
50
|
-
srcFileMap: {
|
|
51
|
-
'test.js': 'console.log("hi");',
|
|
52
|
-
'somethingElse.js': 'eval("bye")',
|
|
53
|
-
'test.css': 'p { text-align: center; }',
|
|
54
|
-
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
const srcCode = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
58
|
-
expect(srcCode).not.toBeUndefined();
|
|
59
|
-
expect(srcCode).toEqual(input.srcFileMap?.['test.js']);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('proccessGetters', () => {
|
|
63
|
-
const filesMap = {};
|
|
64
|
-
filesMap['test.js'] = {
|
|
65
|
-
exports: { 'test.js': { type: 'AdgReference', value: 0 } },
|
|
66
|
-
};
|
|
67
|
-
filesMap['test.html'] = {
|
|
68
|
-
exports: { 'test.html': { type: 'CompositionReference', value: 0 } },
|
|
69
|
-
};
|
|
70
|
-
filesMap['test.css'] = {
|
|
71
|
-
exports: { 'test.css': { type: 'CompositionReference', value: 0 } },
|
|
72
|
-
};
|
|
73
|
-
filesMap['somethingElse.js'] = {
|
|
74
|
-
exports: { 'somethingElse.js': { type: 'AdgReference', value: 0 } },
|
|
75
|
-
};
|
|
76
|
-
it('should process and return only the valid getter', () => {
|
|
77
|
-
const input = {
|
|
78
|
-
moduleInfo: {
|
|
79
|
-
name: 'test',
|
|
80
|
-
namespace: 'lightning',
|
|
81
|
-
type: 'bundle',
|
|
82
|
-
files: filesMap,
|
|
83
|
-
},
|
|
84
|
-
srcFileMap: {
|
|
85
|
-
'test.js': generalMockSourceCode_1.mockOneBadGetter,
|
|
86
|
-
'somethingElse.js': 'eval("bye")',
|
|
87
|
-
'test.css': 'p { text-align: center; }',
|
|
88
|
-
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
const generatorState = initGeneratorState(input);
|
|
92
|
-
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
93
|
-
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
94
|
-
moduleMetadata.importsByName.set('getRecord', {
|
|
95
|
-
generatorAlias: 'i0',
|
|
96
|
-
usedInPriming: false,
|
|
97
|
-
staticallyAnalyzable: false,
|
|
98
|
-
name: 'getRecord',
|
|
99
|
-
resourceName: 'lightning/uiRecordApi',
|
|
100
|
-
isFromInternalNamespace: true,
|
|
101
|
-
isFromSupportedLibrary: true,
|
|
102
|
-
komaciDocImportRef: '0/names/0',
|
|
103
|
-
});
|
|
104
|
-
moduleMetadata.importsByName.set('findContacts', {
|
|
105
|
-
generatorAlias: 'i1',
|
|
106
|
-
usedInPriming: false,
|
|
107
|
-
staticallyAnalyzable: false,
|
|
108
|
-
name: '*',
|
|
109
|
-
resourceName: 'lightning/uiRecordApi',
|
|
110
|
-
isFromInternalNamespace: true,
|
|
111
|
-
isFromSupportedLibrary: true,
|
|
112
|
-
komaciDocImportRef: '0/names/0',
|
|
113
|
-
importAlias: 'findContacts',
|
|
114
|
-
});
|
|
115
|
-
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
116
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
117
|
-
isPublic: true,
|
|
118
|
-
usedInPriming: true,
|
|
119
|
-
});
|
|
120
|
-
moduleMetadata.adgs.get(0).properties.set('record', {
|
|
121
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
122
|
-
isPublic: false,
|
|
123
|
-
usedInPriming: true,
|
|
124
|
-
});
|
|
125
|
-
moduleMetadata.adgs.get(0).properties.set('contacts', {
|
|
126
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
127
|
-
isPublic: false,
|
|
128
|
-
usedInPriming: true,
|
|
129
|
-
});
|
|
130
|
-
moduleMetadata.adgs.get(0).properties.set('searchKey', {
|
|
131
|
-
type: common_shared_1.PropertyTypes.GETTER,
|
|
132
|
-
isPublic: false,
|
|
133
|
-
usedInPriming: true,
|
|
134
|
-
});
|
|
135
|
-
moduleMetadata.adgs.get(0).properties.set('perfectlyGood', {
|
|
136
|
-
type: common_shared_1.PropertyTypes.GETTER,
|
|
137
|
-
isPublic: false,
|
|
138
|
-
usedInPriming: true,
|
|
139
|
-
});
|
|
140
|
-
const src = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
141
|
-
expect(src).not.toBeUndefined();
|
|
142
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
143
|
-
generatorState.scriptGenState.ast = ast;
|
|
144
|
-
const moduleContext = {
|
|
145
|
-
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
146
|
-
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
147
|
-
};
|
|
148
|
-
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
149
|
-
(0, componentAstProcessing_1.processGetters)(0, moduleContext, moduleMetadata, getters);
|
|
150
|
-
const prop = moduleMetadata.adgs
|
|
151
|
-
.get(0)
|
|
152
|
-
.properties.get('perfectlyGood');
|
|
153
|
-
expect(prop?.functionIndex).not.toBeUndefined();
|
|
154
|
-
const adg = moduleMetadata.adgs.get(0);
|
|
155
|
-
expect(adg?.requiredAdgFactoryFunctions.has(common_shared_1.IdKeys.UNRESOLVED_VALUE)).toBeTruthy();
|
|
156
|
-
});
|
|
157
|
-
it('should process and return empty array for no valid getters', () => {
|
|
158
|
-
const input = {
|
|
159
|
-
moduleInfo: {
|
|
160
|
-
name: 'test',
|
|
161
|
-
namespace: 'lightning',
|
|
162
|
-
type: 'bundle',
|
|
163
|
-
files: filesMap,
|
|
164
|
-
},
|
|
165
|
-
srcFileMap: {
|
|
166
|
-
'test.js': generalMockSourceCode_1.mockOnlyBadGetter,
|
|
167
|
-
'somethingElse.js': 'eval("bye")',
|
|
168
|
-
'test.css': 'p { text-align: center; }',
|
|
169
|
-
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
const generatorState = initGeneratorState(input);
|
|
173
|
-
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
174
|
-
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
175
|
-
moduleMetadata.importsByName.set('getRecord', {
|
|
176
|
-
generatorAlias: 'i0',
|
|
177
|
-
usedInPriming: false,
|
|
178
|
-
staticallyAnalyzable: false,
|
|
179
|
-
name: 'getRecord',
|
|
180
|
-
resourceName: 'lightning/uiRecordApi',
|
|
181
|
-
isFromInternalNamespace: true,
|
|
182
|
-
isFromSupportedLibrary: true,
|
|
183
|
-
komaciDocImportRef: '0/names/0',
|
|
184
|
-
});
|
|
185
|
-
moduleMetadata.importsByName.set('findContacts', {
|
|
186
|
-
generatorAlias: 'i1',
|
|
187
|
-
usedInPriming: false,
|
|
188
|
-
staticallyAnalyzable: false,
|
|
189
|
-
name: '*',
|
|
190
|
-
resourceName: 'lightning/uiRecordApi',
|
|
191
|
-
isFromInternalNamespace: true,
|
|
192
|
-
isFromSupportedLibrary: true,
|
|
193
|
-
komaciDocImportRef: '0/names/0',
|
|
194
|
-
importAlias: 'findContacts',
|
|
195
|
-
});
|
|
196
|
-
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
197
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
198
|
-
isPublic: true,
|
|
199
|
-
usedInPriming: true,
|
|
200
|
-
});
|
|
201
|
-
moduleMetadata.adgs.get(0).properties.set('record', {
|
|
202
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
203
|
-
isPublic: false,
|
|
204
|
-
usedInPriming: true,
|
|
205
|
-
});
|
|
206
|
-
moduleMetadata.adgs.get(0).properties.set('contacts', {
|
|
207
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
208
|
-
isPublic: false,
|
|
209
|
-
usedInPriming: true,
|
|
210
|
-
});
|
|
211
|
-
moduleMetadata.adgs.get(0).properties.set('searchKey', {
|
|
212
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
213
|
-
isPublic: false,
|
|
214
|
-
usedInPriming: false,
|
|
215
|
-
});
|
|
216
|
-
const src = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
217
|
-
expect(src).not.toBeUndefined();
|
|
218
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
219
|
-
generatorState.scriptGenState.ast = ast;
|
|
220
|
-
const moduleContext = {
|
|
221
|
-
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
222
|
-
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
223
|
-
};
|
|
224
|
-
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
225
|
-
(0, componentAstProcessing_1.processGetters)(0, moduleContext, moduleMetadata, getters);
|
|
226
|
-
const prop = moduleMetadata.adgs
|
|
227
|
-
.get(0)
|
|
228
|
-
.properties.get('searchKey');
|
|
229
|
-
expect(prop?.functionIndex).toBe(common_shared_1.UNSUPPORTED_FUNCTION);
|
|
230
|
-
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
231
|
-
});
|
|
232
|
-
it('should process and return only getter with just return when namespace is not lightning', () => {
|
|
233
|
-
const input = {
|
|
234
|
-
moduleInfo: {
|
|
235
|
-
name: 'test',
|
|
236
|
-
namespace: 'c',
|
|
237
|
-
type: 'bundle',
|
|
238
|
-
files: filesMap,
|
|
239
|
-
},
|
|
240
|
-
srcFileMap: {
|
|
241
|
-
'test.js': generalMockSourceCode_1.oneGoodMockWithGetterImportUse,
|
|
242
|
-
'somethingElse.js': 'eval("bye")',
|
|
243
|
-
'test.css': 'p { text-align: center; }',
|
|
244
|
-
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
245
|
-
},
|
|
246
|
-
};
|
|
247
|
-
const generatorState = initGeneratorState(input);
|
|
248
|
-
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
249
|
-
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
250
|
-
moduleMetadata.importsByName.set('getRecord', {
|
|
251
|
-
generatorAlias: 'i0',
|
|
252
|
-
usedInPriming: false,
|
|
253
|
-
staticallyAnalyzable: false,
|
|
254
|
-
name: 'getRecord',
|
|
255
|
-
resourceName: 'lightning/uiRecordApi',
|
|
256
|
-
isFromInternalNamespace: true,
|
|
257
|
-
isFromSupportedLibrary: true,
|
|
258
|
-
komaciDocImportRef: '0/names/0',
|
|
259
|
-
});
|
|
260
|
-
moduleMetadata.importsByName.set('findContacts', {
|
|
261
|
-
generatorAlias: 'i1',
|
|
262
|
-
usedInPriming: false,
|
|
263
|
-
staticallyAnalyzable: false,
|
|
264
|
-
name: '*',
|
|
265
|
-
resourceName: 'lightning/uiRecordApi',
|
|
266
|
-
isFromInternalNamespace: true,
|
|
267
|
-
isFromSupportedLibrary: true,
|
|
268
|
-
komaciDocImportRef: '0/names/0',
|
|
269
|
-
importAlias: 'findContacts',
|
|
270
|
-
});
|
|
271
|
-
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
272
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
273
|
-
isPublic: true,
|
|
274
|
-
usedInPriming: true,
|
|
275
|
-
});
|
|
276
|
-
moduleMetadata.adgs.get(0).properties.set('record', {
|
|
277
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
278
|
-
isPublic: false,
|
|
279
|
-
usedInPriming: true,
|
|
280
|
-
});
|
|
281
|
-
moduleMetadata.adgs.get(0).properties.set('contacts', {
|
|
282
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
283
|
-
isPublic: false,
|
|
284
|
-
usedInPriming: true,
|
|
285
|
-
});
|
|
286
|
-
moduleMetadata.adgs.get(0).properties.set('searchKey', {
|
|
287
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
288
|
-
isPublic: false,
|
|
289
|
-
usedInPriming: true,
|
|
290
|
-
});
|
|
291
|
-
moduleMetadata.adgs.get(0).properties.set('perfectlyGood', {
|
|
292
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
293
|
-
isPublic: false,
|
|
294
|
-
usedInPriming: true,
|
|
295
|
-
});
|
|
296
|
-
moduleMetadata.adgs.get(0).properties.set('perfectlyGood2', {
|
|
297
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
298
|
-
isPublic: false,
|
|
299
|
-
usedInPriming: true,
|
|
300
|
-
});
|
|
301
|
-
const src = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
302
|
-
expect(src).not.toBeUndefined();
|
|
303
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
304
|
-
generatorState.scriptGenState.ast = ast;
|
|
305
|
-
const moduleContext = {
|
|
306
|
-
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
307
|
-
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
308
|
-
};
|
|
309
|
-
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
310
|
-
(0, componentAstProcessing_1.processGetters)(0, moduleContext, moduleMetadata, getters);
|
|
311
|
-
let prop = moduleMetadata.adgs
|
|
312
|
-
.get(0)
|
|
313
|
-
.properties.get('searchKey');
|
|
314
|
-
expect(prop?.functionIndex).toBe(common_shared_1.UNSUPPORTED_FUNCTION);
|
|
315
|
-
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
316
|
-
prop = moduleMetadata.adgs
|
|
317
|
-
.get(0)
|
|
318
|
-
.properties.get('perfectlyGood');
|
|
319
|
-
expect(prop?.functionIndex).toBe(common_shared_1.UNSUPPORTED_FUNCTION);
|
|
320
|
-
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
321
|
-
prop = moduleMetadata.adgs
|
|
322
|
-
.get(0)
|
|
323
|
-
.properties.get('perfectlyGood2');
|
|
324
|
-
expect(prop?.functionIndex).not.toBeUndefined();
|
|
325
|
-
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
describe('processTemplateStrings', () => {
|
|
329
|
-
it('can process out bad templates and successfully update metadata', () => {
|
|
330
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/template-component');
|
|
331
|
-
const src = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
332
|
-
encoding: 'utf-8',
|
|
333
|
-
});
|
|
334
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
335
|
-
const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
336
|
-
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
337
|
-
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
338
|
-
moduleMetadata.importsByName.set('getRecord', {
|
|
339
|
-
generatorAlias: 'i0',
|
|
340
|
-
usedInPriming: false,
|
|
341
|
-
staticallyAnalyzable: false,
|
|
342
|
-
name: 'getRecord',
|
|
343
|
-
resourceName: 'lightning/uiRecordApi',
|
|
344
|
-
isFromInternalNamespace: true,
|
|
345
|
-
isFromSupportedLibrary: true,
|
|
346
|
-
komaciDocImportRef: '0/names/0',
|
|
347
|
-
});
|
|
348
|
-
moduleMetadata.importsByName.set('gql', {
|
|
349
|
-
generatorAlias: 'i0',
|
|
350
|
-
usedInPriming: false,
|
|
351
|
-
staticallyAnalyzable: false,
|
|
352
|
-
name: 'gql',
|
|
353
|
-
resourceName: 'lightning/graphql',
|
|
354
|
-
isFromInternalNamespace: true,
|
|
355
|
-
isFromSupportedLibrary: true,
|
|
356
|
-
komaciDocImportRef: '0/names/0',
|
|
357
|
-
});
|
|
358
|
-
moduleMetadata.importsByName.set('LABEL', {
|
|
359
|
-
generatorAlias: 'i0',
|
|
360
|
-
usedInPriming: false,
|
|
361
|
-
staticallyAnalyzable: false,
|
|
362
|
-
name: '*',
|
|
363
|
-
resourceName: '@salesforce/label/crazycool',
|
|
364
|
-
isFromInternalNamespace: true,
|
|
365
|
-
isFromSupportedLibrary: true,
|
|
366
|
-
komaciDocImportRef: '0/names/0',
|
|
367
|
-
importAlias: 'LABEL',
|
|
368
|
-
});
|
|
369
|
-
moduleMetadata.importsByName.set('unusable', {
|
|
370
|
-
generatorAlias: 'i0',
|
|
371
|
-
usedInPriming: false,
|
|
372
|
-
staticallyAnalyzable: false,
|
|
373
|
-
name: '*',
|
|
374
|
-
resourceName: 'bad/import',
|
|
375
|
-
isFromInternalNamespace: false,
|
|
376
|
-
isFromSupportedLibrary: false,
|
|
377
|
-
komaciDocImportRef: '0/names/0',
|
|
378
|
-
importAlias: 'unusable',
|
|
379
|
-
});
|
|
380
|
-
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
381
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
382
|
-
isPublic: true,
|
|
383
|
-
usedInPriming: true,
|
|
384
|
-
});
|
|
385
|
-
moduleMetadata.adgs.get(0).properties.set('contract', {
|
|
386
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
387
|
-
isPublic: false,
|
|
388
|
-
usedInPriming: true,
|
|
389
|
-
});
|
|
390
|
-
moduleMetadata.adgs.get(0).properties.set('account', {
|
|
391
|
-
type: common_shared_1.PropertyTypes.WIRE,
|
|
392
|
-
isPublic: false,
|
|
393
|
-
usedInPriming: true,
|
|
394
|
-
});
|
|
395
|
-
moduleMetadata.adgs.get(0).properties.set('contractId', {
|
|
396
|
-
type: common_shared_1.PropertyTypes.TEMPLATE_STRING,
|
|
397
|
-
isPublic: false,
|
|
398
|
-
usedInPriming: true,
|
|
399
|
-
});
|
|
400
|
-
moduleMetadata.adgs.get(0).properties.set('malicious', {
|
|
401
|
-
type: common_shared_1.PropertyTypes.BASE,
|
|
402
|
-
isPublic: false,
|
|
403
|
-
usedInPriming: true,
|
|
404
|
-
});
|
|
405
|
-
const moduleContext = {
|
|
406
|
-
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
407
|
-
isExternal: (0, common_shared_1.isExternalModule)('lightning'),
|
|
408
|
-
};
|
|
409
|
-
(0, componentAstProcessing_1.processTemplateStrings)(0, moduleContext, moduleMetadata, templateStrings);
|
|
410
|
-
const validTemplate = moduleMetadata.adgs
|
|
411
|
-
.get(0)
|
|
412
|
-
.properties.get('contractId');
|
|
413
|
-
expect(validTemplate).not.toBeUndefined();
|
|
414
|
-
expect(validTemplate.functionIndex).toBe(0);
|
|
415
|
-
const templateFunction = moduleMetadata.adgs.get(0).functions[validTemplate.functionIndex];
|
|
416
|
-
expect(templateFunction.generatedName).toBe('t0');
|
|
417
|
-
expect(templateFunction.componentAstNode?.node.key.name).toBe('contractId');
|
|
418
|
-
expect(templateFunction.requiredProperties).toHaveLength(1);
|
|
419
|
-
expect(templateFunction.requiredProperties).toContain('recordId');
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
//# sourceMappingURL=komaci-ast-unit.spec.js.map
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const glob_1 = require("glob");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const index_1 = require("../index");
|
|
10
|
-
const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-combined-files');
|
|
11
|
-
const INPUT_HTML_JSON_FILENAME = 'komaciHTMLDoc.json';
|
|
12
|
-
const INPUT_JS_JSON_FILENAME = 'komaciJSDoc.json';
|
|
13
|
-
const INPUT_SRC_FILE_JSON_FILENAME = 'actual.js';
|
|
14
|
-
const INPUT_SRC_FILE_HTML_FILENAME = 'actual.html';
|
|
15
|
-
const EXPECTED_JS_FILENAME = 'expected.src';
|
|
16
|
-
function generateModuleSource(komaciHTMLDoc, komaciJSDoc, srcFileMap) {
|
|
17
|
-
const filesMap = {};
|
|
18
|
-
if (komaciHTMLDoc !== null) {
|
|
19
|
-
filesMap['test.html'] = komaciHTMLDoc;
|
|
20
|
-
}
|
|
21
|
-
if (komaciJSDoc !== null) {
|
|
22
|
-
filesMap['test.js'] = komaciJSDoc;
|
|
23
|
-
}
|
|
24
|
-
// adding miscellaneous files of empty Komaci docs, to test the negative case of unexpectedly named files
|
|
25
|
-
filesMap['something.js'] = {};
|
|
26
|
-
filesMap['somethingElese.html'] = {};
|
|
27
|
-
const input = {
|
|
28
|
-
moduleInfo: {
|
|
29
|
-
name: 'test',
|
|
30
|
-
namespace: 'c',
|
|
31
|
-
type: 'bundle',
|
|
32
|
-
files: filesMap,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
input.srcFileMap = srcFileMap;
|
|
36
|
-
return (0, index_1.generateKomaciModule)(input);
|
|
37
|
-
}
|
|
38
|
-
// eslint-disable-next-line jest/no-disabled-tests
|
|
39
|
-
describe('fixtures', () => {
|
|
40
|
-
// find all folder paths containing a file whose name ends in ".src"
|
|
41
|
-
const fixtures = (0, glob_1.globSync)(path_1.default.resolve(FIXTURES_DIR, '**/*.json'));
|
|
42
|
-
for (const caseEntry of fixtures) {
|
|
43
|
-
const caseFolder = path_1.default.dirname(caseEntry);
|
|
44
|
-
const caseName = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
45
|
-
const fixtureFilePath = (fileName) => {
|
|
46
|
-
return path_1.default.join(caseFolder, fileName);
|
|
47
|
-
};
|
|
48
|
-
const readFixtureFile = (fileName) => {
|
|
49
|
-
const filePath = fixtureFilePath(fileName);
|
|
50
|
-
return fs_1.default.existsSync(filePath) ? fs_1.default.readFileSync(filePath, 'utf-8') : null;
|
|
51
|
-
};
|
|
52
|
-
const writeFixtureFile = (fileName, content) => {
|
|
53
|
-
const filePath = fixtureFilePath(fileName);
|
|
54
|
-
fs_1.default.writeFileSync(filePath, content, { encoding: 'utf-8' });
|
|
55
|
-
};
|
|
56
|
-
it(`${caseName}`, () => {
|
|
57
|
-
const src1 = readFixtureFile(INPUT_HTML_JSON_FILENAME);
|
|
58
|
-
const src2 = readFixtureFile(INPUT_JS_JSON_FILENAME);
|
|
59
|
-
const srcFileMap = {};
|
|
60
|
-
srcFileMap['test.js'] = readFixtureFile(INPUT_SRC_FILE_JSON_FILENAME);
|
|
61
|
-
srcFileMap['test.html'] = readFixtureFile(INPUT_SRC_FILE_HTML_FILENAME);
|
|
62
|
-
const komaciHTMLDoc = JSON.parse(src1);
|
|
63
|
-
const komaciJSDoc = JSON.parse(src2);
|
|
64
|
-
const actualModuleSrc = generateModuleSource(komaciHTMLDoc, komaciJSDoc, srcFileMap);
|
|
65
|
-
let expectedModuleSrc = readFixtureFile(EXPECTED_JS_FILENAME);
|
|
66
|
-
if (expectedModuleSrc == null) {
|
|
67
|
-
// write file if doesn't exist (ie new fixture)
|
|
68
|
-
expectedModuleSrc = actualModuleSrc;
|
|
69
|
-
writeFixtureFile(EXPECTED_JS_FILENAME, expectedModuleSrc);
|
|
70
|
-
}
|
|
71
|
-
// check that the actual newly generated mod source matches expected
|
|
72
|
-
expect(actualModuleSrc).toEqual(expectedModuleSrc);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
//# sourceMappingURL=komaci-bundle-module.fixtures.spec.js.map
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const glob_1 = require("glob");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const index_1 = require("../index");
|
|
10
|
-
const fs_2 = require("fs");
|
|
11
|
-
const path_2 = require("path");
|
|
12
|
-
const metadata_1 = require("@lwc/metadata");
|
|
13
|
-
const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-combined-files-multiple-templates');
|
|
14
|
-
const EXPECTED_JS_FILENAME = 'expected.src';
|
|
15
|
-
// eslint-disable-next-line jest/no-disabled-tests
|
|
16
|
-
describe('fixtures', () => {
|
|
17
|
-
// find all folder paths containing a directory called component. This gives us the flexability to name the parent directory
|
|
18
|
-
// either lightning for external comps and c for internal comps.
|
|
19
|
-
const fixtures = (0, glob_1.globSync)(path_1.default.resolve(FIXTURES_DIR, '**/*/component'));
|
|
20
|
-
for (const caseEntry of fixtures) {
|
|
21
|
-
const caseFolder = path_1.default.dirname(caseEntry);
|
|
22
|
-
const relativePath = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
23
|
-
const caseName = relativePath.split('/')[0];
|
|
24
|
-
const expectedSrcFilePath = () => {
|
|
25
|
-
return (caseFolder.slice(0, caseFolder.lastIndexOf('/')) +
|
|
26
|
-
'/' +
|
|
27
|
-
EXPECTED_JS_FILENAME);
|
|
28
|
-
};
|
|
29
|
-
const readFixtureFile = (filePath) => {
|
|
30
|
-
return fs_1.default.existsSync(filePath) ? fs_1.default.readFileSync(filePath, 'utf-8') : null;
|
|
31
|
-
};
|
|
32
|
-
const writeFixtureFile = (filePath, content) => {
|
|
33
|
-
fs_1.default.writeFileSync(filePath, content, { encoding: 'utf-8' });
|
|
34
|
-
};
|
|
35
|
-
it(`${caseName}`, () => {
|
|
36
|
-
const expectedFilePath = expectedSrcFilePath();
|
|
37
|
-
const actualModuleSrc = readAndParseBundle(caseEntry, {
|
|
38
|
-
enableKomaci: true,
|
|
39
|
-
type: 'internal',
|
|
40
|
-
}).output.modGenOutput;
|
|
41
|
-
let expectedModuleSrc = readFixtureFile(expectedFilePath);
|
|
42
|
-
if (expectedModuleSrc == null) {
|
|
43
|
-
// write file if doesn't exist (ie new fixture)
|
|
44
|
-
expectedModuleSrc = actualModuleSrc;
|
|
45
|
-
writeFixtureFile(expectedFilePath, expectedModuleSrc);
|
|
46
|
-
}
|
|
47
|
-
// check that the actual newly generated mod source matches expected
|
|
48
|
-
expect(actualModuleSrc).toEqual(expectedModuleSrc);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* Finds all .js, .mjs, .css, and .html files within the given directory, reads their contents, and combines them into a bundle,
|
|
54
|
-
* and returning the array of BundleFile containing the file's fileName and source
|
|
55
|
-
* @param path
|
|
56
|
-
* @returns An array of BundleFile
|
|
57
|
-
*/
|
|
58
|
-
function readBundle(path) {
|
|
59
|
-
path = (0, path_2.resolve)(path);
|
|
60
|
-
if ((0, fs_2.existsSync)(path)) {
|
|
61
|
-
const contents = (0, fs_2.readdirSync)(path);
|
|
62
|
-
const LWC_EXT = ['.js', '.mjs', '.css', '.html'];
|
|
63
|
-
const lwcBundleFiles = contents.filter((filename) => {
|
|
64
|
-
return LWC_EXT.includes((0, path_2.extname)(filename));
|
|
65
|
-
});
|
|
66
|
-
return lwcBundleFiles.map((fileName) => ({
|
|
67
|
-
fileName,
|
|
68
|
-
source: (0, fs_2.readFileSync)((0, path_2.resolve)(path, fileName), 'utf-8').toString(),
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new Error(`path doesn't exist: ${path}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Takes the directory path of an LWC module bundle and an optional set of config overrides. Returns the ParsedBundle, inlcuding
|
|
77
|
-
* the bundle's 1) LWC Metadata and 2) Komaci / Resolvable module.
|
|
78
|
-
* @param path
|
|
79
|
-
* @param configOverrides
|
|
80
|
-
* @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
|
|
81
|
-
*/
|
|
82
|
-
function readAndParseBundle(path, configOverrides) {
|
|
83
|
-
const files = readBundle(path);
|
|
84
|
-
const name = (0, path_2.basename)(path);
|
|
85
|
-
const namespace = (0, path_2.basename)((0, path_2.dirname)(path));
|
|
86
|
-
const bundleConfig = {
|
|
87
|
-
namespace,
|
|
88
|
-
name,
|
|
89
|
-
type: 'internal',
|
|
90
|
-
namespaceMapping: {},
|
|
91
|
-
files,
|
|
92
|
-
enableKomaci: true,
|
|
93
|
-
npmModuleMapping: {},
|
|
94
|
-
...configOverrides,
|
|
95
|
-
};
|
|
96
|
-
const metadata = (0, metadata_1.collectBundleMetadata)(bundleConfig);
|
|
97
|
-
// Create input to module generator.
|
|
98
|
-
const srcFileMap = files.reduce((map, { fileName, source }) => ({ ...map, [fileName]: source }), {});
|
|
99
|
-
const inputFiles = Object.fromEntries(metadata.files
|
|
100
|
-
.map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
|
|
101
|
-
.filter(([, komaciDoc]) => !!komaciDoc));
|
|
102
|
-
const generatorInput = {
|
|
103
|
-
moduleInfo: {
|
|
104
|
-
name,
|
|
105
|
-
namespace: bundleConfig.namespace,
|
|
106
|
-
type: 'bundle',
|
|
107
|
-
files: inputFiles,
|
|
108
|
-
},
|
|
109
|
-
srcFileMap,
|
|
110
|
-
};
|
|
111
|
-
const modGenOutput = (0, index_1.generateKomaciModule)(generatorInput);
|
|
112
|
-
return {
|
|
113
|
-
input: { bundleConfig, generatorInput },
|
|
114
|
-
output: { modGenOutput, metadata },
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=komaci-bundle-multiple-templates-module.fixtures.spec.js.map
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const glob_1 = require("glob");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const readAndParseBundle_1 = require("./readAndParseBundle");
|
|
10
|
-
const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-gql');
|
|
11
|
-
const EXPECTED_JS_FILENAME = 'expected.src';
|
|
12
|
-
// eslint-disable-next-line jest/no-disabled-tests
|
|
13
|
-
describe('fixtures', () => {
|
|
14
|
-
// find all folder paths containing a directory called component. This gives us the flexability to name the parent directory
|
|
15
|
-
// either lightning for external comps and c for internal comps.
|
|
16
|
-
const fixturePath = path_1.default.resolve(FIXTURES_DIR, '**/*/component');
|
|
17
|
-
const fixtures = (0, glob_1.globSync)(fixturePath);
|
|
18
|
-
for (const caseEntry of fixtures) {
|
|
19
|
-
const caseFolder = path_1.default.dirname(caseEntry);
|
|
20
|
-
const relativePath = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
21
|
-
const caseName = relativePath.split('/')[0];
|
|
22
|
-
const expectedSrcFilePath = () => {
|
|
23
|
-
return (caseFolder.slice(0, caseFolder.lastIndexOf('/')) +
|
|
24
|
-
'/' +
|
|
25
|
-
EXPECTED_JS_FILENAME);
|
|
26
|
-
};
|
|
27
|
-
const readFixtureFile = (filePath) => {
|
|
28
|
-
return fs_1.default.existsSync(filePath) ? fs_1.default.readFileSync(filePath, 'utf-8') : null;
|
|
29
|
-
};
|
|
30
|
-
const writeFixtureFile = (filePath, content) => {
|
|
31
|
-
fs_1.default.writeFileSync(filePath, content, { encoding: 'utf-8' });
|
|
32
|
-
};
|
|
33
|
-
it(`${caseName}`, () => {
|
|
34
|
-
const expectedFilePath = expectedSrcFilePath();
|
|
35
|
-
const actualModuleSrc = (0, readAndParseBundle_1.readAndParseBundle)(caseEntry, {
|
|
36
|
-
enableKomaci: true,
|
|
37
|
-
type: 'internal',
|
|
38
|
-
enableLuvio: true,
|
|
39
|
-
}).output.modGenOutput;
|
|
40
|
-
let expectedModuleSrc = readFixtureFile(expectedFilePath);
|
|
41
|
-
if (expectedModuleSrc == '') {
|
|
42
|
-
// write file if doesn't exist (ie new fixture)
|
|
43
|
-
expectedModuleSrc = actualModuleSrc;
|
|
44
|
-
writeFixtureFile(expectedFilePath, expectedModuleSrc);
|
|
45
|
-
}
|
|
46
|
-
// check that the actual newly generated mod source matches expected
|
|
47
|
-
expect(actualModuleSrc).toEqual(expectedModuleSrc);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=komaci-gql.fixtures.spec.js.map
|