@@ -25,15 +25,21 @@ import shell from 'shelljs';
25
25
import ora from 'ora' ;
26
26
import { paths } from './constants' ;
27
27
import * as Messages from './messages' ;
28
- import { createRollupConfig } from './createRollupConfig ' ;
28
+ import { createBuildConfigs } from './createBuildConfigs ' ;
29
29
import { createJestConfig } from './createJestConfig' ;
30
30
import { createEslintConfig } from './createEslintConfig' ;
31
31
import { resolveApp , safePackageName , clearConsole } from './utils' ;
32
32
import { concatAllArray } from 'jpjs' ;
33
33
import getInstallCmd from './getInstallCmd' ;
34
34
import getInstallArgs from './getInstallArgs' ;
35
35
import { Input , Select } from 'enquirer' ;
36
- import { PackageJson , TsdxOptions } from './types' ;
36
+ import {
37
+ PackageJson ,
38
+ WatchOpts ,
39
+ BuildOpts ,
40
+ ModuleFormat ,
41
+ NormalizedOpts ,
42
+ } from './types' ;
37
43
import { createProgressEstimator } from './createProgressEstimator' ;
38
44
import { templates } from './templates' ;
39
45
import { composePackageJson } from './templates/utils' ;
47
53
appPackageJson = fs . readJSONSync ( paths . appPackageJson ) ;
48
54
} catch ( e ) { }
49
55
50
- // check for custom tsdx.config.js
51
- let tsdxConfig = {
52
- rollup ( config : RollupOptions , _options : TsdxOptions ) : RollupOptions {
53
- return config ;
54
- } ,
55
- } ;
56
-
57
- if ( fs . existsSync ( paths . appConfig ) ) {
58
- tsdxConfig = require ( paths . appConfig ) ;
59
- }
60
-
61
56
export const isDir = ( name : string ) =>
62
57
fs
63
58
. stat ( name )
@@ -80,8 +75,11 @@ async function jsOrTs(filename: string) {
80
75
return resolveApp ( `${ filename } ${ extension } ` ) ;
81
76
}
82
77
83
- async function getInputs ( entries : string [ ] , source ?: string ) {
84
- let inputs : any [ ] = [ ] ;
78
+ async function getInputs (
79
+ entries ?: string | string [ ] ,
80
+ source ?: string
81
+ ) : Promise < string [ ] > {
82
+ let inputs : string [ ] = [ ] ;
85
83
let stub : any [ ] = [ ] ;
86
84
stub
87
85
. concat (
@@ -96,67 +94,6 @@ async function getInputs(entries: string[], source?: string) {
96
94
return concatAllArray ( inputs ) ;
97
95
}
98
96
99
- async function createBuildConfigs (
100
- opts : any
101
- ) : Promise < Array < RollupOptions & { output : OutputOptions } >> {
102
- return await Promise . all (
103
- concatAllArray (
104
- opts . input . map ( ( input : string ) =>
105
- [
106
- opts . format . includes ( 'cjs' ) && {
107
- ...opts ,
108
- format : 'cjs' ,
109
- env : 'development' ,
110
- input,
111
- } ,
112
- opts . format . includes ( 'cjs' ) && {
113
- ...opts ,
114
- format : 'cjs' ,
115
- env : 'production' ,
116
- input,
117
- } ,
118
- opts . format . includes ( 'esm' ) && { ...opts , format : 'esm' , input } ,
119
- opts . format . includes ( 'umd' ) && {
120
- ...opts ,
121
- format : 'umd' ,
122
- env : 'development' ,
123
- input,
124
- } ,
125
- opts . format . includes ( 'umd' ) && {
126
- ...opts ,
127
- format : 'umd' ,
128
- env : 'production' ,
129
- input,
130
- } ,
131
- opts . format . includes ( 'system' ) && {
132
- ...opts ,
133
- format : 'system' ,
134
- env : 'development' ,
135
- input,
136
- } ,
137
- opts . format . includes ( 'system' ) && {
138
- ...opts ,
139
- format : 'system' ,
140
- env : 'production' ,
141
- input,
142
- } ,
143
- ]
144
- . filter ( Boolean )
145
- . map ( ( options : TsdxOptions , index : number ) => ( {
146
- ...options ,
147
- // We want to know if this is the first run for each entryfile
148
- // for certain plugins (e.g. css)
149
- writeMeta : index === 0 ,
150
- } ) )
151
- )
152
- ) . map ( async ( options : TsdxOptions ) => {
153
- // pass the full rollup config to tsdx.config.js override
154
- const config = await createRollupConfig ( options ) ;
155
- return tsdxConfig . rollup ( config , options ) ;
156
- } )
157
- ) ;
158
- }
159
-
160
97
async function moveTypes ( ) {
161
98
try {
162
99
// Move the typescript types to the base of the ./dist folder
320
257
. describe ( 'Rebuilds on any change' )
321
258
. option ( '--entry, -i' , 'Entry module(s)' )
322
259
. example ( 'watch --entry src/foo.tsx' )
323
- . option ( '--target' , 'Specify your target environment' , 'web ' )
260
+ . option ( '--target' , 'Specify your target environment' , 'browser ' )
324
261
. example ( 'watch --target node' )
325
262
. option ( '--name' , 'Specify name exposed in UMD builds' )
326
263
. example ( 'watch --name Foo' )
346
283
. example ( 'build --transpileOnly' )
347
284
. option ( '--extractErrors' , 'Extract invariant errors to ./errors/codes.json.' )
348
285
. example ( 'build --extractErrors' )
349
- . action ( async ( dirtyOpts : any ) => {
286
+ . action ( async ( dirtyOpts : WatchOpts ) => {
350
287
const opts = await normalizeOpts ( dirtyOpts ) ;
351
288
const buildConfigs = await createBuildConfigs ( opts ) ;
352
289
if ( ! opts . noClean ) {
438
375
. describe ( 'Build your project once and exit' )
439
376
. option ( '--entry, -i' , 'Entry module(s)' )
440
377
. example ( 'build --entry src/foo.tsx' )
441
- . option ( '--target' , 'Specify your target environment' , 'web ' )
378
+ . option ( '--target' , 'Specify your target environment' , 'browser ' )
442
379
. example ( 'build --target node' )
443
380
. option ( '--name' , 'Specify name exposed in UMD builds' )
444
381
. example ( 'build --name Foo' )
455
392
. example (
456
393
'build --extractErrors=https://reactjs.org/docs/error-decoder.html?invariant='
457
394
)
458
- . action ( async ( dirtyOpts : any ) => {
395
+ . action ( async ( dirtyOpts : BuildOpts ) => {
459
396
const opts = await normalizeOpts ( dirtyOpts ) ;
460
397
const buildConfigs = await createBuildConfigs ( opts ) ;
461
398
await cleanDistFolder ( ) ;
491
428
}
492
429
} ) ;
493
430
494
- async function normalizeOpts ( opts : any ) {
431
+ async function normalizeOpts ( opts : WatchOpts ) : Promise < NormalizedOpts > {
495
432
return {
496
433
...opts ,
497
434
name : opts . name || appPackageJson . name ,
@@ -501,7 +438,7 @@ async function normalizeOpts(opts: any) {
501
438
return 'esm' ;
502
439
}
503
440
return format ;
504
- } ) ,
441
+ } ) as [ ModuleFormat , ... ModuleFormat [ ] ] ,
505
442
} ;
506
443
}
507
444
0 commit comments