@@ -9,6 +9,21 @@ export interface NodeModuleTracePluginOptions {
9
9
contextDirectory ?: string
10
10
// additional PATH environment variable to use for spawning the `node-file-trace` process
11
11
path ?: string
12
+ // log options
13
+ log ?: {
14
+ all ?: boolean
15
+ detail ?: boolean
16
+ // Default is `error`
17
+ level ?:
18
+ | 'bug'
19
+ | 'fatal'
20
+ | 'error'
21
+ | 'warning'
22
+ | 'hint'
23
+ | 'note'
24
+ | 'suggestions'
25
+ | 'info'
26
+ }
12
27
}
13
28
14
29
export class NodeModuleTracePlugin implements WebpackPluginInstance {
@@ -63,25 +78,54 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
63
78
}
64
79
65
80
private runTrace ( ) {
66
- spawnSync (
67
- 'node-file-trace' ,
68
- [
69
- 'annotate' ,
70
- '--context-directory' ,
71
- this . options ?. contextDirectory ?? '.' ,
72
- '--exact' ,
73
- ...this . chunksToTrace ,
74
- ] ,
75
- {
76
- stdio : 'inherit' ,
77
- env : {
78
- ...process . env ,
79
- PATH : `${ this . options ?. path ?? '' } ${
80
- process . platform === 'win32' ? ';' : ':'
81
- } ${ process . env . PATH } `,
82
- } ,
83
- cwd : this . options ?. cwd ?? process . cwd ( ) ,
81
+ process . stdout . write ( '\n' )
82
+ const args = [
83
+ 'annotate' ,
84
+ '--context-directory' ,
85
+ this . options ?. contextDirectory ?? '.' ,
86
+ '--exact' ,
87
+ ]
88
+ if ( this . options ?. log ?. detail ) {
89
+ args . push ( '--log-detail' )
90
+ }
91
+ if ( this . options ?. log ?. all ) {
92
+ args . push ( '--show-all' )
93
+ }
94
+ const logLevel = this . options ?. log ?. level
95
+ if ( logLevel ) {
96
+ args . push ( `--log-level ${ logLevel } ` )
97
+ }
98
+ let turboTracingPackagePath = ''
99
+ let turboTracingBinPath = ''
100
+ try {
101
+ turboTracingPackagePath = require . resolve ( '@vercel/node-module-trace' )
102
+ } catch ( e ) {
103
+ // ignore
104
+ }
105
+ if ( turboTracingPackagePath ) {
106
+ try {
107
+ turboTracingBinPath = require . resolve (
108
+ `@vercel/node-module-trace-${ process . platform } -${ process . arch } ` ,
109
+ {
110
+ paths : [ turboTracingPackagePath ] ,
111
+ } ,
112
+ )
113
+ } catch ( e ) {
114
+ // ignore
115
+ }
116
+ }
117
+ const pathSep = process . platform === 'win32' ? ';' : ':'
118
+ let paths = `${ this . options ?. path ?? '' } ${ pathSep } ${ process . env . PATH } `
119
+ if ( turboTracingBinPath ) {
120
+ paths = `${ turboTracingBinPath } ${ pathSep } ${ paths } `
121
+ }
122
+ spawnSync ( 'node-file-trace' , [ ...args , ...this . chunksToTrace ] , {
123
+ stdio : 'inherit' ,
124
+ env : {
125
+ ...process . env ,
126
+ PATH : paths ,
84
127
} ,
85
- )
128
+ cwd : this . options ?. cwd ?? process . cwd ( ) ,
129
+ } )
86
130
}
87
131
}
0 commit comments