@plugjs/plug 0.3.4 → 0.4.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 (77) hide show
  1. package/dist/asserts.cjs +9 -11
  2. package/dist/asserts.cjs.map +1 -1
  3. package/dist/asserts.d.ts +1 -2
  4. package/dist/asserts.mjs +8 -9
  5. package/dist/asserts.mjs.map +1 -1
  6. package/dist/build.cjs +29 -5
  7. package/dist/build.cjs.map +1 -1
  8. package/dist/build.d.ts +4 -0
  9. package/dist/build.mjs +27 -5
  10. package/dist/build.mjs.map +1 -1
  11. package/dist/cli.d.mts +12 -0
  12. package/dist/cli.mjs +266 -0
  13. package/dist/cli.mjs.map +6 -0
  14. package/dist/fork.cjs +35 -12
  15. package/dist/fork.cjs.map +1 -1
  16. package/dist/fork.d.ts +10 -0
  17. package/dist/fork.mjs +36 -13
  18. package/dist/fork.mjs.map +1 -1
  19. package/dist/helpers.cjs +30 -10
  20. package/dist/helpers.cjs.map +2 -2
  21. package/dist/helpers.d.ts +12 -0
  22. package/dist/helpers.mjs +35 -11
  23. package/dist/helpers.mjs.map +2 -2
  24. package/dist/index.cjs +5 -0
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.ts +2 -1
  27. package/dist/index.mjs +4 -1
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/logging/emit.cjs +4 -4
  30. package/dist/logging/emit.cjs.map +1 -1
  31. package/dist/logging/emit.mjs +4 -4
  32. package/dist/logging/emit.mjs.map +1 -1
  33. package/dist/logging/logger.cjs +43 -2
  34. package/dist/logging/logger.cjs.map +1 -1
  35. package/dist/logging/logger.d.ts +36 -3
  36. package/dist/logging/logger.mjs +43 -3
  37. package/dist/logging/logger.mjs.map +1 -1
  38. package/dist/logging/options.cjs +5 -2
  39. package/dist/logging/options.cjs.map +1 -1
  40. package/dist/logging/options.mjs +5 -2
  41. package/dist/logging/options.mjs.map +1 -1
  42. package/dist/logging.cjs +14 -3
  43. package/dist/logging.cjs.map +1 -1
  44. package/dist/logging.d.ts +2 -0
  45. package/dist/logging.mjs +13 -3
  46. package/dist/logging.mjs.map +1 -1
  47. package/dist/plugs/build.cjs +66 -0
  48. package/dist/plugs/build.cjs.map +6 -0
  49. package/dist/plugs/build.d.ts +13 -0
  50. package/dist/plugs/build.mjs +40 -0
  51. package/dist/plugs/build.mjs.map +6 -0
  52. package/dist/types.d.ts +2 -0
  53. package/dist/utils/exec.cjs +5 -12
  54. package/dist/utils/exec.cjs.map +2 -2
  55. package/dist/utils/exec.d.ts +0 -2
  56. package/dist/utils/exec.mjs +6 -13
  57. package/dist/utils/exec.mjs.map +1 -1
  58. package/package.json +7 -9
  59. package/src/asserts.ts +9 -11
  60. package/src/build.ts +33 -4
  61. package/{extra/plug.mts → src/cli.mts} +115 -141
  62. package/src/fork.ts +50 -13
  63. package/src/helpers.ts +53 -1
  64. package/src/index.ts +2 -1
  65. package/src/logging/emit.ts +4 -4
  66. package/src/logging/logger.ts +60 -7
  67. package/src/logging/options.ts +5 -1
  68. package/src/logging.ts +20 -5
  69. package/src/plugs/build.ts +58 -0
  70. package/src/types.ts +2 -0
  71. package/src/utils/exec.ts +6 -20
  72. package/cli/plug.mjs +0 -1385
  73. package/cli/ts-loader.mjs +0 -275
  74. package/cli/tsrun.mjs +0 -1204
  75. package/extra/ts-loader.mts +0 -546
  76. package/extra/tsrun.mts +0 -127
  77. package/extra/utils.ts +0 -150
package/extra/utils.ts DELETED
@@ -1,150 +0,0 @@
1
- /* eslint-disable no-console */
2
- import _childProcess from 'node:child_process'
3
- import _fs from 'node:fs'
4
- import _path from 'node:path'
5
- import _url from 'node:url'
6
- import _util from 'node:util'
7
-
8
- /* ========================================================================== *
9
- * PRETTY COLORS *
10
- * ========================================================================== */
11
-
12
- export const $rst = process.stdout.isTTY ? '\u001b[0m' : '' // reset all colors to default
13
- export const $und = process.stdout.isTTY ? '\u001b[4m' : '' // underline on
14
- export const $gry = process.stdout.isTTY ? '\u001b[38;5;240m' : '' // somewhat gray
15
- export const $blu = process.stdout.isTTY ? '\u001b[38;5;69m' : '' // brighter blue
16
- export const $wht = process.stdout.isTTY ? '\u001b[1;38;5;255m' : '' // full-bright white
17
- export const $tsk = process.stdout.isTTY ? '\u001b[38;5;141m' : '' // the color for tasks (purple)
18
-
19
-
20
- /* ========================================================================== *
21
- * TS LOADER FORCE TYPE *
22
- * ========================================================================== */
23
-
24
- function forceType(type: 'commonjs' | 'module'): void {
25
- const debug = _util.debuglog('plug:cli')
26
-
27
- const tsLoaderMarker = Symbol.for('plugjs:tsLoader')
28
-
29
- if (!(tsLoaderMarker in globalThis)) {
30
- throw new Error('TypeScript Loader not available')
31
- }
32
- debug(`Forcing type to "${type}"`)
33
- ;(globalThis as any)[tsLoaderMarker] = type
34
- }
35
-
36
-
37
- /* ========================================================================== *
38
- * FILES UTILITIES *
39
- * ========================================================================== */
40
-
41
- /* Returns a boolean indicating whether the specified file exists or not */
42
- export function isFile(path: string): boolean {
43
- try {
44
- return _fs.statSync(path).isFile()
45
- } catch (error) {
46
- return false
47
- }
48
- }
49
-
50
- /* Returns a boolean indicating whether the specified directory exists or not */
51
- export function isDirectory(path: string): boolean {
52
- try {
53
- return _fs.statSync(path).isDirectory()
54
- } catch (error) {
55
- return false
56
- }
57
- }
58
-
59
-
60
- /* ========================================================================== *
61
- * MAIN ENTRY POINT *
62
- * ========================================================================== */
63
- export function main(callback: (args: string[]) => void | Promise<void>): void {
64
- const debug = _util.debuglog('plug:cli')
65
-
66
- /* Check for source maps and typescript support */
67
- const sourceMapsEnabled = process.execArgv.indexOf('--enable-source-maps') >= 0
68
-
69
- /* Check if our `ts-loader` loader is enabled */
70
- const tsLoaderMarker = Symbol.for('plugjs:tsLoader')
71
- const typeScriptEnabled = (globalThis as any)[tsLoaderMarker]
72
-
73
- /* Some debugging if needed */
74
- debug('SourceMaps enabled =', sourceMapsEnabled)
75
- debug('TypeScript enabled =', typeScriptEnabled || false)
76
-
77
- /* If both source maps and typescript are on, run! */
78
- if (sourceMapsEnabled && typeScriptEnabled) {
79
- const args = process.argv.slice(2).filter((arg: string): string | void => {
80
- if (arg === '--force-esm') {
81
- return forceType('module')
82
- } else if (arg === '--force-cjs') {
83
- return forceType('commonjs')
84
- } else {
85
- return arg
86
- }
87
- })
88
-
89
-
90
- Promise.resolve().then(() => callback(args)).catch(console.error)
91
- } else {
92
- const script = _url.fileURLToPath(import.meta.url)
93
-
94
- /* Fork out ourselves with new options */
95
- const execArgv = [ ...process.execArgv ]
96
-
97
- /* Enable source maps if not done already */
98
- if (! sourceMapsEnabled) execArgv.push('--enable-source-maps')
99
-
100
- /* Enable our ESM TypeScript loader if not done already */
101
- if (! typeScriptEnabled) {
102
- const directory = _path.dirname(script)
103
- const extension = _path.extname(script) // .mts or .mjs
104
- const loader = _path.resolve(directory, `ts-loader${extension}`)
105
- execArgv.push(`--experimental-loader=${loader}`, '--no-warnings')
106
- }
107
-
108
- /*
109
- * It seems that setting "type" as "module" in "package.json" creates some
110
- * problems when the module is being imported from a "commonjs" one.
111
- *
112
- * TypeScript _incorrectly_ says (regardless of how we set up our conditional
113
- * exports) that we must use dynamic imports:
114
- *
115
- * Module '@plugjs/plug' cannot be imported using this construct. The
116
- * specifier only resolves to an ES module, which cannot be imported
117
- * synchronously. Use dynamic import instead.
118
- * TS(1471)
119
- *
120
- * So for now our only option is to leave "type" as "commonjs", and for those
121
- * brave souls willing to force ESM irregardless of what's in "package.json",
122
- * we allow the "--force-esm" option, and instruct `ts-loader` that the
123
- * current directory (and subdirs) will transpile as ESM always.
124
- */
125
-
126
- /* Fork ourselves! */
127
- const child = _childProcess.fork(script, [ ...process.argv.slice(2) ], {
128
- stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ],
129
- execArgv,
130
- })
131
-
132
- /* Monitor child process... */
133
- child.on('error', (error) => {
134
- console.log('Error respawning CLI', error)
135
- process.exit(1)
136
- })
137
-
138
- child.on('exit', (code, signal) => {
139
- if (signal) {
140
- console.log(`CLI process exited with signal ${signal}`)
141
- process.exit(1)
142
- } else if (typeof code !== 'number') {
143
- console.log('CLI process failed for an unknown reason')
144
- process.exit(1)
145
- } else {
146
- process.exit(code)
147
- }
148
- })
149
- }
150
- }