@@ -5,6 +5,7 @@ import { MosaicDirection, MosaicNode, getLeaves } from 'react-mosaic-component';
55import {
66 compareEditors ,
77 getEmptyContent ,
8+ isMainEntryPoint ,
89 isSupportedFile ,
910 monacoLanguage ,
1011} from './utils/editor-utils' ;
@@ -140,8 +141,11 @@ export class EditorMosaic {
140141
141142 /** Add a file. If we already have a file with that name, replace it. */
142143 private addFile ( id : EditorId , value : string ) {
143- if ( ! isSupportedFile ( id ) )
144- throw new Error ( `Cannot add file "${ id } ": Must be .js, .html, or .css` ) ;
144+ if ( ! isSupportedFile ( id ) ) {
145+ throw new Error (
146+ `Cannot add file "${ id } ": Must be .cjs, .js, .mjs, .html, or .css` ,
147+ ) ;
148+ }
145149
146150 // create a monaco model with the file's contents
147151 const { monaco } = window ;
@@ -259,8 +263,17 @@ export class EditorMosaic {
259263
260264 /** Add a new file to the mosaic */
261265 public addNewFile ( id : EditorId , value : string = getEmptyContent ( id ) ) {
262- if ( this . files . has ( id ) )
266+ if ( this . files . has ( id ) ) {
263267 throw new Error ( `Cannot add file "${ id } ": File already exists` ) ;
268+ }
269+
270+ const entryPoint = this . mainEntryPointFile ( ) ;
271+
272+ if ( isMainEntryPoint ( id ) && entryPoint ) {
273+ throw new Error (
274+ `Cannot add file "${ id } ": Main entry point ${ entryPoint } exists` ,
275+ ) ;
276+ }
264277
265278 this . addFile ( id , value ) ;
266279 }
@@ -302,6 +315,10 @@ export class EditorMosaic {
302315 for ( const editor of this . editors . values ( ) ) editor . updateOptions ( options ) ;
303316 }
304317
318+ public mainEntryPointFile ( ) : EditorId | undefined {
319+ return Array . from ( this . files . keys ( ) ) . find ( ( id ) => isMainEntryPoint ( id ) ) ;
320+ }
321+
305322 //=== Listen for user edits
306323
307324 private ignoreAllEdits ( ) {
0 commit comments