Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions packages/app/src/app/overmind/internalActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { getModulePath } from '@codesandbox/common/lib/sandbox/modules';
import { generateFileFromSandbox as generatePackageJsonFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json';
import {
Module,
ModuleTab,
NotificationButton,
Sandbox,
Expand All @@ -14,7 +11,6 @@ import { NotificationStatus } from '@codesandbox/notifications';
import values from 'lodash-es/values';

import { ApiError } from './effects/api/apiFactory';
import { createOptimisticModule } from './utils/common';
import { defaultOpenedModule, mainModule } from './utils/main-module';
import { parseConfigurations } from './utils/parse-configurations';
import { Action, AsyncAction } from '.';
Expand Down Expand Up @@ -272,57 +268,6 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
actions.server.startContainer(sandbox);
};

export const ensurePackageJSON: AsyncAction = async ({
state,
actions,
effects,
}) => {
const sandbox = state.editor.currentSandbox;
if (!sandbox) {
return;
}

const existingPackageJson = sandbox.modules.find(
module => module.directoryShortid == null && module.title === 'package.json'
);

if (sandbox.owned && !existingPackageJson) {
const optimisticId = effects.utils.createOptimisticId();
const optimisticModule = createOptimisticModule({
id: optimisticId,
title: 'package.json',
code: generatePackageJsonFromSandbox(sandbox),
path: '/package.json',
});

sandbox.modules.push(optimisticModule as Module);
optimisticModule.path = getModulePath(
sandbox.modules,
sandbox.directories,
optimisticId
);

// We grab the module from the state to continue working with it (proxy)
const module = sandbox.modules[sandbox.modules.length - 1];

effects.vscode.sandboxFsSync.writeFile(state.editor.modulesByPath, module);

try {
const updatedModule = await effects.api.createModule(sandbox.id, module);

module.id = updatedModule.id;
module.shortid = updatedModule.shortid;
} catch (error) {
sandbox.modules.splice(sandbox.modules.indexOf(module), 1);
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(sandbox);
actions.internal.handleError({
message: 'Could not add package.json file',
error,
});
}
}
};

export const closeTabByIndex: Action<number> = ({ state }, tabIndex) => {
const { currentModule } = state.editor;
const tabs = state.editor.tabs as ModuleTab[];
Expand Down
2 changes: 0 additions & 2 deletions packages/app/src/app/overmind/namespaces/editor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
});
}

actions.internal.ensurePackageJSON();

await actions.editor.internal.initializeSandbox(sandbox);

// We only recover files at this point if we are not live. When live we recover them
Expand Down