mattgoldspink / grunt-sencha-dependencies

Grunt task to get the list of Ext.require dependencies in your application
MIT License
32 stars 22 forks source link

handle http files #23

Open revolunet opened 11 years ago

revolunet commented 11 years ago

Hi Matt,

I'm not sure about this, but would it be possible to handle http served files instead of local files ? I mean i have some index dynamically generated (eg:php) and would be cool to analyse it directly instead of a local index.html.

if it is then we could work on a PR with that feature.

Thanks

revolunet commented 11 years ago

Matt,

Can you please explain why can't we just open the index.html/php file in phantomjs and live switch the debug-all.js file to debug.js and inject the bridge directly ? I think we can intercept in the onResourceRequestedand change file accordingly, dont you ?

Instead of creating a tempfile; Maybe i miss some points though so your opinion is very appreciated.

Thanks

mattgoldspink commented 11 years ago

@revolunet Yes - that makes perfect sense, especially when adding support for remote files. I guess my only question is how should we best let the user configure the path to map the remote files to local ones. We'd need to convert the requested url's to local ones on disk, I guess some mapping configuration like:

     urlMapping: {
         '/lib': 'app/lib'
     }

Any thoughts/opinions? I'll take a stab at refactoring the current code to do this over the weekend.

revolunet commented 11 years ago

Thanks Matt; but why would we need local mapping ?

My naive opinion is that we can directly open the web page, analyse the loader and extract all the dependencies directly, cant we ?

mattgoldspink commented 11 years ago

The idea with this task was to be able to JUST generate a list of files for other tasks to use. This gives a greater flexibility of what people can do next:

This keeps both this task nice and simple - I don't have to bother writing a concat/minifier/xyz next step feature that people might want to use in their build pipeline.

Unfortunately these other grunt tasks won't work with 'http' url, they all are all based on files on disk, hence the need for the mapping from a http request to the local file on disk.

revolunet commented 11 years ago

Ok thanks, i understand, you're perfectly right, separations of concerns is what makes grunt so flexible and powerful.

So your url mapping proposal makes sense. We just need to setup (one or more) url to path mapping in the config.

Do you think the "live changing of the source" approach (using phantomjs onResourceRequested) makes sense ?

Id be please to help so if i can investigate/code something, just tell me :)

Thanks

mattgoldspink commented 11 years ago

@revolunet Sorry for the lack of response on this. I started working on it last weekend and quickly hit some problems that I've not managed to solve. The problem I'm facing is that I don't get passed a networkRequest object in the onResourceRequested callback. So it's not possible for me to change the url. I spent a bit of time trying to figure out why - I have a feeling it could be due to the requests being made for filesystem urls and not http urls, but I'm not 100% sure.

Feel free to take a look into this if you want to. I'm sure two people looking into it will help get it done a little quicker.

revolunet commented 11 years ago

@mattgoldspink : thanks for looking at this.

We're making some tests in that direction with a different approach and will give you our results asap.

From what i understand, all the dependency 'detection' is made using Ext.Loader.history when the application startsup. But this doesn't cover dependencies loaded by objects that appear later in the application, does it ?

Eg: i have a button that instantiate a custom class that uses some new Ext layout or xtypes. Using ext-debug.js we can see that the files are loaded "on demand" and not on application startup and thus the dependency is not detected.

How could we deal with this ?