@plugjs/plug 0.6.116 → 0.7.0

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 (388) hide show
  1. package/dist/asserts.d.ts +1 -0
  2. package/dist/asserts.d.ts.map +1 -0
  3. package/dist/asserts.js +68 -0
  4. package/dist/asserts.js.map +1 -0
  5. package/dist/async.d.ts +2 -1
  6. package/dist/async.d.ts.map +1 -0
  7. package/dist/async.js +52 -0
  8. package/dist/async.js.map +1 -0
  9. package/dist/build.d.ts +2 -1
  10. package/dist/build.d.ts.map +1 -0
  11. package/dist/build.js +236 -0
  12. package/dist/build.js.map +1 -0
  13. package/dist/{cli.d.mts → cli.d.ts} +3 -1
  14. package/dist/cli.d.ts.map +1 -0
  15. package/dist/cli.js +330 -0
  16. package/dist/cli.js.map +1 -0
  17. package/dist/files.d.ts +2 -1
  18. package/dist/files.d.ts.map +1 -0
  19. package/dist/files.js +93 -0
  20. package/dist/files.js.map +1 -0
  21. package/dist/fork.d.ts +5 -4
  22. package/dist/fork.d.ts.map +1 -0
  23. package/dist/fork.js +259 -0
  24. package/dist/fork.js.map +1 -0
  25. package/dist/fs.d.ts +1 -0
  26. package/dist/fs.d.ts.map +1 -0
  27. package/dist/fs.js +72 -0
  28. package/dist/fs.js.map +1 -0
  29. package/dist/globals.d.ts +4 -0
  30. package/dist/globals.d.ts.map +1 -0
  31. package/dist/globals.js +2 -0
  32. package/dist/globals.js.map +1 -0
  33. package/dist/helpers.d.ts +8 -7
  34. package/dist/helpers.d.ts.map +1 -0
  35. package/dist/helpers.js +231 -0
  36. package/dist/helpers.js.map +1 -0
  37. package/dist/index.d.ts +22 -21
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +21 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/logging/colors.d.ts +2 -1
  42. package/dist/logging/colors.d.ts.map +1 -0
  43. package/dist/logging/colors.js +121 -0
  44. package/dist/logging/colors.js.map +1 -0
  45. package/dist/logging/emit.d.ts +2 -1
  46. package/dist/logging/emit.d.ts.map +1 -0
  47. package/dist/logging/emit.js +137 -0
  48. package/dist/logging/emit.js.map +1 -0
  49. package/dist/logging/github.d.ts +2 -1
  50. package/dist/logging/github.d.ts.map +1 -0
  51. package/dist/logging/github.js +46 -0
  52. package/dist/logging/github.js.map +1 -0
  53. package/dist/logging/levels.d.ts +1 -0
  54. package/dist/logging/levels.d.ts.map +1 -0
  55. package/dist/logging/levels.js +50 -0
  56. package/dist/logging/levels.js.map +1 -0
  57. package/dist/logging/logger.d.ts +4 -3
  58. package/dist/logging/logger.d.ts.map +1 -0
  59. package/dist/logging/logger.js +161 -0
  60. package/dist/logging/logger.js.map +1 -0
  61. package/dist/logging/options.d.ts +2 -1
  62. package/dist/logging/options.d.ts.map +1 -0
  63. package/dist/logging/options.js +182 -0
  64. package/dist/logging/options.js.map +1 -0
  65. package/dist/logging/report.d.ts +4 -3
  66. package/dist/logging/report.d.ts.map +1 -0
  67. package/dist/logging/report.js +346 -0
  68. package/dist/logging/report.js.map +1 -0
  69. package/dist/logging/spinner.d.ts +1 -0
  70. package/dist/logging/spinner.d.ts.map +1 -0
  71. package/dist/logging/spinner.js +70 -0
  72. package/dist/logging/spinner.js.map +1 -0
  73. package/dist/logging.d.ts +8 -7
  74. package/dist/logging.d.ts.map +1 -0
  75. package/dist/logging.js +66 -0
  76. package/dist/logging.js.map +1 -0
  77. package/dist/paths.d.ts +33 -13
  78. package/dist/paths.d.ts.map +1 -0
  79. package/dist/paths.js +223 -0
  80. package/dist/paths.js.map +1 -0
  81. package/dist/pipe.d.ts +8 -5
  82. package/dist/pipe.d.ts.map +1 -0
  83. package/dist/pipe.js +205 -0
  84. package/dist/pipe.js.map +1 -0
  85. package/dist/plugs/build.d.ts +5 -4
  86. package/dist/plugs/build.d.ts.map +1 -0
  87. package/dist/plugs/build.js +56 -0
  88. package/dist/plugs/build.js.map +1 -0
  89. package/dist/plugs/copy.d.ts +1 -0
  90. package/dist/plugs/copy.d.ts.map +1 -0
  91. package/dist/plugs/copy.js +92 -0
  92. package/dist/plugs/copy.js.map +1 -0
  93. package/dist/plugs/debug.d.ts +1 -0
  94. package/dist/plugs/debug.d.ts.map +1 -0
  95. package/dist/plugs/debug.js +25 -0
  96. package/dist/plugs/debug.js.map +1 -0
  97. package/dist/plugs/edit.d.ts +2 -1
  98. package/dist/plugs/edit.d.ts.map +1 -0
  99. package/dist/plugs/edit.js +22 -0
  100. package/dist/plugs/edit.js.map +1 -0
  101. package/dist/plugs/esbuild/bundle-locals.d.ts +1 -0
  102. package/dist/plugs/esbuild/bundle-locals.d.ts.map +1 -0
  103. package/dist/plugs/esbuild/bundle-locals.js +29 -0
  104. package/dist/plugs/esbuild/bundle-locals.js.map +1 -0
  105. package/dist/plugs/esbuild/fix-extensions.d.ts +1 -0
  106. package/dist/plugs/esbuild/fix-extensions.d.ts.map +1 -0
  107. package/dist/plugs/esbuild/fix-extensions.js +98 -0
  108. package/dist/plugs/esbuild/fix-extensions.js.map +1 -0
  109. package/dist/plugs/esbuild.d.ts +21 -2
  110. package/dist/plugs/esbuild.d.ts.map +1 -0
  111. package/dist/plugs/esbuild.js +193 -0
  112. package/dist/plugs/esbuild.js.map +1 -0
  113. package/dist/plugs/exec.d.ts +2 -1
  114. package/dist/plugs/exec.d.ts.map +1 -0
  115. package/dist/plugs/exec.js +33 -0
  116. package/dist/plugs/exec.js.map +1 -0
  117. package/dist/plugs/exports.d.ts +1 -0
  118. package/dist/plugs/exports.d.ts.map +1 -0
  119. package/dist/plugs/exports.js +110 -0
  120. package/dist/plugs/exports.js.map +1 -0
  121. package/dist/plugs/filter.d.ts +2 -1
  122. package/dist/plugs/filter.d.ts.map +1 -0
  123. package/dist/plugs/filter.js +34 -0
  124. package/dist/plugs/filter.js.map +1 -0
  125. package/dist/plugs/rmf.d.ts +1 -0
  126. package/dist/plugs/rmf.d.ts.map +1 -0
  127. package/dist/plugs/rmf.js +24 -0
  128. package/dist/plugs/rmf.js.map +1 -0
  129. package/dist/plugs.d.ts +9 -8
  130. package/dist/plugs.d.ts.map +1 -0
  131. package/dist/plugs.js +9 -0
  132. package/dist/plugs.js.map +1 -0
  133. package/dist/types.d.ts +4 -3
  134. package/dist/types.d.ts.map +1 -0
  135. package/dist/types.js +2 -0
  136. package/dist/types.js.map +1 -0
  137. package/dist/utils/ansi.d.ts +1 -0
  138. package/dist/utils/ansi.d.ts.map +1 -0
  139. package/dist/utils/ansi.js +10 -0
  140. package/dist/utils/ansi.js.map +1 -0
  141. package/dist/utils/caller.d.ts +2 -1
  142. package/dist/utils/caller.d.ts.map +1 -0
  143. package/dist/utils/caller.js +33 -0
  144. package/dist/utils/caller.js.map +1 -0
  145. package/dist/utils/diff.d.ts +1 -0
  146. package/dist/utils/diff.d.ts.map +1 -0
  147. package/dist/utils/diff.js +278 -0
  148. package/dist/utils/diff.js.map +1 -0
  149. package/dist/utils/exec.d.ts +2 -1
  150. package/dist/utils/exec.d.ts.map +1 -0
  151. package/dist/utils/exec.js +84 -0
  152. package/dist/utils/exec.js.map +1 -0
  153. package/dist/utils/jsonc.d.ts +1 -0
  154. package/dist/utils/jsonc.d.ts.map +1 -0
  155. package/dist/utils/jsonc.js +46 -0
  156. package/dist/utils/jsonc.js.map +1 -0
  157. package/dist/utils/match.d.ts +1 -0
  158. package/dist/utils/match.d.ts.map +1 -0
  159. package/dist/utils/match.js +40 -0
  160. package/dist/utils/match.js.map +1 -0
  161. package/dist/utils/options.d.ts +1 -0
  162. package/dist/utils/options.d.ts.map +1 -0
  163. package/dist/utils/options.js +17 -0
  164. package/dist/utils/options.js.map +1 -0
  165. package/dist/utils/singleton.d.ts +1 -0
  166. package/dist/utils/singleton.d.ts.map +1 -0
  167. package/dist/utils/singleton.js +20 -0
  168. package/dist/utils/singleton.js.map +1 -0
  169. package/dist/utils/walk.d.ts +3 -2
  170. package/dist/utils/walk.d.ts.map +1 -0
  171. package/dist/utils/walk.js +84 -0
  172. package/dist/utils/walk.js.map +1 -0
  173. package/dist/utils.d.ts +9 -8
  174. package/dist/utils.d.ts.map +1 -0
  175. package/dist/utils.js +9 -0
  176. package/dist/utils.js.map +1 -0
  177. package/package.json +28 -88
  178. package/src/asserts.ts +2 -2
  179. package/src/async.ts +3 -3
  180. package/src/build.ts +10 -10
  181. package/src/{cli.mts → cli.ts} +27 -16
  182. package/src/files.ts +4 -4
  183. package/src/fork.ts +17 -17
  184. package/src/globals.ts +3 -0
  185. package/src/helpers.ts +20 -20
  186. package/src/index.ts +21 -21
  187. package/src/logging/colors.ts +4 -4
  188. package/src/logging/emit.ts +6 -6
  189. package/src/logging/github.ts +3 -3
  190. package/src/logging/logger.ts +12 -12
  191. package/src/logging/options.ts +10 -10
  192. package/src/logging/report.ts +10 -10
  193. package/src/logging/spinner.ts +3 -3
  194. package/src/logging.ts +14 -14
  195. package/src/paths.ts +42 -23
  196. package/src/pipe.ts +13 -8
  197. package/src/plugs/build.ts +8 -8
  198. package/src/plugs/copy.ts +8 -8
  199. package/src/plugs/debug.ts +4 -4
  200. package/src/plugs/edit.ts +5 -5
  201. package/src/plugs/esbuild/fix-extensions.ts +8 -10
  202. package/src/plugs/esbuild.ts +88 -27
  203. package/src/plugs/exec.ts +6 -6
  204. package/src/plugs/exports.ts +32 -35
  205. package/src/plugs/filter.ts +7 -7
  206. package/src/plugs/rmf.ts +5 -5
  207. package/src/plugs.ts +8 -8
  208. package/src/types.ts +3 -3
  209. package/src/utils/caller.ts +4 -4
  210. package/src/utils/diff.ts +2 -2
  211. package/src/utils/exec.ts +7 -7
  212. package/src/utils/jsonc.ts +1 -1
  213. package/src/utils/walk.ts +6 -6
  214. package/src/utils.ts +8 -8
  215. package/dist/asserts.cjs +0 -86
  216. package/dist/asserts.cjs.map +0 -6
  217. package/dist/asserts.mjs +0 -58
  218. package/dist/asserts.mjs.map +0 -6
  219. package/dist/async.cjs +0 -64
  220. package/dist/async.cjs.map +0 -6
  221. package/dist/async.mjs +0 -36
  222. package/dist/async.mjs.map +0 -6
  223. package/dist/build.cjs +0 -222
  224. package/dist/build.cjs.map +0 -6
  225. package/dist/build.mjs +0 -192
  226. package/dist/build.mjs.map +0 -6
  227. package/dist/cli.mjs +0 -258
  228. package/dist/cli.mjs.map +0 -6
  229. package/dist/files.cjs +0 -113
  230. package/dist/files.cjs.map +0 -6
  231. package/dist/files.mjs +0 -93
  232. package/dist/files.mjs.map +0 -6
  233. package/dist/fork.cjs +0 -224
  234. package/dist/fork.cjs.map +0 -6
  235. package/dist/fork.mjs +0 -198
  236. package/dist/fork.mjs.map +0 -6
  237. package/dist/fs.cjs +0 -146
  238. package/dist/fs.cjs.map +0 -6
  239. package/dist/fs.mjs +0 -82
  240. package/dist/fs.mjs.map +0 -6
  241. package/dist/globals.cjs +0 -2
  242. package/dist/globals.cjs.map +0 -6
  243. package/dist/globals.mjs +0 -1
  244. package/dist/globals.mjs.map +0 -6
  245. package/dist/helpers.cjs +0 -182
  246. package/dist/helpers.cjs.map +0 -6
  247. package/dist/helpers.mjs +0 -151
  248. package/dist/helpers.mjs.map +0 -6
  249. package/dist/index.cjs +0 -114
  250. package/dist/index.cjs.map +0 -6
  251. package/dist/index.mjs +0 -48
  252. package/dist/index.mjs.map +0 -6
  253. package/dist/logging/colors.cjs +0 -136
  254. package/dist/logging/colors.cjs.map +0 -6
  255. package/dist/logging/colors.mjs +0 -99
  256. package/dist/logging/colors.mjs.map +0 -6
  257. package/dist/logging/emit.cjs +0 -134
  258. package/dist/logging/emit.cjs.map +0 -6
  259. package/dist/logging/emit.mjs +0 -106
  260. package/dist/logging/emit.mjs.map +0 -6
  261. package/dist/logging/github.cjs +0 -60
  262. package/dist/logging/github.cjs.map +0 -6
  263. package/dist/logging/github.mjs +0 -35
  264. package/dist/logging/github.mjs.map +0 -6
  265. package/dist/logging/levels.cjs +0 -69
  266. package/dist/logging/levels.cjs.map +0 -6
  267. package/dist/logging/levels.mjs +0 -35
  268. package/dist/logging/levels.mjs.map +0 -6
  269. package/dist/logging/logger.cjs +0 -165
  270. package/dist/logging/logger.cjs.map +0 -6
  271. package/dist/logging/logger.mjs +0 -139
  272. package/dist/logging/logger.mjs.map +0 -6
  273. package/dist/logging/options.cjs +0 -192
  274. package/dist/logging/options.cjs.map +0 -6
  275. package/dist/logging/options.mjs +0 -167
  276. package/dist/logging/options.mjs.map +0 -6
  277. package/dist/logging/report.cjs +0 -298
  278. package/dist/logging/report.cjs.map +0 -6
  279. package/dist/logging/report.mjs +0 -273
  280. package/dist/logging/report.mjs.map +0 -6
  281. package/dist/logging/spinner.cjs +0 -100
  282. package/dist/logging/spinner.cjs.map +0 -6
  283. package/dist/logging/spinner.mjs +0 -72
  284. package/dist/logging/spinner.mjs.map +0 -6
  285. package/dist/logging.cjs +0 -91
  286. package/dist/logging.cjs.map +0 -6
  287. package/dist/logging.mjs +0 -58
  288. package/dist/logging.mjs.map +0 -6
  289. package/dist/paths.cjs +0 -170
  290. package/dist/paths.cjs.map +0 -6
  291. package/dist/paths.mjs +0 -132
  292. package/dist/paths.mjs.map +0 -6
  293. package/dist/pipe.cjs +0 -163
  294. package/dist/pipe.cjs.map +0 -6
  295. package/dist/pipe.mjs +0 -135
  296. package/dist/pipe.mjs.map +0 -6
  297. package/dist/plugs/build.cjs +0 -73
  298. package/dist/plugs/build.cjs.map +0 -6
  299. package/dist/plugs/build.mjs +0 -47
  300. package/dist/plugs/build.mjs.map +0 -6
  301. package/dist/plugs/copy.cjs +0 -86
  302. package/dist/plugs/copy.cjs.map +0 -6
  303. package/dist/plugs/copy.mjs +0 -69
  304. package/dist/plugs/copy.mjs.map +0 -6
  305. package/dist/plugs/debug.cjs +0 -24
  306. package/dist/plugs/debug.cjs.map +0 -6
  307. package/dist/plugs/debug.mjs +0 -22
  308. package/dist/plugs/debug.mjs.map +0 -6
  309. package/dist/plugs/edit.cjs +0 -20
  310. package/dist/plugs/edit.cjs.map +0 -6
  311. package/dist/plugs/edit.mjs +0 -18
  312. package/dist/plugs/edit.mjs.map +0 -6
  313. package/dist/plugs/esbuild/bundle-locals.cjs +0 -48
  314. package/dist/plugs/esbuild/bundle-locals.cjs.map +0 -6
  315. package/dist/plugs/esbuild/bundle-locals.mjs +0 -23
  316. package/dist/plugs/esbuild/bundle-locals.mjs.map +0 -6
  317. package/dist/plugs/esbuild/fix-extensions.cjs +0 -89
  318. package/dist/plugs/esbuild/fix-extensions.cjs.map +0 -6
  319. package/dist/plugs/esbuild/fix-extensions.mjs +0 -54
  320. package/dist/plugs/esbuild/fix-extensions.mjs.map +0 -6
  321. package/dist/plugs/esbuild.cjs +0 -139
  322. package/dist/plugs/esbuild.cjs.map +0 -6
  323. package/dist/plugs/esbuild.mjs +0 -116
  324. package/dist/plugs/esbuild.mjs.map +0 -6
  325. package/dist/plugs/exec.cjs +0 -42
  326. package/dist/plugs/exec.cjs.map +0 -6
  327. package/dist/plugs/exec.mjs +0 -25
  328. package/dist/plugs/exec.mjs.map +0 -6
  329. package/dist/plugs/exports.cjs +0 -117
  330. package/dist/plugs/exports.cjs.map +0 -6
  331. package/dist/plugs/exports.mjs +0 -100
  332. package/dist/plugs/exports.mjs.map +0 -6
  333. package/dist/plugs/filter.cjs +0 -47
  334. package/dist/plugs/filter.cjs.map +0 -6
  335. package/dist/plugs/filter.mjs +0 -30
  336. package/dist/plugs/filter.mjs.map +0 -6
  337. package/dist/plugs/rmf.cjs +0 -25
  338. package/dist/plugs/rmf.cjs.map +0 -6
  339. package/dist/plugs/rmf.mjs +0 -23
  340. package/dist/plugs/rmf.mjs.map +0 -6
  341. package/dist/plugs.cjs +0 -39
  342. package/dist/plugs.cjs.map +0 -6
  343. package/dist/plugs.mjs +0 -10
  344. package/dist/plugs.mjs.map +0 -6
  345. package/dist/types.cjs +0 -19
  346. package/dist/types.cjs.map +0 -6
  347. package/dist/types.mjs +0 -1
  348. package/dist/types.mjs.map +0 -6
  349. package/dist/utils/ansi.cjs +0 -39
  350. package/dist/utils/ansi.cjs.map +0 -6
  351. package/dist/utils/ansi.mjs +0 -13
  352. package/dist/utils/ansi.mjs.map +0 -6
  353. package/dist/utils/caller.cjs +0 -57
  354. package/dist/utils/caller.cjs.map +0 -6
  355. package/dist/utils/caller.mjs +0 -32
  356. package/dist/utils/caller.mjs.map +0 -6
  357. package/dist/utils/diff.cjs +0 -282
  358. package/dist/utils/diff.cjs.map +0 -6
  359. package/dist/utils/diff.mjs +0 -256
  360. package/dist/utils/diff.mjs.map +0 -6
  361. package/dist/utils/exec.cjs +0 -113
  362. package/dist/utils/exec.cjs.map +0 -6
  363. package/dist/utils/exec.mjs +0 -78
  364. package/dist/utils/exec.mjs.map +0 -6
  365. package/dist/utils/jsonc.cjs +0 -74
  366. package/dist/utils/jsonc.cjs.map +0 -6
  367. package/dist/utils/jsonc.mjs +0 -48
  368. package/dist/utils/jsonc.mjs.map +0 -6
  369. package/dist/utils/match.cjs +0 -74
  370. package/dist/utils/match.cjs.map +0 -6
  371. package/dist/utils/match.mjs +0 -39
  372. package/dist/utils/match.mjs.map +0 -6
  373. package/dist/utils/options.cjs +0 -39
  374. package/dist/utils/options.cjs.map +0 -6
  375. package/dist/utils/options.mjs +0 -14
  376. package/dist/utils/options.mjs.map +0 -6
  377. package/dist/utils/singleton.cjs +0 -37
  378. package/dist/utils/singleton.cjs.map +0 -6
  379. package/dist/utils/singleton.mjs +0 -12
  380. package/dist/utils/singleton.mjs.map +0 -6
  381. package/dist/utils/walk.cjs +0 -98
  382. package/dist/utils/walk.cjs.map +0 -6
  383. package/dist/utils/walk.mjs +0 -73
  384. package/dist/utils/walk.mjs.map +0 -6
  385. package/dist/utils.cjs +0 -39
  386. package/dist/utils.cjs.map +0 -6
  387. package/dist/utils.mjs +0 -10
  388. package/dist/utils.mjs.map +0 -6
@@ -1,9 +1,9 @@
1
1
  import { sep } from 'node:path'
2
2
 
3
- import { getCurrentWorkingDirectory, resolveRelativeChildPath } from '../paths'
4
- import { logOptions } from './options'
3
+ import { getCurrentWorkingDirectory, resolveRelativeChildPath } from '../paths.ts'
4
+ import { logOptions } from './options.ts'
5
5
 
6
- import type { AbsolutePath } from '../paths'
6
+ import type { AbsolutePath } from '../paths.ts'
7
7
 
8
8
  /* ========================================================================== */
9
9
 
@@ -26,7 +26,7 @@ const ylw = '\u001b[38;5;220m' // yellow
26
26
  const blu = '\u001b[38;5;69m' // brighter blue
27
27
  const mgt = '\u001b[38;5;213m' // pinky magenta
28
28
  const cyn = '\u001b[38;5;81m' // darker cyan
29
- const wht = process.env.GITHUB_ACTIONS === 'true' ?
29
+ const wht = process.env['GITHUB_ACTIONS'] === 'true' ?
30
30
  '\u001b[1;38;5;240m' : // bold gray (GitHub Actions's new white background)
31
31
  '\u001b[1;38;5;255m' // full-bright white
32
32
 
@@ -1,12 +1,12 @@
1
1
  import { formatWithOptions } from 'node:util'
2
2
 
3
- import { fail } from '../asserts'
4
- import { $blu, $grn, $gry, $red, $t, $ylw } from './colors'
5
- import { DEBUG, INFO, NOTICE, TRACE, WARN } from './levels'
6
- import { logOptions } from './options'
7
- import { zapSpinner } from './spinner'
3
+ import { fail } from '../asserts.ts'
4
+ import { $blu, $grn, $gry, $red, $t, $ylw } from './colors.ts'
5
+ import { DEBUG, INFO, NOTICE, TRACE, WARN } from './levels.ts'
6
+ import { logOptions } from './options.ts'
7
+ import { zapSpinner } from './spinner.ts'
8
8
 
9
- import type { LogLevel } from './levels'
9
+ import type { LogLevel } from './levels.ts'
10
10
 
11
11
  /* ========================================================================== */
12
12
 
@@ -1,10 +1,10 @@
1
1
  import { EOL } from 'node:os'
2
2
  import { formatWithOptions } from 'node:util'
3
3
 
4
- import { stripAnsi } from '../utils/ansi'
5
- import { logOptions } from './options'
4
+ import { stripAnsi } from '../utils/ansi.ts'
5
+ import { logOptions } from './options.ts'
6
6
 
7
- import type { AbsolutePath } from '../paths'
7
+ import type { AbsolutePath } from '../paths.ts'
8
8
 
9
9
  /* Initial values, and subscribe to changes */
10
10
  let _output = logOptions.output
@@ -1,17 +1,17 @@
1
1
  import { formatWithOptions } from 'node:util'
2
2
 
3
- import { BuildFailure } from '../asserts'
4
- import { currentContext } from '../async'
5
- import { stripAnsi } from '../utils/ansi'
6
- import { $gry } from './colors'
7
- import { emit } from './emit'
8
- import { DEBUG, ERROR, INFO, NOTICE, TRACE, WARN } from './levels'
9
- import { logOptions } from './options'
10
- import { ReportImpl } from './report'
11
-
12
- import type { LogEmitter, LogEmitterOptions } from './emit'
13
- import type { LogLevel } from './levels'
14
- import type { Report } from './report'
3
+ import { BuildFailure } from '../asserts.ts'
4
+ import { currentContext } from '../async.ts'
5
+ import { stripAnsi } from '../utils/ansi.ts'
6
+ import { $gry } from './colors.ts'
7
+ import { emit } from './emit.ts'
8
+ import { DEBUG, ERROR, INFO, NOTICE, TRACE, WARN } from './levels.ts'
9
+ import { logOptions } from './options.ts'
10
+ import { ReportImpl } from './report.ts'
11
+
12
+ import type { LogEmitter, LogEmitterOptions } from './emit.ts'
13
+ import type { LogLevel } from './levels.ts'
14
+ import type { Report } from './report.ts'
15
15
 
16
16
 
17
17
  /* ========================================================================== */
@@ -1,11 +1,11 @@
1
1
  import { EventEmitter } from 'node:events'
2
2
 
3
- import { getSingleton } from '../utils/singleton'
4
- import { getLevelNumber, NOTICE } from './levels'
3
+ import { getSingleton } from '../utils/singleton.ts'
4
+ import { getLevelNumber, NOTICE } from './levels.ts'
5
5
 
6
6
  import type { Writable } from 'node:stream'
7
7
  import type { InspectOptions } from 'node:util'
8
- import type { LogLevel, LogLevelString } from './levels'
8
+ import type { LogLevel, LogLevelString } from './levels.ts'
9
9
 
10
10
  /* ========================================================================== */
11
11
 
@@ -76,19 +76,19 @@ class LogOptionsImpl extends EventEmitter implements LogOptions {
76
76
  this.setMaxListeners(20)
77
77
 
78
78
  /* The `LOG_LEVEL` variable is one of our `debug`, `info`, ... */
79
- if (process.env.LOG_LEVEL) {
80
- this._level = getLevelNumber(process.env.LOG_LEVEL as LogLevelString)
79
+ if (process.env['LOG_LEVEL']) {
80
+ this._level = getLevelNumber(process.env['LOG_LEVEL'] as LogLevelString)
81
81
  }
82
82
 
83
83
  /* If the `LOG_COLORS` variable is specified, it should be `true` or `false` */
84
- if (process.env.LOG_COLORS) {
85
- if (process.env.LOG_COLORS.toLowerCase() === 'true') this.colors = true
86
- if (process.env.LOG_COLORS.toLowerCase() === 'false') this.colors = false
84
+ if (process.env['LOG_COLORS']) {
85
+ if (process.env['LOG_COLORS'].toLowerCase() === 'true') this.colors = true
86
+ if (process.env['LOG_COLORS'].toLowerCase() === 'false') this.colors = false
87
87
  // Other values don't change the value of `options.colors`
88
88
  }
89
89
 
90
90
  /* If the `GITHUB_ACTIONS` is `true` then enable annotations and use plain logs */
91
- this._githubAnnotations = process.env.GITHUB_ACTIONS === 'true'
91
+ this._githubAnnotations = process.env['GITHUB_ACTIONS'] === 'true'
92
92
  if (this._githubAnnotations) {
93
93
  this._colors = true
94
94
  this._format = 'plain'
@@ -100,7 +100,7 @@ class LogOptionsImpl extends EventEmitter implements LogOptions {
100
100
  * and it's processed _last_ as it's normally only created by fork below
101
101
  * and consumed by the `Exec` plug (which has no other way of communicating)
102
102
  */
103
- const options = JSON.parse(process.env.__LOG_OPTIONS || '{}')
103
+ const options = JSON.parse(process.env['__LOG_OPTIONS'] || '{}')
104
104
  Object.assign(this, options)
105
105
  }
106
106
 
@@ -1,13 +1,13 @@
1
- import { BuildFailure } from '../asserts'
2
- import { readFile } from '../fs'
3
- import { $blu, $cyn, $gry, $plur, $red, $und, $wht, $ylw } from './colors'
4
- import { githubAnnotation } from './github'
5
- import { ERROR, NOTICE, WARN, logLevels } from './levels'
6
- import { logOptions } from './options'
7
-
8
- import type { AbsolutePath } from '../paths'
9
- import type { LogEmitter } from './emit'
10
- import type { LogLevels } from './levels'
1
+ import { BuildFailure } from '../asserts.ts'
2
+ import { readFile } from '../fs.ts'
3
+ import { $blu, $cyn, $gry, $plur, $red, $und, $wht, $ylw } from './colors.ts'
4
+ import { githubAnnotation } from './github.ts'
5
+ import { ERROR, NOTICE, WARN, logLevels } from './levels.ts'
6
+ import { logOptions } from './options.ts'
7
+
8
+ import type { AbsolutePath } from '../paths.ts'
9
+ import type { LogEmitter } from './emit.ts'
10
+ import type { LogLevels } from './levels.ts'
11
11
 
12
12
  let _showSources = logOptions.showSources
13
13
  let _githubAnnotations = logOptions.githubAnnotations
@@ -1,8 +1,8 @@
1
1
  /* coverage ignore file */
2
2
 
3
- import { runningTasks } from '../async'
4
- import { $cyn, $gry, $plur, $t } from './colors'
5
- import { logOptions } from './options'
3
+ import { runningTasks } from '../async.ts'
4
+ import { $cyn, $gry, $plur, $t } from './colors.ts'
5
+ import { logOptions } from './options.ts'
6
6
 
7
7
  /* ========================================================================== */
8
8
 
package/src/logging.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { currentContext } from './async'
2
- import { $gry, $wht } from './logging/colors'
3
- import { getLogger } from './logging/logger'
4
- import { setupSpinner } from './logging/spinner'
5
- import { stripAnsi } from './utils/ansi'
6
-
7
- import type { Log, Logger } from './logging/logger'
8
-
9
- export * from './logging/colors'
10
- export * from './logging/github'
11
- export * from './logging/levels'
12
- export * from './logging/logger'
13
- export * from './logging/options'
14
- export * from './logging/report'
1
+ import { currentContext } from './async.ts'
2
+ import { $gry, $wht } from './logging/colors.ts'
3
+ import { getLogger } from './logging/logger.ts'
4
+ import { setupSpinner } from './logging/spinner.ts'
5
+ import { stripAnsi } from './utils/ansi.ts'
6
+
7
+ import type { Log, Logger } from './logging/logger.ts'
8
+
9
+ export * from './logging/colors.ts'
10
+ export * from './logging/github.ts'
11
+ export * from './logging/levels.ts'
12
+ export * from './logging/logger.ts'
13
+ export * from './logging/options.ts'
14
+ export * from './logging/report.ts'
15
15
 
16
16
  /* ========================================================================== *
17
17
  * 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 './asserts'
6
+ import { assert } from './asserts.ts'
7
7
 
8
8
  /** A _branded_ `string` representing an _absolute_ path name */
9
9
  export type AbsolutePath = string & { __brand_absolute_path: never }
@@ -109,44 +109,59 @@ export function commonPath(path: AbsolutePath, ...paths: string[]): AbsolutePath
109
109
  * MODULE RESOLUTION FUNCTIONS *
110
110
  * ========================================================================== */
111
111
 
112
- function resolveFilename(__fileurl: string): AbsolutePath {
113
- const file = __fileurl.startsWith('file:') ? fileURLToPath(__fileurl) : __fileurl
112
+ /** Resolve a file URL or a path to an {@link AbsolutePath} */
113
+ function resolveFilename(fileurl: string): AbsolutePath {
114
+ const file = fileurl.startsWith('file:') ? fileURLToPath(fileurl) : fileurl
114
115
  assertAbsolutePath(file)
115
116
  return file
116
117
  }
117
118
 
118
- /** Return the equivalent of `__filename` from our `__fileurl` pseudo variable */
119
- export function filenameFromUrl(__fileurl: string): AbsolutePath {
120
- const file = resolveFilename(__fileurl)
121
- assert(resolveFile(file), `Unable to resolve "${__fileurl}" as a file`)
119
+ /**
120
+ * Asserts that `fileurl` (a path or a `file:...` URL) resolves to an
121
+ * existing file.
122
+ */
123
+ export function filenameFromUrl(fileurl: string): AbsolutePath {
124
+ const file = resolveFilename(fileurl)
125
+ assert(resolveFile(file), `Unable to resolve "${fileurl}" as a file`)
122
126
  return file
123
127
  }
124
128
 
125
129
 
126
- /** Return the equivalent of `__dirname` from our `__fileurl` pseudo variable */
127
- export function dirnameFromUrl(__fileurl: string): AbsolutePath {
128
- const dir = getAbsoluteParent(resolveFilename(__fileurl))
129
- assert(resolveDirectory(dir), `Unable to resolve "${__fileurl}" as a directory`)
130
+ /**
131
+ * Asserts that the _parent_ path of `fileurl` (a path or a `file:...` URL)
132
+ * resolves to an existing directory.
133
+ */
134
+ export function dirnameFromUrl(fileurl: string): AbsolutePath {
135
+ const dir = getAbsoluteParent(resolveFilename(fileurl))
136
+ assert(resolveDirectory(dir), `Unable to resolve "${fileurl}" as a directory`)
130
137
  return dir
131
138
  }
132
139
 
133
140
  /**
134
- * Return the absolute path of a file relative to the given `__fileurl`, where
135
- * `__fileurl` is either CommonJS's own `__filename` variable, or EcmaScript's
136
- * `import.meta.url` (so either an absolute path name, or a `file:///...` url).
141
+ * Return the absolute path of of `fileurl` (a path or a `file:...` URL) or
142
+ * (if further `paths` are specified) the absolute path of a file relative to
143
+ * it.
137
144
  *
138
- * If further `paths` are specified, those will be resolved as relative paths
139
- * to the original `__fileurl` so we can easily write something like this:
145
+ * If no `paths` are specified, this will simply return the {@link AbsolutePath}
146
+ * of `fileurl`:
140
147
  *
148
+ * ```ts
149
+ * const thisFile = requireFilename(import.meta.url)
150
+ * // if we write this in "/foo/bar/baz.(ts|js|cjs|mjs)"
151
+ * // `thisFile` will now be "/foo/bar/baz.(ts|js|cjs|mjs)"
141
152
  * ```
142
- * const dataFile = requireFilename(__fileurl, 'data.json')
153
+ *
154
+ * If further `paths` are specified, those will be resolved as relative paths
155
+ * to the original `fileurl` so we can easily write something like this:
156
+ *
157
+ * ```ts
158
+ * const dataFile = requireFilename(import.meta.url, 'data.json')
143
159
  * // if we write this in "/foo/bar/baz.(ts|js|cjs|mjs)"
144
160
  * // `dataFile` will now be "/foo/bar/data.json"
145
161
  * ```
146
162
  */
147
- export function requireFilename(__fileurl: string, ...paths: string[]): AbsolutePath {
148
- const file = resolveFilename(__fileurl)
149
- assertAbsolutePath(file)
163
+ export function requireFilename(fileurl: string, ...paths: string[]): AbsolutePath {
164
+ const file = resolveFilename(fileurl)
150
165
 
151
166
  /* No paths? Return the file! */
152
167
  if (! paths.length) return file
@@ -161,11 +176,15 @@ export function requireFilename(__fileurl: string, ...paths: string[]): Absolute
161
176
  * by Node (or forked to via `child_process.fork`).
162
177
  *
163
178
  * This leverages {@link requireFilename} to figure out the starting point where
164
- * to look for files, and will _try_ to match the same extension of `__fileurl`
179
+ * to look for files, and will _try_ to match the same extension of `fileurl`
165
180
  * (so, `.ts` for `ts-node`, `.mjs` for ESM modules, ...).
181
+ *
182
+ * Extension matching is performed that the same instruction can be used in
183
+ * various scenarions (e.g. `.ts` when running dynamically, `.js`, `.mjs` or
184
+ * `.cjs` after transpilation)
166
185
  */
167
- export function requireResolve(__fileurl: string, module: string): AbsolutePath {
168
- const file = resolveFilename(__fileurl)
186
+ export function requireResolve(fileurl: string, module: string): AbsolutePath {
187
+ const file = resolveFilename(fileurl)
169
188
 
170
189
  // We do our custom resolution _only_ for local (./foo.bar) files...
171
190
  if (module.match(/^\.\.?\//)) {
package/src/pipe.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
2
2
  import { sep } from 'node:path'
3
3
 
4
- import { assert, assertPromises } from './asserts'
5
- import { getLogger } from './logging'
6
- import { getAbsoluteParent, getCurrentWorkingDirectory, resolveAbsolutePath } from './paths'
4
+ import { assert, assertPromises } from './asserts.ts'
5
+ import { getLogger } from './logging.ts'
6
+ import { getAbsoluteParent, getCurrentWorkingDirectory, resolveAbsolutePath } from './paths.ts'
7
7
 
8
- import type { Files } from './files'
9
- import type { Pipe } from './index'
10
- import type { Logger } from './logging'
11
- import type { AbsolutePath } from './paths'
12
- import type { Result } from './types'
8
+ import type { Files } from './files.ts'
9
+ import type { Pipe } from './index.ts'
10
+ import type { Logger } from './logging.ts'
11
+ import type { AbsolutePath } from './paths.ts'
12
+ import type { Result } from './types.ts'
13
13
 
14
14
  /* ========================================================================== *
15
15
  * PLUGS *
@@ -56,6 +56,11 @@ export class Context {
56
56
  this.log = getLogger(taskName)
57
57
  }
58
58
 
59
+ /** Return a new {@link Context} with the specified task name */
60
+ withTaskName(taskName: string): Context {
61
+ return new Context(this.buildFile, taskName)
62
+ }
63
+
59
64
  /**
60
65
  * Resolve a (set of) path(s) in this {@link Context}.
61
66
  *
@@ -1,11 +1,11 @@
1
- import { invokeTasks, isBuild } from '../build'
2
- import { ForkingPlug } from '../fork'
3
- import { $p } from '../logging/colors'
4
- import { requireFilename } from '../paths'
1
+ import { invokeTasks, isBuild } from '../build.ts'
2
+ import { ForkingPlug } from '../fork.ts'
3
+ import { $p } from '../logging/colors.ts'
4
+ import { requireFilename } from '../paths.ts'
5
5
 
6
- import type { Files } from '../files'
7
- import type { ForkOptions } from '../fork'
8
- import type { Context, Plug } from '../pipe'
6
+ import type { Files } from '../files.ts'
7
+ import type { ForkOptions } from '../fork.ts'
8
+ import type { Context, Plug } from '../pipe.ts'
9
9
 
10
10
  export interface RunBuildOptions extends ForkOptions {
11
11
  /** The _current working directory_ to be set when running the build */
@@ -55,6 +55,6 @@ export class RunBuild extends ForkingPlug {
55
55
  props: Readonly<Record<string, string>>,
56
56
  options: ForkOptions,
57
57
  ) {
58
- super(requireFilename(__fileurl), [ tasks, props, options ], RunBuildInternal.name)
58
+ super(requireFilename(import.meta.filename), [ tasks, props, options ], RunBuildInternal.name)
59
59
  }
60
60
  }
package/src/plugs/copy.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { assert } from '../asserts'
2
- import { Files } from '../files'
3
- import { chmod, copyFile, fsConstants, mkdir } from '../fs'
4
- import { $p } from '../logging'
5
- import { assertAbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths'
6
- import { install } from '../pipe'
7
-
8
- import type { Context, PipeParameters, Plug } from '../pipe'
1
+ import { assert } from '../asserts.ts'
2
+ import { Files } from '../files.ts'
3
+ import { chmod, copyFile, fsConstants, mkdir } from '../fs.ts'
4
+ import { $p } from '../logging.ts'
5
+ import { assertAbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths.ts'
6
+ import { install } from '../pipe.ts'
7
+
8
+ import type { Context, PipeParameters, Plug } from '../pipe.ts'
9
9
 
10
10
  /** Options for copying files */
11
11
  export interface CopyOptions {
@@ -1,8 +1,8 @@
1
- import { $gry, $und, $ylw } from '../logging'
2
- import { install } from '../pipe'
1
+ import { $gry, $und, $ylw } from '../logging.ts'
2
+ import { install } from '../pipe.ts'
3
3
 
4
- import type { Files } from '../files'
5
- import type { Context, PipeParameters, Plug } from '../pipe'
4
+ import type { Files } from '../files.ts'
5
+ import type { Context, PipeParameters, Plug } from '../pipe.ts'
6
6
 
7
7
  declare module '../index' {
8
8
  export interface Pipe {
package/src/plugs/edit.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { readFile, writeFile } from '../fs'
2
- import { install } from '../pipe'
1
+ import { readFile, writeFile } from '../fs.ts'
2
+ import { install } from '../pipe.ts'
3
3
 
4
- import type { Files } from '../files'
5
- import type { AbsolutePath } from '../paths'
6
- import type { PipeParameters, Plug } from '../pipe'
4
+ import type { Files } from '../files.ts'
5
+ import type { AbsolutePath } from '../paths.ts'
6
+ import type { PipeParameters, Plug } from '../pipe.ts'
7
7
 
8
8
  declare module '../index' {
9
9
  export interface Pipe {
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path'
2
2
 
3
- import { stat } from '../../fs'
4
- import { assertAbsolutePath, resolveAbsolutePath, resolveFile } from '../../paths'
3
+ import { stat } from '../../fs.ts'
4
+ import { assertAbsolutePath, resolveAbsolutePath, resolveFile } from '../../paths.ts'
5
5
 
6
6
  import type { Plugin } from 'esbuild'
7
7
 
@@ -60,16 +60,14 @@ export function fixExtensions(): Plugin {
60
60
  const resolveDir = args.resolveDir
61
61
  assertAbsolutePath(resolveDir)
62
62
 
63
- /* First of all, check if the _real_ filename exists */
64
- const resolved = resolveAbsolutePath(resolveDir, args.path)
65
- if (resolveFile(resolved)) return { path: args.path, external: true }
66
-
67
63
  /*
68
- * Thank you TypeScript 4.7!!! If the file is ".js", ".mjs" or ".cjs" we
69
- * need to check if we have the corresponding ".ts", ".mts" or ".cjs"
70
- * and return whatever ESBuild maps that particular extension to.
64
+ * Thank you TypeScript 4.7!!! If the file is ".js", ".mjs" or ".cjs"
65
+ * (or even ".ts", ".mts" or ".cts" when "allowImportingTsExtensions"
66
+ * is enabled), we need to check if we have the corresponding ".ts",
67
+ * ".mts" or ".cjs" and return whatever ESBuild maps that particular
68
+ * extension to.
71
69
  */
72
- const match = args.path.match(/(.*)(\.[mc]?js$)/)
70
+ const match = args.path.match(/(.*)(\.[mc]?[jt]s$)/)
73
71
  if (match) {
74
72
  const [ , name, ext ] = match
75
73
  const tspath = name + ext!.replace('js', 'ts')
@@ -2,35 +2,34 @@ import { basename } from 'node:path'
2
2
 
3
3
  import { build } from 'esbuild'
4
4
 
5
- import { assert } from '../asserts'
6
- import { Files } from '../files'
7
- import { readFile } from '../fs'
8
- import { $p, ERROR, WARN } from '../logging'
9
- import { getAbsoluteParent, resolveAbsolutePath } from '../paths'
10
- import { install } from '../pipe'
5
+ import { assert } from '../asserts.ts'
6
+ import { Files } from '../files.ts'
7
+ import { readFile } from '../fs.ts'
8
+ import { $p, ERROR, WARN } from '../logging.ts'
9
+ import { getAbsoluteParent, resolveAbsolutePath } from '../paths.ts'
10
+ import { install } from '../pipe.ts'
11
11
 
12
12
  import type { BuildFailure, BuildOptions, BuildResult, Format, Message, Metafile } from 'esbuild'
13
- import type { FilesBuilder } from '../files'
14
- import type { Logger, ReportLevel, ReportRecord } from '../logging'
15
- import type { AbsolutePath } from '../paths'
16
- import type { Context, PipeParameters, Plug } from '../pipe'
13
+ import type { FilesBuilder } from '../files.ts'
14
+ import type { Logger, ReportLevel, ReportRecord } from '../logging.ts'
15
+ import type { AbsolutePath } from '../paths.ts'
16
+ import type { Context, PipeParameters, Plug } from '../pipe.ts'
17
17
 
18
18
  export type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'>
19
19
 
20
- export * from './esbuild/bundle-locals'
21
- export * from './esbuild/fix-extensions'
22
-
23
- /*
24
- * Type definition for `WebAssembly`. This is normally provided to TypeScript
25
- * by `lib.dom.d.ts`, and is not defined by Node's own types.
26
- *
27
- * https://github.com/evanw/esbuild/issues/2388
28
- */
29
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
- declare const WebAssembly: {
31
- Module: any,
20
+ /** Options for converting ESM modules to CommonJS */
21
+ export interface ModuleToCommonJSOptions {
22
+ /** The extension to use for CommonJS output files (default: `.cjs`) */
23
+ outExtension?: string,
24
+ /** The output directory for CommonJS files (default: same as input directory) */
25
+ outDir?: string,
26
+ /** Whether to minify the output CJS files (default: `false`) */
27
+ minify?: boolean,
32
28
  }
33
29
 
30
+ export * from './esbuild/bundle-locals.ts'
31
+ export * from './esbuild/fix-extensions.ts'
32
+
34
33
  declare module '../index' {
35
34
  export interface Pipe {
36
35
  /**
@@ -43,6 +42,16 @@ declare module '../index' {
43
42
  *
44
43
  */
45
44
  esbuild(options: ESBuildOptions): Pipe
45
+
46
+ /**
47
+ * Transpile EcmaScript Modules (`import`) to CommonJS (`require`) with
48
+ * {@link https://esbuild.github.io/ esbuild}.
49
+ *
50
+ * @param options Minimal options {@link ModuleToCommonJSOptions | options}
51
+ * for transpilation of ESM to CJS.
52
+ *
53
+ */
54
+ esm2cjs(options?: ModuleToCommonJSOptions): Pipe
46
55
  }
47
56
  }
48
57
 
@@ -50,11 +59,11 @@ declare module '../index' {
50
59
  * INSTALLATION / IMPLEMENTATION *
51
60
  * ========================================================================== */
52
61
 
53
- install('esbuild', class ESBuild implements Plug<Files> {
62
+ class ESBuild implements Plug<Files> {
54
63
  constructor(...args: PipeParameters<'esbuild'>)
55
- constructor(private readonly _options: ESBuildOptions) {}
64
+ constructor(protected readonly _options: ESBuildOptions) {}
56
65
 
57
- async pipe(files: Files, context: Context): Promise<Files> {
66
+ async pipe(files: Files, context: Context, override?: ESBuildOptions): Promise<Files> {
58
67
  const entryPoints = [ ...files ]
59
68
  const absWorkingDir = files.directory
60
69
 
@@ -66,11 +75,12 @@ install('esbuild', class ESBuild implements Plug<Files> {
66
75
  /* The default format (if not specified in options) is from package.json */
67
76
  format: this._options.format || await _moduleFormat(files.directory, context.log),
68
77
 
69
- /* Output bese directory */
78
+ /* Output base directory */
70
79
  outbase: absWorkingDir,
71
80
 
72
81
  /* Merge in the caller's options */
73
82
  ...this._options,
83
+ ...override,
74
84
 
75
85
  /* Always override */
76
86
  absWorkingDir,
@@ -135,7 +145,7 @@ install('esbuild', class ESBuild implements Plug<Files> {
135
145
  context.log.info('ESBuild produced', result.length, 'files into', $p(result.directory))
136
146
  return result
137
147
  }
138
- })
148
+ }
139
149
 
140
150
  function convertMessage(level: ReportLevel, message: Message, directory: AbsolutePath): ReportRecord {
141
151
  const record: ReportRecord = { level, message: message.text }
@@ -204,3 +214,54 @@ async function _moduleFormat(directory: AbsolutePath, log: Logger): Promise<Form
204
214
  return type
205
215
  }
206
216
  }
217
+
218
+ /* ========================================================================== *
219
+ * ESM TO CJS CONVERSION *
220
+ * ========================================================================== */
221
+
222
+ class ModuleToCommonJS extends ESBuild {
223
+ constructor(...args: PipeParameters<'esm2cjs'>)
224
+ constructor(options: ModuleToCommonJSOptions = {}) {
225
+ const { minify, outDir, outExtension = '.cjs' } = options
226
+
227
+ super({
228
+ outdir: outDir,
229
+ format: 'cjs',
230
+ platform: 'node',
231
+ target: 'node22',
232
+ sourcemap: 'inline',
233
+ minify: !! minify,
234
+ outExtension: { '.js': outExtension },
235
+ banner: {
236
+ // Our banner for ESM to CJS conversion, to provide a bare-bones
237
+ // support for `import.meta.url` in CJS modules.
238
+ js: `var __importMetaStub = {
239
+ get url() { return require("node:url").pathToFileURL(__filename) }
240
+ };`.replaceAll(/\n\s+/g, ' '),
241
+ },
242
+ define: {
243
+ 'import.meta.url': '__importMetaStub.url',
244
+ 'import.meta.filename': '__filename',
245
+ 'import.meta.dirname': '__dirname',
246
+ },
247
+ })
248
+ }
249
+
250
+ override async pipe(files: Files, context: Context): Promise<Files> {
251
+ // If a directory was not specified at construction time, we default the
252
+ // output directory to the same as the input files...
253
+ const override: ESBuildOptions = this._options.outdir ? {} : {
254
+ outdir: files.directory,
255
+ }
256
+
257
+ // Do It!
258
+ return super.pipe(files, context, override)
259
+ }
260
+ }
261
+
262
+ /* ========================================================================== *
263
+ * INSTALL PLUGS *
264
+ * ========================================================================== */
265
+
266
+ install('esbuild', ESBuild)
267
+ install('esm2cjs', ModuleToCommonJS)