@tapjs/processinfo 1.0.12 → 2.0.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 (166) hide show
  1. package/README.md +20 -11
  2. package/dist/cjs/argv-to-node-options.d.ts +2 -0
  3. package/dist/cjs/argv-to-node-options.d.ts.map +1 -0
  4. package/dist/cjs/argv-to-node-options.js +6 -0
  5. package/dist/cjs/argv-to-node-options.js.map +1 -0
  6. package/dist/cjs/child_process.d.ts +205 -0
  7. package/dist/cjs/child_process.d.ts.map +1 -0
  8. package/dist/cjs/child_process.js +109 -0
  9. package/dist/cjs/child_process.js.map +1 -0
  10. package/dist/cjs/cjs.d.ts +2 -0
  11. package/dist/cjs/cjs.d.ts.map +1 -0
  12. package/dist/cjs/cjs.js +5 -0
  13. package/dist/cjs/cjs.js.map +1 -0
  14. package/dist/cjs/get-exclude.d.ts +3 -0
  15. package/dist/cjs/get-exclude.d.ts.map +1 -0
  16. package/dist/cjs/get-exclude.js +23 -0
  17. package/dist/cjs/get-exclude.js.map +1 -0
  18. package/dist/cjs/get-process-info.d.ts +25 -0
  19. package/dist/cjs/get-process-info.d.ts.map +1 -0
  20. package/dist/cjs/get-process-info.js +69 -0
  21. package/dist/cjs/get-process-info.js.map +1 -0
  22. package/dist/cjs/index.d.ts +44 -0
  23. package/dist/cjs/index.d.ts.map +1 -0
  24. package/dist/cjs/index.js +148 -0
  25. package/dist/cjs/index.js.map +1 -0
  26. package/dist/cjs/json-file.d.ts +3 -0
  27. package/dist/cjs/json-file.d.ts.map +1 -0
  28. package/dist/cjs/json-file.js +20 -0
  29. package/dist/cjs/json-file.js.map +1 -0
  30. package/dist/cjs/loader-paths.d.ts +5 -0
  31. package/dist/cjs/loader-paths.d.ts.map +1 -0
  32. package/dist/cjs/loader-paths.js +35 -0
  33. package/dist/cjs/loader-paths.js.map +1 -0
  34. package/dist/cjs/node-options-env.d.ts +6 -0
  35. package/dist/cjs/node-options-env.d.ts.map +1 -0
  36. package/dist/cjs/node-options-env.js +58 -0
  37. package/dist/cjs/node-options-env.js.map +1 -0
  38. package/dist/cjs/node-options-to-argv.d.ts +2 -0
  39. package/dist/cjs/node-options-to-argv.d.ts.map +1 -0
  40. package/dist/cjs/node-options-to-argv.js +58 -0
  41. package/dist/cjs/node-options-to-argv.js.map +1 -0
  42. package/dist/cjs/package.json +3 -0
  43. package/dist/cjs/process-info-node.d.ts +24 -0
  44. package/dist/cjs/process-info-node.d.ts.map +1 -0
  45. package/dist/cjs/process-info-node.js +100 -0
  46. package/dist/cjs/process-info-node.js.map +1 -0
  47. package/dist/cjs/register-cjs.d.ts +2 -0
  48. package/dist/cjs/register-cjs.d.ts.map +1 -0
  49. package/dist/cjs/register-cjs.js +21 -0
  50. package/dist/cjs/register-cjs.js.map +1 -0
  51. package/dist/cjs/register-coverage.d.ts +7 -0
  52. package/dist/cjs/register-coverage.d.ts.map +1 -0
  53. package/dist/cjs/register-coverage.js +94 -0
  54. package/dist/cjs/register-coverage.js.map +1 -0
  55. package/dist/cjs/register-env.d.ts +2 -0
  56. package/dist/cjs/register-env.d.ts.map +1 -0
  57. package/dist/cjs/register-env.js +26 -0
  58. package/dist/cjs/register-env.js.map +1 -0
  59. package/dist/cjs/register-process-end.d.ts +2 -0
  60. package/dist/cjs/register-process-end.d.ts.map +1 -0
  61. package/dist/cjs/register-process-end.js +30 -0
  62. package/dist/cjs/register-process-end.js.map +1 -0
  63. package/dist/cjs/require-resolve-cjs.d.ts.map +1 -0
  64. package/dist/cjs/require-resolve-cjs.js.map +1 -0
  65. package/dist/cjs/require-resolve.d.ts +3 -0
  66. package/dist/cjs/require-resolve.js +9 -0
  67. package/dist/cjs/spawn-opts.d.ts +10 -0
  68. package/dist/cjs/spawn-opts.d.ts.map +1 -0
  69. package/dist/cjs/spawn-opts.js +18 -0
  70. package/dist/cjs/spawn-opts.js.map +1 -0
  71. package/dist/cjs/x.d.ts +2 -0
  72. package/dist/cjs/x.d.ts.map +1 -0
  73. package/dist/cjs/x.js +5 -0
  74. package/dist/cjs/x.js.map +1 -0
  75. package/dist/mjs/argv-to-node-options.d.ts +2 -0
  76. package/dist/mjs/argv-to-node-options.d.ts.map +1 -0
  77. package/dist/mjs/argv-to-node-options.js +2 -0
  78. package/dist/mjs/argv-to-node-options.js.map +1 -0
  79. package/dist/mjs/child_process.d.ts +205 -0
  80. package/dist/mjs/child_process.d.ts.map +1 -0
  81. package/dist/mjs/child_process.js +99 -0
  82. package/dist/mjs/child_process.js.map +1 -0
  83. package/dist/mjs/esm.d.mts +11 -0
  84. package/dist/mjs/esm.d.mts.map +1 -0
  85. package/dist/mjs/esm.mjs +45 -0
  86. package/dist/mjs/esm.mjs.map +1 -0
  87. package/dist/mjs/get-exclude.d.ts +3 -0
  88. package/dist/mjs/get-exclude.d.ts.map +1 -0
  89. package/dist/mjs/get-exclude.js +19 -0
  90. package/dist/mjs/get-exclude.js.map +1 -0
  91. package/dist/mjs/get-process-info.d.ts +25 -0
  92. package/dist/mjs/get-process-info.d.ts.map +1 -0
  93. package/dist/mjs/get-process-info.js +64 -0
  94. package/dist/mjs/get-process-info.js.map +1 -0
  95. package/dist/mjs/index.d.ts +44 -0
  96. package/dist/mjs/index.d.ts.map +1 -0
  97. package/dist/mjs/index.js +130 -0
  98. package/dist/mjs/index.js.map +1 -0
  99. package/dist/mjs/json-file.d.ts +3 -0
  100. package/dist/mjs/json-file.d.ts.map +1 -0
  101. package/dist/mjs/json-file.js +15 -0
  102. package/dist/mjs/json-file.js.map +1 -0
  103. package/dist/mjs/loader-paths.d.ts +5 -0
  104. package/dist/mjs/loader-paths.d.ts.map +1 -0
  105. package/dist/mjs/loader-paths.js +30 -0
  106. package/dist/mjs/loader-paths.js.map +1 -0
  107. package/dist/mjs/node-options-env.d.ts +6 -0
  108. package/dist/mjs/node-options-env.d.ts.map +1 -0
  109. package/dist/mjs/node-options-env.js +54 -0
  110. package/dist/mjs/node-options-env.js.map +1 -0
  111. package/dist/mjs/node-options-to-argv.d.ts +2 -0
  112. package/dist/mjs/node-options-to-argv.d.ts.map +1 -0
  113. package/dist/mjs/node-options-to-argv.js +54 -0
  114. package/dist/mjs/node-options-to-argv.js.map +1 -0
  115. package/dist/mjs/package.json +3 -0
  116. package/dist/mjs/process-info-node.d.ts +24 -0
  117. package/dist/mjs/process-info-node.d.ts.map +1 -0
  118. package/dist/mjs/process-info-node.js +96 -0
  119. package/dist/mjs/process-info-node.js.map +1 -0
  120. package/dist/mjs/register-cjs.d.ts +2 -0
  121. package/dist/mjs/register-cjs.d.ts.map +1 -0
  122. package/dist/mjs/register-cjs.js +17 -0
  123. package/dist/mjs/register-cjs.js.map +1 -0
  124. package/dist/mjs/register-coverage.d.ts +7 -0
  125. package/dist/mjs/register-coverage.d.ts.map +1 -0
  126. package/dist/mjs/register-coverage.js +89 -0
  127. package/dist/mjs/register-coverage.js.map +1 -0
  128. package/dist/mjs/register-env.d.ts +2 -0
  129. package/dist/mjs/register-env.d.ts.map +1 -0
  130. package/dist/mjs/register-env.js +19 -0
  131. package/dist/mjs/register-env.js.map +1 -0
  132. package/dist/mjs/register-process-end.d.ts +2 -0
  133. package/dist/mjs/register-process-end.d.ts.map +1 -0
  134. package/dist/mjs/register-process-end.js +26 -0
  135. package/dist/mjs/register-process-end.js.map +1 -0
  136. package/dist/mjs/require-resolve.d.ts +3 -0
  137. package/dist/mjs/require-resolve.d.ts.map +1 -0
  138. package/dist/mjs/require-resolve.js +9 -0
  139. package/dist/mjs/require-resolve.js.map +1 -0
  140. package/dist/mjs/spawn-opts.d.ts +10 -0
  141. package/dist/mjs/spawn-opts.d.ts.map +1 -0
  142. package/dist/mjs/spawn-opts.js +14 -0
  143. package/dist/mjs/spawn-opts.js.map +1 -0
  144. package/dist/mjs/x.d.ts +2 -0
  145. package/dist/mjs/x.d.ts.map +1 -0
  146. package/dist/mjs/x.js +2 -0
  147. package/dist/mjs/x.js.map +1 -0
  148. package/package.json +49 -19
  149. package/index.d.ts +0 -208
  150. package/lib/argv-to-node-options.cjs +0 -2
  151. package/lib/child_process.cjs +0 -81
  152. package/lib/cjs.cjs +0 -16
  153. package/lib/esm.mjs +0 -74
  154. package/lib/get-exclude.cjs +0 -21
  155. package/lib/get-process-info.cjs +0 -45
  156. package/lib/index.cjs +0 -163
  157. package/lib/index.d.cts +0 -208
  158. package/lib/index.d.ts +0 -208
  159. package/lib/json-file.cjs +0 -19
  160. package/lib/node-options-env.cjs +0 -100
  161. package/lib/node-options-to-argv.cjs +0 -52
  162. package/lib/process-info-node.cjs +0 -84
  163. package/lib/register-coverage.cjs +0 -74
  164. package/lib/register-env.cjs +0 -21
  165. package/lib/register-process-end.cjs +0 -29
  166. package/lib/spawn-opts.cjs +0 -16
package/lib/index.d.ts DELETED
@@ -1,208 +0,0 @@
1
- /// <reference types="node" />
2
- import {
3
- ChildProcess,
4
- ExecException,
5
- ExecFileOptions,
6
- ExecFileSyncOptions,
7
- ExecOptions,
8
- ExecSyncOptions,
9
- SpawnOptions,
10
- SpawnSyncOptions,
11
- SpawnSyncReturns,
12
- } from 'node:child_process'
13
-
14
- declare interface ProcessInfoOptions {
15
- dir?: string
16
- exclude?: RegExp
17
- }
18
-
19
- declare class ProcessInfoNode {
20
- parent: ProcessInfoNode | null
21
- root: ProcessInfoNode | null
22
- children: ProcessInfoNode[] | null
23
- files: string[] | null
24
- externalID?: string | null
25
- uuid: string
26
- date: string
27
- argv: string[]
28
- execArgv: string[]
29
- pid: number
30
- ppid: number
31
- cwd: string
32
- code?: number | null
33
- signal: string | null
34
- runtime: number
35
- link(db: ProcessInfo): void
36
- NODE_OPTIONS?: string | null
37
- }
38
-
39
- declare interface ProcessInfoSpawnOptions extends SpawnOptions {
40
- externalID?: string
41
- }
42
-
43
- declare interface ProcessInfoSpawnSyncOptions extends SpawnSyncOptions {
44
- externalID?: string
45
- }
46
- declare interface ProcessInfoSpawnSyncOptionsWithStringEncoding
47
- extends ProcessInfoSpawnSyncOptions {
48
- encoding: BufferEncoding
49
- }
50
- interface ProcessInfoSpawnSyncOptionsWithBufferEncoding
51
- extends ProcessInfoSpawnSyncOptions {
52
- encoding?: 'buffer' | null | undefined
53
- }
54
-
55
- declare interface ProcessInfoExecSyncOptions extends ExecSyncOptions {
56
- externalID?: string
57
- }
58
- declare interface ProcessInfoExecSyncOptionsWithStringEncoding
59
- extends ProcessInfoExecSyncOptions {
60
- encoding: BufferEncoding
61
- }
62
- declare interface ProcessInfoExecSyncOptionsWithBufferEncoding
63
- extends ProcessInfoExecSyncOptions {
64
- encoding?: 'buffer' | null | undefined
65
- }
66
-
67
- declare interface ProcessInfoExecOptions extends ExecOptions {
68
- externalID?: string
69
- }
70
- declare interface ProcessInfoExecFileSyncOptions extends ExecFileSyncOptions {
71
- externalID?: string
72
- }
73
- declare interface ProcessInfoExecFileSyncOptionsWithStringEncoding
74
- extends ProcessInfoExecFileSyncOptions {
75
- encoding: BufferEncoding
76
- }
77
- declare interface ProcessInfoExecFileSyncOptionsWithBufferEncoding
78
- extends ProcessInfoExecFileSyncOptions {
79
- encoding?: 'buffer' | null | undefined
80
- }
81
- declare interface ProcessInfoExecFileOptions extends ExecFileOptions {
82
- externalID?: string
83
- }
84
-
85
- declare class ProcessInfo {
86
- public dir: string
87
- public exclude: RegExp
88
- public roots: Set<ProcessInfoNode>
89
- public files: Map<string, Set<ProcessInfoNode>>
90
- public uuids: Map<string, ProcessInfoNode>
91
- public externalIDs: Map<string, ProcessInfoNode>
92
-
93
- private pendingRoot: Map<string, ProcessInfoNode>
94
- private pendingParent: Map<string, ProcessInfoNode>
95
-
96
- constructor(options?: ProcessInfoOptions)
97
-
98
- save(): Promise<void>
99
- saveSync(): void
100
- erase(): Promise<void>
101
- eraseSync(): void
102
-
103
- load(): Promise<ProcessInfo>
104
- loadSync(): ProcessInfo
105
-
106
- static get Node(): typeof ProcessInfoNode
107
- static get ProcessInfo(): typeof ProcessInfo
108
-
109
- static spawn(
110
- cmd: string,
111
- args: string[],
112
- options: ProcessInfoSpawnOptions
113
- ): ChildProcess
114
-
115
- static spawnSync(cmd: string): SpawnSyncReturns<Buffer>
116
- static spawnSync(
117
- cmd: string,
118
- options: ProcessInfoSpawnSyncOptionsWithStringEncoding
119
- ): SpawnSyncReturns<string>
120
- static spawnSync(
121
- cmd: string,
122
- options: ProcessInfoSpawnSyncOptionsWithBufferEncoding
123
- ): SpawnSyncReturns<Buffer>
124
- static spawnSync(
125
- cmd: string,
126
- options?: ProcessInfoSpawnSyncOptions
127
- ): SpawnSyncReturns<string | Buffer>
128
- static spawnSync(
129
- cmd: string,
130
- args: readonly string[]
131
- ): SpawnSyncReturns<Buffer>
132
- static spawnSync(
133
- cmd: string,
134
- args: readonly string[],
135
- options: ProcessInfoSpawnSyncOptionsWithStringEncoding
136
- ): SpawnSyncReturns<string>
137
- static spawnSync(
138
- cmd: string,
139
- args: readonly string[],
140
- options: ProcessInfoSpawnSyncOptionsWithBufferEncoding
141
- ): SpawnSyncReturns<Buffer>
142
- static spawnSync(
143
- cmd: string,
144
- args?: readonly string[],
145
- options?: ProcessInfoSpawnSyncOptions
146
- ): SpawnSyncReturns<string | Buffer>
147
-
148
- static exec(
149
- cmd: string,
150
- options: ProcessInfoExecOptions,
151
- callback?: (
152
- error: ExecException | null,
153
- stdout: Buffer,
154
- stderr: Buffer
155
- ) => void
156
- ): ChildProcess
157
-
158
- static execSync(
159
- cmd: string,
160
- options: ProcessInfoExecSyncOptionsWithStringEncoding
161
- ): string
162
- static execSync(
163
- cmd: string,
164
- options: ProcessInfoExecSyncOptionsWithBufferEncoding
165
- ): Buffer
166
- static execSync(
167
- cmd: string,
168
- options?: ProcessInfoExecSyncOptions
169
- ): string | Buffer
170
-
171
- static execFile(
172
- cmd: string,
173
- args: string[],
174
- options: ProcessInfoExecFileOptions
175
- ): ChildProcess
176
-
177
- static execFileSync(file: string): Buffer
178
- static execFileSync(
179
- file: string,
180
- options: ProcessInfoExecFileSyncOptionsWithStringEncoding
181
- ): string
182
- static execFileSync(
183
- file: string,
184
- options: ProcessInfoExecFileSyncOptionsWithBufferEncoding
185
- ): Buffer
186
- static execFileSync(
187
- file: string,
188
- options?: ProcessInfoExecFileSyncOptions
189
- ): string | Buffer
190
- static execFileSync(file: string, args: readonly string[]): Buffer
191
- static execFileSync(
192
- file: string,
193
- args: readonly string[],
194
- options: ProcessInfoExecFileSyncOptionsWithStringEncoding
195
- ): string
196
- static execFileSync(
197
- file: string,
198
- args: readonly string[],
199
- options: ProcessInfoExecFileSyncOptionsWithBufferEncoding
200
- ): Buffer
201
- static execFileSync(
202
- file: string,
203
- args?: readonly string[],
204
- options?: ProcessInfoExecFileSyncOptions
205
- ): string | Buffer
206
- }
207
-
208
- export = ProcessInfo
package/lib/json-file.cjs DELETED
@@ -1,19 +0,0 @@
1
- // read the file and json decode it, if anything fails, return {}
2
-
3
- const { readFile } = require('fs/promises')
4
- const { readFileSync } = require('fs')
5
-
6
- const safeJSONSync = f => {
7
- try {
8
- return JSON.parse(readFileSync(f, 'utf8'))
9
- } catch (e) {
10
- return {}
11
- }
12
- }
13
-
14
- const safeJSON = f =>
15
- readFile(f, 'utf8')
16
- .then(d => JSON.parse(d))
17
- .catch(() => ({}))
18
-
19
- module.exports = { safeJSON, safeJSONSync }
@@ -1,100 +0,0 @@
1
- const cjsLoader = require.resolve('./cjs.cjs')
2
- const esmLoader = require.resolve('./esm.mjs')
3
-
4
- // esm --loader is actually last-wins, so only counts as having
5
- // it if it's the last loader in line. To get around that, we pass
6
- // ALL loaders to our loader as ?a&b&c&...
7
- //
8
- // cjs --require stacks in order, so as long as it's there, it counts.
9
-
10
- const hasCJSLoader = args => hasLoader(args, ['-r', '--require'], cjsLoader)
11
-
12
- const hasESMLoader = args =>
13
- hasLoader(args, ['--experimental-loader', '--loader'], esmLoader, true)
14
-
15
- const addCJS = args =>
16
- !hasCJSLoader(args) ? args.concat('--require=' + cjsLoader) : args
17
- const addESM = args => squashLoaders(args)
18
-
19
- const cjsOnly = args => (hasESMLoader(args) ? false : hasCJSLoader(args))
20
-
21
- const { nodeOptionsToArgv } = require('./node-options-to-argv.cjs')
22
- const { argvToNodeOptions } = require('./argv-to-node-options.cjs')
23
- const { fileURLToPath, pathToFileURL } = require('url')
24
-
25
- const { resolve } = require('path')
26
- const resolveLoader = (path, isURI) => {
27
- path = decode(path, isURI)
28
- try {
29
- return require.resolve(/^\.?\.[\\/]/.test(path) ? resolve(path) : path)
30
- } catch (e) {
31
- return path
32
- }
33
- }
34
-
35
- const decode = (path, isURI) =>
36
- !isURI
37
- ? path
38
- : /^file:/.test(path)
39
- ? fileURLToPath(path)
40
- : decodeURIComponent(path)
41
-
42
- const squashLoaders = args => {
43
- const loaders = []
44
- const re = /^--(?:experimental-)?loader(?:=(.*))?$/
45
- const squashed = []
46
- for (let i = 0; i < args.length; i++) {
47
- const arg = args[i]
48
- const parsed = arg.match(re)
49
- if (!parsed) {
50
- squashed.push(arg)
51
- continue
52
- }
53
- const val = parsed[1] || args[++i]
54
- if (!val) {
55
- // --loader with no value anywhere, just put it back how it was
56
- // and let node barf on it
57
- squashed.push(arg, args[i - 1])
58
- continue
59
- }
60
- const resolved = resolveLoader(val, true)
61
- if (resolved === esmLoader) {
62
- continue
63
- }
64
- loaders.push(encodeURIComponent(val.replace(/\\/g, '/')))
65
- }
66
- const q = loaders.length ? '?' : ''
67
- squashed.push(`--loader=${pathToFileURL(esmLoader)}${q}${loaders.join('&')}`)
68
- return squashed
69
- }
70
-
71
- const hasLoader = (args, keys, value, isURI = false) => {
72
- value = decode(value, isURI)
73
- for (let i = 0; i < args.length; i++) {
74
- const arg = args[i]
75
- // -r <value>
76
- if (
77
- keys.includes(arg) &&
78
- i < args.length - 1 &&
79
- resolveLoader(args[i + 1], isURI) === value
80
- ) {
81
- return true
82
- } else if (arg.startsWith('--') && arg.includes('=')) {
83
- // --require=<value>
84
- const [k, ...rest] = arg.split('=')
85
- if (keys.includes(k) && resolveLoader(rest.join('='), isURI) === value) {
86
- return true
87
- } else {
88
- continue
89
- }
90
- }
91
- }
92
- return false
93
- }
94
-
95
- const nodeOptionsEnv = (env, args) => {
96
- const no = nodeOptionsToArgv(env.NODE_OPTIONS)
97
- return argvToNodeOptions(cjsOnly(args.concat(no)) ? addCJS(no) : addESM(no))
98
- }
99
-
100
- module.exports = { nodeOptionsEnv }
@@ -1,52 +0,0 @@
1
- exports.nodeOptionsToArgv = no => {
2
- if (!no) return []
3
- const argv = []
4
- let escaping = false
5
- let inquote = false
6
- let tokStart = 0
7
- let tok = ''
8
- for (let i = 0; i < no.length; i++) {
9
- const c = no.charAt(i)
10
- switch (c) {
11
- case '"':
12
- if (escaping) {
13
- tok += no.slice(tokStart, i - 1) + '"'
14
- tokStart = i + 1
15
- escaping = false
16
- } else if (inquote) {
17
- tok += no.slice(tokStart, i)
18
- tokStart = i + 1
19
- inquote = false
20
- } else {
21
- inquote = true
22
- tok += no.slice(tokStart, i)
23
- tokStart = i + 1
24
- }
25
- continue
26
-
27
- case '\\':
28
- if (inquote) {
29
- escaping = true
30
- }
31
- continue
32
-
33
- case ' ':
34
- if (inquote) continue
35
- tok += no.slice(tokStart, i)
36
- tokStart = i + 1
37
- argv.push(tok)
38
- tok = ''
39
- continue
40
-
41
- default:
42
- escaping = false
43
- continue
44
- }
45
- }
46
- if (inquote) {
47
- return []
48
- }
49
- tok += no.slice(tokStart)
50
- argv.push(tok)
51
- return argv
52
- }
@@ -1,84 +0,0 @@
1
- class ProcessInfoNode {
2
- constructor(data) {
3
- this.parent = null
4
- this.children = null
5
- this.files = null
6
- this.externalID = null
7
- Object.assign(this, data)
8
- }
9
-
10
- toJSON() {
11
- return Object.fromEntries(
12
- Object.entries(this)
13
- .filter(([_, val]) => val !== null && val !== undefined)
14
- .map(([key, val]) =>
15
- key === 'root'
16
- ? [key, val.uuid]
17
- : key === 'parent'
18
- ? [key, val.uuid]
19
- : key === 'children'
20
- ? [key, [...val].map(c => c.uuid)]
21
- : [key, val]
22
- )
23
- )
24
- }
25
-
26
- link(db) {
27
- db.uuids.set(this.uuid, this)
28
- this.parent = db.uuids.get(this.parent) || this.parent || null
29
- this.root = db.uuids.get(this.root) || this.root
30
-
31
- if (this.parent === null) {
32
- this.root = this
33
- if (db.pendingRoot.has(this.uuid)) {
34
- for (const n of db.pendingRoot.get(this.uuid)) {
35
- n.root = this
36
- }
37
- db.pendingRoot.delete(this.uuid)
38
- }
39
- db.roots.add(this)
40
- } else if (typeof this.root === 'string') {
41
- if (db.pendingRoot.has(this.root)) {
42
- db.pendingRoot.get(this.root).add(this)
43
- } else {
44
- db.pendingRoot.set(this.root, new Set([this]))
45
- }
46
- }
47
-
48
- if (typeof this.parent === 'string') {
49
- if (db.pendingParent.has(this.parent)) {
50
- db.pendingParent.get(this.parent).add(this)
51
- } else {
52
- db.pendingParent.set(this.parent, new Set([this]))
53
- }
54
- } else if (this.parent !== null) {
55
- if (!this.parent.children) {
56
- this.parent.children = new Set([this])
57
- } else {
58
- this.parent.children.add(this)
59
- }
60
- }
61
-
62
- if (db.pendingParent.has(this.uuid)) {
63
- this.children = db.pendingParent.get(this.uuid)
64
- for (const n of this.children) {
65
- n.parent = this
66
- }
67
- db.pendingParent.delete(this.uuid)
68
- }
69
-
70
- for (const f of this.files) {
71
- if (!db.files.has(f)) {
72
- db.files.set(f, new Set([this]))
73
- } else {
74
- db.files.get(f).add(this)
75
- }
76
- }
77
-
78
- if (this.externalID) {
79
- db.externalIDs.set(this.externalID, this)
80
- }
81
- }
82
- }
83
-
84
- module.exports = { ProcessInfoNode }
@@ -1,74 +0,0 @@
1
- // start tracking coverage, unless disabled explicltly
2
- // export so that we know to collect at the end of the process
3
- const enabled = process.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'
4
- if (enabled) {
5
- process.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'
6
- process.setSourceMapsEnabled(true)
7
-
8
- // NB: coverage exclusion is in addition to processinfo
9
- // exclusion. Only show coverage for a file we care
10
- // about at least somewhat, but coverage is a subset.
11
- const { getExclude } = require('./get-exclude.cjs')
12
- const exclude = getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_')
13
- const inspector = require('inspector')
14
- const session = new inspector.Session()
15
- module.exports.session = session
16
- session.connect()
17
- session.post('Profiler.enable')
18
- session.post('Runtime.enable')
19
- session.post('Profiler.startPreciseCoverage', {
20
- callCount: true,
21
- detailed: true,
22
- })
23
-
24
- const { fileURLToPath } = require('url')
25
- const { findSourceMap } = require('module')
26
-
27
- const lineLengths = f =>
28
- readFileSync(f, 'utf8')
29
- .split(/\n|\u2028|\u2029/)
30
- .map(l => l.length)
31
-
32
- const { mkdirSync, writeFileSync, readFileSync } = require('fs')
33
-
34
- const coverageOnProcessEnd = (cwd, processInfo) => {
35
- const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`
36
- mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })
37
-
38
- session.post('Profiler.takePreciseCoverage', (er, cov) => {
39
- session.post('Profiler.stopPreciseCoverage')
40
-
41
- /* istanbul ignore next - something very strange and bad happened */
42
- if (er) {
43
- throw er
44
- }
45
-
46
- const sourceMapCache = (cov['source-map-cache'] = {})
47
- cov.result = cov.result.filter(obj => {
48
- if (!/^file:/.test(obj.url)) {
49
- return false
50
- }
51
- const f = fileURLToPath(obj.url)
52
- if (!processInfo.files.includes(f) || exclude.test(f)) {
53
- return false
54
- }
55
- // see if it has a source map
56
- const s = findSourceMap(f)
57
- if (s) {
58
- const { payload } = s
59
- sourceMapCache[obj.url] = Object.assign(Object.create(null), {
60
- lineLengths: lineLengths(f),
61
- data: payload,
62
- })
63
- }
64
- return true
65
- })
66
-
67
- writeFileSync(f, JSON.stringify(cov, 0, 2) + '\n', 'utf8')
68
- })
69
- }
70
-
71
- module.exports = { coverageOnProcessEnd }
72
- } else {
73
- module.exports = { coverageOnProcessEnd: () => {} }
74
- }
@@ -1,21 +0,0 @@
1
- const processOnSpawn = require('process-on-spawn')
2
- const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
3
-
4
- processOnSpawn.addListener(obj => {
5
- const env = obj.env || {}
6
- obj.env = Object.assign(env, getEnvs(env))
7
- return obj
8
- })
9
-
10
- const envRE = /^_TAPJS_PROCESSINFO_/
11
-
12
- const getEnvs = env => {
13
- // load it here so that it isn't cached before the loader attaches
14
- // in self-test scenario.
15
- const { nodeOptionsEnv } = require('./node-options-env.cjs')
16
- return Object.fromEntries(
17
- Object.entries(process.env)
18
- .filter(([k, v]) => !hasOwn(env, k) && envRE.test(k))
19
- .concat([['NODE_OPTIONS', nodeOptionsEnv(env, process.execArgv)]])
20
- )
21
- }
@@ -1,29 +0,0 @@
1
- const { onExit } = require('signal-exit')
2
- const { getProcessInfo } = require('./get-process-info.cjs')
3
-
4
- const { mkdirSync, writeFileSync } = require('fs')
5
- const cwd = process.cwd()
6
- const globals = new Set(Object.keys(global))
7
- const { coverageOnProcessEnd } = require('./register-coverage.cjs')
8
-
9
- onExit(
10
- (code, signal) => {
11
- const processInfo = getProcessInfo()
12
- processInfo.code = code
13
- processInfo.signal = signal
14
- const runtime = process.hrtime(processInfo.hrstart)
15
- delete processInfo.hrstart
16
- processInfo.files = [...new Set(processInfo.files)]
17
- processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6
18
- const globalsAdded = Object.keys(global).filter(k => !globals.has(k))
19
- if (globalsAdded.length) {
20
- processInfo.globalsAdded = globalsAdded
21
- }
22
-
23
- const f = `${cwd}/.tap/processinfo/${processInfo.uuid}.json`
24
- mkdirSync(`${cwd}/.tap/processinfo`, { recursive: true })
25
- writeFileSync(f, JSON.stringify(processInfo) + '\n', 'utf8')
26
- coverageOnProcessEnd(cwd, processInfo)
27
- },
28
- { alwaysLast: true }
29
- )
@@ -1,16 +0,0 @@
1
- const { nodeOptionsEnv } = require('./node-options-env.cjs')
2
-
3
- const spawnOpts = (options = {}, exclude) => {
4
- const { externalID } = options
5
- const env = { ...(options.env || process.env) }
6
- env.NODE_OPTIONS = nodeOptionsEnv(env, [])
7
- if (externalID) {
8
- env._TAPJS_PROCESSINFO_EXTERNAL_ID_ = externalID
9
- }
10
- if (exclude) {
11
- env._TAPJS_PROCESSINFO_EXCLUDE_ = String(exclude)
12
- }
13
- return { ...options, env }
14
- }
15
-
16
- module.exports = { spawnOpts }