Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Ignore query string in dest and src when generate grunt config. #443

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/configwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var deepMerge = function (origCfg, cfg) {
return outCfg;
};

// convert url to path
var pathify = function (url) {
return url.replace(/\?.*$/g, '');
};

//
// Create a config writer for the furnished flow.
// The created config will:
Expand Down Expand Up @@ -146,6 +151,10 @@ ConfigWriter.prototype.process = function (file, config) {
}

lfile.blocks.forEach(function (block) {
block = _.cloneDeep(block);
block.dest = pathify(block.dest);
block.src = block.src.map(pathify);

// FIXME: support several searchPath...
var context = {
inDir: self.root || lfile.searchPath[0],
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/block_with_query_string_in_url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- build:js foo.js?type=foo -->
<script src="baz.js?type=baz"></script>
<!-- endbuild -->
16 changes: 16 additions & 0 deletions test/test-usemin.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,22 @@ describe('useminPrepare', function () {
assert.equal(copyCfg.generated.files[0].dest, path.normalize('dist/scripts/plugins.js'));
});

it('should allow query string in url', function () {
grunt.log.muted = true;
grunt.config.init();
grunt.config('useminPrepare', {
html: 'index.html'
});
grunt.file.copy(path.join(__dirname, 'fixtures/block_with_query_string_in_url.html'), 'index.html');
grunt.task.run('useminPrepare');
grunt.task.start();

var concatCfg = grunt.config('concat');
assert.ok(concatCfg);
assert.equal(concatCfg.generated.files[0].dest, path.normalize('.tmp/concat/foo.js'));
assert.deepEqual(concatCfg.generated.files[0].src, [path.normalize('baz.js')]);
});

it('should allow to post configure generated steps', function () {

var concatPostConfig = {
Expand Down