@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.
Files changed (212) hide show
  1. package/dist/async.cjs +20 -19
  2. package/dist/async.cjs.map +1 -1
  3. package/dist/async.d.ts +9 -9
  4. package/dist/async.mjs +18 -17
  5. package/dist/async.mjs.map +1 -1
  6. package/dist/build.cjs +113 -110
  7. package/dist/build.cjs.map +2 -2
  8. package/dist/build.d.ts +14 -56
  9. package/dist/build.mjs +114 -111
  10. package/dist/build.mjs.map +2 -2
  11. package/dist/files.cjs +2 -16
  12. package/dist/files.cjs.map +1 -1
  13. package/dist/files.d.ts +3 -10
  14. package/dist/files.mjs +3 -17
  15. package/dist/files.mjs.map +1 -1
  16. package/dist/fork.cjs +28 -40
  17. package/dist/fork.cjs.map +1 -1
  18. package/dist/fork.d.ts +6 -27
  19. package/dist/fork.mjs +29 -40
  20. package/dist/fork.mjs.map +1 -1
  21. package/dist/helpers.cjs +27 -61
  22. package/dist/helpers.cjs.map +2 -2
  23. package/dist/helpers.d.ts +29 -31
  24. package/dist/helpers.mjs +27 -62
  25. package/dist/helpers.mjs.map +2 -2
  26. package/dist/index.cjs +15 -2
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +9 -13
  29. package/dist/index.mjs +7 -2
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/log/colors.cjs +3 -1
  32. package/dist/log/colors.cjs.map +1 -1
  33. package/dist/log/colors.d.ts +2 -2
  34. package/dist/log/colors.mjs +3 -1
  35. package/dist/log/colors.mjs.map +1 -1
  36. package/dist/log/emit.d.ts +1 -1
  37. package/dist/log/logger.cjs +4 -0
  38. package/dist/log/logger.cjs.map +1 -1
  39. package/dist/log/logger.d.ts +4 -1
  40. package/dist/log/logger.mjs +4 -0
  41. package/dist/log/logger.mjs.map +1 -1
  42. package/dist/log/options.d.ts +1 -1
  43. package/dist/log/report.cjs +2 -11
  44. package/dist/log/report.cjs.map +1 -1
  45. package/dist/log/report.d.ts +36 -4
  46. package/dist/log/report.mjs +1 -10
  47. package/dist/log/report.mjs.map +1 -1
  48. package/dist/log.cjs +1 -1
  49. package/dist/log.cjs.map +1 -1
  50. package/dist/log.d.ts +6 -6
  51. package/dist/log.mjs +2 -2
  52. package/dist/log.mjs.map +1 -1
  53. package/dist/pipe.cjs +69 -26
  54. package/dist/pipe.cjs.map +1 -1
  55. package/dist/pipe.d.ts +178 -119
  56. package/dist/pipe.mjs +71 -24
  57. package/dist/pipe.mjs.map +1 -1
  58. package/dist/plugs/copy.cjs +15 -25
  59. package/dist/plugs/copy.cjs.map +2 -2
  60. package/dist/plugs/copy.d.ts +14 -13
  61. package/dist/plugs/copy.mjs +15 -17
  62. package/dist/plugs/copy.mjs.map +2 -2
  63. package/dist/plugs/coverage/analysis.d.ts +2 -2
  64. package/dist/plugs/coverage/report.cjs +1 -1
  65. package/dist/plugs/coverage/report.cjs.map +1 -1
  66. package/dist/plugs/coverage/report.d.ts +3 -3
  67. package/dist/plugs/coverage/report.mjs +1 -1
  68. package/dist/plugs/coverage/report.mjs.map +1 -1
  69. package/dist/plugs/coverage.cjs +20 -26
  70. package/dist/plugs/coverage.cjs.map +1 -1
  71. package/dist/plugs/coverage.d.ts +33 -30
  72. package/dist/plugs/coverage.mjs +21 -19
  73. package/dist/plugs/coverage.mjs.map +1 -1
  74. package/dist/plugs/debug.cjs +12 -36
  75. package/dist/plugs/debug.cjs.map +1 -1
  76. package/dist/plugs/debug.d.ts +4 -11
  77. package/dist/plugs/debug.mjs +30 -21
  78. package/dist/plugs/debug.mjs.map +1 -1
  79. package/dist/plugs/esbuild/fix-extensions.mjs +1 -1
  80. package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
  81. package/dist/plugs/esbuild.cjs +14 -25
  82. package/dist/plugs/esbuild.cjs.map +1 -1
  83. package/dist/plugs/esbuild.d.ts +11 -16
  84. package/dist/plugs/esbuild.mjs +14 -17
  85. package/dist/plugs/esbuild.mjs.map +1 -1
  86. package/dist/plugs/eslint/runner.cjs +5 -6
  87. package/dist/plugs/eslint/runner.cjs.map +1 -1
  88. package/dist/plugs/eslint/runner.d.ts +6 -20
  89. package/dist/plugs/eslint/runner.mjs +6 -7
  90. package/dist/plugs/eslint/runner.mjs.map +1 -1
  91. package/dist/{task.cjs → plugs/eslint.cjs} +7 -24
  92. package/dist/plugs/eslint.cjs.map +6 -0
  93. package/dist/plugs/eslint.d.ts +34 -0
  94. package/dist/plugs/eslint.mjs +5 -0
  95. package/dist/plugs/eslint.mjs.map +6 -0
  96. package/dist/plugs/exec.cjs +20 -24
  97. package/dist/plugs/exec.cjs.map +1 -1
  98. package/dist/plugs/exec.d.ts +53 -53
  99. package/dist/plugs/exec.mjs +20 -23
  100. package/dist/plugs/exec.mjs.map +1 -1
  101. package/dist/plugs/filter.cjs +9 -19
  102. package/dist/plugs/filter.cjs.map +1 -1
  103. package/dist/plugs/filter.d.ts +21 -15
  104. package/dist/plugs/filter.mjs +10 -12
  105. package/dist/plugs/filter.mjs.map +1 -1
  106. package/dist/plugs/mocha/reporter.cjs +12 -6
  107. package/dist/plugs/mocha/reporter.cjs.map +1 -1
  108. package/dist/plugs/mocha/reporter.d.ts +0 -2
  109. package/dist/plugs/mocha/reporter.mjs +11 -4
  110. package/dist/plugs/mocha/reporter.mjs.map +1 -1
  111. package/dist/plugs/mocha/runner.cjs +4 -5
  112. package/dist/plugs/mocha/runner.cjs.map +1 -1
  113. package/dist/plugs/mocha/runner.d.ts +5 -31
  114. package/dist/plugs/mocha/runner.mjs +5 -6
  115. package/dist/plugs/mocha/runner.mjs.map +1 -1
  116. package/dist/plugs/mocha.cjs +22 -0
  117. package/dist/plugs/mocha.cjs.map +6 -0
  118. package/dist/plugs/mocha.d.ts +35 -0
  119. package/dist/plugs/mocha.mjs +5 -0
  120. package/dist/plugs/mocha.mjs.map +6 -0
  121. package/dist/plugs/rmf.cjs +4 -32
  122. package/dist/plugs/rmf.cjs.map +1 -1
  123. package/dist/plugs/rmf.d.ts +8 -12
  124. package/dist/plugs/rmf.mjs +25 -20
  125. package/dist/plugs/rmf.mjs.map +1 -1
  126. package/dist/plugs/tsc/compiler.d.ts +1 -1
  127. package/dist/plugs/tsc/options.d.ts +1 -1
  128. package/dist/plugs/tsc/report.d.ts +2 -2
  129. package/dist/plugs/tsc/runner.cjs +12 -11
  130. package/dist/plugs/tsc/runner.cjs.map +1 -1
  131. package/dist/plugs/tsc/runner.d.ts +4 -9
  132. package/dist/plugs/tsc/runner.mjs +12 -11
  133. package/dist/plugs/tsc/runner.mjs.map +1 -1
  134. package/dist/plugs/tsc.cjs +7 -0
  135. package/dist/plugs/tsc.cjs.map +6 -0
  136. package/dist/plugs/tsc.d.ts +36 -0
  137. package/dist/plugs/tsc.mjs +15 -0
  138. package/dist/plugs/tsc.mjs.map +6 -0
  139. package/dist/plugs.cjs +3 -5
  140. package/dist/plugs.cjs.map +1 -1
  141. package/dist/plugs.d.ts +10 -17
  142. package/dist/plugs.mjs +3 -5
  143. package/dist/plugs.mjs.map +1 -1
  144. package/dist/types.cjs +19 -0
  145. package/dist/types.cjs.map +6 -0
  146. package/dist/types.d.ts +71 -0
  147. package/dist/types.mjs +1 -0
  148. package/dist/types.mjs.map +6 -0
  149. package/dist/utils/caller.cjs +8 -11
  150. package/dist/utils/caller.cjs.map +2 -2
  151. package/dist/utils/caller.d.ts +2 -7
  152. package/dist/utils/caller.mjs +8 -11
  153. package/dist/utils/caller.mjs.map +2 -2
  154. package/dist/utils/options.cjs +4 -6
  155. package/dist/utils/options.cjs.map +1 -1
  156. package/dist/utils/options.d.ts +16 -15
  157. package/dist/utils/options.mjs +4 -6
  158. package/dist/utils/options.mjs.map +1 -1
  159. package/dist/utils/walk.d.ts +2 -2
  160. package/extra/cli.mjs +31 -20
  161. package/extra/ts-loader.mjs +6 -5
  162. package/package.json +8 -9
  163. package/src/async.ts +27 -19
  164. package/src/files.ts +6 -30
  165. package/src/fork.ts +35 -76
  166. package/src/helpers.ts +66 -99
  167. package/src/index.ts +10 -15
  168. package/src/log/colors.ts +4 -3
  169. package/src/log/emit.ts +4 -4
  170. package/src/log/logger.ts +12 -4
  171. package/src/log/options.ts +1 -1
  172. package/src/log/report.ts +8 -22
  173. package/src/log/spinner.ts +3 -3
  174. package/src/log.ts +9 -9
  175. package/src/paths.ts +1 -1
  176. package/src/pipe.ts +255 -170
  177. package/src/plugs/copy.ts +40 -31
  178. package/src/plugs/coverage/analysis.ts +4 -4
  179. package/src/plugs/coverage/report.ts +6 -5
  180. package/src/plugs/coverage.ts +64 -53
  181. package/src/plugs/debug.ts +28 -26
  182. package/src/plugs/esbuild/fix-extensions.ts +2 -2
  183. package/src/plugs/esbuild.ts +42 -46
  184. package/src/plugs/eslint/runner.ts +16 -31
  185. package/src/plugs/eslint.ts +42 -0
  186. package/src/plugs/exec.ts +93 -82
  187. package/src/plugs/filter.ts +42 -27
  188. package/src/plugs/mocha/reporter.ts +10 -5
  189. package/src/plugs/mocha/runner.ts +12 -38
  190. package/src/plugs/mocha.ts +41 -0
  191. package/src/plugs/rmf.ts +21 -25
  192. package/src/plugs/tsc/compiler.ts +1 -1
  193. package/src/plugs/tsc/options.ts +2 -2
  194. package/src/plugs/tsc/report.ts +2 -2
  195. package/src/plugs/tsc/runner.ts +24 -30
  196. package/src/plugs/tsc.ts +45 -0
  197. package/src/plugs.ts +10 -25
  198. package/src/types.ts +116 -0
  199. package/src/utils/caller.ts +11 -22
  200. package/src/utils/options.ts +49 -17
  201. package/src/utils/walk.ts +4 -4
  202. package/dist/run.cjs +0 -90
  203. package/dist/run.cjs.map +0 -6
  204. package/dist/run.d.ts +0 -89
  205. package/dist/run.mjs +0 -65
  206. package/dist/run.mjs.map +0 -6
  207. package/dist/task.cjs.map +0 -6
  208. package/dist/task.d.ts +0 -15
  209. package/dist/task.mjs +0 -14
  210. package/dist/task.mjs.map +0 -6
  211. package/src/run.ts +0 -159
  212. package/src/task.ts +0 -26
package/dist/pipe.cjs.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I,KAAK,SAAS,YAA4B;AACnD,UAAI,MAAM,WAAW;AAAG,eAAO,mBAAM,YAAQ,yCAA2B,CAAC,EAAE,MAAM;AAEjF,YAAM,CAAE,UAAU,KAAM,IAAI,MAAM,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS;AAChE,eAAO,SAAS,OAAO,KAAK,IAAI,IAAI;AAAA,MACtC,CAAC,CAAC;AAEF,YAAM,WAAW,MAAM;AACvB,YAAM,YAAY,MAAM,IAAI,CAAC,MAAM,EAAE,SAAS;AAE9C,YAAM,gBAAY,yBAAW,UAAU,GAAG,SAAS;AAEnD,aAAO,mBAAM,QAAQ,SAAS,EAAE,MAAM,OAAO,GAAG,KAAK,EAAE,MAAM;AAAA,IAC/D,CAAC;AAAA,EACH;AACF;AAyGO,SAAS,QAGd,MAAY,MAAkB;AAE9B,WAAS,QAAyB,MAAuD;AAEvF,WAAO,KAAK,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC;AAAA,EACpC;AAGA,SAAO,eAAe,MAAM,QAAQ,EAAE,OAAO,KAAK,CAAC;AAGnD,SAAO,eAAe,UAAU,WAAW,MAAM,EAAE,OAAO,KAAK,CAAC;AAClE;AAmBO,SAAS,eACZ,UACA,YACI;AAEN,QAAM,OAAO,cAAc,wBAAY;AAAA,IACrC,eAAe,MAAa;AAC1B,YAAM,YAAY,IAAI;AAAA,IACxB;AAAA,EACF;AAGA,UAAQ,UAAU,IAAI;AACxB;",
5
5
  "names": []
6
6
  }
package/dist/pipe.d.ts CHANGED
@@ -1,128 +1,167 @@
1
- import { Files } from './files.js';
2
- import { Run } from './run.js';
1
+ import { AbsolutePath } from './paths';
2
+ import { Files } from './files';
3
+ import { Logger } from './log';
4
+ /** A convenience type indicating what can be returned by a {@link Plug}. */
5
+ export declare type PlugResult = Files | undefined | void;
3
6
  /**
4
- * The {@link Plug} interface describes an extension mechanism for our build.
7
+ * The {@link Plug} interface describes _build plugin_.
8
+ *
9
+ * A {@link Plug} receives a {@link Files} instance in its input (for example
10
+ * a list of _source `.ts` files_) and optionally produces a possibly different
11
+ * list (for example the _compiled `.js` files_).
5
12
  */
6
- export interface Plug<T extends Files | undefined> {
7
- pipe(files: Files, run: Run): T | Promise<T>;
13
+ export interface Plug<T extends PlugResult> {
14
+ pipe(files: Files, context: Context): T | Promise<T>;
8
15
  }
16
+ /** A type identifying a {@link Plug} as a `function` */
17
+ export declare type PlugFunction<T extends PlugResult> = Plug<T>['pipe'];
9
18
  /**
10
- * A type identifying a {@link Plug} as a `function`
19
+ * The {@link Context} class defines the context in which a {@link Plug}
20
+ * is invoked.
11
21
  */
12
- export declare type PlugFunction<T extends Files | undefined> = Plug<T>['pipe'];
22
+ export declare class Context {
23
+ /** The absolute file name where the task was defined. */
24
+ readonly buildFile: AbsolutePath;
25
+ /** The _name_ of the task associated with this {@link Context}. */
26
+ readonly taskName: string;
27
+ /** The directory of the file where the task was defined (convenience). */
28
+ readonly buildDir: AbsolutePath;
29
+ /** The {@link Logger} associated with this instance. */
30
+ readonly log: Logger;
31
+ constructor(
32
+ /** The absolute file name where the task was defined. */
33
+ buildFile: AbsolutePath,
34
+ /** The _name_ of the task associated with this {@link Context}. */
35
+ taskName: string);
36
+ /**
37
+ * Resolve a (set of) path(s) in this {@link Context}.
38
+ *
39
+ * If the path (or first component thereof) starts with `@...`, then the
40
+ * resolved path will be relative to the directory containing the build file
41
+ * where the current task was defined, otherwise it will be relative to the
42
+ * current working directory.
43
+ */
44
+ resolve(path: string, ...paths: string[]): AbsolutePath;
45
+ }
13
46
  /**
14
- * A {@link Pipe} represents a sequence of operations performed by
15
- * a series of {@link Plug | Plugs}.
47
+ * A class that will be extended by {@link Pipe} where {@link install} will
48
+ * add prototype properties from installed {@link Plug}s
16
49
  */
17
- export interface Pipe {
50
+ declare abstract class PipeProto {
51
+ abstract plug(plug: Plug<PlugResult>): Pipe | Promise<undefined>;
18
52
  }
19
53
  /**
20
- * The {@link Pipe} abstract class exposes the prototype upon which all
21
- * extension plugs will be installed on.
54
+ * The {@link Pipe} class defines processing pipeline where multiple
55
+ * {@link Plug}s can transform lists of {@link Files}.
22
56
  */
23
- export declare abstract class Pipe implements Pipe {
24
- abstract plug(plug: Plug<Files> | PlugFunction<Files>): Pipe & Promise<Files>;
25
- abstract plug(plug: Plug<undefined> | PlugFunction<undefined>): Promise<undefined>;
26
- }
27
- /** Implementation of our {@link Pipe}. */
28
- export declare class PipeImpl<T extends Files | undefined> extends Pipe implements Promise<T> {
29
- #private;
30
- constructor(start: T | Promise<T>, run: Run);
31
- plug<T extends Files | undefined>(arg: Plug<T> | PlugFunction<T>): Pipe & Promise<T>;
32
- then<T1 = T, T2 = never>(onfulfilled?: ((value: T) => T1 | PromiseLike<T1>) | null | undefined, onrejected?: ((reason: any) => T2 | PromiseLike<T2>) | null | undefined): Promise<T1 | T2>;
33
- catch<T0 = never>(onrejected?: ((reason: any) => T0 | PromiseLike<T0>) | null | undefined): Promise<T0 | T>;
34
- finally(onfinally?: (() => void) | null | undefined): Promise<T>;
35
- [Symbol.toStringTag]: string;
57
+ export declare class Pipe extends PipeProto {
58
+ private readonly _context;
59
+ private readonly _run;
60
+ constructor(_context: Context, _run: () => Promise<Files>);
61
+ plug(plug: Plug<Files>): Pipe;
62
+ plug(plug: PlugFunction<Files>): Pipe;
63
+ plug(plug: Plug<void | undefined>): Promise<undefined>;
64
+ plug(plug: PlugFunction<void | undefined>): Promise<undefined>;
65
+ run(): Promise<Files>;
66
+ /**
67
+ * Merge the results of several {@link Pipe}s into a single one.
68
+ *
69
+ * Merging is performed _in parallel_. When serial execution is to be desired,
70
+ * we can merge the awaited _result_ of the {@link Pipe}.
71
+ *
72
+ * For example:
73
+ *
74
+ * ```
75
+ * const pipe: Pipe = merge([
76
+ * // other tasks return `Pipe & Promise<Files>` so we can
77
+ * // direcrly await their result without invoking `run()`
78
+ * await this.anotherTask1(),
79
+ * await this.anotherTask2(),
80
+ * ])
81
+ * ```
82
+ */
83
+ static merge(pipes: (Pipe | Files | Promise<Files>)[]): Pipe;
36
84
  }
37
85
  /** The names which can be installed as direct plugs. */
38
- export declare type PlugName = string & Exclude<keyof Pipe, 'plug' | keyof Promise<Files>>;
39
- /** A convenience type identifying a {@link Plug} constructor. */
40
- export declare type PlugConstructor = new (...args: any) => Plug<Files | undefined>;
41
- /** Convert the resulting type of a {@link Plug} for use in a {@link Pipe} */
42
- declare type PlugReturnForPipe<T> = T extends Plug<infer R> ? R extends Files ? Promise<Files> & Pipe : R extends undefined ? Promise<undefined> : never : never;
43
- /**
44
- * Map constructors into an array of all known overloads.
45
- *
46
- * This is a _royal_ pain in the ass, as we need to distinguish between
47
- * all possible number of overloads of a constructor... Limit to 5 of them!
48
- *
49
- * Also, the empty constructor (when specified in the overloads) will simply
50
- * match the first case (most overloads) and generate functions somewhat like
51
- *
52
- * (...args: unknown[]) => never
53
- * (...args: unknown[]) => never
54
- * (...args: unknown[]) => never
55
- * () => PlugReturnForPipe<R3>
56
- * (arg: Options) => PlugReturnForPipe<R4>
57
- *
58
- * Somehow inferring the result to `Function` or the right type and ANDing all
59
- * those together here doesn't work, so we create this array and we'll AND
60
- * all its members in the PipeExtension<...> type.
61
- */
62
- declare type PlugConstructorOverloads<T extends PlugConstructor> = T extends {
63
- new (...args: infer A0): infer R0;
64
- new (...args: infer A1): infer R1;
65
- new (...args: infer A2): infer R2;
66
- new (...args: infer A3): infer R3;
67
- new (...args: infer A4): infer R4;
68
- } ? [
69
- R0 extends Plug<Files | undefined> ? ((...args: A0) => PlugReturnForPipe<R0>) : Function,
70
- R1 extends Plug<Files | undefined> ? ((...args: A1) => PlugReturnForPipe<R1>) : Function,
71
- R2 extends Plug<Files | undefined> ? ((...args: A2) => PlugReturnForPipe<R2>) : Function,
72
- R3 extends Plug<Files | undefined> ? ((...args: A3) => PlugReturnForPipe<R3>) : Function,
73
- R4 extends Plug<Files | undefined> ? ((...args: A4) => PlugReturnForPipe<R4>) : Function
74
- ] : T extends {
75
- new (...args: infer A0): infer R0;
76
- new (...args: infer A1): infer R1;
77
- new (...args: infer A2): infer R2;
78
- new (...args: infer A3): infer R3;
79
- } ? [
80
- R0 extends Plug<Files | undefined> ? (...args: A0) => PlugReturnForPipe<R0> : Function,
81
- R1 extends Plug<Files | undefined> ? (...args: A1) => PlugReturnForPipe<R1> : Function,
82
- R2 extends Plug<Files | undefined> ? (...args: A2) => PlugReturnForPipe<R2> : Function,
83
- R3 extends Plug<Files | undefined> ? (...args: A3) => PlugReturnForPipe<R3> : Function
84
- ] : T extends {
85
- new (...args: infer A0): infer R0;
86
- new (...args: infer A1): infer R1;
87
- new (...args: infer A2): infer R2;
88
- } ? [
89
- R0 extends Plug<Files | undefined> ? (...args: A0) => PlugReturnForPipe<R0> : Function,
90
- R1 extends Plug<Files | undefined> ? (...args: A1) => PlugReturnForPipe<R1> : Function,
91
- R2 extends Plug<Files | undefined> ? (...args: A2) => PlugReturnForPipe<R2> : Function
92
- ] : T extends {
93
- new (...args: infer A0): infer R0;
94
- new (...args: infer A1): infer R1;
95
- } ? [
96
- R0 extends Plug<Files | undefined> ? (...args: A0) => PlugReturnForPipe<R0> : Function,
97
- R1 extends Plug<Files | undefined> ? (...args: A1) => PlugReturnForPipe<R1> : Function
98
- ] : T extends {
99
- new (...args: infer A0): infer R0;
100
- } ? [
101
- R0 extends Plug<Files | undefined> ? (...args: A0) => PlugReturnForPipe<R0> : Function
102
- ] : never;
86
+ export declare type PlugName = string & Exclude<keyof Pipe, 'plug' | 'run'>;
87
+ /** The parameters of the plug extension with the given name */
88
+ export declare type PipeParameters<Name extends PlugName> = PipeOverloads<Name>['args'];
89
+ /** Extract arguments and return types from function overloads. */
90
+ declare type PipeOverloads<Name extends PlugName> = Pipe[Name] extends {
91
+ (...args: infer A0): infer R0;
92
+ (...args: infer A1): infer R1;
93
+ (...args: infer A2): infer R2;
94
+ (...args: infer A3): infer R3;
95
+ (...args: infer A4): infer R4;
96
+ } ? (R0 extends (Pipe | Promise<undefined>) ? {
97
+ args: A0;
98
+ ret: R0;
99
+ } : never) | (R1 extends (Pipe | Promise<undefined>) ? {
100
+ args: A1;
101
+ ret: R1;
102
+ } : never) | (R2 extends (Pipe | Promise<undefined>) ? {
103
+ args: A2;
104
+ ret: R2;
105
+ } : never) | (R3 extends (Pipe | Promise<undefined>) ? {
106
+ args: A3;
107
+ ret: R3;
108
+ } : never) | (R4 extends (Pipe | Promise<undefined>) ? {
109
+ args: A4;
110
+ ret: R4;
111
+ } : never) : Pipe[Name] extends {
112
+ (...args: infer A0): infer R0;
113
+ (...args: infer A1): infer R1;
114
+ (...args: infer A2): infer R2;
115
+ (...args: infer A3): infer R3;
116
+ } ? (R0 extends (Pipe | Promise<undefined>) ? {
117
+ args: A0;
118
+ ret: R0;
119
+ } : never) | (R1 extends (Pipe | Promise<undefined>) ? {
120
+ args: A1;
121
+ ret: R1;
122
+ } : never) | (R2 extends (Pipe | Promise<undefined>) ? {
123
+ args: A2;
124
+ ret: R2;
125
+ } : never) | (R3 extends (Pipe | Promise<undefined>) ? {
126
+ args: A3;
127
+ ret: R3;
128
+ } : never) : Pipe[Name] extends {
129
+ (...args: infer A0): infer R0;
130
+ (...args: infer A1): infer R1;
131
+ (...args: infer A2): infer R2;
132
+ } ? (R0 extends (Pipe | Promise<undefined>) ? {
133
+ args: A0;
134
+ ret: R0;
135
+ } : never) | (R1 extends (Pipe | Promise<undefined>) ? {
136
+ args: A1;
137
+ ret: R1;
138
+ } : never) | (R2 extends (Pipe | Promise<undefined>) ? {
139
+ args: A2;
140
+ ret: R2;
141
+ } : never) : Pipe[Name] extends {
142
+ (...args: infer A0): infer R0;
143
+ (...args: infer A1): infer R1;
144
+ } ? (R0 extends (Pipe | Promise<undefined>) ? {
145
+ args: A0;
146
+ ret: R0;
147
+ } : never) | (R1 extends (Pipe | Promise<undefined>) ? {
148
+ args: A1;
149
+ ret: R1;
150
+ } : never) : Pipe[Name] extends {
151
+ (...args: infer A0): infer R0;
152
+ } ? (R0 extends (Pipe | Promise<undefined>) ? {
153
+ args: A0;
154
+ ret: R0;
155
+ } : never) : never;
156
+ /** The parameters of the plug extension with the given name */
157
+ declare type PipeResult<Name extends PlugName> = PipeOverloads<Name>['ret'];
103
158
  /**
104
- * A convenience type to easily annotate installed {@link Plug Plugs}.
105
- *
106
- * See also {@link install}.
107
- *
108
- * ```
109
- * export class Write implements Plug {
110
- * // ... the plug implementation lives here
111
- * }
112
- *
113
- * install('write', Write)
114
- *
115
- * declare module '../pipe' {
116
- * export interface Pipe {
117
- * write: PipeExtension<typeof Write>
118
- * }
119
- * }
120
- * ```
159
+ * A type defining the correct constructor for a {@link Plug}, inferring
160
+ * argument types and instance type from the definitions in {@link Pipe}.
121
161
  */
122
- export declare type PipeExtension<T extends PlugConstructor, A = PlugConstructorOverloads<T>> = A extends readonly [infer First, ...infer Rest] ? First & PipeExtension<T, Rest> : A extends readonly [infer Only] ? Only : Function;
162
+ declare type PlugConstructor<Name extends PlugName> = PipeResult<Name> extends Pipe ? new (...args: PipeParameters<Name>) => Plug<Files> : PipeResult<Name> extends Promise<undefined> ? new (...args: PipeParameters<Name>) => Plug<void | undefined> : PipeResult<Name> extends (Pipe | Promise<undefined>) ? new (...args: PipeParameters<Name>) => Plug<Files | void | undefined> : never;
123
163
  /**
124
- * Install a {@link Plug} into our {@link Pipe} prototype, and return a static
125
- * creator function for the {@link Plug} itself.
164
+ * Install a {@link Plug} into our {@link Pipe} prototype.
126
165
  *
127
166
  * This allows our shorthand syntax for well-defined plugs such as:
128
167
  *
@@ -135,18 +174,38 @@ export declare type PipeExtension<T extends PlugConstructor, A = PlugConstructor
135
174
  * Use this alongside interface merging like:
136
175
  *
137
176
  * ```
138
- * export class Write implements Plug {
139
- * // ... the plug implementation lives here
140
- * }
141
- *
142
- * install('write', Write)
143
- *
144
- * declare module '../pipe' {
177
+ * declare module '@plugjs/plug/pipe' {
145
178
  * export interface Pipe {
146
- * write: PipeExtension<typeof Write>
179
+ * write(): Pipe
147
180
  * }
148
181
  * }
182
+ *
183
+ * install('write', class Write implements Plug {
184
+ * constructorg(...args: PipeParams<'write'>) {
185
+ * // here `args` is automatically inferred by whatever was declared above
186
+ * }
187
+ *
188
+ * // ... the plug implementation lives here
189
+ * })
149
190
  * ```
150
191
  */
151
- export declare function install<C extends PlugConstructor>(name: PlugName, ctor: C): void;
192
+ export declare function install<Name extends PlugName, Ctor extends PlugConstructor<Name>>(name: Name, ctor: Ctor): void;
193
+ /**
194
+ * Install a _forking_ {@link Plug} in the {@link Pipe}, in other words
195
+ * execute the plug in a separate process.
196
+ *
197
+ * As a contract, if the _last non-null_ parameter of the constructor is an
198
+ * object and contains the key `coverageDir`, the process will be forked with
199
+ * the approptiately resolved `NODE_V8_COVERAGE` environment variable.
200
+ *
201
+ * Also, forking plugs require some special attention:
202
+ *
203
+ * * plug functions are not supported, only classes implementing the
204
+ * {@link Plug} interface can be used with this.
205
+ *
206
+ * * the class itself _MUST_ be exported as the _default_ export for the
207
+ * `scriptFile` specified below. This is to simplify interoperability between
208
+ * CommonJS and ESM modules as we use dynamic `import(...)` statements.
209
+ */
210
+ export declare function installForking<Name extends PlugName>(plugName: Name, scriptFile: AbsolutePath): void;
152
211
  export {};
package/dist/pipe.mjs CHANGED
@@ -1,44 +1,91 @@
1
1
  // pipe.ts
2
+ import {
3
+ commonPath,
4
+ getAbsoluteParent,
5
+ getCurrentWorkingDirectory,
6
+ resolveAbsolutePath
7
+ } from "./paths.mjs";
8
+ import { sep } from "path";
2
9
  import { assert } from "./assert.mjs";
3
- var Pipe = class {
10
+ import { requireContext } from "./async.mjs";
11
+ import { Files } from "./files.mjs";
12
+ import { ForkingPlug } from "./fork.mjs";
13
+ import { getLogger } from "./log.mjs";
14
+ var Context = class {
15
+ constructor(buildFile, taskName) {
16
+ this.buildFile = buildFile;
17
+ this.taskName = taskName;
18
+ this.buildDir = getAbsoluteParent(buildFile);
19
+ this.log = getLogger(taskName);
20
+ }
21
+ buildDir;
22
+ log;
23
+ resolve(path, ...paths) {
24
+ if (path && path.startsWith("@")) {
25
+ const components = path.substring(1).split(sep).filter((s) => !!s);
26
+ return resolveAbsolutePath(this.buildDir, ...components, ...paths);
27
+ }
28
+ if (!path)
29
+ return getCurrentWorkingDirectory();
30
+ return resolveAbsolutePath(getCurrentWorkingDirectory(), path, ...paths);
31
+ }
32
+ };
33
+ var PipeProto = class {
4
34
  };
5
- var PipeImpl = class extends Pipe {
6
- #promise;
7
- #run;
8
- constructor(start, run) {
35
+ var Pipe = class extends PipeProto {
36
+ constructor(_context, _run) {
9
37
  super();
10
- this.#promise = Promise.resolve(start);
11
- this.#run = run;
38
+ this._context = _context;
39
+ this._run = _run;
12
40
  }
13
41
  plug(arg) {
14
42
  const plug = typeof arg === "function" ? { pipe: arg } : arg;
15
- const promise = this.#promise.then((files) => {
16
- assert(files, "Pipe can not be further extended");
17
- return plug.pipe(files, this.#run);
43
+ const parent = this;
44
+ const context = this._context;
45
+ return new Pipe(context, async () => {
46
+ const previous = await parent.run();
47
+ const current = await plug.pipe(previous, context);
48
+ assert(current, "Unable to extend pipe");
49
+ return current;
18
50
  });
19
- return new PipeImpl(promise, this.#run);
20
51
  }
21
- then(onfulfilled, onrejected) {
22
- return this.#promise.then(onfulfilled, onrejected);
52
+ run() {
53
+ return this._run();
23
54
  }
24
- catch(onrejected) {
25
- return this.#promise.catch(onrejected);
26
- }
27
- finally(onfinally) {
28
- return this.#promise.finally(onfinally);
55
+ static merge(pipes) {
56
+ const context = requireContext();
57
+ return new Pipe(context, async () => {
58
+ if (pipes.length === 0)
59
+ return Files.builder(getCurrentWorkingDirectory()).build();
60
+ const [first, ...other] = await Promise.all(pipes.map((pipe) => {
61
+ return "run" in pipe ? pipe.run() : pipe;
62
+ }));
63
+ const firstDir = first.directory;
64
+ const otherDirs = other.map((f) => f.directory);
65
+ const directory = commonPath(firstDir, ...otherDirs);
66
+ return Files.builder(directory).merge(first, ...other).build();
67
+ });
29
68
  }
30
- [Symbol.toStringTag] = "Pipe";
31
69
  };
32
70
  function install(name, ctor) {
33
- function create(...args) {
71
+ function plug(...args) {
34
72
  return this.plug(new ctor(...args));
35
73
  }
36
- Object.defineProperty(create, "name", { value: name });
37
- Object.defineProperty(Pipe.prototype, name, { value: create });
74
+ Object.defineProperty(plug, "name", { value: name });
75
+ Object.defineProperty(PipeProto.prototype, name, { value: plug });
76
+ }
77
+ function installForking(plugName, scriptFile) {
78
+ const ctor = class extends ForkingPlug {
79
+ constructor(...args) {
80
+ super(scriptFile, args);
81
+ }
82
+ };
83
+ install(plugName, ctor);
38
84
  }
39
85
  export {
86
+ Context,
40
87
  Pipe,
41
- PipeImpl,
42
- install
88
+ install,
89
+ installForking
43
90
  };
44
91
  //# sourceMappingURL=pipe.mjs.map
package/dist/pipe.mjs.map CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/pipe.ts"],
4
- "mappings": ";AAAA,SAAS,cAAc;AA4BhB,IAAe,OAAf,MAAoC;AAG3C;AAIO,IAAM,WAAN,cAAoD,KAA2B;AAAA,EAC3E;AAAA,EACA;AAAA,EAET,YAAY,OAAuB,KAAU;AAC3C,UAAM;AACN,SAAK,WAAW,QAAQ,QAAQ,KAAK;AACrC,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,KAAkC,KAAmD;AACnF,UAAM,OAAO,OAAO,QAAQ,aAAa,EAAE,MAAM,IAAI,IAAI;AACzD,UAAM,UAAU,KAAK,SAAS,KAAK,CAAC,UAAU;AAC5C,aAAO,OAAO,kCAAkC;AAChD,aAAO,KAAK,KAAK,OAAO,KAAK,IAAI;AAAA,IACnC,CAAC;AACD,WAAO,IAAI,SAAS,SAAS,KAAK,IAAI;AAAA,EACxC;AAAA,EAEA,KACI,aACA,YACgB;AAClB,WAAO,KAAK,SAAS,KAAK,aAAa,UAAU;AAAA,EACnD;AAAA,EAEA,MACI,YACe;AACjB,WAAO,KAAK,SAAS,MAAM,UAAU;AAAA,EACvC;AAAA,EAEA,QACI,WACU;AACZ,WAAO,KAAK,SAAS,QAAQ,SAAS;A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A,UAAQ,UAAU,IAAI;AACxB;",
5
5
  "names": []
6
6
  }
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
6
  var __copyProps = (to, from, except, desc) => {
11
7
  if (from && typeof from === "object" || typeof from === "function") {
12
8
  for (let key of __getOwnPropNames(from))
@@ -19,57 +15,55 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
15
 
20
16
  // plugs/copy.ts
21
17
  var copy_exports = {};
22
- __export(copy_exports, {
23
- Copy: () => Copy
24
- });
25
18
  module.exports = __toCommonJS(copy_exports);
26
19
  var import_assert = require("../assert.cjs");
20
+ var import_files = require("../files.cjs");
27
21
  var import_log = require("../log.cjs");
28
22
  var import_paths = require("../paths.cjs");
29
23
  var import_pipe = require("../pipe.cjs");
30
24
  var import_asyncfs = require("../utils/asyncfs.cjs");
31
- var Copy = class {
25
+ (0, import_pipe.install)("copy", class Copy {
32
26
  constructor(_directory, _options = {}) {
33
27
  this._directory = _directory;
34
28
  this._options = _options;
35
29
  }
36
- async pipe(files, run) {
30
+ async pipe(files, context) {
37
31
  const { mode, dirMode, overwrite, rename = (s) => s } = this._options;
38
32
  const flags = overwrite ? import_asyncfs.fsConstants.COPYFILE_EXCL : 0;
39
33
  const dmode = parseMode(dirMode);
40
34
  const fmode = parseMode(mode);
41
- const builder = run.files(this._directory);
35
+ const directory = context.resolve(this._directory);
36
+ const builder = import_files.Files.builder(directory);
42
37
  for (const [relative, absolute] of files.pathMappings()) {
43
38
  const target = (0, import_paths.resolveAbsolutePath)(builder.directory, rename(relative));
44
39
  if (target === absolute) {
45
- run.log.warn("Cowardly refusing to copy same file", (0, import_log.$p)(absolute));
40
+ context.log.warn("Cowardly refusing to copy same file", (0, import_log.$p)(absolute));
46
41
  continue;
47
42
  }
48
- const directory = (0, import_paths.getAbsoluteParent)(target);
49
- const firstParent = await (0, import_asyncfs.mkdir)(directory, { recursive: true });
43
+ const directory2 = (0, import_paths.getAbsoluteParent)(target);
44
+ const firstParent = await (0, import_asyncfs.mkdir)(directory2, { recursive: true });
50
45
  if (firstParent && dmode !== void 0) {
51
46
  (0, import_paths.assertAbsolutePath)(firstParent);
52
- for (let dir = directory; ; dir = (0, import_paths.getAbsoluteParent)(dir)) {
53
- run.log.trace(`Setting mode ${stringifyMode(dmode)} for directory`, (0, import_log.$p)(dir));
47
+ for (let dir = directory2; ; dir = (0, import_paths.getAbsoluteParent)(dir)) {
48
+ context.log.trace(`Setting mode ${stringifyMode(dmode)} for directory`, (0, import_log.$p)(dir));
54
49
  await (0, import_asyncfs.chmod)(dir, dmode);
55
50
  if (dir === firstParent)
56
51
  break;
57
52
  }
58
53
  }
59
- run.log.trace(`Copying "${(0, import_log.$p)(absolute)}" to "${(0, import_log.$p)(target)}"`);
54
+ context.log.trace(`Copying "${(0, import_log.$p)(absolute)}" to "${(0, import_log.$p)(target)}"`);
60
55
  await (0, import_asyncfs.copyFile)(absolute, target, flags);
61
56
  if (fmode !== void 0) {
62
- run.log.trace(`Setting mode ${stringifyMode(fmode)} for file`, (0, import_log.$p)(target));
57
+ context.log.trace(`Setting mode ${stringifyMode(fmode)} for file`, (0, import_log.$p)(target));
63
58
  await (0, import_asyncfs.chmod)(target, fmode);
64
59
  }
65
- builder.unchecked(relative);
60
+ builder.add(target);
66
61
  }
67
62
  const result = builder.build();
68
- run.log.info("Copied", result.length, "files to", (0, import_log.$p)(builder.directory));
63
+ context.log.info("Copied", result.length, "files to", (0, import_log.$p)(builder.directory));
69
64
  return result;
70
65
  }
71
- };
72
- (0, import_pipe.install)("copy", Copy);
66
+ });
73
67
  function parseMode(mode) {
74
68
  if (mode === void 0)
75
69
  return void 0;
@@ -82,8 +76,4 @@ function parseMode(mode) {
82
76
  function stringifyMode(mode) {
83
77
  return mode.toString(8).padStart(4, "0");
84
78
  }
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {
87
- Copy
88
- });
89
79
  //# sourceMappingURL=copy.cjs.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/plugs/copy.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAEvB,iBAAmB;AACnB,mBAA2E;AAC3E,kBAA8B;AAE9B,qBAAoD;AAe7C,IAAM,OAAN,MAAkC;AAAA,EAEvC,YACqB,YACA,WAAwB,CAAC,GAC5C;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,MAAM,KAAK,OAAc,KAA0B;AAEjD,UAAM,EAAE,MAAM,SAAS,WAAW,SAAS,CAAC,MAAc,EAAE,IAAI,KAAK;AACrE,UAAM,QAAQ,YAAY,2BAAY,gBAAgB;AACtD,UAAM,QAAQ,UAAU,OAAO;AAC/B,UAAM,QAAQ,UAAU,IAAI;AAG5B,UAAM,UAAU,IAAI,MAAM,KAAK,UAAU;AAGzC,eAAW,CAAE,UAAU,QAAS,KAAK,MAAM,aAAa,GAAG;AAGzD,YAAM,aAAS,kCAAoB,QAAQ,WAAW,OAAO,QAAQ,CAAC;AAGtE,UAAI,WAAW,UAAU;AACvB,YAAI,IAAI,KAAK,2CAAuC,eAAG,QAAQ,CAAC;AAChE;AAAA,MACF;AAGA,YAAM,gBAAY,gCAAkB,MAAM;AAC1C,YAAM,cAAc,UAAM,sBAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAG9D,UAAI,eAAgB,UAAU,QAAY;AACxC,6CAAmB,WAAW;AAC9B,iBAAS,MAAM,aAAa,UAAM,gCAAkB,GAAG,GAAG;AACxD,cAAI,IAAI,MAAM,gBAAgB,cAAc,KAAK,uBAAmB,eAAG,GAAG,CAAC;AAC3E,oBAAM,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U,WAAO;AACrC,QAAM,SAAS,SAAS,MAAM,CAAC;AAC/B,4BAAO,CAAE,MAAM,MAAM,GAAG,iBAAiB,OAAO;AAChD,SAAO;AACT;AAEA,SAAS,cAAc,MAAsB;AAC3C,SAAO,KAAK,SAAS,CAAC,EAAE,SAAS,GAAG,GAAG;AACzC;",
5
+ "names": ["directory"]
6
6
  }
@@ -1,6 +1,3 @@
1
- import { Files } from '../files.js';
2
- import { Plug } from '../pipe.js';
3
- import { Run } from '../run.js';
4
1
  /** Options for copying files */
5
2
  export interface CopyOptions {
6
3
  /** Whether to allow overwriting or not (default `false`). */
@@ -12,16 +9,20 @@ export interface CopyOptions {
12
9
  /** If specified, this function will be invoked to rename files. */
13
10
  rename?: (relative: string) => string;
14
11
  }
15
- /** Copy the curent {@link Files} to a different directory */
16
- export declare class Copy implements Plug<Files> {
17
- private readonly _directory;
18
- private readonly _options;
19
- constructor(directory: string, options?: CopyOptions);
20
- pipe(files: Files, run: Run): Promise<Files>;
21
- }
22
- declare module '../pipe.js' {
12
+ declare module '../pipe' {
23
13
  interface Pipe {
24
- /** Copy the curent {@link Files} to a different directory */
25
- copy: PipeExtension<typeof Copy>;
14
+ /**
15
+ * Copy the curent {@link Files} to a different directory
16
+ *
17
+ * @param directory The target directory where files will be copied to
18
+ */
19
+ copy(directory: string): Pipe;
20
+ /**
21
+ * Copy the curent {@link Files} to a different directory
22
+ *
23
+ * @param directory The target directory where files will be copied to
24
+ * @param options Extra {@link CopyOptions | options} for the copy operation
25
+ */
26
+ copy(directory: string, options: CopyOptions): Pipe;
26
27
  }
27
28
  }