assets-webpack-plugin
Advanced tools
Comparing version 2.0.0 to 2.2.0
18
index.js
var fs = require('fs'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
@@ -25,6 +26,8 @@ // function extend(target, source) { | ||
try { | ||
// check that output folder exists | ||
fs.lstatSync(outputDir).isDirectory(); | ||
// make sure output folder exists | ||
mkdirp.sync(outputDir); | ||
} catch (e) { | ||
compiler.errors.push(new Error('Plugin: Folder not found ' + outputDir)); | ||
compiler.errors.push(new Error( | ||
'Assets Plugin: Could not create output folder' + outputDir | ||
)); | ||
return callback(); | ||
@@ -83,6 +86,2 @@ } | ||
// if (compiler.options.output.publicPath) { | ||
// chunkMap = compiler.options.output.publicPath + chunkMap; | ||
// } | ||
output[chunkName] = chunkMap; | ||
@@ -172,2 +171,3 @@ } | ||
var output = {}; | ||
var publicPath = compilerOptions.output.publicPath || ''; | ||
@@ -183,6 +183,6 @@ if (stringOrArray instanceof Array) { | ||
var kind = Plugin.getAssetKind(compilerOptions, asset); | ||
output[kind] = asset; | ||
output[kind] = publicPath + asset; | ||
} | ||
} else { | ||
output.js = stringOrArray; | ||
output.js = publicPath + stringOrArray; | ||
} | ||
@@ -189,0 +189,0 @@ |
{ | ||
"name": "assets-webpack-plugin", | ||
"version": "2.0.0", | ||
"version": "2.2.0", | ||
"description": "Emits a json file with assets paths", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jshint *.js spec && jasmine-node --captureExceptions spec" | ||
"test": "jshint *.js spec && ./node_modules/.bin/mocha spec" | ||
}, | ||
@@ -27,11 +27,15 @@ "repository": { | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"css-loader": "^0.9.1", | ||
"extract-text-webpack-plugin": "^0.3.8", | ||
"jasmine-node": "^1.14.5", | ||
"jshint": "^2.5.2", | ||
"mkdirp": "^0.5.0", | ||
"lodash": "^3.9.3", | ||
"mocha": "^2.2.5", | ||
"rimraf": "^2.2.8", | ||
"style-loader": "^0.8.3", | ||
"webpack": "^1.3.3-beta1" | ||
}, | ||
"dependencies": { | ||
"mkdirp": "^0.5.1" | ||
} | ||
} |
assets-webpack-plugin | ||
===================== | ||
[ ![Codeship Status for sporto/assets-webpack-plugin](https://codeship.com/projects/c9171f30-f64d-0132-8e3e-02d99c35d383/status?branch=master)](https://codeship.com/projects/85994) | ||
Webpack plugin that emits a json file with assets paths. | ||
@@ -5,0 +7,0 @@ |
var webpack = require('webpack'); | ||
var Plugin = require('../index.js'); | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
@@ -21,3 +23,3 @@ describe('getAssetKind', function() { | ||
var res = Plugin.getAssetKind(webpackConfig, input); | ||
expect(res).toBe('js'); | ||
expect(res).to.eq('js'); | ||
}); | ||
@@ -32,3 +34,3 @@ | ||
var res = Plugin.getAssetKind(webpackConfig, input); | ||
expect(res).toBe('jsMap'); | ||
expect(res).to.eq('jsMap'); | ||
}); | ||
@@ -39,3 +41,3 @@ | ||
var res = Plugin.getAssetKind(webpackConfig, input); | ||
expect(res).toBe('jsMap'); | ||
expect(res).to.eq('jsMap'); | ||
}); | ||
@@ -42,0 +44,0 @@ |
@@ -1,10 +0,16 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var webpack = require('webpack'); | ||
/*jshint expr: true*/ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
// var mocha = require('mocha'); | ||
var chai = require('chai'); | ||
var webpack = require('webpack'); | ||
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
var rm_rf = require('rimraf'); | ||
var mkdirp = require('mkdirp'); | ||
var Plugin = require('../index.js'); | ||
var rm_rf = require('rimraf'); | ||
var mkdirp = require('mkdirp'); | ||
var _ = require('lodash'); | ||
var Plugin = require('../index.js'); | ||
var expect = chai.expect; | ||
var OUTPUT_DIR = path.join(__dirname, '../dist'); | ||
var OUTPUT_DIR = path.join(__dirname, '../tmp'); | ||
@@ -22,3 +28,3 @@ function expectOutput(args, done) { | ||
mkdirp(OUTPUT_DIR, function(err) { | ||
expect(err).toBeFalsy(); | ||
expect(err).to.be.null; | ||
@@ -28,11 +34,15 @@ outputFile = outputFile || 'webpack-assets.json'; | ||
webpack(webpackConfig, function(err, stats) { | ||
expect(err).toBeFalsy(); | ||
expect(stats.hasErrors()).toBe(false); | ||
expect(err).to.be.null; | ||
expect(stats.hasErrors()).to.be.false; | ||
var content = fs.readFileSync(path.join(OUTPUT_DIR, outputFile)).toString(); | ||
if (expectedResult instanceof RegExp) { | ||
expect(content).toMatch(expectedResult); | ||
if (_.isRegExp(expectedResult)) { | ||
expect(content).to.match(expectedResult); | ||
} else if(_.isString(expectedResult)) { | ||
expect(content).to.contain(expectedResult); | ||
} else { | ||
expect(content).toContain(expectedResult); | ||
// JSON object provided | ||
var actual = JSON.parse(content); | ||
expect(actual).to.eql(expectedResult); | ||
} | ||
@@ -59,3 +69,3 @@ | ||
plugins: [new Plugin({ | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -90,3 +100,3 @@ }; | ||
plugins: [new Plugin({ | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -103,3 +113,2 @@ }; | ||
}; | ||
expected = JSON.stringify(expected); | ||
@@ -124,3 +133,3 @@ var args = { | ||
filename: 'foo.json', | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -134,3 +143,2 @@ }; | ||
}; | ||
expected = JSON.stringify(expected); | ||
@@ -146,21 +154,2 @@ var args = { | ||
it('registers a webpack error when output folder doesnt exists', function(done) { | ||
var webpackConfig = { | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
path: 'notFound' | ||
})] | ||
}; | ||
webpack(webpackConfig, function(err, stats) { | ||
expect(stats.hasErrors()).toBe(true); | ||
expect(stats.toJson().errors[0]).toContain('Plugin'); | ||
done(); | ||
}); | ||
}); | ||
it('works with source maps', function(done) { | ||
@@ -176,3 +165,3 @@ | ||
plugins: [new Plugin({ | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -188,4 +177,2 @@ }; | ||
expected = JSON.stringify(expected); | ||
var args = { | ||
@@ -208,3 +195,3 @@ config: webpackConfig, | ||
plugins: [new Plugin({ | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -232,13 +219,6 @@ }; | ||
plugins: [new Plugin({ | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
}; | ||
// var expected = { | ||
// main: { | ||
// js: "index-bundle-[0-9a-f]+\.js" | ||
// } | ||
// }; | ||
// expected = JSON.stringify(expected); | ||
var expected = /{"main":{"js":"index-bundle-[0-9a-f]+\.js"}}/; | ||
@@ -274,3 +254,3 @@ | ||
new Plugin({ | ||
path: 'dist' | ||
path: 'tmp' | ||
}) | ||
@@ -292,3 +272,2 @@ ] | ||
}; | ||
expected = JSON.stringify(expected); | ||
@@ -303,3 +282,3 @@ var args = { | ||
xit('generates a default file with multiple compilers', function(done) { | ||
it.skip('generates a default file with multiple compilers', function(done) { | ||
var webpackConfig = [ | ||
@@ -316,3 +295,3 @@ { | ||
multiCompiler: true, | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -330,3 +309,3 @@ }, | ||
multiCompiler: true, | ||
path: 'dist' | ||
path: 'tmp' | ||
})] | ||
@@ -344,3 +323,2 @@ } | ||
}; | ||
expected = JSON.stringify(expected); | ||
@@ -355,3 +333,32 @@ var args = { | ||
it('includes full publicPath', function(done) { | ||
var webpackConfig = { | ||
devtool: 'sourcemap', | ||
entry: path.join(__dirname, 'fixtures/one.js'), | ||
output: { | ||
path: OUTPUT_DIR, | ||
publicPath: '/public/path/', | ||
filename: 'index-bundle.js' | ||
}, | ||
plugins: [new Plugin({ | ||
path: 'tmp' | ||
})] | ||
}; | ||
var expected = { | ||
main: { | ||
js: '/public/path/index-bundle.js', | ||
jsMap: '/public/path/index-bundle.js.map' | ||
} | ||
}; | ||
var args = { | ||
config: webpackConfig, | ||
expected: expected | ||
}; | ||
expectOutput(args, done); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
15997
477
111
1
9
+ Addedmkdirp@^0.5.1
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)