Skip to content

Commit d8f888f

Browse files
committed
Finished migration
1 parent 3cff8eb commit d8f888f

14 files changed

Lines changed: 122 additions & 708 deletions

File tree

.eslintrc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"parser": "@babel/eslint-parser",
3+
"parser": "@typescript-eslint/parser",
44
"plugins": ["prettier", "@typescript-eslint"],
55
"settings": {
66
"react": {
@@ -11,7 +11,8 @@
1111
"eslint:recommended",
1212
"plugin:@typescript-eslint/recommended",
1313
"plugin:react/recommended",
14-
"plugin:import/recommended"
14+
"plugin:import/recommended",
15+
"plugin:import/typescript"
1516
],
1617
"env": {
1718
"browser": true,
@@ -54,18 +55,15 @@
5455
"react/no-find-dom-node": "off",
5556
"no-invalid-this": "off",
5657
"complexity": "off",
57-
"no-unused-vars": [
58-
"error",
59-
{
60-
"argsIgnorePattern": "^_+$"
61-
}
62-
],
58+
"no-unused-vars": 0,
6359
"import/no-unresolved": [2, { "ignore": ["polished", "next/document"] }],
6460
"prefer-template": "off",
6561
"filenames/match-regex": "off",
6662
"react/react-in-jsx-scope": "off",
6763
"max-params": ["error", 5],
6864
"max-nested-callbacks": ["error", 5],
69-
"prettier/prettier": "error"
65+
"prettier/prettier": "error",
66+
"@typescript-eslint/no-unused-vars": ["error"],
67+
"@typescript-eslint/no-var-requires": 0
7068
}
7169
}

.github/workflows/code-check.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,27 @@ jobs:
1919
node-version: 18
2020
cache: 'yarn'
2121

22-
- name: Installation
23-
run: yarn --frozen-lockfile
22+
- uses: pnpm/action-setup@v2.2.2
23+
with:
24+
version: 7
2425

25-
- name: Lint
26-
run: yarn lint
26+
- name: Get pnpm store directory
27+
id: pnpm-cache
28+
run: echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
2729

28-
- name: Test
29-
run: yarn run test
30+
- name: Setup pnpm cache
31+
uses: actions/cache@v3
32+
with:
33+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
34+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('./pnpm-lock.yaml') }}
35+
restore-keys: |
36+
${{ runner.os }}-pnpm-store-
3037
31-
- name: Type Check
32-
run: yarn run typecheck
38+
- name: Install dependencies
39+
run: pnpm install
3340

34-
- name: Library Build
35-
run: yarn run build
41+
- name: Check Code ${{ matrix.node-version }}
42+
run: pnpm lint
3643

37-
- name: Storybook Build
38-
run: yarn run storybook:build
44+
- name: Build ${{ matrix.node-version }}
45+
run: pnpm build

.github/workflows/deploy-docs.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,43 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v2
21-
- uses: actions/setup-node@v3
2221
with:
23-
node-version: 16
24-
cache: 'yarn'
22+
fetch-depth: 0
23+
24+
- name: Use Node.js
25+
uses: actions/setup-node@v1
26+
with:
27+
node-version: 18.x
28+
29+
- uses: pnpm/action-setup@v2.2.2
30+
with:
31+
version: 7
32+
33+
- name: Get pnpm store directory
34+
id: pnpm-cache
35+
run: echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
36+
37+
- name: Setup pnpm cache
38+
uses: actions/cache@v3
39+
with:
40+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
41+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42+
restore-keys: |
43+
${{ runner.os }}-pnpm-store-
2544
2645
- name: AWS CLI version
2746
run: "aws --version"
2847

2948
- name: Install Dependencies
30-
run: yarn install --frozen-lockfile
31-
working-directory: ./website
49+
run: pnpm install
50+
working-directory: ./
3251

3352
- name: Build the website
34-
run: yarn build
53+
run: pnpm build
3554
working-directory: ./website
3655

3756
# Use `gh` tool to infer more information about the pull request.
38-
# The underlying issue here is pushes to a non-mergeable/master target branch
57+
# The underlying issue here is pushes to a non-mergeable/main target branch
3958
# don't have the PR number easily available.
4059
# https://stackoverflow.com/a/70102700
4160
- name: Get pull request info
@@ -45,8 +64,8 @@ jobs:
4564
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4665

4766
- name: Deploy docs (production)
48-
if: github.ref == 'refs/heads/master'
49-
run: yarn deploy:prod
67+
if: github.ref == 'refs/heads/main'
68+
run: pnpm run deploy:prod
5069
working-directory: ./website
5170
env:
5271
GITHUB_DEPLOYMENT_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,48 @@ on:
88
jobs:
99
release:
1010
runs-on: ubuntu-latest
11-
permissions:
12-
contents: write
13-
id-token: write
14-
issues: write
15-
repository-projects: write
16-
deployments: write
17-
packages: write
18-
pull-requests: write
1911

2012
steps:
2113
- uses: actions/checkout@v2
22-
- uses: actions/setup-node@v3
2314
with:
24-
node-version: 18
25-
cache: "yarn"
15+
fetch-depth: 0
16+
17+
- name: Use Node.js
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: 18.x
21+
22+
- uses: pnpm/action-setup@v2.2.2
23+
with:
24+
version: 7
25+
26+
- name: Get pnpm store directory
27+
id: pnpm-cache
28+
run: echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
29+
30+
- name: Setup pnpm cache
31+
uses: actions/cache@v3
32+
with:
33+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
34+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
35+
restore-keys: |
36+
${{ runner.os }}-pnpm-store-
2637
2738
- name: Install dependencies
28-
run: yarn install --frozen-lockfile
39+
run: pnpm install
2940

3041
- name: Build packages
31-
run: yarn run build
42+
run: pnpm run build
3243

3344
- name: PR or Publish
3445
id: changesets
3546
uses: changesets/action@v1
3647
with:
37-
version: yarn run version
38-
publish: yarn changeset publish
48+
# Note: Our `package.json:scripts.version` currently doesn't have `--fix-lockfile` for
49+
# `pnpm install` because of a PNPM bug of some kind.
50+
# https://github.com/FormidableLabs/spectacle/issues/1156
51+
version: pnpm run version
52+
publish: pnpm changeset publish
3953
env:
4054
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4155
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"scripts": {
1010
"start:docs": "pnpm run --filter website start",
1111
"build": "pnpm run -r build",
12+
"build:lib": "pnpm run --filter react-live build",
13+
"lint": "pnpm run --parallel lint",
14+
"lint:fix": "pnpm run --parallel lint --fix",
1215
"changeset": "changeset",
1316
"version": "pnpm changeset version && pnpm install --no-frozen-lockfile"
1417
},

packages/react-live/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"test": "jest",
1717
"test:typings": "typings-tester --dir typings",
1818
"typecheck": "tsc --noEmit",
19-
"lint": "eslint --ext .js,.ts,.tsx .",
20-
"lint:fix": "eslint --ext .js,.ts,.tsx . --fix"
19+
"lint": "eslint --ext .js,.ts,.tsx src",
20+
"lint:fix": "eslint --ext .js,.ts,.tsx src --fix"
2121
},
2222
"dependencies": {
2323
"prism-react-renderer": "*",

packages/react-live/src/components/Editor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type Props = {
1010
prism?: typeof Prism;
1111
style?: CSSProperties;
1212
tabMode?: "focus" | "indentation";
13-
theme?: any;
13+
theme?: typeof themes.nightOwl;
1414
onChange?(value: string): void;
1515
};
1616

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Prism from "prismjs";
21
import { Editor } from "../../index";
32
import type { Story } from "@storybook/react";
43

@@ -7,29 +6,28 @@ export default {
76
component: Editor,
87
};
98

10-
const Template = (args: any) => <Editor {...args} />;
9+
const Template = (args: typeof defaultArgs) => <Editor {...args} />;
1110

1211
const defaultArgs = {
1312
language: "js",
1413
code: "const x = 'Hello World!';",
1514
};
1615

17-
export const Default: Story = Template.bind({});
16+
export const Default: Story<typeof defaultArgs> = Template.bind({});
1817
Default.args = defaultArgs;
1918

20-
export const FontFamilyExample: Story = Template.bind({});
21-
FontFamilyExample.args = {
19+
export const FontFamilyExample: Story<typeof fontFamilyArgs> = Template.bind(
20+
{}
21+
);
22+
const fontFamilyArgs = {
2223
...defaultArgs,
2324
style: {
2425
fontFamily: "Monaco",
2526
},
2627
};
28+
FontFamilyExample.args = fontFamilyArgs;
2729

2830
// Can't pass Prism as an arg since it is not JSON-serializable
2931
export const PrismFromNpm = () => (
30-
<Editor
31-
language="javascript"
32-
prism={Prism as any}
33-
code="const x = 'Hello World!';"
34-
/>
32+
<Editor language="javascript" code="const x = 'Hello World!';" />
3533
);

packages/react-live/src/utils/transpile/evalCode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { ComponentType } from "react";
22

3-
const evalCode = (code: string, scope: Record<string, unknown>): ComponentType => {
3+
const evalCode = (
4+
code: string,
5+
scope: Record<string, unknown>
6+
): ComponentType => {
47
const scopeKeys = Object.keys(scope);
58
const scopeValues = scopeKeys.map((key) => scope[key]);
69
return new Function(...scopeKeys, code)(...scopeValues);

packages/react-live/src/utils/transpile/index.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const wrapReturn = (code: string) => `return (${code})`;
1313

1414
type GenerateOptions = {
1515
code: string;
16-
scope?: Record<string, unknown>,
17-
enableTypeScript: boolean
18-
}
16+
scope?: Record<string, unknown>;
17+
enableTypeScript: boolean;
18+
};
1919

2020
export const generateElement = (
2121
{ code = "", scope = {}, enableTypeScript = true }: GenerateOptions,
@@ -29,8 +29,8 @@ export const generateElement = (
2929
* statements in the return.
3030
*/
3131

32-
const firstPassTransforms: Transform[] = ["jsx"]
33-
enableTypeScript && firstPassTransforms.push("typescript")
32+
const firstPassTransforms: Transform[] = ["jsx"];
33+
enableTypeScript && firstPassTransforms.push("typescript");
3434

3535
const transformed = compose<string>(
3636
addJsxConst,
@@ -50,7 +50,7 @@ export const generateElement = (
5050

5151
export const renderElementAsync = (
5252
{ code = "", scope = {}, enableTypeScript = true }: GenerateOptions,
53-
resultCallback: Function,
53+
resultCallback: (...args: unknown[]) => React.ReactNode,
5454
errorCallback: (error: Error) => void
5555
// eslint-disable-next-line consistent-return
5656
) => {
@@ -68,11 +68,8 @@ export const renderElementAsync = (
6868
);
6969
}
7070

71-
const transforms: Transform[] = ["jsx", "imports"]
72-
enableTypeScript && transforms.splice(1, 0, "typescript")
71+
const transforms: Transform[] = ["jsx", "imports"];
72+
enableTypeScript && transforms.splice(1, 0, "typescript");
7373

74-
evalCode(
75-
transform({ transforms })(code),
76-
{ React, ...scope, render }
77-
);
74+
evalCode(transform({ transforms })(code), { React, ...scope, render });
7875
};

0 commit comments

Comments
 (0)