@@ -20,7 +20,9 @@ module.exports = class Inliner {
20
20
this . isLib = fs . existsSync ( path . join ( root , "lib" , pkg ) ) ;
21
21
this . isClient = ! this . isPackage && ! this . isLib ;
22
22
this . isCore = pkg === "core" ;
23
+ this . reExportStubs = false ;
23
24
this . subfolder = this . isPackage ? "packages" : this . isLib ? "lib" : "clients" ;
25
+ this . verbose = process . env . DEBUG || process . argv . includes ( "--debug" ) ;
24
26
25
27
this . packageDirectory = path . join ( root , this . subfolder , pkg ) ;
26
28
@@ -38,7 +40,9 @@ module.exports = class Inliner {
38
40
*/
39
41
async clean ( ) {
40
42
await spawnProcess ( "yarn" , [ "rimraf" , "./dist-cjs" , "tsconfig.cjs.tsbuildinfo" ] , { cwd : this . packageDirectory } ) ;
41
- console . log ( "Deleted ./dist-cjs in " + this . package ) ;
43
+ if ( this . verbose ) {
44
+ console . log ( "Deleted ./dist-cjs in " + this . package ) ;
45
+ }
42
46
return this ;
43
47
}
44
48
@@ -48,7 +52,9 @@ module.exports = class Inliner {
48
52
*/
49
53
async tsc ( ) {
50
54
await spawnProcess ( "yarn" , [ "tsc" , "-p" , "tsconfig.cjs.json" ] , { cwd : this . packageDirectory } ) ;
51
- console . log ( "Finished recompiling ./dist-cjs in " + this . package ) ;
55
+ if ( this . verbose ) {
56
+ console . log ( "Finished recompiling ./dist-cjs in " + this . package ) ;
57
+ }
52
58
this . canonicalExports = Object . keys ( require ( this . outfile ) ) ;
53
59
return this ;
54
60
}
@@ -97,7 +103,9 @@ module.exports = class Inliner {
97
103
const key = path
98
104
. normalize ( path . join ( path . dirname ( keyFile ) , requireStatement [ 1 ] ) )
99
105
. replace ( / ( .* ?) d i s t - c j s \/ / , "./dist-cjs/" ) ;
100
- console . log ( "Transitive variant file:" , key ) ;
106
+ if ( this . verbose ) {
107
+ console . log ( "Transitive variant file:" , key ) ;
108
+ }
101
109
102
110
const transitiveVariant = key . replace ( / ( .* ?) d i s t - c j s \/ / , "" ) . replace ( / ( \. j s ) ? $ / , "" ) ;
103
111
@@ -178,6 +186,11 @@ module.exports = class Inliner {
178
186
recursive : true ,
179
187
force : true ,
180
188
} ) ;
189
+ if (
190
+ ! fs . lstatSync ( path . join ( root , this . subfolder , this . package , "src" , "submodules" , submodule ) ) . isDirectory ( )
191
+ ) {
192
+ continue ;
193
+ }
181
194
await esbuild . build ( {
182
195
...buildOptions ,
183
196
entryPoints : [ path . join ( root , this . subfolder , this . package , "src" , "submodules" , submodule , "index.ts" ) ] ,
@@ -201,18 +214,28 @@ module.exports = class Inliner {
201
214
for await ( const file of walk ( path . join ( this . packageDirectory , "dist-cjs" ) ) ) {
202
215
const relativePath = file . replace ( path . join ( this . packageDirectory , "dist-cjs" ) , "" ) . slice ( 1 ) ;
203
216
217
+ if ( relativePath . includes ( "submodules" ) ) {
218
+ continue ;
219
+ }
220
+
204
221
if ( ! file . endsWith ( ".js" ) ) {
205
- console . log ( "Skipping" , path . basename ( file ) , "file extension is not .js." ) ;
222
+ if ( this . verbose ) {
223
+ console . log ( "Skipping" , path . basename ( file ) , "file extension is not .js." ) ;
224
+ }
206
225
continue ;
207
226
}
208
227
209
228
if ( relativePath === "index.js" ) {
210
- console . log ( "Skipping index.js" ) ;
229
+ if ( this . verbose ) {
230
+ console . log ( "Skipping index.js" ) ;
231
+ }
211
232
continue ;
212
233
}
213
234
214
235
if ( this . variantExternals . find ( ( external ) => relativePath . endsWith ( external ) ) ) {
215
- console . log ( "Not rewriting." , relativePath , "is variant." ) ;
236
+ if ( this . verbose ) {
237
+ console . log ( "Not rewriting." , relativePath , "is variant." ) ;
238
+ }
216
239
continue ;
217
240
}
218
241
@@ -224,7 +247,7 @@ module.exports = class Inliner {
224
247
. map ( ( ) => ".." )
225
248
. join ( "/" ) ) + "/index.js" ;
226
249
227
- if ( this . isClient ) {
250
+ if ( ! this . reExportStubs ) {
228
251
fs . rmSync ( file ) ;
229
252
const files = fs . readdirSync ( path . dirname ( file ) ) ;
230
253
if ( files . length === 0 ) {
@@ -257,7 +280,9 @@ module.exports = class Inliner {
257
280
258
281
this . indexContents = this . indexContents . replace ( find , replace ) ;
259
282
260
- console . log ( "Replacing" , find , "with" , replace ) ;
283
+ if ( this . verbose ) {
284
+ console . log ( "Replacing" , find , "with" , replace ) ;
285
+ }
261
286
}
262
287
263
288
fs . writeFileSync ( this . outfile , this . indexContents , "utf-8" ) ;
@@ -356,9 +381,10 @@ module.exports = class Inliner {
356
381
const checkOrder = [ ...externalsToCheck ] . sort ( ) . reverse ( ) ;
357
382
for ( const external of checkOrder ) {
358
383
if ( line . includes ( external ) ) {
359
- console . log ( "Inline index confirmed require() for variant external:" , external ) ;
384
+ if ( this . verbose ) {
385
+ console . log ( "Inline index confirmed require() for variant external:" , external ) ;
386
+ }
360
387
externalsToCheck . delete ( external ) ;
361
- continue ;
362
388
}
363
389
}
364
390
}
@@ -379,7 +405,9 @@ module.exports = class Inliner {
379
405
. join ( "\n" ) ;
380
406
fs . writeFileSync ( path . join ( __dirname , "tmp" , this . package + ".mjs" ) , tmpFileContents , "utf-8" ) ;
381
407
await spawnProcess ( "node" , [ path . join ( __dirname , "tmp" , this . package + ".mjs" ) ] ) ;
382
- console . log ( "ESM compatibility verified." ) ;
408
+ if ( this . verbose ) {
409
+ console . log ( "ESM compatibility verified." ) ;
410
+ }
383
411
fs . rmSync ( path . join ( __dirname , "tmp" , this . package + ".mjs" ) ) ;
384
412
385
413
return this ;
0 commit comments