Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

Commit c1c63c2

Browse files
committedFeb 21, 2017
Fix lint of plugin code
1 parent a811e05 commit c1c63c2

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed
 

‎.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/fixtures
22
test/expected
3+
createInlineWorker.js

‎index.js

+40-38
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
var WebWorkerTemplatePlugin = require("webpack/lib/webworker/WebWorkerTemplatePlugin");
2-
var SingleEntryPlugin = require("webpack/lib/SingleEntryPlugin");
3-
var path = require("path");
1+
const path = require('path');
2+
const WebWorkerTemplatePlugin = require('webpack/lib/webworker/WebWorkerTemplatePlugin');
3+
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
4+
const loaderUtils = require('loader-utils');
45

5-
var loaderUtils = require("loader-utils");
6-
module.exports = function() {};
7-
module.exports.pitch = function(request) {
8-
if(!this.webpack) throw new Error("Only usable with webpack");
6+
module.exports = function workerLoader() {};
7+
8+
module.exports.pitch = function pitch(request) {
9+
if (!this.webpack) throw new Error('Only usable with webpack');
910
this.cacheable(false);
10-
var callback = this.async();
11-
var query = loaderUtils.parseQuery(this.query);
12-
var filename = loaderUtils.interpolateName(this, query.name || "[hash].worker.js", {
11+
const callback = this.async();
12+
const query = loaderUtils.parseQuery(this.query);
13+
const filename = loaderUtils.interpolateName(this, query.name || '[hash].worker.js', {
1314
context: query.context || this.options.context,
14-
regExp: query.regExp
15+
regExp: query.regExp,
1516
});
16-
var outputOptions = {
17-
filename: filename,
18-
chunkFilename: "[id]." + filename,
19-
namedChunkFilename: null
17+
const outputOptions = {
18+
filename,
19+
chunkFilename: `[id].${filename}`,
20+
namedChunkFilename: null,
2021
};
21-
if(this.options && this.options.worker && this.options.worker.output) {
22-
for(var name in this.options.worker.output) {
22+
if (this.options && this.options.worker && this.options.worker.output) {
23+
Object.keys(this.options.worker.output).forEach((name) => {
2324
outputOptions[name] = this.options.worker.output[name];
24-
}
25+
});
2526
}
26-
var workerCompiler = this._compilation.createChildCompiler("worker", outputOptions);
27+
const workerCompiler = this._compilation.createChildCompiler('worker', outputOptions);
2728
workerCompiler.apply(new WebWorkerTemplatePlugin(outputOptions));
28-
workerCompiler.apply(new SingleEntryPlugin(this.context, "!!" + request, "main"));
29-
if(this.options && this.options.worker && this.options.worker.plugins) {
30-
this.options.worker.plugins.forEach(function(plugin) {
31-
workerCompiler.apply(plugin);
32-
});
29+
workerCompiler.apply(new SingleEntryPlugin(this.context, `!!${request}`, 'main'));
30+
if (this.options && this.options.worker && this.options.worker.plugins) {
31+
this.options.worker.plugins.forEach(plugin => workerCompiler.apply(plugin));
3332
}
34-
var subCache = "subcache " + __dirname + " " + request;
35-
workerCompiler.plugin("compilation", function(compilation) {
36-
if(compilation.cache) {
37-
if(!compilation.cache[subCache])
33+
const subCache = `subcache ${__dirname} ${request}`;
34+
workerCompiler.plugin('compilation', (compilation) => {
35+
if (compilation.cache) {
36+
if (!compilation.cache[subCache]) {
3837
compilation.cache[subCache] = {};
38+
}
3939
compilation.cache = compilation.cache[subCache];
4040
}
4141
});
42-
workerCompiler.runAsChild(function(err, entries, compilation) {
43-
if(err) return callback(err);
42+
workerCompiler.runAsChild((err, entries, compilation) => {
43+
if (err) return callback(err);
4444
if (entries[0]) {
45-
var workerFile = entries[0].files[0];
46-
var constructor = "new Worker(__webpack_public_path__ + " + JSON.stringify(workerFile) + ")";
47-
if(query.inline) {
48-
constructor = "require(" + JSON.stringify("!!" + path.join(__dirname, "createInlineWorker.js")) + ")(" +
49-
JSON.stringify(compilation.assets[workerFile].source()) + ", __webpack_public_path__ + " + JSON.stringify(workerFile) + ")";
45+
const [workerFile] = entries[0].files;
46+
let constructor = `new Worker(__webpack_public_path__ + ${JSON.stringify(workerFile)})`;
47+
if (query.inline) {
48+
constructor = `require(${JSON.stringify(`!!${path.join(__dirname, 'createInlineWorker.js')}`)})(${
49+
JSON.stringify(compilation.assets[workerFile].source())
50+
}, __webpack_public_path__ + ${
51+
JSON.stringify(workerFile)
52+
})`;
5053
}
51-
return callback(null, "module.exports = function() {\n\treturn " + constructor + ";\n};");
52-
} else {
53-
return callback(null, null);
54+
return callback(null, `module.exports = function() {\n\treturn ${constructor};\n};`);
5455
}
56+
return callback(null, null);
5557
});
5658
};

‎package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"exports": "always-multiline",
2121
"functions": "never"
2222
}
23-
]
23+
],
24+
"no-underscore-dangle": 0,
25+
"no-param-reassign": 0
2426
}
2527
},
2628
"peerDependencies": {

0 commit comments

Comments
 (0)
This repository has been archived.