@teambit/watcher 1.0.107 → 1.0.108
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/check-types.ts +5 -0
- package/dist/output-formatter.js +7 -13
- package/dist/output-formatter.js.map +1 -1
- package/dist/watch.cmd.d.ts +1 -1
- package/dist/watcher.d.ts +4 -4
- package/dist/watcher.js +5 -5
- package/dist/watcher.js.map +1 -1
- package/dist/watcher.main.runtime.d.ts +2 -2
- package/index.ts +7 -0
- package/output-formatter.ts +50 -0
- package/package.json +17 -26
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- package/watch-queue.ts +17 -0
- package/watch.cmd.ts +160 -0
- package/watcher.aspect.ts +5 -0
- package/watcher.main.runtime.ts +85 -0
- package/watcher.ts +426 -0
- /package/dist/{preview-1703590665075.js → preview-1703647408454.js} +0 -0
package/check-types.ts
ADDED
package/dist/output-formatter.js
CHANGED
|
@@ -35,19 +35,13 @@ const formatWatchPathsSortByComponent = trackDirs => {
|
|
|
35
35
|
exports.formatWatchPathsSortByComponent = formatWatchPathsSortByComponent;
|
|
36
36
|
function formatCompileResults(compileResults, verbose) {
|
|
37
37
|
if (!compileResults.length || !Array.isArray(compileResults)) return '';
|
|
38
|
-
return compileResults.filter(compileResult => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
resultsForExtension: (_compileResult$result3 = compileResult.results) === null || _compileResult$result3 === void 0 || (_compileResult$result3 = _compileResult$result3.results) === null || _compileResult$result3 === void 0 ? void 0 : _compileResult$result3.map(resultForExtension => ({
|
|
46
|
-
component: resultForExtension.component,
|
|
47
|
-
componentFilesAsString: verboseComponentFilesArrayToString(resultForExtension.buildResults)
|
|
48
|
-
}))
|
|
49
|
-
};
|
|
50
|
-
}).reduce((outputString, compileResult) => `${outputString}
|
|
38
|
+
return compileResults.filter(compileResult => compileResult.results?.results && Array.isArray(compileResult.results?.results)).map(compileResult => ({
|
|
39
|
+
extensionId: compileResult.extensionId,
|
|
40
|
+
resultsForExtension: compileResult.results?.results?.map(resultForExtension => ({
|
|
41
|
+
component: resultForExtension.component,
|
|
42
|
+
componentFilesAsString: verboseComponentFilesArrayToString(resultForExtension.buildResults)
|
|
43
|
+
}))
|
|
44
|
+
})).reduce((outputString, compileResult) => `${outputString}
|
|
51
45
|
${resultsForExtensionArrayToString(compileResult.resultsForExtension, verbose)}`, ` ${_chalk().default.underline('STATUS\tCOMPONENT ID')}`);
|
|
52
46
|
}
|
|
53
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","obj","__esModule","default","verboseComponentFilesArrayToString","componentFiles","reduce","outputString","filePath","resultsForExtensionArrayToString","resultsForExtension","verbose","resultForExtension","chalk","green","component","componentFilesAsString","formatWatchPathsSortByComponent","trackDirs","Object","keys","watchPath","underline","exports","formatCompileResults","compileResults","length","Array","isArray","filter","compileResult","
|
|
1
|
+
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","obj","__esModule","default","verboseComponentFilesArrayToString","componentFiles","reduce","outputString","filePath","resultsForExtensionArrayToString","resultsForExtension","verbose","resultForExtension","chalk","green","component","componentFilesAsString","formatWatchPathsSortByComponent","trackDirs","Object","keys","watchPath","underline","exports","formatCompileResults","compileResults","length","Array","isArray","filter","compileResult","results","map","extensionId","buildResults"],"sources":["output-formatter.ts"],"sourcesContent":["import { OnComponentEventResult } from '@teambit/workspace';\nimport chalk from 'chalk';\n\nconst verboseComponentFilesArrayToString = (componentFiles = []) => {\n return componentFiles.reduce((outputString, filePath) => `${outputString} \\t - ${filePath}\\n`, ``);\n};\n\nconst resultsForExtensionArrayToString = (resultsForExtension, verbose) => {\n return resultsForExtension.reduce(\n (outputString, resultForExtension) =>\n `${outputString}${chalk.green('√')}SUCCESS\\t${resultForExtension.component}\\n\n ${verbose ? resultForExtension.componentFilesAsString : ''}\\n`,\n ''\n );\n};\n\nexport const formatWatchPathsSortByComponent = (trackDirs) => {\n return Object.keys(trackDirs).reduce(\n (outputString, watchPath) =>\n `${outputString}\n ${chalk.green('√')} SUCCESS\\t${trackDirs[watchPath]}\\n\n \\t - ${watchPath}\\n\\n`,\n ` ${chalk.underline('STATUS\\t\\tCOMPONENT ID')}\\n`\n );\n};\n\n/**\n * todo: this was implemented incorrectly.\n * the original idea of `SerializableResults` was to have each one of the aspects registered to the slot, the\n * ability to have their own formatting to their results, and then `toString()` method to print them.\n * Here, the printing is specifically to the Compiler aspect. It should move to where it belongs.\n */\nexport function formatCompileResults(compileResults: OnComponentEventResult[], verbose: boolean) {\n if (!compileResults.length || !Array.isArray(compileResults)) return '';\n return compileResults\n .filter((compileResult) => compileResult.results?.results && Array.isArray(compileResult.results?.results))\n .map((compileResult) => ({\n extensionId: compileResult.extensionId,\n resultsForExtension: compileResult.results?.results?.map((resultForExtension) => ({\n component: resultForExtension.component,\n componentFilesAsString: verboseComponentFilesArrayToString(resultForExtension.buildResults),\n })),\n }))\n .reduce(\n (outputString, compileResult) =>\n `${outputString}\n ${resultsForExtensionArrayToString(compileResult.resultsForExtension, verbose)}`,\n ` ${chalk.underline('STATUS\\tCOMPONENT ID')}`\n );\n}\n"],"mappings":";;;;;;;AACA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0B,SAAAC,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE1B,MAAMG,kCAAkC,GAAGA,CAACC,cAAc,GAAG,EAAE,KAAK;EAClE,OAAOA,cAAc,CAACC,MAAM,CAAC,CAACC,YAAY,EAAEC,QAAQ,KAAM,GAAED,YAAa,SAAQC,QAAS,IAAG,EAAG,EAAC,CAAC;AACpG,CAAC;AAED,MA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kB,CAACG,SAAS;MACvCC,sBAAsB,EAAEZ,kCAAkC,CAACQ,kBAAkB,CAACsB,YAAY;IAC5F,CAAC,CAAC;EACJ,CAAC,CAAC,CAAC,CACF5B,MAAM,CACL,CAACC,YAAY,EAAEuB,aAAa,KACzB,GAAEvB,YAAa;AACxB,IAAIE,gCAAgC,CAACqB,aAAa,CAACpB,mBAAmB,EAAEC,OAAO,CAAE,EAAC,EAC3E,IAAGE,gBAAK,CAACS,SAAS,CAAC,sBAAsB,CAAE,EAC9C,CAAC;AACL"}
|
package/dist/watch.cmd.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Command, CommandOptions } from '@teambit/cli';
|
|
|
2
2
|
import type { Logger } from '@teambit/logger';
|
|
3
3
|
import type { PubsubMain } from '@teambit/pubsub';
|
|
4
4
|
import { WatcherMain } from './watcher.main.runtime';
|
|
5
|
-
export
|
|
5
|
+
export type WatchCmdOpts = {
|
|
6
6
|
verbose?: boolean;
|
|
7
7
|
skipPreCompilation?: boolean;
|
|
8
8
|
checkTypes?: string | boolean;
|
package/dist/watcher.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { CompilationInitiator } from '@teambit/compiler';
|
|
|
7
7
|
import { Workspace, OnComponentEventResult } from '@teambit/workspace';
|
|
8
8
|
import { CheckTypes } from './check-types';
|
|
9
9
|
import { WatcherMain } from './watcher.main.runtime';
|
|
10
|
-
export
|
|
10
|
+
export type WatcherProcessData = {
|
|
11
11
|
watchProcess: ChildProcess;
|
|
12
12
|
compilerId: ComponentID;
|
|
13
13
|
componentIds: ComponentID[];
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type EventMessages = {
|
|
16
16
|
onAll: Function;
|
|
17
17
|
onStart: Function;
|
|
18
18
|
onReady: Function;
|
|
@@ -21,8 +21,8 @@ export declare type EventMessages = {
|
|
|
21
21
|
onUnlink: OnFileEventFunc;
|
|
22
22
|
onError: Function;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
25
|
-
export
|
|
24
|
+
export type OnFileEventFunc = (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: number, failureMsg?: string) => void;
|
|
25
|
+
export type WatchOptions = {
|
|
26
26
|
msgs?: EventMessages;
|
|
27
27
|
initiator?: CompilationInitiator;
|
|
28
28
|
verbose?: boolean;
|
package/dist/watcher.js
CHANGED
|
@@ -131,15 +131,15 @@ class Watcher {
|
|
|
131
131
|
await this.watcherMain.triggerOnPreWatch(componentIds, watchOpts);
|
|
132
132
|
await this.createWatcher();
|
|
133
133
|
const watcher = this.fsWatcher;
|
|
134
|
-
msgs
|
|
134
|
+
msgs?.onStart(this.workspace);
|
|
135
135
|
await this.workspace.scope.watchScopeInternalFiles();
|
|
136
136
|
return new Promise((resolve, reject) => {
|
|
137
137
|
if (this.verbose) {
|
|
138
138
|
// @ts-ignore
|
|
139
|
-
if (msgs
|
|
139
|
+
if (msgs?.onAll) watcher.on('all', msgs?.onAll);
|
|
140
140
|
}
|
|
141
141
|
watcher.on('ready', () => {
|
|
142
|
-
msgs
|
|
142
|
+
msgs?.onReady(this.workspace, this.trackDirs, this.verbose);
|
|
143
143
|
// console.log(this.fsWatcher.getWatched());
|
|
144
144
|
_loader().default.stop();
|
|
145
145
|
});
|
|
@@ -158,10 +158,10 @@ class Watcher {
|
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
const duration = new Date().getTime() - startTime;
|
|
161
|
-
msgs
|
|
161
|
+
msgs?.onChange(files, results, this.verbose, duration, failureMsg);
|
|
162
162
|
});
|
|
163
163
|
watcher.on('error', err => {
|
|
164
|
-
msgs
|
|
164
|
+
msgs?.onError(err);
|
|
165
165
|
reject(err);
|
|
166
166
|
});
|
|
167
167
|
});
|
package/dist/watcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_lodash","_loader","_constants","_logger","_utils","_pMapSeries","_chalk","_chokidar","_workspace","_watchQueue","_excluded","obj","__esModule","default","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_objectWithoutProperties","source","excluded","target","_objectWithoutPropertiesLoose","key","i","sourceSymbolKeys","indexOf","prototype","propertyIsEnumerable","call","sourceKeys","value","_toPropertyKey","configurable","writable","_toPrimitive","String","Symbol","toPrimitive","TypeError","Number","DEBOUNCE_WAIT_MS","Watcher","constructor","workspace","pubsub","watcherMain","options","WatchQueue","ipcEventsDir","ipcEvents","eventsDir","verbose","consumer","watch","_this$options","msgs","watchOpts","setTrackDirs","componentIds","values","trackDirs","triggerOnPreWatch","createWatcher","watcher","fsWatcher","onStart","scope","watchScopeInternalFiles","Promise","resolve","reject","onAll","on","onReady","loader","stop","event","filePath","startTime","Date","getTime","files","results","debounced","irrelevant","failureMsg","handleChange","duration","onChange","err","onError","endsWith","BIT_MAP","bitMapChangesInProgress","buildResults","watchQueue","add","handleBitmapChanges","onIdle","dirname","eventName","basename","logger","warn","triggerGotEvent","WORKSPACE_JSONC","triggerOnWorkspaceConfigChange","componentId","getComponentIdByPath","compIdStr","toString","changedFilesPerComponent","sleep","triggerCompChanges","undefined","join","msg","error","console","message","ms","setTimeout","updatedComponentId","hasId","ids","listIds","find","id","isEqual","ignoreVersion","debug","clearComponentCache","component","get","componentMap","state","_consumer","Error","compFilesRelativeToWorkspace","getFilesRelativeToConsumer","compFiles","nonCompFiles","partition","relativeFile","getRelativePathLinux","Boolean","p","removedFiles","compact","all","map","fs","pathExists","toStringWithoutVersion","bitMap","updateComponentPaths","f","getPathRelativeToConsumer","executeWatchOperationsOnComponent","previewsTrackDirs","_reloadConsumer","triggerOnBitmapChange","newDirs","difference","removedDirs","addResults","mapSeries","dir","flat","executeWatchOperationsOnRemove","chalk","bold","pub","WorkspaceAspect","createOnComponentRemovedEvent","triggerOnComponentRemove","isChange","isComponentWatchedExternally","idStr","createOnComponentChangeEvent","createOnComponentAddEvent","triggerOnComponentChange","triggerOnComponentAdd","OnComponentRemovedEvent","now","hook","OnComponentChangeEvent","OnComponentAddEvent","watcherData","multipleWatchers","m","compilerId","trackDir","findTrackDirByFilePathRecursively","pathNormalizeToLinux","parentDir","usePollingConf","globalConfig","CFG_WATCH_USE_POLLING","usePolling","ignoreLocalScope","pathToCheck","startsWith","path","chokidar","ignoreInitial","ignored","persistent","JSON","stringify","componentsFromBitMap","getAllComponents","bitId","rootDir","getRootDir","resolveComponentId","exports"],"sources":["watcher.ts"],"sourcesContent":["import { PubsubMain } from '@teambit/pubsub';\nimport fs from 'fs-extra';\nimport { dirname, basename } from 'path';\nimport { compact, difference, partition } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { BIT_MAP, CFG_WATCH_USE_POLLING, WORKSPACE_JSONC } 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 '@teambit/chokidar';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport {\n WorkspaceAspect,\n Workspace,\n OnComponentEventResult,\n OnComponentChangeEvent,\n OnComponentAddEvent,\n OnComponentRemovedEvent,\n} from '@teambit/workspace';\nimport { CheckTypes } from './check-types';\nimport { WatcherMain } from './watcher.main.runtime';\nimport { WatchQueue } from './watch-queue';\n\nexport type WatcherProcessData = { watchProcess: ChildProcess; compilerId: ComponentID; componentIds: ComponentID[] };\n\nexport type EventMessages = {\n onAll: Function;\n onStart: Function;\n onReady: Function;\n onChange: OnFileEventFunc;\n onAdd: OnFileEventFunc;\n onUnlink: OnFileEventFunc;\n onError: Function;\n};\n\nexport type OnFileEventFunc = (\n filePaths: string[],\n buildResults: OnComponentEventResult[],\n verbose: boolean,\n duration: number,\n failureMsg?: string\n) => void;\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 compile?: boolean; // whether compile modified/added components during watch process\n};\n\nconst DEBOUNCE_WAIT_MS = 100;\ntype PathLinux = string; // ts fails when importing it from @teambit/legacy/dist/utils/path.\n\nexport class Watcher {\n private fsWatcher: FSWatcher;\n private changedFilesPerComponent: { [componentId: string]: string[] } = {};\n private watchQueue = new WatchQueue();\n private bitMapChangesInProgress = false;\n private ipcEventsDir: string;\n private trackDirs: { [dir: PathLinux]: ComponentID } = {};\n private verbose = false;\n private multipleWatchers: WatcherProcessData[] = [];\n constructor(\n private workspace: Workspace,\n private pubsub: PubsubMain,\n private watcherMain: WatcherMain,\n private options: WatchOptions\n ) {\n this.ipcEventsDir = this.watcherMain.ipcEvents.eventsDir;\n this.verbose = this.options.verbose || false;\n }\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async watch() {\n const { msgs, ...watchOpts } = this.options;\n await this.setTrackDirs();\n const componentIds = Object.values(this.trackDirs);\n await this.watcherMain.triggerOnPreWatch(componentIds, watchOpts);\n await this.createWatcher();\n const watcher = this.fsWatcher;\n msgs?.onStart(this.workspace);\n\n await this.workspace.scope.watchScopeInternalFiles();\n\n return new Promise((resolve, reject) => {\n if (this.verbose) {\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 // console.log(this.fsWatcher.getWatched());\n loader.stop();\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('all', async (event, filePath) => {\n if (event !== 'change' && event !== 'add' && event !== 'unlink') return;\n const startTime = new Date().getTime();\n const { files, results, debounced, irrelevant, failureMsg } = await this.handleChange(filePath);\n if (debounced || irrelevant) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onChange(files, results, this.verbose, duration, failureMsg);\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(filePath: string): Promise<{\n results: OnComponentEventResult[];\n files: string[];\n failureMsg?: string;\n debounced?: boolean;\n irrelevant?: boolean; // file/dir is not part of any component\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 if (dirname(filePath) === this.ipcEventsDir) {\n const eventName = basename(filePath);\n if (eventName !== 'onPostInstall') {\n this.watcherMain.logger.warn(`eventName ${eventName} is not recognized, please handle it`);\n }\n await this.watcherMain.ipcEvents.triggerGotEvent(eventName as 'onPostInstall');\n return { results: [], files: [filePath] };\n }\n if (filePath.endsWith(WORKSPACE_JSONC)) {\n await this.workspace.triggerOnWorkspaceConfigChange();\n return { results: [], files: [filePath] };\n }\n const componentId = this.getComponentIdByPath(filePath);\n if (!componentId) {\n loader.stop();\n return { results: [], files: [], irrelevant: true };\n }\n const compIdStr = componentId.toString();\n if (this.changedFilesPerComponent[compIdStr]) {\n this.changedFilesPerComponent[compIdStr].push(filePath);\n loader.stop();\n return { results: [], files: [], 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));\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 private async triggerCompChanges(\n componentId: ComponentID,\n files: PathOsBasedAbsolute[]\n ): Promise<OnComponentEventResult[]> {\n let updatedComponentId: ComponentID | undefined = componentId;\n if (!(await this.workspace.hasId(componentId))) {\n // bitmap has changed meanwhile, which triggered `handleBitmapChanges`, which re-loaded consumer and updated versions\n // so the original componentId might not be in the workspace now, and we need to find the updated one\n const ids = await this.workspace.listIds();\n updatedComponentId = ids.find((id) => id.isEqual(componentId, { ignoreVersion: true }));\n if (!updatedComponentId) {\n logger.debug(`triggerCompChanges, the component ${componentId.toString()} was probably removed from .bitmap`);\n return [];\n }\n }\n this.workspace.clearComponentCache(updatedComponentId);\n const component = await this.workspace.get(updatedComponentId);\n const componentMap: ComponentMap = component.state._consumer.componentMap;\n if (!componentMap) {\n throw new Error(\n `unable to find componentMap for ${updatedComponentId.toString()}, make sure this component is in .bitmap`\n );\n }\n const compFilesRelativeToWorkspace = componentMap.getFilesRelativeToConsumer();\n const [compFiles, nonCompFiles] = partition(files, (filePath) => {\n const relativeFile = this.getRelativePathLinux(filePath);\n return Boolean(compFilesRelativeToWorkspace.find((p) => p === relativeFile));\n });\n // nonCompFiles are either, files that were removed from the filesystem or existing files that are ignored.\n // the compiler takes care of removedFiles differently, e.g. removes dists dir and old symlinks.\n const removedFiles = compact(\n await Promise.all(nonCompFiles.map(async (filePath) => ((await fs.pathExists(filePath)) ? null : filePath)))\n );\n\n if (!compFiles.length && !removedFiles.length) {\n logger.debug(\n `the following files are part of the component ${componentId.toStringWithoutVersion()} but configured to be ignored:\\n${files.join(\n '\\n'\n )}'`\n );\n return [];\n }\n this.consumer.bitMap.updateComponentPaths(\n componentId,\n compFiles.map((f) => this.consumer.getPathRelativeToConsumer(f)),\n removedFiles.map((f) => this.consumer.getPathRelativeToConsumer(f))\n );\n const buildResults = await this.executeWatchOperationsOnComponent(\n updatedComponentId,\n compFiles,\n removedFiles,\n true\n );\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 await this.workspace.triggerOnBitmapChange();\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 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 mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));\n }\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.createOnComponentRemovedEvent(componentId.toString()));\n await this.workspace.triggerOnComponentRemove(componentId);\n }\n\n private async executeWatchOperationsOnComponent(\n componentId: ComponentID,\n files: PathOsBasedAbsolute[],\n removedFiles: PathOsBasedAbsolute[] = [],\n isChange = true\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.createOnComponentChangeEvent(idStr, 'OnComponentChange'));\n } else {\n logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.createOnComponentAddEvent(idStr, 'OnComponentAdd'));\n }\n\n const buildResults = isChange\n ? await this.workspace.triggerOnComponentChange(componentId, files, removedFiles, this.options)\n : await this.workspace.triggerOnComponentAdd(componentId, this.options);\n\n return buildResults;\n }\n\n private createOnComponentRemovedEvent(idStr) {\n return new OnComponentRemovedEvent(Date.now(), idStr);\n }\n\n private createOnComponentChangeEvent(idStr, hook) {\n return new OnComponentChangeEvent(Date.now(), idStr, hook);\n }\n\n private createOnComponentAddEvent(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)));\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() {\n const usePollingConf = await this.watcherMain.globalConfig.get(CFG_WATCH_USE_POLLING);\n const usePolling = usePollingConf === 'true';\n // const useFsEventsConf = await this.watcherMain.globalConfig.get(CFG_WATCH_USE_FS_EVENTS);\n // const useFsEvents = useFsEventsConf === 'true';\n const ignoreLocalScope = (pathToCheck: string) => {\n if (pathToCheck.startsWith(this.ipcEventsDir)) return false;\n return (\n pathToCheck.startsWith(`${this.workspace.path}/.git/`) || pathToCheck.startsWith(`${this.workspace.path}/.bit/`)\n );\n };\n this.fsWatcher = chokidar.watch(this.workspace.path, {\n ignoreInitial: true,\n // `chokidar` matchers have Bash-parity, so Windows-style backslashes are not supported as separators.\n // (windows-style backslashes are converted to forward slashes)\n ignored: ['**/node_modules/**', '**/package.json', ignoreLocalScope],\n /**\n * default to false, although it causes high CPU usage.\n * see: https://github.com/paulmillr/chokidar/issues/1196#issuecomment-1711033539\n * there is a fix for this in master. once a new version of Chokidar is released, we can upgrade it and then\n * default to true.\n */\n usePolling,\n // useFsEvents,\n persistent: true,\n });\n if (this.verbose) {\n logger.console(`chokidar.options ${JSON.stringify(this.fsWatcher.options, undefined, 2)}`);\n }\n }\n\n private async setTrackDirs() {\n this.trackDirs = {};\n const componentsFromBitMap = this.consumer.bitMap.getAllComponents();\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const rootDir = componentMap.getRootDir();\n if (!rootDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[rootDir] = componentId;\n })\n );\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,O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C;IACnB,MAAMsJ,oBAAoB,GAAG,IAAI,CAAC9J,QAAQ,CAACsG,MAAM,CAACyD,gBAAgB,CAAC,CAAC;IACpE,MAAM/I,OAAO,CAACiF,GAAG,CACf6D,oBAAoB,CAAC5D,GAAG,CAAC,MAAOhB,YAAY,IAAK;MAC/C,MAAM8E,KAAK,GAAG9E,YAAY,CAACP,EAAE;MAC7B,MAAMsF,OAAO,GAAG/E,YAAY,CAACgF,UAAU,CAAC,CAAC;MACzC,IAAI,CAACD,OAAO,EAAE,MAAM,IAAI5E,KAAK,CAAE,GAAE2E,KAAK,CAACtG,QAAQ,CAAC,CAAE,8CAA6C,CAAC;MAChG,MAAMH,WAAW,GAAG,MAAM,IAAI,CAAChE,SAAS,CAAC4K,kBAAkB,CAACH,KAAK,CAAC;MAClE,IAAI,CAACxJ,SAAS,CAACyJ,OAAO,CAAC,GAAG1G,WAAW;IACvC,CAAC,CACH,CAAC;EACH;AACF;AAAC6G,OAAA,CAAA/K,OAAA,GAAAA,OAAA"}
|
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_lodash","_loader","_constants","_logger","_utils","_pMapSeries","_chalk","_chokidar","_workspace","_watchQueue","_excluded","obj","__esModule","default","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_objectWithoutProperties","source","excluded","target","_objectWithoutPropertiesLoose","key","i","sourceSymbolKeys","indexOf","prototype","propertyIsEnumerable","call","sourceKeys","value","_toPropertyKey","configurable","writable","_toPrimitive","String","Symbol","toPrimitive","TypeError","Number","DEBOUNCE_WAIT_MS","Watcher","constructor","workspace","pubsub","watcherMain","options","WatchQueue","ipcEventsDir","ipcEvents","eventsDir","verbose","consumer","watch","_this$options","msgs","watchOpts","setTrackDirs","componentIds","values","trackDirs","triggerOnPreWatch","createWatcher","watcher","fsWatcher","onStart","scope","watchScopeInternalFiles","Promise","resolve","reject","onAll","on","onReady","loader","stop","event","filePath","startTime","Date","getTime","files","results","debounced","irrelevant","failureMsg","handleChange","duration","onChange","err","onError","endsWith","BIT_MAP","bitMapChangesInProgress","buildResults","watchQueue","add","handleBitmapChanges","onIdle","dirname","eventName","basename","logger","warn","triggerGotEvent","WORKSPACE_JSONC","triggerOnWorkspaceConfigChange","componentId","getComponentIdByPath","compIdStr","toString","changedFilesPerComponent","sleep","triggerCompChanges","undefined","join","msg","error","console","message","ms","setTimeout","updatedComponentId","hasId","ids","listIds","find","id","isEqual","ignoreVersion","debug","clearComponentCache","component","get","componentMap","state","_consumer","Error","compFilesRelativeToWorkspace","getFilesRelativeToConsumer","compFiles","nonCompFiles","partition","relativeFile","getRelativePathLinux","Boolean","p","removedFiles","compact","all","map","fs","pathExists","toStringWithoutVersion","bitMap","updateComponentPaths","f","getPathRelativeToConsumer","executeWatchOperationsOnComponent","previewsTrackDirs","_reloadConsumer","triggerOnBitmapChange","newDirs","difference","removedDirs","addResults","mapSeries","dir","flat","executeWatchOperationsOnRemove","chalk","bold","pub","WorkspaceAspect","createOnComponentRemovedEvent","triggerOnComponentRemove","isChange","isComponentWatchedExternally","idStr","createOnComponentChangeEvent","createOnComponentAddEvent","triggerOnComponentChange","triggerOnComponentAdd","OnComponentRemovedEvent","now","hook","OnComponentChangeEvent","OnComponentAddEvent","watcherData","multipleWatchers","m","compilerId","trackDir","findTrackDirByFilePathRecursively","pathNormalizeToLinux","parentDir","usePollingConf","globalConfig","CFG_WATCH_USE_POLLING","usePolling","ignoreLocalScope","pathToCheck","startsWith","path","chokidar","ignoreInitial","ignored","persistent","JSON","stringify","componentsFromBitMap","getAllComponents","bitId","rootDir","getRootDir","resolveComponentId","exports"],"sources":["watcher.ts"],"sourcesContent":["import { PubsubMain } from '@teambit/pubsub';\nimport fs from 'fs-extra';\nimport { dirname, basename } from 'path';\nimport { compact, difference, partition } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { BIT_MAP, CFG_WATCH_USE_POLLING, WORKSPACE_JSONC } 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 '@teambit/chokidar';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport {\n WorkspaceAspect,\n Workspace,\n OnComponentEventResult,\n OnComponentChangeEvent,\n OnComponentAddEvent,\n OnComponentRemovedEvent,\n} from '@teambit/workspace';\nimport { CheckTypes } from './check-types';\nimport { WatcherMain } from './watcher.main.runtime';\nimport { WatchQueue } from './watch-queue';\n\nexport type WatcherProcessData = { watchProcess: ChildProcess; compilerId: ComponentID; componentIds: ComponentID[] };\n\nexport type EventMessages = {\n onAll: Function;\n onStart: Function;\n onReady: Function;\n onChange: OnFileEventFunc;\n onAdd: OnFileEventFunc;\n onUnlink: OnFileEventFunc;\n onError: Function;\n};\n\nexport type OnFileEventFunc = (\n filePaths: string[],\n buildResults: OnComponentEventResult[],\n verbose: boolean,\n duration: number,\n failureMsg?: string\n) => void;\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 compile?: boolean; // whether compile modified/added components during watch process\n};\n\nconst DEBOUNCE_WAIT_MS = 100;\ntype PathLinux = string; // ts fails when importing it from @teambit/legacy/dist/utils/path.\n\nexport class Watcher {\n private fsWatcher: FSWatcher;\n private changedFilesPerComponent: { [componentId: string]: string[] } = {};\n private watchQueue = new WatchQueue();\n private bitMapChangesInProgress = false;\n private ipcEventsDir: string;\n private trackDirs: { [dir: PathLinux]: ComponentID } = {};\n private verbose = false;\n private multipleWatchers: WatcherProcessData[] = [];\n constructor(\n private workspace: Workspace,\n private pubsub: PubsubMain,\n private watcherMain: WatcherMain,\n private options: WatchOptions\n ) {\n this.ipcEventsDir = this.watcherMain.ipcEvents.eventsDir;\n this.verbose = this.options.verbose || false;\n }\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async watch() {\n const { msgs, ...watchOpts } = this.options;\n await this.setTrackDirs();\n const componentIds = Object.values(this.trackDirs);\n await this.watcherMain.triggerOnPreWatch(componentIds, watchOpts);\n await this.createWatcher();\n const watcher = this.fsWatcher;\n msgs?.onStart(this.workspace);\n\n await this.workspace.scope.watchScopeInternalFiles();\n\n return new Promise((resolve, reject) => {\n if (this.verbose) {\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 // console.log(this.fsWatcher.getWatched());\n loader.stop();\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('all', async (event, filePath) => {\n if (event !== 'change' && event !== 'add' && event !== 'unlink') return;\n const startTime = new Date().getTime();\n const { files, results, debounced, irrelevant, failureMsg } = await this.handleChange(filePath);\n if (debounced || irrelevant) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onChange(files, results, this.verbose, duration, failureMsg);\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(filePath: string): Promise<{\n results: OnComponentEventResult[];\n files: string[];\n failureMsg?: string;\n debounced?: boolean;\n irrelevant?: boolean; // file/dir is not part of any component\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 if (dirname(filePath) === this.ipcEventsDir) {\n const eventName = basename(filePath);\n if (eventName !== 'onPostInstall') {\n this.watcherMain.logger.warn(`eventName ${eventName} is not recognized, please handle it`);\n }\n await this.watcherMain.ipcEvents.triggerGotEvent(eventName as 'onPostInstall');\n return { results: [], files: [filePath] };\n }\n if (filePath.endsWith(WORKSPACE_JSONC)) {\n await this.workspace.triggerOnWorkspaceConfigChange();\n return { results: [], files: [filePath] };\n }\n const componentId = this.getComponentIdByPath(filePath);\n if (!componentId) {\n loader.stop();\n return { results: [], files: [], irrelevant: true };\n }\n const compIdStr = componentId.toString();\n if (this.changedFilesPerComponent[compIdStr]) {\n this.changedFilesPerComponent[compIdStr].push(filePath);\n loader.stop();\n return { results: [], files: [], 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));\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 private async triggerCompChanges(\n componentId: ComponentID,\n files: PathOsBasedAbsolute[]\n ): Promise<OnComponentEventResult[]> {\n let updatedComponentId: ComponentID | undefined = componentId;\n if (!(await this.workspace.hasId(componentId))) {\n // bitmap has changed meanwhile, which triggered `handleBitmapChanges`, which re-loaded consumer and updated versions\n // so the original componentId might not be in the workspace now, and we need to find the updated one\n const ids = await this.workspace.listIds();\n updatedComponentId = ids.find((id) => id.isEqual(componentId, { ignoreVersion: true }));\n if (!updatedComponentId) {\n logger.debug(`triggerCompChanges, the component ${componentId.toString()} was probably removed from .bitmap`);\n return [];\n }\n }\n this.workspace.clearComponentCache(updatedComponentId);\n const component = await this.workspace.get(updatedComponentId);\n const componentMap: ComponentMap = component.state._consumer.componentMap;\n if (!componentMap) {\n throw new Error(\n `unable to find componentMap for ${updatedComponentId.toString()}, make sure this component is in .bitmap`\n );\n }\n const compFilesRelativeToWorkspace = componentMap.getFilesRelativeToConsumer();\n const [compFiles, nonCompFiles] = partition(files, (filePath) => {\n const relativeFile = this.getRelativePathLinux(filePath);\n return Boolean(compFilesRelativeToWorkspace.find((p) => p === relativeFile));\n });\n // nonCompFiles are either, files that were removed from the filesystem or existing files that are ignored.\n // the compiler takes care of removedFiles differently, e.g. removes dists dir and old symlinks.\n const removedFiles = compact(\n await Promise.all(nonCompFiles.map(async (filePath) => ((await fs.pathExists(filePath)) ? null : filePath)))\n );\n\n if (!compFiles.length && !removedFiles.length) {\n logger.debug(\n `the following files are part of the component ${componentId.toStringWithoutVersion()} but configured to be ignored:\\n${files.join(\n '\\n'\n )}'`\n );\n return [];\n }\n this.consumer.bitMap.updateComponentPaths(\n componentId,\n compFiles.map((f) => this.consumer.getPathRelativeToConsumer(f)),\n removedFiles.map((f) => this.consumer.getPathRelativeToConsumer(f))\n );\n const buildResults = await this.executeWatchOperationsOnComponent(\n updatedComponentId,\n compFiles,\n removedFiles,\n true\n );\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 await this.workspace.triggerOnBitmapChange();\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 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 mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));\n }\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.createOnComponentRemovedEvent(componentId.toString()));\n await this.workspace.triggerOnComponentRemove(componentId);\n }\n\n private async executeWatchOperationsOnComponent(\n componentId: ComponentID,\n files: PathOsBasedAbsolute[],\n removedFiles: PathOsBasedAbsolute[] = [],\n isChange = true\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.createOnComponentChangeEvent(idStr, 'OnComponentChange'));\n } else {\n logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.createOnComponentAddEvent(idStr, 'OnComponentAdd'));\n }\n\n const buildResults = isChange\n ? await this.workspace.triggerOnComponentChange(componentId, files, removedFiles, this.options)\n : await this.workspace.triggerOnComponentAdd(componentId, this.options);\n\n return buildResults;\n }\n\n private createOnComponentRemovedEvent(idStr) {\n return new OnComponentRemovedEvent(Date.now(), idStr);\n }\n\n private createOnComponentChangeEvent(idStr, hook) {\n return new OnComponentChangeEvent(Date.now(), idStr, hook);\n }\n\n private createOnComponentAddEvent(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)));\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() {\n const usePollingConf = await this.watcherMain.globalConfig.get(CFG_WATCH_USE_POLLING);\n const usePolling = usePollingConf === 'true';\n // const useFsEventsConf = await this.watcherMain.globalConfig.get(CFG_WATCH_USE_FS_EVENTS);\n // const useFsEvents = useFsEventsConf === 'true';\n const ignoreLocalScope = (pathToCheck: string) => {\n if (pathToCheck.startsWith(this.ipcEventsDir)) return false;\n return (\n pathToCheck.startsWith(`${this.workspace.path}/.git/`) || pathToCheck.startsWith(`${this.workspace.path}/.bit/`)\n );\n };\n this.fsWatcher = chokidar.watch(this.workspace.path, {\n ignoreInitial: true,\n // `chokidar` matchers have Bash-parity, so Windows-style backslashes are not supported as separators.\n // (windows-style backslashes are converted to forward slashes)\n ignored: ['**/node_modules/**', '**/package.json', ignoreLocalScope],\n /**\n * default to false, although it causes high CPU usage.\n * see: https://github.com/paulmillr/chokidar/issues/1196#issuecomment-1711033539\n * there is a fix for this in master. once a new version of Chokidar is released, we can upgrade it and then\n * default to true.\n */\n usePolling,\n // useFsEvents,\n persistent: true,\n });\n if (this.verbose) {\n logger.console(`chokidar.options ${JSON.stringify(this.fsWatcher.options, undefined, 2)}`);\n }\n }\n\n private async setTrackDirs() {\n this.trackDirs = {};\n const componentsFromBitMap = this.consumer.bitMap.getAllComponents();\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const rootDir = componentMap.getRootDir();\n if (!rootDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[rootDir] = componentId;\n })\n );\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,WAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,UAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAK,OAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,OAAA;EAAA,MAAAR,IAAA,GAAAE,OAAA;EAAAM,MAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAS,YAAA;EAAA,MAAAT,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
@@ -8,8 +8,8 @@ import { Logger, LoggerMain } from '@teambit/logger';
|
|
|
8
8
|
import { PubsubMain } from '@teambit/pubsub';
|
|
9
9
|
import { Workspace } from '@teambit/workspace';
|
|
10
10
|
import { WatchOptions } from './watcher';
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export type OnPreWatch = (componentIds: ComponentID[], watchOpts: WatchOptions) => Promise<void>;
|
|
12
|
+
export type OnPreWatchSlot = SlotRegistry<OnPreWatch>;
|
|
13
13
|
export declare class WatcherMain {
|
|
14
14
|
private workspace;
|
|
15
15
|
private scope;
|
package/index.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { OnComponentEventResult } from '@teambit/workspace';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
const verboseComponentFilesArrayToString = (componentFiles = []) => {
|
|
5
|
+
return componentFiles.reduce((outputString, filePath) => `${outputString} \t - ${filePath}\n`, ``);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const resultsForExtensionArrayToString = (resultsForExtension, verbose) => {
|
|
9
|
+
return resultsForExtension.reduce(
|
|
10
|
+
(outputString, resultForExtension) =>
|
|
11
|
+
`${outputString}${chalk.green('√')}SUCCESS\t${resultForExtension.component}\n
|
|
12
|
+
${verbose ? resultForExtension.componentFilesAsString : ''}\n`,
|
|
13
|
+
''
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const formatWatchPathsSortByComponent = (trackDirs) => {
|
|
18
|
+
return Object.keys(trackDirs).reduce(
|
|
19
|
+
(outputString, watchPath) =>
|
|
20
|
+
`${outputString}
|
|
21
|
+
${chalk.green('√')} SUCCESS\t${trackDirs[watchPath]}\n
|
|
22
|
+
\t - ${watchPath}\n\n`,
|
|
23
|
+
` ${chalk.underline('STATUS\t\tCOMPONENT ID')}\n`
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* todo: this was implemented incorrectly.
|
|
29
|
+
* the original idea of `SerializableResults` was to have each one of the aspects registered to the slot, the
|
|
30
|
+
* ability to have their own formatting to their results, and then `toString()` method to print them.
|
|
31
|
+
* Here, the printing is specifically to the Compiler aspect. It should move to where it belongs.
|
|
32
|
+
*/
|
|
33
|
+
export function formatCompileResults(compileResults: OnComponentEventResult[], verbose: boolean) {
|
|
34
|
+
if (!compileResults.length || !Array.isArray(compileResults)) return '';
|
|
35
|
+
return compileResults
|
|
36
|
+
.filter((compileResult) => compileResult.results?.results && Array.isArray(compileResult.results?.results))
|
|
37
|
+
.map((compileResult) => ({
|
|
38
|
+
extensionId: compileResult.extensionId,
|
|
39
|
+
resultsForExtension: compileResult.results?.results?.map((resultForExtension) => ({
|
|
40
|
+
component: resultForExtension.component,
|
|
41
|
+
componentFilesAsString: verboseComponentFilesArrayToString(resultForExtension.buildResults),
|
|
42
|
+
})),
|
|
43
|
+
}))
|
|
44
|
+
.reduce(
|
|
45
|
+
(outputString, compileResult) =>
|
|
46
|
+
`${outputString}
|
|
47
|
+
${resultsForExtensionArrayToString(compileResult.resultsForExtension, verbose)}`,
|
|
48
|
+
` ${chalk.underline('STATUS\tCOMPONENT ID')}`
|
|
49
|
+
);
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/watcher",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.108",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/workspace/watcher",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.workspace",
|
|
8
8
|
"name": "watcher",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.108"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -16,33 +16,27 @@
|
|
|
16
16
|
"@teambit/chokidar": "3.5.6",
|
|
17
17
|
"fs-extra": "10.0.0",
|
|
18
18
|
"lodash": "4.17.21",
|
|
19
|
-
"core-js": "^3.0.0",
|
|
20
|
-
"@babel/runtime": "7.20.0",
|
|
21
19
|
"@teambit/harmony": "0.4.6",
|
|
22
20
|
"@teambit/component-id": "1.2.0",
|
|
23
|
-
"@teambit/workspace": "1.0.
|
|
24
|
-
"@teambit/cli": "0.0.
|
|
25
|
-
"@teambit/compiler": "1.0.
|
|
26
|
-
"@teambit/logger": "0.0.
|
|
27
|
-
"@teambit/pubsub": "1.0.
|
|
28
|
-
"@teambit/global-config": "0.0.
|
|
29
|
-
"@teambit/ipc-events": "1.0.
|
|
30
|
-
"@teambit/scope": "1.0.
|
|
21
|
+
"@teambit/workspace": "1.0.108",
|
|
22
|
+
"@teambit/cli": "0.0.840",
|
|
23
|
+
"@teambit/compiler": "1.0.108",
|
|
24
|
+
"@teambit/logger": "0.0.933",
|
|
25
|
+
"@teambit/pubsub": "1.0.108",
|
|
26
|
+
"@teambit/global-config": "0.0.842",
|
|
27
|
+
"@teambit/ipc-events": "1.0.108",
|
|
28
|
+
"@teambit/scope": "1.0.108"
|
|
31
29
|
},
|
|
32
30
|
"devDependencies": {
|
|
33
31
|
"@types/fs-extra": "9.0.7",
|
|
34
32
|
"@types/lodash": "4.14.165",
|
|
35
33
|
"@types/mocha": "9.1.0",
|
|
36
|
-
"@types/
|
|
37
|
-
"@types/
|
|
38
|
-
"@
|
|
39
|
-
"@types/jest": "^26.0.0",
|
|
40
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
|
34
|
+
"@types/jest": "^29.2.2",
|
|
35
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
36
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
|
41
37
|
},
|
|
42
38
|
"peerDependencies": {
|
|
43
|
-
"@teambit/legacy": "1.0.624"
|
|
44
|
-
"react": "^16.8.0 || ^17.0.0",
|
|
45
|
-
"react-dom": "^16.8.0 || ^17.0.0"
|
|
39
|
+
"@teambit/legacy": "1.0.624"
|
|
46
40
|
},
|
|
47
41
|
"license": "Apache-2.0",
|
|
48
42
|
"optionalDependencies": {},
|
|
@@ -56,7 +50,7 @@
|
|
|
56
50
|
},
|
|
57
51
|
"private": false,
|
|
58
52
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
53
|
+
"node": ">=16.0.0"
|
|
60
54
|
},
|
|
61
55
|
"repository": {
|
|
62
56
|
"type": "git",
|
|
@@ -65,12 +59,9 @@
|
|
|
65
59
|
"keywords": [
|
|
66
60
|
"bit",
|
|
67
61
|
"bit-aspect",
|
|
62
|
+
"bit-core-aspect",
|
|
68
63
|
"components",
|
|
69
64
|
"collaboration",
|
|
70
|
-
"web"
|
|
71
|
-
"react",
|
|
72
|
-
"react-components",
|
|
73
|
-
"angular",
|
|
74
|
-
"angular-components"
|
|
65
|
+
"web"
|
|
75
66
|
]
|
|
76
67
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"lib": [
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
4
|
+
"esnext",
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.Iterable"
|
|
9
7
|
],
|
|
10
|
-
"target": "
|
|
11
|
-
"module": "
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"allowJs": true,
|
|
14
|
-
"composite": true,
|
|
8
|
+
"target": "es2020",
|
|
9
|
+
"module": "es2020",
|
|
10
|
+
"jsx": "react-jsx",
|
|
15
11
|
"declaration": true,
|
|
16
12
|
"sourceMap": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
13
|
"experimentalDecorators": true,
|
|
19
|
-
"
|
|
14
|
+
"skipLibCheck": true,
|
|
20
15
|
"moduleResolution": "node",
|
|
21
16
|
"esModuleInterop": true,
|
|
22
|
-
"rootDir": ".",
|
|
23
17
|
"resolveJsonModule": true,
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"strictPropertyInitialization": false,
|
|
28
|
-
"strict": true,
|
|
29
|
-
"noImplicitAny": false,
|
|
30
|
-
"preserveConstEnums": true
|
|
18
|
+
"allowJs": true,
|
|
19
|
+
"outDir": "dist",
|
|
20
|
+
"emitDeclarationOnly": true
|
|
31
21
|
},
|
|
32
22
|
"exclude": [
|
|
23
|
+
"artifacts",
|
|
24
|
+
"public",
|
|
33
25
|
"dist",
|
|
26
|
+
"node_modules",
|
|
27
|
+
"package.json",
|
|
34
28
|
"esm.mjs",
|
|
35
|
-
"
|
|
29
|
+
"**/*.cjs",
|
|
30
|
+
"./dist"
|
|
36
31
|
],
|
|
37
32
|
"include": [
|
|
38
33
|
"**/*",
|
package/types/asset.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ declare module '*.png' {
|
|
|
5
5
|
declare module '*.svg' {
|
|
6
6
|
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
7
|
|
|
8
|
-
export const ReactComponent: FunctionComponent<
|
|
8
|
+
export const ReactComponent: FunctionComponent<
|
|
9
|
+
SVGProps<SVGSVGElement> & { title?: string }
|
|
10
|
+
>;
|
|
9
11
|
const src: string;
|
|
10
12
|
export default src;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
14
|
declare module '*.jpg' {
|
|
15
15
|
const value: any;
|
|
16
16
|
export = value;
|
|
@@ -27,3 +27,15 @@ declare module '*.bmp' {
|
|
|
27
27
|
const value: any;
|
|
28
28
|
export = value;
|
|
29
29
|
}
|
|
30
|
+
declare module '*.otf' {
|
|
31
|
+
const value: any;
|
|
32
|
+
export = value;
|
|
33
|
+
}
|
|
34
|
+
declare module '*.woff' {
|
|
35
|
+
const value: any;
|
|
36
|
+
export = value;
|
|
37
|
+
}
|
|
38
|
+
declare module '*.woff2' {
|
|
39
|
+
const value: any;
|
|
40
|
+
export = value;
|
|
41
|
+
}
|
package/watch-queue.ts
ADDED
|
@@ -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.cmd.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import moment from 'moment';
|
|
3
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
|
4
|
+
import type { Logger } from '@teambit/logger';
|
|
5
|
+
import type { BitBaseEvent, PubsubMain } from '@teambit/pubsub';
|
|
6
|
+
import { OnComponentEventResult } from '@teambit/workspace';
|
|
7
|
+
|
|
8
|
+
// import IDs and events
|
|
9
|
+
import { CompilerAspect, CompilerErrorEvent } from '@teambit/compiler';
|
|
10
|
+
|
|
11
|
+
import { EventMessages, WatchOptions } from './watcher';
|
|
12
|
+
import { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';
|
|
13
|
+
import { CheckTypes } from './check-types';
|
|
14
|
+
import { WatcherMain } from './watcher.main.runtime';
|
|
15
|
+
|
|
16
|
+
export type WatchCmdOpts = {
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
skipPreCompilation?: boolean;
|
|
19
|
+
checkTypes?: string | boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class WatchCommand implements Command {
|
|
23
|
+
name = 'watch';
|
|
24
|
+
description = 'automatically recompile modified components (on save)';
|
|
25
|
+
extendedDescription = `by default, the watcher doesn't use polling, to keep the CPU idle.
|
|
26
|
+
if this doesn't work well for you, run "bit config set watch_use_polling true" to use polling.`;
|
|
27
|
+
helpUrl = 'reference/compiling/compiler-overview';
|
|
28
|
+
alias = '';
|
|
29
|
+
group = 'development';
|
|
30
|
+
options = [
|
|
31
|
+
['v', 'verbose', 'show all watch events and compiler verbose output'],
|
|
32
|
+
['', 'skip-pre-compilation', 'skip compilation step before starting to watch'],
|
|
33
|
+
[
|
|
34
|
+
't',
|
|
35
|
+
'check-types [string]',
|
|
36
|
+
'EXPERIMENTAL. show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project',
|
|
37
|
+
],
|
|
38
|
+
] as CommandOptions;
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
/**
|
|
42
|
+
* logger extension.
|
|
43
|
+
*/
|
|
44
|
+
private pubsub: PubsubMain,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* logger extension.
|
|
48
|
+
*/
|
|
49
|
+
private logger: Logger,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* watcher extension.
|
|
53
|
+
*/
|
|
54
|
+
private watcher: WatcherMain
|
|
55
|
+
) {
|
|
56
|
+
this.registerToEvents();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private registerToEvents() {
|
|
60
|
+
this.pubsub.sub(CompilerAspect.id, this.eventsListener);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private eventsListener = (event: BitBaseEvent<any>) => {
|
|
64
|
+
switch (event.type) {
|
|
65
|
+
case CompilerErrorEvent.TYPE:
|
|
66
|
+
this.logger.console(`Watcher error ${event.data.error}, 'error'`);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
async report(cliArgs: [], watchCmdOpts: WatchCmdOpts) {
|
|
73
|
+
const { verbose, checkTypes } = watchCmdOpts;
|
|
74
|
+
const getCheckTypesEnum = () => {
|
|
75
|
+
switch (checkTypes) {
|
|
76
|
+
case undefined:
|
|
77
|
+
case false:
|
|
78
|
+
return CheckTypes.None;
|
|
79
|
+
case 'project':
|
|
80
|
+
case true: // project is the default
|
|
81
|
+
return CheckTypes.EntireProject;
|
|
82
|
+
case 'file':
|
|
83
|
+
return CheckTypes.ChangedFile;
|
|
84
|
+
default:
|
|
85
|
+
throw new Error(`check-types can be either "file" or "project". got "${checkTypes}"`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const watchOpts: WatchOptions = {
|
|
89
|
+
msgs: getMessages(this.logger),
|
|
90
|
+
verbose,
|
|
91
|
+
compile: true,
|
|
92
|
+
preCompile: !watchCmdOpts.skipPreCompilation,
|
|
93
|
+
spawnTSServer: Boolean(checkTypes), // if check-types is enabled, it must spawn the tsserver.
|
|
94
|
+
checkTypes: getCheckTypesEnum(),
|
|
95
|
+
};
|
|
96
|
+
await this.watcher.watch(watchOpts);
|
|
97
|
+
return 'watcher terminated';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getMessages(logger: Logger): EventMessages {
|
|
102
|
+
return {
|
|
103
|
+
onAll: (event: string, path: string) => logger.console(`Event: "${event}". Path: ${path}`),
|
|
104
|
+
onStart: () => {},
|
|
105
|
+
onReady: (workspace, watchPathsSortByComponent, verbose?: boolean) => {
|
|
106
|
+
clearOutdatedData();
|
|
107
|
+
if (verbose) {
|
|
108
|
+
logger.console(formatWatchPathsSortByComponent(watchPathsSortByComponent));
|
|
109
|
+
}
|
|
110
|
+
logger.console(
|
|
111
|
+
chalk.yellow(
|
|
112
|
+
`Watching for component changes in workspace ${workspace.config.name} (${moment().format('HH:mm:ss')})...\n`
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
onChange: (...args) => {
|
|
117
|
+
printOnFileEvent(logger, 'changed', ...args);
|
|
118
|
+
},
|
|
119
|
+
onAdd: (...args) => {
|
|
120
|
+
printOnFileEvent(logger, 'added', ...args);
|
|
121
|
+
},
|
|
122
|
+
onUnlink: (...args) => {
|
|
123
|
+
printOnFileEvent(logger, 'removed', ...args);
|
|
124
|
+
},
|
|
125
|
+
onError: (err) => {
|
|
126
|
+
logger.console(`Watcher error ${err}`);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function printOnFileEvent(
|
|
132
|
+
logger: Logger,
|
|
133
|
+
eventMsgPlaceholder: 'changed' | 'added' | 'removed',
|
|
134
|
+
filePaths: string[],
|
|
135
|
+
buildResults: OnComponentEventResult[],
|
|
136
|
+
verbose: boolean,
|
|
137
|
+
duration: number,
|
|
138
|
+
failureMsg?: string
|
|
139
|
+
) {
|
|
140
|
+
const files = filePaths.join(', ');
|
|
141
|
+
if (!buildResults.length) {
|
|
142
|
+
if (!failureMsg) {
|
|
143
|
+
if (verbose) logger.console(`The files ${files} have been ${eventMsgPlaceholder}, but nothing to compile\n\n`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
logger.console(`${failureMsg}\n\n`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
logger.console(`The file(s) ${files} have been ${eventMsgPlaceholder}.\n\n`);
|
|
150
|
+
logger.console(formatCompileResults(buildResults, verbose));
|
|
151
|
+
logger.console(`Finished. (${duration}ms)`);
|
|
152
|
+
logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* with console.clear() all history is deleted from the console. this function preserver the history.
|
|
157
|
+
*/
|
|
158
|
+
function clearOutdatedData() {
|
|
159
|
+
process.stdout.write('\x1Bc');
|
|
160
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
|
2
|
+
import { SlotRegistry, Slot } from '@teambit/harmony';
|
|
3
|
+
import GlobalConfigAspect, { GlobalConfigMain } from '@teambit/global-config';
|
|
4
|
+
import ScopeAspect, { ScopeMain } from '@teambit/scope';
|
|
5
|
+
import { ComponentID } from '@teambit/component-id';
|
|
6
|
+
import IpcEventsAspect, { IpcEventsMain } from '@teambit/ipc-events';
|
|
7
|
+
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
8
|
+
import { PubsubAspect, PubsubMain } from '@teambit/pubsub';
|
|
9
|
+
import WorkspaceAspect, { Workspace } from '@teambit/workspace';
|
|
10
|
+
import pMapSeries from 'p-map-series';
|
|
11
|
+
import { WatchCommand } from './watch.cmd';
|
|
12
|
+
import { Watcher, WatchOptions } from './watcher';
|
|
13
|
+
import { WatcherAspect } from './watcher.aspect';
|
|
14
|
+
|
|
15
|
+
export type OnPreWatch = (componentIds: ComponentID[], watchOpts: WatchOptions) => Promise<void>;
|
|
16
|
+
export type OnPreWatchSlot = SlotRegistry<OnPreWatch>;
|
|
17
|
+
|
|
18
|
+
export class WatcherMain {
|
|
19
|
+
constructor(
|
|
20
|
+
private workspace: Workspace,
|
|
21
|
+
private scope: ScopeMain,
|
|
22
|
+
private pubsub: PubsubMain,
|
|
23
|
+
private onPreWatchSlot: OnPreWatchSlot,
|
|
24
|
+
readonly ipcEvents: IpcEventsMain,
|
|
25
|
+
readonly logger: Logger,
|
|
26
|
+
readonly globalConfig: GlobalConfigMain
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
async watch(opts: WatchOptions) {
|
|
30
|
+
const watcher = new Watcher(this.workspace, this.pubsub, this, opts);
|
|
31
|
+
await watcher.watch();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async watchScopeInternalFiles() {
|
|
35
|
+
await this.scope.watchScopeInternalFiles();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async triggerOnPreWatch(componentIds: ComponentID[], watchOpts: WatchOptions) {
|
|
39
|
+
const preWatchFunctions = this.onPreWatchSlot.values();
|
|
40
|
+
await pMapSeries(preWatchFunctions, async (func) => {
|
|
41
|
+
await func(componentIds, watchOpts);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
registerOnPreWatch(onPreWatchFunc: OnPreWatch) {
|
|
46
|
+
this.onPreWatchSlot.register(onPreWatchFunc);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static slots = [Slot.withType<OnPreWatch>()];
|
|
51
|
+
static dependencies = [
|
|
52
|
+
CLIAspect,
|
|
53
|
+
WorkspaceAspect,
|
|
54
|
+
ScopeAspect,
|
|
55
|
+
PubsubAspect,
|
|
56
|
+
LoggerAspect,
|
|
57
|
+
IpcEventsAspect,
|
|
58
|
+
GlobalConfigAspect,
|
|
59
|
+
];
|
|
60
|
+
static runtime = MainRuntime;
|
|
61
|
+
|
|
62
|
+
static async provider(
|
|
63
|
+
[cli, workspace, scope, pubsub, loggerMain, ipcEvents, globalConfig]: [
|
|
64
|
+
CLIMain,
|
|
65
|
+
Workspace,
|
|
66
|
+
ScopeMain,
|
|
67
|
+
PubsubMain,
|
|
68
|
+
LoggerMain,
|
|
69
|
+
IpcEventsMain,
|
|
70
|
+
GlobalConfigMain
|
|
71
|
+
],
|
|
72
|
+
_,
|
|
73
|
+
[onPreWatchSlot]: [OnPreWatchSlot]
|
|
74
|
+
) {
|
|
75
|
+
const logger = loggerMain.createLogger(WatcherAspect.id);
|
|
76
|
+
const watcherMain = new WatcherMain(workspace, scope, pubsub, onPreWatchSlot, ipcEvents, logger, globalConfig);
|
|
77
|
+
const watchCmd = new WatchCommand(pubsub, logger, watcherMain);
|
|
78
|
+
cli.register(watchCmd);
|
|
79
|
+
return watcherMain;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
WatcherAspect.addRuntime(WatcherMain);
|
|
84
|
+
|
|
85
|
+
export default WatcherMain;
|
package/watcher.ts
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { PubsubMain } from '@teambit/pubsub';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { dirname, basename } from 'path';
|
|
4
|
+
import { compact, difference, partition } from 'lodash';
|
|
5
|
+
import { ComponentID } from '@teambit/component-id';
|
|
6
|
+
import loader from '@teambit/legacy/dist/cli/loader';
|
|
7
|
+
import { BIT_MAP, CFG_WATCH_USE_POLLING, WORKSPACE_JSONC } from '@teambit/legacy/dist/constants';
|
|
8
|
+
import { Consumer } from '@teambit/legacy/dist/consumer';
|
|
9
|
+
import logger from '@teambit/legacy/dist/logger/logger';
|
|
10
|
+
import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
|
|
11
|
+
import mapSeries from 'p-map-series';
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
import { ChildProcess } from 'child_process';
|
|
14
|
+
import chokidar, { FSWatcher } from '@teambit/chokidar';
|
|
15
|
+
import ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';
|
|
16
|
+
import { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
|
|
17
|
+
import { CompilationInitiator } from '@teambit/compiler';
|
|
18
|
+
import {
|
|
19
|
+
WorkspaceAspect,
|
|
20
|
+
Workspace,
|
|
21
|
+
OnComponentEventResult,
|
|
22
|
+
OnComponentChangeEvent,
|
|
23
|
+
OnComponentAddEvent,
|
|
24
|
+
OnComponentRemovedEvent,
|
|
25
|
+
} from '@teambit/workspace';
|
|
26
|
+
import { CheckTypes } from './check-types';
|
|
27
|
+
import { WatcherMain } from './watcher.main.runtime';
|
|
28
|
+
import { WatchQueue } from './watch-queue';
|
|
29
|
+
|
|
30
|
+
export type WatcherProcessData = { watchProcess: ChildProcess; compilerId: ComponentID; componentIds: ComponentID[] };
|
|
31
|
+
|
|
32
|
+
export type EventMessages = {
|
|
33
|
+
onAll: Function;
|
|
34
|
+
onStart: Function;
|
|
35
|
+
onReady: Function;
|
|
36
|
+
onChange: OnFileEventFunc;
|
|
37
|
+
onAdd: OnFileEventFunc;
|
|
38
|
+
onUnlink: OnFileEventFunc;
|
|
39
|
+
onError: Function;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type OnFileEventFunc = (
|
|
43
|
+
filePaths: string[],
|
|
44
|
+
buildResults: OnComponentEventResult[],
|
|
45
|
+
verbose: boolean,
|
|
46
|
+
duration: number,
|
|
47
|
+
failureMsg?: string
|
|
48
|
+
) => void;
|
|
49
|
+
|
|
50
|
+
export type WatchOptions = {
|
|
51
|
+
msgs?: EventMessages;
|
|
52
|
+
initiator?: CompilationInitiator;
|
|
53
|
+
verbose?: boolean; // print watch events to the console. (also ts-server events if spawnTSServer is true)
|
|
54
|
+
spawnTSServer?: boolean; // needed for check types and extract API/docs.
|
|
55
|
+
checkTypes?: CheckTypes; // if enabled, the spawnTSServer becomes true.
|
|
56
|
+
preCompile?: boolean; // whether compile all components before start watching
|
|
57
|
+
compile?: boolean; // whether compile modified/added components during watch process
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const DEBOUNCE_WAIT_MS = 100;
|
|
61
|
+
type PathLinux = string; // ts fails when importing it from @teambit/legacy/dist/utils/path.
|
|
62
|
+
|
|
63
|
+
export class Watcher {
|
|
64
|
+
private fsWatcher: FSWatcher;
|
|
65
|
+
private changedFilesPerComponent: { [componentId: string]: string[] } = {};
|
|
66
|
+
private watchQueue = new WatchQueue();
|
|
67
|
+
private bitMapChangesInProgress = false;
|
|
68
|
+
private ipcEventsDir: string;
|
|
69
|
+
private trackDirs: { [dir: PathLinux]: ComponentID } = {};
|
|
70
|
+
private verbose = false;
|
|
71
|
+
private multipleWatchers: WatcherProcessData[] = [];
|
|
72
|
+
constructor(
|
|
73
|
+
private workspace: Workspace,
|
|
74
|
+
private pubsub: PubsubMain,
|
|
75
|
+
private watcherMain: WatcherMain,
|
|
76
|
+
private options: WatchOptions
|
|
77
|
+
) {
|
|
78
|
+
this.ipcEventsDir = this.watcherMain.ipcEvents.eventsDir;
|
|
79
|
+
this.verbose = this.options.verbose || false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get consumer(): Consumer {
|
|
83
|
+
return this.workspace.consumer;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async watch() {
|
|
87
|
+
const { msgs, ...watchOpts } = this.options;
|
|
88
|
+
await this.setTrackDirs();
|
|
89
|
+
const componentIds = Object.values(this.trackDirs);
|
|
90
|
+
await this.watcherMain.triggerOnPreWatch(componentIds, watchOpts);
|
|
91
|
+
await this.createWatcher();
|
|
92
|
+
const watcher = this.fsWatcher;
|
|
93
|
+
msgs?.onStart(this.workspace);
|
|
94
|
+
|
|
95
|
+
await this.workspace.scope.watchScopeInternalFiles();
|
|
96
|
+
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
if (this.verbose) {
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
if (msgs?.onAll) watcher.on('all', msgs?.onAll);
|
|
101
|
+
}
|
|
102
|
+
watcher.on('ready', () => {
|
|
103
|
+
msgs?.onReady(this.workspace, this.trackDirs, this.verbose);
|
|
104
|
+
// console.log(this.fsWatcher.getWatched());
|
|
105
|
+
loader.stop();
|
|
106
|
+
});
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
108
|
+
watcher.on('all', async (event, filePath) => {
|
|
109
|
+
if (event !== 'change' && event !== 'add' && event !== 'unlink') return;
|
|
110
|
+
const startTime = new Date().getTime();
|
|
111
|
+
const { files, results, debounced, irrelevant, failureMsg } = await this.handleChange(filePath);
|
|
112
|
+
if (debounced || irrelevant) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const duration = new Date().getTime() - startTime;
|
|
116
|
+
msgs?.onChange(files, results, this.verbose, duration, failureMsg);
|
|
117
|
+
});
|
|
118
|
+
watcher.on('error', (err) => {
|
|
119
|
+
msgs?.onError(err);
|
|
120
|
+
reject(err);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* *** DEBOUNCING ***
|
|
127
|
+
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
128
|
+
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
129
|
+
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
130
|
+
* if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,
|
|
131
|
+
* it'll only add the file to `this.changedFilesPerComponent` prop.
|
|
132
|
+
* once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,
|
|
133
|
+
* indicating the next file-change to start a new execution.
|
|
134
|
+
*
|
|
135
|
+
* implementation wise, `lodash.debounce` doesn't help here, because:
|
|
136
|
+
* A) it doesn't return the results, unless "leading" option is true. here, it must be false, otherwise, it'll start
|
|
137
|
+
* the execution immediately.
|
|
138
|
+
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
139
|
+
* other components undesirably.
|
|
140
|
+
*
|
|
141
|
+
* *** QUEUE ***
|
|
142
|
+
* the debouncing helps to not execute the same component multiple times concurrently. however, multiple components
|
|
143
|
+
* and .bitmap changes execution can still be processed concurrently.
|
|
144
|
+
* the following example explains why this is an issue.
|
|
145
|
+
* compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.
|
|
146
|
+
* all these changes get pulled at the same time by "git pull", as a result, the execution of compA and the .bitmap
|
|
147
|
+
* happen at the same time.
|
|
148
|
+
* during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this
|
|
149
|
+
* id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.
|
|
150
|
+
* after this change, the workspace doesn't have this id anymore, which will trigger an error.
|
|
151
|
+
* to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all
|
|
152
|
+
* other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).
|
|
153
|
+
* once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.
|
|
154
|
+
* in the example above, at this stage, the id will be resolved to compA@0.0.2.
|
|
155
|
+
* one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at
|
|
156
|
+
* the same time. (the same way is done when loading all components from the filesystem/scope).
|
|
157
|
+
* this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the
|
|
158
|
+
* .bitmap execution starts.
|
|
159
|
+
*/
|
|
160
|
+
private async handleChange(filePath: string): Promise<{
|
|
161
|
+
results: OnComponentEventResult[];
|
|
162
|
+
files: string[];
|
|
163
|
+
failureMsg?: string;
|
|
164
|
+
debounced?: boolean;
|
|
165
|
+
irrelevant?: boolean; // file/dir is not part of any component
|
|
166
|
+
}> {
|
|
167
|
+
try {
|
|
168
|
+
if (filePath.endsWith(BIT_MAP)) {
|
|
169
|
+
this.bitMapChangesInProgress = true;
|
|
170
|
+
const buildResults = await this.watchQueue.add(() => this.handleBitmapChanges());
|
|
171
|
+
this.bitMapChangesInProgress = false;
|
|
172
|
+
loader.stop();
|
|
173
|
+
return { results: buildResults, files: [filePath] };
|
|
174
|
+
}
|
|
175
|
+
if (this.bitMapChangesInProgress) {
|
|
176
|
+
await this.watchQueue.onIdle();
|
|
177
|
+
}
|
|
178
|
+
if (dirname(filePath) === this.ipcEventsDir) {
|
|
179
|
+
const eventName = basename(filePath);
|
|
180
|
+
if (eventName !== 'onPostInstall') {
|
|
181
|
+
this.watcherMain.logger.warn(`eventName ${eventName} is not recognized, please handle it`);
|
|
182
|
+
}
|
|
183
|
+
await this.watcherMain.ipcEvents.triggerGotEvent(eventName as 'onPostInstall');
|
|
184
|
+
return { results: [], files: [filePath] };
|
|
185
|
+
}
|
|
186
|
+
if (filePath.endsWith(WORKSPACE_JSONC)) {
|
|
187
|
+
await this.workspace.triggerOnWorkspaceConfigChange();
|
|
188
|
+
return { results: [], files: [filePath] };
|
|
189
|
+
}
|
|
190
|
+
const componentId = this.getComponentIdByPath(filePath);
|
|
191
|
+
if (!componentId) {
|
|
192
|
+
loader.stop();
|
|
193
|
+
return { results: [], files: [], irrelevant: true };
|
|
194
|
+
}
|
|
195
|
+
const compIdStr = componentId.toString();
|
|
196
|
+
if (this.changedFilesPerComponent[compIdStr]) {
|
|
197
|
+
this.changedFilesPerComponent[compIdStr].push(filePath);
|
|
198
|
+
loader.stop();
|
|
199
|
+
return { results: [], files: [], debounced: true };
|
|
200
|
+
}
|
|
201
|
+
this.changedFilesPerComponent[compIdStr] = [filePath];
|
|
202
|
+
await this.sleep(DEBOUNCE_WAIT_MS);
|
|
203
|
+
const files = this.changedFilesPerComponent[compIdStr];
|
|
204
|
+
delete this.changedFilesPerComponent[compIdStr];
|
|
205
|
+
|
|
206
|
+
const buildResults = await this.watchQueue.add(() => this.triggerCompChanges(componentId, files));
|
|
207
|
+
const failureMsg = buildResults.length
|
|
208
|
+
? undefined
|
|
209
|
+
: `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;
|
|
210
|
+
loader.stop();
|
|
211
|
+
return { results: buildResults, files, failureMsg };
|
|
212
|
+
} catch (err: any) {
|
|
213
|
+
const msg = `watcher found an error while handling ${filePath}`;
|
|
214
|
+
logger.error(msg, err);
|
|
215
|
+
logger.console(`${msg}, ${err.message}`);
|
|
216
|
+
loader.stop();
|
|
217
|
+
return { results: [], files: [filePath], failureMsg: err.message };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private async sleep(ms: number) {
|
|
222
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private async triggerCompChanges(
|
|
226
|
+
componentId: ComponentID,
|
|
227
|
+
files: PathOsBasedAbsolute[]
|
|
228
|
+
): Promise<OnComponentEventResult[]> {
|
|
229
|
+
let updatedComponentId: ComponentID | undefined = componentId;
|
|
230
|
+
if (!(await this.workspace.hasId(componentId))) {
|
|
231
|
+
// bitmap has changed meanwhile, which triggered `handleBitmapChanges`, which re-loaded consumer and updated versions
|
|
232
|
+
// so the original componentId might not be in the workspace now, and we need to find the updated one
|
|
233
|
+
const ids = await this.workspace.listIds();
|
|
234
|
+
updatedComponentId = ids.find((id) => id.isEqual(componentId, { ignoreVersion: true }));
|
|
235
|
+
if (!updatedComponentId) {
|
|
236
|
+
logger.debug(`triggerCompChanges, the component ${componentId.toString()} was probably removed from .bitmap`);
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
this.workspace.clearComponentCache(updatedComponentId);
|
|
241
|
+
const component = await this.workspace.get(updatedComponentId);
|
|
242
|
+
const componentMap: ComponentMap = component.state._consumer.componentMap;
|
|
243
|
+
if (!componentMap) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`unable to find componentMap for ${updatedComponentId.toString()}, make sure this component is in .bitmap`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
const compFilesRelativeToWorkspace = componentMap.getFilesRelativeToConsumer();
|
|
249
|
+
const [compFiles, nonCompFiles] = partition(files, (filePath) => {
|
|
250
|
+
const relativeFile = this.getRelativePathLinux(filePath);
|
|
251
|
+
return Boolean(compFilesRelativeToWorkspace.find((p) => p === relativeFile));
|
|
252
|
+
});
|
|
253
|
+
// nonCompFiles are either, files that were removed from the filesystem or existing files that are ignored.
|
|
254
|
+
// the compiler takes care of removedFiles differently, e.g. removes dists dir and old symlinks.
|
|
255
|
+
const removedFiles = compact(
|
|
256
|
+
await Promise.all(nonCompFiles.map(async (filePath) => ((await fs.pathExists(filePath)) ? null : filePath)))
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
if (!compFiles.length && !removedFiles.length) {
|
|
260
|
+
logger.debug(
|
|
261
|
+
`the following files are part of the component ${componentId.toStringWithoutVersion()} but configured to be ignored:\n${files.join(
|
|
262
|
+
'\n'
|
|
263
|
+
)}'`
|
|
264
|
+
);
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
this.consumer.bitMap.updateComponentPaths(
|
|
268
|
+
componentId,
|
|
269
|
+
compFiles.map((f) => this.consumer.getPathRelativeToConsumer(f)),
|
|
270
|
+
removedFiles.map((f) => this.consumer.getPathRelativeToConsumer(f))
|
|
271
|
+
);
|
|
272
|
+
const buildResults = await this.executeWatchOperationsOnComponent(
|
|
273
|
+
updatedComponentId,
|
|
274
|
+
compFiles,
|
|
275
|
+
removedFiles,
|
|
276
|
+
true
|
|
277
|
+
);
|
|
278
|
+
return buildResults;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.
|
|
283
|
+
*/
|
|
284
|
+
private async handleBitmapChanges(): Promise<OnComponentEventResult[]> {
|
|
285
|
+
const previewsTrackDirs = { ...this.trackDirs };
|
|
286
|
+
await this.workspace._reloadConsumer();
|
|
287
|
+
await this.setTrackDirs();
|
|
288
|
+
await this.workspace.triggerOnBitmapChange();
|
|
289
|
+
const newDirs: string[] = difference(Object.keys(this.trackDirs), Object.keys(previewsTrackDirs));
|
|
290
|
+
const removedDirs: string[] = difference(Object.keys(previewsTrackDirs), Object.keys(this.trackDirs));
|
|
291
|
+
const results: OnComponentEventResult[] = [];
|
|
292
|
+
if (newDirs.length) {
|
|
293
|
+
const addResults = await mapSeries(newDirs, async (dir) =>
|
|
294
|
+
this.executeWatchOperationsOnComponent(this.trackDirs[dir], [], [], false)
|
|
295
|
+
);
|
|
296
|
+
results.push(...addResults.flat());
|
|
297
|
+
}
|
|
298
|
+
if (removedDirs.length) {
|
|
299
|
+
await mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return results;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private async executeWatchOperationsOnRemove(componentId: ComponentID) {
|
|
306
|
+
logger.debug(`running OnComponentRemove hook for ${chalk.bold(componentId.toString())}`);
|
|
307
|
+
this.pubsub.pub(WorkspaceAspect.id, this.createOnComponentRemovedEvent(componentId.toString()));
|
|
308
|
+
await this.workspace.triggerOnComponentRemove(componentId);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private async executeWatchOperationsOnComponent(
|
|
312
|
+
componentId: ComponentID,
|
|
313
|
+
files: PathOsBasedAbsolute[],
|
|
314
|
+
removedFiles: PathOsBasedAbsolute[] = [],
|
|
315
|
+
isChange = true
|
|
316
|
+
): Promise<OnComponentEventResult[]> {
|
|
317
|
+
if (this.isComponentWatchedExternally(componentId)) {
|
|
318
|
+
// update capsule, once done, it automatically triggers the external watcher
|
|
319
|
+
await this.workspace.get(componentId);
|
|
320
|
+
return [];
|
|
321
|
+
}
|
|
322
|
+
const idStr = componentId.toString();
|
|
323
|
+
|
|
324
|
+
if (isChange) {
|
|
325
|
+
logger.debug(`running OnComponentChange hook for ${chalk.bold(idStr)}`);
|
|
326
|
+
this.pubsub.pub(WorkspaceAspect.id, this.createOnComponentChangeEvent(idStr, 'OnComponentChange'));
|
|
327
|
+
} else {
|
|
328
|
+
logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);
|
|
329
|
+
this.pubsub.pub(WorkspaceAspect.id, this.createOnComponentAddEvent(idStr, 'OnComponentAdd'));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const buildResults = isChange
|
|
333
|
+
? await this.workspace.triggerOnComponentChange(componentId, files, removedFiles, this.options)
|
|
334
|
+
: await this.workspace.triggerOnComponentAdd(componentId, this.options);
|
|
335
|
+
|
|
336
|
+
return buildResults;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private createOnComponentRemovedEvent(idStr) {
|
|
340
|
+
return new OnComponentRemovedEvent(Date.now(), idStr);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private createOnComponentChangeEvent(idStr, hook) {
|
|
344
|
+
return new OnComponentChangeEvent(Date.now(), idStr, hook);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private createOnComponentAddEvent(idStr, hook) {
|
|
348
|
+
return new OnComponentAddEvent(Date.now(), idStr, hook);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
private isComponentWatchedExternally(componentId: ComponentID) {
|
|
352
|
+
const watcherData = this.multipleWatchers.find((m) => m.componentIds.find((id) => id.isEqual(componentId)));
|
|
353
|
+
if (watcherData) {
|
|
354
|
+
logger.debug(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private getComponentIdByPath(filePath: string): ComponentID | null {
|
|
361
|
+
const relativeFile = this.getRelativePathLinux(filePath);
|
|
362
|
+
const trackDir = this.findTrackDirByFilePathRecursively(relativeFile);
|
|
363
|
+
if (!trackDir) {
|
|
364
|
+
// the file is not part of any component. If it was a new component, or a new file of
|
|
365
|
+
// existing component, then, handleBitmapChanges() should deal with it.
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
return this.trackDirs[trackDir];
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private getRelativePathLinux(filePath: string) {
|
|
372
|
+
return pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(filePath));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
private findTrackDirByFilePathRecursively(filePath: string): string | null {
|
|
376
|
+
if (this.trackDirs[filePath]) return filePath;
|
|
377
|
+
const parentDir = dirname(filePath);
|
|
378
|
+
if (parentDir === filePath) return null;
|
|
379
|
+
return this.findTrackDirByFilePathRecursively(parentDir);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private async createWatcher() {
|
|
383
|
+
const usePollingConf = await this.watcherMain.globalConfig.get(CFG_WATCH_USE_POLLING);
|
|
384
|
+
const usePolling = usePollingConf === 'true';
|
|
385
|
+
// const useFsEventsConf = await this.watcherMain.globalConfig.get(CFG_WATCH_USE_FS_EVENTS);
|
|
386
|
+
// const useFsEvents = useFsEventsConf === 'true';
|
|
387
|
+
const ignoreLocalScope = (pathToCheck: string) => {
|
|
388
|
+
if (pathToCheck.startsWith(this.ipcEventsDir)) return false;
|
|
389
|
+
return (
|
|
390
|
+
pathToCheck.startsWith(`${this.workspace.path}/.git/`) || pathToCheck.startsWith(`${this.workspace.path}/.bit/`)
|
|
391
|
+
);
|
|
392
|
+
};
|
|
393
|
+
this.fsWatcher = chokidar.watch(this.workspace.path, {
|
|
394
|
+
ignoreInitial: true,
|
|
395
|
+
// `chokidar` matchers have Bash-parity, so Windows-style backslashes are not supported as separators.
|
|
396
|
+
// (windows-style backslashes are converted to forward slashes)
|
|
397
|
+
ignored: ['**/node_modules/**', '**/package.json', ignoreLocalScope],
|
|
398
|
+
/**
|
|
399
|
+
* default to false, although it causes high CPU usage.
|
|
400
|
+
* see: https://github.com/paulmillr/chokidar/issues/1196#issuecomment-1711033539
|
|
401
|
+
* there is a fix for this in master. once a new version of Chokidar is released, we can upgrade it and then
|
|
402
|
+
* default to true.
|
|
403
|
+
*/
|
|
404
|
+
usePolling,
|
|
405
|
+
// useFsEvents,
|
|
406
|
+
persistent: true,
|
|
407
|
+
});
|
|
408
|
+
if (this.verbose) {
|
|
409
|
+
logger.console(`chokidar.options ${JSON.stringify(this.fsWatcher.options, undefined, 2)}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
private async setTrackDirs() {
|
|
414
|
+
this.trackDirs = {};
|
|
415
|
+
const componentsFromBitMap = this.consumer.bitMap.getAllComponents();
|
|
416
|
+
await Promise.all(
|
|
417
|
+
componentsFromBitMap.map(async (componentMap) => {
|
|
418
|
+
const bitId = componentMap.id;
|
|
419
|
+
const rootDir = componentMap.getRootDir();
|
|
420
|
+
if (!rootDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);
|
|
421
|
+
const componentId = await this.workspace.resolveComponentId(bitId);
|
|
422
|
+
this.trackDirs[rootDir] = componentId;
|
|
423
|
+
})
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
File without changes
|