@@ -34,7 +34,10 @@ function bundleResultForEach(bundleResult: BundleResult, cb: (bundleResult: Bund
3434 }
3535}
3636
37- async function build ( project : string , config : BundlerOptions ) : Promise < { bundleResult: BundleResult ; fileRegistry: FileRegistry } > {
37+ async function build (
38+ project : string | undefined ,
39+ config : BundlerOptions
40+ ) : Promise < { bundleResult: BundleResult ; fileRegistry: FileRegistry } > {
3841 if ( config . entryFile == null ) {
3942 throw new EntryFileNotDefinedError ( ) ;
4043 }
@@ -44,16 +47,16 @@ async function build(project: string, config: BundlerOptions): Promise<{ bundleR
4447 }
4548
4649 const fileRegistry : FileRegistry = { } ;
47- const bundler = new Bundler ( fileRegistry , config . rootDir ) ;
50+ const bundler = new Bundler ( fileRegistry , project ) ;
4851 const bundleResult = await bundler . bundle ( config . entryFile , config . dedupeGlobs , config . includePaths , config . ignoreImports ) ;
4952
5053 if ( ! bundleResult . found ) {
5154 throw new EntryFileNotFoundError ( bundleResult . filePath ) ;
5255 }
5356
5457 bundleResultForEach ( bundleResult , result => {
55- if ( ! result . found && result . tilde && config . rootDir == null ) {
56- Log . warn ( " Found tilde import, but rootDir was not specified." ) ;
58+ if ( ! result . found && result . tilde && project == null ) {
59+ Log . warn ( ` Found tilde import, but "project" was not specified.` ) ;
5760 throw new ImportFileNotFoundError ( result . filePath ) ;
5861 }
5962 } ) ;
@@ -118,10 +121,6 @@ async function main(argv: string[]): Promise<void> {
118121 const configLocationDir = path . dirname ( configLocation ) ;
119122 projectLocation = path . resolve ( configLocationDir , config . project ?? "./" ) ;
120123 }
121- if ( projectLocation == null ) {
122- Log . error ( `Could not resolve "project" directory.` ) ;
123- process . exit ( 1 ) ;
124- }
125124
126125 let resolvedLogLevel : LogLevelDesc | undefined ;
127126 if ( config . logLevel != null ) {
@@ -137,13 +136,15 @@ async function main(argv: string[]): Promise<void> {
137136 const onFileChange = debounce ( async ( ) => {
138137 Log . info ( "File changes detected." ) ;
139138
140- // This is already checked as fail fast.
141- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
142- await build ( projectLocation ! , config ) ;
139+ await build ( projectLocation , config ) ;
143140 Log . info ( "Waiting for changes..." ) ;
144141 } ) ;
145142
146- const watchFolder = config . rootDir != null ? config . rootDir : projectLocation ;
143+ if ( config . rootDir ) {
144+ Log . warn ( "rootDir property is missing, using cwd." ) ;
145+ }
146+
147+ const watchFolder = config . rootDir ?? process . cwd ( ) ;
147148
148149 Log . info ( "Waiting for changes..." ) ;
149150 chokidar . watch ( watchFolder ) . on ( "change" , onFileChange ) ;
0 commit comments