jscrambler-metro-plugin 8.4.2 → 8.4.4

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.js CHANGED
@@ -192,12 +192,24 @@ async function obfuscateBundle(
192
192
  return [`${chunks[0]}${globalThisPolyfill}`, ...chunks.slice(1)].join('\n');
193
193
  }
194
194
 
195
+ let showSource = addShowSource;
196
+ let startAtFirstColumn = requireStartAtFirstColumn;
197
+
195
198
  const obfuscatedCode = obfusctedUserFiles[i - 1];
199
+ const sourceFileIgnored = metroUserFilesOnly[i - 1] === obfuscatedCode;
200
+
201
+ if (sourceFileIgnored) {
202
+ // restore excluded files
203
+ showSource = false;
204
+ startAtFirstColumn = false;
205
+ debug && console.log(`debug Jscrambler File ${fileNames[i - 1]} was excluded`);
206
+ }
207
+
196
208
  const tillCodeEnd = c.substr(
197
209
  c.indexOf(JSCRAMBLER_END_ANNOTATION),
198
210
  c.length
199
211
  );
200
- return `${acc}${JSCRAMBLER_BEG_ANNOTATION}${addShowSource ? '"show source";' : ''}${requireStartAtFirstColumn ? '\n' : ''}${obfuscatedCode}${tillCodeEnd}`;
212
+ return `${acc}${JSCRAMBLER_BEG_ANNOTATION}${showSource ? '"show source";' : ''}${startAtFirstColumn ? '\n' : ''}${obfuscatedCode}${tillCodeEnd}`;
201
213
  }, '');
202
214
 
203
215
  await writeFile(bundlePath, stripJscramblerTags(finalBundle));
package/lib/sourceMaps.js CHANGED
@@ -36,9 +36,20 @@ module.exports = async function generateSourceMaps(payload) {
36
36
  await jscrambler.downloadSourceMaps(Object.assign({protectionId}, config));
37
37
 
38
38
  // read obfuscated source-map from filesystem
39
- const obfuscatedSourceMaps = await Promise.all(metroUserFilesOnly.map((c, i) =>
40
- readFile(`${JSCRAMBLER_SOURCE_MAPS_TEMP_FOLDER}/${fileNames[i]}.map`, 'utf8')
41
- ));
39
+ const obfuscatedSourceMaps = await Promise.all(
40
+ metroUserFilesOnly.map((c, i) =>
41
+ readFile(
42
+ `${JSCRAMBLER_SOURCE_MAPS_TEMP_FOLDER}/${fileNames[i]}.map`,
43
+ 'utf8',
44
+ ).catch((e) => {
45
+ if (e.code === 'ENOENT') {
46
+ // when a source file is excluded, the sourcemap is not produced
47
+ return null;
48
+ }
49
+ throw e;
50
+ }),
51
+ ),
52
+ );
42
53
 
43
54
  // read metro source-map
44
55
  const metroSourceMap = await readFile(bundleSourceMapPath, 'utf8');
@@ -46,7 +57,10 @@ module.exports = async function generateSourceMaps(payload) {
46
57
 
47
58
  const metroSourceMapConsumer = new sourceMap.SourceMapConsumer(metroSourceMap);
48
59
  const finalSourceMapGenerator = new sourceMap.SourceMapGenerator({file: bundlePath});
49
- const ofuscatedSourceMapConsumers = obfuscatedSourceMaps.map(map => new sourceMap.SourceMapConsumer(map));
60
+ const ofuscatedSourceMapConsumers = obfuscatedSourceMaps.map((map) =>
61
+ // when a source file is excluded, the sourcemap is not produced
62
+ map ? new sourceMap.SourceMapConsumer(map) : null,
63
+ );
50
64
 
51
65
  // add all original sources and sourceContents
52
66
  metroSourceMapConsumer.sources.forEach(function (sourceFile) {
@@ -80,14 +94,22 @@ module.exports = async function generateSourceMaps(payload) {
80
94
  shiftLines = tmpShiftLine;
81
95
  }
82
96
 
83
- if (fileNamesIndex !== -1) {
97
+ if (
98
+ fileNamesIndex !== -1 &&
99
+ /* check if sourceMap was loaded */
100
+ ofuscatedSourceMapConsumers[fileNamesIndex]
101
+ ) {
84
102
  /* jscrambler obfuscated files */
85
103
  const {lineStart, lineEnd, columnStart} = metroBundleLocs[fileNamesIndex];
86
104
  const {lineStart: finalLineStart, lineEnd: finalLineEnd} = finalBundleLocs[fileNamesIndex];
87
105
  const allGeneratedPositionsFor = ofuscatedSourceMapConsumers[fileNamesIndex].allGeneratedPositionsFor({
88
106
  source: normalizePath,
89
107
  line: mapping.generatedLine - lineStart + 1 /* avoid line=0 */,
90
- column: mapping.generatedColumn - columnStart
108
+ column:
109
+ mapping.generatedColumn -
110
+ (mapping.generatedLine === lineStart
111
+ ? columnStart /* column start should be applied only to the first line */
112
+ : 0),
91
113
  });
92
114
 
93
115
  if (allGeneratedPositionsFor.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jscrambler-metro-plugin",
3
- "version": "8.4.2",
3
+ "version": "8.4.4",
4
4
  "description": "A plugin to use metro with Jscrambler",
5
5
  "exports": "./lib/index.js",
6
6
  "peerDependencies": {