@plugjs/plug 0.4.0 → 0.4.2
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.cjs +1 -1
- package/dist/asserts.cjs.map +1 -1
- package/dist/asserts.mjs +1 -1
- package/dist/asserts.mjs.map +1 -1
- package/dist/async.cjs +5 -20
- package/dist/async.cjs.map +2 -2
- package/dist/async.mjs +5 -20
- package/dist/async.mjs.map +2 -2
- package/dist/build.cjs +95 -70
- package/dist/build.cjs.map +2 -2
- package/dist/build.d.ts +6 -8
- package/dist/build.mjs +92 -67
- package/dist/build.mjs.map +2 -2
- package/dist/cli.mjs +1 -1
- package/dist/files.cjs +5 -3
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.ts +2 -1
- package/dist/files.mjs +11 -4
- package/dist/files.mjs.map +1 -1
- package/dist/helpers.cjs +3 -4
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.mjs +3 -4
- package/dist/helpers.mjs.map +1 -1
- package/dist/logging/options.cjs +3 -10
- package/dist/logging/options.cjs.map +1 -1
- package/dist/logging/options.d.ts +44 -1
- package/dist/logging/options.mjs +3 -10
- package/dist/logging/options.mjs.map +1 -1
- package/dist/plugs/build.cjs +4 -7
- package/dist/plugs/build.cjs.map +1 -1
- package/dist/plugs/build.mjs +2 -5
- package/dist/plugs/build.mjs.map +1 -1
- package/dist/plugs/debug.cjs +7 -9
- package/dist/plugs/debug.cjs.map +1 -1
- package/dist/plugs/debug.mjs +8 -10
- package/dist/plugs/debug.mjs.map +1 -1
- package/dist/types.cjs +12 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +33 -9
- package/dist/types.mjs +5 -0
- package/dist/types.mjs.map +2 -2
- package/dist/utils/diff.cjs +1 -4
- package/dist/utils/diff.cjs.map +1 -1
- package/dist/utils/diff.mjs +1 -4
- package/dist/utils/diff.mjs.map +1 -1
- package/dist/utils/{types.cjs → singleton.cjs} +14 -13
- package/dist/utils/singleton.cjs.map +6 -0
- package/dist/utils/singleton.d.ts +12 -0
- package/dist/utils/singleton.mjs +13 -0
- package/dist/utils/singleton.mjs.map +6 -0
- package/dist/utils.cjs +2 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
- package/src/asserts.ts +1 -1
- package/src/async.ts +6 -29
- package/src/build.ts +151 -117
- package/src/files.ts +14 -6
- package/src/helpers.ts +3 -4
- package/src/logging/options.ts +4 -13
- package/src/plugs/build.ts +2 -15
- package/src/plugs/debug.ts +10 -9
- package/src/types.ts +52 -23
- package/src/utils/diff.ts +1 -6
- package/src/utils/singleton.ts +19 -0
- package/src/utils.ts +1 -1
- package/dist/utils/types.cjs.map +0 -6
- package/dist/utils/types.d.ts +0 -4
- package/dist/utils/types.mjs +0 -12
- package/dist/utils/types.mjs.map +0 -6
- package/src/utils/types.ts +0 -11
package/src/types.ts
CHANGED
|
@@ -38,21 +38,23 @@ export interface State {
|
|
|
38
38
|
* The {@link Task} interface normalizes a task definition, associating it with
|
|
39
39
|
* its build file, its sibling {@link Task}s and available _properties_.
|
|
40
40
|
*/
|
|
41
|
-
export interface Task<T extends Result = Result
|
|
42
|
-
/**
|
|
43
|
-
|
|
41
|
+
export interface Task<T extends Result = Result> {
|
|
42
|
+
/** The unique ID of this {@link Task} */
|
|
43
|
+
readonly id: number,
|
|
44
|
+
/** The _original_ name of this task */
|
|
45
|
+
readonly name: string
|
|
44
46
|
/** All _properties_ siblings to this {@link Task} */
|
|
45
47
|
readonly props: Props
|
|
46
48
|
/** All {@link Tasks} sibling to this {@link Task} */
|
|
47
49
|
readonly tasks: Tasks
|
|
48
50
|
/** The absolute file name where this {@link Task} was defined */
|
|
49
51
|
readonly buildFile: AbsolutePath,
|
|
50
|
-
/** Invoke a task from in the context of a {@link Build} */
|
|
51
|
-
invoke(state: State, taskName: string): Promise<T>
|
|
52
52
|
/** Other {@link Task}s hooked _before_ this one */
|
|
53
53
|
readonly before: Task[]
|
|
54
54
|
/** Other {@link Task}s hooked _after_ this one */
|
|
55
55
|
readonly after: Task[]
|
|
56
|
+
/** Invoke a task from in the context of a {@link Build} */
|
|
57
|
+
invoke(state: State, taskName: string): Promise<T>
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -64,6 +66,12 @@ export type TaskResult = Pipe | Files | void | undefined
|
|
|
64
66
|
/** The {@link TaskDef} type identifies the _definition_ of a task. */
|
|
65
67
|
export type TaskDef<R extends TaskResult = TaskResult> = () => R | Promise<R>
|
|
66
68
|
|
|
69
|
+
/** A callable, compiled {@link Task} from a {@link TaskDef} */
|
|
70
|
+
export type TaskCall<D extends BuildDef = BuildDef, R extends Result = Result> = {
|
|
71
|
+
(props?: Partial<Props<D>>): Promise<R>
|
|
72
|
+
task: Task<R>
|
|
73
|
+
}
|
|
74
|
+
|
|
67
75
|
/* ========================================================================== *
|
|
68
76
|
* TASKS AND PROPERTIES *
|
|
69
77
|
* ========================================================================== */
|
|
@@ -75,12 +83,12 @@ export type Props<D extends BuildDef = BuildDef> = {
|
|
|
75
83
|
|
|
76
84
|
/** A type identifying all _tasks_ in a {@link Build} */
|
|
77
85
|
export type Tasks<D extends BuildDef = BuildDef> = {
|
|
78
|
-
readonly [ k in string & keyof D as D[k] extends TaskDef |
|
|
86
|
+
readonly [ k in string & keyof D as D[k] extends TaskDef | TaskCall ? k : never ] :
|
|
79
87
|
D[k] extends TaskDef<infer R> ?
|
|
80
|
-
R extends void | undefined ?
|
|
81
|
-
R extends Pipe | Files ?
|
|
88
|
+
R extends void | undefined ? TaskCall<D, undefined> :
|
|
89
|
+
R extends Pipe | Files ? TaskCall<D, Files> :
|
|
82
90
|
never :
|
|
83
|
-
D[k] extends
|
|
91
|
+
D[k] extends TaskCall ? D[k] :
|
|
84
92
|
never
|
|
85
93
|
}
|
|
86
94
|
|
|
@@ -93,7 +101,7 @@ export type Tasks<D extends BuildDef = BuildDef> = {
|
|
|
93
101
|
* all its properties and tasks.
|
|
94
102
|
*/
|
|
95
103
|
export interface BuildDef {
|
|
96
|
-
[ k : string ] : string | TaskDef |
|
|
104
|
+
[ k : string ] : string | TaskDef | TaskCall
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
/**
|
|
@@ -101,24 +109,45 @@ export interface BuildDef {
|
|
|
101
109
|
* {@link TaskDef | task definitions }.
|
|
102
110
|
*/
|
|
103
111
|
export type ThisBuild<D extends BuildDef> = {
|
|
104
|
-
readonly [ k in keyof D ] :
|
|
105
|
-
k extends
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
R extends Files ? () => Pipe :
|
|
113
|
-
never :
|
|
114
|
-
D[k] extends string ?
|
|
115
|
-
string :
|
|
112
|
+
readonly [ k in keyof D as k extends string ? k : never ] :
|
|
113
|
+
D[k] extends TaskDef<infer R> ?
|
|
114
|
+
R extends Promise<undefined> | void | undefined ? () => Promise<undefined> :
|
|
115
|
+
R extends Pipe | Files ? () => Pipe :
|
|
116
|
+
never :
|
|
117
|
+
D[k] extends TaskCall<any, infer R> ?
|
|
118
|
+
R extends undefined ? () => Promise<undefined> :
|
|
119
|
+
R extends Files ? () => Pipe :
|
|
116
120
|
never :
|
|
121
|
+
D[k] extends string ?
|
|
122
|
+
string :
|
|
117
123
|
never
|
|
118
124
|
}
|
|
119
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Symbol indicating that an object is a {@link Build}.
|
|
128
|
+
*
|
|
129
|
+
* In a compiled {@link Build} this symbol will be associated with a function
|
|
130
|
+
* taking an array of strings (task names) and record of props to override
|
|
131
|
+
*/
|
|
132
|
+
export const buildMarker = Symbol.for('plugjs:plug:types:Build')
|
|
133
|
+
|
|
120
134
|
/**
|
|
121
135
|
* The {@link Build} type represents the collection of {@link Task}s
|
|
122
136
|
* and _properties_ compiled from a {@link BuildDef | build definition}.
|
|
123
137
|
*/
|
|
124
|
-
export type Build<D extends BuildDef = BuildDef> =
|
|
138
|
+
export type Build<D extends BuildDef = BuildDef> = Props<D> & Tasks<D> & {
|
|
139
|
+
readonly [buildMarker]: (
|
|
140
|
+
tasks: readonly string[],
|
|
141
|
+
props?: Record<string, string | undefined>,
|
|
142
|
+
) => Promise<void>
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A type identifying all _task names_ in a {@link Build}. */
|
|
146
|
+
export type BuildTasks<B extends Build> = string & keyof {
|
|
147
|
+
[ name in keyof B as B[name] extends Function ? name : never ] : any
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A type identifying a subset of _properties_ for a {@link Build}. */
|
|
151
|
+
export type BuildProps<B extends Build> = {
|
|
152
|
+
[ name in keyof B as B[name] extends string ? name : never ]? : string
|
|
153
|
+
}
|
package/src/utils/diff.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { inspect, isDeepStrictEqual } from 'node:util'
|
|
|
3
3
|
|
|
4
4
|
import { assert } from '../asserts'
|
|
5
5
|
import { $grn, $red, logOptions } from '../logging'
|
|
6
|
-
import { getTypeOf } from './types'
|
|
7
6
|
|
|
8
7
|
import type { InspectOptions } from 'node:util'
|
|
9
8
|
|
|
@@ -326,13 +325,9 @@ export function textDiff(
|
|
|
326
325
|
let lhsLines: string[]
|
|
327
326
|
let rhsLines: string[]
|
|
328
327
|
|
|
329
|
-
// Get the _real_ types of both arguments
|
|
330
|
-
const lhsType = getTypeOf(lhs)
|
|
331
|
-
const rhsType = getTypeOf(rhs)
|
|
332
|
-
|
|
333
328
|
// If _both_ arguments are strings, then just split and compare, otherwise
|
|
334
329
|
// we nuse NodeJS' inspect to prep their string version
|
|
335
|
-
if ((
|
|
330
|
+
if ((typeof lhs === 'string') && (typeof rhs === 'string')) {
|
|
336
331
|
lhsLines = lhs.split('\n')
|
|
337
332
|
rhsLines = rhs.split('\n')
|
|
338
333
|
} else {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the instance of a _singleton_ variable.
|
|
3
|
+
*
|
|
4
|
+
* Sometimes we need unique instances _per process_ (for example our async
|
|
5
|
+
* context). The problem is that the code might get called from two (or three)
|
|
6
|
+
* different versions of this file: the .cjs transpiled code, the .mjs
|
|
7
|
+
* transpiled one, or the .ts dynamically transpiled by our dynamic loader.
|
|
8
|
+
*
|
|
9
|
+
* A _singleton_ associates an instance with a symbol in `globalThis` and ensure
|
|
10
|
+
* there is only _one_ instance per process (per `globalThis`).
|
|
11
|
+
*/
|
|
12
|
+
export function getSingleton<T>(symbol: symbol, factory: () => T): T {
|
|
13
|
+
const anyGlobalThis = globalThis as any
|
|
14
|
+
if (anyGlobalThis[symbol]) return anyGlobalThis[symbol] as T
|
|
15
|
+
|
|
16
|
+
const value = factory()
|
|
17
|
+
Object.defineProperty(anyGlobalThis, symbol, { value })
|
|
18
|
+
return value
|
|
19
|
+
}
|
package/src/utils.ts
CHANGED
package/dist/utils/types.cjs.map
DELETED
package/dist/utils/types.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** A type adding the values `null` or `array` to the result of `typeof` */
|
|
2
|
-
export type BasicType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'null' | 'array';
|
|
3
|
-
/** Get the _real_ type of a value, including `null` or `array` */
|
|
4
|
-
export declare function getTypeOf(what: unknown): BasicType;
|
package/dist/utils/types.mjs
DELETED
package/dist/utils/types.mjs.map
DELETED
package/src/utils/types.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** A type adding the values `null` or `array` to the result of `typeof` */
|
|
2
|
-
export type BasicType =
|
|
3
|
-
| 'string' | 'number' | 'bigint' | 'boolean' | 'symbol'
|
|
4
|
-
| 'undefined' | 'object' | 'function' | 'null' | 'array'
|
|
5
|
-
|
|
6
|
-
/** Get the _real_ type of a value, including `null` or `array` */
|
|
7
|
-
export function getTypeOf(what: unknown): BasicType {
|
|
8
|
-
if (Array.isArray(what)) return 'array'
|
|
9
|
-
if (what === null) return 'null'
|
|
10
|
-
return typeof what
|
|
11
|
-
}
|