Skip to content

Commit

Permalink
Merge branch 'master' into webpack-2
Browse files Browse the repository at this point in the history
Conflicts:
	.travis.yml
	bin/config-optimist.js
	test/statsCases/define-plugin/expected.txt
  • Loading branch information
sokra committed Sep 19, 2015
2 parents 060ba5e + 3c7b13f commit 7cbd78c
Show file tree
Hide file tree
Showing 27 changed files with 171 additions and 46 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sudo: false
language: node_js
node_js:
- "0.12"
- node
- iojs-1
- iojs-2
Expand All @@ -10,7 +11,11 @@ env:
- NO_WATCH_TESTS=1

before_install:
- '[ "${TRAVIS_NODE_VERSION}" != "0.10" ] || npm install -g npm'
- '[ "${TRAVIS_NODE_VERSION}" != "0.10" ] || npm install -g npm@^2'

before_script:
- npm link
- npm link webpack

after_success:
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ MIT (http://www.opensource.org/licenses/mit-license.php)
(In chronological order)

* @google for [Google Web Toolkit (GWT)](https://code.google.com/p/google-web-toolkit), which aims to compile Java to JavaScript. It features a similar [Code Splitting](https://code.google.com/p/google-web-toolkit/wiki/CodeSplitting) as webpack.
* @medikoo for [modules-webmake](https://github.com/medikoo/modules-webmake), which is a simlar project. webpack was born because I wanted Code Splitting for modules-webpack. Interestingly the [Code Splitting issue is still open](https://github.com/medikoo/modules-webmake/issues/7) (thanks also to @Phoscur for the discussion).
* @medikoo for [modules-webmake](https://github.com/medikoo/modules-webmake), which is a similar project. webpack was born because I wanted Code Splitting for modules-webpack. Interestingly the [Code Splitting issue is still open](https://github.com/medikoo/modules-webmake/issues/7) (thanks also to @Phoscur for the discussion).
* @substack for [browserify](http://browserify.org/), which is a similar project and source for many ideas.
* @jrburke for [require.js](http://requirejs.org/), which is a similar project and source for many ideas.
* @defunctzombie for the [browser-field spec](https://gist.github.com/defunctzombie/4339901), which makes modules available for node.js, browserify and webpack.
Expand Down
3 changes: 2 additions & 1 deletion bin/config-optimist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function(optimist) {
optimist
.boolean("help").alias("help", "h").alias("help", "?").describe("help")
.string("config").describe("config")
.string("config").alias("config", "c").describe("config")
.string("env").describe("env", "Enviroment passed to the config, when it is a function")
.string("context").describe("context")
.string("entry").describe("entry")
Expand All @@ -24,6 +24,7 @@ module.exports = function(optimist) {
.string("target").describe("target")
.boolean("cache").describe("cache").default("cache", true)
.boolean("watch").alias("watch", "w").describe("watch")
.boolean("watch-stdin").alias("watch-stdin", "stdin").describe("watch which closes when stdin ends")
.describe("watch-aggregate-timeout")
.describe("watch-poll")
.boolean("hot").alias("hot", "h").describe("hot")
Expand Down
7 changes: 7 additions & 0 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ module.exports = function(optimist, argv, convertOptions) {
options.watchOptions.poll = true;
}

if(argv["watch-stdin"]) {
options.watchOptions = options.watchOptions || {};
options.watchOptions.stdin = true;
options.watch = true;
}

function processOptions(options) {
function ifArg(name, fn, init, finalize) {
if(Array.isArray(argv[name])) {
Expand Down Expand Up @@ -507,6 +513,7 @@ module.exports = function(optimist, argv, convertOptions) {
throw new Error("'output.filename' is required, either in config file or as --output-file");
} else {
optimist.showHelp();
console.error("Output filename not configured.");
process.exit(-1);
}
}
Expand Down
6 changes: 6 additions & 0 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ function compilerCallback(err, stats) {
if(options.watch) {
var primaryOptions = !Array.isArray(options) ? options : options[0];
var watchOptions = primaryOptions.watchOptions || primaryOptions.watch || {};
if(watchOptions.stdin) {
process.stdin.on('end', function() {
process.exit(0)
});
process.stdin.resume();
}
compiler.watch(watchOptions, compilerCallback);
} else
compiler.run(compilerCallback);
2 changes: 2 additions & 0 deletions lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function Compilation(compiler) {
module.exports = Compilation;

Compilation.prototype = Object.create(Tapable.prototype);
Compilation.prototype.constructor = Compilation;

Compilation.prototype.templatesPlugin = function(name, fn) {
this.mainTemplate.plugin(name, fn);
this.chunkTemplate.plugin(name, fn);
Expand Down
1 change: 1 addition & 0 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function Compiler() {
module.exports = Compiler;

Compiler.prototype = Object.create(Tapable.prototype);
Compiler.prototype.constructor = Compiler;

Compiler.Watching = Watching;
Compiler.prototype.watch = function(watchOptions, handler) {
Expand Down
2 changes: 2 additions & 0 deletions lib/ContextModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function ContextModuleFactory(resolvers) {
module.exports = ContextModuleFactory;

ContextModuleFactory.prototype = Object.create(Tapable.prototype);
ContextModuleFactory.prototype.constructor = ContextModuleFactory;

ContextModuleFactory.prototype.create = function(context, dependency, callback) {
this.applyPluginsAsyncWaterfall("before-resolve", {
context: context,
Expand Down
2 changes: 2 additions & 0 deletions lib/DllModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function DllModuleFactory() {
module.exports = DllModuleFactory;

DllModuleFactory.prototype = Object.create(Tapable.prototype);
DllModuleFactory.prototype.constructor = DllModuleFactory;

DllModuleFactory.prototype.create = function(context, dependency, callback) {
callback(null, new DllModule(context, dependency.dependencies, dependency.name, dependency.type));
};
8 changes: 6 additions & 2 deletions lib/LibraryTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function accessorAccess(base, accessor, joinWith) {
}).join(joinWith || "; ");
}

function LibraryTemplatePlugin(name, target) {
function LibraryTemplatePlugin(name, target, umdNamedDefine) {
this.name = name;
this.target = target;
this.umdNamedDefine = umdNamedDefine;
}
module.exports = LibraryTemplatePlugin;
LibraryTemplatePlugin.prototype.apply = function(compiler) {
Expand Down Expand Up @@ -60,7 +61,10 @@ LibraryTemplatePlugin.prototype.apply = function(compiler) {
case "umd":
case "umd2":
var UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
compilation.apply(new UmdMainTemplatePlugin(this.name, this.target === "umd2"));
compilation.apply(new UmdMainTemplatePlugin(this.name, {
optionalAmdExternalAsGlobal: this.target === "umd2",
namedDefine: this.umdNamedDefine
}));
break;
case "jsonp":
var JsonpExportMainTemplatePlugin = require("./JsonpExportMainTemplatePlugin");
Expand Down
1 change: 1 addition & 0 deletions lib/MultiCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function MultiCompiler(compilers) {
module.exports = MultiCompiler;

MultiCompiler.prototype = Object.create(Tapable.prototype);
MultiCompiler.prototype.constructor = MultiCompiler;

MultiCompiler.prototype.watch = function(watchDelay, handler) {
var watchings = this.compilers.map(function(compiler) {
Expand Down
2 changes: 2 additions & 0 deletions lib/MultiModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function MultiModuleFactory() {
module.exports = MultiModuleFactory;

MultiModuleFactory.prototype = Object.create(Tapable.prototype);
MultiModuleFactory.prototype.constructor = MultiModuleFactory;

MultiModuleFactory.prototype.create = function(context, dependency, callback) {
callback(null, new MultiModule(context, dependency.dependencies, dependency.name));
};
2 changes: 2 additions & 0 deletions lib/NormalModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function NormalModuleFactory(context, resolvers, parser, options) {
module.exports = NormalModuleFactory;

NormalModuleFactory.prototype = Object.create(Tapable.prototype);
NormalModuleFactory.prototype.constructor = NormalModuleFactory;

NormalModuleFactory.prototype.create = function(context, dependency, callback) {
context = context || this.context;
var request = dependency.request;
Expand Down
2 changes: 2 additions & 0 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = Parser;
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API

Parser.prototype = Object.create(Tapable.prototype);
Parser.prototype.constructor = Parser;

Parser.prototype.initializeEvaluating = function() {
function joinRanges(startRange, endRange) {
if(!endRange) return startRange;
Expand Down
1 change: 1 addition & 0 deletions lib/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Template.toIdentifier = function(str) {
};

Template.prototype = Object.create(Tapable.prototype);
Template.prototype.constructor = Template;

Template.prototype.indent = function indent(str) {
if(Array.isArray(str)) {
Expand Down
23 changes: 18 additions & 5 deletions lib/UmdMainTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ function accessorAccess(base, accessor) {
}).join(", ");
}

function UmdMainTemplatePlugin(name, optionalAmdExternalAsGlobal) {
function UmdMainTemplatePlugin(name, options) {
this.name = name;
this.optionalAmdExternalAsGlobal = optionalAmdExternalAsGlobal;
this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal;
this.namedDefine = options.namedDefine;
}
module.exports = UmdMainTemplatePlugin;
UmdMainTemplatePlugin.prototype.apply = function(compilation) {
Expand Down Expand Up @@ -87,6 +88,11 @@ UmdMainTemplatePlugin.prototype.apply = function(compilation) {
return "__WEBPACK_EXTERNAL_MODULE_" + m.id + "__";
}).join(", ");
}

function libraryName(library) {
return JSON.stringify(replaceKeys([].concat(library).pop()));
}

if(optionalExternals.length > 0) {
var amdFactory = "function webpackLoadOptionalExternalModuleAmd(" + externalsArguments(requiredExternals) + ") {\n" +
" return factory(" + (
Expand All @@ -98,18 +104,25 @@ UmdMainTemplatePlugin.prototype.apply = function(compilation) {
} else {
var amdFactory = "factory";
}

return new ConcatSource(new OriginalSource(
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
" if(typeof exports === 'object' && typeof module === 'object')\n" +
" module.exports = factory(" + externalsRequireArray("commonjs2") + ");\n" +
" else if(typeof define === 'function' && define.amd)\n" +
(requiredExternals.length > 0 ?
" define(" + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" :
" define(" + amdFactory + ");\n"
(this.name && this.namedDefine === true ?
" define(" + libraryName(this.name) + ", " + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n" :
" define(" + externalsDepsArray(requiredExternals) + ", " + amdFactory + ");\n"
) :
(this.name && this.namedDefine === true ?
" define(" + libraryName(this.name) + ", [], " + amdFactory + ");\n" :
" define([], " + amdFactory + ");\n"
)
) +
(this.name ?
" else if(typeof exports === 'object')\n" +
" exports[" + JSON.stringify(replaceKeys([].concat(this.name).pop())) + "] = factory(" + externalsRequireArray("commonjs") + ");\n" +
" exports[" + libraryName(this.name) + "] = factory(" + externalsRequireArray("commonjs") + ");\n" +
" else\n" +
" " + replaceKeys(accessorAccess("root", this.name)) + " = factory(" + externalsRootArray(externals) + ");\n" :
" else {\n" +
Expand Down
7 changes: 4 additions & 3 deletions lib/WatchIgnorePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function IgnoringWatchFileSystem(wfs, paths) {
this.paths = paths;
}

IgnoringWatchFileSystem.prototype.watch = function(files, dirs, missing, startTime, delay, callback, callbackUndelayed) {
IgnoringWatchFileSystem.prototype.watch = function(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
var ignored = function(path) {
return this.paths.some(function(p) {
return p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0;
Expand All @@ -25,10 +25,11 @@ IgnoringWatchFileSystem.prototype.watch = function(files, dirs, missing, startTi
var notIgnored = function(path) {
return !ignored(path);
};

var ignoredFiles = files.filter(ignored);
var ignoredDirs = dirs.filter(ignored);

this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, delay, function(err, filesModified, dirsModified, fileTimestamps, dirTimestamps) {
this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, function(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) {
if(err) return callback(err);

ignoredFiles.forEach(function(path) {
Expand All @@ -39,6 +40,6 @@ IgnoringWatchFileSystem.prototype.watch = function(files, dirs, missing, startTi
dirTimestamps[path] = 1;
});

callback(err, filesModified, dirsModified, fileTimestamps, dirTimestamps);
callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);
}, callbackUndelayed);
};
5 changes: 3 additions & 2 deletions lib/WebpackOptionsApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
"clipboard",
"crash-reporter",
"screen",
"shell"
"shell",
"native-image"
]),
new LoaderTargetPlugin(options.target)
);
Expand All @@ -153,7 +154,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
}
if(options.output.library || options.output.libraryTarget !== "var") {
var LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget));
compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget, options.output.umdNamedDefine));
}
if(options.externals) {
var ExternalsPlugin = require("./ExternalsPlugin");
Expand Down
5 changes: 5 additions & 0 deletions lib/dependencies/ConstDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ ConstDependency.Template.prototype.apply = function(dep, source) {
else
source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
};

ConstDependency.prototype.updateHash = function(hash) {
hash.update(this.range + "");
hash.update(this.expression + "");
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack",
"version": "1.11.0",
"version": "1.12.2",
"author": "Tobias Koppers @sokra",
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
"dependencies": {
Expand All @@ -9,13 +9,14 @@
"clone": "^1.0.2",
"enhanced-resolve": "~0.9.0",
"interpret": "^0.6.4",
"loader-utils": "^0.2.11",
"memory-fs": "~0.2.0",
"mkdirp": "~0.5.0",
"node-libs-browser": ">= 0.4.0 <=0.6.0",
"optimist": "~0.6.0",
"supports-color": "^3.1.0",
"tapable": "~0.1.8",
"uglify-js": "~2.4.13",
"uglify-js": "~2.4.24",
"watchpack": "^0.2.1",
"webpack-core": "~0.6.0"
},
Expand All @@ -25,6 +26,7 @@
"bundle-loader": "~0.5.0",
"codecov.io": "^0.1.2",
"coffee-loader": "~0.7.1",
"coffee-script": "^1.10.0",
"component-webpack-plugin": "~0.2.0",
"coveralls": "^2.11.2",
"css-loader": "~0.15.0",
Expand All @@ -37,11 +39,12 @@
"glob": "^5.0.14",
"i18n-webpack-plugin": "~0.2.0",
"istanbul": "^0.3.13",
"jade": "^1.11.0",
"jade-loader": "~0.7.0",
"js-beautify": "^1.5.10",
"json-loader": "~0.5.1",
"less": "^2.5.1",
"less-loader": "^2.0.0",
"loader-utils": "^0.2.11",
"mocha": "~2.2.0",
"mocha-lcov-reporter": "0.0.2",
"raw-loader": "~0.5.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/forEachBeautifiedFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ module.exports = function forEachBeautifiedFile(fn, callback) {
if(err) return callback(err);
callback();
});
})
});

};
Loading

0 comments on commit 7cbd78c

Please sign in to comment.