Skip to content

Commit

Permalink
Merge pull request #6864 from webpack/bump_prettier
Browse files Browse the repository at this point in the history
Update prettier toolchain
  • Loading branch information
sokra committed Mar 29, 2018
2 parents 0f70fcb + 8d8da4c commit 2bd495c
Show file tree
Hide file tree
Showing 39 changed files with 202 additions and 254 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
@@ -1,7 +1,7 @@
module.exports = {
root: true,
plugins: ["prettier", "node"],
extends: ["eslint:recommended", "plugin:node/recommended"],
extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"],
env: {
node: true,
es6: true
Expand All @@ -16,6 +16,7 @@ module.exports = {
"semi": "error",
"no-template-curly-in-string": "error",
"no-caller": "error",
"no-control-regex": "off",
"yoda": "error",
"eqeqeq": "error",
"global-require": "off",
Expand Down
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

5 changes: 5 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,5 @@
module.exports = {
printWidth: 80,
useTabs: true,
tabWidth: 2
};
4 changes: 1 addition & 3 deletions bin/webpack.js
Expand Up @@ -43,9 +43,7 @@ if (!webpackCliInstalled) {

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

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

console.error("The CLI moved into a separate package: webpack-cli");
const questionInterface = readLine.createInterface({
Expand Down
4 changes: 2 additions & 2 deletions lib/APIPlugin.js
Expand Up @@ -52,11 +52,11 @@ class APIPlugin {
? ParserHelpers.toConstantDependency(
parser,
REPLACEMENTS[key]
)
)
: ParserHelpers.toConstantDependencyWithWebpackRequire(
parser,
REPLACEMENTS[key]
)
)
);
parser.hooks.evaluateTypeof
.for(key)
Expand Down
10 changes: 4 additions & 6 deletions lib/AmdMainTemplatePlugin.js
Expand Up @@ -36,17 +36,15 @@ class AmdMainTemplatePlugin {
});

return new ConcatSource(
`define(${JSON.stringify(name)}, ${externalsDepsArray}, function(${
externalsArguments
}) { return `,
`define(${JSON.stringify(
name
)}, ${externalsDepsArray}, function(${externalsArguments}) { return `,
source,
"});"
);
} else if (externalsArguments) {
return new ConcatSource(
`define(${externalsDepsArray}, function(${
externalsArguments
}) { return `,
`define(${externalsDepsArray}, function(${externalsArguments}) { return `,
source,
"});"
);
Expand Down
4 changes: 1 addition & 3 deletions lib/AsyncDependencyToInitialChunkError.js
Expand Up @@ -11,9 +11,7 @@ module.exports = class AsyncDependencyToInitialChunkError extends WebpackError {
super();

this.name = "AsyncDependencyToInitialChunkError";
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${
chunkName
}" is already used by an entrypoint.`;
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`;
this.module = module;
this.origin = module;
this.originLoc = loc;
Expand Down
4 changes: 2 additions & 2 deletions lib/Compilation.js
Expand Up @@ -628,12 +628,12 @@ class Compilation extends Tapable {
const errorAndCallback = this.bail
? err => {
callback(err);
}
}
: err => {
err.dependencies = [dependency];
this.errors.push(err);
callback();
};
};

if (
typeof dependency !== "object" ||
Expand Down
12 changes: 6 additions & 6 deletions lib/ContextModule.js
Expand Up @@ -293,9 +293,11 @@ class ContextModule extends Module {
getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
if (typeof fakeMap === "number")
return `return ${this.getReturn(fakeMap)};`;
return `return ${fakeMapDataExpression} === 1 ? ${this.getReturn(1)} : ${
fakeMapDataExpression
} ? ${this.getReturn(2)} : ${this.getReturn(0)};`;
return `return ${fakeMapDataExpression} === 1 ? ${this.getReturn(
1
)} : ${fakeMapDataExpression} ? ${this.getReturn(2)} : ${this.getReturn(
0
)};`;
}

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

const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1;
const requestPrefix = hasMultipleOrNoChunks
? `Promise.all(ids.slice(${
chunksStartPosition
}).map(__webpack_require__.e))`
? `Promise.all(ids.slice(${chunksStartPosition}).map(__webpack_require__.e))`
: `__webpack_require__.e(ids[${chunksStartPosition}])`;
const returnModuleObject = this.getReturnModuleObjectSource(
fakeMap,
Expand Down
4 changes: 2 additions & 2 deletions lib/DefinePlugin.js
Expand Up @@ -112,7 +112,7 @@ class DefinePlugin {
? ParserHelpers.toConstantDependencyWithWebpackRequire(
parser,
code
)
)
: ParserHelpers.toConstantDependency(parser, code)
);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ class DefinePlugin {
? ParserHelpers.toConstantDependencyWithWebpackRequire(
parser,
code
)
)
: ParserHelpers.toConstantDependency(parser, code)
);
parser.hooks.typeof
Expand Down
4 changes: 1 addition & 3 deletions lib/EnvironmentPlugin.js
Expand Up @@ -42,9 +42,7 @@ class EnvironmentPlugin {
if (value === undefined) {
compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
const error = new Error(
`EnvironmentPlugin - ${
key
} environment variable is undefined.\n\n` +
`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
"You can pass an object with default values to suppress this warning.\n" +
"See https://webpack.js.org/plugins/environment-plugin for example."
);
Expand Down
6 changes: 3 additions & 3 deletions lib/ExternalModule.js
Expand Up @@ -76,9 +76,9 @@ class ExternalModule extends Module {
}

checkExternalVariable(variableToCheck, request) {
return `if(typeof ${
variableToCheck
} === 'undefined') {${WebpackMissingModule.moduleCode(request)}}\n`;
return `if(typeof ${variableToCheck} === 'undefined') {${WebpackMissingModule.moduleCode(
request
)}}\n`;
}

getSourceForAmdOrUmdExternal(id, optional, request) {
Expand Down
4 changes: 2 additions & 2 deletions lib/MainTemplate.js
Expand Up @@ -179,15 +179,15 @@ module.exports = class MainTemplate extends Tapable {
"if(threw) delete installedModules[moduleId];"
]),
"}"
]
]
: [
"// Execute the module function",
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
hash,
chunk,
"moduleId"
)});`
]
]
),
"",
"// Flag the module as loaded",
Expand Down
2 changes: 1 addition & 1 deletion lib/ModuleFilenameHelpers.js
Expand Up @@ -63,7 +63,7 @@ ModuleFilenameHelpers.createFilename = (module, options, requestShortener) => {
? options
: {
moduleFilenameTemplate: options
}
}
);

let absoluteResourcePath;
Expand Down
2 changes: 1 addition & 1 deletion lib/NormalModuleFactory.js
Expand Up @@ -412,7 +412,7 @@ class NormalModuleFactory extends Tapable {
const optionsOnly = item.options
? {
options: item.options
}
}
: undefined;
return callback(
null,
Expand Down
4 changes: 2 additions & 2 deletions lib/RecordIdsPlugin.js
Expand Up @@ -26,7 +26,7 @@ class RecordIdsPlugin {
compiler.context,
module.identifier(),
compilation.cache
)
)
: module.identifier();
records.modules.byIdentifier[identifier] = module.id;
records.modules.usedIds[module.id] = module.id;
Expand All @@ -46,7 +46,7 @@ class RecordIdsPlugin {
compiler.context,
module.identifier(),
compilation.cache
)
)
: module.identifier();
const id = records.modules.byIdentifier[identifier];
if (id === undefined) continue;
Expand Down
60 changes: 15 additions & 45 deletions lib/RuntimeTemplate.js
Expand Up @@ -86,15 +86,11 @@ module.exports = class RuntimeTemplate {
if (exportsType === "namespace") {
return rawModule;
} else if (exportsType === "named") {
return `Object.assign({/* fake namespace object */}, ${
rawModule
}, { "default": ${rawModule} })`;
return `Object.assign({/* fake namespace object */}, ${rawModule}, { "default": ${rawModule} })`;
} else if (strict) {
return `Object({ /* fake namespace object */ "default": ${rawModule} })`;
} else {
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 }); }())`;
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 }); }())`;
}
}

Expand All @@ -120,11 +116,7 @@ module.exports = class RuntimeTemplate {
header += `var id = ${idExpr}; `;
idExpr = "id";
}
header += `if(!__webpack_require__.m[${
idExpr
}]) { var e = new Error("Module '" + ${
idExpr
} + "' is not available (weak dependency)"); e.code = 'MODULE_NOT_FOUND'; throw e; } `;
header += `if(!__webpack_require__.m[${idExpr}]) { var e = new Error("Module '" + ${idExpr} + "' is not available (weak dependency)"); e.code = 'MODULE_NOT_FOUND'; throw e; } `;
}
const rawModule = this.moduleRaw({
module,
Expand All @@ -135,22 +127,14 @@ module.exports = class RuntimeTemplate {
if (header) {
getModuleFunction = `function() { ${header}return ${rawModule}; }`;
} else {
getModuleFunction = `__webpack_require__.bind(null, ${comment}${
idExpr
})`;
getModuleFunction = `__webpack_require__.bind(null, ${comment}${idExpr})`;
}
} else if (exportsType === "named") {
getModuleFunction = `function() { ${header}var module = ${
rawModule
}; return Object.assign({/* fake namespace object */}, module, { "default": module }); }`;
getModuleFunction = `function() { ${header}var module = ${rawModule}; return Object.assign({/* fake namespace object */}, module, { "default": module }); }`;
} else if (strict) {
getModuleFunction = `function() { ${
header
}return { /* fake namespace object */ "default": ${rawModule} }; }`;
getModuleFunction = `function() { ${header}return { /* fake namespace object */ "default": ${rawModule} }; }`;
} else {
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 }); }`;
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 }); }`;
}

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

const exportsType = module.buildMeta && module.buildMeta.exportsType;
let content = `/* harmony import */ ${optDeclaration}${
importVar
} = __webpack_require__(${comment}${JSON.stringify(module.id)});\n`;
let content = `/* harmony import */ ${optDeclaration}${importVar} = __webpack_require__(${comment}${JSON.stringify(
module.id
)});\n`;

if (!exportsType && !originModule.buildMeta.strictHarmonyModule) {
content += `/* harmony import */ ${optDeclaration}${
importVar
}_default = /*#__PURE__*/__webpack_require__.n(${importVar});\n`;
content += `/* harmony import */ ${optDeclaration}${importVar}_default = /*#__PURE__*/__webpack_require__.n(${importVar});\n`;
}
if (exportsType === "named") {
if (Array.isArray(module.buildMeta.providedExports))
content += `${optDeclaration}${
importVar
}_namespace = /*#__PURE__*/Object.assign({}, ${
importVar
}, {"default": ${importVar}});\n`;
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/Object.assign({}, ${importVar}, {"default": ${importVar}});\n`;
else
content += `${optDeclaration}${
importVar
}_namespace = /*#__PURE__*/{ /* fake namespace object */ "default": ${
importVar
} };\n`;
content += `${optDeclaration}${importVar}_namespace = /*#__PURE__*/{ /* fake namespace object */ "default": ${importVar} };\n`;
}
return content;
}
Expand Down Expand Up @@ -223,13 +197,9 @@ module.exports = class RuntimeTemplate {
return "/* non-default import from non-esm module */undefined";
} else if (!exportName) {
if (asiSafe) {
return `/*#__PURE__*/{ /* fake namespace object */ "default": ${
importVar
} }`;
return `/*#__PURE__*/{ /* fake namespace object */ "default": ${importVar} }`;
} else {
return `/*#__PURE__*/Object({ /* fake namespace object */ "default": ${
importVar
} })`;
return `/*#__PURE__*/Object({ /* fake namespace object */ "default": ${importVar} })`;
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/TemplatedPathPlugin.js
Expand Up @@ -81,9 +81,7 @@ const replacePathVariables = (path, data) => {
REGEXP_CONTENTHASH_FOR_TEST.test(path))
) {
throw new Error(
`Cannot use [chunkhash] or [contenthash] for chunk in '${
path
}' (use [hash] instead)`
`Cannot use [chunkhash] or [contenthash] for chunk in '${path}' (use [hash] instead)`
);
}

Expand Down

0 comments on commit 2bd495c

Please sign in to comment.