wiledal / gulp-include

Enables functionality similar to that of snockets / sprockets or other file insertion compilation tools.
158 stars 68 forks source link

Variables not scoped properly #69

Closed vwochnik closed 8 years ago

vwochnik commented 8 years ago

The variables used by this plugin are not scoped properly, i.e. encapsulated in an IIFE, such that when two instances of include run in parallel with different includePaths for instance, it's getting very messy.

For now, am reloading the module for each successive call:

delete require.cache[require.resolve("gulp-include")];
var include = require("gulp-include");
lukasbestle commented 8 years ago

+1!

It also causes an issue with the require syntax if two files are built in parallel. The two instances will share the includedFiles variable and required files are only included into the first file even though all instances are completely independent and shouldn't be sharing this variable.

If a proper rewrite with functions that don't access the global scope is too much work for you, I recommend wrapping everything with a function and exporting that function. The global variables will then be specific to the function call they originated from.

wiledal commented 8 years ago

Sorry for the late reaction. I'll look into this asap, shouldn't be a huge fix. I have patched similar issues before, but never considered parallel building.

wiledal commented 8 years ago

Solved in 2.3.1, let me know if you have any issues.