@plugjs/plug 0.0.14 → 0.0.15

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 (212) hide show
  1. package/dist/async.cjs +20 -19
  2. package/dist/async.cjs.map +1 -1
  3. package/dist/async.d.ts +9 -9
  4. package/dist/async.mjs +18 -17
  5. package/dist/async.mjs.map +1 -1
  6. package/dist/build.cjs +144 -110
  7. package/dist/build.cjs.map +2 -2
  8. package/dist/build.d.ts +12 -56
  9. package/dist/build.mjs +146 -112
  10. package/dist/build.mjs.map +2 -2
  11. package/dist/files.cjs +2 -16
  12. package/dist/files.cjs.map +1 -1
  13. package/dist/files.d.ts +3 -10
  14. package/dist/files.mjs +3 -17
  15. package/dist/files.mjs.map +1 -1
  16. package/dist/fork.cjs +28 -40
  17. package/dist/fork.cjs.map +1 -1
  18. package/dist/fork.d.ts +6 -27
  19. package/dist/fork.mjs +29 -40
  20. package/dist/fork.mjs.map +1 -1
  21. package/dist/helpers.cjs +61 -63
  22. package/dist/helpers.cjs.map +2 -2
  23. package/dist/helpers.d.ts +15 -37
  24. package/dist/helpers.mjs +61 -64
  25. package/dist/helpers.mjs.map +2 -2
  26. package/dist/index.cjs +3 -2
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +9 -13
  29. package/dist/index.mjs +3 -2
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/log/colors.cjs +3 -1
  32. package/dist/log/colors.cjs.map +1 -1
  33. package/dist/log/colors.d.ts +2 -2
  34. package/dist/log/colors.mjs +3 -1
  35. package/dist/log/colors.mjs.map +1 -1
  36. package/dist/log/emit.d.ts +1 -1
  37. package/dist/log/logger.cjs +4 -0
  38. package/dist/log/logger.cjs.map +1 -1
  39. package/dist/log/logger.d.ts +4 -1
  40. package/dist/log/logger.mjs +4 -0
  41. package/dist/log/logger.mjs.map +1 -1
  42. package/dist/log/options.d.ts +1 -1
  43. package/dist/log/report.cjs +2 -11
  44. package/dist/log/report.cjs.map +1 -1
  45. package/dist/log/report.d.ts +36 -4
  46. package/dist/log/report.mjs +1 -10
  47. package/dist/log/report.mjs.map +1 -1
  48. package/dist/log.cjs +1 -1
  49. package/dist/log.cjs.map +1 -1
  50. package/dist/log.d.ts +6 -6
  51. package/dist/log.mjs +2 -2
  52. package/dist/log.mjs.map +1 -1
  53. package/dist/pipe.cjs +41 -34
  54. package/dist/pipe.cjs.map +1 -1
  55. package/dist/pipe.d.ts +149 -119
  56. package/dist/pipe.mjs +38 -32
  57. package/dist/pipe.mjs.map +1 -1
  58. package/dist/plugs/copy.cjs +15 -25
  59. package/dist/plugs/copy.cjs.map +2 -2
  60. package/dist/plugs/copy.d.ts +14 -13
  61. package/dist/plugs/copy.mjs +15 -17
  62. package/dist/plugs/copy.mjs.map +2 -2
  63. package/dist/plugs/coverage/analysis.d.ts +2 -2
  64. package/dist/plugs/coverage/report.cjs +1 -1
  65. package/dist/plugs/coverage/report.cjs.map +1 -1
  66. package/dist/plugs/coverage/report.d.ts +3 -3
  67. package/dist/plugs/coverage/report.mjs +1 -1
  68. package/dist/plugs/coverage/report.mjs.map +1 -1
  69. package/dist/plugs/coverage.cjs +19 -25
  70. package/dist/plugs/coverage.cjs.map +1 -1
  71. package/dist/plugs/coverage.d.ts +33 -30
  72. package/dist/plugs/coverage.mjs +20 -18
  73. package/dist/plugs/coverage.mjs.map +1 -1
  74. package/dist/plugs/debug.cjs +8 -37
  75. package/dist/plugs/debug.cjs.map +1 -1
  76. package/dist/plugs/debug.d.ts +4 -11
  77. package/dist/plugs/debug.mjs +24 -20
  78. package/dist/plugs/debug.mjs.map +1 -1
  79. package/dist/plugs/esbuild/fix-extensions.mjs +1 -1
  80. package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
  81. package/dist/plugs/esbuild.cjs +14 -25
  82. package/dist/plugs/esbuild.cjs.map +1 -1
  83. package/dist/plugs/esbuild.d.ts +11 -16
  84. package/dist/plugs/esbuild.mjs +14 -17
  85. package/dist/plugs/esbuild.mjs.map +1 -1
  86. package/dist/plugs/eslint/runner.cjs +5 -6
  87. package/dist/plugs/eslint/runner.cjs.map +1 -1
  88. package/dist/plugs/eslint/runner.d.ts +6 -20
  89. package/dist/plugs/eslint/runner.mjs +6 -7
  90. package/dist/plugs/eslint/runner.mjs.map +1 -1
  91. package/dist/{task.cjs → plugs/eslint.cjs} +7 -24
  92. package/dist/plugs/eslint.cjs.map +6 -0
  93. package/dist/plugs/eslint.d.ts +34 -0
  94. package/dist/plugs/eslint.mjs +5 -0
  95. package/dist/plugs/eslint.mjs.map +6 -0
  96. package/dist/plugs/exec.cjs +20 -24
  97. package/dist/plugs/exec.cjs.map +1 -1
  98. package/dist/plugs/exec.d.ts +53 -53
  99. package/dist/plugs/exec.mjs +20 -23
  100. package/dist/plugs/exec.mjs.map +1 -1
  101. package/dist/plugs/filter.cjs +9 -19
  102. package/dist/plugs/filter.cjs.map +1 -1
  103. package/dist/plugs/filter.d.ts +21 -15
  104. package/dist/plugs/filter.mjs +10 -12
  105. package/dist/plugs/filter.mjs.map +1 -1
  106. package/dist/plugs/mocha/reporter.cjs +12 -6
  107. package/dist/plugs/mocha/reporter.cjs.map +1 -1
  108. package/dist/plugs/mocha/reporter.d.ts +0 -2
  109. package/dist/plugs/mocha/reporter.mjs +11 -4
  110. package/dist/plugs/mocha/reporter.mjs.map +1 -1
  111. package/dist/plugs/mocha/runner.cjs +4 -5
  112. package/dist/plugs/mocha/runner.cjs.map +1 -1
  113. package/dist/plugs/mocha/runner.d.ts +5 -31
  114. package/dist/plugs/mocha/runner.mjs +5 -6
  115. package/dist/plugs/mocha/runner.mjs.map +1 -1
  116. package/dist/plugs/mocha.cjs +22 -0
  117. package/dist/plugs/mocha.cjs.map +6 -0
  118. package/dist/plugs/mocha.d.ts +35 -0
  119. package/dist/plugs/mocha.mjs +5 -0
  120. package/dist/plugs/mocha.mjs.map +6 -0
  121. package/dist/plugs/rmf.cjs +4 -32
  122. package/dist/plugs/rmf.cjs.map +1 -1
  123. package/dist/plugs/rmf.d.ts +8 -12
  124. package/dist/plugs/rmf.mjs +25 -20
  125. package/dist/plugs/rmf.mjs.map +1 -1
  126. package/dist/plugs/tsc/compiler.d.ts +1 -1
  127. package/dist/plugs/tsc/options.d.ts +1 -1
  128. package/dist/plugs/tsc/report.d.ts +2 -2
  129. package/dist/plugs/tsc/runner.cjs +12 -11
  130. package/dist/plugs/tsc/runner.cjs.map +1 -1
  131. package/dist/plugs/tsc/runner.d.ts +4 -9
  132. package/dist/plugs/tsc/runner.mjs +12 -11
  133. package/dist/plugs/tsc/runner.mjs.map +1 -1
  134. package/dist/plugs/tsc.cjs +7 -0
  135. package/dist/plugs/tsc.cjs.map +6 -0
  136. package/dist/plugs/tsc.d.ts +36 -0
  137. package/dist/plugs/tsc.mjs +15 -0
  138. package/dist/plugs/tsc.mjs.map +6 -0
  139. package/dist/plugs.cjs +3 -5
  140. package/dist/plugs.cjs.map +1 -1
  141. package/dist/plugs.d.ts +10 -17
  142. package/dist/plugs.mjs +3 -5
  143. package/dist/plugs.mjs.map +1 -1
  144. package/dist/types.cjs +19 -0
  145. package/dist/types.cjs.map +6 -0
  146. package/dist/types.d.ts +72 -0
  147. package/dist/types.mjs +1 -0
  148. package/dist/types.mjs.map +6 -0
  149. package/dist/utils/caller.cjs +8 -11
  150. package/dist/utils/caller.cjs.map +2 -2
  151. package/dist/utils/caller.d.ts +2 -7
  152. package/dist/utils/caller.mjs +8 -11
  153. package/dist/utils/caller.mjs.map +2 -2
  154. package/dist/utils/options.cjs +4 -6
  155. package/dist/utils/options.cjs.map +1 -1
  156. package/dist/utils/options.d.ts +16 -15
  157. package/dist/utils/options.mjs +4 -6
  158. package/dist/utils/options.mjs.map +1 -1
  159. package/dist/utils/walk.d.ts +2 -2
  160. package/extra/cli.mjs +31 -20
  161. package/extra/ts-loader.mjs +6 -5
  162. package/package.json +6 -6
  163. package/src/async.ts +27 -19
  164. package/src/files.ts +6 -30
  165. package/src/fork.ts +35 -76
  166. package/src/helpers.ts +89 -101
  167. package/src/index.ts +10 -15
  168. package/src/log/colors.ts +4 -3
  169. package/src/log/emit.ts +4 -4
  170. package/src/log/logger.ts +12 -4
  171. package/src/log/options.ts +1 -1
  172. package/src/log/report.ts +8 -22
  173. package/src/log/spinner.ts +3 -3
  174. package/src/log.ts +9 -9
  175. package/src/paths.ts +1 -1
  176. package/src/pipe.ts +191 -178
  177. package/src/plugs/copy.ts +40 -31
  178. package/src/plugs/coverage/analysis.ts +4 -4
  179. package/src/plugs/coverage/report.ts +6 -5
  180. package/src/plugs/coverage.ts +64 -53
  181. package/src/plugs/debug.ts +22 -27
  182. package/src/plugs/esbuild/fix-extensions.ts +2 -2
  183. package/src/plugs/esbuild.ts +42 -46
  184. package/src/plugs/eslint/runner.ts +16 -31
  185. package/src/plugs/eslint.ts +42 -0
  186. package/src/plugs/exec.ts +93 -82
  187. package/src/plugs/filter.ts +42 -27
  188. package/src/plugs/mocha/reporter.ts +10 -5
  189. package/src/plugs/mocha/runner.ts +12 -38
  190. package/src/plugs/mocha.ts +41 -0
  191. package/src/plugs/rmf.ts +21 -25
  192. package/src/plugs/tsc/compiler.ts +1 -1
  193. package/src/plugs/tsc/options.ts +2 -2
  194. package/src/plugs/tsc/report.ts +2 -2
  195. package/src/plugs/tsc/runner.ts +24 -30
  196. package/src/plugs/tsc.ts +45 -0
  197. package/src/plugs.ts +10 -25
  198. package/src/types.ts +123 -0
  199. package/src/utils/caller.ts +11 -22
  200. package/src/utils/options.ts +49 -17
  201. package/src/utils/walk.ts +4 -4
  202. package/dist/run.cjs +0 -90
  203. package/dist/run.cjs.map +0 -6
  204. package/dist/run.d.ts +0 -89
  205. package/dist/run.mjs +0 -65
  206. package/dist/run.mjs.map +0 -6
  207. package/dist/task.cjs.map +0 -6
  208. package/dist/task.d.ts +0 -15
  209. package/dist/task.mjs +0 -14
  210. package/dist/task.mjs.map +0 -6
  211. package/src/run.ts +0 -159
  212. package/src/task.ts +0 -26
@@ -1,25 +1,25 @@
1
1
  import { html, initFunction } from '@plugjs/cov8-html'
2
2
  import { sep } from 'node:path'
3
- import { fail } from '../assert.js'
4
- import { Files } from '../files.js'
5
- import { $gry, $ms, $p, $red, $ylw, ERROR, NOTICE, WARN } from '../log.js'
6
- import { AbsolutePath } from '../paths.js'
7
- import { install, Plug } from '../pipe.js'
8
- import { Run } from '../run.js'
9
- import { createAnalyser, SourceMapBias } from './coverage/analysis.js'
10
- import { coverageReport, CoverageResult } from './coverage/report.js'
3
+ import { fail } from '../assert'
4
+ import { Files } from '../files'
5
+ import { $gry, $ms, $p, $red, $ylw, ERROR, NOTICE, WARN } from '../log'
6
+ import { AbsolutePath, resolveAbsolutePath } from '../paths'
7
+ import { install, PipeParameters, Plug, Context } from '../pipe'
8
+ import { walk } from '../utils/walk'
9
+ import { createAnalyser, SourceMapBias } from './coverage/analysis'
10
+ import { coverageReport, CoverageResult } from './coverage/report'
11
11
 
12
12
  /** Options to analyse coverage reports */
13
13
  export interface CoverageOptions {
14
14
  /** The bias for source map analisys (defaults to `greatest_lower_bound`) */
15
15
  sourceMapBias?: SourceMapBias
16
- /** Minimum _overall_ coverage (as a percentage) */
16
+ /** Minimum _overall_ coverage (as a percentage, defaults to 50) */
17
17
  minimumCoverage?: number,
18
- /** Optimal _overall_ coverage (as a percentage) */
18
+ /** Optimal _overall_ coverage (as a percentage, defaults to 50) */
19
19
  optimalCoverage?: number,
20
- /** Minimum _per-file_ coverage (as a percentage) */
20
+ /** Minimum _per-file_ coverage (as a percentage, defaults to 75) */
21
21
  minimumFileCoverage?: number,
22
- /** Optimal _per-file_ coverage (as a percentage) */
22
+ /** Optimal _per-file_ coverage (as a percentage, defaults to 75) */
23
23
  optimalFileCoverage?: number,
24
24
  }
25
25
 
@@ -28,35 +28,58 @@ export interface CoverageReportOptions extends CoverageOptions {
28
28
  reportDir: string,
29
29
  }
30
30
 
31
- /**
32
- * The {@link Coverage} plug type is inferred from the constructor, so this
33
- * type helps to declare the correct types as we can't really infer them from
34
- * `typeof Coverage`...
35
- */
36
- type CoverageConstructor = {
37
- new (coverageDir: string): Coverage<CoverageOptions>
38
- new (coverageDir: string, options: CoverageOptions): Coverage<CoverageOptions>
39
- new (coverageDir: string, options: CoverageReportOptions): Coverage<CoverageReportOptions>
31
+ declare module '../pipe' {
32
+ export interface Pipe {
33
+ /**
34
+ * Analyse coverage using files generated by V8/NodeJS.
35
+ *
36
+ * @param coverageDir The directory where the `coverage-XXX.json` files
37
+ * generated by V8/NodeJS can be found.
38
+ */
39
+ coverage(coverageDir: string): Promise<undefined>
40
+ /**
41
+ * Analyse coverage using files generated by V8/NodeJS.
42
+ *
43
+ * @param coverageDir The directory where the `coverage-XXX.json` files
44
+ * generated by V8/NodeJS can be found.
45
+ * @param options Extra {@link CoverageOptions | options} allowing to
46
+ * specify coverage thresholds.
47
+ */
48
+ coverage(coverageDir: string, options: CoverageOptions): Promise<undefined>
49
+ /**
50
+ * Analyse coverage using files generated by V8/NodeJS and produce an HTML
51
+ * report in the directory specified in `options`.
52
+ *
53
+ * @param coverageDir The directory where the `coverage-XXX.json` files
54
+ * generated by V8/NodeJS can be found.
55
+ * @param options Extra {@link CoverageOptions | options} allowing to
56
+ * specify coverage thresholds where the HTML report should
57
+ * be written to.
58
+ */
59
+ coverage(coverageDir: string, options: CoverageReportOptions): Pipe
60
+ }
40
61
  }
41
62
 
42
- /** Analyse coverage using files generated by V8/NodeJS. */
43
- export class Coverage<
44
- T extends CoverageOptions | CoverageReportOptions,
45
- > implements Plug<T extends CoverageReportOptions ? Files : undefined> {
46
- constructor(coverageDir: string)
47
- constructor(coverageDir: string, options?: T)
63
+ /* ========================================================================== *
64
+ * INSTALLATION / IMPLEMENTATION *
65
+ * ========================================================================== */
66
+
67
+ install('coverage', class Coverage implements Plug<Files | undefined> {
68
+ constructor(...args: PipeParameters<'coverage'>)
48
69
  constructor(
49
70
  private readonly _coverageDir: string,
50
71
  private readonly _options: Partial<CoverageReportOptions> = {},
51
72
  ) {}
52
73
 
53
- async pipe(files: Files, run: Run): Promise<T extends CoverageReportOptions ? Files : undefined> {
54
- const coverageFiles = await run.find('coverage-*.json', {
55
- directory: this._coverageDir,
56
- })
74
+ async pipe(files: Files, context: Context): Promise<Files | undefined> {
75
+ const coverageDir = context.resolve(this._coverageDir)
76
+ const coverageFiles: AbsolutePath[] = []
77
+ for await (const file of walk(coverageDir, [ 'coverage-*.json' ])) {
78
+ coverageFiles.push(resolveAbsolutePath(coverageDir, file))
79
+ }
57
80
 
58
81
  if (coverageFiles.length === 0) {
59
- fail(`No coverage files found in ${$p(coverageFiles.directory)}`)
82
+ fail(`No coverage files found in ${$p(coverageDir)}`)
60
83
  }
61
84
 
62
85
  const sourceFiles = [ ...files.absolutePaths() ]
@@ -64,15 +87,15 @@ export class Coverage<
64
87
  const ms1 = Date.now()
65
88
  const analyser = await createAnalyser(
66
89
  sourceFiles,
67
- [ ...coverageFiles.absolutePaths() ],
90
+ coverageFiles,
68
91
  this._options.sourceMapBias || 'least_upper_bound',
69
- run.log,
92
+ context.log,
70
93
  )
71
- run.log.info('Parsed', coverageFiles.length, 'coverage files', $ms(Date.now() - ms1))
94
+ context.log.info('Parsed', coverageFiles.length, 'coverage files', $ms(Date.now() - ms1))
72
95
 
73
96
  const ms2 = Date.now()
74
- const report = await coverageReport(analyser, sourceFiles, run.log)
75
- run.log.info('Analysed', sourceFiles.length, 'source files', $ms(Date.now() - ms2))
97
+ const report = await coverageReport(analyser, sourceFiles, context.log)
98
+ context.log.info('Analysed', sourceFiles.length, 'source files', $ms(Date.now() - ms2))
76
99
 
77
100
  analyser.destroy()
78
101
 
@@ -95,7 +118,7 @@ export class Coverage<
95
118
 
96
119
  let fileErrors = 0
97
120
  let fileWarnings = 0
98
- const _report = run.report('Coverage report')
121
+ const _report = context.log.report('Coverage report')
99
122
 
100
123
  for (const [ _file, result ] of Object.entries(report.results)) {
101
124
  const { coverage, totalNodes } = result.nodeCoverage
@@ -135,7 +158,8 @@ export class Coverage<
135
158
  if (this._options.reportDir == null) return _report.done(false) as any
136
159
 
137
160
  /* Create a builder to emit our reports */
138
- const builder = run.files(this._options.reportDir)
161
+ const reportDir = context.resolve(this._options.reportDir)
162
+ const builder = Files.builder(reportDir)
139
163
 
140
164
  /* Thresholds to inject in the report */
141
165
  const date = new Date().toISOString()
@@ -180,17 +204,4 @@ export class Coverage<
180
204
  /* Return emitted files */
181
205
  return builder.build() as any
182
206
  }
183
- }
184
-
185
- /* ========================================================================== *
186
- * INSTALLATION *
187
- * ========================================================================== */
188
-
189
- install('coverage', Coverage)
190
-
191
- declare module '../pipe.js' {
192
- export interface Pipe {
193
- /** Analyse coverage using files generated by V8/NodeJS. */
194
- coverage: PipeExtension<CoverageConstructor>
195
- }
196
- }
207
+ })
@@ -1,35 +1,30 @@
1
- import { Files } from '../files.js'
2
- import { $gry, $p, $und } from '../log.js'
3
- import { install, Plug } from '../pipe.js'
4
- import { Run } from '../run.js'
1
+ import { Files } from '../files'
2
+ import { $gry, $p, $und } from '../log'
3
+ import { install, Plug, Context } from '../pipe'
5
4
 
6
- /** Writes some info about the current {@link Files} being passed around. */
7
- export class Debug implements Plug<Files> {
8
- constructor() {}
9
-
10
- async pipe(files: Files, run: Run): Promise<Files> {
11
- run.log.notice('Debugging', files.length, 'files')
12
- run.log.notice('- base dir:', $p(run.resolve('@')))
13
- run.log.notice('- build file dir:', $p(run.resolve('.')))
14
- run.log.notice('- files dir:', $p(files.directory))
15
- if (files.length) {
16
- const [ path, ...paths ] = files
17
- run.log.notice('- relative paths:', $und($gry(path)))
18
- for (const p of paths) run.log.notice('- :', $und($gry(p)))
19
- }
20
- return files
5
+ declare module '../pipe' {
6
+ export interface Pipe {
7
+ /** Log some info about the current {@link Files} being passed around. */
8
+ debug(): Pipe
21
9
  }
22
10
  }
23
11
 
24
12
  /* ========================================================================== *
25
- * INSTALLATION *
13
+ * INSTALLATION / IMPLEMENTATION *
26
14
  * ========================================================================== */
27
15
 
28
- install('debug', Debug)
29
-
30
- declare module '../pipe.js' {
31
- export interface Pipe {
32
- /** Writes some info about the current {@link Files} being passed around. */
33
- debug: PipeExtension<typeof Debug>
16
+ /** Writes some info about the current {@link Files} being passed around. */
17
+ install('debug', class Debug implements Plug<Files> {
18
+ async pipe(files: Files, context: Context): Promise<Files> {
19
+ context.log.notice('Debugging', files.length, 'files')
20
+ context.log.notice('- base dir:', $p(context.resolve('@')))
21
+ context.log.notice('- build file dir:', $p(context.resolve('.')))
22
+ context.log.notice('- files dir:', $p(files.directory))
23
+ if (files.length) {
24
+ const [ path, ...paths ] = files
25
+ context.log.notice('- relative paths:', $und($gry(path)))
26
+ for (const p of paths) context.log.notice('- :', $und($gry(p)))
27
+ }
28
+ return files
34
29
  }
35
- }
30
+ })
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path'
2
2
 
3
3
  import { Plugin } from 'esbuild'
4
- import { assertAbsolutePath, resolveFile, resolveAbsolutePath } from '../../paths.js'
5
- import { stat } from '../../utils/asyncfs.js'
4
+ import { assertAbsolutePath, resolveAbsolutePath, resolveFile } from '../../paths'
5
+ import { stat } from '../../utils/asyncfs'
6
6
 
7
7
  /**
8
8
  * A simple ESBuild plugin fixing extensions for `require` and `import` calls.
@@ -1,23 +1,41 @@
1
1
  import { build, BuildFailure, BuildOptions, BuildResult, Format, Message, Metafile } from 'esbuild'
2
2
  import { basename } from 'node:path'
3
- import { assert } from '../assert.js'
4
- import { Files, FilesBuilder } from '../files.js'
5
- import { $p, ERROR, Logger, ReportLevel, ReportRecord, WARN } from '../log.js'
6
- import { AbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths.js'
7
- import { install, Plug } from '../pipe.js'
8
- import { Run } from '../run.js'
9
- import { readFile } from '../utils/asyncfs.js'
3
+ import { assert } from '../assert'
4
+ import { Files, FilesBuilder } from '../files'
5
+ import { $p, ERROR, Logger, ReportLevel, ReportRecord, WARN } from '../log'
6
+ import { AbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths'
7
+ import { install, PipeParameters, Plug, Context } from '../pipe'
8
+ import { readFile } from '../utils/asyncfs'
10
9
 
11
10
  export type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'>
12
11
 
13
- /**
14
- * Transpile and bundle files with {@link https://esbuild.github.io/ | esbuild}.
15
- */
16
- export class ESBuild implements Plug<Files> {
17
- constructor(options: ESBuildOptions)
12
+ export * from './esbuild/bundle-locals'
13
+ export * from './esbuild/fix-extensions'
14
+
15
+ declare module '../pipe' {
16
+ export interface Pipe {
17
+ /**
18
+ * Transpile and bundle with {@link https://esbuild.github.io/ esbuild}.
19
+ *
20
+ * For documentation on the _options_ to pass to _esbuild_ refer to its
21
+ * {@link https://esbuild.github.io/api/#build-api documentation}.
22
+ *
23
+ * @param options Build {@link ESBuildOptions | options} to pass to esbuild.
24
+ *
25
+ */
26
+ esbuild(options: ESBuildOptions): Pipe
27
+ }
28
+ }
29
+
30
+ /* ========================================================================== *
31
+ * INSTALLATION / IMPLEMENTATION *
32
+ * ========================================================================== */
33
+
34
+ install('esbuild', class ESBuild implements Plug<Files> {
35
+ constructor(...args: PipeParameters<'esbuild'>)
18
36
  constructor(private readonly _options: ESBuildOptions) {}
19
37
 
20
- async pipe(files: Files, run: Run): Promise<Files> {
38
+ async pipe(files: Files, context: Context): Promise<Files> {
21
39
  const entryPoints = [ ...files ]
22
40
  const absWorkingDir = files.directory
23
41
 
@@ -27,7 +45,7 @@ export class ESBuild implements Plug<Files> {
27
45
  target: `node${process.versions['node'].split('.')[0]}`,
28
46
 
29
47
  /* The default format (if not specified in options) is from package.json */
30
- format: this._options.format || await _moduleFormat(files.directory, run.log),
48
+ format: this._options.format || await _moduleFormat(files.directory, context.log),
31
49
 
32
50
  /* Output bese directory */
33
51
  outbase: absWorkingDir,
@@ -48,29 +66,29 @@ export class ESBuild implements Plug<Files> {
48
66
  /* Where to write, where to write? */
49
67
  let builder: FilesBuilder
50
68
  if (options.bundle && options.outfile && (entryPoints.length === 1)) {
51
- builder = run.files(absWorkingDir)
69
+ builder = Files.builder(absWorkingDir)
52
70
  const outputFile = resolveAbsolutePath(absWorkingDir, options.outfile)
53
71
  const entryPoint = resolveAbsolutePath(absWorkingDir, entryPoints[0])
54
72
  options.outfile = outputFile
55
73
 
56
- run.log.debug('Bundling', $p(entryPoint), 'into', $p(outputFile))
74
+ context.log.debug('Bundling', $p(entryPoint), 'into', $p(outputFile))
57
75
  } else {
58
76
  assert(options.outdir, 'Option "outdir" must be specified')
59
77
 
60
- builder = run.files(options.outdir)
78
+ builder = Files.builder(context.resolve(options.outdir))
61
79
  options.outdir = builder.directory
62
80
 
63
81
  const message = options.bundle ? 'Bundling' : 'Transpiling'
64
- run.log.debug(message, entryPoints.length, 'files to', $p(builder.directory))
82
+ context.log.debug(message, entryPoints.length, 'files to', $p(builder.directory))
65
83
  }
66
84
 
67
- const report = run.report('ESBuild Report')
85
+ const report = context.log.report('ESBuild Report')
68
86
 
69
- run.log.trace('Running ESBuild', options)
87
+ context.log.trace('Running ESBuild', options)
70
88
  let esbuild: undefined | (BuildResult & { metafile: Metafile })
71
89
  try {
72
90
  esbuild = await build({ ...options, metafile: true })
73
- run.log.trace('ESBuild Results', esbuild)
91
+ context.log.trace('ESBuild Results', esbuild)
74
92
 
75
93
  report.add(...esbuild.warnings.map((m) => convertMessage(WARN, m, absWorkingDir)))
76
94
  report.add(...esbuild.errors.map((m) => convertMessage(ERROR, m, absWorkingDir)))
@@ -86,14 +104,14 @@ export class ESBuild implements Plug<Files> {
86
104
  assert(esbuild, 'ESBuild did not produce any result')
87
105
 
88
106
  for (const file in esbuild.metafile.outputs) {
89
- builder.unchecked(resolveAbsolutePath(absWorkingDir, file))
107
+ builder.add(resolveAbsolutePath(absWorkingDir, file))
90
108
  }
91
109
 
92
110
  const result = builder.build()
93
- run.log.info('ESBuild produced', result.length, 'files into', $p(result.directory))
111
+ context.log.info('ESBuild produced', result.length, 'files into', $p(result.directory))
94
112
  return result
95
113
  }
96
- }
114
+ })
97
115
 
98
116
  function convertMessage(level: ReportLevel, message: Message, directory: AbsolutePath): ReportRecord {
99
117
  const record: ReportRecord = { level, message: message.text }
@@ -109,28 +127,6 @@ function convertMessage(level: ReportLevel, message: Message, directory: Absolut
109
127
  return record
110
128
  }
111
129
 
112
- /* ========================================================================== *
113
- * INSTALLATION *
114
- * ========================================================================== */
115
-
116
- install('esbuild', ESBuild)
117
-
118
- declare module '../pipe.js' {
119
- export interface Pipe {
120
- /**
121
- * Transpile and bundle files with {@link https://esbuild.github.io/ esbuild}.
122
- */
123
- esbuild: PipeExtension<typeof ESBuild>
124
- }
125
- }
126
-
127
- /* ========================================================================== *
128
- * PLUGINS *
129
- * ========================================================================== */
130
-
131
- export * from './esbuild/bundle-locals.js'
132
- export * from './esbuild/fix-extensions.js'
133
-
134
130
  /* ========================================================================== *
135
131
  * DEFAULT MODULE FORMAT FROM PACKAGE.JSON *
136
132
  * ========================================================================== */
@@ -1,42 +1,28 @@
1
1
  import { ESLint as RealESLint } from 'eslint'
2
- import { assert, failure } from '../../assert.js'
3
- import { Files } from '../../files.js'
4
- import { $p, ERROR, NOTICE, WARN } from '../../log.js'
5
- import { getCurrentWorkingDirectory, resolveDirectory, resolveFile, resolveAbsolutePath } from '../../paths.js'
6
- import { Plug } from '../../pipe.js'
7
- import { Run } from '../../run.js'
8
- import { readFile } from '../../utils/asyncfs.js'
9
-
10
- export interface ESLintOptions {
11
- /** ESLint's own _current working directory_, where config files are. */
12
- directory?: string
13
- /** Show sources in report? */
14
- showSources?: boolean
15
- /**
16
- * ESLint's _override_ configuration file: configurations specified in this
17
- * file will override any other configuration specified elsewhere.
18
- */
19
- configFile?: string
20
- }
21
-
22
- /** Writes some info about the current {@link Files} being passed around. */
23
- export default class ESLint implements Plug<undefined> {
2
+ import { assert, failure } from '../../assert'
3
+ import { Files } from '../../files'
4
+ import { $p, ERROR, NOTICE, WARN } from '../../log'
5
+ import { getCurrentWorkingDirectory, resolveAbsolutePath, resolveDirectory, resolveFile } from '../../paths'
6
+ import { PipeParameters, Plug, Context } from '../../pipe'
7
+ import { readFile } from '../../utils/asyncfs'
8
+ import { ESLintOptions } from '../eslint'
9
+
10
+ /** Runner implementation for the `ESLint` plug. */
11
+ export default class ESLint implements Plug<void> {
24
12
  private readonly _options: Readonly<ESLintOptions>
25
13
 
26
- constructor()
27
- constructor(configFile: string)
28
- constructor(options: ESLintOptions)
14
+ constructor(...arg: PipeParameters<'eslint'>)
29
15
  constructor(arg: string | ESLintOptions = {}) {
30
16
  this._options = typeof arg === 'string' ? { configFile: arg } : arg
31
17
  }
32
18
 
33
- async pipe(files: Files, run: Run): Promise<undefined> {
19
+ async pipe(files: Files, context: Context): Promise<void> {
34
20
  const { directory, configFile } = this._options
35
21
 
36
- const cwd = directory ? run.resolve(directory) : getCurrentWorkingDirectory()
22
+ const cwd = directory ? context.resolve(directory) : getCurrentWorkingDirectory()
37
23
  assert(resolveDirectory(cwd), `ESLint directory ${$p(cwd)} does not exist`)
38
24
 
39
- const overrideConfigFile = configFile ? run.resolve(configFile) : undefined
25
+ const overrideConfigFile = configFile ? context.resolve(configFile) : undefined
40
26
  if (overrideConfigFile) {
41
27
  assert(resolveFile(overrideConfigFile), `ESLint configuration ${$p(overrideConfigFile)} does not exist`)
42
28
  }
@@ -58,7 +44,7 @@ export default class ESLint implements Plug<undefined> {
58
44
  const summary = settlements.reduce((summary, settlement, i) => {
59
45
  /* Promise rejected, meaining hard failure */
60
46
  if (settlement.status === 'rejected') {
61
- run.log.error('Error linting', $p(paths[i]), settlement.reason)
47
+ context.log.error('Error linting', $p(paths[i]), settlement.reason)
62
48
  summary.failures ++
63
49
  return summary
64
50
  }
@@ -76,7 +62,7 @@ export default class ESLint implements Plug<undefined> {
76
62
  if (failures) throw failure() // already logged above
77
63
 
78
64
  /* Create our report */
79
- const report = run.report('ESLint Report')
65
+ const report = context.log.report('ESLint Report')
80
66
 
81
67
  /* Convert ESLint results into our report records */
82
68
  for (const result of results) {
@@ -107,6 +93,5 @@ export default class ESLint implements Plug<undefined> {
107
93
 
108
94
  /* Emit our report and fail on errors */
109
95
  report.done(this._options.showSources)
110
- return undefined
111
96
  }
112
97
  }
@@ -0,0 +1,42 @@
1
+ import { requireResolve } from '../paths'
2
+ import { installForking } from '../pipe'
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'))