Completely updated React, fixed #11, (hopefully)
This commit is contained in:
+18
-13
@@ -24,6 +24,9 @@
|
||||
<a href="https://opencollective.com/webpack#sponsors">
|
||||
<img src="https://opencollective.com/webpack/sponsors/badge.svg">
|
||||
</a>
|
||||
<a href="https://github.com/webpack/webpack/graphs/contributors">
|
||||
<img src="https://img.shields.io/github/contributors/webpack/webpack.svg">
|
||||
</a>
|
||||
<a href="https://gitter.im/webpack/webpack">
|
||||
<img src="https://badges.gitter.im/webpack/webpack.svg">
|
||||
</a>
|
||||
@@ -80,7 +83,7 @@ within webpack itself use this plugin interface. This makes webpack very
|
||||
|:--:|:----:|:----------|
|
||||
|[common-chunks-webpack-plugin][common]|![common-npm]|Generates chunks of common modules shared between entry points and splits them into separate bundles (e.g vendor.bundle.js && app.bundle.js)|
|
||||
|[extract-text-webpack-plugin][extract]|![extract-npm]|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)|
|
||||
|[compression-webpack-plugin][compression]|![compression-npm]|Prepare compressed versions of assets to serve them with Content-Encoding|
|
||||
|[compression-webpack-plugin][compression]|![compression-npm]|Prepares compressed versions of assets to serve them with Content-Encoding|
|
||||
|[i18n-webpack-plugin][i18n]|![i18n-npm]|Adds i18n support to your bundles|
|
||||
|[html-webpack-plugin][html-plugin]|![html-plugin-npm]| Simplifies creation of HTML files (`index.html`) to serve your bundles|
|
||||
|
||||
@@ -112,7 +115,7 @@ or are automatically applied via regex from your webpack configuration.
|
||||
|Name|Status|Description|
|
||||
|:--:|:----:|:----------|
|
||||
|[raw-loader][raw]|![raw-npm]|Loads raw content of a file (utf-8)|
|
||||
|[val-loader][val]|![val-npm]|Executes code as module and consider exports as JS code|
|
||||
|[val-loader][val]|![val-npm]|Executes code as module and considers exports as JS code|
|
||||
|[url-loader][url]|![url-npm]|Works like the file loader, but can return a Data Url if the file is smaller than a limit|
|
||||
|[file-loader][file]|![file-npm]|Emits the file into the output folder and returns the (relative) url|
|
||||
|
||||
@@ -143,10 +146,11 @@ or are automatically applied via regex from your webpack configuration.
|
||||
|
||||
|Name|Status|Description|
|
||||
|:--:|:----:|:----------|
|
||||
|<a href="https://github.com/webpack/script-loader">`<script>`</a>|![script-npm]|Executes a JavaScript file once in global context (like in script tag), requires are not parsed|
|
||||
|<a href="https://github.com/webpack/script-loader">`<script>`</a>|![script-npm]|Executes a JavaScript file once in global context (like in script tag), `require()`s are not parsed|
|
||||
|<a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a>|![babel-npm]|Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a>|
|
||||
|<a href="https://github.com/jupl/traceur-loader"><img width="48" height="48" src="https://google.github.com/traceur-compiler/logo/tc.svg"></a>|![traceur-npm]|Loads ES2015+ code and transpiles to ES5 using [Traceur](https://github.com/google/traceur-compiler)|
|
||||
|<a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a>|![type-npm]|Loads TypeScript like JavaScript|
|
||||
|[`awesome-typescript-loader`](https://github.com/s-panferov/awesome-typescript-loader)|![awesome-typescript-npm]|Awesome TypeScript loader for webpack|
|
||||
|<a href="https://github.com/webpack/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a>|![coffee-npm]|Loads CoffeeScript like JavaScript|
|
||||
|
||||
|
||||
@@ -155,12 +159,13 @@ or are automatically applied via regex from your webpack configuration.
|
||||
[traceur-npm]: https://img.shields.io/npm/v/traceur-loader.svg
|
||||
[coffee-npm]: https://img.shields.io/npm/v/coffee-loader.svg
|
||||
[type-npm]: https://img.shields.io/npm/v/ts-loader.svg
|
||||
[awesome-typescript-npm]: https://img.shields.io/npm/v/awesome-typescript-loader.svg
|
||||
|
||||
#### Templating
|
||||
|
||||
|Name|Status|Description|
|
||||
|:--:|:----:|:----------|
|
||||
|<a href="https://github.com/webpack/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a>|![html-npm]|Exports HTML as string, require references to static resources|
|
||||
|<a href="https://github.com/webpack/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a>|![html-npm]|Exports HTML as string, requires references to static resources|
|
||||
|<a href="https://github.com/pugjs/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a>|![pug-npm]|Loads Pug templates and returns a function|
|
||||
|<a href="https://github.com/webpack/jade-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/jade-3.svg"></a>|![jade-npm]|Loads Jade templates and returns a function|
|
||||
|<a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a>|![md-npm]|Compiles Markdown to HTML|
|
||||
@@ -212,14 +217,14 @@ or are automatically applied via regex from your webpack configuration.
|
||||
|Name|Status|Description|
|
||||
|:--:|:----:|:----------|
|
||||
|<a href="https://github.com/vuejs/vue-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/vue-9.svg"></a>|![vue-npm]|Loads and compiles Vue Components|
|
||||
|<a href="https://github.com/JonDum/polymer-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a>|![polymer-npm]|Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules|
|
||||
|<a href="https://github.com/webpack-contrib/polymer-webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a>|![polymer-npm]|Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules|
|
||||
|<a href="https://github.com/TheLarkInn/angular2-template-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/angular-icon-1.svg"></a>|![angular-npm]| Loads and compiles Angular 2 Components|
|
||||
|<a href="https://github.com/riot/tag-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/riot.svg"></a>|![riot-npm]| Riot official webpack loader|
|
||||
|
||||
|
||||
|
||||
[vue-npm]: https://img.shields.io/npm/v/vue-loader.svg
|
||||
[polymer-npm]: https://img.shields.io/npm/v/polymer-loader.svg
|
||||
[polymer-npm]: https://img.shields.io/npm/v/polymer-webpack-loader.svg
|
||||
[angular-npm]: https://img.shields.io/npm/v/angular2-template-loader.svg
|
||||
[riot-npm]: https://img.shields.io/npm/v/riot-tag-loader.svg
|
||||
|
||||
@@ -259,15 +264,15 @@ Contributions go far beyond pull requests and commits. Although we love giving y
|
||||
* Adding unit, or functional tests
|
||||
* Triaging GitHub issues -- especially determining whether an issue still persists or is reproducible.
|
||||
* [Searching #webpack on twitter](https://twitter.com/search?q=webpack) and helping someone else who needs help
|
||||
* Teaching others how to contribute to one of the many webpack repo's!
|
||||
* [Blogging, speaking about, or creating tutorials](https://github.com/webpack-contrib/awesome-webpack) about one of webpack's many features.
|
||||
* Teaching others how to contribute to one of the many webpack's repos!
|
||||
* [Blogging, speaking about, or creating tutorials](https://github.com/webpack-contrib/awesome-webpack) about one of webpack's many features.
|
||||
* Helping others in our webpack [gitter channel](https://gitter.im/webpack/webpack).
|
||||
|
||||
If you are worried or don't know where to start, you can **always** reach out to [Sean Larkin (@TheLarkInn) on Twitter](https://twitter.com/thelarkinn) or simply submit an issue and a maintainer can help give you guidance!
|
||||
If you are worried or don't know where to start, you can **always** reach out to [Sean Larkin (@TheLarkInn) on Twitter](https://twitter.com/thelarkinn) or simply submit an issue and a maintainer can help give you guidance!
|
||||
|
||||
We have also started a series on our [Medium Publication](https://medium.com/webpack) called [The Contributor's Guide to webpack](https://medium.com/webpack/contributors-guide/home). We welcome you to read it and post any questions or responses if you still need help.
|
||||
We have also started a series on our [Medium Publication](https://medium.com/webpack) called [The Contributor's Guide to webpack](https://medium.com/webpack/contributors-guide/home). We welcome you to read it and post any questions or responses if you still need help.
|
||||
|
||||
_Looking to speak about webpack?_ We'd **love** to review your talk abstract/CFP! You can email it to webpack [at] opencollective [dot] com and we can give pointers or tips!!!
|
||||
_Looking to speak about webpack?_ We'd **love** to review your talk abstract/CFP! You can email it to webpack [at] opencollective [dot] com and we can give pointers or tips!!!
|
||||
|
||||
<h3 align="center">Creating your own plugins and loaders</h3>
|
||||
|
||||
@@ -277,9 +282,9 @@ If you create a loader or plugin, we would <3 for you to open source it, and put
|
||||
|
||||
We consider webpack to be a low-level tool used not only individually but also layered beneath other awesome tools. Because of it's flexibility, webpack isn't always the _easiest_ entry-level solution, however we do believe it is the most powerful. That said, we're always looking for ways improve and simplify the tool without compromising functionality. If you have any ideas on ways to accomplish this, we're all ears!
|
||||
|
||||
If you're just getting started, take a look at [our new docs and concepts page](https://webpack.js.org/concepts/). This has a high level overview that is great for beginners!!
|
||||
If you're just getting started, take a look at [our new docs and concepts page](https://webpack.js.org/concepts/). This has a high level overview that is great for beginners!!
|
||||
|
||||
If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack) where there are always individuals looking to help out!
|
||||
If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack) where there are always individuals looking to help out!
|
||||
|
||||
If you are still having difficulty, we would love for you to post
|
||||
a question to [StackOverflow with the webpack tag](https://stackoverflow.com/tags/webpack). It is much easier to answer questions that include your webpack.config.js and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!)
|
||||
|
||||
+12
-8
@@ -333,16 +333,19 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
|
||||
var compiler;
|
||||
try {
|
||||
compiler = webpack(options);
|
||||
} catch(e) {
|
||||
var WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError");
|
||||
if(e instanceof WebpackOptionsValidationError) {
|
||||
} catch(err) {
|
||||
if(err.name === "WebpackOptionsValidationError") {
|
||||
if(argv.color)
|
||||
console.error("\u001b[1m\u001b[31m" + e.message + "\u001b[39m\u001b[22m");
|
||||
console.error(
|
||||
`\u001b[1m\u001b[31m${err.message}\u001b[39m\u001b[22m`
|
||||
);
|
||||
else
|
||||
console.error(e.message);
|
||||
process.exit(1); // eslint-disable-line no-process-exit
|
||||
console.error(err.message);
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
}
|
||||
throw e;
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
if(argv.progress) {
|
||||
@@ -361,7 +364,8 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
|
||||
lastHash = null;
|
||||
console.error(err.stack || err);
|
||||
if(err.details) console.error(err.details);
|
||||
process.exit(1); // eslint-disable-line
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
if(outputOptions.json) {
|
||||
process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ if(module.hot) {
|
||||
require("./log-apply-result")(updatedModules, renewedModules);
|
||||
|
||||
checkForUpdate(true);
|
||||
return null;
|
||||
});
|
||||
}).catch(function(err) {
|
||||
var status = module.hot.status();
|
||||
|
||||
+4
-2
@@ -47,10 +47,12 @@ class BannerPlugin {
|
||||
filename = filename.substr(0, querySplit);
|
||||
}
|
||||
|
||||
if(filename.indexOf("/") < 0) {
|
||||
const lastSlashIndex = filename.lastIndexOf("/");
|
||||
|
||||
if(lastSlashIndex === -1) {
|
||||
basename = filename;
|
||||
} else {
|
||||
basename = filename.substr(filename.lastIndexOf("/") + 1);
|
||||
basename = filename.substr(lastSlashIndex + 1);
|
||||
}
|
||||
|
||||
const comment = compilation.getPath(banner, {
|
||||
|
||||
+2
-2
@@ -404,14 +404,14 @@ class Chunk {
|
||||
return this.addMultiplierAndOverhead(integratedModulesSize, options);
|
||||
}
|
||||
|
||||
getChunkMaps(includeEntries, realHash) {
|
||||
getChunkMaps(includeInitial, realHash) {
|
||||
const chunksProcessed = [];
|
||||
const chunkHashMap = {};
|
||||
const chunkNameMap = {};
|
||||
(function addChunk(chunk) {
|
||||
if(chunksProcessed.indexOf(chunk) >= 0) return;
|
||||
chunksProcessed.push(chunk);
|
||||
if(!chunk.hasRuntime() || includeEntries) {
|
||||
if(!chunk.isInitial() || includeInitial) {
|
||||
chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
|
||||
if(chunk.name)
|
||||
chunkNameMap[chunk.id] = chunk.name;
|
||||
|
||||
+81
-92
@@ -34,7 +34,7 @@ function byId(a, b) {
|
||||
|
||||
function iterationBlockVariable(variables, fn) {
|
||||
for(let indexVariable = 0; indexVariable < variables.length; indexVariable++) {
|
||||
let varDep = variables[indexVariable].dependencies;
|
||||
const varDep = variables[indexVariable].dependencies;
|
||||
for(let indexVDep = 0; indexVDep < varDep.length; indexVDep++) {
|
||||
fn(varDep[indexVDep]);
|
||||
}
|
||||
@@ -116,8 +116,8 @@ class Compilation extends Tapable {
|
||||
cacheModule.disconnect();
|
||||
this._modules[identifier] = cacheModule;
|
||||
this.modules.push(cacheModule);
|
||||
cacheModule.errors.forEach(err => this.errors.push(err), this);
|
||||
cacheModule.warnings.forEach(err => this.warnings.push(err), this);
|
||||
cacheModule.errors.forEach(err => this.errors.push(err));
|
||||
cacheModule.warnings.forEach(err => this.warnings.push(err));
|
||||
return cacheModule;
|
||||
}
|
||||
}
|
||||
@@ -300,9 +300,7 @@ class Compilation extends Tapable {
|
||||
iterationDependencies(dependencies);
|
||||
|
||||
if(_this.profile) {
|
||||
if(!module.profile) {
|
||||
module.profile = {};
|
||||
}
|
||||
module.profile = module.profile || {};
|
||||
const time = Date.now() - start;
|
||||
if(!module.profile.dependencies || time > module.profile.dependencies) {
|
||||
module.profile.dependencies = time;
|
||||
@@ -572,112 +570,111 @@ class Compilation extends Tapable {
|
||||
}
|
||||
|
||||
seal(callback) {
|
||||
const self = this;
|
||||
self.applyPlugins0("seal");
|
||||
self.nextFreeModuleIndex = 0;
|
||||
self.nextFreeModuleIndex2 = 0;
|
||||
self.preparedChunks.forEach(preparedChunk => {
|
||||
this.applyPlugins0("seal");
|
||||
this.nextFreeModuleIndex = 0;
|
||||
this.nextFreeModuleIndex2 = 0;
|
||||
this.preparedChunks.forEach(preparedChunk => {
|
||||
const module = preparedChunk.module;
|
||||
const chunk = self.addChunk(preparedChunk.name, module);
|
||||
const entrypoint = self.entrypoints[chunk.name] = new Entrypoint(chunk.name);
|
||||
const chunk = this.addChunk(preparedChunk.name, module);
|
||||
const entrypoint = this.entrypoints[chunk.name] = new Entrypoint(chunk.name);
|
||||
entrypoint.unshiftChunk(chunk);
|
||||
|
||||
chunk.addModule(module);
|
||||
module.addChunk(chunk);
|
||||
chunk.entryModule = module;
|
||||
self.assignIndex(module);
|
||||
self.assignDepth(module);
|
||||
this.assignIndex(module);
|
||||
this.assignDepth(module);
|
||||
});
|
||||
self.processDependenciesBlocksForChunks(self.chunks.slice());
|
||||
self.sortModules(self.modules);
|
||||
self.applyPlugins0("optimize");
|
||||
this.processDependenciesBlocksForChunks(this.chunks.slice());
|
||||
this.sortModules(this.modules);
|
||||
this.applyPlugins0("optimize");
|
||||
|
||||
while(self.applyPluginsBailResult1("optimize-modules-basic", self.modules) ||
|
||||
self.applyPluginsBailResult1("optimize-modules", self.modules) ||
|
||||
self.applyPluginsBailResult1("optimize-modules-advanced", self.modules)) { /* empty */ }
|
||||
self.applyPlugins1("after-optimize-modules", self.modules);
|
||||
while(this.applyPluginsBailResult1("optimize-modules-basic", this.modules) ||
|
||||
this.applyPluginsBailResult1("optimize-modules", this.modules) ||
|
||||
this.applyPluginsBailResult1("optimize-modules-advanced", this.modules)) { /* empty */ }
|
||||
this.applyPlugins1("after-optimize-modules", this.modules);
|
||||
|
||||
while(self.applyPluginsBailResult1("optimize-chunks-basic", self.chunks) ||
|
||||
self.applyPluginsBailResult1("optimize-chunks", self.chunks) ||
|
||||
self.applyPluginsBailResult1("optimize-chunks-advanced", self.chunks)) { /* empty */ }
|
||||
self.applyPlugins1("after-optimize-chunks", self.chunks);
|
||||
while(this.applyPluginsBailResult1("optimize-chunks-basic", this.chunks) ||
|
||||
this.applyPluginsBailResult1("optimize-chunks", this.chunks) ||
|
||||
this.applyPluginsBailResult1("optimize-chunks-advanced", this.chunks)) { /* empty */ }
|
||||
this.applyPlugins1("after-optimize-chunks", this.chunks);
|
||||
|
||||
self.applyPluginsAsyncSeries("optimize-tree", self.chunks, self.modules, function sealPart2(err) {
|
||||
this.applyPluginsAsyncSeries("optimize-tree", this.chunks, this.modules, (err) => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
self.applyPlugins2("after-optimize-tree", self.chunks, self.modules);
|
||||
this.applyPlugins2("after-optimize-tree", this.chunks, this.modules);
|
||||
|
||||
while(self.applyPluginsBailResult("optimize-chunk-modules-basic", self.chunks, self.modules) ||
|
||||
self.applyPluginsBailResult("optimize-chunk-modules", self.chunks, self.modules) ||
|
||||
self.applyPluginsBailResult("optimize-chunk-modules-advanced", self.chunks, self.modules)) { /* empty */ }
|
||||
self.applyPlugins2("after-optimize-chunk-modules", self.chunks, self.modules);
|
||||
while(this.applyPluginsBailResult("optimize-chunk-modules-basic", this.chunks, this.modules) ||
|
||||
this.applyPluginsBailResult("optimize-chunk-modules", this.chunks, this.modules) ||
|
||||
this.applyPluginsBailResult("optimize-chunk-modules-advanced", this.chunks, this.modules)) { /* empty */ }
|
||||
this.applyPlugins2("after-optimize-chunk-modules", this.chunks, this.modules);
|
||||
|
||||
const shouldRecord = self.applyPluginsBailResult("should-record") !== false;
|
||||
const shouldRecord = this.applyPluginsBailResult("should-record") !== false;
|
||||
|
||||
self.applyPlugins2("revive-modules", self.modules, self.records);
|
||||
self.applyPlugins1("optimize-module-order", self.modules);
|
||||
self.applyPlugins1("advanced-optimize-module-order", self.modules);
|
||||
self.applyPlugins1("before-module-ids", self.modules);
|
||||
self.applyPlugins1("module-ids", self.modules);
|
||||
self.applyModuleIds();
|
||||
self.applyPlugins1("optimize-module-ids", self.modules);
|
||||
self.applyPlugins1("after-optimize-module-ids", self.modules);
|
||||
this.applyPlugins2("revive-modules", this.modules, this.records);
|
||||
this.applyPlugins1("optimize-module-order", this.modules);
|
||||
this.applyPlugins1("advanced-optimize-module-order", this.modules);
|
||||
this.applyPlugins1("before-module-ids", this.modules);
|
||||
this.applyPlugins1("module-ids", this.modules);
|
||||
this.applyModuleIds();
|
||||
this.applyPlugins1("optimize-module-ids", this.modules);
|
||||
this.applyPlugins1("after-optimize-module-ids", this.modules);
|
||||
|
||||
self.sortItemsWithModuleIds();
|
||||
this.sortItemsWithModuleIds();
|
||||
|
||||
self.applyPlugins2("revive-chunks", self.chunks, self.records);
|
||||
self.applyPlugins1("optimize-chunk-order", self.chunks);
|
||||
self.applyPlugins1("before-chunk-ids", self.chunks);
|
||||
self.applyChunkIds();
|
||||
self.applyPlugins1("optimize-chunk-ids", self.chunks);
|
||||
self.applyPlugins1("after-optimize-chunk-ids", self.chunks);
|
||||
this.applyPlugins2("revive-chunks", this.chunks, this.records);
|
||||
this.applyPlugins1("optimize-chunk-order", this.chunks);
|
||||
this.applyPlugins1("before-chunk-ids", this.chunks);
|
||||
this.applyChunkIds();
|
||||
this.applyPlugins1("optimize-chunk-ids", this.chunks);
|
||||
this.applyPlugins1("after-optimize-chunk-ids", this.chunks);
|
||||
|
||||
self.sortItemsWithChunkIds();
|
||||
this.sortItemsWithChunkIds();
|
||||
|
||||
if(shouldRecord)
|
||||
self.applyPlugins2("record-modules", self.modules, self.records);
|
||||
this.applyPlugins2("record-modules", this.modules, this.records);
|
||||
if(shouldRecord)
|
||||
self.applyPlugins2("record-chunks", self.chunks, self.records);
|
||||
this.applyPlugins2("record-chunks", this.chunks, this.records);
|
||||
|
||||
self.applyPlugins0("before-hash");
|
||||
self.createHash();
|
||||
self.applyPlugins0("after-hash");
|
||||
this.applyPlugins0("before-hash");
|
||||
this.createHash();
|
||||
this.applyPlugins0("after-hash");
|
||||
|
||||
if(shouldRecord)
|
||||
self.applyPlugins1("record-hash", self.records);
|
||||
this.applyPlugins1("record-hash", this.records);
|
||||
|
||||
self.applyPlugins0("before-module-assets");
|
||||
self.createModuleAssets();
|
||||
if(self.applyPluginsBailResult("should-generate-chunk-assets") !== false) {
|
||||
self.applyPlugins0("before-chunk-assets");
|
||||
self.createChunkAssets();
|
||||
this.applyPlugins0("before-module-assets");
|
||||
this.createModuleAssets();
|
||||
if(this.applyPluginsBailResult("should-generate-chunk-assets") !== false) {
|
||||
this.applyPlugins0("before-chunk-assets");
|
||||
this.createChunkAssets();
|
||||
}
|
||||
self.applyPlugins1("additional-chunk-assets", self.chunks);
|
||||
self.summarizeDependencies();
|
||||
this.applyPlugins1("additional-chunk-assets", this.chunks);
|
||||
this.summarizeDependencies();
|
||||
if(shouldRecord)
|
||||
self.applyPlugins2("record", self, self.records);
|
||||
this.applyPlugins2("record", this, this.records);
|
||||
|
||||
self.applyPluginsAsync("additional-assets", err => {
|
||||
this.applyPluginsAsync("additional-assets", err => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
self.applyPluginsAsync("optimize-chunk-assets", self.chunks, err => {
|
||||
this.applyPluginsAsync("optimize-chunk-assets", this.chunks, err => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
self.applyPlugins1("after-optimize-chunk-assets", self.chunks);
|
||||
self.applyPluginsAsync("optimize-assets", self.assets, err => {
|
||||
this.applyPlugins1("after-optimize-chunk-assets", this.chunks);
|
||||
this.applyPluginsAsync("optimize-assets", this.assets, err => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
self.applyPlugins1("after-optimize-assets", self.assets);
|
||||
if(self.applyPluginsBailResult("need-additional-seal")) {
|
||||
self.unseal();
|
||||
return self.seal(callback);
|
||||
this.applyPlugins1("after-optimize-assets", this.assets);
|
||||
if(this.applyPluginsBailResult("need-additional-seal")) {
|
||||
this.unseal();
|
||||
return this.seal(callback);
|
||||
}
|
||||
return self.applyPluginsAsync("after-seal", callback);
|
||||
return this.applyPluginsAsync("after-seal", callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -685,11 +682,7 @@ class Compilation extends Tapable {
|
||||
}
|
||||
|
||||
sortModules(modules) {
|
||||
modules.sort((a, b) => {
|
||||
if(a.index < b.index) return -1;
|
||||
if(a.index > b.index) return 1;
|
||||
return 0;
|
||||
});
|
||||
modules.sort(byId);
|
||||
}
|
||||
|
||||
reportDependencyErrorsAndWarnings(module, blocks) {
|
||||
@@ -1097,9 +1090,9 @@ class Compilation extends Tapable {
|
||||
}
|
||||
|
||||
applyModuleIds() {
|
||||
let unusedIds = [];
|
||||
const unusedIds = [];
|
||||
let nextFreeModuleId = 0;
|
||||
let usedIds = [];
|
||||
const usedIds = [];
|
||||
// TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
|
||||
const usedIdMap = Object.create(null);
|
||||
if(this.usedModuleIds) {
|
||||
@@ -1218,14 +1211,12 @@ class Compilation extends Tapable {
|
||||
sortItemsWithChunkIds() {
|
||||
this.chunks.sort(byId);
|
||||
|
||||
const modules = this.modules;
|
||||
for(let indexModule = 0; indexModule < modules.length; indexModule++) {
|
||||
modules[indexModule].sortItems(true);
|
||||
for(let indexModule = 0; indexModule < this.modules.length; indexModule++) {
|
||||
this.modules[indexModule].sortItems(true);
|
||||
}
|
||||
|
||||
const chunks = this.chunks;
|
||||
for(let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
||||
chunks[indexChunk].sortItems();
|
||||
for(let indexChunk = 0; indexChunk < this.chunks.length; indexChunk++) {
|
||||
this.chunks[indexChunk].sortItems();
|
||||
}
|
||||
|
||||
const byMessage = (a, b) => {
|
||||
@@ -1253,18 +1244,16 @@ class Compilation extends Tapable {
|
||||
this.contextDependencies = [];
|
||||
this.missingDependencies = [];
|
||||
|
||||
const children = this.children;
|
||||
for(let indexChildren = 0; indexChildren < children.length; indexChildren++) {
|
||||
const child = children[indexChildren];
|
||||
for(let indexChildren = 0; indexChildren < this.children.length; indexChildren++) {
|
||||
const child = this.children[indexChildren];
|
||||
|
||||
this.fileDependencies = this.fileDependencies.concat(child.fileDependencies);
|
||||
this.contextDependencies = this.contextDependencies.concat(child.contextDependencies);
|
||||
this.missingDependencies = this.missingDependencies.concat(child.missingDependencies);
|
||||
}
|
||||
|
||||
const modules = this.modules;
|
||||
for(let indexModule = 0; indexModule < modules.length; indexModule++) {
|
||||
const module = modules[indexModule];
|
||||
for(let indexModule = 0; indexModule < this.modules.length; indexModule++) {
|
||||
const module = this.modules[indexModule];
|
||||
|
||||
if(module.fileDependencies) {
|
||||
const fileDependencies = module.fileDependencies;
|
||||
@@ -1425,7 +1414,7 @@ class Compilation extends Tapable {
|
||||
}
|
||||
|
||||
createChildCompiler(name, outputOptions, plugins) {
|
||||
var idx = (this.childrenCounters[name] || 0);
|
||||
const idx = (this.childrenCounters[name] || 0);
|
||||
this.childrenCounters[name] = idx + 1;
|
||||
return this.compiler.createChildCompiler(this, name, idx, outputOptions, plugins);
|
||||
}
|
||||
|
||||
+22
-26
@@ -6,6 +6,7 @@
|
||||
|
||||
const path = require("path");
|
||||
const Tapable = require("tapable");
|
||||
const util = require("util");
|
||||
|
||||
const Compilation = require("./Compilation");
|
||||
const Stats = require("./Stats");
|
||||
@@ -186,35 +187,30 @@ class Compiler extends Tapable {
|
||||
loader: null,
|
||||
context: null
|
||||
};
|
||||
let deprecationReported = false;
|
||||
this.parser = {
|
||||
plugin: (hook, fn) => {
|
||||
if(!deprecationReported) {
|
||||
console.warn("webpack: Using compiler.parser is deprecated.\n" +
|
||||
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. " +
|
||||
"It was called " + new Error().stack.split("\n")[2].trim() + ".");
|
||||
deprecationReported = true;
|
||||
}
|
||||
this.plugin("compilation", (compilation, data) => {
|
||||
data.normalModuleFactory.plugin("parser", parser => {
|
||||
parser.plugin(hook, fn);
|
||||
plugin: util.deprecate(
|
||||
(hook, fn) => {
|
||||
this.plugin("compilation", (compilation, data) => {
|
||||
data.normalModuleFactory.plugin("parser", parser => {
|
||||
parser.plugin(hook, fn);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
apply: () => {
|
||||
const args = arguments;
|
||||
if(!deprecationReported) {
|
||||
console.warn("webpack: Using compiler.parser is deprecated.\n" +
|
||||
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. " +
|
||||
"It was called " + new Error().stack.split("\n")[2].trim() + ".");
|
||||
deprecationReported = true;
|
||||
}
|
||||
this.plugin("compilation", (compilation, data) => {
|
||||
data.normalModuleFactory.plugin("parser", parser => {
|
||||
parser.apply.apply(parser, args);
|
||||
},
|
||||
"webpack: Using compiler.parser is deprecated.\n" +
|
||||
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. "
|
||||
),
|
||||
apply: util.deprecate(
|
||||
() => {
|
||||
const args = arguments;
|
||||
this.plugin("compilation", (compilation, data) => {
|
||||
data.normalModuleFactory.plugin("parser", parser => {
|
||||
parser.apply.apply(parser, args);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
"webpack: Using compiler.parser is deprecated.\n" +
|
||||
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. "
|
||||
)
|
||||
};
|
||||
|
||||
this.options = {};
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var Tapable = require("tapable");
|
||||
var DllModule = require("./DllModule");
|
||||
const Tapable = require("tapable");
|
||||
const DllModule = require("./DllModule");
|
||||
|
||||
class DllModuleFactory extends Tapable {
|
||||
constructor() {
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ class DllReferencePlugin {
|
||||
manifest = params["dll reference " + manifest];
|
||||
}
|
||||
const name = this.options.name || manifest.name;
|
||||
const sourceType = this.options.sourceType || "var";
|
||||
const sourceType = this.options.sourceType || (manifest && manifest.type) || "var";
|
||||
const externals = {};
|
||||
const source = "dll-reference " + name;
|
||||
externals[source] = name;
|
||||
|
||||
+10
@@ -7,6 +7,9 @@
|
||||
|
||||
const DefinePlugin = require("./DefinePlugin");
|
||||
|
||||
const needsEnvVarFix = ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
|
||||
process.platform === "win32";
|
||||
|
||||
class EnvironmentPlugin {
|
||||
constructor(keys) {
|
||||
if(Array.isArray(keys)) {
|
||||
@@ -23,6 +26,13 @@ class EnvironmentPlugin {
|
||||
|
||||
apply(compiler) {
|
||||
const definitions = this.keys.reduce((defs, key) => {
|
||||
// TODO remove once the fix has made its way into Node 8.
|
||||
// Work around https://github.com/nodejs/node/pull/18463,
|
||||
// affecting Node 8 & 9 by performing an OS-level
|
||||
// operation that always succeeds before reading
|
||||
// environment variables:
|
||||
if(needsEnvVarFix) require("os").cpus();
|
||||
|
||||
const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key];
|
||||
|
||||
if(value === undefined) {
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -55,7 +55,7 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
|
||||
sourceMap.sources = moduleFilenames;
|
||||
if(sourceMap.sourcesContent) {
|
||||
sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
|
||||
return `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener)}`;
|
||||
return typeof content === "string" ? `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], this.requestShortener)}` : null;
|
||||
}, this);
|
||||
}
|
||||
sourceMap.sourceRoot = options.sourceRoot || "";
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
|
||||
class ExternalsPlugin {
|
||||
constructor(type, externals) {
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ class FlagDependencyUsagePlugin {
|
||||
else if(usedExports === true)
|
||||
module.usedExports = true;
|
||||
else if(Array.isArray(usedExports)) {
|
||||
var old = module.usedExports ? module.usedExports.length : -1;
|
||||
const old = module.usedExports ? module.usedExports.length : -1;
|
||||
module.usedExports = addToSet(module.usedExports || [], usedExports);
|
||||
if(module.usedExports.length === old)
|
||||
return;
|
||||
|
||||
+5
-5
@@ -25,6 +25,11 @@ module.exports = class HotModuleReplacementPlugin {
|
||||
const requestTimeout = this.requestTimeout;
|
||||
const hotUpdateChunkFilename = compiler.options.output.hotUpdateChunkFilename;
|
||||
const hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename;
|
||||
compiler.plugin("additional-pass", callback => {
|
||||
if(multiStep)
|
||||
return setTimeout(callback, fullBuildTimeout);
|
||||
return callback();
|
||||
});
|
||||
compiler.plugin("compilation", (compilation, params) => {
|
||||
const hotUpdateChunkTemplate = compilation.hotUpdateChunkTemplate;
|
||||
if(!hotUpdateChunkTemplate) return;
|
||||
@@ -88,11 +93,6 @@ module.exports = class HotModuleReplacementPlugin {
|
||||
if(multiStep && !recompilation && !initialPass)
|
||||
return true;
|
||||
});
|
||||
compiler.plugin("additional-pass", callback => {
|
||||
if(multiStep)
|
||||
return setTimeout(callback, fullBuildTimeout);
|
||||
return callback();
|
||||
});
|
||||
compilation.plugin("additional-chunk-assets", function() {
|
||||
const records = this.records;
|
||||
if(records.hash === this.hash) return;
|
||||
|
||||
+4
-3
@@ -29,6 +29,7 @@ class JsonpMainTemplatePlugin {
|
||||
const chunkMaps = chunk.getChunkMaps();
|
||||
const crossOriginLoading = this.outputOptions.crossOriginLoading;
|
||||
const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout;
|
||||
const jsonpScriptType = this.outputOptions.jsonpScriptType;
|
||||
const scriptSrcPath = this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
|
||||
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
|
||||
hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
|
||||
@@ -48,7 +49,7 @@ class JsonpMainTemplatePlugin {
|
||||
});
|
||||
return this.asString([
|
||||
"var script = document.createElement('script');",
|
||||
"script.type = 'text/javascript';",
|
||||
`script.type = ${JSON.stringify(jsonpScriptType)};`,
|
||||
"script.charset = 'utf-8';",
|
||||
"script.async = true;",
|
||||
`script.timeout = ${chunkLoadTimeout};`,
|
||||
@@ -195,8 +196,8 @@ class JsonpMainTemplatePlugin {
|
||||
function hotDisposeChunk(chunkId) {
|
||||
delete installedChunks[chunkId];
|
||||
}
|
||||
var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];
|
||||
this[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
||||
var parentHotUpdateCallback = window[${JSON.stringify(hotUpdateFunction)}];
|
||||
window[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
||||
});
|
||||
mainTemplate.plugin("hash", function(hash) {
|
||||
hash.update("jsonp");
|
||||
|
||||
+3
-1
@@ -99,7 +99,9 @@ module.exports = class MainTemplate extends Template {
|
||||
});
|
||||
this.plugin("require-extensions", (source, chunk, hash) => {
|
||||
const buf = [];
|
||||
if(chunk.chunks.length > 0) {
|
||||
const chunkMaps = chunk.getChunkMaps();
|
||||
// Check if there are non initial chunks which need to be imported using require-ensure
|
||||
if(Object.keys(chunkMaps.hash).length) {
|
||||
buf.push("// This file contains only the entry chunk.");
|
||||
buf.push("// The chunk loading function for additional chunks");
|
||||
buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
|
||||
|
||||
+2
-2
@@ -7,12 +7,12 @@
|
||||
class NoEmitOnErrorsPlugin {
|
||||
apply(compiler) {
|
||||
compiler.plugin("should-emit", (compilation) => {
|
||||
if(compilation.errors.length > 0)
|
||||
if(compilation.getStats().hasErrors())
|
||||
return false;
|
||||
});
|
||||
compiler.plugin("compilation", (compilation) => {
|
||||
compilation.plugin("should-record", () => {
|
||||
if(compilation.errors.length > 0)
|
||||
if(compilation.getStats().hasErrors())
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
+3
-1
@@ -133,7 +133,9 @@ class NormalModuleFactory extends Tapable {
|
||||
try {
|
||||
loaders.forEach(item => {
|
||||
if(typeof item.options === "string" && /^\?/.test(item.options)) {
|
||||
item.options = this.ruleSet.findOptionsByIdent(item.options.substr(1));
|
||||
const ident = item.options.substr(1);
|
||||
item.options = this.ruleSet.findOptionsByIdent(ident);
|
||||
item.ident = ident;
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
|
||||
function getProperty(obj, name) {
|
||||
name = name.split(".");
|
||||
for(var i = 0; i < name.length - 1; i++) {
|
||||
for(let i = 0; i < name.length - 1; i++) {
|
||||
obj = obj[name[i]];
|
||||
if(typeof obj !== "object" || !obj) return;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ function getProperty(obj, name) {
|
||||
|
||||
function setProperty(obj, name, value) {
|
||||
name = name.split(".");
|
||||
for(var i = 0; i < name.length - 1; i++) {
|
||||
for(let i = 0; i < name.length - 1; i++) {
|
||||
if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
|
||||
if(!obj[name[i]]) obj[name[i]] = {};
|
||||
obj = obj[name[i]];
|
||||
|
||||
+79
@@ -174,6 +174,15 @@ class Parser extends Tapable {
|
||||
res.setNumber(left.number / right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === "**") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(Math.pow(left.number, right.number));
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === "==" || expr.operator === "===") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
@@ -200,6 +209,60 @@ class Parser extends Tapable {
|
||||
} else if(left.isBoolean() && right.isBoolean()) {
|
||||
return res.setBoolean(left.bool !== right.bool);
|
||||
}
|
||||
} else if(expr.operator === "&") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(left.number & right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === "|") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(left.number | right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === "^") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(left.number ^ right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === ">>>") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(left.number >>> right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === ">>") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(left.number >> right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
} else if(expr.operator === "<<") {
|
||||
left = this.evaluateExpression(expr.left);
|
||||
right = this.evaluateExpression(expr.right);
|
||||
if(!left || !right) return;
|
||||
if(!left.isNumber() || !right.isNumber()) return;
|
||||
res = new BasicEvaluatedExpression();
|
||||
res.setNumber(left.number << right.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
}
|
||||
});
|
||||
this.plugin("evaluate UnaryExpression", function(expr) {
|
||||
@@ -242,6 +305,14 @@ class Parser extends Tapable {
|
||||
} else if(argument.isNumber()) {
|
||||
return new BasicEvaluatedExpression().setBoolean(!argument.number).setRange(expr.range);
|
||||
}
|
||||
} else if(expr.operator === "~") {
|
||||
const argument = this.evaluateExpression(expr.argument);
|
||||
if(!argument) return;
|
||||
if(!argument.isNumber()) return;
|
||||
const res = new BasicEvaluatedExpression();
|
||||
res.setNumber(~argument.number);
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
}
|
||||
});
|
||||
this.plugin("evaluate typeof undefined", function(expr) {
|
||||
@@ -1047,6 +1118,14 @@ class Parser extends Tapable {
|
||||
}
|
||||
|
||||
walkNewExpression(expression) {
|
||||
const callee = this.evaluateExpression(expression.callee);
|
||||
if(callee.isIdentifier()) {
|
||||
const result = this.applyPluginsBailResult("new " + callee.identifier, expression);
|
||||
if(result === true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.walkExpression(expression.callee);
|
||||
if(expression.arguments)
|
||||
this.walkExpressions(expression.arguments);
|
||||
|
||||
+3
-3
@@ -158,7 +158,7 @@ class SourceMapDevToolPlugin {
|
||||
const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m));
|
||||
sourceMap.sources = moduleFilenames;
|
||||
if(sourceMap.sourcesContent && !options.noSources) {
|
||||
sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
|
||||
sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => typeof content === "string" ? `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}` : null);
|
||||
} else {
|
||||
sourceMap.sourcesContent = undefined;
|
||||
}
|
||||
@@ -181,14 +181,14 @@ class SourceMapDevToolPlugin {
|
||||
}
|
||||
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
||||
chunk,
|
||||
filename,
|
||||
filename: options.fileContext ? path.relative(options.fileContext, filename) : filename,
|
||||
query,
|
||||
basename: basename(filename)
|
||||
});
|
||||
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
|
||||
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
|
||||
}
|
||||
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
||||
const sourceMapUrl = options.publicPath ? options.publicPath + sourceMapFile.replace(/\\/g, "/") : path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
||||
if(currentSourceMappingURLComment !== false) {
|
||||
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
||||
}
|
||||
|
||||
+4
-2
@@ -50,11 +50,13 @@ class Stats {
|
||||
}
|
||||
|
||||
hasWarnings() {
|
||||
return this.compilation.warnings.length > 0;
|
||||
return this.compilation.warnings.length > 0 ||
|
||||
this.compilation.children.some(child => child.getStats().hasWarnings());
|
||||
}
|
||||
|
||||
hasErrors() {
|
||||
return this.compilation.errors.length > 0;
|
||||
return this.compilation.errors.length > 0 ||
|
||||
this.compilation.children.some(child => child.getStats().hasErrors());
|
||||
}
|
||||
|
||||
// remove a prefixed "!" that can be specified to reverse sort order
|
||||
|
||||
+6
-2
@@ -60,6 +60,10 @@ const replacePathVariables = (path, data) => {
|
||||
const chunkHash = chunk && (chunk.renderedHash || chunk.hash);
|
||||
const chunkHashWithLength = chunk && chunk.hashWithLength;
|
||||
|
||||
if(typeof path === "function") {
|
||||
path = path(data);
|
||||
}
|
||||
|
||||
if(data.noChunkHash && REGEXP_CHUNKHASH_FOR_TEST.test(path)) {
|
||||
throw new Error(`Cannot use [chunkhash] for chunk in '${path}' (use [hash] instead)`);
|
||||
}
|
||||
@@ -101,9 +105,9 @@ class TemplatedPathPlugin {
|
||||
const outputOptions = this.outputOptions;
|
||||
const chunkFilename = outputOptions.chunkFilename || outputOptions.filename;
|
||||
if(REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
|
||||
hash.update(JSON.stringify(chunk.getChunkMaps(true, true).hash));
|
||||
hash.update(JSON.stringify(chunk.getChunkMaps(false, true).hash));
|
||||
if(REGEXP_NAME_FOR_TEST.test(chunkFilename))
|
||||
hash.update(JSON.stringify(chunk.getChunkMaps(true, true).name));
|
||||
hash.update(JSON.stringify(chunk.getChunkMaps(false, true).name));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ class UmdMainTemplatePlugin {
|
||||
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
|
||||
" }\n"
|
||||
) +
|
||||
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
|
||||
"})(typeof self !== 'undefined' ? self : this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
|
||||
});
|
||||
mainTemplate.plugin("global-hash-paths", (paths) => {
|
||||
if(this.names.root) paths = paths.concat(this.names.root);
|
||||
|
||||
+1
@@ -61,6 +61,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
||||
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
|
||||
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
|
||||
this.set("output.crossOriginLoading", false);
|
||||
this.set("output.jsonpScriptType", "text/javascript");
|
||||
this.set("output.chunkLoadTimeout", 120000);
|
||||
this.set("output.hashFunction", "md5");
|
||||
this.set("output.hashDigest", "hex");
|
||||
|
||||
+34
-11
@@ -35,10 +35,21 @@ const getSchemaPartText = (schemaPart, additionalPath) => {
|
||||
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
|
||||
let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
|
||||
if(schemaPart.description)
|
||||
schemaText += `\n${schemaPart.description}`;
|
||||
schemaText += `\n-> ${schemaPart.description}`;
|
||||
return schemaText;
|
||||
};
|
||||
|
||||
const getSchemaPartDescription = schemaPart => {
|
||||
while(schemaPart.$ref) schemaPart = getSchemaPart(schemaPart.$ref);
|
||||
if(schemaPart.description)
|
||||
return `\n-> ${schemaPart.description}`;
|
||||
return "";
|
||||
};
|
||||
|
||||
const filterChildren = children => {
|
||||
return children.filter(err => err.keyword !== "anyOf" && err.keyword !== "allOf" && err.keyword !== "oneOf");
|
||||
};
|
||||
|
||||
const indent = (str, prefix, firstLine) => {
|
||||
if(firstLine) {
|
||||
return prefix + str.replace(/\n(?!$)/g, "\n" + prefix);
|
||||
@@ -143,8 +154,16 @@ class WebpackOptionsValidationError extends WebpackError {
|
||||
return baseMessage;
|
||||
} else if(err.keyword === "oneOf" || err.keyword === "anyOf") {
|
||||
if(err.children && err.children.length > 0) {
|
||||
if(err.schema.length === 1) {
|
||||
const lastChild = err.children[err.children.length - 1];
|
||||
const remainingChildren = err.children.slice(0, err.children.length - 1);
|
||||
return WebpackOptionsValidationError.formatValidationError(Object.assign({}, lastChild, {
|
||||
children: remainingChildren,
|
||||
parentSchema: Object.assign({}, err.parentSchema, lastChild.parentSchema)
|
||||
}));
|
||||
}
|
||||
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}\n` +
|
||||
`Details:\n${err.children.map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
|
||||
`Details:\n${filterChildren(err.children).map(err => " * " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n")}`;
|
||||
}
|
||||
return `${dataPath} should be one of these:\n${getSchemaPartText(err.parentSchema)}`;
|
||||
|
||||
@@ -158,29 +177,33 @@ class WebpackOptionsValidationError extends WebpackError {
|
||||
} else if(err.keyword === "type") {
|
||||
switch(err.params.type) {
|
||||
case "object":
|
||||
return `${dataPath} should be an object.`;
|
||||
return `${dataPath} should be an object.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
case "string":
|
||||
return `${dataPath} should be a string.`;
|
||||
return `${dataPath} should be a string.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
case "boolean":
|
||||
return `${dataPath} should be a boolean.`;
|
||||
return `${dataPath} should be a boolean.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
case "number":
|
||||
return `${dataPath} should be a number.`;
|
||||
return `${dataPath} should be a number.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
case "array":
|
||||
return `${dataPath} should be an array:\n${getSchemaPartText(err.parentSchema)}`;
|
||||
}
|
||||
return `${dataPath} should be ${err.params.type}:\n${getSchemaPartText(err.parentSchema)}`;
|
||||
} else if(err.keyword === "instanceof") {
|
||||
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}.`;
|
||||
return `${dataPath} should be an instance of ${getSchemaPartText(err.parentSchema)}`;
|
||||
} else if(err.keyword === "required") {
|
||||
const missingProperty = err.params.missingProperty.replace(/^\./, "");
|
||||
return `${dataPath} misses the property '${missingProperty}'.\n${getSchemaPartText(err.parentSchema, ["properties", missingProperty])}`;
|
||||
} else if(err.keyword === "minLength" || err.keyword === "minItems") {
|
||||
} else if(err.keyword === "minimum") {
|
||||
return `${dataPath} ${err.message}.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
} else if(err.keyword === "uniqueItems") {
|
||||
return `${dataPath} should not contain the item '${err.data[err.params.i]}' twice.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
} else if(err.keyword === "minLength" || err.keyword === "minItems" || err.keyword === "minProperties") {
|
||||
if(err.params.limit === 1)
|
||||
return `${dataPath} should not be empty.`;
|
||||
return `${dataPath} should not be empty.${getSchemaPartDescription(err.parentSchema)}`;
|
||||
else
|
||||
return `${dataPath} ${err.message}`;
|
||||
return `${dataPath} ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
|
||||
} else if(err.keyword === "absolutePath") {
|
||||
const baseMessage = `${dataPath}: ${err.message}`;
|
||||
const baseMessage = `${dataPath}: ${err.message}${getSchemaPartDescription(err.parentSchema)}`;
|
||||
if(dataPath === "configuration.output.filename") {
|
||||
return `${baseMessage}\n` +
|
||||
"Please use output.path to specify absolute path and output.filename for the file name.";
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
|
||||
return {
|
||||
f: [
|
||||
"var __WEBPACK_AMD_DEFINE_RESULT__;",
|
||||
`!(__WEBPACK_AMD_DEFINE_RESULT__ = #.call(exports, __webpack_require__, exports, module),
|
||||
`!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, __webpack_require__, exports, module),
|
||||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
|
||||
],
|
||||
o: [
|
||||
@@ -42,7 +42,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
|
||||
],
|
||||
af: [
|
||||
"var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;",
|
||||
`!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = #.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
||||
`!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, __WEBPACK_AMD_DEFINE_RESULT__ = (#).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
||||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
|
||||
],
|
||||
ao: [
|
||||
@@ -70,7 +70,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
|
||||
],
|
||||
laf: [
|
||||
"var __WEBPACK_AMD_DEFINE_ARRAY__, XXX;",
|
||||
"!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = (#.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)))"
|
||||
"!(__WEBPACK_AMD_DEFINE_ARRAY__ = #, XXX = ((#).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)))"
|
||||
],
|
||||
lao: [
|
||||
"var XXX;",
|
||||
|
||||
Generated
Vendored
+18
-6
@@ -23,6 +23,18 @@ function isBoundFunctionExpression(expr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isUnboundFunctionExpression(expr) {
|
||||
if(expr.type === "FunctionExpression") return true;
|
||||
if(expr.type === "ArrowFunctionExpression") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isCallable(expr) {
|
||||
if(isUnboundFunctionExpression(expr)) return true;
|
||||
if(isBoundFunctionExpression(expr)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
class AMDDefineDependencyParserPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
@@ -38,7 +50,7 @@ class AMDDefineDependencyParserPlugin {
|
||||
let array, fn, obj, namedModule;
|
||||
switch(expr.arguments.length) {
|
||||
case 1:
|
||||
if(expr.arguments[0].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[0])) {
|
||||
if(isCallable(expr.arguments[0])) {
|
||||
// define(f() {...})
|
||||
fn = expr.arguments[0];
|
||||
} else if(expr.arguments[0].type === "ObjectExpression") {
|
||||
@@ -54,7 +66,7 @@ class AMDDefineDependencyParserPlugin {
|
||||
if(expr.arguments[0].type === "Literal") {
|
||||
namedModule = expr.arguments[0].value;
|
||||
// define("...", ...)
|
||||
if(expr.arguments[1].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[1])) {
|
||||
if(isCallable(expr.arguments[1])) {
|
||||
// define("...", f() {...})
|
||||
fn = expr.arguments[1];
|
||||
} else if(expr.arguments[1].type === "ObjectExpression") {
|
||||
@@ -67,7 +79,7 @@ class AMDDefineDependencyParserPlugin {
|
||||
}
|
||||
} else {
|
||||
array = expr.arguments[0];
|
||||
if(expr.arguments[1].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[1])) {
|
||||
if(isCallable(expr.arguments[1])) {
|
||||
// define([...], f() {})
|
||||
fn = expr.arguments[1];
|
||||
} else if(expr.arguments[1].type === "ObjectExpression") {
|
||||
@@ -84,7 +96,7 @@ class AMDDefineDependencyParserPlugin {
|
||||
// define("...", [...], f() {...})
|
||||
namedModule = expr.arguments[0].value;
|
||||
array = expr.arguments[1];
|
||||
if(expr.arguments[2].type === "FunctionExpression" || isBoundFunctionExpression(expr.arguments[2])) {
|
||||
if(isCallable(expr.arguments[2])) {
|
||||
// define("...", [...], f() {})
|
||||
fn = expr.arguments[2];
|
||||
} else if(expr.arguments[2].type === "ObjectExpression") {
|
||||
@@ -102,7 +114,7 @@ class AMDDefineDependencyParserPlugin {
|
||||
let fnParams = null;
|
||||
let fnParamsOffset = 0;
|
||||
if(fn) {
|
||||
if(fn.type === "FunctionExpression") fnParams = fn.params;
|
||||
if(isUnboundFunctionExpression(fn)) fnParams = fn.params;
|
||||
else if(isBoundFunctionExpression(fn)) {
|
||||
fnParams = fn.callee.object.params;
|
||||
fnParamsOffset = fn.arguments.length - 1;
|
||||
@@ -134,7 +146,7 @@ class AMDDefineDependencyParserPlugin {
|
||||
});
|
||||
}
|
||||
let inTry;
|
||||
if(fn && fn.type === "FunctionExpression") {
|
||||
if(fn && isUnboundFunctionExpression(fn)) {
|
||||
inTry = parser.scope.inTry;
|
||||
parser.inScope(fnParams, () => {
|
||||
parser.scope.renames = fnRenames;
|
||||
|
||||
+4
-4
@@ -44,8 +44,8 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate {
|
||||
|
||||
source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1, startBlock);
|
||||
source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = ");
|
||||
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (");
|
||||
source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
||||
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; ((");
|
||||
source.insert(depBlock.functionRange[1], ").apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
||||
source.replace(depBlock.functionRange[1], depBlock.errorCallbackRange[0] - 1, errorRangeBlock);
|
||||
source.replace(depBlock.errorCallbackRange[1], depBlock.outerRange[1] - 1, endBlock);
|
||||
return;
|
||||
@@ -57,8 +57,8 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate {
|
||||
const endBlock = `}${depBlock.functionBindThis ? ".bind(this)" : ""}${wrapper[1]}__webpack_require__.oe${wrapper[2]}`;
|
||||
source.replace(depBlock.outerRange[0], depBlock.arrayRange[0] - 1, startBlock);
|
||||
source.insert(depBlock.arrayRange[0] + 0.9, "var __WEBPACK_AMD_REQUIRE_ARRAY__ = ");
|
||||
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; (");
|
||||
source.insert(depBlock.functionRange[1], ".apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
||||
source.replace(depBlock.arrayRange[1], depBlock.functionRange[0] - 1, "; ((");
|
||||
source.insert(depBlock.functionRange[1], ").apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));");
|
||||
source.replace(depBlock.functionRange[1], depBlock.outerRange[1] - 1, endBlock);
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+2
-2
@@ -9,7 +9,7 @@ const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency
|
||||
module.exports = class HarmonyDetectionParserPlugin {
|
||||
apply(parser) {
|
||||
parser.plugin("program", (ast) => {
|
||||
var isHarmony = ast.body.some(statement => {
|
||||
const isHarmony = ast.body.some(statement => {
|
||||
return /^(Import|Export).*Declaration$/.test(statement.type);
|
||||
});
|
||||
if(isHarmony) {
|
||||
@@ -32,7 +32,7 @@ module.exports = class HarmonyDetectionParserPlugin {
|
||||
module.exportsArgument = "__webpack_exports__";
|
||||
}
|
||||
});
|
||||
var nonHarmonyIdentifiers = ["define", "exports"];
|
||||
const nonHarmonyIdentifiers = ["define", "exports"];
|
||||
nonHarmonyIdentifiers.forEach(identifer => {
|
||||
parser.plugin(`evaluate typeof ${identifer}`, nullInHarmony);
|
||||
parser.plugin(`typeof ${identifer}`, skipInHarmony);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
var ModuleDependency = require("./ModuleDependency");
|
||||
const ModuleDependency = require("./ModuleDependency");
|
||||
|
||||
class HarmonyImportDependency extends ModuleDependency {
|
||||
constructor(request, importedVar, range) {
|
||||
|
||||
+4
-4
@@ -14,8 +14,8 @@ const lookup = (parent, mod) => {
|
||||
segs = mod.split("/");
|
||||
path.pop();
|
||||
|
||||
for(var i = 0; i < segs.length; i++) {
|
||||
var seg = segs[i];
|
||||
for(let i = 0; i < segs.length; i++) {
|
||||
const seg = segs[i];
|
||||
if(seg === "..") path.pop();
|
||||
else if(seg !== ".") path.push(seg);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ const lookup = (parent, mod) => {
|
||||
|
||||
LocalModulesHelpers.addLocalModule = (state, name) => {
|
||||
if(!state.localModules) state.localModules = [];
|
||||
var m = new LocalModule(state.module, name, state.localModules.length);
|
||||
const m = new LocalModule(state.module, name, state.localModules.length);
|
||||
state.localModules.push(m);
|
||||
return m;
|
||||
};
|
||||
@@ -36,7 +36,7 @@ LocalModulesHelpers.getLocalModule = (state, name, namedModule) => {
|
||||
// resolve dependency name relative to the defining named module
|
||||
name = lookup(namedModule, name);
|
||||
}
|
||||
for(var i = 0; i < state.localModules.length; i++) {
|
||||
for(let i = 0; i < state.localModules.length; i++) {
|
||||
if(state.localModules[i].name === name)
|
||||
return state.localModules[i];
|
||||
}
|
||||
|
||||
+8
@@ -11,6 +11,14 @@ class RequireIncludeDependency extends ModuleDependency {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
getReference() {
|
||||
if(!this.module) return null;
|
||||
return {
|
||||
module: this.module,
|
||||
importedNames: [] // This doesn't use any export
|
||||
};
|
||||
}
|
||||
|
||||
get type() {
|
||||
return "require.include";
|
||||
}
|
||||
|
||||
+3
-1
@@ -6,9 +6,11 @@
|
||||
|
||||
const ExternalsPlugin = require("../ExternalsPlugin");
|
||||
|
||||
const builtins = require("module").builtinModules || Object.keys(process.binding("natives"));
|
||||
|
||||
class NodeTargetPlugin {
|
||||
apply(compiler) {
|
||||
new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
|
||||
new ExternalsPlugin("commonjs", builtins).apply(compiler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-6
@@ -7,6 +7,7 @@
|
||||
const Module = require("../Module");
|
||||
const Template = require("../Template");
|
||||
const Parser = require("../Parser");
|
||||
const crypto = require("crypto");
|
||||
const acorn = require("acorn");
|
||||
const escope = require("escope");
|
||||
const ReplaceSource = require("webpack-sources/lib/ReplaceSource");
|
||||
@@ -142,6 +143,7 @@ function getPathInAst(ast, node) {
|
||||
}
|
||||
|
||||
function enterNode(n) {
|
||||
if(!n) return undefined;
|
||||
const r = n.range;
|
||||
if(r) {
|
||||
if(r[0] <= nr[0] && r[1] >= nr[1]) {
|
||||
@@ -210,6 +212,7 @@ class ConcatenatedModule extends Module {
|
||||
Object.assign(this.assets, m.assets);
|
||||
}
|
||||
}
|
||||
this._identifier = this._createIdentifier();
|
||||
}
|
||||
|
||||
get modules() {
|
||||
@@ -219,12 +222,7 @@ class ConcatenatedModule extends Module {
|
||||
}
|
||||
|
||||
identifier() {
|
||||
return this._orderedConcatenationList.map(info => {
|
||||
switch(info.type) {
|
||||
case "concatenated":
|
||||
return info.module.identifier();
|
||||
}
|
||||
}).filter(Boolean).join(" ");
|
||||
return this._identifier;
|
||||
}
|
||||
|
||||
readableIdentifier(requestShortener) {
|
||||
@@ -297,6 +295,19 @@ class ConcatenatedModule extends Module {
|
||||
return list;
|
||||
}
|
||||
|
||||
_createIdentifier() {
|
||||
let orderedConcatenationListIdentifiers = "";
|
||||
for(let i = 0; i < this._orderedConcatenationList.length; i++) {
|
||||
if(this._orderedConcatenationList[i].type === "concatenated") {
|
||||
orderedConcatenationListIdentifiers += this._orderedConcatenationList[i].module.identifier();
|
||||
orderedConcatenationListIdentifiers += " ";
|
||||
}
|
||||
}
|
||||
const hash = crypto.createHash("md5");
|
||||
hash.update(orderedConcatenationListIdentifiers);
|
||||
return this.rootModule.identifier() + " " + hash.digest("hex");
|
||||
}
|
||||
|
||||
source(dependencyTemplates, outputOptions, requestShortener) {
|
||||
// Metainfo for each module
|
||||
const modulesWithInfo = this._orderedConcatenationList.map((info, idx) => {
|
||||
|
||||
+2
-2
@@ -82,8 +82,8 @@ class WebWorkerMainTemplatePlugin {
|
||||
});
|
||||
|
||||
return source + "\n" +
|
||||
`var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];\n` +
|
||||
`this[${JSON.stringify(hotUpdateFunction)}] = ` +
|
||||
`var parentHotUpdateCallback = self[${JSON.stringify(hotUpdateFunction)}];\n` +
|
||||
`self[${JSON.stringify(hotUpdateFunction)}] = ` +
|
||||
Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js"))
|
||||
.replace(/\/\/\$semicolon/g, ";")
|
||||
.replace(/\$require\$/g, this.requireFn)
|
||||
|
||||
+1
-3
@@ -21,9 +21,7 @@
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack"
|
||||
],
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz",
|
||||
"_spec": "2.1.1",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
|
||||
+1
-3
@@ -21,9 +21,7 @@
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "5.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack"
|
||||
],
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/ajv/-/ajv-5.3.0.tgz",
|
||||
"_spec": "5.3.0",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
|
||||
+54
-17
@@ -1,27 +1,64 @@
|
||||
'use strict';
|
||||
module.exports = function () {
|
||||
var str = [].map.call(arguments, function (str) {
|
||||
return str.trim();
|
||||
}).filter(function (str) {
|
||||
return str.length;
|
||||
}).join('-');
|
||||
|
||||
if (!str.length) {
|
||||
function preserveCamelCase(str) {
|
||||
let isLastCharLower = false;
|
||||
let isLastCharUpper = false;
|
||||
let isLastLastCharUpper = false;
|
||||
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const c = str[i];
|
||||
|
||||
if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
|
||||
str = str.substr(0, i) + '-' + str.substr(i);
|
||||
isLastCharLower = false;
|
||||
isLastLastCharUpper = isLastCharUpper;
|
||||
isLastCharUpper = true;
|
||||
i++;
|
||||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
|
||||
str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
|
||||
isLastLastCharUpper = isLastCharUpper;
|
||||
isLastCharUpper = false;
|
||||
isLastCharLower = true;
|
||||
} else {
|
||||
isLastCharLower = c.toLowerCase() === c;
|
||||
isLastLastCharUpper = isLastCharUpper;
|
||||
isLastCharUpper = c.toUpperCase() === c;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
module.exports = function (str) {
|
||||
if (arguments.length > 1) {
|
||||
str = Array.from(arguments)
|
||||
.map(x => x.trim())
|
||||
.filter(x => x.length)
|
||||
.join('-');
|
||||
} else {
|
||||
str = str.trim();
|
||||
}
|
||||
|
||||
if (str.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (str.length === 1 || !(/[_.\- ]+/).test(str) ) {
|
||||
if (str[0] === str[0].toLowerCase() && str.slice(1) !== str.slice(1).toLowerCase()) {
|
||||
return str;
|
||||
}
|
||||
|
||||
if (str.length === 1) {
|
||||
return str.toLowerCase();
|
||||
}
|
||||
|
||||
if (/^[a-z0-9]+$/.test(str)) {
|
||||
return str;
|
||||
}
|
||||
|
||||
const hasUpperCase = str !== str.toLowerCase();
|
||||
|
||||
if (hasUpperCase) {
|
||||
str = preserveCamelCase(str);
|
||||
}
|
||||
|
||||
return str
|
||||
.replace(/^[_.\- ]+/, '')
|
||||
.toLowerCase()
|
||||
.replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
|
||||
return p1.toUpperCase();
|
||||
});
|
||||
.replace(/^[_.\- ]+/, '')
|
||||
.toLowerCase()
|
||||
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
|
||||
};
|
||||
|
||||
+19
-17
@@ -1,46 +1,45 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"camelcase@1.2.1",
|
||||
"camelcase@4.1.0",
|
||||
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
|
||||
]
|
||||
],
|
||||
"_from": "camelcase@1.2.1",
|
||||
"_id": "camelcase@1.2.1",
|
||||
"_from": "camelcase@4.1.0",
|
||||
"_id": "camelcase@4.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=",
|
||||
"_integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
|
||||
"_location": "/webpack/camelcase",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "camelcase@1.2.1",
|
||||
"raw": "camelcase@4.1.0",
|
||||
"name": "camelcase",
|
||||
"escapedName": "camelcase",
|
||||
"rawSpec": "1.2.1",
|
||||
"rawSpec": "4.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.2.1"
|
||||
"fetchSpec": "4.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/uglify-js/yargs"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz",
|
||||
"_spec": "1.2.1",
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
|
||||
"_spec": "4.1.0",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "http://sindresorhus.com"
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/camelcase/issues"
|
||||
},
|
||||
"description": "Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar",
|
||||
"devDependencies": {
|
||||
"ava": "0.0.4"
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
@@ -67,7 +66,10 @@
|
||||
"url": "git+https://github.com/sindresorhus/camelcase.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "1.2.1"
|
||||
"version": "4.1.0",
|
||||
"xo": {
|
||||
"esnext": true
|
||||
}
|
||||
}
|
||||
|
||||
+15
-14
@@ -5,7 +5,7 @@
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
```
|
||||
$ npm install --save camelcase
|
||||
```
|
||||
|
||||
@@ -13,44 +13,45 @@ $ npm install --save camelcase
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var camelCase = require('camelcase');
|
||||
const camelCase = require('camelcase');
|
||||
|
||||
camelCase('foo-bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo_bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('Foo-Bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('--foo.bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('__foo__bar__');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
console.log(process.argv[3]);
|
||||
//=> --foo-bar
|
||||
//=> '--foo-bar'
|
||||
camelCase(process.argv[3]);
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo', 'bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('__foo__', '--bar');
|
||||
//=> fooBar
|
||||
//=> 'fooBar'
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
See [`decamelize`](https://github.com/sindresorhus/decamelize) for the inverse.
|
||||
- [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
|
||||
- [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
|
||||
+1
-3
@@ -21,9 +21,7 @@
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.1.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui"
|
||||
],
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz",
|
||||
"_spec": "0.1.3",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
repo_token: NiRhyj91Z2vtgob6XdEAqs83rzNnbMZUu
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
after_script: "NODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha --require patched-blanket --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js"
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
<a name="3.2.0"></a>
|
||||
# [3.2.0](https://github.com/yargs/cliui/compare/v3.1.2...v3.2.0) (2016-04-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* reduces tarball size ([acc6c33](https://github.com/yargs/cliui/commit/acc6c33))
|
||||
|
||||
### Features
|
||||
|
||||
* adds standard-version for release management ([ff84e32](https://github.com/yargs/cliui/commit/ff84e32))
|
||||
+13
-7
@@ -1,8 +1,9 @@
|
||||
# cliui
|
||||
|
||||
[](https://travis-ci.org/bcoe/cliui)
|
||||
[](https://coveralls.io/r/bcoe/cliui?branch=)
|
||||
[](https://travis-ci.org/yargs/cliui)
|
||||
[](https://coveralls.io/r/yargs/cliui?branch=)
|
||||
[](https://www.npmjs.com/package/cliui)
|
||||
[](https://github.com/conventional-changelog/standard-version)
|
||||
|
||||
easily create complex multi-column command-line-interfaces.
|
||||
|
||||
@@ -23,15 +24,17 @@ ui.div({
|
||||
ui.div(
|
||||
{
|
||||
text: "-f, --file",
|
||||
width: 40,
|
||||
width: 20,
|
||||
padding: [0, 4, 0, 4]
|
||||
},
|
||||
{
|
||||
text: "the file to load",
|
||||
width: 25
|
||||
text: "the file to load." +
|
||||
chalk.green("(if this description is long it wraps).")
|
||||
,
|
||||
width: 20
|
||||
},
|
||||
{
|
||||
text: "[required]",
|
||||
text: chalk.red("[required]"),
|
||||
align: 'right'
|
||||
}
|
||||
)
|
||||
@@ -39,6 +42,8 @@ ui.div(
|
||||
console.log(ui.toString())
|
||||
```
|
||||
|
||||
<img width="500" src="screenshot.png">
|
||||
|
||||
## Layout DSL
|
||||
|
||||
cliui exposes a simple layout DSL:
|
||||
@@ -48,7 +53,7 @@ object:
|
||||
|
||||
* `\n`: characters will be interpreted as new rows.
|
||||
* `\t`: characters will be interpreted as new columns.
|
||||
* ` `: characters will be interpreted as padding.
|
||||
* `\s`: characters will be interpreted as padding.
|
||||
|
||||
**as an example...**
|
||||
|
||||
@@ -97,6 +102,7 @@ options:
|
||||
* **width:** the width of a column.
|
||||
* **align:** alignment, `right` or `center`.
|
||||
* **padding:** `[top, right, bottom, left]`.
|
||||
* **border:** should a border be placed around the div?
|
||||
|
||||
### cliui.span(column, column, column)
|
||||
|
||||
|
||||
+107
-64
@@ -1,12 +1,14 @@
|
||||
var wrap = require('wordwrap'),
|
||||
align = {
|
||||
right: require('right-align'),
|
||||
center: require('center-align')
|
||||
},
|
||||
top = 0,
|
||||
right = 1,
|
||||
bottom = 2,
|
||||
left = 3
|
||||
var stringWidth = require('string-width')
|
||||
var stripAnsi = require('strip-ansi')
|
||||
var wrap = require('wrap-ansi')
|
||||
var align = {
|
||||
right: alignRight,
|
||||
center: alignCenter
|
||||
}
|
||||
var top = 0
|
||||
var right = 1
|
||||
var bottom = 2
|
||||
var left = 3
|
||||
|
||||
function UI (opts) {
|
||||
this.width = opts.width
|
||||
@@ -42,9 +44,9 @@ UI.prototype._shouldApplyLayoutDSL = function () {
|
||||
}
|
||||
|
||||
UI.prototype._applyLayoutDSL = function (str) {
|
||||
var _this = this,
|
||||
rows = str.split('\n'),
|
||||
leftColumnWidth = 0
|
||||
var _this = this
|
||||
var rows = str.split('\n')
|
||||
var leftColumnWidth = 0
|
||||
|
||||
// simple heuristic for layout, make sure the
|
||||
// second column lines up along the left-hand.
|
||||
@@ -52,10 +54,10 @@ UI.prototype._applyLayoutDSL = function (str) {
|
||||
// than 50% of the screen.
|
||||
rows.forEach(function (row) {
|
||||
var columns = row.split('\t')
|
||||
if (columns.length > 1 && columns[0].length > leftColumnWidth) {
|
||||
if (columns.length > 1 && stringWidth(columns[0]) > leftColumnWidth) {
|
||||
leftColumnWidth = Math.min(
|
||||
Math.floor(_this.width * 0.5),
|
||||
columns[0].length
|
||||
stringWidth(columns[0])
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -68,7 +70,7 @@ UI.prototype._applyLayoutDSL = function (str) {
|
||||
_this.div.apply(_this, columns.map(function (r, i) {
|
||||
return {
|
||||
text: r.trim(),
|
||||
padding: [0, r.match(/\s*$/)[0].length, 0, r.match(/^\s*/)[0].length],
|
||||
padding: _this._measurePadding(r),
|
||||
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
|
||||
}
|
||||
}))
|
||||
@@ -79,13 +81,20 @@ UI.prototype._applyLayoutDSL = function (str) {
|
||||
|
||||
UI.prototype._colFromString = function (str) {
|
||||
return {
|
||||
text: str
|
||||
text: str,
|
||||
padding: this._measurePadding(str)
|
||||
}
|
||||
}
|
||||
|
||||
UI.prototype._measurePadding = function (str) {
|
||||
// measure padding without ansi escape codes
|
||||
var noAnsi = stripAnsi(str)
|
||||
return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length]
|
||||
}
|
||||
|
||||
UI.prototype.toString = function () {
|
||||
var _this = this,
|
||||
lines = []
|
||||
var _this = this
|
||||
var lines = []
|
||||
|
||||
_this.rows.forEach(function (row, i) {
|
||||
_this.rowToString(row, lines)
|
||||
@@ -103,13 +112,13 @@ UI.prototype.toString = function () {
|
||||
}
|
||||
|
||||
UI.prototype.rowToString = function (row, lines) {
|
||||
var _this = this,
|
||||
paddingLeft,
|
||||
rrows = this._rasterize(row),
|
||||
str = '',
|
||||
ts,
|
||||
width,
|
||||
wrapWidth
|
||||
var _this = this
|
||||
var padding
|
||||
var rrows = this._rasterize(row)
|
||||
var str = ''
|
||||
var ts
|
||||
var width
|
||||
var wrapWidth
|
||||
|
||||
rrows.forEach(function (rrow, r) {
|
||||
str = ''
|
||||
@@ -118,27 +127,30 @@ UI.prototype.rowToString = function (row, lines) {
|
||||
width = row[c].width // the width with padding.
|
||||
wrapWidth = _this._negatePadding(row[c]) // the width without padding.
|
||||
|
||||
for (var i = 0; i < Math.max(wrapWidth, col.length); i++) {
|
||||
ts += col.charAt(i) || ' '
|
||||
ts += col
|
||||
|
||||
for (var i = 0; i < wrapWidth - stringWidth(col); i++) {
|
||||
ts += ' '
|
||||
}
|
||||
|
||||
// align the string within its column.
|
||||
if (row[c].align && row[c].align !== 'left' && _this.wrap) {
|
||||
ts = align[row[c].align](ts.trim() + '\n' + new Array(wrapWidth + 1).join(' '))
|
||||
.split('\n')[0]
|
||||
if (ts.length < wrapWidth) ts += new Array(width - ts.length).join(' ')
|
||||
ts = align[row[c].align](ts, wrapWidth)
|
||||
if (stringWidth(ts) < wrapWidth) ts += new Array(width - stringWidth(ts)).join(' ')
|
||||
}
|
||||
|
||||
// add left/right padding and print string.
|
||||
paddingLeft = (row[c].padding || [0, 0, 0, 0])[left]
|
||||
if (paddingLeft) str += new Array(row[c].padding[left] + 1).join(' ')
|
||||
// apply border and padding to string.
|
||||
padding = row[c].padding || [0, 0, 0, 0]
|
||||
if (padding[left]) str += new Array(padding[left] + 1).join(' ')
|
||||
str += addBorder(row[c], ts, '| ')
|
||||
str += ts
|
||||
if (row[c].padding && row[c].padding[right]) str += new Array(row[c].padding[right] + 1).join(' ')
|
||||
str += addBorder(row[c], ts, ' |')
|
||||
if (padding[right]) str += new Array(padding[right] + 1).join(' ')
|
||||
|
||||
// if prior row is span, try to render the
|
||||
// current row on the prior line.
|
||||
if (r === 0 && lines.length > 0) {
|
||||
str = _this._renderInline(str, lines[lines.length - 1], paddingLeft)
|
||||
str = _this._renderInline(str, lines[lines.length - 1])
|
||||
}
|
||||
})
|
||||
|
||||
@@ -152,11 +164,21 @@ UI.prototype.rowToString = function (row, lines) {
|
||||
return lines
|
||||
}
|
||||
|
||||
function addBorder (col, ts, style) {
|
||||
if (col.border) {
|
||||
if (/[.']-+[.']/.test(ts)) return ''
|
||||
else if (ts.trim().length) return style
|
||||
else return ' '
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
// if the full 'source' can render in
|
||||
// the target line, do so.
|
||||
UI.prototype._renderInline = function (source, previousLine, paddingLeft) {
|
||||
var target = previousLine.text,
|
||||
str = ''
|
||||
UI.prototype._renderInline = function (source, previousLine) {
|
||||
var leadingWhitespace = source.match(/^ */)[0].length
|
||||
var target = previousLine.text
|
||||
var targetTextWidth = stringWidth(target.trimRight())
|
||||
|
||||
if (!previousLine.span) return source
|
||||
|
||||
@@ -167,39 +189,34 @@ UI.prototype._renderInline = function (source, previousLine, paddingLeft) {
|
||||
return target + source
|
||||
}
|
||||
|
||||
for (var i = 0, tc, sc; i < Math.max(source.length, target.length); i++) {
|
||||
tc = target.charAt(i) || ' '
|
||||
sc = source.charAt(i) || ' '
|
||||
// we tried to overwrite a character in the other string.
|
||||
if (tc !== ' ' && sc !== ' ') return source
|
||||
// there is not enough whitespace to maintain padding.
|
||||
if (sc !== ' ' && i < paddingLeft + target.length) return source
|
||||
// :thumbsup:
|
||||
if (tc === ' ') str += sc
|
||||
else str += tc
|
||||
}
|
||||
if (leadingWhitespace < targetTextWidth) return source
|
||||
|
||||
previousLine.hidden = true
|
||||
|
||||
return str
|
||||
return target.trimRight() + new Array(leadingWhitespace - targetTextWidth + 1).join(' ') + source.trimLeft()
|
||||
}
|
||||
|
||||
UI.prototype._rasterize = function (row) {
|
||||
var _this = this,
|
||||
i,
|
||||
rrow,
|
||||
rrows = [],
|
||||
widths = this._columnWidths(row),
|
||||
wrapped
|
||||
var _this = this
|
||||
var i
|
||||
var rrow
|
||||
var rrows = []
|
||||
var widths = this._columnWidths(row)
|
||||
var wrapped
|
||||
|
||||
// word wrap all columns, and create
|
||||
// a data-structure that is easy to rasterize.
|
||||
row.forEach(function (col, c) {
|
||||
// leave room for left and right padding.
|
||||
col.width = widths[c]
|
||||
if (_this.wrap) wrapped = wrap.hard(_this._negatePadding(col))(col.text).split('\n')
|
||||
if (_this.wrap) wrapped = wrap(col.text, _this._negatePadding(col), {hard: true}).split('\n')
|
||||
else wrapped = col.text.split('\n')
|
||||
|
||||
if (col.border) {
|
||||
wrapped.unshift('.' + new Array(_this._negatePadding(col) + 3).join('-') + '.')
|
||||
wrapped.push("'" + new Array(_this._negatePadding(col) + 3).join('-') + "'")
|
||||
}
|
||||
|
||||
// add top and bottom padding.
|
||||
if (col.padding) {
|
||||
for (i = 0; i < (col.padding[top] || 0); i++) wrapped.unshift('')
|
||||
@@ -224,15 +241,16 @@ UI.prototype._rasterize = function (row) {
|
||||
UI.prototype._negatePadding = function (col) {
|
||||
var wrapWidth = col.width
|
||||
if (col.padding) wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0)
|
||||
if (col.border) wrapWidth -= 4
|
||||
return wrapWidth
|
||||
}
|
||||
|
||||
UI.prototype._columnWidths = function (row) {
|
||||
var _this = this,
|
||||
widths = [],
|
||||
unset = row.length,
|
||||
unsetWidth,
|
||||
remainingWidth = this.width
|
||||
var _this = this
|
||||
var widths = []
|
||||
var unset = row.length
|
||||
var unsetWidth
|
||||
var remainingWidth = this.width
|
||||
|
||||
// column widths can be set in config.
|
||||
row.forEach(function (col, i) {
|
||||
@@ -248,7 +266,7 @@ UI.prototype._columnWidths = function (row) {
|
||||
// any unset widths should be calculated.
|
||||
if (unset) unsetWidth = Math.floor(remainingWidth / unset)
|
||||
widths.forEach(function (w, i) {
|
||||
if (!_this.wrap) widths[i] = row[i].width || row[i].text.length
|
||||
if (!_this.wrap) widths[i] = row[i].width || stringWidth(row[i].text)
|
||||
else if (w === undefined) widths[i] = Math.max(unsetWidth, _minWidth(row[i]))
|
||||
})
|
||||
|
||||
@@ -259,8 +277,33 @@ UI.prototype._columnWidths = function (row) {
|
||||
// a column, based on padding preferences.
|
||||
function _minWidth (col) {
|
||||
var padding = col.padding || []
|
||||
var minWidth = 1 + (padding[left] || 0) + (padding[right] || 0)
|
||||
if (col.border) minWidth += 4
|
||||
return minWidth
|
||||
}
|
||||
|
||||
return 1 + (padding[left] || 0) + (padding[right] || 0)
|
||||
function alignRight (str, width) {
|
||||
str = str.trim()
|
||||
var padding = ''
|
||||
var strWidth = stringWidth(str)
|
||||
|
||||
if (strWidth < width) {
|
||||
padding = new Array(width - strWidth + 1).join(' ')
|
||||
}
|
||||
|
||||
return padding + str
|
||||
}
|
||||
|
||||
function alignCenter (str, width) {
|
||||
str = str.trim()
|
||||
var padding = ''
|
||||
var strWidth = stringWidth(str.trim())
|
||||
|
||||
if (strWidth < width) {
|
||||
padding = new Array(parseInt((width - strWidth) / 2, 10) + 1).join(' ')
|
||||
}
|
||||
|
||||
return padding + str
|
||||
}
|
||||
|
||||
module.exports = function (opts) {
|
||||
|
||||
Generated
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
var stripAnsi = require('strip-ansi');
|
||||
var codePointAt = require('code-point-at');
|
||||
var isFullwidthCodePoint = require('is-fullwidth-code-point');
|
||||
|
||||
// https://github.com/nodejs/io.js/blob/cff7300a578be1b10001f2d967aaedc88aee6402/lib/readline.js#L1345
|
||||
module.exports = function (str) {
|
||||
if (typeof str !== 'string' || str.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var width = 0;
|
||||
|
||||
str = stripAnsi(str);
|
||||
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var code = codePointAt(str, i);
|
||||
|
||||
// ignore control characters
|
||||
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// surrogates
|
||||
if (code >= 0x10000) {
|
||||
i++;
|
||||
}
|
||||
|
||||
if (isFullwidthCodePoint(code)) {
|
||||
width += 2;
|
||||
} else {
|
||||
width++;
|
||||
}
|
||||
}
|
||||
|
||||
return width;
|
||||
};
|
||||
Generated
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Generated
Vendored
+91
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"string-width@1.0.2",
|
||||
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
|
||||
]
|
||||
],
|
||||
"_from": "string-width@1.0.2",
|
||||
"_id": "string-width@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
|
||||
"_location": "/webpack/cliui/string-width",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "string-width@1.0.2",
|
||||
"name": "string-width",
|
||||
"escapedName": "string-width",
|
||||
"rawSpec": "1.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
||||
"_spec": "1.0.2",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/string-width/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
"strip-ansi": "^3.0.0"
|
||||
},
|
||||
"description": "Get the visual width of a string - the number of columns required to display it",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/string-width#readme",
|
||||
"keywords": [
|
||||
"string",
|
||||
"str",
|
||||
"character",
|
||||
"char",
|
||||
"unicode",
|
||||
"width",
|
||||
"visual",
|
||||
"column",
|
||||
"columns",
|
||||
"fullwidth",
|
||||
"full-width",
|
||||
"full",
|
||||
"ansi",
|
||||
"escape",
|
||||
"codes",
|
||||
"cli",
|
||||
"command-line",
|
||||
"terminal",
|
||||
"console",
|
||||
"cjk",
|
||||
"chinese",
|
||||
"japanese",
|
||||
"korean",
|
||||
"fixed-width"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "string-width",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/string-width.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
# string-width [](https://travis-ci.org/sindresorhus/string-width)
|
||||
|
||||
> Get the visual width of a string - the number of columns required to display it
|
||||
|
||||
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
|
||||
|
||||
Useful to be able to measure the actual width of command-line output.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save string-width
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const stringWidth = require('string-width');
|
||||
|
||||
stringWidth('古');
|
||||
//=> 2
|
||||
|
||||
stringWidth('\u001b[1m古\u001b[22m');
|
||||
//=> 2
|
||||
|
||||
stringWidth('a');
|
||||
//=> 1
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
|
||||
- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
|
||||
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
+36
-29
@@ -1,38 +1,40 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"cliui@2.1.0",
|
||||
"cliui@3.2.0",
|
||||
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
|
||||
]
|
||||
],
|
||||
"_from": "cliui@2.1.0",
|
||||
"_id": "cliui@2.1.0",
|
||||
"_from": "cliui@3.2.0",
|
||||
"_id": "cliui@3.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=",
|
||||
"_integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=",
|
||||
"_location": "/webpack/cliui",
|
||||
"_phantomChildren": {},
|
||||
"_phantomChildren": {
|
||||
"code-point-at": "1.1.0",
|
||||
"is-fullwidth-code-point": "1.0.0",
|
||||
"strip-ansi": "3.0.1"
|
||||
},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "cliui@2.1.0",
|
||||
"raw": "cliui@3.2.0",
|
||||
"name": "cliui",
|
||||
"escapedName": "cliui",
|
||||
"rawSpec": "2.1.0",
|
||||
"rawSpec": "3.2.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.0"
|
||||
"fetchSpec": "3.2.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/uglify-js/yargs"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz",
|
||||
"_spec": "2.1.0",
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
|
||||
"_spec": "3.2.0",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
"author": {
|
||||
"name": "Ben Coe",
|
||||
"email": "ben@npmjs.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bcoe/cliui/issues"
|
||||
"url": "https://github.com/yargs/cliui/issues"
|
||||
},
|
||||
"config": {
|
||||
"blanket": {
|
||||
@@ -47,22 +49,24 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"center-align": "^0.1.1",
|
||||
"right-align": "^0.1.1",
|
||||
"wordwrap": "0.0.2"
|
||||
"string-width": "^1.0.1",
|
||||
"strip-ansi": "^3.0.1",
|
||||
"wrap-ansi": "^2.0.0"
|
||||
},
|
||||
"description": "easily create complex multi-column command-line-interfaces",
|
||||
"devDependencies": {
|
||||
"blanket": "^1.1.6",
|
||||
"chai": "^2.2.0",
|
||||
"coveralls": "^2.11.2",
|
||||
"mocha": "^2.2.4",
|
||||
"mocha-lcov-reporter": "0.0.2",
|
||||
"mocoverage": "^1.0.0",
|
||||
"patched-blanket": "^1.0.1",
|
||||
"standard": "^3.6.1"
|
||||
"chai": "^3.5.0",
|
||||
"chalk": "^1.1.2",
|
||||
"coveralls": "^2.11.8",
|
||||
"mocha": "^2.4.5",
|
||||
"nyc": "^6.4.0",
|
||||
"standard": "^6.0.8",
|
||||
"standard-version": "^2.1.2"
|
||||
},
|
||||
"homepage": "https://github.com/bcoe/cliui#readme",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/yargs/cliui#readme",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"command-line",
|
||||
@@ -77,10 +81,13 @@
|
||||
"name": "cliui",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/bcoe/cliui.git"
|
||||
"url": "git+ssh://git@github.com/yargs/cliui.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && mocha --check-leaks --ui exports --require patched-blanket -R mocoverage"
|
||||
"coverage": "nyc --reporter=text-lcov mocha | coveralls",
|
||||
"pretest": "standard",
|
||||
"test": "nyc mocha",
|
||||
"version": "standard-version"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
@@ -90,5 +97,5 @@
|
||||
"it"
|
||||
]
|
||||
},
|
||||
"version": "2.1.0"
|
||||
"version": "3.2.0"
|
||||
}
|
||||
|
||||
-349
@@ -1,349 +0,0 @@
|
||||
/* global describe, it */
|
||||
|
||||
require('chai').should()
|
||||
|
||||
var cliui = require('../')
|
||||
|
||||
describe('cliui', function () {
|
||||
describe('div', function () {
|
||||
it("wraps text at 'width' if a single column is given", function () {
|
||||
var ui = cliui({
|
||||
width: 10
|
||||
})
|
||||
|
||||
ui.div('i am a string that should be wrapped')
|
||||
|
||||
ui.toString().split('\n').forEach(function (row) {
|
||||
row.length.should.be.lte(10)
|
||||
})
|
||||
})
|
||||
|
||||
it('evenly divides text across columns if multiple columns are given', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.div(
|
||||
{text: 'i am a string that should be wrapped', width: 15},
|
||||
'i am a second string that should be wrapped',
|
||||
'i am a third string that should be wrapped'
|
||||
)
|
||||
|
||||
// total width of all columns is <=
|
||||
// the width cliui is initialized with.
|
||||
ui.toString().split('\n').forEach(function (row) {
|
||||
row.length.should.be.lte(40)
|
||||
})
|
||||
|
||||
// it should wrap each column appropriately.
|
||||
var expected = [
|
||||
'i am a string i am a i am a third',
|
||||
'that should be second string that',
|
||||
'wrapped string that should be',
|
||||
' should be wrapped',
|
||||
' wrapped'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('allows for a blank row to be appended', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.div()
|
||||
|
||||
// it should wrap each column appropriately.
|
||||
var expected = ['']
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_columnWidths', function () {
|
||||
it('uses same width for each column by default', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
}),
|
||||
widths = ui._columnWidths([{}, {}, {}])
|
||||
|
||||
widths[0].should.equal(13)
|
||||
widths[1].should.equal(13)
|
||||
widths[2].should.equal(13)
|
||||
})
|
||||
|
||||
it('divides width over remaining columns if first column has width specified', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
}),
|
||||
widths = ui._columnWidths([{width: 20}, {}, {}])
|
||||
|
||||
widths[0].should.equal(20)
|
||||
widths[1].should.equal(10)
|
||||
widths[2].should.equal(10)
|
||||
})
|
||||
|
||||
it('divides width over remaining columns if middle column has width specified', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
}),
|
||||
widths = ui._columnWidths([{}, {width: 10}, {}])
|
||||
|
||||
widths[0].should.equal(15)
|
||||
widths[1].should.equal(10)
|
||||
widths[2].should.equal(15)
|
||||
})
|
||||
|
||||
it('keeps track of remaining width if multiple columns have width specified', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
}),
|
||||
widths = ui._columnWidths([{width: 20}, {width: 12}, {}])
|
||||
|
||||
widths[0].should.equal(20)
|
||||
widths[1].should.equal(12)
|
||||
widths[2].should.equal(8)
|
||||
})
|
||||
|
||||
it('uses a sane default if impossible widths are specified', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
}),
|
||||
widths = ui._columnWidths([{width: 30}, {width: 30}, {padding: [0, 2, 0, 1]}])
|
||||
|
||||
widths[0].should.equal(30)
|
||||
widths[1].should.equal(30)
|
||||
widths[2].should.equal(4)
|
||||
})
|
||||
})
|
||||
|
||||
describe('alignment', function () {
|
||||
it('allows a column to be right aligned', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.div(
|
||||
'i am a string',
|
||||
{text: 'i am a second string', align: 'right'},
|
||||
'i am a third string that should be wrapped'
|
||||
)
|
||||
|
||||
// it should right-align the second column.
|
||||
var expected = [
|
||||
'i am a stringi am a secondi am a third',
|
||||
' stringstring that',
|
||||
' should be',
|
||||
' wrapped'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('allows a column to be center aligned', function () {
|
||||
var ui = cliui({
|
||||
width: 60
|
||||
})
|
||||
|
||||
ui.div(
|
||||
'i am a string',
|
||||
{text: 'i am a second string', align: 'center', padding: [0, 2, 0, 2]},
|
||||
'i am a third string that should be wrapped'
|
||||
)
|
||||
|
||||
// it should right-align the second column.
|
||||
var expected = [
|
||||
'i am a string i am a second i am a third string',
|
||||
' string that should be',
|
||||
' wrapped'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('padding', function () {
|
||||
it('handles left/right padding', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.div(
|
||||
{text: 'i have padding on my left', padding: [0, 0, 0, 4]},
|
||||
{text: 'i have padding on my right', padding: [0, 2, 0, 0], align: 'center'},
|
||||
{text: 'i have no padding', padding: [0, 0, 0, 0]}
|
||||
)
|
||||
|
||||
// it should add left/right padding to columns.
|
||||
var expected = [
|
||||
' i have i have i have no',
|
||||
' padding padding on padding',
|
||||
' on my my right',
|
||||
' left'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('handles top/bottom padding', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.div(
|
||||
'i am a string',
|
||||
{text: 'i am a second string', padding: [2, 0, 0, 0]},
|
||||
{text: 'i am a third string that should be wrapped', padding: [0, 0, 1, 0]}
|
||||
)
|
||||
|
||||
// it should add top/bottom padding to second
|
||||
// and third columns.
|
||||
var expected = [
|
||||
'i am a string i am a third',
|
||||
' string that',
|
||||
' i am a secondshould be',
|
||||
' string wrapped',
|
||||
''
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('wrap', function () {
|
||||
it('allows wordwrap to be disabled', function () {
|
||||
var ui = cliui({
|
||||
wrap: false
|
||||
})
|
||||
|
||||
ui.div(
|
||||
{text: 'i am a string', padding: [0, 1, 0, 0]},
|
||||
{text: 'i am a second string', padding: [0, 2, 0, 0]},
|
||||
{text: 'i am a third string that should not be wrapped', padding: [0, 0, 0, 2]}
|
||||
)
|
||||
|
||||
ui.toString().should.equal('i am a string i am a second string i am a third string that should not be wrapped')
|
||||
})
|
||||
})
|
||||
|
||||
describe('span', function () {
|
||||
it('appends the next row to the end of the prior row if it fits', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.span(
|
||||
{text: 'i am a string that will be wrapped', width: 30}
|
||||
)
|
||||
|
||||
ui.div(
|
||||
{text: ' [required] [default: 99]', align: 'right'}
|
||||
)
|
||||
|
||||
var expected = [
|
||||
'i am a string that will be',
|
||||
'wrapped [required] [default: 99]'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('does not append the string if it does not fit on the prior row', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.span(
|
||||
{text: 'i am a string that will be wrapped', width: 30}
|
||||
)
|
||||
|
||||
ui.div(
|
||||
{text: 'i am a second row', align: 'left'}
|
||||
)
|
||||
|
||||
var expected = [
|
||||
'i am a string that will be',
|
||||
'wrapped',
|
||||
'i am a second row'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('always appends text to prior span if wrap is disabled', function () {
|
||||
var ui = cliui({
|
||||
wrap: false,
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.span(
|
||||
{text: 'i am a string that will be wrapped', width: 30}
|
||||
)
|
||||
|
||||
ui.div(
|
||||
{text: 'i am a second row', align: 'left', padding: [0, 0, 0, 3]}
|
||||
)
|
||||
|
||||
ui.div('a third line')
|
||||
|
||||
var expected = [
|
||||
'i am a string that will be wrapped i am a second row',
|
||||
'a third line'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('layoutDSL', function () {
|
||||
it('turns tab into multiple columns', function () {
|
||||
var ui = cliui({
|
||||
width: 60
|
||||
})
|
||||
|
||||
ui.div(
|
||||
' <regex> \tmy awesome regex\n <my second thing> \tanother row\t a third column'
|
||||
)
|
||||
|
||||
var expected = [
|
||||
' <regex> my awesome regex',
|
||||
' <my second thing> another row a third column'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('turns newline into multiple rows', function () {
|
||||
var ui = cliui({
|
||||
width: 40
|
||||
})
|
||||
|
||||
ui.div(
|
||||
'Usage: $0\n <regex>\t my awesome regex\n <glob>\t my awesome glob\t [required]'
|
||||
)
|
||||
var expected = [
|
||||
'Usage: $0',
|
||||
' <regex> my awesome regex',
|
||||
' <glob> my awesome [required]',
|
||||
' glob'
|
||||
]
|
||||
|
||||
ui.toString().split('\n').should.eql(expected)
|
||||
})
|
||||
|
||||
it('does not apply DSL if wrap is false', function () {
|
||||
var ui = cliui({
|
||||
width: 40,
|
||||
wrap: false
|
||||
})
|
||||
|
||||
ui.div(
|
||||
'Usage: $0\ttwo\tthree'
|
||||
)
|
||||
|
||||
ui.toString().should.eql('Usage: $0\ttwo\tthree')
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
+1
@@ -22,6 +22,7 @@
|
||||
"fetchSpec": "1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui/string-width",
|
||||
"/webpack/wrap-ansi/string-width",
|
||||
"/webpack/yargs/cliui/string-width"
|
||||
],
|
||||
|
||||
Generated
Vendored
+1
@@ -22,6 +22,7 @@
|
||||
"fetchSpec": "1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui/string-width",
|
||||
"/webpack/wrap-ansi/string-width",
|
||||
"/webpack/yargs/cliui/string-width"
|
||||
],
|
||||
|
||||
+1
-3
@@ -21,9 +21,7 @@
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.1.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui"
|
||||
],
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz",
|
||||
"_spec": "0.1.3",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
|
||||
+2
@@ -22,6 +22,8 @@
|
||||
"fetchSpec": "3.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui",
|
||||
"/webpack/cliui/string-width",
|
||||
"/webpack/wrap-ansi",
|
||||
"/webpack/wrap-ansi/string-width",
|
||||
"/webpack/yargs/cliui",
|
||||
|
||||
-2
@@ -11,8 +11,6 @@
|
||||
"_integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=",
|
||||
"_location": "/webpack/uglify-js",
|
||||
"_phantomChildren": {
|
||||
"camelcase": "1.2.1",
|
||||
"cliui": "2.1.0",
|
||||
"decamelize": "1.2.0",
|
||||
"window-size": "0.1.0"
|
||||
},
|
||||
|
||||
+1
-3
@@ -21,9 +21,7 @@
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui"
|
||||
],
|
||||
"_requiredBy": [],
|
||||
"_resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz",
|
||||
"_spec": "0.0.2",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
|
||||
+1
@@ -26,6 +26,7 @@
|
||||
"fetchSpec": "2.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/webpack/cliui",
|
||||
"/webpack/yargs/cliui"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
|
||||
|
||||
+34
-25
@@ -1,31 +1,31 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"webpack@3.8.1",
|
||||
"webpack@3.11.0",
|
||||
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
|
||||
]
|
||||
],
|
||||
"_from": "webpack@3.8.1",
|
||||
"_id": "webpack@3.8.1",
|
||||
"_from": "webpack@3.11.0",
|
||||
"_id": "webpack@3.11.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-5ZXLWWsMqHKFr5y0N3Eo5IIisxeEeRAajNq4mELb/WELOR7srdbQk2N5XiyNy2A/AgvlR3AmeBCZJW8lHrolbw==",
|
||||
"_integrity": "sha512-3kOFejWqj5ISpJk4Qj/V7w98h9Vl52wak3CLiw/cDOfbVTq7FeoZ0SdoHHY9PYlHr50ZS42OfvzE2vB4nncKQg==",
|
||||
"_location": "/webpack",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "webpack@3.8.1",
|
||||
"raw": "webpack@3.11.0",
|
||||
"name": "webpack",
|
||||
"escapedName": "webpack",
|
||||
"rawSpec": "3.8.1",
|
||||
"rawSpec": "3.11.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.8.1"
|
||||
"fetchSpec": "3.11.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/webpack/-/webpack-3.8.1.tgz",
|
||||
"_spec": "3.8.1",
|
||||
"_resolved": "https://registry.npmjs.org/webpack/-/webpack-3.11.0.tgz",
|
||||
"_spec": "3.11.0",
|
||||
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
|
||||
"author": {
|
||||
"name": "Tobias Koppers @sokra"
|
||||
@@ -39,8 +39,8 @@
|
||||
"dependencies": {
|
||||
"acorn": "^5.0.0",
|
||||
"acorn-dynamic-import": "^2.0.0",
|
||||
"ajv": "^5.1.5",
|
||||
"ajv-keywords": "^2.0.0",
|
||||
"ajv": "^6.1.0",
|
||||
"ajv-keywords": "^3.1.0",
|
||||
"async": "^2.1.2",
|
||||
"enhanced-resolve": "^3.4.0",
|
||||
"escope": "^3.6.0",
|
||||
@@ -66,7 +66,6 @@
|
||||
"benchmark": "^2.1.1",
|
||||
"bundle-loader": "~0.5.0",
|
||||
"codacy-coverage": "^2.0.1",
|
||||
"codecov.io": "^0.1.2",
|
||||
"coffee-loader": "~0.7.1",
|
||||
"coffee-script": "^1.10.0",
|
||||
"coveralls": "^2.11.2",
|
||||
@@ -77,6 +76,7 @@
|
||||
"express": "~4.13.1",
|
||||
"extract-text-webpack-plugin": "^3.0.0",
|
||||
"file-loader": "^0.11.2",
|
||||
"glob": "^7.1.2",
|
||||
"i18n-webpack-plugin": "^1.0.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"jade": "^1.11.0",
|
||||
@@ -87,10 +87,10 @@
|
||||
"lodash": "^4.17.4",
|
||||
"mocha": "^3.2.0",
|
||||
"mocha-lcov-reporter": "^1.0.0",
|
||||
"nsp": "^2.6.1",
|
||||
"raw-loader": "~0.5.0",
|
||||
"react": "^15.2.1",
|
||||
"react-dom": "^15.2.1",
|
||||
"rimraf": "^2.6.2",
|
||||
"script-loader": "~0.7.0",
|
||||
"should": "^11.1.1",
|
||||
"simple-git": "^1.65.0",
|
||||
@@ -123,25 +123,34 @@
|
||||
},
|
||||
"scripts": {
|
||||
"appveyor:benchmark": "npm run benchmark",
|
||||
"appveyor:test": "node node_modules\\mocha\\bin\\mocha --max-old-space-size=4096 --harmony test/*.test.js",
|
||||
"appveyor:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
|
||||
"appveyor:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
|
||||
"beautify-lint": "beautify-lint \"lib/**/*.js\" \"hot/**/*.js\" \"bin/**/*.js\" \"benchmark/*.js\" \"test/*.js\"",
|
||||
"benchmark": "mocha --max-old-space-size=4096 --harmony test/*.benchmark.js -R spec",
|
||||
"benchmark": "mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.benchmark.js -R spec",
|
||||
"build:examples": "cd examples && node buildAll.js",
|
||||
"circleci:lint": "npm run lint-files && npm run nsp",
|
||||
"circleci:test": "node node_modules/mocha/bin/mocha --max-old-space-size=4096 --harmony test/*.test.js",
|
||||
"cover": "node --max-old-space-size=4096 --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
|
||||
"cover:min": "node --max-old-space-size=4096 --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
|
||||
"circleci:lint": "npm run lint-files",
|
||||
"circleci:test": "node node_modules/mocha/bin/mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.test.js test/*.unittest.js",
|
||||
"cover": "npm run cover:init && npm run cover:all && npm run cover:report",
|
||||
"cover:all": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.test.js test/*.unittest.js",
|
||||
"cover:init": "rimraf coverage",
|
||||
"cover:integration": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.test.js",
|
||||
"cover:report": "istanbul report",
|
||||
"cover:report-min": "istanbul report --report lcovonly",
|
||||
"cover:unit": "node --max-old-space-size=4096 --harmony --trace-deprecation ./node_modules/istanbul/lib/cli.js cover --report none node_modules/mocha/bin/_mocha -- test/*.unittest.js",
|
||||
"fix": "npm run lint -- --fix",
|
||||
"lint": "eslint lib bin hot buildin \"test/**/webpack.config.js\" \"test/binCases/**/test.js\" \"examples/**/webpack.config.js\"",
|
||||
"lint-files": "npm run lint && npm run beautify-lint",
|
||||
"nsp": "nsp check --output summary",
|
||||
"lint-files": "npm run lint && npm run beautify-lint && npm run schema-lint",
|
||||
"pretest": "npm run lint-files",
|
||||
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish",
|
||||
"test": "mocha test/*.test.js --max-old-space-size=4096 --harmony --check-leaks",
|
||||
"schema-lint": "mocha test/*.lint.js --opts test/lint-mocha.opts",
|
||||
"test": "mocha test/*.test.js test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
|
||||
"test:integration": "mocha test/*.test.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
|
||||
"test:unit": "mocha test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
|
||||
"travis:benchmark": "npm run benchmark",
|
||||
"travis:lint": "npm run lint-files && npm run nsp",
|
||||
"travis:test": "npm run cover:min"
|
||||
"travis:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
|
||||
"travis:lint": "npm run lint-files",
|
||||
"travis:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min"
|
||||
},
|
||||
"version": "3.8.1",
|
||||
"version": "3.11.0",
|
||||
"web": "lib/webpack.web.js"
|
||||
}
|
||||
|
||||
+405
-76
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user