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
1 change: 1 addition & 0 deletions packages/app/config/babel.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
require.resolve('@babel/plugin-transform-destructuring'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('@babel/plugin-proposal-optional-chaining'),
require.resolve('@babel/plugin-transform-runtime'),
require.resolve('babel-plugin-lodash'),
require.resolve('@babel/plugin-syntax-dynamic-import'),
Expand Down
1 change: 1 addition & 0 deletions packages/app/config/babel.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
require.resolve('@babel/plugin-transform-async-to-generator'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('@babel/plugin-proposal-optional-chaining'),
require.resolve('@babel/plugin-transform-runtime'),
require.resolve('babel-plugin-lodash'),
require.resolve('@babel/plugin-syntax-dynamic-import'),
Expand Down
3 changes: 2 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"circular-json": "^0.4.0",
"codemirror": "^5.27.4",
"codesandbox-api": "0.0.23",
"codesandbox-import-utils": "2.1.2",
"codesandbox-import-utils": "^2.1.11",
"color": "^0.11.4",
"compare-versions": "^3.1.0",
"console": "^0.7.2",
Expand Down Expand Up @@ -223,6 +223,7 @@
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-proposal-optional-chaining": "^7.7.4",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-async-to-generator": "^7.5.0",
"@babel/plugin-transform-react-display-name": "^7.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import getTemplateDefinition from '@codesandbox/common/lib/templates';
import getTemplateDefinition, {
TemplateType,
} from '@codesandbox/common/lib/templates';
import {
Module,
ModuleTab,
Expand Down Expand Up @@ -175,8 +177,8 @@ export const saveCode: AsyncAction<{
};

export const updateCurrentTemplate: AsyncAction = async ({
state,
effects,
state,
}) => {
try {
const currentTemplate = state.editor.currentSandbox.template;
Expand All @@ -187,9 +189,9 @@ export const updateCurrentTemplate: AsyncAction = async ({
// in the sandbox configuration.
if (
templateDefinition.isServer ||
state.editor.parsedConfigurations.sandbox.parsed.template
state.editor.parsedConfigurations?.sandbox?.parsed?.template
) {
const { parsed } = state.editor.parsedConfigurations.package;
const { parsed = {} } = state.editor.parsedConfigurations?.package || {};

const modulesByPath = mapValues(state.editor.modulesByPath, module => ({
// No idea why this typing fails!
Expand All @@ -199,10 +201,10 @@ export const updateCurrentTemplate: AsyncAction = async ({
isBinary: module.isBinary,
}));

// TODO: What is a templat really? Two different kinds of templates here, need to fix the types
// TODO: What is a template really? Two different kinds of templates here, need to fix the types
// Talk to Ives and Bogdan
const newTemplate =
computeTemplate(parsed, modulesByPath) || ('node' as any);
const newTemplate = (computeTemplate(parsed, modulesByPath) ||
'node') as TemplateType;

if (
newTemplate !== currentTemplate &&
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/app/overmind/namespaces/editor/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import getTemplate from '@codesandbox/common/lib/templates';
import { generateFileFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json';
import { getPreviewTabs } from '@codesandbox/common/lib/templates/devtools';
import { ViewConfig } from '@codesandbox/common/lib/templates/template';
import {
ParsedConfigurationFiles,
ViewConfig,
} from '@codesandbox/common/lib/templates/template';
import {
DevToolsTabPosition,
DiffTab,
Expand Down Expand Up @@ -56,7 +59,7 @@ type State = {
mainModule: Derive<State, Module>;
currentPackageJSON: Derive<State, Module>;
currentPackageJSONCode: Derive<State, string>;
parsedConfigurations: Derive<State, any>;
parsedConfigurations: Derive<State, ParsedConfigurationFiles> | null;
currentTab: Derive<State, ModuleTab | DiffTab>;
modulesByPath: SandboxFs;
isAdvancedEditor: Derive<State, boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ export const Dependencies: FunctionComponent = () => {
resource => !resource.includes('fonts.googleapis.com/css')
);

if (!parsedConfigurations.package) {
if (!parsedConfigurations?.package) {
return <ErrorMessage>Unable to find package.json</ErrorMessage>;
}

const { parsed, error } = parsedConfigurations.package;
const { error, parsed } = parsedConfigurations.package;
if (error) {
return (
<ErrorMessage>We weren{"'"}t able to parse the package.json</ErrorMessage>
);
}

const { dependencies = {} /* devDependencies = {} */ } = parsed;
const { externalResourcesEnabled } = getTemplateDefinition(template);

const dependencies = parsed.dependencies || {};
return (
<div>
<Margin bottom={0}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ const Task = styled.button`
`;

type Props = {
package:
| {
scripts: {
[command: string]: string;
};
}
| undefined;
package?: {
scripts?: {
[command: string]: string;
};
};
};

// These scripts are only supposed to run on the main thread.
Expand Down Expand Up @@ -73,7 +71,7 @@ export class Tasks extends React.PureComponent<Props> {
};

render() {
if (!this.props.package || !this.props.package.scripts) {
if (!this.props.package?.scripts) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ export const Server: FunctionComponent = () => {
<SubTitle>Run Scripts</SubTitle>
<Margin top={0.5}>
<TasksContainer disconnected={disconnected}>
<Tasks
package={
parsedConfigurations.package &&
parsedConfigurations.package.parsed
}
/>
<Tasks package={parsedConfigurations?.package?.parsed} />
</TasksContainer>
</Margin>
</Margin>
Expand Down
4 changes: 1 addition & 3 deletions packages/common/src/templates/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export type ConfigurationFile = {
};

export type ParsedConfigurationFile<T> = {
parsed?: T;
code: string;
generated: boolean;
error?: Error;
path: string;
};
} & ({ error: Error; parsed?: undefined } | { error?: undefined; parsed: T });

export type ConfigurationUIProps = {
file: string;
Expand Down
7 changes: 3 additions & 4 deletions packages/common/src/templates/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ export type ParsedConfigurationFiles = {
package?: ParsedConfigurationFile<{
main: string;
dependencies?: Dependencies;
devDependencies: Dependencies;
resolutions?: {
[source: string]: string;
};
devDependencies?: Dependencies;
resolutions?: { [source: string]: string };
scripts?: { [script: string]: string };
[otherProperties: string]: any | undefined;
}>;
[path: string]: ParsedConfigurationFile<any> | undefined;
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-catch-binding" "^7.2.0"

"@babel/plugin-proposal-optional-chaining@^7.6.0":
version "7.6.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.6.0.tgz#e9bf1f9b9ba10c77c033082da75f068389041af8"
integrity sha512-kj4gkZ6qUggkprRq3Uh5KP8XnE1MdIO0J7MhdDX8+rAbB6dJ2UrensGIS+0NPZAaaJ1Vr0PN6oLUgXMU1uMcSg==
"@babel/plugin-proposal-optional-chaining@^7.6.0", "@babel/plugin-proposal-optional-chaining@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.7.4.tgz#3f04c2de1a942cbd3008324df8144b9cbc0ca0ba"
integrity sha512-JmgaS+ygAWDR/STPe3/7y0lNlHgS+19qZ9aC06nYLwQ/XB7c0q5Xs+ksFU3EDnp9EiEsO0dnRAOKeyLHTZuW3A==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-chaining" "^7.2.0"
"@babel/plugin-syntax-optional-chaining" "^7.7.4"

"@babel/plugin-proposal-unicode-property-regex@^7.0.0", "@babel/plugin-proposal-unicode-property-regex@^7.4.0", "@babel/plugin-proposal-unicode-property-regex@^7.4.4":
version "7.4.4"
Expand Down Expand Up @@ -490,10 +490,10 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-optional-chaining@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.2.0.tgz#a59d6ae8c167e7608eaa443fda9fa8fa6bf21dff"
integrity sha512-HtGCtvp5Uq/jH/WNUPkK6b7rufnCPLLlDAFN7cmACoIjaOOiXxUt3SswU5loHqrhtqTsa/WoLQ1OQ1AGuZqaWA==
"@babel/plugin-syntax-optional-chaining@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.7.4.tgz#c91fdde6de85d2eb8906daea7b21944c3610c901"
integrity sha512-2MqYD5WjZSbJdUagnJvIdSfkb/ucOC9/1fRJxm7GAxY6YQLWlUvkfxoNbUPcPLHJyetKUDQ4+yyuUyAoc0HriA==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

Expand Down Expand Up @@ -7814,17 +7814,17 @@ codemirror@^5.27.4:
version "5.38.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.38.0.tgz#26a9551446e51dbdde36aabe60f72469724fd332"

codesandbox-import-util-types@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/codesandbox-import-util-types/-/codesandbox-import-util-types-2.1.2.tgz#2d0b7e977eadd4c0b5baeeaaae0b79c7e6c6900a"
integrity sha512-/6kk/qbV9n+2+vH5aVUNlskyNlhhxGBzzUvt7Ne2MGWkSRv42QMFxuZgMd+bjmXBENUZjrJPGXPK7HxxD1Q67w==
codesandbox-import-util-types@^2.1.9:
version "2.1.9"
resolved "https://registry.yarnpkg.com/codesandbox-import-util-types/-/codesandbox-import-util-types-2.1.9.tgz#24ba5ec3d966f51f18b78c48d32e6411da90aa74"
integrity sha512-Vc4qh+neVfHtS3RG+7wvaErMoEKdNTnLFnyj4Dcbn3NV7v9nlPj/z6MGhHp9S+vAjegWorFzxg9lKB1WGHTt5Q==

[email protected].2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/codesandbox-import-utils/-/codesandbox-import-utils-2.1.2.tgz#30613e28e79db681a555df70e5a916a7797f5c5d"
integrity sha512-cbvNa+dzYw2R3ofUkj51LsT8DX1GIoWVeDaJdSMJgZQSxXptjrf6zsLogcJtY8ihOURjED8CWEbQvpbHTM94EA==
codesandbox-import-utils@^2.1.11:
version "2.1.11"
resolved "https://registry.yarnpkg.com/codesandbox-import-utils/-/codesandbox-import-utils-2.1.11.tgz#171ce53a77b8dcd196fdcfaf0f6bc52b1206444a"
integrity sha512-vkA0drdzO2ArMUzl8/AhEuzaW6qX3ic1SXPmruVS7bo/3K1P8H+S9CbuUNPo67X54/LzHwMnAZgZMXwN8vrw7Q==
dependencies:
codesandbox-import-util-types "^2.1.2"
codesandbox-import-util-types "^2.1.9"
istextorbinary "^2.2.1"
lz-string "^1.4.4"

Expand Down