@lwc/sfdc-compiler-utils 2.19.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/LICENSE.txt +21 -0
- package/dist/__tests__/namespace.spec.d.ts +1 -0
- package/dist/__tests__/namespace.spec.js +462 -0
- package/dist/__tests__/namespace.spec.js.map +1 -0
- package/dist/__tests__/no-explicit-namespace.spec.d.ts +1 -0
- package/dist/__tests__/no-explicit-namespace.spec.js +258 -0
- package/dist/__tests__/no-explicit-namespace.spec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/namespace-utils.d.ts +23 -0
- package/dist/namespace-utils.js +290 -0
- package/dist/namespace-utils.js.map +1 -0
- package/jest.config.js +6 -0
- package/package.json +15 -0
- package/src/__tests__/namespace.spec.ts +760 -0
- package/src/__tests__/no-explicit-namespace.spec.ts +350 -0
- package/src/index.ts +9 -0
- package/src/namespace-utils.ts +366 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { containsExplicitNamespace } from '../namespace-utils';
|
|
2
|
+
|
|
3
|
+
describe('disallow references with an explicit namespace', () => {
|
|
4
|
+
describe('negative cases', () => {
|
|
5
|
+
test('should throw when invocation is misconfigured', () => {
|
|
6
|
+
expect(() => containsExplicitNamespace(undefined as any, 'a', 'b')).toThrowError(
|
|
7
|
+
'Failed to check explicit namespace usage.' +
|
|
8
|
+
'Expected string values for "value", "type", and "explicitNamespace" ' +
|
|
9
|
+
'parameters, received "undefined," "a", "b".'
|
|
10
|
+
);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('should throw on processing unsupported reference type', () => {
|
|
14
|
+
expect(() => containsExplicitNamespace('label', 'bar', 'nsC')).toThrowError(
|
|
15
|
+
'Unsupported reference type bar'
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('reference types that do not have namespace', () => {
|
|
21
|
+
test('"client" type should return false', () => {
|
|
22
|
+
const actual = containsExplicitNamespace('formFactor', 'client', 'c');
|
|
23
|
+
expect(actual).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('"cssvars" type should return false', () => {
|
|
27
|
+
const actual = containsExplicitNamespace('customProperties', 'cssvars', 'c');
|
|
28
|
+
expect(actual).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('"i18n" type should return false', () => {
|
|
32
|
+
const actual = containsExplicitNamespace('id', 'i18n', 'c');
|
|
33
|
+
expect(actual).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('"slds" type should return false', () => {
|
|
37
|
+
const actual = containsExplicitNamespace('index.css', 'slds', 'c');
|
|
38
|
+
expect(actual).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('"user" type should return false', () => {
|
|
42
|
+
const actual = containsExplicitNamespace('id', 'user', 'c');
|
|
43
|
+
expect(actual).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
test('"userPermission" type should return false', () => {
|
|
46
|
+
const actual = containsExplicitNamespace('ViewSetup', 'userPermission', 'c');
|
|
47
|
+
expect(actual).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('"gate" type should return false', () => {
|
|
51
|
+
const actual = containsExplicitNamespace('foo.bar.gate.name', 'gate', 'c');
|
|
52
|
+
expect(actual).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('"metric" type should return false', () => {
|
|
56
|
+
const actual = containsExplicitNamespace('foo.bar.metric.name', 'metric', 'c');
|
|
57
|
+
expect(actual).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('"internal" type should return false', () => {
|
|
61
|
+
const actual = containsExplicitNamespace('id', 'internal', 'c');
|
|
62
|
+
expect(actual).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('explicit namespace in label', () => {
|
|
67
|
+
test('should return "false" when not using namespace and explicit value is "c"', () => {
|
|
68
|
+
const actual = containsExplicitNamespace('label', 'label', 'c');
|
|
69
|
+
expect(actual).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
73
|
+
const actual = containsExplicitNamespace('nsC.label', 'label', 'nsC');
|
|
74
|
+
expect(actual).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('should return "false" when explicit parameter value is "c" and the reference is explicit ', () => {
|
|
78
|
+
const actual = containsExplicitNamespace('nsC.label', 'label', 'c');
|
|
79
|
+
expect(actual).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('should return "false" when references value has default namespace', () => {
|
|
83
|
+
const actual = containsExplicitNamespace('c.label', 'label', 'nsC');
|
|
84
|
+
expect(actual).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should return "false" when not using namespace at all', () => {
|
|
88
|
+
const actual = containsExplicitNamespace('label', 'label', 'nsC');
|
|
89
|
+
expect(actual).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
93
|
+
const actual = containsExplicitNamespace('c.label', 'label', 'c');
|
|
94
|
+
expect(actual).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('explicit namespace in resourceUrl', () => {
|
|
99
|
+
test('should return "false" when not using namespace and explicit value is "c"', () => {
|
|
100
|
+
const actual = containsExplicitNamespace('resource', 'resourceUrl', 'c');
|
|
101
|
+
expect(actual).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
104
|
+
const actual = containsExplicitNamespace('nsC__resource', 'resourceUrl', 'nsC');
|
|
105
|
+
expect(actual).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('should return "false" when using default namespace in the reference', () => {
|
|
109
|
+
const actual = containsExplicitNamespace('c__resourceUrl', 'resourceUrl', 'nsC');
|
|
110
|
+
expect(actual).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('should return "false" when not using default namespace and reference is explicit', () => {
|
|
114
|
+
const actual = containsExplicitNamespace('resource', 'resourceUrl', 'nsC');
|
|
115
|
+
expect(actual).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('should return "false" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
119
|
+
const actual = containsExplicitNamespace('nsC__resourceUrl', 'resourceUrl', 'c');
|
|
120
|
+
expect(actual).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
124
|
+
const actual = containsExplicitNamespace('c__resourceUrl', 'resourceUrl', 'c');
|
|
125
|
+
expect(actual).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('explicit namespace in contentAssetUrl', () => {
|
|
130
|
+
test('should return "false" when not using namespace and explicit value is "c"', () => {
|
|
131
|
+
const actual = containsExplicitNamespace('asset', 'contentAssetUrl', 'c');
|
|
132
|
+
expect(actual).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
136
|
+
const actual = containsExplicitNamespace('nsC__asset', 'contentAssetUrl', 'nsC');
|
|
137
|
+
expect(actual).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('should return "false" when using default namespace in the reference', () => {
|
|
141
|
+
const actual = containsExplicitNamespace('c__asset', 'contentAssetUrl', 'nsC');
|
|
142
|
+
expect(actual).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('should return "false" when not using default namespace and reference is explicit', () => {
|
|
146
|
+
const actual = containsExplicitNamespace('asset', 'contentAssetUrl', 'nsC');
|
|
147
|
+
expect(actual).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('should return "true" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
151
|
+
const actual = containsExplicitNamespace('nsC__asset', 'contentAssetUrl', 'c');
|
|
152
|
+
expect(actual).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
156
|
+
const actual = containsExplicitNamespace('c__asset', 'contentAssetUrl', 'c');
|
|
157
|
+
expect(actual).toBe(false);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('explicit namespace in customPermission', () => {
|
|
162
|
+
test('should return "false" when not using namespace and explicit value is "c"', () => {
|
|
163
|
+
const actual = containsExplicitNamespace('perm', 'customPermission', 'c');
|
|
164
|
+
expect(actual).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
167
|
+
const actual = containsExplicitNamespace(
|
|
168
|
+
'nsC__customPermission',
|
|
169
|
+
'customPermission',
|
|
170
|
+
'nsC'
|
|
171
|
+
);
|
|
172
|
+
expect(actual).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('should return "false" when using default namespace in the reference', () => {
|
|
176
|
+
const actual = containsExplicitNamespace(
|
|
177
|
+
'c__customPermission',
|
|
178
|
+
'customPermission',
|
|
179
|
+
'nsC'
|
|
180
|
+
);
|
|
181
|
+
expect(actual).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('should return "false" when not using default namespace and reference is explicit', () => {
|
|
185
|
+
const actual = containsExplicitNamespace('perm', 'customPermission', 'nsC');
|
|
186
|
+
expect(actual).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('should return "false" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
190
|
+
const actual = containsExplicitNamespace(
|
|
191
|
+
'nsC__customPermission',
|
|
192
|
+
'customPermission',
|
|
193
|
+
'c'
|
|
194
|
+
);
|
|
195
|
+
expect(actual).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
199
|
+
const actual = containsExplicitNamespace(
|
|
200
|
+
'c__customPermission',
|
|
201
|
+
'customPermission',
|
|
202
|
+
'c'
|
|
203
|
+
);
|
|
204
|
+
expect(actual).toBe(false);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('explicit namespace in apexMethod', () => {
|
|
209
|
+
test('should return "false" when not using namespace and explicit value is "c"', () => {
|
|
210
|
+
const actual = containsExplicitNamespace('MyClass.methodA', 'apexMethod', 'c');
|
|
211
|
+
expect(actual).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
215
|
+
const actual = containsExplicitNamespace('nsC.MyClass.methodA', 'apexMethod', 'nsC');
|
|
216
|
+
expect(actual).toBe(true);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('should return "false" when using default namespace in the reference', () => {
|
|
220
|
+
const actual = containsExplicitNamespace('c.MyClass.methodA', 'apexMethod', 'nsC');
|
|
221
|
+
expect(actual).toBe(false);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('should return "false" when not using namespace at all', () => {
|
|
225
|
+
const actual = containsExplicitNamespace('MyClass.methodA', 'apexMethod', 'nsC');
|
|
226
|
+
expect(actual).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('should return "false" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
230
|
+
const actual = containsExplicitNamespace('nsC.MyClass.methodA', 'apexMethod', 'c');
|
|
231
|
+
expect(actual).toBe(false);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
235
|
+
const actual = containsExplicitNamespace('c.MyClass.methodA', 'apexMethod', 'c');
|
|
236
|
+
expect(actual).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe('explicit namespace in schema', () => {
|
|
241
|
+
test('should return "false" when not using namespace and explicit value is "c"', () => {
|
|
242
|
+
const actual = containsExplicitNamespace('CustomObject__c', 'schema', 'c');
|
|
243
|
+
expect(actual).toBe(false);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
247
|
+
const actual = containsExplicitNamespace(
|
|
248
|
+
'nsC__CustomObject__c.nsC__parentContact__r.Account.Name',
|
|
249
|
+
'schema',
|
|
250
|
+
'nsC'
|
|
251
|
+
);
|
|
252
|
+
expect(actual).toBe(true);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('should return "false" when references value has default namespace', () => {
|
|
256
|
+
const actual = containsExplicitNamespace(
|
|
257
|
+
'c__CustomObject__c.c__parentContact__r.Account.Name',
|
|
258
|
+
'schema',
|
|
259
|
+
'nsC'
|
|
260
|
+
);
|
|
261
|
+
expect(actual).toBe(false);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('should return "true" when using mixed resource contains explicit namespace', () => {
|
|
265
|
+
const actual = containsExplicitNamespace(
|
|
266
|
+
'c__CustomObject__c.nsC__parentContact__r.Account.Name',
|
|
267
|
+
'schema',
|
|
268
|
+
'nsC'
|
|
269
|
+
);
|
|
270
|
+
expect(actual).toBe(true);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('should return "false" when not using namespace at all', () => {
|
|
274
|
+
const actual = containsExplicitNamespace('MyClass.methodA', 'schema', 'nsC');
|
|
275
|
+
expect(actual).toBe(false);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('should return "false" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
279
|
+
const actual = containsExplicitNamespace(
|
|
280
|
+
'nsC__CustomObject__c.nsC__parentContact__r.Account.Name',
|
|
281
|
+
'schema',
|
|
282
|
+
'c'
|
|
283
|
+
);
|
|
284
|
+
expect(actual).toBe(false);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
288
|
+
const actual = containsExplicitNamespace(
|
|
289
|
+
'c__CustomObject__c.nsC__parentContact__r.Account.Name',
|
|
290
|
+
'schema',
|
|
291
|
+
'c'
|
|
292
|
+
);
|
|
293
|
+
expect(actual).toBe(false);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe('explicit namespace in module', () => {
|
|
298
|
+
test('should return "true" when not using default namespace and reference is explicit', () => {
|
|
299
|
+
const actual = containsExplicitNamespace('nsC/utils', 'module', 'nsC');
|
|
300
|
+
expect(actual).toBe(true);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('should return "false" when references value has default namespace', () => {
|
|
304
|
+
const actual = containsExplicitNamespace('c/utils', 'module', 'nsC');
|
|
305
|
+
expect(actual).toBe(false);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('should return "false" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
309
|
+
const actual = containsExplicitNamespace('nsC/utils', 'module', 'c');
|
|
310
|
+
expect(actual).toBe(false);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
314
|
+
const actual = containsExplicitNamespace('c/utils', 'module', 'c');
|
|
315
|
+
expect(actual).toBe(false);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('should return "false" when module does not have namespace and explicit value is "c"', () => {
|
|
319
|
+
const actual = containsExplicitNamespace('lwc', 'module', 'c');
|
|
320
|
+
expect(actual).toBe(false);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe('explicit namespace in component', () => {
|
|
325
|
+
test('should return "true" when using explicit namespace', () => {
|
|
326
|
+
const actual = containsExplicitNamespace('explicit-child-tag', 'component', 'explicit');
|
|
327
|
+
expect(actual).toBe(true);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('should return "true" when using camel-cased namespace', () => {
|
|
331
|
+
const actual = containsExplicitNamespace('nsc-child-tag', 'component', 'nsC');
|
|
332
|
+
expect(actual).toBe(true);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('should return "false" when using default namespace in the reference', () => {
|
|
336
|
+
const actual = containsExplicitNamespace('c-child-tag', 'component', 'nsC');
|
|
337
|
+
expect(actual).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('should return "false" when explicit parameter value is "c" but the reference is explicit ', () => {
|
|
341
|
+
const actual = containsExplicitNamespace('explicit-child-tag', 'component', 'c');
|
|
342
|
+
expect(actual).toBe(false);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test('should return "false" when both explicit namespace and reference use "c"', () => {
|
|
346
|
+
const actual = containsExplicitNamespace('c-child-tag', 'component', 'c');
|
|
347
|
+
expect(actual).toBe(false);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
package/src/index.ts
ADDED