@plugjs/plug 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.
Files changed (264) hide show
  1. package/LICENSE.md +211 -0
  2. package/NOTICE.md +13 -0
  3. package/README.md +7 -0
  4. package/dist/assert.cjs +72 -0
  5. package/dist/assert.cjs.map +6 -0
  6. package/dist/assert.mjs +41 -0
  7. package/dist/assert.mjs.map +6 -0
  8. package/dist/async.cjs +58 -0
  9. package/dist/async.cjs.map +6 -0
  10. package/dist/async.mjs +30 -0
  11. package/dist/async.mjs.map +6 -0
  12. package/dist/build.cjs +136 -0
  13. package/dist/build.cjs.map +6 -0
  14. package/dist/build.mjs +110 -0
  15. package/dist/build.mjs.map +6 -0
  16. package/dist/files.cjs +113 -0
  17. package/dist/files.cjs.map +6 -0
  18. package/dist/files.mjs +88 -0
  19. package/dist/files.mjs.map +6 -0
  20. package/dist/fork.cjs +177 -0
  21. package/dist/fork.cjs.map +6 -0
  22. package/dist/fork.mjs +151 -0
  23. package/dist/fork.mjs.map +6 -0
  24. package/dist/helpers.cjs +129 -0
  25. package/dist/helpers.cjs.map +6 -0
  26. package/dist/helpers.mjs +97 -0
  27. package/dist/helpers.mjs.map +6 -0
  28. package/dist/index.cjs +25 -0
  29. package/dist/index.cjs.map +6 -0
  30. package/dist/index.mjs +7 -0
  31. package/dist/index.mjs.map +6 -0
  32. package/dist/log/colors.cjs +129 -0
  33. package/dist/log/colors.cjs.map +6 -0
  34. package/dist/log/colors.mjs +93 -0
  35. package/dist/log/colors.mjs.map +6 -0
  36. package/dist/log/emit.cjs +109 -0
  37. package/dist/log/emit.cjs.map +6 -0
  38. package/dist/log/emit.mjs +83 -0
  39. package/dist/log/emit.mjs.map +6 -0
  40. package/dist/log/levels.cjs +75 -0
  41. package/dist/log/levels.cjs.map +6 -0
  42. package/dist/log/levels.mjs +41 -0
  43. package/dist/log/levels.mjs.map +6 -0
  44. package/dist/log/logger.cjs +129 -0
  45. package/dist/log/logger.cjs.map +6 -0
  46. package/dist/log/logger.mjs +104 -0
  47. package/dist/log/logger.mjs.map +6 -0
  48. package/dist/log/options.cjs +149 -0
  49. package/dist/log/options.cjs.map +6 -0
  50. package/dist/log/options.mjs +124 -0
  51. package/dist/log/options.mjs.map +6 -0
  52. package/dist/log/report.cjs +284 -0
  53. package/dist/log/report.cjs.map +6 -0
  54. package/dist/log/report.mjs +259 -0
  55. package/dist/log/report.mjs.map +6 -0
  56. package/dist/log/spinner.cjs +83 -0
  57. package/dist/log/spinner.cjs.map +6 -0
  58. package/dist/log/spinner.mjs +57 -0
  59. package/dist/log/spinner.mjs.map +6 -0
  60. package/dist/log.cjs +71 -0
  61. package/dist/log.cjs.map +6 -0
  62. package/dist/log.mjs +45 -0
  63. package/dist/log.mjs.map +6 -0
  64. package/dist/paths.cjs +158 -0
  65. package/dist/paths.cjs.map +6 -0
  66. package/dist/paths.mjs +122 -0
  67. package/dist/paths.mjs.map +6 -0
  68. package/dist/pipe.cjs +71 -0
  69. package/dist/pipe.cjs.map +6 -0
  70. package/dist/pipe.mjs +44 -0
  71. package/dist/pipe.mjs.map +6 -0
  72. package/dist/plugs/copy.cjs +95 -0
  73. package/dist/plugs/copy.cjs.map +6 -0
  74. package/dist/plugs/copy.mjs +64 -0
  75. package/dist/plugs/copy.mjs.map +6 -0
  76. package/dist/plugs/coverage/analysis.cjs +229 -0
  77. package/dist/plugs/coverage/analysis.cjs.map +6 -0
  78. package/dist/plugs/coverage/analysis.mjs +202 -0
  79. package/dist/plugs/coverage/analysis.mjs.map +6 -0
  80. package/dist/plugs/coverage/report.cjs +215 -0
  81. package/dist/plugs/coverage/report.cjs.map +6 -0
  82. package/dist/plugs/coverage/report.mjs +200 -0
  83. package/dist/plugs/coverage/report.mjs.map +6 -0
  84. package/dist/plugs/coverage.cjs +142 -0
  85. package/dist/plugs/coverage.cjs.map +6 -0
  86. package/dist/plugs/coverage.mjs +117 -0
  87. package/dist/plugs/coverage.mjs.map +6 -0
  88. package/dist/plugs/debug.cjs +50 -0
  89. package/dist/plugs/debug.cjs.map +6 -0
  90. package/dist/plugs/debug.mjs +25 -0
  91. package/dist/plugs/debug.mjs.map +6 -0
  92. package/dist/plugs/esbuild/bundle-locals.cjs +51 -0
  93. package/dist/plugs/esbuild/bundle-locals.cjs.map +6 -0
  94. package/dist/plugs/esbuild/bundle-locals.mjs +26 -0
  95. package/dist/plugs/esbuild/bundle-locals.mjs.map +6 -0
  96. package/dist/plugs/esbuild/check-dependencies.cjs +140 -0
  97. package/dist/plugs/esbuild/check-dependencies.cjs.map +6 -0
  98. package/dist/plugs/esbuild/check-dependencies.mjs +115 -0
  99. package/dist/plugs/esbuild/check-dependencies.mjs.map +6 -0
  100. package/dist/plugs/esbuild/fix-extensions.cjs +91 -0
  101. package/dist/plugs/esbuild/fix-extensions.cjs.map +6 -0
  102. package/dist/plugs/esbuild/fix-extensions.mjs +60 -0
  103. package/dist/plugs/esbuild/fix-extensions.mjs.map +6 -0
  104. package/dist/plugs/esbuild.cjs +109 -0
  105. package/dist/plugs/esbuild.cjs.map +6 -0
  106. package/dist/plugs/esbuild.mjs +83 -0
  107. package/dist/plugs/esbuild.mjs.map +6 -0
  108. package/dist/plugs/eslint/runner.cjs +91 -0
  109. package/dist/plugs/eslint/runner.cjs.map +6 -0
  110. package/dist/plugs/eslint/runner.mjs +68 -0
  111. package/dist/plugs/eslint/runner.mjs.map +6 -0
  112. package/dist/plugs/exec.cjs +128 -0
  113. package/dist/plugs/exec.cjs.map +6 -0
  114. package/dist/plugs/exec.mjs +96 -0
  115. package/dist/plugs/exec.mjs.map +6 -0
  116. package/dist/plugs/filter.cjs +59 -0
  117. package/dist/plugs/filter.cjs.map +6 -0
  118. package/dist/plugs/filter.mjs +34 -0
  119. package/dist/plugs/filter.mjs.map +6 -0
  120. package/dist/plugs/mocha/reporter.cjs +140 -0
  121. package/dist/plugs/mocha/reporter.cjs.map +6 -0
  122. package/dist/plugs/mocha/reporter.mjs +107 -0
  123. package/dist/plugs/mocha/reporter.mjs.map +6 -0
  124. package/dist/plugs/mocha/runner.cjs +73 -0
  125. package/dist/plugs/mocha/runner.cjs.map +6 -0
  126. package/dist/plugs/mocha/runner.mjs +44 -0
  127. package/dist/plugs/mocha/runner.mjs.map +6 -0
  128. package/dist/plugs/tsc/compiler.cjs +74 -0
  129. package/dist/plugs/tsc/compiler.cjs.map +6 -0
  130. package/dist/plugs/tsc/compiler.mjs +43 -0
  131. package/dist/plugs/tsc/compiler.mjs.map +6 -0
  132. package/dist/plugs/tsc/options.cjs +82 -0
  133. package/dist/plugs/tsc/options.cjs.map +6 -0
  134. package/dist/plugs/tsc/options.mjs +51 -0
  135. package/dist/plugs/tsc/options.mjs.map +6 -0
  136. package/dist/plugs/tsc/report.cjs +90 -0
  137. package/dist/plugs/tsc/report.cjs.map +6 -0
  138. package/dist/plugs/tsc/report.mjs +59 -0
  139. package/dist/plugs/tsc/report.mjs.map +6 -0
  140. package/dist/plugs/tsc/runner.cjs +101 -0
  141. package/dist/plugs/tsc/runner.cjs.map +6 -0
  142. package/dist/plugs/tsc/runner.mjs +72 -0
  143. package/dist/plugs/tsc/runner.mjs.map +6 -0
  144. package/dist/plugs.cjs +31 -0
  145. package/dist/plugs.cjs.map +6 -0
  146. package/dist/plugs.mjs +13 -0
  147. package/dist/plugs.mjs.map +6 -0
  148. package/dist/run.cjs +95 -0
  149. package/dist/run.cjs.map +6 -0
  150. package/dist/run.mjs +70 -0
  151. package/dist/run.mjs.map +6 -0
  152. package/dist/task.cjs +39 -0
  153. package/dist/task.cjs.map +6 -0
  154. package/dist/task.mjs +14 -0
  155. package/dist/task.mjs.map +6 -0
  156. package/dist/utils/asyncfs.cjs +143 -0
  157. package/dist/utils/asyncfs.cjs.map +6 -0
  158. package/dist/utils/asyncfs.mjs +83 -0
  159. package/dist/utils/asyncfs.mjs.map +6 -0
  160. package/dist/utils/caller.cjs +59 -0
  161. package/dist/utils/caller.cjs.map +6 -0
  162. package/dist/utils/caller.mjs +34 -0
  163. package/dist/utils/caller.mjs.map +6 -0
  164. package/dist/utils/match.cjs +69 -0
  165. package/dist/utils/match.cjs.map +6 -0
  166. package/dist/utils/match.mjs +38 -0
  167. package/dist/utils/match.mjs.map +6 -0
  168. package/dist/utils/options.cjs +41 -0
  169. package/dist/utils/options.cjs.map +6 -0
  170. package/dist/utils/options.mjs +16 -0
  171. package/dist/utils/options.mjs.map +6 -0
  172. package/dist/utils/walk.cjs +104 -0
  173. package/dist/utils/walk.cjs.map +6 -0
  174. package/dist/utils/walk.mjs +79 -0
  175. package/dist/utils/walk.mjs.map +6 -0
  176. package/extra/cli.mjs +212 -0
  177. package/extra/ts-loader.mjs +214 -0
  178. package/extra/webassembly.d.ts +11 -0
  179. package/package.json +57 -0
  180. package/src/assert.ts +47 -0
  181. package/src/async.ts +50 -0
  182. package/src/files.ts +129 -0
  183. package/src/fork.ts +263 -0
  184. package/src/helpers.ts +145 -0
  185. package/src/index.ts +20 -0
  186. package/src/log/colors.ts +119 -0
  187. package/src/log/emit.ts +125 -0
  188. package/src/log/levels.ts +65 -0
  189. package/src/log/logger.ts +171 -0
  190. package/src/log/options.ts +199 -0
  191. package/src/log/report.ts +433 -0
  192. package/src/log/spinner.ts +70 -0
  193. package/src/log.ts +68 -0
  194. package/src/paths.ts +213 -0
  195. package/src/pipe.ts +231 -0
  196. package/src/plugs/copy.ts +113 -0
  197. package/src/plugs/coverage/analysis.ts +395 -0
  198. package/src/plugs/coverage/report.ts +337 -0
  199. package/src/plugs/coverage.ts +194 -0
  200. package/src/plugs/debug.ts +35 -0
  201. package/src/plugs/esbuild/bundle-locals.ts +33 -0
  202. package/src/plugs/esbuild/check-dependencies.ts +158 -0
  203. package/src/plugs/esbuild/fix-extensions.ts +108 -0
  204. package/src/plugs/esbuild.ts +128 -0
  205. package/src/plugs/eslint/runner.ts +112 -0
  206. package/src/plugs/exec.ts +215 -0
  207. package/src/plugs/filter.ts +56 -0
  208. package/src/plugs/mocha/reporter.ts +152 -0
  209. package/src/plugs/mocha/runner.ts +77 -0
  210. package/src/plugs/tsc/compiler.ts +66 -0
  211. package/src/plugs/tsc/options.ts +97 -0
  212. package/src/plugs/tsc/report.ts +74 -0
  213. package/src/plugs/tsc/runner.ts +100 -0
  214. package/src/plugs.ts +33 -0
  215. package/src/run.ts +160 -0
  216. package/src/task.ts +26 -0
  217. package/src/utils/asyncfs.ts +82 -0
  218. package/src/utils/caller.ts +45 -0
  219. package/src/utils/match.ts +286 -0
  220. package/src/utils/options.ts +22 -0
  221. package/src/utils/walk.ts +136 -0
  222. package/types/assert.d.ts +18 -0
  223. package/types/async.d.ts +20 -0
  224. package/types/build.d.ts +56 -0
  225. package/types/files.d.ts +44 -0
  226. package/types/fork.d.ts +57 -0
  227. package/types/helpers.d.ts +49 -0
  228. package/types/index.d.ts +14 -0
  229. package/types/log/colors.d.ts +25 -0
  230. package/types/log/emit.d.ts +14 -0
  231. package/types/log/levels.d.ts +52 -0
  232. package/types/log/logger.d.ts +31 -0
  233. package/types/log/options.d.ts +40 -0
  234. package/types/log/report.d.ts +64 -0
  235. package/types/log/spinner.d.ts +2 -0
  236. package/types/log.d.ts +10 -0
  237. package/types/paths.d.ts +76 -0
  238. package/types/pipe.d.ts +152 -0
  239. package/types/plugs/copy.d.ts +27 -0
  240. package/types/plugs/coverage/analysis.d.ts +104 -0
  241. package/types/plugs/coverage/report.d.ts +53 -0
  242. package/types/plugs/coverage.d.ts +46 -0
  243. package/types/plugs/debug.d.ts +14 -0
  244. package/types/plugs/esbuild/bundle-locals.d.ts +6 -0
  245. package/types/plugs/esbuild/check-dependencies.d.ts +12 -0
  246. package/types/plugs/esbuild/fix-extensions.d.ts +29 -0
  247. package/types/plugs/esbuild.d.ts +24 -0
  248. package/types/plugs/eslint/runner.d.ts +22 -0
  249. package/types/plugs/exec.d.ts +90 -0
  250. package/types/plugs/filter.d.ts +23 -0
  251. package/types/plugs/mocha/reporter.d.ts +8 -0
  252. package/types/plugs/mocha/runner.d.ts +34 -0
  253. package/types/plugs/tsc/compiler.d.ts +24 -0
  254. package/types/plugs/tsc/options.d.ts +8 -0
  255. package/types/plugs/tsc/report.d.ts +5 -0
  256. package/types/plugs/tsc/runner.d.ts +13 -0
  257. package/types/plugs.d.ts +16 -0
  258. package/types/run.d.ts +89 -0
  259. package/types/task.d.ts +15 -0
  260. package/types/utils/asyncfs.d.ts +37 -0
  261. package/types/utils/caller.d.ts +7 -0
  262. package/types/utils/match.d.ts +216 -0
  263. package/types/utils/options.d.ts +15 -0
  264. package/types/utils/walk.d.ts +28 -0
@@ -0,0 +1,124 @@
1
+ // log/options.ts
2
+ import { EventEmitter } from "node:events";
3
+ import { getLevelNumber, NOTICE } from "./levels.mjs";
4
+ var LogOptionsImpl = class extends EventEmitter {
5
+ _output = process.stderr;
6
+ _level = NOTICE;
7
+ _colors = this._output.isTTY;
8
+ _spinner = true;
9
+ _lineLength = this._output.columns || 80;
10
+ _showSources = true;
11
+ _inspectOptions = {};
12
+ _defaultTaskName = "";
13
+ _taskLength = 0;
14
+ _indentSize = 2;
15
+ constructor() {
16
+ super();
17
+ if (process.env.LOG_LEVEL) {
18
+ this._level = getLevelNumber(process.env.LOG_LEVEL);
19
+ }
20
+ if (process.env.LOG_COLOR) {
21
+ if (process.env.LOG_COLOR.toLowerCase() === "true")
22
+ this.colors = true;
23
+ if (process.env.LOG_COLOR.toLowerCase() === "false")
24
+ this.colors = false;
25
+ }
26
+ Object.assign(this, JSON.parse(process.env.__LOG_OPTIONS || "{}"));
27
+ }
28
+ _notifyListeners() {
29
+ super.emit("changed", this);
30
+ }
31
+ fork(taskName) {
32
+ return {
33
+ level: this._level,
34
+ colors: this._colors,
35
+ lineLength: this._lineLength,
36
+ taskLength: this._taskLength,
37
+ defaultTaskName: taskName || this._defaultTaskName,
38
+ spinner: false
39
+ };
40
+ }
41
+ get output() {
42
+ return this._output;
43
+ }
44
+ set output(output) {
45
+ this._output = output;
46
+ this._colors = !!output.isTTY;
47
+ this._lineLength = output.columns;
48
+ this._notifyListeners();
49
+ }
50
+ get level() {
51
+ return this._level;
52
+ }
53
+ set level(level) {
54
+ this._level = level;
55
+ this._notifyListeners();
56
+ }
57
+ get colors() {
58
+ return this._colors;
59
+ }
60
+ set colors(color) {
61
+ this._colors = color;
62
+ this._notifyListeners();
63
+ }
64
+ get spinner() {
65
+ return this._spinner;
66
+ }
67
+ set spinner(spinner) {
68
+ this._spinner = spinner;
69
+ this._notifyListeners();
70
+ }
71
+ get lineLength() {
72
+ return this._lineLength;
73
+ }
74
+ set lineLength(lineLength) {
75
+ this._lineLength = lineLength;
76
+ this._notifyListeners();
77
+ }
78
+ get taskLength() {
79
+ return this._taskLength;
80
+ }
81
+ set taskLength(taskLength) {
82
+ this._taskLength = taskLength;
83
+ this._notifyListeners();
84
+ }
85
+ get indentSize() {
86
+ return this._indentSize;
87
+ }
88
+ set indentSize(indentSize) {
89
+ this._indentSize = indentSize;
90
+ if (this._indentSize < 1)
91
+ this._indentSize = 1;
92
+ this._notifyListeners();
93
+ }
94
+ get showSources() {
95
+ return this._showSources;
96
+ }
97
+ set showSources(showSources) {
98
+ this._showSources = showSources;
99
+ this._notifyListeners();
100
+ }
101
+ get defaultTaskName() {
102
+ return this._defaultTaskName;
103
+ }
104
+ set defaultTaskName(defaultTaskName) {
105
+ this._defaultTaskName = defaultTaskName;
106
+ this._notifyListeners();
107
+ }
108
+ get inspectOptions() {
109
+ return {
110
+ colors: this._colors,
111
+ breakLength: this._lineLength,
112
+ ...this._inspectOptions
113
+ };
114
+ }
115
+ setInspectOption(key, value) {
116
+ this._inspectOptions[key] = value;
117
+ this._notifyListeners();
118
+ }
119
+ };
120
+ var logOptions = new LogOptionsImpl();
121
+ export {
122
+ logOptions
123
+ };
124
+ //# sourceMappingURL=options.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/log/options.ts"],
4
+ "mappings": ";AAAA,SAAS,oBAAoB;AAG7B,SAAS,gBAA0C,cAAc;AA8C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A,EACxB;AACF;AAGO,IAAM,aAAyB,IAAI,eAAe;",
5
+ "names": []
6
+ }
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // log/report.ts
21
+ var report_exports = {};
22
+ __export(report_exports, {
23
+ createReport: () => createReport
24
+ });
25
+ module.exports = __toCommonJS(report_exports);
26
+ var import_assert = require("../assert.cjs");
27
+ var import_asyncfs = require("../utils/asyncfs.cjs");
28
+ var import_colors = require("./colors.cjs");
29
+ var import_emit = require("./emit.cjs");
30
+ var import_levels = require("./levels.cjs");
31
+ var import_options = require("./options.cjs");
32
+ var _colors = import_options.logOptions.colors;
33
+ import_options.logOptions.on("changed", ({ colors }) => {
34
+ _colors = colors;
35
+ });
36
+ function createReport(title, taskName) {
37
+ const emitter = _colors ? import_emit.emitColor : import_emit.emitPlain;
38
+ return new ReportImpl(title, taskName, emitter);
39
+ }
40
+ var nul = "\u2400";
41
+ var ReportImpl = class {
42
+ constructor(_title, _task, _emitter) {
43
+ this._title = _title;
44
+ this._task = _task;
45
+ this._emitter = _emitter;
46
+ }
47
+ _sources = /* @__PURE__ */ new Map();
48
+ _annotations = /* @__PURE__ */ new Map();
49
+ _records = /* @__PURE__ */ new Map();
50
+ _noticeRecords = 0;
51
+ _warningRecords = 0;
52
+ _errorRecords = 0;
53
+ _noticeAnnotations = 0;
54
+ _warningAnnotations = 0;
55
+ _errorAnnotations = 0;
56
+ get notices() {
57
+ return this._noticeRecords + this._noticeAnnotations;
58
+ }
59
+ get warnings() {
60
+ return this._warningRecords + this._warningAnnotations;
61
+ }
62
+ get errors() {
63
+ return this._errorRecords + this._errorAnnotations;
64
+ }
65
+ get noticeRecords() {
66
+ return this._noticeRecords;
67
+ }
68
+ get warningRecords() {
69
+ return this._warningRecords;
70
+ }
71
+ get errorRecords() {
72
+ return this._errorRecords;
73
+ }
74
+ get noticeAnnotations() {
75
+ return this._noticeAnnotations;
76
+ }
77
+ get warningAnnotations() {
78
+ return this._warningAnnotations;
79
+ }
80
+ get errorAnnotations() {
81
+ return this._errorAnnotations;
82
+ }
83
+ get records() {
84
+ return this._noticeRecords + this._warningRecords + this._errorRecords;
85
+ }
86
+ get annotations() {
87
+ return this._noticeAnnotations + this._warningAnnotations + this._errorAnnotations;
88
+ }
89
+ get empty() {
90
+ return !(this.records + this.annotations);
91
+ }
92
+ annotate(annotationLevel, file, note) {
93
+ if (note) {
94
+ const level = annotationLevel;
95
+ this._annotations.set(file, { level, note });
96
+ switch (level) {
97
+ case import_levels.NOTICE:
98
+ this._noticeRecords++;
99
+ break;
100
+ case import_levels.WARN:
101
+ this._warningRecords++;
102
+ break;
103
+ case import_levels.ERROR:
104
+ this._errorRecords++;
105
+ break;
106
+ }
107
+ }
108
+ return this;
109
+ }
110
+ add(...records) {
111
+ for (const record of records) {
112
+ let messages = Array.isArray(record.message) ? [...record.message.map((msg) => msg.split("\n")).flat(1)] : record.message.split("\n");
113
+ messages = messages.filter((message) => !!message);
114
+ if (!messages.length)
115
+ (0, import_assert.fail)("No message for report record");
116
+ const level = record.level;
117
+ const file = record.file;
118
+ const source = record.source || void 0;
119
+ const tags = record.tags ? Array.isArray(record.tags) ? [...record.tags] : [record.tags] : [];
120
+ switch (level) {
121
+ case import_levels.NOTICE:
122
+ this._noticeRecords++;
123
+ break;
124
+ case import_levels.WARN:
125
+ this._warningRecords++;
126
+ break;
127
+ case import_levels.ERROR:
128
+ this._errorRecords++;
129
+ break;
130
+ }
131
+ let line = 0;
132
+ let column = 0;
133
+ let length = 1;
134
+ if (file && record.line) {
135
+ line = record.line;
136
+ if (record.column) {
137
+ column = record.column;
138
+ if (record.length) {
139
+ length = record.length;
140
+ if (length < 0) {
141
+ length = Number.MAX_SAFE_INTEGER;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ if (file && source && !this._sources.has(file)) {
147
+ this._sources.set(file, source.split("\n"));
148
+ }
149
+ let reports = this._records.get(file || nul);
150
+ if (!reports)
151
+ this._records.set(file || nul, reports = /* @__PURE__ */ new Set());
152
+ reports.add({ level, messages, tags, line, column, length });
153
+ }
154
+ return this;
155
+ }
156
+ async loadSources() {
157
+ const promises = [];
158
+ for (const file of this._records.keys()) {
159
+ if (!file)
160
+ continue;
161
+ if (file === nul)
162
+ continue;
163
+ if (this._sources.has(file))
164
+ continue;
165
+ promises.push((0, import_asyncfs.readFile)(file, "utf-8").then((source) => source.split("\n")).then((lines) => this._sources.set(file, lines)));
166
+ }
167
+ await Promise.allSettled(promises);
168
+ }
169
+ done(showSources) {
170
+ if (showSources == null)
171
+ showSources = import_options.logOptions.showSources;
172
+ if (!this.empty)
173
+ this._emit(showSources);
174
+ if (this.errors)
175
+ throw (0, import_assert.failure)();
176
+ }
177
+ _emit(showSources) {
178
+ let fPad = 0;
179
+ let aPad = 0;
180
+ let mPad = 0;
181
+ let lPad = 0;
182
+ let cPad = 0;
183
+ const entries = [...this._annotations.keys(), ...this._records.keys()].filter((file, i, a) => a.indexOf(file) === i).sort((a, b) => {
184
+ return (a || "") < (b || "") ? -1 : (a || "") > (b || "") ? 1 : 0;
185
+ }).map((file) => {
186
+ const ann = file && file !== nul && this._annotations.get(file);
187
+ const records = [...this._records.get(file) || []].sort(({ line: al, column: ac }, { line: bl, column: bc }) => (al || Number.MAX_SAFE_INTEGER) - (bl || Number.MAX_SAFE_INTEGER) || (ac || Number.MAX_SAFE_INTEGER) - (bc || Number.MAX_SAFE_INTEGER)).map((record) => {
188
+ if (record.line && record.line > lPad)
189
+ lPad = record.line;
190
+ if (record.column && record.column > cPad)
191
+ cPad = record.column;
192
+ for (const message of record.messages) {
193
+ if (message.length > mPad)
194
+ mPad = message.length;
195
+ }
196
+ return record;
197
+ });
198
+ if (file && file.length > fPad)
199
+ fPad = file.length;
200
+ if (ann && ann.note.length > aPad)
201
+ aPad = ann.note.length;
202
+ return { file, records, annotation: ann };
203
+ });
204
+ mPad = mPad <= 100 ? mPad : 0;
205
+ lPad = lPad.toString().length;
206
+ cPad = cPad.toString().length;
207
+ const options = { taskName: this._task, level: import_levels.INFO };
208
+ this._emitter(options, [""]);
209
+ this._emitter(options, [(0, import_colors.$und)((0, import_colors.$wht)(this._title))]);
210
+ for (let f = 0; f < entries.length; f++) {
211
+ const { file, records, annotation } = entries[f];
212
+ const source = file && file != nul && this._sources.get(file);
213
+ if (f === 0 || entries[f - 1]?.records.length) {
214
+ this._emitter(options, [""]);
215
+ }
216
+ if (file && file !== nul && annotation) {
217
+ const { level, note } = annotation;
218
+ const $col = level === import_levels.NOTICE ? import_colors.$blu : level === import_levels.WARN ? import_colors.$ylw : import_colors.$red;
219
+ const ann = `${(0, import_colors.$gry)("[")}${$col(note.padStart(aPad))}${(0, import_colors.$gry)("]")}`;
220
+ const pad = "".padStart(fPad - file.length);
221
+ this._emitter({ ...options, level }, [(0, import_colors.$wht)((0, import_colors.$und)(file)), pad, ann]);
222
+ } else if (file !== nul) {
223
+ this._emitter(options, [(0, import_colors.$wht)((0, import_colors.$und)(file))]);
224
+ } else if (f > 0) {
225
+ this._emitter(options, [""]);
226
+ }
227
+ for (let r = 0; r < records.length; r++) {
228
+ const { level, messages, tags, line, column, length = 1 } = records[r];
229
+ let pfx;
230
+ if (file && line) {
231
+ if (column) {
232
+ pfx = ` ${line.toString().padStart(lPad)}:${column.toString().padEnd(cPad)} `;
233
+ } else {
234
+ pfx = ` ${line.toString().padStart(lPad)}:${"-".padEnd(cPad)} `;
235
+ }
236
+ } else if (file != nul) {
237
+ pfx = ` ${"-".padStart(lPad)}:${"-".padEnd(cPad)} `;
238
+ } else {
239
+ pfx = " ~ ";
240
+ }
241
+ const prefix = "".padStart(pfx.length + 1);
242
+ const tag = tags.length == 0 ? "" : `${(0, import_colors.$gry)("[")}${tags.map((tag2) => (0, import_colors.$cyn)(tag2)).join((0, import_colors.$gry)("|"))}${(0, import_colors.$gry)("]")}`;
243
+ if (messages.length === 1) {
244
+ this._emitter({ ...options, level }, [(0, import_colors.$gry)(pfx), messages[0].padEnd(mPad), tag]);
245
+ } else {
246
+ for (let m = 0; m < messages.length; m++) {
247
+ if (!m) {
248
+ this._emitter({ ...options, level }, [(0, import_colors.$gry)(pfx), messages[m]]);
249
+ } else if (m === messages.length - 1) {
250
+ this._emitter({ ...options, level, prefix }, [messages[m].padEnd(mPad), tag]);
251
+ } else {
252
+ this._emitter({ ...options, level, prefix }, [messages[m]]);
253
+ }
254
+ }
255
+ }
256
+ if (showSources && source && source[line - 1]) {
257
+ if (column) {
258
+ const $col = level === import_levels.NOTICE ? import_colors.$blu : level === import_levels.WARN ? import_colors.$ylw : import_colors.$red;
259
+ const offset = column - 1;
260
+ const head = (0, import_colors.$gry)(source[line - 1].substring(0, offset));
261
+ const body = (0, import_colors.$und)($col(source[line - 1].substring(offset, offset + length)));
262
+ const tail = (0, import_colors.$gry)(source[line - 1].substring(offset + length));
263
+ this._emitter({ ...options, level, prefix }, [(0, import_colors.$gry)(`| ${head}${body}${tail}`)]);
264
+ } else {
265
+ this._emitter({ ...options, level, prefix }, [(0, import_colors.$gry)(`| ${source[line - 1]}`)]);
266
+ }
267
+ }
268
+ }
269
+ }
270
+ const eLabel = this.errors === 1 ? "error" : "errors";
271
+ const wLabel = this.warnings === 1 ? "warning" : "warnings";
272
+ const eNumber = this.errors ? (0, import_colors.$red)(this.errors) : "no";
273
+ const wNumber = this.warnings ? (0, import_colors.$ylw)(this.warnings) : "no";
274
+ this._emitter(options, [""]);
275
+ this._emitter(options, ["Found", eNumber, eLabel, "and", wNumber, wLabel]);
276
+ this._emitter(options, [""]);
277
+ return this;
278
+ }
279
+ };
280
+ // Annotate the CommonJS export names for ESM import in node:
281
+ 0 && (module.exports = {
282
+ createReport
283
+ });
284
+ //# sourceMappingURL=report.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/log/report.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8B;AAE9B,qBAAyB;AACzB,oBAAyD;AACzD,kBAAiD;AACjD,oBAAqD;AACrD,qBAA2B;AAK3B,IAAI,UAAU,0BAAW;AACzB,0BAAW,GAAG,WAAW,CAAC,EAAE,OAAO,MAAM;AACvC,YAAU;AACZ,CAAC;AAgFM,SAAS,aAAa,OAAe,UAA0B;AACpE,QAAM,UAAU,UAAU,wBAAY;AACtC,SAAO,IAAI,WAAW,OAAO,UAAU,OAAO;AAChD;AAMA,IAAM,MAAM;AAiBZ,IAAM,aAAN,MAAmC;AAAA,EAWjC,YACqB,QACA,OACA,UACnB;AAHmB;AACA;AACA;AAAA,EAClB;AAAA,EAdc,WAAW,oBAAI,IAA4B;AAAA,EAC3C,eAAe,oBAAI,IAA4C;AAAA,EAC/D,WAAW,oBAAI,IAAoD;AAAA,EAC5E,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,oBAAoB;AAAA,EAQ5B,IAAI,UAAkB;AACpB,WAAO,KAAK,iBAAiB,KAAK;AAAA,EACpC;AAAA,EAEA,IAAI,WAAmB;AACrB,WAAO,KAAK,kBAAkB,KAAK;AAAA,EACrC;AAAA,EAEA,IAAI,SAAiB;AACnB,WAAO,KAAK,g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0 +1,259 @@
1
+ // log/report.ts
2
+ import { fail, failure } from "../assert.mjs";
3
+ import { readFile } from "../utils/asyncfs.mjs";
4
+ import { $blu, $cyn, $gry, $red, $und, $wht, $ylw } from "./colors.mjs";
5
+ import { emitColor, emitPlain } from "./emit.mjs";
6
+ import { ERROR, INFO, NOTICE, WARN } from "./levels.mjs";
7
+ import { logOptions } from "./options.mjs";
8
+ var _colors = logOptions.colors;
9
+ logOptions.on("changed", ({ colors }) => {
10
+ _colors = colors;
11
+ });
12
+ function createReport(title, taskName) {
13
+ const emitter = _colors ? emitColor : emitPlain;
14
+ return new ReportImpl(title, taskName, emitter);
15
+ }
16
+ var nul = "\u2400";
17
+ var ReportImpl = class {
18
+ constructor(_title, _task, _emitter) {
19
+ this._title = _title;
20
+ this._task = _task;
21
+ this._emitter = _emitter;
22
+ }
23
+ _sources = /* @__PURE__ */ new Map();
24
+ _annotations = /* @__PURE__ */ new Map();
25
+ _records = /* @__PURE__ */ new Map();
26
+ _noticeRecords = 0;
27
+ _warningRecords = 0;
28
+ _errorRecords = 0;
29
+ _noticeAnnotations = 0;
30
+ _warningAnnotations = 0;
31
+ _errorAnnotations = 0;
32
+ get notices() {
33
+ return this._noticeRecords + this._noticeAnnotations;
34
+ }
35
+ get warnings() {
36
+ return this._warningRecords + this._warningAnnotations;
37
+ }
38
+ get errors() {
39
+ return this._errorRecords + this._errorAnnotations;
40
+ }
41
+ get noticeRecords() {
42
+ return this._noticeRecords;
43
+ }
44
+ get warningRecords() {
45
+ return this._warningRecords;
46
+ }
47
+ get errorRecords() {
48
+ return this._errorRecords;
49
+ }
50
+ get noticeAnnotations() {
51
+ return this._noticeAnnotations;
52
+ }
53
+ get warningAnnotations() {
54
+ return this._warningAnnotations;
55
+ }
56
+ get errorAnnotations() {
57
+ return this._errorAnnotations;
58
+ }
59
+ get records() {
60
+ return this._noticeRecords + this._warningRecords + this._errorRecords;
61
+ }
62
+ get annotations() {
63
+ return this._noticeAnnotations + this._warningAnnotations + this._errorAnnotations;
64
+ }
65
+ get empty() {
66
+ return !(this.records + this.annotations);
67
+ }
68
+ annotate(annotationLevel, file, note) {
69
+ if (note) {
70
+ const level = annotationLevel;
71
+ this._annotations.set(file, { level, note });
72
+ switch (level) {
73
+ case NOTICE:
74
+ this._noticeRecords++;
75
+ break;
76
+ case WARN:
77
+ this._warningRecords++;
78
+ break;
79
+ case ERROR:
80
+ this._errorRecords++;
81
+ break;
82
+ }
83
+ }
84
+ return this;
85
+ }
86
+ add(...records) {
87
+ for (const record of records) {
88
+ let messages = Array.isArray(record.message) ? [...record.message.map((msg) => msg.split("\n")).flat(1)] : record.message.split("\n");
89
+ messages = messages.filter((message) => !!message);
90
+ if (!messages.length)
91
+ fail("No message for report record");
92
+ const level = record.level;
93
+ const file = record.file;
94
+ const source = record.source || void 0;
95
+ const tags = record.tags ? Array.isArray(record.tags) ? [...record.tags] : [record.tags] : [];
96
+ switch (level) {
97
+ case NOTICE:
98
+ this._noticeRecords++;
99
+ break;
100
+ case WARN:
101
+ this._warningRecords++;
102
+ break;
103
+ case ERROR:
104
+ this._errorRecords++;
105
+ break;
106
+ }
107
+ let line = 0;
108
+ let column = 0;
109
+ let length = 1;
110
+ if (file && record.line) {
111
+ line = record.line;
112
+ if (record.column) {
113
+ column = record.column;
114
+ if (record.length) {
115
+ length = record.length;
116
+ if (length < 0) {
117
+ length = Number.MAX_SAFE_INTEGER;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ if (file && source && !this._sources.has(file)) {
123
+ this._sources.set(file, source.split("\n"));
124
+ }
125
+ let reports = this._records.get(file || nul);
126
+ if (!reports)
127
+ this._records.set(file || nul, reports = /* @__PURE__ */ new Set());
128
+ reports.add({ level, messages, tags, line, column, length });
129
+ }
130
+ return this;
131
+ }
132
+ async loadSources() {
133
+ const promises = [];
134
+ for (const file of this._records.keys()) {
135
+ if (!file)
136
+ continue;
137
+ if (file === nul)
138
+ continue;
139
+ if (this._sources.has(file))
140
+ continue;
141
+ promises.push(readFile(file, "utf-8").then((source) => source.split("\n")).then((lines) => this._sources.set(file, lines)));
142
+ }
143
+ await Promise.allSettled(promises);
144
+ }
145
+ done(showSources) {
146
+ if (showSources == null)
147
+ showSources = logOptions.showSources;
148
+ if (!this.empty)
149
+ this._emit(showSources);
150
+ if (this.errors)
151
+ throw failure();
152
+ }
153
+ _emit(showSources) {
154
+ let fPad = 0;
155
+ let aPad = 0;
156
+ let mPad = 0;
157
+ let lPad = 0;
158
+ let cPad = 0;
159
+ const entries = [...this._annotations.keys(), ...this._records.keys()].filter((file, i, a) => a.indexOf(file) === i).sort((a, b) => {
160
+ return (a || "") < (b || "") ? -1 : (a || "") > (b || "") ? 1 : 0;
161
+ }).map((file) => {
162
+ const ann = file && file !== nul && this._annotations.get(file);
163
+ const records = [...this._records.get(file) || []].sort(({ line: al, column: ac }, { line: bl, column: bc }) => (al || Number.MAX_SAFE_INTEGER) - (bl || Number.MAX_SAFE_INTEGER) || (ac || Number.MAX_SAFE_INTEGER) - (bc || Number.MAX_SAFE_INTEGER)).map((record) => {
164
+ if (record.line && record.line > lPad)
165
+ lPad = record.line;
166
+ if (record.column && record.column > cPad)
167
+ cPad = record.column;
168
+ for (const message of record.messages) {
169
+ if (message.length > mPad)
170
+ mPad = message.length;
171
+ }
172
+ return record;
173
+ });
174
+ if (file && file.length > fPad)
175
+ fPad = file.length;
176
+ if (ann && ann.note.length > aPad)
177
+ aPad = ann.note.length;
178
+ return { file, records, annotation: ann };
179
+ });
180
+ mPad = mPad <= 100 ? mPad : 0;
181
+ lPad = lPad.toString().length;
182
+ cPad = cPad.toString().length;
183
+ const options = { taskName: this._task, level: INFO };
184
+ this._emitter(options, [""]);
185
+ this._emitter(options, [$und($wht(this._title))]);
186
+ for (let f = 0; f < entries.length; f++) {
187
+ const { file, records, annotation } = entries[f];
188
+ const source = file && file != nul && this._sources.get(file);
189
+ if (f === 0 || entries[f - 1]?.records.length) {
190
+ this._emitter(options, [""]);
191
+ }
192
+ if (file && file !== nul && annotation) {
193
+ const { level, note } = annotation;
194
+ const $col = level === NOTICE ? $blu : level === WARN ? $ylw : $red;
195
+ const ann = `${$gry("[")}${$col(note.padStart(aPad))}${$gry("]")}`;
196
+ const pad = "".padStart(fPad - file.length);
197
+ this._emitter({ ...options, level }, [$wht($und(file)), pad, ann]);
198
+ } else if (file !== nul) {
199
+ this._emitter(options, [$wht($und(file))]);
200
+ } else if (f > 0) {
201
+ this._emitter(options, [""]);
202
+ }
203
+ for (let r = 0; r < records.length; r++) {
204
+ const { level, messages, tags, line, column, length = 1 } = records[r];
205
+ let pfx;
206
+ if (file && line) {
207
+ if (column) {
208
+ pfx = ` ${line.toString().padStart(lPad)}:${column.toString().padEnd(cPad)} `;
209
+ } else {
210
+ pfx = ` ${line.toString().padStart(lPad)}:${"-".padEnd(cPad)} `;
211
+ }
212
+ } else if (file != nul) {
213
+ pfx = ` ${"-".padStart(lPad)}:${"-".padEnd(cPad)} `;
214
+ } else {
215
+ pfx = " ~ ";
216
+ }
217
+ const prefix = "".padStart(pfx.length + 1);
218
+ const tag = tags.length == 0 ? "" : `${$gry("[")}${tags.map((tag2) => $cyn(tag2)).join($gry("|"))}${$gry("]")}`;
219
+ if (messages.length === 1) {
220
+ this._emitter({ ...options, level }, [$gry(pfx), messages[0].padEnd(mPad), tag]);
221
+ } else {
222
+ for (let m = 0; m < messages.length; m++) {
223
+ if (!m) {
224
+ this._emitter({ ...options, level }, [$gry(pfx), messages[m]]);
225
+ } else if (m === messages.length - 1) {
226
+ this._emitter({ ...options, level, prefix }, [messages[m].padEnd(mPad), tag]);
227
+ } else {
228
+ this._emitter({ ...options, level, prefix }, [messages[m]]);
229
+ }
230
+ }
231
+ }
232
+ if (showSources && source && source[line - 1]) {
233
+ if (column) {
234
+ const $col = level === NOTICE ? $blu : level === WARN ? $ylw : $red;
235
+ const offset = column - 1;
236
+ const head = $gry(source[line - 1].substring(0, offset));
237
+ const body = $und($col(source[line - 1].substring(offset, offset + length)));
238
+ const tail = $gry(source[line - 1].substring(offset + length));
239
+ this._emitter({ ...options, level, prefix }, [$gry(`| ${head}${body}${tail}`)]);
240
+ } else {
241
+ this._emitter({ ...options, level, prefix }, [$gry(`| ${source[line - 1]}`)]);
242
+ }
243
+ }
244
+ }
245
+ }
246
+ const eLabel = this.errors === 1 ? "error" : "errors";
247
+ const wLabel = this.warnings === 1 ? "warning" : "warnings";
248
+ const eNumber = this.errors ? $red(this.errors) : "no";
249
+ const wNumber = this.warnings ? $ylw(this.warnings) : "no";
250
+ this._emitter(options, [""]);
251
+ this._emitter(options, ["Found", eNumber, eLabel, "and", wNumber, wLabel]);
252
+ this._emitter(options, [""]);
253
+ return this;
254
+ }
255
+ };
256
+ export {
257
+ createReport
258
+ };
259
+ //# sourceMappingURL=report.mjs.map