Skip to content

Commit 0b6746a

Browse files
Merge pull request #188 from FormidableLabs/v2-gh-actions-changesets
Add GitHub Actions + Changesets
2 parents 5ad6e2d + 7f69fe3 commit 0b6746a

File tree

7 files changed

+2256
-1166
lines changed

7 files changed

+2256
-1166
lines changed

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": [
4+
"@svitejs/changesets-changelog-github-compact",
5+
{
6+
"repo": "FormidableLabs/prism-react-renderer"
7+
}
8+
],
9+
"access": "public",
10+
"baseBranch": "master"
11+
}

.github/workflows/release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: groqd Release Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: 18
17+
18+
- uses: pnpm/action-setup@v2
19+
with:
20+
version: 8.2.0
21+
- name: Get pnpm store directory
22+
id: pnpm-cache
23+
shell: bash
24+
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
25+
- uses: actions/cache@v3
26+
name: Setup pnpm cache
27+
with:
28+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
29+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
30+
restore-keys: ${{ runner.os }}-pnpm-store-
31+
- name: Install dependencies
32+
run: pnpm install
33+
34+
- name: Build packages
35+
run: pnpm run build
36+
37+
- name: PR or Publish
38+
id: changesets
39+
uses: changesets/action@v1
40+
with:
41+
version: pnpm run version
42+
publish: pnpm run changeset publish
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/static-analysis.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
static-analysis:
12+
name: 'Lint and Type-check'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
20+
- uses: pnpm/action-setup@v2
21+
with:
22+
version: 8.2.0
23+
- name: Get pnpm store directory
24+
id: pnpm-cache
25+
shell: bash
26+
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
27+
- uses: actions/cache@v3
28+
name: Setup pnpm cache
29+
with:
30+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
31+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
32+
restore-keys: ${{ runner.os }}-pnpm-store-
33+
- name: Install dependencies
34+
run: pnpm install
35+
36+
- name: Build library
37+
run: pnpm run build
38+
- name: Type Check
39+
run: pnpm run typecheck
40+
- name: Lint
41+
run: pnpm run lint

.github/workflows/unit-test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Unit Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
matrix:
12+
name: 'Node ${{ matrix.node }}'
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
node: [16, 18]
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: ${{ matrix.node }}
22+
23+
- uses: pnpm/action-setup@v2
24+
with:
25+
version: 8.2.0
26+
- name: Get pnpm store directory
27+
id: pnpm-cache
28+
shell: bash
29+
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
30+
- uses: actions/cache@v3
31+
name: Setup pnpm cache
32+
with:
33+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
34+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
35+
restore-keys: ${{ runner.os }}-pnpm-store-
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Generate language definitions
40+
run: pnpm run build:languages
41+
42+
- name: Unit Test
43+
run: pnpm run test
44+

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
"typecheck": "pnpm run -r typecheck",
1010
"check:ci": "pnpm run typecheck && pnpm run lint && pnpm run test",
1111
"start:demo": "pnpm --filter demo dev",
12-
"build": "pnpm --sequential --filter generate-prism-languages --filter prism-react-renderer --filter demo build",
13-
"build:watch": "pnpm --filter generate-prism-languages build && pnpm --filter prism-react-renderer build:watch"
12+
"build": "pnpm --sequential --filter generate-prism-languages --filter prism-react-renderer build",
13+
"build:languages": "pnpm --filter generate-prism-languages build",
14+
"build:watch": "pnpm --filter generate-prism-languages build && pnpm --filter prism-react-renderer build:watch",
15+
"changeset": "changeset",
16+
"version": "pnpm changeset version && pnpm install"
1417
},
1518
"devDependencies": {
19+
"@changesets/cli": "^2.26.0",
20+
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
1621
"@babel/cli": "^7.10.4",
1722
"@babel/core": "^7.21.4",
1823
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",

packages/prism-react-renderer/src/utils/normalizeTokens.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Token } from "../types"
2-
import type { Token as PrismToken } from "prismjs"
2+
import type { Token as PrismToken, TokenStream } from "prismjs"
33

44
const newlineRe = /\r\n|\r|\n/
55

@@ -33,7 +33,7 @@ const appendTypes = (types: string[], add: string[] | string): string[] => {
3333
// are always of type "plain".
3434
// This is not recursive to avoid exceeding the call-stack limit, since it's unclear
3535
// how nested Prism's tokens can become
36-
const normalizeTokens = (tokens: Array<PrismToken | string>): Token[][] => {
36+
const normalizeTokens = (tokens: (PrismToken | string)[]): Token[][] => {
3737
const typeArrStack: string[][] = [[]]
3838
const tokenArrStack = [tokens]
3939
const tokenArrIndexStack = [0]
@@ -47,7 +47,7 @@ const normalizeTokens = (tokens: Array<PrismToken | string>): Token[][] => {
4747
while (
4848
(i = tokenArrIndexStack[stackIndex]++) < tokenArrSizeStack[stackIndex]
4949
) {
50-
let content: any
50+
let content: TokenStream
5151
let types = typeArrStack[stackIndex]
5252
const tokenArr = tokenArrStack[stackIndex]
5353
const token = tokenArr[i]
@@ -70,7 +70,7 @@ const normalizeTokens = (tokens: Array<PrismToken | string>): Token[][] => {
7070
if (typeof content !== "string") {
7171
stackIndex++
7272
typeArrStack.push(types)
73-
tokenArrStack.push(content)
73+
tokenArrStack.push(content as PrismToken[])
7474
tokenArrIndexStack.push(0)
7575
tokenArrSizeStack.push(content.length)
7676
continue

0 commit comments

Comments
 (0)