From 527e4e0992cc54552f2aa41c21f7efec9b3515ed Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Wed, 2 Apr 2014 10:23:05 -0700 Subject: [PATCH] Do path resolution before import processing and style inlining Excluded imports did not have the information to modify their paths correctly, leading to duplication in path. This also reduces the the complexity of path resolution for style inlining, so a win all around. Fixes #27 --- lib/vulcan.js | 18 +++++++----------- package.json | 8 ++++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/vulcan.js b/lib/vulcan.js index 61228483..d1dcfc77 100644 --- a/lib/vulcan.js +++ b/lib/vulcan.js @@ -63,7 +63,7 @@ function inlineSheets($, inputPath, outputPath) { $('link[rel="stylesheet"]').each(function() { var href = this.attr('href'); if (href && !excludeStyle(href)) { - var filepath = path.resolve(inputPath, href); + var filepath = path.resolve(options.outputDir, href); // fix up paths in the stylesheet to be relative to the location of the style var content = pathresolver.rewriteURL(path.dirname(filepath), inputPath, readFile(filepath)); var styleDoc = cheerio.load(''); @@ -99,9 +99,9 @@ function concat(filename) { read[filename] = true; var $ = readDocument(filename); var dir = path.dirname(filename); - processImports($, dir); - inlineSheets($, dir, options.outputDir); pathresolver.resolvePaths($, dir, options.outputDir); + processImports($); + inlineSheets($, dir, options.outputDir); return $.html(); } else { if (options.verbose) { @@ -110,14 +110,11 @@ function concat(filename) { } } -function processImports($, prefix) { +function processImports($) { $(constants.IMPORTS).each(function() { var href = this.attr('href'); - if (excludeImport(href)) { - // rewrite href to be deduplicated later - this.attr('href', pathresolver.rewriteRelPath(prefix, options.outputDir, href)); - } else { - this.replaceWith(concat(path.resolve(prefix, href))); + if (!excludeImport(href)) { + this.replaceWith(concat(path.resolve(options.outputDir, href))); } }); } @@ -156,15 +153,14 @@ function removeCommentsAndWhitespace($) { function handleMainDocument() { // reset shared buffers - imports_before_polymer = []; read = {}; var $ = readDocument(options.input); var dir = path.dirname(options.input); + pathresolver.resolvePaths($, dir, options.outputDir); processImports($, dir); if (options.inline) { inlineSheets($, dir, options.outputDir); } - pathresolver.resolvePaths($, dir, options.outputDir); // strip scripts into a separate file if (options.csp) { diff --git a/package.json b/package.json index 12f972b2..37747f33 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "vulcanize": "bin/vulcanize" }, "dependencies": { - "cheerio": "~0.13.1", - "nopt": "~2.2.0", + "async": "^0.6.2", + "cheerio": "^0.14.0", "clean-css": "~2.1.0", - "uglify-js": "~2.4.8", - "async": "^0.6.2" + "nopt": "~2.2.0", + "uglify-js": "~2.4.8" }, "devDependencies": {}, "scripts": {