duojs / duo

A next-generation package manager for the front-end
3.42k stars 117 forks source link

Invisible dependencies in plugins #353

Open beverlycodes opened 10 years ago

beverlycodes commented 10 years ago

I seem to be hitting edge case after edge case this week. Some background: I've written a plugin that compiles Sass files with Ruby Sass. The plugin does its job just fine, but because Sass has its own internal mechanism for importing other Sass files, it creates a set of invisible dependencies that Duo can't be aware of. I suspect this might be a wider issue for any plugin whose compiler has its own internal means of import/include/require resolution.

The main issue is that changing those internal dependencies does not impact the mtime of the root Sass file, nor does Duo have a list of dependency mtimes to check. Duo just holds onto its cached copy of the root file within duo.json until I touch or update that file.

I'm at a loss for how to resolve this. At first glance, it seems like I need a way to tell Duo "never cache this file in duo.json.", but that means every Duo build will involve a full Sass rebuild. I'd only favor that as a last-resort solution because those builds can get pretty slow.

I thought about making this Sass file a full blown component with a component.json. That's not exactly desirable either, because the Sass file is already a manifest to other Sass files. A component.json would mean having to keep two duplicate manifests in sync in alternate forms, solely for the sake of invalidating one of them to trigger a rebuild.

Short of creating one massive Sass file that does not use Sass imports, I'm not sure how to get changes to my Sass dependencies to affect the mtime of the root file.

dominicbarnes commented 9 years ago

This is a really sticky problem, as you pointed out since duo doesn't know what it doesn't know.

I did find sass/sass#809, which would be immeasurably helpful to this whole process. If you could use the sass cli to output all the files it imports, a plugin could easily traverse those files and set the mtime of the root file as the latest mtime it finds in that tree.

Unfortunately, sass doesn't support this yet, but perhaps if we get more people to request this it will become a reality. :)

stephenmathieson commented 9 years ago

yeah theres really nothing we can do here. if sass handles imports before duo can get to them, there's no way of us knowing anything

frankwallis commented 9 years ago

I have a similar issue with typescript declaration files - I thought maybe the plugin should call duo.include to 'include' these files in the build after it has started?