jscrambler-metro-plugin
Advanced tools
Comparing version 5.4.3 to 5.5.0
@@ -6,2 +6,3 @@ const {emptyDir, remove, mkdirp, readFile, writeFile} = require('fs-extra'); | ||
const path = require('path'); | ||
const metroSourceMap = require('metro-source-map'); | ||
@@ -28,3 +29,3 @@ const BUNDLE_OUTPUT_CLI_ARG = '--bundle-output'; | ||
function obfuscateBundle(bundlePath, fileNames, config) { | ||
function obfuscateBundle(bundlePath, fileNames, sourceMapFiles, config) { | ||
let userFiles; | ||
@@ -61,8 +62,20 @@ let filesWithMycode; | ||
) | ||
.then(() => | ||
Promise.all( | ||
sourceMapFiles.map(({filename, content}) => | ||
writeFile(`${JSCRAMBLER_SRC_TEMP_FOLDER}${filename}`, content) | ||
) | ||
) | ||
) | ||
.then(() => { | ||
config.filesSrc = [`${JSCRAMBLER_SRC_TEMP_FOLDER}/**/*.js`]; | ||
config.filesSrc = [`${JSCRAMBLER_SRC_TEMP_FOLDER}/**/*.js?(.map)`]; | ||
config.filesDest = JSCRAMBLER_DIST_TEMP_FOLDER; | ||
config.cwd = JSCRAMBLER_SRC_TEMP_FOLDER; | ||
config.clientId = JSCRAMBLER_CLIENT_ID; | ||
return jscrambler.protectAndDownload(config); | ||
const jscramblerOp = !!config.instrument | ||
? jscrambler.instrumentAndDownload | ||
: jscrambler.protectAndDownload; | ||
return jscramblerOp.call(jscrambler, config); | ||
}) | ||
@@ -107,9 +120,41 @@ .then(protectionId => | ||
module.exports = function(config = {}, projectRoot = process.cwd()) { | ||
/** | ||
* Use 'metro-source-map' to build a standard source-map from raw mappings | ||
* @param {{code: string, map: Array.<Array<number>>}} output | ||
* @param {string} modulePath | ||
* @param {string} source | ||
* @returns {string} | ||
*/ | ||
function buildModuleSourceMap(output, modulePath, source) { | ||
return metroSourceMap | ||
.fromRawMappings([ | ||
{ | ||
...output, | ||
source, | ||
path: modulePath | ||
} | ||
]) | ||
.toString(modulePath); | ||
} | ||
module.exports = function(_config = {}, projectRoot = process.cwd()) { | ||
const bundlePath = getBundlePath(); | ||
const fileNames = new Set(); | ||
const sourceMapFiles = []; | ||
const config = Object.assign({}, jscrambler.config, _config); | ||
const sourceMaps = !!config.sourceMaps; | ||
const instrument = !!config.instrument; | ||
if (sourceMaps) { | ||
throw new Error(`Currently, Jscrambler doesn't support React Native source maps`); | ||
} | ||
process.on('beforeExit', function(exitCode) { | ||
console.log('Obfuscating code'); | ||
obfuscateBundle(bundlePath, Array.from(fileNames), config) | ||
console.log( | ||
instrument | ||
? 'info Jscrambler Instrumenting Code' | ||
: 'info Jscrambler Obfuscating Code' | ||
); | ||
obfuscateBundle(bundlePath, Array.from(fileNames), sourceMapFiles, config) | ||
.catch(err => { | ||
@@ -134,6 +179,16 @@ console.error(err); | ||
fileNames.add( | ||
_module.path.replace(JSCRAMBLER_EXTS, ".js").replace(projectRoot, "") | ||
); | ||
_module.output.forEach(({data}) => | ||
const relativePath = _module.path.replace(projectRoot, ''); | ||
const normalizePath = relativePath.replace(JSCRAMBLER_EXTS, '.js'); | ||
fileNames.add(normalizePath); | ||
_module.output.forEach(({data}) => { | ||
if ((instrument || sourceMaps) && Array.isArray(data.map)) { | ||
sourceMapFiles.push({ | ||
filename: `${normalizePath}.map`, | ||
content: buildModuleSourceMap( | ||
data, | ||
relativePath, | ||
_module.getSource().toString() | ||
) | ||
}); | ||
} | ||
wrapCodeWithTags( | ||
@@ -143,4 +198,4 @@ data, | ||
JSCRAMBLER_END_ANNOTATION | ||
) | ||
); | ||
); | ||
}); | ||
return true; | ||
@@ -147,0 +202,0 @@ } |
{ | ||
"name": "jscrambler-metro-plugin", | ||
"version": "5.4.3", | ||
"version": "5.5.0", | ||
"description": "A plugin to use metro with Jscrambler", | ||
"main": "lib/index.js", | ||
"peerDependencies": { | ||
"metro-source-map": "0.x" | ||
}, | ||
"dependencies": { | ||
"commander": "^2.20.0", | ||
"fs-extra": "^8.0.1", | ||
"jscrambler": "^5.4.3" | ||
"jscrambler": "^5.5.0" | ||
}, | ||
@@ -11,0 +14,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6997
181
0
4
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/generator@7.26.3(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.3(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.26.4(transitive)
+ Added@babel/types@7.26.3(transitive)
+ Added@jridgewell/gen-mapping@0.3.8(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedflow-enums-runtime@0.0.6(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@3.1.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedmetro-source-map@0.81.0(transitive)
+ Addedmetro-symbolicate@0.81.0(transitive)
+ Addednullthrows@1.1.1(transitive)
+ Addedob1@0.81.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedvlq@1.0.1(transitive)
+ Addedxtend@4.0.2(transitive)
Updatedjscrambler@^5.5.0