jscrambler-metro-plugin 8.4.16 → 8.4.18

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.
Files changed (2) hide show
  1. package/lib/sourceMaps.js +31 -8
  2. package/package.json +1 -1
package/lib/sourceMaps.js CHANGED
@@ -55,8 +55,15 @@ module.exports = async function generateSourceMaps(payload) {
55
55
  const metroSourceMap = await readFile(bundleSourceMapPath, 'utf8');
56
56
  const finalBundleLocs = await extractLocs(finalBundle);
57
57
 
58
- const metroSourceMapConsumer = new sourceMap.SourceMapConsumer(metroSourceMap);
59
- const finalSourceMapGenerator = new sourceMap.SourceMapGenerator({file: bundlePath});
58
+ const metroSourceMapConsumer = new sourceMap.SourceMapConsumer(
59
+ metroSourceMap,
60
+ );
61
+ // retrieve debug ids after the validation by the sourcemap package
62
+ // eslint-disable-next-line camelcase
63
+ const { debugId, debug_id } = JSON.parse(metroSourceMap);
64
+ const finalSourceMapGenerator = new sourceMap.SourceMapGenerator({
65
+ file: bundlePath,
66
+ });
60
67
  const ofuscatedSourceMapConsumers = obfuscatedSourceMaps.map((map) =>
61
68
  // when a source file is excluded, the sourcemap is not produced
62
69
  map ? new sourceMap.SourceMapConsumer(map) : null,
@@ -138,15 +145,31 @@ module.exports = async function generateSourceMaps(payload) {
138
145
  /* vendor code */
139
146
  newMappings[0].generated.line += shiftLines;
140
147
 
141
- // code inserted with no real source file associated,
142
- // so we need to clean the invalid source value (f.e. ".")
143
- if (normalizePath.length === 0) {
148
+ // when the original line/column can't be found, it means that there isn't a real source file associated.
149
+ // Thus, if source file name exists it must be cleaned (f.e ".") to avoid an invalid mapping error
150
+ if (newMappings[0].original === null && newMappings[0].source) {
144
151
  newMappings[0].source = null;
145
152
  }
146
153
  }
147
154
 
148
- newMappings.forEach((newMapping) => finalSourceMapGenerator.addMapping(newMapping));
155
+ newMappings.forEach((newMapping) =>
156
+ finalSourceMapGenerator.addMapping(newMapping),
157
+ );
149
158
  })
150
159
 
151
- return finalSourceMapGenerator.toString();
152
- }
160
+ const finalSourceMaps = finalSourceMapGenerator.toString();
161
+
162
+ // for when react native debugIds are necessary in the sourcemaps (upload to sentry for example)
163
+ // needs to be added in the end since the debugIds are not in SourceMapGenerator type
164
+ const finalSourceMapsJson = JSON.parse(finalSourceMaps);
165
+ if (debugId) {
166
+ finalSourceMapsJson.debugId = debugId;
167
+ }
168
+ // eslint-disable-next-line camelcase
169
+ if (debug_id) {
170
+ // eslint-disable-next-line camelcase
171
+ finalSourceMapsJson.debugId = debug_id;
172
+ }
173
+
174
+ return JSON.stringify(finalSourceMapsJson);
175
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jscrambler-metro-plugin",
3
- "version": "8.4.16",
3
+ "version": "8.4.18",
4
4
  "description": "A plugin to use metro with Jscrambler Code Integrity",
5
5
  "exports": "./lib/index.js",
6
6
  "peerDependencies": {