@teambit/workspace 0.0.881 → 0.0.883

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 (108) hide show
  1. package/dist/bit-map.js +10 -51
  2. package/dist/bit-map.js.map +1 -1
  3. package/dist/build-graph-from-fs.js +1 -53
  4. package/dist/build-graph-from-fs.js.map +1 -1
  5. package/dist/capsule.cmd.js +2 -34
  6. package/dist/capsule.cmd.js.map +1 -1
  7. package/dist/component-config-file/component-config-file.js +2 -60
  8. package/dist/component-config-file/component-config-file.js.map +1 -1
  9. package/dist/component-config-file/exceptions/already-exists.js +0 -6
  10. package/dist/component-config-file/exceptions/already-exists.js.map +1 -1
  11. package/dist/component-config-file/exceptions/index.js +0 -3
  12. package/dist/component-config-file/exceptions/index.js.map +1 -1
  13. package/dist/component-config-file/index.js +0 -6
  14. package/dist/component-config-file/index.js.map +1 -1
  15. package/dist/component-tree.widget.js +0 -18
  16. package/dist/component-tree.widget.js.map +1 -1
  17. package/dist/constants.js.map +1 -1
  18. package/dist/eject-conf.cmd.js +0 -23
  19. package/dist/eject-conf.cmd.js.map +1 -1
  20. package/dist/envs-subcommands/envs-replace.cmd.js +0 -13
  21. package/dist/envs-subcommands/envs-replace.cmd.js.map +1 -1
  22. package/dist/envs-subcommands/envs-set.cmd.js +0 -16
  23. package/dist/envs-subcommands/envs-set.cmd.js.map +1 -1
  24. package/dist/envs-subcommands/envs-unset.cmd.js +0 -18
  25. package/dist/envs-subcommands/envs-unset.cmd.js.map +1 -1
  26. package/dist/events/index.js +0 -6
  27. package/dist/events/index.js.map +1 -1
  28. package/dist/events/on-component-add-event.js +1 -12
  29. package/dist/events/on-component-add-event.js.map +1 -1
  30. package/dist/events/on-component-change-event.js +1 -12
  31. package/dist/events/on-component-change-event.js.map +1 -1
  32. package/dist/events/on-component-removed-event.js +1 -12
  33. package/dist/events/on-component-removed-event.js.map +1 -1
  34. package/dist/exceptions/incorrect-env-aspect.js +0 -6
  35. package/dist/exceptions/incorrect-env-aspect.js.map +1 -1
  36. package/dist/index.js +0 -19
  37. package/dist/index.js.map +1 -1
  38. package/dist/list.cmd.js +2 -15
  39. package/dist/list.cmd.js.map +1 -1
  40. package/dist/pattern.cmd.js +0 -16
  41. package/dist/pattern.cmd.js.map +1 -1
  42. package/dist/scope-subcommands/scope-set.cmd.js +0 -17
  43. package/dist/scope-subcommands/scope-set.cmd.js.map +1 -1
  44. package/dist/ui/index.js +0 -3
  45. package/dist/ui/index.js.map +1 -1
  46. package/dist/ui/workspace/default-component.js.map +1 -1
  47. package/dist/ui/workspace/index.js +0 -2
  48. package/dist/ui/workspace/index.js.map +1 -1
  49. package/dist/ui/workspace/use-workspace.js +14 -49
  50. package/dist/ui/workspace/use-workspace.js.map +1 -1
  51. package/dist/ui/workspace/workspace-context.js +0 -7
  52. package/dist/ui/workspace/workspace-context.js.map +1 -1
  53. package/dist/ui/workspace/workspace-model.js +2 -14
  54. package/dist/ui/workspace/workspace-model.js.map +1 -1
  55. package/dist/ui/workspace/workspace-overview/index.js +0 -3
  56. package/dist/ui/workspace/workspace-overview/index.js.map +1 -1
  57. package/dist/ui/workspace/workspace-overview/workspace-overview.js +0 -23
  58. package/dist/ui/workspace/workspace-overview/workspace-overview.js.map +1 -1
  59. package/dist/ui/workspace/workspace-provider.js +0 -8
  60. package/dist/ui/workspace/workspace-provider.js.map +1 -1
  61. package/dist/ui/workspace/workspace.js +2 -52
  62. package/dist/ui/workspace/workspace.js.map +1 -1
  63. package/dist/use.cmd.js +0 -13
  64. package/dist/use.cmd.js.map +1 -1
  65. package/dist/watch/check-types.js +0 -1
  66. package/dist/watch/check-types.js.map +1 -1
  67. package/dist/watch/output-formatter.js +1 -12
  68. package/dist/watch/output-formatter.js.map +1 -1
  69. package/dist/watch/watch-queue.js +0 -13
  70. package/dist/watch/watch-queue.js.map +1 -1
  71. package/dist/watch/watch.cmd.js +6 -41
  72. package/dist/watch/watch.cmd.js.map +1 -1
  73. package/dist/watch/watcher.js +13 -133
  74. package/dist/watch/watcher.js.map +1 -1
  75. package/dist/workspace-component/component-status.js +0 -4
  76. package/dist/workspace-component/component-status.js.map +1 -1
  77. package/dist/workspace-component/index.js +0 -6
  78. package/dist/workspace-component/index.js.map +1 -1
  79. package/dist/workspace-component/workspace-component-loader.js +31 -116
  80. package/dist/workspace-component/workspace-component-loader.js.map +1 -1
  81. package/dist/workspace-component/workspace-component.js +1 -11
  82. package/dist/workspace-component/workspace-component.js.map +1 -1
  83. package/dist/workspace-section.js +2 -0
  84. package/dist/workspace-section.js.map +1 -1
  85. package/dist/workspace.aspect.js +0 -5
  86. package/dist/workspace.aspect.js.map +1 -1
  87. package/dist/workspace.composition.js +0 -6
  88. package/dist/workspace.composition.js.map +1 -1
  89. package/dist/workspace.d.ts +1 -0
  90. package/dist/workspace.graphql.js +0 -12
  91. package/dist/workspace.graphql.js.map +1 -1
  92. package/dist/workspace.js +141 -545
  93. package/dist/workspace.js.map +1 -1
  94. package/dist/workspace.main.runtime.js +0 -55
  95. package/dist/workspace.main.runtime.js.map +1 -1
  96. package/dist/workspace.provider.js +8 -77
  97. package/dist/workspace.provider.js.map +1 -1
  98. package/dist/workspace.ui-root.js +3 -17
  99. package/dist/workspace.ui-root.js.map +1 -1
  100. package/dist/workspace.ui.drawer.js +2 -24
  101. package/dist/workspace.ui.drawer.js.map +1 -1
  102. package/dist/workspace.ui.runtime.js +0 -75
  103. package/dist/workspace.ui.runtime.js.map +1 -1
  104. package/package-tar/teambit-workspace-0.0.883.tgz +0 -0
  105. package/package.json +18 -18
  106. package/{preview-1666409808293.js → preview-1666582798766.js} +2 -2
  107. package/workspace-component/workspace-component-loader.ts +13 -3
  108. package/package-tar/teambit-workspace-0.0.881.tgz +0 -0
@@ -1,166 +1,115 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.flat.js");
6
-
7
5
  require("core-js/modules/es.array.iterator.js");
8
-
9
6
  require("core-js/modules/es.array.unscopables.flat.js");
10
-
11
7
  require("core-js/modules/es.promise.js");
12
-
13
8
  Object.defineProperty(exports, "__esModule", {
14
9
  value: true
15
10
  });
16
11
  exports.Watcher = void 0;
17
-
18
12
  function _objectWithoutProperties2() {
19
13
  const data = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
20
-
21
14
  _objectWithoutProperties2 = function () {
22
15
  return data;
23
16
  };
24
-
25
17
  return data;
26
18
  }
27
-
28
19
  function _defineProperty2() {
29
20
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
30
-
31
21
  _defineProperty2 = function () {
32
22
  return data;
33
23
  };
34
-
35
24
  return data;
36
25
  }
37
-
38
26
  function _path() {
39
27
  const data = require("path");
40
-
41
28
  _path = function () {
42
29
  return data;
43
30
  };
44
-
45
31
  return data;
46
32
  }
47
-
48
33
  function _lodash() {
49
34
  const data = require("lodash");
50
-
51
35
  _lodash = function () {
52
36
  return data;
53
37
  };
54
-
55
38
  return data;
56
39
  }
57
-
58
40
  function _loader() {
59
41
  const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
60
-
61
42
  _loader = function () {
62
43
  return data;
63
44
  };
64
-
65
45
  return data;
66
46
  }
67
-
68
47
  function _constants() {
69
48
  const data = require("@teambit/legacy/dist/constants");
70
-
71
49
  _constants = function () {
72
50
  return data;
73
51
  };
74
-
75
52
  return data;
76
53
  }
77
-
78
54
  function _logger() {
79
55
  const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
80
-
81
56
  _logger = function () {
82
57
  return data;
83
58
  };
84
-
85
59
  return data;
86
60
  }
87
-
88
61
  function _utils() {
89
62
  const data = require("@teambit/legacy/dist/utils");
90
-
91
63
  _utils = function () {
92
64
  return data;
93
65
  };
94
-
95
66
  return data;
96
67
  }
97
-
98
68
  function _pMapSeries() {
99
69
  const data = _interopRequireDefault(require("p-map-series"));
100
-
101
70
  _pMapSeries = function () {
102
71
  return data;
103
72
  };
104
-
105
73
  return data;
106
74
  }
107
-
108
75
  function _chalk() {
109
76
  const data = _interopRequireDefault(require("chalk"));
110
-
111
77
  _chalk = function () {
112
78
  return data;
113
79
  };
114
-
115
80
  return data;
116
81
  }
117
-
118
82
  function _chokidar() {
119
83
  const data = _interopRequireDefault(require("chokidar"));
120
-
121
84
  _chokidar = function () {
122
85
  return data;
123
86
  };
124
-
125
87
  return data;
126
88
  }
127
-
128
89
  function _() {
129
90
  const data = require("../");
130
-
131
91
  _ = function () {
132
92
  return data;
133
93
  };
134
-
135
94
  return data;
136
95
  }
137
-
138
96
  function _events() {
139
97
  const data = require("../events");
140
-
141
98
  _events = function () {
142
99
  return data;
143
100
  };
144
-
145
101
  return data;
146
102
  }
147
-
148
103
  function _watchQueue() {
149
104
  const data = require("./watch-queue");
150
-
151
105
  _watchQueue = function () {
152
106
  return data;
153
107
  };
154
-
155
108
  return data;
156
109
  }
157
-
158
110
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
159
-
160
111
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
161
-
162
112
  const DEBOUNCE_WAIT_MS = 100;
163
-
164
113
  class Watcher {
165
114
  constructor(workspace, pubsub, trackDirs = {}, verbose = false, multipleWatchers = []) {
166
115
  this.workspace = workspace;
@@ -173,17 +122,15 @@ class Watcher {
173
122
  (0, _defineProperty2().default)(this, "watchQueue", new (_watchQueue().WatchQueue)());
174
123
  (0, _defineProperty2().default)(this, "bitMapChangesInProgress", false);
175
124
  }
176
-
177
125
  get consumer() {
178
126
  return this.workspace.consumer;
179
127
  }
180
-
181
128
  async watchAll(opts) {
182
129
  const {
183
- msgs
184
- } = opts,
185
- watchOpts = (0, _objectWithoutProperties2().default)(opts, ["msgs"]); // TODO: run build in the beginning of process (it's work like this in other envs)
186
-
130
+ msgs
131
+ } = opts,
132
+ watchOpts = (0, _objectWithoutProperties2().default)(opts, ["msgs"]);
133
+ // TODO: run build in the beginning of process (it's work like this in other envs)
187
134
  const pathsToWatch = await this.getPathsToWatch();
188
135
  const componentIds = Object.values(this.trackDirs);
189
136
  await this.workspace.triggerOnPreWatch(componentIds, watchOpts);
@@ -196,11 +143,10 @@ class Watcher {
196
143
  // @ts-ignore
197
144
  if (msgs !== null && msgs !== void 0 && msgs.onAll) watcher.on('all', msgs === null || msgs === void 0 ? void 0 : msgs.onAll);
198
145
  }
199
-
200
146
  watcher.on('ready', () => {
201
147
  msgs === null || msgs === void 0 ? void 0 : msgs.onReady(this.workspace, this.trackDirs, this.verbose);
202
- }); // eslint-disable-next-line @typescript-eslint/no-misused-promises
203
-
148
+ });
149
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
204
150
  watcher.on('change', async filePath => {
205
151
  const startTime = new Date().getTime();
206
152
  const {
@@ -209,15 +155,13 @@ class Watcher {
209
155
  debounced,
210
156
  failureMsg
211
157
  } = await this.handleChange(filePath, opts === null || opts === void 0 ? void 0 : opts.initiator);
212
-
213
158
  if (debounced) {
214
159
  return;
215
160
  }
216
-
217
161
  const duration = new Date().getTime() - startTime;
218
162
  msgs === null || msgs === void 0 ? void 0 : msgs.onChange(files, results, this.verbose, duration, failureMsg);
219
- }); // eslint-disable-next-line @typescript-eslint/no-misused-promises
220
-
163
+ });
164
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
221
165
  watcher.on('add', async filePath => {
222
166
  const startTime = new Date().getTime();
223
167
  const {
@@ -226,15 +170,13 @@ class Watcher {
226
170
  debounced,
227
171
  failureMsg
228
172
  } = await this.handleChange(filePath, opts === null || opts === void 0 ? void 0 : opts.initiator);
229
-
230
173
  if (debounced) {
231
174
  return;
232
175
  }
233
-
234
176
  const duration = new Date().getTime() - startTime;
235
177
  msgs === null || msgs === void 0 ? void 0 : msgs.onAdd(files, results, this.verbose, duration, failureMsg);
236
- }); // eslint-disable-next-line @typescript-eslint/no-misused-promises
237
-
178
+ });
179
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
238
180
  watcher.on('unlink', async p => {
239
181
  msgs === null || msgs === void 0 ? void 0 : msgs.onUnlink(p);
240
182
  await this.handleChange(p);
@@ -245,6 +187,7 @@ class Watcher {
245
187
  });
246
188
  });
247
189
  }
190
+
248
191
  /**
249
192
  * *** DEBOUNCING ***
250
193
  * some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
@@ -280,65 +223,48 @@ class Watcher {
280
223
  * this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the
281
224
  * .bitmap execution starts.
282
225
  */
283
-
284
-
285
226
  async handleChange(filePath, initiator) {
286
227
  try {
287
228
  if (filePath.endsWith(_constants().BIT_MAP)) {
288
229
  this.bitMapChangesInProgress = true;
289
230
  const buildResults = await this.watchQueue.add(() => this.handleBitmapChanges());
290
231
  this.bitMapChangesInProgress = false;
291
-
292
232
  _loader().default.stop();
293
-
294
233
  return {
295
234
  results: buildResults,
296
235
  files: [filePath]
297
236
  };
298
237
  }
299
-
300
238
  if (this.bitMapChangesInProgress) {
301
239
  await this.watchQueue.onIdle();
302
240
  }
303
-
304
241
  const componentId = this.getComponentIdByPath(filePath);
305
-
306
242
  if (!componentId) {
307
243
  const failureMsg = `file ${filePath} is not part of any component, ignoring it`;
308
-
309
244
  _logger().default.debug(failureMsg);
310
-
311
245
  _loader().default.stop();
312
-
313
246
  return {
314
247
  results: [],
315
248
  files: [filePath],
316
249
  failureMsg
317
250
  };
318
251
  }
319
-
320
252
  const compIdStr = componentId.toString();
321
-
322
253
  if (this.changedFilesPerComponent[compIdStr]) {
323
254
  this.changedFilesPerComponent[compIdStr].push(filePath);
324
-
325
255
  _loader().default.stop();
326
-
327
256
  return {
328
257
  results: [],
329
258
  debounced: true
330
259
  };
331
260
  }
332
-
333
261
  this.changedFilesPerComponent[compIdStr] = [filePath];
334
262
  await this.sleep(DEBOUNCE_WAIT_MS);
335
263
  const files = this.changedFilesPerComponent[compIdStr];
336
264
  delete this.changedFilesPerComponent[compIdStr];
337
265
  const buildResults = await this.watchQueue.add(() => this.triggerCompChanges(componentId, files, initiator));
338
266
  const failureMsg = buildResults.length ? undefined : `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;
339
-
340
267
  _loader().default.stop();
341
-
342
268
  return {
343
269
  results: buildResults,
344
270
  files,
@@ -346,13 +272,9 @@ class Watcher {
346
272
  };
347
273
  } catch (err) {
348
274
  const msg = `watcher found an error while handling ${filePath}`;
349
-
350
275
  _logger().default.error(msg, err);
351
-
352
276
  _logger().default.console(`${msg}, ${err.message}`);
353
-
354
277
  _loader().default.stop();
355
-
356
278
  return {
357
279
  results: [],
358
280
  files: [filePath],
@@ -360,18 +282,16 @@ class Watcher {
360
282
  };
361
283
  }
362
284
  }
363
-
364
285
  async sleep(ms) {
365
286
  return new Promise(resolve => setTimeout(resolve, ms));
366
287
  }
288
+
367
289
  /**
368
290
  * if a file was added/remove, once the component is loaded, it changes .bitmap, and then the
369
291
  * entire cache is invalidated and the consumer is reloaded.
370
292
  * when a file just changed, no need to reload the consumer, it is enough to just delete the
371
293
  * component from the cache (both, workspace and consumer)
372
294
  */
373
-
374
-
375
295
  async triggerCompChanges(componentId, files, initiator) {
376
296
  this.workspace.clearComponentCache(componentId);
377
297
  const component = await this.workspace.get(componentId);
@@ -379,141 +299,106 @@ class Watcher {
379
299
  const compFiles = files.filter(filePath => {
380
300
  const relativeFile = this.getRelativePathLinux(filePath);
381
301
  const isCompFile = Boolean(componentMap.getFilesRelativeToConsumer().find(p => p === relativeFile));
382
-
383
302
  if (!isCompFile) {
384
303
  _logger().default.debug(`file ${filePath} is inside the component ${componentId.toString()} but configured to be ignored`);
385
304
  }
386
-
387
305
  return isCompFile;
388
306
  });
389
-
390
307
  if (!compFiles.length) {
391
308
  return [];
392
309
  }
393
-
394
310
  const buildResults = await this.executeWatchOperationsOnComponent(componentId, compFiles, true, initiator);
395
311
  return buildResults;
396
312
  }
313
+
397
314
  /**
398
315
  * if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.
399
316
  */
400
-
401
-
402
317
  async handleBitmapChanges() {
403
318
  const previewsTrackDirs = _objectSpread({}, this.trackDirs);
404
-
405
319
  await this.workspace._reloadConsumer();
406
320
  await this.setTrackDirs();
407
321
  const newDirs = (0, _lodash().difference)(Object.keys(this.trackDirs), Object.keys(previewsTrackDirs));
408
322
  const removedDirs = (0, _lodash().difference)(Object.keys(previewsTrackDirs), Object.keys(this.trackDirs));
409
323
  const results = [];
410
-
411
324
  if (newDirs.length) {
412
325
  this.fsWatcher.add(newDirs);
413
326
  const addResults = await (0, _pMapSeries().default)(newDirs, async dir => this.executeWatchOperationsOnComponent(this.trackDirs[dir], [], false));
414
327
  results.push(...addResults.flat());
415
328
  }
416
-
417
329
  if (removedDirs.length) {
418
330
  await this.fsWatcher.unwatch(removedDirs);
419
331
  await (0, _pMapSeries().default)(removedDirs, dir => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));
420
332
  }
421
-
422
333
  return results;
423
334
  }
424
-
425
335
  async executeWatchOperationsOnRemove(componentId) {
426
336
  _logger().default.debug(`running OnComponentRemove hook for ${_chalk().default.bold(componentId.toString())}`);
427
-
428
337
  this.pubsub.pub(_().WorkspaceAspect.id, this.creatOnComponentRemovedEvent(componentId.toString()));
429
338
  await this.workspace.triggerOnComponentRemove(componentId);
430
339
  }
431
-
432
340
  async executeWatchOperationsOnComponent(componentId, files, isChange = true, initiator) {
433
341
  if (this.isComponentWatchedExternally(componentId)) {
434
342
  // update capsule, once done, it automatically triggers the external watcher
435
343
  await this.workspace.get(componentId);
436
344
  return [];
437
345
  }
438
-
439
346
  const idStr = componentId.toString();
440
-
441
347
  if (isChange) {
442
348
  _logger().default.debug(`running OnComponentChange hook for ${_chalk().default.bold(idStr)}`);
443
-
444
349
  this.pubsub.pub(_().WorkspaceAspect.id, this.creatOnComponentChangeEvent(idStr, 'OnComponentChange'));
445
350
  } else {
446
351
  _logger().default.debug(`running OnComponentAdd hook for ${_chalk().default.bold(idStr)}`);
447
-
448
352
  this.pubsub.pub(_().WorkspaceAspect.id, this.creatOnComponentAddEvent(idStr, 'OnComponentAdd'));
449
353
  }
450
-
451
354
  let buildResults;
452
-
453
355
  try {
454
356
  buildResults = isChange ? await this.workspace.triggerOnComponentChange(componentId, files, initiator) : await this.workspace.triggerOnComponentAdd(componentId);
455
357
  } catch (err) {
456
358
  // do not exit the watch process on errors, just print them
457
359
  const msg = `found an issue during onComponentChange or onComponentAdd hooks`;
458
-
459
360
  _logger().default.error(msg, err);
460
-
461
361
  _logger().default.console(`\n${msg}: ${err.message || err}`);
462
-
463
362
  return [];
464
363
  }
465
-
466
364
  return buildResults;
467
365
  }
468
-
469
366
  creatOnComponentRemovedEvent(idStr) {
470
367
  return new (_events().OnComponentRemovedEvent)(Date.now(), idStr);
471
368
  }
472
-
473
369
  creatOnComponentChangeEvent(idStr, hook) {
474
370
  return new (_events().OnComponentChangeEvent)(Date.now(), idStr, hook);
475
371
  }
476
-
477
372
  creatOnComponentAddEvent(idStr, hook) {
478
373
  return new (_events().OnComponentAddEvent)(Date.now(), idStr, hook);
479
374
  }
480
-
481
375
  isComponentWatchedExternally(componentId) {
482
376
  const watcherData = this.multipleWatchers.find(m => m.componentIds.find(id => id.isEqual(componentId._legacy)));
483
-
484
377
  if (watcherData) {
485
378
  _logger().default.debug(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);
486
-
487
379
  return true;
488
380
  }
489
-
490
381
  return false;
491
382
  }
492
-
493
383
  getComponentIdByPath(filePath) {
494
384
  const relativeFile = this.getRelativePathLinux(filePath);
495
385
  const trackDir = this.findTrackDirByFilePathRecursively(relativeFile);
496
-
497
386
  if (!trackDir) {
498
387
  // the file is not part of any component. If it was a new component, or a new file of
499
388
  // existing component, then, handleBitmapChanges() should deal with it.
500
389
  return null;
501
390
  }
502
-
503
391
  return this.trackDirs[trackDir];
504
392
  }
505
-
506
393
  getRelativePathLinux(filePath) {
507
394
  return (0, _utils().pathNormalizeToLinux)(this.consumer.getPathRelativeToConsumer(filePath));
508
395
  }
509
-
510
396
  findTrackDirByFilePathRecursively(filePath) {
511
397
  if (this.trackDirs[filePath]) return filePath;
512
398
  const parentDir = (0, _path().dirname)(filePath);
513
399
  if (parentDir === filePath) return null;
514
400
  return this.findTrackDirByFilePathRecursively(parentDir);
515
401
  }
516
-
517
402
  async createWatcher(pathsToWatch) {
518
403
  this.fsWatcher = _chokidar().default.watch(pathsToWatch, {
519
404
  ignoreInitial: true,
@@ -528,14 +413,12 @@ class Watcher {
528
413
  if (path.includes(`${_path().sep}node_modules${_path().sep}`) || path.includes(`${_path().sep}package.json`)) {
529
414
  return true;
530
415
  }
531
-
532
416
  return false;
533
417
  },
534
418
  persistent: true,
535
419
  useFsEvents: false
536
420
  });
537
421
  }
538
-
539
422
  async setTrackDirs() {
540
423
  this.trackDirs = {};
541
424
  const componentsFromBitMap = this.consumer.bitMap.getAllComponents();
@@ -547,16 +430,13 @@ class Watcher {
547
430
  this.trackDirs[rootDir] = componentId;
548
431
  }));
549
432
  }
550
-
551
433
  async getPathsToWatch() {
552
434
  await this.setTrackDirs();
553
435
  const paths = [...Object.keys(this.trackDirs), _constants().BIT_MAP];
554
436
  const pathsAbsolute = paths.map(dir => this.consumer.toAbsolutePath(dir));
555
437
  return pathsAbsolute;
556
438
  }
557
-
558
439
  }
559
-
560
440
  exports.Watcher = Watcher;
561
441
 
562
442
  //# sourceMappingURL=watcher.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["DEBOUNCE_WAIT_MS","Watcher","constructor","workspace","pubsub","trackDirs","verbose","multipleWatchers","WatchQueue","consumer","watchAll","opts","msgs","watchOpts","pathsToWatch","getPathsToWatch","componentIds","Object","values","triggerOnPreWatch","createWatcher","watcher","fsWatcher","onStart","Promise","resolve","reject","process","env","BIT_LOG","onAll","on","onReady","filePath","startTime","Date","getTime","files","results","debounced","failureMsg","handleChange","initiator","duration","onChange","onAdd","p","onUnlink","err","onError","endsWith","BIT_MAP","bitMapChangesInProgress","buildResults","watchQueue","add","handleBitmapChanges","loader","stop","onIdle","componentId","getComponentIdByPath","logger","debug","compIdStr","toString","changedFilesPerComponent","push","sleep","triggerCompChanges","length","undefined","join","msg","error","console","message","ms","setTimeout","clearComponentCache","component","get","componentMap","state","_consumer","compFiles","filter","relativeFile","getRelativePathLinux","isCompFile","Boolean","getFilesRelativeToConsumer","find","executeWatchOperationsOnComponent","previewsTrackDirs","_reloadConsumer","setTrackDirs","newDirs","difference","keys","removedDirs","addResults","mapSeries","dir","flat","unwatch","executeWatchOperationsOnRemove","chalk","bold","pub","WorkspaceAspect","id","creatOnComponentRemovedEvent","triggerOnComponentRemove","isChange","isComponentWatchedExternally","idStr","creatOnComponentChangeEvent","creatOnComponentAddEvent","triggerOnComponentChange","triggerOnComponentAdd","OnComponentRemovedEvent","now","hook","OnComponentChangeEvent","OnComponentAddEvent","watcherData","m","isEqual","_legacy","compilerId","trackDir","findTrackDirByFilePathRecursively","pathNormalizeToLinux","getPathRelativeToConsumer","parentDir","dirname","chokidar","watch","ignoreInitial","ignored","path","includes","sep","persistent","useFsEvents","componentsFromBitMap","bitMap","getAllComponents","all","map","bitId","rootDir","getRootDir","Error","resolveComponentId","paths","pathsAbsolute","toAbsolutePath"],"sources":["watcher.ts"],"sourcesContent":["import { PubsubMain } from '@teambit/pubsub';\nimport { dirname, sep } from 'path';\nimport { difference } from 'lodash';\nimport { ComponentID } from '@teambit/component';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { BIT_MAP } from '@teambit/legacy/dist/constants';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport mapSeries from 'p-map-series';\nimport chalk from 'chalk';\nimport { ChildProcess } from 'child_process';\nimport chokidar, { FSWatcher } from 'chokidar';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { PathLinux, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport { WorkspaceAspect } from '../';\nimport { OnComponentChangeEvent, OnComponentAddEvent, OnComponentRemovedEvent } from '../events';\nimport { Workspace } from '../workspace';\nimport { OnComponentEventResult } from '../on-component-events';\nimport { CheckTypes } from './check-types';\nimport { WatchQueue } from './watch-queue';\n\nexport type WatcherProcessData = { watchProcess: ChildProcess; compilerId: BitId; componentIds: BitId[] };\n\nexport type EventMessages = {\n onAll: Function;\n onStart: Function;\n onReady: Function;\n onChange: Function;\n onAdd: Function;\n onUnlink: Function;\n onError: Function;\n};\n\nexport type WatchOptions = {\n msgs?: EventMessages;\n initiator?: CompilationInitiator;\n verbose?: boolean; // print watch events to the console. (also ts-server events if spawnTSServer is true)\n spawnTSServer?: boolean; // needed for check types and extract API/docs.\n checkTypes?: CheckTypes; // if enabled, the spawnTSServer becomes true.\n preCompile?: boolean; // whether compile all components before start watching\n};\n\nconst DEBOUNCE_WAIT_MS = 100;\n\nexport class Watcher {\n private fsWatcher: FSWatcher;\n private changedFilesPerComponent: { [componentId: string]: string[] } = {};\n private watchQueue = new WatchQueue();\n private bitMapChangesInProgress = false;\n constructor(\n private workspace: Workspace,\n private pubsub: PubsubMain,\n private trackDirs: { [dir: PathLinux]: ComponentID } = {},\n private verbose = false,\n private multipleWatchers: WatcherProcessData[] = []\n ) {}\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async watchAll(opts: WatchOptions) {\n const { msgs, ...watchOpts } = opts;\n // TODO: run build in the beginning of process (it's work like this in other envs)\n const pathsToWatch = await this.getPathsToWatch();\n const componentIds = Object.values(this.trackDirs);\n await this.workspace.triggerOnPreWatch(componentIds, watchOpts);\n await this.createWatcher(pathsToWatch);\n const watcher = this.fsWatcher;\n msgs?.onStart(this.workspace);\n\n return new Promise((resolve, reject) => {\n // prefix your command with \"BIT_LOG=*\" to see all watch events\n if (process.env.BIT_LOG) {\n // @ts-ignore\n if (msgs?.onAll) watcher.on('all', msgs?.onAll);\n }\n watcher.on('ready', () => {\n msgs?.onReady(this.workspace, this.trackDirs, this.verbose);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('change', async (filePath) => {\n const startTime = new Date().getTime();\n const { files, results, debounced, failureMsg } = await this.handleChange(filePath, opts?.initiator);\n if (debounced) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onChange(files, results, this.verbose, duration, failureMsg);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('add', async (filePath) => {\n const startTime = new Date().getTime();\n const { files, results, debounced, failureMsg } = await this.handleChange(filePath, opts?.initiator);\n if (debounced) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onAdd(files, results, this.verbose, duration, failureMsg);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('unlink', async (p) => {\n msgs?.onUnlink(p);\n await this.handleChange(p);\n });\n watcher.on('error', (err) => {\n msgs?.onError(err);\n reject(err);\n });\n });\n }\n\n /**\n * *** DEBOUNCING ***\n * some actions trigger multiple files changes at (almost) the same time. e.g. \"git pull\".\n * this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.\n * the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).\n * if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,\n * it'll only add the file to `this.changedFilesPerComponent` prop.\n * once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,\n * indicating the next file-change to start a new execution.\n *\n * implementation wise, `lodash.debounce` doesn't help here, because:\n * A) it doesn't return the results, unless \"leading\" option is true. here, it must be false, otherwise, it'll start\n * the execution immediately.\n * B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay\n * other components undesirably.\n *\n * *** QUEUE ***\n * the debouncing helps to not execute the same component multiple times concurrently. however, multiple components\n * and .bitmap changes execution can still be processed concurrently.\n * the following example explains why this is an issue.\n * compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.\n * all these changes get pulled at the same time by \"git pull\", as a result, the execution of compA and the .bitmap\n * happen at the same time.\n * during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this\n * id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.\n * after this change, the workspace doesn't have this id anymore, which will trigger an error.\n * to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all\n * other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).\n * once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.\n * in the example above, at this stage, the id will be resolved to compA@0.0.2.\n * one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at\n * the same time. (the same way is done when loading all components from the filesystem/scope).\n * this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the\n * .bitmap execution starts.\n */\n private async handleChange(\n filePath: string,\n initiator?: CompilationInitiator\n ): Promise<{\n results: OnComponentEventResult[];\n files?: string[];\n failureMsg?: string;\n debounced?: boolean;\n }> {\n try {\n if (filePath.endsWith(BIT_MAP)) {\n this.bitMapChangesInProgress = true;\n const buildResults = await this.watchQueue.add(() => this.handleBitmapChanges());\n this.bitMapChangesInProgress = false;\n loader.stop();\n return { results: buildResults, files: [filePath] };\n }\n if (this.bitMapChangesInProgress) {\n await this.watchQueue.onIdle();\n }\n const componentId = this.getComponentIdByPath(filePath);\n if (!componentId) {\n const failureMsg = `file ${filePath} is not part of any component, ignoring it`;\n logger.debug(failureMsg);\n loader.stop();\n return { results: [], files: [filePath], failureMsg };\n }\n const compIdStr = componentId.toString();\n if (this.changedFilesPerComponent[compIdStr]) {\n this.changedFilesPerComponent[compIdStr].push(filePath);\n loader.stop();\n return { results: [], debounced: true };\n }\n this.changedFilesPerComponent[compIdStr] = [filePath];\n await this.sleep(DEBOUNCE_WAIT_MS);\n const files = this.changedFilesPerComponent[compIdStr];\n delete this.changedFilesPerComponent[compIdStr];\n\n const buildResults = await this.watchQueue.add(() => this.triggerCompChanges(componentId, files, initiator));\n const failureMsg = buildResults.length\n ? undefined\n : `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;\n loader.stop();\n return { results: buildResults, files, failureMsg };\n } catch (err: any) {\n const msg = `watcher found an error while handling ${filePath}`;\n logger.error(msg, err);\n logger.console(`${msg}, ${err.message}`);\n loader.stop();\n return { results: [], files: [filePath], failureMsg: err.message };\n }\n }\n\n private async sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * if a file was added/remove, once the component is loaded, it changes .bitmap, and then the\n * entire cache is invalidated and the consumer is reloaded.\n * when a file just changed, no need to reload the consumer, it is enough to just delete the\n * component from the cache (both, workspace and consumer)\n */\n private async triggerCompChanges(\n componentId: ComponentID,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n this.workspace.clearComponentCache(componentId);\n const component = await this.workspace.get(componentId);\n const componentMap: ComponentMap = component.state._consumer.componentMap;\n const compFiles = files.filter((filePath) => {\n const relativeFile = this.getRelativePathLinux(filePath);\n const isCompFile = Boolean(componentMap.getFilesRelativeToConsumer().find((p) => p === relativeFile));\n if (!isCompFile) {\n logger.debug(`file ${filePath} is inside the component ${componentId.toString()} but configured to be ignored`);\n }\n return isCompFile;\n });\n if (!compFiles.length) {\n return [];\n }\n const buildResults = await this.executeWatchOperationsOnComponent(componentId, compFiles, true, initiator);\n return buildResults;\n }\n\n /**\n * if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.\n */\n private async handleBitmapChanges(): Promise<OnComponentEventResult[]> {\n const previewsTrackDirs = { ...this.trackDirs };\n await this.workspace._reloadConsumer();\n await this.setTrackDirs();\n const newDirs: string[] = difference(Object.keys(this.trackDirs), Object.keys(previewsTrackDirs));\n const removedDirs: string[] = difference(Object.keys(previewsTrackDirs), Object.keys(this.trackDirs));\n const results: OnComponentEventResult[] = [];\n if (newDirs.length) {\n this.fsWatcher.add(newDirs);\n const addResults = await mapSeries(newDirs, async (dir) =>\n this.executeWatchOperationsOnComponent(this.trackDirs[dir], [], false)\n );\n results.push(...addResults.flat());\n }\n if (removedDirs.length) {\n await this.fsWatcher.unwatch(removedDirs);\n await mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));\n }\n return results;\n }\n\n private async executeWatchOperationsOnRemove(componentId: ComponentID) {\n logger.debug(`running OnComponentRemove hook for ${chalk.bold(componentId.toString())}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentRemovedEvent(componentId.toString()));\n await this.workspace.triggerOnComponentRemove(componentId);\n }\n\n private async executeWatchOperationsOnComponent(\n componentId: ComponentID,\n files: string[],\n isChange = true,\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n if (this.isComponentWatchedExternally(componentId)) {\n // update capsule, once done, it automatically triggers the external watcher\n await this.workspace.get(componentId);\n return [];\n }\n const idStr = componentId.toString();\n\n if (isChange) {\n logger.debug(`running OnComponentChange hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentChangeEvent(idStr, 'OnComponentChange'));\n } else {\n logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentAddEvent(idStr, 'OnComponentAdd'));\n }\n\n let buildResults: OnComponentEventResult[];\n try {\n buildResults = isChange\n ? await this.workspace.triggerOnComponentChange(componentId, files, initiator)\n : await this.workspace.triggerOnComponentAdd(componentId);\n } catch (err: any) {\n // do not exit the watch process on errors, just print them\n const msg = `found an issue during onComponentChange or onComponentAdd hooks`;\n logger.error(msg, err);\n logger.console(`\\n${msg}: ${err.message || err}`);\n return [];\n }\n return buildResults;\n }\n\n private creatOnComponentRemovedEvent(idStr) {\n return new OnComponentRemovedEvent(Date.now(), idStr);\n }\n\n private creatOnComponentChangeEvent(idStr, hook) {\n return new OnComponentChangeEvent(Date.now(), idStr, hook);\n }\n\n private creatOnComponentAddEvent(idStr, hook) {\n return new OnComponentAddEvent(Date.now(), idStr, hook);\n }\n\n private isComponentWatchedExternally(componentId: ComponentID) {\n const watcherData = this.multipleWatchers.find((m) => m.componentIds.find((id) => id.isEqual(componentId._legacy)));\n if (watcherData) {\n logger.debug(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);\n return true;\n }\n return false;\n }\n\n private getComponentIdByPath(filePath: string): ComponentID | null {\n const relativeFile = this.getRelativePathLinux(filePath);\n const trackDir = this.findTrackDirByFilePathRecursively(relativeFile);\n if (!trackDir) {\n // the file is not part of any component. If it was a new component, or a new file of\n // existing component, then, handleBitmapChanges() should deal with it.\n return null;\n }\n return this.trackDirs[trackDir];\n }\n\n private getRelativePathLinux(filePath: string) {\n return pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(filePath));\n }\n\n private findTrackDirByFilePathRecursively(filePath: string): string | null {\n if (this.trackDirs[filePath]) return filePath;\n const parentDir = dirname(filePath);\n if (parentDir === filePath) return null;\n return this.findTrackDirByFilePathRecursively(parentDir);\n }\n\n private async createWatcher(pathsToWatch: string[]) {\n this.fsWatcher = chokidar.watch(pathsToWatch, {\n ignoreInitial: true,\n // Using the function way since the regular way not working as expected\n // It might be solved when upgrading to chokidar > 3.0.0\n // See:\n // https://github.com/paulmillr/chokidar/issues/773\n // https://github.com/paulmillr/chokidar/issues/492\n // https://github.com/paulmillr/chokidar/issues/724\n ignored: (path) => {\n // Ignore package.json temporarily since it cerates endless loop since it's re-written after each build\n if (path.includes(`${sep}node_modules${sep}`) || path.includes(`${sep}package.json`)) {\n return true;\n }\n return false;\n },\n persistent: true,\n useFsEvents: false,\n });\n }\n\n async setTrackDirs() {\n this.trackDirs = {};\n const componentsFromBitMap = this.consumer.bitMap.getAllComponents();\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const rootDir = componentMap.getRootDir();\n if (!rootDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[rootDir] = componentId;\n })\n );\n }\n\n private async getPathsToWatch(): Promise<PathOsBasedAbsolute[]> {\n await this.setTrackDirs();\n const paths = [...Object.keys(this.trackDirs), BIT_MAP];\n const pathsAbsolute = paths.map((dir) => this.consumer.toAbsolutePath(dir));\n return pathsAbsolute;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAuBA,MAAMA,gBAAgB,GAAG,GAAzB;;AAEO,MAAMC,OAAN,CAAc;EAKnBC,WAAW,CACDC,SADC,EAEDC,MAFC,EAGDC,SAA4C,GAAG,EA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GAAEC,WAAI,cAArB,CAAjD,EAAsF;UACpF,OAAO,IAAP;QACD;;QACD,OAAO,KAAP;MACD,CAd2C;MAe5CC,UAAU,EAAE,IAfgC;MAgB5CC,WAAW,EAAE;IAhB+B,CAA7B,CAAjB;EAkBD;;EAEiB,MAAZjD,YAAY,GAAG;IACnB,KAAK3F,SAAL,GAAiB,EAAjB;IACA,MAAM6I,oBAAoB,GAAG,KAAKzI,QAAL,CAAc0I,MAAd,CAAqBC,gBAArB,EAA7B;IACA,MAAM5H,OAAO,CAAC6H,GAAR,CACJH,oBAAoB,CAACI,GAArB,CAAyB,MAAOpE,YAAP,IAAwB;MAC/C,MAAMqE,KAAK,GAAGrE,YAAY,CAAC6B,EAA3B;MACA,MAAMyC,OAAO,GAAGtE,YAAY,CAACuE,UAAb,EAAhB;MACA,IAAI,CAACD,OAAL,EAAc,MAAM,IAAIE,KAAJ,CAAW,GAAEH,KAAK,CAACtF,QAAN,EAAiB,8CAA9B,CAAN;MACd,MAAML,WAAW,GAAG,MAAM,KAAKzD,SAAL,CAAewJ,kBAAf,CAAkCJ,KAAlC,CAA1B;MACA,KAAKlJ,SAAL,CAAemJ,OAAf,IAA0B5F,WAA1B;IACD,CAND,CADI,CAAN;EASD;;EAE4B,MAAf7C,eAAe,GAAmC;IAC9D,MAAM,KAAKiF,YAAL,EAAN;IACA,MAAM4D,KAAK,GAAG,CAAC,GAAG3I,MAAM,CAACkF,IAAP,CAAY,KAAK9F,SAAjB,CAAJ,EAAiC8C,oBAAjC,CAAd;IACA,MAAM0G,aAAa,GAAGD,KAAK,CAACN,GAAN,CAAW/C,GAAD,IAAS,KAAK9F,QAAL,CAAcqJ,cAAd,CAA6BvD,GAA7B,CAAnB,CAAtB;IACA,OAAOsD,aAAP;EACD;;AAlVkB"}
1
+ {"version":3,"names":["DEBOUNCE_WAIT_MS","Watcher","constructor","workspace","pubsub","trackDirs","verbose","multipleWatchers","WatchQueue","consumer","watchAll","opts","msgs","watchOpts","pathsToWatch","getPathsToWatch","componentIds","Object","values","triggerOnPreWatch","createWatcher","watcher","fsWatcher","onStart","Promise","resolve","reject","process","env","BIT_LOG","onAll","on","onReady","filePath","startTime","Date","getTime","files","results","debounced","failureMsg","handleChange","initiator","duration","onChange","onAdd","p","onUnlink","err","onError","endsWith","BIT_MAP","bitMapChangesInProgress","buildResults","watchQueue","add","handleBitmapChanges","loader","stop","onIdle","componentId","getComponentIdByPath","logger","debug","compIdStr","toString","changedFilesPerComponent","push","sleep","triggerCompChanges","length","undefined","join","msg","error","console","message","ms","setTimeout","clearComponentCache","component","get","componentMap","state","_consumer","compFiles","filter","relativeFile","getRelativePathLinux","isCompFile","Boolean","getFilesRelativeToConsumer","find","executeWatchOperationsOnComponent","previewsTrackDirs","_reloadConsumer","setTrackDirs","newDirs","difference","keys","removedDirs","addResults","mapSeries","dir","flat","unwatch","executeWatchOperationsOnRemove","chalk","bold","pub","WorkspaceAspect","id","creatOnComponentRemovedEvent","triggerOnComponentRemove","isChange","isComponentWatchedExternally","idStr","creatOnComponentChangeEvent","creatOnComponentAddEvent","triggerOnComponentChange","triggerOnComponentAdd","OnComponentRemovedEvent","now","hook","OnComponentChangeEvent","OnComponentAddEvent","watcherData","m","isEqual","_legacy","compilerId","trackDir","findTrackDirByFilePathRecursively","pathNormalizeToLinux","getPathRelativeToConsumer","parentDir","dirname","chokidar","watch","ignoreInitial","ignored","path","includes","sep","persistent","useFsEvents","componentsFromBitMap","bitMap","getAllComponents","all","map","bitId","rootDir","getRootDir","Error","resolveComponentId","paths","pathsAbsolute","toAbsolutePath"],"sources":["watcher.ts"],"sourcesContent":["import { PubsubMain } from '@teambit/pubsub';\nimport { dirname, sep } from 'path';\nimport { difference } from 'lodash';\nimport { ComponentID } from '@teambit/component';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { BIT_MAP } from '@teambit/legacy/dist/constants';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport mapSeries from 'p-map-series';\nimport chalk from 'chalk';\nimport { ChildProcess } from 'child_process';\nimport chokidar, { FSWatcher } from 'chokidar';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { PathLinux, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport { WorkspaceAspect } from '../';\nimport { OnComponentChangeEvent, OnComponentAddEvent, OnComponentRemovedEvent } from '../events';\nimport { Workspace } from '../workspace';\nimport { OnComponentEventResult } from '../on-component-events';\nimport { CheckTypes } from './check-types';\nimport { WatchQueue } from './watch-queue';\n\nexport type WatcherProcessData = { watchProcess: ChildProcess; compilerId: BitId; componentIds: BitId[] };\n\nexport type EventMessages = {\n onAll: Function;\n onStart: Function;\n onReady: Function;\n onChange: Function;\n onAdd: Function;\n onUnlink: Function;\n onError: Function;\n};\n\nexport type WatchOptions = {\n msgs?: EventMessages;\n initiator?: CompilationInitiator;\n verbose?: boolean; // print watch events to the console. (also ts-server events if spawnTSServer is true)\n spawnTSServer?: boolean; // needed for check types and extract API/docs.\n checkTypes?: CheckTypes; // if enabled, the spawnTSServer becomes true.\n preCompile?: boolean; // whether compile all components before start watching\n};\n\nconst DEBOUNCE_WAIT_MS = 100;\n\nexport class Watcher {\n private fsWatcher: FSWatcher;\n private changedFilesPerComponent: { [componentId: string]: string[] } = {};\n private watchQueue = new WatchQueue();\n private bitMapChangesInProgress = false;\n constructor(\n private workspace: Workspace,\n private pubsub: PubsubMain,\n private trackDirs: { [dir: PathLinux]: ComponentID } = {},\n private verbose = false,\n private multipleWatchers: WatcherProcessData[] = []\n ) {}\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async watchAll(opts: WatchOptions) {\n const { msgs, ...watchOpts } = opts;\n // TODO: run build in the beginning of process (it's work like this in other envs)\n const pathsToWatch = await this.getPathsToWatch();\n const componentIds = Object.values(this.trackDirs);\n await this.workspace.triggerOnPreWatch(componentIds, watchOpts);\n await this.createWatcher(pathsToWatch);\n const watcher = this.fsWatcher;\n msgs?.onStart(this.workspace);\n\n return new Promise((resolve, reject) => {\n // prefix your command with \"BIT_LOG=*\" to see all watch events\n if (process.env.BIT_LOG) {\n // @ts-ignore\n if (msgs?.onAll) watcher.on('all', msgs?.onAll);\n }\n watcher.on('ready', () => {\n msgs?.onReady(this.workspace, this.trackDirs, this.verbose);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('change', async (filePath) => {\n const startTime = new Date().getTime();\n const { files, results, debounced, failureMsg } = await this.handleChange(filePath, opts?.initiator);\n if (debounced) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onChange(files, results, this.verbose, duration, failureMsg);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('add', async (filePath) => {\n const startTime = new Date().getTime();\n const { files, results, debounced, failureMsg } = await this.handleChange(filePath, opts?.initiator);\n if (debounced) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onAdd(files, results, this.verbose, duration, failureMsg);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('unlink', async (p) => {\n msgs?.onUnlink(p);\n await this.handleChange(p);\n });\n watcher.on('error', (err) => {\n msgs?.onError(err);\n reject(err);\n });\n });\n }\n\n /**\n * *** DEBOUNCING ***\n * some actions trigger multiple files changes at (almost) the same time. e.g. \"git pull\".\n * this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.\n * the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).\n * if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,\n * it'll only add the file to `this.changedFilesPerComponent` prop.\n * once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,\n * indicating the next file-change to start a new execution.\n *\n * implementation wise, `lodash.debounce` doesn't help here, because:\n * A) it doesn't return the results, unless \"leading\" option is true. here, it must be false, otherwise, it'll start\n * the execution immediately.\n * B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay\n * other components undesirably.\n *\n * *** QUEUE ***\n * the debouncing helps to not execute the same component multiple times concurrently. however, multiple components\n * and .bitmap changes execution can still be processed concurrently.\n * the following example explains why this is an issue.\n * compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.\n * all these changes get pulled at the same time by \"git pull\", as a result, the execution of compA and the .bitmap\n * happen at the same time.\n * during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this\n * id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.\n * after this change, the workspace doesn't have this id anymore, which will trigger an error.\n * to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all\n * other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).\n * once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.\n * in the example above, at this stage, the id will be resolved to compA@0.0.2.\n * one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at\n * the same time. (the same way is done when loading all components from the filesystem/scope).\n * this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the\n * .bitmap execution starts.\n */\n private async handleChange(\n filePath: string,\n initiator?: CompilationInitiator\n ): Promise<{\n results: OnComponentEventResult[];\n files?: string[];\n failureMsg?: string;\n debounced?: boolean;\n }> {\n try {\n if (filePath.endsWith(BIT_MAP)) {\n this.bitMapChangesInProgress = true;\n const buildResults = await this.watchQueue.add(() => this.handleBitmapChanges());\n this.bitMapChangesInProgress = false;\n loader.stop();\n return { results: buildResults, files: [filePath] };\n }\n if (this.bitMapChangesInProgress) {\n await this.watchQueue.onIdle();\n }\n const componentId = this.getComponentIdByPath(filePath);\n if (!componentId) {\n const failureMsg = `file ${filePath} is not part of any component, ignoring it`;\n logger.debug(failureMsg);\n loader.stop();\n return { results: [], files: [filePath], failureMsg };\n }\n const compIdStr = componentId.toString();\n if (this.changedFilesPerComponent[compIdStr]) {\n this.changedFilesPerComponent[compIdStr].push(filePath);\n loader.stop();\n return { results: [], debounced: true };\n }\n this.changedFilesPerComponent[compIdStr] = [filePath];\n await this.sleep(DEBOUNCE_WAIT_MS);\n const files = this.changedFilesPerComponent[compIdStr];\n delete this.changedFilesPerComponent[compIdStr];\n\n const buildResults = await this.watchQueue.add(() => this.triggerCompChanges(componentId, files, initiator));\n const failureMsg = buildResults.length\n ? undefined\n : `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;\n loader.stop();\n return { results: buildResults, files, failureMsg };\n } catch (err: any) {\n const msg = `watcher found an error while handling ${filePath}`;\n logger.error(msg, err);\n logger.console(`${msg}, ${err.message}`);\n loader.stop();\n return { results: [], files: [filePath], failureMsg: err.message };\n }\n }\n\n private async sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * if a file was added/remove, once the component is loaded, it changes .bitmap, and then the\n * entire cache is invalidated and the consumer is reloaded.\n * when a file just changed, no need to reload the consumer, it is enough to just delete the\n * component from the cache (both, workspace and consumer)\n */\n private async triggerCompChanges(\n componentId: ComponentID,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n this.workspace.clearComponentCache(componentId);\n const component = await this.workspace.get(componentId);\n const componentMap: ComponentMap = component.state._consumer.componentMap;\n const compFiles = files.filter((filePath) => {\n const relativeFile = this.getRelativePathLinux(filePath);\n const isCompFile = Boolean(componentMap.getFilesRelativeToConsumer().find((p) => p === relativeFile));\n if (!isCompFile) {\n logger.debug(`file ${filePath} is inside the component ${componentId.toString()} but configured to be ignored`);\n }\n return isCompFile;\n });\n if (!compFiles.length) {\n return [];\n }\n const buildResults = await this.executeWatchOperationsOnComponent(componentId, compFiles, true, initiator);\n return buildResults;\n }\n\n /**\n * if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.\n */\n private async handleBitmapChanges(): Promise<OnComponentEventResult[]> {\n const previewsTrackDirs = { ...this.trackDirs };\n await this.workspace._reloadConsumer();\n await this.setTrackDirs();\n const newDirs: string[] = difference(Object.keys(this.trackDirs), Object.keys(previewsTrackDirs));\n const removedDirs: string[] = difference(Object.keys(previewsTrackDirs), Object.keys(this.trackDirs));\n const results: OnComponentEventResult[] = [];\n if (newDirs.length) {\n this.fsWatcher.add(newDirs);\n const addResults = await mapSeries(newDirs, async (dir) =>\n this.executeWatchOperationsOnComponent(this.trackDirs[dir], [], false)\n );\n results.push(...addResults.flat());\n }\n if (removedDirs.length) {\n await this.fsWatcher.unwatch(removedDirs);\n await mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));\n }\n return results;\n }\n\n private async executeWatchOperationsOnRemove(componentId: ComponentID) {\n logger.debug(`running OnComponentRemove hook for ${chalk.bold(componentId.toString())}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentRemovedEvent(componentId.toString()));\n await this.workspace.triggerOnComponentRemove(componentId);\n }\n\n private async executeWatchOperationsOnComponent(\n componentId: ComponentID,\n files: string[],\n isChange = true,\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n if (this.isComponentWatchedExternally(componentId)) {\n // update capsule, once done, it automatically triggers the external watcher\n await this.workspace.get(componentId);\n return [];\n }\n const idStr = componentId.toString();\n\n if (isChange) {\n logger.debug(`running OnComponentChange hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentChangeEvent(idStr, 'OnComponentChange'));\n } else {\n logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentAddEvent(idStr, 'OnComponentAdd'));\n }\n\n let buildResults: OnComponentEventResult[];\n try {\n buildResults = isChange\n ? await this.workspace.triggerOnComponentChange(componentId, files, initiator)\n : await this.workspace.triggerOnComponentAdd(componentId);\n } catch (err: any) {\n // do not exit the watch process on errors, just print them\n const msg = `found an issue during onComponentChange or onComponentAdd hooks`;\n logger.error(msg, err);\n logger.console(`\\n${msg}: ${err.message || err}`);\n return [];\n }\n return buildResults;\n }\n\n private creatOnComponentRemovedEvent(idStr) {\n return new OnComponentRemovedEvent(Date.now(), idStr);\n }\n\n private creatOnComponentChangeEvent(idStr, hook) {\n return new OnComponentChangeEvent(Date.now(), idStr, hook);\n }\n\n private creatOnComponentAddEvent(idStr, hook) {\n return new OnComponentAddEvent(Date.now(), idStr, hook);\n }\n\n private isComponentWatchedExternally(componentId: ComponentID) {\n const watcherData = this.multipleWatchers.find((m) => m.componentIds.find((id) => id.isEqual(componentId._legacy)));\n if (watcherData) {\n logger.debug(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);\n return true;\n }\n return false;\n }\n\n private getComponentIdByPath(filePath: string): ComponentID | null {\n const relativeFile = this.getRelativePathLinux(filePath);\n const trackDir = this.findTrackDirByFilePathRecursively(relativeFile);\n if (!trackDir) {\n // the file is not part of any component. If it was a new component, or a new file of\n // existing component, then, handleBitmapChanges() should deal with it.\n return null;\n }\n return this.trackDirs[trackDir];\n }\n\n private getRelativePathLinux(filePath: string) {\n return pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(filePath));\n }\n\n private findTrackDirByFilePathRecursively(filePath: string): string | null {\n if (this.trackDirs[filePath]) return filePath;\n const parentDir = dirname(filePath);\n if (parentDir === filePath) return null;\n return this.findTrackDirByFilePathRecursively(parentDir);\n }\n\n private async createWatcher(pathsToWatch: string[]) {\n this.fsWatcher = chokidar.watch(pathsToWatch, {\n ignoreInitial: true,\n // Using the function way since the regular way not working as expected\n // It might be solved when upgrading to chokidar > 3.0.0\n // See:\n // https://github.com/paulmillr/chokidar/issues/773\n // https://github.com/paulmillr/chokidar/issues/492\n // https://github.com/paulmillr/chokidar/issues/724\n ignored: (path) => {\n // Ignore package.json temporarily since it cerates endless loop since it's re-written after each build\n if (path.includes(`${sep}node_modules${sep}`) || path.includes(`${sep}package.json`)) {\n return true;\n }\n return false;\n },\n persistent: true,\n useFsEvents: false,\n });\n }\n\n async setTrackDirs() {\n this.trackDirs = {};\n const componentsFromBitMap = this.consumer.bitMap.getAllComponents();\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const rootDir = componentMap.getRootDir();\n if (!rootDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[rootDir] = componentId;\n })\n );\n }\n\n private async getPathsToWatch(): Promise<PathOsBasedAbsolute[]> {\n await this.setTrackDirs();\n const paths = [...Object.keys(this.trackDirs), BIT_MAP];\n const pathsAbsolute = paths.map((dir) => this.consumer.toAbsolutePath(dir));\n return pathsAbsolute;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA2C;AAAA;AAuB3C,MAAMA,gBAAgB,GAAG,GAAG;AAErB,MAAMC,OAAO,CAAC;EAKnBC,WAAW,CACDC,SAAoB,EACpBC,MAAkB,EAClBC,SAA4C,GAAG,CAAC,CAAC,EACjDC,OAAO,GAAG,KAAK,EACfC,gBAAsC,GAAG,EAAE,EACnD;IAAA,KALQJ,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,MAAkB,GAAlBA,MAAkB;IAAA,KAClBC,SAA4C,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