@contrast/rewriter 1.12.0 → 1.14.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/cache.js +6 -5
- package/lib/index.js +7 -6
- package/package.json +6 -6
package/lib/cache.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
13
|
* way not consistent with the End User License Agreement.
|
|
14
14
|
*/
|
|
15
|
-
// @ts-
|
|
15
|
+
// @ts-nocheck
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const fs = require('node:fs');
|
|
@@ -20,6 +20,7 @@ const fsPromises = require('node:fs/promises');
|
|
|
20
20
|
const os = require('node:os');
|
|
21
21
|
const path = require('node:path');
|
|
22
22
|
const { version } = require('../package.json');
|
|
23
|
+
const { primordials: { StringPrototypeReplace, StringPrototypeReplaceAll } } = require('@contrast/common');
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Returns the modification time of a file as a number.
|
|
@@ -44,10 +45,10 @@ module.exports.Cache = class Cache {
|
|
|
44
45
|
this.logger = core.logger.child({ name: 'contrast:rewriter:cache' });
|
|
45
46
|
/** @type {Set<import('.').Mode>} */
|
|
46
47
|
this.modes = new Set();
|
|
47
|
-
this.appDirRegex = new RegExp(`^${core.appInfo.app_dir
|
|
48
|
+
this.appDirRegex = new RegExp(`^${StringPrototypeReplaceAll.call(core.appInfo.app_dir, '\\', '\\\\')}`);
|
|
48
49
|
this.cacheDir = path.join(
|
|
49
50
|
core.config.agent.node.rewrite.cache.path,
|
|
50
|
-
core.appInfo.name
|
|
51
|
+
StringPrototypeReplace.call(core.appInfo.name, '/', '_'),
|
|
51
52
|
version,
|
|
52
53
|
);
|
|
53
54
|
}
|
|
@@ -73,10 +74,10 @@ module.exports.Cache = class Cache {
|
|
|
73
74
|
* @returns {string}
|
|
74
75
|
*/
|
|
75
76
|
getCachedFilename(filename) {
|
|
76
|
-
filename =
|
|
77
|
+
filename = StringPrototypeReplace.call(filename, this.appDirRegex, '_');
|
|
77
78
|
|
|
78
79
|
if (os.platform() === 'win32') {
|
|
79
|
-
filename =
|
|
80
|
+
filename = StringPrototypeReplace.call(filename, /^([A-Za-z]):/, '$1_');
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
return path.join(
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
const Module = require('node:module');
|
|
19
19
|
const { transform, transformSync } = require('@swc/core');
|
|
20
20
|
const { Cache } = require('./cache');
|
|
21
|
+
const { primordials: { StringPrototypeReplace, StringPrototypeSubstring } } = require('@contrast/common');
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @typedef {Object} Core
|
|
@@ -39,10 +40,10 @@ const { Cache } = require('./cache');
|
|
|
39
40
|
// @ts-expect-error `wrapper` is missing from @types/node
|
|
40
41
|
const prefix = Module.wrapper[0];
|
|
41
42
|
// @ts-expect-error `wrapper` is missing from @types/node
|
|
42
|
-
const suffix = Module.wrapper[1]
|
|
43
|
+
const suffix = StringPrototypeReplace.call(Module.wrapper[1], /;$/, '.apply(this, arguments);');
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
const
|
|
45
|
+
// @ts-expect-error `@contrast/agent-swc-plugin` .d.ts file doesn't exist.
|
|
46
|
+
const { defaultRewriter, defaultUnwriter } = require('@contrast/agent-swc-plugin');
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
* Wraps the source content as necessary to support rewriting.
|
|
@@ -58,7 +59,7 @@ const wrap = (content) => {
|
|
|
58
59
|
// function body. swc doesn't include the commented shebang in the generated
|
|
59
60
|
// code despite including comments otherwise.
|
|
60
61
|
if (content.charAt(0) === '#') {
|
|
61
|
-
shebang =
|
|
62
|
+
shebang = StringPrototypeSubstring.call(content, 0, content.indexOf('\n') + 1);
|
|
62
63
|
content = `//${content}`;
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -105,7 +106,7 @@ class Rewriter {
|
|
|
105
106
|
},
|
|
106
107
|
jsc: {
|
|
107
108
|
experimental: {
|
|
108
|
-
plugins: [[
|
|
109
|
+
plugins: [[defaultRewriter, {
|
|
109
110
|
assess: this.modes.has('assess'),
|
|
110
111
|
inject: opts.inject,
|
|
111
112
|
}]],
|
|
@@ -166,7 +167,7 @@ class Rewriter {
|
|
|
166
167
|
},
|
|
167
168
|
jsc: {
|
|
168
169
|
experimental: {
|
|
169
|
-
plugins: [[
|
|
170
|
+
plugins: [[defaultUnwriter, {}]],
|
|
170
171
|
},
|
|
171
172
|
},
|
|
172
173
|
sourceMaps: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/rewriter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.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)",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"test": "../scripts/test.sh"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@contrast/agent-swc-plugin": "
|
|
18
|
-
"@contrast/
|
|
19
|
-
"@contrast/
|
|
20
|
-
"@contrast/
|
|
21
|
-
"@contrast/
|
|
17
|
+
"@contrast/agent-swc-plugin": "^2.0.0",
|
|
18
|
+
"@contrast/common": "1.26.0",
|
|
19
|
+
"@contrast/config": "1.34.0",
|
|
20
|
+
"@contrast/core": "1.38.0",
|
|
21
|
+
"@contrast/logger": "1.11.0",
|
|
22
22
|
"@swc/core": "1.5.29"
|
|
23
23
|
}
|
|
24
24
|
}
|