lucy-cli 0.7.13 → 0.7.14

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.
@@ -17,62 +17,113 @@ export function updateWixTypes(options) {
17
17
  localModules = options.projectSettings.lucySettings.modules;
18
18
  }
19
19
  // Add module to publicSettings
20
+ publicSettings.compilerOptions.paths['backend/*.web'] = ["../../../typescript/backend/*.web.ts"];
21
+ publicSettings.compilerOptions.paths['backend/*.web.js'] = ["../../../typescript/backend/*.web.ts"];
22
+ publicSettings.compilerOptions.paths['backend/*.jsw'] = ["../../../typescript/backend/*.jsw.ts"];
20
23
  publicSettings.compilerOptions.paths.mocks = ["../../../typescript/__mocks__/*"];
21
24
  publicSettings.compilerOptions.paths['types/*'] = ["../../../typescript/types/*"];
22
25
  publicSettings.compilerOptions.paths['public/*'] = ["../../../typescript/public/*.ts"];
23
- publicSettings.include = ["../../../typescript/public/**/*", "../../../typescript/__mocks__/**/*", "../../../typescript/backend/**/*"];
26
+ publicSettings.include = [
27
+ "../../../typescript/public/**/*",
28
+ "../../../typescript/__mocks__/**/*",
29
+ ];
24
30
  // Add module to backendSettings
25
31
  backendSettings.compilerOptions.paths.mocks = ["../../../typescript/__mocks__/*"];
26
32
  backendSettings.compilerOptions.paths['types/*'] = [`../../../typescript/types/*`];
27
- backendSettings.include = ["../../../typescript/backend/**/*.web.js", "../../../typescript/__mocks__/**/*"];
33
+ backendSettings.include = [
34
+ "../../../typescript/backend/**/*",
35
+ "../../../typescript/__mocks__/**/*"
36
+ ];
28
37
  // Add module to masterSettings
38
+ masterSettings.compilerOptions.paths['backend/*.web'] = ["../../../typescript/backend/*.web.ts"];
39
+ masterSettings.compilerOptions.paths['backend/*.web.js'] = ["../../../typescript/backend/*.web.ts"];
40
+ masterSettings.compilerOptions.paths['backend/*.jsw'] = ["../../../typescript/backend/*.jsw.ts"];
29
41
  masterSettings.compilerOptions.paths['types/*'] = ["../../../typescript/types/*"];
30
- masterSettings.include = ["../../../typescript/public/**/*", "index.d.ts", "../../../typescript/__mocks__/**/*", "../../../typescript/backend/**/*"];
42
+ masterSettings.include = [
43
+ "../../../typescript/public/**/*",
44
+ "../../../typescript/__mocks__/**/*",
45
+ ];
31
46
  // Add module to pageSettings
47
+ pageSettings.compilerOptions.paths['backend/*.web'] = ["../../../typescript/backend/*.web.ts"];
48
+ pageSettings.compilerOptions.paths['backend/*.web.js'] = ["../../../typescript/backend/*.web.ts"];
49
+ pageSettings.compilerOptions.paths['backend/*.jsw'] = ["../../../typescript/backend/*.jsw.ts"];
32
50
  pageSettings.compilerOptions.paths['types/*'] = ["../../../typescript/types/*"];
33
- pageSettings.compilerOptions.paths['backend/*'] = ["../../../typescript/backend/*.jsw.ts"];
34
- pageSettings.include = ["../../../typescript/public/**/*", "../../../typescript/__mocks__/**/*", "../../../typescript/backend/**/*"];
51
+ pageSettings.compilerOptions.paths['backend/*.jsw'] = ["../../../typescript/backend/*.jsw.ts"];
52
+ pageSettings.include = [
53
+ "../../../typescript/public/**/*",
54
+ "../../../typescript/__mocks__/**/*",
55
+ ];
35
56
  if (modules) {
36
57
  for (const [name] of Object.entries(modules)) {
37
58
  // Add module to publicSettings
38
- publicSettings.compilerOptions.paths['backend/*.web.js'] = [`../../../${name}/backend/*.web.ts`];
39
- publicSettings.compilerOptions.paths['backend/*.web'] = [`../../../${name}/backend/*.web.ts`];
59
+ publicSettings.compilerOptions.paths['backend/*.web.js'].push(`../../../${name}/backend/*.web.ts`);
60
+ publicSettings.compilerOptions.paths['backend/*.web'].push(`../../../${name}/backend/*.web.ts`);
61
+ publicSettings.compilerOptions.paths['backend/*.jsw'].push(`../../../${name}/backend/*.jsw.ts`);
40
62
  publicSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*`);
41
63
  publicSettings.compilerOptions.paths.mocks.push(...[`../../../${name}/__mocks__/*`]);
42
64
  publicSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*`);
43
- publicSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*`]);
65
+ publicSettings.include.push(...[
66
+ `../../../${name}/public/**/*`,
67
+ `../../../${name}__mocks__/**/*`,
68
+ ]);
44
69
  // Add module to backendSettings
45
70
  backendSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*`);
46
71
  backendSettings.compilerOptions.paths['backend/*'].push(`../../../${name}/backend/*`);
47
72
  backendSettings.compilerOptions.paths.mocks.push(...[`../../../${name}/__mocks__/*`]);
48
73
  backendSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*`);
49
- backendSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*`, `../../../${name}/backend/**/*.web.ts`]);
74
+ backendSettings.include.push(...[
75
+ `../../../${name}/public/**/*`,
76
+ `../../../${name}__mocks__/**/*`,
77
+ `../../../${name}/backend/**/*`
78
+ ]);
50
79
  // Add module to masterSettings
51
- masterSettings.compilerOptions.paths['backend/*.web.js'] = [`../../../${name}/backend/*.web.ts`];
52
- masterSettings.compilerOptions.paths['backend/*.web'] = [`../../../${name}/backend/*.web.ts`];
80
+ masterSettings.compilerOptions.paths['backend/*.web.js'].push(`../../../${name}/backend/*.web.ts`);
81
+ masterSettings.compilerOptions.paths['backend/*.web'].push(`../../../${name}/backend/*.web.ts`);
82
+ masterSettings.compilerOptions.paths['backend/*.jsw'].push(`../../../${name}/backend/*.jsw.ts`);
53
83
  masterSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*`);
54
- masterSettings.compilerOptions.paths['backend/*'].push(`../../../${name}/backend/*`);
55
84
  masterSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*`);
56
- masterSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*`]);
85
+ masterSettings.include.push(...[
86
+ `../../../${name}/public/**/*`,
87
+ `../../../${name}__mocks__/**/*`,
88
+ ]);
57
89
  // Add module to pageSettings
58
- pageSettings.compilerOptions.paths['backend/*.web.js'] = [`../../../${name}/backend/*.web.ts`];
59
- pageSettings.compilerOptions.paths['backend/*.web'] = [`../../../${name}/backend/*.web.ts`];
90
+ pageSettings.compilerOptions.paths['backend/*.web.js'].push(`../../../${name}/backend/*.web.ts`);
91
+ pageSettings.compilerOptions.paths['backend/*.web'].push(`../../../${name}/backend/*.web.ts`);
92
+ pageSettings.compilerOptions.paths['backend/*.jsw'].push(`../../../${name}/backend/*.jsw.ts`);
60
93
  pageSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*`);
61
- pageSettings.compilerOptions.paths['backend/*'].push(`../../../${name}/backend/*.jsw.ts`);
62
94
  pageSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*`);
63
- pageSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*`]);
95
+ pageSettings.include.push(...[
96
+ `../../../${name}/public/**/*`,
97
+ `../../../${name}__mocks__/**/*`,
98
+ ]);
64
99
  }
65
100
  }
66
- return gulp.src(['./.wix/types/**/*.json', '!./.wix/types/wix-code-types/*.json'])
101
+ return gulp.src(['./.wix/types/**/*.json', '!./.wix/types/wix-code-types/**/*'])
67
102
  .pipe(flatmap(function (stream, file) {
68
103
  count++;
69
- if (file.dirname.endsWith('public'))
70
- return stream.pipe(jeditor(publicSettings)).pipe(jeditor((json) => processJson(json)));
71
- if (file.dirname.endsWith('backend'))
72
- return stream.pipe(jeditor(backendSettings)).pipe(jeditor((json) => processJson(json)));
73
- if (file.dirname.endsWith('masterPage'))
74
- return stream.pipe(jeditor(masterSettings)).pipe(jeditor((json) => processJson(json)));
75
- return stream.pipe(jeditor(pageSettings)).pipe(jeditor((json) => processJson(json)));
104
+ if (file.dirname.endsWith('public')) {
105
+ return stream.pipe(jeditor(publicSettings))
106
+ .pipe(jeditor((json) => cleanTsConfig(json)))
107
+ .pipe(jeditor((json) => processJson(json)))
108
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions));
109
+ }
110
+ if (file.dirname.endsWith('backend')) {
111
+ return stream.pipe(jeditor(backendSettings))
112
+ .pipe(jeditor((json) => cleanTsConfig(json)))
113
+ .pipe(jeditor((json) => processJson(json)));
114
+ }
115
+ ;
116
+ if (file.dirname.endsWith('masterPage')) {
117
+ return stream.pipe(jeditor(masterSettings))
118
+ .pipe(jeditor((json) => cleanTsConfig(json)))
119
+ .pipe(jeditor((json) => processJson(json)))
120
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions));
121
+ }
122
+ ;
123
+ return stream.pipe(jeditor(pageSettings))
124
+ .pipe(jeditor((json) => cleanTsConfig(json)))
125
+ .pipe(jeditor((json) => processJson(json)))
126
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions));
76
127
  }))
77
128
  .pipe(replace('masterPage.masterPage.js', 'masterPage.ts', replaceOptions))
78
129
  .pipe(replace('/src/', '/typescript/', replaceOptions))
@@ -157,18 +208,54 @@ function removeDuplicatesFromArray(arr) {
157
208
  }
158
209
  function processJson(obj) {
159
210
  if (Array.isArray(obj)) {
160
- return removeDuplicatesFromArray(obj);
211
+ // Process arrays and remove duplicate items
212
+ const uniqueArray = removeDuplicatesFromArray(obj);
213
+ return uniqueArray.length > 0 ? uniqueArray : undefined; // Remove empty arrays
161
214
  }
162
215
  else if (obj && typeof obj === 'object') {
216
+ // Process objects, ensuring keys are unique
163
217
  const result = {};
218
+ const seenKeys = new Set();
164
219
  for (const key in obj) {
165
220
  if (Object.prototype.hasOwnProperty.call(obj, key)) {
166
- result[key] = processJson(obj[key]);
221
+ if (!seenKeys.has(key)) {
222
+ const processedValue = processJson(obj[key]);
223
+ if (processedValue !== undefined) { // Remove keys with undefined values
224
+ seenKeys.add(key);
225
+ result[key] = processedValue;
226
+ }
227
+ }
167
228
  }
168
229
  }
169
- return result;
230
+ // If all keys were empty or undefined, return undefined
231
+ return Object.keys(result).length > 0 ? result : undefined;
170
232
  }
171
233
  else {
234
+ // Return primitive values as-is
172
235
  return obj;
173
236
  }
174
237
  }
238
+ function cleanTsConfig(json) {
239
+ // Process the paths object to remove duplicates
240
+ if (json.compilerOptions?.paths) {
241
+ for (const key in json.compilerOptions.paths) {
242
+ if (Array.isArray(json.compilerOptions.paths[key])) {
243
+ const uniquePaths = [...new Set(json.compilerOptions.paths[key])];
244
+ json.compilerOptions.paths[key] = uniquePaths.length > 0 ? uniquePaths : undefined;
245
+ }
246
+ }
247
+ }
248
+ // Process the include array to remove duplicates
249
+ if (Array.isArray(json.include)) {
250
+ const uniqueIncludes = [...new Set(json.include)];
251
+ json.include = uniqueIncludes.length > 0 ? uniqueIncludes : undefined;
252
+ }
253
+ // Remove empty or undefined fields
254
+ if (json.compilerOptions?.paths) {
255
+ json.compilerOptions.paths = Object.fromEntries(Object.entries(json.compilerOptions.paths).filter(([_, value]) => value !== undefined));
256
+ }
257
+ if (json.include?.length === 0) {
258
+ delete json.include;
259
+ }
260
+ return json;
261
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "lucy-cli",
4
- "version": "0.7.13",
4
+ "version": "0.7.14",
5
5
  "description": "Lucy Framework for WIX Studio Editor",
6
6
  "main": ".dist/index.js",
7
7
  "scripts": {
@@ -6,12 +6,12 @@
6
6
  "jsx": "react-jsx",
7
7
  "noEmit": false,
8
8
  "noUncheckedIndexedAccess": true,
9
- "lib": ["DOM"],
9
+ "lib": ["DOM", "ESNext"],
10
10
  "paths": {
11
11
  "backend/*.web.js": [],
12
12
  "backend/*.web": [],
13
+ "backend/*.jsw": [],
13
14
  "public/*": [],
14
- "backend/*": [],
15
15
  "wix-types/*": ["../wix-code-types/dist/types/*"],
16
16
  "types/*": []
17
17
  }
@@ -7,12 +7,12 @@
7
7
  "jsx": "react-jsx",
8
8
  "noEmit": false,
9
9
  "noUncheckedIndexedAccess": true,
10
- "lib": ["DOM", "es2015"],
10
+ "lib": ["DOM", "ESNext"],
11
11
  "paths": {
12
12
  "backend/*.web.js": [],
13
13
  "backend/*.web": [],
14
+ "backend/*.jsw": [],
14
15
  "public/*": [],
15
- "backend/*": [],
16
16
  "wix-types/*": ["../wix-code-types/dist/types/*"],
17
17
  "types/*": []
18
18
  }
@@ -6,10 +6,11 @@
6
6
  "strict": true,
7
7
  "jsx": "react-jsx",
8
8
  "strictNullChecks": true,
9
- "lib": ["DOM"],
9
+ "lib": ["DOM", "ESNext"],
10
10
  "paths": {
11
11
  "backend/*.web.js": [],
12
12
  "backend/*.web": [],
13
+ "backend/*.jsw": [],
13
14
  "mocks": [],
14
15
  "public/*": [],
15
16
  "types/*": [],
package/src/gulp/types.ts CHANGED
@@ -22,62 +22,115 @@ export function updateWixTypes(options: TaskOptions) {
22
22
  localModules = options.projectSettings.lucySettings.modules as unknown as Record<string, string>;
23
23
  }
24
24
  // Add module to publicSettings
25
+ publicSettings.compilerOptions.paths['backend/*.web'] = [ "../../../typescript/backend/*.web.ts" ] as never;
26
+ publicSettings.compilerOptions.paths['backend/*.web.js'] = [ "../../../typescript/backend/*.web.ts" ] as never;
27
+ publicSettings.compilerOptions.paths['backend/*.jsw'] = [ "../../../typescript/backend/*.jsw.ts" ] as never;
25
28
  publicSettings.compilerOptions.paths.mocks = [ "../../../typescript/__mocks__/*" ] as never;
26
29
  publicSettings.compilerOptions.paths['types/*'] = [ "../../../typescript/types/*" ] as never;
27
30
  publicSettings.compilerOptions.paths['public/*'] = [ "../../../typescript/public/*.ts" ] as never;
28
- publicSettings.include = [ "../../../typescript/public/**/*", "../../../typescript/__mocks__/**/*", "../../../typescript/backend/**/*" ] as never;
31
+ publicSettings.include = [
32
+ "../../../typescript/public/**/*",
33
+ "../../../typescript/__mocks__/**/*",
34
+ ] as never;
35
+
29
36
  // Add module to backendSettings
30
37
  backendSettings.compilerOptions.paths.mocks = [ "../../../typescript/__mocks__/*" ] as never;
31
38
  backendSettings.compilerOptions.paths['types/*'] = [ `../../../typescript/types/*` ] as never;
32
- backendSettings.include = [ "../../../typescript/backend/**/*.web.js", "../../../typescript/__mocks__/**/*" ] as never;
39
+ backendSettings.include = [
40
+ "../../../typescript/backend/**/*",
41
+ "../../../typescript/__mocks__/**/*"
42
+ ] as never;
33
43
  // Add module to masterSettings
44
+ masterSettings.compilerOptions.paths['backend/*.web'] = [ "../../../typescript/backend/*.web.ts" ] as never;
45
+ masterSettings.compilerOptions.paths['backend/*.web.js'] = [ "../../../typescript/backend/*.web.ts" ] as never;
46
+ masterSettings.compilerOptions.paths['backend/*.jsw'] = [ "../../../typescript/backend/*.jsw.ts" ] as never;
34
47
  masterSettings.compilerOptions.paths['types/*'] = [ "../../../typescript/types/*" ] as never;
35
- masterSettings.include = [ "../../../typescript/public/**/*", "index.d.ts", "../../../typescript/__mocks__/**/*", "../../../typescript/backend/**/*" ] as never;
48
+ masterSettings.include = [
49
+ "../../../typescript/public/**/*",
50
+ "../../../typescript/__mocks__/**/*",
51
+ ] as never;
36
52
  // Add module to pageSettings
53
+ pageSettings.compilerOptions.paths['backend/*.web'] = [ "../../../typescript/backend/*.web.ts" ] as never;
54
+ pageSettings.compilerOptions.paths['backend/*.web.js'] = [ "../../../typescript/backend/*.web.ts" ] as never;
55
+ pageSettings.compilerOptions.paths['backend/*.jsw'] = [ "../../../typescript/backend/*.jsw.ts" ] as never;
37
56
  pageSettings.compilerOptions.paths['types/*'] = [ "../../../typescript/types/*" ] as never;
38
- pageSettings.compilerOptions.paths['backend/*'] = [ "../../../typescript/backend/*.jsw.ts" ] as never;
39
- pageSettings.include = [ "../../../typescript/public/**/*", "../../../typescript/__mocks__/**/*", "../../../typescript/backend/**/*" ] as never;
57
+ pageSettings.compilerOptions.paths['backend/*.jsw'] = [ "../../../typescript/backend/*.jsw.ts" ] as never;
58
+ pageSettings.include = [
59
+ "../../../typescript/public/**/*",
60
+ "../../../typescript/__mocks__/**/*",
61
+ ] as never;
40
62
 
41
63
  if (modules) {
42
64
  for (const [name] of Object.entries(modules)) {
43
65
  // Add module to publicSettings
44
- publicSettings.compilerOptions.paths['backend/*.web.js'] = [`../../../${name}/backend/*.web.ts`] as never;
45
- publicSettings.compilerOptions.paths['backend/*.web'] = [`../../../${name}/backend/*.web.ts`] as never;
66
+ publicSettings.compilerOptions.paths['backend/*.web.js'].push(`../../../${name}/backend/*.web.ts` as never);
67
+ publicSettings.compilerOptions.paths['backend/*.web'].push(`../../../${name}/backend/*.web.ts` as never);
68
+ publicSettings.compilerOptions.paths['backend/*.jsw'].push(`../../../${name}/backend/*.jsw.ts` as never);
46
69
  publicSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*` as never);
47
70
  publicSettings.compilerOptions.paths.mocks.push(...[ `../../../${name}/__mocks__/*` as never ]);
48
71
  publicSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*` as never);
49
- publicSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*` ] as never[]);
72
+ publicSettings.include.push(...[
73
+ `../../../${name}/public/**/*`,
74
+ `../../../${name}__mocks__/**/*`,
75
+ ] as never[]);
50
76
  // Add module to backendSettings
51
77
  backendSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*` as never);
52
78
  backendSettings.compilerOptions.paths['backend/*'].push(`../../../${name}/backend/*` as never);
53
79
  backendSettings.compilerOptions.paths.mocks.push(...[ `../../../${name}/__mocks__/*` ] as never[]);
54
80
  backendSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*` as never);
55
- backendSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*`, `../../../${name}/backend/**/*.web.ts` ] as never[]);
81
+ backendSettings.include.push(...[
82
+ `../../../${name}/public/**/*`,
83
+ `../../../${name}__mocks__/**/*`,
84
+ `../../../${name}/backend/**/*`
85
+ ] as never[]);
56
86
  // Add module to masterSettings
57
- masterSettings.compilerOptions.paths['backend/*.web.js'] = [`../../../${name}/backend/*.web.ts`] as never;
58
- masterSettings.compilerOptions.paths['backend/*.web'] = [`../../../${name}/backend/*.web.ts`] as never;
87
+ masterSettings.compilerOptions.paths['backend/*.web.js'].push(`../../../${name}/backend/*.web.ts` as never);
88
+ masterSettings.compilerOptions.paths['backend/*.web'].push(`../../../${name}/backend/*.web.ts` as never);
89
+ masterSettings.compilerOptions.paths['backend/*.jsw'].push(`../../../${name}/backend/*.jsw.ts` as never);
59
90
  masterSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*` as never);
60
- masterSettings.compilerOptions.paths['backend/*'].push(`../../../${name}/backend/*` as never);
61
91
  masterSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*` as never);
62
- masterSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*` ] as never[]);
92
+ masterSettings.include.push(...[
93
+ `../../../${name}/public/**/*`,
94
+ `../../../${name}__mocks__/**/*`,
95
+ ] as never[]);
63
96
  // Add module to pageSettings
64
- pageSettings.compilerOptions.paths['backend/*.web.js'] = [`../../../${name}/backend/*.web.ts`] as never;
65
- pageSettings.compilerOptions.paths['backend/*.web'] = [`../../../${name}/backend/*.web.ts`] as never;
97
+ pageSettings.compilerOptions.paths['backend/*.web.js'].push(`../../../${name}/backend/*.web.ts` as never);
98
+ pageSettings.compilerOptions.paths['backend/*.web'].push(`../../../${name}/backend/*.web.ts` as never);
99
+ pageSettings.compilerOptions.paths['backend/*.jsw'].push(`../../../${name}/backend/*.jsw.ts` as never);
66
100
  pageSettings.compilerOptions.paths['public/*'].push(`../../../${name}/public/*` as never);
67
- pageSettings.compilerOptions.paths['backend/*'].push(`../../../${name}/backend/*.jsw.ts` as never);
68
101
  pageSettings.compilerOptions.paths['types/*'].push(`../../../${name}/types/*` as never);
69
- pageSettings.include.push(...[`../../../${name}/public/**/*`, `../../../${name}/backend/**/*.web.js`, `../../../${name}__mocks__/**/*`, `../../../${name}/backend/**/*` ] as never[]);
102
+ pageSettings.include.push(...[
103
+ `../../../${name}/public/**/*`,
104
+ `../../../${name}__mocks__/**/*`,
105
+ ] as never[]);
70
106
  }
71
107
  }
72
108
 
73
- return gulp.src(['./.wix/types/**/*.json', '!./.wix/types/wix-code-types/*.json'])
109
+ return gulp.src(['./.wix/types/**/*.json', '!./.wix/types/wix-code-types/**/*'])
74
110
  .pipe(flatmap(function(stream: NodeJS.ReadableStream, file: File) {
75
111
  count ++;
76
- if (file.dirname.endsWith('public')) return stream.pipe(jeditor(publicSettings)).pipe(jeditor((json: any) => processJson(json)));
77
- if (file.dirname.endsWith('backend')) return stream.pipe(jeditor(backendSettings)).pipe(jeditor((json: any) => processJson(json)));
78
- if (file.dirname.endsWith('masterPage')) return stream.pipe(jeditor(masterSettings)).pipe(jeditor((json: any) => processJson(json)));
112
+ if (file.dirname.endsWith('public')) {
113
+ return stream.pipe(jeditor(publicSettings))
114
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
115
+ .pipe(jeditor((json: any) => processJson(json)))
116
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions));
117
+ }
118
+ if (file.dirname.endsWith('backend')) {
119
+ return stream.pipe(jeditor(backendSettings))
120
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
121
+ .pipe(jeditor((json: any) => processJson(json)))
122
+ };
123
+ if (file.dirname.endsWith('masterPage')) {
124
+ return stream.pipe(jeditor(masterSettings))
125
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
126
+ .pipe(jeditor((json: any) => processJson(json)))
127
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
128
+ };
79
129
 
80
- return stream.pipe(jeditor(pageSettings)).pipe(jeditor((json: any) => processJson(json)));
130
+ return stream.pipe(jeditor(pageSettings))
131
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
132
+ .pipe(jeditor((json: any) => processJson(json)))
133
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions));
81
134
  }))
82
135
  .pipe(replace('masterPage.masterPage.js', 'masterPage.ts', replaceOptions))
83
136
  .pipe(replace('/src/', '/typescript/', replaceOptions))
@@ -141,51 +194,95 @@ export function addTypes(options: TaskOptions, done: gulp.TaskFunctionCallback):
141
194
  });
142
195
  };
143
196
 
144
-
145
197
  function makeHashable(obj: any): any {
146
- if (Array.isArray(obj)) {
147
- return obj.map(makeHashable);
148
- } else if (obj && typeof obj === 'object') {
149
- const sortedKeys = Object.keys(obj).sort();
150
- const result: any = {};
151
- for (const key of sortedKeys) {
152
- result[key] = makeHashable(obj[key]);
153
- }
154
- return result;
155
- } else {
156
- return obj;
157
- }
198
+ if (Array.isArray(obj)) {
199
+ return obj.map(makeHashable);
200
+ } else if (obj && typeof obj === 'object') {
201
+ const sortedKeys = Object.keys(obj).sort();
202
+ const result: any = {};
203
+ for (const key of sortedKeys) {
204
+ result[key] = makeHashable(obj[key]);
205
+ }
206
+ return result;
207
+ } else {
208
+ return obj;
209
+ }
158
210
  }
159
211
 
160
212
  function removeDuplicatesFromArray(arr: any[]): any[] {
161
- const seen = new Set<string>();
162
- const newArr: any[] = [];
213
+ const seen = new Set<string>();
214
+ const newArr: any[] = [];
163
215
 
164
- for (const item of arr) {
165
- const processedItem = processJson(item); // Recursively process the item
166
- const hashableItem = makeHashable(processedItem);
167
- const serializedItem = JSON.stringify(hashableItem);
216
+ for (const item of arr) {
217
+ const processedItem = processJson(item); // Recursively process the item
218
+ const hashableItem = makeHashable(processedItem);
219
+ const serializedItem = JSON.stringify(hashableItem);
168
220
 
169
- if (!seen.has(serializedItem)) {
170
- seen.add(serializedItem);
171
- newArr.push(processedItem);
172
- }
173
- }
174
- return newArr;
221
+ if (!seen.has(serializedItem)) {
222
+ seen.add(serializedItem);
223
+ newArr.push(processedItem);
224
+ }
225
+ }
226
+ return newArr;
175
227
  }
176
228
 
177
229
  function processJson(obj: any): any {
178
- if (Array.isArray(obj)) {
179
- return removeDuplicatesFromArray(obj);
180
- } else if (obj && typeof obj === 'object') {
181
- const result: any = {};
182
- for (const key in obj) {
183
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
184
- result[key] = processJson(obj[key]);
185
- }
186
- }
187
- return result;
188
- } else {
189
- return obj;
190
- }
230
+ if (Array.isArray(obj)) {
231
+ // Process arrays and remove duplicate items
232
+ const uniqueArray = removeDuplicatesFromArray(obj);
233
+ return uniqueArray.length > 0 ? uniqueArray : undefined; // Remove empty arrays
234
+ } else if (obj && typeof obj === 'object') {
235
+ // Process objects, ensuring keys are unique
236
+ const result: any = {};
237
+ const seenKeys = new Set<string>();
238
+
239
+ for (const key in obj) {
240
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
241
+ if (!seenKeys.has(key)) {
242
+ const processedValue = processJson(obj[key]);
243
+ if (processedValue !== undefined) { // Remove keys with undefined values
244
+ seenKeys.add(key);
245
+ result[key] = processedValue;
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ // If all keys were empty or undefined, return undefined
252
+ return Object.keys(result).length > 0 ? result : undefined;
253
+ } else {
254
+ // Return primitive values as-is
255
+ return obj;
256
+ }
257
+ }
258
+
259
+ function cleanTsConfig(json: any): any {
260
+ // Process the paths object to remove duplicates
261
+ if (json.compilerOptions?.paths) {
262
+ for (const key in json.compilerOptions.paths) {
263
+ if (Array.isArray(json.compilerOptions.paths[key])) {
264
+ const uniquePaths = [...new Set(json.compilerOptions.paths[key])];
265
+ json.compilerOptions.paths[key] = uniquePaths.length > 0 ? uniquePaths : undefined;
266
+ }
267
+ }
268
+ }
269
+
270
+ // Process the include array to remove duplicates
271
+ if (Array.isArray(json.include)) {
272
+ const uniqueIncludes = [...new Set(json.include)];
273
+ json.include = uniqueIncludes.length > 0 ? uniqueIncludes : undefined;
274
+ }
275
+
276
+ // Remove empty or undefined fields
277
+ if (json.compilerOptions?.paths) {
278
+ json.compilerOptions.paths = Object.fromEntries(
279
+ Object.entries(json.compilerOptions.paths).filter(([_, value]) => value !== undefined)
280
+ );
281
+ }
282
+
283
+ if (json.include?.length === 0) {
284
+ delete json.include;
285
+ }
286
+
287
+ return json;
191
288
  }
package/tsconfig.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "strictNullChecks": true,
18
18
  "noImplicitAny": true,
19
19
  "noImplicitReturns": true,
20
- "noUncheckedIndexedAccess": true,
20
+ "noUncheckedIndexedAccess": false,
21
21
  "noImplicitThis": false,
22
22
  "strictBindCallApply": false,
23
23
  "strictFunctionTypes": true,