-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Names of files processed by Minify plugin can't contain Special characters (, ).
Also, more special character, like * can't be used in arguments.
environment: Windows
possible solution:
- check escaping of ( )
- avoid CMD shell
I also included my work-around.
Although it can't be used to fix the problem, maybe it will come useful for testing the issue.
Or for someone to use it as a workaround.
I was not able to un-minify files which name include brackets: assets_manifest (8).min.js
It's also not possible to use * to define comments to remove in plugin option file: "comments_to_keep": "/^(?!XXX).*$/"
The error dialog shows that brackets are being escaped ^^(8^^), but this doesn't do the trick, at least on my PC.
node.js doesn't have a problem with these characters, they only needs to be escaped/avoided
because of a CMD (BAT) file, or more specifically CMD shell.
The process is, that
Minify plugin by default calls uglifyjs, Windows will find uglifyjs.cmd in a folder added to PATH environment variable.
Here: C:\Users\Papo\AppData\Roaming\npm\uglifyjs.cmd
this bat will in return call: node "%~dp0\node_modules\uglify-js\bin\uglifyjs" %*
To avoid the CMD shell, I tried to define the command in Minify plugin:
"uglifyjs_command": "node C:\\Users\\Papo\\AppData\\Roaming\\npm\\node_modules\\uglify-js\\bin\\uglifyjs"
But the same problem with ^^( caused error (screenshot below)
The plugin(?) is trying to escape the brackets.
(maybe it can decide if do escape based on presence of bat/cmd extension in uglifyjs_command)
So I did a PowerShell script, where I translated the contents of the uglify.cmd and
as PowerShell doesn't have a problem with (), I removed the ^^ from all arguments.
I than added:
"uglifyjs_command": "PowerShell.exe -ExecutionPolicy Unrestricted -File C:\Users\Papo\AppData\Roaming\npm\uglifyjs.ps1"
and now I can minimize/un-minimize files with () in their names.
also, I can use * (I haven't tested comments_to_keep with * yet, but * shows in a log file)
there is one weirdness though, the single ^ from: "comments_to_keep": "/^(?!XXX).*$/", is missing.
log doesn't show it, so it probably gets removed before the ps1 script
echo "args before:`n$args" | Out-File c:\_test\uglifyjs.log
for ($i=0; $i -lt $args.Length; $i++) {
$args[$i] = $args[$i].Replace("^^","")
}
echo "`nargs after:`n$args" | Out-File c:\_test\uglifyjs.log -Append
if (Test-Path -LiteralPath $PSScriptRoot\node.exe) {
&$PSScriptRoot\node.exe "$PSScriptRoot\node_modules\uglify-js\bin\uglifyjs" $args
} else {
$env:PATHEXT = $env:PATHEXT.Replace(".js","")
$env:PATHEXT = $env:PATHEXT.Replace(";;",";")
&node "$PSScriptRoot\node_modules\uglify-js\bin\uglifyjs" $args
}
