@plugjs/plug 0.0.14 → 0.0.15

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 +144 -110
  7. package/dist/build.cjs.map +2 -2
  8. package/dist/build.d.ts +12 -56
  9. package/dist/build.mjs +146 -112
  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 +61 -63
  22. package/dist/helpers.cjs.map +2 -2
  23. package/dist/helpers.d.ts +15 -37
  24. package/dist/helpers.mjs +61 -64
  25. package/dist/helpers.mjs.map +2 -2
  26. package/dist/index.cjs +3 -2
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +9 -13
  29. package/dist/index.mjs +3 -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 +41 -34
  54. package/dist/pipe.cjs.map +1 -1
  55. package/dist/pipe.d.ts +149 -119
  56. package/dist/pipe.mjs +38 -32
  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 +19 -25
  70. package/dist/plugs/coverage.cjs.map +1 -1
  71. package/dist/plugs/coverage.d.ts +33 -30
  72. package/dist/plugs/coverage.mjs +20 -18
  73. package/dist/plugs/coverage.mjs.map +1 -1
  74. package/dist/plugs/debug.cjs +8 -37
  75. package/dist/plugs/debug.cjs.map +1 -1
  76. package/dist/plugs/debug.d.ts +4 -11
  77. package/dist/plugs/debug.mjs +24 -20
  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 +72 -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 +6 -6
  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 +89 -101
  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 +191 -178
  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 +22 -27
  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 +123 -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
@@ -1,15 +1,14 @@
1
- import ts from 'typescript' // TypeScript does NOT support ESM modules
2
-
3
- import { failure } from '../../assert.js'
4
- import { Files } from '../../files.js'
5
- import { $p, log } from '../../log.js'
6
- import { AbsolutePath, resolveFile } from '../../paths.js'
7
- import { Plug } from '../../pipe.js'
8
- import { Run } from '../../run.js'
9
- import { parseOptions, ParseOptions } from '../../utils/options.js'
10
- import { TypeScriptHost } from './compiler.js'
11
- import { getCompilerOptions } from './options.js'
12
- import { updateReport } from './report.js'
1
+ import ts from 'typescript'; // TypeScript does NOT support ESM modules
2
+
3
+ import { failure } from '../../assert'
4
+ import { Files } from '../../files'
5
+ import { $p, log } from '../../log'
6
+ import { AbsolutePath, resolveFile } from '../../paths'
7
+ import { Context, PipeParameters, Plug } from '../../pipe'
8
+ import { parseOptions } from '../../utils/options'
9
+ import { TypeScriptHost } from './compiler'
10
+ import { getCompilerOptions } from './options'
11
+ import { updateReport } from './report'
13
12
 
14
13
  /* ========================================================================== *
15
14
  * WORKER PLUG *
@@ -19,20 +18,15 @@ export default class Tsc implements Plug<Files> {
19
18
  private readonly _tsconfig?: string
20
19
  private readonly _options: ts.CompilerOptions
21
20
 
22
- constructor()
23
- constructor(config: string)
24
- constructor(options: ts.CompilerOptions)
25
- constructor(config: string, options: ts.CompilerOptions)
26
-
27
- constructor(...args: ParseOptions<ts.CompilerOptions>) {
21
+ constructor(...args: PipeParameters<'tsc'>) {
28
22
  const { params: [ tsconfig ], options } = parseOptions(args, {})
29
23
  this._tsconfig = tsconfig
30
24
  this._options = options
31
25
  }
32
26
 
33
- async pipe(files: Files, run: Run): Promise<Files> {
34
- const baseDir = run.resolve('.') // "this" directory, base of all relative paths
35
- const report = run.report('TypeScript Report') // report used throughout
27
+ async pipe(files: Files, context: Context): Promise<Files> {
28
+ const baseDir = context.resolve('.') // "this" directory, base of all relative paths
29
+ const report = context.log.report('TypeScript Report') // report used throughout
36
30
  const overrides = { ...this._options } // clone our options
37
31
 
38
32
  /*
@@ -40,13 +34,13 @@ export default class Tsc implements Plug<Files> {
40
34
  * alongside the sources, otherwise checked in the current directory.
41
35
  */
42
36
  const sourcesConfig = resolveFile(files.directory, 'tsconfig.json')
43
- const tsconfig = this._tsconfig ? run.resolve(this._tsconfig) :
44
- sourcesConfig || resolveFile(run.resolve('tsconfig.json'))
37
+ const tsconfig = this._tsconfig ? context.resolve(this._tsconfig) :
38
+ sourcesConfig || resolveFile(context.resolve('tsconfig.json'))
45
39
 
46
40
  /* Root directory must always exist */
47
41
  let rootDir: AbsolutePath
48
42
  if (overrides.rootDir) {
49
- rootDir = overrides.rootDir = run.resolve(overrides.rootDir)
43
+ rootDir = overrides.rootDir = context.resolve(overrides.rootDir)
50
44
  } else {
51
45
  rootDir = overrides.rootDir = files.directory
52
46
  }
@@ -54,24 +48,24 @@ export default class Tsc implements Plug<Files> {
54
48
  /* Output directory _also_ must always exist */
55
49
  let outDir: AbsolutePath
56
50
  if (overrides.outDir) {
57
- outDir = overrides.outDir = run.resolve(overrides.outDir)
51
+ outDir = overrides.outDir = context.resolve(overrides.outDir)
58
52
  } else {
59
53
  outDir = overrides.outDir = rootDir // default to the root directory
60
54
  }
61
55
 
62
56
  /* All other root paths */
63
57
  if (overrides.rootDirs) {
64
- overrides.rootDirs = overrides.rootDirs.map((dir) => run.resolve(dir))
58
+ overrides.rootDirs = overrides.rootDirs.map((dir) => context.resolve(dir))
65
59
  }
66
60
 
67
61
  /* The baseURL is resolved, as well */
68
- if (overrides.baseUrl) overrides.baseUrl = run.resolve(overrides.baseUrl)
62
+ if (overrides.baseUrl) overrides.baseUrl = context.resolve(overrides.baseUrl)
69
63
 
70
64
  /* We can now get our compiler options, and check any and all overrides */
71
65
  const { errors, options } = await getCompilerOptions(
72
66
  tsconfig, // resolved tsconfig.json from constructor, might be undefined
73
67
  overrides, // overrides from constructor, might be an empty object
74
- run.buildFile, // the build file where the overrides were specified,
68
+ context.buildFile, // the build file where the overrides were specified,
75
69
  baseDir) // base dir where to resolve overrides
76
70
 
77
71
  /* Update report and fail on errors */
@@ -95,13 +89,13 @@ export default class Tsc implements Plug<Files> {
95
89
  if (report.errors) report.done(true)
96
90
 
97
91
  /* Write out all files asynchronously */
98
- const builder = run.files(outDir)
92
+ const builder = Files.builder(outDir)
99
93
  const promises: Promise<void>[] = []
100
94
  const result = program.emit(undefined, (fileName, code) => {
101
95
  promises.push(builder.write(fileName, code).then((file) => {
102
96
  log.trace('Written', $p(file))
103
97
  }).catch((error) => {
104
- run.log.error('Error writing to', fileName, error)
98
+ context.log.error('Error writing to', fileName, error)
105
99
  throw failure() // no more logs!
106
100
  }))
107
101
  })
@@ -0,0 +1,45 @@
1
+ import type { CompilerOptions } from 'typescript'
2
+
3
+ import { requireResolve } from '../paths'
4
+ import { installForking } from '../pipe'
5
+
6
+ declare module '../pipe' {
7
+ export interface Pipe {
8
+ /**
9
+ * Run the {@link https://www.typescriptlang.org/ TypeScript Compiler}
10
+ * over the input source files, using the default `tsconfig.json` file.
11
+ */
12
+ tsc(): Pipe
13
+
14
+ /**
15
+ * Run the {@link https://www.typescriptlang.org/ TypeScript Compiler}
16
+ * over the input source files, specifying the `tsconfig.json` file.
17
+ *
18
+ * @param configFile The `tsconfig.json` file to use.
19
+ */
20
+ tsc(configFile: string): Pipe
21
+
22
+ /**
23
+ * Run the {@link https://www.typescriptlang.org/ TypeScript Compiler}
24
+ * over the input source files, using the default `tsconfig.json` file
25
+ * and overriding some options
26
+ *
27
+ * @param options {@link CompilerOptions | Options} overriding what's
28
+ * currently specified in the default `tsconfig.json`.
29
+ */
30
+ tsc(options: CompilerOptions): Pipe
31
+
32
+ /**
33
+ * Run the {@link https://www.typescriptlang.org/ TypeScript Compiler}
34
+ * over the input source files, specifying the `tsconfig.json` file
35
+ * and overriding some options
36
+ *
37
+ * @param configFile The `tsconfig.json` file to use.
38
+ * @param options {@link CompilerOptions | Options} overriding what's
39
+ * currently specified in the specified `tsconfig.json`.
40
+ */
41
+ tsc(configFile: string, options: CompilerOptions): Pipe
42
+ }
43
+ }
44
+
45
+ installForking('tsc', requireResolve(__fileurl, './tsc/runner'))
package/src/plugs.ts CHANGED
@@ -2,33 +2,18 @@
2
2
  * FORKING PLUGS *
3
3
  * ========================================================================== */
4
4
 
5
- import { installForking } from './fork.js'
6
- import { requireResolve } from './paths.js'
7
-
8
- import type ESLint from './plugs/eslint/runner.js'
9
- import type Mocha from './plugs/mocha/runner.js'
10
- import type Tsc from './plugs/tsc/runner.js'
11
-
12
- declare module './pipe.js' {
13
- export interface Pipe {
14
- eslint: PipeExtension<typeof ESLint>
15
- mocha: PipeExtension<typeof Mocha>
16
- tsc: PipeExtension<typeof Tsc>
17
- }
18
- }
19
-
20
- installForking('eslint', requireResolve(__fileurl, './plugs/eslint/runner'))
21
- installForking('mocha', requireResolve(__fileurl, './plugs/mocha/runner'))
22
- installForking('tsc', requireResolve(__fileurl, './plugs/tsc/runner'))
5
+ export * from './plugs/eslint'
6
+ export * from './plugs/mocha'
7
+ export * from './plugs/tsc'
23
8
 
24
9
  /* ========================================================================== *
25
10
  * STANDARD IN-PROCESS PLUGS *
26
11
  * ========================================================================== */
27
12
 
28
- export * from './plugs/copy.js'
29
- export * from './plugs/coverage.js'
30
- export * from './plugs/debug.js'
31
- export * from './plugs/esbuild.js'
32
- export * from './plugs/exec.js'
33
- export * from './plugs/filter.js'
34
- export * from './plugs/rmf.js'
13
+ export * from './plugs/copy'
14
+ export * from './plugs/coverage'
15
+ export * from './plugs/debug'
16
+ export * from './plugs/esbuild'
17
+ export * from './plugs/exec'
18
+ export * from './plugs/filter'
19
+ export * from './plugs/rmf'
package/src/types.ts ADDED
@@ -0,0 +1,123 @@
1
+ import type { Files } from './files'
2
+ import type { AbsolutePath } from './paths'
3
+ import type { Pipe } from './pipe'
4
+
5
+ /**
6
+ * A type describing the ultimate result of a {@link Plug}, {@link Pipe} or
7
+ * {@link Task}, that is either a {@link Files} instance or `undefined`.
8
+ */
9
+ export type Result = Files | undefined
10
+
11
+ /* ========================================================================== *
12
+ * STATE AND CONTEXT *
13
+ * ========================================================================== */
14
+
15
+ /**
16
+ * The {@link State} interface defines a component tracking the current
17
+ * _state_ of a build, caching the result of {@link Task}s, and tracking their
18
+ * invocation stack to avoid infinite loops.
19
+ */
20
+ export interface State {
21
+ /** The cache of the result of {@link Task}s execution */
22
+ readonly cache: Map<Task, Promise<Result>>
23
+ /** The current {@link Task} invocation stack (to avoid infinite loops) */
24
+ readonly stack: Task[],
25
+ /** All {@link Tasks} available in this {@link State} */
26
+ readonly tasks: Tasks
27
+ /** All _properties_ available in this {@link State} */
28
+ readonly props: Props
29
+ }
30
+
31
+ /* ========================================================================== *
32
+ * TASKS *
33
+ * ========================================================================== */
34
+
35
+ /**
36
+ * The {@link Task} interface normalizes a task definition, associating it with
37
+ * its build file, its sibling {@link Task}s and available _properties_.
38
+ */
39
+ export interface Task<T extends Result = Result> {
40
+ /** All _properties_ siblings to this {@link Task} */
41
+ readonly props: Props
42
+ /** All {@link Tasks} sibling to this {@link Task} */
43
+ readonly tasks: Tasks
44
+ /** The absolute file name where this {@link Task} was defined */
45
+ readonly buildFile: AbsolutePath,
46
+ /** Invoke a task from (possibly) a different {@link Context} */
47
+ call(state: State, taskName: string): Promise<T>
48
+ }
49
+
50
+ /**
51
+ * The {@link TaskResult} type identifies _what_ can be returned by a
52
+ * {@link TaskDef | _task definition_}.
53
+ */
54
+ export type TaskResult = Pipe | Promise<undefined> | Files | void | undefined
55
+
56
+ /** The {@link TaskDef} type identifies the _definition_ of a task. */
57
+ export type TaskDef<R extends TaskResult = TaskResult> = () => R | Promise<R>
58
+
59
+ /* ========================================================================== *
60
+ * TASKS AND PROPERTIES *
61
+ * ========================================================================== */
62
+
63
+ /** A type identifying all _properties_ of a {@link Context}. */
64
+ export type Props<D extends BuildDef = BuildDef> = {
65
+ readonly [ k in string & keyof D as D[k] extends string ? k : never ] : string
66
+ }
67
+
68
+ /** A type identifying all _tasks_ in a {@link Context} */
69
+ export type Tasks<D extends BuildDef = BuildDef> = {
70
+ readonly [ k in string & keyof D as D[k] extends TaskDef | Task ? k : never ] :
71
+ D[k] extends TaskDef<infer R> ?
72
+ R extends void | undefined ? Task<undefined> :
73
+ R extends Promise<undefined> ? Task<undefined> :
74
+ R extends Pipe ? Task<Files> :
75
+ R extends Files ? Task<Files> :
76
+ never :
77
+ D[k] extends Task ? D[k] :
78
+ never
79
+ }
80
+
81
+ /* ========================================================================== *
82
+ * BUILD *
83
+ * ========================================================================== */
84
+
85
+ /**
86
+ * The {@link BuildDef} interface describes the _definition_ of a
87
+ * {@link Context}, that is the object passed to {@link build} to produce
88
+ * a {@link Build}.
89
+ */
90
+ export interface BuildDef {
91
+ [ k : string ] : string | TaskDef | Task
92
+ }
93
+
94
+ /**
95
+ * The type that will be used for `this` when invoking
96
+ * {@link TaskDef | task definitions }.
97
+ */
98
+ export type ThisBuild<D extends BuildDef> = {
99
+ readonly [ k in keyof D ] :
100
+ k extends string ?
101
+ D[k] extends TaskDef<infer R> ?
102
+ R extends Promise<undefined> | void | undefined ? () => Promise<undefined> :
103
+ R extends Pipe | Files ? () => Pipe & Promise<Files> :
104
+ never :
105
+ D[k] extends Task<infer R> ?
106
+ R extends undefined ? () => Promise<undefined> :
107
+ R extends Files ? () => Pipe & Promise<Files> :
108
+ never :
109
+ D[k] extends string ?
110
+ string :
111
+ never :
112
+ never
113
+ }
114
+
115
+ /**
116
+ * The {@link Build} type represents the collection of {@link Task}s
117
+ * and _properties_ compiled from a {@link BuildDef | build definition}.
118
+ */
119
+ export type Build<
120
+ D extends BuildDef = BuildDef,
121
+ T extends Tasks<D> = Tasks<D>,
122
+ P extends Props<D> = Props<D>,
123
+ > = T & P
@@ -1,44 +1,33 @@
1
1
  import { statSync } from 'node:fs'
2
2
  import { fileURLToPath } from 'node:url'
3
- import { assert } from '../assert.js'
4
- import { AbsolutePath, assertAbsolutePath } from '../paths.js'
3
+ import { assert } from '../assert'
4
+ import { $p } from '../log'
5
+ import { AbsolutePath, assertAbsolutePath } from '../paths'
5
6
 
6
- export interface Location {
7
- file: AbsolutePath,
8
- line?: number | undefined,
9
- column?: number | undefined,
10
- }
11
-
12
- export function findCaller(of: (...args: any[]) => any): Location {
7
+ export function findCaller(of: (...args: any[]) => any): AbsolutePath {
13
8
  const oldPrepareStackTrace = Error.prepareStackTrace
14
9
 
15
10
  try {
16
- Error.prepareStackTrace = (_, stackTraces): Location | undefined => {
11
+ Error.prepareStackTrace = (_, stackTraces): AbsolutePath | undefined => {
17
12
  const nullableFileOrUrl = stackTraces[0].getFileName()
18
13
  if (! nullableFileOrUrl) return
19
14
 
20
- const nullableLine = stackTraces[0].getColumnNumber()
21
- const nullableColumn = stackTraces[0].getColumnNumber()
22
-
23
- const line = typeof nullableLine === 'number' ? nullableLine : undefined
24
- const column = typeof nullableColumn === 'number' ? nullableColumn : undefined
25
-
26
15
  const file =
27
16
  nullableFileOrUrl.startsWith('file:/') ?
28
17
  fileURLToPath(nullableFileOrUrl) :
29
18
  nullableFileOrUrl
30
19
 
31
20
  assertAbsolutePath(file)
32
- return { file, line, column }
21
+ return file
33
22
  }
34
23
 
35
- const record: { stack?: Location } = {}
24
+ const record: { stack?: AbsolutePath } = {}
36
25
  Error.captureStackTrace(record, of)
37
- const location = record.stack
26
+ const file = record.stack
38
27
 
39
- assert(location, 'Unable to determine build file name')
40
- assert(statSync(location.file).isFile(), `Build file "${location.file}" not found`)
41
- return location
28
+ assert(file, 'Unable to determine build file name')
29
+ assert(statSync(file).isFile(), `Build file ${$p(file)} not found`)
30
+ return file
42
31
  } finally {
43
32
  Error.prepareStackTrace = oldPrepareStackTrace
44
33
  }
@@ -1,22 +1,54 @@
1
- export type ParsedOptions<Options> = { params: string[], options: Options }
2
- export type ParsedOptionalOptions<Options> = { params: string[], options?: Options | undefined }
3
- export type ParseOptions<Options> = string[] | [ ...string[], Options ] | [ Options ]
4
-
5
- /** Parse an array of at least one string, followed by an optional `Options` argument. */
6
- export function parseOptions<Options>(args: ParseOptions<Options>): ParsedOptionalOptions<Options>
7
- /** Parse an array of at least one string, followed by an optional `Options` argument. */
8
- export function parseOptions<Options>(args: ParseOptions<Options>, defaults?: undefined): ParsedOptionalOptions<Options>
9
- /** Parse an array of at least one string, followed by an optional `Options` argument, ensuring some defaults are present. */
10
- export function parseOptions<Options, Defaults extends Options>(args: ParseOptions<Options>, defaults: Defaults): ParsedOptions<Options & Defaults>
11
- // overloaded implementation
12
- export function parseOptions<Options, Defaults extends Options>(args: ParseOptions<Options>, defaults?: Defaults): ParsedOptions<any> {
1
+ /** A type extacting string parameters from an arguments array */
2
+ export type ParsedParams<Args extends readonly any[]> =
3
+ // Normal tuple, we stop processing if the _first_ argument is not a string!
4
+ Args extends readonly [ infer First, ...infer Rest ] ?
5
+ First extends string ? [ First, ...ParsedParams<Rest> ] : [] :
6
+
7
+ // If not caught above, here "first" is the rest parameter in the tuple
8
+ Args extends readonly [ ...infer First, infer Rest ] ?
9
+ Rest extends string ? [ ...ParsedParams<First>, Rest ] : [ ...ParsedParams<First> ] :
10
+
11
+ // Not a tuple: normal string array or the end of our arguments
12
+ Args extends readonly string[] ? [ ...Args ] : []
13
+
14
+ /** A type extacting the (last) options type from an arguments array */
15
+ export type ParsedOptions<Args extends readonly any[]> = // , Defaults> =
16
+ Args extends readonly [ ...string[], infer Last ] ?
17
+ Last extends object ? // Record<any, any> ?
18
+ Last : // last arg is a record, defaults is null or undefined
19
+ never : // last arg is a string, defaults is null or undefined
20
+ never // args is not an array
21
+
22
+ /** Parserable arguments: a number of strings, followed by optional options */
23
+ export type ParseOptions<Options extends Record<any, any>> =
24
+ readonly [ ...params: string[] ] | readonly [ ...params: string[], options: Options ]
25
+
26
+ /** The return type from {@link ParseOptions} */
27
+ export interface ParsedResult<Args extends readonly any [], Options, Defaults> {
28
+ params: ParsedParams<Args>,
29
+ options: Defaults extends null | undefined ? Options | undefined : Options & Defaults
30
+ }
31
+
32
+ /**
33
+ * Parse an array of arguments (a number of strings optionally followed by an
34
+ * options object into parameters and options.
35
+ */
36
+ export function parseOptions<
37
+ Args extends ParseOptions<any>,
38
+ Options extends ParsedOptions<Args> = ParsedOptions<Args>,
39
+ Defaults extends ParsedOptions<Args> | null | undefined = undefined,
40
+ >(args: Args, defaults?: Defaults): ParsedResult<Args, Options, Defaults> {
13
41
  const params: string[] = []
14
- const options: any = { ...defaults }
42
+ const clone: any[] = [ ...args ]
15
43
 
16
- for (const arg of args) {
17
- if (typeof arg === 'string') params.push(arg)
18
- else Object.assign(options, arg)
44
+ // Collect all strings at the beginning of our arguments array
45
+ while (typeof clone[0] === 'string') {
46
+ params.push(clone.shift())
19
47
  }
20
48
 
21
- return { params, options }
49
+ // The options is the _last_ element in our arguments array (if any)
50
+ const options = Object.assign({}, defaults, clone.pop())
51
+
52
+ // All done
53
+ return { params, options } as ParsedResult<Args, Options, Defaults>
22
54
  }
package/src/utils/walk.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Dir } from 'node:fs'
2
2
  import { basename, join } from 'node:path'
3
- import { $p, log } from '../log.js'
4
- import { AbsolutePath, resolveAbsolutePath } from '../paths.js'
5
- import { opendir, stat } from './asyncfs.js'
6
- import { match, MatchOptions } from './match.js'
3
+ import { $p, log } from '../log'
4
+ import { AbsolutePath, resolveAbsolutePath } from '../paths'
5
+ import { opendir, stat } from './asyncfs'
6
+ import { match, MatchOptions } from './match'
7
7
 
8
8
  /** Specific options for walking a directory */
9
9
  export interface WalkOptions extends MatchOptions {
package/dist/run.cjs DELETED
@@ -1,90 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
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
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // run.ts
21
- var run_exports = {};
22
- __export(run_exports, {
23
- RunImpl: () => RunImpl
24
- });
25
- module.exports = __toCommonJS(run_exports);
26
- var import_node_path = require("node:path");
27
- var import_files = require("./files.cjs");
28
- var import_log = require("./log.cjs");
29
- var import_paths = require("./paths.cjs");
30
- var import_pipe = require("./pipe.cjs");
31
- var import_options = require("./utils/options.cjs");
32
- var import_walk = require("./utils/walk.cjs");
33
- var RunImpl = class {
34
- taskName;
35
- buildFile;
36
- buildDir;
37
- log;
38
- constructor({ taskName, buildDir, buildFile, log }) {
39
- this.taskName = taskName;
40
- this.buildDir = buildDir;
41
- this.buildFile = buildFile;
42
- this.log = log || (0, import_log.getLogger)(taskName);
43
- }
44
- setLogLevel(level) {
45
- this.log.level = (0, import_log.getLevelNumber)(level);
46
- }
47
- report(title) {
48
- return (0, import_log.createReport)(title, this.taskName);
49
- }
50
- resolve(path, ...paths) {
51
- if (path && path.startsWith("@")) {
52
- const components = path.substring(1).split(import_node_path.sep).filter((s) => !!s);
53
- return (0, import_paths.resolveAbsolutePath)(this.buildDir, ...components, ...paths);
54
- }
55
- if (!path)
56
- return (0, import_paths.getCurrentWorkingDirectory)();
57
- return (0, import_paths.resolveAbsolutePath)((0, import_paths.getCurrentWorkingDirectory)(), path, ...paths);
58
- }
59
- files(first, ...paths) {
60
- if (typeof first === "string") {
61
- return import_files.Files.builder(this.resolve(first, ...paths));
62
- } else if (first) {
63
- return import_files.Files.builder(first);
64
- } else {
65
- return import_files.Files.builder(this.resolve());
66
- }
67
- }
68
- find(glob, ...args) {
69
- const { params, options: { directory, ...options } } = (0, import_options.parseOptions)(args, {});
70
- const promise = Promise.resolve().then(async () => {
71
- const builder = this.files(directory || ".");
72
- for await (const file of (0, import_walk.walk)(builder.directory, [glob, ...params], options)) {
73
- builder.unchecked(file);
74
- }
75
- return builder.build();
76
- });
77
- return this.pipe(promise);
78
- }
79
- pipe(files) {
80
- return new import_pipe.PipeImpl(files, this);
81
- }
82
- call(name) {
83
- throw new Error(`Unable to call task "${name}"`);
84
- }
85
- };
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- RunImpl
89
- });
90
- //# sourceMappingURL=run.cjs.map
package/dist/run.cjs.map DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/run.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAoB;AACpB,mBAAoC;AACpC,iBAAwF;AACxF,mBAA8E;AAC9E,kBAA+B;AAC/B,qBAA2C;AAC3C,kBAAkC;AAgF3B,IAAM,UAAN,MAA6B;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIT,YAAY,EAAE,UAAU,UAAU,WAAW,IAAI,GAA2B;AAC1E,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,YAAY;AACjB,SAAK,MAAM,WAAO,sBAAU,QAAQ;AAAA,EACtC;AAAA,EAGA,YAAY,OAA6B;AACvC,SAAK,IAAI,YAAQ,2BAAe,KAAK;AAAA,EACvC;AAAA,EAEA,OAAO,OAAuB;AAC5B,eAAO,yBAAa,OAAO,KAAK,QAAQ;AAAA,EAC1C;AAAA,EAEA,QAAQ,SAAkB,OAA+B;AAEvD,QAAI,QAAQ,KAAK,WAAW,GAAG,GAAG;AAEhC,YAAM,aAAa,KAAK,UAAU,CAAC,EAAE,MAAM,oBAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACjE,iBAAO,kCAAoB,KAAK,UAAU,GAAG,YAAY,GAAG,KAAK;AAAA,IACnE;AAGA,QAAI,CAAE;AAAM,iBAAO,yCAA2B;AAG9C,eAAO,sCAAoB,yCAA2B,GAAG,MAAM,GAAG,KAAK;AAAA,EACzE;AAAA,EAIA,MAAM,UAAsC,OAA+B;AACzE,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,mBAAM,QAAQ,KAAK,QAAQ,OAAO,GAAG,KAAK,CAAC;AAAA,IACpD,WAAW,OAAO;AAChB,aAAO,mBAAM,QAAQ,KAAK;AAAA,IAC5B,OAAO;AACL,aAAO,mBAAM,QAAQ,KAAK,QAAQ,CAAC;AAAA,IACrC;AAAA,EACF;AAAA,EAEA,KAAK,SAAiB,MAAwD;AAC5E,UAAM,EAAE,QAAQ,SAAS,EAAE,cAAc,QAAQ,EAAE,QAAI,6BAAa,MAAM,CAAC,CAAC;AAE5E,UAAM,UAAU,QAAQ,QAAQ,EAAE,KAAK,YAAY;AACjD,YAAM,UAAU,KAAK,MAAM,aAAa,GAAG;AAC3C,uBAAiB,YAAQ,kBAAK,QAAQ,WAAW,CAAE,MAAM,GAAG,MAAO,GAAG,OAAO,GAAG;AAC9E,gBAAQ,UAAU,IAAI;AAAA,MACxB;AACA,aAAO,QAAQ,MAAM;AAAA,IACvB,CAAC;AAED,WAAO,KAAK,KAAK,OAAO;AAAA,EAC1B;AAAA,EAEA,KAAK,OAAsD;AACzD,WAAO,IAAI,qBAAS,OAAO,IAAI;AAAA,EACjC;AAAA,EAEA,KAAK,MAA0C;AAC7C,UAAM,IAAI,MAAM,wBAAwB,OAAO;AAAA,EACjD;AACF;",
5
- "names": []
6
- }
package/dist/run.d.ts DELETED
@@ -1,89 +0,0 @@
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
- * _directory containing the build file where the task was defined_, otherwise
47
- * it will be relative to the {@link process.cwd | current working directory}.
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(path?: string, ...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
- }