@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/helpers.ts
CHANGED
|
@@ -1,32 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from './
|
|
1
|
+
import { assert } from './assert'
|
|
2
|
+
import { requireContext } from './async'
|
|
3
|
+
import { Files } from './files'
|
|
4
|
+
import { $p, log } from './log'
|
|
5
|
+
import { AbsolutePath, getCurrentWorkingDirectory, resolveDirectory, resolveFile } from './paths'
|
|
6
|
+
import { Pipe } from './pipe'
|
|
7
|
+
import { rm } from './utils/asyncfs'
|
|
8
|
+
import { ParseOptions, parseOptions } from './utils/options'
|
|
9
|
+
import { walk, WalkOptions } from './utils/walk'
|
|
10
|
+
|
|
11
|
+
/* ========================================================================== *
|
|
12
|
+
* EXTERNAL HELPERS *
|
|
13
|
+
* ========================================================================== */
|
|
14
|
+
|
|
15
|
+
/** The {@link FindOptions} interface defines the options for finding files. */
|
|
16
|
+
export interface FindOptions extends WalkOptions {
|
|
17
|
+
/** The directory where to start looking for files. */
|
|
18
|
+
directory?: string
|
|
19
|
+
}
|
|
8
20
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
/** Find files in the current directory using the specified _glob_. */
|
|
22
|
+
export function find(glob: string): Pipe
|
|
23
|
+
/** Find files in the current directory using the specified _globs_. */
|
|
24
|
+
export function find(glob: string, ...globs: string[]): Pipe
|
|
25
|
+
/** Find files using the specified _glob_ and {@link FindOptions | options}. */
|
|
26
|
+
export function find(glob: string, options: FindOptions): Pipe
|
|
27
|
+
/** Find files using the specified _globs_ and {@link FindOptions | options}. */
|
|
28
|
+
export function find(glob: string, ...extra: [...globs: string[], options: FindOptions]): Pipe
|
|
29
|
+
/* Overload */
|
|
30
|
+
export function find(...args: ParseOptions<FindOptions>): Pipe {
|
|
31
|
+
const { params: globs, options } = parseOptions(args, {})
|
|
32
|
+
|
|
33
|
+
const context = requireContext()
|
|
34
|
+
return new Pipe(context, async (): Promise<Files> => {
|
|
35
|
+
const directory = options.directory ?
|
|
36
|
+
context.resolve(options.directory) :
|
|
37
|
+
getCurrentWorkingDirectory()
|
|
38
|
+
|
|
39
|
+
const builder = Files.builder(directory)
|
|
40
|
+
for await (const file of walk(directory, globs, options)) {
|
|
41
|
+
builder.add(file)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return builder.build()
|
|
45
|
+
})
|
|
46
|
+
}
|
|
17
47
|
|
|
18
48
|
/**
|
|
19
49
|
* Recursively remove the specified directory _**(use with care)**_.
|
|
20
50
|
*/
|
|
21
51
|
export async function rmrf(directory: string): Promise<void> {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const dir = run.resolve(directory)
|
|
52
|
+
const context = requireContext()
|
|
53
|
+
const dir = context.resolve(directory)
|
|
25
54
|
|
|
26
55
|
assert(dir !== getCurrentWorkingDirectory(),
|
|
27
56
|
`Cowardly refusing to wipe current working directory ${$p(dir)}`)
|
|
28
57
|
|
|
29
|
-
assert(dir !==
|
|
58
|
+
assert(dir !== context.resolve('@'),
|
|
30
59
|
`Cowardly refusing to wipe build file directory ${$p(dir)}`)
|
|
31
60
|
|
|
32
61
|
if (! resolveDirectory(dir)) {
|
|
@@ -39,95 +68,33 @@ export async function rmrf(directory: string): Promise<void> {
|
|
|
39
68
|
}
|
|
40
69
|
|
|
41
70
|
/**
|
|
42
|
-
*
|
|
71
|
+
* Resolve a (set of) path(s) into an {@link AbsolutePath}.
|
|
43
72
|
*
|
|
44
|
-
*
|
|
73
|
+
* If the path (or first component thereof) starts with `@...`, then the
|
|
74
|
+
* resolved path will be relative to the directory containing the build file
|
|
75
|
+
* where the current task was defined, otherwise it will be relative to the
|
|
76
|
+
* current working directory.
|
|
45
77
|
*/
|
|
46
|
-
export function
|
|
47
|
-
|
|
48
|
-
assert(run, 'Unable to find files outside a running task')
|
|
49
|
-
return run.setLogLevel(level)
|
|
78
|
+
export function resolve(...paths: [ string, ...string[] ]): AbsolutePath {
|
|
79
|
+
return requireContext().resolve(...paths)
|
|
50
80
|
}
|
|
51
81
|
|
|
52
82
|
/**
|
|
53
|
-
*
|
|
83
|
+
* Return an absolute path of the file if it exist on disk.
|
|
54
84
|
*
|
|
55
|
-
*
|
|
56
|
-
* _directory containing the build file where the task was defined_, otherwise
|
|
57
|
-
* it will be relative to the {@link process.cwd | current working directory}.
|
|
58
|
-
*/
|
|
59
|
-
export function resolve(...paths: string[]): AbsolutePath {
|
|
60
|
-
const run = currentRun()
|
|
61
|
-
assert(run, 'Unable to find files outside a running task')
|
|
62
|
-
return run.resolve(...paths)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Create a new {@link Files} instance.
|
|
85
|
+
* See the comments on {@link resolve} to understand how paths are resolved.
|
|
68
86
|
*/
|
|
69
|
-
export function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const run = currentRun()
|
|
73
|
-
assert(run, 'Unable to create files builder outside a running task')
|
|
74
|
-
if (typeof first === 'string') {
|
|
75
|
-
return run.files(first, ...paths)
|
|
76
|
-
} else if (first) {
|
|
77
|
-
return run.files(first)
|
|
78
|
-
} else {
|
|
79
|
-
return run.files()
|
|
80
|
-
}
|
|
87
|
+
export function isFile(...paths: [ string, ...string[] ]): AbsolutePath | undefined {
|
|
88
|
+
const path = requireContext().resolve(...paths)
|
|
89
|
+
return resolveFile(path)
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
/**
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const run = currentRun()
|
|
88
|
-
assert(run, 'Unable to create files builder outside a running task')
|
|
89
|
-
|
|
90
|
-
const promise = Promise.resolve().then(async () => {
|
|
91
|
-
// No arguments, no files... Just convenience!
|
|
92
|
-
if (args.length === 0) return run.pipe(run.files().build())
|
|
93
|
-
|
|
94
|
-
// Resolve all the `Files` instances (might be from other tasks)
|
|
95
|
-
const instances = await Promise.all(args)
|
|
96
|
-
const [ first, ...others ] = instances
|
|
97
|
-
|
|
98
|
-
const firstDir = first.directory
|
|
99
|
-
const otherDirs = others.map((f) => f.directory)
|
|
100
|
-
|
|
101
|
-
const directory = commonPath(firstDir, ...otherDirs)
|
|
102
|
-
|
|
103
|
-
return run.files(directory).merge(first, ...others).build()
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
return run.pipe(promise)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Find files according to the globs and {@link FindOptions} specified.
|
|
93
|
+
* Return an absolute path of the directory if it exist on disk.
|
|
94
|
+
*
|
|
95
|
+
* See the comments on {@link resolve} to understand how paths are resolved.
|
|
111
96
|
*/
|
|
112
|
-
export function
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
return run.find(glob, ...args)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Create a {@link Pipe} from a {@link Files} instance. */
|
|
119
|
-
export function pipe(files: Files | Promise<Files>): Pipe & Promise<Files> {
|
|
120
|
-
const run = currentRun()
|
|
121
|
-
assert(run, 'Unable to create pipes outside a running task')
|
|
122
|
-
return run.pipe(files)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Return an absolute path of the file if it exist on disk */
|
|
126
|
-
export function isFile(...paths: string[]): AbsolutePath | undefined {
|
|
127
|
-
return resolveFile(resolve(...paths))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Return an absolute path of the file if it exist on disk */
|
|
131
|
-
export function isDirectory(...paths: string[]): AbsolutePath | undefined {
|
|
132
|
-
return resolveDirectory(resolve(...paths))
|
|
97
|
+
export function isDirectory(...paths: [ string, ...string[] ]): AbsolutePath | undefined {
|
|
98
|
+
const path = requireContext().resolve(...paths)
|
|
99
|
+
return resolveDirectory(path)
|
|
133
100
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
/// <reference path="../extra/webassembly.d.ts" />
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export * from './plugs.js'
|
|
7
|
-
export * from './log.js'
|
|
8
|
-
export * from './helpers.js'
|
|
3
|
+
export type { AbsolutePath } from './paths'
|
|
4
|
+
export type { Files, FilesBuilder } from './files'
|
|
5
|
+
export { Pipe } from './pipe'
|
|
9
6
|
|
|
10
|
-
//
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
7
|
+
// Our minimal exports
|
|
8
|
+
export * from './assert'
|
|
9
|
+
export * from './build'
|
|
10
|
+
export * from './helpers'
|
|
11
|
+
export * from './log'
|
|
14
12
|
|
|
15
13
|
// PlugJS types
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export type { FindOptions, Run } from './run.js'
|
|
19
|
-
export type { Pipe, Plug, PlugFunction } from './pipe.js'
|
|
20
|
-
export type { Task } from './task.js'
|
|
14
|
+
export * from './plugs'
|
|
15
|
+
export * from './types'
|
package/src/log/colors.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sep } from 'node:path'
|
|
2
|
-
import { AbsolutePath, getCurrentWorkingDirectory, resolveRelativeChildPath } from '../paths
|
|
3
|
-
import { logOptions } from './options
|
|
2
|
+
import { AbsolutePath, getCurrentWorkingDirectory, resolveRelativeChildPath } from '../paths'
|
|
3
|
+
import { logOptions } from './options'
|
|
4
4
|
|
|
5
5
|
/* ========================================================================== */
|
|
6
6
|
|
|
@@ -49,7 +49,7 @@ export function $t(task: string): string {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** Colorize milliseconds. */
|
|
52
|
-
export function $ms(millis: number): string {
|
|
52
|
+
export function $ms(millis: number, note?: string): string {
|
|
53
53
|
let string: string
|
|
54
54
|
if (millis >= 60000) {
|
|
55
55
|
// One minute or more: style is Xm Ys
|
|
@@ -70,6 +70,7 @@ export function $ms(millis: number): string {
|
|
|
70
70
|
// Milliseconds: style is 123ms
|
|
71
71
|
string = `${millis}ms`
|
|
72
72
|
}
|
|
73
|
+
if (note) string = `${note} ${string}`
|
|
73
74
|
return _colors ? `${gry}[${string}]${rst}` : `[${string}]`
|
|
74
75
|
}
|
|
75
76
|
|
package/src/log/emit.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { formatWithOptions } from 'node:util'
|
|
2
|
-
import { $blu, $grn, $gry, $red, $t, $ylw } from './colors
|
|
3
|
-
import { DEBUG, INFO, LogLevel, NOTICE, TRACE, WARN } from './levels
|
|
4
|
-
import { logOptions } from './options
|
|
5
|
-
import { zapSpinner } from './spinner
|
|
2
|
+
import { $blu, $grn, $gry, $red, $t, $ylw } from './colors'
|
|
3
|
+
import { DEBUG, INFO, LogLevel, NOTICE, TRACE, WARN } from './levels'
|
|
4
|
+
import { logOptions } from './options'
|
|
5
|
+
import { zapSpinner } from './spinner'
|
|
6
6
|
|
|
7
7
|
/* ========================================================================== */
|
|
8
8
|
|
package/src/log/logger.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { isBuildError, isBuildFailure } from '../assert
|
|
2
|
-
import { emitColor, emitPlain, LogEmitter } from './emit
|
|
3
|
-
import { DEBUG, ERROR, INFO, LogLevel, NOTICE, TRACE, WARN } from './levels
|
|
4
|
-
import { logOptions } from './options
|
|
1
|
+
import { isBuildError, isBuildFailure } from '../assert'
|
|
2
|
+
import { emitColor, emitPlain, LogEmitter } from './emit'
|
|
3
|
+
import { DEBUG, ERROR, INFO, LogLevel, NOTICE, TRACE, WARN } from './levels'
|
|
4
|
+
import { logOptions } from './options'
|
|
5
|
+
import { Report, ReportImpl } from './report'
|
|
5
6
|
|
|
6
7
|
/* ========================================================================== */
|
|
7
8
|
|
|
@@ -48,6 +49,8 @@ export interface Logger extends Log {
|
|
|
48
49
|
leave(): this
|
|
49
50
|
/** Leave a sub-level of logging, decreasing indent */
|
|
50
51
|
leave(level: LogLevel, message: string): this
|
|
52
|
+
/** Create a {@link Report} associated with this instance */
|
|
53
|
+
report(title: string): Report
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/** Return a {@link Logger} associated with the specified task name. */
|
|
@@ -149,6 +152,7 @@ class LoggerImpl implements Logger {
|
|
|
149
152
|
const [ level, message ] = args
|
|
150
153
|
this._stack.push({ level, message, indent: this._indent })
|
|
151
154
|
}
|
|
155
|
+
|
|
152
156
|
this._indent ++
|
|
153
157
|
return this
|
|
154
158
|
}
|
|
@@ -168,4 +172,8 @@ class LoggerImpl implements Logger {
|
|
|
168
172
|
|
|
169
173
|
return this
|
|
170
174
|
}
|
|
175
|
+
|
|
176
|
+
report(title: string): Report {
|
|
177
|
+
return new ReportImpl(title, this._task, this._emitter)
|
|
178
|
+
}
|
|
171
179
|
}
|
package/src/log/options.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events'
|
|
2
2
|
import { Writable } from 'node:stream'
|
|
3
3
|
import { InspectOptions } from 'node:util'
|
|
4
|
-
import { getLevelNumber, LogLevel, LogLevelString, NOTICE } from './levels
|
|
4
|
+
import { getLevelNumber, LogLevel, LogLevelString, NOTICE } from './levels'
|
|
5
5
|
|
|
6
6
|
/* ========================================================================== */
|
|
7
7
|
|
package/src/log/report.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import { fail, failure } from '../assert
|
|
2
|
-
import { AbsolutePath } from '../paths
|
|
3
|
-
import { readFile } from '../utils/asyncfs
|
|
4
|
-
import { $blu, $cyn, $gry, $red, $und, $wht, $ylw } from './colors
|
|
5
|
-
import {
|
|
6
|
-
import { ERROR, LogLevels, NOTICE, WARN } from './levels
|
|
7
|
-
import { logOptions } from './options
|
|
1
|
+
import { fail, failure } from '../assert'
|
|
2
|
+
import { AbsolutePath } from '../paths'
|
|
3
|
+
import { readFile } from '../utils/asyncfs'
|
|
4
|
+
import { $blu, $cyn, $gry, $red, $und, $wht, $ylw } from './colors'
|
|
5
|
+
import { LogEmitter } from './emit'
|
|
6
|
+
import { ERROR, LogLevels, NOTICE, WARN } from './levels'
|
|
7
|
+
import { logOptions } from './options'
|
|
8
8
|
|
|
9
9
|
/* ========================================================================== */
|
|
10
10
|
|
|
11
|
-
/* Track changes for colors */
|
|
12
|
-
let _colors = logOptions.colors
|
|
13
|
-
logOptions.on('changed', ({ colors }) => {
|
|
14
|
-
_colors = colors
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
/* ========================================================================== *
|
|
18
|
-
|
|
19
11
|
/** Levels used in a {@link Report} */
|
|
20
12
|
export type ReportLevel = LogLevels['NOTICE' | 'WARN' | 'ERROR']
|
|
21
13
|
|
|
@@ -91,12 +83,6 @@ export interface Report {
|
|
|
91
83
|
done(showSources?: boolean | undefined): void
|
|
92
84
|
}
|
|
93
85
|
|
|
94
|
-
/** Create a new {@link Report} with the given title */
|
|
95
|
-
export function createReport(title: string, taskName: string): Report {
|
|
96
|
-
const emitter = _colors ? emitColor : emitPlain
|
|
97
|
-
return new ReportImpl(title, taskName, emitter)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
86
|
/* ========================================================================== *
|
|
101
87
|
* REPORT IMPLEMENTATION *
|
|
102
88
|
* ========================================================================== */
|
|
@@ -118,7 +104,7 @@ interface ReportInternalAnnotation {
|
|
|
118
104
|
readonly note: string
|
|
119
105
|
}
|
|
120
106
|
|
|
121
|
-
class ReportImpl implements Report {
|
|
107
|
+
export class ReportImpl implements Report {
|
|
122
108
|
private readonly _sources = new Map<AbsolutePath, string[]>()
|
|
123
109
|
private readonly _annotations = new Map<AbsolutePath, ReportInternalAnnotation>()
|
|
124
110
|
private readonly _records = new Map<AbsolutePath | Null, Set<ReportInternalRecord>>()
|
package/src/log/spinner.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { runningTasks } from '../async
|
|
2
|
-
import { $cyn, $gry, $t } from './colors
|
|
3
|
-
import { logOptions } from './options
|
|
1
|
+
import { runningTasks } from '../async'
|
|
2
|
+
import { $cyn, $gry, $t } from './colors'
|
|
3
|
+
import { logOptions } from './options'
|
|
4
4
|
|
|
5
5
|
/* ========================================================================== */
|
|
6
6
|
|
package/src/log.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getLogger, Log } from './log/logger
|
|
3
|
-
import { setupSpinner } from './log/spinner
|
|
1
|
+
import { currentContext } from './async'
|
|
2
|
+
import { getLogger, Log } from './log/logger'
|
|
3
|
+
import { setupSpinner } from './log/spinner'
|
|
4
4
|
|
|
5
|
-
export * from './log/colors
|
|
6
|
-
export * from './log/levels
|
|
7
|
-
export * from './log/logger
|
|
8
|
-
export * from './log/options
|
|
9
|
-
export * from './log/report
|
|
5
|
+
export * from './log/colors'
|
|
6
|
+
export * from './log/levels'
|
|
7
|
+
export * from './log/logger'
|
|
8
|
+
export * from './log/options'
|
|
9
|
+
export * from './log/report'
|
|
10
10
|
|
|
11
11
|
/* ========================================================================== *
|
|
12
12
|
* INITIALIZATION *
|
|
@@ -25,7 +25,7 @@ export type LogFunction = ((...args: [ any, ...any ]) => void) & Log
|
|
|
25
25
|
/** Our logging function (defaulting to the `NOTICE` level) */
|
|
26
26
|
export const log: LogFunction = ((): LogFunction => {
|
|
27
27
|
/* Return either the current run's log, or the default task's logger */
|
|
28
|
-
const logger = (): Log => (
|
|
28
|
+
const logger = (): Log => (currentContext()?.log || getLogger())
|
|
29
29
|
|
|
30
30
|
/* Create a Logger wrapping the current logger */
|
|
31
31
|
const wrapper: Log = {
|
package/src/paths.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { statSync } from 'node:fs'
|
|
|
2
2
|
import { createRequire } from 'node:module'
|
|
3
3
|
import { dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path'
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
5
|
-
import { assert } from './assert
|
|
5
|
+
import { assert } from './assert'
|
|
6
6
|
|
|
7
7
|
/** A _branded_ `string` representing an _absolute_ path name */
|
|
8
8
|
export type AbsolutePath = string & { __brand_absolute_path: never }
|