Open leewz opened 7 years ago
The short answer is: no.
It is a bug, or at least the propagation of a bug.
Those options won't work, because inject
sees the wrong path.
To be more explicit:
The path being injected is not correct in any combination of starting/ending locations. I think it's because I used a relative path for gulp.src
's base
option, but the gulp docs did the same.
IMO I think the plugins not setting a correct path is the problem and not inject
.
But please show me an excerpt of your code and I think we can solve this without changing any of the plugins.
I made a testcase here: https://github.com/hparra/gulp-rename/issues/71#issuecomment-257401362
The line in gulp-rename
that makes path
relative: https://github.com/hparra/gulp-rename/blob/master/index.js#L54
file.path = Path.join(file.base, path);
There are other plugins that turn relative .base
into relative .path
, so I figured inject
could just resolve .path
before it uses it. Currently, inject
adds a slash to a relative path instead of resolving .path
(and ignores targetFile.base
):
var base = opt.relative ? path.dirname(addRootSlash(unixify(targetFile.path))) : addRootSlash(unixify(sourceFile.cwd));
Using an absolute path for .base
solves the issue, but relative .base
is in an example in gulp's docs. Perhaps Vinyl.js should automatically turn base
and path
absolute?
Seems that
inject
doesn't like when fileToInject.path isn't absolute. It should be absolute, but some libraries don't always set it properly (such asgulp-rename
andgulp-concat
).Should
gulp-inject
check for and handle the case where.path
is not absolute?