@plugjs/plug 0.4.7 → 0.4.8
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/asserts.mjs +6 -0
- package/dist/asserts.mjs.map +1 -1
- package/dist/async.mjs +6 -0
- package/dist/async.mjs.map +1 -1
- package/dist/build.mjs +6 -0
- package/dist/build.mjs.map +1 -1
- package/dist/cli.mjs +6 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/files.mjs +6 -0
- package/dist/files.mjs.map +1 -1
- package/dist/fork.mjs +6 -0
- package/dist/fork.mjs.map +1 -1
- package/dist/fs.mjs +6 -0
- package/dist/fs.mjs.map +1 -1
- package/dist/helpers.mjs +6 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -1
- package/dist/logging/colors.cjs +3 -5
- package/dist/logging/colors.cjs.map +1 -1
- package/dist/logging/colors.d.ts +1 -1
- package/dist/logging/colors.mjs +9 -5
- package/dist/logging/colors.mjs.map +1 -1
- package/dist/logging/emit.cjs +11 -11
- package/dist/logging/emit.cjs.map +1 -1
- package/dist/logging/emit.d.ts +3 -3
- package/dist/logging/emit.mjs +16 -10
- package/dist/logging/emit.mjs.map +1 -1
- package/dist/logging/github.cjs +7 -5
- package/dist/logging/github.cjs.map +1 -1
- package/dist/logging/github.mjs +13 -5
- package/dist/logging/github.mjs.map +1 -1
- package/dist/logging/levels.mjs +6 -0
- package/dist/logging/levels.mjs.map +1 -1
- package/dist/logging/logger.cjs +4 -4
- package/dist/logging/logger.cjs.map +1 -1
- package/dist/logging/logger.mjs +11 -5
- package/dist/logging/logger.mjs.map +1 -1
- package/dist/logging/options.cjs +13 -0
- package/dist/logging/options.cjs.map +1 -1
- package/dist/logging/options.d.ts +5 -0
- package/dist/logging/options.mjs +19 -0
- package/dist/logging/options.mjs.map +1 -1
- package/dist/logging/report.mjs +6 -0
- package/dist/logging/report.mjs.map +1 -1
- package/dist/logging/spinner.cjs +5 -2
- package/dist/logging/spinner.cjs.map +1 -1
- package/dist/logging/spinner.mjs +11 -2
- package/dist/logging/spinner.mjs.map +1 -1
- package/dist/logging.mjs +6 -0
- package/dist/logging.mjs.map +1 -1
- package/dist/paths.mjs +6 -0
- package/dist/paths.mjs.map +1 -1
- package/dist/pipe.mjs +6 -0
- package/dist/pipe.mjs.map +1 -1
- package/dist/plugs/build.mjs +6 -0
- package/dist/plugs/build.mjs.map +1 -1
- package/dist/plugs/copy.mjs +6 -0
- package/dist/plugs/copy.mjs.map +1 -1
- package/dist/plugs/debug.mjs +6 -0
- package/dist/plugs/debug.mjs.map +1 -1
- package/dist/plugs/edit.mjs +6 -0
- package/dist/plugs/edit.mjs.map +1 -1
- package/dist/plugs/esbuild/bundle-locals.mjs +6 -0
- package/dist/plugs/esbuild/bundle-locals.mjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs +6 -0
- package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
- package/dist/plugs/esbuild.cjs +10 -1
- package/dist/plugs/esbuild.cjs.map +1 -1
- package/dist/plugs/esbuild.d.ts +4 -1
- package/dist/plugs/esbuild.mjs +16 -1
- package/dist/plugs/esbuild.mjs.map +1 -1
- package/dist/plugs/exec.mjs +6 -0
- package/dist/plugs/exec.mjs.map +1 -1
- package/dist/plugs/exports.mjs +6 -0
- package/dist/plugs/exports.mjs.map +1 -1
- package/dist/plugs/filter.mjs +6 -0
- package/dist/plugs/filter.mjs.map +1 -1
- package/dist/plugs/rmf.mjs +6 -0
- package/dist/plugs/rmf.mjs.map +1 -1
- package/dist/plugs.mjs +6 -0
- package/dist/plugs.mjs.map +1 -1
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/caller.mjs +6 -0
- package/dist/utils/caller.mjs.map +1 -1
- package/dist/utils/diff.mjs +6 -0
- package/dist/utils/diff.mjs.map +1 -1
- package/dist/utils/exec.mjs +6 -0
- package/dist/utils/exec.mjs.map +1 -1
- package/dist/utils/match.mjs +6 -0
- package/dist/utils/match.mjs.map +1 -1
- package/dist/utils/options.mjs +6 -0
- package/dist/utils/options.mjs.map +1 -1
- package/dist/utils/singleton.mjs +6 -0
- package/dist/utils/singleton.mjs.map +1 -1
- package/dist/utils/walk.mjs +6 -0
- package/dist/utils/walk.mjs.map +1 -1
- package/dist/utils.mjs +6 -0
- package/dist/utils.mjs.map +1 -1
- package/package.json +2 -2
- package/src/logging/colors.ts +10 -4
- package/src/logging/emit.ts +11 -11
- package/src/logging/github.ts +8 -3
- package/src/logging/logger.ts +5 -5
- package/src/logging/options.ts +18 -1
- package/src/logging/spinner.ts +6 -2
- package/src/plugs/esbuild.ts +20 -2
package/src/logging/emit.ts
CHANGED
|
@@ -40,8 +40,8 @@ export type LogEmitter = (options: LogEmitterOptions, args: any[]) => void
|
|
|
40
40
|
|
|
41
41
|
/* ========================================================================== */
|
|
42
42
|
|
|
43
|
-
/** Emit in full colors! */
|
|
44
|
-
export const
|
|
43
|
+
/** Emit in full colors with spinner support and whatnot! */
|
|
44
|
+
export const emitFancy: LogEmitter = (options: LogEmitterOptions, args: any[]): void => {
|
|
45
45
|
const { taskName, level, prefix = '', indent = 0 } = options
|
|
46
46
|
const logPrefix = ''.padStart(indent * _indentSize) + prefix
|
|
47
47
|
|
|
@@ -50,7 +50,7 @@ export const emitColor: LogEmitter = (options: LogEmitterOptions, args: any[]):
|
|
|
50
50
|
|
|
51
51
|
/* Task name or blank padding */
|
|
52
52
|
prefixes.push(''.padStart(_taskLength - taskName.length, ' ')) // padding
|
|
53
|
-
prefixes.push(`${$t(taskName)}`) // task name
|
|
53
|
+
prefixes.push(`${$t(taskName, false)}`) // task name
|
|
54
54
|
|
|
55
55
|
/* Level indicator (our little colorful squares) */
|
|
56
56
|
if (level <= TRACE) {
|
|
@@ -83,7 +83,7 @@ export const emitColor: LogEmitter = (options: LogEmitterOptions, args: any[]):
|
|
|
83
83
|
|
|
84
84
|
/* ========================================================================== */
|
|
85
85
|
|
|
86
|
-
/** Emit in plain text
|
|
86
|
+
/** Emit in plain text (maybe with some colors?) */
|
|
87
87
|
export const emitPlain: LogEmitter = (options: LogEmitterOptions, args: any[]): void => {
|
|
88
88
|
const { taskName, level, prefix = '', indent = 0 } = options
|
|
89
89
|
const logPrefix = ''.padStart(indent * _indentSize) + prefix
|
|
@@ -91,20 +91,20 @@ export const emitPlain: LogEmitter = (options: LogEmitterOptions, args: any[]):
|
|
|
91
91
|
const prefixes: string[] = []
|
|
92
92
|
|
|
93
93
|
const pad = ''.padStart(_taskLength - taskName.length, ' ')
|
|
94
|
-
prefixes.push(`${pad}${taskName}`)
|
|
94
|
+
prefixes.push(`${pad}${$t(taskName, false)}`)
|
|
95
95
|
|
|
96
96
|
if (level <= TRACE) {
|
|
97
|
-
prefixes.push('
|
|
97
|
+
prefixes.push(` ${$gry('\u2502')} ${$gry(' trace')} ${$gry('\u2502')} `)
|
|
98
98
|
} else if (level <= DEBUG) {
|
|
99
|
-
prefixes.push('
|
|
99
|
+
prefixes.push(` ${$gry('\u2502')} ${$gry(' debug')} ${$gry('\u2502')} `)
|
|
100
100
|
} else if (level <= INFO) {
|
|
101
|
-
prefixes.push('
|
|
101
|
+
prefixes.push(` ${$gry('\u2502')} ${$grn(' info')} ${$gry('\u2502')} `)
|
|
102
102
|
} else if (level <= NOTICE) {
|
|
103
|
-
prefixes.push('
|
|
103
|
+
prefixes.push(` ${$gry('\u2502')} ${$blu('notice')} ${$gry('\u2502')} `)
|
|
104
104
|
} else if (level <= WARN) {
|
|
105
|
-
prefixes.push('
|
|
105
|
+
prefixes.push(` ${$gry('\u2502')} ${$ylw(' warn')} ${$gry('\u2502')} `)
|
|
106
106
|
} else {
|
|
107
|
-
prefixes.push('
|
|
107
|
+
prefixes.push(` ${$gry('\u2502')} ${$red(' error')} ${$gry('\u2502')} `)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/* The prefix (task name and level) */
|
package/src/logging/github.ts
CHANGED
|
@@ -5,14 +5,17 @@ import { logOptions } from './options'
|
|
|
5
5
|
|
|
6
6
|
import type { AbsolutePath } from '../paths'
|
|
7
7
|
|
|
8
|
+
/* Strip ANSI from strings */
|
|
9
|
+
const ansiRegExp = new RegExp([
|
|
10
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
11
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
|
|
12
|
+
].join('|'), 'g')
|
|
8
13
|
|
|
9
14
|
/* Initial values, and subscribe to changes */
|
|
10
|
-
let _colors = logOptions.colors
|
|
11
15
|
let _output = logOptions.output
|
|
12
16
|
let _inspectOptions = logOptions.inspectOptions
|
|
13
17
|
let _githubAnnotations = logOptions.githubAnnotations
|
|
14
18
|
logOptions.on('changed', (options) => {
|
|
15
|
-
_colors = options.colors
|
|
16
19
|
_output = options.output
|
|
17
20
|
_githubAnnotations = options.githubAnnotations
|
|
18
21
|
_inspectOptions = { ...options.inspectOptions, breakLength: Infinity }
|
|
@@ -21,6 +24,7 @@ logOptions.on('changed', (options) => {
|
|
|
21
24
|
|
|
22
25
|
function escapeData(data: string): string {
|
|
23
26
|
return data
|
|
27
|
+
.replace(ansiRegExp, '')
|
|
24
28
|
.replace(/%/g, '%25')
|
|
25
29
|
.replace(/\r/g, '%0D')
|
|
26
30
|
.replace(/\n/g, '%0A')
|
|
@@ -28,6 +32,7 @@ function escapeData(data: string): string {
|
|
|
28
32
|
|
|
29
33
|
function escapeProp(prop: string | number): string {
|
|
30
34
|
return `${prop}`
|
|
35
|
+
.replace(ansiRegExp, '')
|
|
31
36
|
.replace(/%/g, '%25')
|
|
32
37
|
.replace(/\r/g, '%0D')
|
|
33
38
|
.replace(/\n/g, '%0A')
|
|
@@ -51,7 +56,7 @@ export function githubAnnotation(type: GithubAnnotationType, message: string, ..
|
|
|
51
56
|
export function githubAnnotation(options: GithubAnnotationOptions, message: string, ...args: any[]): void
|
|
52
57
|
|
|
53
58
|
export function githubAnnotation(options: GithubAnnotationType | GithubAnnotationOptions, ...args: any[]): void {
|
|
54
|
-
if (
|
|
59
|
+
if (! _githubAnnotations) return
|
|
55
60
|
|
|
56
61
|
if (typeof options === 'string') options = { type: options }
|
|
57
62
|
const { type, ...parameters } = options
|
package/src/logging/logger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatWithOptions } from 'node:util'
|
|
2
2
|
|
|
3
3
|
import { BuildFailure } from '../asserts'
|
|
4
|
-
import {
|
|
4
|
+
import { emitFancy, emitPlain } from './emit'
|
|
5
5
|
import { DEBUG, ERROR, INFO, NOTICE, TRACE, WARN } from './levels'
|
|
6
6
|
import { logOptions } from './options'
|
|
7
7
|
import { ReportImpl } from './report'
|
|
@@ -16,11 +16,11 @@ import type { Report } from './report'
|
|
|
16
16
|
|
|
17
17
|
/* Initial value of log colors, and subscribe to changes */
|
|
18
18
|
let _level = logOptions.level
|
|
19
|
-
let
|
|
19
|
+
let _format = logOptions.format
|
|
20
20
|
let _defaultTaskName = logOptions.defaultTaskName
|
|
21
|
-
logOptions.on('changed', ({ defaultTaskName,
|
|
21
|
+
logOptions.on('changed', ({ defaultTaskName, format, level }) => {
|
|
22
22
|
_defaultTaskName = defaultTaskName
|
|
23
|
-
|
|
23
|
+
_format = format
|
|
24
24
|
_level = level
|
|
25
25
|
})
|
|
26
26
|
|
|
@@ -67,7 +67,7 @@ export interface Logger extends Log {
|
|
|
67
67
|
export function getLogger(task: string = _defaultTaskName): Logger {
|
|
68
68
|
let logger = _loggers.get(task)
|
|
69
69
|
if (! logger) {
|
|
70
|
-
const emitter =
|
|
70
|
+
const emitter = _format === 'fancy' ? emitFancy : emitPlain
|
|
71
71
|
logger = new LoggerImpl(task, emitter)
|
|
72
72
|
_loggers.set(task, logger)
|
|
73
73
|
}
|
package/src/logging/options.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface LogOptions {
|
|
|
18
18
|
level: LogLevel,
|
|
19
19
|
/** Whether to log in colors or not. */
|
|
20
20
|
colors: boolean,
|
|
21
|
+
/** The format of the log to use: `plain` or `fancy`. */
|
|
22
|
+
format: 'plain' | 'fancy',
|
|
21
23
|
/** Whether to enable the tasks spinner or not. */
|
|
22
24
|
spinner: boolean,
|
|
23
25
|
/** Width of the current terminal (if any) or `80`. */
|
|
@@ -62,6 +64,7 @@ class LogOptionsImpl extends EventEmitter implements LogOptions {
|
|
|
62
64
|
private _output: Writable = process.stderr
|
|
63
65
|
private _level: LogLevel = NOTICE
|
|
64
66
|
private _colors = (<NodeJS.WriteStream> this._output).isTTY
|
|
67
|
+
private _format: 'fancy' | 'plain' = this._colors ? 'fancy' : 'plain'
|
|
65
68
|
private _colorsSet = false // have colors been set manually?
|
|
66
69
|
private _spinner = true // by default, the spinner is enabled
|
|
67
70
|
private _lineLength = (<NodeJS.WriteStream> this._output).columns || 80
|
|
@@ -88,8 +91,13 @@ class LogOptionsImpl extends EventEmitter implements LogOptions {
|
|
|
88
91
|
// Other values don't change the value of `options.colors`
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
/* If the `GITHUB_ACTIONS` is `true` then enable annotations */
|
|
94
|
+
/* If the `GITHUB_ACTIONS` is `true` then enable annotations and use plain logs */
|
|
92
95
|
this._githubAnnotations = process.env.GITHUB_ACTIONS === 'true'
|
|
96
|
+
if (this._githubAnnotations) {
|
|
97
|
+
this._colors = true
|
|
98
|
+
this._format = 'plain'
|
|
99
|
+
this._spinner = false
|
|
100
|
+
}
|
|
93
101
|
|
|
94
102
|
/*
|
|
95
103
|
* The `__LOG_OPTIONS` variable is a JSON-serialized `LogOptions` object
|
|
@@ -154,6 +162,15 @@ class LogOptionsImpl extends EventEmitter implements LogOptions {
|
|
|
154
162
|
this._notifyListeners()
|
|
155
163
|
}
|
|
156
164
|
|
|
165
|
+
get format(): 'plain' | 'fancy' {
|
|
166
|
+
return this._format
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
set format(format: 'plain' | 'fancy') {
|
|
170
|
+
this._format = format === 'fancy' ? 'fancy' : 'plain'
|
|
171
|
+
this._notifyListeners()
|
|
172
|
+
}
|
|
173
|
+
|
|
157
174
|
get spinner(): boolean {
|
|
158
175
|
return this._spinner
|
|
159
176
|
}
|
package/src/logging/spinner.ts
CHANGED
|
@@ -14,11 +14,13 @@ export const zapSpinner = '\u001b[0G\u001b[2K'
|
|
|
14
14
|
/* Initial value of log colors, and subscribe to changes */
|
|
15
15
|
let _output = logOptions.output
|
|
16
16
|
let _colors = logOptions.colors
|
|
17
|
+
let _format = logOptions.format
|
|
17
18
|
let _spinner = logOptions.spinner
|
|
18
19
|
let _taskLength = logOptions.taskLength
|
|
19
|
-
logOptions.on('changed', ({ output, colors, spinner, taskLength }) => {
|
|
20
|
+
logOptions.on('changed', ({ output, colors, format, spinner, taskLength }) => {
|
|
20
21
|
_output = output
|
|
21
22
|
_colors = colors
|
|
23
|
+
_format = format
|
|
22
24
|
_spinner = spinner
|
|
23
25
|
_taskLength = taskLength
|
|
24
26
|
setupSpinner()
|
|
@@ -68,5 +70,7 @@ function spin(): void {
|
|
|
68
70
|
/* Start or stop the spinner */
|
|
69
71
|
export function setupSpinner(): void {
|
|
70
72
|
if (_interval) clearInterval(_interval)
|
|
71
|
-
if (_colors && _spinner
|
|
73
|
+
if (_colors && _spinner && (_format === 'fancy')) {
|
|
74
|
+
_interval = setInterval(spin, 150).unref()
|
|
75
|
+
}
|
|
72
76
|
}
|
package/src/plugs/esbuild.ts
CHANGED
|
@@ -15,7 +15,10 @@ import type { Logger, ReportLevel, ReportRecord } from '../logging'
|
|
|
15
15
|
import type { AbsolutePath } from '../paths'
|
|
16
16
|
import type { Context, PipeParameters, Plug } from '../pipe'
|
|
17
17
|
|
|
18
|
-
export type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'>
|
|
18
|
+
export type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'> & {
|
|
19
|
+
/** Add support for `__filename` and `__dirname` in ESM modules (default: `true`). */
|
|
20
|
+
enableEsmPathHelpers?: boolean
|
|
21
|
+
}
|
|
19
22
|
|
|
20
23
|
export * from './esbuild/bundle-locals'
|
|
21
24
|
export * from './esbuild/fix-extensions'
|
|
@@ -46,6 +49,7 @@ install('esbuild', class ESBuild implements Plug<Files> {
|
|
|
46
49
|
async pipe(files: Files, context: Context): Promise<Files> {
|
|
47
50
|
const entryPoints = [ ...files ]
|
|
48
51
|
const absWorkingDir = files.directory
|
|
52
|
+
const { enableEsmPathHelpers = true, ...esbuildOptions } = this._options
|
|
49
53
|
|
|
50
54
|
const options: BuildOptions = {
|
|
51
55
|
/* Default our platform/target to NodeJS, current major version */
|
|
@@ -59,7 +63,7 @@ install('esbuild', class ESBuild implements Plug<Files> {
|
|
|
59
63
|
outbase: absWorkingDir,
|
|
60
64
|
|
|
61
65
|
/* Merge in the caller's options */
|
|
62
|
-
...
|
|
66
|
+
...esbuildOptions,
|
|
63
67
|
|
|
64
68
|
/* Always override */
|
|
65
69
|
absWorkingDir,
|
|
@@ -71,6 +75,20 @@ install('esbuild', class ESBuild implements Plug<Files> {
|
|
|
71
75
|
options.define = Object.assign({ __fileurl: '__filename' }, options.define)
|
|
72
76
|
} else if (options.format === 'esm') {
|
|
73
77
|
options.define = Object.assign({ __fileurl: 'import.meta.url' }, options.define)
|
|
78
|
+
|
|
79
|
+
/* If enabled, add support for `__filename` and `__dirname` in ESM */
|
|
80
|
+
if (enableEsmPathHelpers) {
|
|
81
|
+
options.define['__dirname'] = '__$$_esm_paths_helper.__dirname'
|
|
82
|
+
options.define['__filename'] = '__$$_esm_paths_helper.__filename'
|
|
83
|
+
options.banner = { ...options.banner,
|
|
84
|
+
js: (options.banner?.js || '') +
|
|
85
|
+
';const __$$_esm_paths_helper = await (async() => {\n' +
|
|
86
|
+
' const __filename = (await import("node:url")).fileURLToPath(import.meta.url);\n' +
|
|
87
|
+
' const __dirname = (await import("node:path")).dirname(__filename);\n' +
|
|
88
|
+
' return { __filename, __dirname };\n' +
|
|
89
|
+
'})();',
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
}
|
|
75
93
|
|
|
76
94
|
/* Sanity check on output file/directory */
|