@teambit/watcher 0.0.1
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/check-types.d.ts +5 -0
- package/dist/check-types.js +15 -0
- package/dist/check-types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/output-formatter.d.ts +9 -0
- package/dist/output-formatter.js +54 -0
- package/dist/output-formatter.js.map +1 -0
- package/dist/preview-1676777489824.js +7 -0
- package/dist/watch-queue.d.ts +8 -0
- package/dist/watch-queue.js +44 -0
- package/dist/watch-queue.js.map +1 -0
- package/dist/watch.cmd.d.ts +55 -0
- package/dist/watch.cmd.js +173 -0
- package/dist/watch.cmd.js.map +1 -0
- package/dist/watcher.aspect.d.ts +2 -0
- package/dist/watcher.aspect.js +19 -0
- package/dist/watcher.aspect.js.map +1 -0
- package/dist/watcher.d.ts +110 -0
- package/dist/watcher.js +456 -0
- package/dist/watcher.js.map +1 -0
- package/dist/watcher.main.runtime.d.ts +24 -0
- package/dist/watcher.main.runtime.js +117 -0
- package/dist/watcher.main.runtime.js.map +1 -0
- package/package-tar/teambit-watcher-0.0.1.tgz +0 -0
- package/package.json +63 -0
- package/tsconfig.json +40 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CheckTypes = void 0;
|
|
7
|
+
let CheckTypes;
|
|
8
|
+
exports.CheckTypes = CheckTypes;
|
|
9
|
+
(function (CheckTypes) {
|
|
10
|
+
CheckTypes[CheckTypes["None"] = 0] = "None";
|
|
11
|
+
CheckTypes[CheckTypes["EntireProject"] = 1] = "EntireProject";
|
|
12
|
+
CheckTypes[CheckTypes["ChangedFile"] = 2] = "ChangedFile";
|
|
13
|
+
})(CheckTypes || (exports.CheckTypes = CheckTypes = {}));
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=check-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CheckTypes"],"sources":["check-types.ts"],"sourcesContent":["export enum CheckTypes {\n None, // keep this. it equals zero. this way we can do \"if checkTypes() ... \"\n EntireProject,\n ChangedFile,\n}\n"],"mappings":";;;;;;IAAYA,UAAU;AAAA;AAAA,WAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;AAAA,GAAVA,UAAU,0BAAVA,UAAU"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CheckTypes", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _checkTypes().CheckTypes;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "WatchOptions", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _watcher2().WatchOptions;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "WatcherAspect", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _watcher().WatcherAspect;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
exports.default = void 0;
|
|
25
|
+
function _watcher() {
|
|
26
|
+
const data = require("./watcher.aspect");
|
|
27
|
+
_watcher = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
function _watcher2() {
|
|
33
|
+
const data = require("./watcher");
|
|
34
|
+
_watcher2 = function () {
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
function _checkTypes() {
|
|
40
|
+
const data = require("./check-types");
|
|
41
|
+
_checkTypes = function () {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
var _default = _watcher().WatcherAspect;
|
|
47
|
+
exports.default = _default;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WatcherAspect"],"sources":["index.ts"],"sourcesContent":["import { WatcherAspect } from './watcher.aspect';\n\nexport { WatchOptions } from './watcher';\nexport { CheckTypes } from './check-types';\nexport type { WatcherMain } from './watcher.main.runtime';\nexport default WatcherAspect;\nexport { WatcherAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA2C,eAE5BA,wBAAa;AAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OnComponentEventResult } from '@teambit/workspace';
|
|
2
|
+
export declare const formatWatchPathsSortByComponent: (trackDirs: any) => string;
|
|
3
|
+
/**
|
|
4
|
+
* todo: this was implemented incorrectly.
|
|
5
|
+
* the original idea of `SerializableResults` was to have each one of the aspects registered to the slot, the
|
|
6
|
+
* ability to have their own formatting to their results, and then `toString()` method to print them.
|
|
7
|
+
* Here, the printing is specifically to the Compiler aspect. It should move to where it belongs.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatCompileResults(compileResults: OnComponentEventResult[], verbose: boolean): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.formatCompileResults = formatCompileResults;
|
|
8
|
+
exports.formatWatchPathsSortByComponent = void 0;
|
|
9
|
+
function _chalk() {
|
|
10
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
11
|
+
_chalk = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
const verboseComponentFilesArrayToString = componentFiles => {
|
|
17
|
+
return componentFiles.reduce((outputString, filePath) => `${outputString} \t - ${filePath}\n`, ``);
|
|
18
|
+
};
|
|
19
|
+
const resultsForExtensionArrayToString = (resultsForExtension, verbose) => {
|
|
20
|
+
return resultsForExtension.reduce((outputString, resultForExtension) => `${outputString}${_chalk().default.green('√')}SUCCESS\t${resultForExtension.component}\n
|
|
21
|
+
${verbose ? resultForExtension.componentFilesAsString : ''}\n`, '');
|
|
22
|
+
};
|
|
23
|
+
const formatWatchPathsSortByComponent = trackDirs => {
|
|
24
|
+
return Object.keys(trackDirs).reduce((outputString, watchPath) => `${outputString}
|
|
25
|
+
${_chalk().default.green('√')} SUCCESS\t${trackDirs[watchPath]}\n
|
|
26
|
+
\t - ${watchPath}\n\n`, ` ${_chalk().default.underline('STATUS\t\tCOMPONENT ID')}\n`);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* todo: this was implemented incorrectly.
|
|
31
|
+
* the original idea of `SerializableResults` was to have each one of the aspects registered to the slot, the
|
|
32
|
+
* ability to have their own formatting to their results, and then `toString()` method to print them.
|
|
33
|
+
* Here, the printing is specifically to the Compiler aspect. It should move to where it belongs.
|
|
34
|
+
*/
|
|
35
|
+
exports.formatWatchPathsSortByComponent = formatWatchPathsSortByComponent;
|
|
36
|
+
function formatCompileResults(compileResults, verbose) {
|
|
37
|
+
if (!compileResults.length || !Array.isArray(compileResults)) return '';
|
|
38
|
+
return compileResults.filter(compileResult => {
|
|
39
|
+
var _compileResult$result, _compileResult$result2;
|
|
40
|
+
return ((_compileResult$result = compileResult.results) === null || _compileResult$result === void 0 ? void 0 : _compileResult$result.results) && Array.isArray((_compileResult$result2 = compileResult.results) === null || _compileResult$result2 === void 0 ? void 0 : _compileResult$result2.results);
|
|
41
|
+
}).map(compileResult => {
|
|
42
|
+
var _compileResult$result3, _compileResult$result4;
|
|
43
|
+
return {
|
|
44
|
+
extensionId: compileResult.extensionId,
|
|
45
|
+
resultsForExtension: (_compileResult$result3 = compileResult.results) === null || _compileResult$result3 === void 0 ? void 0 : (_compileResult$result4 = _compileResult$result3.results) === null || _compileResult$result4 === void 0 ? void 0 : _compileResult$result4.map(resultForExtension => ({
|
|
46
|
+
component: resultForExtension.component,
|
|
47
|
+
componentFilesAsString: verboseComponentFilesArrayToString(resultForExtension.buildResults)
|
|
48
|
+
}))
|
|
49
|
+
};
|
|
50
|
+
}).reduce((outputString, compileResult) => `${outputString}
|
|
51
|
+
${resultsForExtensionArrayToString(compileResult.resultsForExtension, verbose)}`, ` ${_chalk().default.underline('STATUS\tCOMPONENT ID')}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=output-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["verboseComponentFilesArrayToString","componentFiles","reduce","outputString","filePath","resultsForExtensionArrayToString","resultsForExtension","verbose","resultForExtension","chalk","green","component","componentFilesAsString","formatWatchPathsSortByComponent","trackDirs","Object","keys","watchPath","underline","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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA,MAAMA,kCAAkC,GAAIC,cAAc,IAAK;EAC7D,OAAOA,cAAc,CAACC,MAAM,CAAC,CAACC,YAAY,EAAEC,QAAQ,KAAM,GAAED,YAAa,SAAQC,QAAS,IAAG,EAAG,EAAC,CAAC;AACpG,CAAC;AAED,MAAMC,gCAAgC,GAAG,CAACC,mBAAmB,EAAEC,OAAO,KAAK;EACzE,OAAOD,mBAAmB,CAACJ,MAAM,CAC/B,CAACC,YAAY,EAAEK,kBAAkB,KAC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AAC,CAAC;IACJ,CAAC;EAAA,CAAC,CAAC,CACF3B,MAAM,CACL,CAACC,YAAY,EAAEsB,aAAa,KACzB,GAAEtB,YAAa;AACxB,IAAIE,gCAAgC,CAACoB,aAAa,CAACnB,mBAAmB,EAAEC,OAAO,CAAE,EAAC,EAC3E,IAAGE,gBAAK,CAACS,SAAS,CAAC,sBAAsB,CAAE,EAAC,CAC9C;AACL"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
export declare class WatchQueue {
|
|
3
|
+
private queue;
|
|
4
|
+
constructor(concurrency?: number);
|
|
5
|
+
getQueue(): PQueue<import("p-queue/dist/priority-queue").default, import("p-queue").DefaultAddOptions>;
|
|
6
|
+
add<T>(fn: () => T, priority?: number): Promise<T>;
|
|
7
|
+
onIdle(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.WatchQueue = void 0;
|
|
8
|
+
function _defineProperty2() {
|
|
9
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
_defineProperty2 = function () {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _pQueue() {
|
|
16
|
+
const data = _interopRequireDefault(require("p-queue"));
|
|
17
|
+
_pQueue = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
class WatchQueue {
|
|
23
|
+
constructor(concurrency = 1) {
|
|
24
|
+
(0, _defineProperty2().default)(this, "queue", void 0);
|
|
25
|
+
this.queue = new (_pQueue().default)({
|
|
26
|
+
concurrency,
|
|
27
|
+
autoStart: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getQueue() {
|
|
31
|
+
return this.queue;
|
|
32
|
+
}
|
|
33
|
+
add(fn, priority) {
|
|
34
|
+
return this.queue.add(fn, {
|
|
35
|
+
priority
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
onIdle() {
|
|
39
|
+
return this.queue.onIdle();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.WatchQueue = WatchQueue;
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=watch-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WatchQueue","constructor","concurrency","queue","PQueue","autoStart","getQueue","add","fn","priority","onIdle"],"sources":["watch-queue.ts"],"sourcesContent":["import PQueue from 'p-queue';\n\nexport class WatchQueue {\n private queue: PQueue;\n constructor(concurrency = 1) {\n this.queue = new PQueue({ concurrency, autoStart: true });\n }\n getQueue() {\n return this.queue;\n }\n add<T>(fn: () => T, priority?: number): Promise<T> {\n return this.queue.add(fn, { priority });\n }\n onIdle(): Promise<void> {\n return this.queue.onIdle();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,UAAU,CAAC;EAEtBC,WAAW,CAACC,WAAW,GAAG,CAAC,EAAE;IAAA;IAC3B,IAAI,CAACC,KAAK,GAAG,KAAIC,iBAAM,EAAC;MAAEF,WAAW;MAAEG,SAAS,EAAE;IAAK,CAAC,CAAC;EAC3D;EACAC,QAAQ,GAAG;IACT,OAAO,IAAI,CAACH,KAAK;EACnB;EACAI,GAAG,CAAIC,EAAW,EAAEC,QAAiB,EAAc;IACjD,OAAO,IAAI,CAACN,KAAK,CAACI,GAAG,CAACC,EAAE,EAAE;MAAEC;IAAS,CAAC,CAAC;EACzC;EACAC,MAAM,GAAkB;IACtB,OAAO,IAAI,CAACP,KAAK,CAACO,MAAM,EAAE;EAC5B;AACF;AAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
+
import type { Logger } from '@teambit/logger';
|
|
3
|
+
import type { PubsubMain } from '@teambit/pubsub';
|
|
4
|
+
import { OnComponentEventResult } from '@teambit/workspace';
|
|
5
|
+
import { WatcherMain } from './watcher.main.runtime';
|
|
6
|
+
export declare type WatchCmdOpts = {
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
skipPreCompilation?: boolean;
|
|
9
|
+
checkTypes?: string | boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare class WatchCommand implements Command {
|
|
12
|
+
/**
|
|
13
|
+
* logger extension.
|
|
14
|
+
*/
|
|
15
|
+
private pubsub;
|
|
16
|
+
/**
|
|
17
|
+
* logger extension.
|
|
18
|
+
*/
|
|
19
|
+
private logger;
|
|
20
|
+
/**
|
|
21
|
+
* watcher extension.
|
|
22
|
+
*/
|
|
23
|
+
private watcher;
|
|
24
|
+
msgs: {
|
|
25
|
+
onAll: (event: string, path: string) => void;
|
|
26
|
+
onStart: () => void;
|
|
27
|
+
onReady: (workspace: any, watchPathsSortByComponent: any, verbose: any) => void;
|
|
28
|
+
onChange: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string) => void;
|
|
29
|
+
onAdd: (filePaths: string[], buildResults: OnComponentEventResult[], verbose: boolean, duration: any, failureMsg?: string) => void;
|
|
30
|
+
onUnlink: (p: any) => void;
|
|
31
|
+
onError: (err: any) => void;
|
|
32
|
+
};
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
helpUrl: string;
|
|
36
|
+
alias: string;
|
|
37
|
+
group: string;
|
|
38
|
+
options: CommandOptions;
|
|
39
|
+
constructor(
|
|
40
|
+
/**
|
|
41
|
+
* logger extension.
|
|
42
|
+
*/
|
|
43
|
+
pubsub: PubsubMain,
|
|
44
|
+
/**
|
|
45
|
+
* logger extension.
|
|
46
|
+
*/
|
|
47
|
+
logger: Logger,
|
|
48
|
+
/**
|
|
49
|
+
* watcher extension.
|
|
50
|
+
*/
|
|
51
|
+
watcher: WatcherMain);
|
|
52
|
+
private registerToEvents;
|
|
53
|
+
private eventsListener;
|
|
54
|
+
report(cliArgs: [], watchCmdOpts: WatchCmdOpts): Promise<string>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.promise.js");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.WatchCommand = void 0;
|
|
9
|
+
function _defineProperty2() {
|
|
10
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
_defineProperty2 = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
function _chalk() {
|
|
17
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
18
|
+
_chalk = function () {
|
|
19
|
+
return data;
|
|
20
|
+
};
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
function _moment() {
|
|
24
|
+
const data = _interopRequireDefault(require("moment"));
|
|
25
|
+
_moment = function () {
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
function _compiler() {
|
|
31
|
+
const data = require("@teambit/compiler");
|
|
32
|
+
_compiler = function () {
|
|
33
|
+
return data;
|
|
34
|
+
};
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
function _outputFormatter() {
|
|
38
|
+
const data = require("./output-formatter");
|
|
39
|
+
_outputFormatter = function () {
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
function _checkTypes() {
|
|
45
|
+
const data = require("./check-types");
|
|
46
|
+
_checkTypes = function () {
|
|
47
|
+
return data;
|
|
48
|
+
};
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
// import IDs and events
|
|
52
|
+
|
|
53
|
+
class WatchCommand {
|
|
54
|
+
constructor(
|
|
55
|
+
/**
|
|
56
|
+
* logger extension.
|
|
57
|
+
*/
|
|
58
|
+
pubsub,
|
|
59
|
+
/**
|
|
60
|
+
* logger extension.
|
|
61
|
+
*/
|
|
62
|
+
logger,
|
|
63
|
+
/**
|
|
64
|
+
* watcher extension.
|
|
65
|
+
*/
|
|
66
|
+
watcher) {
|
|
67
|
+
this.pubsub = pubsub;
|
|
68
|
+
this.logger = logger;
|
|
69
|
+
this.watcher = watcher;
|
|
70
|
+
(0, _defineProperty2().default)(this, "msgs", {
|
|
71
|
+
onAll: (event, path) => this.logger.console(`Event: "${event}". Path: ${path}`),
|
|
72
|
+
onStart: () => {},
|
|
73
|
+
onReady: (workspace, watchPathsSortByComponent, verbose) => {
|
|
74
|
+
clearOutdatedData();
|
|
75
|
+
if (verbose) {
|
|
76
|
+
this.logger.console((0, _outputFormatter().formatWatchPathsSortByComponent)(watchPathsSortByComponent));
|
|
77
|
+
}
|
|
78
|
+
this.logger.console(_chalk().default.yellow(`Watching for component changes in workspace ${workspace.config.name} (${(0, _moment().default)().format('HH:mm:ss')})...\n`));
|
|
79
|
+
},
|
|
80
|
+
onChange: (filePaths, buildResults, verbose, duration, failureMsg) => {
|
|
81
|
+
const files = filePaths.join(', ');
|
|
82
|
+
// clearOutdatedData();
|
|
83
|
+
if (!buildResults.length) {
|
|
84
|
+
failureMsg = failureMsg || `The files ${files} have been changed, but nothing to compile`;
|
|
85
|
+
this.logger.console(`${failureMsg}\n\n`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.logger.console(`The file(s) ${files} have been changed.\n\n`);
|
|
89
|
+
this.logger.console((0, _outputFormatter().formatCompileResults)(buildResults, verbose));
|
|
90
|
+
this.logger.console(`Finished. (${duration}ms)`);
|
|
91
|
+
this.logger.console(_chalk().default.yellow(`Watching for component changes (${(0, _moment().default)().format('HH:mm:ss')})...`));
|
|
92
|
+
},
|
|
93
|
+
onAdd: (filePaths, buildResults, verbose, duration, failureMsg) => {
|
|
94
|
+
const files = filePaths.join(', ');
|
|
95
|
+
// clearOutdatedData();
|
|
96
|
+
if (!buildResults.length) {
|
|
97
|
+
failureMsg = failureMsg || `The files ${files} have been added, but nothing to compile`;
|
|
98
|
+
this.logger.console(`${failureMsg}\n\n`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.logger.console(`The file(s) ${filePaths} have been added.\n\n`);
|
|
102
|
+
this.logger.console((0, _outputFormatter().formatCompileResults)(buildResults, verbose));
|
|
103
|
+
this.logger.console(`Finished. (${duration}ms)`);
|
|
104
|
+
this.logger.console(_chalk().default.yellow(`Watching for component changes (${(0, _moment().default)().format('HH:mm:ss')})...`));
|
|
105
|
+
},
|
|
106
|
+
onUnlink: p => {
|
|
107
|
+
this.logger.console(`file ${p} has been removed`);
|
|
108
|
+
},
|
|
109
|
+
onError: err => {
|
|
110
|
+
this.logger.console(`Watcher error ${err}`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
(0, _defineProperty2().default)(this, "name", 'watch');
|
|
114
|
+
(0, _defineProperty2().default)(this, "description", 'automatically recompile modified components (on save)');
|
|
115
|
+
(0, _defineProperty2().default)(this, "helpUrl", 'reference/compiling/compiler-overview');
|
|
116
|
+
(0, _defineProperty2().default)(this, "alias", '');
|
|
117
|
+
(0, _defineProperty2().default)(this, "group", 'development');
|
|
118
|
+
(0, _defineProperty2().default)(this, "options", [['v', 'verbose', 'show npm verbose output for inspection and print the stack trace'], ['', 'skip-pre-compilation', 'skip the compilation step before starting to watch'], ['t', 'check-types [string]', 'EXPERIMENTAL. show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project']]);
|
|
119
|
+
(0, _defineProperty2().default)(this, "eventsListener", event => {
|
|
120
|
+
switch (event.type) {
|
|
121
|
+
case _compiler().CompilerErrorEvent.TYPE:
|
|
122
|
+
this.logger.console(`Watcher error ${event.data.error}, 'error'`);
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
this.registerToEvents();
|
|
128
|
+
}
|
|
129
|
+
registerToEvents() {
|
|
130
|
+
this.pubsub.sub(_compiler().CompilerAspect.id, this.eventsListener);
|
|
131
|
+
}
|
|
132
|
+
async report(cliArgs, watchCmdOpts) {
|
|
133
|
+
const {
|
|
134
|
+
verbose,
|
|
135
|
+
checkTypes
|
|
136
|
+
} = watchCmdOpts;
|
|
137
|
+
const getCheckTypesEnum = () => {
|
|
138
|
+
switch (checkTypes) {
|
|
139
|
+
case undefined:
|
|
140
|
+
case false:
|
|
141
|
+
return _checkTypes().CheckTypes.None;
|
|
142
|
+
case 'project':
|
|
143
|
+
case true:
|
|
144
|
+
// project is the default
|
|
145
|
+
return _checkTypes().CheckTypes.EntireProject;
|
|
146
|
+
case 'file':
|
|
147
|
+
return _checkTypes().CheckTypes.ChangedFile;
|
|
148
|
+
default:
|
|
149
|
+
throw new Error(`check-types can be either "file" or "project". got "${checkTypes}"`);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const watchOpts = {
|
|
153
|
+
msgs: this.msgs,
|
|
154
|
+
verbose,
|
|
155
|
+
preCompile: !watchCmdOpts.skipPreCompilation,
|
|
156
|
+
spawnTSServer: Boolean(checkTypes),
|
|
157
|
+
// if check-types is enabled, it must spawn the tsserver.
|
|
158
|
+
checkTypes: getCheckTypesEnum()
|
|
159
|
+
};
|
|
160
|
+
await this.watcher.watch(watchOpts);
|
|
161
|
+
return 'watcher terminated';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* with console.clear() all history is deleted from the console. this function preserver the history.
|
|
167
|
+
*/
|
|
168
|
+
exports.WatchCommand = WatchCommand;
|
|
169
|
+
function clearOutdatedData() {
|
|
170
|
+
process.stdout.write('\x1Bc');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=watch.cmd.js.map
|
|
@@ -0,0 +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","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","watch","process","stdout","write"],"sources":["watch.cmd.ts"],"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';\nimport { OnComponentEventResult } from '@teambit/workspace';\n\n// import IDs and events\nimport { CompilerAspect, CompilerErrorEvent } from '@teambit/compiler';\n\nimport { WatchOptions } from './watcher';\nimport { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';\nimport { CheckTypes } from './check-types';\nimport { WatcherMain } from './watcher.main.runtime';\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 = 'automatically recompile modified components (on save)';\n helpUrl = 'reference/compiling/compiler-overview';\n alias = '';\n group = 'development';\n options = [\n ['v', 'verbose', 'show npm verbose output for inspection and print the 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: WatcherMain\n ) {\n this.registerToEvents();\n }\n\n private registerToEvents() {\n this.pubsub.sub(CompilerAspect.id, this.eventsListener);\n }\n\n private eventsListener = (event: BitBaseEvent<any>) => {\n switch (event.type) {\n case CompilerErrorEvent.TYPE:\n this.logger.console(`Watcher error ${event.data.error}, 'error'`);\n break;\n default:\n }\n };\n\n async 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.watch(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;AAOA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AALA;;AAcO,MAAMA,YAAY,CAAoB;EA4E3CC,WAAW;EACT;AACJ;AACA;EACYC,MAAkB;EAE1B;AACJ;AACA;EACYC,MAAc;EAEtB;AACJ;AACA;EACYC,OAAoB,EAC5B;IAAA,KAXQF,MAAkB,GAAlBA,MAAkB;IAAA,KAKlBC,MAAc,GAAdA,MAAc;IAAA,KAKdC,OAAoB,GAApBA,OAA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;AAEA;AACA;AACA;AAFA;AAGA,SAAS3C,iBAAiB,GAAG;EAC3BkD,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,OAAO,CAAC;AAC/B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WatcherAspect = void 0;
|
|
7
|
+
function _harmony() {
|
|
8
|
+
const data = require("@teambit/harmony");
|
|
9
|
+
_harmony = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
const WatcherAspect = _harmony().Aspect.create({
|
|
15
|
+
id: 'teambit.workspace/watcher'
|
|
16
|
+
});
|
|
17
|
+
exports.WatcherAspect = WatcherAspect;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=watcher.aspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WatcherAspect","Aspect","create","id"],"sources":["watcher.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const WatcherAspect = Aspect.create({\n id: 'teambit.workspace/watcher',\n});\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,aAAa,GAAGC,iBAAM,CAACC,MAAM,CAAC;EACzCC,EAAE,EAAE;AACN,CAAC,CAAC;AAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PubsubMain } from '@teambit/pubsub';
|
|
3
|
+
import { ComponentID } from '@teambit/component';
|
|
4
|
+
import { BitId } from '@teambit/legacy-bit-id';
|
|
5
|
+
import { Consumer } from '@teambit/legacy/dist/consumer';
|
|
6
|
+
import { ChildProcess } from 'child_process';
|
|
7
|
+
import { PathLinux } from '@teambit/legacy/dist/utils/path';
|
|
8
|
+
import { CompilationInitiator } from '@teambit/compiler';
|
|
9
|
+
import { Workspace } from '@teambit/workspace';
|
|
10
|
+
import { CheckTypes } from './check-types';
|
|
11
|
+
import { WatcherMain } from './watcher.main.runtime';
|
|
12
|
+
export declare type WatcherProcessData = {
|
|
13
|
+
watchProcess: ChildProcess;
|
|
14
|
+
compilerId: BitId;
|
|
15
|
+
componentIds: BitId[];
|
|
16
|
+
};
|
|
17
|
+
export declare type EventMessages = {
|
|
18
|
+
onAll: Function;
|
|
19
|
+
onStart: Function;
|
|
20
|
+
onReady: Function;
|
|
21
|
+
onChange: Function;
|
|
22
|
+
onAdd: Function;
|
|
23
|
+
onUnlink: Function;
|
|
24
|
+
onError: Function;
|
|
25
|
+
};
|
|
26
|
+
export declare type WatchOptions = {
|
|
27
|
+
msgs?: EventMessages;
|
|
28
|
+
initiator?: CompilationInitiator;
|
|
29
|
+
verbose?: boolean;
|
|
30
|
+
spawnTSServer?: boolean;
|
|
31
|
+
checkTypes?: CheckTypes;
|
|
32
|
+
preCompile?: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare class Watcher {
|
|
35
|
+
private workspace;
|
|
36
|
+
private pubsub;
|
|
37
|
+
private watcherMain;
|
|
38
|
+
private trackDirs;
|
|
39
|
+
private verbose;
|
|
40
|
+
private multipleWatchers;
|
|
41
|
+
private fsWatcher;
|
|
42
|
+
private changedFilesPerComponent;
|
|
43
|
+
private watchQueue;
|
|
44
|
+
private bitMapChangesInProgress;
|
|
45
|
+
constructor(workspace: Workspace, pubsub: PubsubMain, watcherMain: WatcherMain, trackDirs?: {
|
|
46
|
+
[dir: PathLinux]: ComponentID;
|
|
47
|
+
}, verbose?: boolean, multipleWatchers?: WatcherProcessData[]);
|
|
48
|
+
get consumer(): Consumer;
|
|
49
|
+
watchAll(opts: WatchOptions): Promise<unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* *** DEBOUNCING ***
|
|
52
|
+
* some actions trigger multiple files changes at (almost) the same time. e.g. "git pull".
|
|
53
|
+
* this causes some performance and instability issues. a debouncing mechanism was implemented to help with this.
|
|
54
|
+
* the way how it works is that the first file of the same component starts the execution with a delay (e.g. 200ms).
|
|
55
|
+
* if, in the meanwhile, another file of the same component was changed, it won't start a new execution, instead,
|
|
56
|
+
* it'll only add the file to `this.changedFilesPerComponent` prop.
|
|
57
|
+
* once the execution starts, it'll delete this component-id from the `this.changedFilesPerComponent` array,
|
|
58
|
+
* indicating the next file-change to start a new execution.
|
|
59
|
+
*
|
|
60
|
+
* implementation wise, `lodash.debounce` doesn't help here, because:
|
|
61
|
+
* A) it doesn't return the results, unless "leading" option is true. here, it must be false, otherwise, it'll start
|
|
62
|
+
* the execution immediately.
|
|
63
|
+
* B) it debounces the method regardless the param passes to it. so it'll disregard the component-id and will delay
|
|
64
|
+
* other components undesirably.
|
|
65
|
+
*
|
|
66
|
+
* *** QUEUE ***
|
|
67
|
+
* the debouncing helps to not execute the same component multiple times concurrently. however, multiple components
|
|
68
|
+
* and .bitmap changes execution can still be processed concurrently.
|
|
69
|
+
* the following example explains why this is an issue.
|
|
70
|
+
* compA is changed in the .bitmap file from version 0.0.1 to 0.0.2. its files were changed as well.
|
|
71
|
+
* all these changes get pulled at the same time by "git pull", as a result, the execution of compA and the .bitmap
|
|
72
|
+
* happen at the same time.
|
|
73
|
+
* during the execution of compA, the component id is parsed as compA@0.0.1, later, it asks for the Workspace for this
|
|
74
|
+
* id. while the workspace is looking for this id, the .bitmap execution reloaded the consumer and changed all versions.
|
|
75
|
+
* after this change, the workspace doesn't have this id anymore, which will trigger an error.
|
|
76
|
+
* to ensure this won't happen, we keep a flag to indicate whether the .bitmap execution is running, and if so, all
|
|
77
|
+
* other executions are paused until the queue is empty (this is done by awaiting for queue.onIdle).
|
|
78
|
+
* once the queue is empty, we know the .bitmap process was done and the workspace has all new ids.
|
|
79
|
+
* in the example above, at this stage, the id will be resolved to compA@0.0.2.
|
|
80
|
+
* one more thing, the queue is configured to have concurrency of 1. to make sure two components are not processed at
|
|
81
|
+
* the same time. (the same way is done when loading all components from the filesystem/scope).
|
|
82
|
+
* this way we can also ensure that if compA was started before the .bitmap execution, it will complete before the
|
|
83
|
+
* .bitmap execution starts.
|
|
84
|
+
*/
|
|
85
|
+
private handleChange;
|
|
86
|
+
private sleep;
|
|
87
|
+
/**
|
|
88
|
+
* if a file was added/remove, once the component is loaded, it changes .bitmap, and then the
|
|
89
|
+
* entire cache is invalidated and the consumer is reloaded.
|
|
90
|
+
* when a file just changed, no need to reload the consumer, it is enough to just delete the
|
|
91
|
+
* component from the cache (both, workspace and consumer)
|
|
92
|
+
*/
|
|
93
|
+
private triggerCompChanges;
|
|
94
|
+
/**
|
|
95
|
+
* if .bitmap changed, it's possible that a new component has been added. trigger onComponentAdd.
|
|
96
|
+
*/
|
|
97
|
+
private handleBitmapChanges;
|
|
98
|
+
private executeWatchOperationsOnRemove;
|
|
99
|
+
private executeWatchOperationsOnComponent;
|
|
100
|
+
private creatOnComponentRemovedEvent;
|
|
101
|
+
private creatOnComponentChangeEvent;
|
|
102
|
+
private creatOnComponentAddEvent;
|
|
103
|
+
private isComponentWatchedExternally;
|
|
104
|
+
private getComponentIdByPath;
|
|
105
|
+
private getRelativePathLinux;
|
|
106
|
+
private findTrackDirByFilePathRecursively;
|
|
107
|
+
private createWatcher;
|
|
108
|
+
setTrackDirs(): Promise<void>;
|
|
109
|
+
private getPathsToWatch;
|
|
110
|
+
}
|