@ast-grep/napi 0.1.0 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -83
- package/index.js +13 -13
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ast-grep/napi
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
> Template project for writing node packages with napi-rs.
|
|
6
|
-
|
|
7
|
-
# Usage
|
|
8
|
-
|
|
9
|
-
1. Click **Use this template**.
|
|
10
|
-
2. **Clone** your project.
|
|
11
|
-
3. Run `yarn install` to install dependencies.
|
|
12
|
-
4. Run `npx napi rename -n [name]` command under the project folder to rename your package.
|
|
13
|
-
|
|
14
|
-
## Install this test package
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
yarn add @napi-rs/package-template
|
|
18
|
-
```
|
|
3
|
+
See https://github.com/HerringtonDarkholme/ast-grep
|
|
19
4
|
|
|
20
5
|
## Support matrix
|
|
21
6
|
|
|
@@ -37,69 +22,3 @@ yarn add @napi-rs/package-template
|
|
|
37
22
|
<!-- | Android armv7 | ✓ | ✓ | ✓ | -->
|
|
38
23
|
<!-- | FreeBSD x64 | ✓ | ✓ | ✓ | -->
|
|
39
24
|
|
|
40
|
-
## Ability
|
|
41
|
-
|
|
42
|
-
### Build
|
|
43
|
-
|
|
44
|
-
After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
|
|
45
|
-
|
|
46
|
-
### Test
|
|
47
|
-
|
|
48
|
-
With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
|
|
49
|
-
|
|
50
|
-
### CI
|
|
51
|
-
|
|
52
|
-
With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@14`, `node@16`, `@node18`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
|
|
53
|
-
|
|
54
|
-
### Release
|
|
55
|
-
|
|
56
|
-
Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
|
|
57
|
-
|
|
58
|
-
With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
|
|
59
|
-
|
|
60
|
-
The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
|
|
61
|
-
|
|
62
|
-
In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
|
|
63
|
-
|
|
64
|
-
`NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
|
|
65
|
-
|
|
66
|
-
## Develop requirements
|
|
67
|
-
|
|
68
|
-
- Install the latest `Rust`
|
|
69
|
-
- Install `Node.js@10+` which fully supported `Node-API`
|
|
70
|
-
- Install `yarn@1.x`
|
|
71
|
-
|
|
72
|
-
## Test in local
|
|
73
|
-
|
|
74
|
-
- yarn
|
|
75
|
-
- yarn build
|
|
76
|
-
- yarn test
|
|
77
|
-
|
|
78
|
-
And you will see:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
$ ava --verbose
|
|
82
|
-
|
|
83
|
-
✔ sync function from native code
|
|
84
|
-
✔ sleep function from native code (201ms)
|
|
85
|
-
─
|
|
86
|
-
|
|
87
|
-
2 tests passed
|
|
88
|
-
✨ Done in 1.12s.
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Release package
|
|
92
|
-
|
|
93
|
-
Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
|
|
94
|
-
|
|
95
|
-
In `Settings -> Secrets`, add **NPM_TOKEN** into it.
|
|
96
|
-
|
|
97
|
-
When you want to release the package:
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
|
|
101
|
-
|
|
102
|
-
git push
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
GitHub actions will do the rest job for you.
|
package/index.js
CHANGED
|
@@ -30,7 +30,7 @@ switch (platform) {
|
|
|
30
30
|
if (localFileExisted) {
|
|
31
31
|
nativeBinding = require('./ast-grep-napi.android-arm64.node')
|
|
32
32
|
} else {
|
|
33
|
-
nativeBinding = require('ast-grep
|
|
33
|
+
nativeBinding = require('@ast-grep/napi-android-arm64')
|
|
34
34
|
}
|
|
35
35
|
} catch (e) {
|
|
36
36
|
loadError = e
|
|
@@ -42,7 +42,7 @@ switch (platform) {
|
|
|
42
42
|
if (localFileExisted) {
|
|
43
43
|
nativeBinding = require('./ast-grep-napi.android-arm-eabi.node')
|
|
44
44
|
} else {
|
|
45
|
-
nativeBinding = require('ast-grep
|
|
45
|
+
nativeBinding = require('@ast-grep/napi-android-arm-eabi')
|
|
46
46
|
}
|
|
47
47
|
} catch (e) {
|
|
48
48
|
loadError = e
|
|
@@ -62,7 +62,7 @@ switch (platform) {
|
|
|
62
62
|
if (localFileExisted) {
|
|
63
63
|
nativeBinding = require('./ast-grep-napi.win32-x64-msvc.node')
|
|
64
64
|
} else {
|
|
65
|
-
nativeBinding = require('ast-grep
|
|
65
|
+
nativeBinding = require('@ast-grep/napi-win32-x64-msvc')
|
|
66
66
|
}
|
|
67
67
|
} catch (e) {
|
|
68
68
|
loadError = e
|
|
@@ -76,7 +76,7 @@ switch (platform) {
|
|
|
76
76
|
if (localFileExisted) {
|
|
77
77
|
nativeBinding = require('./ast-grep-napi.win32-ia32-msvc.node')
|
|
78
78
|
} else {
|
|
79
|
-
nativeBinding = require('ast-grep
|
|
79
|
+
nativeBinding = require('@ast-grep/napi-win32-ia32-msvc')
|
|
80
80
|
}
|
|
81
81
|
} catch (e) {
|
|
82
82
|
loadError = e
|
|
@@ -90,7 +90,7 @@ switch (platform) {
|
|
|
90
90
|
if (localFileExisted) {
|
|
91
91
|
nativeBinding = require('./ast-grep-napi.win32-arm64-msvc.node')
|
|
92
92
|
} else {
|
|
93
|
-
nativeBinding = require('ast-grep
|
|
93
|
+
nativeBinding = require('@ast-grep/napi-win32-arm64-msvc')
|
|
94
94
|
}
|
|
95
95
|
} catch (e) {
|
|
96
96
|
loadError = e
|
|
@@ -108,7 +108,7 @@ switch (platform) {
|
|
|
108
108
|
if (localFileExisted) {
|
|
109
109
|
nativeBinding = require('./ast-grep-napi.darwin-x64.node')
|
|
110
110
|
} else {
|
|
111
|
-
nativeBinding = require('ast-grep
|
|
111
|
+
nativeBinding = require('@ast-grep/napi-darwin-x64')
|
|
112
112
|
}
|
|
113
113
|
} catch (e) {
|
|
114
114
|
loadError = e
|
|
@@ -122,7 +122,7 @@ switch (platform) {
|
|
|
122
122
|
if (localFileExisted) {
|
|
123
123
|
nativeBinding = require('./ast-grep-napi.darwin-arm64.node')
|
|
124
124
|
} else {
|
|
125
|
-
nativeBinding = require('ast-grep
|
|
125
|
+
nativeBinding = require('@ast-grep/napi-darwin-arm64')
|
|
126
126
|
}
|
|
127
127
|
} catch (e) {
|
|
128
128
|
loadError = e
|
|
@@ -141,7 +141,7 @@ switch (platform) {
|
|
|
141
141
|
if (localFileExisted) {
|
|
142
142
|
nativeBinding = require('./ast-grep-napi.freebsd-x64.node')
|
|
143
143
|
} else {
|
|
144
|
-
nativeBinding = require('ast-grep
|
|
144
|
+
nativeBinding = require('@ast-grep/napi-freebsd-x64')
|
|
145
145
|
}
|
|
146
146
|
} catch (e) {
|
|
147
147
|
loadError = e
|
|
@@ -158,7 +158,7 @@ switch (platform) {
|
|
|
158
158
|
if (localFileExisted) {
|
|
159
159
|
nativeBinding = require('./ast-grep-napi.linux-x64-musl.node')
|
|
160
160
|
} else {
|
|
161
|
-
nativeBinding = require('ast-grep
|
|
161
|
+
nativeBinding = require('@ast-grep/napi-linux-x64-musl')
|
|
162
162
|
}
|
|
163
163
|
} catch (e) {
|
|
164
164
|
loadError = e
|
|
@@ -171,7 +171,7 @@ switch (platform) {
|
|
|
171
171
|
if (localFileExisted) {
|
|
172
172
|
nativeBinding = require('./ast-grep-napi.linux-x64-gnu.node')
|
|
173
173
|
} else {
|
|
174
|
-
nativeBinding = require('ast-grep
|
|
174
|
+
nativeBinding = require('@ast-grep/napi-linux-x64-gnu')
|
|
175
175
|
}
|
|
176
176
|
} catch (e) {
|
|
177
177
|
loadError = e
|
|
@@ -187,7 +187,7 @@ switch (platform) {
|
|
|
187
187
|
if (localFileExisted) {
|
|
188
188
|
nativeBinding = require('./ast-grep-napi.linux-arm64-musl.node')
|
|
189
189
|
} else {
|
|
190
|
-
nativeBinding = require('ast-grep
|
|
190
|
+
nativeBinding = require('@ast-grep/napi-linux-arm64-musl')
|
|
191
191
|
}
|
|
192
192
|
} catch (e) {
|
|
193
193
|
loadError = e
|
|
@@ -200,7 +200,7 @@ switch (platform) {
|
|
|
200
200
|
if (localFileExisted) {
|
|
201
201
|
nativeBinding = require('./ast-grep-napi.linux-arm64-gnu.node')
|
|
202
202
|
} else {
|
|
203
|
-
nativeBinding = require('ast-grep
|
|
203
|
+
nativeBinding = require('@ast-grep/napi-linux-arm64-gnu')
|
|
204
204
|
}
|
|
205
205
|
} catch (e) {
|
|
206
206
|
loadError = e
|
|
@@ -215,7 +215,7 @@ switch (platform) {
|
|
|
215
215
|
if (localFileExisted) {
|
|
216
216
|
nativeBinding = require('./ast-grep-napi.linux-arm-gnueabihf.node')
|
|
217
217
|
} else {
|
|
218
|
-
nativeBinding = require('ast-grep
|
|
218
|
+
nativeBinding = require('@ast-grep/napi-linux-arm-gnueabihf')
|
|
219
219
|
}
|
|
220
220
|
} catch (e) {
|
|
221
221
|
loadError = e
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ast-grep/napi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Search and Rewrite code at large scale using precise AST pattern",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/HerringtonDarkholme/ast-grep",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@swc-node/register": "1.5.1",
|
|
48
48
|
"ava": "4.3.3",
|
|
49
49
|
"chalk": "5.0.1",
|
|
50
|
-
"typescript": "4.8.
|
|
50
|
+
"typescript": "4.8.3"
|
|
51
51
|
},
|
|
52
52
|
"ava": {
|
|
53
53
|
"require": [
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
},
|
|
65
65
|
"packageManager": "yarn@3.2.3",
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@ast-grep/napi-win32-x64-msvc": "0.1.
|
|
68
|
-
"@ast-grep/napi-darwin-x64": "0.1.
|
|
69
|
-
"@ast-grep/napi-linux-x64-gnu": "0.1.
|
|
70
|
-
"@ast-grep/napi-win32-ia32-msvc": "0.1.
|
|
71
|
-
"@ast-grep/napi-darwin-arm64": "0.1.
|
|
72
|
-
"@ast-grep/napi-win32-arm64-msvc": "0.1.
|
|
67
|
+
"@ast-grep/napi-win32-x64-msvc": "0.1.4",
|
|
68
|
+
"@ast-grep/napi-darwin-x64": "0.1.4",
|
|
69
|
+
"@ast-grep/napi-linux-x64-gnu": "0.1.4",
|
|
70
|
+
"@ast-grep/napi-win32-ia32-msvc": "0.1.4",
|
|
71
|
+
"@ast-grep/napi-darwin-arm64": "0.1.4",
|
|
72
|
+
"@ast-grep/napi-win32-arm64-msvc": "0.1.4"
|
|
73
73
|
}
|
|
74
74
|
}
|