@contrast/rewriter 1.21.3 → 1.22.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/lib/index.js +16 -2
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
// @ts-check
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
const Module = require('node:module');
|
|
20
|
+
const { arch, platform } = require('node:os');
|
|
19
21
|
const path = require('node:path');
|
|
20
|
-
const { transform, transformSync } = require('@swc/core');
|
|
21
|
-
const { Cache } = require('./cache');
|
|
22
|
+
const { parseSync, transform, transformSync } = require('@swc/core');
|
|
22
23
|
const { primordials: { StringPrototypeReplace, StringPrototypeSubstring } } = require('@contrast/common');
|
|
24
|
+
const { Cache } = require('./cache');
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* @typedef {Object} Core
|
|
@@ -184,6 +186,18 @@ class Rewriter {
|
|
|
184
186
|
* @returns {Rewriter}
|
|
185
187
|
*/
|
|
186
188
|
module.exports = function init(core) {
|
|
189
|
+
// Check that the correct bindings for `swc` are installed, throwing and
|
|
190
|
+
// stopping instrumentation if not.
|
|
191
|
+
try {
|
|
192
|
+
parseSync('');
|
|
193
|
+
} catch (cause) {
|
|
194
|
+
// @ts-expect-error TS hates errors
|
|
195
|
+
throw (cause.message === 'Bindings not found.') ?
|
|
196
|
+
// @ts-expect-error `cause` requires ts to target es2022 or above, which corresponds to Node 17+, despite being added to Node in 16.9
|
|
197
|
+
new Error(`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.`, { cause })
|
|
198
|
+
: cause;
|
|
199
|
+
}
|
|
200
|
+
|
|
187
201
|
core.rewriter = new Rewriter(core);
|
|
188
202
|
return core.rewriter;
|
|
189
203
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/rewriter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "A transpilation tool mainly used for instrumentation",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@contrast/agent-swc-plugin": "^2.0.0",
|
|
24
|
-
"@contrast/common": "1.
|
|
25
|
-
"@contrast/config": "1.
|
|
26
|
-
"@contrast/core": "1.
|
|
27
|
-
"@contrast/logger": "1.
|
|
24
|
+
"@contrast/common": "1.30.0",
|
|
25
|
+
"@contrast/config": "1.41.0",
|
|
26
|
+
"@contrast/core": "1.46.0",
|
|
27
|
+
"@contrast/logger": "1.19.0",
|
|
28
28
|
"@swc/core": "1.5.29"
|
|
29
29
|
}
|
|
30
30
|
}
|