@jsenv/core 23.2.2 → 23.3.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 (34) hide show
  1. package/{license → LICENSE} +0 -0
  2. package/package.json +13 -14
  3. package/src/buildProject.js +12 -13
  4. package/src/execute.js +92 -93
  5. package/src/internal/browser-launcher/executeHtmlFile.js +6 -7
  6. package/src/internal/building/buildUsingRollup.js +3 -4
  7. package/src/internal/building/build_logs.js +7 -6
  8. package/src/internal/building/createJsenvRollupPlugin.js +9 -14
  9. package/src/internal/building/url_trace.js +3 -4
  10. package/src/internal/compiling/createCompiledFileService.js +8 -5
  11. package/src/internal/compiling/startCompileServer.js +55 -46
  12. package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +2 -3
  13. package/src/internal/executing/createSummaryLog.js +12 -14
  14. package/src/internal/executing/executeConcurrently.js +7 -5
  15. package/src/internal/executing/executePlan.js +80 -80
  16. package/src/internal/executing/executionLogs.js +14 -18
  17. package/src/internal/executing/execution_colors.js +6 -12
  18. package/src/internal/executing/launchAndExecute.js +125 -145
  19. package/src/internal/node-launcher/createControllableNodeProcess.js +26 -23
  20. package/src/launchBrowser.js +64 -61
  21. package/src/launchNode.js +6 -6
  22. package/src/startExploring.js +2 -17
  23. package/src/abort/abortable.js +0 -172
  24. package/src/abort/callback_list.js +0 -64
  25. package/src/abort/callback_race.js +0 -34
  26. package/src/abort/cleaner.js +0 -22
  27. package/src/abort/main.js +0 -32
  28. package/src/abort/process_teardown_events.js +0 -59
  29. package/src/internal/createCallbackList.js +0 -21
  30. package/src/internal/executing/logUtils.js +0 -30
  31. package/src/internal/executing/writeLog.js +0 -106
  32. package/src/internal/executing/writeLog.test-manual.js +0 -62
  33. package/src/internal/logs/log_style.js +0 -40
  34. package/src/signal/signal.js +0 -65
@@ -1,59 +0,0 @@
1
- import { raceCallbacks } from "./callback_race.js"
2
-
3
- export const raceProcessTeardownEvents = (processTeardownEvents, callback) => {
4
- return raceCallbacks(
5
- {
6
- ...(processTeardownEvents.SIGHUP ? SIGHUP_CALLBACK : {}),
7
- ...(processTeardownEvents.SIGTERM ? SIGTERM_CALLBACK : {}),
8
- ...(processTeardownEvents.SIGINT ? SIGINT_CALLBACK : {}),
9
- ...(processTeardownEvents.beforeExit ? BEFORE_EXIT_CALLBACK : {}),
10
- ...(processTeardownEvents.exit ? EXIT_CALLBACK : {}),
11
- },
12
- callback,
13
- )
14
- }
15
-
16
- const SIGHUP_CALLBACK = {
17
- SIGHUP: (cb) => {
18
- process.on("SIGHUP", cb)
19
- return () => {
20
- process.removeListener("SIGHUP", cb)
21
- }
22
- },
23
- }
24
-
25
- const SIGTERM_CALLBACK = {
26
- SIGTERM: (cb) => {
27
- process.on("SIGTERM", cb)
28
- return () => {
29
- process.removeListener("SIGTERM", cb)
30
- }
31
- },
32
- }
33
-
34
- const BEFORE_EXIT_CALLBACK = {
35
- beforeExit: (cb) => {
36
- process.on("beforeExit", cb)
37
- return () => {
38
- process.removeListener("beforeExit", cb)
39
- }
40
- },
41
- }
42
-
43
- const EXIT_CALLBACK = {
44
- exit: (cb) => {
45
- process.on("exit", cb)
46
- return () => {
47
- process.removeListener("exit", cb)
48
- }
49
- },
50
- }
51
-
52
- const SIGINT_CALLBACK = {
53
- SIGINT: (cb) => {
54
- process.on("SIGINT", cb)
55
- return () => {
56
- process.removeListener("SIGINT", cb)
57
- }
58
- },
59
- }
@@ -1,21 +0,0 @@
1
- export const createCallbackList = () => {
2
- const callbackSet = new Set()
3
-
4
- const register = (callback) => {
5
- callbackSet.add(callback)
6
- return () => {
7
- callbackSet.delete(callback)
8
- }
9
- }
10
-
11
- const notify = (...args) => {
12
- callbackSet.forEach((callback) => {
13
- callback(...args)
14
- })
15
- }
16
-
17
- return {
18
- register,
19
- notify,
20
- }
21
- }
@@ -1,30 +0,0 @@
1
- // https://github.com/yarnpkg/yarn/blob/master/src/reporters/console/util.js
2
- // https://github.com/yarnpkg/yarn/blob/master/src/reporters/console/progress-bar.js
3
- // https://github.com/sindresorhus/log-update/blob/master/index.js
4
- // see https://github.com/jsenv/jsenv-core/issues/59
5
- import readline from "node:readline"
6
- import tty from "node:tty"
7
-
8
- import { createSupportsColor } from "supports-color"
9
-
10
- const CLEAR_WHOLE_LINE = 0
11
-
12
- export const clearLine = (stdout = process.stdout) => {
13
- if (createSupportsColor(stdout)) {
14
- readline.clearLine(stdout, CLEAR_WHOLE_LINE)
15
- readline.cursorTo(stdout, 0)
16
- } else if (stdout instanceof tty.WriteStream) {
17
- if (stdout.columns > 0) {
18
- stdout.write(`\r${" ".repeat(stdout.columns - 1)}`)
19
- }
20
- stdout.write(`\r`)
21
- }
22
- }
23
-
24
- export const toStartOfLine = (stdout = process.stdout) => {
25
- if (createSupportsColor(stdout)) {
26
- readline.cursorTo(stdout, 0)
27
- } else {
28
- stdout.write("\r")
29
- }
30
- }
@@ -1,106 +0,0 @@
1
- import readline from "readline"
2
-
3
- import stringWidth from "string-width"
4
- import { memoize } from "@jsenv/filesystem"
5
-
6
- export const writeLog = (
7
- string,
8
- { mightUpdate = true, stream = process.stdout } = {},
9
- ) => {
10
- string = `${string}
11
- `
12
- stream.write(string)
13
-
14
- const moveCursorToLineAbove = () => {
15
- readline.moveCursor(stream, 0, -1)
16
- }
17
-
18
- const clearCursorLine = () => {
19
- readline.clearLine(stream, 0)
20
- }
21
-
22
- const remove = memoize(() => {
23
- const { columns = 80, rows = 24 } = stream
24
- const logLines = string.split(/\r\n|\r|\n/)
25
- let visualLineCount = 0
26
- logLines.forEach((logLine) => {
27
- const width = stringWidth(logLine)
28
- visualLineCount += width === 0 ? 1 : Math.ceil(width / columns)
29
- })
30
-
31
- if (visualLineCount > rows) {
32
- // the whole log cannot be cleared because it's vertically to long
33
- // (longer than terminal height)
34
- // readline.moveCursor cannot move cursor higher than screen height
35
- // it means we would only clear the visible part of the log
36
- // better keep the log untouched
37
- return
38
- }
39
-
40
- while (visualLineCount--) {
41
- clearCursorLine()
42
- if (visualLineCount > 0) {
43
- moveCursorToLineAbove()
44
- }
45
- }
46
- // an other version of the while above could the code below
47
- // readline.moveCursor(stream, 0, -visualLineCount)
48
- // readline.clearScreenDown(stream)
49
- })
50
-
51
- if (mightUpdate) {
52
- const consoleModified = spyConsoleModification()
53
-
54
- let updated = false
55
- const update = (newString) => {
56
- if (updated) {
57
- console.warn(`cannot update twice`)
58
- return null
59
- }
60
- updated = true
61
-
62
- if (!consoleModified()) {
63
- remove()
64
- }
65
- return writeLog(newString, { stream })
66
- }
67
-
68
- return { remove, update }
69
- }
70
-
71
- return {
72
- remove,
73
- update: null,
74
- }
75
- }
76
-
77
- // maybe https://github.com/gajus/output-interceptor/tree/v3.0.0 ?
78
- // the problem with listening data on stdout
79
- // is that node.js will later throw error if stream gets closed
80
- // while something listening data on it
81
- const spyConsoleModification = () => {
82
- const { stdout, stderr } = process
83
- const originalStdoutWrite = stdout.write
84
- const originalStdErrWrite = stderr.write
85
-
86
- let modified = false
87
-
88
- stdout.write = function (...args /* chunk, encoding, callback */) {
89
- modified = true
90
- return originalStdoutWrite.call(stdout, ...args)
91
- }
92
- stderr.write = function (...args) {
93
- modified = true
94
- return originalStdErrWrite.call(stderr, ...args)
95
- }
96
-
97
- const uninstall = () => {
98
- stdout.write = originalStdoutWrite
99
- stderr.write = originalStdErrWrite
100
- }
101
-
102
- return () => {
103
- uninstall()
104
- return modified
105
- }
106
- }
@@ -1,62 +0,0 @@
1
- import { assert } from "@jsenv/assert"
2
- import { writeLog } from "./writeLog.js"
3
-
4
- {
5
- const first = writeLog(`1
6
- 2
7
- 3
8
- 4
9
- 5
10
- 6
11
- 7
12
- 8
13
- 9
14
- 10
15
- 11
16
- 12
17
- 13
18
- 14
19
- 15
20
- 16
21
- 17
22
- 18`)
23
- const second = first.update(`a
24
- b
25
- c
26
- d
27
- e
28
- f
29
- g`)
30
- second.update(`alpha
31
- beta
32
- gamma`)
33
- // must be verfied by human eyes
34
- // depending on terminal height
35
- // either the whole log can be rewritten (updated)
36
- // or it will be kept and second log appended at the bottom
37
- }
38
-
39
- {
40
- const hello = writeLog(`hello
41
- foo`)
42
- hello.update(`hello
43
- bar`)
44
-
45
- const expected = `hello
46
- bar`
47
- const actual = expected // must be verified by human eyes
48
- assert({ actual, expected })
49
- }
50
-
51
- {
52
- const hello = writeLog("hello")
53
- console.log("hey")
54
- const world = hello.update("world")
55
- world.update("!")
56
-
57
- const expected = `hello
58
- hey
59
- !`
60
- const actual = expected // must be verified by human eyes
61
- assert({ actual, expected })
62
- }
@@ -1,40 +0,0 @@
1
- import isUnicodeSupported from "is-unicode-supported"
2
- import { createSupportsColor } from "supports-color"
3
-
4
- const canUseUnicode = isUnicodeSupported()
5
- const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic
6
- let canUseColors = processSupportsBasicColor
7
-
8
- // GitHub workflow does support ANSI but "supports-color" returns false
9
- // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
10
- if (process.env.GITHUB_WORKFLOW) {
11
- // Check on FORCE_COLOR is to ensure it is prio over GitHub workflow check
12
- if (process.env.FORCE_COLOR !== "false") {
13
- // in unit test we use process.env.FORCE_COLOR = 'false' to fake
14
- // that colors are not supported. Let it have priority
15
- canUseColors = true
16
- }
17
- }
18
-
19
- // https://github.com/Marak/colors.js/blob/master/lib/styles.js
20
- export const ANSI_RED = "\x1b[31m"
21
- export const ANSI_GREEN = "\x1b[32m"
22
- export const ANSI_YELLOW = "\x1b[33m"
23
- export const ANSI_BLUE = "\x1b[34m"
24
- export const ANSI_MAGENTA = "\x1b[35m"
25
- export const ANSI_GREY = "\x1b[90m"
26
- export const ANSI_RESET = "\x1b[0m"
27
-
28
- export const setANSIColor = canUseColors
29
- ? (text, ANSI_COLOR) => `${ANSI_COLOR}${text}${ANSI_RESET}`
30
- : (text) => text
31
-
32
- export const commandSignColorLess = canUseUnicode ? `❯` : `>`
33
- export const okSignColorLess = canUseUnicode ? `✔` : `√`
34
- export const failureSignColorLess = canUseUnicode ? `✖` : `×`
35
-
36
- export const commandSign = setANSIColor(commandSignColorLess, ANSI_GREY) // ANSI_MAGENTA)
37
- export const okSign = setANSIColor(okSignColorLess, ANSI_GREEN)
38
- export const failureSign = setANSIColor(failureSignColorLess, ANSI_RED)
39
- export const infoSign = setANSIColor(canUseUnicode ? `ℹ` : `i`, ANSI_BLUE)
40
- export const warningSign = setANSIColor(canUseUnicode ? `⚠` : `‼`, ANSI_YELLOW)
@@ -1,65 +0,0 @@
1
- export const createSignal = ({ once = false } = {}) => {
2
- let callbacks = []
3
-
4
- const signal = {}
5
-
6
- const addCallback = (callback) => {
7
- if (typeof callback !== "function") {
8
- throw new Error(`callback must be a function, got ${callback}`)
9
- }
10
-
11
- // don't register twice
12
- const existingCallback = callbacks.find((callbackCandidate) => {
13
- return callbackCandidate === callback
14
- })
15
- if (existingCallback) {
16
- if (typeof process.emitWarning === "object") {
17
- process.emitWarning(`Trying to register same callback twice`, {
18
- CODE: "CALLBACK_DUPLICATION",
19
- detail: `It's often the sign that code is executd more than once`,
20
- })
21
- } else {
22
- console.warn(`Trying to add same callback twice`)
23
- }
24
- } else {
25
- callbacks = [...callbacks, callback]
26
- }
27
-
28
- return () => {
29
- callbacks = arrayWithout(callbacks, callback)
30
- }
31
- }
32
-
33
- const emit = (value) => {
34
- signal.emitted = true
35
-
36
- const callbacksCopy = callbacks.slice()
37
- if (once) {
38
- callbacks.length = 0
39
- }
40
- callbacksCopy.forEach((callback) => {
41
- callback(value)
42
- })
43
- }
44
-
45
- signal.emitted = false
46
- signal.addCallback = addCallback
47
- signal.emit = emit
48
-
49
- return signal
50
- }
51
-
52
- const arrayWithout = (array, item) => {
53
- if (array.length === 0) return array
54
- const arrayWithoutItem = []
55
- let i = 0
56
- while (i < array.length) {
57
- const value = array[i]
58
- i++
59
- if (value === item) {
60
- continue
61
- }
62
- arrayWithoutItem.push(value)
63
- }
64
- return arrayWithoutItem
65
- }