@plugjs/plug 0.0.27 → 0.1.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 (282) hide show
  1. package/dist/{failure.cjs → asserts.cjs} +30 -10
  2. package/dist/asserts.cjs.map +6 -0
  3. package/dist/{failure.d.ts → asserts.d.ts} +4 -1
  4. package/dist/asserts.mjs +51 -0
  5. package/dist/asserts.mjs.map +6 -0
  6. package/dist/async.cjs +2 -2
  7. package/dist/async.cjs.map +1 -1
  8. package/dist/async.mjs +2 -2
  9. package/dist/async.mjs.map +1 -1
  10. package/dist/build.cjs +22 -33
  11. package/dist/build.cjs.map +1 -1
  12. package/dist/build.d.ts +2 -13
  13. package/dist/build.mjs +17 -27
  14. package/dist/build.mjs.map +1 -1
  15. package/dist/files.cjs +7 -11
  16. package/dist/files.cjs.map +1 -1
  17. package/dist/files.mjs +5 -9
  18. package/dist/files.mjs.map +1 -1
  19. package/dist/fork.cjs +35 -30
  20. package/dist/fork.cjs.map +1 -1
  21. package/dist/fork.d.ts +6 -3
  22. package/dist/fork.mjs +18 -13
  23. package/dist/fork.mjs.map +1 -1
  24. package/dist/{utils/asyncfs.cjs → fs.cjs} +6 -6
  25. package/dist/fs.cjs.map +6 -0
  26. package/dist/{utils/asyncfs.d.ts → fs.d.ts} +1 -1
  27. package/dist/{utils/asyncfs.mjs → fs.mjs} +3 -3
  28. package/dist/fs.mjs.map +6 -0
  29. package/dist/helpers.cjs +31 -14
  30. package/dist/helpers.cjs.map +1 -1
  31. package/dist/helpers.d.ts +30 -1
  32. package/dist/helpers.mjs +22 -7
  33. package/dist/helpers.mjs.map +1 -1
  34. package/dist/index.cjs +36 -6
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.ts +25 -8
  37. package/dist/index.mjs +20 -5
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/{log → logging}/colors.cjs +1 -1
  40. package/dist/{log → logging}/colors.cjs.map +1 -1
  41. package/dist/{log → logging}/colors.d.ts +0 -0
  42. package/dist/{log → logging}/colors.mjs +1 -1
  43. package/dist/{log → logging}/colors.mjs.map +1 -1
  44. package/dist/{log → logging}/emit.cjs +1 -2
  45. package/dist/{log → logging}/emit.cjs.map +2 -2
  46. package/dist/{log → logging}/emit.d.ts +1 -1
  47. package/dist/{log → logging}/emit.mjs +1 -2
  48. package/dist/{log → logging}/emit.mjs.map +2 -2
  49. package/dist/{log → logging}/levels.cjs +1 -1
  50. package/dist/{log → logging}/levels.cjs.map +1 -1
  51. package/dist/{log → logging}/levels.d.ts +6 -6
  52. package/dist/{log → logging}/levels.mjs +1 -1
  53. package/dist/{log → logging}/levels.mjs.map +1 -1
  54. package/dist/{log → logging}/logger.cjs +13 -7
  55. package/dist/logging/logger.cjs.map +6 -0
  56. package/dist/{log → logging}/logger.d.ts +0 -0
  57. package/dist/{log → logging}/logger.mjs +11 -5
  58. package/dist/logging/logger.mjs.map +6 -0
  59. package/dist/{log → logging}/options.cjs +12 -6
  60. package/dist/logging/options.cjs.map +6 -0
  61. package/dist/{log → logging}/options.d.ts +1 -1
  62. package/dist/{log → logging}/options.mjs +12 -6
  63. package/dist/logging/options.mjs.map +6 -0
  64. package/dist/{log → logging}/report.cjs +11 -11
  65. package/dist/logging/report.cjs.map +6 -0
  66. package/dist/{log → logging}/report.d.ts +1 -1
  67. package/dist/{log → logging}/report.mjs +8 -8
  68. package/dist/logging/report.mjs.map +6 -0
  69. package/dist/{log → logging}/spinner.cjs +1 -1
  70. package/dist/{log → logging}/spinner.cjs.map +1 -1
  71. package/dist/{log → logging}/spinner.d.ts +0 -0
  72. package/dist/{log → logging}/spinner.mjs +1 -1
  73. package/dist/{log → logging}/spinner.mjs.map +1 -1
  74. package/dist/{log.cjs → logging.cjs} +13 -16
  75. package/dist/logging.cjs.map +6 -0
  76. package/dist/logging.d.ts +10 -0
  77. package/dist/{log.mjs → logging.mjs} +10 -13
  78. package/dist/logging.mjs.map +6 -0
  79. package/dist/paths.cjs +25 -27
  80. package/dist/paths.cjs.map +1 -1
  81. package/dist/paths.d.ts +8 -8
  82. package/dist/paths.mjs +23 -25
  83. package/dist/paths.mjs.map +1 -1
  84. package/dist/pipe.cjs +10 -13
  85. package/dist/pipe.cjs.map +1 -1
  86. package/dist/pipe.d.ts +13 -19
  87. package/dist/pipe.mjs +6 -9
  88. package/dist/pipe.mjs.map +1 -1
  89. package/dist/plugs/copy.cjs +14 -14
  90. package/dist/plugs/copy.cjs.map +1 -1
  91. package/dist/plugs/copy.d.ts +1 -1
  92. package/dist/plugs/copy.mjs +3 -3
  93. package/dist/plugs/copy.mjs.map +1 -1
  94. package/dist/plugs/debug.cjs +7 -7
  95. package/dist/plugs/debug.cjs.map +1 -1
  96. package/dist/plugs/debug.d.ts +1 -1
  97. package/dist/plugs/debug.mjs +1 -1
  98. package/dist/plugs/edit.cjs +21 -0
  99. package/dist/plugs/edit.cjs.map +6 -0
  100. package/dist/plugs/edit.d.ts +7 -0
  101. package/dist/plugs/edit.mjs +29 -0
  102. package/dist/plugs/edit.mjs.map +6 -0
  103. package/dist/plugs/esbuild/fix-extensions.cjs +7 -8
  104. package/dist/plugs/esbuild/fix-extensions.cjs.map +1 -1
  105. package/dist/plugs/esbuild/fix-extensions.mjs +4 -5
  106. package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
  107. package/dist/plugs/esbuild.cjs +19 -14
  108. package/dist/plugs/esbuild.cjs.map +1 -1
  109. package/dist/plugs/esbuild.d.ts +2 -2
  110. package/dist/plugs/esbuild.mjs +8 -3
  111. package/dist/plugs/esbuild.mjs.map +1 -1
  112. package/dist/plugs/exec.cjs +2 -82
  113. package/dist/plugs/exec.cjs.map +2 -2
  114. package/dist/plugs/exec.d.ts +6 -32
  115. package/dist/plugs/exec.mjs +2 -68
  116. package/dist/plugs/exec.mjs.map +1 -1
  117. package/dist/plugs/filter.d.ts +1 -1
  118. package/dist/plugs/rmf.cjs +5 -5
  119. package/dist/plugs/rmf.cjs.map +1 -1
  120. package/dist/plugs/rmf.d.ts +1 -1
  121. package/dist/plugs/rmf.mjs +2 -2
  122. package/dist/plugs/rmf.mjs.map +1 -1
  123. package/dist/plugs.cjs +1 -4
  124. package/dist/plugs.cjs.map +1 -1
  125. package/dist/plugs.d.ts +1 -4
  126. package/dist/plugs.mjs +1 -4
  127. package/dist/plugs.mjs.map +1 -1
  128. package/dist/types.d.ts +8 -8
  129. package/dist/utils/caller.cjs +8 -5
  130. package/dist/utils/caller.cjs.map +1 -1
  131. package/dist/utils/caller.mjs +6 -3
  132. package/dist/utils/caller.mjs.map +1 -1
  133. package/dist/utils/exec.cjs +102 -0
  134. package/dist/utils/exec.cjs.map +6 -0
  135. package/dist/utils/exec.d.ts +15 -0
  136. package/dist/utils/exec.mjs +71 -0
  137. package/dist/utils/exec.mjs.map +6 -0
  138. package/dist/utils/match.d.ts +1 -1
  139. package/dist/utils/options.d.ts +3 -3
  140. package/dist/utils/walk.cjs +7 -7
  141. package/dist/utils/walk.cjs.map +1 -1
  142. package/dist/utils/walk.mjs +2 -2
  143. package/dist/utils/walk.mjs.map +1 -1
  144. package/dist/{plugs/tsc.cjs → utils.cjs} +9 -7
  145. package/dist/utils.cjs.map +6 -0
  146. package/dist/utils.d.ts +4 -0
  147. package/dist/utils.mjs +6 -0
  148. package/dist/utils.mjs.map +6 -0
  149. package/extra/cli.mjs +26 -5
  150. package/extra/ts-loader.mjs +4 -4
  151. package/package.json +101 -20
  152. package/src/{assert.ts → asserts.ts} +36 -1
  153. package/src/async.ts +3 -1
  154. package/src/build.ts +179 -0
  155. package/src/files.ts +5 -5
  156. package/src/fork.ts +19 -11
  157. package/src/{utils/asyncfs.ts → fs.ts} +7 -6
  158. package/src/helpers.ts +56 -8
  159. package/src/index.ts +30 -8
  160. package/src/{log → logging}/colors.ts +0 -0
  161. package/src/{log → logging}/emit.ts +0 -1
  162. package/src/{log → logging}/levels.ts +0 -0
  163. package/src/{log → logging}/logger.ts +13 -4
  164. package/src/{log → logging}/options.ts +11 -7
  165. package/src/{log → logging}/report.ts +10 -9
  166. package/src/{log → logging}/spinner.ts +0 -0
  167. package/src/{log.ts → logging.ts} +7 -7
  168. package/src/paths.ts +36 -41
  169. package/src/pipe.ts +13 -20
  170. package/src/plugs/copy.ts +4 -4
  171. package/src/plugs/debug.ts +2 -2
  172. package/src/plugs/edit.ts +34 -0
  173. package/src/plugs/esbuild/fix-extensions.ts +2 -2
  174. package/src/plugs/esbuild.ts +13 -7
  175. package/src/plugs/exec.ts +8 -129
  176. package/src/plugs/filter.ts +1 -1
  177. package/src/plugs/rmf.ts +3 -3
  178. package/src/plugs.ts +1 -13
  179. package/src/types.ts +1 -1
  180. package/src/utils/caller.ts +6 -3
  181. package/src/utils/exec.ts +112 -0
  182. package/src/utils/walk.ts +3 -3
  183. package/src/utils.ts +4 -0
  184. package/types/{webassembly.d.ts → plugjs.d.ts} +7 -1
  185. package/dist/assert.cjs +0 -52
  186. package/dist/assert.cjs.map +0 -6
  187. package/dist/assert.d.ts +0 -4
  188. package/dist/assert.mjs +0 -26
  189. package/dist/assert.mjs.map +0 -6
  190. package/dist/failure.cjs.map +0 -6
  191. package/dist/failure.mjs +0 -33
  192. package/dist/failure.mjs.map +0 -6
  193. package/dist/log/logger.cjs.map +0 -6
  194. package/dist/log/logger.mjs.map +0 -6
  195. package/dist/log/options.cjs.map +0 -6
  196. package/dist/log/options.mjs.map +0 -6
  197. package/dist/log/report.cjs.map +0 -6
  198. package/dist/log/report.mjs.map +0 -6
  199. package/dist/log.cjs.map +0 -6
  200. package/dist/log.d.ts +0 -10
  201. package/dist/log.mjs.map +0 -6
  202. package/dist/plugs/coverage/analysis.cjs +0 -234
  203. package/dist/plugs/coverage/analysis.cjs.map +0 -6
  204. package/dist/plugs/coverage/analysis.d.ts +0 -104
  205. package/dist/plugs/coverage/analysis.mjs +0 -207
  206. package/dist/plugs/coverage/analysis.mjs.map +0 -6
  207. package/dist/plugs/coverage/report.cjs +0 -235
  208. package/dist/plugs/coverage/report.cjs.map +0 -6
  209. package/dist/plugs/coverage/report.d.ts +0 -59
  210. package/dist/plugs/coverage/report.mjs +0 -220
  211. package/dist/plugs/coverage/report.mjs.map +0 -6
  212. package/dist/plugs/coverage.cjs +0 -140
  213. package/dist/plugs/coverage.cjs.map +0 -6
  214. package/dist/plugs/coverage.d.ts +0 -49
  215. package/dist/plugs/coverage.mjs +0 -123
  216. package/dist/plugs/coverage.mjs.map +0 -6
  217. package/dist/plugs/eslint/runner.cjs +0 -91
  218. package/dist/plugs/eslint/runner.cjs.map +0 -6
  219. package/dist/plugs/eslint/runner.d.ts +0 -8
  220. package/dist/plugs/eslint/runner.mjs +0 -68
  221. package/dist/plugs/eslint/runner.mjs.map +0 -6
  222. package/dist/plugs/eslint.cjs +0 -22
  223. package/dist/plugs/eslint.cjs.map +0 -6
  224. package/dist/plugs/eslint.d.ts +0 -34
  225. package/dist/plugs/eslint.mjs +0 -5
  226. package/dist/plugs/eslint.mjs.map +0 -6
  227. package/dist/plugs/mocha/reporter.cjs +0 -159
  228. package/dist/plugs/mocha/reporter.cjs.map +0 -6
  229. package/dist/plugs/mocha/reporter.d.ts +0 -6
  230. package/dist/plugs/mocha/reporter.mjs +0 -127
  231. package/dist/plugs/mocha/reporter.mjs.map +0 -6
  232. package/dist/plugs/mocha/runner.cjs +0 -82
  233. package/dist/plugs/mocha/runner.cjs.map +0 -6
  234. package/dist/plugs/mocha/runner.d.ts +0 -8
  235. package/dist/plugs/mocha/runner.mjs +0 -53
  236. package/dist/plugs/mocha/runner.mjs.map +0 -6
  237. package/dist/plugs/mocha.cjs +0 -22
  238. package/dist/plugs/mocha.cjs.map +0 -6
  239. package/dist/plugs/mocha.d.ts +0 -37
  240. package/dist/plugs/mocha.mjs +0 -5
  241. package/dist/plugs/mocha.mjs.map +0 -6
  242. package/dist/plugs/tsc/compiler.cjs +0 -74
  243. package/dist/plugs/tsc/compiler.cjs.map +0 -6
  244. package/dist/plugs/tsc/compiler.d.ts +0 -24
  245. package/dist/plugs/tsc/compiler.mjs +0 -43
  246. package/dist/plugs/tsc/compiler.mjs.map +0 -6
  247. package/dist/plugs/tsc/options.cjs +0 -82
  248. package/dist/plugs/tsc/options.cjs.map +0 -6
  249. package/dist/plugs/tsc/options.d.ts +0 -8
  250. package/dist/plugs/tsc/options.mjs +0 -51
  251. package/dist/plugs/tsc/options.mjs.map +0 -6
  252. package/dist/plugs/tsc/report.cjs +0 -90
  253. package/dist/plugs/tsc/report.cjs.map +0 -6
  254. package/dist/plugs/tsc/report.d.ts +0 -5
  255. package/dist/plugs/tsc/report.mjs +0 -59
  256. package/dist/plugs/tsc/report.mjs.map +0 -6
  257. package/dist/plugs/tsc/runner.cjs +0 -124
  258. package/dist/plugs/tsc/runner.cjs.map +0 -6
  259. package/dist/plugs/tsc/runner.d.ts +0 -8
  260. package/dist/plugs/tsc/runner.mjs +0 -95
  261. package/dist/plugs/tsc/runner.mjs.map +0 -6
  262. package/dist/plugs/tsc.cjs.map +0 -6
  263. package/dist/plugs/tsc.d.ts +0 -48
  264. package/dist/plugs/tsc.mjs +0 -5
  265. package/dist/plugs/tsc.mjs.map +0 -6
  266. package/dist/utils/asyncfs.cjs.map +0 -6
  267. package/dist/utils/asyncfs.mjs.map +0 -6
  268. package/src/failure.ts +0 -43
  269. package/src/plugs/coverage/analysis.ts +0 -400
  270. package/src/plugs/coverage/report.ts +0 -368
  271. package/src/plugs/coverage.ts +0 -216
  272. package/src/plugs/eslint/runner.ts +0 -100
  273. package/src/plugs/eslint.ts +0 -42
  274. package/src/plugs/mocha/reporter.ts +0 -178
  275. package/src/plugs/mocha/runner.ts +0 -66
  276. package/src/plugs/mocha.ts +0 -43
  277. package/src/plugs/tsc/compiler.ts +0 -68
  278. package/src/plugs/tsc/options.ts +0 -100
  279. package/src/plugs/tsc/report.ts +0 -77
  280. package/src/plugs/tsc/runner.ts +0 -133
  281. package/src/plugs/tsc.ts +0 -58
  282. package/types/globals.d.ts +0 -15
@@ -1,12 +1,12 @@
1
1
  import { currentContext } from './async'
2
- import { getLogger, type Log } from './log/logger'
3
- import { setupSpinner } from './log/spinner'
2
+ import { getLogger, type Log } from './logging/logger'
3
+ import { setupSpinner } from './logging/spinner'
4
4
 
5
- export * from './log/colors'
6
- export * from './log/levels'
7
- export * from './log/logger'
8
- export * from './log/options'
9
- export * from './log/report'
5
+ export * from './logging/colors'
6
+ export * from './logging/levels'
7
+ export * from './logging/logger'
8
+ export * from './logging/options'
9
+ export * from './logging/report'
10
10
 
11
11
  /* ========================================================================== *
12
12
  * INITIALIZATION *
package/src/paths.ts CHANGED
@@ -3,7 +3,7 @@ import { createRequire } from 'node:module'
3
3
  import { dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path'
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url'
5
5
 
6
- import { assert } from './assert'
6
+ import { assert } from './asserts'
7
7
 
8
8
  /** A _branded_ `string` representing an _absolute_ path name */
9
9
  export type AbsolutePath = string & { __brand_absolute_path: never }
@@ -14,9 +14,8 @@ export type AbsolutePath = string & { __brand_absolute_path: never }
14
14
 
15
15
  /** Resolve a path into an {@link AbsolutePath} */
16
16
  export function resolveAbsolutePath(directory: AbsolutePath, ...paths: string[]): AbsolutePath {
17
- const resolved = resolve(directory, ...paths) as AbsolutePath
18
- assert(isAbsolute(resolved), `Path "${join(...paths)}" resolved in "${directory}" is not absolute`)
19
- return resolved
17
+ assertAbsolutePath(directory)
18
+ return resolve(directory, ...paths) as AbsolutePath
20
19
  }
21
20
 
22
21
  /**
@@ -32,8 +31,6 @@ export function resolveAbsolutePath(directory: AbsolutePath, ...paths: string[])
32
31
  * ```
33
32
  */
34
33
  export function resolveRelativeChildPath(directory: AbsolutePath, ...paths: string[]): string | undefined {
35
- assertAbsolutePath(directory)
36
-
37
34
  const abs = resolveAbsolutePath(directory, ...paths)
38
35
  const rel = relative(directory, abs)
39
36
  return (isAbsolute(rel) || (rel === '..') || rel.startsWith(`..${sep}`)) ? undefined : rel
@@ -43,7 +40,6 @@ export function resolveRelativeChildPath(directory: AbsolutePath, ...paths: stri
43
40
  * Asserts that a path is a relative path to the directory specified, failing
44
41
  * the build if it's not (see also {@link resolveRelativeChildPath}).
45
42
  */
46
-
47
43
  export function assertRelativeChildPath(directory: AbsolutePath, ...paths: string[]): string {
48
44
  const relative = resolveRelativeChildPath(directory, ...paths)
49
45
  assert(relative, `Path "${join(...paths)}" not relative to "${directory}"`)
@@ -76,6 +72,38 @@ export function getCurrentWorkingDirectory(): AbsolutePath {
76
72
  return cwd
77
73
  }
78
74
 
75
+ /**
76
+ * Return the _common_ path amongst all specified paths.
77
+ *
78
+ * While the first `path` _must_ be an {@link AbsolutePath}, all other `paths`
79
+ * can be _relative_ and will be resolved against the first `path`.
80
+ */
81
+ export function commonPath(path: AbsolutePath, ...paths: string[]): AbsolutePath {
82
+ assertAbsolutePath(path)
83
+
84
+ // Here the first path will be split into its components
85
+ // on win => [ 'C:', 'Windows', 'System32' ]
86
+ // on unx => [ '', 'usr'
87
+ const components = normalize(path).split(sep)
88
+
89
+ let length = components.length
90
+ for (const current of paths) {
91
+ const absolute = resolveAbsolutePath(path, current)
92
+ const parts = absolute.split(sep)
93
+ for (let i = 0; i < length; i++) {
94
+ if (components[i] !== parts[i]) {
95
+ length = i
96
+ break
97
+ }
98
+ }
99
+
100
+ assert(length, 'No common ancestors amongst paths')
101
+ }
102
+
103
+ const common = components.slice(0, length).join(sep)
104
+ assertAbsolutePath(common)
105
+ return common
106
+ }
79
107
 
80
108
  /* ========================================================================== *
81
109
  * MODULE RESOLUTION FUNCTIONS *
@@ -130,7 +158,7 @@ export function requireResolve(__fileurl: string, module: string): AbsolutePath
130
158
  // ... then delegate to the standard "require.resolve(...)"
131
159
  const url = pathToFileURL(file)
132
160
  const ext = extname(file)
133
- const checks = ext ? [ `${module}`, `${module}${ext}`, `${module}/index${ext}` ] : [ module ]
161
+ const checks = [ `${module}`, `${module}${ext}`, `${module}/index${ext}` ]
134
162
 
135
163
  for (const check of checks) {
136
164
  const resolved = fileURLToPath(new URL(check, url)) as AbsolutePath
@@ -147,39 +175,6 @@ export function requireResolve(__fileurl: string, module: string): AbsolutePath
147
175
  return required
148
176
  }
149
177
 
150
- /**
151
- * Return the _common_ path amongst all specified paths.
152
- *
153
- * While the first `path` _must_ be an {@link AbsolutePath}, all other `paths`
154
- * can be _relative_ and will be resolved against the first `path`.
155
- */
156
- export function commonPath(path: AbsolutePath, ...paths: string[]): AbsolutePath {
157
- assertAbsolutePath(path)
158
-
159
- // Here the first path will be split into its components
160
- // on win => [ 'C:', 'Windows', 'System32' ]
161
- // on unx => [ '', 'usr'
162
- const components = normalize(path).split(sep)
163
-
164
- let length = components.length
165
- for (const current of paths) {
166
- const absolute = resolveAbsolutePath(path, current)
167
- const parts = absolute.split(sep)
168
- for (let i = 0; i < length; i++) {
169
- if (components[i] !== parts[i]) {
170
- length = i
171
- break
172
- }
173
- }
174
-
175
- assert(length, 'No common ancestors amongst paths')
176
- }
177
-
178
- const common = components.slice(0, length).join(sep)
179
- assertAbsolutePath(common)
180
- return common
181
- }
182
-
183
178
  /* ========================================================================== *
184
179
  * FILE CHECKING FUNCTIONS *
185
180
  * ========================================================================== */
package/src/pipe.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { sep } from 'node:path'
2
2
 
3
- import { assert, assertPromises } from './assert'
4
- import { getLogger } from './log'
3
+ import { assert, assertPromises } from './asserts'
4
+ import { getLogger } from './logging'
5
5
  import { getAbsoluteParent, getCurrentWorkingDirectory, resolveAbsolutePath } from './paths'
6
6
 
7
7
  import type { Files } from './files'
8
- import type { Logger } from './log'
8
+ import type { Logger } from './logging'
9
9
  import type { AbsolutePath } from './paths'
10
10
  import type { Result } from './types'
11
+ import type { Pipe } from './index'
11
12
 
12
13
  /* ========================================================================== *
13
14
  * PLUGS *
@@ -138,27 +139,19 @@ export class ContextPromises {
138
139
  }
139
140
  }
140
141
 
141
- /**
142
- * A class that will be extended by {@link Pipe} where {@link install} will
143
- * add prototype properties from installed {@link Plug}s
144
- */
145
- abstract class PipeProto {
146
- abstract plug(plug: Plug<PlugResult>): Pipe | Promise<undefined>
142
+ /** The default implementation of the {@link Pipe} interface. */
143
+ export interface PipeImpl extends Pipe {
144
+ // used simply for merging types
147
145
  }
148
146
 
149
- /**
150
- * The {@link Pipe} class defines processing pipeline where multiple
151
- * {@link Plug}s can transform lists of {@link Files}.
152
- */
153
- export class Pipe extends PipeProto implements Promise<Files> {
147
+ /** The default implementation of the {@link Pipe} interface. */
148
+ export class PipeImpl implements Pipe {
154
149
  readonly [Symbol.toStringTag] = 'Pipe'
155
150
 
156
151
  constructor(
157
152
  private readonly _context: Context,
158
153
  private readonly _promise: Promise<Result>,
159
154
  ) {
160
- super()
161
-
162
155
  // New "Pipe", remember the promise!
163
156
  ContextPromises.get(_context).hot(_promise)
164
157
  }
@@ -218,7 +211,7 @@ export class Pipe extends PipeProto implements Promise<Files> {
218
211
  ContextPromises.get(this._context).cold(this._promise)
219
212
 
220
213
  // Create and return the new Pipe
221
- return new Pipe(this._context, this._promise.then(async (result) => {
214
+ return new PipeImpl(this._context, this._promise.then(async (result) => {
222
215
  assert(result, 'Unable to extend pipe')
223
216
  const result2 = await plug.pipe(result, this._context)
224
217
  return result2 || undefined
@@ -335,14 +328,14 @@ export function install<
335
328
  Ctor extends PlugConstructor<Name>,
336
329
  >(name: Name, ctor: Ctor): void {
337
330
  /* The function plugging the newly constructed plug in a pipe */
338
- function plug(this: PipeProto, ...args: PipeParameters<Name>): Pipe | Promise<undefined> {
331
+ function plug(this: PipeImpl, ...args: PipeParameters<Name>): Pipe | Promise<undefined> {
339
332
  // eslint-disable-next-line new-cap
340
- return this.plug(new ctor(...args))
333
+ return this.plug(new ctor(...args) as any)
341
334
  }
342
335
 
343
336
  /* Setup name so that stack traces look better */
344
337
  Object.defineProperty(plug, 'name', { value: name })
345
338
 
346
339
  /* Inject the create function in the Pipe's prototype */
347
- Object.defineProperty(PipeProto.prototype, name, { value: plug })
340
+ void Object.defineProperty(PipeImpl.prototype, name, { value: plug })
348
341
  }
package/src/plugs/copy.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { assert } from '../assert'
1
+ import { assert } from '../asserts'
2
2
  import { Files } from '../files'
3
- import { $p } from '../log'
3
+ import { chmod, copyFile, fsConstants, mkdir } from '../fs'
4
+ import { $p } from '../logging'
4
5
  import { assertAbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths'
5
6
  import { install } from '../pipe'
6
- import { chmod, copyFile, fsConstants, mkdir } from '../utils/asyncfs'
7
7
 
8
8
  import type { Context, PipeParameters, Plug } from '../pipe'
9
9
 
@@ -19,7 +19,7 @@ export interface CopyOptions {
19
19
  rename?: (relative: string) => string
20
20
  }
21
21
 
22
- declare module '../pipe' {
22
+ declare module '../index' {
23
23
  export interface Pipe {
24
24
  /**
25
25
  * Copy the curent {@link Files} to a different directory
@@ -1,10 +1,10 @@
1
- import { $gry, $p, $und, $ylw } from '../log'
1
+ import { $gry, $p, $und, $ylw } from '../logging'
2
2
  import { install } from '../pipe'
3
3
 
4
4
  import type { Files } from '../files'
5
5
  import type { Context, PipeParameters, Plug } from '../pipe'
6
6
 
7
- declare module '../pipe' {
7
+ declare module '../index' {
8
8
  export interface Pipe {
9
9
  /** Log some info about the current {@link Files} being passed around. */
10
10
  debug(title?: string): Pipe
@@ -0,0 +1,34 @@
1
+ import { readFile, writeFile } from '../fs'
2
+ import { install } from '../pipe'
3
+
4
+ import type { Files } from '../files'
5
+ import type { PipeParameters, Plug } from '../pipe'
6
+
7
+ declare module '../index' {
8
+ export interface Pipe {
9
+ /** Edits the content of all files in a pipeline. */
10
+ edit(callback: (content: string) => string | void | Promise<string | void>): Pipe
11
+ }
12
+ }
13
+
14
+ /* ========================================================================== *
15
+ * INSTALLATION / IMPLEMENTATION *
16
+ * ========================================================================== */
17
+
18
+ /** Edits the content of all files in a pipeline. */
19
+ install('edit', class Edit implements Plug<Files> {
20
+ private readonly _callback: (content: string) => string | void | Promise<string | void>
21
+
22
+ constructor(...args: PipeParameters<'edit'>) {
23
+ this._callback = args[0]
24
+ }
25
+
26
+ async pipe(files: Files): Promise<Files> {
27
+ for (const file of files.absolutePaths()) {
28
+ const data = await readFile(file, 'utf-8')
29
+ const edited = await this._callback(data)
30
+ if (edited !== undefined) await writeFile(file, edited, 'utf-8')
31
+ }
32
+ return files
33
+ }
34
+ })
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path'
2
2
 
3
+ import { stat } from '../../fs'
3
4
  import { assertAbsolutePath, resolveAbsolutePath, resolveFile } from '../../paths'
4
- import { stat } from '../../utils/asyncfs'
5
5
 
6
6
  import type { Plugin } from 'esbuild'
7
7
 
@@ -72,7 +72,7 @@ export function fixExtensions(): Plugin {
72
72
  const match = args.path.match(/(.*)(\.[mc]?js$)/)
73
73
  if (match) {
74
74
  const [ , name, ext ] = match
75
- const tspath = name + ext.replace('js', 'ts')
75
+ const tspath = name + ext!.replace('js', 'ts')
76
76
  const tsfile = resolveAbsolutePath(resolveDir, tspath)
77
77
  if (resolveFile(tsfile)) {
78
78
  const newext = ext === '.mjs' ? mjs : ext === '.cjs' ? cjs : js
@@ -2,25 +2,25 @@ import { basename } from 'node:path'
2
2
 
3
3
  import { build } from 'esbuild'
4
4
 
5
- import { assert } from '../assert'
5
+ import { assert } from '../asserts'
6
6
  import { Files } from '../files'
7
- import { $p, ERROR, WARN } from '../log'
7
+ import { readFile } from '../fs'
8
+ import { $p, ERROR, WARN } from '../logging'
8
9
  import { getAbsoluteParent, resolveAbsolutePath } from '../paths'
9
10
  import { install } from '../pipe'
10
- import { readFile } from '../utils/asyncfs'
11
11
 
12
+ import type { BuildFailure, BuildOptions, BuildResult, Format, Message, Metafile } from 'esbuild'
12
13
  import type { FilesBuilder } from '../files'
13
- import type { Logger, ReportLevel, ReportRecord } from '../log'
14
+ import type { Logger, ReportLevel, ReportRecord } from '../logging'
14
15
  import type { AbsolutePath } from '../paths'
15
16
  import type { Context, PipeParameters, Plug } from '../pipe'
16
- import type { BuildFailure, BuildOptions, BuildResult, Format, Message, Metafile } from 'esbuild'
17
17
 
18
18
  export type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'>
19
19
 
20
20
  export * from './esbuild/bundle-locals'
21
21
  export * from './esbuild/fix-extensions'
22
22
 
23
- declare module '../pipe' {
23
+ declare module '../index' {
24
24
  export interface Pipe {
25
25
  /**
26
26
  * Transpile and bundle with {@link https://esbuild.github.io/ esbuild}.
@@ -68,6 +68,12 @@ install('esbuild', class ESBuild implements Plug<Files> {
68
68
  watch: false,
69
69
  }
70
70
 
71
+ if (options.format === 'cjs') {
72
+ options.define = Object.assign({ __fileurl: '__filename' }, options.define)
73
+ } else if (options.format === 'esm') {
74
+ options.define = Object.assign({ __fileurl: 'import.meta.url' }, options.define)
75
+ }
76
+
71
77
  /* Sanity check on output file/directory */
72
78
  assert(!(options.outdir && options.outfile), 'Options "outfile" and "outdir" can not coexist')
73
79
 
@@ -76,7 +82,7 @@ install('esbuild', class ESBuild implements Plug<Files> {
76
82
  if (options.bundle && options.outfile && (entryPoints.length === 1)) {
77
83
  builder = Files.builder(absWorkingDir)
78
84
  const outputFile = resolveAbsolutePath(absWorkingDir, options.outfile)
79
- const entryPoint = resolveAbsolutePath(absWorkingDir, entryPoints[0])
85
+ const entryPoint = resolveAbsolutePath(absWorkingDir, entryPoints[0]!)
80
86
  options.outfile = outputFile
81
87
 
82
88
  context.log.debug('Bundling', $p(entryPoint), 'into', $p(outputFile))
package/src/plugs/exec.ts CHANGED
@@ -1,40 +1,27 @@
1
- import { spawn } from 'node:child_process'
2
- import path from 'node:path'
3
- import reaadline from 'node:readline'
4
-
5
- import { assert } from '../assert'
6
- import { requireContext } from '../async'
7
- import { $p, logOptions } from '../log'
8
- import { getCurrentWorkingDirectory, resolveDirectory } from '../paths'
9
1
  import { install } from '../pipe'
10
2
  import { parseOptions } from '../utils/options'
3
+ import { execChild } from '../utils/exec'
11
4
 
5
+ import type { ExecChildOptions } from '../utils/exec'
12
6
  import type { Files } from '../files'
13
- import type { AbsolutePath } from '../paths'
14
7
  import type { Context, PipeParameters, Plug } from '../pipe'
15
- import type { SpawnOptions } from 'node:child_process'
16
8
 
17
9
  /** Options for executing scripts */
18
- export interface ExecOptions {
19
- /** Extra environment variables, or overrides for existing ones */
20
- env?: Record<string, any>,
21
- /** Whether to run in the context of a _shell_ or not */
22
- shell?: string | boolean,
10
+ export interface ExecOptions extends ExecChildOptions {
23
11
  /**
24
12
  * The current working directory of the process to execute.
25
13
  *
26
- * Defaults to the current {@link Files.directory | Files' directory} when
27
- * used as a {@link Plug} or `process.cwd()` when used from {@link exec}.
14
+ * Defaults to the current {@link Files.directory | Files' directory}.
28
15
  */
29
16
  cwd?: string
30
17
  /**
31
- * When used as a {@link Plug}, the {@link Files} will be appended to the
32
- * current arguments as _relative_ files (default) or _absolute_ (if false).
18
+ * Whether the {@link Files} will be appended to the current arguments as
19
+ * _relative_ files (default or `true`) or _absolute_ (if `false`).
33
20
  */
34
21
  relativePaths?: boolean
35
22
  }
36
23
 
37
- declare module '../pipe' {
24
+ declare module '../index' {
38
25
  export interface Pipe {
39
26
  /**
40
27
  * Execute a shell command, adding to its _arguments_ the list of files
@@ -114,117 +101,9 @@ install('exec', class Exec implements Plug<Files> {
114
101
  if (options.shell) params.forEach((s, i, a) => a[i] = JSON.stringify(s))
115
102
 
116
103
  // Run our child
117
- await spawnChild(this._cmd, [ ...this._args, ...params ], options, context)
104
+ await execChild(this._cmd, [ ...this._args, ...params ], options, context)
118
105
 
119
106
  // Return our files
120
107
  return files
121
108
  }
122
109
  })
123
-
124
- /**
125
- * Execute a command and await for its result from within a task.
126
- *
127
- * For example:
128
- *
129
- * ```
130
- * import { exec } from '@plugjs/plugjs'
131
- *
132
- * export default build({
133
- * async runme() {
134
- * await exec('ls', '-la', '/')
135
- * // or similarly letting the shell interpret the command
136
- * await exec('ls -la /', { shell: true })
137
- * },
138
- * })
139
- * ```
140
- *
141
- * @param cmd The command to execute
142
- * @param args Any additional argument for the command to execute
143
- * @param options Extra {@link ExecOptions | options} for process execution
144
- */
145
- export function exec(
146
- cmd: string,
147
- ...args:
148
- | [ ...args: string[] ]
149
- | [ ...args: string[], options: ExecOptions ]
150
- ): Promise<void> {
151
- const { params, options } = parseOptions(args)
152
- return spawnChild(cmd, params, options, requireContext())
153
- }
154
-
155
-
156
- /* ========================================================================== *
157
- * INTERNALS *
158
- * ========================================================================== */
159
-
160
- async function spawnChild(
161
- cmd: string,
162
- args: readonly string[],
163
- options: ExecOptions = {},
164
- context: Context,
165
- ): Promise<void> {
166
- const {
167
- env = {}, // default empty environment
168
- shell = false, // by default do not use a shell
169
- cwd = undefined, // by default use "process.cwd()"
170
- ...extraOptions
171
- } = options
172
-
173
- const childCwd = cwd ? context.resolve(cwd) : getCurrentWorkingDirectory()
174
- assert(resolveDirectory(childCwd), `Current working directory ${$p(childCwd)} does not exist`)
175
-
176
- // Figure out the PATH environment variable
177
- const childPaths: AbsolutePath[] = []
178
-
179
- // The `.../node_modules/.bin` path relative to the current working dir */
180
- const baseNodePath = context.resolve('@node_modules', '.bin')
181
- if (resolveDirectory(baseNodePath)) childPaths.push(baseNodePath)
182
-
183
- // The `.../node_bodules/.bin` path relative to the buildDir */
184
- const buildNodePath = context.resolve('./node_modules', '.bin')
185
- if (resolveDirectory(buildNodePath)) childPaths.push(buildNodePath)
186
-
187
- // Any other paths either from `process.env` or `env` (which overrides it)
188
- const extraPath = env.PATH || process.env.PATH
189
- if (extraPath) childPaths.push(extraPath)
190
-
191
- // Build our environment variables record
192
- const PATH = childPaths.join(path.delimiter)
193
- const __LOG_OPTIONS = JSON.stringify(logOptions.fork(context.taskName))
194
- const childEnv = { ...process.env, ...env, PATH, __LOG_OPTIONS }
195
-
196
- // Prepare the options for calling `spawn`
197
- const childOptions: SpawnOptions = {
198
- ...extraOptions,
199
- stdio: [ 'ignore', 'pipe', 'pipe' ],
200
- cwd: childCwd,
201
- env: childEnv,
202
- shell,
203
- }
204
-
205
- // Spawn our subprocess and monitor its stdout/stderr
206
- context.log.info('Executing', [ cmd, ...args ])
207
- context.log.info('Execution options', childOptions)
208
- const child = spawn(cmd, args, childOptions)
209
-
210
- if (child.stdout) {
211
- const out = reaadline.createInterface(child.stdout)
212
- out.on('line', (line) => line ? context.log.notice(line) : context.log.notice('\u00a0'))
213
- }
214
-
215
- if (child.stderr) {
216
- const err = reaadline.createInterface(child.stderr)
217
- err.on('line', (line) => line ? context.log.warn(line) : context.log.warn('\u00a0'))
218
- }
219
-
220
- // Return our promise from the spawn events
221
- return new Promise<void>((resolve, reject) => {
222
- child.on('error', (error) => reject(error))
223
- child.on('exit', (code, signal) => {
224
- if (code === 0) return resolve()
225
- if (signal) return reject(new Error(`Child process exited with signal ${signal}`))
226
- if (code) return reject(new Error(`Child process exited with code ${code}`))
227
- reject(new Error('Child process failed for an unknown reason'))
228
- })
229
- })
230
- }
@@ -13,7 +13,7 @@ export interface FilterOptions extends MatchOptions {
13
13
  directory?: string
14
14
  }
15
15
 
16
- declare module '../pipe' {
16
+ declare module '../index' {
17
17
  export interface Pipe {
18
18
  /**
19
19
  * Filter the current {@link Files} using globs.
package/src/plugs/rmf.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { $gry, $p } from '../log'
1
+ import { rm } from '../fs'
2
+ import { $gry, $p } from '../logging'
2
3
  import { install } from '../pipe'
3
- import { rm } from '../utils/asyncfs'
4
4
 
5
5
  import type { Files } from '../files'
6
6
  import type { Context, PipeParameters, Plug } from '../pipe'
7
7
 
8
- declare module '../pipe' {
8
+ declare module '../index' {
9
9
  export interface Pipe {
10
10
  /**
11
11
  * Remove all {@link Files} piped in.
package/src/plugs.ts CHANGED
@@ -1,18 +1,6 @@
1
- /* ========================================================================== *
2
- * FORKING PLUGS *
3
- * ========================================================================== */
4
-
5
- export * from './plugs/eslint'
6
- export * from './plugs/mocha'
7
- export * from './plugs/tsc'
8
-
9
- /* ========================================================================== *
10
- * STANDARD IN-PROCESS PLUGS *
11
- * ========================================================================== */
12
-
13
1
  export * from './plugs/copy'
14
- export * from './plugs/coverage'
15
2
  export * from './plugs/debug'
3
+ export * from './plugs/edit'
16
4
  export * from './plugs/esbuild'
17
5
  export * from './plugs/exec'
18
6
  export * from './plugs/filter'
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Files } from './files'
2
2
  import type { AbsolutePath } from './paths'
3
- import type { Pipe } from './pipe'
3
+ import type { Pipe } from './index'
4
4
 
5
5
  /**
6
6
  * A type describing the ultimate result of a {@link Plug}, {@link Pipe} or
@@ -1,8 +1,8 @@
1
1
  import { statSync } from 'node:fs'
2
2
  import { fileURLToPath } from 'node:url'
3
3
 
4
- import { assert } from '../assert'
5
- import { $p } from '../log'
4
+ import { assert } from '../asserts'
5
+ import { $p } from '../logging'
6
6
  import { assertAbsolutePath } from '../paths'
7
7
 
8
8
  import type { AbsolutePath } from '../paths'
@@ -12,7 +12,10 @@ export function findCaller(of: (...args: any[]) => any): AbsolutePath {
12
12
 
13
13
  try {
14
14
  Error.prepareStackTrace = (_, stackTraces): AbsolutePath | undefined => {
15
- const nullableFileOrUrl = stackTraces[0].getFileName()
15
+ const [ stackTrace ] = stackTraces
16
+ if (! stackTrace) return
17
+
18
+ const nullableFileOrUrl = stackTrace.getFileName()
16
19
  if (! nullableFileOrUrl) return
17
20
 
18
21
  const file =