@plugjs/plug 0.0.1

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 (264) hide show
  1. package/LICENSE.md +211 -0
  2. package/NOTICE.md +13 -0
  3. package/README.md +7 -0
  4. package/dist/assert.cjs +72 -0
  5. package/dist/assert.cjs.map +6 -0
  6. package/dist/assert.mjs +41 -0
  7. package/dist/assert.mjs.map +6 -0
  8. package/dist/async.cjs +58 -0
  9. package/dist/async.cjs.map +6 -0
  10. package/dist/async.mjs +30 -0
  11. package/dist/async.mjs.map +6 -0
  12. package/dist/build.cjs +136 -0
  13. package/dist/build.cjs.map +6 -0
  14. package/dist/build.mjs +110 -0
  15. package/dist/build.mjs.map +6 -0
  16. package/dist/files.cjs +113 -0
  17. package/dist/files.cjs.map +6 -0
  18. package/dist/files.mjs +88 -0
  19. package/dist/files.mjs.map +6 -0
  20. package/dist/fork.cjs +177 -0
  21. package/dist/fork.cjs.map +6 -0
  22. package/dist/fork.mjs +151 -0
  23. package/dist/fork.mjs.map +6 -0
  24. package/dist/helpers.cjs +129 -0
  25. package/dist/helpers.cjs.map +6 -0
  26. package/dist/helpers.mjs +97 -0
  27. package/dist/helpers.mjs.map +6 -0
  28. package/dist/index.cjs +25 -0
  29. package/dist/index.cjs.map +6 -0
  30. package/dist/index.mjs +7 -0
  31. package/dist/index.mjs.map +6 -0
  32. package/dist/log/colors.cjs +129 -0
  33. package/dist/log/colors.cjs.map +6 -0
  34. package/dist/log/colors.mjs +93 -0
  35. package/dist/log/colors.mjs.map +6 -0
  36. package/dist/log/emit.cjs +109 -0
  37. package/dist/log/emit.cjs.map +6 -0
  38. package/dist/log/emit.mjs +83 -0
  39. package/dist/log/emit.mjs.map +6 -0
  40. package/dist/log/levels.cjs +75 -0
  41. package/dist/log/levels.cjs.map +6 -0
  42. package/dist/log/levels.mjs +41 -0
  43. package/dist/log/levels.mjs.map +6 -0
  44. package/dist/log/logger.cjs +129 -0
  45. package/dist/log/logger.cjs.map +6 -0
  46. package/dist/log/logger.mjs +104 -0
  47. package/dist/log/logger.mjs.map +6 -0
  48. package/dist/log/options.cjs +149 -0
  49. package/dist/log/options.cjs.map +6 -0
  50. package/dist/log/options.mjs +124 -0
  51. package/dist/log/options.mjs.map +6 -0
  52. package/dist/log/report.cjs +284 -0
  53. package/dist/log/report.cjs.map +6 -0
  54. package/dist/log/report.mjs +259 -0
  55. package/dist/log/report.mjs.map +6 -0
  56. package/dist/log/spinner.cjs +83 -0
  57. package/dist/log/spinner.cjs.map +6 -0
  58. package/dist/log/spinner.mjs +57 -0
  59. package/dist/log/spinner.mjs.map +6 -0
  60. package/dist/log.cjs +71 -0
  61. package/dist/log.cjs.map +6 -0
  62. package/dist/log.mjs +45 -0
  63. package/dist/log.mjs.map +6 -0
  64. package/dist/paths.cjs +158 -0
  65. package/dist/paths.cjs.map +6 -0
  66. package/dist/paths.mjs +122 -0
  67. package/dist/paths.mjs.map +6 -0
  68. package/dist/pipe.cjs +71 -0
  69. package/dist/pipe.cjs.map +6 -0
  70. package/dist/pipe.mjs +44 -0
  71. package/dist/pipe.mjs.map +6 -0
  72. package/dist/plugs/copy.cjs +95 -0
  73. package/dist/plugs/copy.cjs.map +6 -0
  74. package/dist/plugs/copy.mjs +64 -0
  75. package/dist/plugs/copy.mjs.map +6 -0
  76. package/dist/plugs/coverage/analysis.cjs +229 -0
  77. package/dist/plugs/coverage/analysis.cjs.map +6 -0
  78. package/dist/plugs/coverage/analysis.mjs +202 -0
  79. package/dist/plugs/coverage/analysis.mjs.map +6 -0
  80. package/dist/plugs/coverage/report.cjs +215 -0
  81. package/dist/plugs/coverage/report.cjs.map +6 -0
  82. package/dist/plugs/coverage/report.mjs +200 -0
  83. package/dist/plugs/coverage/report.mjs.map +6 -0
  84. package/dist/plugs/coverage.cjs +142 -0
  85. package/dist/plugs/coverage.cjs.map +6 -0
  86. package/dist/plugs/coverage.mjs +117 -0
  87. package/dist/plugs/coverage.mjs.map +6 -0
  88. package/dist/plugs/debug.cjs +50 -0
  89. package/dist/plugs/debug.cjs.map +6 -0
  90. package/dist/plugs/debug.mjs +25 -0
  91. package/dist/plugs/debug.mjs.map +6 -0
  92. package/dist/plugs/esbuild/bundle-locals.cjs +51 -0
  93. package/dist/plugs/esbuild/bundle-locals.cjs.map +6 -0
  94. package/dist/plugs/esbuild/bundle-locals.mjs +26 -0
  95. package/dist/plugs/esbuild/bundle-locals.mjs.map +6 -0
  96. package/dist/plugs/esbuild/check-dependencies.cjs +140 -0
  97. package/dist/plugs/esbuild/check-dependencies.cjs.map +6 -0
  98. package/dist/plugs/esbuild/check-dependencies.mjs +115 -0
  99. package/dist/plugs/esbuild/check-dependencies.mjs.map +6 -0
  100. package/dist/plugs/esbuild/fix-extensions.cjs +91 -0
  101. package/dist/plugs/esbuild/fix-extensions.cjs.map +6 -0
  102. package/dist/plugs/esbuild/fix-extensions.mjs +60 -0
  103. package/dist/plugs/esbuild/fix-extensions.mjs.map +6 -0
  104. package/dist/plugs/esbuild.cjs +109 -0
  105. package/dist/plugs/esbuild.cjs.map +6 -0
  106. package/dist/plugs/esbuild.mjs +83 -0
  107. package/dist/plugs/esbuild.mjs.map +6 -0
  108. package/dist/plugs/eslint/runner.cjs +91 -0
  109. package/dist/plugs/eslint/runner.cjs.map +6 -0
  110. package/dist/plugs/eslint/runner.mjs +68 -0
  111. package/dist/plugs/eslint/runner.mjs.map +6 -0
  112. package/dist/plugs/exec.cjs +128 -0
  113. package/dist/plugs/exec.cjs.map +6 -0
  114. package/dist/plugs/exec.mjs +96 -0
  115. package/dist/plugs/exec.mjs.map +6 -0
  116. package/dist/plugs/filter.cjs +59 -0
  117. package/dist/plugs/filter.cjs.map +6 -0
  118. package/dist/plugs/filter.mjs +34 -0
  119. package/dist/plugs/filter.mjs.map +6 -0
  120. package/dist/plugs/mocha/reporter.cjs +140 -0
  121. package/dist/plugs/mocha/reporter.cjs.map +6 -0
  122. package/dist/plugs/mocha/reporter.mjs +107 -0
  123. package/dist/plugs/mocha/reporter.mjs.map +6 -0
  124. package/dist/plugs/mocha/runner.cjs +73 -0
  125. package/dist/plugs/mocha/runner.cjs.map +6 -0
  126. package/dist/plugs/mocha/runner.mjs +44 -0
  127. package/dist/plugs/mocha/runner.mjs.map +6 -0
  128. package/dist/plugs/tsc/compiler.cjs +74 -0
  129. package/dist/plugs/tsc/compiler.cjs.map +6 -0
  130. package/dist/plugs/tsc/compiler.mjs +43 -0
  131. package/dist/plugs/tsc/compiler.mjs.map +6 -0
  132. package/dist/plugs/tsc/options.cjs +82 -0
  133. package/dist/plugs/tsc/options.cjs.map +6 -0
  134. package/dist/plugs/tsc/options.mjs +51 -0
  135. package/dist/plugs/tsc/options.mjs.map +6 -0
  136. package/dist/plugs/tsc/report.cjs +90 -0
  137. package/dist/plugs/tsc/report.cjs.map +6 -0
  138. package/dist/plugs/tsc/report.mjs +59 -0
  139. package/dist/plugs/tsc/report.mjs.map +6 -0
  140. package/dist/plugs/tsc/runner.cjs +101 -0
  141. package/dist/plugs/tsc/runner.cjs.map +6 -0
  142. package/dist/plugs/tsc/runner.mjs +72 -0
  143. package/dist/plugs/tsc/runner.mjs.map +6 -0
  144. package/dist/plugs.cjs +31 -0
  145. package/dist/plugs.cjs.map +6 -0
  146. package/dist/plugs.mjs +13 -0
  147. package/dist/plugs.mjs.map +6 -0
  148. package/dist/run.cjs +95 -0
  149. package/dist/run.cjs.map +6 -0
  150. package/dist/run.mjs +70 -0
  151. package/dist/run.mjs.map +6 -0
  152. package/dist/task.cjs +39 -0
  153. package/dist/task.cjs.map +6 -0
  154. package/dist/task.mjs +14 -0
  155. package/dist/task.mjs.map +6 -0
  156. package/dist/utils/asyncfs.cjs +143 -0
  157. package/dist/utils/asyncfs.cjs.map +6 -0
  158. package/dist/utils/asyncfs.mjs +83 -0
  159. package/dist/utils/asyncfs.mjs.map +6 -0
  160. package/dist/utils/caller.cjs +59 -0
  161. package/dist/utils/caller.cjs.map +6 -0
  162. package/dist/utils/caller.mjs +34 -0
  163. package/dist/utils/caller.mjs.map +6 -0
  164. package/dist/utils/match.cjs +69 -0
  165. package/dist/utils/match.cjs.map +6 -0
  166. package/dist/utils/match.mjs +38 -0
  167. package/dist/utils/match.mjs.map +6 -0
  168. package/dist/utils/options.cjs +41 -0
  169. package/dist/utils/options.cjs.map +6 -0
  170. package/dist/utils/options.mjs +16 -0
  171. package/dist/utils/options.mjs.map +6 -0
  172. package/dist/utils/walk.cjs +104 -0
  173. package/dist/utils/walk.cjs.map +6 -0
  174. package/dist/utils/walk.mjs +79 -0
  175. package/dist/utils/walk.mjs.map +6 -0
  176. package/extra/cli.mjs +212 -0
  177. package/extra/ts-loader.mjs +214 -0
  178. package/extra/webassembly.d.ts +11 -0
  179. package/package.json +57 -0
  180. package/src/assert.ts +47 -0
  181. package/src/async.ts +50 -0
  182. package/src/files.ts +129 -0
  183. package/src/fork.ts +263 -0
  184. package/src/helpers.ts +145 -0
  185. package/src/index.ts +20 -0
  186. package/src/log/colors.ts +119 -0
  187. package/src/log/emit.ts +125 -0
  188. package/src/log/levels.ts +65 -0
  189. package/src/log/logger.ts +171 -0
  190. package/src/log/options.ts +199 -0
  191. package/src/log/report.ts +433 -0
  192. package/src/log/spinner.ts +70 -0
  193. package/src/log.ts +68 -0
  194. package/src/paths.ts +213 -0
  195. package/src/pipe.ts +231 -0
  196. package/src/plugs/copy.ts +113 -0
  197. package/src/plugs/coverage/analysis.ts +395 -0
  198. package/src/plugs/coverage/report.ts +337 -0
  199. package/src/plugs/coverage.ts +194 -0
  200. package/src/plugs/debug.ts +35 -0
  201. package/src/plugs/esbuild/bundle-locals.ts +33 -0
  202. package/src/plugs/esbuild/check-dependencies.ts +158 -0
  203. package/src/plugs/esbuild/fix-extensions.ts +108 -0
  204. package/src/plugs/esbuild.ts +128 -0
  205. package/src/plugs/eslint/runner.ts +112 -0
  206. package/src/plugs/exec.ts +215 -0
  207. package/src/plugs/filter.ts +56 -0
  208. package/src/plugs/mocha/reporter.ts +152 -0
  209. package/src/plugs/mocha/runner.ts +77 -0
  210. package/src/plugs/tsc/compiler.ts +66 -0
  211. package/src/plugs/tsc/options.ts +97 -0
  212. package/src/plugs/tsc/report.ts +74 -0
  213. package/src/plugs/tsc/runner.ts +100 -0
  214. package/src/plugs.ts +33 -0
  215. package/src/run.ts +160 -0
  216. package/src/task.ts +26 -0
  217. package/src/utils/asyncfs.ts +82 -0
  218. package/src/utils/caller.ts +45 -0
  219. package/src/utils/match.ts +286 -0
  220. package/src/utils/options.ts +22 -0
  221. package/src/utils/walk.ts +136 -0
  222. package/types/assert.d.ts +18 -0
  223. package/types/async.d.ts +20 -0
  224. package/types/build.d.ts +56 -0
  225. package/types/files.d.ts +44 -0
  226. package/types/fork.d.ts +57 -0
  227. package/types/helpers.d.ts +49 -0
  228. package/types/index.d.ts +14 -0
  229. package/types/log/colors.d.ts +25 -0
  230. package/types/log/emit.d.ts +14 -0
  231. package/types/log/levels.d.ts +52 -0
  232. package/types/log/logger.d.ts +31 -0
  233. package/types/log/options.d.ts +40 -0
  234. package/types/log/report.d.ts +64 -0
  235. package/types/log/spinner.d.ts +2 -0
  236. package/types/log.d.ts +10 -0
  237. package/types/paths.d.ts +76 -0
  238. package/types/pipe.d.ts +152 -0
  239. package/types/plugs/copy.d.ts +27 -0
  240. package/types/plugs/coverage/analysis.d.ts +104 -0
  241. package/types/plugs/coverage/report.d.ts +53 -0
  242. package/types/plugs/coverage.d.ts +46 -0
  243. package/types/plugs/debug.d.ts +14 -0
  244. package/types/plugs/esbuild/bundle-locals.d.ts +6 -0
  245. package/types/plugs/esbuild/check-dependencies.d.ts +12 -0
  246. package/types/plugs/esbuild/fix-extensions.d.ts +29 -0
  247. package/types/plugs/esbuild.d.ts +24 -0
  248. package/types/plugs/eslint/runner.d.ts +22 -0
  249. package/types/plugs/exec.d.ts +90 -0
  250. package/types/plugs/filter.d.ts +23 -0
  251. package/types/plugs/mocha/reporter.d.ts +8 -0
  252. package/types/plugs/mocha/runner.d.ts +34 -0
  253. package/types/plugs/tsc/compiler.d.ts +24 -0
  254. package/types/plugs/tsc/options.d.ts +8 -0
  255. package/types/plugs/tsc/report.d.ts +5 -0
  256. package/types/plugs/tsc/runner.d.ts +13 -0
  257. package/types/plugs.d.ts +16 -0
  258. package/types/run.d.ts +89 -0
  259. package/types/task.d.ts +15 -0
  260. package/types/utils/asyncfs.d.ts +37 -0
  261. package/types/utils/caller.d.ts +7 -0
  262. package/types/utils/match.d.ts +216 -0
  263. package/types/utils/options.d.ts +15 -0
  264. package/types/utils/walk.d.ts +28 -0
@@ -0,0 +1,53 @@
1
+ import { Logger } from '../../log.js';
2
+ import { AbsolutePath } from '../../paths.js';
3
+ import { CoverageAnalyser } from './analysis.js';
4
+ /**
5
+ * A constant indicating that coverage was skipped (is irrelevant, for e.g.
6
+ * comment or typescript definition nodes)
7
+ */
8
+ export declare const COVERAGE_SKIPPED = -2;
9
+ /**
10
+ * A constant indicating that coverage was intentionally ignored because of a
11
+ * specific "coverage ignore ..." comment
12
+ */
13
+ export declare const COVERAGE_IGNORED = -1;
14
+ /** Node coverage summary */
15
+ export interface NodeCoverageResult {
16
+ /** Number of _covered_ nodes (good!) */
17
+ coveredNodes: number;
18
+ /** Number of nodes with _no coverage_ (bad!) */
19
+ missingNodes: number;
20
+ /** Number of nodes ignored by comments like `coverage ignore xxx` */
21
+ ignoredNodes: number;
22
+ /** Total number of nodes (sum of `covered`, `missing` and `ignored`) */
23
+ totalNodes: number;
24
+ /** Percentage of code coverage (covered as a % of total - ignored nodes)*/
25
+ coverage: number;
26
+ }
27
+ /** Per-file coverage result */
28
+ export interface CoverageResult {
29
+ /** The actual code this coverage is for */
30
+ code: string;
31
+ /**
32
+ * Per _character_ coverage report:
33
+ * - `-2`: coverage skipped (comments, typescript declarations, ...)
34
+ * - `-1`: coverage ignored (when using `coverage ignore xxx`)
35
+ * - `0`: no coverage collected for this character
36
+ * - _any number greater than zero_: number of times this was covered
37
+ */
38
+ codeCoverage: number[];
39
+ /** Node coverage summary */
40
+ nodeCoverage: NodeCoverageResult;
41
+ }
42
+ /** Aggregation of {@link CoverageResult} over all files */
43
+ export declare type CoverageResults = Record<AbsolutePath, CoverageResult>;
44
+ /** Our coverage report, per file */
45
+ export interface CoverageReport {
46
+ results: CoverageResults;
47
+ nodes: NodeCoverageResult;
48
+ }
49
+ /**
50
+ * Analyse coverage for the specified source files, using the data from the
51
+ * specified coverage files and produce a {@link CoverageReport}.
52
+ */
53
+ export declare function coverageReport(analyser: CoverageAnalyser, sourceFiles: AbsolutePath[], log: Logger): Promise<CoverageReport>;
@@ -0,0 +1,46 @@
1
+ import { Files } from '../files.js';
2
+ import { Plug } from '../pipe.js';
3
+ import { Run } from '../run.js';
4
+ import { SourceMapBias } from './coverage/analysis.js';
5
+ /** Options to analyse coverage reports */
6
+ export interface CoverageOptions {
7
+ /** The bias for source map analisys (defaults to `greatest_lower_bound`) */
8
+ sourceMapBias?: SourceMapBias;
9
+ /** Minimum _overall_ coverage (as a percentage) */
10
+ minimumCoverage?: number;
11
+ /** Optimal _overall_ coverage (as a percentage) */
12
+ optimalCoverage?: number;
13
+ /** Minimum _per-file_ coverage (as a percentage) */
14
+ minimumFileCoverage?: number;
15
+ /** Optimal _per-file_ coverage (as a percentage) */
16
+ optimalFileCoverage?: number;
17
+ }
18
+ export interface CoverageReportOptions extends CoverageOptions {
19
+ /** If specified, a JSON and HTML report will be written to this directory */
20
+ reportDir: string;
21
+ }
22
+ /**
23
+ * The {@link Coverage} plug type is inferred from the constructor, so this
24
+ * type helps to declare the correct types as we can't really infer them from
25
+ * `typeof Coverage`...
26
+ */
27
+ declare type CoverageConstructor = {
28
+ new (coverageDir: string): Coverage<CoverageOptions>;
29
+ new (coverageDir: string, options: CoverageOptions): Coverage<CoverageOptions>;
30
+ new (coverageDir: string, options: CoverageReportOptions): Coverage<CoverageReportOptions>;
31
+ };
32
+ /** Analyse coverage using files generated by V8/NodeJS. */
33
+ export declare class Coverage<T extends CoverageOptions | CoverageReportOptions> implements Plug<T extends CoverageReportOptions ? Files : undefined> {
34
+ private readonly _coverageDir;
35
+ private readonly _options;
36
+ constructor(coverageDir: string);
37
+ constructor(coverageDir: string, options?: T);
38
+ pipe(files: Files, run: Run): Promise<T extends CoverageReportOptions ? Files : undefined>;
39
+ }
40
+ declare module '../pipe.js' {
41
+ interface Pipe {
42
+ /** Analyse coverage using files generated by V8/NodeJS. */
43
+ coverage: PipeExtension<CoverageConstructor>;
44
+ }
45
+ }
46
+ export {};
@@ -0,0 +1,14 @@
1
+ import { Files } from '../files.js';
2
+ import { Plug } from '../pipe.js';
3
+ import { Run } from '../run.js';
4
+ /** Writes some info about the current {@link Files} being passed around. */
5
+ export declare class Debug implements Plug<Files> {
6
+ constructor();
7
+ pipe(files: Files, run: Run): Promise<Files>;
8
+ }
9
+ declare module '../pipe.js' {
10
+ interface Pipe {
11
+ /** Writes some info about the current {@link Files} being passed around. */
12
+ debug: PipeExtension<typeof Debug>;
13
+ }
14
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'esbuild';
2
+ /**
3
+ * A simple ESBuild plugin bundling _only_ local files, and marking anything
4
+ * imported from `node_modules` as _external_.
5
+ */
6
+ export declare function bundleLocals(): Plugin;
@@ -0,0 +1,12 @@
1
+ import { Plugin } from 'esbuild';
2
+ export interface CheckDependenciesOptions {
3
+ allowDev?: boolean | 'warn' | 'error';
4
+ allowPeer?: boolean | 'warn' | 'error';
5
+ allowOptional?: boolean | 'warn' | 'error';
6
+ allowUnused?: boolean | 'warn' | 'error';
7
+ ignored?: string[];
8
+ }
9
+ export declare function checkDependencies(): Plugin;
10
+ export declare function checkDependencies(packageJson: string): Plugin;
11
+ export declare function checkDependencies(options: CheckDependenciesOptions): Plugin;
12
+ export declare function checkDependencies(packageJson: string, options: CheckDependenciesOptions): Plugin;
@@ -0,0 +1,29 @@
1
+ import { Plugin } from 'esbuild';
2
+ /**
3
+ * A simple ESBuild plugin fixing extensions for `require` and `import` calls.
4
+ *
5
+ * This can be useful when compiling dual-module packages (`esm` and `cjs`),
6
+ * where the file module type is determined by the `.mjs` or `.cjs` extension.
7
+ *
8
+ * For example this will make sure all `import` statements use the `.mjs`
9
+ * extensions, while all `require` use `.cjs`.
10
+ *
11
+ * ```
12
+ * await find('*.ts', { directory: 'src' })
13
+ * .esbuild({
14
+ * outdir: 'dist',
15
+ * format: 'cjs',
16
+ * plugins: [ fixExtensions ],
17
+ * outExtension: { '.js': '.mjs' },
18
+ * })
19
+ *
20
+ * await find('*.ts', { directory: 'src' })
21
+ * .esbuild({
22
+ * outdir: 'dist',
23
+ * format: 'esm',
24
+ * plugins: [ fixExtensions ],
25
+ * outExtension: { '.js': '.mjs' },
26
+ * })
27
+ * ```
28
+ */
29
+ export declare function fixExtensions(): Plugin;
@@ -0,0 +1,24 @@
1
+ import { BuildOptions } from 'esbuild';
2
+ import { Files } from '../files.js';
3
+ import { Plug } from '../pipe.js';
4
+ import { Run } from '../run.js';
5
+ export declare type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'>;
6
+ /**
7
+ * Transpile and bundle files with {@link https://esbuild.github.io/ | esbuild}.
8
+ */
9
+ export declare class ESBuild implements Plug<Files> {
10
+ private readonly _options;
11
+ constructor(options: ESBuildOptions);
12
+ pipe(files: Files, run: Run): Promise<Files>;
13
+ }
14
+ declare module '../pipe.js' {
15
+ interface Pipe {
16
+ /**
17
+ * Transpile and bundle files with {@link https://esbuild.github.io/ esbuild}.
18
+ */
19
+ esbuild: PipeExtension<typeof ESBuild>;
20
+ }
21
+ }
22
+ export * from './esbuild/bundle-locals.js';
23
+ export * from './esbuild/check-dependencies.js';
24
+ export * from './esbuild/fix-extensions.js';
@@ -0,0 +1,22 @@
1
+ import { Files } from '../../files.js';
2
+ import { Plug } from '../../pipe.js';
3
+ import { Run } from '../../run.js';
4
+ export interface ESLintOptions {
5
+ /** ESLint's own _current working directory_, where config files are. */
6
+ directory?: string;
7
+ /** Show sources in report? */
8
+ showSources?: boolean;
9
+ /**
10
+ * ESLint's _override_ configuration file: configurations specified in this
11
+ * file will override any other configuration specified elsewhere.
12
+ */
13
+ configFile?: string;
14
+ }
15
+ /** Writes some info about the current {@link Files} being passed around. */
16
+ export default class ESLint implements Plug<undefined> {
17
+ private readonly _options;
18
+ constructor();
19
+ constructor(configFile: string);
20
+ constructor(options: ESLintOptions);
21
+ pipe(files: Files, run: Run): Promise<undefined>;
22
+ }
@@ -0,0 +1,90 @@
1
+ import { Files } from '../files.js';
2
+ import { Plug } from '../pipe.js';
3
+ import { Run } from '../run.js';
4
+ import { ParseOptions } from '../utils/options.js';
5
+ /** Options for executing scripts */
6
+ export interface ExecOptions {
7
+ /** Extra environment variables, or overrides for existing ones */
8
+ env?: Record<string, any>;
9
+ /** Whether to run in the context of a _shell_ or not */
10
+ shell?: string | boolean;
11
+ /**
12
+ * The current working directory of the process to execute.
13
+ *
14
+ * Defaults to the current {@link Files.directory | Files' directory} when
15
+ * used as a {@link Plug} or `process.cwd()` when used from {@link exec}.
16
+ */
17
+ cwd?: string;
18
+ /**
19
+ * When used as a {@link Plug}, the {@link Files} will be appended to the
20
+ * current arguments as _relative_ files (default) or _absolute_ (if false).
21
+ */
22
+ relativePaths?: boolean;
23
+ }
24
+ /**
25
+ * Execute a shell command, adding to its _arguments_ the list of files from
26
+ * the current pipe (much like `xargs` does on Unix systems).
27
+ *
28
+ * This {@link Plug} returns the same {@link Files} it was given, so that
29
+ * executing a shell command doesn't interrupt a {@link Pipe}.
30
+ *
31
+ * For example:
32
+ *
33
+ * ```
34
+ * import { find, exec } from '@plugjs/plugjs'
35
+ *
36
+ * export default build({
37
+ * async runme() {
38
+ * find('*.ts', { directory: 'src' })
39
+ * .plug(new Exec('chmod', '755' }))
40
+ * .plug(new Exec('chown root:root', { shell: true }))
41
+ * },
42
+ * })
43
+ * ```
44
+ */
45
+ export declare class Exec implements Plug<Files> {
46
+ private readonly _cmd;
47
+ private readonly _args;
48
+ private readonly _options;
49
+ constructor(cmd: string, ...args: ParseOptions<ExecOptions>);
50
+ pipe(files: Files, run: Run): Promise<Files>;
51
+ }
52
+ /**
53
+ * Execute a command and await for its result from within a task.
54
+ *
55
+ * For example:
56
+ *
57
+ * ```
58
+ * import { exec } from '@plugjs/plugjs'
59
+ *
60
+ * export default build({
61
+ * async runme() {
62
+ * await exec('ls', '-la', '/')
63
+ * },
64
+ * })
65
+ * ```
66
+ */
67
+ export declare function exec(cmd: string, ...args: ParseOptions<ExecOptions>): Promise<void>;
68
+ declare module '../pipe.js' {
69
+ interface Pipe {
70
+ /**
71
+ * Execute a shell command, adding to its _arguments_ the list of files
72
+ * from the current pipe (much like `xargs` does on Unix systems).
73
+ *
74
+ * For example:
75
+ *
76
+ * ```
77
+ * import { find, exec } from '@plugjs/plugjs'
78
+ *
79
+ * export default build({
80
+ * async runme() {
81
+ * find('*.ts', { directory: 'src' })
82
+ * .exec('chmod', '755' })
83
+ * .exec('chown root:root', { shell: true })
84
+ * },
85
+ * })
86
+ * ```
87
+ */
88
+ exec: PipeExtension<typeof Exec>;
89
+ }
90
+ }
@@ -0,0 +1,23 @@
1
+ import { Files } from '../files.js';
2
+ import { Plug } from '../pipe.js';
3
+ import { Run } from '../run.js';
4
+ import { MatchOptions } from '../utils/match.js';
5
+ import { ParseOptions } from '../utils/options.js';
6
+ /** Options for filtering {@link Files}. */
7
+ export interface FilterOptions extends MatchOptions {
8
+ /** The base directory for filtering, and relativising the resulting files. */
9
+ directory?: string;
10
+ }
11
+ /** Filter the current {@link Files} using globs. */
12
+ export declare class Filter implements Plug<Files> {
13
+ private readonly _globs;
14
+ private readonly _options;
15
+ constructor(glob: string, ...args: ParseOptions<FilterOptions>);
16
+ pipe(files: Files, run: Run): Files;
17
+ }
18
+ declare module '../pipe.js' {
19
+ interface Pipe {
20
+ /** Filter the current {@link Files} using globs. */
21
+ filter: PipeExtension<typeof Filter>;
22
+ }
23
+ }
@@ -0,0 +1,8 @@
1
+ import RealMocha from 'mocha';
2
+ /** Symbol to inject `Logger` in reporter options */
3
+ export declare const logSymbol: unique symbol;
4
+ /** Symbol to inject `Run` in reporter options */
5
+ export declare const runSymbol: unique symbol;
6
+ export declare class PlugReporter extends RealMocha.reporters.Base {
7
+ constructor(runner: RealMocha.Runner, options: RealMocha.MochaOptions);
8
+ }
@@ -0,0 +1,34 @@
1
+ import { Files } from '../../files.js';
2
+ import { Plug } from '../../pipe.js';
3
+ import { Run } from '../../run.js';
4
+ /** Options to construct our {@link Mocha} plug. */
5
+ export interface MochaOptions {
6
+ /** Specify the directory where coverage data will be saved */
7
+ coverageDir?: string;
8
+ /** Bail after first test failure? */
9
+ bail?: boolean;
10
+ /** Show diff on failure? */
11
+ diff?: boolean;
12
+ /** Report tests without running them? */
13
+ dryRun?: boolean;
14
+ /** Tests marked `only` fail the suite? */
15
+ forbidOnly?: boolean;
16
+ /** Pending tests fail the suite? */
17
+ forbidPending?: false;
18
+ /** Reporter name. */
19
+ reporter?: string;
20
+ /** Options for the reporter */
21
+ reporterOptions?: Record<string, any>;
22
+ /** Number of times to retry failed tests. */
23
+ retries?: number;
24
+ /** Slow threshold value. */
25
+ slow?: number;
26
+ /** Timeout threshold value. */
27
+ timeout?: number;
28
+ }
29
+ /** Writes some info about the current {@link Files} being passed around. */
30
+ export default class Mocha implements Plug<undefined> {
31
+ private readonly _options;
32
+ constructor(_options?: MochaOptions);
33
+ pipe(files: Files, run: Run): Promise<undefined>;
34
+ }
@@ -0,0 +1,24 @@
1
+ import ts from 'typescript';
2
+ import { AbsolutePath } from '../../paths.js';
3
+ export declare class TypeScriptHost implements ts.CompilerHost {
4
+ private readonly _directory;
5
+ constructor(directory: AbsolutePath);
6
+ /** Get a source file parsing one of our virtual files */
7
+ getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile | undefined;
8
+ /** Never write any files */
9
+ writeFile(fileName: string): void;
10
+ /** Get the default library associated with the given options */
11
+ getDefaultLibFileName(options: ts.CompilerOptions): string;
12
+ /** Check for filesystem case sensitivity */
13
+ useCaseSensitiveFileNames(): boolean;
14
+ /** Check for the existence of a given file */
15
+ fileExists(fileName: string): boolean;
16
+ /** Read the file if it exists, otherwise return undefined */
17
+ readFile(fileName: string): string | undefined;
18
+ /** Return the current working directory */
19
+ getCurrentDirectory(): AbsolutePath;
20
+ /** Return the canonical name for the specified file */
21
+ getCanonicalFileName(fileName: string): string;
22
+ /** Return the new line sequence used by this platform */
23
+ getNewLine(): string;
24
+ }
@@ -0,0 +1,8 @@
1
+ import ts from 'typescript';
2
+ import { AbsolutePath } from '../../paths.js';
3
+ export declare type CompilerOptionsAndDiagnostics = {
4
+ options: ts.CompilerOptions;
5
+ errors: readonly ts.Diagnostic[];
6
+ };
7
+ export declare function getCompilerOptions(file?: AbsolutePath): Promise<CompilerOptionsAndDiagnostics>;
8
+ export declare function getCompilerOptions(file: AbsolutePath | undefined, overrides: ts.CompilerOptions, overridesFile: AbsolutePath): Promise<CompilerOptionsAndDiagnostics>;
@@ -0,0 +1,5 @@
1
+ import ts from 'typescript';
2
+ import { Report } from '../../log.js';
3
+ import { AbsolutePath } from '../../paths.js';
4
+ /** Update a report, adding records from an array of {@link ts.Diagnostic} */
5
+ export declare function updateReport(report: Report, diagnostics: readonly ts.Diagnostic[], directory: AbsolutePath): void;
@@ -0,0 +1,13 @@
1
+ import ts from 'typescript';
2
+ import { Files } from '../../files.js';
3
+ import { Plug } from '../../pipe.js';
4
+ import { Run } from '../../run.js';
5
+ export default class Tsc implements Plug<Files> {
6
+ private readonly _tsconfig?;
7
+ private readonly _options;
8
+ constructor();
9
+ constructor(config: string);
10
+ constructor(options: ts.CompilerOptions);
11
+ constructor(config: string, options: ts.CompilerOptions);
12
+ pipe(files: Files, run: Run): Promise<Files>;
13
+ }
@@ -0,0 +1,16 @@
1
+ import type ESLint from './plugs/eslint/runner.js';
2
+ import type Mocha from './plugs/mocha/runner.js';
3
+ import type Tsc from './plugs/tsc/runner.js';
4
+ declare module './pipe.js' {
5
+ interface Pipe {
6
+ eslint: PipeExtension<typeof ESLint>;
7
+ mocha: PipeExtension<typeof Mocha>;
8
+ tsc: PipeExtension<typeof Tsc>;
9
+ }
10
+ }
11
+ export * from './plugs/copy.js';
12
+ export * from './plugs/coverage.js';
13
+ export * from './plugs/debug.js';
14
+ export * from './plugs/esbuild.js';
15
+ export * from './plugs/exec.js';
16
+ export * from './plugs/filter.js';
package/types/run.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { Files, FilesBuilder } from './files.js';
2
+ import { Logger, LogLevelString, Report } from './log.js';
3
+ import { AbsolutePath } from './paths.js';
4
+ import { Pipe } from './pipe.js';
5
+ import { ParseOptions } from './utils/options.js';
6
+ import { WalkOptions } from './utils/walk.js';
7
+ /** The {@link FindOptions} interface defines the options for finding files. */
8
+ export interface FindOptions extends WalkOptions {
9
+ /**
10
+ * The directory where to start looking for files according to the rules
11
+ * specified in {@link Run.resolve}.
12
+ */
13
+ directory?: string;
14
+ }
15
+ /**
16
+ * The {@link Run} interface defines the context in which a {@link Task} is
17
+ * invoked.
18
+ *
19
+ * Runs keep track of the invocation stack (to avoid circular dependencies) and
20
+ * of the cached results for {@link Task} invocations.
21
+ */
22
+ export interface Run {
23
+ /**
24
+ * The _name_ of the task associated with this {@link Run} (if one is).
25
+ *
26
+ * Tasks can have different names in different builds, this refers to the
27
+ * _task name_ in the build being executed.
28
+ */
29
+ readonly taskName: string;
30
+ /** The absolute file name of the build */
31
+ readonly buildFile: AbsolutePath;
32
+ /** For convenience, the directory of the build file */
33
+ readonly buildDir: AbsolutePath;
34
+ /** The {@link Logger} associated with this instance. */
35
+ readonly log: Logger;
36
+ /** Set the logging level within this {@link Run} */
37
+ setLogLevel(level: LogLevelString): void;
38
+ /** Call another {@link Task} from this one. */
39
+ call(name: string): Promise<Files | undefined>;
40
+ /** Create a new {@link Report} with the given _title_ */
41
+ report(title: string): Report;
42
+ /**
43
+ * Resolve a path in the context of this {@link Run}.
44
+ *
45
+ * If the path starts with `@...` it is considered to be relative to the
46
+ * {@link process.cwd | current working directory}, otherwise it will be
47
+ * resolved against the build file where the task was originally defined in.
48
+ */
49
+ resolve(...paths: string[]): AbsolutePath;
50
+ /** Create a {@link FilesBuilder} cloning an existing {@link Files}. */
51
+ files(files: Files): FilesBuilder;
52
+ /**
53
+ * Create a {@link FilesBuilder} instance resolving the directory specified
54
+ * according to the rules specified in {@link Run.resolve}.
55
+ */
56
+ files(...paths: string[]): FilesBuilder;
57
+ /**
58
+ * Find files according to the globs and {@link FindOptions} specified.
59
+ */
60
+ find(glob: string, ...args: ParseOptions<FindOptions>): Pipe & Promise<Files>;
61
+ /**
62
+ * Create a new {@link Pipe} wrapping the specified {@link Files}.
63
+ */
64
+ pipe(files: Files | Promise<Files>): Pipe & Promise<Files>;
65
+ }
66
+ /** Constructor options for our default {@link Run} implementation */
67
+ export interface RunConstructionOptions {
68
+ readonly taskName: string;
69
+ readonly buildDir: AbsolutePath;
70
+ readonly buildFile: AbsolutePath;
71
+ readonly log?: Logger;
72
+ }
73
+ /** Our default {@link Run} implementation */
74
+ export declare class RunImpl implements Run {
75
+ readonly taskName: string;
76
+ readonly buildFile: AbsolutePath;
77
+ readonly buildDir: AbsolutePath;
78
+ readonly log: Logger;
79
+ constructor(options: RunConstructionOptions);
80
+ /** Set the logging level within this {@link Run} */
81
+ setLogLevel(level: LogLevelString): void;
82
+ report(title: string): Report;
83
+ resolve(...paths: string[]): AbsolutePath;
84
+ files(files: Files): FilesBuilder;
85
+ files(...paths: string[]): FilesBuilder;
86
+ find(glob: string, ...args: ParseOptions<FindOptions>): Pipe & Promise<Files>;
87
+ pipe(files: Files | Promise<Files>): Pipe & Promise<Files>;
88
+ call(name: string): Promise<Files | undefined>;
89
+ }
@@ -0,0 +1,15 @@
1
+ import type { BuildContext, TaskDefinition, ThisBuild } from './build.js';
2
+ import type { Files } from './files.js';
3
+ import type { Run } from './run.js';
4
+ export interface Task<T extends Files | undefined = Files | undefined> {
5
+ /** The {@link BuildContext} of where this task was originally defined */
6
+ readonly context: BuildContext;
7
+ /** Invoked by the {@link Run} when actually executing this {@link Task} */
8
+ call(thisBuild: ThisBuild<any>, run: Run): Promise<T>;
9
+ }
10
+ export declare class TaskImpl implements Task<Files | undefined> {
11
+ readonly context: BuildContext;
12
+ private readonly _definition;
13
+ constructor(context: BuildContext, _definition: TaskDefinition<any>);
14
+ call(self: ThisBuild<any>, run: Run): Promise<Files | undefined>;
15
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { constants } from 'node:fs';
3
+ import fsp from 'node:fs/promises';
4
+ declare const fs: typeof fsp & {
5
+ constants: typeof constants;
6
+ };
7
+ export default fs;
8
+ export declare const access: typeof fsp.access;
9
+ export declare const copyFile: typeof fsp.copyFile;
10
+ export declare const cp: typeof fsp.cp;
11
+ export declare const open: typeof fsp.open;
12
+ export declare const opendir: typeof fsp.opendir;
13
+ export declare const rename: typeof fsp.rename;
14
+ export declare const truncate: typeof fsp.truncate;
15
+ export declare const rm: typeof fsp.rm;
16
+ export declare const rmdir: typeof fsp.rmdir;
17
+ export declare const mkdir: typeof fsp.mkdir;
18
+ export declare const readdir: typeof fsp.readdir;
19
+ export declare const readlink: typeof fsp.readlink;
20
+ export declare const symlink: typeof fsp.symlink;
21
+ export declare const lstat: typeof fsp.lstat;
22
+ export declare const stat: typeof fsp.stat;
23
+ export declare const link: typeof fsp.link;
24
+ export declare const unlink: typeof fsp.unlink;
25
+ export declare const chmod: typeof fsp.chmod;
26
+ export declare const lchmod: typeof fsp.lchmod;
27
+ export declare const lchown: typeof fsp.lchown;
28
+ export declare const chown: typeof fsp.chown;
29
+ export declare const utimes: typeof fsp.utimes;
30
+ export declare const lutimes: typeof fsp.lutimes;
31
+ export declare const realpath: typeof fsp.realpath;
32
+ export declare const mkdtemp: typeof fsp.mkdtemp;
33
+ export declare const writeFile: typeof fsp.writeFile;
34
+ export declare const appendFile: typeof fsp.appendFile;
35
+ export declare const readFile: typeof fsp.readFile;
36
+ export declare const watch: typeof fsp.watch;
37
+ export { constants } from 'node:fs';
@@ -0,0 +1,7 @@
1
+ import { AbsolutePath } from '../paths.js';
2
+ export interface Location {
3
+ file: AbsolutePath;
4
+ line?: number | undefined;
5
+ column?: number | undefined;
6
+ }
7
+ export declare function findCaller(of: (...args: any[]) => any): Location;