@plugjs/plug 0.6.117 → 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.
- package/dist/asserts.d.ts +1 -0
- package/dist/asserts.d.ts.map +1 -0
- package/dist/asserts.js +68 -0
- package/dist/asserts.js.map +1 -0
- package/dist/async.d.ts +2 -1
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +52 -0
- package/dist/async.js.map +1 -0
- package/dist/build.d.ts +2 -1
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +236 -0
- package/dist/build.js.map +1 -0
- package/dist/{cli.d.mts → cli.d.ts} +3 -1
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +330 -0
- package/dist/cli.js.map +1 -0
- package/dist/files.d.ts +2 -1
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +93 -0
- package/dist/files.js.map +1 -0
- package/dist/fork.d.ts +5 -4
- package/dist/fork.d.ts.map +1 -0
- package/dist/fork.js +259 -0
- package/dist/fork.js.map +1 -0
- package/dist/fs.d.ts +1 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +72 -0
- package/dist/fs.js.map +1 -0
- package/dist/globals.d.ts +4 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +2 -0
- package/dist/globals.js.map +1 -0
- package/dist/helpers.d.ts +8 -7
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +231 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +22 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/colors.d.ts +2 -1
- package/dist/logging/colors.d.ts.map +1 -0
- package/dist/logging/colors.js +121 -0
- package/dist/logging/colors.js.map +1 -0
- package/dist/logging/emit.d.ts +2 -1
- package/dist/logging/emit.d.ts.map +1 -0
- package/dist/logging/emit.js +137 -0
- package/dist/logging/emit.js.map +1 -0
- package/dist/logging/github.d.ts +2 -1
- package/dist/logging/github.d.ts.map +1 -0
- package/dist/logging/github.js +46 -0
- package/dist/logging/github.js.map +1 -0
- package/dist/logging/levels.d.ts +1 -0
- package/dist/logging/levels.d.ts.map +1 -0
- package/dist/logging/levels.js +50 -0
- package/dist/logging/levels.js.map +1 -0
- package/dist/logging/logger.d.ts +4 -3
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +161 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/options.d.ts +2 -1
- package/dist/logging/options.d.ts.map +1 -0
- package/dist/logging/options.js +182 -0
- package/dist/logging/options.js.map +1 -0
- package/dist/logging/report.d.ts +4 -3
- package/dist/logging/report.d.ts.map +1 -0
- package/dist/logging/report.js +346 -0
- package/dist/logging/report.js.map +1 -0
- package/dist/logging/spinner.d.ts +1 -0
- package/dist/logging/spinner.d.ts.map +1 -0
- package/dist/logging/spinner.js +70 -0
- package/dist/logging/spinner.js.map +1 -0
- package/dist/logging.d.ts +8 -7
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +66 -0
- package/dist/logging.js.map +1 -0
- package/dist/paths.d.ts +33 -13
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +223 -0
- package/dist/paths.js.map +1 -0
- package/dist/pipe.d.ts +8 -5
- package/dist/pipe.d.ts.map +1 -0
- package/dist/pipe.js +205 -0
- package/dist/pipe.js.map +1 -0
- package/dist/plugs/build.d.ts +5 -4
- package/dist/plugs/build.d.ts.map +1 -0
- package/dist/plugs/build.js +56 -0
- package/dist/plugs/build.js.map +1 -0
- package/dist/plugs/copy.d.ts +1 -0
- package/dist/plugs/copy.d.ts.map +1 -0
- package/dist/plugs/copy.js +92 -0
- package/dist/plugs/copy.js.map +1 -0
- package/dist/plugs/debug.d.ts +1 -0
- package/dist/plugs/debug.d.ts.map +1 -0
- package/dist/plugs/debug.js +25 -0
- package/dist/plugs/debug.js.map +1 -0
- package/dist/plugs/edit.d.ts +2 -1
- package/dist/plugs/edit.d.ts.map +1 -0
- package/dist/plugs/edit.js +22 -0
- package/dist/plugs/edit.js.map +1 -0
- package/dist/plugs/esbuild/bundle-locals.d.ts +1 -0
- package/dist/plugs/esbuild/bundle-locals.d.ts.map +1 -0
- package/dist/plugs/esbuild/bundle-locals.js +29 -0
- package/dist/plugs/esbuild/bundle-locals.js.map +1 -0
- package/dist/plugs/esbuild/fix-extensions.d.ts +1 -0
- package/dist/plugs/esbuild/fix-extensions.d.ts.map +1 -0
- package/dist/plugs/esbuild/fix-extensions.js +98 -0
- package/dist/plugs/esbuild/fix-extensions.js.map +1 -0
- package/dist/plugs/esbuild.d.ts +21 -2
- package/dist/plugs/esbuild.d.ts.map +1 -0
- package/dist/plugs/esbuild.js +193 -0
- package/dist/plugs/esbuild.js.map +1 -0
- package/dist/plugs/exec.d.ts +2 -1
- package/dist/plugs/exec.d.ts.map +1 -0
- package/dist/plugs/exec.js +33 -0
- package/dist/plugs/exec.js.map +1 -0
- package/dist/plugs/exports.d.ts +1 -0
- package/dist/plugs/exports.d.ts.map +1 -0
- package/dist/plugs/exports.js +110 -0
- package/dist/plugs/exports.js.map +1 -0
- package/dist/plugs/filter.d.ts +2 -1
- package/dist/plugs/filter.d.ts.map +1 -0
- package/dist/plugs/filter.js +34 -0
- package/dist/plugs/filter.js.map +1 -0
- package/dist/plugs/rmf.d.ts +1 -0
- package/dist/plugs/rmf.d.ts.map +1 -0
- package/dist/plugs/rmf.js +24 -0
- package/dist/plugs/rmf.js.map +1 -0
- package/dist/plugs.d.ts +9 -8
- package/dist/plugs.d.ts.map +1 -0
- package/dist/plugs.js +9 -0
- package/dist/plugs.js.map +1 -0
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/ansi.d.ts +1 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +10 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/caller.d.ts +2 -1
- package/dist/utils/caller.d.ts.map +1 -0
- package/dist/utils/caller.js +33 -0
- package/dist/utils/caller.js.map +1 -0
- package/dist/utils/diff.d.ts +1 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +278 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/exec.d.ts +2 -1
- package/dist/utils/exec.d.ts.map +1 -0
- package/dist/utils/exec.js +84 -0
- package/dist/utils/exec.js.map +1 -0
- package/dist/utils/jsonc.d.ts +1 -0
- package/dist/utils/jsonc.d.ts.map +1 -0
- package/dist/utils/jsonc.js +46 -0
- package/dist/utils/jsonc.js.map +1 -0
- package/dist/utils/match.d.ts +1 -0
- package/dist/utils/match.d.ts.map +1 -0
- package/dist/utils/match.js +40 -0
- package/dist/utils/match.js.map +1 -0
- package/dist/utils/options.d.ts +1 -0
- package/dist/utils/options.d.ts.map +1 -0
- package/dist/utils/options.js +17 -0
- package/dist/utils/options.js.map +1 -0
- package/dist/utils/singleton.d.ts +1 -0
- package/dist/utils/singleton.d.ts.map +1 -0
- package/dist/utils/singleton.js +20 -0
- package/dist/utils/singleton.js.map +1 -0
- package/dist/utils/walk.d.ts +3 -2
- package/dist/utils/walk.d.ts.map +1 -0
- package/dist/utils/walk.js +84 -0
- package/dist/utils/walk.js.map +1 -0
- package/dist/utils.d.ts +9 -8
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +9 -0
- package/dist/utils.js.map +1 -0
- package/package.json +27 -87
- package/src/asserts.ts +2 -2
- package/src/async.ts +3 -3
- package/src/build.ts +10 -10
- package/src/{cli.mts → cli.ts} +27 -16
- package/src/files.ts +4 -4
- package/src/fork.ts +17 -17
- package/src/globals.ts +3 -0
- package/src/helpers.ts +20 -20
- package/src/index.ts +21 -21
- package/src/logging/colors.ts +4 -4
- package/src/logging/emit.ts +6 -6
- package/src/logging/github.ts +3 -3
- package/src/logging/logger.ts +12 -12
- package/src/logging/options.ts +10 -10
- package/src/logging/report.ts +10 -10
- package/src/logging/spinner.ts +3 -3
- package/src/logging.ts +14 -14
- package/src/paths.ts +42 -23
- package/src/pipe.ts +13 -8
- package/src/plugs/build.ts +8 -8
- package/src/plugs/copy.ts +8 -8
- package/src/plugs/debug.ts +4 -4
- package/src/plugs/edit.ts +5 -5
- package/src/plugs/esbuild/fix-extensions.ts +8 -10
- package/src/plugs/esbuild.ts +88 -27
- package/src/plugs/exec.ts +6 -6
- package/src/plugs/exports.ts +32 -35
- package/src/plugs/filter.ts +7 -7
- package/src/plugs/rmf.ts +5 -5
- package/src/plugs.ts +8 -8
- package/src/types.ts +3 -3
- package/src/utils/caller.ts +4 -4
- package/src/utils/diff.ts +2 -2
- package/src/utils/exec.ts +7 -7
- package/src/utils/jsonc.ts +1 -1
- package/src/utils/walk.ts +6 -6
- package/src/utils.ts +8 -8
- package/dist/asserts.cjs +0 -86
- package/dist/asserts.cjs.map +0 -6
- package/dist/asserts.mjs +0 -58
- package/dist/asserts.mjs.map +0 -6
- package/dist/async.cjs +0 -64
- package/dist/async.cjs.map +0 -6
- package/dist/async.mjs +0 -36
- package/dist/async.mjs.map +0 -6
- package/dist/build.cjs +0 -222
- package/dist/build.cjs.map +0 -6
- package/dist/build.mjs +0 -192
- package/dist/build.mjs.map +0 -6
- package/dist/cli.mjs +0 -258
- package/dist/cli.mjs.map +0 -6
- package/dist/files.cjs +0 -113
- package/dist/files.cjs.map +0 -6
- package/dist/files.mjs +0 -93
- package/dist/files.mjs.map +0 -6
- package/dist/fork.cjs +0 -224
- package/dist/fork.cjs.map +0 -6
- package/dist/fork.mjs +0 -198
- package/dist/fork.mjs.map +0 -6
- package/dist/fs.cjs +0 -146
- package/dist/fs.cjs.map +0 -6
- package/dist/fs.mjs +0 -82
- package/dist/fs.mjs.map +0 -6
- package/dist/globals.cjs +0 -2
- package/dist/globals.cjs.map +0 -6
- package/dist/globals.mjs +0 -1
- package/dist/globals.mjs.map +0 -6
- package/dist/helpers.cjs +0 -182
- package/dist/helpers.cjs.map +0 -6
- package/dist/helpers.mjs +0 -151
- package/dist/helpers.mjs.map +0 -6
- package/dist/index.cjs +0 -114
- package/dist/index.cjs.map +0 -6
- package/dist/index.mjs +0 -48
- package/dist/index.mjs.map +0 -6
- package/dist/logging/colors.cjs +0 -136
- package/dist/logging/colors.cjs.map +0 -6
- package/dist/logging/colors.mjs +0 -99
- package/dist/logging/colors.mjs.map +0 -6
- package/dist/logging/emit.cjs +0 -134
- package/dist/logging/emit.cjs.map +0 -6
- package/dist/logging/emit.mjs +0 -106
- package/dist/logging/emit.mjs.map +0 -6
- package/dist/logging/github.cjs +0 -60
- package/dist/logging/github.cjs.map +0 -6
- package/dist/logging/github.mjs +0 -35
- package/dist/logging/github.mjs.map +0 -6
- package/dist/logging/levels.cjs +0 -69
- package/dist/logging/levels.cjs.map +0 -6
- package/dist/logging/levels.mjs +0 -35
- package/dist/logging/levels.mjs.map +0 -6
- package/dist/logging/logger.cjs +0 -165
- package/dist/logging/logger.cjs.map +0 -6
- package/dist/logging/logger.mjs +0 -139
- package/dist/logging/logger.mjs.map +0 -6
- package/dist/logging/options.cjs +0 -192
- package/dist/logging/options.cjs.map +0 -6
- package/dist/logging/options.mjs +0 -167
- package/dist/logging/options.mjs.map +0 -6
- package/dist/logging/report.cjs +0 -298
- package/dist/logging/report.cjs.map +0 -6
- package/dist/logging/report.mjs +0 -273
- package/dist/logging/report.mjs.map +0 -6
- package/dist/logging/spinner.cjs +0 -100
- package/dist/logging/spinner.cjs.map +0 -6
- package/dist/logging/spinner.mjs +0 -72
- package/dist/logging/spinner.mjs.map +0 -6
- package/dist/logging.cjs +0 -91
- package/dist/logging.cjs.map +0 -6
- package/dist/logging.mjs +0 -58
- package/dist/logging.mjs.map +0 -6
- package/dist/paths.cjs +0 -170
- package/dist/paths.cjs.map +0 -6
- package/dist/paths.mjs +0 -132
- package/dist/paths.mjs.map +0 -6
- package/dist/pipe.cjs +0 -163
- package/dist/pipe.cjs.map +0 -6
- package/dist/pipe.mjs +0 -135
- package/dist/pipe.mjs.map +0 -6
- package/dist/plugs/build.cjs +0 -73
- package/dist/plugs/build.cjs.map +0 -6
- package/dist/plugs/build.mjs +0 -47
- package/dist/plugs/build.mjs.map +0 -6
- package/dist/plugs/copy.cjs +0 -86
- package/dist/plugs/copy.cjs.map +0 -6
- package/dist/plugs/copy.mjs +0 -69
- package/dist/plugs/copy.mjs.map +0 -6
- package/dist/plugs/debug.cjs +0 -24
- package/dist/plugs/debug.cjs.map +0 -6
- package/dist/plugs/debug.mjs +0 -22
- package/dist/plugs/debug.mjs.map +0 -6
- package/dist/plugs/edit.cjs +0 -20
- package/dist/plugs/edit.cjs.map +0 -6
- package/dist/plugs/edit.mjs +0 -18
- package/dist/plugs/edit.mjs.map +0 -6
- package/dist/plugs/esbuild/bundle-locals.cjs +0 -48
- package/dist/plugs/esbuild/bundle-locals.cjs.map +0 -6
- package/dist/plugs/esbuild/bundle-locals.mjs +0 -23
- package/dist/plugs/esbuild/bundle-locals.mjs.map +0 -6
- package/dist/plugs/esbuild/fix-extensions.cjs +0 -89
- package/dist/plugs/esbuild/fix-extensions.cjs.map +0 -6
- package/dist/plugs/esbuild/fix-extensions.mjs +0 -54
- package/dist/plugs/esbuild/fix-extensions.mjs.map +0 -6
- package/dist/plugs/esbuild.cjs +0 -139
- package/dist/plugs/esbuild.cjs.map +0 -6
- package/dist/plugs/esbuild.mjs +0 -116
- package/dist/plugs/esbuild.mjs.map +0 -6
- package/dist/plugs/exec.cjs +0 -42
- package/dist/plugs/exec.cjs.map +0 -6
- package/dist/plugs/exec.mjs +0 -25
- package/dist/plugs/exec.mjs.map +0 -6
- package/dist/plugs/exports.cjs +0 -117
- package/dist/plugs/exports.cjs.map +0 -6
- package/dist/plugs/exports.mjs +0 -100
- package/dist/plugs/exports.mjs.map +0 -6
- package/dist/plugs/filter.cjs +0 -47
- package/dist/plugs/filter.cjs.map +0 -6
- package/dist/plugs/filter.mjs +0 -30
- package/dist/plugs/filter.mjs.map +0 -6
- package/dist/plugs/rmf.cjs +0 -25
- package/dist/plugs/rmf.cjs.map +0 -6
- package/dist/plugs/rmf.mjs +0 -23
- package/dist/plugs/rmf.mjs.map +0 -6
- package/dist/plugs.cjs +0 -39
- package/dist/plugs.cjs.map +0 -6
- package/dist/plugs.mjs +0 -10
- package/dist/plugs.mjs.map +0 -6
- package/dist/types.cjs +0 -19
- package/dist/types.cjs.map +0 -6
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +0 -6
- package/dist/utils/ansi.cjs +0 -39
- package/dist/utils/ansi.cjs.map +0 -6
- package/dist/utils/ansi.mjs +0 -13
- package/dist/utils/ansi.mjs.map +0 -6
- package/dist/utils/caller.cjs +0 -57
- package/dist/utils/caller.cjs.map +0 -6
- package/dist/utils/caller.mjs +0 -32
- package/dist/utils/caller.mjs.map +0 -6
- package/dist/utils/diff.cjs +0 -282
- package/dist/utils/diff.cjs.map +0 -6
- package/dist/utils/diff.mjs +0 -256
- package/dist/utils/diff.mjs.map +0 -6
- package/dist/utils/exec.cjs +0 -113
- package/dist/utils/exec.cjs.map +0 -6
- package/dist/utils/exec.mjs +0 -78
- package/dist/utils/exec.mjs.map +0 -6
- package/dist/utils/jsonc.cjs +0 -74
- package/dist/utils/jsonc.cjs.map +0 -6
- package/dist/utils/jsonc.mjs +0 -48
- package/dist/utils/jsonc.mjs.map +0 -6
- package/dist/utils/match.cjs +0 -74
- package/dist/utils/match.cjs.map +0 -6
- package/dist/utils/match.mjs +0 -39
- package/dist/utils/match.mjs.map +0 -6
- package/dist/utils/options.cjs +0 -39
- package/dist/utils/options.cjs.map +0 -6
- package/dist/utils/options.mjs +0 -14
- package/dist/utils/options.mjs.map +0 -6
- package/dist/utils/singleton.cjs +0 -37
- package/dist/utils/singleton.cjs.map +0 -6
- package/dist/utils/singleton.mjs +0 -12
- package/dist/utils/singleton.mjs.map +0 -6
- package/dist/utils/walk.cjs +0 -98
- package/dist/utils/walk.cjs.map +0 -6
- package/dist/utils/walk.mjs +0 -73
- package/dist/utils/walk.mjs.map +0 -6
- package/dist/utils.cjs +0 -39
- package/dist/utils.cjs.map +0 -6
- package/dist/utils.mjs +0 -10
- package/dist/utils.mjs.map +0 -6
package/src/logging/colors.ts
CHANGED
|
@@ -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
|
|
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
|
|
package/src/logging/emit.ts
CHANGED
|
@@ -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
|
|
package/src/logging/github.ts
CHANGED
|
@@ -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
|
package/src/logging/logger.ts
CHANGED
|
@@ -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
|
/* ========================================================================== */
|
package/src/logging/options.ts
CHANGED
|
@@ -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
|
|
80
|
-
this._level = getLevelNumber(process.env
|
|
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
|
|
85
|
-
if (process.env
|
|
86
|
-
if (process.env
|
|
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
|
|
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
|
|
103
|
+
const options = JSON.parse(process.env['__LOG_OPTIONS'] || '{}')
|
|
104
104
|
Object.assign(this, options)
|
|
105
105
|
}
|
|
106
106
|
|
package/src/logging/report.ts
CHANGED
|
@@ -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
|
package/src/logging/spinner.ts
CHANGED
|
@@ -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
|
-
|
|
113
|
-
|
|
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
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
135
|
-
* `
|
|
136
|
-
*
|
|
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
|
|
139
|
-
*
|
|
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
|
-
*
|
|
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(
|
|
148
|
-
const file = resolveFilename(
|
|
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 `
|
|
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(
|
|
168
|
-
const file = resolveFilename(
|
|
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
|
*
|
package/src/plugs/build.ts
CHANGED
|
@@ -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(
|
|
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 {
|
package/src/plugs/debug.ts
CHANGED
|
@@ -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"
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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]?
|
|
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')
|
package/src/plugs/esbuild.ts
CHANGED
|
@@ -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
|
-
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
62
|
+
class ESBuild implements Plug<Files> {
|
|
54
63
|
constructor(...args: PipeParameters<'esbuild'>)
|
|
55
|
-
constructor(
|
|
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
|
|
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)
|