Skip to content

Commit 86e0fdf

Browse files
authored
Merge pull request #166 from code-hike/next
v0.4.0
2 parents 0ffc295 + 374d73d commit 86e0fdf

File tree

291 files changed

+15570
-17953
lines changed

Some content is hidden

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

291 files changed

+15570
-17953
lines changed

.github/workflows/bundle_analysis.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: 'Bundle Analysis'
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- next # change this if your default branch is named differently
8+
workflow_dispatch:
9+
10+
defaults:
11+
run:
12+
# change this if your nextjs app does not live at the root of the repo
13+
working-directory: .
14+
15+
jobs:
16+
analyze:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Use Node.js 14.x
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 14.x
25+
26+
- name: Cache node modules
27+
uses: actions/cache@v1
28+
with:
29+
path: node_modules
30+
key: yarn-deps-${{ hashFiles('yarn.lock') }}
31+
restore-keys: |
32+
yarn-deps-${{ hashFiles('yarn.lock') }}
33+
34+
- name: Build library
35+
run: |
36+
yarn install --frozen-lockfile 2>&1 | grep -v '^[warning|info]'
37+
yarn build:lib
38+
39+
- name: Restore next build
40+
uses: actions/cache@v2
41+
id: restore-build-cache
42+
env:
43+
cache-name: cache-next-build
44+
with:
45+
# if you use a custom build directory, replace all instances of `.next` in this file with your build directory
46+
# ex: if your app builds to `dist`, replace `.next` with `dist`
47+
path: ./examples/bundle-test/.next/cache
48+
# change this if you prefer a more strict cache
49+
key: ${{ runner.os }}-build-${{ env.cache-name }}
50+
51+
- name: Build next.js app
52+
working-directory: ./examples/bundle-test
53+
# change this if your site requires a custom build command
54+
run: yarn build
55+
56+
# Here's the first place where next-bundle-analysis' own script is used
57+
# This step pulls the raw bundle stats for the current bundle
58+
- name: Analyze bundle
59+
working-directory: ./examples/bundle-test
60+
run: npx -p nextjs-bundle-analysis report
61+
62+
- name: Upload bundle
63+
uses: actions/upload-artifact@v2
64+
with:
65+
name: bundle
66+
path: ./examples/bundle-test/.next/analyze/__bundle_analysis.json
67+
68+
- name: Download base branch bundle stats
69+
uses: dawidd6/action-download-artifact@v2
70+
if: success() && github.event.number
71+
with:
72+
workflow: bundle_analysis.yml
73+
branch: ${{ github.event.pull_request.base.ref }}
74+
path: ./examples/bundle-test/.next/analyze/base
75+
76+
# And here's the second place - this runs after we have both the current and
77+
# base branch bundle stats, and will compare them to determine what changed.
78+
# There are two configurable arguments that come from package.json:
79+
#
80+
# - budget: optional, set a budget (bytes) against which size changes are measured
81+
# it's set to 350kb here by default, as informed by the following piece:
82+
# https://infrequently.org/2021/03/the-performance-inequality-gap/
83+
#
84+
# - red-status-percentage: sets the percent size increase where you get a red
85+
# status indicator, defaults to 20%
86+
#
87+
# Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
88+
# entry in your package.json file.
89+
- name: Compare with base branch bundle
90+
working-directory: ./examples/bundle-test
91+
if: success() && github.event.number
92+
run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
93+
94+
- name: Get comment body
95+
working-directory: ./examples/bundle-test
96+
id: get-comment-body
97+
if: success() && github.event.number
98+
run: |
99+
body=$(cat .next/analyze/__bundle_analysis_comment.txt)
100+
body="${body//'%'/'%25'}"
101+
body="${body//$'\n'/'%0A'}"
102+
body="${body//$'\r'/'%0D'}"
103+
echo ::set-output name=body::$body
104+
105+
- name: Find Comment
106+
uses: peter-evans/find-comment@v1
107+
if: success() && github.event.number
108+
id: fc
109+
with:
110+
issue-number: ${{ github.event.number }}
111+
body-includes: '<!-- __NEXTJS_BUNDLE -->'
112+
113+
- name: Create Comment
114+
uses: peter-evans/[email protected]
115+
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
116+
with:
117+
issue-number: ${{ github.event.number }}
118+
body: ${{ steps.get-comment-body.outputs.body }}
119+
120+
- name: Update Comment
121+
uses: peter-evans/[email protected]
122+
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
123+
with:
124+
issue-number: ${{ github.event.number }}
125+
body: ${{ steps.get-comment-body.outputs.body }}
126+
comment-id: ${{ steps.fc.outputs.comment-id }}
127+
edit-mode: replace

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ jobs:
99
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
1010
steps:
1111
- uses: actions/checkout@v2
12-
with:
13-
fetch-depth: 10 # 👈 Required to retrieve git history
1412

1513
- name: Prepare repository
1614
run: git fetch --unshallow --tags
@@ -35,6 +33,7 @@ jobs:
3533
run: |
3634
yarn install --frozen-lockfile 2>&1 | grep -v '^[warning|info]'
3735
yarn build
36+
yarn test
3837
yarn release
3938
# - name: Publish to Chromatic
4039
# uses: chromaui/action@v1

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ yarn-error.log
99
.vscode
1010
storybook-static
1111
packages/playground/out
12-
packages/starter
12+
packages/starter
13+
14+
# Contentlayer
15+
.contentlayer

.gitpod.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": false,
3+
"overrides": [
4+
{
5+
"files": "*.md",
6+
"options": {
7+
"parser": "mdx"
8+
}
9+
}
10+
]
11+
}

examples/browser/index.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Code Hike in the browser</title>
5+
<link
6+
rel="stylesheet"
7+
href="https://esm.sh/@code-hike/[email protected]/dist/index.css"
8+
/>
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
13+
<script type="module">
14+
import React from "https://esm.sh/react"
15+
import ReactDOM from "https://esm.sh/react-dom"
16+
import { evaluate } from "https://esm.sh/@mdx-js/mdx?dev"
17+
import * as runtime from "https://esm.sh/react/jsx-runtime.js"
18+
19+
import { remarkCodeHike } from "https://esm.sh/@code-hike/[email protected]/dist/index.browser.mjs"
20+
import { CH } from "https://esm.sh/@code-hike/[email protected]/components"
21+
import theme from "https://esm.sh/[email protected]/themes/nord.json" assert { type: "json" }
22+
23+
const mdx = `# Test
24+
25+
~~~python hello.py mark=1[22:30]
26+
print("Rendered with Code Hike")
27+
~~~
28+
`
29+
30+
const { default: Content } = await evaluate(mdx, {
31+
...runtime,
32+
remarkPlugins: [[remarkCodeHike, { autoImport: false, theme }]],
33+
})
34+
35+
const App = () => {
36+
return React.createElement(Content, { components: { CH } })
37+
}
38+
39+
ReactDOM.render(React.createElement(App), document.getElementById("root"))
40+
</script>
41+
</body>
42+
</html>

examples/bundle-test/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.next

examples/bundle-test/next.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { remarkCodeHike } = require("@code-hike/mdx")
2+
const theme = require("shiki/themes/nord.json")
3+
4+
const withMDX = require("@next/mdx")({
5+
extension: /\.mdx?$/,
6+
options: {
7+
remarkPlugins: [[remarkCodeHike, { theme }]],
8+
},
9+
})
10+
11+
module.exports = withMDX({
12+
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
13+
})

examples/bundle-test/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "bundle-test",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "next",
7+
"build": "next build"
8+
},
9+
"dependencies": {
10+
"@code-hike/mdx": "^0.3.0",
11+
"@mdx-js/loader": "^2.0.0",
12+
"@next/mdx": "^12.1.0",
13+
"next": "^12.1.0",
14+
"react": "^17.0.2",
15+
"react-dom": "^17.0.2"
16+
},
17+
"nextBundleAnalysis": {
18+
"budget": 358400,
19+
"budgetPercentIncreaseRed": 20,
20+
"showDetails": true,
21+
"minimumChangeThreshold": 0
22+
}
23+
}

examples/bundle-test/pages/_app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "@code-hike/mdx/styles"
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp

examples/bundle-test/pages/js-page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Page() {
2+
return (
3+
<div>
4+
<h1>Hello</h1>
5+
Lorem ipsum dolor sit amet. Consectetur adipiscing elit.
6+
</div>
7+
)
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Hello world
2+
3+
```js focus=2,4[10:13]
4+
function lorem(ipsum, dolor = 1) {
5+
const sit = ipsum == null ? 0 : ipsum.sit
6+
dolor = sit - amet(dolor)
7+
return sit ? consectetur(ipsum) : []
8+
}
9+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Hello
2+
3+
Lorem ipsum dolor sit amet. Consectetur adipiscing elit.

0 commit comments

Comments
 (0)