@contrast/rewriter 1.10.0 → 1.10.1
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 +2 -80
- package/package.json +4 -6
package/lib/index.js
CHANGED
|
@@ -16,9 +16,6 @@
|
|
|
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');
|
|
22
19
|
const { transform, transformSync } = require('@swc/core');
|
|
23
20
|
const { Cache } = require('./cache');
|
|
24
21
|
|
|
@@ -133,14 +130,7 @@ class Rewriter {
|
|
|
133
130
|
content = wrap(content);
|
|
134
131
|
}
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
// }
|
|
142
|
-
|
|
143
|
-
return result;
|
|
133
|
+
return transform(content, this.rewriteConfig(opts));
|
|
144
134
|
}
|
|
145
135
|
|
|
146
136
|
/**
|
|
@@ -159,14 +149,7 @@ class Rewriter {
|
|
|
159
149
|
content = wrap(content);
|
|
160
150
|
}
|
|
161
151
|
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
// }
|
|
168
|
-
|
|
169
|
-
return result;
|
|
152
|
+
return transformSync(content, this.rewriteConfig(opts));
|
|
170
153
|
}
|
|
171
154
|
|
|
172
155
|
/**
|
|
@@ -189,67 +172,6 @@ class Rewriter {
|
|
|
189
172
|
sourceMaps: false,
|
|
190
173
|
}).code;
|
|
191
174
|
}
|
|
192
|
-
|
|
193
|
-
// not used with new version of swc; it chains source maps.
|
|
194
|
-
/**
|
|
195
|
-
* If there is a .map file in the same directory as the code being rewritten
|
|
196
|
-
* then chain the two maps together. This is an async function because there
|
|
197
|
-
* is no reason to wait for the source map to be finalized at startup. node-mono
|
|
198
|
-
* writes the map file asynchronously but performs two synchronous IO reads
|
|
199
|
-
* before calling transfer. This code performs a single async read before
|
|
200
|
-
* calling transfer.
|
|
201
|
-
*
|
|
202
|
-
* Question: should this log or just defer to the caller?
|
|
203
|
-
*
|
|
204
|
-
* @param {string} possibleMapPath the absolute path to a possibly pre-existing source map.
|
|
205
|
-
* @param {string} contrastMap the source map generated by the agent
|
|
206
|
-
* @returns {Promise<string>} promise to the final sourceMap object or, if an error,
|
|
207
|
-
* the input contrast source-map.
|
|
208
|
-
*/
|
|
209
|
-
// @ts-ignore
|
|
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
|
-
// }
|
|
223
|
-
|
|
224
|
-
// // return the merged map or the original contrast map
|
|
225
|
-
// return contrastMap;
|
|
226
|
-
// }
|
|
227
|
-
|
|
228
|
-
// not used with new version of swc; it chains source maps.
|
|
229
|
-
/**
|
|
230
|
-
* @param {string} possibleMapPath the absolute path to a possibly pre-existing source map.
|
|
231
|
-
* @param {string} contrastMap the source map generated by the agent
|
|
232
|
-
* @returns {string} the final sourceMap object or, if an error,
|
|
233
|
-
* the input contrast source-map.
|
|
234
|
-
*/
|
|
235
|
-
// @ts-ignore
|
|
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
|
-
// }
|
|
249
|
-
|
|
250
|
-
// // return the merged map or the original contrast map
|
|
251
|
-
// return contrastMap;
|
|
252
|
-
// }
|
|
253
175
|
}
|
|
254
176
|
|
|
255
177
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/rewriter",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
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,9 @@
|
|
|
14
14
|
"test": "../scripts/test.sh"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@contrast/agent-swc-plugin": "
|
|
18
|
-
"@contrast/agent-swc-plugin-unwrite": "
|
|
17
|
+
"@contrast/agent-swc-plugin": "1.5.1",
|
|
18
|
+
"@contrast/agent-swc-plugin-unwrite": "1.5.1",
|
|
19
19
|
"@contrast/common": "1.23.0",
|
|
20
|
-
"@
|
|
21
|
-
"@swc/core": "1.5.29",
|
|
22
|
-
"multi-stage-sourcemap": "^0.3.1"
|
|
20
|
+
"@swc/core": "1.5.29"
|
|
23
21
|
}
|
|
24
22
|
}
|