1- import { getModulePath } from '@codesandbox/common/lib/sandbox/modules' ;
2- import { generateFileFromSandbox as generatePackageJsonFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json' ;
31import {
4- Module ,
52 ModuleTab ,
63 NotificationButton ,
74 Sandbox ,
@@ -14,7 +11,6 @@ import { NotificationStatus } from '@codesandbox/notifications';
1411import values from 'lodash-es/values' ;
1512
1613import { ApiError } from './effects/api/apiFactory' ;
17- import { createOptimisticModule } from './utils/common' ;
1814import { defaultOpenedModule , mainModule } from './utils/main-module' ;
1915import { parseConfigurations } from './utils/parse-configurations' ;
2016import { Action , AsyncAction } from '.' ;
@@ -270,57 +266,6 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
270266 actions . server . startContainer ( sandbox ) ;
271267} ;
272268
273- export const ensurePackageJSON : AsyncAction = async ( {
274- state,
275- actions,
276- effects,
277- } ) => {
278- const sandbox = state . editor . currentSandbox ;
279- if ( ! sandbox ) {
280- return ;
281- }
282-
283- const existingPackageJson = sandbox . modules . find (
284- module => module . directoryShortid == null && module . title === 'package.json'
285- ) ;
286-
287- if ( sandbox . owned && ! existingPackageJson ) {
288- const optimisticId = effects . utils . createOptimisticId ( ) ;
289- const optimisticModule = createOptimisticModule ( {
290- id : optimisticId ,
291- title : 'package.json' ,
292- code : generatePackageJsonFromSandbox ( sandbox ) ,
293- path : '/package.json' ,
294- } ) ;
295-
296- sandbox . modules . push ( optimisticModule as Module ) ;
297- optimisticModule . path = getModulePath (
298- sandbox . modules ,
299- sandbox . directories ,
300- optimisticId
301- ) ;
302-
303- // We grab the module from the state to continue working with it (proxy)
304- const module = sandbox . modules [ sandbox . modules . length - 1 ] ;
305-
306- effects . vscode . sandboxFsSync . writeFile ( state . editor . modulesByPath , module ) ;
307-
308- try {
309- const updatedModule = await effects . api . createModule ( sandbox . id , module ) ;
310-
311- module . id = updatedModule . id ;
312- module . shortid = updatedModule . shortid ;
313- } catch ( error ) {
314- sandbox . modules . splice ( sandbox . modules . indexOf ( module ) , 1 ) ;
315- state . editor . modulesByPath = effects . vscode . sandboxFsSync . create ( sandbox ) ;
316- actions . internal . handleError ( {
317- message : 'Could not add package.json file' ,
318- error,
319- } ) ;
320- }
321- }
322- } ;
323-
324269export const closeTabByIndex : Action < number > = ( { state } , tabIndex ) => {
325270 const { currentModule } = state . editor ;
326271 const tabs = state . editor . tabs as ModuleTab [ ] ;
0 commit comments