@plugjs/plug 0.0.27 → 0.1.0

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 (270) hide show
  1. package/dist/{failure.cjs → asserts.cjs} +29 -9
  2. package/dist/asserts.cjs.map +6 -0
  3. package/dist/{failure.d.ts → asserts.d.ts} +4 -1
  4. package/dist/asserts.mjs +51 -0
  5. package/dist/asserts.mjs.map +6 -0
  6. package/dist/async.cjs +2 -2
  7. package/dist/async.cjs.map +1 -1
  8. package/dist/async.mjs +2 -2
  9. package/dist/async.mjs.map +1 -1
  10. package/dist/build.cjs +21 -30
  11. package/dist/build.cjs.map +1 -1
  12. package/dist/build.d.ts +2 -13
  13. package/dist/build.mjs +16 -24
  14. package/dist/build.mjs.map +1 -1
  15. package/dist/files.cjs +3 -3
  16. package/dist/files.cjs.map +1 -1
  17. package/dist/files.mjs +1 -1
  18. package/dist/files.mjs.map +1 -1
  19. package/dist/fork.cjs +35 -30
  20. package/dist/fork.cjs.map +1 -1
  21. package/dist/fork.d.ts +6 -3
  22. package/dist/fork.mjs +18 -13
  23. package/dist/fork.mjs.map +1 -1
  24. package/dist/{utils/asyncfs.cjs → fs.cjs} +6 -6
  25. package/dist/{utils/asyncfs.cjs.map → fs.cjs.map} +2 -2
  26. package/dist/{utils/asyncfs.d.ts → fs.d.ts} +1 -1
  27. package/dist/{utils/asyncfs.mjs → fs.mjs} +3 -3
  28. package/dist/{utils/asyncfs.mjs.map → fs.mjs.map} +2 -2
  29. package/dist/helpers.cjs +21 -14
  30. package/dist/helpers.cjs.map +1 -1
  31. package/dist/helpers.d.ts +24 -1
  32. package/dist/helpers.mjs +13 -7
  33. package/dist/helpers.mjs.map +1 -1
  34. package/dist/index.cjs +36 -6
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.ts +25 -8
  37. package/dist/index.mjs +20 -5
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/{log → logging}/colors.cjs +1 -1
  40. package/dist/{log → logging}/colors.cjs.map +1 -1
  41. package/dist/{log → logging}/colors.d.ts +0 -0
  42. package/dist/{log → logging}/colors.mjs +1 -1
  43. package/dist/{log → logging}/colors.mjs.map +1 -1
  44. package/dist/{log → logging}/emit.cjs +1 -2
  45. package/dist/{log → logging}/emit.cjs.map +2 -2
  46. package/dist/{log → logging}/emit.d.ts +0 -0
  47. package/dist/{log → logging}/emit.mjs +1 -2
  48. package/dist/{log → logging}/emit.mjs.map +2 -2
  49. package/dist/{log → logging}/levels.cjs +1 -1
  50. package/dist/{log → logging}/levels.cjs.map +1 -1
  51. package/dist/{log → logging}/levels.d.ts +0 -0
  52. package/dist/{log → logging}/levels.mjs +1 -1
  53. package/dist/{log → logging}/levels.mjs.map +1 -1
  54. package/dist/{log → logging}/logger.cjs +13 -7
  55. package/dist/logging/logger.cjs.map +6 -0
  56. package/dist/{log → logging}/logger.d.ts +0 -0
  57. package/dist/{log → logging}/logger.mjs +11 -5
  58. package/dist/logging/logger.mjs.map +6 -0
  59. package/dist/{log → logging}/options.cjs +12 -6
  60. package/dist/logging/options.cjs.map +6 -0
  61. package/dist/{log → logging}/options.d.ts +1 -1
  62. package/dist/{log → logging}/options.mjs +12 -6
  63. package/dist/logging/options.mjs.map +6 -0
  64. package/dist/{log → logging}/report.cjs +10 -9
  65. package/dist/{log → logging}/report.cjs.map +2 -2
  66. package/dist/{log → logging}/report.d.ts +0 -0
  67. package/dist/{log → logging}/report.mjs +7 -6
  68. package/dist/{log → logging}/report.mjs.map +2 -2
  69. package/dist/{log → logging}/spinner.cjs +1 -1
  70. package/dist/{log → logging}/spinner.cjs.map +1 -1
  71. package/dist/{log → logging}/spinner.d.ts +0 -0
  72. package/dist/{log → logging}/spinner.mjs +1 -1
  73. package/dist/{log → logging}/spinner.mjs.map +1 -1
  74. package/dist/{log.cjs → logging.cjs} +12 -12
  75. package/dist/{log.cjs.map → logging.cjs.map} +2 -2
  76. package/dist/{log.d.ts → logging.d.ts} +6 -6
  77. package/dist/{log.mjs → logging.mjs} +9 -9
  78. package/dist/{log.mjs.map → logging.mjs.map} +1 -1
  79. package/dist/paths.cjs +5 -5
  80. package/dist/paths.cjs.map +1 -1
  81. package/dist/paths.mjs +1 -1
  82. package/dist/pipe.cjs +10 -13
  83. package/dist/pipe.cjs.map +1 -1
  84. package/dist/pipe.d.ts +6 -12
  85. package/dist/pipe.mjs +6 -9
  86. package/dist/pipe.mjs.map +1 -1
  87. package/dist/plugs/copy.cjs +14 -14
  88. package/dist/plugs/copy.cjs.map +1 -1
  89. package/dist/plugs/copy.d.ts +1 -1
  90. package/dist/plugs/copy.mjs +3 -3
  91. package/dist/plugs/copy.mjs.map +1 -1
  92. package/dist/plugs/debug.cjs +7 -7
  93. package/dist/plugs/debug.cjs.map +1 -1
  94. package/dist/plugs/debug.d.ts +1 -1
  95. package/dist/plugs/debug.mjs +1 -1
  96. package/dist/plugs/edit.cjs +21 -0
  97. package/dist/plugs/edit.cjs.map +6 -0
  98. package/dist/plugs/edit.d.ts +7 -0
  99. package/dist/plugs/edit.mjs +29 -0
  100. package/dist/plugs/edit.mjs.map +6 -0
  101. package/dist/plugs/esbuild/fix-extensions.cjs +4 -4
  102. package/dist/plugs/esbuild/fix-extensions.cjs.map +1 -1
  103. package/dist/plugs/esbuild/fix-extensions.mjs +1 -1
  104. package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
  105. package/dist/plugs/esbuild.cjs +19 -14
  106. package/dist/plugs/esbuild.cjs.map +1 -1
  107. package/dist/plugs/esbuild.d.ts +1 -1
  108. package/dist/plugs/esbuild.mjs +8 -3
  109. package/dist/plugs/esbuild.mjs.map +1 -1
  110. package/dist/plugs/exec.cjs +2 -82
  111. package/dist/plugs/exec.cjs.map +2 -2
  112. package/dist/plugs/exec.d.ts +6 -32
  113. package/dist/plugs/exec.mjs +2 -68
  114. package/dist/plugs/exec.mjs.map +1 -1
  115. package/dist/plugs/filter.d.ts +1 -1
  116. package/dist/plugs/rmf.cjs +5 -5
  117. package/dist/plugs/rmf.cjs.map +1 -1
  118. package/dist/plugs/rmf.d.ts +1 -1
  119. package/dist/plugs/rmf.mjs +2 -2
  120. package/dist/plugs/rmf.mjs.map +1 -1
  121. package/dist/plugs.cjs +1 -4
  122. package/dist/plugs.cjs.map +1 -1
  123. package/dist/plugs.d.ts +1 -4
  124. package/dist/plugs.mjs +1 -4
  125. package/dist/plugs.mjs.map +1 -1
  126. package/dist/types.d.ts +1 -1
  127. package/dist/utils/caller.cjs +8 -5
  128. package/dist/utils/caller.cjs.map +1 -1
  129. package/dist/utils/caller.mjs +6 -3
  130. package/dist/utils/caller.mjs.map +1 -1
  131. package/dist/utils/exec.cjs +102 -0
  132. package/dist/utils/exec.cjs.map +6 -0
  133. package/dist/utils/exec.d.ts +15 -0
  134. package/dist/utils/exec.mjs +71 -0
  135. package/dist/utils/exec.mjs.map +6 -0
  136. package/dist/utils/walk.cjs +7 -7
  137. package/dist/utils/walk.cjs.map +1 -1
  138. package/dist/utils/walk.mjs +2 -2
  139. package/dist/utils/walk.mjs.map +1 -1
  140. package/dist/{plugs/tsc.cjs → utils.cjs} +9 -7
  141. package/dist/utils.cjs.map +6 -0
  142. package/dist/utils.d.ts +4 -0
  143. package/dist/utils.mjs +6 -0
  144. package/dist/utils.mjs.map +6 -0
  145. package/extra/cli.mjs +26 -5
  146. package/extra/ts-loader.mjs +2 -2
  147. package/package.json +90 -15
  148. package/src/{assert.ts → asserts.ts} +36 -1
  149. package/src/async.ts +3 -1
  150. package/src/files.ts +1 -1
  151. package/src/fork.ts +19 -11
  152. package/src/{utils/asyncfs.ts → fs.ts} +1 -1
  153. package/src/helpers.ts +40 -8
  154. package/src/index.ts +30 -8
  155. package/src/{log → logging}/colors.ts +0 -0
  156. package/src/{log → logging}/emit.ts +0 -1
  157. package/src/{log → logging}/levels.ts +0 -0
  158. package/src/{log → logging}/logger.ts +13 -4
  159. package/src/{log → logging}/options.ts +11 -7
  160. package/src/{log → logging}/report.ts +10 -9
  161. package/src/{log → logging}/spinner.ts +0 -0
  162. package/src/{log.ts → logging.ts} +7 -7
  163. package/src/paths.ts +1 -1
  164. package/src/pipe.ts +13 -20
  165. package/src/plugs/copy.ts +4 -4
  166. package/src/plugs/debug.ts +2 -2
  167. package/src/plugs/edit.ts +34 -0
  168. package/src/plugs/esbuild/fix-extensions.ts +2 -2
  169. package/src/plugs/esbuild.ts +13 -7
  170. package/src/plugs/exec.ts +8 -129
  171. package/src/plugs/filter.ts +1 -1
  172. package/src/plugs/rmf.ts +3 -3
  173. package/src/plugs.ts +1 -13
  174. package/src/types.ts +1 -1
  175. package/src/utils/caller.ts +6 -3
  176. package/src/utils/exec.ts +112 -0
  177. package/src/utils/walk.ts +3 -3
  178. package/src/utils.ts +4 -0
  179. package/types/{webassembly.d.ts → plugjs.d.ts} +7 -1
  180. package/dist/assert.cjs +0 -52
  181. package/dist/assert.cjs.map +0 -6
  182. package/dist/assert.d.ts +0 -4
  183. package/dist/assert.mjs +0 -26
  184. package/dist/assert.mjs.map +0 -6
  185. package/dist/failure.cjs.map +0 -6
  186. package/dist/failure.mjs +0 -33
  187. package/dist/failure.mjs.map +0 -6
  188. package/dist/log/logger.cjs.map +0 -6
  189. package/dist/log/logger.mjs.map +0 -6
  190. package/dist/log/options.cjs.map +0 -6
  191. package/dist/log/options.mjs.map +0 -6
  192. package/dist/plugs/coverage/analysis.cjs +0 -234
  193. package/dist/plugs/coverage/analysis.cjs.map +0 -6
  194. package/dist/plugs/coverage/analysis.d.ts +0 -104
  195. package/dist/plugs/coverage/analysis.mjs +0 -207
  196. package/dist/plugs/coverage/analysis.mjs.map +0 -6
  197. package/dist/plugs/coverage/report.cjs +0 -235
  198. package/dist/plugs/coverage/report.cjs.map +0 -6
  199. package/dist/plugs/coverage/report.d.ts +0 -59
  200. package/dist/plugs/coverage/report.mjs +0 -220
  201. package/dist/plugs/coverage/report.mjs.map +0 -6
  202. package/dist/plugs/coverage.cjs +0 -140
  203. package/dist/plugs/coverage.cjs.map +0 -6
  204. package/dist/plugs/coverage.d.ts +0 -49
  205. package/dist/plugs/coverage.mjs +0 -123
  206. package/dist/plugs/coverage.mjs.map +0 -6
  207. package/dist/plugs/eslint/runner.cjs +0 -91
  208. package/dist/plugs/eslint/runner.cjs.map +0 -6
  209. package/dist/plugs/eslint/runner.d.ts +0 -8
  210. package/dist/plugs/eslint/runner.mjs +0 -68
  211. package/dist/plugs/eslint/runner.mjs.map +0 -6
  212. package/dist/plugs/eslint.cjs +0 -22
  213. package/dist/plugs/eslint.cjs.map +0 -6
  214. package/dist/plugs/eslint.d.ts +0 -34
  215. package/dist/plugs/eslint.mjs +0 -5
  216. package/dist/plugs/eslint.mjs.map +0 -6
  217. package/dist/plugs/mocha/reporter.cjs +0 -159
  218. package/dist/plugs/mocha/reporter.cjs.map +0 -6
  219. package/dist/plugs/mocha/reporter.d.ts +0 -6
  220. package/dist/plugs/mocha/reporter.mjs +0 -127
  221. package/dist/plugs/mocha/reporter.mjs.map +0 -6
  222. package/dist/plugs/mocha/runner.cjs +0 -82
  223. package/dist/plugs/mocha/runner.cjs.map +0 -6
  224. package/dist/plugs/mocha/runner.d.ts +0 -8
  225. package/dist/plugs/mocha/runner.mjs +0 -53
  226. package/dist/plugs/mocha/runner.mjs.map +0 -6
  227. package/dist/plugs/mocha.cjs +0 -22
  228. package/dist/plugs/mocha.cjs.map +0 -6
  229. package/dist/plugs/mocha.d.ts +0 -37
  230. package/dist/plugs/mocha.mjs +0 -5
  231. package/dist/plugs/mocha.mjs.map +0 -6
  232. package/dist/plugs/tsc/compiler.cjs +0 -74
  233. package/dist/plugs/tsc/compiler.cjs.map +0 -6
  234. package/dist/plugs/tsc/compiler.d.ts +0 -24
  235. package/dist/plugs/tsc/compiler.mjs +0 -43
  236. package/dist/plugs/tsc/compiler.mjs.map +0 -6
  237. package/dist/plugs/tsc/options.cjs +0 -82
  238. package/dist/plugs/tsc/options.cjs.map +0 -6
  239. package/dist/plugs/tsc/options.d.ts +0 -8
  240. package/dist/plugs/tsc/options.mjs +0 -51
  241. package/dist/plugs/tsc/options.mjs.map +0 -6
  242. package/dist/plugs/tsc/report.cjs +0 -90
  243. package/dist/plugs/tsc/report.cjs.map +0 -6
  244. package/dist/plugs/tsc/report.d.ts +0 -5
  245. package/dist/plugs/tsc/report.mjs +0 -59
  246. package/dist/plugs/tsc/report.mjs.map +0 -6
  247. package/dist/plugs/tsc/runner.cjs +0 -124
  248. package/dist/plugs/tsc/runner.cjs.map +0 -6
  249. package/dist/plugs/tsc/runner.d.ts +0 -8
  250. package/dist/plugs/tsc/runner.mjs +0 -95
  251. package/dist/plugs/tsc/runner.mjs.map +0 -6
  252. package/dist/plugs/tsc.cjs.map +0 -6
  253. package/dist/plugs/tsc.d.ts +0 -48
  254. package/dist/plugs/tsc.mjs +0 -5
  255. package/dist/plugs/tsc.mjs.map +0 -6
  256. package/src/failure.ts +0 -43
  257. package/src/plugs/coverage/analysis.ts +0 -400
  258. package/src/plugs/coverage/report.ts +0 -368
  259. package/src/plugs/coverage.ts +0 -216
  260. package/src/plugs/eslint/runner.ts +0 -100
  261. package/src/plugs/eslint.ts +0 -42
  262. package/src/plugs/mocha/reporter.ts +0 -178
  263. package/src/plugs/mocha/runner.ts +0 -66
  264. package/src/plugs/mocha.ts +0 -43
  265. package/src/plugs/tsc/compiler.ts +0 -68
  266. package/src/plugs/tsc/options.ts +0 -100
  267. package/src/plugs/tsc/report.ts +0 -77
  268. package/src/plugs/tsc/runner.ts +0 -133
  269. package/src/plugs/tsc.ts +0 -58
  270. package/types/globals.d.ts +0 -15
@@ -1,42 +0,0 @@
1
- import { installForking } from '../fork'
2
- import { requireResolve } from '../paths'
3
-
4
- export interface ESLintOptions {
5
- /** ESLint's own _current working directory_, where config files are. */
6
- directory?: string
7
- /** Show sources in report? */
8
- showSources?: boolean
9
- /**
10
- * ESLint's _override_ configuration file: configurations specified in this
11
- * file will override any other configuration specified elsewhere.
12
- */
13
- configFile?: string
14
- }
15
-
16
- declare module '../pipe' {
17
- export interface Pipe {
18
- /**
19
- * Run {@link https://eslint.org/ _ESlint_} over the input source files,
20
- * using the configuration from the local `.eslintrc.*` file.
21
- */
22
- eslint(): Promise<undefined>
23
-
24
- /**
25
- * Run {@link https://eslint.org/ _ESlint_} over the input source files,
26
- * using the configuration from the specified `configFile` (this wil
27
- * override any `.eslintrc.*` file).
28
- *
29
- * @param configFile The configuration file to use
30
- */
31
- eslint(configFile: string): Promise<undefined>
32
-
33
- /**
34
- * Run {@link https://eslint.org/ _ESlint_} over the input source files..
35
- *
36
- * @param options {@link ESLintOptions | Options} to pass to _ESLint_
37
- */
38
- eslint(options: ESLintOptions): Promise<undefined>
39
- }
40
- }
41
-
42
- installForking('eslint', requireResolve(__fileurl, './eslint/runner'))
@@ -1,178 +0,0 @@
1
- import { diffJson } from 'diff'
2
- import RealMocha from 'mocha' // Mocha types pollute the global scope!
3
-
4
- import { $blu, $grn, $gry, $ms, $red, $wht, $ylw, ERROR, NOTICE, WARN } from '../../log'
5
-
6
- import type { Logger } from '../../log'
7
- import type { AssertionError } from 'node:assert'
8
-
9
- const _pending = '\u22EF' // middle ellipsis
10
- const _success = '\u2714' // heavy check mark
11
- const _failure = '\u2718' // heavy ballot x
12
- const _details = '\u21B3' // downwards arrow with tip rightwards
13
-
14
- /* ========================================================================== *
15
- * LOGGER / REPORTER *
16
- * ========================================================================== */
17
-
18
- /** Symbol to inject `Logger` in reporter options */
19
- export const logSymbol = Symbol()
20
-
21
- export class PlugReporter extends RealMocha.reporters.Base {
22
- constructor(runner: RealMocha.Runner, options: RealMocha.MochaOptions) {
23
- super(runner, options)
24
-
25
- const showDiff = !! options.diff
26
- const log = options.reporterOptions[logSymbol] as Logger
27
- const failures: RealMocha.Test[] = []
28
- const rootSuite = runner.suite
29
- let slow = 0
30
-
31
- // Enter a suite (increase indent)
32
- runner.on('suite', (suite) => {
33
- if (suite === rootSuite) return
34
- log.notice('')
35
- log.enter(NOTICE, `${$wht(suite.title)}`)
36
- })
37
-
38
- // Leave a suite (decrease indent)
39
- runner.on('suite end', () => {
40
- log.leave()
41
- })
42
-
43
- runner.on('fail', (test) => {
44
- // Hooks fail here (not on "hook end")
45
- if (test.type as any === 'hook') {
46
- const number = failures.push(test)
47
- const tag = $gry('[') + $red('failed') + $gry('] [') + $red(number) + $gry(']')
48
- log.error(`${$red(_failure)} ${test.title} ${tag}`)
49
- }
50
- })
51
-
52
- // Enter a test (increase indent)
53
- runner.on('test', (test) => {
54
- // mark that we _entered_ the test ('pending' might be called)
55
- (<any> test).__plugjs__entered = true
56
- log.enter(NOTICE, `${$blu(_pending)} ${test.title}`)
57
- })
58
-
59
- // Enter a pending test (increase indent)
60
- runner.on('pending', (test) => {
61
- // pending is also called when "this.skip" gets called inside the test
62
- if ((<any> test).__plugjs__entered === true) return
63
- log.enter(NOTICE, `${$blu(_pending)} ${test.title}`)
64
- })
65
-
66
- // Leave a test (handle warning/failures and decrease indent)
67
- runner.on('test end', (test) => {
68
- if (test.isPassed()) {
69
- const duration = test.duration || 0
70
- if (duration < test.slow()) {
71
- log.leave(NOTICE, `${$grn(_success)} ${test.title}`)
72
- } else {
73
- log.leave(WARN, `${$ylw(_success)} ${test.title} ${$ms(duration, 'slow')}`)
74
- slow ++
75
- }
76
- } else if (test.isPending()) {
77
- const tag = $gry('[') + $ylw('skipped') + $gry(']')
78
- log.leave(WARN, `${$ylw(_pending)} ${test.title} ${tag}`)
79
- } else if (test.isFailed()) {
80
- const number = failures.push(test)
81
- const tag = $gry('[') + $red('failed') + $gry('] [') + $red(number) + $gry(']')
82
- log.leave(ERROR, `${$red(_failure)} ${test.title} ${tag}`)
83
- }
84
- })
85
-
86
- // Mocha finished running, dump our report
87
- runner.once('end', () => {
88
- // console.log('[end]')
89
- try {
90
- // Each failure gets dumped individually
91
- for (let i = 0; i < failures.length; i ++) {
92
- log.notice('')
93
- const failure = failures[i]
94
-
95
- // The titles (from the suite, up to the test)
96
- const titles = [ failure.title ]
97
- for (let parent = failure.parent; parent; parent = parent?.parent) {
98
- if (parent.parent) titles.unshift(parent.title)
99
- }
100
-
101
- // Log out our titles (one per line, indented)
102
- log.error(`${$gry('Failure [')}${$red(i + 1)}${$gry(']')}`)
103
- titles.forEach((title, indent) => {
104
- log.error(` ${''.padStart(indent * 4)}${$gry(_details)} ${$wht(title)}`)
105
- })
106
-
107
- // If we have an error, luckily this is an `Error` instance
108
- if (failure.err) {
109
- const message = `${failure.err}` // this is the message, can be multiple lines
110
- const messageOrStack = failure.err.stack || `${failure.err}` // maybe a stack?
111
- const messageIndex = messageOrStack.indexOf(message)
112
-
113
- // Subtrack the message from the stack
114
- const stack =
115
- messageOrStack === message ? '' :
116
- messageIndex < 0 ? messageOrStack :
117
- messageOrStack.substring(messageIndex + message.length)
118
-
119
- // Split and clean up stack lines
120
- const stackLines = stack.split('\n')
121
- .map((line) => line.trim())
122
- .filter((line) => !! line)
123
-
124
- // Output the message
125
- log.enter(ERROR, '')
126
- log.error($red(message))
127
-
128
- // Should we diff?
129
- if (showDiff && ('actual' in failure.err) && ('expected' in failure.err)) {
130
- const err = failure.err as AssertionError
131
- const actual =
132
- err.actual === undefined ? '[undefined]' :
133
- err.actual === null ? '[null]' :
134
- err.actual
135
-
136
- const expected =
137
- err.expected === undefined ? '[undefined]' :
138
- err.expected === null ? '[null]' :
139
- err.expected
140
-
141
- const changes = diffJson(actual as any, expected as any)
142
-
143
- const diff = changes.map((change): string => {
144
- if (change.removed) return $red(change.value)
145
- if (change.added) return $grn(change.value)
146
- return $gry(change.value)
147
- }).join('')
148
-
149
- log.enter(ERROR, `${$gry('diff')} ${$grn('expected')} ${$gry('/')} ${$red('actual')}`)
150
- log.error(diff)
151
- log.leave()
152
- }
153
-
154
- // Dump our stack trace and leave
155
- stackLines.forEach((line) => log.error(line))
156
- log.leave()
157
- }
158
- }
159
-
160
- // If we have some statistics, then let's dump them out in pretty colors
161
- if (runner.stats) {
162
- log.notice('')
163
- const { passes, pending, failures, duration = 0 } = runner.stats
164
- const fmt = (n: number): string => n === 1 ? `${n} test` : `${n} tests`
165
- if (passes) log.notice($grn(fmt(passes)), 'passing', $ms(duration))
166
- if (slow) log.warn($ylw(fmt(slow)), 'slow')
167
- if (pending) log.warn($ylw(fmt(pending)), 'pending')
168
- if (failures) log.error($red(fmt(failures)), 'failed')
169
- }
170
-
171
- // Done...
172
- log.notice('')
173
- } catch (error) {
174
- log.error('Error rendering Mocha report', error)
175
- }
176
- })
177
- }
178
- }
@@ -1,66 +0,0 @@
1
- import RealMocha from 'mocha' // Mocha types pollute the global scope!
2
-
3
- import { assert } from '../../assert'
4
- import { BuildFailure } from '../../failure'
5
- import { $p, $wht, NOTICE } from '../../log'
6
- import { resolveFile } from '../../paths'
7
- import { logSymbol, PlugReporter } from './reporter'
8
-
9
- import type { Files } from '../../files'
10
- import type { Context, PipeParameters, Plug } from '../../pipe'
11
- import type { MochaOptions } from '../mocha'
12
-
13
- /** Writes some info about the current {@link Files} being passed around. */
14
- export default class Mocha implements Plug<void> {
15
- constructor(...args: PipeParameters<'mocha'>)
16
- constructor(private readonly _options: MochaOptions = {}) {}
17
-
18
- async pipe(files: Files, context: Context): Promise<void> {
19
- // Enter log here, so that log messages called when loading files get
20
- // properly indented by our logger
21
- context.log.notice('') // empty line
22
- context.log.enter(NOTICE, $wht('Starting Mocha'))
23
-
24
- // Expand our options
25
- const { require, ...options } = this._options
26
-
27
- // See if we require a setup script...
28
- if (require) {
29
- const requiredFile = context.resolve(require)
30
- const scriptFile = resolveFile(requiredFile)
31
- assert(scriptFile, `Mocha setup file ${$p(requiredFile)} not found`)
32
- context.log.debug(`Importing setup script ${$p(requiredFile)}`)
33
- await import(scriptFile)
34
- }
35
-
36
- // Create the mocha runner
37
- const mocha = new RealMocha({
38
- diff: true, // by defaut enable diffs
39
- reporter: PlugReporter, // default to our reporter
40
- ...options, // override defaults with all other options
41
- reporterOptions: {
42
- ...options.reporterOptions,
43
- [logSymbol]: context.log, // always force a log
44
- },
45
- allowUncaught: false, // never allow uncaught exceptions
46
- delay: false, // never delay running
47
- })
48
-
49
- // Tell mocha about all our files
50
- for (const file of files.absolutePaths()) mocha.addFile(file)
51
-
52
- await mocha.loadFilesAsync()
53
-
54
- // Run mocha!
55
- return new Promise((resolve, reject) => {
56
- try {
57
- mocha.run((failures) => {
58
- if (failures) reject(BuildFailure.fail())
59
- resolve(undefined)
60
- })
61
- } catch (error) {
62
- reject(error)
63
- }
64
- })
65
- }
66
- }
@@ -1,43 +0,0 @@
1
- import { installForking } from '../fork'
2
- import { requireResolve } from '../paths'
3
-
4
- /** Options to construct our {@link Mocha} plug. */
5
- export interface MochaOptions {
6
- /** Specify the directory where coverage data will be saved */
7
- coverageDir?: string,
8
- /** Bail after first test failure? */
9
- bail?: boolean,
10
- /** Show diff on failure? */
11
- diff?: boolean,
12
- /** Report tests without running them? */
13
- dryRun?: boolean,
14
- /** Tests marked `only` fail the suite? */
15
- forbidOnly?: boolean,
16
- /** Pending tests fail the suite? */
17
- forbidPending?: false,
18
- /** Reporter name. */
19
- reporter?: string
20
- /** Options for the reporter */
21
- reporterOptions?: Record<string, any>,
22
- /** Number of times to retry failed tests. */
23
- retries?: number,
24
- /** Slow threshold value. */
25
- slow?: number,
26
- /** Setup file to import before running Mocha. */
27
- require?: string,
28
- /** Timeout threshold value. */
29
- timeout?: number,
30
- }
31
-
32
- declare module '../pipe' {
33
- export interface Pipe {
34
- /**
35
- * Run tests using {@link https://mochajs.org/ _Mocha_}.
36
- *
37
- * @param options Optional {@link MochaOptions | options} for _Mocha_.
38
- */
39
- mocha(options?: MochaOptions): Promise<undefined>
40
- }
41
- }
42
-
43
- installForking('mocha', requireResolve(__fileurl, './mocha/runner'))
@@ -1,68 +0,0 @@
1
- import ts from 'typescript' // TypeScript does NOT support ESM modules
2
-
3
- import { resolveAbsolutePath } from '../../paths'
4
-
5
- import type { AbsolutePath } from '../../paths'
6
-
7
- export class TypeScriptHost
8
- implements ts.CompilerHost {
9
- constructor(directory: AbsolutePath)
10
- constructor(private readonly _directory: AbsolutePath) {}
11
-
12
- /* ======================================================================== */
13
-
14
- /** Get a source file parsing one of our virtual files */
15
- getSourceFile(
16
- fileName: string,
17
- languageVersion: ts.ScriptTarget,
18
- ): ts.SourceFile | undefined {
19
- const code = this.readFile(fileName)
20
- return code ? ts.createSourceFile(fileName, code, languageVersion) : void 0
21
- }
22
-
23
- /** Never write any files */
24
- writeFile(fileName: string): void {
25
- throw new Error(`Cowardly refusing to write "${fileName}"`)
26
- }
27
-
28
- /** Get the default library associated with the given options */
29
- getDefaultLibFileName(options: ts.CompilerOptions): string {
30
- return ts.getDefaultLibFilePath(options)
31
- }
32
-
33
- /** Check for filesystem case sensitivity */
34
- useCaseSensitiveFileNames(): boolean {
35
- return ts.sys.useCaseSensitiveFileNames
36
- }
37
-
38
- /** Check for the existence of a given file */
39
- fileExists(fileName: string): boolean {
40
- return ts.sys.fileExists(resolveAbsolutePath(this.getCurrentDirectory(), fileName))
41
- }
42
-
43
- /** Read the file if it exists, otherwise return undefined */
44
- readFile(fileName: string): string | undefined {
45
- return ts.sys.readFile(resolveAbsolutePath(this.getCurrentDirectory(), fileName))
46
- }
47
-
48
- /** Return the current working directory */
49
- getCurrentDirectory(): AbsolutePath {
50
- return this._directory
51
- }
52
-
53
- /** Return the canonical name for the specified file */
54
- getCanonicalFileName(fileName: string): string {
55
- if (ts.sys.useCaseSensitiveFileNames) return fileName
56
-
57
- // Lifted from TypeScript sources
58
- const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_. ]+/g
59
- return fileNameLowerCaseRegExp.test(fileName) ?
60
- fileName.replace(fileNameLowerCaseRegExp, (s) => s.toLowerCase()) :
61
- fileName
62
- }
63
-
64
- /** Return the new line sequence used by this platform */
65
- getNewLine(): string {
66
- return ts.sys.newLine
67
- }
68
- }
@@ -1,100 +0,0 @@
1
- import ts from 'typescript' // TypeScript does NOT support ESM modules
2
-
3
- import { getAbsoluteParent, resolveAbsolutePath } from '../../paths'
4
- import { readFile } from '../../utils/asyncfs'
5
-
6
- import type { AbsolutePath } from '../../paths'
7
-
8
- /* ========================================================================== */
9
-
10
- export type CompilerOptionsAndDiagnostics = {
11
- options: ts.CompilerOptions,
12
- errors: readonly ts.Diagnostic[],
13
- }
14
-
15
- /* ========================================================================== */
16
-
17
- function mergeResults(
18
- base: CompilerOptionsAndDiagnostics,
19
- override: CompilerOptionsAndDiagnostics,
20
- ): CompilerOptionsAndDiagnostics {
21
- return {
22
- options: { ...base.options, ...override.options },
23
- errors: [ ...base.errors, ...override.errors ],
24
- }
25
- }
26
-
27
- /* ========================================================================== */
28
-
29
- async function loadOptions(
30
- file: AbsolutePath,
31
- stack: AbsolutePath[] = [ file ],
32
- ): Promise<CompilerOptionsAndDiagnostics> {
33
- const dir = getAbsoluteParent(file)
34
-
35
- // Load up our config file and convert is wicked JSON
36
- const data = await readFile(file, 'utf-8')
37
- const { config, error } = ts.parseConfigFileTextToJson(file, data)
38
- if (error) return { options: {}, errors: [ error ] }
39
-
40
- // Parse up the configuration file as options
41
- const { compilerOptions = {}, extends: extendsPath } = config
42
- const result = ts.convertCompilerOptionsFromJson(compilerOptions, dir, file)
43
- if (result.errors.length) return result
44
-
45
- // If we don't extend, we can return our result
46
- if (!extendsPath) return result
47
-
48
- // Resolve the name of the file this config extends
49
- const ext = resolveAbsolutePath(dir, extendsPath)
50
-
51
- // Triple check that we are not recursively importing this file
52
- if (stack.includes(ext)) {
53
- return { options: {}, errors: [ {
54
- messageText: `Circularity detected extending from "${ext}"`,
55
- category: ts.DiagnosticCategory.Error,
56
- code: 18000, // copied from typescript internals...
57
- file: ts.createSourceFile(file, data, ts.ScriptTarget.JSON, false, ts.ScriptKind.JSON),
58
- start: undefined,
59
- length: undefined,
60
- } ] }
61
- }
62
-
63
- // Push our file in the stack and load recursively
64
- return mergeResults(await loadOptions(ext, [ ...stack, ext ]), result)
65
- }
66
-
67
- /* ========================================================================== */
68
-
69
- export async function getCompilerOptions(
70
- file?: AbsolutePath,
71
- ): Promise<CompilerOptionsAndDiagnostics>
72
-
73
- export async function getCompilerOptions(
74
- file: AbsolutePath | undefined,
75
- overrides: ts.CompilerOptions,
76
- overridesFile: AbsolutePath,
77
- overridesBasePath: AbsolutePath,
78
- ): Promise<CompilerOptionsAndDiagnostics>
79
-
80
- /** Load compiler options from a JSON file, and merge in the overrides */
81
- export async function getCompilerOptions(
82
- file?: AbsolutePath,
83
- ...override: [ ts.CompilerOptions, AbsolutePath, AbsolutePath ] | []
84
- ): Promise<CompilerOptionsAndDiagnostics> {
85
- let result: CompilerOptionsAndDiagnostics = { options: ts.getDefaultCompilerOptions(), errors: [] }
86
-
87
- // If we have a file to parse, load it, otherwise try "tsconfig.json"
88
- if (file) result = mergeResults(result, await loadOptions(file))
89
-
90
- // If we have overrides, merge them
91
- if (override.length) {
92
- const [ overrides, overridesFile, overridesDir ] = override
93
- const options = ts.convertCompilerOptionsFromJson(overrides, overridesDir, overridesFile)
94
- delete options.options.configFilePath // remove build file name...
95
- result = mergeResults(result, options)
96
- }
97
-
98
- // Return all we have
99
- return result
100
- }
@@ -1,77 +0,0 @@
1
- import ts from 'typescript' // TypeScript does NOT support ESM modules
2
-
3
- import { ERROR, NOTICE, WARN } from '../../log'
4
- import { resolveAbsolutePath } from '../../paths'
5
-
6
- import type { Report, ReportLevel, ReportRecord } from '../../log'
7
- import type { AbsolutePath } from '../../paths'
8
-
9
- function convertMessageChain(chain: ts.DiagnosticMessageChain, indent = 0): string[] {
10
- const message = `${''.padStart(indent * 2)}${chain.messageText}`
11
-
12
- if (chain.next) {
13
- const next = chain.next.map((c) => convertMessageChain(c, indent + 1))
14
- return [ message, ...next.flat(1) ]
15
- } else {
16
- return [ message ]
17
- }
18
- }
19
-
20
- function convertDiagnostics(
21
- diagnostics: readonly ts.Diagnostic[],
22
- directory: AbsolutePath,
23
- ): ReportRecord[] {
24
- return diagnostics.map((diagnostic): ReportRecord => {
25
- // console.log(diagnostic)
26
- void directory
27
-
28
- // Convert the `DiagnosticCategory` to our level
29
- let level: ReportLevel
30
- switch (diagnostic.category) {
31
- case ts.DiagnosticCategory.Error: level = ERROR; break
32
- case ts.DiagnosticCategory.Warning: level = WARN; break
33
- default: level = NOTICE
34
- }
35
-
36
- // Convert the `messageText` to a string
37
- let message: string | string[]
38
- if (typeof diagnostic.messageText === 'string') {
39
- message = diagnostic.messageText
40
- } else {
41
- message = convertMessageChain(diagnostic.messageText)
42
- }
43
-
44
- // Simple variables
45
- const tags = `TS${diagnostic.code}`
46
-
47
-
48
- if (diagnostic.file) {
49
- const { file: sourceFile, start, length } = diagnostic
50
- const file = resolveAbsolutePath(directory, sourceFile.fileName)
51
- const source = sourceFile.getFullText()
52
-
53
- if (start !== undefined) {
54
- const position = sourceFile.getLineAndCharacterOfPosition(start)
55
- let { line, character: column } = position
56
- column += 1
57
- line += 1
58
-
59
- return { level, message, tags, file, source, line, column, length }
60
- } else {
61
- return { level, message, tags, file, source }
62
- }
63
- } else {
64
- return { level, message, tags }
65
- }
66
- })
67
- }
68
-
69
- /** Update a report, adding records from an array of {@link ts.Diagnostic} */
70
- export function updateReport(
71
- report: Report,
72
- diagnostics: readonly ts.Diagnostic[],
73
- directory: AbsolutePath,
74
- ): void {
75
- const records = convertDiagnostics(diagnostics, directory)
76
- report.add(...records)
77
- }