@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/fork.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { Files } from './files.js';
2
- import { LogOptions } from './log.js';
3
- import { AbsolutePath } from './paths.js';
4
- import { Plug, PlugName } from './pipe.js';
5
- import { Run } from './run.js';
1
+ import { Files } from './files';
2
+ import { LogOptions } from './log';
3
+ import { AbsolutePath } from './paths';
4
+ import { Plug, PlugResult, Context } from './pipe';
6
5
  /** Fork data, from parent to child process */
7
6
  export interface ForkData {
8
7
  /** Script name for the Plug to execute */
@@ -13,8 +12,6 @@ export interface ForkData {
13
12
  taskName: string;
14
13
  /** Build file name */
15
14
  buildFile: AbsolutePath;
16
- /** Build directory */
17
- buildDir: AbsolutePath;
18
15
  /** Files directory */
19
16
  filesDir: AbsolutePath;
20
17
  /** All files to pipe */
@@ -31,27 +28,9 @@ export interface ForkResult {
31
28
  /** All files returned by the plug */
32
29
  filesList?: AbsolutePath[] | undefined;
33
30
  }
34
- /**
35
- * Install a _forking_ {@link Plug} in the {@link Pipe}, in other words
36
- * execute the plug in a separate process.
37
- *
38
- * As a contract, if the _last non-null_ parameter of the constructor is an
39
- * object and contains the key `coverageDir`, the process will be forked with
40
- * the approptiately resolved `NODE_V8_COVERAGE` environment variable.
41
- *
42
- * Also, forking plugs require some special attention:
43
- *
44
- * * plug functions are not supported, only classes implementing the
45
- * {@link Plug} interface can be used with this.
46
- *
47
- * * the class itself _MUST_ be exported as the _default_ export for the
48
- * `scriptFile` specified below. This is to simplify interoperability between
49
- * CommonJS and ESM modules as we use dynamic `import(...)` statements.
50
- */
51
- export declare function installForking(plugName: PlugName, scriptFile: AbsolutePath): void;
52
- export declare abstract class ForkingPlug implements Plug<Files | undefined> {
31
+ export declare abstract class ForkingPlug implements Plug<PlugResult> {
53
32
  private readonly _scriptFile;
54
33
  private readonly _arguments;
55
34
  constructor(_scriptFile: AbsolutePath, _arguments: any[]);
56
- pipe(files: Files, run: Run): Promise<Files | undefined>;
35
+ pipe(files: Files, context: Context): Promise<PlugResult>;
57
36
  }
package/dist/fork.mjs CHANGED
@@ -2,44 +2,35 @@
2
2
  import { fork } from "node:child_process";
3
3
  import { assert, failure } from "./assert.mjs";
4
4
  import { runAsync } from "./async.mjs";
5
+ import { Files } from "./files.mjs";
5
6
  import { $gry, $p, logOptions } from "./log.mjs";
6
- import { resolveFile, requireFilename } from "./paths.mjs";
7
- import { install } from "./pipe.mjs";
8
- import { RunImpl } from "./run.mjs";
9
- function installForking(plugName, scriptFile) {
10
- const ctor = class extends ForkingPlug {
11
- constructor(...args) {
12
- super(scriptFile, args);
13
- }
14
- };
15
- install(plugName, ctor);
16
- }
7
+ import { requireFilename, resolveFile } from "./paths.mjs";
8
+ import { Context } from "./pipe.mjs";
17
9
  var ForkingPlug = class {
18
10
  constructor(_scriptFile, _arguments) {
19
11
  this._scriptFile = _scriptFile;
20
12
  this._arguments = _arguments;
21
13
  }
22
- pipe(files, run) {
14
+ pipe(files, context) {
23
15
  const message = {
24
16
  scriptFile: this._scriptFile,
25
17
  constructorArgs: this._arguments,
26
- taskName: run.taskName,
27
- buildFile: run.buildFile,
28
- buildDir: run.buildDir,
18
+ taskName: context.taskName,
19
+ buildFile: context.buildFile,
29
20
  filesDir: files.directory,
30
21
  filesList: [...files.absolutePaths()],
31
- logOpts: logOptions.fork(run.taskName)
22
+ logOpts: logOptions.fork(context.taskName)
32
23
  };
33
24
  const script = requireFilename(import.meta.url);
34
- run.log.debug("About to fork plug from", $p(script));
25
+ context.log.debug("About to fork plug from", $p(script));
35
26
  const env = { ...process.env };
36
27
  for (let i = this._arguments.length - 1; i >= 0; i--) {
37
28
  if (this._arguments[i] == null)
38
29
  continue;
39
30
  if (typeof this._arguments[i] === "object") {
40
31
  if (typeof this._arguments[i].coverageDir === "string") {
41
- const dir = env.NODE_V8_COVERAGE = run.resolve(this._arguments[i].coverageDir);
42
- run.log.debug("Forked process will produce coverage in", $p(dir));
32
+ const dir = env.NODE_V8_COVERAGE = context.resolve(this._arguments[i].coverageDir);
33
+ context.log.debug("Forked process will produce coverage in", $p(dir));
43
34
  }
44
35
  }
45
36
  }
@@ -47,46 +38,46 @@ var ForkingPlug = class {
47
38
  stdio: ["ignore", "inherit", "inherit", "ipc"],
48
39
  env
49
40
  });
50
- run.log.info("Running", $p(script), $gry(`(pid=${child.pid})`));
41
+ context.log.info("Running", $p(script), $gry(`(pid=${child.pid})`));
51
42
  let done = false;
52
43
  return new Promise((resolve, reject) => {
53
44
  let result = void 0;
54
45
  child.on("error", (error) => {
55
- run.log.error("Child process error", error);
46
+ context.log.error("Child process error", error);
56
47
  return done || reject(failure());
57
48
  });
58
49
  child.on("message", (message2) => {
59
- run.log.debug("Message from child process", message2);
50
+ context.log.debug("Message from child process", message2);
60
51
  result = message2;
61
52
  });
62
53
  child.on("exit", (code, signal) => {
63
54
  if (signal) {
64
- run.log.error(`Child process exited with signal ${signal}`, $gry(`(pid=${child.pid})`));
55
+ context.log.error(`Child process exited with signal ${signal}`, $gry(`(pid=${child.pid})`));
65
56
  return done || reject(failure());
66
57
  } else if (code !== 0) {
67
- run.log.error(`Child process exited with code ${code}`, $gry(`(pid=${child.pid})`));
58
+ context.log.error(`Child process exited with code ${code}`, $gry(`(pid=${child.pid})`));
68
59
  return done || reject(failure());
69
60
  } else if (!result) {
70
- run.log.error("Child process exited with no result", $gry(`(pid=${child.pid})`));
61
+ context.log.error("Child process exited with no result", $gry(`(pid=${child.pid})`));
71
62
  return done || reject(failure());
72
63
  } else if (result.failed) {
73
64
  return done || reject(failure());
74
65
  }
75
- return done || resolve(message.filesDir && message.filesList ? run.files(message.filesDir).unchecked(...message.filesList).build() : void 0);
66
+ return done || resolve(message.filesDir && message.filesList ? Files.builder(message.filesDir).add(...message.filesList).build() : void 0);
76
67
  });
77
68
  try {
78
69
  const result2 = child.send(message, (error) => {
79
70
  if (error) {
80
- run.log.error("Error sending message to child process (callback failure)", error);
71
+ context.log.error("Error sending message to child process (callback failure)", error);
81
72
  reject(failure());
82
73
  }
83
74
  });
84
75
  if (!result2) {
85
- run.log.error("Error sending message to child process (send returned false)");
76
+ context.log.error("Error sending message to child process (send returned false)");
86
77
  reject(failure());
87
78
  }
88
79
  } catch (error) {
89
- run.log.error("Error sending message to child process (exception caught)", error);
80
+ context.log.error("Error sending message to child process (exception caught)", error);
90
81
  reject(failure());
91
82
  }
92
83
  }).finally(() => done = true);
@@ -104,15 +95,14 @@ if (process.argv[1] === requireFilename(import.meta.url) && process.send) {
104
95
  constructorArgs,
105
96
  taskName,
106
97
  buildFile,
107
- buildDir,
108
98
  filesDir,
109
99
  filesList,
110
100
  logOpts
111
101
  } = message;
112
102
  Object.assign(logOptions, logOpts);
113
- const run = new RunImpl({ buildDir, buildFile, taskName });
114
- run.log.debug("Message from parent process", message);
115
- const result = runAsync(run, taskName, async () => {
103
+ const context = new Context(buildFile, taskName);
104
+ context.log.debug("Message from parent process", message);
105
+ const result = runAsync(context, taskName, async () => {
116
106
  assert(resolveFile(scriptFile), `Script file ${$p(scriptFile)} not found`);
117
107
  const script = await import(scriptFile);
118
108
  let Ctor = script;
@@ -123,8 +113,8 @@ if (process.argv[1] === requireFilename(import.meta.url) && process.send) {
123
113
  `Script ${$p(scriptFile)} does not export a default constructor`
124
114
  );
125
115
  const plug = new Ctor(...constructorArgs);
126
- const files = run.files(filesDir).unchecked(...filesList).build();
127
- return plug.pipe(files, run);
116
+ const files = Files.builder(filesDir).add(...filesList).build();
117
+ return plug.pipe(files, context);
128
118
  });
129
119
  const promise = result.then((result2) => {
130
120
  const message2 = result2 ? { failed: false, filesDir: result2.directory, filesList: [...result2.absolutePaths()] } : { failed: false };
@@ -132,22 +122,21 @@ if (process.argv[1] === requireFilename(import.meta.url) && process.send) {
132
122
  process.send(message2, (err) => err ? reject(err) : resolve());
133
123
  });
134
124
  }, (error) => {
135
- run.log.error(error);
125
+ context.log.error(error);
136
126
  return new Promise((resolve, reject) => {
137
127
  process.send({ failed: true }, (err) => err ? reject(err) : resolve());
138
128
  });
139
129
  });
140
130
  promise.then(() => {
141
- run.log.debug("Forked plug exiting");
131
+ context.log.debug("Forked plug exiting");
142
132
  process.exit(0);
143
133
  }, (error) => {
144
- run.log.error("Error sending message back to parent process", error);
134
+ context.log.error("Error sending message back to parent process", error);
145
135
  process.exit(1);
146
136
  });
147
137
  });
148
138
  }
149
139
  export {
150
- ForkingPlug,
151
- installForking
140
+ ForkingPlug
152
141
  };
153
142
  //# sourceMappingURL=fork.mjs.map
package/dist/fork.mjs.map CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/fork.ts"],
4
- "mappings": ";AAAA,SAAS,YAAY;AACrB,SAAS,QAAQ,eAAe;AAChC,SAAS,gBAAgB;AAEzB,SAAS,MAAM,IAAgB,kBAAkB;AACjD,SAAuB,aAAa,uBAAuB;AAC3D,SAAS,eAA+B;AACxC,SAAc,eAAe;AAqDtB,SAAS,eACZ,UACA,YACI;AAEN,QAAM,OAAO,cAAc,YAAY;AAAA,IACrC,eAAe,MAAa;AAC1B,YAAM,YAAY,IAAI;AAAA,IACxB;AAAA,EACF;AAGA,UAAQ,UAAU,IAAI;AACxB;AAMO,IAAe,cAAf,MAA8D;AAAA,EACnE,YACqB,aACA,YACnB;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,KAAK,OAAc,KAAsC;AACvD,UAAM,UAAoB;AAAA,MACxB,YAAY,KAAK;AAAA,MACjB,iBAAiB,KAAK;AAAA,MACtB,UAAU,IAAI;AAAA,MACd,WAAW,IAAI;AAAA,MACf,UAAU,IAAI;AAAA,MACd,UAAU,MAAM;AAAA,MAChB,WAAW,CAAE,GAAG,MAAM,cAAc,CAAE;AAAA,MACtC,SAAS,WAAW,KAAK,IAAI,QAAQ;AAAA,IACvC;AAGA,UAAM,SAAS,gBAAgB,eAAS;AACxC,QAAI,IAAI,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAGnD,UAAM,MAAM,EAAE,GAAG,QAAQ,IAAI;AAG7B,aAAS,IAAI,KAAK,WAAW,SAAS,GAAG,KAAK,GAAG,KAA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S,WAAW;AAC5C,gBAAQ,KAAMD,UAAS,CAAC,QAAe,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC;AAAA,MACtE,CAAC;AAAA,IACH,GAAG,CAAC,UAAU;AACZ,cAAQ,IAAI,MAAM,KAAK;AACvB,aAAO,IAAI,QAAc,CAAC,SAAS,WAAW;AAC5C,gBAAQ,KAAM,EAAE,QAAQ,KAAK,GAAG,CAAC,QAAe,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC;AAAA,MAC/E,CAAC;AAAA,IACH,CAAC;AAGD,YAAQ,KAAK,MAAM;AACjB,cAAQ,IAAI,MAAM,qBAAqB;AACvC,cAAQ,KAAK,CAAC;AAAA,IAChB,GAAG,CAAC,UAAU;AACZ,cAAQ,IAAI,MAAM,gDAAgD,KAAK;AACvE,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AACH;",
5
5
  "names": ["message", "result"]
6
6
  }
package/dist/helpers.cjs CHANGED
@@ -20,32 +20,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // helpers.ts
21
21
  var helpers_exports = {};
22
22
  __export(helpers_exports, {
23
- files: () => files,
24
23
  find: () => find,
25
24
  isDirectory: () => isDirectory,
26
25
  isFile: () => isFile,
27
- merge: () => merge,
28
- pipe: () => pipe,
29
26
  resolve: () => resolve,
30
- rmrf: () => rmrf,
31
- setLogLevel: () => setLogLevel
27
+ rmrf: () => rmrf
32
28
  });
33
29
  module.exports = __toCommonJS(helpers_exports);
34
- var import_paths = require("./paths.cjs");
35
30
  var import_assert = require("./assert.cjs");
36
31
  var import_async = require("./async.cjs");
32
+ var import_files = require("./files.cjs");
37
33
  var import_log = require("./log.cjs");
34
+ var import_paths = require("./paths.cjs");
35
+ var import_pipe = require("./pipe.cjs");
38
36
  var import_asyncfs = require("./utils/asyncfs.cjs");
37
+ var import_options = require("./utils/options.cjs");
38
+ var import_walk = require("./utils/walk.cjs");
39
+ function find(...args) {
40
+ const { params: globs, options } = (0, import_options.parseOptions)(args, {});
41
+ const context = (0, import_async.requireContext)();
42
+ return new import_pipe.Pipe(context, async () => {
43
+ const directory = options.directory ? context.resolve(options.directory) : (0, import_paths.getCurrentWorkingDirectory)();
44
+ const builder = import_files.Files.builder(directory);
45
+ for await (const file of (0, import_walk.walk)(directory, globs, options)) {
46
+ builder.add(file);
47
+ }
48
+ return builder.build();
49
+ });
50
+ }
39
51
  async function rmrf(directory) {
40
- const run = (0, import_async.currentRun)();
41
- (0, import_assert.assert)(run, "Unable to find files outside a running task");
42
- const dir = run.resolve(directory);
52
+ const context = (0, import_async.requireContext)();
53
+ const dir = context.resolve(directory);
43
54
  (0, import_assert.assert)(
44
55
  dir !== (0, import_paths.getCurrentWorkingDirectory)(),
45
56
  `Cowardly refusing to wipe current working directory ${(0, import_log.$p)(dir)}`
46
57
  );
47
58
  (0, import_assert.assert)(
48
- dir !== run.buildDir,
59
+ dir !== context.resolve("@"),
49
60
  `Cowardly refusing to wipe build file directory ${(0, import_log.$p)(dir)}`
50
61
  );
51
62
  if (!(0, import_paths.resolveDirectory)(dir)) {
@@ -55,68 +66,23 @@ async function rmrf(directory) {
55
66
  import_log.log.notice("Removing directory", (0, import_log.$p)(dir), "recursively");
56
67
  await (0, import_asyncfs.rm)(dir, { recursive: true });
57
68
  }
58
- function setLogLevel(level) {
59
- const run = (0, import_async.currentRun)();
60
- (0, import_assert.assert)(run, "Unable to find files outside a running task");
61
- return run.setLogLevel(level);
62
- }
63
69
  function resolve(...paths) {
64
- const run = (0, import_async.currentRun)();
65
- (0, import_assert.assert)(run, "Unable to find files outside a running task");
66
- return run.resolve(...paths);
67
- }
68
- function files(first, ...paths) {
69
- const run = (0, import_async.currentRun)();
70
- (0, import_assert.assert)(run, "Unable to create files builder outside a running task");
71
- if (typeof first === "string") {
72
- return run.files(first, ...paths);
73
- } else if (first) {
74
- return run.files(first);
75
- } else {
76
- return run.files();
77
- }
78
- }
79
- function merge(args) {
80
- const run = (0, import_async.currentRun)();
81
- (0, import_assert.assert)(run, "Unable to create files builder outside a running task");
82
- const promise = Promise.resolve().then(async () => {
83
- if (args.length === 0)
84
- return run.pipe(run.files().build());
85
- const instances = await Promise.all(args);
86
- const [first, ...others] = instances;
87
- const firstDir = first.directory;
88
- const otherDirs = others.map((f) => f.directory);
89
- const directory = (0, import_paths.commonPath)(firstDir, ...otherDirs);
90
- return run.files(directory).merge(first, ...others).build();
91
- });
92
- return run.pipe(promise);
93
- }
94
- function find(glob, ...args) {
95
- const run = (0, import_async.currentRun)();
96
- (0, import_assert.assert)(run, "Unable to find files outside a running task");
97
- return run.find(glob, ...args);
98
- }
99
- function pipe(files2) {
100
- const run = (0, import_async.currentRun)();
101
- (0, import_assert.assert)(run, "Unable to create pipes outside a running task");
102
- return run.pipe(files2);
70
+ return (0, import_async.requireContext)().resolve(...paths);
103
71
  }
104
72
  function isFile(...paths) {
105
- return (0, import_paths.resolveFile)(resolve(...paths));
73
+ const path = (0, import_async.requireContext)().resolve(...paths);
74
+ return (0, import_paths.resolveFile)(path);
106
75
  }
107
76
  function isDirectory(...paths) {
108
- return (0, import_paths.resolveDirectory)(resolve(...paths));
77
+ const path = (0, import_async.requireContext)().resolve(...paths);
78
+ return (0, import_paths.resolveDirectory)(path);
109
79
  }
110
80
  // Annotate the CommonJS export names for ESM import in node:
111
81
  0 && (module.exports = {
112
- files,
113
82
  find,
114
83
  isDirectory,
115
84
  isFile,
116
- merge,
117
- pipe,
118
85
  resolve,
119
- rmrf,
120
- setLogLevel
86
+ rmrf
121
87
  });
122
88
  //# sourceMappingURL=helpers.cjs.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/helpers.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAMO;AAEP,oBAAuB;AACvB,mBAA2B;AAE3B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M,UAAU,mBAAM,QAAQ,SAAS;AACvC,qBAAiB,YAAQ,kBAAK,WAAW,OAAO,OAAO,GAAG;AACxD,cAAQ,IAAI,IAAI;AAAA,IAClB;AAEA,WAAO,QAAQ,MAAM;AAAA,EACvB,CAAC;AACH;AAKA,eAAsB,KAAK,WAAkC;AAC3D,QAAM,cAAU,6BAAe;AAC/B,QAAM,MAAM,QAAQ,QAAQ,SAAS;AAErC;AAAA,IAAO,YAAQ,yCAA2B;AAAA,IACtC,2DAAuD,eAAG,GAAG;AAAA,EAAG;AAEpE;AAAA,IAAO,QAAQ,QAAQ,QAAQ,GAAG;AAAA,IAC9B,sDAAkD,eAAG,GAAG;AAAA,EAAG;AAE/D,MAAI,KAAE,+BAAiB,GAAG,GAAG;AAC3B,mBAAI,KAAK,iBAAa,eAAG,GAAG,GAAG,WAAW;AAC1C;AAAA,EACF;AAEA,iBAAI,OAAO,0BAAsB,eAAG,GAAG,GAAG,aAAa;AACvD,YAAM,mBAAG,KAAK,EAAE,WAAW,KAAK,CAAC;AACnC;AAUO,SAAS,WAAW,OAA8C;AACvE,aAAO,6BAAe,EAAE,QAAQ,GAAG,KAAK;AAC1C;AAOO,SAAS,UAAU,OAA0D;AAClF,QAAM,WAAO,6BAAe,EAAE,QAAQ,GAAG,KAAK;AAC9C,aAAO,0BAAY,IAAI;AACzB;AAOO,SAAS,eAAe,OAA0D;AACvF,QAAM,WAAO,6BAAe,EAAE,QAAQ,GAAG,KAAK;AAC9C,aAAO,+BAAiB,IAAI;AAC9B;",
5
+ "names": []
6
6
  }
package/dist/helpers.d.ts CHANGED
@@ -1,43 +1,41 @@
1
- import { AbsolutePath } from './paths.js';
2
- import { Files, FilesBuilder } from './files.js';
3
- import { LogLevelString } from './log.js';
4
- import { Pipe } from './pipe.js';
5
- import { FindOptions } from './run.js';
6
- import { ParseOptions } from './utils/options.js';
1
+ import { AbsolutePath } from './paths';
2
+ import { Pipe } from './pipe';
3
+ import { WalkOptions } from './utils/walk';
4
+ /** The {@link FindOptions} interface defines the options for finding files. */
5
+ export interface FindOptions extends WalkOptions {
6
+ /** The directory where to start looking for files. */
7
+ directory?: string;
8
+ }
9
+ /** Find files in the current directory using the specified _glob_. */
10
+ export declare function find(glob: string): Pipe;
11
+ /** Find files in the current directory using the specified _globs_. */
12
+ export declare function find(glob: string, ...globs: string[]): Pipe;
13
+ /** Find files using the specified _glob_ and {@link FindOptions | options}. */
14
+ export declare function find(glob: string, options: FindOptions): Pipe;
15
+ /** Find files using the specified _globs_ and {@link FindOptions | options}. */
16
+ export declare function find(glob: string, ...extra: [...globs: string[], options: FindOptions]): Pipe;
7
17
  /**
8
18
  * Recursively remove the specified directory _**(use with care)**_.
9
19
  */
10
20
  export declare function rmrf(directory: string): Promise<void>;
11
21
  /**
12
- * Set the current _log level_.
22
+ * Resolve a (set of) path(s) into an {@link AbsolutePath}.
13
23
  *
14
- * The _level_ will be applied _only_ within the execution of the current task.
24
+ * If the path (or first component thereof) starts with `@...`, then the
25
+ * resolved path will be relative to the directory containing the build file
26
+ * where the current task was defined, otherwise it will be relative to the
27
+ * current working directory.
15
28
  */
16
- export declare function setLogLevel(level: LogLevelString): void;
29
+ export declare function resolve(...paths: [string, ...string[]]): AbsolutePath;
17
30
  /**
18
- * Resolve a path into an {@link AbsolutePath}.
31
+ * Return an absolute path of the file if it exist on disk.
19
32
  *
20
- * If the path starts with `@...` it is considered to be relative to the
21
- * _directory containing the build file where the task was defined_, otherwise
22
- * it will be relative to the {@link process.cwd | current working directory}.
33
+ * See the comments on {@link resolve} to understand how paths are resolved.
23
34
  */
24
- export declare function resolve(...paths: string[]): AbsolutePath;
35
+ export declare function isFile(...paths: [string, ...string[]]): AbsolutePath | undefined;
25
36
  /**
26
- * Create a new {@link Files} instance.
27
- */
28
- export declare function files(files: Files): FilesBuilder;
29
- export declare function files(directory: string, ...paths: string[]): FilesBuilder;
30
- /**
31
- * Merge multiple {@link Files} instance.
32
- */
33
- export declare function merge(args: (Files | Promise<Files>)[]): Promise<Files> & Pipe;
34
- /**
35
- * Find files according to the globs and {@link FindOptions} specified.
37
+ * Return an absolute path of the directory if it exist on disk.
38
+ *
39
+ * See the comments on {@link resolve} to understand how paths are resolved.
36
40
  */
37
- export declare function find(glob: string, ...args: ParseOptions<FindOptions>): Pipe & Promise<Files>;
38
- /** Create a {@link Pipe} from a {@link Files} instance. */
39
- export declare function pipe(files: Files | Promise<Files>): Pipe & Promise<Files>;
40
- /** Return an absolute path of the file if it exist on disk */
41
- export declare function isFile(...paths: string[]): AbsolutePath | undefined;
42
- /** Return an absolute path of the file if it exist on disk */
43
- export declare function isDirectory(...paths: string[]): AbsolutePath | undefined;
41
+ export declare function isDirectory(...paths: [string, ...string[]]): AbsolutePath | undefined;
package/dist/helpers.mjs CHANGED
@@ -1,24 +1,34 @@
1
1
  // helpers.ts
2
- import {
3
- commonPath,
4
- getCurrentWorkingDirectory,
5
- resolveDirectory,
6
- resolveFile
7
- } from "./paths.mjs";
8
2
  import { assert } from "./assert.mjs";
9
- import { currentRun } from "./async.mjs";
3
+ import { requireContext } from "./async.mjs";
4
+ import { Files } from "./files.mjs";
10
5
  import { $p, log } from "./log.mjs";
6
+ import { getCurrentWorkingDirectory, resolveDirectory, resolveFile } from "./paths.mjs";
7
+ import { Pipe } from "./pipe.mjs";
11
8
  import { rm } from "./utils/asyncfs.mjs";
9
+ import { parseOptions } from "./utils/options.mjs";
10
+ import { walk } from "./utils/walk.mjs";
11
+ function find(...args) {
12
+ const { params: globs, options } = parseOptions(args, {});
13
+ const context = requireContext();
14
+ return new Pipe(context, async () => {
15
+ const directory = options.directory ? context.resolve(options.directory) : getCurrentWorkingDirectory();
16
+ const builder = Files.builder(directory);
17
+ for await (const file of walk(directory, globs, options)) {
18
+ builder.add(file);
19
+ }
20
+ return builder.build();
21
+ });
22
+ }
12
23
  async function rmrf(directory) {
13
- const run = currentRun();
14
- assert(run, "Unable to find files outside a running task");
15
- const dir = run.resolve(directory);
24
+ const context = requireContext();
25
+ const dir = context.resolve(directory);
16
26
  assert(
17
27
  dir !== getCurrentWorkingDirectory(),
18
28
  `Cowardly refusing to wipe current working directory ${$p(dir)}`
19
29
  );
20
30
  assert(
21
- dir !== run.buildDir,
31
+ dir !== context.resolve("@"),
22
32
  `Cowardly refusing to wipe build file directory ${$p(dir)}`
23
33
  );
24
34
  if (!resolveDirectory(dir)) {
@@ -28,67 +38,22 @@ async function rmrf(directory) {
28
38
  log.notice("Removing directory", $p(dir), "recursively");
29
39
  await rm(dir, { recursive: true });
30
40
  }
31
- function setLogLevel(level) {
32
- const run = currentRun();
33
- assert(run, "Unable to find files outside a running task");
34
- return run.setLogLevel(level);
35
- }
36
41
  function resolve(...paths) {
37
- const run = currentRun();
38
- assert(run, "Unable to find files outside a running task");
39
- return run.resolve(...paths);
40
- }
41
- function files(first, ...paths) {
42
- const run = currentRun();
43
- assert(run, "Unable to create files builder outside a running task");
44
- if (typeof first === "string") {
45
- return run.files(first, ...paths);
46
- } else if (first) {
47
- return run.files(first);
48
- } else {
49
- return run.files();
50
- }
51
- }
52
- function merge(args) {
53
- const run = currentRun();
54
- assert(run, "Unable to create files builder outside a running task");
55
- const promise = Promise.resolve().then(async () => {
56
- if (args.length === 0)
57
- return run.pipe(run.files().build());
58
- const instances = await Promise.all(args);
59
- const [first, ...others] = instances;
60
- const firstDir = first.directory;
61
- const otherDirs = others.map((f) => f.directory);
62
- const directory = commonPath(firstDir, ...otherDirs);
63
- return run.files(directory).merge(first, ...others).build();
64
- });
65
- return run.pipe(promise);
66
- }
67
- function find(glob, ...args) {
68
- const run = currentRun();
69
- assert(run, "Unable to find files outside a running task");
70
- return run.find(glob, ...args);
71
- }
72
- function pipe(files2) {
73
- const run = currentRun();
74
- assert(run, "Unable to create pipes outside a running task");
75
- return run.pipe(files2);
42
+ return requireContext().resolve(...paths);
76
43
  }
77
44
  function isFile(...paths) {
78
- return resolveFile(resolve(...paths));
45
+ const path = requireContext().resolve(...paths);
46
+ return resolveFile(path);
79
47
  }
80
48
  function isDirectory(...paths) {
81
- return resolveDirectory(resolve(...paths));
49
+ const path = requireContext().resolve(...paths);
50
+ return resolveDirectory(path);
82
51
  }
83
52
  export {
84
- files,
85
53
  find,
86
54
  isDirectory,
87
55
  isFile,
88
- merge,
89
- pipe,
90
56
  resolve,
91
- rmrf,
92
- setLogLevel
57
+ rmrf
93
58
  };
94
59
  //# sourceMappingURL=helpers.mjs.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/helpers.ts"],
4
- "mappings": ";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAE3B,SAAS,IAAI,WAA2B;AAGxC,SAAS,UAAU;AAMnB,eAAsB,KAAK,WAAkC;AAC3D,QAAM,MAAM,WAAW;AACvB,SAAO,KAAK,6CAA6C;AACzD,QAAM,MAAM,IAAI,QAAQ,SAAS;AAEjC;AAAA,IAAO,QAAQ,2BAA2B;AAAA,IACtC,uDAAuD,GAAG,GAAG;AAAA,EAAG;AAEpE;AAAA,IAAO,QAAQ,IAAI;AAAA,IACf,kDAAkD,GAAG,GAAG;AAAA,EAAG;AAE/D,MAAI,CAAE,iBAAiB,GAAG,GAAG;AAC3B,QAAI,KAAK,aAAa,GAAG,GAAG,GAAG,WAAW;AAC1C;AAAA,EACF;AAEA,MAAI,OAAO,sBAAsB,GAAG,GAAG,GAAG,aAAa;AACvD,QAAM,GAAG,KAAK,EAAE,WAAW,KAAK,CAAC;AACnC;AAOO,SAAS,YAAY,OAA6B;AACvD,QAAM,MAAM,WAAW;AACvB,SAAO,KAAK,6CAA6C;AACzD,SAAO,IAAI,YAAY,KAAK;AAC9B;AASO,SAAS,WAAW,OAA+B;AACxD,QAAM,MAAM,WAAW;AACvB,SAAO,KAAK,6CAA6C;AACzD,SAAO,IAAI,QAAQ,GAAG,KAAK;AAC7B;AAQO,SAAS,MAAM,UAAsC,OAA+B;AACzF,Q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AAOO,SAAS,eAAe,OAA0D;AACvF,QAAM,OAAO,eAAe,EAAE,QAAQ,GAAG,KAAK;AAC9C,SAAO,iBAAiB,IAAI;AAC9B;",
5
+ "names": []
6
6
  }
package/dist/index.cjs CHANGED
@@ -3,6 +3,10 @@ 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
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -16,10 +20,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
20
 
17
21
  // index.ts
18
22
  var src_exports = {};
23
+ __export(src_exports, {
24
+ Pipe: () => import_pipe.Pipe
25
+ });
19
26
  module.exports = __toCommonJS(src_exports);
27
+ var import_pipe = require("./pipe.cjs");
20
28
  __reExport(src_exports, require("./assert.cjs"), module.exports);
21
29
  __reExport(src_exports, require("./build.cjs"), module.exports);
22
- __reExport(src_exports, require("./plugs.cjs"), module.exports);
23
- __reExport(src_exports, require("./log.cjs"), module.exports);
24
30
  __reExport(src_exports, require("./helpers.cjs"), module.exports);
31
+ __reExport(src_exports, require("./log.cjs"), module.exports);
32
+ __reExport(src_exports, require("./plugs.cjs"), module.exports);
33
+ __reExport(src_exports, require("./types.cjs"), module.exports);
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ Pipe
37
+ });
25
38
  //# sourceMappingURL=index.cjs.map