alexo / wro4j

New project location is:https://github.com/wro4j/wro4j
442 stars 110 forks source link

Exception for partial JS file #193

Closed FagnerMartinsBrack closed 10 years ago

FagnerMartinsBrack commented 10 years ago

I have a partial JS file named intro-win-jquery.js that I use to wrap non AMD module into a proper one, mocking the gobal variabled and cleaning after the script is executed:

intro-win-jquery.js:

define( ["jquery"], function( $ ) {
    var jQuery = $;
    window.jQuery = $;

Everything works fine using maven plugin without minification, but when I am going to minify all my resources I get the following exception:

[INFO] processing group: jquery.highcharts.js
0    ERROR RhinoScriptBuilder   - JavaScriptException occured: Could not execute the script because: 
{
  "message": "Unexpected token: eof (undefined)",
  "line": 3.0,
  "col": 20.0,
  "pos": 73.0,
  "stack": null
}
1    ERROR ExceptionHandlingProcessorDecorator - Failed to process the resource: ro.isdc.wro.model.resource.Resource@54e8d586[JS,/js/amdify/intro-win-jquery.js,true] using processor: ro.isdc.wro.extensions.processor.js.UglifyJsProcessor@369d61aa. Reason: Could not execute the script because: 
{
  "message": "Unexpected token: eof (undefined)",
  "line": 3.0,
  "col": 20.0,
  "pos": 73.0,
  "stack": null
}
[ERROR] Exception occured while processing: ro.isdc.wro.WroRuntimeException: Could not execute the script because: 
{
  "message": "Unexpected token: eof (undefined)",
  "line": 3.0,
  "col": 20.0,
  "pos": 73.0,
  "stack": null
}, class: ro.isdc.wro.WroRuntimeException,caused by: 
ro.isdc.wro.WroRuntimeException: Could not execute the script because: 
{
  "message": "Unexpected token: eof (undefined)",
  "line": 3.0,
  "col": 20.0,
  "pos": 73.0,
  "stack": null
}
    at ro.isdc.wro.extensions.script.RhinoScriptBuilder.evaluate(RhinoScriptBuilder.java:203)
    at ro.isdc.wro.extensions.processor.support.uglify.UglifyJs.process(UglifyJs.java:155)
    at ro.isdc.wro.extensions.processor.js.BeautifyJsProcessor.process(BeautifyJsProcessor.java:77)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.LazyProcessorDecorator.process(LazyProcessorDecorator.java:49)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.SupportAwareProcessorDecorator.process(SupportAwareProcessorDecorator.java:39)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.ExceptionHandlingProcessorDecorator.process(ExceptionHandlingProcessorDecorator.java:56)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.BenchmarkProcessorDecorator.process(BenchmarkProcessorDecorator.java:44)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.DefaultProcessorDecorator.process(DefaultProcessorDecorator.java:42)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor$2.process(PreProcessorExecutor.java:227)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor.applyPreProcessors(PreProcessorExecutor.java:207)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor.processAndMerge(PreProcessorExecutor.java:103)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor.processAndMerge(PreProcessorExecutor.java:77)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.process(GroupsProcessor.java:83)
    at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:101)
    at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:35)
    at ro.isdc.wro.cache.support.AbstractSynchronizedCacheStrategyDecorator.get(AbstractSynchronizedCacheStrategyDecorator.java:55)
    at ro.isdc.wro.manager.ResourceBundleProcessor.serveProcessedBundle(ResourceBundleProcessor.java:63)
    at ro.isdc.wro.manager.WroManager.process(WroManager.java:159)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.processGroup(Wro4jMojo.java:254)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.doExecute(Wro4jMojo.java:139)
    at ro.isdc.wro.maven.plugin.AbstractWro4jMojo.execute(AbstractWro4jMojo.java:164)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

It seems wro4j fails to process my invalid script file. The thing is that the script file is invalid by design, it is not supposed to execute but just to concatenate.

wro.properties:

preProcessors=uglifyJs
FagnerMartinsBrack commented 10 years ago

When I was writing this issue I realized I was using preProcessors=uglifyJs. Of course it would incur an error because I am telling wro4j to minify before the concatenation would happen. But since I spend a few minutes start writing this, I finished and posted this in the hope that if someone else has the same problem He will find the obvious solution here :D

alexo commented 10 years ago

Thanks for sharing this.

FagnerMartinsBrack commented 10 years ago

Reading again I realized the solution wasn't clear:

You should not be using ...

preProcessors=uglifyJs

... instead you should be using...

postProcessors=uglifyJs

That's because the minification should be done AFTER the concatenation, not before.

alexo commented 10 years ago

@FagnerMartinsBrack Don't you prefer the google closure instead of uglifyJs?

FagnerMartinsBrack commented 10 years ago

What is the difference?

alexo commented 10 years ago

its faster and I don't think it would break the minimization for this particular case when used as preProcessor.

FagnerMartinsBrack commented 10 years ago

The thing is that, for my purpose, it doesn't matter if minification is done before or after the concatenation. The only benefit would be the "faster" thing, but for now there's no bottleneck to be worried about. I will take a look in other tools later, though.