Skip to content

Commit 671bb23

Browse files
authoredJan 9, 2023
feat: migrate esbuild to rollup (#678)
1 parent 74769a5 commit 671bb23

File tree

23 files changed

+536
-6563
lines changed

23 files changed

+536
-6563
lines changed
 

‎.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v14.17.0
1+
v16

‎package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"sandpack-client",
77
"sandpack-react",
88
"sandpack-themes",
9-
"website/*",
10-
"examples/*"
9+
"website/*"
1110
],
1211
"nohoist": [
1312
"website/docs/**",
14-
"**/html-minifier-terser"
13+
"**/html-minifier-terser",
14+
"examples/**"
1515
],
1616
"description": "",
1717
"scripts": {
@@ -36,16 +36,17 @@
3636
"author": "CodeSandbox",
3737
"license": "Apache-2.0",
3838
"devDependencies": {
39+
"@octokit/rest": "^18.12.0",
3940
"@babel/preset-env": "^7.16.5",
4041
"@babel/preset-react": "^7.16.5",
4142
"@babel/preset-typescript": "^7.16.5",
42-
"@octokit/rest": "^18.12.0",
43+
"@rollup/plugin-commonjs": "^24.0.0",
44+
"@rollup/plugin-typescript": "^10.0.1",
4345
"@types/jest": "^27.4.0",
4446
"@typescript-eslint/eslint-plugin": "^4.0.0",
4547
"@typescript-eslint/parser": "^4.0.0",
4648
"babel-eslint": "^10.0.0",
4749
"babel-jest": "^27.4.5",
48-
"esbuild": "^0.12.21",
4950
"eslint": "^7.5.0",
5051
"eslint-config-prettier": "^8.1.0",
5152
"eslint-config-react-app": "^6.0.0",
@@ -63,6 +64,8 @@
6364
"package-build-stats": "7.3.13",
6465
"prettier": "^2.2.1",
6566
"react-test-renderer": "^18.1.0",
67+
"rollup": "^3.9.1",
68+
"rollup-plugin-replace": "^2.2.0",
6669
"turbo": "^1.5.5"
6770
},
6871
"lint-staged": {

‎sandpack-client/build.js

-44
This file was deleted.

‎sandpack-client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"clean": "rm -rf dist sandpack",
1818
"prebuild": "yarn run clean",
1919
"test": "jest .",
20-
"build": "node build.js && yarn run build:types",
20+
"build": "rollup -c && yarn run build:types",
2121
"build:types": "tsc -p tsconfig.json",
2222
"lint": "eslint '**/*.ts?(x)' --fix",
2323
"build:publish": "yarn build && gulp",

‎sandpack-client/rollup.config.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const typescript = require("@rollup/plugin-typescript");
2+
const pkg = require("./package.json");
3+
const commonjs = require("@rollup/plugin-commonjs");
4+
5+
const replace = require("rollup-plugin-replace");
6+
7+
const configBase = {
8+
input: "src/index.ts",
9+
output: [
10+
{
11+
file: pkg.main,
12+
exports: "named",
13+
format: "cjs",
14+
inlineDynamicImports: true,
15+
interop: "auto",
16+
},
17+
{
18+
file: pkg.module,
19+
exports: "named",
20+
format: "es",
21+
inlineDynamicImports: true,
22+
},
23+
],
24+
25+
plugins: [
26+
typescript({ tsconfig: "./tsconfig.json" }),
27+
replace({
28+
"process.env.CODESANDBOX_ENV": `"${process.env.CODESANDBOX_ENV}"`,
29+
"process.env.PACKAGE_VERSION": `"${pkg.version}"`,
30+
}),
31+
commonjs({ requireReturnsDefault: "preferred" }),
32+
],
33+
external: [
34+
...Object.keys(pkg.dependencies),
35+
...Object.keys(pkg.devDependencies),
36+
],
37+
};
38+
39+
module.exports = configBase;

‎sandpack-client/src/client.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isEqual from "lodash.isequal";
33

44
import Protocol from "./file-resolver-protocol";
55
import { IFrameProtocol } from "./iframe-protocol";
6-
import type {
6+
import {
77
Dependencies,
88
SandpackBundlerFiles,
99
BundlerState,
@@ -16,15 +16,14 @@ import type {
1616
ReactDevToolsMode,
1717
Template,
1818
NpmRegistry,
19+
SandpackLogLevel,
1920
} from "./types";
2021
import {
2122
createPackageJSON,
2223
addPackageJSONIfNeeded,
2324
extractErrorDetails,
2425
} from "./utils";
2526

26-
import { SandpackLogLevel } from ".";
27-
2827
export interface ClientOptions {
2928
/**
3029
* Paths to external resources

‎sandpack-react/build.js

-41
This file was deleted.

‎sandpack-react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"prebuild": "yarn run clean",
2121
"test": "TEST_ENV=true jest . --transformIgnorePatterns \"node_modules/(?!@codemirror)/\" --modulePathIgnorePatterns \"e2e\"",
2222
"lint": "eslint '**/*.ts?(x)' --fix",
23-
"build": "node build.js && yarn run build:types",
23+
"build": "rollup -c && yarn run build:types",
2424
"build:publish": "yarn build",
2525
"build:types": "tsc -p tsconfig.json",
2626
"start": "tsc -p tsconfig.esm.json --watch",

‎sandpack-react/rollup.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const typescript = require("@rollup/plugin-typescript");
2+
const pkg = require("./package.json");
3+
const commonjs = require("@rollup/plugin-commonjs");
4+
5+
const replace = require("rollup-plugin-replace");
6+
7+
const configBase = {
8+
input: "src/index.ts",
9+
output: [
10+
{
11+
file: pkg.main,
12+
exports: "named",
13+
format: "cjs",
14+
inlineDynamicImports: true,
15+
interop: "auto",
16+
},
17+
{
18+
file: pkg.module,
19+
exports: "named",
20+
format: "es",
21+
inlineDynamicImports: true,
22+
},
23+
],
24+
25+
plugins: [
26+
typescript({ tsconfig: "./tsconfig.json" }),
27+
replace({ "process.env.TEST_ENV": "false" }),
28+
commonjs({ requireReturnsDefault: "preferred" }),
29+
],
30+
external: [
31+
...Object.keys(pkg.dependencies),
32+
...Object.keys(pkg.devDependencies),
33+
...Object.keys(pkg.peerDependencies),
34+
],
35+
};
36+
37+
module.exports = configBase;

‎sandpack-react/src/components/FileExplorer/Directory.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import type { SandpackBundlerFiles } from "@codesandbox/sandpack-client";
22
import * as React from "react";
33

4-
import type { SandpackOptions } from "../..";
5-
4+
import type { SandpackFileExplorerProp } from ".";
5+
import { SandpackOptions } from "../../types";
66
import { File } from "./File";
77
import { ModuleList } from "./ModuleList";
88

9-
import type { SandpackFileExplorerProp } from ".";
10-
119
export interface Props extends SandpackFileExplorerProp {
1210
prefixedPath: string;
1311
files: SandpackBundlerFiles;

‎sandpack-react/src/components/FileExplorer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from "react";
22

3-
import { stackClassName } from "../..";
43
import { useSandpack } from "../../hooks/useSandpack";
54
import { css, THEME_PREFIX } from "../../styles";
65
import { classNames } from "../../utils/classNames";
6+
import { stackClassName } from "../common";
77

88
import { ModuleList } from "./ModuleList";
99

‎sandpack-react/src/components/Tests/Header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from "react";
22

3-
import { ConsoleIcon } from "../..";
43
import { css } from "../../styles";
54
import { roundedButtonClassName, buttonClassName } from "../../styles/shared";
65
import { classNames } from "../../utils/classNames";
6+
import { ConsoleIcon } from "../icons";
77

88
import type { Status } from "./SandpackTests";
99

‎sandpack-react/src/components/TranspiledCode/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useClasser } from "@code-hike/classer";
22
import * as React from "react";
33

4-
import { stackClassName } from "../..";
54
import { useSandpack } from "../../hooks/useSandpack";
65
import { useTranspiledCode } from "../../hooks/useTranspiledCode";
76
import { css, THEME_PREFIX } from "../../styles";
87
import { classNames } from "../../utils/classNames";
98
import type { CodeViewerProps } from "../CodeViewer";
109
import { SandpackCodeViewer } from "../CodeViewer";
10+
import { stackClassName } from "../common";
1111
import { ErrorOverlay } from "../common/ErrorOverlay";
1212
import { LoadingOverlay } from "../common/LoadingOverlay";
1313

‎sandpack-react/src/components/common/Layout.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { useSandpack } from "../../hooks/useSandpack";
55
import { css, THEME_PREFIX } from "../../styles";
66
import { classNames } from "../../utils/classNames";
77
import { useCombinedRefs } from "../CodeEditor/utils";
8-
9-
import { stackClassName } from ".";
8+
import { stackClassName } from "./Stack";
109

1110
/**
1211
* @category Components

‎sandpack-react/src/components/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ export * from "./FileTabs";
55
export * from "./Navigator";
66
export * from "./Preview";
77
export * from "./TranspiledCode";
8-
export * from "./ReactDevTools";
98
export * from "./Tests";
109
export * from "./Console";

‎sandpack-react/src/hooks/useSandpackClient.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import * as React from "react";
88

99
import type { SandpackState } from "../types";
1010
import { generateRandomId } from "../utils/stringUtils";
11-
12-
import { useSandpack } from "./";
11+
import { useSandpack } from "./useSandpack";
1312

1413
interface UseSandpackClient {
1514
sandpack: SandpackState;

‎sandpack-react/src/presets/Sandpack.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("getSandpackCssText", () => {
3333
</SandpackProvider>
3434
);
3535

36-
expect(getSandpackCssText().length).toBe(4343);
36+
expect(getSandpackCssText().length).toBe(4600);
3737
expect(getSandpackCssText()).not.toContain(componentClassName);
3838
});
3939

‎sandpack-react/src/presets/Sandpack.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import * as React from "react";
33

4-
import { SANDBOX_TEMPLATES, SandpackStack } from "..";
54
import type { CodeEditorProps } from "../components/CodeEditor";
65
import { SandpackCodeEditor } from "../components/CodeEditor";
76
import { SandpackConsole } from "../components/Console";
@@ -24,6 +23,8 @@ import type {
2423
SandpackPredefinedTemplate,
2524
} from "../types";
2625
import { classNames } from "../utils/classNames";
26+
import { SandpackStack } from "../components/common";
27+
import { SANDBOX_TEMPLATES } from "../templates";
2728

2829
/**
2930
* @hidden

‎sandpack-themes/build.js

-39
This file was deleted.

‎sandpack-themes/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"clean": "rm -rf dist",
1818
"prebuild": "yarn run clean",
19-
"build": "node build.js && yarn run build:types",
19+
"build": "rollup -c && yarn run build:types",
2020
"build:types": "tsc -p tsconfig.json",
2121
"build:publish": "yarn build",
2222
"typecheck": "tsc"

‎sandpack-themes/rollup.config.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const typescript = require("@rollup/plugin-typescript");
2+
const pkg = require("./package.json");
3+
4+
const configBase = {
5+
input: "src/index.ts",
6+
output: [
7+
{
8+
file: pkg.main,
9+
exports: "named",
10+
format: "cjs",
11+
inlineDynamicImports: true,
12+
interop: "auto",
13+
},
14+
{
15+
file: pkg.module,
16+
exports: "named",
17+
format: "es",
18+
inlineDynamicImports: true,
19+
},
20+
],
21+
22+
plugins: [typescript({ tsconfig: "./tsconfig.json" })],
23+
external: [...Object.keys(pkg.devDependencies)],
24+
};
25+
26+
module.exports = configBase;

‎website/theme/pages/index.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,17 @@ function Library({ setTheme }) {
330330
<>
331331
<Title>Themes</Title>
332332
<PickerContainer>
333-
{Object.entries(themeGallery).map(([label, payload]) => (
334-
<PickerTheme
335-
key={JSON.stringify(payload)}
336-
colors={[payload.colors.accent, payload.colors.surface1]}
337-
label={label}
338-
onClick={() => setTheme(payload)}
339-
/>
340-
))}
333+
{Object.entries(themeGallery).map(([label, payload]) => {
334+
if (!payload.colors) return null;
335+
return (
336+
<PickerTheme
337+
key={JSON.stringify(payload)}
338+
colors={[payload.colors.accent, payload.colors.surface1]}
339+
label={label}
340+
onClick={() => setTheme(payload)}
341+
/>
342+
);
343+
})}
341344
</PickerContainer>
342345
</>
343346
);

‎yarn.lock

+399-6,405
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.