Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
fix(index): typo buildMobule => buildModule (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Feb 24, 2018
1 parent 4c7f80a commit 259adad
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions src/index.js
@@ -1,8 +1,6 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
/* eslint-disable
no-param-reassign
*/

import crypto from 'crypto';
import { SourceMapConsumer } from 'source-map';
import { SourceMapSource, RawSource, ConcatSource } from 'webpack-sources';
Expand All @@ -14,10 +12,6 @@ import schema from './options.json';
import Uglify from './uglify';
import versions from './uglify/versions';

/* eslint-disable
no-param-reassign
*/

const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/;

class UglifyJsPlugin {
Expand Down Expand Up @@ -95,7 +89,7 @@ class UglifyJsPlugin {
apply(compiler) {
const requestShortener = new RequestShortener(compiler.context);

const buildMobuleFn = (moduleArg) => {
const buildModuleFn = (moduleArg) => {
// to get detailed location info about errors
moduleArg.useSourceMap = true;
};
Expand All @@ -105,8 +99,10 @@ class UglifyJsPlugin {
cache: this.options.cache,
parallel: this.options.parallel,
});

const uglifiedAssets = new WeakSet();
const tasks = [];

chunks.reduce((acc, chunk) => acc.concat(chunk.files || []), [])
.concat(compilation.additionalChunkAssets || [])
.filter(ModuleFilenameHelpers.matchObject.bind(null, this.options))
Expand Down Expand Up @@ -164,7 +160,14 @@ class UglifyJsPlugin {

tasks.push(task);
} catch (error) {
compilation.errors.push(UglifyJsPlugin.buildError(error, file, sourceMap, requestShortener));
compilation.errors.push(
UglifyJsPlugin.buildError(
error,
file,
sourceMap,
requestShortener,
),
);
}
});

Expand All @@ -181,13 +184,25 @@ class UglifyJsPlugin {
// Handling results
// Error case: add errors, and go to next file
if (error) {
compilation.errors.push(UglifyJsPlugin.buildError(error, file, sourceMap, requestShortener));
compilation.errors.push(
UglifyJsPlugin.buildError(
error,
file,
sourceMap,
requestShortener,
),
);

return;
}

let outputSource;
if (map) {
outputSource = new SourceMapSource(code, file, JSON.parse(map), input, inputSourceMap);
outputSource = new SourceMapSource(
code,
file,
JSON.parse(map), input, inputSourceMap,
);
} else {
outputSource = new RawSource(code);
}
Expand All @@ -197,9 +212,11 @@ class UglifyJsPlugin {
// Add a banner to the original file
if (this.options.extractComments.banner !== false) {
let banner = this.options.extractComments.banner || `For license information please see ${commentsFile}`;

if (typeof banner === 'function') {
banner = banner(commentsFile);
}

if (banner) {
outputSource = new ConcatSource(
`/*! ${banner} */\n`, outputSource,
Expand All @@ -208,6 +225,7 @@ class UglifyJsPlugin {
}

const commentsSource = new RawSource(`${extractedComments.join('\n\n')}\n`);

if (commentsFile in compilation.assets) {
// commentsFile already exists, append new comments...
if (compilation.assets[commentsFile] instanceof ConcatSource) {
Expand All @@ -228,14 +246,24 @@ class UglifyJsPlugin {

// Handling warnings
if (warnings) {
const warnArr = UglifyJsPlugin.buildWarnings(warnings, file, sourceMap, this.options.warningsFilter, requestShortener);
const warnArr = UglifyJsPlugin.buildWarnings(
warnings,
file,
sourceMap,
this.options.warningsFilter,
requestShortener,
);

if (warnArr.length > 0) {
compilation.warnings.push(new Error(`${file} from UglifyJs\n${warnArr.join('\n')}`));
compilation.warnings.push(
new Error(`${file} from UglifyJs\n${warnArr.join('\n')}`),
);
}
}
});

uglify.exit();

callback();
});
};
Expand All @@ -245,15 +273,15 @@ class UglifyJsPlugin {

compiler.hooks.compilation.tap(plugin, (compilation) => {
if (this.options.sourceMap) {
compilation.hooks.buildMobule.tap(plugin, buildMobuleFn);
compilation.hooks.buildModule.tap(plugin, buildModuleFn);
}

compilation.hooks.optimizeChunkAssets.tapAsync(plugin, optimizeFn.bind(this, compilation));
});
} else {
compiler.plugin('compilation', (compilation) => {
if (this.options.sourceMap) {
compilation.plugin('build-module', buildMobuleFn);
compilation.plugin('build-module', buildModuleFn);
}

compilation.plugin('optimize-chunk-assets', optimizeFn.bind(this, compilation));
Expand Down

0 comments on commit 259adad

Please sign in to comment.