@matter/tools 0.12.2 → 0.12.3-alpha.0-20250203-34ba45cae

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 (225) hide show
  1. package/dist/cjs/ansi-text/chars.d.ts +11 -0
  2. package/dist/cjs/ansi-text/chars.d.ts.map +1 -0
  3. package/dist/cjs/ansi-text/chars.js +57 -0
  4. package/dist/cjs/ansi-text/chars.js.map +6 -0
  5. package/dist/cjs/ansi-text/consumer.d.ts +45 -0
  6. package/dist/cjs/ansi-text/consumer.d.ts.map +1 -0
  7. package/dist/cjs/ansi-text/consumer.js +22 -0
  8. package/dist/cjs/ansi-text/consumer.js.map +6 -0
  9. package/dist/cjs/ansi-text/contiguous-output-segment.d.ts +31 -0
  10. package/dist/cjs/ansi-text/contiguous-output-segment.d.ts.map +1 -0
  11. package/dist/cjs/ansi-text/contiguous-output-segment.js +156 -0
  12. package/dist/cjs/ansi-text/contiguous-output-segment.js.map +6 -0
  13. package/dist/cjs/ansi-text/index.d.ts +12 -0
  14. package/dist/cjs/ansi-text/index.d.ts.map +1 -0
  15. package/dist/cjs/ansi-text/index.js +29 -0
  16. package/dist/cjs/ansi-text/index.js.map +6 -0
  17. package/dist/cjs/ansi-text/printer.d.ts +24 -0
  18. package/dist/cjs/ansi-text/printer.d.ts.map +1 -0
  19. package/dist/cjs/ansi-text/printer.js +81 -0
  20. package/dist/cjs/ansi-text/printer.js.map +6 -0
  21. package/dist/cjs/ansi-text/producer.d.ts +17 -0
  22. package/dist/cjs/ansi-text/producer.d.ts.map +1 -0
  23. package/dist/cjs/ansi-text/producer.js +45 -0
  24. package/dist/cjs/ansi-text/producer.js.map +6 -0
  25. package/dist/cjs/ansi-text/screen.d.ts +13 -0
  26. package/dist/cjs/ansi-text/screen.d.ts.map +1 -0
  27. package/dist/cjs/ansi-text/screen.js +38 -0
  28. package/dist/cjs/ansi-text/screen.js.map +6 -0
  29. package/dist/cjs/ansi-text/sgr.d.ts +100 -0
  30. package/dist/cjs/ansi-text/sgr.d.ts.map +1 -0
  31. package/dist/cjs/ansi-text/sgr.js +140 -0
  32. package/dist/cjs/ansi-text/sgr.js.map +6 -0
  33. package/dist/cjs/ansi-text/std.d.ts +17 -0
  34. package/dist/cjs/ansi-text/std.d.ts.map +1 -0
  35. package/dist/cjs/ansi-text/std.js +43 -0
  36. package/dist/cjs/ansi-text/std.js.map +6 -0
  37. package/dist/cjs/ansi-text/style.d.ts +88 -0
  38. package/dist/cjs/ansi-text/style.d.ts.map +1 -0
  39. package/dist/cjs/ansi-text/style.js +257 -0
  40. package/dist/cjs/ansi-text/style.js.map +6 -0
  41. package/dist/cjs/ansi-text/text-builder.d.ts +78 -0
  42. package/dist/cjs/ansi-text/text-builder.d.ts.map +1 -0
  43. package/dist/cjs/ansi-text/text-builder.js +164 -0
  44. package/dist/cjs/ansi-text/text-builder.js.map +6 -0
  45. package/dist/cjs/ansi-text/text-writer.d.ts +30 -0
  46. package/dist/cjs/ansi-text/text-writer.d.ts.map +1 -0
  47. package/dist/cjs/ansi-text/text-writer.js +317 -0
  48. package/dist/cjs/ansi-text/text-writer.js.map +6 -0
  49. package/dist/cjs/ansi-text/token.d.ts +61 -0
  50. package/dist/cjs/ansi-text/token.d.ts.map +1 -0
  51. package/dist/cjs/ansi-text/token.js +22 -0
  52. package/dist/cjs/ansi-text/token.js.map +6 -0
  53. package/dist/cjs/ansi-text/tokenize.d.ts +11 -0
  54. package/dist/cjs/ansi-text/tokenize.d.ts.map +1 -0
  55. package/dist/cjs/ansi-text/tokenize.js +190 -0
  56. package/dist/cjs/ansi-text/tokenize.js.map +6 -0
  57. package/dist/cjs/ansi-text/truncator.d.ts +20 -0
  58. package/dist/cjs/ansi-text/truncator.d.ts.map +1 -0
  59. package/dist/cjs/ansi-text/truncator.js +72 -0
  60. package/dist/cjs/ansi-text/truncator.js.map +6 -0
  61. package/dist/cjs/ansi-text/visible-width-of.d.ts +10 -0
  62. package/dist/cjs/ansi-text/visible-width-of.d.ts.map +1 -0
  63. package/dist/cjs/ansi-text/visible-width-of.js +55 -0
  64. package/dist/cjs/ansi-text/visible-width-of.js.map +6 -0
  65. package/dist/cjs/ansi-text/wrapper.d.ts +34 -0
  66. package/dist/cjs/ansi-text/wrapper.d.ts.map +1 -0
  67. package/dist/cjs/ansi-text/wrapper.js +208 -0
  68. package/dist/cjs/ansi-text/wrapper.js.map +6 -0
  69. package/dist/cjs/building/cli.js +6 -6
  70. package/dist/cjs/building/cli.js.map +1 -1
  71. package/dist/cjs/building/graph.d.ts +2 -2
  72. package/dist/cjs/building/graph.d.ts.map +1 -1
  73. package/dist/cjs/building/graph.js.map +1 -1
  74. package/dist/cjs/building/project-builder.d.ts +38 -0
  75. package/dist/cjs/building/project-builder.d.ts.map +1 -0
  76. package/dist/cjs/building/project-builder.js +200 -0
  77. package/dist/cjs/building/project-builder.js.map +6 -0
  78. package/dist/cjs/building/tsconfig.js +1 -1
  79. package/dist/cjs/building/tsconfig.js.map +1 -1
  80. package/dist/cjs/index.d.ts +4 -6
  81. package/dist/cjs/index.d.ts.map +1 -1
  82. package/dist/cjs/index.js +4 -6
  83. package/dist/cjs/index.js.map +1 -1
  84. package/dist/cjs/running/ensure-compiled.js +2 -2
  85. package/dist/cjs/running/ensure-compiled.js.map +1 -1
  86. package/dist/cjs/util/commander.d.ts.map +1 -1
  87. package/dist/cjs/util/commander.js +4 -5
  88. package/dist/cjs/util/commander.js.map +2 -2
  89. package/dist/cjs/util/index.d.ts +1 -0
  90. package/dist/cjs/util/index.d.ts.map +1 -1
  91. package/dist/cjs/util/index.js +1 -0
  92. package/dist/cjs/util/index.js.map +1 -1
  93. package/dist/cjs/util/progress.d.ts +2 -2
  94. package/dist/cjs/util/progress.d.ts.map +1 -1
  95. package/dist/cjs/util/progress.js +25 -53
  96. package/dist/cjs/util/progress.js.map +2 -2
  97. package/dist/cjs/versioning/versioner.js +2 -12
  98. package/dist/cjs/versioning/versioner.js.map +2 -2
  99. package/dist/esm/ansi-text/chars.d.ts +11 -0
  100. package/dist/esm/ansi-text/chars.d.ts.map +1 -0
  101. package/dist/esm/ansi-text/chars.js +37 -0
  102. package/dist/esm/ansi-text/chars.js.map +6 -0
  103. package/dist/esm/ansi-text/consumer.d.ts +45 -0
  104. package/dist/esm/ansi-text/consumer.d.ts.map +1 -0
  105. package/dist/esm/ansi-text/consumer.js +6 -0
  106. package/dist/esm/ansi-text/consumer.js.map +6 -0
  107. package/dist/esm/ansi-text/contiguous-output-segment.d.ts +31 -0
  108. package/dist/esm/ansi-text/contiguous-output-segment.d.ts.map +1 -0
  109. package/dist/esm/ansi-text/contiguous-output-segment.js +136 -0
  110. package/dist/esm/ansi-text/contiguous-output-segment.js.map +6 -0
  111. package/dist/esm/ansi-text/index.d.ts +12 -0
  112. package/dist/esm/ansi-text/index.d.ts.map +1 -0
  113. package/dist/esm/ansi-text/index.js +12 -0
  114. package/dist/esm/ansi-text/index.js.map +6 -0
  115. package/dist/esm/ansi-text/printer.d.ts +24 -0
  116. package/dist/esm/ansi-text/printer.d.ts.map +1 -0
  117. package/dist/esm/ansi-text/printer.js +61 -0
  118. package/dist/esm/ansi-text/printer.js.map +6 -0
  119. package/dist/esm/ansi-text/producer.d.ts +17 -0
  120. package/dist/esm/ansi-text/producer.d.ts.map +1 -0
  121. package/dist/esm/ansi-text/producer.js +25 -0
  122. package/dist/esm/ansi-text/producer.js.map +6 -0
  123. package/dist/esm/ansi-text/screen.d.ts +13 -0
  124. package/dist/esm/ansi-text/screen.d.ts.map +1 -0
  125. package/dist/esm/ansi-text/screen.js +18 -0
  126. package/dist/esm/ansi-text/screen.js.map +6 -0
  127. package/dist/esm/ansi-text/sgr.d.ts +100 -0
  128. package/dist/esm/ansi-text/sgr.d.ts.map +1 -0
  129. package/dist/esm/ansi-text/sgr.js +120 -0
  130. package/dist/esm/ansi-text/sgr.js.map +6 -0
  131. package/dist/esm/ansi-text/std.d.ts +17 -0
  132. package/dist/esm/ansi-text/std.d.ts.map +1 -0
  133. package/dist/esm/ansi-text/std.js +23 -0
  134. package/dist/esm/ansi-text/std.js.map +6 -0
  135. package/dist/esm/ansi-text/style.d.ts +88 -0
  136. package/dist/esm/ansi-text/style.d.ts.map +1 -0
  137. package/dist/esm/ansi-text/style.js +245 -0
  138. package/dist/esm/ansi-text/style.js.map +6 -0
  139. package/dist/esm/ansi-text/text-builder.d.ts +78 -0
  140. package/dist/esm/ansi-text/text-builder.d.ts.map +1 -0
  141. package/dist/esm/ansi-text/text-builder.js +150 -0
  142. package/dist/esm/ansi-text/text-builder.js.map +6 -0
  143. package/dist/esm/ansi-text/text-writer.d.ts +30 -0
  144. package/dist/esm/ansi-text/text-writer.d.ts.map +1 -0
  145. package/dist/esm/ansi-text/text-writer.js +297 -0
  146. package/dist/esm/ansi-text/text-writer.js.map +6 -0
  147. package/dist/esm/ansi-text/token.d.ts +61 -0
  148. package/dist/esm/ansi-text/token.d.ts.map +1 -0
  149. package/dist/esm/ansi-text/token.js +6 -0
  150. package/dist/esm/ansi-text/token.js.map +6 -0
  151. package/dist/esm/ansi-text/tokenize.d.ts +11 -0
  152. package/dist/esm/ansi-text/tokenize.d.ts.map +1 -0
  153. package/dist/esm/ansi-text/tokenize.js +170 -0
  154. package/dist/esm/ansi-text/tokenize.js.map +6 -0
  155. package/dist/esm/ansi-text/truncator.d.ts +20 -0
  156. package/dist/esm/ansi-text/truncator.d.ts.map +1 -0
  157. package/dist/esm/ansi-text/truncator.js +52 -0
  158. package/dist/esm/ansi-text/truncator.js.map +6 -0
  159. package/dist/esm/ansi-text/visible-width-of.d.ts +10 -0
  160. package/dist/esm/ansi-text/visible-width-of.d.ts.map +1 -0
  161. package/dist/esm/ansi-text/visible-width-of.js +35 -0
  162. package/dist/esm/ansi-text/visible-width-of.js.map +6 -0
  163. package/dist/esm/ansi-text/wrapper.d.ts +34 -0
  164. package/dist/esm/ansi-text/wrapper.d.ts.map +1 -0
  165. package/dist/esm/ansi-text/wrapper.js +188 -0
  166. package/dist/esm/ansi-text/wrapper.js.map +6 -0
  167. package/dist/esm/building/cli.js +3 -3
  168. package/dist/esm/building/cli.js.map +1 -1
  169. package/dist/esm/building/graph.d.ts +2 -2
  170. package/dist/esm/building/graph.d.ts.map +1 -1
  171. package/dist/esm/building/graph.js +1 -1
  172. package/dist/esm/building/graph.js.map +1 -1
  173. package/dist/esm/building/project-builder.d.ts +38 -0
  174. package/dist/esm/building/project-builder.d.ts.map +1 -0
  175. package/dist/esm/building/project-builder.js +180 -0
  176. package/dist/esm/building/project-builder.js.map +6 -0
  177. package/dist/esm/building/tsconfig.js +2 -2
  178. package/dist/esm/building/tsconfig.js.map +1 -1
  179. package/dist/esm/index.d.ts +4 -6
  180. package/dist/esm/index.d.ts.map +1 -1
  181. package/dist/esm/index.js +5 -7
  182. package/dist/esm/index.js.map +1 -1
  183. package/dist/esm/running/ensure-compiled.js +3 -3
  184. package/dist/esm/running/ensure-compiled.js.map +1 -1
  185. package/dist/esm/util/commander.d.ts.map +1 -1
  186. package/dist/esm/util/commander.js +5 -6
  187. package/dist/esm/util/commander.js.map +1 -1
  188. package/dist/esm/util/index.d.ts +1 -0
  189. package/dist/esm/util/index.d.ts.map +1 -1
  190. package/dist/esm/util/index.js +2 -1
  191. package/dist/esm/util/index.js.map +1 -1
  192. package/dist/esm/util/progress.d.ts +2 -2
  193. package/dist/esm/util/progress.d.ts.map +1 -1
  194. package/dist/esm/util/progress.js +26 -44
  195. package/dist/esm/util/progress.js.map +1 -1
  196. package/dist/esm/versioning/versioner.js +3 -3
  197. package/dist/esm/versioning/versioner.js.map +1 -1
  198. package/package.json +11 -1
  199. package/src/ansi-text/chars.ts +31 -0
  200. package/src/ansi-text/consumer.ts +53 -0
  201. package/src/ansi-text/contiguous-output-segment.ts +181 -0
  202. package/src/ansi-text/index.ts +14 -0
  203. package/src/ansi-text/printer.ts +86 -0
  204. package/src/ansi-text/producer.ts +29 -0
  205. package/src/ansi-text/screen.ts +18 -0
  206. package/src/ansi-text/sgr.ts +154 -0
  207. package/src/ansi-text/std.ts +28 -0
  208. package/src/ansi-text/style.ts +369 -0
  209. package/src/ansi-text/text-builder.ts +261 -0
  210. package/src/ansi-text/text-writer.ts +363 -0
  211. package/src/ansi-text/token.ts +76 -0
  212. package/src/ansi-text/tokenize.ts +212 -0
  213. package/src/ansi-text/truncator.ts +63 -0
  214. package/src/ansi-text/visible-width-of.ts +39 -0
  215. package/src/ansi-text/wrapper.ts +244 -0
  216. package/src/building/cli.ts +2 -2
  217. package/src/building/graph.ts +2 -2
  218. package/src/building/project-builder.ts +230 -0
  219. package/src/building/tsconfig.ts +2 -4
  220. package/src/index.ts +4 -6
  221. package/src/running/ensure-compiled.ts +2 -2
  222. package/src/util/commander.ts +4 -6
  223. package/src/util/index.ts +1 -0
  224. package/src/util/progress.ts +24 -61
  225. package/src/versioning/versioner.ts +2 -2
@@ -0,0 +1,230 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { createHash } from "crypto";
8
+ import { Progress } from "../util/progress.js";
9
+ import { BuildError } from "./error.js";
10
+ import { Graph } from "./graph.js";
11
+ import { BuildInformation, Project } from "./project.js";
12
+ import { createTypescriptContext } from "./typescript.js";
13
+ import { TypescriptContext } from "./typescript/context.js";
14
+
15
+ export enum Target {
16
+ clean = "clean",
17
+ types = "types",
18
+ esm = "esm",
19
+ cjs = "cjs",
20
+ }
21
+
22
+ export interface Options {
23
+ targets?: Target[];
24
+ clean?: boolean;
25
+ graph?: Graph;
26
+ }
27
+
28
+ /**
29
+ * High-level build coordination.
30
+ *
31
+ * Warning: This class is intended for command line use and will process.exit if things go wrong.
32
+ */
33
+ export class ProjectBuilder {
34
+ unconditional: boolean;
35
+ tsContext?: TypescriptContext;
36
+ graph?: Graph;
37
+
38
+ constructor(private options: Options = {}) {
39
+ this.graph = options.graph;
40
+ this.unconditional =
41
+ options.clean || (options.targets !== undefined && options.targets?.indexOf(Target.clean) !== -1);
42
+ }
43
+
44
+ get hasClean() {
45
+ return this.options.clean;
46
+ }
47
+
48
+ clearClean() {
49
+ delete this.options.clean;
50
+ }
51
+
52
+ hasTargets() {
53
+ return this.options.targets && this.options.targets.length > 0;
54
+ }
55
+
56
+ public async configure(project: Project) {
57
+ if (!project.pkg.hasConfig) {
58
+ return;
59
+ }
60
+
61
+ await project.configure();
62
+ }
63
+
64
+ public async build(project: Project) {
65
+ const progress = project.pkg.start("Building");
66
+
67
+ try {
68
+ await this.#doBuild(project, progress);
69
+ } catch (e: any) {
70
+ progress.shutdown();
71
+ process.stderr.write(`${e.stack ?? e.message}\n\n`);
72
+ process.exit(1);
73
+ }
74
+
75
+ progress.shutdown();
76
+ }
77
+
78
+ async #doBuild(project: Project, progress: Progress) {
79
+ const targets = this.#selectTargets(project);
80
+
81
+ if (targets.has(Target.clean) || this.options.clean) {
82
+ await progress.run("Clean", () => project.clean());
83
+ }
84
+
85
+ if (!targets.has(Target.types) && !targets.has(Target.esm) && !targets.has(Target.cjs)) {
86
+ return;
87
+ }
88
+
89
+ const info: BuildInformation = {};
90
+
91
+ const config = await project.configure();
92
+
93
+ await config?.before?.({ project });
94
+
95
+ // If available we use graph to access dependency API shas
96
+ const graph = this.graph ?? (await Graph.forProject(project.pkg.path));
97
+ let node: Graph.Node | undefined;
98
+ if (graph) {
99
+ node = graph.get(project.pkg.name);
100
+ for (const dep of node.dependencies) {
101
+ if (dep.info.apiSha !== undefined) {
102
+ if (info.dependencyApiShas === undefined) {
103
+ info.dependencyApiShas = {};
104
+ }
105
+ info.dependencyApiShas[dep.pkg.name] = dep.info.apiSha;
106
+ }
107
+ }
108
+ }
109
+
110
+ if (targets.has(Target.types)) {
111
+ try {
112
+ // Obtain or initialize typescript solution builder
113
+ let context = this.tsContext;
114
+ if (context === undefined) {
115
+ context = this.tsContext = await createTypescriptContext(project.pkg.workspace, graph);
116
+ }
117
+
118
+ const refreshCallback = progress.refresh.bind(progress);
119
+
120
+ if (project.pkg.isLibrary) {
121
+ const apiSha = createHash("sha1");
122
+
123
+ // Our API SHA changes if that of any dependency changes
124
+ if (node) {
125
+ for (const dep of node.dependencies) {
126
+ if (dep.info.apiSha !== undefined) {
127
+ apiSha.update(dep.info.apiSha);
128
+ }
129
+ }
130
+ }
131
+
132
+ await progress.run(`Generate ${progress.emphasize("type declarations")}`, async () => {
133
+ await context.build(project.pkg, "src", refreshCallback);
134
+ await project.hashDeclarations(apiSha);
135
+ });
136
+
137
+ // Work-in-progress alternative doc generation implementation
138
+ // await progress.run(`Extract ${progress.emphasize("api docs")}`, () =>
139
+ // emitApiDoc(project.pkg, program, progress),
140
+ // );
141
+
142
+ info.apiSha = apiSha.digest("hex");
143
+ } else {
144
+ await progress.run(`Validate ${progress.emphasize("types")}`, () =>
145
+ context.build(project.pkg, "src", refreshCallback, false),
146
+ );
147
+ }
148
+ if (project.pkg.hasTests) {
149
+ await progress.run(`Validate ${progress.emphasize("test types")}`, () =>
150
+ context.build(project.pkg, "test", refreshCallback),
151
+ );
152
+ }
153
+ } catch (e) {
154
+ if (e instanceof BuildError) {
155
+ progress.failure("Terminating due to type errors");
156
+ process.stderr.write(`${e.diagnostics}\n`);
157
+ process.exit(1);
158
+ }
159
+ throw e;
160
+ }
161
+ }
162
+
163
+ const formats = Array<"esm" | "cjs">();
164
+ if (targets.has(Target.esm)) {
165
+ formats.push("esm");
166
+ }
167
+ if (targets.has(Target.cjs)) {
168
+ formats.push("cjs");
169
+ }
170
+
171
+ if (formats.length) {
172
+ const groups = [project.pkg.isLibrary ? "library" : "app"];
173
+ if (project.pkg.hasTests) {
174
+ groups.push("tests");
175
+ }
176
+
177
+ const formatDesc = formats.map(progress.emphasize).join("+");
178
+ const groupDesc = groups.map(progress.emphasize).join("+");
179
+
180
+ await progress.run(`Transpile ${groupDesc} to ${formatDesc}`, async () => {
181
+ for (const format of formats) {
182
+ await this.#transpile(project, format);
183
+ }
184
+ });
185
+ }
186
+
187
+ await config?.after?.({ project });
188
+
189
+ // Only update build information when there are no explicit targets so we know it's a full build
190
+ if (!this.options.targets?.length) {
191
+ await project.recordBuildInfo(info);
192
+ if (node) {
193
+ node.info = info;
194
+ }
195
+ }
196
+ }
197
+
198
+ async #transpile(project: Project, format: "esm" | "cjs") {
199
+ await project.buildSource(format);
200
+ if (project.pkg.hasTests) {
201
+ await project.buildTests(format);
202
+ }
203
+ }
204
+
205
+ #selectTargets(project: Project) {
206
+ const targets = new Set<string>(this.options.targets);
207
+
208
+ if (!targets.size) {
209
+ targets.add(Target.types);
210
+
211
+ if (project.pkg.supportsEsm) {
212
+ targets.add(Target.esm);
213
+ }
214
+
215
+ if (project.pkg.supportsCjs) {
216
+ targets.add(Target.cjs);
217
+ }
218
+ } else {
219
+ if (!project.pkg.supportsEsm) {
220
+ targets.delete(Target.esm);
221
+ }
222
+
223
+ if (!project.pkg.supportsCjs) {
224
+ targets.delete(Target.cjs);
225
+ }
226
+ }
227
+
228
+ return targets;
229
+ }
230
+ }
@@ -50,10 +50,8 @@ async function syncSubproject(node: Graph.Node, path: string, ...extraRefs: stri
50
50
 
51
51
  const tsconfig = await node.pkg.readJson(tsconfigPath);
52
52
 
53
- const deps = node.dependencies
54
- .filter(dep => dep.pkg.isLibrary)
55
- .map(dep => dep.pkg.resolve("src"))
56
- .filter(p => !p.match(/packages[\\/]tools/));
53
+ const deps = node.dependencies.filter(dep => dep.pkg.isLibrary).map(dep => dep.pkg.resolve("src"));
54
+ //.filter(p => !p.match(/packages[\\/]tools/));
57
55
 
58
56
  const desired = [...new Set([...deps, ...extraRefs])];
59
57
 
package/src/index.ts CHANGED
@@ -4,12 +4,10 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- export * from "./building/builder.js";
7
+ export * from "./ansi-text/index.js";
8
+ export * from "./ansi-text/std.js";
8
9
  export * from "./building/graph.js";
10
+ export * from "./building/project-builder.js";
9
11
  export * from "./building/project.js";
10
12
  export * from "./running/ensure-compiled.js";
11
- export * from "./util/commander.js";
12
- export * from "./util/file.js";
13
- export * from "./util/glob.js";
14
- export * from "./util/package.js";
15
- export * from "./util/progress.js";
13
+ export * from "./util/index.js";
@@ -6,8 +6,8 @@
6
6
 
7
7
  import { exit } from "process";
8
8
  import { fileURLToPath } from "url";
9
- import { Builder } from "../building/builder.js";
10
9
  import { Graph } from "../building/graph.js";
10
+ import { ProjectBuilder } from "../building/project-builder.js";
11
11
  import { Project } from "../building/project.js";
12
12
  import { Package } from "../util/package.js";
13
13
 
@@ -39,7 +39,7 @@ export async function ensureCompiled(path: string) {
39
39
  // In development we currently build package and dependencies unconditionally before running
40
40
  const isDevelopment = !path.match(/[\\/]node_modules[\\/]/);
41
41
  if (isDevelopment && format !== "none") {
42
- const builder = new Builder();
42
+ const builder = new ProjectBuilder();
43
43
  const dependencies = await Graph.forProject(path);
44
44
  if (dependencies) {
45
45
  // Project is in a workspace; build along with dependencies from the same workspace
@@ -4,11 +4,9 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import colors from "ansi-colors";
8
7
  import { Command } from "commander";
9
8
  import process from "process";
10
-
11
- colors.enabled = process.stdout.isTTY;
9
+ import { ansi } from "../ansi-text/text-builder.js";
12
10
 
13
11
  export function commander(name: string, description: string) {
14
12
  return new Command(name)
@@ -16,7 +14,7 @@ export function commander(name: string, description: string) {
16
14
  .allowExcessArguments(false)
17
15
  .configureOutput({
18
16
  writeOut: str => process.stdout.write(`\n${formatHelp(str)}\n`),
19
- writeErr: str => process.stderr.write(`\n${colors.red(str)}\n`),
17
+ writeErr: str => process.stderr.write(`\n${ansi.red(str)}\n`),
20
18
  });
21
19
  }
22
20
  function formatHelp(help: string) {
@@ -24,11 +22,11 @@ function formatHelp(help: string) {
24
22
  return help;
25
23
  }
26
24
 
27
- help = help.replace(/^Usage: (\S+)/, (_match, name) => `Usage: ${colors.bold(name)}`);
25
+ help = help.replace(/^Usage: (\S+)/, (_match, name) => `Usage: ${ansi.bold(name)}`);
28
26
  help = help.replace(/^( {2}.+ {2})/gm, (_match, input: string) =>
29
27
  input
30
28
  .split(",")
31
- .map(item => item.replace(/(-*\w+)/, (_match, word) => colors.blue(word)))
29
+ .map(item => item.replace(/(-*\w+)/, (_match, word) => ansi.blue(word).toString()))
32
30
  .join(","),
33
31
  );
34
32
  return help;
package/src/util/index.ts CHANGED
@@ -9,3 +9,4 @@ export * from "./errors.js";
9
9
  export * from "./file.js";
10
10
  export * from "./glob.js";
11
11
  export * from "./package.js";
12
+ export * from "./progress.js";
@@ -4,16 +4,17 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import colors from "ansi-colors";
8
7
  import { stderr, stdout } from "process";
8
+ import { screen } from "../ansi-text/screen.js";
9
+ import { std } from "../ansi-text/std.js";
10
+ import { ansi } from "../ansi-text/text-builder.js";
9
11
  import { Package } from "./package.js";
10
12
 
11
- const CLEAR = "\x1b[K";
12
13
  const SPINNER = "◐◓◑◒"; //"⡜⠔⠢⢣"; //["⚫︎", "⚪︎"]; "⡈⠔⠢⢁";
13
14
  const SPINNER_INTERVAL = 100;
14
15
 
15
16
  function packageIdentity(pkg: Package) {
16
- let identity = colors.bold(pkg.json.name);
17
+ let identity = ansi.bold(pkg.json.name).toString();
17
18
  if (pkg.json.version) {
18
19
  identity = `${identity}@${pkg.json.version}`;
19
20
  }
@@ -50,24 +51,20 @@ const writeStatus = (() => {
50
51
  intercept(stderr);
51
52
 
52
53
  return function writeStatus(text: string, willOverwrite = false) {
53
- const columns = process.stdout.columns;
54
- if (willOverwrite && columns !== undefined && text.length > columns - 2) {
55
- text = filterAnsi(text, columns - 2) + "…";
56
- }
57
-
58
- text += willOverwrite ? "\r" : "\n";
54
+ text += willOverwrite ? `${screen.erase.toEol}\r` : `${screen.erase.toEol}\n`;
59
55
  if (text === lastStatus) {
60
56
  return;
61
57
  }
62
58
 
63
- if (lastStatus) {
64
- lastStatus = undefined;
65
- stdout.write(CLEAR);
66
- } else if (needNewline && !text.startsWith("\n")) {
67
- stdout.write("\n");
68
- }
59
+ std.out.state({ buffer: true }, () => {
60
+ if (lastStatus) {
61
+ lastStatus = undefined;
62
+ } else if (needNewline && !text.startsWith("\n")) {
63
+ std.out("\n");
64
+ }
69
65
 
70
- stdout.write(text);
66
+ std.out.writeTruncated(text);
67
+ });
71
68
 
72
69
  lastStatus = text;
73
70
  };
@@ -86,15 +83,15 @@ export class Progress {
86
83
  constructor() {}
87
84
 
88
85
  emphasize(text: unknown) {
89
- return colors.bold(`${text}`);
86
+ return ansi.bold(`${text}`);
90
87
  }
91
88
 
92
89
  deemphasize(text: unknown) {
93
- return colors.dim(`${text}`);
90
+ return ansi.dim(`${text}`);
94
91
  }
95
92
 
96
93
  skip(why: string, pkg: Package) {
97
- stdout.write(colors.dim(`Skip ${packageIdentity(pkg)}: ${why}\n\n`));
94
+ std.out.write(ansi.dim(`Skip ${packageIdentity(pkg)}: ${why}\n\n`));
98
95
  }
99
96
 
100
97
  startup(what: string, pkgOrOverwrite?: Package | boolean) {
@@ -130,34 +127,32 @@ export class Progress {
130
127
  return;
131
128
  }
132
129
 
133
- const subtask = this.#subtasks.length
134
- ? colors.dim(` (${colors.dim(this.#subtasks[this.#subtasks.length - 1])})`)
135
- : "";
130
+ const subtask = this.#subtasks.length ? ansi.dim(` (${this.#subtasks[this.#subtasks.length - 1]})`) : "";
136
131
 
137
- writeStatus(` ${colors.yellow(this.#spinner)} ${this.#ongoingText}${subtask}`, true);
132
+ writeStatus(` ${ansi.yellow(this.#spinner)} ${this.#ongoingText}${subtask}`, true);
138
133
  }
139
134
 
140
135
  success(text: string) {
141
136
  this.status = Progress.Status.Success;
142
- writeStatus(` ${colors.green("✓")} ${text} ${this.#duration}`);
137
+ writeStatus(` ${ansi.green("✓")} ${text} ${this.#duration}`);
143
138
  this.#start = this.#ongoingText = undefined;
144
139
  }
145
140
 
146
141
  failure(text: string) {
147
142
  this.status = Progress.Status.Failure;
148
- writeStatus(` ${colors.redBright("✗")} ${text} ${this.#duration}`);
143
+ writeStatus(` ${ansi.bright.red("✗")} ${text} ${this.#duration}`);
149
144
  this.#start = this.#ongoingText = undefined;
150
145
  }
151
146
 
152
147
  info(label: string, value?: any) {
153
148
  if (value) {
154
- label = `${colors.dim(label)} ${value}`;
149
+ label = `${ansi.dim(label)} ${value}`;
155
150
  }
156
- writeStatus(` ${colors.dim("‣")} ${label}`);
151
+ writeStatus(` ${ansi.dim("‣")} ${label}`);
157
152
  }
158
153
 
159
154
  warn(text: string) {
160
- stdout.write(` ${colors.yellow("Warning:")} ${text}\n`);
155
+ std.out.write(` ${ansi.yellow("Warning:")} ${text}\n`);
161
156
  }
162
157
 
163
158
  shutdown() {
@@ -223,7 +218,7 @@ export class Progress {
223
218
  } else {
224
219
  ms = Math.trunc(ms / 1000);
225
220
  }
226
- return colors.dim.yellow(`(${ms}s)`);
221
+ return `${ansi.dim.yellow}(${ms}s)${ansi.not.dim.not.yellow}`;
227
222
  }
228
223
  }
229
224
 
@@ -235,35 +230,3 @@ export namespace Progress {
235
230
  Failure = "failure",
236
231
  }
237
232
  }
238
-
239
- // See https://stackoverflow.com/questions/26238553/how-can-i-truncate-a-string-to-a-maximum-length-without-breaking-ansi-escape-cod
240
- // TODO - this function doesn't seem entirely correct, still seems to truncate too much
241
- // Crop the length of lines, ANSI escape code aware
242
- // Always outputs every escape char, regardless of length (so we always end up with a sane state)
243
- // Visible characters are filtered out once length is exceeded
244
- function filterAnsi(str: string, len: number) {
245
- if (!len || len < 10) return str; // probably not a valid console -- send back the whole line
246
- let count = 0, // number of visible chars on line so far
247
- esc = false, // in an escape sequence
248
- longesc = false; // in a multi-character escape sequence
249
- let outp = true; // should output this character
250
- return str
251
- .split("")
252
- .filter(function (c) {
253
- // filter characters...
254
- if (esc && !longesc && c == "[") longesc = true; // have seen an escape, now '[', start multi-char escape
255
- if (c == "\x1b") esc = true; // start of escape sequence
256
-
257
- outp = count < len || esc; // if length exceeded, don't output non-escape chars
258
- if (!esc && !longesc) count++; // if not in escape, count visible char
259
-
260
- if (esc && !longesc && c != "\x1b") esc = false; // out of single char escape
261
- if (longesc && c != "[" && c >= "@" && c <= "~") {
262
- esc = false;
263
- longesc = false;
264
- } // end of multi-char escape
265
-
266
- return outp; // result for filter
267
- })
268
- .join(""); // glue chars back into string
269
- }
@@ -4,9 +4,9 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import colors from "ansi-colors";
8
7
  import { existsSync, readFileSync } from "fs";
9
8
  import { cp, writeFile } from "fs/promises";
9
+ import { ansi } from "../ansi-text/text-builder.js";
10
10
  import { Graph } from "../building/graph.js";
11
11
  import { execute } from "../running/execute.js";
12
12
  import { Package } from "../util/package.js";
@@ -54,7 +54,7 @@ export class Versioner {
54
54
  this.#members = new Set(graph.nodes.map(node => node.pkg.name));
55
55
 
56
56
  for (const node of graph.nodes) {
57
- const what = `Apply ${colors.bold(this.#definiteVersion)} to ${colors.bold(node.pkg.name)}`;
57
+ const what = `Apply ${ansi.bold(this.#definiteVersion)} to ${ansi.bold(node.pkg.name)}`;
58
58
  progress?.update(what);
59
59
  if (this.#applyOne(node.pkg)) {
60
60
  progress?.success(what);