Skip to content

Commit 2bd495c

Browse files
authored
Merge pull request webpack#6864 from webpack/bump_prettier
Update prettier toolchain
2 parents 0f70fcb + 8d8da4c commit 2bd495c

39 files changed

+202
-254
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
plugins: ["prettier", "node"],
4-
extends: ["eslint:recommended", "plugin:node/recommended"],
4+
extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"],
55
env: {
66
node: true,
77
es6: true
@@ -16,6 +16,7 @@ module.exports = {
1616
"semi": "error",
1717
"no-template-curly-in-string": "error",
1818
"no-caller": "error",
19+
"no-control-regex": "off",
1920
"yoda": "error",
2021
"eqeqeq": "error",
2122
"global-require": "off",

.prettierrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.prettierrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
printWidth: 80,
3+
useTabs: true,
4+
tabWidth: 2
5+
};

bin/webpack.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ if (!webpackCliInstalled) {
4343

4444
const commandToBeRun = `${packageManager} ${options.join(" ")}`;
4545

46-
const question = `Would you like to install webpack-cli? (That will run ${
47-
commandToBeRun
48-
}) `;
46+
const question = `Would you like to install webpack-cli? (That will run ${commandToBeRun}) `;
4947

5048
console.error("The CLI moved into a separate package: webpack-cli");
5149
const questionInterface = readLine.createInterface({

lib/APIPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class APIPlugin {
5252
? ParserHelpers.toConstantDependency(
5353
parser,
5454
REPLACEMENTS[key]
55-
)
55+
)
5656
: ParserHelpers.toConstantDependencyWithWebpackRequire(
5757
parser,
5858
REPLACEMENTS[key]
59-
)
59+
)
6060
);
6161
parser.hooks.evaluateTypeof
6262
.for(key)

lib/AmdMainTemplatePlugin.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@ class AmdMainTemplatePlugin {
3636
});
3737

3838
return new ConcatSource(
39-
`define(${JSON.stringify(name)}, ${externalsDepsArray}, function(${
40-
externalsArguments
41-
}) { return `,
39+
`define(${JSON.stringify(
40+
name
41+
)}, ${externalsDepsArray}, function(${externalsArguments}) { return `,
4242
source,
4343
"});"
4444
);
4545
} else if (externalsArguments) {
4646
return new ConcatSource(
47-
`define(${externalsDepsArray}, function(${
48-
externalsArguments
49-
}) { return `,
47+
`define(${externalsDepsArray}, function(${externalsArguments}) { return `,
5048
source,
5149
"});"
5250
);

lib/AsyncDependencyToInitialChunkError.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ module.exports = class AsyncDependencyToInitialChunkError extends WebpackError {
1111
super();
1212

1313
this.name = "AsyncDependencyToInitialChunkError";
14-
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${
15-
chunkName
16-
}" is already used by an entrypoint.`;
14+
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`;
1715
this.module = module;
1816
this.origin = module;
1917
this.originLoc = loc;

lib/Compilation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ class Compilation extends Tapable {
628628
const errorAndCallback = this.bail
629629
? err => {
630630
callback(err);
631-
}
631+
}
632632
: err => {
633633
err.dependencies = [dependency];
634634
this.errors.push(err);
635635
callback();
636-
};
636+
};
637637

638638
if (
639639
typeof dependency !== "object" ||

lib/ContextModule.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,11 @@ class ContextModule extends Module {
293293
getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
294294
if (typeof fakeMap === "number")
295295
return `return ${this.getReturn(fakeMap)};`;
296-
return `return ${fakeMapDataExpression} === 1 ? ${this.getReturn(1)} : ${
297-
fakeMapDataExpression
298-
} ? ${this.getReturn(2)} : ${this.getReturn(0)};`;
296+
return `return ${fakeMapDataExpression} === 1 ? ${this.getReturn(
297+
1
298+
)} : ${fakeMapDataExpression} ? ${this.getReturn(2)} : ${this.getReturn(
299+
0
300+
)};`;
299301
}
300302

301303
getSyncSource(dependencies, id) {
@@ -512,9 +514,7 @@ module.exports = webpackAsyncContext;`;
512514

513515
const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1;
514516
const requestPrefix = hasMultipleOrNoChunks
515-
? `Promise.all(ids.slice(${
516-
chunksStartPosition
517-
}).map(__webpack_require__.e))`
517+
? `Promise.all(ids.slice(${chunksStartPosition}).map(__webpack_require__.e))`
518518
: `__webpack_require__.e(ids[${chunksStartPosition}])`;
519519
const returnModuleObject = this.getReturnModuleObjectSource(
520520
fakeMap,

lib/DefinePlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class DefinePlugin {
112112
? ParserHelpers.toConstantDependencyWithWebpackRequire(
113113
parser,
114114
code
115-
)
115+
)
116116
: ParserHelpers.toConstantDependency(parser, code)
117117
);
118118
}
@@ -164,7 +164,7 @@ class DefinePlugin {
164164
? ParserHelpers.toConstantDependencyWithWebpackRequire(
165165
parser,
166166
code
167-
)
167+
)
168168
: ParserHelpers.toConstantDependency(parser, code)
169169
);
170170
parser.hooks.typeof

lib/EnvironmentPlugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class EnvironmentPlugin {
4242
if (value === undefined) {
4343
compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
4444
const error = new Error(
45-
`EnvironmentPlugin - ${
46-
key
47-
} environment variable is undefined.\n\n` +
45+
`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
4846
"You can pass an object with default values to suppress this warning.\n" +
4947
"See https://webpack.js.org/plugins/environment-plugin for example."
5048
);

lib/ExternalModule.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ class ExternalModule extends Module {
7676
}
7777

7878
checkExternalVariable(variableToCheck, request) {
79-
return `if(typeof ${
80-
variableToCheck
81-
} === 'undefined') {${WebpackMissingModule.moduleCode(request)}}\n`;
79+
return `if(typeof ${variableToCheck} === 'undefined') {${WebpackMissingModule.moduleCode(
80+
request
81+
)}}\n`;
8282
}
8383

8484
getSourceForAmdOrUmdExternal(id, optional, request) {

lib/MainTemplate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ module.exports = class MainTemplate extends Tapable {
179179
"if(threw) delete installedModules[moduleId];"
180180
]),
181181
"}"
182-
]
182+
]
183183
: [
184184
"// Execute the module function",
185185
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
186186
hash,
187187
chunk,
188188
"moduleId"
189189
)});`
190-
]
190+
]
191191
),
192192
"",
193193
"// Flag the module as loaded",

lib/ModuleFilenameHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ModuleFilenameHelpers.createFilename = (module, options, requestShortener) => {
6363
? options
6464
: {
6565
moduleFilenameTemplate: options
66-
}
66+
}
6767
);
6868

6969
let absoluteResourcePath;

lib/NormalModuleFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class NormalModuleFactory extends Tapable {
412412
const optionsOnly = item.options
413413
? {
414414
options: item.options
415-
}
415+
}
416416
: undefined;
417417
return callback(
418418
null,

lib/RecordIdsPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class RecordIdsPlugin {
2626
compiler.context,
2727
module.identifier(),
2828
compilation.cache
29-
)
29+
)
3030
: module.identifier();
3131
records.modules.byIdentifier[identifier] = module.id;
3232
records.modules.usedIds[module.id] = module.id;
@@ -46,7 +46,7 @@ class RecordIdsPlugin {
4646
compiler.context,
4747
module.identifier(),
4848
compilation.cache
49-
)
49+
)
5050
: module.identifier();
5151
const id = records.modules.byIdentifier[identifier];
5252
if (id === undefined) continue;

lib/RuntimeTemplate.js

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@ module.exports = class RuntimeTemplate {
8686
if (exportsType === "namespace") {
8787
return rawModule;
8888
} else if (exportsType === "named") {
89-
return `Object.assign({/* fake namespace object */}, ${
90-
rawModule
91-
}, { "default": ${rawModule} })`;
89+
return `Object.assign({/* fake namespace object */}, ${rawModule}, { "default": ${rawModule} })`;
9290
} else if (strict) {
9391
return `Object({ /* fake namespace object */ "default": ${rawModule} })`;
9492
} else {
95-
return `Object(function() { var module = ${
96-
rawModule
97-
}; return typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }); }())`;
93+
return `Object(function() { var module = ${rawModule}; return typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }); }())`;
9894
}
9995
}
10096

@@ -120,11 +116,7 @@ module.exports = class RuntimeTemplate {
120116
header += `var id = ${idExpr}; `;
121117
idExpr = "id";
122118
}
123-
header += `if(!__webpack_require__.m[${
124-
idExpr
125-
}]) { var e = new Error("Module '" + ${
126-
idExpr
127-
} + "' is not available (weak dependency)"); e.code = 'MODULE_NOT_FOUND'; throw e; } `;
119+
header += `if(!__webpack_require__.m[${idExpr}]) { var e = new Error("Module '" + ${idExpr} + "' is not available (weak dependency)"); e.code = 'MODULE_NOT_FOUND'; throw e; } `;
128120
}
129121
const rawModule = this.moduleRaw({
130122
module,
@@ -135,22 +127,14 @@ module.exports = class RuntimeTemplate {
135127
if (header) {
136128
getModuleFunction = `function() { ${header}return ${rawModule}; }`;
137129
} else {
138-
getModuleFunction = `__webpack_require__.bind(null, ${comment}${
139-
idExpr
140-
})`;
130+
getModuleFunction = `__webpack_require__.bind(null, ${comment}${idExpr})`;
141131
}
142132
} else if (exportsType === "named") {
143-
getModuleFunction = `function() { ${header}var module = ${
144-
rawModule
145-
}; return Object.assign({/* fake namespace object */}, module, { "default": module }); }`;
133+
getModuleFunction = `function() { ${header}var module = ${rawModule}; return Object.assign({/* fake namespace object */}, module, { "default": module }); }`;
146134
} else if (strict) {
147-
getModuleFunction = `function() { ${
148-
header
149-
}return { /* fake namespace object */ "default": ${rawModule} }; }`;
135+
getModuleFunction = `function() { ${header}return { /* fake namespace object */ "default": ${rawModule} }; }`;
150136
} else {
151-
getModuleFunction = `function() { ${header}var module = ${
152-
rawModule
153-
}; return typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }); }`;
137+
getModuleFunction = `function() { ${header}var module = ${rawModule}; return typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }); }`;
154138
}
155139

156140
return `${promise || "Promise.resolve()"}.then(${getModuleFunction})`;
@@ -167,28 +151,18 @@ module.exports = class RuntimeTemplate {
167151
const optDeclaration = update ? "" : "var ";
168152

169153
const exportsType = module.buildMeta && module.buildMeta.exportsType;
170-
let content = `/* harmony import */ ${optDeclaration}${
171-
importVar
172-
} = __webpack_require__(${comment}${JSON.stringify(module.id)});\n`;
154+
let content = `/* harmony import */ ${optDeclaration}${importVar} = __webpack_require__(${comment}${JSON.stringify(
155+
module.id
156+
)});\n`;
173157

174158
if (!exportsType && !originModule.buildMeta.strictHarmonyModule) {
175-
content += `/* harmony import */ ${optDeclaration}${
176-
importVar
177-
}_default = /*#__PURE__*/__webpack_require__.n(${importVar});\n`;
159+
content += `/* harmony import */ ${optDeclaration}${importVar}_default = /*#__PURE__*/__webpack_require__.n(${importVar});\n`;
178160
}
179161
if (exportsType === "named") {
180162
if (Array.isArray(module.buildMeta.providedExports))
181-
content += `${optDeclaration}${
182-
importVar
183-
}_namespace = /*#__PURE__*/Object.assign({}, ${
184-
importVar
185-
}, {"default": ${importVar}});\n`;
163+
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/Object.assign({}, ${importVar}, {"default": ${importVar}});\n`;
186164
else
187-
content += `${optDeclaration}${
188-
importVar
189-
}_namespace = /*#__PURE__*/{ /* fake namespace object */ "default": ${
190-
importVar
191-
} };\n`;
165+
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/{ /* fake namespace object */ "default": ${importVar} };\n`;
192166
}
193167
return content;
194168
}
@@ -223,13 +197,9 @@ module.exports = class RuntimeTemplate {
223197
return "/* non-default import from non-esm module */undefined";
224198
} else if (!exportName) {
225199
if (asiSafe) {
226-
return `/*#__PURE__*/{ /* fake namespace object */ "default": ${
227-
importVar
228-
} }`;
200+
return `/*#__PURE__*/{ /* fake namespace object */ "default": ${importVar} }`;
229201
} else {
230-
return `/*#__PURE__*/Object({ /* fake namespace object */ "default": ${
231-
importVar
232-
} })`;
202+
return `/*#__PURE__*/Object({ /* fake namespace object */ "default": ${importVar} })`;
233203
}
234204
}
235205
}

lib/TemplatedPathPlugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ const replacePathVariables = (path, data) => {
8181
REGEXP_CONTENTHASH_FOR_TEST.test(path))
8282
) {
8383
throw new Error(
84-
`Cannot use [chunkhash] or [contenthash] for chunk in '${
85-
path
86-
}' (use [hash] instead)`
84+
`Cannot use [chunkhash] or [contenthash] for chunk in '${path}' (use [hash] instead)`
8785
);
8886
}
8987

0 commit comments

Comments
 (0)