@teambit/watcher 0.0.0-cd7fda3ef709e5042e7b7400d4fa080c0023cc57 → 0.0.0-cdb58239f5bc01a402acffeff4bd00a8273df674

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Format a helpful error message when FSEvents stream limit is reached.
3
+ * Lists running bit watchers and provides suggestions for freeing up streams.
4
+ */
5
+ export declare function formatFSEventsErrorMessage(): Promise<string>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatFSEventsErrorMessage = formatFSEventsErrorMessage;
7
+ function _child_process() {
8
+ const data = require("child_process");
9
+ _child_process = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _util() {
15
+ const data = require("util");
16
+ _util = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _chalk() {
22
+ const data = _interopRequireDefault(require("chalk"));
23
+ _chalk = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
29
+ const execAsync = (0, _util().promisify)(_child_process().exec);
30
+ /**
31
+ * Detect running bit watcher processes on macOS.
32
+ * Returns a list of processes running bit watch, bit start, bit run, or bit server commands.
33
+ */
34
+ async function detectRunningBitWatchers() {
35
+ if (process.platform !== 'darwin') {
36
+ return []; // FSEvents is macOS-specific
37
+ }
38
+ try {
39
+ // Use ps -eo for more predictable output format (just pid and command)
40
+ const {
41
+ stdout
42
+ } = await execAsync(`ps -eo pid,command | grep -E "/bit (watch|start|run|server)" | grep -v grep || true`);
43
+ if (!stdout.trim()) {
44
+ return [];
45
+ }
46
+ const processes = [];
47
+ const lines = stdout.trim().split('\n');
48
+ for (const line of lines) {
49
+ const trimmedLine = line.trim();
50
+ const firstSpaceIdx = trimmedLine.indexOf(' ');
51
+ if (firstSpaceIdx === -1) continue;
52
+ const pidStr = trimmedLine.slice(0, firstSpaceIdx);
53
+ const command = trimmedLine.slice(firstSpaceIdx + 1).trim();
54
+
55
+ // Validate PID is purely numeric to prevent command injection
56
+ if (!/^\d+$/.test(pidStr)) continue;
57
+ const pid = parseInt(pidStr, 10);
58
+ if (pid === process.pid) continue; // Skip current process
59
+
60
+ // server-forever is just a spawner process, it doesn't run a watcher itself
61
+ if (/server-forever/.test(command)) continue;
62
+
63
+ // bit server is started by VS Code extension - users should close VS Code windows instead of killing these
64
+ const isVSCodeServer = /bit server(?:\s|$)/.test(command);
65
+
66
+ // Get the working directory of this process using lsof
67
+ let cwd = 'unknown';
68
+ try {
69
+ const {
70
+ stdout: lsofOut
71
+ } = await execAsync(`lsof -p ${pid} 2>/dev/null | grep cwd | head -1 || true`);
72
+ // lsof output format: "node PID user cwd DIR ... /path/to/dir"
73
+ // The path is the last field and starts with /
74
+ const cwdMatch = lsofOut.match(/\s(\/[^\s]+)\s*$/);
75
+ if (cwdMatch) {
76
+ cwd = cwdMatch[1];
77
+ }
78
+ } catch {
79
+ // Ignore lsof errors
80
+ }
81
+ processes.push({
82
+ pid,
83
+ command,
84
+ cwd,
85
+ isVSCodeServer
86
+ });
87
+ }
88
+ return processes;
89
+ } catch {
90
+ return [];
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Format a helpful error message when FSEvents stream limit is reached.
96
+ * Lists running bit watchers and provides suggestions for freeing up streams.
97
+ */
98
+ async function formatFSEventsErrorMessage() {
99
+ const runningWatchers = await detectRunningBitWatchers();
100
+ const killableProcesses = runningWatchers.filter(p => !p.isVSCodeServer);
101
+ const vscodeServers = runningWatchers.filter(p => p.isVSCodeServer);
102
+ let message = `Failed to start the watcher: Error starting FSEvents stream
103
+ macOS limits the total number of FSEvents watchers system-wide (undocumented limit, typically ~500).
104
+ Each running watcher process may consume multiple streams internally.`;
105
+ if (runningWatchers.length > 0) {
106
+ message += `\n\n${_chalk().default.yellow('Found the following Bit watcher processes:')}`;
107
+ for (const proc of runningWatchers) {
108
+ const cwdInfo = proc.cwd !== 'unknown' ? ` (${proc.cwd})` : '';
109
+ const vscodeNote = proc.isVSCodeServer ? _chalk().default.gray(' [VS Code extension]') : '';
110
+ message += `\n ${_chalk().default.cyan(`PID ${proc.pid}`)}: ${proc.command}${cwdInfo}${vscodeNote}`;
111
+ }
112
+ message += `\n\n${_chalk().default.yellow('To free up FSEvents streams, you can:')}`;
113
+ if (killableProcesses.length > 0) {
114
+ message += `\n 1. Close unnecessary terminal tabs running bit watch/start/run`;
115
+ message += `\n 2. Kill specific processes: ${_chalk().default.cyan(`kill ${killableProcesses.map(p => p.pid).join(' ')}`)}`;
116
+ }
117
+ if (vscodeServers.length > 0) {
118
+ message += `\n ${killableProcesses.length > 0 ? '3' : '1'}. Close unused VS Code windows (${vscodeServers.length} VS Code Bit server${vscodeServers.length > 1 ? 's' : ''} running)`;
119
+ }
120
+ }
121
+ message += `\n
122
+ ${_chalk().default.green('Recommended solution:')} Install Watchman to avoid FSEvents limits entirely.
123
+ Watchman is a file watching service that uses a single daemon for all watchers:
124
+ ${_chalk().default.cyan('brew install watchman')}
125
+
126
+ ${_chalk().default.yellow('Note:')} If you're using "bit start" or "bit run", you don't need "bit watch" separately.
127
+ With the VS Code Bit extension, you can use "Compile on Change" instead of running a watcher manually.
128
+
129
+ For more details, see: https://facebook.github.io/watchman/docs/troubleshooting#fseventstreamstart-register_with_server-error-f2d_register_rpc--null--21`;
130
+ return message;
131
+ }
132
+
133
+ //# sourceMappingURL=fsevents-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_child_process","data","require","_util","_chalk","_interopRequireDefault","e","__esModule","default","execAsync","promisify","exec","detectRunningBitWatchers","process","platform","stdout","trim","processes","lines","split","line","trimmedLine","firstSpaceIdx","indexOf","pidStr","slice","command","test","pid","parseInt","isVSCodeServer","cwd","lsofOut","cwdMatch","match","push","formatFSEventsErrorMessage","runningWatchers","killableProcesses","filter","p","vscodeServers","message","length","chalk","yellow","proc","cwdInfo","vscodeNote","gray","cyan","map","join","green"],"sources":["fsevents-error.ts"],"sourcesContent":["import { exec } from 'child_process';\nimport { promisify } from 'util';\nimport chalk from 'chalk';\n\nconst execAsync = promisify(exec);\n\ntype BitWatcherProcess = {\n pid: number;\n command: string;\n cwd: string;\n isVSCodeServer: boolean; // bit server processes are managed by VS Code extension\n};\n\n/**\n * Detect running bit watcher processes on macOS.\n * Returns a list of processes running bit watch, bit start, bit run, or bit server commands.\n */\nasync function detectRunningBitWatchers(): Promise<BitWatcherProcess[]> {\n if (process.platform !== 'darwin') {\n return []; // FSEvents is macOS-specific\n }\n\n try {\n // Use ps -eo for more predictable output format (just pid and command)\n const { stdout } = await execAsync(\n `ps -eo pid,command | grep -E \"/bit (watch|start|run|server)\" | grep -v grep || true`\n );\n\n if (!stdout.trim()) {\n return [];\n }\n\n const processes: BitWatcherProcess[] = [];\n const lines = stdout.trim().split('\\n');\n\n for (const line of lines) {\n const trimmedLine = line.trim();\n const firstSpaceIdx = trimmedLine.indexOf(' ');\n if (firstSpaceIdx === -1) continue;\n\n const pidStr = trimmedLine.slice(0, firstSpaceIdx);\n const command = trimmedLine.slice(firstSpaceIdx + 1).trim();\n\n // Validate PID is purely numeric to prevent command injection\n if (!/^\\d+$/.test(pidStr)) continue;\n\n const pid = parseInt(pidStr, 10);\n if (pid === process.pid) continue; // Skip current process\n\n // server-forever is just a spawner process, it doesn't run a watcher itself\n if (/server-forever/.test(command)) continue;\n\n // bit server is started by VS Code extension - users should close VS Code windows instead of killing these\n const isVSCodeServer = /bit server(?:\\s|$)/.test(command);\n\n // Get the working directory of this process using lsof\n let cwd = 'unknown';\n try {\n const { stdout: lsofOut } = await execAsync(`lsof -p ${pid} 2>/dev/null | grep cwd | head -1 || true`);\n // lsof output format: \"node PID user cwd DIR ... /path/to/dir\"\n // The path is the last field and starts with /\n const cwdMatch = lsofOut.match(/\\s(\\/[^\\s]+)\\s*$/);\n if (cwdMatch) {\n cwd = cwdMatch[1];\n }\n } catch {\n // Ignore lsof errors\n }\n\n processes.push({ pid, command, cwd, isVSCodeServer });\n }\n\n return processes;\n } catch {\n return [];\n }\n}\n\n/**\n * Format a helpful error message when FSEvents stream limit is reached.\n * Lists running bit watchers and provides suggestions for freeing up streams.\n */\nexport async function formatFSEventsErrorMessage(): Promise<string> {\n const runningWatchers = await detectRunningBitWatchers();\n const killableProcesses = runningWatchers.filter((p) => !p.isVSCodeServer);\n const vscodeServers = runningWatchers.filter((p) => p.isVSCodeServer);\n\n let message = `Failed to start the watcher: Error starting FSEvents stream\nmacOS limits the total number of FSEvents watchers system-wide (undocumented limit, typically ~500).\nEach running watcher process may consume multiple streams internally.`;\n\n if (runningWatchers.length > 0) {\n message += `\\n\\n${chalk.yellow('Found the following Bit watcher processes:')}`;\n for (const proc of runningWatchers) {\n const cwdInfo = proc.cwd !== 'unknown' ? ` (${proc.cwd})` : '';\n const vscodeNote = proc.isVSCodeServer ? chalk.gray(' [VS Code extension]') : '';\n message += `\\n ${chalk.cyan(`PID ${proc.pid}`)}: ${proc.command}${cwdInfo}${vscodeNote}`;\n }\n\n message += `\\n\\n${chalk.yellow('To free up FSEvents streams, you can:')}`;\n if (killableProcesses.length > 0) {\n message += `\\n 1. Close unnecessary terminal tabs running bit watch/start/run`;\n message += `\\n 2. Kill specific processes: ${chalk.cyan(`kill ${killableProcesses.map((p) => p.pid).join(' ')}`)}`;\n }\n if (vscodeServers.length > 0) {\n message += `\\n ${killableProcesses.length > 0 ? '3' : '1'}. Close unused VS Code windows (${vscodeServers.length} VS Code Bit server${vscodeServers.length > 1 ? 's' : ''} running)`;\n }\n }\n\n message += `\\n\n${chalk.green('Recommended solution:')} Install Watchman to avoid FSEvents limits entirely.\nWatchman is a file watching service that uses a single daemon for all watchers:\n ${chalk.cyan('brew install watchman')}\n\n${chalk.yellow('Note:')} If you're using \"bit start\" or \"bit run\", you don't need \"bit watch\" separately.\nWith the VS Code Bit extension, you can use \"Compile on Change\" instead of running a watcher manually.\n\nFor more details, see: https://facebook.github.io/watchman/docs/troubleshooting#fseventstreamstart-register_with_server-error-f2d_register_rpc--null--21`;\n\n return message;\n}\n"],"mappings":";;;;;;AAAA,SAAAA,eAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,cAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,MAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,OAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,MAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0B,SAAAI,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1B,MAAMG,SAAS,GAAG,IAAAC,iBAAS,EAACC,qBAAI,CAAC;AASjC;AACA;AACA;AACA;AACA,eAAeC,wBAAwBA,CAAA,EAAiC;EACtE,IAAIC,OAAO,CAACC,QAAQ,KAAK,QAAQ,EAAE;IACjC,OAAO,EAAE,CAAC,CAAC;EACb;EAEA,IAAI;IACF;IACA,MAAM;MAAEC;IAAO,CAAC,GAAG,MAAMN,SAAS,CAChC,qFACF,CAAC;IAED,IAAI,CAACM,MAAM,CAACC,IAAI,CAAC,CAAC,EAAE;MAClB,OAAO,EAAE;IACX;IAEA,MAAMC,SAA8B,GAAG,EAAE;IACzC,MAAMC,KAAK,GAAGH,MAAM,CAACC,IAAI,CAAC,CAAC,CAACG,KAAK,CAAC,IAAI,CAAC;IAEvC,KAAK,MAAMC,IAAI,IAAIF,KAAK,EAAE;MACxB,MAAMG,WAAW,GAAGD,IAAI,CAACJ,IAAI,CAAC,CAAC;MAC/B,MAAMM,aAAa,GAAGD,WA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CAACE,MAAM,sBAAsBF,aAAa,CAACE,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,WAAW;IACvL;EACF;EAEAD,OAAO,IAAI;AACb,EAAEE,gBAAK,CAACS,KAAK,CAAC,uBAAuB,CAAC;AACtC;AACA,IAAIT,gBAAK,CAACM,IAAI,CAAC,uBAAuB,CAAC;AACvC;AACA,EAAEN,gBAAK,CAACC,MAAM,CAAC,OAAO,CAAC;AACvB;AACA;AACA,yJAAyJ;EAEvJ,OAAOH,OAAO;AAChB","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -2,5 +2,7 @@ import { WatcherAspect } from './watcher.aspect';
2
2
  export type { WatchOptions } from './watcher';
3
3
  export { CheckTypes } from './check-types';
4
4
  export type { WatcherMain } from './watcher.main.runtime';
5
+ export { WatcherDaemon, WatcherClient, getOrCreateWatcherConnection } from './watcher-daemon';
6
+ export type { WatcherEvent, WatcherError, WatcherHeartbeat, WatcherReady, WatcherMessage } from './watcher-daemon';
5
7
  export default WatcherAspect;
6
8
  export { WatcherAspect };
package/dist/index.js CHANGED
@@ -15,7 +15,25 @@ Object.defineProperty(exports, "WatcherAspect", {
15
15
  return _watcher().WatcherAspect;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "WatcherClient", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _watcherDaemon().WatcherClient;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "WatcherDaemon", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _watcherDaemon().WatcherDaemon;
28
+ }
29
+ });
18
30
  exports.default = void 0;
31
+ Object.defineProperty(exports, "getOrCreateWatcherConnection", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _watcherDaemon().getOrCreateWatcherConnection;
35
+ }
36
+ });
19
37
  function _watcher() {
20
38
  const data = require("./watcher.aspect");
21
39
  _watcher = function () {
@@ -30,6 +48,13 @@ function _checkTypes() {
30
48
  };
31
49
  return data;
32
50
  }
51
+ function _watcherDaemon() {
52
+ const data = require("./watcher-daemon");
53
+ _watcherDaemon = function () {
54
+ return data;
55
+ };
56
+ return data;
57
+ }
33
58
  var _default = exports.default = _watcher().WatcherAspect;
34
59
 
35
60
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_watcher","data","require","_checkTypes","_default","exports","default","WatcherAspect"],"sources":["index.ts"],"sourcesContent":["import { WatcherAspect } from './watcher.aspect';\n\nexport type { WatchOptions } from './watcher';\nexport { CheckTypes } from './check-types';\nexport type { WatcherMain } from './watcher.main.runtime';\nexport default WatcherAspect;\nexport { WatcherAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,YAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2C,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE5BC,wBAAa","ignoreList":[]}
1
+ {"version":3,"names":["_watcher","data","require","_checkTypes","_watcherDaemon","_default","exports","default","WatcherAspect"],"sources":["index.ts"],"sourcesContent":["import { WatcherAspect } from './watcher.aspect';\n\nexport type { WatchOptions } from './watcher';\nexport { CheckTypes } from './check-types';\nexport type { WatcherMain } from './watcher.main.runtime';\nexport { WatcherDaemon, WatcherClient, getOrCreateWatcherConnection } from './watcher-daemon';\nexport type { WatcherEvent, WatcherError, WatcherHeartbeat, WatcherReady, WatcherMessage } from './watcher-daemon';\nexport default WatcherAspect;\nexport { WatcherAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,YAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,eAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,cAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8F,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE/EC,wBAAa","ignoreList":[]}
@@ -12,13 +12,6 @@ function _logger() {
12
12
  };
13
13
  return data;
14
14
  }
15
- function _compiler() {
16
- const data = require("@teambit/compiler");
17
- _compiler = function () {
18
- return data;
19
- };
20
- return data;
21
- }
22
15
  function _chalk() {
23
16
  const data = _interopRequireDefault(require("chalk"));
24
17
  _chalk = function () {
@@ -33,6 +26,13 @@ function _lodash() {
33
26
  };
34
27
  return data;
35
28
  }
29
+ function _legacy() {
30
+ const data = require("@teambit/legacy.constants");
31
+ _legacy = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
36
36
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
37
37
  function formatWatchPathsSortByComponent(trackDirs) {
38
38
  const title = ` ${_chalk().default.underline('STATUS\tCOMPONENT ID')}\n`;
@@ -46,7 +46,7 @@ function formatCompileResults(compileResults) {
46
46
  if (!compileResults.length) return '';
47
47
  return (0, _lodash().compact)(compileResults
48
48
  // currently, we are interested only in the compiler results
49
- .filter(compileResult => compileResult.extensionId === _compiler().CompilerAspect.id).map(compileResult => compileResult.results.toString())).join('\n');
49
+ .filter(compileResult => compileResult.extensionId === _legacy().Extensions.compiler).map(compileResult => compileResult.results.toString())).join('\n');
50
50
  }
51
51
 
52
52
  //# sourceMappingURL=output-formatter.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_logger","data","require","_compiler","_chalk","_interopRequireDefault","_lodash","e","__esModule","default","formatWatchPathsSortByComponent","trackDirs","title","chalk","underline","Object","keys","reduce","outputString","watchPath","componentId","formattedWatchPath","Logger","successSymbol","formatCompileResults","compileResults","length","compact","filter","compileResult","extensionId","CompilerAspect","id","map","results","toString","join"],"sources":["output-formatter.ts"],"sourcesContent":["import { Logger } from '@teambit/logger';\nimport { CompilerAspect } from '@teambit/compiler';\nimport type { OnComponentEventResult } from '@teambit/workspace';\nimport chalk from 'chalk';\nimport type { RootDirs } from './watcher';\nimport { compact } from 'lodash';\n\nexport function formatWatchPathsSortByComponent(trackDirs: RootDirs) {\n const title = ` ${chalk.underline('STATUS\\tCOMPONENT ID')}\\n`;\n return Object.keys(trackDirs).reduce((outputString, watchPath) => {\n const componentId = trackDirs[watchPath];\n const formattedWatchPath = `\\t\\t - ${watchPath}\\n`;\n return `${outputString}${Logger.successSymbol()} SUCCESS\\t${componentId}\\n${formattedWatchPath}`;\n }, title);\n}\n\nexport function formatCompileResults(compileResults: OnComponentEventResult[]) {\n if (!compileResults.length) return '';\n return compact(\n compileResults\n // currently, we are interested only in the compiler results\n .filter((compileResult) => compileResult.extensionId === CompilerAspect.id)\n .map((compileResult) => compileResult.results.toString())\n ).join('\\n');\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,OAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,MAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAiC,SAAAI,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1B,SAASG,+BAA+BA,CAACC,SAAmB,EAAE;EACnE,MAAMC,KAAK,GAAG,IAAIC,gBAAK,CAACC,SAAS,CAAC,sBAAsB,CAAC,IAAI;EAC7D,OAAOC,MAAM,CAACC,IAAI,CAACL,SAAS,CAAC,CAACM,MAAM,CAAC,CAACC,YAAY,EAAEC,SAAS,KAAK;IAChE,MAAMC,WAAW,GAAGT,SAAS,CAACQ,SAAS,CAAC;IACxC,MAAME,kBAAkB,GAAG,UAAUF,SAAS,IAAI;IAClD,OAAO,GAAGD,YAAY,GAAGI,gBAAM,CAACC,aAAa,CAAC,CAAC,aAAaH,WAAW,KAAKC,kBAAkB,EAAE;EAClG,CAAC,EAAET,KAAK,CAAC;AACX;AAEO,SAASY,oBAAoBA,CAACC,cAAwC,EAAE;EAC7E,IAAI,CAACA,cAAc,CAACC,MAAM,EAAE,OAAO,EAAE;EACrC,OAAO,IAAAC,iBAAO,EACZF;EACE;EAAA,CACCG,MAAM,CAAEC,aAAa,IAAKA,aAAa,CAACC,WAAW,KAAKC,0BAAc,CAACC,EAAE,CAAC,CAC1EC,GAAG,CAAEJ,aAAa,IAAKA,aAAa,CAACK,OAAO,CAACC,QAAQ,CAAC,CAAC,CAC5D,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACd","ignoreList":[]}
1
+ {"version":3,"names":["_logger","data","require","_chalk","_interopRequireDefault","_lodash","_legacy","e","__esModule","default","formatWatchPathsSortByComponent","trackDirs","title","chalk","underline","Object","keys","reduce","outputString","watchPath","componentId","formattedWatchPath","Logger","successSymbol","formatCompileResults","compileResults","length","compact","filter","compileResult","extensionId","Extensions","compiler","map","results","toString","join"],"sources":["output-formatter.ts"],"sourcesContent":["import { Logger } from '@teambit/logger';\nimport type { OnComponentEventResult } from '@teambit/workspace';\nimport chalk from 'chalk';\nimport type { RootDirs } from './watcher';\nimport { compact } from 'lodash';\nimport { Extensions } from '@teambit/legacy.constants';\n\nexport function formatWatchPathsSortByComponent(trackDirs: RootDirs) {\n const title = ` ${chalk.underline('STATUS\\tCOMPONENT ID')}\\n`;\n return Object.keys(trackDirs).reduce((outputString, watchPath) => {\n const componentId = trackDirs[watchPath];\n const formattedWatchPath = `\\t\\t - ${watchPath}\\n`;\n return `${outputString}${Logger.successSymbol()} SUCCESS\\t${componentId}\\n${formattedWatchPath}`;\n }, title);\n}\n\nexport function formatCompileResults(compileResults: OnComponentEventResult[]) {\n if (!compileResults.length) return '';\n return compact(\n compileResults\n // currently, we are interested only in the compiler results\n .filter((compileResult) => compileResult.extensionId === Extensions.compiler)\n .map((compileResult) => compileResult.results.toString())\n ).join('\\n');\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAuD,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhD,SAASG,+BAA+BA,CAACC,SAAmB,EAAE;EACnE,MAAMC,KAAK,GAAG,IAAIC,gBAAK,CAACC,SAAS,CAAC,sBAAsB,CAAC,IAAI;EAC7D,OAAOC,MAAM,CAACC,IAAI,CAACL,SAAS,CAAC,CAACM,MAAM,CAAC,CAACC,YAAY,EAAEC,SAAS,KAAK;IAChE,MAAMC,WAAW,GAAGT,SAAS,CAACQ,SAAS,CAAC;IACxC,MAAME,kBAAkB,GAAG,UAAUF,SAAS,IAAI;IAClD,OAAO,GAAGD,YAAY,GAAGI,gBAAM,CAACC,aAAa,CAAC,CAAC,aAAaH,WAAW,KAAKC,kBAAkB,EAAE;EAClG,CAAC,EAAET,KAAK,CAAC;AACX;AAEO,SAASY,oBAAoBA,CAACC,cAAwC,EAAE;EAC7E,IAAI,CAACA,cAAc,CAACC,MAAM,EAAE,OAAO,EAAE;EACrC,OAAO,IAAAC,iBAAO,EACZF;EACE;EAAA,CACCG,MAAM,CAAEC,aAAa,IAAKA,aAAa,CAACC,WAAW,KAAKC,oBAAU,CAACC,QAAQ,CAAC,CAC5EC,GAAG,CAAEJ,aAAa,IAAKA,aAAa,CAACK,OAAO,CAACC,QAAQ,CAAC,CAAC,CAC5D,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACd","ignoreList":[]}
@@ -1,6 +1,5 @@
1
1
  import type { Command, CommandOptions } from '@teambit/cli';
2
2
  import type { Logger } from '@teambit/logger';
3
- import type { PubsubMain } from '@teambit/pubsub';
4
3
  import type { WatcherMain } from './watcher.main.runtime';
5
4
  type WatchCmdOpts = {
6
5
  verbose?: boolean;
@@ -12,10 +11,6 @@ type WatchCmdOpts = {
12
11
  trigger?: string;
13
12
  };
14
13
  export declare class WatchCommand implements Command {
15
- /**
16
- * logger extension.
17
- */
18
- private pubsub;
19
14
  /**
20
15
  * logger extension.
21
16
  */
@@ -32,10 +27,6 @@ export declare class WatchCommand implements Command {
32
27
  group: string;
33
28
  options: CommandOptions;
34
29
  constructor(
35
- /**
36
- * logger extension.
37
- */
38
- pubsub: PubsubMain,
39
30
  /**
40
31
  * logger extension.
41
32
  */
@@ -44,8 +35,6 @@ export declare class WatchCommand implements Command {
44
35
  * watcher extension.
45
36
  */
46
37
  watcher: WatcherMain);
47
- private registerToEvents;
48
- private eventsListener;
49
38
  wait(cliArgs: [], watchCmdOpts: WatchCmdOpts): Promise<void>;
50
39
  }
51
40
  export {};
package/dist/watch.cmd.js CHANGED
@@ -25,13 +25,6 @@ function _componentId() {
25
25
  };
26
26
  return data;
27
27
  }
28
- function _compiler() {
29
- const data = require("@teambit/compiler");
30
- _compiler = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
28
  function _outputFormatter() {
36
29
  const data = require("./output-formatter");
37
30
  _outputFormatter = function () {
@@ -52,10 +45,6 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
52
45
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
53
46
  class WatchCommand {
54
47
  constructor(
55
- /**
56
- * logger extension.
57
- */
58
- pubsub,
59
48
  /**
60
49
  * logger extension.
61
50
  */
@@ -64,29 +53,17 @@ class WatchCommand {
64
53
  * watcher extension.
65
54
  */
66
55
  watcher) {
67
- this.pubsub = pubsub;
68
56
  this.logger = logger;
69
57
  this.watcher = watcher;
70
58
  _defineProperty(this, "name", 'watch');
71
- _defineProperty(this, "description", 'automatically recompile modified components (on save)');
72
- _defineProperty(this, "extendedDescription", `by default, the watcher doesn't use polling, to keep the CPU idle.
73
- if this doesn't work well for you, run "bit config set watch_use_polling true" to use polling.`);
59
+ _defineProperty(this, "description", 'watch and compile components on file changes');
60
+ _defineProperty(this, "extendedDescription", `monitors component files for changes and automatically recompiles them using their environment's configured compiler.
61
+ enables immediate feedback during development by keeping components compiled as you work.
62
+ by default uses file system events (not polling) to minimize CPU usage - enable polling with "bit config set watch_use_polling true" if needed.`);
74
63
  _defineProperty(this, "helpUrl", 'reference/compiling/compiler-overview');
75
64
  _defineProperty(this, "alias", '');
76
65
  _defineProperty(this, "group", 'component-development');
77
66
  _defineProperty(this, "options", [['v', 'verbose', 'show all watch events and compiler verbose output'], ['', 'skip-pre-compilation', 'skip compilation step before starting to watch'], ['t', 'check-types [string]', 'show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project'], ['i', 'import', 'DEPRECATED. it is now the default. helpful when using git. import component objects if .bitmap changed not by bit'], ['', 'skip-import', 'do not import component objects if .bitmap changed not by bit'], ['', 'generate-types', 'EXPERIMENTAL. generate d.ts files for typescript components (hurts performance)'], ['', 'trigger <comp-id>', 'trigger recompilation of the specified component regardless of what changed. helpful when this comp-id must be a bundle']]);
78
- _defineProperty(this, "eventsListener", event => {
79
- switch (event.type) {
80
- case _compiler().CompilerErrorEvent.TYPE:
81
- this.logger.console(`Watcher error ${event.data.error}, 'error'`);
82
- break;
83
- default:
84
- }
85
- });
86
- this.registerToEvents();
87
- }
88
- registerToEvents() {
89
- this.pubsub.sub(_compiler().CompilerAspect.id, this.eventsListener);
90
67
  }
91
68
  async wait(cliArgs, watchCmdOpts) {
92
69
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["_chalk","data","_interopRequireDefault","require","_moment","_componentId","_compiler","_outputFormatter","_checkTypes","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","WatchCommand","constructor","pubsub","logger","watcher","event","type","CompilerErrorEvent","TYPE","console","error","registerToEvents","sub","CompilerAspect","id","eventsListener","wait","cliArgs","watchCmdOpts","verbose","checkTypes","import","importIfNeeded","skipImport","trigger","consoleWarning","getCheckTypesEnum","undefined","CheckTypes","None","EntireProject","ChangedFile","Error","watchOpts","compile","preCompile","skipPreCompilation","spawnTSServer","Boolean","ComponentID","fromString","generateTypes","preImport","watch","getMessages","exports","onAll","path","onStart","onReady","workspace","watchPathsSortByComponent","clearOutdatedData","formatWatchPathsSortByComponent","chalk","yellow","name","moment","format","onChange","args","printOnFileEvent","onAdd","onUnlink","onError","err","eventMsgPlaceholder","filePaths","buildResults","duration","failureMsg","files","join","length","formatCompileResults","process","stdout","write"],"sources":["watch.cmd.ts"],"sourcesContent":["import chalk from 'chalk';\nimport moment from 'moment';\nimport type { Command, CommandOptions } from '@teambit/cli';\nimport type { Logger } from '@teambit/logger';\nimport type { BitBaseEvent, PubsubMain } from '@teambit/pubsub';\nimport type { OnComponentEventResult, Workspace } from '@teambit/workspace';\nimport { ComponentID } from '@teambit/component-id';\nimport { CompilerAspect, CompilerErrorEvent } from '@teambit/compiler';\nimport type { EventMessages, RootDirs, WatchOptions } from './watcher';\nimport { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';\nimport { CheckTypes } from './check-types';\nimport type { WatcherMain } from './watcher.main.runtime';\n\ntype WatchCmdOpts = {\n verbose?: boolean;\n skipPreCompilation?: boolean;\n checkTypes?: string | boolean;\n import?: boolean;\n skipImport?: boolean;\n generateTypes?: boolean;\n trigger?: string;\n};\n\nexport class WatchCommand implements Command {\n name = 'watch';\n description = 'automatically recompile modified components (on save)';\n extendedDescription = `by default, the watcher doesn't use polling, to keep the CPU idle.\nif this doesn't work well for you, run \"bit config set watch_use_polling true\" to use polling.`;\n helpUrl = 'reference/compiling/compiler-overview';\n alias = '';\n group = 'component-development';\n options = [\n ['v', 'verbose', 'show all watch events and compiler verbose output'],\n ['', 'skip-pre-compilation', 'skip compilation step before starting to watch'],\n [\n 't',\n 'check-types [string]',\n 'show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project',\n ],\n [\n 'i',\n 'import',\n 'DEPRECATED. it is now the default. helpful when using git. import component objects if .bitmap changed not by bit',\n ],\n ['', 'skip-import', 'do not import component objects if .bitmap changed not by bit'],\n ['', 'generate-types', 'EXPERIMENTAL. generate d.ts files for typescript components (hurts performance)'],\n [\n '',\n 'trigger <comp-id>',\n 'trigger recompilation of the specified component regardless of what changed. helpful when this comp-id must be a bundle',\n ],\n ] as CommandOptions;\n\n constructor(\n /**\n * logger extension.\n */\n private pubsub: PubsubMain,\n\n /**\n * logger extension.\n */\n private logger: Logger,\n\n /**\n * watcher extension.\n */\n private watcher: WatcherMain\n ) {\n this.registerToEvents();\n }\n\n private registerToEvents() {\n this.pubsub.sub(CompilerAspect.id, this.eventsListener);\n }\n\n private eventsListener = (event: BitBaseEvent<any>) => {\n switch (event.type) {\n case CompilerErrorEvent.TYPE:\n this.logger.console(`Watcher error ${event.data.error}, 'error'`);\n break;\n default:\n }\n };\n\n async wait(cliArgs: [], watchCmdOpts: WatchCmdOpts) {\n const { verbose, checkTypes, import: importIfNeeded, skipImport, trigger } = watchCmdOpts;\n if (importIfNeeded) {\n this.logger.consoleWarning('the \"--import\" flag is deprecated and is now the default behavior');\n }\n const getCheckTypesEnum = () => {\n switch (checkTypes) {\n case undefined:\n case false:\n return CheckTypes.None;\n case 'project':\n case true: // project is the default\n return CheckTypes.EntireProject;\n case 'file':\n return CheckTypes.ChangedFile;\n default:\n throw new Error(`check-types can be either \"file\" or \"project\". got \"${checkTypes}\"`);\n }\n };\n const watchOpts: WatchOptions = {\n verbose,\n compile: true,\n preCompile: !watchCmdOpts.skipPreCompilation,\n spawnTSServer: Boolean(checkTypes), // if check-types is enabled, it must spawn the tsserver.\n checkTypes: getCheckTypesEnum(),\n import: !skipImport,\n trigger: trigger ? ComponentID.fromString(trigger) : undefined,\n generateTypes: watchCmdOpts.generateTypes,\n preImport: !skipImport,\n };\n await this.watcher.watch(watchOpts, getMessages(this.logger));\n }\n}\n\nfunction getMessages(logger: Logger): EventMessages {\n return {\n onAll: (event: string, path: string) => logger.console(`Event: \"${event}\". Path: ${path}`),\n onStart: () => {},\n onReady: (workspace: Workspace, watchPathsSortByComponent: RootDirs, verbose?: boolean) => {\n clearOutdatedData();\n if (verbose) {\n logger.console(formatWatchPathsSortByComponent(watchPathsSortByComponent));\n }\n logger.console(\n chalk.yellow(\n `Watching for component changes in workspace ${workspace.name} (${moment().format('HH:mm:ss')})...\\n`\n )\n );\n },\n onChange: (...args) => {\n printOnFileEvent(logger, 'changed', ...args);\n },\n onAdd: (...args) => {\n printOnFileEvent(logger, 'added', ...args);\n },\n onUnlink: (...args) => {\n printOnFileEvent(logger, 'removed', ...args);\n },\n onError: (err) => {\n logger.console(`Watcher error ${err}`);\n },\n };\n}\n\nfunction printOnFileEvent(\n logger: Logger,\n eventMsgPlaceholder: 'changed' | 'added' | 'removed',\n filePaths: string[],\n buildResults: OnComponentEventResult[],\n verbose: boolean,\n duration: number,\n failureMsg?: string\n) {\n const files = filePaths.join(', ');\n if (!buildResults.length) {\n if (!failureMsg) {\n if (verbose) logger.console(`The files ${files} have been ${eventMsgPlaceholder}, but nothing to compile\\n\\n`);\n return;\n }\n logger.console(`${failureMsg}\\n\\n`);\n return;\n }\n logger.console(`The file(s) ${files} have been ${eventMsgPlaceholder}.\\n`);\n logger.console(formatCompileResults(buildResults));\n logger.console(`Finished (${duration}ms).`);\n logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));\n}\n\n/**\n * with console.clear() all history is deleted from the console. this function preserver the history.\n */\nfunction clearOutdatedData() {\n process.stdout.write('\\x1Bc');\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,YAAA,YAAAA,C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,CAACK,MAAM,EAAE;IACxB,IAAI,CAACH,UAAU,EAAE;MACf,IAAInD,OAAO,EAAEhB,MAAM,CAACM,OAAO,CAAC,aAAa8D,KAAK,cAAcL,mBAAmB,8BAA8B,CAAC;MAC9G;IACF;IACA/D,MAAM,CAACM,OAAO,CAAC,GAAG6D,UAAU,MAAM,CAAC;IACnC;EACF;EACAnE,MAAM,CAACM,OAAO,CAAC,eAAe8D,KAAK,cAAcL,mBAAmB,KAAK,CAAC;EAC1E/D,MAAM,CAACM,OAAO,CAAC,IAAAiE,uCAAoB,EAACN,YAAY,CAAC,CAAC;EAClDjE,MAAM,CAACM,OAAO,CAAC,aAAa4D,QAAQ,MAAM,CAAC;EAC3ClE,MAAM,CAACM,OAAO,CAAC6C,gBAAK,CAACC,MAAM,CAAC,mCAAmC,IAAAE,iBAAM,EAAC,CAAC,CAACC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACpG;;AAEA;AACA;AACA;AACA,SAASN,iBAAiBA,CAAA,EAAG;EAC3BuB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,OAAO,CAAC;AAC/B","ignoreList":[]}
1
+ {"version":3,"names":["_chalk","data","_interopRequireDefault","require","_moment","_componentId","_outputFormatter","_checkTypes","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","WatchCommand","constructor","logger","watcher","wait","cliArgs","watchCmdOpts","verbose","checkTypes","import","importIfNeeded","skipImport","trigger","consoleWarning","getCheckTypesEnum","undefined","CheckTypes","None","EntireProject","ChangedFile","Error","watchOpts","compile","preCompile","skipPreCompilation","spawnTSServer","Boolean","ComponentID","fromString","generateTypes","preImport","watch","getMessages","exports","onAll","event","path","console","onStart","onReady","workspace","watchPathsSortByComponent","clearOutdatedData","formatWatchPathsSortByComponent","chalk","yellow","name","moment","format","onChange","args","printOnFileEvent","onAdd","onUnlink","onError","err","eventMsgPlaceholder","filePaths","buildResults","duration","failureMsg","files","join","length","formatCompileResults","process","stdout","write"],"sources":["watch.cmd.ts"],"sourcesContent":["import chalk from 'chalk';\nimport moment from 'moment';\nimport type { Command, CommandOptions } from '@teambit/cli';\nimport type { Logger } from '@teambit/logger';\nimport type { OnComponentEventResult, Workspace } from '@teambit/workspace';\nimport { ComponentID } from '@teambit/component-id';\nimport type { EventMessages, RootDirs, WatchOptions } from './watcher';\nimport { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';\nimport { CheckTypes } from './check-types';\nimport type { WatcherMain } from './watcher.main.runtime';\n\ntype WatchCmdOpts = {\n verbose?: boolean;\n skipPreCompilation?: boolean;\n checkTypes?: string | boolean;\n import?: boolean;\n skipImport?: boolean;\n generateTypes?: boolean;\n trigger?: string;\n};\n\nexport class WatchCommand implements Command {\n name = 'watch';\n description = 'watch and compile components on file changes';\n extendedDescription = `monitors component files for changes and automatically recompiles them using their environment's configured compiler.\nenables immediate feedback during development by keeping components compiled as you work.\nby default uses file system events (not polling) to minimize CPU usage - enable polling with \"bit config set watch_use_polling true\" if needed.`;\n helpUrl = 'reference/compiling/compiler-overview';\n alias = '';\n group = 'component-development';\n options = [\n ['v', 'verbose', 'show all watch events and compiler verbose output'],\n ['', 'skip-pre-compilation', 'skip compilation step before starting to watch'],\n [\n 't',\n 'check-types [string]',\n 'show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project',\n ],\n [\n 'i',\n 'import',\n 'DEPRECATED. it is now the default. helpful when using git. import component objects if .bitmap changed not by bit',\n ],\n ['', 'skip-import', 'do not import component objects if .bitmap changed not by bit'],\n ['', 'generate-types', 'EXPERIMENTAL. generate d.ts files for typescript components (hurts performance)'],\n [\n '',\n 'trigger <comp-id>',\n 'trigger recompilation of the specified component regardless of what changed. helpful when this comp-id must be a bundle',\n ],\n ] as CommandOptions;\n\n constructor(\n /**\n * logger extension.\n */\n private logger: Logger,\n\n /**\n * watcher extension.\n */\n private watcher: WatcherMain\n ) {}\n\n async wait(cliArgs: [], watchCmdOpts: WatchCmdOpts) {\n const { verbose, checkTypes, import: importIfNeeded, skipImport, trigger } = watchCmdOpts;\n if (importIfNeeded) {\n this.logger.consoleWarning('the \"--import\" flag is deprecated and is now the default behavior');\n }\n const getCheckTypesEnum = () => {\n switch (checkTypes) {\n case undefined:\n case false:\n return CheckTypes.None;\n case 'project':\n case true: // project is the default\n return CheckTypes.EntireProject;\n case 'file':\n return CheckTypes.ChangedFile;\n default:\n throw new Error(`check-types can be either \"file\" or \"project\". got \"${checkTypes}\"`);\n }\n };\n const watchOpts: WatchOptions = {\n verbose,\n compile: true,\n preCompile: !watchCmdOpts.skipPreCompilation,\n spawnTSServer: Boolean(checkTypes), // if check-types is enabled, it must spawn the tsserver.\n checkTypes: getCheckTypesEnum(),\n import: !skipImport,\n trigger: trigger ? ComponentID.fromString(trigger) : undefined,\n generateTypes: watchCmdOpts.generateTypes,\n preImport: !skipImport,\n };\n await this.watcher.watch(watchOpts, getMessages(this.logger));\n }\n}\n\nfunction getMessages(logger: Logger): EventMessages {\n return {\n onAll: (event: string, path: string) => logger.console(`Event: \"${event}\". Path: ${path}`),\n onStart: () => {},\n onReady: (workspace: Workspace, watchPathsSortByComponent: RootDirs, verbose?: boolean) => {\n clearOutdatedData();\n if (verbose) {\n logger.console(formatWatchPathsSortByComponent(watchPathsSortByComponent));\n }\n logger.console(\n chalk.yellow(\n `Watching for component changes in workspace ${workspace.name} (${moment().format('HH:mm:ss')})...\\n`\n )\n );\n },\n onChange: (...args) => {\n printOnFileEvent(logger, 'changed', ...args);\n },\n onAdd: (...args) => {\n printOnFileEvent(logger, 'added', ...args);\n },\n onUnlink: (...args) => {\n printOnFileEvent(logger, 'removed', ...args);\n },\n onError: (err) => {\n logger.console(`Watcher error ${err}`);\n },\n };\n}\n\nfunction printOnFileEvent(\n logger: Logger,\n eventMsgPlaceholder: 'changed' | 'added' | 'removed',\n filePaths: string[],\n buildResults: OnComponentEventResult[],\n verbose: boolean,\n duration: number,\n failureMsg?: string\n) {\n const files = filePaths.join(', ');\n if (!buildResults.length) {\n if (!failureMsg) {\n if (verbose) logger.console(`The files ${files} have been ${eventMsgPlaceholder}, but nothing to compile\\n\\n`);\n return;\n }\n logger.console(`${failureMsg}\\n\\n`);\n return;\n }\n logger.console(`The file(s) ${files} have been ${eventMsgPlaceholder}.\\n`);\n logger.console(formatCompileResults(buildResults));\n logger.console(`Finished (${duration}ms).`);\n logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));\n}\n\n/**\n * with console.clear() all history is deleted from the console. this function preserver the history.\n */\nfunction clearOutdatedData() {\n process.stdout.write('\\x1Bc');\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAIA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,iBAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,gBAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,YAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2C,SAAAC,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,g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CACvBjD,MAAc,EACdsD,mBAAoD,EACpDC,SAAmB,EACnBC,YAAsC,EACtCnD,OAAgB,EAChBoD,QAAgB,EAChBC,UAAmB,EACnB;EACA,MAAMC,KAAK,GAAGJ,SAAS,CAACK,IAAI,CAAC,IAAI,CAAC;EAClC,IAAI,CAACJ,YAAY,CAACK,MAAM,EAAE;IACxB,IAAI,CAACH,UAAU,EAAE;MACf,IAAIrD,OAAO,EAAEL,MAAM,CAACmC,OAAO,CAAC,aAAawB,KAAK,cAAcL,mBAAmB,8BAA8B,CAAC;MAC9G;IACF;IACAtD,MAAM,CAACmC,OAAO,CAAC,GAAGuB,UAAU,MAAM,CAAC;IACnC;EACF;EACA1D,MAAM,CAACmC,OAAO,CAAC,eAAewB,KAAK,cAAcL,mBAAmB,KAAK,CAAC;EAC1EtD,MAAM,CAACmC,OAAO,CAAC,IAAA2B,uCAAoB,EAACN,YAAY,CAAC,CAAC;EAClDxD,MAAM,CAACmC,OAAO,CAAC,aAAasB,QAAQ,MAAM,CAAC;EAC3CzD,MAAM,CAACmC,OAAO,CAACO,gBAAK,CAACC,MAAM,CAAC,mCAAmC,IAAAE,iBAAM,EAAC,CAAC,CAACC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACpG;;AAEA;AACA;AACA;AACA,SAASN,iBAAiBA,CAAA,EAAG;EAC3BuB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,OAAO,CAAC;AAC/B","ignoreList":[]}
@@ -0,0 +1,156 @@
1
+ import type { Event } from '@parcel/watcher';
2
+ import type { Logger } from '@teambit/logger';
3
+ export type WatcherEvent = {
4
+ type: 'events';
5
+ events: Event[];
6
+ };
7
+ export type WatcherError = {
8
+ type: 'error';
9
+ message: string;
10
+ isDropError?: boolean;
11
+ };
12
+ export type WatcherHeartbeat = {
13
+ type: 'heartbeat';
14
+ timestamp: number;
15
+ };
16
+ export type WatcherReady = {
17
+ type: 'ready';
18
+ };
19
+ export type WatcherMessage = WatcherEvent | WatcherError | WatcherHeartbeat | WatcherReady;
20
+ /**
21
+ * WatcherDaemon is the server-side of the shared watcher infrastructure.
22
+ * It runs a Unix domain socket server and broadcasts file system events to all connected clients.
23
+ *
24
+ * Only ONE daemon can run per workspace. The daemon is responsible for:
25
+ * 1. Subscribing to Parcel Watcher for file system events
26
+ * 2. Broadcasting events to all connected clients
27
+ * 3. Sending heartbeats to clients so they know the daemon is alive
28
+ * 4. Cleaning up resources on shutdown
29
+ */
30
+ export declare class WatcherDaemon {
31
+ private scopePath;
32
+ private logger;
33
+ private server;
34
+ private clients;
35
+ private heartbeatInterval;
36
+ private isShuttingDown;
37
+ constructor(scopePath: string, logger: Logger);
38
+ get socketPath(): string;
39
+ get lockPath(): string;
40
+ /**
41
+ * Check if a daemon is already running for this workspace
42
+ */
43
+ static isRunning(scopePath: string, logger?: Logger): Promise<boolean>;
44
+ /**
45
+ * Try to connect to an existing daemon socket
46
+ */
47
+ private static tryConnect;
48
+ /**
49
+ * Start the daemon server
50
+ */
51
+ start(): Promise<void>;
52
+ /**
53
+ * Handle a new client connection
54
+ */
55
+ private handleConnection;
56
+ /**
57
+ * Broadcast events to all connected clients
58
+ */
59
+ broadcast(message: WatcherMessage): void;
60
+ /**
61
+ * Send message to a specific client
62
+ */
63
+ private sendToClient;
64
+ /**
65
+ * Broadcast file system events from Parcel watcher
66
+ */
67
+ broadcastEvents(events: Event[]): void;
68
+ /**
69
+ * Broadcast an error to all clients
70
+ */
71
+ broadcastError(message: string, isDropError?: boolean): void;
72
+ /**
73
+ * Start sending heartbeats to clients
74
+ */
75
+ private startHeartbeat;
76
+ /**
77
+ * Get the number of connected clients
78
+ */
79
+ get clientCount(): number;
80
+ /**
81
+ * Stop the daemon and cleanup
82
+ */
83
+ stop(): Promise<void>;
84
+ }
85
+ /**
86
+ * WatcherClient connects to an existing WatcherDaemon to receive file system events.
87
+ *
88
+ * Usage:
89
+ * ```typescript
90
+ * const client = new WatcherClient(scopePath, logger);
91
+ * await client.connect();
92
+ * client.onEvents((events) => { ... });
93
+ * client.onError((err) => { ... });
94
+ * ```
95
+ */
96
+ export declare class WatcherClient {
97
+ private scopePath;
98
+ private logger;
99
+ private socket;
100
+ private eventsHandler;
101
+ private errorHandler;
102
+ private readyHandler;
103
+ private disconnectHandler;
104
+ private buffer;
105
+ private isConnected;
106
+ constructor(scopePath: string, logger: Logger);
107
+ get socketPath(): string;
108
+ /**
109
+ * Connect to the daemon
110
+ */
111
+ connect(): Promise<void>;
112
+ /**
113
+ * Handle incoming data from the daemon
114
+ */
115
+ private handleData;
116
+ /**
117
+ * Handle a parsed message from the daemon
118
+ */
119
+ private handleMessage;
120
+ /**
121
+ * Register handler for file system events
122
+ */
123
+ onEvents(handler: (events: Event[]) => void): void;
124
+ /**
125
+ * Register handler for errors
126
+ */
127
+ onError(handler: (error: WatcherError) => void): void;
128
+ /**
129
+ * Register handler for ready signal
130
+ */
131
+ onReady(handler: () => void): void;
132
+ /**
133
+ * Register handler for disconnection
134
+ */
135
+ onDisconnect(handler: () => void): void;
136
+ /**
137
+ * Check if connected to daemon
138
+ */
139
+ get connected(): boolean;
140
+ /**
141
+ * Disconnect from the daemon
142
+ */
143
+ disconnect(): void;
144
+ }
145
+ /**
146
+ * Get or create a watcher connection for the given workspace.
147
+ * Returns either a daemon (if we're the first) or a client (if daemon exists).
148
+ *
149
+ * Uses retry with random jitter to handle race conditions when multiple processes
150
+ * try to become the daemon simultaneously.
151
+ */
152
+ export declare function getOrCreateWatcherConnection(scopePath: string, logger: Logger, retryCount?: number): Promise<{
153
+ isDaemon: boolean;
154
+ daemon?: WatcherDaemon;
155
+ client?: WatcherClient;
156
+ }>;