assets-webpack-plugin
Advanced tools
Comparing version 3.0.0 to 3.1.0
74
index.js
@@ -16,3 +16,4 @@ var merge = require('lodash.merge'); | ||
prettyPrint: false, | ||
update: false | ||
update: false, | ||
fullPath: true | ||
}, options); | ||
@@ -31,15 +32,16 @@ this.writer = createQueuedWriter(createOutputWriter(this.options)); | ||
var options = compiler.options; | ||
var stats = compilation.getStats().toJson({ | ||
hash: true, | ||
publicPath: true, | ||
assets: true, | ||
chunks: false, | ||
modules: false, | ||
source: false, | ||
errorDetails: false, | ||
timings: false | ||
}); | ||
var options = compiler.options; | ||
var stats = compilation.getStats().toJson({ | ||
hash: true, | ||
publicPath: true, | ||
assets: true, | ||
chunks: false, | ||
modules: false, | ||
source: false, | ||
errorDetails: false, | ||
timings: false | ||
}); | ||
// publicPath with resolved [hash] placeholder | ||
var publicPath = stats.publicPath || ''; | ||
var assetPath = (stats.publicPath && self.options.fullPath) ? stats.publicPath : ''; | ||
// assetsByChunkName contains a hash with the bundle names and the produced files | ||
@@ -53,31 +55,31 @@ // e.g. { one: 'one-bundle.js', two: 'two-bundle.js' } | ||
// } | ||
var assetsByChunkName = stats.assetsByChunkName; | ||
var assetsByChunkName = stats.assetsByChunkName; | ||
var output = Object.keys(assetsByChunkName).reduce(function (chunkMap, chunkName) { | ||
var assets = assetsByChunkName[chunkName]; | ||
if (!Array.isArray(assets)) { | ||
assets = [assets]; | ||
} | ||
chunkMap[chunkName] = assets.reduce(function (typeMap, asset) { | ||
if (isHMRUpdate(options, asset) || isSourceMap(options, asset)) { | ||
return typeMap; | ||
} | ||
var output = Object.keys(assetsByChunkName).reduce(function (chunkMap, chunkName) { | ||
var assets = assetsByChunkName[chunkName]; | ||
if (!Array.isArray(assets)) { | ||
assets = [assets]; | ||
} | ||
chunkMap[chunkName] = assets.reduce(function (typeMap, asset) { | ||
if (isHMRUpdate(options, asset) || isSourceMap(options, asset)) { | ||
return typeMap; | ||
} | ||
var typeName = getAssetKind(options, asset); | ||
typeMap[typeName] = publicPath + asset; | ||
var typeName = getAssetKind(options, asset); | ||
typeMap[typeName] = assetPath + asset; | ||
return typeMap; | ||
}, {}); | ||
return typeMap; | ||
}, {}); | ||
return chunkMap; | ||
}, {}); | ||
return chunkMap; | ||
}, {}); | ||
self.writer(output, function (err) { | ||
if (err) { | ||
compilation.errors.push(err); | ||
} | ||
callback(); | ||
}); | ||
self.writer(output, function (err) { | ||
if (err) { | ||
compilation.errors.push(err); | ||
} | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -84,0 +86,0 @@ }; |
@@ -19,34 +19,34 @@ var mkdirp = require('mkdirp'); | ||
mkdirp(options.path, function (err) { | ||
if (err) { | ||
return next(error('Could not create output folder ' + options.path, err)); | ||
} | ||
fs.readFile(outputPath, 'utf8', function (err, data) { | ||
if (err) { | ||
return next(error('Could not create output folder ' + options.path, err)); | ||
} | ||
fs.readFile(outputPath, 'utf8', function (err, data) { | ||
// if file does not exist, just write data to it | ||
if (err && err.code !== 'ENOENT') { | ||
return next(error('Could not read output file ' + outputPath, err)); | ||
} | ||
if (err && err.code !== 'ENOENT') { | ||
return next(error('Could not read output file ' + outputPath, err)); | ||
} | ||
// if options.update is false and we're on first run, | ||
// start with empty data | ||
data = overwrite ? '{}' : data || '{}'; | ||
data = overwrite ? '{}' : data || '{}'; | ||
var oldAssets; | ||
try { | ||
oldAssets = JSON.parse(data); | ||
} catch (err) { | ||
oldAssets = {}; | ||
} | ||
var oldAssets; | ||
try { | ||
oldAssets = JSON.parse(data); | ||
} catch (err) { | ||
oldAssets = {}; | ||
} | ||
var assets = merge({}, oldAssets, newAssets); | ||
var output = JSON.stringify(assets, null, options.prettyPrint ? 2 : null); | ||
var assets = merge({}, oldAssets, newAssets); | ||
var output = JSON.stringify(assets, null, options.prettyPrint ? 2 : null); | ||
fs.writeFile(outputPath, output, function (err) { | ||
if (err) { | ||
return next(error('Unable to write to ' + outputPath, err)); | ||
} | ||
firstRun = false; | ||
next(); | ||
}); | ||
}); | ||
fs.writeFile(outputPath, output, function (err) { | ||
if (err) { | ||
return next(error('Unable to write to ' + outputPath, err)); | ||
} | ||
firstRun = false; | ||
next(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}; |
@@ -14,10 +14,10 @@ | ||
return function (err) { | ||
queue.shift(); | ||
callback(err); | ||
queue.shift(); | ||
callback(err); | ||
var next = queue[0]; | ||
if (next) { | ||
processor(next.data, iterator(next.callback)); | ||
} | ||
}; | ||
var next = queue[0]; | ||
if (next) { | ||
processor(next.data, iterator(next.callback)); | ||
} | ||
}; | ||
}; | ||
@@ -31,5 +31,5 @@ | ||
// start processing | ||
processor(data, iterator(callback)); | ||
} | ||
processor(data, iterator(callback)); | ||
} | ||
}; | ||
}; |
@@ -45,19 +45,19 @@ var escapeRegExp = require('escape-string-regexp'); | ||
return this.fields.reduce(function (output, field) { | ||
var replacement = '', | ||
placeholder = field.placeholder, | ||
width = field.width; | ||
var replacement = '', | ||
placeholder = field.placeholder, | ||
width = field.width; | ||
if (field.prefix) { | ||
output += field.prefix; | ||
} | ||
if (placeholder) { | ||
replacement = data[placeholder] || ''; | ||
if (width && (placeholder === 'hash' || placeholder === 'chunkhash')) { | ||
replacement = replacement.slice(0, width); | ||
} | ||
output += replacement; | ||
} | ||
if (field.prefix) { | ||
output += field.prefix; | ||
} | ||
if (placeholder) { | ||
replacement = data[placeholder] || ''; | ||
if (width && (placeholder === 'hash' || placeholder === 'chunkhash')) { | ||
replacement = replacement.slice(0, width); | ||
} | ||
output += replacement; | ||
} | ||
return output; | ||
}, ''); | ||
return output; | ||
}, ''); | ||
} | ||
@@ -91,34 +91,34 @@ }; | ||
if (!char) { | ||
fields.push({ | ||
prefix: prefix, | ||
placeholder: null | ||
}); | ||
break; | ||
} else if (char === '[') { | ||
input = str.slice(pos); | ||
match = SIMPLE_PLACEHOLDER_RX.exec(input); | ||
if (match) { | ||
fields.push({ | ||
prefix: prefix, | ||
placeholder: null | ||
}); | ||
break; | ||
} else if (char === '[') { | ||
prefix: prefix, | ||
placeholder: match[1].toLowerCase() | ||
}); | ||
pos += match[0].length; | ||
prefix = ''; | ||
continue; | ||
} | ||
input = str.slice(pos); | ||
match = SIMPLE_PLACEHOLDER_RX.exec(input); | ||
if (match) { | ||
fields.push({ | ||
prefix: prefix, | ||
placeholder: match[1].toLowerCase() | ||
}); | ||
pos += match[0].length; | ||
prefix = ''; | ||
continue; | ||
} | ||
match = HASH_PLACEHOLDER_RX.exec(input); | ||
if (match) { | ||
fields.push({ | ||
prefix: prefix, | ||
placeholder: match[1].toLowerCase(), | ||
width: parseInt(match[2] || 0, 10) | ||
}); | ||
pos += match[0].length; | ||
prefix = ''; | ||
continue; | ||
} | ||
match = HASH_PLACEHOLDER_RX.exec(input); | ||
if (match) { | ||
fields.push({ | ||
prefix: prefix, | ||
placeholder: match[1].toLowerCase(), | ||
width: parseInt(match[2] || 0, 10) | ||
}); | ||
pos += match[0].length; | ||
prefix = ''; | ||
continue; | ||
} | ||
} | ||
} | ||
prefix += char; | ||
@@ -139,30 +139,30 @@ pos++; | ||
if (i === 0) { | ||
pattern = '^'; | ||
} | ||
pattern = '^'; | ||
} | ||
if (field.prefix) { | ||
pattern += '(' + escapeRegExp(field.prefix) + ')'; | ||
} | ||
pattern += '(' + escapeRegExp(field.prefix) + ')'; | ||
} | ||
if (field.placeholder) { | ||
switch (field.placeholder) { | ||
case 'id': | ||
pattern += '\\d+'; | ||
break; | ||
case 'hash': | ||
case 'chunkhash': | ||
pattern += '[0-9a-fA-F]'; | ||
pattern += field.width ? '{1,' + field.width + '}' : '+'; | ||
break; | ||
case 'name': | ||
case 'file': | ||
case 'filebase': | ||
pattern += '.+?'; | ||
break; | ||
case 'query': | ||
pattern += '(?:\\?.+?)?'; | ||
break; | ||
} | ||
switch (field.placeholder) { | ||
case 'id': | ||
pattern += '\\d+'; | ||
break; | ||
case 'hash': | ||
case 'chunkhash': | ||
pattern += '[0-9a-fA-F]'; | ||
pattern += field.width ? '{1,' + field.width + '}' : '+'; | ||
break; | ||
case 'name': | ||
case 'file': | ||
case 'filebase': | ||
pattern += '.+?'; | ||
break; | ||
case 'query': | ||
pattern += '(?:\\?.+?)?'; | ||
break; | ||
} | ||
} | ||
if (i === length - 1) { | ||
pattern += '$'; | ||
} | ||
pattern += '$'; | ||
} | ||
@@ -169,0 +169,0 @@ return pattern; |
{ | ||
"name": "assets-webpack-plugin", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Emits a json file with assets paths", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,8 +11,8 @@ var getAssetKind = require('../lib/getAssetKind.js'); | ||
webpackConfig = { | ||
output: { | ||
filename: '[name].js?[hash]', | ||
sourceMapFilename: '[file].map[query]' | ||
}, | ||
devtool: 'sourcemap' | ||
}; | ||
output: { | ||
filename: '[name].js?[hash]', | ||
sourceMapFilename: '[file].map[query]' | ||
}, | ||
devtool: 'sourcemap' | ||
}; | ||
}); | ||
@@ -23,12 +23,12 @@ | ||
it('returns js', function () { | ||
var input = 'desktop.js'; | ||
var res = getAssetKind(webpackConfig, input); | ||
expect(res).to.eq('js'); | ||
}); | ||
var input = 'desktop.js'; | ||
var res = getAssetKind(webpackConfig, input); | ||
expect(res).to.eq('js'); | ||
}); | ||
it('returns js with hash', function () { | ||
var input = 'desktop.js?9b913c8594ce98e06b21'; | ||
var res = getAssetKind(webpackConfig, input); | ||
expect(res).to.eq('js'); | ||
}); | ||
var input = 'desktop.js?9b913c8594ce98e06b21'; | ||
var res = getAssetKind(webpackConfig, input); | ||
expect(res).to.eq('js'); | ||
}); | ||
@@ -35,0 +35,0 @@ }); |
@@ -21,23 +21,23 @@ /*jshint expr: true*/ | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
path: 'tmp' | ||
})] | ||
}; | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
path: 'tmp' | ||
})] | ||
}; | ||
var expected = { | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
expected = JSON.stringify(expected); | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -49,26 +49,26 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js'), | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name]-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js'), | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name]-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
var expected = { | ||
one: { | ||
js: 'one-bundle.js' | ||
}, | ||
two: { | ||
js: 'two-bundle.js' | ||
} | ||
}; | ||
one: { | ||
js: 'one-bundle.js' | ||
}, | ||
two: { | ||
js: 'two-bundle.js' | ||
} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -81,24 +81,24 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
filename: 'foo.json', | ||
path: 'tmp' | ||
})] | ||
}; | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
filename: 'foo.json', | ||
path: 'tmp' | ||
})] | ||
}; | ||
var expected = { | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected, | ||
outputFile: 'foo.json' | ||
}; | ||
config: webpackConfig, | ||
expected: expected, | ||
outputFile: 'foo.json' | ||
}; | ||
@@ -111,21 +111,21 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
devtool: 'sourcemap', | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
devtool: 'sourcemap', | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
var expected = { | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -138,9 +138,9 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle-[hash].js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle-[hash].js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
@@ -150,5 +150,5 @@ var expected = /{"main":{"js":"index-bundle-[0-9a-f]+\.js"}}/; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -161,9 +161,9 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name].js?[hash]' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name].js?[hash]' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
@@ -173,5 +173,5 @@ var expected = /{"main":{"js":"main\.js\?[0-9a-f]+"}}/; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -184,41 +184,41 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js'), | ||
two: path.join(__dirname, 'fixtures/two.js'), | ||
styles: path.join(__dirname, 'fixtures/styles.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name]-bundle.js' | ||
}, | ||
module: { | ||
loaders: [ | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js'), | ||
two: path.join(__dirname, 'fixtures/two.js'), | ||
styles: path.join(__dirname, 'fixtures/styles.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name]-bundle.js' | ||
}, | ||
module: { | ||
loaders: [ | ||
{test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader')} | ||
] | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin('[name]-bundle.css', {allChunks: true}), | ||
new Plugin({ | ||
path: 'tmp' | ||
}) | ||
] | ||
}; | ||
] | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin('[name]-bundle.css', {allChunks: true}), | ||
new Plugin({ | ||
path: 'tmp' | ||
}) | ||
] | ||
}; | ||
var expected = { | ||
one: { | ||
js: 'one-bundle.js' | ||
}, | ||
two: { | ||
js: 'two-bundle.js' | ||
}, | ||
styles: { | ||
js: 'styles-bundle.js', | ||
css: 'styles-bundle.css' | ||
} | ||
}; | ||
one: { | ||
js: 'one-bundle.js' | ||
}, | ||
two: { | ||
js: 'two-bundle.js' | ||
}, | ||
styles: { | ||
js: 'styles-bundle.js', | ||
css: 'styles-bundle.css' | ||
} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -231,10 +231,10 @@ expectOutput(args, done); | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
publicPath: '/public/path/[hash]/', | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
publicPath: '/public/path/[hash]/', | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp'})] | ||
}; | ||
@@ -244,5 +244,5 @@ var expected = new RegExp('/public/path/[0-9a-f]+/index-bundle.js', 'i'); | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -252,28 +252,59 @@ expectOutput(args, done); | ||
it('doesn\'t include full publicPath', function (done) { | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
publicPath: '/public/path/[hash]/', | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
path: 'tmp', | ||
fullPath: false | ||
})] | ||
}; | ||
var expected = { | ||
main: { | ||
js: 'index-bundle.js' | ||
} | ||
}; | ||
expected = JSON.stringify(expected); | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
expectOutput(args, done); | ||
}); | ||
it('works with CommonChunksPlugin', function (done) { | ||
var webpackConfig = { | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/common-chunks/one.js'), | ||
two: path.join(__dirname, 'fixtures/common-chunks/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name].js' | ||
}, | ||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({name: 'common'}), | ||
new Plugin({path: 'tmp'}) | ||
] | ||
}; | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/common-chunks/one.js'), | ||
two: path.join(__dirname, 'fixtures/common-chunks/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: '[name].js' | ||
}, | ||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({name: 'common'}), | ||
new Plugin({path: 'tmp'}) | ||
] | ||
}; | ||
var expected = { | ||
one: {js: 'one.js'}, | ||
two: {js: 'two.js'}, | ||
common: {js: 'common.js'} | ||
}; | ||
one: {js: 'one.js'}, | ||
two: {js: 'two.js'}, | ||
common: {js: 'common.js'} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -280,0 +311,0 @@ expectOutput(args, done); |
@@ -11,6 +11,6 @@ var chai = require('chai'); | ||
var config = { | ||
output: { | ||
hotUpdateChunkFilename: 'hmr-yo[id].[hash].js[query]' | ||
} | ||
}; | ||
output: { | ||
hotUpdateChunkFilename: 'hmr-yo[id].[hash].js[query]' | ||
} | ||
}; | ||
var input = 'hmr-yo42.b4d455.js?f00b43'; | ||
@@ -23,6 +23,6 @@ var res = isHMRUpdate(config, input); | ||
var config = { | ||
output: { | ||
hotUpdateChunkFilename: '[id][hash][name]hmr.js[query]' | ||
} | ||
}; | ||
output: { | ||
hotUpdateChunkFilename: '[id][hash][name]hmr.js[query]' | ||
} | ||
}; | ||
var input = '42940455foo-hmr.js?f00b43'; | ||
@@ -35,6 +35,6 @@ var res = isHMRUpdate(config, input); | ||
var config = { | ||
output: { | ||
hotUpdateChunkFilename: '[id][hash][name]hmr.js[query]' | ||
} | ||
}; | ||
output: { | ||
hotUpdateChunkFilename: '[id][hash][name]hmr.js[query]' | ||
} | ||
}; | ||
expect(isHMRUpdate(config, '42940455foo-hmr?f00b43')).to.eq(false); | ||
@@ -41,0 +41,0 @@ }); |
@@ -11,6 +11,6 @@ var chai = require('chai'); | ||
var config = { | ||
output: { | ||
sourceMapFilename: 'sourcemap-yo[id].[hash].js[query]' | ||
} | ||
}; | ||
output: { | ||
sourceMapFilename: 'sourcemap-yo[id].[hash].js[query]' | ||
} | ||
}; | ||
var input = 'sourcemap-yo42.b4d455.js?f00b43'; | ||
@@ -23,6 +23,6 @@ var res = isSourceMap(config, input); | ||
var config = { | ||
output: { | ||
sourceMapFilename: '[id][hash][name]_map.js[query]' | ||
} | ||
}; | ||
output: { | ||
sourceMapFilename: '[id][hash][name]_map.js[query]' | ||
} | ||
}; | ||
var input = '42940455foo_map.js?f00b43'; | ||
@@ -35,6 +35,6 @@ var res = isSourceMap(config, input); | ||
var config = { | ||
output: { | ||
sourceMapFilename: '[id][hash][name]_map.js[query]' | ||
} | ||
}; | ||
output: { | ||
sourceMapFilename: '[id][hash][name]_map.js[query]' | ||
} | ||
}; | ||
expect(isSourceMap(config, '42940455foo.js?f00b43')).to.eq(false); | ||
@@ -41,0 +41,0 @@ }); |
@@ -24,37 +24,37 @@ /*jshint expr: true*/ | ||
var webpackConfig = [ | ||
{ | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'one-bundle.js' | ||
}, | ||
plugins: [plugin] | ||
{ | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js') | ||
}, | ||
{ | ||
entry: { | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'two-bundle.js' | ||
}, | ||
plugins: [plugin] | ||
} | ||
]; | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'one-bundle.js' | ||
}, | ||
plugins: [plugin] | ||
}, | ||
{ | ||
entry: { | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'two-bundle.js' | ||
}, | ||
plugins: [plugin] | ||
} | ||
]; | ||
var expected = { | ||
one: { | ||
js: 'one-bundle.js' | ||
}, | ||
two: { | ||
js: 'two-bundle.js' | ||
} | ||
}; | ||
one: { | ||
js: 'one-bundle.js' | ||
}, | ||
two: { | ||
js: 'two-bundle.js' | ||
} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
@@ -66,21 +66,21 @@ expectOutput(args, done); | ||
var config_1 = { | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'one-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: true})] | ||
}; | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'one-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: true})] | ||
}; | ||
var config_2 = { | ||
entry: { | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'two-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: true})] | ||
}; | ||
entry: { | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'two-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: true})] | ||
}; | ||
@@ -91,6 +91,6 @@ var expected = {one: {js: 'one-bundle.js'}, two: {js: 'two-bundle.js'}}; | ||
webpack(config_1, function (err, stats) { | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
expectOutput(args, done); | ||
}); | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
expectOutput(args, done); | ||
}); | ||
}); | ||
@@ -100,21 +100,21 @@ | ||
var config_1 = { | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'one-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: false})] | ||
}; | ||
entry: { | ||
one: path.join(__dirname, 'fixtures/one.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'one-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: false})] | ||
}; | ||
var config_2 = { | ||
entry: { | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'two-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: false})] | ||
}; | ||
entry: { | ||
two: path.join(__dirname, 'fixtures/two.js') | ||
}, | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'two-bundle.js' | ||
}, | ||
plugins: [new Plugin({path: 'tmp', update: false})] | ||
}; | ||
@@ -125,7 +125,7 @@ var expected = {two: {js: 'two-bundle.js'}}; | ||
webpack(config_1, function (err, stats) { | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
expectOutput(args, done); | ||
}); | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
expectOutput(args, done); | ||
}); | ||
}); | ||
}); |
@@ -13,9 +13,9 @@ | ||
it('parses the empty string', function () { | ||
expect(parseTemplate('').fields).to.eql([ | ||
expect(parseTemplate('').fields).to.eql([ | ||
{prefix: '', placeholder: null} | ||
]); | ||
}); | ||
]); | ||
}); | ||
it('parses consecutive placeholders', function () { | ||
expect(parseTemplate('[id][name][query]').fields).to.eql([ | ||
expect(parseTemplate('[id][name][query]').fields).to.eql([ | ||
{prefix: '', placeholder: 'id'}, | ||
@@ -25,7 +25,7 @@ {prefix: '', placeholder: 'name'}, | ||
{prefix: '', placeholder: null} | ||
]); | ||
}); | ||
]); | ||
}); | ||
it('parses placeholders and prefixes', function () { | ||
expect(parseTemplate('some[id]and[name]then[query]').fields).to.eql([ | ||
expect(parseTemplate('some[id]and[name]then[query]').fields).to.eql([ | ||
{prefix: 'some', placeholder: 'id'}, | ||
@@ -35,28 +35,28 @@ {prefix: 'and', placeholder: 'name'}, | ||
{prefix: '', placeholder: null} | ||
]); | ||
}); | ||
]); | ||
}); | ||
it('handles unknown placeholders', function () { | ||
expect(parseTemplate('some[unknown][id]then[hash:pwnd][query]').fields).to.eql([ | ||
expect(parseTemplate('some[unknown][id]then[hash:pwnd][query]').fields).to.eql([ | ||
{prefix: 'some[unknown]', placeholder: 'id'}, | ||
{prefix: 'then[hash:pwnd]', placeholder: 'query'}, | ||
{prefix: '', placeholder: null} | ||
]); | ||
}); | ||
]); | ||
}); | ||
it('handles wierdly formatted placeholders', function () { | ||
expect(parseTemplate('some[chunk[id]then[whoops[query]]').fields).to.eql([ | ||
expect(parseTemplate('some[chunk[id]then[whoops[query]]').fields).to.eql([ | ||
{prefix: 'some[chunk', placeholder: 'id'}, | ||
{prefix: 'then[whoops', placeholder: 'query'}, | ||
{prefix: ']', placeholder: null} | ||
]); | ||
}); | ||
]); | ||
}); | ||
it('parses hash width syntax', function () { | ||
expect(parseTemplate('[hash:10]and[chunkhash:42]').fields).to.eql([ | ||
expect(parseTemplate('[hash:10]and[chunkhash:42]').fields).to.eql([ | ||
{prefix: '', placeholder: 'hash', width: 10}, | ||
{prefix: 'and', placeholder: 'chunkhash', width: 42}, | ||
{prefix: '', placeholder: null} | ||
]); | ||
}); | ||
]); | ||
}); | ||
@@ -68,38 +68,38 @@ }); | ||
it('matches strings without placeholders', function () { | ||
var tpl = parseTemplate('foo-bar.jsx'); | ||
expect(tpl.matches('foo-bar.jsx')).to.eq(true); | ||
expect(tpl.matches('foo-bar.css')).to.eq(false); | ||
}); | ||
var tpl = parseTemplate('foo-bar.jsx'); | ||
expect(tpl.matches('foo-bar.jsx')).to.eq(true); | ||
expect(tpl.matches('foo-bar.css')).to.eq(false); | ||
}); | ||
it('matches strings with [id] placeholder', function () { | ||
var tpl = parseTemplate('foo-bar.[id].js'); | ||
expect(tpl.matches('foo-bar.666.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar.nope.js')).to.eq(false); | ||
}); | ||
var tpl = parseTemplate('foo-bar.[id].js'); | ||
expect(tpl.matches('foo-bar.666.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar.nope.js')).to.eq(false); | ||
}); | ||
it('matches strings with [name] placeholder', function () { | ||
var tpl = parseTemplate('[name].js'); | ||
expect(tpl.matches('foo-bar.chunk.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar.chunk.css')).to.eq(false); | ||
}); | ||
var tpl = parseTemplate('[name].js'); | ||
expect(tpl.matches('foo-bar.chunk.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar.chunk.css')).to.eq(false); | ||
}); | ||
it('matches strings with [query] placeholder', function () { | ||
var tpl = parseTemplate('[name].js[query]'); | ||
expect(tpl.matches('foo-bar.js?anything')).to.eq(true); | ||
var tpl = parseTemplate('[name].js[query]'); | ||
expect(tpl.matches('foo-bar.js?anything')).to.eq(true); | ||
// query parameter is optional, so this should match too | ||
expect(tpl.matches('foo-bar.js')).to.eq(true); | ||
}); | ||
expect(tpl.matches('foo-bar.js')).to.eq(true); | ||
}); | ||
it('matches strings with [hash] placeholder', function () { | ||
var tpl = parseTemplate('[name]_[hash].js'); | ||
expect(tpl.matches('foo-bar_f00b43.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar_w00t.js')).to.eq(false); | ||
}); | ||
var tpl = parseTemplate('[name]_[hash].js'); | ||
expect(tpl.matches('foo-bar_f00b43.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar_w00t.js')).to.eq(false); | ||
}); | ||
it('matches strings with constrained-width [hash] placeholder', function () { | ||
var tpl = parseTemplate('[name]_[hash:6].js'); | ||
expect(tpl.matches('foo-bar_f00.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar_b4d455.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar_f00b43b47.js')).to.eq(false); | ||
}); | ||
var tpl = parseTemplate('[name]_[hash:6].js'); | ||
expect(tpl.matches('foo-bar_f00.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar_b4d455.js')).to.eq(true); | ||
expect(tpl.matches('foo-bar_f00b43b47.js')).to.eq(false); | ||
}); | ||
@@ -106,0 +106,0 @@ }); |
@@ -13,10 +13,10 @@ var _ = require('lodash'); | ||
if (!args.config) { | ||
throw new Error('Expected args.config'); | ||
} | ||
throw new Error('Expected args.config'); | ||
} | ||
if (!args.expected) { | ||
throw new Error('Expected args.expected'); | ||
} | ||
throw new Error('Expected args.expected'); | ||
} | ||
if (!done) { | ||
throw new Error('Expected done'); | ||
} | ||
throw new Error('Expected done'); | ||
} | ||
@@ -29,27 +29,27 @@ var webpackConfig = args.config; | ||
mkdirp(outputDir, function (err) { | ||
expect(err).to.be.null; | ||
expect(err).to.be.null; | ||
outputFile = outputFile || 'webpack-assets.json'; | ||
outputFile = outputFile || 'webpack-assets.json'; | ||
webpack(webpackConfig, function (err, stats) { | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
webpack(webpackConfig, function (err, stats) { | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
var content = fs.readFileSync(path.join(outputDir, outputFile)).toString(); | ||
var content = fs.readFileSync(path.join(outputDir, outputFile)).toString(); | ||
if (_.isRegExp(expectedResult)) { | ||
expect(content).to.match(expectedResult); | ||
} else if(_.isString(expectedResult)) { | ||
expect(content).to.contain(expectedResult); | ||
} else { | ||
if (_.isRegExp(expectedResult)) { | ||
expect(content).to.match(expectedResult); | ||
} else if(_.isString(expectedResult)) { | ||
expect(content).to.contain(expectedResult); | ||
} else { | ||
// JSON object provided | ||
var actual = JSON.parse(content); | ||
expect(actual).to.eql(expectedResult); | ||
} | ||
var actual = JSON.parse(content); | ||
expect(actual).to.eql(expectedResult); | ||
} | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
913
33726