├── .gitignore ├── README.md ├── lib ├── bower-loader.js ├── bower-plugin-logger.js ├── bower-plugin-main-resolver.js ├── bower-plugin-manifest-resolver.js ├── bower-plugin-utils.js └── bower-plugin.js ├── package.json └── test ├── custom-file.js ├── custom-module-directories.js ├── exclusions.js ├── fixtures ├── bower_components │ ├── fixture-fonts.woff │ ├── module-custom-bower-file │ │ ├── custom.json │ │ ├── module0.css │ │ └── module0.js │ ├── module-custom-file-fallback │ │ ├── bower.json │ │ ├── custom.json │ │ ├── module0.css │ │ └── module0.js │ ├── module-missing-bower │ │ └── module0.js │ ├── module-missing-referenced-file │ │ └── bower.json │ ├── module-multiple-js │ │ ├── bower.json │ │ ├── module0.js │ │ └── module1.js │ ├── module-multiple-mixed-with-subdirs │ │ ├── bower.json │ │ ├── css │ │ │ └── module0.css │ │ ├── fonts │ │ │ └── fixture-fonts.woff │ │ └── js │ │ │ └── module0.js │ ├── module-multiple-mixed │ │ ├── bower.json │ │ ├── module0.css │ │ └── module0.js │ ├── module-provided-a │ │ ├── bower.json │ │ └── module0.js │ ├── module-provided-b │ │ ├── bower.json │ │ └── module0.js │ ├── module-single-array │ │ ├── bower.json │ │ └── module0.js │ ├── module-single-string-css │ │ ├── bower.json │ │ └── module0.css │ ├── module-single-string │ │ ├── bower.json │ │ └── module0.js │ └── module-with-exclusions │ │ ├── bower.json │ │ ├── module0.js │ │ └── module1.js ├── custom-module-multiple-js.js ├── custom-module-single-string.js ├── custom_components │ ├── custom-module-multiple-js │ │ ├── bower.json │ │ ├── module0.js │ │ └── module1.js │ └── custom-module-single-string │ │ ├── bower.json │ │ ├── custom-module-single-string-bower.js │ │ ├── custom-module-single-string-node.js │ │ └── package.json ├── integration-with-provide.js ├── module-alias.js ├── module-custom-bower-file.js ├── module-custom-file-fallback.js ├── module-missing-bower.js ├── module-missing-referenced-file.js ├── module-missing.js ├── module-multiple-js.js ├── module-multiple-mixed-with-subdirs.js ├── module-multiple-mixed.js ├── module-single-array.js ├── module-single-string-css.js ├── module-single-string.js ├── module-with-exclusions.js └── require-multiple-modules.js ├── inclusions.js ├── missing.js ├── multi-module.js ├── search-resolve-modules-directories.js ├── single-module.js ├── test-utils.js ├── utils.js ├── with-module-alias.js └── with-provide-plugin.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | dist/ 4 | node_modules/ 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bower Webpack Plugin 2 | 3 | Use [Bower](http://bower.io/) with [Webpack](http://webpack.github.io/). 4 | 5 | # Getting started 6 | 7 | Install the plugin: 8 | 9 | ``` 10 | npm install --save-dev bower-webpack-plugin 11 | ``` 12 | 13 | Add the plugin to your Webpack configuration: 14 | 15 | ```javascript 16 | var BowerWebpackPlugin = require("bower-webpack-plugin"); 17 | module.exports = { 18 | module: { 19 | loaders: [ 20 | { 21 | test: /\.css$/, 22 | loader: "style-loader!css-loader" 23 | } 24 | ] 25 | }, 26 | plugins: [new BowerWebpackPlugin()] 27 | }; 28 | ``` 29 | 30 | # Configuration 31 | 32 | The plugin takes options object as its single argument. 33 | 34 | * `modulesDirectories` {`string[]` or `string`} - the array of extra module directories, the plugin will look for bower components in. Unless `searchResolveModulesDirectories` is `false`, the plugin searches also for modules in directories defined at [`resolve.modulesDirectories`](http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories). 35 | 36 | * `manifestFiles` {`string[]` or `string`} - the names of the bower manifest files. The plugin will try them in the order they are mentioned. The first matching will be used. 37 | 38 | * `includes` {`RegExp[]` or `RegExp`} - the plugin will match files contained in a manifest file, and will include only those which match any of the RegExp expressions. 39 | 40 | * `excludes` {`RegExp[]` or `RegExp`} - the plugin will match files contained in a manifest, and will exclude all files, which match any of the expressions. 41 | 42 | * `searchResolveModulesDirectories` {`boolean`} - if `false`, the plugin will not search [`resolve.modulesDirectories`](http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories) for bower components. 43 | 44 | Using the plugin, without specifying the configuration is equivalent to following: 45 | 46 | ```javascript 47 | plugins: [ 48 | new BowerWebpackPlugin({ 49 | modulesDirectories: ["bower_components"], 50 | manifestFiles: "bower.json", 51 | includes: /.*/, 52 | excludes: [], 53 | searchResolveModulesDirectories: true 54 | }) 55 | ] 56 | ``` 57 | 58 | # Usage 59 | 60 | When the plugin is active, you can require bower modules using `require`. 61 | 62 | # Example 63 | 64 | This example shows how to use Twitter bootstrap installed by `bower` in your project. 65 | 66 | Make sure, you have [bower installed](http://bower.io/#install-bower). 67 | Create new project and install bower-webpack-plugin: 68 | 69 | ``` 70 | npm init 71 | npm install --save-dev webpack file-loader style-loader css-loader bower-webpack-plugin 72 | ``` 73 | 74 | Install *bootstrap* bower component: 75 | 76 | ``` 77 | bower install bootstrap 78 | ``` 79 | 80 | Create an `index.html` file: 81 | 82 | ```html 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
91 |
92 |
93 |

Press the button, to see if Bowerk Webpack Plugin works...

94 | 97 |
98 |
99 | 100 | 101 | 116 |
117 | 118 | 119 | ``` 120 | 121 | Create a `demo.css` file: 122 | 123 | ```css 124 | .main-page { 125 | display: table; 126 | width: 100%; 127 | height: 100%; 128 | min-height: 100%; 129 | background-color: #26A65B; 130 | } 131 | 132 | .message-wrapper { 133 | display: table-cell; 134 | text-align: center; 135 | vertical-align: middle; 136 | } 137 | 138 | .box { 139 | width: 50%; 140 | margin: 0 auto; 141 | background: #F2F1EF; 142 | padding: 30px; 143 | box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); 144 | } 145 | ``` 146 | 147 | Create `entry.js`, where you require bootstrap. 148 | 149 | ```javascript 150 | require("jquery"); 151 | require("bootstrap"); 152 | require("./demo.css"); 153 | ``` 154 | 155 | Twitter bootstrap comes with CSS, JavaScript, Fonts and Less. Let's assume we want to use compiled CSS, and we don't need less files. 156 | 157 | Create `webpack.config.js` with the following content: 158 | 159 | ```javascript 160 | var webpack = require("webpack"); 161 | var BowerWebpackPlugin = require('bower-webpack-plugin'); 162 | 163 | module.exports = { 164 | entry: "./entry.js", 165 | output: { 166 | path: __dirname, 167 | filename: "bundle.js" 168 | }, 169 | module: { 170 | loaders: [ 171 | {test: /\.css$/, loader: "style!css"}, 172 | {test: /\.(woff|svg|ttf|eot)([\?]?.*)$/, loader: "file-loader?name=[name].[ext]"} 173 | ] 174 | }, 175 | plugins: [ 176 | new BowerWebpackPlugin({ 177 | excludes: /.*\.less/ 178 | }), 179 | new webpack.ProvidePlugin({ 180 | $: "jquery", 181 | jQuery: "jquery" 182 | }) 183 | ] 184 | }; 185 | ``` 186 | 187 | Run `webpack` and open the `index.html` file. 188 | 189 | # Release History 190 | 191 | ## 0.1.9 - 28 Sep 2015 192 | 193 | Changes: 194 | * [Respect '.bowerrc' settings](https://github.com/lpiepiora/bower-webpack-plugin/issues/25) 195 | * Use MIT as SPDX license 196 | 197 | ## 0.1.8 - 06 Apr 2015 198 | 199 | Changes: 200 | * [Add 'searchResolveModulesDirectories' option](https://github.com/lpiepiora/bower-webpack-plugin/pull/15) 201 | 202 | ## 0.1.6 - 01 Feb 2015 203 | 204 | Changes: 205 | * [Fix resolving of bower.json, when used in conjunction with other plugins](https://github.com/lpiepiora/bower-webpack-plugin/pull/11) 206 | 207 | ## 0.1.5 - 05 Jan 2015 208 | 209 | Changes: 210 | * [Use data.resource rather than userRequest](https://github.com/lpiepiora/bower-webpack-plugin/pull/9) 211 | 212 | ## 0.1.4 - 13 Dec 2014 213 | 214 | Fixes for issues: 215 | * [The example never finishes and leaks](https://github.com/lpiepiora/bower-webpack-plugin/issues/6) 216 | 217 | ## 0.1.3 - 27 Nov 2014 218 | 219 | Fixes for issues: 220 | * [The example never finishes and leaks](https://github.com/lpiepiora/bower-webpack-plugin/issues/6) 221 | 222 | ## 0.1.2 - 31 Oct 2014 223 | 224 | Fixes for issues: 225 | * [Resolve strategy](https://github.com/lpiepiora/bower-webpack-plugin/issues/5) 226 | 227 | ## 0.1.1 - 30 Oct 2014 228 | 229 | Fixes for issues: 230 | * [Use resolve.modulesDirectories, when resolving bower modules](https://github.com/lpiepiora/bower-webpack-plugin/issues/2) 231 | * [Requesting modules aliased via 'resolve.alias' fails](https://github.com/lpiepiora/bower-webpack-plugin/issues/3) 232 | 233 | ## 0.1.0 - 26 Oct 2014 234 | 235 | Initial release 236 | -------------------------------------------------------------------------------- /lib/bower-loader.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | "use strict"; 26 | 27 | var util = require('util'); 28 | var loaderUtils = require('loader-utils'); 29 | 30 | /** 31 | * Loads bower main files from a specified bower manifest file 32 | * @param source source file, which must be loaded 33 | * @returns {string} containing require for each included file 34 | * @function 35 | */ 36 | module.exports = function (source) { 37 | var bower = JSON.parse(source), 38 | result = [], 39 | bowerMainFiles = (util.isArray(bower.main)) ? bower.main : [bower.main], 40 | bowerMainIncludes = loaderUtils.parseQuery(this.query).include; 41 | 42 | function includesContain(entry) { 43 | return bowerMainIncludes.some(function (include) { 44 | return entry === include; 45 | }); 46 | } 47 | 48 | this.cacheable(); 49 | 50 | bowerMainFiles.filter(includesContain).forEach(function (item) { 51 | if (/\.js$/.test(item)) { 52 | result.push("module.exports = require(" + JSON.stringify("./" + item) + ");"); 53 | } else { 54 | result.push("require(" + JSON.stringify("./" + item) + ");"); 55 | } 56 | }); 57 | 58 | return result.join("\n"); 59 | 60 | }; -------------------------------------------------------------------------------- /lib/bower-plugin-logger.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | "use strict"; 26 | 27 | /** 28 | * A helper utility to log information 29 | * @returns {Logger} 30 | * @constructor 31 | */ 32 | function Logger() { 33 | if (!(this instanceof Logger)) { 34 | return new Logger(); 35 | } 36 | 37 | this.logData = []; 38 | 39 | } 40 | 41 | module.exports = Logger; 42 | 43 | /** 44 | * Logs a message 45 | * @param {string} msg - the message to be logged 46 | */ 47 | Logger.prototype.log = function (msg) { 48 | this.logData.push(" " + msg); 49 | }; 50 | 51 | /** 52 | * Writes out logged information to the callback.log, if such method exists 53 | * @param callback the callback 54 | */ 55 | Logger.prototype.writeOut = function (callback) { 56 | if (callback.log) { 57 | this.logData.forEach(callback.log, callback); 58 | } 59 | this.logData.length = 0; 60 | }; -------------------------------------------------------------------------------- /lib/bower-plugin-main-resolver.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | "use strict"; 26 | 27 | var Q = require("q"); 28 | var path = require("path"); 29 | 30 | /** 31 | * The object, returned when the main files are resolved within a manifest file. 32 | * @typedef {Object} MainResolver~ResolveResult 33 | * @property {string} manifestFile - a manifest file, which was resolved 34 | * @property {string[]} mainFiles - the list of resolved main files, which were found in the manifestFile 35 | */ 36 | 37 | /** 38 | * Resolves main files from a bower manifest file 39 | * @param webpackPlugin 40 | * @param {RegExp[]} includes - the list of patterns for matching files to include 41 | * @param {RegExp[]} excludes - the list of patterns for matching files to exclude 42 | * @returns {MainResolver} 43 | * @constructor 44 | */ 45 | function MainResolver(webpackPlugin, includes, excludes) { 46 | if (!(this instanceof MainResolver)) { 47 | return new MainResolver(webpackPlugin, includes, excludes); 48 | } 49 | this.webpackPlugin = webpackPlugin; 50 | this.includes = includes; 51 | this.excludes = excludes; 52 | } 53 | 54 | module.exports = MainResolver; 55 | 56 | /** 57 | * @param manifestFile 58 | * @lends {MainResolver.resolve} 59 | * @returns {Promise} a promise, which when resolved successfully, will contain a {@link MainResolver~ResolveResult} or will contain an {@link Error} if rejected. 60 | */ 61 | MainResolver.prototype.resolve = function (manifestFile) { 62 | var basedir = path.dirname(manifestFile), 63 | includes = this.includes, 64 | excludes = this.excludes, 65 | fileSystem = this.webpackPlugin.fileSystem, 66 | readFile = Q.nbind(fileSystem.readFile, fileSystem); 67 | 68 | function includeMatching(file) { 69 | var filePath = path.normalize(path.join(basedir, file)); 70 | return includes.some(function (include) { 71 | return include.test(filePath); 72 | }); 73 | } 74 | 75 | function excludeMatching(file) { 76 | var filePath = path.normalize(path.join(basedir, file)); 77 | return excludes.length === 0 || excludes.every(function (exclude) { return !exclude.test(filePath); }); 78 | } 79 | 80 | return readFile(manifestFile). 81 | then(JSON.parse). 82 | then(function (jsonManifestFile) { 83 | var mainFiles = Array.isArray(jsonManifestFile.main) ? jsonManifestFile.main : [jsonManifestFile.main]; 84 | return { 85 | manifestFile: manifestFile, 86 | mainFiles: mainFiles.filter(includeMatching).filter(excludeMatching) 87 | }; 88 | }); 89 | 90 | 91 | }; -------------------------------------------------------------------------------- /lib/bower-plugin-manifest-resolver.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | "use strict"; 26 | 27 | var Q = require('q'); 28 | var path = require('path'); 29 | 30 | /** 31 | * Resolves a bower manifest file, in the given loop paths, using specified manifest file names 32 | * @param webpackPlugin - the webpack plugin instance 33 | * @param {string[]} moduleDirectories - an array of directories, which are used to lookup a manifest file. 34 | * The paths are tried in order, as specified in the array. 35 | * @param {string[]} manifestFiles - an array of possible names of manifest files. 36 | * The files are tried in the order as they are specified in the array. 37 | * @returns {ManifestResolver} 38 | * @constructor 39 | */ 40 | function ManifestResolver(webpackPlugin, moduleDirectories, manifestFiles) { 41 | if (!(this instanceof ManifestResolver)) { 42 | return new ManifestResolver(webpackPlugin, moduleDirectories, manifestFiles); 43 | } 44 | 45 | this.webpackPlugin = webpackPlugin; 46 | this.modulesDirectories = moduleDirectories; 47 | this.manifestFiles = manifestFiles; 48 | 49 | } 50 | 51 | module.exports = ManifestResolver; 52 | 53 | /** 54 | * Finds the first existing manifest file. 55 | * @param request - the webpack request object 56 | * @param {Logger} logger - the logger used to log debug information 57 | * @returns {Promise} a promise, which when resolves contains a path to the resolved manifest file. 58 | * when the promise is rejected it contains an {@link Error} 59 | */ 60 | ManifestResolver.prototype.resolve = function (request, logger) { 61 | var webpackPlugin = this.webpackPlugin, 62 | fsStat = Q.nbind(webpackPlugin.fileSystem.stat, webpackPlugin.fileSystem); 63 | 64 | function resolveBowerManifest(startBase, modulesDirectories, moduleName, manifestFiles) { 65 | var deferred = Q.defer(), 66 | visited = {}; 67 | 68 | logger.log("resolve 'bower component' " + moduleName + " manifest files using [" + manifestFiles.join(",") + "]"); 69 | logger.log(" resolve file"); 70 | 71 | (function loopDirectoryHierarchy(base) { 72 | 73 | // create a copy 74 | var remainingModulesDirectories = modulesDirectories.slice(0); 75 | 76 | visited[base] = true; 77 | 78 | (function loopModulesDirectories() { 79 | var newBase, lookupPath, possibleModulePath, remainingManifestFiles; 80 | 81 | if (remainingModulesDirectories.length === 0) { 82 | newBase = webpackPlugin.normalize(base + path.sep + ".."); 83 | if (visited.hasOwnProperty(newBase)) { 84 | return deferred.reject(new Error( 85 | "No bower component: " + base + "/[" + modulesDirectories.join(",") + "]/" + moduleName + "/[" + manifestFiles.join(",") + "]" 86 | )); 87 | } 88 | 89 | return loopDirectoryHierarchy(newBase); 90 | } 91 | 92 | lookupPath = remainingModulesDirectories.shift(); 93 | possibleModulePath = webpackPlugin.join(webpackPlugin.join(base, lookupPath), moduleName); 94 | // create a copy 95 | remainingManifestFiles = manifestFiles.slice(0); 96 | 97 | (function loopManifestFiles() { 98 | var manifestFile, filePath; 99 | 100 | if (remainingManifestFiles.length === 0) { 101 | return loopModulesDirectories(); 102 | } 103 | 104 | manifestFile = remainingManifestFiles.shift(); 105 | filePath = webpackPlugin.join(possibleModulePath, manifestFile); 106 | 107 | fsStat(filePath).then( 108 | function (stat) { 109 | if (!stat.isDirectory()) { 110 | return deferred.resolve(filePath); 111 | } 112 | 113 | logger.log(" " + filePath + " was a directory"); 114 | return loopManifestFiles(); 115 | }, 116 | function () { 117 | logger.log(" " + filePath + " doesn't exists"); 118 | return loopManifestFiles(); 119 | } 120 | ); 121 | }()); 122 | 123 | }()); 124 | 125 | }(startBase)); 126 | 127 | return deferred.promise; 128 | } 129 | 130 | return resolveBowerManifest(request.path, this.modulesDirectories, request.request, this.manifestFiles); 131 | 132 | }; 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /lib/bower-plugin-utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | "use strict"; 26 | 27 | /** 28 | * Given an array, returns new array having only unique entries. 29 | * @param array {Object[]} the array, which may contain duplicates 30 | * @returns {Object[]} an array containing only unique elements 31 | */ 32 | exports.unique = function (array) { 33 | var u = {}, result = [], arrLen = array.length; 34 | for (var i = 0; i < arrLen; i++) { 35 | if (u.hasOwnProperty(array[i])) { 36 | continue; 37 | } 38 | u[array[i]] = true; 39 | result.push(array[i]); 40 | } 41 | return result; 42 | }; 43 | 44 | /** 45 | * Resolves a directory setting using .bowerrc 46 | * @returns String directory as configured in .bowerrc 47 | */ 48 | exports.resolveComponentsDirectory = function() { 49 | var fs = require("fs"); 50 | var bowerRcFilename = ".bowerrc"; 51 | var defaultFolder = "bower_components"; 52 | 53 | try { 54 | // If .bowerrc exists, parse and if set return its directory option. 55 | fs.statSync(bowerRcFilename); 56 | var bowerRc = JSON.parse(fs.readFileSync(bowerRcFilename)); 57 | if (bowerRc.directory) { 58 | return bowerRc.directory; 59 | } 60 | } catch (err) { 61 | if (err.code !== "ENOENT") { 62 | var Logger = require("./bower-plugin-logger"); 63 | var logger = new Logger(); 64 | logger.log(err); 65 | } 66 | } 67 | 68 | return defaultFolder; 69 | }; 70 | -------------------------------------------------------------------------------- /lib/bower-plugin.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | "use strict"; 26 | 27 | var path = require("path"); 28 | var Logger = require("./bower-plugin-logger"); 29 | var ManifestResolver = require("./bower-plugin-manifest-resolver.js"); 30 | var MainResolver = require("./bower-plugin-main-resolver.js"); 31 | var pluginUtils = require("./bower-plugin-utils"); 32 | 33 | /** 34 | * Configuration for the plugin 35 | * @typedef {Object} BowerWebpackPlugin~Options 36 | * @property {string|string[]} [modulesDirectories=["bower_components"]] - the directories, where the plugin searches for bower components 37 | * @property {string|string[]} [manifestFiles=["bower.json"]] - the list of bower manifest files, 38 | * the plugin will try, when looking for a manifest file 39 | * @property {RegExp|RegExp[]} [includes=[RegExp(".*")]] - the list of regular expressions, used to check if a file referenced 40 | * by the manifest file should be included. 41 | * @property {RegExp|RegExp[]} [excludes=[]] - the list of regular expressions, used to check if a file referenced by the manifest 42 | * should be excluded by the plugin. 43 | * @property {boolean} [searchResolveModulesDirectories=true] - whether to search through resolve.modulesDirectories for bower components 44 | */ 45 | /** 46 | * Creates new Bower Webpack Plugin 47 | * @param {BowerWebpackPlugin~Options} [options] - options, containing a configuration for the plugin 48 | * @returns {BowerWebpackPlugin} 49 | * @constructor 50 | */ 51 | function BowerWebpackPlugin(options) { 52 | var opt = options || {}; 53 | this.modulesDirectories = opt.modulesDirectories ? [].concat(opt.modulesDirectories) : [pluginUtils.resolveComponentsDirectory()]; 54 | this.manifestFiles = opt.manifestFiles ? [].concat(opt.manifestFiles) : ["bower.json"]; 55 | this.includes = opt.includes ? [].concat(opt.includes) : [/.*/]; 56 | this.excludes = opt.excludes ? [].concat(opt.excludes) : []; 57 | this.searchResolveModulesDirectories = opt.searchResolveModulesDirectories === false ? false : true; 58 | } 59 | 60 | module.exports = BowerWebpackPlugin; 61 | 62 | BowerWebpackPlugin.prototype.apply = function (compiler) { 63 | var configModulesDirectories = this.searchResolveModulesDirectories ? compiler.options.resolve.modulesDirectories : [], 64 | modulesDirectories = pluginUtils.unique(this.modulesDirectories.concat(configModulesDirectories)), 65 | manifestFiles = this.manifestFiles, 66 | includes = this.includes, 67 | excludes = this.excludes, 68 | manifestMainFiles = {}; 69 | 70 | compiler.resolvers.normal.plugin('module', function (request, finalCallback) { 71 | 72 | var logger = new Logger(), 73 | manifestResolver = new ManifestResolver(this, modulesDirectories, manifestFiles), 74 | mainResolver = new MainResolver(this, includes, excludes); 75 | 76 | // the plugin does not support modules with slashes - no nesting here... 77 | // e.g. require('some-module/whatever'); will not be resolved 78 | if (request.request.indexOf('/') >= 0) { 79 | return finalCallback(); 80 | } 81 | 82 | manifestResolver.resolve(request, logger). 83 | then(mainResolver.resolve.bind(mainResolver)). 84 | then(function (resolveResult) { 85 | 86 | manifestMainFiles[resolveResult.manifestFile] = resolveResult.mainFiles; 87 | 88 | logger.writeOut(finalCallback); 89 | return finalCallback(null, { 90 | path: resolveResult.manifestFile, 91 | query: request.query, 92 | resolved: true 93 | }); 94 | 95 | }) 96 | .catch(function () { 97 | logger.writeOut(finalCallback); 98 | finalCallback(); 99 | }); 100 | 101 | }); 102 | 103 | 104 | compiler.plugin("normal-module-factory", function (nmf) { 105 | nmf.plugin("after-resolve", function (data, callback) { 106 | 107 | if (!manifestMainFiles.hasOwnProperty(data.resource)) { 108 | return callback(null, data); 109 | } 110 | 111 | function componentName(manifestFilePath) { 112 | var dirname = path.dirname(manifestFilePath), 113 | indexOfLastSeparator = dirname.lastIndexOf(path.sep); 114 | return dirname.substring(indexOfLastSeparator + 1); 115 | } 116 | 117 | var bowerComponentName = componentName(data.resource), 118 | bowerLoaderPath = path.join(__dirname, "bower-loader"), 119 | bowerLoaderParams = JSON.stringify({include: manifestMainFiles[data.resource]}); 120 | 121 | data.loaders = [bowerLoaderPath + "?" + bowerLoaderParams]; 122 | data.request = bowerComponentName + " (bower component)"; 123 | data.userRequest = bowerComponentName + " (bower component)"; 124 | 125 | return callback(null, data); 126 | 127 | }); 128 | }); 129 | 130 | }; 131 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bower-webpack-plugin", 3 | "version": "0.1.9", 4 | "description": "Use bower with webpack", 5 | "main": "lib/bower-plugin.js", 6 | "devDependencies": { 7 | "css-loader": "^0.9.0", 8 | "file-loader": "^0.8.1", 9 | "jsdom": "^1.0.3", 10 | "mocha": "1.21.x", 11 | "rimraf": "^2.2.8", 12 | "should": "4.0.x", 13 | "style-loader": "^0.8.1", 14 | "webpack": "^1.4.0" 15 | }, 16 | "peerDependencies": { 17 | "webpack": ">=1.4.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha --reporter spec", 21 | "debug-test": "mocha --debug-brk --reporter spec" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git://github.com/lpiepiora/bower-webpack-plugin.git" 26 | }, 27 | "keywords": [ 28 | "webpack", 29 | "plugin", 30 | "bower" 31 | ], 32 | "author": { 33 | "name": "Lukasz Piepiora", 34 | "email": "lpiepiora@gmail.com", 35 | "url": "https://github.com/lpiepiora" 36 | }, 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/lpiepiora/bower-webpack-plugin/issues" 40 | }, 41 | "homepage": "https://github.com/lpiepiora/bower-webpack-plugin", 42 | "dependencies": { 43 | "loader-utils": "^0.2.5", 44 | "q": "^1.0.1" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/custom-file.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require('./test-utils'); 26 | 27 | var BowerWebpackPlugin = require("../"); 28 | 29 | testUtils.describe("resolving of files, when having custom module file name", function () { 30 | var config = testUtils.config; 31 | var testBowerPlugin = testUtils.testBowerPlugin; 32 | 33 | it("should take the custom file, when the normal file is last", function (done) { 34 | var expectations = { 35 | js: ['module-custom-bower-file'], 36 | css: ['module-custom-bower-file'], 37 | font: ['fixture-fonts.woff'] 38 | }; 39 | 40 | var cfg = config('module-custom-bower-file'); 41 | cfg.plugins = [ 42 | new BowerWebpackPlugin({manifestFiles: ["custom.json", "bower.json"]}) 43 | ]; 44 | 45 | testBowerPlugin(cfg, expectations, done); 46 | }); 47 | 48 | it("should take the custom file, when the normal file is missing", function (done) { 49 | var expectations = { 50 | js: ['module-custom-bower-file'], 51 | css: ['module-custom-bower-file'], 52 | font: ['fixture-fonts.woff'] 53 | }; 54 | 55 | var cfg = config('module-custom-bower-file'); 56 | cfg.plugins = [ 57 | new BowerWebpackPlugin({manifestFiles: ["bower.json", "custom.json"]}) 58 | ]; 59 | 60 | testBowerPlugin(cfg, expectations, done); 61 | }); 62 | 63 | 64 | it("should take the custom file, when it is first in the array", function (done) { 65 | var expectations = { 66 | js: ['module-custom-file-fallback'], 67 | css: ['module-custom-file-fallback'], 68 | font: ['fixture-fonts.woff'] 69 | }; 70 | 71 | var cfg = config('module-custom-file-fallback'); 72 | cfg.plugins = [ 73 | new BowerWebpackPlugin({manifestFiles: ["custom.json", "bower.json"]}) 74 | ]; 75 | 76 | testBowerPlugin(cfg, expectations, done); 77 | }); 78 | 79 | }); -------------------------------------------------------------------------------- /test/custom-module-directories.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require("./test-utils"); 26 | var BowerWebpackPlugin = require("../"); 27 | var fs = require("fs"); 28 | 29 | testUtils.describe("resolving components being stored in custom module directories", function () { 30 | var config = testUtils.config, 31 | testBowerPluginError = testUtils.testBowerPluginError, 32 | testBowerPlugin = testUtils.testBowerPlugin; 33 | 34 | it("should not resolve a component stored in 'custom_components' if no custom configuration is given", function (done) { 35 | testBowerPluginError(config("custom-module-multiple-js"), done); 36 | }); 37 | 38 | it("should resolve a component stored in 'custom_components' dir if it's specified in 'resolve.modulesDirectories'", function (done) { 39 | var cfg = config("custom-module-multiple-js"), 40 | expectations = { 41 | js: ['custom-module-multiple-js-0', 'custom-module-multiple-js-1'], 42 | css: [] 43 | }; 44 | 45 | cfg.resolve = { 46 | modulesDirectories: ["custom_components", "bower_components"] 47 | }; 48 | 49 | testBowerPlugin(cfg, expectations, done); 50 | }); 51 | 52 | it("should resolve a component stored in 'custom_components' dir, if the 'cfg.resolve' is undefined", function (done) { 53 | var cfg = config("custom-module-multiple-js"), 54 | expectations = { 55 | js: ['custom-module-multiple-js-0', 'custom-module-multiple-js-1'], 56 | css: [] 57 | }; 58 | 59 | cfg.resolve = undefined; 60 | 61 | cfg.plugins = [ 62 | new BowerWebpackPlugin({ 63 | modulesDirectories: ["custom_components", "bower_components"] 64 | }) 65 | ]; 66 | 67 | testBowerPlugin(cfg, expectations, done); 68 | }); 69 | 70 | it("should resolve a component stored in 'custom_components' dir, if the 'cfg.resolve.moduleDirectories' is undefined", function (done) { 71 | var cfg = config("custom-module-multiple-js"), 72 | expectations = { 73 | js: ['custom-module-multiple-js-0', 'custom-module-multiple-js-1'], 74 | css: [] 75 | }; 76 | 77 | cfg.resolve = { 78 | modulesDirectories: undefined 79 | }; 80 | 81 | cfg.plugins = [ 82 | new BowerWebpackPlugin({ 83 | modulesDirectories: ["custom_components", "bower_components"] 84 | }) 85 | ]; 86 | 87 | testBowerPlugin(cfg, expectations, done); 88 | }); 89 | 90 | it("should resolve a component stored in 'custom_components' dir if it's specified in 'modulesDirectories'", function (done) { 91 | var cfg = config("custom-module-multiple-js"), 92 | expectations = { 93 | js: ['custom-module-multiple-js-0', 'custom-module-multiple-js-1'], 94 | css: [] 95 | }; 96 | 97 | cfg.plugins = [ 98 | new BowerWebpackPlugin({ 99 | modulesDirectories: ["custom_components", "bower_components"] 100 | }) 101 | ]; 102 | 103 | testBowerPlugin(cfg, expectations, done); 104 | }); 105 | 106 | 107 | it("should resolve a component stored in 'custom_components' dir, if specified in a .bowerrc file", function (done) { 108 | var cfg = config("custom-module-multiple-js"), 109 | expectations = { 110 | js: ['custom-module-multiple-js-0', 'custom-module-multiple-js-1'], 111 | css: [] 112 | }; 113 | 114 | cfg.resolve = { 115 | modulesDirectories: undefined 116 | }; 117 | 118 | // Generate a .bowerrc file pointing to `custom_components` 119 | var bowerRcFilename = ".bowerrc", 120 | bowerRc = { 121 | "directory": "custom_components" 122 | } 123 | fs.writeFileSync(bowerRcFilename, JSON.stringify(bowerRc)); 124 | 125 | cfg.plugins = [ 126 | new BowerWebpackPlugin() 127 | ]; 128 | 129 | testBowerPlugin(cfg, expectations, done); 130 | 131 | // Clean-up. 132 | fs.unlinkSync(bowerRcFilename); 133 | }); 134 | 135 | }); 136 | -------------------------------------------------------------------------------- /test/exclusions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require('./test-utils'); 26 | 27 | var BowerWebpackPlugin = require("../"); 28 | 29 | testUtils.describe("resolving of modules, with exclusion of unwanted files", function () { 30 | var config = testUtils.config; 31 | var testBowerPlugin = testUtils.testBowerPlugin; 32 | 33 | it("should exclude unwanted files based on the regular expressions (string test)", function (done) { 34 | var expectations = { 35 | js: ['module-with-exclusions-1'], 36 | css: [] 37 | }; 38 | 39 | var cfg = config('module-with-exclusions'); 40 | cfg.plugins = [ 41 | new BowerWebpackPlugin({excludes: /.*0\.js/}) 42 | ]; 43 | 44 | testBowerPlugin(cfg, expectations, done); 45 | }); 46 | 47 | it("should exclude unwanted files based on the regular expressions (array test)", function (done) { 48 | var expectations = { 49 | js: ['module-with-exclusions-1'], 50 | css: [] 51 | }; 52 | 53 | var cfg = config('module-with-exclusions'); 54 | cfg.plugins = [ 55 | new BowerWebpackPlugin({excludes: [/.*0\.js/]}) 56 | ]; 57 | 58 | testBowerPlugin(cfg, expectations, done); 59 | }); 60 | 61 | it("should include all files if a regular expression doesn't match", function (done) { 62 | var expectations = { 63 | js: ['module-with-exclusions-0', 'module-with-exclusions-1'], 64 | css: [] 65 | }; 66 | 67 | var cfg = config('module-with-exclusions'); 68 | cfg.plugins = [ 69 | new BowerWebpackPlugin({excludes: [/.*\.css/]}) 70 | ]; 71 | 72 | testBowerPlugin(cfg, expectations, done); 73 | }); 74 | 75 | it("should include, a file which is unmatched by excludes", function (done) { 76 | var expectations = { 77 | js: ['module-with-exclusions-0'], 78 | css: [] 79 | }; 80 | 81 | var cfg = config('module-with-exclusions'); 82 | cfg.plugins = [ 83 | new BowerWebpackPlugin({excludes: [/.*5\.js/, /.*1\.js/]}) 84 | ]; 85 | 86 | testBowerPlugin(cfg, expectations, done); 87 | }); 88 | 89 | it("should include no files if all are matched by an exclusion regexps", function (done) { 90 | var expectations = { 91 | js: [], 92 | css: [] 93 | }; 94 | 95 | var cfg = config('module-with-exclusions'); 96 | cfg.plugins = [ 97 | new BowerWebpackPlugin({excludes: [/.*0\.js/, /.*1\.js/]}) 98 | ]; 99 | 100 | testBowerPlugin(cfg, expectations, done); 101 | }); 102 | 103 | it("should include all files if a regular expression doesn't match (with component name)", function (done) { 104 | var expectations = { 105 | js: ['module-with-exclusions-0', 'module-with-exclusions-1'], 106 | css: [] 107 | }; 108 | 109 | var cfg = config('module-with-exclusions'); 110 | cfg.plugins = [ 111 | new BowerWebpackPlugin({excludes: /.*\/some-module\/.*\.js/}) 112 | ]; 113 | 114 | testBowerPlugin(cfg, expectations, done); 115 | }); 116 | 117 | 118 | }); -------------------------------------------------------------------------------- /test/fixtures/bower_components/fixture-fonts.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lpiepiora/bower-webpack-plugin/8ae8d55b2a072dc57be4942b77e432ba3c5f9126/test/fixtures/bower_components/fixture-fonts.woff -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-bower-file/custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-custom-bower-file", 3 | "version": "0.0.1", 4 | "main": [ 5 | "module0.js", 6 | "module0.css" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-bower-file/module0.css: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | @font-face { 26 | font-family: 'module-custom-bower-file'; 27 | src: url(../fixture-fonts.woff); 28 | } 29 | 30 | .module-custom-bower-file { 31 | font-size: 2em; 32 | font-family: 'module-custom-bower-file', serif; 33 | } 34 | -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-bower-file/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-custom-bower-file"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-file-fallback/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-custom-file-fallback", 3 | "version": "0.0.1", 4 | "main": [ 5 | ] 6 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-file-fallback/custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-custom-file-fallback", 3 | "version": "0.0.1", 4 | "main": [ 5 | "module0.js", 6 | "module0.css" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-file-fallback/module0.css: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | @font-face { 26 | font-family: 'module-custom-file-fallback'; 27 | src: url(../fixture-fonts.woff); 28 | } 29 | 30 | .module-custom-file-fallback { 31 | font-size: 2em; 32 | font-family: 'module-custom-file-fallback', serif; 33 | } 34 | -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-custom-file-fallback/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-custom-file-fallback"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-missing-bower/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-missing-bower"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-missing-referenced-file/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-missing-referenced-file", 3 | "version": "0.0.1", 4 | "main": [ 5 | "module0.js", 6 | "module1.js" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-js/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-multiple-js", 3 | "version": "0.0.1", 4 | "main": [ 5 | "module0.js", 6 | "module1.js" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-js/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-multiple-js-0"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-js/module1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-multiple-js-1"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed-with-subdirs/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-multiple-subdirs", 3 | "version": "0.0.1", 4 | "main": [ 5 | "js/module0.js", 6 | "css/module0.css" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed-with-subdirs/css/module0.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'module-multiple-mixed-with-subdirs'; 3 | src: url(../fonts/fixture-fonts.woff); 4 | } 5 | 6 | .module-multiple-mixed-with-subdirs { 7 | font-size: 2em; 8 | font-family: 'module-multiple-mixed-with-subdirs', serif; 9 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed-with-subdirs/fonts/fixture-fonts.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lpiepiora/bower-webpack-plugin/8ae8d55b2a072dc57be4942b77e432ba3c5f9126/test/fixtures/bower_components/module-multiple-mixed-with-subdirs/fonts/fixture-fonts.woff -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed-with-subdirs/js/module0.js: -------------------------------------------------------------------------------- 1 | window.loadedModules = window.loadedModules || []; 2 | window.loadedModules.push("module-multiple-mixed-with-subdirs"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-multiple-array", 3 | "version": "0.0.1", 4 | "main": [ 5 | "module0.js", 6 | "module0.css" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed/module0.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'module-multiple-mixed'; 3 | src: url(../fixture-fonts.woff); 4 | } 5 | 6 | .module-multiple-mixed { 7 | font-size: 2em; 8 | font-family: 'module-multiple-mixed', serif; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-multiple-mixed/module0.js: -------------------------------------------------------------------------------- 1 | window.loadedModules = window.loadedModules || []; 2 | window.loadedModules.push("module-multiple-mixed"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-provided-a/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-provided-a", 3 | "version": "0.0.1", 4 | "main": [ 5 | "./module0.js" 6 | ] 7 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-provided-a/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | module.exports = "module-provided-a"; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-provided-b/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-provided-b", 3 | "version": "0.0.1", 4 | "main": [ 5 | "./module0.js" 6 | ] 7 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-provided-b/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | if (providedA) { 27 | window.loadedModules.push("module-provided-b"); 28 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-single-array/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-single-array", 3 | "version": "0.0.1", 4 | "main": ["./module0.js"] 5 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-single-array/module0.js: -------------------------------------------------------------------------------- 1 | window.loadedModules = window.loadedModules || []; 2 | window.loadedModules.push("module-single-array"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-single-string-css/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-single-string-css", 3 | "version": "0.0.1", 4 | "main": "./module0.css" 5 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-single-string-css/module0.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'module-single-string-css'; 3 | src: url(../fixture-fonts.woff); 4 | } 5 | 6 | .module-single-string-css { 7 | font-size: 10px; 8 | font-family: 'module-single-string-css', serif; 9 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-single-string/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-single-string", 3 | "version": "0.0.1", 4 | "main": "./module0.js" 5 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-single-string/module0.js: -------------------------------------------------------------------------------- 1 | window.loadedModules = window.loadedModules || []; 2 | window.loadedModules.push("module-single-string"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-with-exclusions/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-with-exclusions", 3 | "version": "0.0.1", 4 | "main": [ 5 | "./module0.js", 6 | "./module1.js" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-with-exclusions/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-with-exclusions-0"); -------------------------------------------------------------------------------- /test/fixtures/bower_components/module-with-exclusions/module1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("module-with-exclusions-1"); -------------------------------------------------------------------------------- /test/fixtures/custom-module-multiple-js.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require("custom-module-multiple-js"); -------------------------------------------------------------------------------- /test/fixtures/custom-module-single-string.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('custom-module-single-string'); 26 | -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-multiple-js/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-module-multiple-js", 3 | "version": "0.0.1", 4 | "main": [ 5 | "module0.js", 6 | "module1.js" 7 | ] 8 | } -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-multiple-js/module0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("custom-module-multiple-js-0"); -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-multiple-js/module1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | window.loadedModules = window.loadedModules || []; 26 | window.loadedModules.push("custom-module-multiple-js-1"); -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-single-string/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-module-single-string", 3 | "version": "0.0.1", 4 | "main": "custom-module-single-string-bower.js" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-single-string/custom-module-single-string-bower.js: -------------------------------------------------------------------------------- 1 | window.loadedModules = window.loadedModules || []; 2 | window.loadedModules.push("custom-module-single-string-bower"); 3 | -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-single-string/custom-module-single-string-node.js: -------------------------------------------------------------------------------- 1 | window.loadedModules = window.loadedModules || []; 2 | window.loadedModules.push("custom-module-single-string-node"); 3 | -------------------------------------------------------------------------------- /test/fixtures/custom_components/custom-module-single-string/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-module-single-string", 3 | "version": "0.0.1", 4 | "main": "custom-module-single-string-node.js" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/integration-with-provide.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require("module-provided-a"); 26 | require("module-provided-b"); 27 | -------------------------------------------------------------------------------- /test/fixtures/module-alias.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | // 'aliased-module' aliased as 'module-single-array' 26 | require("aliased-module"); -------------------------------------------------------------------------------- /test/fixtures/module-custom-bower-file.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require("module-custom-bower-file"); -------------------------------------------------------------------------------- /test/fixtures/module-custom-file-fallback.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-custom-file-fallback'); -------------------------------------------------------------------------------- /test/fixtures/module-missing-bower.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-missing-bower'); -------------------------------------------------------------------------------- /test/fixtures/module-missing-referenced-file.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require("module-missing-referenced-file"); -------------------------------------------------------------------------------- /test/fixtures/module-missing.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('missing-module'); -------------------------------------------------------------------------------- /test/fixtures/module-multiple-js.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-multiple-js'); 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/module-multiple-mixed-with-subdirs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-multiple-mixed-with-subdirs'); -------------------------------------------------------------------------------- /test/fixtures/module-multiple-mixed.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-multiple-mixed'); -------------------------------------------------------------------------------- /test/fixtures/module-single-array.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-single-array'); -------------------------------------------------------------------------------- /test/fixtures/module-single-string-css.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-single-string-css'); -------------------------------------------------------------------------------- /test/fixtures/module-single-string.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-single-string'); -------------------------------------------------------------------------------- /test/fixtures/module-with-exclusions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-with-exclusions'); -------------------------------------------------------------------------------- /test/fixtures/require-multiple-modules.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | require('module-single-string-css'); 26 | require("module-single-array"); 27 | require('module-multiple-mixed-with-subdirs'); -------------------------------------------------------------------------------- /test/inclusions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require('./test-utils'); 26 | var BowerWebpackPlugin = require("../"); 27 | 28 | testUtils.describe("resolving of modules, with exclusion of unwanted files", function () { 29 | var config = testUtils.config; 30 | var testBowerPlugin = testUtils.testBowerPlugin; 31 | 32 | it("should include only wanted files based on the regular expressions (string test)", function (done) { 33 | var expectations = { 34 | js: ['module-with-exclusions-1'], 35 | css: [] 36 | }; 37 | 38 | var cfg = config('module-with-exclusions'); 39 | cfg.plugins = [ 40 | new BowerWebpackPlugin({includes: /.*1\.js/}) 41 | ]; 42 | 43 | testBowerPlugin(cfg, expectations, done); 44 | }); 45 | 46 | it("should include only wanted files based on the regular expressions (array test)", function (done) { 47 | var expectations = { 48 | js: ['module-with-exclusions-1'], 49 | css: [] 50 | }; 51 | 52 | var cfg = config('module-with-exclusions'); 53 | cfg.plugins = [ 54 | new BowerWebpackPlugin({includes: [/.*1\.js/]}) 55 | ]; 56 | 57 | testBowerPlugin(cfg, expectations, done); 58 | }); 59 | 60 | it("should include multiple files, matched by multiple regular expressions", function (done) { 61 | var expectations = { 62 | js: ['module-with-exclusions-0', 'module-with-exclusions-1'], 63 | css: [] 64 | }; 65 | 66 | var cfg = config('module-with-exclusions'); 67 | cfg.plugins = [ 68 | new BowerWebpackPlugin({includes: [/.*0\.js/, /.*1\.js/]}) 69 | ]; 70 | 71 | testBowerPlugin(cfg, expectations, done); 72 | }); 73 | 74 | 75 | it("should include nothing if a regular expression doesn't match", function (done) { 76 | var expectations = { 77 | js: [], 78 | css: [] 79 | }; 80 | 81 | var cfg = config('module-with-exclusions'); 82 | cfg.plugins = [ 83 | new BowerWebpackPlugin({includes: [/.*\.css/]}) 84 | ]; 85 | 86 | testBowerPlugin(cfg, expectations, done); 87 | }); 88 | 89 | it("should include nothing, if a regular expression doesn't match (with component name)", function (done) { 90 | var expectations = { 91 | js: [], 92 | css: [] 93 | }; 94 | 95 | var cfg = config('module-with-exclusions'); 96 | cfg.plugins = [ 97 | new BowerWebpackPlugin({includes: /.*\/some-module\/.*\.js/}) 98 | ]; 99 | 100 | testBowerPlugin(cfg, expectations, done); 101 | }); 102 | 103 | 104 | }); -------------------------------------------------------------------------------- /test/missing.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require('./test-utils'); 26 | 27 | testUtils.describe("behaviour when requiring missing modules or files", function () { 28 | 29 | var config = testUtils.config; 30 | var testBowerPluginError = testUtils.testBowerPluginError; 31 | 32 | it("should raise errors, when requiring a module, which does not exist", function (done) { 33 | testBowerPluginError(config("module-missing.js"), done); 34 | }); 35 | 36 | it("should raise errors, when requiring a module, which does not have a 'bower.json' file", function (done) { 37 | testBowerPluginError(config("module-missing-bower.js"), done); 38 | }); 39 | 40 | it("should raise errors, when requiring a module, which does not have files referenced from a 'bower.json' file", function (done) { 41 | testBowerPluginError(config("module-missing-referenced-file.js"), done); 42 | }) 43 | 44 | }); -------------------------------------------------------------------------------- /test/multi-module.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require("./test-utils"); 26 | 27 | testUtils.describe("resolving of multi-file modules", function () { 28 | 29 | var config = testUtils.config; 30 | var testBowerPlugin = testUtils.testBowerPlugin; 31 | 32 | it("should load two JavaScript files included in a 'bower.json' file", function (done) { 33 | var expectations = { 34 | js: ["module-multiple-js-0", "module-multiple-js-1"], 35 | css: [] 36 | }; 37 | testBowerPlugin(config('module-multiple-js.js'), expectations, done); 38 | }); 39 | 40 | it("should load files of mixed types included in a 'bower.json' file", function (done) { 41 | var expectations = { 42 | js: ['module-multiple-mixed'], 43 | css: ['module-multiple-mixed'], 44 | font: ['fixture-fonts.woff'] 45 | }; 46 | testBowerPlugin(config('module-multiple-mixed.js'), expectations, done); 47 | }); 48 | 49 | it("should load files of mixed types included in a 'bower.json' file, when the file points to sub-directories", function (done) { 50 | var expectations = { 51 | js: ['module-multiple-mixed-with-subdirs'], 52 | css: ['module-multiple-mixed-with-subdirs'], 53 | font: ['fixture-fonts.woff'] 54 | }; 55 | testBowerPlugin(config('module-multiple-mixed-with-subdirs.js'), expectations, done); 56 | }); 57 | 58 | it("should load files, which are required by multiple modules", function (done) { 59 | var expectations = { 60 | js: ['module-single-array', 'module-multiple-mixed-with-subdirs'], 61 | css: ['module-single-string-css', 'module-multiple-mixed-with-subdirs'], 62 | font: ['fixture-fonts.woff'] 63 | }; 64 | 65 | testBowerPlugin(config('require-multiple-modules.js'), expectations, done); 66 | 67 | }); 68 | 69 | }); 70 | -------------------------------------------------------------------------------- /test/search-resolve-modules-directories.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | var testUtils = require("./test-utils"); 25 | var BowerWebpackPlugin = require("../"); 26 | 27 | testUtils.describe("searching for components 'resolve.modulesDirectories'", function () { 28 | var config = testUtils.config, 29 | testBowerPluginError = testUtils.testBowerPluginError, 30 | testBowerPlugin = testUtils.testBowerPlugin; 31 | 32 | it("should occur by default", function (done) { 33 | var cfg = config("custom-module-single-string"), 34 | expectations = { 35 | js: ['custom-module-single-string-bower'], 36 | css: [] 37 | }; 38 | 39 | cfg.resolve = { 40 | modulesDirectories: ["custom_components", "bower_components"] 41 | }; 42 | 43 | testBowerPlugin(cfg, expectations, done); 44 | }); 45 | 46 | it("should not occur when 'searchResolveModulesDirectories' is false", function (done) { 47 | var cfg = config("custom-module-single-string"), 48 | expectations = { 49 | js: ['custom-module-single-string-node'], 50 | css: [] 51 | }; 52 | 53 | cfg.resolve = { 54 | modulesDirectories: ["custom_components", "bower_components"] 55 | }; 56 | 57 | cfg.plugins = [ 58 | new BowerWebpackPlugin({ 59 | searchResolveModulesDirectories: false 60 | }) 61 | ]; 62 | 63 | testBowerPlugin(cfg, expectations, done); 64 | }); 65 | 66 | it("should occur when 'searchResolveModulesDirectories' is true", function (done) { 67 | var cfg = config("custom-module-single-string"), 68 | expectations = { 69 | js: ['custom-module-single-string-bower'], 70 | css: [] 71 | }; 72 | 73 | cfg.resolve = { 74 | modulesDirectories: ["custom_components", "bower_components"] 75 | }; 76 | 77 | cfg.plugins = [ 78 | new BowerWebpackPlugin({ 79 | searchResolveModulesDirectories: true 80 | }) 81 | ] 82 | 83 | testBowerPlugin(cfg, expectations, done); 84 | }); 85 | }); 86 | -------------------------------------------------------------------------------- /test/single-module.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | var testUtils = require("./test-utils"); 25 | 26 | testUtils.describe("resolving of single file modules", function () { 27 | var config = testUtils.config; 28 | var testBowerPlugin = testUtils.testBowerPlugin; 29 | 30 | it("should load a 'main' with a single string value, pointing to a JavaScript file", function (done) { 31 | var expectations = { 32 | js: ['module-single-string'], 33 | css: [] 34 | }; 35 | 36 | testBowerPlugin(config('module-single-string.js'), expectations, done); 37 | 38 | }); 39 | 40 | it("should load a 'main' with a single string value, pointing to a CSS file", function (done) { 41 | 42 | var expectations = { 43 | js: [], 44 | css: ['module-single-string-css'], 45 | font: ['fixture-fonts.woff'] 46 | }; 47 | 48 | testBowerPlugin(config('module-single-string-css.js'), expectations, done); 49 | 50 | }); 51 | 52 | it("should load a 'main' with an array having a single value, pointing to a file", function (done) { 53 | var expectations = { 54 | js: ['module-single-array'], 55 | css: [] 56 | }; 57 | testBowerPlugin(config('module-single-array.js'), expectations, done); 58 | }) 59 | 60 | }); -------------------------------------------------------------------------------- /test/test-utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | var should = require("should"); 25 | var path = require("path"); 26 | var webpack = require('webpack'); 27 | var fs = require('fs'); 28 | var jsdom = require("jsdom"); 29 | var rm = require('rimraf'); 30 | 31 | var BowerWebpackPlugin = require("../"); 32 | 33 | var OUTPUT_DIR = path.join(__dirname, '../dist'); 34 | 35 | exports.OUTPUT_DIR = OUTPUT_DIR; 36 | 37 | /** 38 | * Describes a bower plugin test. 39 | * @param text 40 | * @param fn 41 | */ 42 | exports.describe = function (text, fn) { 43 | function clearOutput(done) { 44 | return rm(OUTPUT_DIR, done); 45 | } 46 | 47 | return describe(text, function () { 48 | beforeEach(clearOutput); 49 | afterEach(clearOutput); 50 | fn(); 51 | }); 52 | }; 53 | 54 | /** 55 | * Tests if the plugin returns soft error 56 | * @param webpackConfig 57 | * @param done 58 | */ 59 | exports.testBowerPluginError = function testBowerPlugin(webpackConfig, done) { 60 | webpack(webpackConfig, function (err, stats) { 61 | stats.hasErrors().should.be.eql(true); 62 | done(); 63 | }); 64 | }; 65 | 66 | /** 67 | * @param {Object} webpackConfig configuration for webpack 68 | * @param {Object} expectedModules expected css and js files 69 | * @param done called when done 70 | */ 71 | exports.testBowerPlugin = function testBowerPlugin(webpackConfig, expectedModules, done) { 72 | 73 | webpack(webpackConfig, function (err, stats) { 74 | 75 | var jsonStats = stats.toJson(); 76 | jsonStats.errors.should.be.eql([]); 77 | 78 | var bundleScript = 'file:///' + path.join(webpackConfig.output.path, webpackConfig.output.filename); 79 | jsdom.env("", [bundleScript], {}, function (errors, window) { 80 | should(errors).be.equal(null); 81 | 82 | var document = window.document; 83 | 84 | (function checkExpectedJs() { 85 | var expectedJs = expectedModules.js || []; 86 | if (expectedJs.length > 0) should(window.loadedModules).eql(expectedJs); 87 | })(); 88 | 89 | (function checkExpectedCSS() { 90 | var expectedCss = expectedModules.css || []; 91 | if (expectedCss.length > 0) { 92 | var loadedCssClasses = []; 93 | 94 | var styleTags = document.getElementsByTagName('style'); 95 | for (var i = 0; i < styleTags.length; i++) { 96 | var declarations = styleTags[i].innerHTML.split("}"); 97 | for (var j = 0; j < declarations.length; j++) { 98 | var name = declarations[j].match(/^\s*\.([^\s]+).*/); 99 | if (name) loadedCssClasses.push(name[1]); 100 | } 101 | } 102 | 103 | should(loadedCssClasses).eql(expectedCss); 104 | } 105 | })(); 106 | 107 | (function checkExpectedFonts() { 108 | var expectedFont = expectedModules.font || []; 109 | for (var i = 0; i < expectedFont.length; i++) { 110 | fs.existsSync(path.join(OUTPUT_DIR, expectedFont[i])).should.be.equal(true); 111 | } 112 | })(); 113 | 114 | window.close(); 115 | done(); 116 | }); 117 | }) 118 | }; 119 | 120 | /** 121 | * Creates default config using a defined entry point 122 | * @param {string} entryPoint name of the file, which acts as an entry point 123 | * @returns {{entry: *, output: {path: *, filename: string}, plugins: *[], debug: boolean}} 124 | */ 125 | exports.config = function config(entryPoint) { 126 | return { 127 | entry: path.join(__dirname, "fixtures", entryPoint), 128 | output: { 129 | path: OUTPUT_DIR, 130 | filename: 'bundle' + entryPoint 131 | }, 132 | plugins: [new BowerWebpackPlugin()], 133 | module: { 134 | loaders: [ 135 | { 136 | test: /\.css$/, 137 | loader: "style-loader!css-loader" 138 | }, 139 | { 140 | test: /\.woff([\?]?.*)$/, 141 | loader: "file-loader?name=[name].[ext]" 142 | } 143 | ] 144 | }, 145 | debug: true 146 | }; 147 | }; -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | var fs = require("fs"); 27 | var pluginUtils = require("../lib/bower-plugin-utils"); 28 | 29 | describe("plugin utils library", function () { 30 | 31 | describe("unique method", function () { 32 | 33 | it("should return an empty array when passed an empty array", function (done) { 34 | var result = pluginUtils.unique([]); 35 | result.should.be.eql([]); 36 | done(); 37 | }); 38 | 39 | it("should return an array containing the same elements, when the array has only unique elements", function (done) { 40 | var result = pluginUtils.unique(["one", "two", "three"]); 41 | result.length.should.be.equal(3); 42 | result.should.be.eql(["one", "two", "three"]); 43 | done(); 44 | }); 45 | 46 | it("should return an array, which doesn't contain duplicated elements", function (done) { 47 | var result = pluginUtils.unique(["one", "two", "two", "three", "one"]); 48 | result.should.be.eql(["one", "two", "three"]); 49 | result.length.should.be.equal(3); 50 | done(); 51 | }); 52 | 53 | }); 54 | 55 | describe("bower_components resolution", function () { 56 | 57 | it("should return 'bower_components' when no .bowerrc file", function(done) { 58 | var result = pluginUtils.resolveComponentsDirectory(); 59 | result.should.be.eql("bower_components"); 60 | done(); 61 | }); 62 | 63 | it("should return 'bower_components' when no definition in .bowerrc", function(done) { 64 | 65 | // Generate a .bowerrc file 66 | var bowerRcFilename = ".bowerrc", 67 | bowerRc = { 68 | "foo": ["bar"] 69 | } 70 | fs.writeFileSync(bowerRcFilename, JSON.stringify(bowerRc)); 71 | var result = pluginUtils.resolveComponentsDirectory(); 72 | fs.unlinkSync(bowerRcFilename); 73 | 74 | result.should.be.eql("bower_components"); 75 | done(); 76 | }); 77 | 78 | it("should detect 'custom_components' if .bowerrc specifies it", function(done) { 79 | 80 | // Generate a .bowerrc file pointing to `custom_components` 81 | var bowerRcFilename = ".bowerrc", 82 | bowerRc = { 83 | "foo": "bar", 84 | "directory": "custom_components" 85 | } 86 | fs.writeFileSync(bowerRcFilename, JSON.stringify(bowerRc)); 87 | var result = pluginUtils.resolveComponentsDirectory(); 88 | fs.unlinkSync(bowerRcFilename); 89 | 90 | result.should.be.eql("custom_components"); 91 | done(); 92 | }); 93 | 94 | }); 95 | 96 | }); 97 | -------------------------------------------------------------------------------- /test/with-module-alias.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require('./test-utils'); 26 | 27 | testUtils.describe("integration with module alias plugin", function () { 28 | 29 | var config = testUtils.config; 30 | var testBowerPlugin = testUtils.testBowerPlugin; 31 | 32 | it("should resolve modules, which were aliased by a 'resolve.alias' entry", function (done) { 33 | var expectations = { 34 | js: ['module-single-array'], 35 | css: [] 36 | }; 37 | 38 | var cfg = config("module-alias"); 39 | cfg.resolve = {}; 40 | cfg.resolve.alias = { 41 | "aliased-module": "module-single-array" 42 | }; 43 | 44 | testBowerPlugin(cfg, expectations, done); 45 | }); 46 | 47 | }); -------------------------------------------------------------------------------- /test/with-provide-plugin.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Lukasz Piepiora 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | var testUtils = require('./test-utils'); 26 | 27 | var webpack = require("webpack"); 28 | var BowerWebpackPlugin = require("../"); 29 | 30 | testUtils.describe("integration with provide plugin", function () { 31 | 32 | var config = testUtils.config; 33 | var testBowerPlugin = testUtils.testBowerPlugin; 34 | 35 | it("should load a plugin via the provide plugin", function (done) { 36 | 37 | var expectations = { 38 | js: ['module-provided-b'], 39 | css: [] 40 | }; 41 | 42 | var cfg = config('integration-with-provide'); 43 | cfg.plugins = [ 44 | new BowerWebpackPlugin(), 45 | new webpack.ProvidePlugin({ 46 | providedA: "module-provided-a" 47 | }) 48 | ]; 49 | 50 | testBowerPlugin(cfg, expectations, done); 51 | }); 52 | 53 | }); --------------------------------------------------------------------------------