@contrast/agent-bundle 5.40.0 → 5.41.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/node_modules/@contrast/agent/package.json +11 -11
- package/node_modules/@contrast/agent-swc-plugin/index.js +9 -3
- package/node_modules/@contrast/agent-swc-plugin/methods.js +15 -1
- package/node_modules/@contrast/agent-swc-plugin/package.json +5 -8
- package/node_modules/@contrast/agent-swc-plugin/rewriter.wasm +0 -0
- package/node_modules/@contrast/agentify/lib/index.js +2 -2
- package/node_modules/@contrast/agentify/package.json +15 -14
- package/node_modules/@contrast/architecture-components/package.json +5 -5
- package/node_modules/@contrast/assess/lib/dataflow/propagation/install/util-format.js +44 -21
- package/node_modules/@contrast/assess/lib/dataflow/sources/install/body-parser.js +1 -1
- package/node_modules/@contrast/assess/lib/dataflow/sources/install/koa/koa-bodyparsers.js +3 -1
- package/node_modules/@contrast/assess/lib/dataflow/sources/install/qs6.js +5 -5
- package/node_modules/@contrast/assess/lib/dataflow/sources/install/querystring.js +2 -1
- package/node_modules/@contrast/assess/lib/index.d.ts +0 -1
- package/node_modules/@contrast/assess/lib/make-source-context.js +7 -37
- package/node_modules/@contrast/assess/lib/sampler/common.js +7 -11
- package/node_modules/@contrast/assess/package.json +12 -11
- package/node_modules/@contrast/common/lib/types.d.ts +7 -1
- package/node_modules/@contrast/common/package.json +1 -1
- package/node_modules/@contrast/config/lib/common.js +1 -1
- package/node_modules/@contrast/config/lib/config.js +49 -27
- package/node_modules/@contrast/config/lib/index.d.ts +2 -2
- package/node_modules/@contrast/config/lib/options.js +4 -4
- package/node_modules/@contrast/config/package.json +4 -3
- package/node_modules/@contrast/core/lib/sensitive-data-masking/protect-listener.js +15 -15
- package/node_modules/@contrast/core/package.json +6 -6
- package/node_modules/@contrast/deadzones/package.json +5 -5
- package/node_modules/@contrast/dep-hooks/package.json +3 -3
- package/node_modules/@contrast/esm-hooks/package.json +6 -6
- package/node_modules/@contrast/instrumentation/lib/index.js +0 -1
- package/node_modules/@contrast/instrumentation/package.json +5 -5
- package/node_modules/@contrast/library-analysis/lib/install/library-reporting/dep.json +298 -148
- package/node_modules/@contrast/library-analysis/package.json +4 -4
- package/node_modules/@contrast/logger/lib/serializers.js +2 -2
- package/node_modules/@contrast/logger/package.json +3 -3
- package/node_modules/@contrast/metrics/package.json +6 -6
- package/node_modules/@contrast/patcher/package.json +2 -2
- package/node_modules/@contrast/protect/lib/get-source-context.js +3 -1
- package/node_modules/@contrast/protect/lib/index.js +6 -1
- package/node_modules/@contrast/protect/lib/input-analysis/handlers.js +7 -9
- package/node_modules/@contrast/protect/lib/input-analysis/install/http.js +18 -19
- package/node_modules/@contrast/protect/lib/input-analysis/install/qs6.js +18 -17
- package/node_modules/@contrast/protect/lib/input-analysis/install/universal-cookie4.js +2 -3
- package/node_modules/@contrast/protect/lib/make-source-context.js +22 -66
- package/node_modules/@contrast/protect/lib/semantic-analysis/handlers.js +73 -72
- package/node_modules/@contrast/protect/package.json +11 -11
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/index.js +7 -7
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.d.ts +3 -3
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/application-activity/translations.js +24 -21
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/index.js +1 -1
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/translations.d.ts +1 -2
- package/node_modules/@contrast/reporter/lib/reporters/contrast-ui/endpoints/traces/translations.js +8 -2
- package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.d.ts +2 -2
- package/node_modules/@contrast/reporter/lib/reporters/security-logger/index.js +22 -20
- package/node_modules/@contrast/reporter/package.json +7 -7
- package/node_modules/@contrast/rewriter/lib/index.js +2 -2
- package/node_modules/@contrast/rewriter/package.json +6 -6
- package/node_modules/@contrast/route-coverage/lib/index.js +1 -9
- package/node_modules/@contrast/route-coverage/lib/install/express/express5.js +17 -19
- package/node_modules/@contrast/route-coverage/package.json +8 -8
- package/node_modules/@contrast/scopes/package.json +5 -5
- package/node_modules/@contrast/sec-obs/lib/traces/http.js +2 -2
- package/node_modules/@contrast/sec-obs/lib/traces/http.test.js +17 -0
- package/node_modules/@contrast/sec-obs/lib/traces/outbound-service-call.js +2 -2
- package/node_modules/@contrast/sec-obs/lib/traces/outbound-service-call.test.js +17 -0
- package/node_modules/@contrast/sec-obs/package.json +9 -9
- package/node_modules/@contrast/sources/lib/index.js +109 -0
- package/node_modules/@contrast/sources/lib/index.test.js +120 -0
- package/node_modules/@contrast/{route-coverage/lib/normalized-url-mapper.js → sources/lib/normalized-uri-mapper.js} +10 -3
- package/node_modules/@contrast/sources/lib/normalized-uri-mapper.test.js +59 -0
- package/node_modules/@contrast/{sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/constants.js → sources/lib/req-data.js} +0 -6
- package/node_modules/@contrast/sources/lib/source-info.js +183 -0
- package/node_modules/@contrast/sources/lib/source-info.test.js +68 -0
- package/node_modules/@contrast/sources/package.json +16 -0
- package/node_modules/@contrast/telemetry/package.json +6 -6
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.d.ts +2831 -77
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js +2831 -77
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.d.ts +415 -98
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js +415 -98
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.d.ts +106 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js +106 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.d.ts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.d.ts +2831 -77
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js +2831 -77
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.d.ts +415 -98
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js +415 -98
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.d.ts +106 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js +106 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.d.ts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.d.ts +2831 -77
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js +2858 -103
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.d.ts +415 -98
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js +420 -102
- package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.d.ts +106 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js +106 -0
- package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/version.d.ts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/package.json +3 -3
- package/node_modules/@types/node/README.md +2 -2
- package/node_modules/@types/node/fs.d.ts +13 -1
- package/node_modules/@types/node/http.d.ts +4 -19
- package/node_modules/@types/node/inspector.d.ts +53 -0
- package/node_modules/@types/node/package.json +2 -82
- package/node_modules/axios/CHANGELOG.md +17 -0
- package/node_modules/axios/README.md +1 -4
- package/node_modules/axios/dist/axios.js +39 -5
- package/node_modules/axios/dist/axios.js.map +1 -1
- package/node_modules/axios/dist/axios.min.js +2 -2
- package/node_modules/axios/dist/axios.min.js.map +1 -1
- package/node_modules/axios/dist/browser/axios.cjs +46 -9
- package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
- package/node_modules/axios/dist/esm/axios.js +46 -9
- package/node_modules/axios/dist/esm/axios.js.map +1 -1
- package/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/node_modules/axios/dist/node/axios.cjs +46 -9
- package/node_modules/axios/dist/node/axios.cjs.map +1 -1
- package/node_modules/axios/index.d.cts +13 -2
- package/node_modules/axios/lib/core/Axios.js +2 -2
- package/node_modules/axios/lib/core/mergeConfig.js +1 -1
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/throttle.js +1 -1
- package/node_modules/axios/lib/helpers/toURLEncodedForm.js +4 -3
- package/node_modules/axios/lib/utils.js +36 -0
- package/node_modules/axios/package.json +5 -5
- package/node_modules/deepmerge/.editorconfig +7 -0
- package/node_modules/deepmerge/.eslintcache +1 -0
- package/node_modules/deepmerge/changelog.md +167 -0
- package/node_modules/deepmerge/dist/cjs.js +133 -0
- package/node_modules/deepmerge/dist/umd.js +139 -0
- package/node_modules/deepmerge/index.d.ts +20 -0
- package/node_modules/deepmerge/index.js +106 -0
- package/node_modules/deepmerge/license.txt +21 -0
- package/node_modules/deepmerge/package.json +42 -0
- package/node_modules/deepmerge/readme.md +264 -0
- package/node_modules/deepmerge/rollup.config.js +22 -0
- package/node_modules/follow-redirects/package.json +1 -1
- package/node_modules/form-data/CHANGELOG.md +601 -0
- package/node_modules/form-data/{Readme.md → README.md} +4 -4
- package/node_modules/form-data/lib/form_data.js +2 -6
- package/node_modules/form-data/package.json +22 -6
- package/node_modules/nan/.github/workflows/ci.yml +8 -10
- package/node_modules/nan/.pre-commit-config.yaml +8 -0
- package/node_modules/nan/CHANGELOG.md +5 -1
- package/node_modules/nan/README.md +4 -4
- package/node_modules/nan/nan.h +16 -12
- package/node_modules/nan/nan_callbacks.h +13 -0
- package/node_modules/nan/nan_callbacks_12_inl.h +16 -2
- package/node_modules/nan/nan_callbacks_pre_12_inl.h +6 -2
- package/node_modules/nan/nan_maybe_43_inl.h +1 -1
- package/node_modules/nan/nan_maybe_pre_43_inl.h +1 -1
- package/node_modules/nan/nan_scriptorigin.h +11 -9
- package/node_modules/nan/nan_typedarray_contents.h +1 -1
- package/node_modules/nan/package.json +2 -2
- package/package.json +2 -2
- package/node_modules/@contrast/agentify/lib/sources.js +0 -95
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/constants.d.ts +0 -385
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/constants.js +0 -270
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/index.d.ts +0 -40
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/index.js +0 -228
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/primordials.d.ts +0 -65
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/primordials.js +0 -66
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/types.d.ts +0 -383
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/lib/types.js +0 -30
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/common/package.json +0 -23
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/README.md +0 -44
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/common.js +0 -131
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/config.js +0 -290
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/index.d.ts +0 -328
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/index.js +0 -29
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/options.js +0 -836
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/lib/validators.js +0 -23
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/config/package.json +0 -27
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/README.md +0 -98
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/agent-info.js +0 -36
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/app-info.js +0 -233
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/build-id.js +0 -51
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/capture-stacktrace.js +0 -256
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/contrast-methods.js +0 -155
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/index.d.ts +0 -52
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/ioc/core.js +0 -95
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/is-agent-path.js +0 -37
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/messages.js +0 -28
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/index.js +0 -63
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/protect-listener.js +0 -111
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/sensitive-data-masking/server-settings-listener.js +0 -44
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/cloud-provider-metadata.js +0 -146
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/index.js +0 -225
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/linux-os-info.js +0 -137
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/lib/system-info/utils.js +0 -35
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/core/package.json +0 -33
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/README.md +0 -94
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-handler-registry.d.ts +0 -121
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-handler-registry.js +0 -206
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.d.ts +0 -72
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/export-hook-descriptor.js +0 -88
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/handler-invoker.d.ts +0 -46
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/handler-invoker.js +0 -106
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/helpers.d.ts +0 -28
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/helpers.js +0 -66
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/index.d.ts +0 -115
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/index.js +0 -208
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/package-finder.d.ts +0 -43
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/lib/package-finder.js +0 -79
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/dep-hooks/package.json +0 -29
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/README.md +0 -270
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/index.d.ts +0 -16
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/index.js +0 -132
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/serializers.d.ts +0 -33
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/serializers.js +0 -75
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/utils.d.ts +0 -15
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/lib/utils.js +0 -34
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/logger/package.json +0 -28
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/README.md +0 -51
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/lib/index.d.ts +0 -101
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/lib/index.js +0 -544
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/patcher/package.json +0 -25
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/README.md +0 -6
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/lib/cache.js +0 -318
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/lib/index.js +0 -216
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/lib/rewrite-is-deadzoned.js +0 -143
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/rewriter/package.json +0 -30
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/LICENSE +0 -12
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/constants.js +0 -26
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/index.d.ts +0 -46
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/index.js +0 -70
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/bluebird.js +0 -128
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/index.js +0 -34
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb-core.js +0 -83
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb3.js +0 -89
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb4.js +0 -80
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mongodb6.js +0 -46
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/mysql.js +0 -151
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/install/redis.js +0 -79
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/lib/utils.js +0 -35
- package/node_modules/@contrast/sec-obs/node_modules/@contrast/scopes/package.json +0 -28
- package/node_modules/form-data/README.md.bak +0 -355
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@contrast/patcher",
|
|
3
|
-
"version": "1.25.0",
|
|
4
|
-
"description": "Advanced monkey patching--registers hooks to run in and around functions",
|
|
5
|
-
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
-
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
7
|
-
"files": [
|
|
8
|
-
"lib/",
|
|
9
|
-
"!*.test.*",
|
|
10
|
-
"!tsconfig.*",
|
|
11
|
-
"!*.map"
|
|
12
|
-
],
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"types": "lib/index.d.ts",
|
|
15
|
-
"engines": {
|
|
16
|
-
"npm": ">=6.13.7 <7 || >= 8.3.1",
|
|
17
|
-
"node": ">= 16.9.1"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"test": "bash ../scripts/test.sh"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@contrast/logger": "1.26.0"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Copyright: 2025 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.
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright: 2025 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
|
-
// @ts-nocheck
|
|
16
|
-
'use strict';
|
|
17
|
-
|
|
18
|
-
const fs = require('node:fs');
|
|
19
|
-
const fsPromises = require('node:fs/promises');
|
|
20
|
-
const os = require('node:os');
|
|
21
|
-
const path = require('node:path');
|
|
22
|
-
const { version } = require('../package.json');
|
|
23
|
-
const { primordials: { StringPrototypeReplace, StringPrototypeReplaceAll, FsReadFileSync } } = require('@contrast/common');
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Returns the modification time of a file as a number.
|
|
27
|
-
* @param {string} filename
|
|
28
|
-
* @returns {Promise<number>}
|
|
29
|
-
*/
|
|
30
|
-
const mtime = async (filename) => +(await fsPromises.stat(filename)).mtime;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns the modification time of a file as a number.
|
|
34
|
-
* @param {string} filename
|
|
35
|
-
* @returns {number}
|
|
36
|
-
*/
|
|
37
|
-
const mtimeSync = (filename) => +fs.statSync(filename).mtime;
|
|
38
|
-
|
|
39
|
-
module.exports.Cache = class Cache {
|
|
40
|
-
/**
|
|
41
|
-
* @param {import('.').Core} core
|
|
42
|
-
*/
|
|
43
|
-
constructor(core) {
|
|
44
|
-
this.config = core.config;
|
|
45
|
-
this.logger = core.logger.child({ name: 'contrast:rewriter:cache' });
|
|
46
|
-
/** @type {Set<import('.').Mode>} */
|
|
47
|
-
this.modes = new Set();
|
|
48
|
-
this.appDirRegex = new RegExp(`^${StringPrototypeReplaceAll.call(core.appInfo.app_dir, '\\', '\\\\')}`);
|
|
49
|
-
this.cacheDir = path.join(
|
|
50
|
-
core.config.agent.node.rewrite.cache.path,
|
|
51
|
-
StringPrototypeReplace.call(core.appInfo.name, '/', '_'),
|
|
52
|
-
version,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Sets the rewriter to 'assess' or 'protect' mode, enabling different
|
|
58
|
-
* transforms.
|
|
59
|
-
* @param {import('.').Mode} mode
|
|
60
|
-
*/
|
|
61
|
-
install(mode) {
|
|
62
|
-
this.modes.add(mode);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Returns the filename of a cached rewrite result. Paths within the `app_dir`
|
|
67
|
-
* directory are nested under the `_` directory to prevent potential
|
|
68
|
-
* collisions with absolute paths.
|
|
69
|
-
* /path/to/app/node_modules/mod/index.js
|
|
70
|
-
* -> '.contrast/app_name/5.1.2/assess/_/node_modules/mod/index.js
|
|
71
|
-
* /somewhere/else/index.js
|
|
72
|
-
* -> .contrast/app_name/5.1.2/assess/somewhere/else/index.js
|
|
73
|
-
* @param {string} filename
|
|
74
|
-
* @returns {string}
|
|
75
|
-
*/
|
|
76
|
-
getCachedFilename(filename) {
|
|
77
|
-
filename = StringPrototypeReplace.call(filename, this.appDirRegex, '_');
|
|
78
|
-
|
|
79
|
-
if (os.platform() === 'win32') {
|
|
80
|
-
filename = StringPrototypeReplace.call(filename, /^([A-Za-z]):/, '$1_');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return path.join(
|
|
84
|
-
this.cacheDir,
|
|
85
|
-
this.modes.has('assess') ? 'assess' : 'protect',
|
|
86
|
-
filename,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Looks up and returns the cached filename for a previously rewritten file
|
|
92
|
-
* asynchronously.
|
|
93
|
-
* @param {string} filename
|
|
94
|
-
* @returns {Promise<string | undefined>}
|
|
95
|
-
*/
|
|
96
|
-
async find(filename) {
|
|
97
|
-
const filenameCached = this.getCachedFilename(filename);
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const [time, timeCached] = await Promise.all([mtime(filename), mtime(filenameCached)]);
|
|
101
|
-
if (time > timeCached) {
|
|
102
|
-
this.logger.trace(
|
|
103
|
-
{
|
|
104
|
-
filename,
|
|
105
|
-
filenameCached,
|
|
106
|
-
mtime: time,
|
|
107
|
-
mtimeCached: timeCached,
|
|
108
|
-
},
|
|
109
|
-
'Cache stale, falling back to compiling.'
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.logger.trace(
|
|
116
|
-
{
|
|
117
|
-
filename,
|
|
118
|
-
filenameCached,
|
|
119
|
-
mtime: time,
|
|
120
|
-
mtimeCached: timeCached,
|
|
121
|
-
},
|
|
122
|
-
'Cache current.'
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
return filenameCached;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
// @ts-expect-error ts treats errors poorly.
|
|
128
|
-
if (err.code !== 'ENOENT') {
|
|
129
|
-
this.logger.error(
|
|
130
|
-
{ err, filename, filenameCached },
|
|
131
|
-
'An unexpected error occurred, falling back to compiling.'
|
|
132
|
-
);
|
|
133
|
-
} else {
|
|
134
|
-
this.logger.trace(
|
|
135
|
-
{ filename, filenameCached },
|
|
136
|
-
'Cache miss, falling back to compiling.',
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Looks up and returns the source map for a previously rewritten file.
|
|
146
|
-
* @param {string} filename
|
|
147
|
-
* @returns {Promise<string | undefined>}
|
|
148
|
-
*/
|
|
149
|
-
async readMap(filename) {
|
|
150
|
-
const filenameCached = this.getCachedFilename(filename);
|
|
151
|
-
const sourceMap = `${filenameCached}.map`;
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
return fsPromises.readFile(sourceMap, 'utf8');
|
|
155
|
-
} catch (err) {
|
|
156
|
-
// @ts-expect-error ts treats errors poorly.
|
|
157
|
-
if (err.code !== 'ENOENT') {
|
|
158
|
-
this.logger.warn(
|
|
159
|
-
{ err, filename, filenameCached, sourceMap },
|
|
160
|
-
'An unexpected error occurred finding source map.'
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Looks up and returns the string content of a previously rewritten file
|
|
169
|
-
* synchronously. Used when we need to block on cache lookups.
|
|
170
|
-
* @param {string} filename
|
|
171
|
-
* @returns {string | undefined}
|
|
172
|
-
*/
|
|
173
|
-
readSync(filename) {
|
|
174
|
-
const filenameCached = this.getCachedFilename(filename);
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
const time = mtimeSync(filename);
|
|
178
|
-
const timeCached = mtimeSync(filenameCached);
|
|
179
|
-
if (time > timeCached) {
|
|
180
|
-
this.logger.trace(
|
|
181
|
-
{
|
|
182
|
-
filename,
|
|
183
|
-
filenameCached,
|
|
184
|
-
mtime: time,
|
|
185
|
-
mtimeCached: timeCached,
|
|
186
|
-
},
|
|
187
|
-
'Cache stale, falling back to compiling.'
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
this.logger.trace(
|
|
194
|
-
{
|
|
195
|
-
filename,
|
|
196
|
-
filenameCached,
|
|
197
|
-
mtime: time,
|
|
198
|
-
mtimeCached: timeCached,
|
|
199
|
-
},
|
|
200
|
-
'Cache current.'
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
return FsReadFileSync(filenameCached, 'utf8');
|
|
204
|
-
} catch (err) {
|
|
205
|
-
// @ts-expect-error ts treats errors poorly.
|
|
206
|
-
if (err.code !== 'ENOENT') {
|
|
207
|
-
this.logger.error(
|
|
208
|
-
{ err, filename, filenameCached },
|
|
209
|
-
'An unexpected error occurred, falling back to compiling.'
|
|
210
|
-
);
|
|
211
|
-
} else {
|
|
212
|
-
this.logger.trace(
|
|
213
|
-
{ filename, filenameCached },
|
|
214
|
-
'Cache miss, falling back to compiling.',
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return undefined;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Synchronously writes a rewritten file to the cache directory. This is
|
|
224
|
-
* intended for use by require instrumentation because require is a sync
|
|
225
|
-
* operation.
|
|
226
|
-
*
|
|
227
|
-
* Incorrectly using the .write() method for require can result in the
|
|
228
|
-
* "unexpected end-of-file" error or rewriting the same file multiple
|
|
229
|
-
* times because it's required again before the write operation has
|
|
230
|
-
* completed.
|
|
231
|
-
*
|
|
232
|
-
* @param {string} filename
|
|
233
|
-
* @param {import('@swc/core').Output} result
|
|
234
|
-
* @returns {void}
|
|
235
|
-
*/
|
|
236
|
-
writeSync(filename, result) {
|
|
237
|
-
const filenameCached = this.getCachedFilename(filename);
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
fs.mkdirSync(path.dirname(filenameCached), { recursive: true });
|
|
241
|
-
|
|
242
|
-
fs.writeFileSync(filenameCached, result.code, 'utf8');
|
|
243
|
-
|
|
244
|
-
if (result.map) {
|
|
245
|
-
fs.writeFileSync(`${filenameCached}.map`, result.map, 'utf8');
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
this.logger.trace(
|
|
249
|
-
{
|
|
250
|
-
filename,
|
|
251
|
-
filenameCached,
|
|
252
|
-
},
|
|
253
|
-
'Cache entry created.'
|
|
254
|
-
);
|
|
255
|
-
} catch (err) {
|
|
256
|
-
this.logger.warn(
|
|
257
|
-
{
|
|
258
|
-
err,
|
|
259
|
-
filename,
|
|
260
|
-
filenameCached,
|
|
261
|
-
},
|
|
262
|
-
'Unable to cache rewrite results.'
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Asynchronously writes a rewritten file to the cache directory. This is
|
|
269
|
-
* intended for use by import instrumentation because import is an async
|
|
270
|
-
* operation.
|
|
271
|
-
*
|
|
272
|
-
* The caller should await this method to ensure that the cache is written
|
|
273
|
-
* before proceeding. If the caller doesn't wait, it's possible that the
|
|
274
|
-
* code will attempt to read a half-written file and get an "unexpected
|
|
275
|
-
* end-of-file" error or that the same file will be rewritten because it's
|
|
276
|
-
* required again before the file appears in the file system.
|
|
277
|
-
*
|
|
278
|
-
* @param {string} filename
|
|
279
|
-
* @param {import('@swc/core').Output} result
|
|
280
|
-
* @returns {Promise<void>}
|
|
281
|
-
*/
|
|
282
|
-
async write(filename, result) {
|
|
283
|
-
const filenameCached = this.getCachedFilename(filename);
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
await fsPromises.mkdir(path.dirname(filenameCached), { recursive: true });
|
|
287
|
-
|
|
288
|
-
const writePromises = [
|
|
289
|
-
fsPromises.writeFile(filenameCached, result.code, 'utf8')
|
|
290
|
-
];
|
|
291
|
-
|
|
292
|
-
if (result.map) {
|
|
293
|
-
writePromises.push(
|
|
294
|
-
fsPromises.writeFile(`${filenameCached}.map`, result.map, 'utf8')
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
await Promise.all(writePromises);
|
|
299
|
-
|
|
300
|
-
this.logger.trace(
|
|
301
|
-
{
|
|
302
|
-
filename,
|
|
303
|
-
filenameCached,
|
|
304
|
-
},
|
|
305
|
-
'Cache entry created.'
|
|
306
|
-
);
|
|
307
|
-
} catch (err) {
|
|
308
|
-
this.logger.warn(
|
|
309
|
-
{
|
|
310
|
-
err,
|
|
311
|
-
filename,
|
|
312
|
-
filenameCached,
|
|
313
|
-
},
|
|
314
|
-
'Unable to cache rewrite results.'
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
};
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright: 2025 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
|
-
// @ts-check
|
|
16
|
-
'use strict';
|
|
17
|
-
|
|
18
|
-
const Module = require('node:module');
|
|
19
|
-
const { arch, platform } = require('node:os');
|
|
20
|
-
const path = require('node:path');
|
|
21
|
-
const { parseSync, transform, transformSync } = require('@swc/core');
|
|
22
|
-
const { primordials: { StringPrototypeReplace, StringPrototypeSubstring } } = require('@contrast/common');
|
|
23
|
-
const { Cache } = require('./cache');
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {Object} Core
|
|
27
|
-
* @prop {import('@contrast/common').AppInfo} appInfo
|
|
28
|
-
* @prop {import('@contrast/config').Config} config
|
|
29
|
-
* @prop {import('@contrast/logger').Logger} logger
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* @typedef {'assess' | 'protect'} Mode
|
|
33
|
-
*/
|
|
34
|
-
/**
|
|
35
|
-
* @typedef {Object} RewriteOpts
|
|
36
|
-
* @prop {string=} filename e.g. 'index.js'
|
|
37
|
-
* @prop {boolean=} isModule if true, file is parsed as an ES module instead of a CJS script
|
|
38
|
-
* @prop {boolean=} inject if true, injects ContrastMethods on the global object
|
|
39
|
-
* @prop {boolean=} wrap if true, wraps the content with a modified module wrapper IIFE
|
|
40
|
-
* @prop {boolean=} minify if true, minifies the output when source maps are enabled
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
// @ts-expect-error `wrapper` is missing from @types/node.
|
|
44
|
-
const prefix = Module.wrapper[0];
|
|
45
|
-
// @ts-expect-error `wrapper` is missing from @types/node, primordials overloads are poorly handled.
|
|
46
|
-
const suffix = StringPrototypeReplace.call(Module.wrapper[1], /;$/, '.apply(this, arguments);');
|
|
47
|
-
|
|
48
|
-
// @ts-expect-error `@contrast/agent-swc-plugin` .d.ts file doesn't exist.
|
|
49
|
-
const { defaultRewriter, defaultUnwriter } = require('@contrast/agent-swc-plugin');
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Wraps the source content as necessary to support rewriting.
|
|
53
|
-
* Wrapping must occur before rewriting since the underlying rewriter cannot
|
|
54
|
-
* parse certain valid statements such as `return` statements in a CJS script.
|
|
55
|
-
* @param {string} content
|
|
56
|
-
* @returns {string}
|
|
57
|
-
*/
|
|
58
|
-
const wrap = (content) => {
|
|
59
|
-
let shebang = '';
|
|
60
|
-
|
|
61
|
-
// The shebang will be commented out since it cannot be present in a
|
|
62
|
-
// function body. swc doesn't include the commented shebang in the generated
|
|
63
|
-
// code despite including comments otherwise.
|
|
64
|
-
if (content.charAt(0) === '#') {
|
|
65
|
-
shebang = StringPrototypeSubstring.call(content, 0, content.indexOf('\n') + 1);
|
|
66
|
-
content = `//${content}`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
content = `${shebang}${prefix}${content}${suffix}`;
|
|
70
|
-
|
|
71
|
-
return content;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
class Rewriter {
|
|
75
|
-
/**
|
|
76
|
-
* @param {Core} core
|
|
77
|
-
*/
|
|
78
|
-
constructor(core) {
|
|
79
|
-
this.core = core;
|
|
80
|
-
this.logger = core.logger.child({ name: 'contrast:rewriter' });
|
|
81
|
-
/** @type {Set<Mode>} */
|
|
82
|
-
this.modes = new Set();
|
|
83
|
-
this.cache = new Cache(core);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Sets the rewriter to 'assess' or 'protect' mode, enabling different
|
|
88
|
-
* transforms.
|
|
89
|
-
* @param {Mode} mode
|
|
90
|
-
*/
|
|
91
|
-
install(mode) {
|
|
92
|
-
this.logger.trace('installing rewriter mode: %s', mode);
|
|
93
|
-
this.modes.add(mode);
|
|
94
|
-
this.cache.install(mode);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @param {RewriteOpts} opts
|
|
99
|
-
* @returns {import('@swc/core').Options}
|
|
100
|
-
*/
|
|
101
|
-
rewriteConfig(opts) {
|
|
102
|
-
const nodeCfg = this.core.config.agent.node;
|
|
103
|
-
const sourceMaps = nodeCfg.source_maps.enable;
|
|
104
|
-
const minify = opts.minify && nodeCfg.source_maps.enable && nodeCfg.rewrite.minify;
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
swcrc: false,
|
|
108
|
-
filename: opts.filename,
|
|
109
|
-
isModule: opts.isModule,
|
|
110
|
-
env: {
|
|
111
|
-
targets: {
|
|
112
|
-
node: process.versions.node,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
jsc: {
|
|
116
|
-
experimental: {
|
|
117
|
-
plugins: [[defaultRewriter, {
|
|
118
|
-
assess: this.modes.has('assess'),
|
|
119
|
-
inject: opts.inject,
|
|
120
|
-
}]],
|
|
121
|
-
cacheRoot: path.join(nodeCfg.rewrite.cache.path, '.swc'),
|
|
122
|
-
},
|
|
123
|
-
// disable most of the more invasive options.
|
|
124
|
-
// see: https://terser.org/docs/options/#compress-options
|
|
125
|
-
minify: minify ? { compress: { defaults: false } } : undefined
|
|
126
|
-
},
|
|
127
|
-
minify,
|
|
128
|
-
sourceMaps,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Rewrites the provided source code string asynchronously. this is used in an ESM
|
|
134
|
-
* context. CJS cannot use this because `require` is synchronous.
|
|
135
|
-
*
|
|
136
|
-
* @param {string} content
|
|
137
|
-
* @param {RewriteOpts=} opts
|
|
138
|
-
* @returns {Promise<import('@swc/core').Output>} with possibly modified source map.
|
|
139
|
-
*/
|
|
140
|
-
async rewrite(content, opts = {}) {
|
|
141
|
-
this.logger.trace({ opts }, 'rewriting %s', opts.filename);
|
|
142
|
-
|
|
143
|
-
if (opts.wrap) {
|
|
144
|
-
content = wrap(content);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return transform(content, this.rewriteConfig(opts));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Rewrites the provided source code string synchronously. this is used in a CJS
|
|
152
|
-
* context. while ESM could use this, performance is better when using the async
|
|
153
|
-
* version.
|
|
154
|
-
*
|
|
155
|
-
* @param {string} content
|
|
156
|
-
* @param {RewriteOpts=} opts
|
|
157
|
-
* @returns {import('@swc/core').Output} with possibly modified source map.
|
|
158
|
-
*/
|
|
159
|
-
rewriteSync(content, opts = {}) {
|
|
160
|
-
this.logger.trace({ opts }, 'rewriting %s', opts.filename);
|
|
161
|
-
|
|
162
|
-
if (opts.wrap) {
|
|
163
|
-
content = wrap(content);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return transformSync(content, this.rewriteConfig(opts));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Removes contrast-related rewritten code from provided source code string.
|
|
171
|
-
* @param {string} content
|
|
172
|
-
* @returns {string}
|
|
173
|
-
*/
|
|
174
|
-
unwriteSync(content) {
|
|
175
|
-
return transformSync(content, {
|
|
176
|
-
swcrc: false,
|
|
177
|
-
env: {
|
|
178
|
-
targets: {
|
|
179
|
-
node: process.versions.node,
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
jsc: {
|
|
183
|
-
experimental: {
|
|
184
|
-
plugins: [[defaultUnwriter, {}]],
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
sourceMaps: false,
|
|
188
|
-
}).code;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @param {Core & { rewriter?: Rewriter; }} core
|
|
194
|
-
* @returns {Rewriter}
|
|
195
|
-
*/
|
|
196
|
-
module.exports = function init(core) {
|
|
197
|
-
// Check that the correct bindings for `swc` are installed, throwing and
|
|
198
|
-
// stopping instrumentation if not.
|
|
199
|
-
try {
|
|
200
|
-
parseSync('');
|
|
201
|
-
} catch (cause) {
|
|
202
|
-
// @ts-expect-error TS hates errors.
|
|
203
|
-
throw cause.message === 'Bindings not found.'
|
|
204
|
-
? new Error(
|
|
205
|
-
`Contrast cannot detect the correct precompiled dependencies for the current environment: ${platform()}-${arch()}. This typically occurs when deploying an installation from one environment to a different execution environment.`,
|
|
206
|
-
// @ts-expect-error `cause` requires ts to target es2022 or above, which corresponds to Node 17+, despite being added to Node in 16.9.
|
|
207
|
-
{ cause },
|
|
208
|
-
)
|
|
209
|
-
: cause;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
core.rewriter = new Rewriter(core);
|
|
213
|
-
return core.rewriter;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
module.exports.Rewriter = Rewriter;
|