Skip to content

Commit 3760db8

Browse files
authored
Merge pull request #334 from kamiazya/support-ink3
feat: support ink 3
2 parents 149368e + 7a1a23b commit 3760db8

17 files changed

+2752
-3263
lines changed

.eslintrc.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"useJSXTextNode": true
1111
},
1212
"settings": {
13+
"react": {
14+
"version": "detect"
15+
},
1316
"import/resolver": {
1417
"node": {
1518
"extensions": [
@@ -30,8 +33,9 @@
3033
"airbnb",
3134
"plugin:prettier/recommended",
3235
"plugin:@typescript-eslint/recommended",
33-
"prettier/@typescript-eslint",
34-
"plugin:jest/recommended"
36+
"prettier",
37+
"plugin:jest/recommended",
38+
"plugin:react-hooks/recommended"
3539
],
3640
"rules": {
3741
"prettier/prettier": "error",
@@ -46,6 +50,13 @@
4650
".tsx"
4751
]
4852
}
53+
],
54+
"react/function-component-definition": [
55+
2,
56+
{
57+
"namedComponents": "arrow-function",
58+
"unnamedComponents": "arrow-function"
59+
}
4960
]
5061
}
5162
}

.github/FUNDING.yml

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

.github/dependabot.yml

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

.github/release-drafter.yml

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

.github/workflows/node-ci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ on: [push]
44

55
jobs:
66
test:
7-
name: Test on node ${{ matrix.node-version }} and ${{ matrix.os }}
8-
runs-on: ${{ matrix.os }}
7+
name: Test on node ${{ matrix.node-version }}
8+
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
node-version: [10.x, 12.x]
12-
os: [ubuntu-latest, windows-latest, macos-latest]
11+
node-version: [12.x, 14.x, 16.x]
1312

1413
steps:
1514
- uses: actions/checkout@v1
@@ -43,7 +42,7 @@ jobs:
4342
- uses: actions/checkout@master
4443
- uses: actions/setup-node@v1
4544
with:
46-
node-version: 12.x
45+
node-version: 16.x
4746
registry-url: https://registry.npmjs.org
4847
- name: Install dependencies
4948
run: yarn install --frozen-lockfile --ignore-optional

.github/workflows/release-management.yml

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

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"semi": true,
55
"trailingComma": "all",
66
"printWidth": 120,
7-
"bracketSpacing": true
7+
"bracketSpacing": true,
8+
"endOfLine": "auto"
89
}

package.json

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "ink-highlight",
33
"version": "0.2.1",
4-
"main": "lib/index.js",
5-
"types": "lib/index.d.ts",
4+
"main": "./lib/index.js",
5+
"types": "./lib/index.d.ts",
6+
"exports": {
7+
"import": "./lib/index.mjs",
8+
"require": "./lib/index.js"
9+
},
610
"repository": {
711
"type": "git",
812
"url": "https://github.com/kamiazya/ink-highlight.git"
@@ -36,44 +40,48 @@
3640
"scripts": {
3741
"demo": "ts-node -P demo/tsconfig.json demo/main",
3842
"test": "jest",
39-
"build": "rollup -c",
43+
"build": "rollup -c && prettier --write './lib/index.d.ts'",
4044
"lint": "eslint -c .eslintrc.json --ext ts,tsx src",
4145
"format": "yarn lint --fix"
4246
},
4347
"peerDependencies": {
44-
"ink": "^2.0.0",
45-
"react": "^16.8.0"
48+
"ink": "^3.0.0",
49+
"react": "^17.0.0"
4650
},
4751
"dependencies": {
48-
"cli-highlight": "^2.1.4",
49-
"prop-types": "^15.7.2"
52+
"cli-highlight": "^2.1.11",
53+
"prop-types": "^15.8.1"
5054
},
5155
"devDependencies": {
52-
"@rollup/plugin-typescript": "^4.0.0",
53-
"@types/jest": "^25.1.4",
54-
"@types/prop-types": "^15.7.3",
55-
"@types/react": "^16.9.23",
56-
"@typescript-eslint/eslint-plugin": "^2.22.0",
57-
"@typescript-eslint/parser": "^2.22.0",
58-
"eslint": "^6.8.0",
59-
"eslint-config-airbnb": "^18.0.1",
60-
"eslint-config-prettier": "^6.10.0",
61-
"eslint-plugin-import": "^2.20.1",
62-
"eslint-plugin-jest": "^23.8.2",
63-
"eslint-plugin-jsx-a11y": "^6.2.3",
64-
"eslint-plugin-prettier": "^3.1.2",
65-
"eslint-plugin-react": "^7.19.0",
66-
"ink": "^2.7.1",
67-
"ink-testing-library": "^1.0.3",
68-
"jest": "^25.1.0",
69-
"jest-snapshot-serializer-raw": "^1.1.0",
70-
"prettier": "^1.19.1",
71-
"react": "^16.13.0",
72-
"rollup": "^2.0.2",
73-
"rollup-plugin-terser": "^5.2.0",
74-
"ts-jest": "^25.2.1",
75-
"ts-node": "^8.6.2",
56+
"@rollup/plugin-typescript": "^8.3.1",
57+
"@types/jest": "^27.4.1",
58+
"@types/node": "*",
59+
"@types/prop-types": "^15.7.4",
60+
"@types/react": "^17.0.43",
61+
"@typescript-eslint/eslint-plugin": "^5.18.0",
62+
"@typescript-eslint/parser": "^5.18.0",
63+
"eslint": "^8.12.0",
64+
"eslint-config-airbnb": "^19.0.4",
65+
"eslint-config-prettier": "^8.5.0",
66+
"eslint-plugin-import": "^2.26.0",
67+
"eslint-plugin-jest": "^26.1.3",
68+
"eslint-plugin-jsx-a11y": "^6.5.1",
69+
"eslint-plugin-prettier": "^4.0.0",
70+
"eslint-plugin-react": "^7.29.4",
71+
"eslint-plugin-react-hooks": "^4.3.0",
72+
"ink": "^3.2.0",
73+
"ink-testing-library": "^2.1.0",
74+
"jest": "^27.5.1",
75+
"jest-snapshot-serializer-raw": "^1.2.0",
76+
"prettier": "^2.6.2",
77+
"react": "^17.0.0",
78+
"rollup": "^2.70.1",
79+
"rollup-plugin-delete": "^2.0.0",
80+
"rollup-plugin-dts": "^4.2.0",
81+
"rollup-plugin-terser": "^7.0.2",
82+
"ts-jest": "^27.1.4",
83+
"ts-node": "^10.7.0",
7684
"tslib": "*",
77-
"typescript": "^3.8.3"
85+
"typescript": "^4.6.3"
7886
}
7987
}

rollup.config.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,51 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
import typescript from '@rollup/plugin-typescript';
3+
import del from 'rollup-plugin-delete';
4+
import dts from 'rollup-plugin-dts';
25
import { terser } from 'rollup-plugin-terser';
36

4-
export default {
5-
input: 'src/index.ts',
6-
output: [
7-
{
8-
format: 'cjs',
9-
dir: 'lib',
10-
},
11-
],
12-
plugins: [typescript(), terser()],
13-
external: ['react', 'prop-types', 'ink', 'cli-highlight'],
14-
};
7+
/** @type {import('rollup').RollupOutput[]} */
8+
const options = [
9+
{
10+
input: './src/index.ts',
11+
plugins: [
12+
typescript({
13+
declaration: true,
14+
}),
15+
terser({
16+
format: {
17+
comments: false,
18+
},
19+
}),
20+
],
21+
external: ['react', 'ink', 'prop-types', 'cli-highlight'],
22+
output: [
23+
{
24+
format: 'cjs',
25+
dir: './lib',
26+
},
27+
{
28+
format: 'esm',
29+
file: './lib/index.mjs',
30+
},
31+
],
32+
},
33+
{
34+
input: './lib/index.d.ts',
35+
plugins: [
36+
del({
37+
targets: ['lib/**/*.d.ts', '!lib/index.d.ts'],
38+
hook: 'buildEnd',
39+
}),
40+
dts(),
41+
],
42+
output: [
43+
{
44+
format: 'esm',
45+
file: './lib/index.d.ts',
46+
},
47+
],
48+
},
49+
];
50+
51+
export default options;

src/components/Highlight.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { FC, useContext } from 'react';
2+
import { Text } from 'ink';
23
import PropTypes from 'prop-types';
34
import { highlight } from 'cli-highlight';
45
import { HighlightOptions, HighlightOptionsContext } from './HighlightOptionsContext';
@@ -13,33 +14,29 @@ export const Highlight: FC<Props> = ({ code, ...option }) => {
1314
const contextOption = useContext(HighlightOptionsContext);
1415
const language = option.language !== undefined ? option.language : contextOption.language;
1516
const ignoreIllegals = option.ignoreIllegals !== undefined ? option.ignoreIllegals : contextOption.ignoreIllegals;
16-
const continuation = option.continuation !== undefined ? option.continuation : contextOption.continuation;
1717
const languageSubset = option.languageSubset !== undefined ? option.languageSubset : contextOption.languageSubset;
1818

1919
return (
20-
<>
20+
<Text>
2121
{highlight(code, {
2222
language,
2323
ignoreIllegals,
24-
continuation,
2524
languageSubset,
2625
theme,
2726
})}
28-
</>
27+
</Text>
2928
);
3029
};
3130

3231
Highlight.propTypes = {
3332
code: PropTypes.string.isRequired,
3433
language: PropTypes.string,
3534
ignoreIllegals: PropTypes.bool,
36-
continuation: PropTypes.any,
3735
languageSubset: PropTypes.arrayOf(PropTypes.string.isRequired),
3836
};
3937

4038
Highlight.defaultProps = {
4139
language: undefined,
4240
ignoreIllegals: undefined,
43-
continuation: undefined,
4441
languageSubset: undefined,
4542
};

0 commit comments

Comments
 (0)