@teambit/workspace 0.0.749 → 0.0.752
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bit-map.d.ts +5 -0
- package/dist/bit-map.js +9 -0
- package/dist/bit-map.js.map +1 -1
- package/dist/watch/watch.cmd.d.ts +2 -2
- package/dist/watch/watch.cmd.js +15 -5
- package/dist/watch/watch.cmd.js.map +1 -1
- package/dist/watch/watcher.d.ts +27 -8
- package/dist/watch/watcher.js +136 -44
- package/dist/watch/watcher.js.map +1 -1
- package/dist/workspace.js +10 -23
- package/dist/workspace.js.map +1 -1
- package/package-tar/teambit-workspace-0.0.752.tgz +0 -0
- package/package.json +31 -31
- package/{preview-1654140507156.js → preview-1654399579544.js} +2 -2
- package/watch/watch.cmd.tsx +25 -5
- package/watch/watcher.ts +104 -40
- package/package-tar/teambit-workspace-0.0.749.tgz +0 -0
package/dist/bit-map.d.ts
CHANGED
|
@@ -35,4 +35,9 @@ export declare class BitMap {
|
|
|
35
35
|
* components that were not tagged yet are safe to rename them from the .bitmap file.
|
|
36
36
|
*/
|
|
37
37
|
renameNewComponent(sourceId: ComponentID, targetId: ComponentID): void;
|
|
38
|
+
/**
|
|
39
|
+
* this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be
|
|
40
|
+
* empty.
|
|
41
|
+
*/
|
|
42
|
+
getExportedLaneId(): import("@teambit/legacy/scopes/lanes/lane-id").LaneId | undefined;
|
|
38
43
|
}
|
package/dist/bit-map.js
CHANGED
|
@@ -194,6 +194,15 @@ class BitMap {
|
|
|
194
194
|
bitMapEntry.id = targetId._legacy;
|
|
195
195
|
this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be
|
|
199
|
+
* empty.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
getExportedLaneId() {
|
|
204
|
+
return this.legacyBitMap.remoteLaneId;
|
|
205
|
+
}
|
|
197
206
|
|
|
198
207
|
}
|
|
199
208
|
|
package/dist/bit-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","isEqual","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","removeDefaultScope","defaultScope","setDefaultScope","write","writeBitMap","ignoreVersion","getComponent","_legacy","getAspectIdFromConfig","componentId","ignoreAspectVersion","undefined","toString","allVersions","Object","keys","filter","startsWith","toStringWithoutVersion","length","BitError","join","renameNewComponent","sourceId","targetId","hasVersion","removeComponent","setComponent"],"sources":["bit-map.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\nimport { BitError } from '@teambit/bit-error';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n addComponentConfig(id: ComponentID, aspectId: string, config: Record<string, any> = {}): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n if (!config) {\n delete bitMapEntry.config[aspectId];\n } else {\n bitMapEntry.config[aspectId] = config;\n }\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (currentConfig) {\n delete bitMapEntry.config[aspectId];\n } else {\n if (!markWithMinusIfNotExist) {\n return false; // no changes\n }\n bitMapEntry.config[aspectId] = REMOVE_EXTENSION_SPECIAL_SIGN;\n }\n\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeEntireConfig(id: ComponentID): boolean {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (!bitMapEntry.config) return false;\n delete bitMapEntry.config;\n this.legacyBitMap.markAsChanged();\n return true;\n }\n\n setEntireConfig(id: ComponentID, config: Record<string, any>) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.config = config;\n this.legacyBitMap.markAsChanged();\n }\n\n removeDefaultScope(id: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (bitMapEntry.defaultScope) {\n delete bitMapEntry.defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n }\n\n setDefaultScope(id: ComponentID, defaultScope: string) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.defaultScope = defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n getAspectIdFromConfig(\n componentId: ComponentID,\n aspectId: ComponentID,\n ignoreAspectVersion = false\n ): string | undefined {\n const bitMapEntry = this.getBitmapEntry(componentId);\n const config = bitMapEntry.config;\n if (!config) {\n return undefined;\n }\n if (config[aspectId.toString()]) {\n return aspectId.toString();\n }\n if (!ignoreAspectVersion) {\n return undefined;\n }\n const allVersions = Object.keys(config).filter((id) => id.startsWith(`${aspectId.toStringWithoutVersion()}@`));\n if (allVersions.length > 1) {\n throw new BitError(\n `error: the same aspect ${\n aspectId.toStringWithoutVersion\n } configured multiple times for \"${componentId.toString()}\"\\n${allVersions.join('\\n')}`\n );\n }\n return allVersions.length === 1 ? allVersions[0] : undefined;\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;EAClBC,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;IAAA,KAAxDD,YAAwD,GAAxDA,YAAwD;IAAA,KAApBC,QAAoB,GAApBA,QAAoB;EAAE;EAE9E;AACF;AACA;AACA;AACA;;;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F;AACA;;;EACEW,kBAAkB,CAACC,QAAD,EAAwBC,QAAxB,EAA+C;IAC/D,MAAMnC,WAAW,GAAG,KAAKC,cAAL,CAAoBiC,QAApB,CAApB;;IACA,IAAIlC,WAAW,CAACJ,EAAZ,CAAewC,UAAf,EAAJ,EAAiC;MAC/B,MAAM,IAAIrC,KAAJ,CAAW,kDAAiDC,WAAW,CAACJ,EAAZ,CAAe2B,QAAf,EAA0B,EAAtF,CAAN;IACD;;IACD,KAAK9B,YAAL,CAAkB4C,eAAlB,CAAkCrC,WAAW,CAACJ,EAA9C;IACAI,WAAW,CAACJ,EAAZ,GAAiBuC,QAAQ,CAACjB,OAA1B;IACA,KAAKzB,YAAL,CAAkB6C,YAAlB,CAA+BtC,WAAW,CAACJ,EAA3C,EAA+CI,WAA/C;EACD;;AA9HiB"}
|
|
1
|
+
{"version":3,"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","isEqual","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","removeDefaultScope","defaultScope","setDefaultScope","write","writeBitMap","ignoreVersion","getComponent","_legacy","getAspectIdFromConfig","componentId","ignoreAspectVersion","undefined","toString","allVersions","Object","keys","filter","startsWith","toStringWithoutVersion","length","BitError","join","renameNewComponent","sourceId","targetId","hasVersion","removeComponent","setComponent","getExportedLaneId","remoteLaneId"],"sources":["bit-map.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\nimport { BitError } from '@teambit/bit-error';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n addComponentConfig(id: ComponentID, aspectId: string, config: Record<string, any> = {}): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n if (!config) {\n delete bitMapEntry.config[aspectId];\n } else {\n bitMapEntry.config[aspectId] = config;\n }\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (currentConfig) {\n delete bitMapEntry.config[aspectId];\n } else {\n if (!markWithMinusIfNotExist) {\n return false; // no changes\n }\n bitMapEntry.config[aspectId] = REMOVE_EXTENSION_SPECIAL_SIGN;\n }\n\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeEntireConfig(id: ComponentID): boolean {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (!bitMapEntry.config) return false;\n delete bitMapEntry.config;\n this.legacyBitMap.markAsChanged();\n return true;\n }\n\n setEntireConfig(id: ComponentID, config: Record<string, any>) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.config = config;\n this.legacyBitMap.markAsChanged();\n }\n\n removeDefaultScope(id: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (bitMapEntry.defaultScope) {\n delete bitMapEntry.defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n }\n\n setDefaultScope(id: ComponentID, defaultScope: string) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.defaultScope = defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n getAspectIdFromConfig(\n componentId: ComponentID,\n aspectId: ComponentID,\n ignoreAspectVersion = false\n ): string | undefined {\n const bitMapEntry = this.getBitmapEntry(componentId);\n const config = bitMapEntry.config;\n if (!config) {\n return undefined;\n }\n if (config[aspectId.toString()]) {\n return aspectId.toString();\n }\n if (!ignoreAspectVersion) {\n return undefined;\n }\n const allVersions = Object.keys(config).filter((id) => id.startsWith(`${aspectId.toStringWithoutVersion()}@`));\n if (allVersions.length > 1) {\n throw new BitError(\n `error: the same aspect ${\n aspectId.toStringWithoutVersion\n } configured multiple times for \"${componentId.toString()}\"\\n${allVersions.join('\\n')}`\n );\n }\n return allVersions.length === 1 ? allVersions[0] : undefined;\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n\n /**\n * this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be\n * empty.\n */\n getExportedLaneId() {\n return this.legacyBitMap.remoteLaneId;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;EAClBC,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;IAAA,KAAxDD,YAAwD,GAAxDA,YAAwD;IAAA,KAApBC,QAAoB,GAApBA,QAAoB;EAAE;EAE9E;AACF;AACA;AACA;AACA;;;EACEC,kBAAkB,CAACC,EAAD,EAAkBC,QAAlB,EAAoCC,MAA2B,GAAG,EAAlE,EAA+E;IAC/F,IAAI,CAACD,QAAD,IAAa,OAAOA,QAAP,KAAoB,QAArC,EAA+C,MAAM,IAAIE,KAAJ,CAAW,qCAAoCF,QAAS,EAAxD,CAAN;IAC/C,MAAMG,WAAW,GAAG,KAAKC,cAAL,CAAoBL,EAApB,EAAwB;MAAEM,qBAAqB,EAAE;IAAzB,CAAxB,CAApB;IACA,MAAMC,aAAa,GAAG,CAACH,WAAW,CAACF,MAAb,KAACE,WAAW,CAACF,MAAb,GAAwB,EAAxB,GAA4BD,QAA5B,CAAtB;;IACA,IAAI,IAAAO,iBAAA,EAAQD,aAAR,EAAuBL,MAAvB,CAAJ,EAAoC;MAClC,OAAO,KAAP,CADkC,CACpB;IACf;;IACD,IAAI,CAACA,MAAL,EAAa;MACX,OAAOE,WAAW,CAACF,MAAZ,CAAmBD,QAAnB,CAAP;IACD,CAFD,MAEO;MACLG,WAAW,CAACF,MAAZ,CAAmBD,QAAnB,IAA+BC,MAA/B;IACD;;IACD,KAAKL,YAAL,CAAkBY,aAAlB;IAEA,OAAO,IAAP,CAd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,WAAW,GAAGC,MAAM,CAACC,IAAP,CAAY5B,MAAZ,EAAoB6B,MAApB,CAA4B/B,EAAD,IAAQA,EAAE,CAACgC,UAAH,CAAe,GAAE/B,QAAQ,CAACgC,sBAAT,EAAkC,GAAnD,CAAnC,CAApB;;IACA,IAAIL,WAAW,CAACM,MAAZ,GAAqB,CAAzB,EAA4B;MAC1B,MAAM,KAAIC,oBAAJ,EACH,0BACClC,QAAQ,CAACgC,sBACV,mCAAkCT,WAAW,CAACG,QAAZ,EAAuB,MAAKC,WAAW,CAACQ,IAAZ,CAAiB,IAAjB,CAAuB,EAHlF,CAAN;IAKD;;IACD,OAAOR,WAAW,CAACM,MAAZ,KAAuB,CAAvB,GAA2BN,WAAW,CAAC,CAAD,CAAtC,GAA4CF,SAAnD;EACD;EAED;AACF;AACA;;;EACEW,kBAAkB,CAACC,QAAD,EAAwBC,QAAxB,EAA+C;IAC/D,MAAMnC,WAAW,GAAG,KAAKC,cAAL,CAAoBiC,QAApB,CAApB;;IACA,IAAIlC,WAAW,CAACJ,EAAZ,CAAewC,UAAf,EAAJ,EAAiC;MAC/B,MAAM,IAAIrC,KAAJ,CAAW,kDAAiDC,WAAW,CAACJ,EAAZ,CAAe2B,QAAf,EAA0B,EAAtF,CAAN;IACD;;IACD,KAAK9B,YAAL,CAAkB4C,eAAlB,CAAkCrC,WAAW,CAACJ,EAA9C;IACAI,WAAW,CAACJ,EAAZ,GAAiBuC,QAAQ,CAACjB,OAA1B;IACA,KAAKzB,YAAL,CAAkB6C,YAAlB,CAA+BtC,WAAW,CAACJ,EAA3C,EAA+CI,WAA/C;EACD;EAED;AACF;AACA;AACA;;;EACEuC,iBAAiB,GAAG;IAClB,OAAO,KAAK9C,YAAL,CAAkB+C,YAAzB;EACD;;AAtIiB"}
|
|
@@ -25,8 +25,8 @@ export declare class WatchCommand implements Command {
|
|
|
25
25
|
onAll: (event: string, path: string) => void;
|
|
26
26
|
onStart: () => void;
|
|
27
27
|
onReady: (workspace: any, watchPathsSortByComponent: any, verbose: any) => void;
|
|
28
|
-
onChange: (
|
|
29
|
-
onAdd: (
|
|
28
|
+
onChange: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string | undefined) => void;
|
|
29
|
+
onAdd: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string | undefined) => void;
|
|
30
30
|
onUnlink: (p: any) => void;
|
|
31
31
|
onError: (err: any) => void;
|
|
32
32
|
};
|
package/dist/watch/watch.cmd.js
CHANGED
|
@@ -99,22 +99,32 @@ class WatchCommand {
|
|
|
99
99
|
|
|
100
100
|
this.logger.console(_chalk().default.yellow(`Watching for component changes in workspace ${workspace.config.name} (${(0, _moment().default)().format('HH:mm:ss')})...\n`));
|
|
101
101
|
},
|
|
102
|
-
onChange: (
|
|
102
|
+
onChange: (filePaths, buildResults, verbose, duration, failureMsg) => {
|
|
103
|
+
const files = filePaths.join(', ');
|
|
103
104
|
clearOutdatedData();
|
|
104
105
|
|
|
105
106
|
if (!buildResults.length) {
|
|
106
|
-
|
|
107
|
+
failureMsg = failureMsg || `The files ${files} have been changed, but nothing to compile`;
|
|
108
|
+
this.logger.console(`${failureMsg}\n\n`);
|
|
107
109
|
return;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
this.logger.console(`The file ${
|
|
112
|
+
this.logger.console(`The file(s) ${files} have been changed.\n\n`);
|
|
111
113
|
this.logger.console((0, _outputFormatter().formatCompileResults)(buildResults, verbose));
|
|
112
114
|
this.logger.console(`Finished. (${duration}ms)`);
|
|
113
115
|
this.logger.console(_chalk().default.yellow(`Watching for component changes (${(0, _moment().default)().format('HH:mm:ss')})...`));
|
|
114
116
|
},
|
|
115
|
-
onAdd: (
|
|
117
|
+
onAdd: (filePaths, buildResults, verbose, duration, failureMsg) => {
|
|
118
|
+
const files = filePaths.join(', ');
|
|
116
119
|
clearOutdatedData();
|
|
117
|
-
|
|
120
|
+
|
|
121
|
+
if (!buildResults.length) {
|
|
122
|
+
failureMsg = failureMsg || `The files ${files} have been added, but nothing to compile`;
|
|
123
|
+
this.logger.console(`${failureMsg}\n\n`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.logger.console(`The file(s) ${filePaths} have been added.\n\n`);
|
|
118
128
|
this.logger.console((0, _outputFormatter().formatCompileResults)(buildResults, verbose));
|
|
119
129
|
this.logger.console(`Finished. (${duration}ms)`);
|
|
120
130
|
this.logger.console(_chalk().default.yellow(`Watching for component changes (${(0, _moment().default)().format('HH:mm:ss')})...`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["WatchCommand","constructor","pubsub","logger","watcher","onAll","event","path","console","onStart","onReady","workspace","watchPathsSortByComponent","verbose","clearOutdatedData","formatWatchPathsSortByComponent","chalk","yellow","config","name","moment","format","onChange","
|
|
1
|
+
{"version":3,"names":["WatchCommand","constructor","pubsub","logger","watcher","onAll","event","path","console","onStart","onReady","workspace","watchPathsSortByComponent","verbose","clearOutdatedData","formatWatchPathsSortByComponent","chalk","yellow","config","name","moment","format","onChange","filePaths","buildResults","duration","failureMsg","files","join","length","formatCompileResults","onAdd","onUnlink","p","onError","err","type","CompilerErrorEvent","TYPE","data","error","registerToEvents","sub","CompilerAspect","id","eventsListener","report","cliArgs","watchCmdOpts","checkTypes","getCheckTypesEnum","undefined","CheckTypes","None","EntireProject","ChangedFile","Error","watchOpts","msgs","preCompile","skipPreCompilation","spawnTSServer","Boolean","watchAll","process","stdout","write"],"sources":["watch.cmd.tsx"],"sourcesContent":["import chalk from 'chalk';\nimport moment from 'moment';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport type { Logger } from '@teambit/logger';\nimport type { BitBaseEvent, PubsubMain } from '@teambit/pubsub';\n\n// import IDs and events\nimport { CompilerAspect, CompilerErrorEvent } from '@teambit/compiler';\n\nimport { Watcher, WatchOptions } from './watcher';\nimport { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';\nimport { OnComponentEventResult } from '../on-component-events';\nimport { CheckTypes } from './check-types';\n\nexport type WatchCmdOpts = {\n verbose?: boolean;\n skipPreCompilation?: boolean;\n checkTypes?: string | boolean;\n};\n\nexport class WatchCommand implements Command {\n msgs = {\n onAll: (event: string, path: string) => this.logger.console(`Event: \"${event}\". Path: ${path}`),\n onStart: () => {},\n onReady: (workspace, watchPathsSortByComponent, verbose) => {\n clearOutdatedData();\n if (verbose) {\n this.logger.console(formatWatchPathsSortByComponent(watchPathsSortByComponent));\n }\n this.logger.console(\n chalk.yellow(\n `Watching for component changes in workspace ${workspace.config.name} (${moment().format('HH:mm:ss')})...\\n`\n )\n );\n },\n onChange: (\n filePaths: string[],\n buildResults: OnComponentEventResult[],\n verbose: boolean,\n duration,\n failureMsg?: string\n ) => {\n const files = filePaths.join(', ');\n clearOutdatedData();\n if (!buildResults.length) {\n failureMsg = failureMsg || `The files ${files} have been changed, but nothing to compile`;\n this.logger.console(`${failureMsg}\\n\\n`);\n return;\n }\n this.logger.console(`The file(s) ${files} have been changed.\\n\\n`);\n this.logger.console(formatCompileResults(buildResults, verbose));\n this.logger.console(`Finished. (${duration}ms)`);\n this.logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));\n },\n onAdd: (\n filePaths: string[],\n buildResults: OnComponentEventResult[],\n verbose: boolean,\n duration,\n failureMsg?: string\n ) => {\n const files = filePaths.join(', ');\n clearOutdatedData();\n if (!buildResults.length) {\n failureMsg = failureMsg || `The files ${files} have been added, but nothing to compile`;\n this.logger.console(`${failureMsg}\\n\\n`);\n return;\n }\n this.logger.console(`The file(s) ${filePaths} have been added.\\n\\n`);\n this.logger.console(formatCompileResults(buildResults, verbose));\n this.logger.console(`Finished. (${duration}ms)`);\n this.logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));\n },\n onUnlink: (p) => {\n this.logger.console(`file ${p} has been removed`);\n },\n onError: (err) => {\n this.logger.console(`Watcher error ${err}`);\n },\n };\n\n name = 'watch';\n description = 'watch a set of components';\n alias = '';\n group = 'development';\n shortDescription = '';\n options = [\n ['v', 'verbose', 'showing npm verbose output for inspection and prints stack trace'],\n ['', 'skip-pre-compilation', 'skip the compilation step before starting to watch'],\n [\n 't',\n 'check-types [string]',\n 'EXPERIMENTAL. show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project',\n ],\n ] as CommandOptions;\n\n constructor(\n /**\n * logger extension.\n */\n private pubsub: PubsubMain,\n\n /**\n * logger extension.\n */\n private logger: Logger,\n\n /**\n * watcher extension.\n */\n private watcher: Watcher\n ) {\n this.registerToEvents();\n }\n\n private registerToEvents() {\n this.pubsub.sub(CompilerAspect.id, this.eventsListener);\n }\n\n private eventsListener = (event: BitBaseEvent<any>) => {\n switch (event.type) {\n case CompilerErrorEvent.TYPE:\n this.logger.console(`Watcher error ${event.data.error}, 'error'`);\n break;\n default:\n }\n };\n\n async report(cliArgs: [], watchCmdOpts: WatchCmdOpts) {\n const { verbose, checkTypes } = watchCmdOpts;\n const getCheckTypesEnum = () => {\n switch (checkTypes) {\n case undefined:\n case false:\n return CheckTypes.None;\n case 'project':\n case true: // project is the default\n return CheckTypes.EntireProject;\n case 'file':\n return CheckTypes.ChangedFile;\n default:\n throw new Error(`check-types can be either \"file\" or \"project\". got \"${checkTypes}\"`);\n }\n };\n const watchOpts: WatchOptions = {\n msgs: this.msgs,\n verbose,\n preCompile: !watchCmdOpts.skipPreCompilation,\n spawnTSServer: Boolean(checkTypes), // if check-types is enabled, it must spawn the tsserver.\n checkTypes: getCheckTypesEnum(),\n };\n await this.watcher.watchAll(watchOpts);\n return 'watcher terminated';\n }\n}\n\n/**\n * with console.clear() all history is deleted from the console. this function preserver the history.\n */\nfunction clearOutdatedData() {\n process.stdout.write('\\x1Bc');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;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AAE,KAAKA,IADmB;MAE9B7C,OAF8B;MAG9B8C,UAAU,EAAE,CAACX,YAAY,CAACY,kBAHI;MAI9BC,aAAa,EAAEC,OAAO,CAACb,UAAD,CAJQ;MAIM;MACpCA,UAAU,EAAEC,iBAAiB;IALC,CAAhC;IAOA,MAAM,KAAK9C,OAAL,CAAa2D,QAAb,CAAsBN,SAAtB,CAAN;IACA,OAAO,oBAAP;EACD;;AArI0C;AAwI7C;AACA;AACA;;;;;AACA,SAAS3C,iBAAT,GAA6B;EAC3BkD,OAAO,CAACC,MAAR,CAAeC,KAAf,CAAqB,OAArB;AACD"}
|
package/dist/watch/watcher.d.ts
CHANGED
|
@@ -37,12 +37,37 @@ export declare class Watcher {
|
|
|
37
37
|
private verbose;
|
|
38
38
|
private multipleWatchers;
|
|
39
39
|
private fsWatcher;
|
|
40
|
+
private changedFilesPerComponent;
|
|
40
41
|
constructor(workspace: Workspace, pubsub: PubsubMain, trackDirs?: {
|
|
41
42
|
[dir: PathLinux]: ComponentID;
|
|
42
43
|
}, verbose?: boolean, multipleWatchers?: WatcherProcessData[]);
|
|
43
44
|
get consumer(): Consumer;
|
|
44
45
|
watchAll(opts: WatchOptions): Promise<unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
48
|
+
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
49
|
+
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
50
|
+
* if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,
|
|
51
|
+
* it'll only add the file to `this.changedFilesPerComponent` prop.
|
|
52
|
+
* once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,
|
|
53
|
+
* indicating the next file-change to start a new execution.
|
|
54
|
+
*
|
|
55
|
+
* implementation wise, `lodash.debounce` doesn't help here, because:
|
|
56
|
+
* A) it doesn't return the results, unless "leading" option is true. here, it must be false, otherwise, it'll start
|
|
57
|
+
* the execution immediately.
|
|
58
|
+
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
59
|
+
* other components undesirably.
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
45
62
|
private handleChange;
|
|
63
|
+
private sleep;
|
|
64
|
+
/**
|
|
65
|
+
* if a file was added/remove, once the component is loaded, it changes .bitmap, and then the
|
|
66
|
+
* entire cache is invalidated and the consumer is reloaded.
|
|
67
|
+
* when a file just changed, no need to reload the consumer, it is enough to just delete the
|
|
68
|
+
* component from the cache (both, workspace and consumer)
|
|
69
|
+
*/
|
|
70
|
+
private triggerCompChanges;
|
|
46
71
|
/**
|
|
47
72
|
* if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.
|
|
48
73
|
*/
|
|
@@ -52,15 +77,9 @@ export declare class Watcher {
|
|
|
52
77
|
private creatOnComponentRemovedEvent;
|
|
53
78
|
private creatOnComponentChangeEvent;
|
|
54
79
|
private creatOnComponentAddEvent;
|
|
55
|
-
private completeWatch;
|
|
56
80
|
private isComponentWatchedExternally;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* entire cache is invalidated and the consumer is reloaded.
|
|
60
|
-
* when a file just changed, no need to reload the consumer, it is enough to just delete the
|
|
61
|
-
* component from the cache (both, workspace and consumer)
|
|
62
|
-
*/
|
|
63
|
-
private getComponentIdAndClearItsCache;
|
|
81
|
+
private getComponentIdByPath;
|
|
82
|
+
private getRelativePathLinux;
|
|
64
83
|
private findTrackDirByFilePathRecursively;
|
|
65
84
|
private createWatcher;
|
|
66
85
|
setTrackDirs(): Promise<void>;
|
package/dist/watch/watcher.js
CHANGED
|
@@ -149,6 +149,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
149
149
|
|
|
150
150
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
151
151
|
|
|
152
|
+
const DEBOUNCE_WAIT_MS = 100;
|
|
153
|
+
|
|
152
154
|
class Watcher {
|
|
153
155
|
constructor(workspace, pubsub, trackDirs = {}, verbose = false, multipleWatchers = []) {
|
|
154
156
|
this.workspace = workspace;
|
|
@@ -157,6 +159,7 @@ class Watcher {
|
|
|
157
159
|
this.verbose = verbose;
|
|
158
160
|
this.multipleWatchers = multipleWatchers;
|
|
159
161
|
(0, _defineProperty2().default)(this, "fsWatcher", void 0);
|
|
162
|
+
(0, _defineProperty2().default)(this, "changedFilesPerComponent", {});
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
get consumer() {
|
|
@@ -188,16 +191,36 @@ class Watcher {
|
|
|
188
191
|
|
|
189
192
|
watcher.on('change', async filePath => {
|
|
190
193
|
const startTime = new Date().getTime();
|
|
191
|
-
const
|
|
194
|
+
const {
|
|
195
|
+
files,
|
|
196
|
+
results,
|
|
197
|
+
debounced,
|
|
198
|
+
failureMsg
|
|
199
|
+
} = await this.handleChange(filePath, opts === null || opts === void 0 ? void 0 : opts.initiator);
|
|
200
|
+
|
|
201
|
+
if (debounced) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
192
205
|
const duration = new Date().getTime() - startTime;
|
|
193
|
-
msgs === null || msgs === void 0 ? void 0 : msgs.onChange(
|
|
206
|
+
msgs === null || msgs === void 0 ? void 0 : msgs.onChange(files, results, this.verbose, duration, failureMsg);
|
|
194
207
|
}); // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
195
208
|
|
|
196
209
|
watcher.on('add', async filePath => {
|
|
197
210
|
const startTime = new Date().getTime();
|
|
198
|
-
const
|
|
211
|
+
const {
|
|
212
|
+
files,
|
|
213
|
+
results,
|
|
214
|
+
debounced,
|
|
215
|
+
failureMsg
|
|
216
|
+
} = await this.handleChange(filePath, opts === null || opts === void 0 ? void 0 : opts.initiator);
|
|
217
|
+
|
|
218
|
+
if (debounced) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
199
222
|
const duration = new Date().getTime() - startTime;
|
|
200
|
-
msgs === null || msgs === void 0 ? void 0 : msgs.onAdd(
|
|
223
|
+
msgs === null || msgs === void 0 ? void 0 : msgs.onAdd(files, results, this.verbose, duration, failureMsg);
|
|
201
224
|
}); // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
202
225
|
|
|
203
226
|
watcher.on('unlink', async p => {
|
|
@@ -210,26 +233,80 @@ class Watcher {
|
|
|
210
233
|
});
|
|
211
234
|
});
|
|
212
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
238
|
+
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
239
|
+
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
240
|
+
* if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,
|
|
241
|
+
* it'll only add the file to `this.changedFilesPerComponent` prop.
|
|
242
|
+
* once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,
|
|
243
|
+
* indicating the next file-change to start a new execution.
|
|
244
|
+
*
|
|
245
|
+
* implementation wise, `lodash.debounce` doesn't help here, because:
|
|
246
|
+
* A) it doesn't return the results, unless "leading" option is true. here, it must be false, otherwise, it'll start
|
|
247
|
+
* the execution immediately.
|
|
248
|
+
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
249
|
+
* other components undesirably.
|
|
250
|
+
*
|
|
251
|
+
*/
|
|
252
|
+
|
|
213
253
|
|
|
214
254
|
async handleChange(filePath, initiator) {
|
|
215
255
|
try {
|
|
216
256
|
if (filePath.endsWith(_constants().BIT_MAP)) {
|
|
217
257
|
const buildResults = await this.handleBitmapChanges();
|
|
218
|
-
|
|
219
|
-
|
|
258
|
+
|
|
259
|
+
_loader().default.stop();
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
results: buildResults,
|
|
263
|
+
files: [filePath]
|
|
264
|
+
};
|
|
220
265
|
}
|
|
221
266
|
|
|
222
|
-
const componentId =
|
|
267
|
+
const componentId = this.getComponentIdByPath(filePath);
|
|
223
268
|
|
|
224
269
|
if (!componentId) {
|
|
225
|
-
|
|
270
|
+
const failureMsg = `file ${filePath} is not part of any component, ignoring it`;
|
|
271
|
+
|
|
272
|
+
_logger().default.debug(failureMsg);
|
|
273
|
+
|
|
274
|
+
_loader().default.stop();
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
results: [],
|
|
278
|
+
files: [filePath],
|
|
279
|
+
failureMsg
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const compIdStr = componentId.toString();
|
|
226
284
|
|
|
227
|
-
|
|
285
|
+
if (this.changedFilesPerComponent[compIdStr]) {
|
|
286
|
+
this.changedFilesPerComponent[compIdStr].push(filePath);
|
|
287
|
+
|
|
288
|
+
_loader().default.stop();
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
results: [],
|
|
292
|
+
debounced: true
|
|
293
|
+
};
|
|
228
294
|
}
|
|
229
295
|
|
|
230
|
-
|
|
231
|
-
this.
|
|
232
|
-
|
|
296
|
+
this.changedFilesPerComponent[compIdStr] = [filePath];
|
|
297
|
+
await this.sleep(DEBOUNCE_WAIT_MS);
|
|
298
|
+
const files = this.changedFilesPerComponent[compIdStr];
|
|
299
|
+
delete this.changedFilesPerComponent[compIdStr];
|
|
300
|
+
const buildResults = await this.triggerCompChanges(componentId, files, initiator);
|
|
301
|
+
const failureMsg = buildResults.length ? undefined : `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;
|
|
302
|
+
|
|
303
|
+
_loader().default.stop();
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
results: buildResults,
|
|
307
|
+
files,
|
|
308
|
+
failureMsg
|
|
309
|
+
};
|
|
233
310
|
} catch (err) {
|
|
234
311
|
const msg = `watcher found an error while handling ${filePath}`;
|
|
235
312
|
|
|
@@ -237,8 +314,48 @@ class Watcher {
|
|
|
237
314
|
|
|
238
315
|
_logger().default.console(`${msg}, ${err.message}`);
|
|
239
316
|
|
|
317
|
+
_loader().default.stop();
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
results: [],
|
|
321
|
+
files: [filePath],
|
|
322
|
+
failureMsg: err.message
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async sleep(ms) {
|
|
328
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* if a file was added/remove, once the component is loaded, it changes .bitmap, and then the
|
|
332
|
+
* entire cache is invalidated and the consumer is reloaded.
|
|
333
|
+
* when a file just changed, no need to reload the consumer, it is enough to just delete the
|
|
334
|
+
* component from the cache (both, workspace and consumer)
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
async triggerCompChanges(componentId, files, initiator) {
|
|
339
|
+
this.workspace.clearComponentCache(componentId);
|
|
340
|
+
const component = await this.workspace.get(componentId);
|
|
341
|
+
const componentMap = component.state._consumer.componentMap;
|
|
342
|
+
const compFiles = files.filter(filePath => {
|
|
343
|
+
const relativeFile = this.getRelativePathLinux(filePath);
|
|
344
|
+
const isCompFile = Boolean(componentMap.getFilesRelativeToConsumer().find(p => p === relativeFile));
|
|
345
|
+
|
|
346
|
+
if (!isCompFile) {
|
|
347
|
+
_logger().default.debug(`file ${filePath} is inside the component ${componentId.toString()} but configured to be ignored`);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return isCompFile;
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
if (!compFiles.length) {
|
|
240
354
|
return [];
|
|
241
355
|
}
|
|
356
|
+
|
|
357
|
+
const buildResults = await this.executeWatchOperationsOnComponent(componentId, compFiles, true, initiator);
|
|
358
|
+
return buildResults;
|
|
242
359
|
}
|
|
243
360
|
/**
|
|
244
361
|
* if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.
|
|
@@ -309,13 +426,7 @@ class Watcher {
|
|
|
309
426
|
return [];
|
|
310
427
|
}
|
|
311
428
|
|
|
312
|
-
|
|
313
|
-
return buildResults;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
_logger().default.console(`${idStr} doesn't have a compiler, nothing to build`);
|
|
317
|
-
|
|
318
|
-
return [];
|
|
429
|
+
return buildResults;
|
|
319
430
|
}
|
|
320
431
|
|
|
321
432
|
creatOnComponentRemovedEvent(idStr) {
|
|
@@ -330,12 +441,6 @@ class Watcher {
|
|
|
330
441
|
return new (_events().OnComponentAddEvent)(Date.now(), idStr, hook);
|
|
331
442
|
}
|
|
332
443
|
|
|
333
|
-
completeWatch() {
|
|
334
|
-
_loader().default.stop();
|
|
335
|
-
|
|
336
|
-
return [];
|
|
337
|
-
}
|
|
338
|
-
|
|
339
444
|
isComponentWatchedExternally(componentId) {
|
|
340
445
|
const watcherData = this.multipleWatchers.find(m => m.componentIds.find(id => id.isEqual(componentId._legacy)));
|
|
341
446
|
|
|
@@ -347,16 +452,9 @@ class Watcher {
|
|
|
347
452
|
|
|
348
453
|
return false;
|
|
349
454
|
}
|
|
350
|
-
/**
|
|
351
|
-
* if a file was added/remove, once the component is loaded, it changes .bitmap, and then the
|
|
352
|
-
* entire cache is invalidated and the consumer is reloaded.
|
|
353
|
-
* when a file just changed, no need to reload the consumer, it is enough to just delete the
|
|
354
|
-
* component from the cache (both, workspace and consumer)
|
|
355
|
-
*/
|
|
356
455
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const relativeFile = (0, _utils().pathNormalizeToLinux)(this.consumer.getPathRelativeToConsumer(filePath));
|
|
456
|
+
getComponentIdByPath(filePath) {
|
|
457
|
+
const relativeFile = this.getRelativePathLinux(filePath);
|
|
360
458
|
const trackDir = this.findTrackDirByFilePathRecursively(relativeFile);
|
|
361
459
|
|
|
362
460
|
if (!trackDir) {
|
|
@@ -365,17 +463,11 @@ class Watcher {
|
|
|
365
463
|
return null;
|
|
366
464
|
}
|
|
367
465
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const component = await this.workspace.get(componentId);
|
|
371
|
-
const componentMap = component.state._consumer.componentMap;
|
|
372
|
-
|
|
373
|
-
if (componentMap.getFilesRelativeToConsumer().find(p => p === relativeFile)) {
|
|
374
|
-
return componentId;
|
|
375
|
-
} // the file is inside the component dir but it's ignored. (e.g. it's in IGNORE_LIST)
|
|
376
|
-
|
|
466
|
+
return this.trackDirs[trackDir];
|
|
467
|
+
}
|
|
377
468
|
|
|
378
|
-
|
|
469
|
+
getRelativePathLinux(filePath) {
|
|
470
|
+
return (0, _utils().pathNormalizeToLinux)(this.consumer.getPathRelativeToConsumer(filePath));
|
|
379
471
|
}
|
|
380
472
|
|
|
381
473
|
findTrackDirByFilePathRecursively(filePath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Watcher","constructor","workspace","pubsub","trackDirs","verbose","multipleWatchers","consumer","watchAll","opts","msgs","watchOpts","pathsToWatch","getPathsToWatch","componentIds","Object","values","triggerOnPreWatch","createWatcher","watcher","fsWatcher","onStart","Promise","resolve","reject","process","env","BIT_LOG","onAll","on","onReady","filePath","startTime","Date","getTime","buildResults","handleChange","initiator","duration","onChange","onAdd","p","onUnlink","err","onError","endsWith","BIT_MAP","handleBitmapChanges","completeWatch","componentId","getComponentIdAndClearItsCache","logger","debug","executeWatchOperationsOnComponent","msg","error","console","message","previewsTrackDirs","_reloadConsumer","setTrackDirs","newDirs","difference","keys","removedDirs","results","length","add","addResults","mapSeries","dir","push","flat","unwatch","executeWatchOperationsOnRemove","chalk","bold","toString","pub","WorkspaceAspect","id","creatOnComponentRemovedEvent","triggerOnComponentRemove","files","isChange","isComponentWatchedExternally","get","idStr","creatOnComponentChangeEvent","creatOnComponentAddEvent","triggerOnComponentChange","triggerOnComponentAdd","OnComponentRemovedEvent","now","hook","OnComponentChangeEvent","OnComponentAddEvent","loader","stop","watcherData","find","m","isEqual","_legacy","compilerId","relativeFile","pathNormalizeToLinux","getPathRelativeToConsumer","trackDir","findTrackDirByFilePathRecursively","clearComponentCache","component","componentMap","state","_consumer","getFilesRelativeToConsumer","parentDir","dirname","chokidar","watch","ignoreInitial","ignored","path","includes","sep","persistent","useFsEvents","componentsFromBitMap","bitMap","getAllComponents","COMPONENT_ORIGINS","AUTHORED","IMPORTED","all","map","bitId","getTrackDir","Error","resolveComponentId","paths","pathsAbsolute","toAbsolutePath"],"sources":["watcher.ts"],"sourcesContent":["import { PubsubMain } from '@teambit/pubsub';\nimport { dirname, sep } from 'path';\nimport { difference } from 'lodash';\nimport { ComponentID } from '@teambit/component';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { BIT_MAP, COMPONENT_ORIGINS } from '@teambit/legacy/dist/constants';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport mapSeries from 'p-map-series';\nimport chalk from 'chalk';\nimport { ChildProcess } from 'child_process';\nimport chokidar, { FSWatcher } from 'chokidar';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { PathLinux, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport { WorkspaceAspect } from '../';\nimport { OnComponentChangeEvent, OnComponentAddEvent, OnComponentRemovedEvent } from '../events';\nimport { Workspace } from '../workspace';\nimport { OnComponentEventResult } from '../on-component-events';\nimport { CheckTypes } from './check-types';\n\nexport type WatcherProcessData = { watchProcess: ChildProcess; compilerId: BitId; componentIds: BitId[] };\n\nexport type EventMessages = {\n onAll: Function;\n onStart: Function;\n onReady: Function;\n onChange: Function;\n onAdd: Function;\n onUnlink: Function;\n onError: Function;\n};\n\nexport type WatchOptions = {\n msgs?: EventMessages;\n initiator?: CompilationInitiator;\n verbose?: boolean; // print watch events to the console. (also ts-server events if spawnTSServer is true)\n spawnTSServer?: boolean; // needed for check types and extract API/docs.\n checkTypes?: CheckTypes; // if enabled, the spawnTSServer becomes true.\n preCompile?: boolean; // whether compile all components before start watching\n};\n\nexport class Watcher {\n private fsWatcher: FSWatcher;\n constructor(\n private workspace: Workspace,\n private pubsub: PubsubMain,\n private trackDirs: { [dir: PathLinux]: ComponentID } = {},\n private verbose = false,\n private multipleWatchers: WatcherProcessData[] = []\n ) {}\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async watchAll(opts: WatchOptions) {\n const { msgs, ...watchOpts } = opts;\n // TODO: run build in the beginning of process (it's work like this in other envs)\n const pathsToWatch = await this.getPathsToWatch();\n const componentIds = Object.values(this.trackDirs);\n await this.workspace.triggerOnPreWatch(componentIds, watchOpts);\n await this.createWatcher(pathsToWatch);\n const watcher = this.fsWatcher;\n msgs?.onStart(this.workspace);\n\n return new Promise((resolve, reject) => {\n // prefix your command with \"BIT_LOG=*\" to see all watch events\n if (process.env.BIT_LOG) {\n // @ts-ignore\n if (msgs?.onAll) watcher.on('all', msgs?.onAll);\n }\n watcher.on('ready', () => {\n msgs?.onReady(this.workspace, this.trackDirs, this.verbose);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('change', async (filePath) => {\n const startTime = new Date().getTime();\n const buildResults = (await this.handleChange(filePath, opts?.initiator)) || [];\n const duration = new Date().getTime() - startTime;\n msgs?.onChange(filePath, buildResults, this.verbose, duration);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('add', async (filePath) => {\n const startTime = new Date().getTime();\n const buildResults = (await this.handleChange(filePath)) || [];\n const duration = new Date().getTime() - startTime;\n msgs?.onAdd(filePath, buildResults, this.verbose, duration);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('unlink', async (p) => {\n msgs?.onUnlink(p);\n await this.handleChange(p);\n });\n watcher.on('error', (err) => {\n msgs?.onError(err);\n reject(err);\n });\n });\n }\n\n private async handleChange(filePath: string, initiator?: CompilationInitiator): Promise<OnComponentEventResult[]> {\n try {\n if (filePath.endsWith(BIT_MAP)) {\n const buildResults = await this.handleBitmapChanges();\n this.completeWatch();\n return buildResults;\n }\n const componentId = await this.getComponentIdAndClearItsCache(filePath);\n if (!componentId) {\n logger.debug(`file ${filePath} is not part of any component, ignoring it`);\n return this.completeWatch();\n }\n\n const buildResults = await this.executeWatchOperationsOnComponent(componentId, [filePath], true, initiator);\n this.completeWatch();\n return buildResults;\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 return [];\n }\n }\n\n /**\n * if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.\n */\n private async handleBitmapChanges(): Promise<OnComponentEventResult[]> {\n const previewsTrackDirs = { ...this.trackDirs };\n await this.workspace._reloadConsumer();\n await this.setTrackDirs();\n const newDirs: string[] = difference(Object.keys(this.trackDirs), Object.keys(previewsTrackDirs));\n const removedDirs: string[] = difference(Object.keys(previewsTrackDirs), Object.keys(this.trackDirs));\n const results: OnComponentEventResult[] = [];\n if (newDirs.length) {\n this.fsWatcher.add(newDirs);\n const addResults = await mapSeries(newDirs, async (dir) =>\n this.executeWatchOperationsOnComponent(this.trackDirs[dir], [], false)\n );\n results.push(...addResults.flat());\n }\n if (removedDirs.length) {\n await this.fsWatcher.unwatch(removedDirs);\n await mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));\n }\n return results;\n }\n\n private async executeWatchOperationsOnRemove(componentId: ComponentID) {\n logger.debug(`running OnComponentRemove hook for ${chalk.bold(componentId.toString())}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentRemovedEvent(componentId.toString()));\n await this.workspace.triggerOnComponentRemove(componentId);\n }\n\n private async executeWatchOperationsOnComponent(\n componentId: ComponentID,\n files: string[],\n isChange = true,\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n if (this.isComponentWatchedExternally(componentId)) {\n // update capsule, once done, it automatically triggers the external watcher\n await this.workspace.get(componentId);\n return [];\n }\n const idStr = componentId.toString();\n\n if (isChange) {\n logger.debug(`running OnComponentChange hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentChangeEvent(idStr, 'OnComponentChange'));\n } else {\n logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentAddEvent(idStr, 'OnComponentAdd'));\n }\n\n let buildResults: OnComponentEventResult[];\n try {\n buildResults = isChange\n ? await this.workspace.triggerOnComponentChange(componentId, files, initiator)\n : await this.workspace.triggerOnComponentAdd(componentId);\n } catch (err: any) {\n // do not exit the watch process on errors, just print them\n const msg = `found an issue during onComponentChange or onComponentAdd hooks`;\n logger.error(msg, err);\n logger.console(`\\n${msg}: ${err.message || err}`);\n return [];\n }\n if (buildResults && buildResults.length) {\n return buildResults;\n }\n logger.console(`${idStr} doesn't have a compiler, nothing to build`);\n return [];\n }\n\n private creatOnComponentRemovedEvent(idStr) {\n return new OnComponentRemovedEvent(Date.now(), idStr);\n }\n\n private creatOnComponentChangeEvent(idStr, hook) {\n return new OnComponentChangeEvent(Date.now(), idStr, hook);\n }\n\n private creatOnComponentAddEvent(idStr, hook) {\n return new OnComponentAddEvent(Date.now(), idStr, hook);\n }\n\n private completeWatch() {\n loader.stop();\n return [];\n }\n\n private isComponentWatchedExternally(componentId: ComponentID) {\n const watcherData = this.multipleWatchers.find((m) => m.componentIds.find((id) => id.isEqual(componentId._legacy)));\n if (watcherData) {\n logger.debug(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);\n return true;\n }\n return false;\n }\n\n /**\n * if a file was added/remove, once the component is loaded, it changes .bitmap, and then the\n * entire cache is invalidated and the consumer is reloaded.\n * when a file just changed, no need to reload the consumer, it is enough to just delete the\n * component from the cache (both, workspace and consumer)\n */\n private async getComponentIdAndClearItsCache(filePath: string): Promise<ComponentID | null> {\n const relativeFile = pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(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 const componentId = this.trackDirs[trackDir];\n this.workspace.clearComponentCache(componentId);\n const component = await this.workspace.get(componentId);\n const componentMap: ComponentMap = component.state._consumer.componentMap;\n if (componentMap.getFilesRelativeToConsumer().find((p) => p === relativeFile)) {\n return componentId;\n }\n // the file is inside the component dir but it's ignored. (e.g. it's in IGNORE_LIST)\n return null;\n }\n\n private findTrackDirByFilePathRecursively(filePath: string): string | null {\n if (this.trackDirs[filePath]) return filePath;\n const parentDir = dirname(filePath);\n if (parentDir === filePath) return null;\n return this.findTrackDirByFilePathRecursively(parentDir);\n }\n\n private async createWatcher(pathsToWatch: string[]) {\n this.fsWatcher = chokidar.watch(pathsToWatch, {\n ignoreInitial: true,\n // Using the function way since the regular way not working as expected\n // It might be solved when upgrading to chokidar > 3.0.0\n // See:\n // https://github.com/paulmillr/chokidar/issues/773\n // https://github.com/paulmillr/chokidar/issues/492\n // https://github.com/paulmillr/chokidar/issues/724\n ignored: (path) => {\n // Ignore package.json temporarily since it cerates endless loop since it's re-written after each build\n if (path.includes(`${sep}node_modules${sep}`) || path.includes(`${sep}package.json`)) {\n return true;\n }\n return false;\n },\n persistent: true,\n useFsEvents: false,\n });\n }\n\n async setTrackDirs() {\n this.trackDirs = {};\n const componentsFromBitMap = this.consumer.bitMap.getAllComponents([\n COMPONENT_ORIGINS.AUTHORED,\n COMPONENT_ORIGINS.IMPORTED,\n ]);\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const trackDir = componentMap.getTrackDir();\n if (!trackDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[trackDir] = componentId;\n })\n );\n }\n\n private async getPathsToWatch(): Promise<PathOsBasedAbsolute[]> {\n await this.setTrackDirs();\n const paths = [...Object.keys(this.trackDirs), BIT_MAP];\n const pathsAbsolute = paths.map((dir) => this.consumer.toAbsolutePath(dir));\n return pathsAbsolute;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AA0BO,MAAMA,OAAN,CAAc;EAEnBC,WAAW,CACDC,SADC,EAEDC,MAFC,EAGDC,SAA4C,GAAG,EAH9C,EAIDC,OAAO,GAAG,KAJT,EAKDC,gBAAsC,GAAG,EALxC,EAMT;IAAA,KALQJ,SAKR,GALQA,SAKR;IAAA,KAJQC,MAIR,GAJQA,MAIR;IAAA,KAHQC,SAGR,GAHQA,SAGR;IAAA,KAFQC,OAER,GAFQA,OAER;IAAA,KADQC,gBACR,GADQA,gBACR;IAAA;EAAE;;EAEQ,IAARC,QAAQ,GAAa;IACvB,OAAO,KAAKL,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kBD;;EAEiB,MAAZlE,YAAY,GAAG;IACnB,KAAKxD,SAAL,GAAiB,EAAjB;IACA,MAAM2H,oBAAoB,GAAG,KAAKxH,QAAL,CAAcyH,MAAd,CAAqBC,gBAArB,CAAsC,CACjEC,8BAAA,CAAkBC,QAD+C,EAEjED,8BAAA,CAAkBE,QAF+C,CAAtC,CAA7B;IAIA,MAAM9G,OAAO,CAAC+G,GAAR,CACJN,oBAAoB,CAACO,GAArB,CAAyB,MAAOtB,YAAP,IAAwB;MAC/C,MAAMuB,KAAK,GAAGvB,YAAY,CAAChC,EAA3B;MACA,MAAM4B,QAAQ,GAAGI,YAAY,CAACwB,WAAb,EAAjB;MACA,IAAI,CAAC5B,QAAL,EAAe,MAAM,IAAI6B,KAAJ,CAAW,GAAEF,KAAK,CAAC1D,QAAN,EAAiB,8CAA9B,CAAN;MACf,MAAM5B,WAAW,GAAG,MAAM,KAAK/C,SAAL,CAAewI,kBAAf,CAAkCH,KAAlC,CAA1B;MACA,KAAKnI,SAAL,CAAewG,QAAf,IAA2B3D,WAA3B;IACD,CAND,CADI,CAAN;EASD;;EAE4B,MAAfpC,eAAe,GAAmC;IAC9D,MAAM,KAAK+C,YAAL,EAAN;IACA,MAAM+E,KAAK,GAAG,CAAC,GAAG5H,MAAM,CAACgD,IAAP,CAAY,KAAK3D,SAAjB,CAAJ,EAAiC0C,oBAAjC,CAAd;IACA,MAAM8F,aAAa,GAAGD,KAAK,CAACL,GAAN,CAAWhE,GAAD,IAAS,KAAK/D,QAAL,CAAcsI,cAAd,CAA6BvE,GAA7B,CAAnB,CAAtB;IACA,OAAOsE,aAAP;EACD;;AA9PkB"}
|
|
1
|
+
{"version":3,"names":["DEBOUNCE_WAIT_MS","Watcher","constructor","workspace","pubsub","trackDirs","verbose","multipleWatchers","consumer","watchAll","opts","msgs","watchOpts","pathsToWatch","getPathsToWatch","componentIds","Object","values","triggerOnPreWatch","createWatcher","watcher","fsWatcher","onStart","Promise","resolve","reject","process","env","BIT_LOG","onAll","on","onReady","filePath","startTime","Date","getTime","files","results","debounced","failureMsg","handleChange","initiator","duration","onChange","onAdd","p","onUnlink","err","onError","endsWith","BIT_MAP","buildResults","handleBitmapChanges","loader","stop","componentId","getComponentIdByPath","logger","debug","compIdStr","toString","changedFilesPerComponent","push","sleep","triggerCompChanges","length","undefined","join","msg","error","console","message","ms","setTimeout","clearComponentCache","component","get","componentMap","state","_consumer","compFiles","filter","relativeFile","getRelativePathLinux","isCompFile","Boolean","getFilesRelativeToConsumer","find","executeWatchOperationsOnComponent","previewsTrackDirs","_reloadConsumer","setTrackDirs","newDirs","difference","keys","removedDirs","add","addResults","mapSeries","dir","flat","unwatch","executeWatchOperationsOnRemove","chalk","bold","pub","WorkspaceAspect","id","creatOnComponentRemovedEvent","triggerOnComponentRemove","isChange","isComponentWatchedExternally","idStr","creatOnComponentChangeEvent","creatOnComponentAddEvent","triggerOnComponentChange","triggerOnComponentAdd","OnComponentRemovedEvent","now","hook","OnComponentChangeEvent","OnComponentAddEvent","watcherData","m","isEqual","_legacy","compilerId","trackDir","findTrackDirByFilePathRecursively","pathNormalizeToLinux","getPathRelativeToConsumer","parentDir","dirname","chokidar","watch","ignoreInitial","ignored","path","includes","sep","persistent","useFsEvents","componentsFromBitMap","bitMap","getAllComponents","COMPONENT_ORIGINS","AUTHORED","IMPORTED","all","map","bitId","getTrackDir","Error","resolveComponentId","paths","pathsAbsolute","toAbsolutePath"],"sources":["watcher.ts"],"sourcesContent":["import { PubsubMain } from '@teambit/pubsub';\nimport { dirname, sep } from 'path';\nimport { difference } from 'lodash';\nimport { ComponentID } from '@teambit/component';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport loader from '@teambit/legacy/dist/cli/loader';\nimport { BIT_MAP, COMPONENT_ORIGINS } from '@teambit/legacy/dist/constants';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport mapSeries from 'p-map-series';\nimport chalk from 'chalk';\nimport { ChildProcess } from 'child_process';\nimport chokidar, { FSWatcher } from 'chokidar';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { PathLinux, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport { WorkspaceAspect } from '../';\nimport { OnComponentChangeEvent, OnComponentAddEvent, OnComponentRemovedEvent } from '../events';\nimport { Workspace } from '../workspace';\nimport { OnComponentEventResult } from '../on-component-events';\nimport { CheckTypes } from './check-types';\n\nexport type WatcherProcessData = { watchProcess: ChildProcess; compilerId: BitId; componentIds: BitId[] };\n\nexport type EventMessages = {\n onAll: Function;\n onStart: Function;\n onReady: Function;\n onChange: Function;\n onAdd: Function;\n onUnlink: Function;\n onError: Function;\n};\n\nexport type WatchOptions = {\n msgs?: EventMessages;\n initiator?: CompilationInitiator;\n verbose?: boolean; // print watch events to the console. (also ts-server events if spawnTSServer is true)\n spawnTSServer?: boolean; // needed for check types and extract API/docs.\n checkTypes?: CheckTypes; // if enabled, the spawnTSServer becomes true.\n preCompile?: boolean; // whether compile all components before start watching\n};\n\nconst DEBOUNCE_WAIT_MS = 100;\n\nexport class Watcher {\n private fsWatcher: FSWatcher;\n private changedFilesPerComponent: { [componentId: string]: string[] } = {};\n constructor(\n private workspace: Workspace,\n private pubsub: PubsubMain,\n private trackDirs: { [dir: PathLinux]: ComponentID } = {},\n private verbose = false,\n private multipleWatchers: WatcherProcessData[] = []\n ) {}\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async watchAll(opts: WatchOptions) {\n const { msgs, ...watchOpts } = opts;\n // TODO: run build in the beginning of process (it's work like this in other envs)\n const pathsToWatch = await this.getPathsToWatch();\n const componentIds = Object.values(this.trackDirs);\n await this.workspace.triggerOnPreWatch(componentIds, watchOpts);\n await this.createWatcher(pathsToWatch);\n const watcher = this.fsWatcher;\n msgs?.onStart(this.workspace);\n\n return new Promise((resolve, reject) => {\n // prefix your command with \"BIT_LOG=*\" to see all watch events\n if (process.env.BIT_LOG) {\n // @ts-ignore\n if (msgs?.onAll) watcher.on('all', msgs?.onAll);\n }\n watcher.on('ready', () => {\n msgs?.onReady(this.workspace, this.trackDirs, this.verbose);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('change', async (filePath) => {\n const startTime = new Date().getTime();\n const { files, results, debounced, failureMsg } = await this.handleChange(filePath, opts?.initiator);\n if (debounced) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onChange(files, results, this.verbose, duration, failureMsg);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('add', async (filePath) => {\n const startTime = new Date().getTime();\n const { files, results, debounced, failureMsg } = await this.handleChange(filePath, opts?.initiator);\n if (debounced) {\n return;\n }\n const duration = new Date().getTime() - startTime;\n msgs?.onAdd(files, results, this.verbose, duration, failureMsg);\n });\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n watcher.on('unlink', async (p) => {\n msgs?.onUnlink(p);\n await this.handleChange(p);\n });\n watcher.on('error', (err) => {\n msgs?.onError(err);\n reject(err);\n });\n });\n }\n\n /**\n * some actions trigger multiple files changes at (almost) the same time. e.g. \"git pull\".\n * this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.\n * the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).\n * if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,\n * it'll only add the file to `this.changedFilesPerComponent` prop.\n * once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,\n * indicating the next file-change to start a new execution.\n *\n * implementation wise, `lodash.debounce` doesn't help here, because:\n * A) it doesn't return the results, unless \"leading\" option is true. here, it must be false, otherwise, it'll start\n * the execution immediately.\n * B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay\n * other components undesirably.\n *\n */\n private async handleChange(\n filePath: string,\n initiator?: CompilationInitiator\n ): Promise<{\n results: OnComponentEventResult[];\n files?: string[];\n failureMsg?: string;\n debounced?: boolean;\n }> {\n try {\n if (filePath.endsWith(BIT_MAP)) {\n const buildResults = await this.handleBitmapChanges();\n loader.stop();\n return { results: buildResults, files: [filePath] };\n }\n const componentId = this.getComponentIdByPath(filePath);\n if (!componentId) {\n const failureMsg = `file ${filePath} is not part of any component, ignoring it`;\n logger.debug(failureMsg);\n loader.stop();\n return { results: [], files: [filePath], failureMsg };\n }\n\n const compIdStr = componentId.toString();\n if (this.changedFilesPerComponent[compIdStr]) {\n this.changedFilesPerComponent[compIdStr].push(filePath);\n loader.stop();\n return { results: [], debounced: true };\n }\n this.changedFilesPerComponent[compIdStr] = [filePath];\n await this.sleep(DEBOUNCE_WAIT_MS);\n const files = this.changedFilesPerComponent[compIdStr];\n delete this.changedFilesPerComponent[compIdStr];\n\n const buildResults = await this.triggerCompChanges(componentId, files, initiator);\n const failureMsg = buildResults.length\n ? undefined\n : `files ${files.join(', ')} are inside the component ${compIdStr} but configured to be ignored`;\n loader.stop();\n return { results: buildResults, files, failureMsg };\n } catch (err: any) {\n const msg = `watcher found an error while handling ${filePath}`;\n logger.error(msg, err);\n logger.console(`${msg}, ${err.message}`);\n loader.stop();\n return { results: [], files: [filePath], failureMsg: err.message };\n }\n }\n\n private async sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * if a file was added/remove, once the component is loaded, it changes .bitmap, and then the\n * entire cache is invalidated and the consumer is reloaded.\n * when a file just changed, no need to reload the consumer, it is enough to just delete the\n * component from the cache (both, workspace and consumer)\n */\n private async triggerCompChanges(\n componentId: ComponentID,\n files: string[],\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n this.workspace.clearComponentCache(componentId);\n const component = await this.workspace.get(componentId);\n const componentMap: ComponentMap = component.state._consumer.componentMap;\n const compFiles = files.filter((filePath) => {\n const relativeFile = this.getRelativePathLinux(filePath);\n const isCompFile = Boolean(componentMap.getFilesRelativeToConsumer().find((p) => p === relativeFile));\n if (!isCompFile) {\n logger.debug(`file ${filePath} is inside the component ${componentId.toString()} but configured to be ignored`);\n }\n return isCompFile;\n });\n if (!compFiles.length) {\n return [];\n }\n const buildResults = await this.executeWatchOperationsOnComponent(componentId, compFiles, true, initiator);\n return buildResults;\n }\n\n /**\n * if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.\n */\n private async handleBitmapChanges(): Promise<OnComponentEventResult[]> {\n const previewsTrackDirs = { ...this.trackDirs };\n await this.workspace._reloadConsumer();\n await this.setTrackDirs();\n const newDirs: string[] = difference(Object.keys(this.trackDirs), Object.keys(previewsTrackDirs));\n const removedDirs: string[] = difference(Object.keys(previewsTrackDirs), Object.keys(this.trackDirs));\n const results: OnComponentEventResult[] = [];\n if (newDirs.length) {\n this.fsWatcher.add(newDirs);\n const addResults = await mapSeries(newDirs, async (dir) =>\n this.executeWatchOperationsOnComponent(this.trackDirs[dir], [], false)\n );\n results.push(...addResults.flat());\n }\n if (removedDirs.length) {\n await this.fsWatcher.unwatch(removedDirs);\n await mapSeries(removedDirs, (dir) => this.executeWatchOperationsOnRemove(previewsTrackDirs[dir]));\n }\n return results;\n }\n\n private async executeWatchOperationsOnRemove(componentId: ComponentID) {\n logger.debug(`running OnComponentRemove hook for ${chalk.bold(componentId.toString())}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentRemovedEvent(componentId.toString()));\n await this.workspace.triggerOnComponentRemove(componentId);\n }\n\n private async executeWatchOperationsOnComponent(\n componentId: ComponentID,\n files: string[],\n isChange = true,\n initiator?: CompilationInitiator\n ): Promise<OnComponentEventResult[]> {\n if (this.isComponentWatchedExternally(componentId)) {\n // update capsule, once done, it automatically triggers the external watcher\n await this.workspace.get(componentId);\n return [];\n }\n const idStr = componentId.toString();\n\n if (isChange) {\n logger.debug(`running OnComponentChange hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentChangeEvent(idStr, 'OnComponentChange'));\n } else {\n logger.debug(`running OnComponentAdd hook for ${chalk.bold(idStr)}`);\n this.pubsub.pub(WorkspaceAspect.id, this.creatOnComponentAddEvent(idStr, 'OnComponentAdd'));\n }\n\n let buildResults: OnComponentEventResult[];\n try {\n buildResults = isChange\n ? await this.workspace.triggerOnComponentChange(componentId, files, initiator)\n : await this.workspace.triggerOnComponentAdd(componentId);\n } catch (err: any) {\n // do not exit the watch process on errors, just print them\n const msg = `found an issue during onComponentChange or onComponentAdd hooks`;\n logger.error(msg, err);\n logger.console(`\\n${msg}: ${err.message || err}`);\n return [];\n }\n return buildResults;\n }\n\n private creatOnComponentRemovedEvent(idStr) {\n return new OnComponentRemovedEvent(Date.now(), idStr);\n }\n\n private creatOnComponentChangeEvent(idStr, hook) {\n return new OnComponentChangeEvent(Date.now(), idStr, hook);\n }\n\n private creatOnComponentAddEvent(idStr, hook) {\n return new OnComponentAddEvent(Date.now(), idStr, hook);\n }\n\n private isComponentWatchedExternally(componentId: ComponentID) {\n const watcherData = this.multipleWatchers.find((m) => m.componentIds.find((id) => id.isEqual(componentId._legacy)));\n if (watcherData) {\n logger.debug(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);\n return true;\n }\n return false;\n }\n\n private getComponentIdByPath(filePath: string): ComponentID | null {\n const relativeFile = this.getRelativePathLinux(filePath);\n const trackDir = this.findTrackDirByFilePathRecursively(relativeFile);\n if (!trackDir) {\n // the file is not part of any component. If it was a new component, or a new file of\n // existing component, then, handleBitmapChanges() should deal with it.\n return null;\n }\n return this.trackDirs[trackDir];\n }\n\n private getRelativePathLinux(filePath: string) {\n return pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(filePath));\n }\n\n private findTrackDirByFilePathRecursively(filePath: string): string | null {\n if (this.trackDirs[filePath]) return filePath;\n const parentDir = dirname(filePath);\n if (parentDir === filePath) return null;\n return this.findTrackDirByFilePathRecursively(parentDir);\n }\n\n private async createWatcher(pathsToWatch: string[]) {\n this.fsWatcher = chokidar.watch(pathsToWatch, {\n ignoreInitial: true,\n // Using the function way since the regular way not working as expected\n // It might be solved when upgrading to chokidar > 3.0.0\n // See:\n // https://github.com/paulmillr/chokidar/issues/773\n // https://github.com/paulmillr/chokidar/issues/492\n // https://github.com/paulmillr/chokidar/issues/724\n ignored: (path) => {\n // Ignore package.json temporarily since it cerates endless loop since it's re-written after each build\n if (path.includes(`${sep}node_modules${sep}`) || path.includes(`${sep}package.json`)) {\n return true;\n }\n return false;\n },\n persistent: true,\n useFsEvents: false,\n });\n }\n\n async setTrackDirs() {\n this.trackDirs = {};\n const componentsFromBitMap = this.consumer.bitMap.getAllComponents([\n COMPONENT_ORIGINS.AUTHORED,\n COMPONENT_ORIGINS.IMPORTED,\n ]);\n await Promise.all(\n componentsFromBitMap.map(async (componentMap) => {\n const bitId = componentMap.id;\n const trackDir = componentMap.getTrackDir();\n if (!trackDir) throw new Error(`${bitId.toString()} has no rootDir, which is invalid in Harmony`);\n const componentId = await this.workspace.resolveComponentId(bitId);\n this.trackDirs[trackDir] = componentId;\n })\n );\n }\n\n private async getPathsToWatch(): Promise<PathOsBasedAbsolute[]> {\n await this.setTrackDirs();\n const paths = [...Object.keys(this.trackDirs), BIT_MAP];\n const pathsAbsolute = paths.map((dir) => this.consumer.toAbsolutePath(dir));\n return pathsAbsolute;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;E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