piral-cli 1.4.0-beta.6250 → 1.4.0-beta.6252

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.
Files changed (162) hide show
  1. package/lib/api.js +8 -17
  2. package/lib/api.js.map +1 -1
  3. package/lib/apps/add-piral-instance-pilet.js +20 -31
  4. package/lib/apps/add-piral-instance-pilet.js.map +1 -1
  5. package/lib/apps/build-pilet.js +139 -147
  6. package/lib/apps/build-pilet.js.map +1 -1
  7. package/lib/apps/build-piral.js +130 -144
  8. package/lib/apps/build-piral.js.map +1 -1
  9. package/lib/apps/debug-pilet.js +107 -119
  10. package/lib/apps/debug-pilet.js.map +1 -1
  11. package/lib/apps/debug-piral.js +62 -70
  12. package/lib/apps/debug-piral.js.map +1 -1
  13. package/lib/apps/declaration-piral.js +6 -17
  14. package/lib/apps/declaration-piral.js.map +1 -1
  15. package/lib/apps/new-pilet.js +71 -82
  16. package/lib/apps/new-pilet.js.map +1 -1
  17. package/lib/apps/new-piral.js +42 -53
  18. package/lib/apps/new-piral.js.map +1 -1
  19. package/lib/apps/pack-pilet.js +7 -18
  20. package/lib/apps/pack-pilet.js.map +1 -1
  21. package/lib/apps/publish-pilet.js +127 -141
  22. package/lib/apps/publish-pilet.js.map +1 -1
  23. package/lib/apps/publish-piral.js +48 -63
  24. package/lib/apps/publish-piral.js.map +1 -1
  25. package/lib/apps/remove-piral-instance-pilet.js +30 -35
  26. package/lib/apps/remove-piral-instance-pilet.js.map +1 -1
  27. package/lib/apps/run-emulator-piral.js +49 -61
  28. package/lib/apps/run-emulator-piral.js.map +1 -1
  29. package/lib/apps/upgrade-pilet.js +64 -76
  30. package/lib/apps/upgrade-pilet.js.map +1 -1
  31. package/lib/apps/upgrade-piral.js +31 -43
  32. package/lib/apps/upgrade-piral.js.map +1 -1
  33. package/lib/apps/validate-pilet.js +34 -45
  34. package/lib/apps/validate-pilet.js.map +1 -1
  35. package/lib/apps/validate-piral.js +29 -51
  36. package/lib/apps/validate-piral.js.map +1 -1
  37. package/lib/build/bundler-calls.js +12 -3
  38. package/lib/build/bundler-calls.js.map +1 -1
  39. package/lib/build/run-build-pilet.js +5 -14
  40. package/lib/build/run-build-pilet.js.map +1 -1
  41. package/lib/build/run-build-piral.js +5 -14
  42. package/lib/build/run-build-piral.js.map +1 -1
  43. package/lib/build/run-debug-mono-piral.js +5 -14
  44. package/lib/build/run-debug-mono-piral.js.map +1 -1
  45. package/lib/build/run-debug-pilet.js +5 -14
  46. package/lib/build/run-debug-pilet.js.map +1 -1
  47. package/lib/build/run-debug-piral.js +5 -14
  48. package/lib/build/run-debug-piral.js.map +1 -1
  49. package/lib/bundler.js +100 -127
  50. package/lib/bundler.js.map +1 -1
  51. package/lib/commands.js +5 -1
  52. package/lib/commands.js.map +1 -1
  53. package/lib/common/browser.js +13 -26
  54. package/lib/common/browser.js.map +1 -1
  55. package/lib/common/compatibility.js +10 -21
  56. package/lib/common/compatibility.js.map +1 -1
  57. package/lib/common/declaration.js +80 -101
  58. package/lib/common/declaration.js.map +1 -1
  59. package/lib/common/emulator.js +186 -182
  60. package/lib/common/emulator.js.map +1 -1
  61. package/lib/common/http.js +7 -4
  62. package/lib/common/http.js.map +1 -1
  63. package/lib/common/importmap.js +172 -187
  64. package/lib/common/importmap.js.map +1 -1
  65. package/lib/common/injectors.js +4 -1
  66. package/lib/common/injectors.js.map +1 -1
  67. package/lib/common/inspect.js +5 -2
  68. package/lib/common/inspect.js.map +1 -1
  69. package/lib/common/interactive.js +9 -15
  70. package/lib/common/interactive.js.map +1 -1
  71. package/lib/common/io.js +256 -299
  72. package/lib/common/io.js.map +1 -1
  73. package/lib/common/language.js +21 -5
  74. package/lib/common/language.js.map +1 -1
  75. package/lib/common/npm.js +193 -228
  76. package/lib/common/npm.js.map +1 -1
  77. package/lib/common/pack.js +71 -86
  78. package/lib/common/pack.js.map +1 -1
  79. package/lib/common/package.js +426 -448
  80. package/lib/common/package.js.map +1 -1
  81. package/lib/common/parallel.js +12 -23
  82. package/lib/common/parallel.js.map +1 -1
  83. package/lib/common/patcher.js +54 -71
  84. package/lib/common/patcher.js.map +1 -1
  85. package/lib/common/platform.js +1 -12
  86. package/lib/common/platform.js.map +1 -1
  87. package/lib/common/port.js +11 -24
  88. package/lib/common/port.js.map +1 -1
  89. package/lib/common/rules.js +6 -17
  90. package/lib/common/rules.js.map +1 -1
  91. package/lib/common/scaffold.js +52 -59
  92. package/lib/common/scaffold.js.map +1 -1
  93. package/lib/common/shell.js +49 -58
  94. package/lib/common/shell.js.map +1 -1
  95. package/lib/common/spec.js +1 -1
  96. package/lib/common/spec.js.map +1 -1
  97. package/lib/common/template.js +3 -14
  98. package/lib/common/template.js.map +1 -1
  99. package/lib/common/watcher.js +7 -16
  100. package/lib/common/watcher.js.map +1 -1
  101. package/lib/common/website.d.ts +1 -0
  102. package/lib/common/website.js +67 -57
  103. package/lib/common/website.js.map +1 -1
  104. package/lib/injectors/pilet-injector.js +138 -145
  105. package/lib/injectors/pilet-injector.js.map +1 -1
  106. package/lib/injectors/piral-injector.js +55 -67
  107. package/lib/injectors/piral-injector.js.map +1 -1
  108. package/lib/messages.d.ts +81 -0
  109. package/lib/messages.js +94 -1
  110. package/lib/messages.js.map +1 -1
  111. package/lib/npm-clients/bun.js +36 -60
  112. package/lib/npm-clients/bun.js.map +1 -1
  113. package/lib/npm-clients/index.js +10 -21
  114. package/lib/npm-clients/index.js.map +1 -1
  115. package/lib/npm-clients/lerna.js +48 -72
  116. package/lib/npm-clients/lerna.js.map +1 -1
  117. package/lib/npm-clients/npm.js +69 -105
  118. package/lib/npm-clients/npm.js.map +1 -1
  119. package/lib/npm-clients/pnp.js +35 -59
  120. package/lib/npm-clients/pnp.js.map +1 -1
  121. package/lib/npm-clients/pnpm.js +35 -59
  122. package/lib/npm-clients/pnpm.js.map +1 -1
  123. package/lib/npm-clients/rush.js +53 -77
  124. package/lib/npm-clients/rush.js.map +1 -1
  125. package/lib/npm-clients/yarn.js +35 -59
  126. package/lib/npm-clients/yarn.js.map +1 -1
  127. package/lib/platforms/node.js +4 -17
  128. package/lib/platforms/node.js.map +1 -1
  129. package/lib/platforms/web.js +81 -96
  130. package/lib/platforms/web.js.map +1 -1
  131. package/lib/plugin.js +56 -75
  132. package/lib/plugin.js.map +1 -1
  133. package/lib/questionnaire.js +46 -12
  134. package/lib/questionnaire.js.map +1 -1
  135. package/lib/release.js +32 -47
  136. package/lib/release.js.map +1 -1
  137. package/lib/rules/index.js +10 -23
  138. package/lib/rules/index.js.map +1 -1
  139. package/lib/rules/pilet-has-externals-as-peers.js +34 -45
  140. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  141. package/lib/rules/pilet-has-no-self-reference.js +16 -27
  142. package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
  143. package/lib/rules/pilet-has-non-conflicting-css.js +27 -42
  144. package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
  145. package/lib/rules/pilet-stays-small.js +20 -33
  146. package/lib/rules/pilet-stays-small.js.map +1 -1
  147. package/lib/rules/pilet-uses-latest-piral.js +17 -28
  148. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  149. package/lib/rules/piral-has-valid-devDependencies.js +4 -1
  150. package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
  151. package/lib/runner.js +3 -12
  152. package/lib/runner.js.map +1 -1
  153. package/lib/select.js +21 -32
  154. package/lib/select.js.map +1 -1
  155. package/lib/start.js +6 -17
  156. package/lib/start.js.map +1 -1
  157. package/package.json +2 -2
  158. package/src/apps/build-piral.test.ts +1 -1
  159. package/src/common/package.ts +9 -2
  160. package/src/common/website.ts +43 -15
  161. package/src/injectors/pilet-injector.ts +12 -2
  162. package/src/messages.ts +93 -0
package/lib/common/io.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -49,16 +40,14 @@ function getDestination(entryFiles, target) {
49
40
  }
50
41
  }
51
42
  exports.getDestination = getDestination;
52
- function removeAny(target) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const isDir = yield checkIsDirectory(target);
55
- if (isDir) {
56
- yield removeDirectory(target);
57
- }
58
- else {
59
- yield removeFile(target);
60
- }
61
- });
43
+ async function removeAny(target) {
44
+ const isDir = await checkIsDirectory(target);
45
+ if (isDir) {
46
+ await removeDirectory(target);
47
+ }
48
+ else {
49
+ await removeFile(target);
50
+ }
62
51
  }
63
52
  exports.removeAny = removeAny;
64
53
  function removeDirectory(targetDir) {
@@ -66,40 +55,36 @@ function removeDirectory(targetDir) {
66
55
  return new Promise((resolve, reject) => (0, rimraf_1.default)(targetDir, (err) => (err ? reject(err) : resolve())));
67
56
  }
68
57
  exports.removeDirectory = removeDirectory;
69
- function createDirectory(targetDir) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- try {
72
- (0, log_1.log)('generalDebug_0003', `Trying to create "${targetDir}" ...`);
73
- yield new Promise((resolve, reject) => {
74
- (0, fs_2.mkdir)(targetDir, { recursive: true }, (err) => (err ? reject(err) : resolve()));
75
- });
76
- return true;
77
- }
78
- catch (e) {
79
- (0, log_1.log)('cannotCreateDirectory_0044');
80
- (0, log_1.log)('generalDebug_0003', `Error while creating ${targetDir}: ${e}`);
81
- return false;
82
- }
83
- });
58
+ async function createDirectory(targetDir) {
59
+ try {
60
+ (0, log_1.log)('generalDebug_0003', `Trying to create "${targetDir}" ...`);
61
+ await new Promise((resolve, reject) => {
62
+ (0, fs_2.mkdir)(targetDir, { recursive: true }, (err) => (err ? reject(err) : resolve()));
63
+ });
64
+ return true;
65
+ }
66
+ catch (e) {
67
+ (0, log_1.log)('cannotCreateDirectory_0044');
68
+ (0, log_1.log)('generalDebug_0003', `Error while creating ${targetDir}: ${e}`);
69
+ return false;
70
+ }
84
71
  }
85
72
  exports.createDirectory = createDirectory;
86
- function getEntryFiles(content, basePath) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- (0, log_1.log)('generalDebug_0003', `Extract entry files from "${basePath}".`);
89
- const matcher = /<script\s.*?src=(?:"(.*?)"|'(.*?)'|([^\s>]*)).*?>/gi;
90
- const results = [];
91
- let result = undefined;
92
- while ((result = matcher.exec(content))) {
93
- const src = result[1] || result[2] || result[3];
94
- (0, log_1.log)('generalDebug_0003', `Found potential entry file "${src}".`);
95
- const filePath = (0, path_1.resolve)(basePath, src);
96
- const exists = yield checkExists(filePath);
97
- if (exists) {
98
- results.push(filePath);
99
- }
73
+ async function getEntryFiles(content, basePath) {
74
+ (0, log_1.log)('generalDebug_0003', `Extract entry files from "${basePath}".`);
75
+ const matcher = /<script\s.*?src=(?:"(.*?)"|'(.*?)'|([^\s>]*)).*?>/gi;
76
+ const results = [];
77
+ let result = undefined;
78
+ while ((result = matcher.exec(content))) {
79
+ const src = result[1] || result[2] || result[3];
80
+ (0, log_1.log)('generalDebug_0003', `Found potential entry file "${src}".`);
81
+ const filePath = (0, path_1.resolve)(basePath, src);
82
+ const exists = await checkExists(filePath);
83
+ if (exists) {
84
+ results.push(filePath);
100
85
  }
101
- return results;
102
- });
86
+ }
87
+ return results;
103
88
  }
104
89
  exports.getEntryFiles = getEntryFiles;
105
90
  function makeTempDir(prefix) {
@@ -124,15 +109,13 @@ function checkExists(target) {
124
109
  });
125
110
  }
126
111
  exports.checkExists = checkExists;
127
- function checkExistingDirectory(target) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- (0, log_1.log)('generalDebug_0003', `Checking directory "${target}" ...`);
130
- if (yield checkExists(target)) {
131
- (0, log_1.log)('generalDebug_0003', `Target exists, but not yet clear if directory.`);
132
- return yield checkIsDirectory(target);
133
- }
134
- return false;
135
- });
112
+ async function checkExistingDirectory(target) {
113
+ (0, log_1.log)('generalDebug_0003', `Checking directory "${target}" ...`);
114
+ if (await checkExists(target)) {
115
+ (0, log_1.log)('generalDebug_0003', `Target exists, but not yet clear if directory.`);
116
+ return await checkIsDirectory(target);
117
+ }
118
+ return false;
136
119
  }
137
120
  exports.checkExistingDirectory = checkExistingDirectory;
138
121
  function checkIsDirectory(target) {
@@ -154,22 +137,20 @@ function getFileNames(target) {
154
137
  });
155
138
  }
156
139
  exports.getFileNames = getFileNames;
157
- function findFile(topDir, fileName, stopDir = (0, path_1.resolve)(topDir, '/')) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- const fileNames = Array.isArray(fileName) ? fileName : [fileName];
160
- for (const fn of fileNames) {
161
- const path = (0, path_1.join)(topDir, fn);
162
- const exists = yield checkExists(path);
163
- if (exists) {
164
- return path;
165
- }
166
- }
167
- if (topDir !== stopDir) {
168
- const parentDir = (0, path_1.resolve)(topDir, '..');
169
- return yield findFile(parentDir, fileNames, stopDir);
140
+ async function findFile(topDir, fileName, stopDir = (0, path_1.resolve)(topDir, '/')) {
141
+ const fileNames = Array.isArray(fileName) ? fileName : [fileName];
142
+ for (const fn of fileNames) {
143
+ const path = (0, path_1.join)(topDir, fn);
144
+ const exists = await checkExists(path);
145
+ if (exists) {
146
+ return path;
170
147
  }
171
- return undefined;
172
- });
148
+ }
149
+ if (topDir !== stopDir) {
150
+ const parentDir = (0, path_1.resolve)(topDir, '..');
151
+ return await findFile(parentDir, fileNames, stopDir);
152
+ }
153
+ return undefined;
173
154
  }
174
155
  exports.findFile = findFile;
175
156
  function matchPattern(baseDir, pattern) {
@@ -188,102 +169,98 @@ function matchPattern(baseDir, pattern) {
188
169
  });
189
170
  });
190
171
  }
191
- function matchAnyPattern(baseDir, pattern) {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- const matches = yield Promise.all(pattern.patterns.map((pattern) => matchPattern(baseDir, pattern)));
194
- return {
195
- pattern: pattern.original,
196
- results: matches.reduce((agg, curr) => [...agg, ...curr], []),
197
- };
198
- });
172
+ async function matchAnyPattern(baseDir, pattern) {
173
+ const matches = await Promise.all(pattern.patterns.map((pattern) => matchPattern(baseDir, pattern)));
174
+ return {
175
+ pattern: pattern.original,
176
+ results: matches.reduce((agg, curr) => [...agg, ...curr], []),
177
+ };
199
178
  }
200
179
  const preferences = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.esm', '.es', '.es6', '.html'];
201
- function matchAnyPilet(baseDir, patterns) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- const matches = [];
204
- const pilets = [];
205
- const matched = (name, path) => {
206
- pilets.push(name);
207
- matches.push(path);
208
- };
209
- const exts = preferences.map((s) => s.substring(1)).join(',');
210
- const allPatterns = patterns.reduce((agg, curr) => {
211
- const patterns = [];
212
- if (/[a-zA-Z0-9\-\*]$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
213
- patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${constants_1.packageJson}`, `${curr}/${constants_1.piletJson}`);
214
- }
215
- else if (curr.endsWith('/')) {
216
- patterns.push(`${curr}index.{${exts}}`, `${curr}${constants_1.packageJson}`, `${curr}${constants_1.piletJson}`);
217
- }
218
- else if (curr === '.' || curr === '..') {
219
- patterns.push(`${curr}/index.{${exts}}`, `${curr}/${constants_1.packageJson}`, `${curr}/${constants_1.piletJson}`);
220
- }
221
- else {
222
- patterns.push(curr);
223
- }
224
- agg.push({ original: curr, patterns });
225
- return agg;
226
- }, []);
227
- yield Promise.all(allPatterns.map((patterns) => matchAnyPattern(baseDir, patterns).then(({ results, pattern }) => __awaiter(this, void 0, void 0, function* () {
228
- if (!results.length) {
229
- (0, log_1.log)('generalDebug_0003', `Found no potential entry points using "${pattern}".`);
230
- }
231
- else {
232
- //TODO -> shouldn't take the first one,
233
- // should be the first one, yes, but, PER pilet
234
- // so that multiple pilets can be considered, too
235
- (0, log_1.log)('generalDebug_0003', `Found ${results.length} potential entry points in "${pattern}".`);
236
- for (const result of results) {
237
- const fileName = (0, path_1.basename)(result);
238
- if (fileName === constants_1.packageJson) {
239
- (0, log_1.log)('generalDebug_0003', `Entry point is a "${constants_1.packageJson}" and needs further inspection.`);
240
- const targetDir = (0, path_1.dirname)(result);
241
- const { source, name } = yield readJson(targetDir, fileName);
242
- if (!pilets.includes(name)) {
243
- if (typeof source === 'string') {
244
- (0, log_1.log)('generalDebug_0003', `Found a "source" field with value "${source}".`);
245
- const target = (0, path_1.resolve)(targetDir, source);
246
- const exists = yield checkExists(target);
247
- if (exists) {
248
- (0, log_1.log)('generalDebug_0003', `Taking existing target as "${target}".`);
249
- matched(name, target);
250
- }
251
- else {
252
- (0, log_1.log)('generalDebug_0003', `Source target "${target}" does not exist. Skipped.`);
253
- }
180
+ async function matchAnyPilet(baseDir, patterns) {
181
+ const matches = [];
182
+ const pilets = [];
183
+ const matched = (name, path) => {
184
+ pilets.push(name);
185
+ matches.push(path);
186
+ };
187
+ const exts = preferences.map((s) => s.substring(1)).join(',');
188
+ const allPatterns = patterns.reduce((agg, curr) => {
189
+ const patterns = [];
190
+ if (/[a-zA-Z0-9\-\*]$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
191
+ patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${constants_1.packageJson}`, `${curr}/${constants_1.piletJson}`);
192
+ }
193
+ else if (curr.endsWith('/')) {
194
+ patterns.push(`${curr}index.{${exts}}`, `${curr}${constants_1.packageJson}`, `${curr}${constants_1.piletJson}`);
195
+ }
196
+ else if (curr === '.' || curr === '..') {
197
+ patterns.push(`${curr}/index.{${exts}}`, `${curr}/${constants_1.packageJson}`, `${curr}/${constants_1.piletJson}`);
198
+ }
199
+ else {
200
+ patterns.push(curr);
201
+ }
202
+ agg.push({ original: curr, patterns });
203
+ return agg;
204
+ }, []);
205
+ await Promise.all(allPatterns.map((patterns) => matchAnyPattern(baseDir, patterns).then(async ({ results, pattern }) => {
206
+ if (!results.length) {
207
+ (0, log_1.log)('generalDebug_0003', `Found no potential entry points using "${pattern}".`);
208
+ }
209
+ else {
210
+ //TODO -> shouldn't take the first one,
211
+ // should be the first one, yes, but, PER pilet
212
+ // so that multiple pilets can be considered, too
213
+ (0, log_1.log)('generalDebug_0003', `Found ${results.length} potential entry points in "${pattern}".`);
214
+ for (const result of results) {
215
+ const fileName = (0, path_1.basename)(result);
216
+ if (fileName === constants_1.packageJson) {
217
+ (0, log_1.log)('generalDebug_0003', `Entry point is a "${constants_1.packageJson}" and needs further inspection.`);
218
+ const targetDir = (0, path_1.dirname)(result);
219
+ const { source, name } = await readJson(targetDir, fileName);
220
+ if (!pilets.includes(name)) {
221
+ if (typeof source === 'string') {
222
+ (0, log_1.log)('generalDebug_0003', `Found a "source" field with value "${source}".`);
223
+ const target = (0, path_1.resolve)(targetDir, source);
224
+ const exists = await checkExists(target);
225
+ if (exists) {
226
+ (0, log_1.log)('generalDebug_0003', `Taking existing target as "${target}".`);
227
+ matched(name, target);
254
228
  }
255
229
  else {
256
- (0, log_1.log)('generalDebug_0003', `No "source" field found. Trying combinations in "src".`);
257
- const files = yield matchPattern(targetDir, `src/index.{${exts}}`);
258
- if (files.length > 0) {
259
- (0, log_1.log)('generalDebug_0003', `Found a result; taking "${files[0]}".`);
260
- matched(name, files[0]);
261
- }
262
- else {
263
- (0, log_1.log)('generalDebug_0003', `Found no results in "src". Skipped.`);
264
- }
230
+ (0, log_1.log)('generalDebug_0003', `Source target "${target}" does not exist. Skipped.`);
265
231
  }
266
232
  }
267
- }
268
- else {
269
- const packageJsonPath = yield findFile(result, constants_1.packageJson);
270
- if (packageJsonPath) {
271
- const targetDir = (0, path_1.dirname)(packageJsonPath);
272
- const { name } = yield readJson(targetDir, constants_1.packageJson);
273
- if (!pilets.includes(name)) {
274
- (0, log_1.log)('generalDebug_0003', `Entry point result is "${result}".`);
275
- matched(name, result);
233
+ else {
234
+ (0, log_1.log)('generalDebug_0003', `No "source" field found. Trying combinations in "src".`);
235
+ const files = await matchPattern(targetDir, `src/index.{${exts}}`);
236
+ if (files.length > 0) {
237
+ (0, log_1.log)('generalDebug_0003', `Found a result; taking "${files[0]}".`);
238
+ matched(name, files[0]);
239
+ }
240
+ else {
241
+ (0, log_1.log)('generalDebug_0003', `Found no results in "src". Skipped.`);
276
242
  }
277
243
  }
278
- else {
279
- (0, log_1.log)('generalDebug_0003', `Could not find "${constants_1.packageJson}" for entry "${result}". Skipping.`);
244
+ }
245
+ }
246
+ else {
247
+ const packageJsonPath = await findFile(result, constants_1.packageJson);
248
+ if (packageJsonPath) {
249
+ const targetDir = (0, path_1.dirname)(packageJsonPath);
250
+ const { name } = await readJson(targetDir, constants_1.packageJson);
251
+ if (!pilets.includes(name)) {
252
+ (0, log_1.log)('generalDebug_0003', `Entry point result is "${result}".`);
253
+ matched(name, result);
280
254
  }
281
255
  }
256
+ else {
257
+ (0, log_1.log)('generalDebug_0003', `Could not find "${constants_1.packageJson}" for entry "${result}". Skipping.`);
258
+ }
282
259
  }
283
260
  }
284
- }))));
285
- return matches;
286
- });
261
+ }
262
+ })));
263
+ return matches;
287
264
  }
288
265
  exports.matchAnyPilet = matchAnyPilet;
289
266
  function matchFiles(baseDir, pattern) {
@@ -303,75 +280,65 @@ function matchFiles(baseDir, pattern) {
303
280
  });
304
281
  }
305
282
  exports.matchFiles = matchFiles;
306
- function createFileIfNotExists(targetDir, fileName, content, forceOverwrite = enums_1.ForceOverwrite.no) {
307
- return __awaiter(this, void 0, void 0, function* () {
308
- const targetFile = (0, path_1.join)(targetDir, fileName);
309
- (0, log_1.log)('generalDebug_0003', `Checking if file "${targetFile}" exists ...`);
310
- const exists = yield checkExists(targetFile);
311
- if (!exists ||
312
- forceOverwrite === enums_1.ForceOverwrite.yes ||
313
- (forceOverwrite === enums_1.ForceOverwrite.prompt && (yield promptOverwrite(targetFile)))) {
314
- yield createDirectory((0, path_1.dirname)(targetFile));
315
- (0, log_1.log)('generalDebug_0003', `Creating file "${targetFile}" ...`);
316
- if (typeof content === 'string') {
317
- yield writeText(targetDir, fileName, content);
318
- }
319
- else {
320
- yield writeBinary(targetDir, fileName, content);
321
- }
283
+ async function createFileIfNotExists(targetDir, fileName, content, forceOverwrite = enums_1.ForceOverwrite.no) {
284
+ const targetFile = (0, path_1.join)(targetDir, fileName);
285
+ (0, log_1.log)('generalDebug_0003', `Checking if file "${targetFile}" exists ...`);
286
+ const exists = await checkExists(targetFile);
287
+ if (!exists ||
288
+ forceOverwrite === enums_1.ForceOverwrite.yes ||
289
+ (forceOverwrite === enums_1.ForceOverwrite.prompt && (await promptOverwrite(targetFile)))) {
290
+ await createDirectory((0, path_1.dirname)(targetFile));
291
+ (0, log_1.log)('generalDebug_0003', `Creating file "${targetFile}" ...`);
292
+ if (typeof content === 'string') {
293
+ await writeText(targetDir, fileName, content);
322
294
  }
323
- });
295
+ else {
296
+ await writeBinary(targetDir, fileName, content);
297
+ }
298
+ }
324
299
  }
325
300
  exports.createFileIfNotExists = createFileIfNotExists;
326
- function updateExistingFile(targetDir, fileName, content) {
327
- return __awaiter(this, void 0, void 0, function* () {
328
- const targetFile = (0, path_1.join)(targetDir, fileName);
329
- (0, log_1.log)('generalDebug_0003', `Checking if file "${targetFile}" exists ...`);
330
- const exists = yield checkExists(targetFile);
331
- if (exists) {
332
- (0, log_1.log)('generalDebug_0003', `Updating file "${targetFile}" ...`);
333
- yield new Promise((resolve, reject) => {
334
- (0, fs_3.writeFile)(targetFile, content, 'utf8', (err) => (err ? reject(err) : resolve()));
335
- });
336
- }
337
- });
301
+ async function updateExistingFile(targetDir, fileName, content) {
302
+ const targetFile = (0, path_1.join)(targetDir, fileName);
303
+ (0, log_1.log)('generalDebug_0003', `Checking if file "${targetFile}" exists ...`);
304
+ const exists = await checkExists(targetFile);
305
+ if (exists) {
306
+ (0, log_1.log)('generalDebug_0003', `Updating file "${targetFile}" ...`);
307
+ await new Promise((resolve, reject) => {
308
+ (0, fs_3.writeFile)(targetFile, content, 'utf8', (err) => (err ? reject(err) : resolve()));
309
+ });
310
+ }
338
311
  }
339
312
  exports.updateExistingFile = updateExistingFile;
340
- function getHash(targetFile) {
341
- return __awaiter(this, void 0, void 0, function* () {
342
- return new Promise((resolve) => {
343
- (0, fs_3.readFile)(targetFile, (err, c) => (err ? resolve(undefined) : resolve((0, hash_1.computeHash)(c))));
344
- });
313
+ async function getHash(targetFile) {
314
+ return new Promise((resolve) => {
315
+ (0, fs_3.readFile)(targetFile, (err, c) => (err ? resolve(undefined) : resolve((0, hash_1.computeHash)(c))));
345
316
  });
346
317
  }
347
318
  exports.getHash = getHash;
348
- function mergeWithJson(targetDir, fileName, newContent) {
349
- return __awaiter(this, void 0, void 0, function* () {
350
- const targetFile = (0, path_1.join)(targetDir, fileName);
351
- const content = yield new Promise((resolve) => {
352
- (0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('{}') : resolve(c)));
353
- });
354
- const originalContent = JSON.parse(content);
355
- return (0, merge_1.deepMerge)(originalContent, newContent);
319
+ async function mergeWithJson(targetDir, fileName, newContent) {
320
+ const targetFile = (0, path_1.join)(targetDir, fileName);
321
+ const content = await new Promise((resolve) => {
322
+ (0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('{}') : resolve(c)));
356
323
  });
324
+ const originalContent = JSON.parse(content);
325
+ return (0, merge_1.deepMerge)(originalContent, newContent);
357
326
  }
358
327
  exports.mergeWithJson = mergeWithJson;
359
- function readJson(targetDir, fileName, defaultValue = {}) {
360
- return __awaiter(this, void 0, void 0, function* () {
361
- const targetFile = (0, path_1.join)(targetDir, fileName);
362
- const content = yield new Promise((resolve) => {
363
- (0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('') : resolve(c)));
364
- });
365
- if (content) {
366
- try {
367
- return JSON.parse(content);
368
- }
369
- catch (ex) {
370
- (0, log_1.log)('generalError_0002', `Invalid JSON found in file "${fileName}" at "${targetDir}".`);
371
- }
372
- }
373
- return defaultValue;
328
+ async function readJson(targetDir, fileName, defaultValue = {}) {
329
+ const targetFile = (0, path_1.join)(targetDir, fileName);
330
+ const content = await new Promise((resolve) => {
331
+ (0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('') : resolve(c)));
374
332
  });
333
+ if (content) {
334
+ try {
335
+ return JSON.parse(content);
336
+ }
337
+ catch (ex) {
338
+ (0, log_1.log)('generalError_0002', `Invalid JSON found in file "${fileName}" at "${targetDir}".`);
339
+ }
340
+ }
341
+ return defaultValue;
375
342
  }
376
343
  exports.readJson = readJson;
377
344
  function readBinary(targetDir, fileName) {
@@ -405,44 +372,40 @@ function writeBinary(targetDir, fileName, data) {
405
372
  });
406
373
  }
407
374
  exports.writeBinary = writeBinary;
408
- function updateExistingJson(targetDir, fileName, newContent) {
409
- return __awaiter(this, void 0, void 0, function* () {
410
- const content = yield mergeWithJson(targetDir, fileName, newContent);
411
- yield updateExistingFile(targetDir, fileName, JSON.stringify(content, undefined, 2));
412
- });
375
+ async function updateExistingJson(targetDir, fileName, newContent) {
376
+ const content = await mergeWithJson(targetDir, fileName, newContent);
377
+ await updateExistingFile(targetDir, fileName, JSON.stringify(content, undefined, 2));
413
378
  }
414
379
  exports.updateExistingJson = updateExistingJson;
415
- function copy(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
416
- return __awaiter(this, void 0, void 0, function* () {
417
- yield createDirectory((0, path_1.dirname)(target));
418
- try {
419
- const flag = forceOverwrite === enums_1.ForceOverwrite.yes ? 0 : fs_2.constants.COPYFILE_EXCL;
420
- const isDir = yield checkIsDirectory(source);
421
- if (isDir) {
422
- const files = yield getFileNames(source);
423
- const results = yield Promise.all(files.map((file) => copy((0, path_1.resolve)(source, file), (0, path_1.resolve)(target, file), forceOverwrite)));
424
- return results.every(Boolean);
425
- }
426
- else {
427
- yield new Promise((resolve, reject) => {
428
- (0, fs_3.copyFile)(source, target, flag, (err) => (err ? reject(err) : resolve()));
429
- });
430
- return true;
431
- }
380
+ async function copy(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
381
+ await createDirectory((0, path_1.dirname)(target));
382
+ try {
383
+ const flag = forceOverwrite === enums_1.ForceOverwrite.yes ? 0 : fs_2.constants.COPYFILE_EXCL;
384
+ const isDir = await checkIsDirectory(source);
385
+ if (isDir) {
386
+ const files = await getFileNames(source);
387
+ const results = await Promise.all(files.map((file) => copy((0, path_1.resolve)(source, file), (0, path_1.resolve)(target, file), forceOverwrite)));
388
+ return results.every(Boolean);
432
389
  }
433
- catch (e) {
434
- if (forceOverwrite === enums_1.ForceOverwrite.prompt) {
435
- const shouldOverwrite = yield promptOverwrite(target);
436
- if (shouldOverwrite) {
437
- return yield copy(source, target, enums_1.ForceOverwrite.yes);
438
- }
439
- }
440
- else {
441
- (0, log_1.log)('didNotOverWriteFile_0045', target);
390
+ else {
391
+ await new Promise((resolve, reject) => {
392
+ (0, fs_3.copyFile)(source, target, flag, (err) => (err ? reject(err) : resolve()));
393
+ });
394
+ return true;
395
+ }
396
+ }
397
+ catch (e) {
398
+ if (forceOverwrite === enums_1.ForceOverwrite.prompt) {
399
+ const shouldOverwrite = await promptOverwrite(target);
400
+ if (shouldOverwrite) {
401
+ return await copy(source, target, enums_1.ForceOverwrite.yes);
442
402
  }
443
403
  }
444
- return false;
445
- });
404
+ else {
405
+ (0, log_1.log)('didNotOverWriteFile_0045', target);
406
+ }
407
+ }
408
+ return false;
446
409
  }
447
410
  exports.copy = copy;
448
411
  /**
@@ -465,59 +428,53 @@ function removeFile(target) {
465
428
  });
466
429
  }
467
430
  exports.removeFile = removeFile;
468
- function move(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
469
- return __awaiter(this, void 0, void 0, function* () {
470
- const dir = yield checkIsDirectory(target);
471
- if (dir) {
472
- const file = (0, path_1.basename)(source);
473
- target = (0, path_1.resolve)(target, file);
474
- }
475
- const success = yield copy(source, target, forceOverwrite);
476
- if (success) {
477
- yield removeFile(source);
478
- return target;
479
- }
480
- return source;
481
- });
431
+ async function move(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
432
+ const dir = await checkIsDirectory(target);
433
+ if (dir) {
434
+ const file = (0, path_1.basename)(source);
435
+ target = (0, path_1.resolve)(target, file);
436
+ }
437
+ const success = await copy(source, target, forceOverwrite);
438
+ if (success) {
439
+ await removeFile(source);
440
+ return target;
441
+ }
442
+ return source;
482
443
  }
483
444
  exports.move = move;
484
- function getSourceFiles(entry) {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- const dir = (0, path_1.dirname)(entry);
487
- (0, log_1.log)('generalDebug_0003', `Trying to get source files from "${dir}" ...`);
488
- const files = yield matchFiles(dir, '**/*.?(jsx|tsx|js|ts)');
489
- return files.map((path) => {
490
- const directory = (0, path_1.dirname)(path);
491
- const name = (0, path_1.basename)(path);
492
- return {
493
- path,
494
- directory,
495
- name,
496
- read() {
497
- return __awaiter(this, void 0, void 0, function* () {
498
- const content = yield readText(directory, name);
499
- if (name.endsWith('.ts') || name.endsWith('.tsx')) {
500
- return (0, typescript_1.transpileModule)(content, {
501
- fileName: path,
502
- moduleName: name,
503
- compilerOptions: {
504
- allowJs: true,
505
- skipLibCheck: true,
506
- declaration: false,
507
- sourceMap: false,
508
- checkJs: false,
509
- jsx: typescript_1.JsxEmit.React,
510
- module: typescript_1.ModuleKind.ESNext,
511
- moduleResolution: typescript_1.ModuleResolutionKind.NodeJs,
512
- target: typescript_1.ScriptTarget.ESNext,
513
- },
514
- }).outputText;
515
- }
516
- return content;
517
- });
518
- },
519
- };
520
- });
445
+ async function getSourceFiles(entry) {
446
+ const dir = (0, path_1.dirname)(entry);
447
+ (0, log_1.log)('generalDebug_0003', `Trying to get source files from "${dir}" ...`);
448
+ const files = await matchFiles(dir, '**/*.?(jsx|tsx|js|ts)');
449
+ return files.map((path) => {
450
+ const directory = (0, path_1.dirname)(path);
451
+ const name = (0, path_1.basename)(path);
452
+ return {
453
+ path,
454
+ directory,
455
+ name,
456
+ async read() {
457
+ const content = await readText(directory, name);
458
+ if (name.endsWith('.ts') || name.endsWith('.tsx')) {
459
+ return (0, typescript_1.transpileModule)(content, {
460
+ fileName: path,
461
+ moduleName: name,
462
+ compilerOptions: {
463
+ allowJs: true,
464
+ skipLibCheck: true,
465
+ declaration: false,
466
+ sourceMap: false,
467
+ checkJs: false,
468
+ jsx: typescript_1.JsxEmit.React,
469
+ module: typescript_1.ModuleKind.ESNext,
470
+ moduleResolution: typescript_1.ModuleResolutionKind.NodeJs,
471
+ target: typescript_1.ScriptTarget.ESNext,
472
+ },
473
+ }).outputText;
474
+ }
475
+ return content;
476
+ },
477
+ };
521
478
  });
522
479
  }
523
480
  exports.getSourceFiles = getSourceFiles;