Skip to content

Commit

Permalink
Fixed prefixed file copy operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Nov 19, 2012
1 parent 1ecf22b commit 67c4f74
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function literalNode(href, id) {

function lookupPath(url, paths, options) {
var resolutions = options.resolutions || [0],
original = url.href,
dir = dirname(url.pathname),
ext = extname(url.pathname),
base = basename(url.pathname, ext);
Expand Down Expand Up @@ -155,13 +156,16 @@ function lookupPath(url, paths, options) {
}

// Remap relative paths
var filePath = href;
if (options.externalPrefix && !/^\//.test(href)) {
href = options.externalPrefix + href;
}

return {
resolution: parseFloat(resolution),
found: found,
original: original,
filePath: filePath,
href: href
};
});
Expand Down Expand Up @@ -200,9 +204,10 @@ function outputPath(resolution, id, options) {

// To large
if (buf.length > sizeLimit) {

// If copy files flag is true and not an absolute url
if (options.copyFiles && !/^\//.test(resolution.href)) {
var relativeDir = dirname(resolution.href),
if (options.copyFiles && !/^\//.test(resolution.filePath)) {
var relativeDir = dirname(resolution.filePath),
outputDir = options.outdir || dirname(this.filename),
components = relativeDir.split('/');

Expand All @@ -216,7 +221,7 @@ function outputPath(resolution, id, options) {
}
}
}
fs.writeFileSync(outputDir + '/' + basename(resolution.href), buf);
fs.writeFileSync(outputDir + '/' + basename(resolution.filePath), buf);
}
return literalNode(resolution.href);
}
Expand Down

0 comments on commit 67c4f74

Please sign in to comment.