lucy-cli 0.7.13 → 0.7.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,62 +17,116 @@ 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
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
110
+ }
111
+ if (file.dirname.endsWith('backend')) {
112
+ return stream.pipe(jeditor(backendSettings))
113
+ .pipe(jeditor((json) => cleanTsConfig(json)))
114
+ .pipe(jeditor((json) => processJson(json)));
115
+ }
116
+ ;
117
+ if (file.dirname.endsWith('masterPage')) {
118
+ return stream.pipe(jeditor(masterSettings))
119
+ .pipe(jeditor((json) => cleanTsConfig(json)))
120
+ .pipe(jeditor((json) => processJson(json)))
121
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
122
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
123
+ }
124
+ ;
125
+ return stream.pipe(jeditor(pageSettings))
126
+ .pipe(jeditor((json) => cleanTsConfig(json)))
127
+ .pipe(jeditor((json) => processJson(json)))
128
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
129
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
76
130
  }))
77
131
  .pipe(replace('masterPage.masterPage.js', 'masterPage.ts', replaceOptions))
78
132
  .pipe(replace('/src/', '/typescript/', replaceOptions))
@@ -157,18 +211,54 @@ function removeDuplicatesFromArray(arr) {
157
211
  }
158
212
  function processJson(obj) {
159
213
  if (Array.isArray(obj)) {
160
- return removeDuplicatesFromArray(obj);
214
+ // Process arrays and remove duplicate items
215
+ const uniqueArray = removeDuplicatesFromArray(obj);
216
+ return uniqueArray.length > 0 ? uniqueArray : undefined; // Remove empty arrays
161
217
  }
162
218
  else if (obj && typeof obj === 'object') {
219
+ // Process objects, ensuring keys are unique
163
220
  const result = {};
221
+ const seenKeys = new Set();
164
222
  for (const key in obj) {
165
223
  if (Object.prototype.hasOwnProperty.call(obj, key)) {
166
- result[key] = processJson(obj[key]);
224
+ if (!seenKeys.has(key)) {
225
+ const processedValue = processJson(obj[key]);
226
+ if (processedValue !== undefined) { // Remove keys with undefined values
227
+ seenKeys.add(key);
228
+ result[key] = processedValue;
229
+ }
230
+ }
167
231
  }
168
232
  }
169
- return result;
233
+ // If all keys were empty or undefined, return undefined
234
+ return Object.keys(result).length > 0 ? result : undefined;
170
235
  }
171
236
  else {
237
+ // Return primitive values as-is
172
238
  return obj;
173
239
  }
174
240
  }
241
+ function cleanTsConfig(json) {
242
+ // Process the paths object to remove duplicates
243
+ if (json.compilerOptions?.paths) {
244
+ for (const key in json.compilerOptions.paths) {
245
+ if (Array.isArray(json.compilerOptions.paths[key])) {
246
+ const uniquePaths = [...new Set(json.compilerOptions.paths[key])];
247
+ json.compilerOptions.paths[key] = uniquePaths.length > 0 ? uniquePaths : undefined;
248
+ }
249
+ }
250
+ }
251
+ // Process the include array to remove duplicates
252
+ if (Array.isArray(json.include)) {
253
+ const uniqueIncludes = [...new Set(json.include)];
254
+ json.include = uniqueIncludes.length > 0 ? uniqueIncludes : undefined;
255
+ }
256
+ // Remove empty or undefined fields
257
+ if (json.compilerOptions?.paths) {
258
+ json.compilerOptions.paths = Object.fromEntries(Object.entries(json.compilerOptions.paths).filter(([_, value]) => value !== undefined));
259
+ }
260
+ if (json.include?.length === 0) {
261
+ delete json.include;
262
+ }
263
+ return json;
264
+ }
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.15",
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,118 @@ 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
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
118
+ }
119
+ if (file.dirname.endsWith('backend')) {
120
+ return stream.pipe(jeditor(backendSettings))
121
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
122
+ .pipe(jeditor((json: any) => processJson(json)))
123
+ };
124
+ if (file.dirname.endsWith('masterPage')) {
125
+ return stream.pipe(jeditor(masterSettings))
126
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
127
+ .pipe(jeditor((json: any) => processJson(json)))
128
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
129
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
130
+ };
79
131
 
80
- return stream.pipe(jeditor(pageSettings)).pipe(jeditor((json: any) => processJson(json)));
132
+ return stream.pipe(jeditor(pageSettings))
133
+ .pipe(jeditor((json: any) => cleanTsConfig(json)))
134
+ .pipe(jeditor((json: any) => processJson(json)))
135
+ .pipe(replace('"../backend.d.ts",', '', replaceOptions))
136
+ .pipe(replace('"../../../src/backend/\\*\\*/\\*.web.js",', '', replaceOptions));
81
137
  }))
82
138
  .pipe(replace('masterPage.masterPage.js', 'masterPage.ts', replaceOptions))
83
139
  .pipe(replace('/src/', '/typescript/', replaceOptions))
@@ -141,51 +197,95 @@ export function addTypes(options: TaskOptions, done: gulp.TaskFunctionCallback):
141
197
  });
142
198
  };
143
199
 
144
-
145
200
  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
- }
201
+ if (Array.isArray(obj)) {
202
+ return obj.map(makeHashable);
203
+ } else if (obj && typeof obj === 'object') {
204
+ const sortedKeys = Object.keys(obj).sort();
205
+ const result: any = {};
206
+ for (const key of sortedKeys) {
207
+ result[key] = makeHashable(obj[key]);
208
+ }
209
+ return result;
210
+ } else {
211
+ return obj;
212
+ }
158
213
  }
159
214
 
160
215
  function removeDuplicatesFromArray(arr: any[]): any[] {
161
- const seen = new Set<string>();
162
- const newArr: any[] = [];
216
+ const seen = new Set<string>();
217
+ const newArr: any[] = [];
163
218
 
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);
219
+ for (const item of arr) {
220
+ const processedItem = processJson(item); // Recursively process the item
221
+ const hashableItem = makeHashable(processedItem);
222
+ const serializedItem = JSON.stringify(hashableItem);
168
223
 
169
- if (!seen.has(serializedItem)) {
170
- seen.add(serializedItem);
171
- newArr.push(processedItem);
172
- }
173
- }
174
- return newArr;
224
+ if (!seen.has(serializedItem)) {
225
+ seen.add(serializedItem);
226
+ newArr.push(processedItem);
227
+ }
228
+ }
229
+ return newArr;
175
230
  }
176
231
 
177
232
  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
- }
233
+ if (Array.isArray(obj)) {
234
+ // Process arrays and remove duplicate items
235
+ const uniqueArray = removeDuplicatesFromArray(obj);
236
+ return uniqueArray.length > 0 ? uniqueArray : undefined; // Remove empty arrays
237
+ } else if (obj && typeof obj === 'object') {
238
+ // Process objects, ensuring keys are unique
239
+ const result: any = {};
240
+ const seenKeys = new Set<string>();
241
+
242
+ for (const key in obj) {
243
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
244
+ if (!seenKeys.has(key)) {
245
+ const processedValue = processJson(obj[key]);
246
+ if (processedValue !== undefined) { // Remove keys with undefined values
247
+ seenKeys.add(key);
248
+ result[key] = processedValue;
249
+ }
250
+ }
251
+ }
252
+ }
253
+
254
+ // If all keys were empty or undefined, return undefined
255
+ return Object.keys(result).length > 0 ? result : undefined;
256
+ } else {
257
+ // Return primitive values as-is
258
+ return obj;
259
+ }
260
+ }
261
+
262
+ function cleanTsConfig(json: any): any {
263
+ // Process the paths object to remove duplicates
264
+ if (json.compilerOptions?.paths) {
265
+ for (const key in json.compilerOptions.paths) {
266
+ if (Array.isArray(json.compilerOptions.paths[key])) {
267
+ const uniquePaths = [...new Set(json.compilerOptions.paths[key])];
268
+ json.compilerOptions.paths[key] = uniquePaths.length > 0 ? uniquePaths : undefined;
269
+ }
270
+ }
271
+ }
272
+
273
+ // Process the include array to remove duplicates
274
+ if (Array.isArray(json.include)) {
275
+ const uniqueIncludes = [...new Set(json.include)];
276
+ json.include = uniqueIncludes.length > 0 ? uniqueIncludes : undefined;
277
+ }
278
+
279
+ // Remove empty or undefined fields
280
+ if (json.compilerOptions?.paths) {
281
+ json.compilerOptions.paths = Object.fromEntries(
282
+ Object.entries(json.compilerOptions.paths).filter(([_, value]) => value !== undefined)
283
+ );
284
+ }
285
+
286
+ if (json.include?.length === 0) {
287
+ delete json.include;
288
+ }
289
+
290
+ return json;
191
291
  }
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,