Skip to content

Commit 78e7b28

Browse files
committedJul 8, 2024
Vendor bash-parser
1 parent 2679f20 commit 78e7b28

File tree

9 files changed

+142
-81
lines changed

9 files changed

+142
-81
lines changed
 

‎biome.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"**/tmp",
77
"**/fixtures",
88
"packages/knip/package.json",
9+
"packages/knip/vendor/bash-parser/index.js",
910
"packages/docs/.astro"
1011
]
1112
},

‎bun.lockb

-8.56 KB
Binary file not shown.

‎packages/knip/@types/bash-parser/index.d.ts

-76
This file was deleted.

‎packages/knip/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"schema-jsonc.json"
6161
],
6262
"dependencies": {
63-
"@ericcornelissen/bash-parser": "0.5.3",
6463
"@nodelib/fs.walk": "2.0.0",
6564
"@snyk/github-codeowners": "1.1.0",
6665
"easy-table": "1.2.0",

‎packages/knip/src/binaries/bash-parser.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import parse from '@ericcornelissen/bash-parser';
2-
import type { Assignment, ExpansionNode, Node, Prefix } from '@ericcornelissen/bash-parser';
1+
import parse, { type Assignment, type ExpansionNode, type Node, type Prefix } from '../../vendor/bash-parser/index.js';
32
import { debugLogObject } from '../util/debug.js';
43
import { toBinary } from '../util/protocols.js';
54
import * as FallbackResolver from './resolvers/fallback.js';

‎packages/knip/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"exclude": [],
2626
"files": [
2727
"./@types/github-codeowners/index.d.ts",
28-
"./@types/summary/index.d.ts",
29-
"./@types/bash-parser/index.d.ts"
28+
"./@types/summary/index.d.ts"
3029
]
3130
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```sh
2+
git clone git@github.com:ericcornelissen/bash-parser.git
3+
cd bash-parser
4+
npm install
5+
npm run build
6+
npx esbuild src/index.js --outfile=$HOME/p/knip/knip/packages/knip/vendor/bash-parser/index.js --bundle --platform=node --format=esm --tree-shaking=true --minify
7+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
type Name = {
2+
type: string;
3+
text: string;
4+
};
5+
6+
type CompoundList = {
7+
type: 'CompoundList';
8+
commands: Command[];
9+
};
10+
11+
type Command = {
12+
type: 'Command';
13+
name?: Name;
14+
suffix: Name[];
15+
prefix?: Prefix[];
16+
};
17+
18+
export type Prefix = ExpansionNode | Assignment;
19+
20+
type LogicalExpression = {
21+
type: 'LogicalExpression';
22+
left: Command;
23+
right: Command;
24+
};
25+
26+
type If = {
27+
type: 'If';
28+
clause: Node;
29+
then: Node;
30+
else?: Node;
31+
};
32+
33+
type For = {
34+
type: 'For';
35+
name: Name;
36+
wordlist: Name[];
37+
do: CompoundList;
38+
};
39+
40+
type Function_ = {
41+
type: 'Function';
42+
name: Name;
43+
body: CompoundList;
44+
};
45+
46+
export type ExpansionNode = {
47+
expansion: Expansion[];
48+
};
49+
50+
type Expansion = {
51+
type: 'CommandExpansion';
52+
commandAST: AST;
53+
};
54+
55+
type Pipeline = {
56+
type: 'Pipeline';
57+
commands: Command[];
58+
};
59+
60+
export type Assignment = {
61+
type: 'AssignmentWord';
62+
text: string;
63+
};
64+
65+
export type Node = CompoundList | Command | LogicalExpression | If | For | Function_ | Pipeline;
66+
67+
export type AST = {
68+
type: 'Script';
69+
commands: Node[];
70+
};
71+
72+
declare const parse: (s: string) => AST;
73+
74+
export default parse;

‎packages/knip/vendor/bash-parser/index.js

+58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.