@ohos-ports/contrast-agent-swc-plugin 0.0.0-stage → 3.4.0-beta.0
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/LICENSE +12 -0
- package/README.md +93 -2
- package/index.js +24 -0
- package/methods.js +15 -0
- package/package.json +43 -4
- package/rewriter.wasm +0 -0
- package/unwriter.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright: 2026 Contrast Security, Inc
|
|
2
|
+
Contact: support@contrastsecurity.com
|
|
3
|
+
License: Commercial
|
|
4
|
+
|
|
5
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
6
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
7
|
+
made available through public repositories, use of this Software is subject to
|
|
8
|
+
the applicable End User Licensing Agreement found at
|
|
9
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
10
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
11
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
12
|
+
way not consistent with the End User License Agreement.
|
package/README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Contrast Node Agent v5 swc plugins
|
|
2
|
+
|
|
3
|
+
[`swc`](https://swc.rs) plugins for the Node agent's swc rewriter.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
These plugins are designed to be used programmatically from `@swc/core`.
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const { transformSync } = require('@swc/core');
|
|
11
|
+
const {
|
|
12
|
+
defaultRewriter,
|
|
13
|
+
defaultUnwriter,
|
|
14
|
+
// this is not being built or released until a need arises
|
|
15
|
+
//noPropagationRewriter
|
|
16
|
+
} = require('@contrast/agent-swc-plugin');
|
|
17
|
+
|
|
18
|
+
const result = transformSync(src, {
|
|
19
|
+
env: {
|
|
20
|
+
targets: {
|
|
21
|
+
node: '18', // specify your (lowest) node version
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
jsc: {
|
|
25
|
+
experimental: {
|
|
26
|
+
plugins: [[defaultRewriter, { assess: true, inject: true }]],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Setup
|
|
33
|
+
|
|
34
|
+
See: https://swc.rs/docs/plugin/ecmascript/getting-started
|
|
35
|
+
|
|
36
|
+
### Install `rust`
|
|
37
|
+
|
|
38
|
+
https://www.rust-lang.org/tools/install
|
|
39
|
+
|
|
40
|
+
### Toolchain and `wasm` target
|
|
41
|
+
|
|
42
|
+
`rust-toolchain.toml` pins the Rust version and the `wasm32-wasip1` target, so
|
|
43
|
+
rustup installs both on the first `cargo` command in this repo.
|
|
44
|
+
|
|
45
|
+
https://blog.rust-lang.org/2024/04/09/updates-to-rusts-wasi-targets.html
|
|
46
|
+
|
|
47
|
+
### Install and test
|
|
48
|
+
|
|
49
|
+
`cargo test` runs the Rust fixture tests for the rewriter and unwriter. Set
|
|
50
|
+
`UPDATE=1` to regenerate fixture outputs after an intended change.
|
|
51
|
+
`npm test` builds the release wasm and runs the JavaScript integration tests
|
|
52
|
+
against it through `@swc/core`.
|
|
53
|
+
|
|
54
|
+
### Building
|
|
55
|
+
|
|
56
|
+
To build release-ready targets, either run `npm run build` or
|
|
57
|
+
`cargo build --release --target wasm32-wasip1`.
|
|
58
|
+
|
|
59
|
+
### Benchmarks
|
|
60
|
+
|
|
61
|
+
Pull requests run a comparison job that benchmarks the PR against its base.
|
|
62
|
+
Native transforms run under Valgrind, which reports instruction counts with
|
|
63
|
+
Callgrind and heap usage with DHAT. The wasm plugins are timed through
|
|
64
|
+
`@swc/core` by `scripts/compare.js`. Each side builds against its own
|
|
65
|
+
`swc_core` and runs on the `@swc/core` from its own `package-lock.json`, so a PR
|
|
66
|
+
that upgrades swc is compared against what main actually ships. In that case
|
|
67
|
+
the wasm numbers include the host upgrade, not only the plugin change.
|
|
68
|
+
|
|
69
|
+
Valgrind doesn't run on macOS, so the same comparison can run locally in Docker.
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
scripts/bench-docker.sh [base-ref]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This compares the working tree, including uncommitted changes, against
|
|
76
|
+
`base-ref` (default `origin/main`). The container config is in
|
|
77
|
+
`scripts/bench.Dockerfile`. Linux builds and `node_modules` live in Docker
|
|
78
|
+
volumes named `swc-plugins-bench-*`, so they don't touch your local checkout
|
|
79
|
+
and later runs are incremental. The container runs with
|
|
80
|
+
`--security-opt seccomp=unconfined` because gungraun needs to disable ASLR,
|
|
81
|
+
which Docker's default seccomp profile blocks.
|
|
82
|
+
|
|
83
|
+
## Releasing
|
|
84
|
+
|
|
85
|
+
Run `npm version <major|minor|patch>` to bump the version. Push the changes
|
|
86
|
+
and tag to the repo.
|
|
87
|
+
|
|
88
|
+
When the version bump is merged to main, invoke the `release` workflow using
|
|
89
|
+
either the GitHub UI or the `gh` CLI program.
|
|
90
|
+
|
|
91
|
+
Publishing uses npm trusted publishing from `release.yaml` in the `npm-publish`
|
|
92
|
+
GitHub environment. Renaming the workflow file or the environment breaks
|
|
93
|
+
publishing until the trusted publisher on npmjs.com is updated.
|
|
2
94
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2026 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const rewriter = require.resolve('./rewriter.wasm');
|
|
17
|
+
const unwriter = require.resolve('./unwriter.wasm');
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
rewriter,
|
|
21
|
+
unwriter,
|
|
22
|
+
defaultRewriter: rewriter,
|
|
23
|
+
defaultUnwriter: unwriter,
|
|
24
|
+
};
|
package/methods.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/contrast-agent-swc-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.4.0-beta.0",
|
|
4
|
+
"description": "SWC plugins Contrast Node agent",
|
|
5
|
+
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"swc-plugin"
|
|
9
|
+
],
|
|
10
|
+
"main": "index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"methods.js",
|
|
14
|
+
"*.wasm"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "cargo build --workspace --release --target wasm32-wasip1",
|
|
18
|
+
"clean": "cargo clean && rimraf .swc/ *.wasm",
|
|
19
|
+
"pretest": "npm run build && npm run prepack && rimraf .swc/",
|
|
20
|
+
"test": "mocha",
|
|
21
|
+
"prepack": "cp target/wasm32-wasip1/release/*.wasm ."
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@ohos-ports/swc-core": "~1.16.22-beta.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@swc/core": "^1.16.18",
|
|
28
|
+
"@tsconfig/node16": "16.1.4",
|
|
29
|
+
"chai": "^5.2.1",
|
|
30
|
+
"express": "5.1.0",
|
|
31
|
+
"lodash": "4.17.21",
|
|
32
|
+
"mocha": "^11.7.1",
|
|
33
|
+
"rimraf": "^6.0.1",
|
|
34
|
+
"source-map": "^0.7.4",
|
|
35
|
+
"typescript": "5.8.3"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
40
|
+
"directory": "ports/contrast-agent-swc-plugin/3.4.0"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/rewriter.wasm
ADDED
|
Binary file
|
package/unwriter.wasm
ADDED
|
Binary file
|