@teambit/workspace 0.0.757 → 0.0.758
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/envs-subcommands/envs-replace.cmd.d.ts +8 -0
- package/dist/envs-subcommands/envs-replace.cmd.js +11 -0
- package/dist/envs-subcommands/envs-replace.cmd.js.map +1 -1
- package/dist/watch/watch-queue.d.ts +8 -0
- package/dist/watch/watch-queue.js +57 -0
- package/dist/watch/watch-queue.js.map +1 -0
- package/dist/watch/watcher.d.ts +21 -0
- package/dist/watch/watcher.js +39 -2
- package/dist/watch/watcher.js.map +1 -1
- package/envs-subcommands/envs-replace.cmd.ts +10 -0
- package/package-tar/teambit-workspace-0.0.758.tgz +0 -0
- package/package.json +32 -31
- package/{preview-1654831618244.js → preview-1654918011878.js} +2 -2
- package/watch/watch-queue.ts +17 -0
- package/watch/watcher.ts +29 -3
- package/package-tar/teambit-workspace-0.0.757.tgz +0 -0
|
@@ -6,6 +6,14 @@ export declare class EnvsReplaceCmd implements Command {
|
|
|
6
6
|
description: string;
|
|
7
7
|
options: never[];
|
|
8
8
|
group: string;
|
|
9
|
+
arguments: {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}[];
|
|
13
|
+
examples: {
|
|
14
|
+
cmd: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}[];
|
|
9
17
|
constructor(workspace: Workspace);
|
|
10
18
|
report([oldEnv, env]: [string, string]): Promise<string>;
|
|
11
19
|
}
|
|
@@ -38,6 +38,17 @@ class EnvsReplaceCmd {
|
|
|
38
38
|
(0, _defineProperty2().default)(this, "description", 'replace an existing env with another env for all components using the old env');
|
|
39
39
|
(0, _defineProperty2().default)(this, "options", []);
|
|
40
40
|
(0, _defineProperty2().default)(this, "group", 'development');
|
|
41
|
+
(0, _defineProperty2().default)(this, "arguments", [{
|
|
42
|
+
name: 'old-env',
|
|
43
|
+
description: 'current environment id'
|
|
44
|
+
}, {
|
|
45
|
+
name: 'new-env',
|
|
46
|
+
description: 'target environment id'
|
|
47
|
+
}]);
|
|
48
|
+
(0, _defineProperty2().default)(this, "examples", [{
|
|
49
|
+
cmd: 'replace teambit.harmony/aspect teambit.harmony/node',
|
|
50
|
+
description: 'all components using aspect env, will be replaced with node env'
|
|
51
|
+
}]);
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
async report([oldEnv, env]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["EnvsReplaceCmd","constructor","workspace","report","oldEnv","env","envId","resolveComponentId","components","getComponentsUsingEnv","componentIds","map","comp","id","setEnvToComponents","chalk","bold","toString","compId","join"],"sources":["envs-replace.cmd.ts"],"sourcesContent":["import { Command } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from '../workspace';\n\nexport class EnvsReplaceCmd implements Command {\n name = 'replace <old-env> <new-env>';\n description = 'replace an existing env with another env for all components using the old env';\n options = [];\n group = 'development';\n\n constructor(private workspace: Workspace) {}\n\n async report([oldEnv, env]: [string, string]) {\n const envId = await this.workspace.resolveComponentId(env);\n const components = await this.workspace.getComponentsUsingEnv(oldEnv, true, true);\n const componentIds = components.map((comp) => comp.id);\n await this.workspace.setEnvToComponents(envId, componentIds);\n return `added ${chalk.bold(envId.toString())} env to the following component(s):\n${componentIds.map((compId) => compId.toString()).join('\\n')}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;
|
|
1
|
+
{"version":3,"names":["EnvsReplaceCmd","constructor","workspace","name","description","cmd","report","oldEnv","env","envId","resolveComponentId","components","getComponentsUsingEnv","componentIds","map","comp","id","setEnvToComponents","chalk","bold","toString","compId","join"],"sources":["envs-replace.cmd.ts"],"sourcesContent":["import { Command } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from '../workspace';\n\nexport class EnvsReplaceCmd implements Command {\n name = 'replace <old-env> <new-env>';\n description = 'replace an existing env with another env for all components using the old env';\n options = [];\n group = 'development';\n arguments = [\n { name: 'old-env', description: 'current environment id' },\n { name: 'new-env', description: 'target environment id' },\n ];\n examples = [\n {\n cmd: 'replace teambit.harmony/aspect teambit.harmony/node',\n description: 'all components using aspect env, will be replaced with node env',\n },\n ];\n\n constructor(private workspace: Workspace) {}\n\n async report([oldEnv, env]: [string, string]) {\n const envId = await this.workspace.resolveComponentId(env);\n const components = await this.workspace.getComponentsUsingEnv(oldEnv, true, true);\n const componentIds = components.map((comp) => comp.id);\n await this.workspace.setEnvToComponents(envId, componentIds);\n return `added ${chalk.bold(envId.toString())} env to the following component(s):\n${componentIds.map((compId) => compId.toString()).join('\\n')}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;EAgB7CC,WAAW,CAASC,SAAT,EAA+B;IAAA,KAAtBA,SAAsB,GAAtBA,SAAsB;IAAA,8CAfnC,6BAemC;IAAA,qDAd5B,+EAc4B;IAAA,iDAbhC,EAagC;IAAA,+CAZlC,aAYkC;IAAA,mDAX9B,CACV;MAAEC,IAAI,EAAE,SAAR;MAAmBC,WAAW,EAAE;IAAhC,CADU,EAEV;MAAED,IAAI,EAAE,SAAR;MAAmBC,WAAW,EAAE;IAAhC,CAFU,CAW8B;IAAA,kDAP/B,CACT;MACEC,GAAG,EAAE,qDADP;MAEED,WAAW,EAAE;IAFf,CADS,CAO+B;EAAE;;EAEhC,MAANE,MAAM,CAAC,CAACC,MAAD,EAASC,GAAT,CAAD,EAAkC;IAC5C,MAAMC,KAAK,GAAG,MAAM,KAAKP,SAAL,CAAeQ,kBAAf,CAAkCF,GAAlC,CAApB;IACA,MAAMG,UAAU,GAAG,MAAM,KAAKT,SAAL,CAAeU,qBAAf,CAAqCL,MAArC,EAA6C,IAA7C,EAAmD,IAAnD,CAAzB;IACA,MAAMM,YAAY,GAAGF,UAAU,CAACG,GAAX,CAAgBC,IAAD,IAAUA,IAAI,CAACC,EAA9B,CAArB;IACA,MAAM,KAAKd,SAAL,CAAee,kBAAf,CAAkCR,KAAlC,EAAyCI,YAAzC,CAAN;IACA,OAAQ,SAAQK,gBAAA,CAAMC,IAAN,CAAWV,KAAK,CAACW,QAAN,EAAX,CAA6B;AACjD,EAAEP,YAAY,CAACC,GAAb,CAAkBO,MAAD,IAAYA,MAAM,CAACD,QAAP,EAA7B,EAAgDE,IAAhD,CAAqD,IAArD,CAA2D,EADzD;EAED;;AAzB4C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
export declare class WatchQueue {
|
|
3
|
+
private queue;
|
|
4
|
+
constructor(concurrency?: number);
|
|
5
|
+
getQueue(): PQueue<import("p-queue/dist/priority-queue").default, import("p-queue").DefaultAddOptions>;
|
|
6
|
+
add<T>(fn: () => T, priority?: number): Promise<T>;
|
|
7
|
+
onIdle(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.WatchQueue = void 0;
|
|
9
|
+
|
|
10
|
+
function _defineProperty2() {
|
|
11
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
|
|
13
|
+
_defineProperty2 = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _pQueue() {
|
|
21
|
+
const data = _interopRequireDefault(require("p-queue"));
|
|
22
|
+
|
|
23
|
+
_pQueue = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class WatchQueue {
|
|
31
|
+
constructor(concurrency = 1) {
|
|
32
|
+
(0, _defineProperty2().default)(this, "queue", void 0);
|
|
33
|
+
this.queue = new (_pQueue().default)({
|
|
34
|
+
concurrency,
|
|
35
|
+
autoStart: true
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getQueue() {
|
|
40
|
+
return this.queue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
add(fn, priority) {
|
|
44
|
+
return this.queue.add(fn, {
|
|
45
|
+
priority
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onIdle() {
|
|
50
|
+
return this.queue.onIdle();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.WatchQueue = WatchQueue;
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=watch-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WatchQueue","constructor","concurrency","queue","PQueue","autoStart","getQueue","add","fn","priority","onIdle"],"sources":["watch-queue.ts"],"sourcesContent":["import PQueue from 'p-queue';\n\nexport class WatchQueue {\n private queue: PQueue;\n constructor(concurrency = 1) {\n this.queue = new PQueue({ concurrency, autoStart: true });\n }\n getQueue() {\n return this.queue;\n }\n add<T>(fn: () => T, priority?: number): Promise<T> {\n return this.queue.add(fn, { priority });\n }\n onIdle(): Promise<void> {\n return this.queue.onIdle();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,UAAN,CAAiB;EAEtBC,WAAW,CAACC,WAAW,GAAG,CAAf,EAAkB;IAAA;IAC3B,KAAKC,KAAL,GAAa,KAAIC,iBAAJ,EAAW;MAAEF,WAAF;MAAeG,SAAS,EAAE;IAA1B,CAAX,CAAb;EACD;;EACDC,QAAQ,GAAG;IACT,OAAO,KAAKH,KAAZ;EACD;;EACDI,GAAG,CAAIC,EAAJ,EAAiBC,QAAjB,EAAgD;IACjD,OAAO,KAAKN,KAAL,CAAWI,GAAX,CAAeC,EAAf,EAAmB;MAAEC;IAAF,CAAnB,CAAP;EACD;;EACDC,MAAM,GAAkB;IACtB,OAAO,KAAKP,KAAL,CAAWO,MAAX,EAAP;EACD;;AAbqB"}
|
package/dist/watch/watcher.d.ts
CHANGED
|
@@ -38,12 +38,15 @@ export declare class Watcher {
|
|
|
38
38
|
private multipleWatchers;
|
|
39
39
|
private fsWatcher;
|
|
40
40
|
private changedFilesPerComponent;
|
|
41
|
+
private watchQueue;
|
|
42
|
+
private bitMapChangesInProgress;
|
|
41
43
|
constructor(workspace: Workspace, pubsub: PubsubMain, trackDirs?: {
|
|
42
44
|
[dir: PathLinux]: ComponentID;
|
|
43
45
|
}, verbose?: boolean, multipleWatchers?: WatcherProcessData[]);
|
|
44
46
|
get consumer(): Consumer;
|
|
45
47
|
watchAll(opts: WatchOptions): Promise<unknown>;
|
|
46
48
|
/**
|
|
49
|
+
* *** DEBOUNCING ***
|
|
47
50
|
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
48
51
|
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
49
52
|
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
@@ -58,6 +61,24 @@ export declare class Watcher {
|
|
|
58
61
|
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
59
62
|
* other components undesirably.
|
|
60
63
|
*
|
|
64
|
+
* *** QUEUE ***
|
|
65
|
+
* the debouncing helps to not execute the same component multiple times concurrently. however, multiple components
|
|
66
|
+
* and .bitmap changes execution can still be processed concurrently.
|
|
67
|
+
* the following example explains why this is an issue.
|
|
68
|
+
* compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.
|
|
69
|
+
* all these changes get pulled at the same time by "git pull", as a result, the execution of compA and the .bitmap
|
|
70
|
+
* happen at the same time.
|
|
71
|
+
* during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this
|
|
72
|
+
* id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.
|
|
73
|
+
* after this change, the workspace doesn't have this id anymore, which will trigger an error.
|
|
74
|
+
* to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all
|
|
75
|
+
* other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).
|
|
76
|
+
* once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.
|
|
77
|
+
* in the example above, at this stage, the id will be resolved to compA@0.0.2.
|
|
78
|
+
* one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at
|
|
79
|
+
* the same time. (the same way is done when loading all components from the filesystem/scope).
|
|
80
|
+
* this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the
|
|
81
|
+
* .bitmap execution starts.
|
|
61
82
|
*/
|
|
62
83
|
private handleChange;
|
|
63
84
|
private sleep;
|
package/dist/watch/watcher.js
CHANGED
|
@@ -145,6 +145,16 @@ function _events() {
|
|
|
145
145
|
return data;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
function _watchQueue() {
|
|
149
|
+
const data = require("./watch-queue");
|
|
150
|
+
|
|
151
|
+
_watchQueue = function () {
|
|
152
|
+
return data;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
|
|
148
158
|
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; }
|
|
149
159
|
|
|
150
160
|
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; }
|
|
@@ -160,6 +170,8 @@ class Watcher {
|
|
|
160
170
|
this.multipleWatchers = multipleWatchers;
|
|
161
171
|
(0, _defineProperty2().default)(this, "fsWatcher", void 0);
|
|
162
172
|
(0, _defineProperty2().default)(this, "changedFilesPerComponent", {});
|
|
173
|
+
(0, _defineProperty2().default)(this, "watchQueue", new (_watchQueue().WatchQueue)());
|
|
174
|
+
(0, _defineProperty2().default)(this, "bitMapChangesInProgress", false);
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
get consumer() {
|
|
@@ -234,6 +246,7 @@ class Watcher {
|
|
|
234
246
|
});
|
|
235
247
|
}
|
|
236
248
|
/**
|
|
249
|
+
* *** DEBOUNCING ***
|
|
237
250
|
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
238
251
|
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
239
252
|
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
@@ -248,13 +261,33 @@ class Watcher {
|
|
|
248
261
|
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
249
262
|
* other components undesirably.
|
|
250
263
|
*
|
|
264
|
+
* *** QUEUE ***
|
|
265
|
+
* the debouncing helps to not execute the same component multiple times concurrently. however, multiple components
|
|
266
|
+
* and .bitmap changes execution can still be processed concurrently.
|
|
267
|
+
* the following example explains why this is an issue.
|
|
268
|
+
* compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.
|
|
269
|
+
* all these changes get pulled at the same time by "git pull", as a result, the execution of compA and the .bitmap
|
|
270
|
+
* happen at the same time.
|
|
271
|
+
* during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this
|
|
272
|
+
* id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.
|
|
273
|
+
* after this change, the workspace doesn't have this id anymore, which will trigger an error.
|
|
274
|
+
* to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all
|
|
275
|
+
* other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).
|
|
276
|
+
* once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.
|
|
277
|
+
* in the example above, at this stage, the id will be resolved to compA@0.0.2.
|
|
278
|
+
* one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at
|
|
279
|
+
* the same time. (the same way is done when loading all components from the filesystem/scope).
|
|
280
|
+
* this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the
|
|
281
|
+
* .bitmap execution starts.
|
|
251
282
|
*/
|
|
252
283
|
|
|
253
284
|
|
|
254
285
|
async handleChange(filePath, initiator) {
|
|
255
286
|
try {
|
|
256
287
|
if (filePath.endsWith(_constants().BIT_MAP)) {
|
|
257
|
-
|
|
288
|
+
this.bitMapChangesInProgress = true;
|
|
289
|
+
const buildResults = await this.watchQueue.add(() => this.handleBitmapChanges());
|
|
290
|
+
this.bitMapChangesInProgress = false;
|
|
258
291
|
|
|
259
292
|
_loader().default.stop();
|
|
260
293
|
|
|
@@ -264,6 +297,10 @@ class Watcher {
|
|
|
264
297
|
};
|
|
265
298
|
}
|
|
266
299
|
|
|
300
|
+
if (this.bitMapChangesInProgress) {
|
|
301
|
+
await this.watchQueue.onIdle();
|
|
302
|
+
}
|
|
303
|
+
|
|
267
304
|
const componentId = this.getComponentIdByPath(filePath);
|
|
268
305
|
|
|
269
306
|
if (!componentId) {
|
|
@@ -297,7 +334,7 @@ class Watcher {
|
|
|
297
334
|
await this.sleep(DEBOUNCE_WAIT_MS);
|
|
298
335
|
const files = this.changedFilesPerComponent[compIdStr];
|
|
299
336
|
delete this.changedFilesPerComponent[compIdStr];
|
|
300
|
-
const buildResults = await this.triggerCompChanges(componentId, files, initiator);
|
|
337
|
+
const buildResults = await this.watchQueue.add(() => this.triggerCompChanges(componentId, files, initiator));
|
|
301
338
|
const failureMsg = buildResults.length ? undefined : `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;
|
|
302
339
|
|
|
303
340
|
_loader().default.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEBOUNCE_WAIT_MS","Watcher","constructor","workspace","pubsub","trackDirs","verbose","multipleWatchers","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","buildResults","handleBitmapChanges","loader","stop","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","add","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","COMPONENT_ORIGINS","AUTHORED","IMPORTED","all","map","bitId","getTrackDir","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, COMPONENT_ORIGINS } 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';\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 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 * 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 */\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 const buildResults = await this.handleBitmapChanges();\n loader.stop();\n return { results: buildResults, files: [filePath] };\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\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.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 COMPONENT_ORIGINS.AUTHORED,\n COMPONENT_ORIGINS.IMPORTED,\n ]);\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const trackDir = componentMap.getTrackDir();\n if (!trackDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[trackDir] = 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":";;;;;;;;;;;;;;;;;;;;;;;;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6C,oBAAjC,CAAd;IACA,MAAMyG,aAAa,GAAGD,KAAK,CAACL,GAAN,CAAWlD,GAAD,IAAS,KAAK3F,QAAL,CAAcoJ,cAAd,CAA6BzD,GAA7B,CAAnB,CAAtB;IACA,OAAOwD,aAAP;EACD;;AA5TkB"}
|
|
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","COMPONENT_ORIGINS","AUTHORED","IMPORTED","all","map","bitId","getTrackDir","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, COMPONENT_ORIGINS } 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 COMPONENT_ORIGINS.AUTHORED,\n COMPONENT_ORIGINS.IMPORTED,\n ]);\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const trackDir = componentMap.getTrackDir();\n if (!trackDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[trackDir] = 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;;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KAAK,GAAG,CAAC,GAAG7I,MAAM,CAACkF,IAAP,CAAY,KAAK9F,SAAjB,CAAJ,EAAiC8C,oBAAjC,CAAd;IACA,MAAM4G,aAAa,GAAGD,KAAK,CAACL,GAAN,CAAWlD,GAAD,IAAS,KAAK9F,QAAL,CAAcuJ,cAAd,CAA6BzD,GAA7B,CAAnB,CAAtB;IACA,OAAOwD,aAAP;EACD;;AArVkB"}
|
|
@@ -7,6 +7,16 @@ export class EnvsReplaceCmd implements Command {
|
|
|
7
7
|
description = 'replace an existing env with another env for all components using the old env';
|
|
8
8
|
options = [];
|
|
9
9
|
group = 'development';
|
|
10
|
+
arguments = [
|
|
11
|
+
{ name: 'old-env', description: 'current environment id' },
|
|
12
|
+
{ name: 'new-env', description: 'target environment id' },
|
|
13
|
+
];
|
|
14
|
+
examples = [
|
|
15
|
+
{
|
|
16
|
+
cmd: 'replace teambit.harmony/aspect teambit.harmony/node',
|
|
17
|
+
description: 'all components using aspect env, will be replaced with node env',
|
|
18
|
+
},
|
|
19
|
+
];
|
|
10
20
|
|
|
11
21
|
constructor(private workspace: Workspace) {}
|
|
12
22
|
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/workspace",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.758",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/workspace/workspace",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.workspace",
|
|
8
8
|
"name": "workspace",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.758"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"detect-indent": "5.0.0",
|
|
26
26
|
"detect-newline": "3.1.0",
|
|
27
27
|
"stringify-package": "1.0.1",
|
|
28
|
+
"p-queue": "6.6.2",
|
|
28
29
|
"moment": "2.29.2",
|
|
29
30
|
"chokidar": "3.5.1",
|
|
30
31
|
"@react-hook/latest": "1.0.3",
|
|
@@ -39,46 +40,46 @@
|
|
|
39
40
|
"@teambit/bit-error": "0.0.394",
|
|
40
41
|
"@teambit/component-id": "0.0.402",
|
|
41
42
|
"@teambit/legacy-bit-id": "0.0.399",
|
|
42
|
-
"@teambit/logger": "0.0.
|
|
43
|
-
"@teambit/scope": "0.0.
|
|
44
|
-
"@teambit/cli": "0.0.
|
|
45
|
-
"@teambit/isolator": "0.0.
|
|
46
|
-
"@teambit/component-tree": "0.0.
|
|
43
|
+
"@teambit/logger": "0.0.594",
|
|
44
|
+
"@teambit/scope": "0.0.758",
|
|
45
|
+
"@teambit/cli": "0.0.501",
|
|
46
|
+
"@teambit/isolator": "0.0.758",
|
|
47
|
+
"@teambit/component-tree": "0.0.546",
|
|
47
48
|
"@teambit/component.ui.component-status-resolver": "0.0.492",
|
|
48
|
-
"@teambit/lanes.ui.lanes": "0.0.
|
|
49
|
+
"@teambit/lanes.ui.lanes": "0.0.68",
|
|
49
50
|
"@teambit/harmony.modules.resolved-component": "0.0.484",
|
|
50
|
-
"@teambit/dependency-resolver": "0.0.
|
|
51
|
-
"@teambit/compiler": "0.0.
|
|
52
|
-
"@teambit/component": "0.0.
|
|
53
|
-
"@teambit/graphql": "0.0.
|
|
54
|
-
"@teambit/aspect-loader": "0.0.
|
|
55
|
-
"@teambit/bundler": "0.0.
|
|
56
|
-
"@teambit/community": "0.0.
|
|
57
|
-
"@teambit/envs": "0.0.
|
|
58
|
-
"@teambit/pubsub": "0.0.
|
|
59
|
-
"@teambit/ui": "0.0.
|
|
60
|
-
"@teambit/variants": "0.0.
|
|
51
|
+
"@teambit/dependency-resolver": "0.0.758",
|
|
52
|
+
"@teambit/compiler": "0.0.758",
|
|
53
|
+
"@teambit/component": "0.0.758",
|
|
54
|
+
"@teambit/graphql": "0.0.758",
|
|
55
|
+
"@teambit/aspect-loader": "0.0.758",
|
|
56
|
+
"@teambit/bundler": "0.0.758",
|
|
57
|
+
"@teambit/community": "0.0.49",
|
|
58
|
+
"@teambit/envs": "0.0.758",
|
|
59
|
+
"@teambit/pubsub": "0.0.758",
|
|
60
|
+
"@teambit/ui": "0.0.758",
|
|
61
|
+
"@teambit/variants": "0.0.597",
|
|
61
62
|
"@teambit/component-issues": "0.0.54",
|
|
62
|
-
"@teambit/config": "0.0.
|
|
63
|
+
"@teambit/config": "0.0.514",
|
|
63
64
|
"@teambit/harmony.modules.requireable-component": "0.0.484",
|
|
64
|
-
"@teambit/importer": "0.0.
|
|
65
|
-
"@teambit/lane-id": "0.0.
|
|
65
|
+
"@teambit/importer": "0.0.187",
|
|
66
|
+
"@teambit/lane-id": "0.0.20",
|
|
66
67
|
"@teambit/workspace.modules.match-pattern": "0.0.489",
|
|
67
|
-
"@teambit/component.ui.component-drawer": "0.0.
|
|
68
|
+
"@teambit/component.ui.component-drawer": "0.0.47",
|
|
68
69
|
"@teambit/design.ui.tree": "0.0.5",
|
|
69
|
-
"@teambit/ui-foundation.ui.side-bar": "0.0.
|
|
70
|
-
"@teambit/command-bar": "0.0.
|
|
70
|
+
"@teambit/ui-foundation.ui.side-bar": "0.0.565",
|
|
71
|
+
"@teambit/command-bar": "0.0.758",
|
|
71
72
|
"@teambit/component.ui.component-filters": "0.0.5",
|
|
72
|
-
"@teambit/graph": "0.0.
|
|
73
|
-
"@teambit/sidebar": "0.0.
|
|
73
|
+
"@teambit/graph": "0.0.758",
|
|
74
|
+
"@teambit/sidebar": "0.0.758",
|
|
74
75
|
"@teambit/ui-foundation.ui.main-dropdown": "0.0.487",
|
|
75
76
|
"@teambit/ui-foundation.ui.menu": "0.0.487",
|
|
76
77
|
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.490",
|
|
77
78
|
"@teambit/ui-foundation.ui.tree.drawer": "0.0.499",
|
|
78
79
|
"@teambit/toolbox.time.time-format": "0.0.483",
|
|
79
80
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
|
|
80
|
-
"@teambit/component-descriptor": "0.0.
|
|
81
|
-
"@teambit/deprecation": "0.0.
|
|
81
|
+
"@teambit/component-descriptor": "0.0.63",
|
|
82
|
+
"@teambit/deprecation": "0.0.758",
|
|
82
83
|
"@teambit/ui-foundation.ui.constants.z-indexes": "0.0.487",
|
|
83
84
|
"@teambit/ui-foundation.ui.buttons.collapser": "0.0.194",
|
|
84
85
|
"@teambit/ui-foundation.ui.corner": "0.0.498",
|
|
@@ -105,7 +106,7 @@
|
|
|
105
106
|
"peerDependencies": {
|
|
106
107
|
"react-router-dom": "^6.0.0",
|
|
107
108
|
"@apollo/client": "^3.0.0",
|
|
108
|
-
"@teambit/legacy": "1.0.
|
|
109
|
+
"@teambit/legacy": "1.0.281",
|
|
109
110
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
110
111
|
"react": "^16.8.0 || ^17.0.0"
|
|
111
112
|
},
|
|
@@ -133,7 +134,7 @@
|
|
|
133
134
|
"react": "-"
|
|
134
135
|
},
|
|
135
136
|
"peerDependencies": {
|
|
136
|
-
"@teambit/legacy": "1.0.
|
|
137
|
+
"@teambit/legacy": "1.0.281",
|
|
137
138
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
138
139
|
"react": "^16.8.0 || ^17.0.0"
|
|
139
140
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_workspace@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_workspace@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_workspace@0.0.758/dist/workspace.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_workspace@0.0.758/dist/workspace.docs.mdx')]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
|
|
3
|
+
export class WatchQueue {
|
|
4
|
+
private queue: PQueue;
|
|
5
|
+
constructor(concurrency = 1) {
|
|
6
|
+
this.queue = new PQueue({ concurrency, autoStart: true });
|
|
7
|
+
}
|
|
8
|
+
getQueue() {
|
|
9
|
+
return this.queue;
|
|
10
|
+
}
|
|
11
|
+
add<T>(fn: () => T, priority?: number): Promise<T> {
|
|
12
|
+
return this.queue.add(fn, { priority });
|
|
13
|
+
}
|
|
14
|
+
onIdle(): Promise<void> {
|
|
15
|
+
return this.queue.onIdle();
|
|
16
|
+
}
|
|
17
|
+
}
|
package/watch/watcher.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { OnComponentChangeEvent, OnComponentAddEvent, OnComponentRemovedEvent }
|
|
|
20
20
|
import { Workspace } from '../workspace';
|
|
21
21
|
import { OnComponentEventResult } from '../on-component-events';
|
|
22
22
|
import { CheckTypes } from './check-types';
|
|
23
|
+
import { WatchQueue } from './watch-queue';
|
|
23
24
|
|
|
24
25
|
export type WatcherProcessData = { watchProcess: ChildProcess; compilerId: BitId; componentIds: BitId[] };
|
|
25
26
|
|
|
@@ -47,6 +48,8 @@ const DEBOUNCE_WAIT_MS = 100;
|
|
|
47
48
|
export class Watcher {
|
|
48
49
|
private fsWatcher: FSWatcher;
|
|
49
50
|
private changedFilesPerComponent: { [componentId: string]: string[] } = {};
|
|
51
|
+
private watchQueue = new WatchQueue();
|
|
52
|
+
private bitMapChangesInProgress = false;
|
|
50
53
|
constructor(
|
|
51
54
|
private workspace: Workspace,
|
|
52
55
|
private pubsub: PubsubMain,
|
|
@@ -111,6 +114,7 @@ export class Watcher {
|
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
/**
|
|
117
|
+
* *** DEBOUNCING ***
|
|
114
118
|
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
115
119
|
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
116
120
|
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
@@ -125,6 +129,24 @@ export class Watcher {
|
|
|
125
129
|
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
126
130
|
* other components undesirably.
|
|
127
131
|
*
|
|
132
|
+
* *** QUEUE ***
|
|
133
|
+
* the debouncing helps to not execute the same component multiple times concurrently. however, multiple components
|
|
134
|
+
* and .bitmap changes execution can still be processed concurrently.
|
|
135
|
+
* the following example explains why this is an issue.
|
|
136
|
+
* compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.
|
|
137
|
+
* all these changes get pulled at the same time by "git pull", as a result, the execution of compA and the .bitmap
|
|
138
|
+
* happen at the same time.
|
|
139
|
+
* during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this
|
|
140
|
+
* id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.
|
|
141
|
+
* after this change, the workspace doesn't have this id anymore, which will trigger an error.
|
|
142
|
+
* to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all
|
|
143
|
+
* other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).
|
|
144
|
+
* once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.
|
|
145
|
+
* in the example above, at this stage, the id will be resolved to compA@0.0.2.
|
|
146
|
+
* one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at
|
|
147
|
+
* the same time. (the same way is done when loading all components from the filesystem/scope).
|
|
148
|
+
* this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the
|
|
149
|
+
* .bitmap execution starts.
|
|
128
150
|
*/
|
|
129
151
|
private async handleChange(
|
|
130
152
|
filePath: string,
|
|
@@ -137,10 +159,15 @@ export class Watcher {
|
|
|
137
159
|
}> {
|
|
138
160
|
try {
|
|
139
161
|
if (filePath.endsWith(BIT_MAP)) {
|
|
140
|
-
|
|
162
|
+
this.bitMapChangesInProgress = true;
|
|
163
|
+
const buildResults = await this.watchQueue.add(() => this.handleBitmapChanges());
|
|
164
|
+
this.bitMapChangesInProgress = false;
|
|
141
165
|
loader.stop();
|
|
142
166
|
return { results: buildResults, files: [filePath] };
|
|
143
167
|
}
|
|
168
|
+
if (this.bitMapChangesInProgress) {
|
|
169
|
+
await this.watchQueue.onIdle();
|
|
170
|
+
}
|
|
144
171
|
const componentId = this.getComponentIdByPath(filePath);
|
|
145
172
|
if (!componentId) {
|
|
146
173
|
const failureMsg = `file ${filePath} is not part of any component, ignoring it`;
|
|
@@ -148,7 +175,6 @@ export class Watcher {
|
|
|
148
175
|
loader.stop();
|
|
149
176
|
return { results: [], files: [filePath], failureMsg };
|
|
150
177
|
}
|
|
151
|
-
|
|
152
178
|
const compIdStr = componentId.toString();
|
|
153
179
|
if (this.changedFilesPerComponent[compIdStr]) {
|
|
154
180
|
this.changedFilesPerComponent[compIdStr].push(filePath);
|
|
@@ -160,7 +186,7 @@ export class Watcher {
|
|
|
160
186
|
const files = this.changedFilesPerComponent[compIdStr];
|
|
161
187
|
delete this.changedFilesPerComponent[compIdStr];
|
|
162
188
|
|
|
163
|
-
const buildResults = await this.triggerCompChanges(componentId, files, initiator);
|
|
189
|
+
const buildResults = await this.watchQueue.add(() => this.triggerCompChanges(componentId, files, initiator));
|
|
164
190
|
const failureMsg = buildResults.length
|
|
165
191
|
? undefined
|
|
166
192
|
: `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;
|
|
Binary file
|