Skip to content

Commit d0f6dfd

Browse files
committed
Fix parsedConfigurations type
1 parent fa0ae73 commit d0f6dfd

File tree

3 files changed

+11
-9
lines changed
  • packages
    • app/src/app
      • overmind/namespaces/editor
      • pages/Sandbox/Editor/Workspace/Dependencies
    • common/src/templates/configuration

3 files changed

+11
-9
lines changed

packages/app/src/app/overmind/namespaces/editor/state.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import getTemplate from '@codesandbox/common/lib/templates';
22
import { generateFileFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json';
33
import { getPreviewTabs } from '@codesandbox/common/lib/templates/devtools';
4-
import { ViewConfig } from '@codesandbox/common/lib/templates/template';
4+
import {
5+
ParsedConfigurationFiles,
6+
ViewConfig,
7+
} from '@codesandbox/common/lib/templates/template';
58
import {
69
DevToolsTabPosition,
710
DiffTab,
@@ -56,7 +59,7 @@ type State = {
5659
mainModule: Derive<State, Module>;
5760
currentPackageJSON: Derive<State, Module>;
5861
currentPackageJSONCode: Derive<State, string>;
59-
parsedConfigurations: Derive<State, any>;
62+
parsedConfigurations: Derive<State, ParsedConfigurationFiles> | null;
6063
currentTab: Derive<State, ModuleTab | DiffTab>;
6164
modulesByPath: SandboxFs;
6265
isAdvancedEditor: Derive<State, boolean>;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,27 @@ export const Dependencies: FunctionComponent = () => {
3232
resource => !resource.includes('fonts.googleapis.com/css')
3333
);
3434

35-
if (!parsedConfigurations.package) {
35+
if (!parsedConfigurations?.package) {
3636
return <ErrorMessage>Unable to find package.json</ErrorMessage>;
3737
}
3838

39-
const { parsed, error } = parsedConfigurations.package;
39+
const { error, parsed } = parsedConfigurations.package;
4040
if (error) {
4141
return (
4242
<ErrorMessage>We weren{"'"}t able to parse the package.json</ErrorMessage>
4343
);
4444
}
4545

46+
const { dependencies = {} /* devDependencies = {} */ } = parsed;
4647
const { externalResourcesEnabled } = getTemplateDefinition(template);
4748
return (
4849
<div>
4950
<Margin bottom={0}>
50-
{Object.keys(parsed.dependencies)
51+
{Object.keys(dependencies)
5152
.sort()
5253
.map(dependency => (
5354
<VersionEntry
54-
dependencies={parsed.dependencies}
55+
dependencies={dependencies}
5556
dependency={dependency}
5657
key={dependency}
5758
onRefresh={(name, version) => addNpmDependency({ name, version })}

packages/common/src/templates/configuration/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ export type ConfigurationFile = {
1818
};
1919

2020
export type ParsedConfigurationFile<T> = {
21-
parsed?: T;
2221
code: string;
2322
generated: boolean;
24-
error?: Error;
2523
path: string;
26-
};
24+
} & ({ parsed: T } | { error: Error });
2725

2826
export type ConfigurationUIProps = {
2927
file: string;

0 commit comments

Comments
 (0)