@komaci/esm-generator 242.1.9 → 242.2.1
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/__tests__/index.spec.js +153 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +41 -1
- package/package.json +4 -4
|
@@ -137,4 +137,157 @@ describe('Handling errors that throw inside a call to generateKomaciModule', ()
|
|
|
137
137
|
expect(skipStackEnd).toBe(expectedModuleSecondHalf);
|
|
138
138
|
});
|
|
139
139
|
});
|
|
140
|
+
describe('normalizeSrcFileKeys', () => {
|
|
141
|
+
it('should properly normalize keys that are full filePaths', () => {
|
|
142
|
+
const bundleSrcFileMap = {
|
|
143
|
+
'c/test/test.js': {},
|
|
144
|
+
'c/test/test.css': {},
|
|
145
|
+
'c/test/test.html': {},
|
|
146
|
+
};
|
|
147
|
+
const input = {
|
|
148
|
+
moduleInfo: {
|
|
149
|
+
name: 'test',
|
|
150
|
+
namespace: 'c',
|
|
151
|
+
type: 'bundle',
|
|
152
|
+
files: bundleSrcFileMap,
|
|
153
|
+
},
|
|
154
|
+
srcFileMap: {
|
|
155
|
+
'c/test/test.js': '',
|
|
156
|
+
'c/test/test.css': 'p { text-align: center; }',
|
|
157
|
+
'c/test/test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
(0, __1.normalizeSrcFileKeys)(input);
|
|
161
|
+
expect(input.moduleInfo.files['test.js']).not.toBeUndefined();
|
|
162
|
+
expect(input.moduleInfo.files['test.css']).not.toBeUndefined();
|
|
163
|
+
expect(input.moduleInfo.files['test.html']).not.toBeUndefined();
|
|
164
|
+
expect(input.srcFileMap['test.js']).not.toBeUndefined();
|
|
165
|
+
expect(input.srcFileMap['test.css']).not.toBeUndefined();
|
|
166
|
+
expect(input.srcFileMap['test.html']).not.toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
it('should properly normalize keys that are full filePaths with sub dirs', () => {
|
|
169
|
+
const bundleSrcFileMap = {
|
|
170
|
+
'c/test/test.js': {},
|
|
171
|
+
'c/test/test.css': {},
|
|
172
|
+
'c/test/test.html': {},
|
|
173
|
+
'c/test/templates/test2.html': {},
|
|
174
|
+
};
|
|
175
|
+
const input = {
|
|
176
|
+
moduleInfo: {
|
|
177
|
+
name: 'test',
|
|
178
|
+
namespace: 'c',
|
|
179
|
+
type: 'bundle',
|
|
180
|
+
files: bundleSrcFileMap,
|
|
181
|
+
},
|
|
182
|
+
srcFileMap: {
|
|
183
|
+
'c/test/test.js': '',
|
|
184
|
+
'c/test/test.css': 'p { text-align: center; }',
|
|
185
|
+
'c/test/test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
186
|
+
'c/test/templates/test2.html': '<html><body><h1>Hey</h1></body></html>',
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
(0, __1.normalizeSrcFileKeys)(input);
|
|
190
|
+
expect(input.moduleInfo.files['test.js']).not.toBeUndefined();
|
|
191
|
+
expect(input.moduleInfo.files['test.css']).not.toBeUndefined();
|
|
192
|
+
expect(input.moduleInfo.files['test.html']).not.toBeUndefined();
|
|
193
|
+
expect(input.srcFileMap['test.js']).not.toBeUndefined();
|
|
194
|
+
expect(input.srcFileMap['test.css']).not.toBeUndefined();
|
|
195
|
+
expect(input.srcFileMap['test.html']).not.toBeUndefined();
|
|
196
|
+
});
|
|
197
|
+
it('keys stay same when passed in by fileName', () => {
|
|
198
|
+
const bundleSrcFileMap = {
|
|
199
|
+
'test.js': {},
|
|
200
|
+
'test.css': {},
|
|
201
|
+
'test.html': {},
|
|
202
|
+
};
|
|
203
|
+
const input = {
|
|
204
|
+
moduleInfo: {
|
|
205
|
+
name: 'test',
|
|
206
|
+
namespace: 'c',
|
|
207
|
+
type: 'bundle',
|
|
208
|
+
files: bundleSrcFileMap,
|
|
209
|
+
},
|
|
210
|
+
srcFileMap: {
|
|
211
|
+
'test.js': '',
|
|
212
|
+
'test.css': 'p { text-align: center; }',
|
|
213
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
(0, __1.normalizeSrcFileKeys)(input);
|
|
217
|
+
expect(input.moduleInfo.files['test.js']).not.toBeUndefined();
|
|
218
|
+
expect(input.moduleInfo.files['test.css']).not.toBeUndefined();
|
|
219
|
+
expect(input.moduleInfo.files['test.html']).not.toBeUndefined();
|
|
220
|
+
expect(input.srcFileMap['test.js']).not.toBeUndefined();
|
|
221
|
+
expect(input.srcFileMap['test.css']).not.toBeUndefined();
|
|
222
|
+
expect(input.srcFileMap['test.html']).not.toBeUndefined();
|
|
223
|
+
});
|
|
224
|
+
it('keys stay same for single html file', () => {
|
|
225
|
+
const bundleSrcFileMap = {
|
|
226
|
+
'test.html': {},
|
|
227
|
+
};
|
|
228
|
+
const input = {
|
|
229
|
+
moduleInfo: {
|
|
230
|
+
name: 'test',
|
|
231
|
+
namespace: 'c',
|
|
232
|
+
type: 'bundle',
|
|
233
|
+
files: bundleSrcFileMap,
|
|
234
|
+
},
|
|
235
|
+
srcFileMap: {
|
|
236
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
(0, __1.normalizeSrcFileKeys)(input);
|
|
240
|
+
expect(input.moduleInfo.files['test.html']).not.toBeUndefined();
|
|
241
|
+
expect(input.srcFileMap['test.html']).not.toBeUndefined();
|
|
242
|
+
});
|
|
243
|
+
it('key is normalized when full path is provided', () => {
|
|
244
|
+
const bundleSrcFileMap = {
|
|
245
|
+
'c/test/test.html': {},
|
|
246
|
+
};
|
|
247
|
+
const input = {
|
|
248
|
+
moduleInfo: {
|
|
249
|
+
name: 'test',
|
|
250
|
+
namespace: 'c',
|
|
251
|
+
type: 'bundle',
|
|
252
|
+
files: bundleSrcFileMap,
|
|
253
|
+
},
|
|
254
|
+
srcFileMap: {
|
|
255
|
+
'c/test/test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
(0, __1.normalizeSrcFileKeys)(input);
|
|
259
|
+
expect(input.moduleInfo.files['test.html']).not.toBeUndefined();
|
|
260
|
+
expect(input.srcFileMap['test.html']).not.toBeUndefined();
|
|
261
|
+
});
|
|
262
|
+
it('No keys change, with subDir included', () => {
|
|
263
|
+
const bundleSrcFileMap = {
|
|
264
|
+
'test.js': {},
|
|
265
|
+
'test.css': {},
|
|
266
|
+
'test.html': {},
|
|
267
|
+
'templates/test2.html': {},
|
|
268
|
+
};
|
|
269
|
+
const input = {
|
|
270
|
+
moduleInfo: {
|
|
271
|
+
name: 'test',
|
|
272
|
+
namespace: 'c',
|
|
273
|
+
type: 'bundle',
|
|
274
|
+
files: bundleSrcFileMap,
|
|
275
|
+
},
|
|
276
|
+
srcFileMap: {
|
|
277
|
+
'test.js': '',
|
|
278
|
+
'test.css': 'p { text-align: center; }',
|
|
279
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
280
|
+
'templates/test2.html': '<html><body><h1>Hey</h1></body></html>',
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
(0, __1.normalizeSrcFileKeys)(input);
|
|
284
|
+
expect(input.moduleInfo.files['test.js']).not.toBeUndefined();
|
|
285
|
+
expect(input.moduleInfo.files['test.css']).not.toBeUndefined();
|
|
286
|
+
expect(input.moduleInfo.files['test.html']).not.toBeUndefined();
|
|
287
|
+
expect(input.srcFileMap['test.js']).not.toBeUndefined();
|
|
288
|
+
expect(input.srcFileMap['test.css']).not.toBeUndefined();
|
|
289
|
+
expect(input.srcFileMap['test.html']).not.toBeUndefined();
|
|
290
|
+
expect(input.srcFileMap['templates/test2.html']).not.toBeUndefined();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
140
293
|
//# sourceMappingURL=index.spec.js.map
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { GeneratorInput } from './types';
|
|
2
2
|
export { GeneratorInput } from './types';
|
|
3
3
|
export declare function generateKomaciModule(input: GeneratorInput): string;
|
|
4
|
+
/**
|
|
5
|
+
* Function to normalize map keys if input is passed in as full filePaths.
|
|
6
|
+
* @param input the generator input.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeSrcFileKeys(input: GeneratorInput): void;
|
|
4
9
|
/**
|
|
5
10
|
* Helper function to process and build the resolvable module based off the generator input and inital generator state.
|
|
6
11
|
* @param input the Generator input
|
package/build/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.processGeneratorInputAndState = exports.generateKomaciModule = void 0;
|
|
29
|
+
exports.processGeneratorInputAndState = exports.normalizeSrcFileKeys = exports.generateKomaciModule = void 0;
|
|
30
30
|
const generator_1 = __importDefault(require("@babel/generator"));
|
|
31
31
|
const componentAstProcessing_1 = require("./componentAstProcessing");
|
|
32
32
|
const functionAstGeneration_1 = require("./functionAstGeneration");
|
|
@@ -47,12 +47,52 @@ function generateKomaciModule(input) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.generateKomaciModule = generateKomaciModule;
|
|
50
|
+
/**
|
|
51
|
+
* Function to normalize map keys if input is passed in as full filePaths.
|
|
52
|
+
* @param input the generator input.
|
|
53
|
+
*/
|
|
54
|
+
function normalizeSrcFileKeys(input) {
|
|
55
|
+
const componentBasePath = input.moduleInfo.namespace + '/' + input.moduleInfo.name;
|
|
56
|
+
if (input.moduleInfo.type === 'bundle') {
|
|
57
|
+
const fileMap = input.moduleInfo.files;
|
|
58
|
+
const fileMapEntries = Object.keys(fileMap);
|
|
59
|
+
for (const fullFilename of fileMapEntries) {
|
|
60
|
+
if (fullFilename.includes(componentBasePath)) {
|
|
61
|
+
const index = fullFilename.indexOf(componentBasePath) +
|
|
62
|
+
componentBasePath.length +
|
|
63
|
+
1;
|
|
64
|
+
const normalizedPath = fullFilename.substring(index);
|
|
65
|
+
fileMap[normalizedPath] = fileMap[fullFilename];
|
|
66
|
+
delete fileMap[fullFilename];
|
|
67
|
+
if (input.srcFileMap) {
|
|
68
|
+
input.srcFileMap[normalizedPath] = input.srcFileMap[fullFilename];
|
|
69
|
+
delete input.srcFileMap[fullFilename];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (input.moduleInfo.type === 'file') {
|
|
75
|
+
const fileInfo = input.moduleInfo;
|
|
76
|
+
const fileName = fileInfo.fileName;
|
|
77
|
+
if (fileName.includes(componentBasePath)) {
|
|
78
|
+
const index = fileName.indexOf(componentBasePath) + componentBasePath.length + 1;
|
|
79
|
+
const normalizedPath = fileName.substring(index);
|
|
80
|
+
fileInfo.fileName = normalizedPath;
|
|
81
|
+
if (input.srcFileMap) {
|
|
82
|
+
input.srcFileMap[normalizedPath] = input.srcFileMap[fileName];
|
|
83
|
+
delete input.srcFileMap[fileName];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.normalizeSrcFileKeys = normalizeSrcFileKeys;
|
|
50
89
|
/**
|
|
51
90
|
* Helper function to process and build the resolvable module based off the generator input and inital generator state.
|
|
52
91
|
* @param input the Generator input
|
|
53
92
|
* @returns the resolvable module.
|
|
54
93
|
*/
|
|
55
94
|
function processGeneratorInputAndState(input) {
|
|
95
|
+
normalizeSrcFileKeys(input);
|
|
56
96
|
if (input.moduleInfo.type === 'file') {
|
|
57
97
|
// Determine file type based on extension in file name.
|
|
58
98
|
const segments = (0, common_shared_1.getFilepathSegments)(input.moduleInfo.fileName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/esm-generator",
|
|
3
|
-
"version": "242.1
|
|
3
|
+
"version": "242.2.1",
|
|
4
4
|
"description": "Komaci generator for ADG ES modules",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/core": "^7.9.0",
|
|
30
30
|
"@babel/generator": "^7.9.0",
|
|
31
|
-
"@komaci/common-shared": "242.1
|
|
32
|
-
"@komaci/static-analyzer": "242.1
|
|
31
|
+
"@komaci/common-shared": "242.2.1",
|
|
32
|
+
"@komaci/static-analyzer": "242.2.1",
|
|
33
33
|
"o11y": "^240.7.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/types": "^7.9.0",
|
|
37
|
-
"@komaci/types": "242.1
|
|
37
|
+
"@komaci/types": "242.2.1",
|
|
38
38
|
"@lwc-platform/sfdc-lwc-compiler": "^2.18.0-240.2"
|
|
39
39
|
}
|
|
40
40
|
}
|