@plugjs/plug 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async.cjs +20 -19
- package/dist/async.cjs.map +1 -1
- package/dist/async.d.ts +9 -9
- package/dist/async.mjs +18 -17
- package/dist/async.mjs.map +1 -1
- package/dist/build.cjs +113 -110
- package/dist/build.cjs.map +2 -2
- package/dist/build.d.ts +14 -56
- package/dist/build.mjs +114 -111
- package/dist/build.mjs.map +2 -2
- package/dist/files.cjs +2 -16
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.ts +3 -10
- package/dist/files.mjs +3 -17
- package/dist/files.mjs.map +1 -1
- package/dist/fork.cjs +28 -40
- package/dist/fork.cjs.map +1 -1
- package/dist/fork.d.ts +6 -27
- package/dist/fork.mjs +29 -40
- package/dist/fork.mjs.map +1 -1
- package/dist/helpers.cjs +27 -61
- package/dist/helpers.cjs.map +2 -2
- package/dist/helpers.d.ts +29 -31
- package/dist/helpers.mjs +27 -62
- package/dist/helpers.mjs.map +2 -2
- package/dist/index.cjs +15 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -13
- package/dist/index.mjs +7 -2
- package/dist/index.mjs.map +1 -1
- package/dist/log/colors.cjs +3 -1
- package/dist/log/colors.cjs.map +1 -1
- package/dist/log/colors.d.ts +2 -2
- package/dist/log/colors.mjs +3 -1
- package/dist/log/colors.mjs.map +1 -1
- package/dist/log/emit.d.ts +1 -1
- package/dist/log/logger.cjs +4 -0
- package/dist/log/logger.cjs.map +1 -1
- package/dist/log/logger.d.ts +4 -1
- package/dist/log/logger.mjs +4 -0
- package/dist/log/logger.mjs.map +1 -1
- package/dist/log/options.d.ts +1 -1
- package/dist/log/report.cjs +2 -11
- package/dist/log/report.cjs.map +1 -1
- package/dist/log/report.d.ts +36 -4
- package/dist/log/report.mjs +1 -10
- package/dist/log/report.mjs.map +1 -1
- package/dist/log.cjs +1 -1
- package/dist/log.cjs.map +1 -1
- package/dist/log.d.ts +6 -6
- package/dist/log.mjs +2 -2
- package/dist/log.mjs.map +1 -1
- package/dist/pipe.cjs +69 -26
- package/dist/pipe.cjs.map +1 -1
- package/dist/pipe.d.ts +178 -119
- package/dist/pipe.mjs +71 -24
- package/dist/pipe.mjs.map +1 -1
- package/dist/plugs/copy.cjs +15 -25
- package/dist/plugs/copy.cjs.map +2 -2
- package/dist/plugs/copy.d.ts +14 -13
- package/dist/plugs/copy.mjs +15 -17
- package/dist/plugs/copy.mjs.map +2 -2
- package/dist/plugs/coverage/analysis.d.ts +2 -2
- package/dist/plugs/coverage/report.cjs +1 -1
- package/dist/plugs/coverage/report.cjs.map +1 -1
- package/dist/plugs/coverage/report.d.ts +3 -3
- package/dist/plugs/coverage/report.mjs +1 -1
- package/dist/plugs/coverage/report.mjs.map +1 -1
- package/dist/plugs/coverage.cjs +20 -26
- package/dist/plugs/coverage.cjs.map +1 -1
- package/dist/plugs/coverage.d.ts +33 -30
- package/dist/plugs/coverage.mjs +21 -19
- package/dist/plugs/coverage.mjs.map +1 -1
- package/dist/plugs/debug.cjs +12 -36
- package/dist/plugs/debug.cjs.map +1 -1
- package/dist/plugs/debug.d.ts +4 -11
- package/dist/plugs/debug.mjs +30 -21
- package/dist/plugs/debug.mjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
- package/dist/plugs/esbuild.cjs +14 -25
- package/dist/plugs/esbuild.cjs.map +1 -1
- package/dist/plugs/esbuild.d.ts +11 -16
- package/dist/plugs/esbuild.mjs +14 -17
- package/dist/plugs/esbuild.mjs.map +1 -1
- package/dist/plugs/eslint/runner.cjs +5 -6
- package/dist/plugs/eslint/runner.cjs.map +1 -1
- package/dist/plugs/eslint/runner.d.ts +6 -20
- package/dist/plugs/eslint/runner.mjs +6 -7
- package/dist/plugs/eslint/runner.mjs.map +1 -1
- package/dist/{task.cjs → plugs/eslint.cjs} +7 -24
- package/dist/plugs/eslint.cjs.map +6 -0
- package/dist/plugs/eslint.d.ts +34 -0
- package/dist/plugs/eslint.mjs +5 -0
- package/dist/plugs/eslint.mjs.map +6 -0
- package/dist/plugs/exec.cjs +20 -24
- package/dist/plugs/exec.cjs.map +1 -1
- package/dist/plugs/exec.d.ts +53 -53
- package/dist/plugs/exec.mjs +20 -23
- package/dist/plugs/exec.mjs.map +1 -1
- package/dist/plugs/filter.cjs +9 -19
- package/dist/plugs/filter.cjs.map +1 -1
- package/dist/plugs/filter.d.ts +21 -15
- package/dist/plugs/filter.mjs +10 -12
- package/dist/plugs/filter.mjs.map +1 -1
- package/dist/plugs/mocha/reporter.cjs +12 -6
- package/dist/plugs/mocha/reporter.cjs.map +1 -1
- package/dist/plugs/mocha/reporter.d.ts +0 -2
- package/dist/plugs/mocha/reporter.mjs +11 -4
- package/dist/plugs/mocha/reporter.mjs.map +1 -1
- package/dist/plugs/mocha/runner.cjs +4 -5
- package/dist/plugs/mocha/runner.cjs.map +1 -1
- package/dist/plugs/mocha/runner.d.ts +5 -31
- package/dist/plugs/mocha/runner.mjs +5 -6
- package/dist/plugs/mocha/runner.mjs.map +1 -1
- package/dist/plugs/mocha.cjs +22 -0
- package/dist/plugs/mocha.cjs.map +6 -0
- package/dist/plugs/mocha.d.ts +35 -0
- package/dist/plugs/mocha.mjs +5 -0
- package/dist/plugs/mocha.mjs.map +6 -0
- package/dist/plugs/rmf.cjs +4 -32
- package/dist/plugs/rmf.cjs.map +1 -1
- package/dist/plugs/rmf.d.ts +8 -12
- package/dist/plugs/rmf.mjs +25 -20
- package/dist/plugs/rmf.mjs.map +1 -1
- package/dist/plugs/tsc/compiler.d.ts +1 -1
- package/dist/plugs/tsc/options.d.ts +1 -1
- package/dist/plugs/tsc/report.d.ts +2 -2
- package/dist/plugs/tsc/runner.cjs +12 -11
- package/dist/plugs/tsc/runner.cjs.map +1 -1
- package/dist/plugs/tsc/runner.d.ts +4 -9
- package/dist/plugs/tsc/runner.mjs +12 -11
- package/dist/plugs/tsc/runner.mjs.map +1 -1
- package/dist/plugs/tsc.cjs +7 -0
- package/dist/plugs/tsc.cjs.map +6 -0
- package/dist/plugs/tsc.d.ts +36 -0
- package/dist/plugs/tsc.mjs +15 -0
- package/dist/plugs/tsc.mjs.map +6 -0
- package/dist/plugs.cjs +3 -5
- package/dist/plugs.cjs.map +1 -1
- package/dist/plugs.d.ts +10 -17
- package/dist/plugs.mjs +3 -5
- package/dist/plugs.mjs.map +1 -1
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +6 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +6 -0
- package/dist/utils/caller.cjs +8 -11
- package/dist/utils/caller.cjs.map +2 -2
- package/dist/utils/caller.d.ts +2 -7
- package/dist/utils/caller.mjs +8 -11
- package/dist/utils/caller.mjs.map +2 -2
- package/dist/utils/options.cjs +4 -6
- package/dist/utils/options.cjs.map +1 -1
- package/dist/utils/options.d.ts +16 -15
- package/dist/utils/options.mjs +4 -6
- package/dist/utils/options.mjs.map +1 -1
- package/dist/utils/walk.d.ts +2 -2
- package/extra/cli.mjs +31 -20
- package/extra/ts-loader.mjs +6 -5
- package/package.json +8 -9
- package/src/async.ts +27 -19
- package/src/files.ts +6 -30
- package/src/fork.ts +35 -76
- package/src/helpers.ts +66 -99
- package/src/index.ts +10 -15
- package/src/log/colors.ts +4 -3
- package/src/log/emit.ts +4 -4
- package/src/log/logger.ts +12 -4
- package/src/log/options.ts +1 -1
- package/src/log/report.ts +8 -22
- package/src/log/spinner.ts +3 -3
- package/src/log.ts +9 -9
- package/src/paths.ts +1 -1
- package/src/pipe.ts +255 -170
- package/src/plugs/copy.ts +40 -31
- package/src/plugs/coverage/analysis.ts +4 -4
- package/src/plugs/coverage/report.ts +6 -5
- package/src/plugs/coverage.ts +64 -53
- package/src/plugs/debug.ts +28 -26
- package/src/plugs/esbuild/fix-extensions.ts +2 -2
- package/src/plugs/esbuild.ts +42 -46
- package/src/plugs/eslint/runner.ts +16 -31
- package/src/plugs/eslint.ts +42 -0
- package/src/plugs/exec.ts +93 -82
- package/src/plugs/filter.ts +42 -27
- package/src/plugs/mocha/reporter.ts +10 -5
- package/src/plugs/mocha/runner.ts +12 -38
- package/src/plugs/mocha.ts +41 -0
- package/src/plugs/rmf.ts +21 -25
- package/src/plugs/tsc/compiler.ts +1 -1
- package/src/plugs/tsc/options.ts +2 -2
- package/src/plugs/tsc/report.ts +2 -2
- package/src/plugs/tsc/runner.ts +24 -30
- package/src/plugs/tsc.ts +45 -0
- package/src/plugs.ts +10 -25
- package/src/types.ts +116 -0
- package/src/utils/caller.ts +11 -22
- package/src/utils/options.ts +49 -17
- package/src/utils/walk.ts +4 -4
- package/dist/run.cjs +0 -90
- package/dist/run.cjs.map +0 -6
- package/dist/run.d.ts +0 -89
- package/dist/run.mjs +0 -65
- package/dist/run.mjs.map +0 -6
- package/dist/task.cjs.map +0 -6
- package/dist/task.d.ts +0 -15
- package/dist/task.mjs +0 -14
- package/dist/task.mjs.map +0 -6
- package/src/run.ts +0 -159
- package/src/task.ts +0 -26
package/src/plugs/coverage.ts
CHANGED
|
@@ -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
|
|
4
|
-
import { Files } from '../files
|
|
5
|
-
import { $gry, $ms, $p, $red, $ylw, ERROR, NOTICE, WARN } from '../log
|
|
6
|
-
import { AbsolutePath } from '../paths
|
|
7
|
-
import { install, Plug } from '../pipe
|
|
8
|
-
import {
|
|
9
|
-
import { createAnalyser, SourceMapBias } from './coverage/analysis
|
|
10
|
-
import { coverageReport, CoverageResult } from './coverage/report
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
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,
|
|
54
|
-
const
|
|
55
|
-
|
|
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(
|
|
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
|
-
|
|
90
|
+
coverageFiles,
|
|
68
91
|
this._options.sourceMapBias || 'least_upper_bound',
|
|
69
|
-
|
|
92
|
+
context.log,
|
|
70
93
|
)
|
|
71
|
-
|
|
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,
|
|
75
|
-
|
|
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 =
|
|
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
|
|
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
|
+
})
|
package/src/plugs/debug.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import { Files } from '../files
|
|
2
|
-
import { $gry, $p, $und } from '../log
|
|
3
|
-
import { install, Plug } from '../pipe
|
|
4
|
-
import { Run } from '../run.js'
|
|
1
|
+
import { Files } from '../files'
|
|
2
|
+
import { $gry, $p, $und, $ylw } from '../log'
|
|
3
|
+
import { install, Plug, Context, PipeParameters } from '../pipe'
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
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(title?: string): Pipe
|
|
21
9
|
}
|
|
22
10
|
}
|
|
23
11
|
|
|
24
12
|
/* ========================================================================== *
|
|
25
|
-
* INSTALLATION
|
|
13
|
+
* INSTALLATION / IMPLEMENTATION *
|
|
26
14
|
* ========================================================================== */
|
|
27
15
|
|
|
28
|
-
|
|
16
|
+
/** Writes some info about the current {@link Files} being passed around. */
|
|
17
|
+
install('debug', class Debug implements Plug<Files> {
|
|
18
|
+
private readonly _title: string
|
|
19
|
+
|
|
20
|
+
constructor(...args: PipeParameters<'debug'>) {
|
|
21
|
+
const [ title = 'Debugging' ] = args
|
|
22
|
+
this._title = title
|
|
23
|
+
}
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
async pipe(files: Files, context: Context): Promise<Files> {
|
|
26
|
+
context.log.notice(this._title, `${$gry('(')}${$ylw(files.length)} ${$gry('files)')}`)
|
|
27
|
+
context.log.notice('- base dir:', $p(context.resolve('@')))
|
|
28
|
+
context.log.notice('- build file dir:', $p(context.resolve('.')))
|
|
29
|
+
context.log.notice('- files dir:', $p(files.directory))
|
|
30
|
+
if (files.length) {
|
|
31
|
+
const [ path, ...paths ] = files
|
|
32
|
+
context.log.notice('- relative paths:', $und($gry(path)))
|
|
33
|
+
for (const p of paths) context.log.notice('- :', $und($gry(p)))
|
|
34
|
+
}
|
|
35
|
+
return files
|
|
34
36
|
}
|
|
35
|
-
}
|
|
37
|
+
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { Plugin } from 'esbuild'
|
|
4
|
-
import { assertAbsolutePath,
|
|
5
|
-
import { stat } from '../../utils/asyncfs
|
|
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.
|
package/src/plugs/esbuild.ts
CHANGED
|
@@ -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
|
|
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, Plug } from '../pipe
|
|
8
|
-
import {
|
|
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
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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,
|
|
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,
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
82
|
+
context.log.debug(message, entryPoints.length, 'files to', $p(builder.directory))
|
|
65
83
|
}
|
|
66
84
|
|
|
67
|
-
const report =
|
|
85
|
+
const report = context.log.report('ESBuild Report')
|
|
68
86
|
|
|
69
|
-
|
|
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
|
-
|
|
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.
|
|
107
|
+
builder.add(resolveAbsolutePath(absWorkingDir, file))
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
const result = builder.build()
|
|
93
|
-
|
|
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
|
|
3
|
-
import { Files } from '../../files
|
|
4
|
-
import { $p, ERROR, NOTICE, WARN } from '../../log
|
|
5
|
-
import { getCurrentWorkingDirectory, resolveDirectory, resolveFile
|
|
6
|
-
import { Plug } from '../../pipe
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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,
|
|
19
|
+
async pipe(files: Files, context: Context): Promise<void> {
|
|
34
20
|
const { directory, configFile } = this._options
|
|
35
21
|
|
|
36
|
-
const cwd = directory ?
|
|
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 ?
|
|
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
|
-
|
|
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 =
|
|
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'))
|