Skip to content

Commit 5523e2c

Browse files
authored
Build pipeline for common (codesandbox#1573)
* Convert common to TypeScript * Remove compiled folder * Update paths * Revert "Update paths" This reverts commit 437355d. * Update paths * Build step * Refine build pipeline * Update yarn.lock * Enable esModuleInterop * Fix window reference * Fix default import for env file * Fix default exports in webpack * Update paths to common * Fix tests * Ignore build files in tests * Fix path to common * Fixes
1 parent 4f75bbd commit 5523e2c

File tree

479 files changed

+1879
-1344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

479 files changed

+1879
-1344
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build:prod": "lerna run build --scope homepage --stream && lerna run build --scope app --stream && gulp",
99
"build:embed": "lerna run build:embed --scope app --stream && gulp",
1010
"build:clean": "lerna run build:clean --scope app --scope homepage && rimraf www",
11-
"build:deps": "lerna run build:dev --scope codesandbox-api --scope codesandbox-browserfs --scope node-services && lerna run build:dev --scope sse-hooks",
11+
"build:deps": "lerna run build:dev --scope codesandbox-api --scope codesandbox-browserfs --scope node-services --scope common && lerna run build:dev --scope sse-hooks",
1212
"start": "yarn build:deps && lerna run start --scope app --stream",
1313
"start:fast": "lerna run start --scope app --stream",
1414
"start:vscode": "VSCODE=1 yarn start:fast & cd standalone-packages/monaco-editor && yarn simpleserver & cd standalone-packages/vscode && yarn watch",

packages/app/config/webpack.common.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
77
const CopyWebpackPlugin = require('copy-webpack-plugin');
88
const HappyPack = require('happypack');
99
const WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
10-
const env = require('common/config/env');
11-
const getHost = require('common/utils/host');
10+
const env = require('common/lib/config/env');
11+
const getHost = require('common/lib/utils/host');
1212

1313
const babelDev = require('./babel.dev');
1414
const babelProd = require('./babel.prod');
1515

16-
const NODE_ENV = JSON.parse(env['process.env.NODE_ENV']);
16+
const NODE_ENV = JSON.parse(env.default['process.env.NODE_ENV']);
1717
const SANDBOX_ONLY = !!process.env.SANDBOX_ONLY;
1818
const __DEV__ = NODE_ENV === 'development'; // eslint-disable-line no-underscore-dangle
1919
const __PROD__ = NODE_ENV === 'production'; // eslint-disable-line no-underscore-dangle
2020
// const __TEST__ = NODE_ENV === 'test'; // eslint-disable-line no-underscore-dangle
2121
const babelConfig = __DEV__ ? babelDev : babelProd;
2222

23-
const publicPath = SANDBOX_ONLY || __DEV__ ? '/' : getHost() + '/';
23+
const publicPath = SANDBOX_ONLY || __DEV__ ? '/' : getHost.default() + '/';
2424

2525
// Shim for `eslint-plugin-vue/lib/index.js`
2626
const ESLINT_PLUGIN_VUE_INDEX = `module.exports = {
@@ -146,7 +146,7 @@ module.exports = {
146146
},
147147
{
148148
test: /\.(j|t)sx?$/,
149-
include: [paths.src, paths.common, /@emmetio/],
149+
include: [paths.src, /@emmetio/],
150150
exclude: [
151151
/eslint\.4\.1\.0\.min\.js$/,
152152
/typescriptServices\.js$/,
@@ -418,7 +418,7 @@ module.exports = {
418418
]),
419419
// Makes some environment variables available to the JS code, for example:
420420
// if (process.env.NODE_ENV === 'development') { ... }. See `env.js`.
421-
new webpack.DefinePlugin(env),
421+
new webpack.DefinePlugin(env.default),
422422
// Watcher doesn't work well if you mistype casing in a path so we use
423423
// a plugin that prints an error when you attempt to do this.
424424
// See https://github.com/facebookincubator/create-react-app/issues/240

packages/app/scripts/build.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,29 @@ function printFileSizes(stats, previousSizeMap) {
6363
.toJson()
6464
.assets.filter(asset => /\.(js|css)$/.test(asset.name))
6565
.map(asset => {
66-
let fileContents = fs.readFileSync(`${paths.appBuild}/${asset.name}`);
67-
let size = gzipSize(fileContents);
68-
let previousSize = previousSizeMap[removeFileNameHash(asset.name)];
69-
let difference = getDifferenceLabel(size, previousSize);
70-
return {
71-
folder: path.join('build', path.dirname(asset.name)),
72-
name: path.basename(asset.name),
73-
size,
74-
sizeLabel: filesize(size) + (difference ? ` (${difference})` : ''),
75-
};
66+
try {
67+
let fileContents = fs.readFileSync(`${paths.appBuild}/${asset.name}`);
68+
let size = gzipSize(fileContents);
69+
let previousSize = previousSizeMap[removeFileNameHash(asset.name)];
70+
let difference = getDifferenceLabel(size, previousSize);
71+
return {
72+
folder: path.join('build', path.dirname(asset.name)),
73+
name: path.basename(asset.name),
74+
size,
75+
sizeLabel: filesize(size) + (difference ? ` (${difference})` : ''),
76+
};
77+
} catch (e) {
78+
return {
79+
folder: path.join('build', path.dirname(asset.name)),
80+
name: path.basename(asset.name),
81+
error: e,
82+
};
83+
}
7684
});
7785
assets.sort((a, b) => b.size - a.size);
7886
let longestSizeLabelLength = Math.max.apply(
7987
null,
80-
assets.map(a => stripAnsi(a.sizeLabel).length)
88+
assets.map(a => (a.error ? 'ERROR'.length : stripAnsi(a.sizeLabel).length))
8189
);
8290
assets.forEach(asset => {
8391
let sizeLabel = asset.sizeLabel;
@@ -86,11 +94,20 @@ function printFileSizes(stats, previousSizeMap) {
8694
let rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
8795
sizeLabel += rightPadding;
8896
}
89-
console.log(
90-
` ${sizeLabel} ${chalk.dim(asset.folder + path.sep)}${chalk.cyan(
91-
asset.name
92-
)}`
93-
);
97+
98+
if (asset.error) {
99+
console.log(
100+
` ERROR ${chalk.dim(asset.folder + path.sep)}${chalk.cyan(
101+
asset.name
102+
)}`
103+
);
104+
} else {
105+
console.log(
106+
` ${sizeLabel} ${chalk.dim(asset.folder + path.sep)}${chalk.cyan(
107+
asset.name
108+
)}`
109+
);
110+
}
94111
});
95112
}
96113

packages/app/src/app/components/Button/elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled, { css } from 'styled-components';
22
import Link from 'react-router-dom/Link';
3-
import theme from 'common/theme';
3+
import theme from 'common/lib/theme';
44

55
const getBackgroundColor = ({
66
theme: internalTheme,

packages/app/src/app/components/CodeEditor/CodeMirror/elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import styled, { css, keyframes } from 'styled-components';
2-
import theme from 'common/theme';
2+
import theme from 'common/lib/theme';
33

44
const fadeInAnimation = keyframes`
55
0% { background-color: #374140; }

packages/app/src/app/components/CodeEditor/CodeMirror/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as React from 'react';
44
import CodeMirror from 'codemirror';
55
import { withTheme } from 'styled-components';
66

7-
import type { ModuleError, Module } from 'common/types';
7+
import type { ModuleError, Module } from 'common/lib/types';
88
import { getCodeMirror } from 'app/utils/codemirror';
99

1010
import 'codemirror/addon/dialog/dialog';

packages/app/src/app/components/CodeEditor/Configuration/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// @flow
22
import React from 'react';
33
import { TextOperation } from 'ot';
4-
import type { Module } from 'common/types';
5-
import getUI from 'common/templates/configuration/ui';
4+
import type { Module } from 'common/lib/types';
5+
import getUI from 'common/lib/templates/configuration/ui';
66
import getType from 'app/utils/get-type';
77
import EntryIcons from 'app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons';
8-
import Tooltip from 'common/components/Tooltip';
8+
import Tooltip from 'common/lib/components/Tooltip';
99

1010
import CodeIcon from 'react-icons/lib/md/code';
1111

packages/app/src/app/components/CodeEditor/FilePath/elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components';
22
import ChevronLeft from 'react-icons/lib/md/chevron-left';
33
import ExitZen from 'react-icons/lib/md/fullscreen-exit';
4-
import { withTooltip } from 'common/components/Tooltip';
4+
import { withTooltip } from 'common/lib/components/Tooltip';
55

66
export const Container = styled.div`
77
background-color: rgba(0, 0, 0, 0.3);

packages/app/src/app/components/CodeEditor/FilePath/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { getModulePath } from 'common/sandbox/modules';
2+
import { getModulePath } from 'common/lib/sandbox/modules';
33
import EntryIcons from 'app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons';
44
import getType from 'app/utils/get-type';
55

packages/app/src/app/components/CodeEditor/FuzzySearch/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import * as React from 'react';
22
import { sortBy, groupBy, flatten } from 'lodash-es';
33
import Downshift from 'downshift';
44
import matchSorter from 'match-sorter';
5-
import { getModulePath } from 'common/sandbox/modules';
6-
import Input from 'common/components/Input';
5+
import { getModulePath } from 'common/lib/sandbox/modules';
6+
import Input from 'common/lib/components/Input';
77
import EntryIcons from 'app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons';
88
import getType from 'app/utils/get-type';
9-
import { ESC } from 'common/utils/keycodes';
9+
import { ESC } from 'common/lib/utils/keycodes';
1010
import {
1111
Container,
1212
InputContainer,

0 commit comments

Comments
 (0)