mishoo / UglifyJS

JavaScript parser / mangler / compressor / beautifier toolkit
http://lisperator.net/uglifyjs/
Other
13.16k stars 1.25k forks source link

Invalid input source map when --source-map content is absolute path #5936

Closed XHighIntell closed 1 month ago

XHighIntell commented 1 month ago

Uglify version (uglifyjs -V) 3.19.3

JavaScript input To make it simple, I have 2 files that are built from Typescript. file.js file.js.map

The uglifyjs CLI command executed: The below command works correctly

uglifyjs "file.js" --compress --mangle --source-map "content='file.js.map',includeSources,url='file.min.js.map'" --output "file.min.js"

But when I use absolute path to the javascript and source map files (content is not changed). I got errors

npx uglifyjs "E:\My Life\OneDrive\Projects\Typescript Template 2\wwwroot\apps\file.js" --compress --mangle --source-map "content='E:\My Life\OneDrive\Projects\Typescript Template 2\wwwroot\apps\file.js.map',includeSources,url='file.min.js.map'" --output "E:\My Life\OneDrive\Projects\Typescript Template 2\wwwroot\apps\file.min.js"

JavaScript output or error produced.

ERROR: invalid input source map: E:My LifeOneDriveProjectsTypescript Template 2wwwrootappsfile.js.map
    at parse_source_map (eval at <anonymous> (E:\My Life\OneDrive\Projects\Typescript Template 2\build\node_modules\uglify-js\tools\node.js:18:1), <anonymous>:24940:15)
    at Object.minify (eval at <anonymous> (E:\My Life\OneDrive\Projects\Typescript Template 2\build\node_modules\uglify-js\tools\node.js:18:1), <anonymous>:25063:38)
    at run (E:\My Life\OneDrive\Projects\Typescript Template 2\build\node_modules\uglify-js\bin\uglifyjs:397:27)
    at Object.<anonymous> (E:\My Life\OneDrive\Projects\Typescript Template 2\build\node_modules\uglify-js\bin\uglifyjs:295:5)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49
XHighIntell commented 1 month ago

Somehow, the cli still needs to escape characters like in javascript to make it work.

--source-map "content='E:\\My Life\\OneDrive\\Projects\\Typescript Template 2\\wwwroot\\apps\\dashboard\\dashboard.js.map',includeSources,url='dashboard.js.map'" 
alexlamsl commented 1 month ago

That is working as expected − content's value is JavaScript string literal, i.e. you need to escape the back-slash (\)