-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading Exception #760
Comments
No, I think the root reason is OUTPUT PATH IS WRONG
So I can get the exception say Reproduce ReposI create a reproduce repos: https://github.com/njw6622/test-obfuscator.git git clone https://github.com/njw6622/test-obfuscator.git
cd test-obfuscator
npm i
npm test |
Ok. But the problem is that i can't test it, because i'm developing under UNIX environment ( |
Yes, i managed to reproduce the problem. |
Thank you. |
First, I added some Code from screenshotconfig.json{ "optionsPreset": "default", "sourceMap": true, "sourceMapFileName": "abcdefg" } Console output writeFile: "dist\src\a.js" obfuscatedCode.getObfuscatedCode() mkdirpSync: dist\src undefined writeFile: "/abcdefg.js.map" obfuscatedCode.getSourceMap() mkdirpSync: / undefined [javascript-obfuscator-cli] Error in file: src\a.js... Error: EPERM: operation not permitted, mkdir 'D:\' at Object.mkdirSync (fs.js:840:3) at mkdirpNativeSync (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\mkdirp\lib\mkdirp-native.js:26:17) at Object.this (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\mkdirp\index.js:22:7) at t.ObfuscatedCodeWriter.ObfuscatedCodeWriter [as writeFile] (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\utils\SourceCodeReader.ts:21:32) at F.apply (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\JavaScriptObfuscatorCLI.ts:226:74) at F.obfuscatedCodeWriter (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\decorators\Initializable.ts:61:39) at F.apply (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\JavaScriptObfuscatorCLI.ts:197:14) at F.value (D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\decorators\Initializable.ts:61:39) at D:\_PROJECTS\_WEB\test2\test-obfuscator\node_modules\javascript-obfuscator\dist\webpack:\JavaScriptObfuscator\src\cli\JavaScriptObfuscatorCLI.ts:188:5 at Array.forEach () npm ERR! Test failed. See above for more details. The exception is caused by Code from screenshottest.jsconst mkdirp = require("mkdirp"); mkdirp.sync("/") Console output internal/fs/utils.js:230 throw err; ^ Error: EPERM: operation not permitted, mkdir 'D:\' �[90m at Object.mkdirSync (fs.js:840:3)�[39m at mkdirpNativeSync (D:\_PROJECTS\_WEB\test2\test\node_modules\�[4mmkdirp�[24m\lib\mkdirp-native.js:25:17) at Function.mkdirpSync [as sync] (D:\_PROJECTS\_WEB\test2\test\node_modules\�[4mmkdirp�[24m\index.js:21:7) at Object. (D:\_PROJECTS\_WEB\test2\test\test.js:2:8) �[90m at Module._compile (internal/modules/cjs/loader.js:1158:30)�[39m �[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)�[39m �[90m at Module.load (internal/modules/cjs/loader.js:1002:32)�[39m �[90m at Function.Module._load (internal/modules/cjs/loader.js:901:14)�[39m �[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)�[39m �[90m at internal/main/run_main_module.js:18:47�[39m { errno: �[33m-4048�[39m, syscall: �[32m'mkdir'�[39m, code: �[32m'EPERM'�[39m, path: �[32m'D:\\'�[39m } The problem is that function getOutputSourceMapPath is generating strange paths. Code from screenshottest_codeWriter__getOutputSourceMapPath.jsconst getOutputSourceMapPath = (outputCodePath, sourceMapFileName = '') => { if (sourceMapFileName) { outputCodePath = `${outputCodePath.substring( 0, outputCodePath.lastIndexOf('/') )}/${sourceMapFileName}`; } Console output getOutputSourceMapPath("", "abcdefg") = /abcdefg.js.map getOutputSourceMapPath("./", "./abcdefg") = .js.map getOutputSourceMapPath("", "./abcdefg") = /.js.map getOutputSourceMapPath("", "./abcdefg") = /.js.map getOutputSourceMapPath("path.with/dot.in.name/", "abcdefg") = path.js.map getOutputSourceMapPath("pathwith/dot.in.name/", "abcdefg") = pathwith/dot.js.map getOutputSourceMapPath("dir/dist", "abcdefg.some.suffix.maybe") = dir/abcdefg.js.map getOutputSourceMapPath("path.with/dot.in.name/", "abcdefg.some.suffix.maybe") = path.js.map getOutputSourceMapPath("/dir/dist", "abcdefg") = /dir/abcdefg.js.map getOutputSourceMapPath("/dir", "abcdefg") = /abcdefg.js.map getOutputSourceMapPath("dir/dist", "abcdefg") = dir/abcdefg.js.map getOutputSourceMapPath("dir", "abcdefg") = /abcdefg.js.map getOutputSourceMapPath("D:/dir/dist", "abcdefg") = D:/dir/abcdefg.js.map getOutputSourceMapPath("D:/dir/dist", "../abcdefg") = D:/dir/.js.map Also i remember that getOutputCodePath also had problems on Windows #576 So I think that working with paths needs refactoring and more tests, but I don't know good ways to do it. Maybe path.resolve is better for this? Also it may exclude bugs with splitting by ".". |
Same here on Windows even with one file instead of whole directory. My workaround is to specify a full path for the source map file. I guess this doesn't work for directories. I remember that I had a problem creating nested directories on Windows and Linux a few years ago. I didn't look into the problem in detail, but I leave you this code which is still in use and maybe helpul here if it's the same issue. It works like icl.pathDelimRegex = /[\/\\]/;
icl.getDirPathByFilePath = function(path)
{
var pathEntities = path.split(icl.pathDelimRegex);
pathEntities.pop();
return pathEntities.join("/");
};
icl.createDirDone = function(dir, fprops)
{
if (fprops === undefined)
{
fprops = 0o777;
}
var d = icl.Deferred();
function createDirRcsv(dirEntities, i)
{
var curDir = dirEntities.slice(0, i).join("/");
fs.mkdir(curDir, fprops, function(err) {
if (err && err.code !== "EEXIST")
{
d.reject(err);
}
else if (i <= dirEntities.length)
{
createDirRcsv(dirEntities, i+1);
}
else
{
d.resolve();
}
});
}
var dirEntities = dir.split(icl.pathDelimRegex);
var i = 1;
if (/^[\\\/]{2}/.test(dir))
{
i = 3;
}
else if (!dirEntities[0].length || dirEntities[0][dirEntities[0].length - 1] === ":")
{
// absolute path beginning with "/" (Linux etc.) or "X:" (Windows)
i = 2;
}
createDirRcsv(dirEntities, i);
return d.promise();
};
// Then it's used like that:
icl.createDirDone(icl.getDirPathByFilePath(path)).then(/*...*/); |
I managed to setup TravisCI build under windows. It fails with the same error. So, now i'll try to fix it |
Anybody can test this PR: |
Merged to the |
Thank you! |
You can test it right now directly from |
Have anybody tested this? |
Sorry, I need more time, I think I'm ready in a few hours |
I tested it and it works with master. I also reproduced the error from last week with the old version before, to make sure I can trust the positive result. Thanks for fixing it! |
Nice! I'll release the new version soon. |
Released as |
When I want to obfuscate one directory like this:
javascript-obfuscator <srcDir> --output <destDir> --config <myConfig>
If in my config I assign value to
sourceMapFileName
, then an exception thown:The exception is too terrible and I found out reason after one day...
Expected Behavior
So when obfuscating one directory the option
sourceMapFileName
should not be set?If set I want get correct prompt... Thanks!
Your Environment
The text was updated successfully, but these errors were encountered: