@contrast/rewriter 1.8.2 → 1.8.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/lib/index.js +45 -42
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const Module = require('node:module');
|
|
19
|
-
const fs = require('node:fs');
|
|
20
|
-
const fsp = fs.promises;
|
|
21
|
-
const { transfer } = require('multi-stage-sourcemap');
|
|
19
|
+
//const fs = require('node:fs');
|
|
20
|
+
//const fsp = fs.promises;
|
|
21
|
+
//const { transfer } = require('multi-stage-sourcemap');
|
|
22
22
|
const { transform, transformSync } = require('@swc/core');
|
|
23
23
|
const { Cache } = require('./cache');
|
|
24
24
|
|
|
@@ -135,9 +135,10 @@ class Rewriter {
|
|
|
135
135
|
|
|
136
136
|
const result = await transform(content, this.rewriteConfig(opts));
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
138
|
+
// not used with new version of swc; it chains source maps.
|
|
139
|
+
// if (result.map) {
|
|
140
|
+
// result.map = await this.ifSourceMapExistsChainIt(`${opts.filename}.map`, result.map);
|
|
141
|
+
// }
|
|
141
142
|
|
|
142
143
|
return result;
|
|
143
144
|
}
|
|
@@ -160,9 +161,10 @@ class Rewriter {
|
|
|
160
161
|
|
|
161
162
|
const result = transformSync(content, this.rewriteConfig(opts));
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
164
|
+
// not used with new version of swc; it chains source maps.
|
|
165
|
+
// if (result.map) {
|
|
166
|
+
// result.map = this.ifSourceMapExistsChainItSync(`${opts.filename}.map`, result.map);
|
|
167
|
+
// }
|
|
166
168
|
|
|
167
169
|
return result;
|
|
168
170
|
}
|
|
@@ -188,7 +190,7 @@ class Rewriter {
|
|
|
188
190
|
}).code;
|
|
189
191
|
}
|
|
190
192
|
|
|
191
|
-
|
|
193
|
+
// not used with new version of swc; it chains source maps.
|
|
192
194
|
/**
|
|
193
195
|
* If there is a .map file in the same directory as the code being rewritten
|
|
194
196
|
* then chain the two maps together. This is an async function because there
|
|
@@ -205,24 +207,25 @@ class Rewriter {
|
|
|
205
207
|
* the input contrast source-map.
|
|
206
208
|
*/
|
|
207
209
|
// @ts-ignore
|
|
208
|
-
async ifSourceMapExistsChainIt(possibleMapPath, contrastMap) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
210
|
+
// async ifSourceMapExistsChainIt(possibleMapPath, contrastMap) {
|
|
211
|
+
// try {
|
|
212
|
+
// const data = await fsp.readFile(possibleMapPath, 'utf8');
|
|
213
|
+
// const existingMap = JSON.parse(data);
|
|
214
|
+
// contrastMap = transfer({ fromSourceMap: contrastMap, toSourceMap: existingMap });
|
|
215
|
+
// this.logger.trace({ existingMap: possibleMapPath }, 'merged source-map');
|
|
216
|
+
// } catch (err) {
|
|
217
|
+
// // if the map file isn't found, it's not an error, otherwise log it.
|
|
218
|
+
// // @ts-ignore
|
|
219
|
+
// if (err.code !== 'ENOENT') {
|
|
220
|
+
// this.logger.debug({ existingMap: possibleMapPath, err }, 'failed to read');
|
|
221
|
+
// }
|
|
222
|
+
// }
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
224
|
+
// // return the merged map or the original contrast map
|
|
225
|
+
// return contrastMap;
|
|
226
|
+
// }
|
|
225
227
|
|
|
228
|
+
// not used with new version of swc; it chains source maps.
|
|
226
229
|
/**
|
|
227
230
|
* @param {string} possibleMapPath the absolute path to a possibly pre-existing source map.
|
|
228
231
|
* @param {string} contrastMap the source map generated by the agent
|
|
@@ -230,23 +233,23 @@ class Rewriter {
|
|
|
230
233
|
* the input contrast source-map.
|
|
231
234
|
*/
|
|
232
235
|
// @ts-ignore
|
|
233
|
-
ifSourceMapExistsChainItSync(possibleMapPath, contrastMap) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
236
|
+
// ifSourceMapExistsChainItSync(possibleMapPath, contrastMap) {
|
|
237
|
+
// try {
|
|
238
|
+
// const data = fs.readFileSync(possibleMapPath, 'utf8');
|
|
239
|
+
// const existingMap = JSON.parse(data);
|
|
240
|
+
// contrastMap = transfer({ fromSourceMap: contrastMap, toSourceMap: existingMap });
|
|
241
|
+
// this.logger.trace({ existingMap: possibleMapPath }, 'merged source-map');
|
|
242
|
+
// } catch (err) {
|
|
243
|
+
// // if the map file isn't found, it's not an error, otherwise log it.
|
|
244
|
+
// // @ts-ignore
|
|
245
|
+
// if (err.code !== 'ENOENT') {
|
|
246
|
+
// this.logger.debug({ existingMap: possibleMapPath, err }, 'failed to read');
|
|
247
|
+
// }
|
|
248
|
+
// }
|
|
246
249
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
+
// // return the merged map or the original contrast map
|
|
251
|
+
// return contrastMap;
|
|
252
|
+
// }
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/rewriter",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
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": "1.5.
|
|
18
|
-
"@contrast/agent-swc-plugin-unwrite": "1.5.
|
|
19
|
-
"@contrast/common": "1.21.
|
|
17
|
+
"@contrast/agent-swc-plugin": "^1.5.1",
|
|
18
|
+
"@contrast/agent-swc-plugin-unwrite": "^1.5.1",
|
|
19
|
+
"@contrast/common": "1.21.3",
|
|
20
20
|
"@contrast/synchronous-source-maps": "^1.1.3",
|
|
21
|
-
"@swc/core": "1.
|
|
21
|
+
"@swc/core": "^1.5.29",
|
|
22
22
|
"multi-stage-sourcemap": "^0.3.1"
|
|
23
23
|
}
|
|
24
24
|
}
|