@plugjs/plug 0.0.17 → 0.0.19
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/assert.cjs +3 -3
- package/dist/assert.cjs.map +1 -1
- package/dist/assert.d.ts +1 -1
- package/dist/assert.mjs +3 -3
- package/dist/assert.mjs.map +1 -1
- package/dist/build.cjs +2 -5
- package/dist/build.cjs.map +1 -1
- package/dist/build.mjs +4 -7
- package/dist/build.mjs.map +1 -1
- package/dist/failure.cjs +17 -6
- package/dist/failure.cjs.map +1 -1
- package/dist/failure.d.ts +5 -6
- package/dist/failure.mjs +17 -6
- package/dist/failure.mjs.map +1 -1
- package/dist/fork.cjs +9 -9
- package/dist/fork.cjs.map +1 -1
- package/dist/fork.mjs +9 -9
- package/dist/fork.mjs.map +1 -1
- package/dist/log/logger.cjs +4 -2
- package/dist/log/logger.cjs.map +1 -1
- package/dist/log/logger.mjs +4 -2
- package/dist/log/logger.mjs.map +1 -1
- package/dist/log/report.cjs +2 -2
- package/dist/log/report.cjs.map +1 -1
- package/dist/log/report.mjs +2 -2
- package/dist/log/report.mjs.map +1 -1
- package/dist/pipe.cjs +37 -15
- package/dist/pipe.cjs.map +1 -1
- package/dist/pipe.d.ts +21 -1
- package/dist/pipe.mjs +36 -14
- package/dist/pipe.mjs.map +1 -1
- package/dist/plugs/eslint/runner.cjs +1 -1
- package/dist/plugs/eslint/runner.cjs.map +1 -1
- package/dist/plugs/eslint/runner.mjs +1 -1
- package/dist/plugs/eslint/runner.mjs.map +1 -1
- package/dist/plugs/mocha/runner.cjs +1 -1
- package/dist/plugs/mocha/runner.cjs.map +1 -1
- package/dist/plugs/mocha/runner.mjs +1 -1
- package/dist/plugs/mocha/runner.mjs.map +1 -1
- package/dist/plugs/tsc/runner.cjs +4 -2
- package/dist/plugs/tsc/runner.cjs.map +1 -1
- package/dist/plugs/tsc/runner.mjs +5 -3
- package/dist/plugs/tsc/runner.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assert.ts +3 -3
- package/src/failure.ts +28 -16
- package/src/fork.ts +9 -9
- package/src/log/logger.ts +11 -4
- package/src/log/report.ts +2 -2
- package/src/pipe.ts +51 -14
- package/src/plugs/eslint/runner.ts +1 -1
- package/src/plugs/mocha/runner.ts +1 -1
- package/src/plugs/tsc/runner.ts +5 -3
package/src/log/logger.ts
CHANGED
|
@@ -85,11 +85,18 @@ class LoggerImpl implements Logger {
|
|
|
85
85
|
private _emit(level: LogLevel, args: [ any, ...any ]): this {
|
|
86
86
|
if (this._level > level) return this
|
|
87
87
|
|
|
88
|
-
//
|
|
88
|
+
// The `BuildFailure` is a bit special case
|
|
89
89
|
const params = args.filter((arg) => {
|
|
90
90
|
if (isBuildFailure(arg)) {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// Filter out any previously logged build failure and mark
|
|
92
|
+
if (arg.logged) return false
|
|
93
|
+
arg.logged = true
|
|
94
|
+
|
|
95
|
+
// If the build failure has any root cause, log those
|
|
96
|
+
arg.errors.forEach((error) => this._emit(level, [ error ]))
|
|
97
|
+
|
|
98
|
+
// Log this only if it has a message
|
|
99
|
+
return !! arg.message
|
|
93
100
|
} else {
|
|
94
101
|
return true
|
|
95
102
|
}
|
|
@@ -148,7 +155,7 @@ class LoggerImpl implements Logger {
|
|
|
148
155
|
|
|
149
156
|
fail(...args: [ any, ...any ]): never {
|
|
150
157
|
this._emit(ERROR, args)
|
|
151
|
-
throw
|
|
158
|
+
throw BuildFailure.fail()
|
|
152
159
|
}
|
|
153
160
|
|
|
154
161
|
enter(): this
|
package/src/log/report.ts
CHANGED
|
@@ -194,7 +194,7 @@ export class ReportImpl implements Report {
|
|
|
194
194
|
if (! messages.length) {
|
|
195
195
|
const options = { taskName: this._task, level: ERROR }
|
|
196
196
|
this._emitter(options, [ 'No message for report record' ])
|
|
197
|
-
throw
|
|
197
|
+
throw BuildFailure.fail()
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
const level = record.level
|
|
@@ -267,7 +267,7 @@ export class ReportImpl implements Report {
|
|
|
267
267
|
done(showSources?: boolean | undefined): void {
|
|
268
268
|
if (showSources == null) showSources = logOptions.showSources
|
|
269
269
|
if (! this.empty) this._emit(showSources)
|
|
270
|
-
if (this.errors) throw
|
|
270
|
+
if (this.errors) throw BuildFailure.fail()
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
private _emit(showSources: boolean): this {
|
package/src/pipe.ts
CHANGED
|
@@ -87,22 +87,59 @@ export class Context {
|
|
|
87
87
|
* ========================================================================== */
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* In pipe chains, we want to keep track of the _leaf_
|
|
90
|
+
* In pipe chains, we want to keep track of the _leaf_ promises (that
|
|
91
91
|
* is, when a derived pipe is created calling `plug` we want to track only the
|
|
92
92
|
* new, derived, promise).
|
|
93
93
|
*
|
|
94
94
|
* We key these _leaf_ promises by _context_ (with a WeakMap), and those will
|
|
95
95
|
* be awaited at the end of the task.
|
|
96
96
|
*/
|
|
97
|
-
const contextPromises = new WeakMap<Context,
|
|
97
|
+
const contextPromises = new WeakMap<Context, ContextPromises>()
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
/**
|
|
100
|
+
* An internal class recording _hot_ (failure will fail the task) and _cold_
|
|
101
|
+
* (failure will be ignored) {@link Promise}s for a task's {@link Context}.
|
|
102
|
+
*/
|
|
103
|
+
export class ContextPromises {
|
|
104
|
+
private readonly _cold = new Set<Promise<Result>>()
|
|
105
|
+
private readonly _hot = new Set<Promise<Result>>()
|
|
106
|
+
|
|
107
|
+
/* Private constructor */
|
|
108
|
+
private constructor(readonly context: Context) {}
|
|
109
|
+
|
|
110
|
+
/** Track a {@link Promise} _hot_ (failure will fail the task) */
|
|
111
|
+
hot(promise: Promise<Result>): void {
|
|
112
|
+
this._cold.delete(promise)
|
|
113
|
+
this._hot.add(promise)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Track a {@link Promise} _cold_ (failure will be ignored) */
|
|
117
|
+
cold(promise: Promise<Result>): void {
|
|
118
|
+
this._hot.delete(promise)
|
|
119
|
+
this._cold.add(promise)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Await all tracked {@link Promise}s, triggering a build failure if any of
|
|
124
|
+
* the _hot_ ones is rejected.
|
|
125
|
+
*/
|
|
126
|
+
static async wait(context: Context): Promise<void> {
|
|
127
|
+
const instance = contextPromises.get(context)
|
|
128
|
+
if (! instance) return
|
|
129
|
+
|
|
130
|
+
await Promise.allSettled([ ...instance._cold ])
|
|
131
|
+
await assertPromises([ ...instance._hot ])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Get a {@link ContextPromises} instance for the given {@link Context} */
|
|
135
|
+
static get(context: Context): ContextPromises {
|
|
136
|
+
let promises = contextPromises.get(context)
|
|
137
|
+
if (! promises) {
|
|
138
|
+
promises = new ContextPromises(context)
|
|
139
|
+
contextPromises.set(context, promises)
|
|
140
|
+
}
|
|
141
|
+
return promises
|
|
104
142
|
}
|
|
105
|
-
return promises
|
|
106
143
|
}
|
|
107
144
|
|
|
108
145
|
/**
|
|
@@ -127,7 +164,7 @@ export class Pipe extends PipeProto implements Promise<Files> {
|
|
|
127
164
|
super()
|
|
128
165
|
|
|
129
166
|
// New "Pipe", remember the promise!
|
|
130
|
-
|
|
167
|
+
ContextPromises.get(_context).hot(_promise)
|
|
131
168
|
}
|
|
132
169
|
|
|
133
170
|
/* ------------------------------------------------------------------------ *
|
|
@@ -152,7 +189,7 @@ export class Pipe extends PipeProto implements Promise<Files> {
|
|
|
152
189
|
onrejected?: ((reason: any) => R2 | PromiseLike<R2>) | null | undefined,
|
|
153
190
|
): Promise<R1 | R2> {
|
|
154
191
|
// We are delegating the handling of this promise to the caller
|
|
155
|
-
|
|
192
|
+
ContextPromises.get(this._context).cold(this._promise)
|
|
156
193
|
return this._promise.then(onfulfilled as (value: Result) => R1 | PromiseLike<R1>, onrejected)
|
|
157
194
|
}
|
|
158
195
|
|
|
@@ -160,13 +197,13 @@ export class Pipe extends PipeProto implements Promise<Files> {
|
|
|
160
197
|
onrejected?: ((reason: any) => R | PromiseLike<R>) | null | undefined,
|
|
161
198
|
): Promise<Files | R> {
|
|
162
199
|
// We are delegating the handling of this promise to the caller
|
|
163
|
-
|
|
200
|
+
ContextPromises.get(this._context).cold(this._promise)
|
|
164
201
|
return this._promise.catch(onrejected) as Promise<Files | R>
|
|
165
202
|
}
|
|
166
203
|
|
|
167
204
|
finally(onfinally?: (() => void) | null | undefined): Promise<Files> {
|
|
168
205
|
// We are delegating the handling of this promise to the caller
|
|
169
|
-
|
|
206
|
+
ContextPromises.get(this._context).cold(this._promise)
|
|
170
207
|
return this._promise.finally(onfinally) as Promise<Files>
|
|
171
208
|
}
|
|
172
209
|
|
|
@@ -182,7 +219,7 @@ export class Pipe extends PipeProto implements Promise<Files> {
|
|
|
182
219
|
const plug = typeof arg === 'function' ? { pipe: arg } : arg
|
|
183
220
|
|
|
184
221
|
// We are creating a new "leaf" Pipe, we can forget our promise
|
|
185
|
-
|
|
222
|
+
ContextPromises.get(this._context).cold(this._promise)
|
|
186
223
|
|
|
187
224
|
// Create and return the new Pipe
|
|
188
225
|
return new Pipe(this._context, this._promise.then(async (result) => {
|
|
@@ -214,7 +251,7 @@ export class Pipe extends PipeProto implements Promise<Files> {
|
|
|
214
251
|
if (pipes.length === 0) return Files.builder(getCurrentWorkingDirectory()).build()
|
|
215
252
|
|
|
216
253
|
// Await for all pipes / files / files promises
|
|
217
|
-
const results = await assertPromises<Files>(pipes
|
|
254
|
+
const results = await assertPromises<Files>(pipes)
|
|
218
255
|
|
|
219
256
|
// Find the common directory between all the Files instances
|
|
220
257
|
const [ firstDir, ...otherDirs ] = results.map((f) => f.directory)
|
|
@@ -60,7 +60,7 @@ export default class ESLint implements Plug<void> {
|
|
|
60
60
|
|
|
61
61
|
/* In case of failures from promises, fail! */
|
|
62
62
|
const { results, failures } = summary
|
|
63
|
-
if (failures) throw
|
|
63
|
+
if (failures) throw BuildFailure.fail()
|
|
64
64
|
|
|
65
65
|
/* Create our report */
|
|
66
66
|
const report = context.log.report('ESLint Report')
|
|
@@ -40,7 +40,7 @@ export default class Mocha implements Plug<void> {
|
|
|
40
40
|
return new Promise((resolve, reject) => {
|
|
41
41
|
try {
|
|
42
42
|
mocha.run((failures) => {
|
|
43
|
-
if (failures) reject(
|
|
43
|
+
if (failures) reject(BuildFailure.fail())
|
|
44
44
|
resolve(undefined)
|
|
45
45
|
})
|
|
46
46
|
} catch (error) {
|
package/src/plugs/tsc/runner.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { assertPromises } from '../../assert'
|
|
|
4
4
|
import { BuildFailure } from '../../failure'
|
|
5
5
|
import { Files } from '../../files'
|
|
6
6
|
import { $p, log } from '../../log'
|
|
7
|
-
import { AbsolutePath, resolveFile } from '../../paths'
|
|
7
|
+
import { AbsolutePath, resolveAbsolutePath, resolveFile } from '../../paths'
|
|
8
8
|
import { Context, PipeParameters, Plug } from '../../pipe'
|
|
9
9
|
import { parseOptions } from '../../utils/options'
|
|
10
10
|
import { TypeScriptHost } from './compiler'
|
|
@@ -96,12 +96,14 @@ export default class Tsc implements Plug<Files> {
|
|
|
96
96
|
promises.push(builder.write(fileName, code).then((file) => {
|
|
97
97
|
log.trace('Written', $p(file))
|
|
98
98
|
}).catch((error) => {
|
|
99
|
-
|
|
99
|
+
const outFile = resolveAbsolutePath(outDir, fileName)
|
|
100
|
+
log.error('Error writing to', $p(outFile), error)
|
|
101
|
+
throw BuildFailure.fail()
|
|
100
102
|
}))
|
|
101
103
|
})
|
|
102
104
|
|
|
103
105
|
/* Await for all files to be written and check */
|
|
104
|
-
await assertPromises(promises
|
|
106
|
+
await assertPromises(promises)
|
|
105
107
|
|
|
106
108
|
/* Update report and fail on errors */
|
|
107
109
|
updateReport(report, result.diagnostics, rootDir)
|