Upgrade to Prettier 2

This commit is contained in:
Mohsen Azimi 2020-03-28 18:10:15 -04:00
parent e964f0810c
commit 7b07a8db66
70 changed files with 251 additions and 270 deletions

View File

@ -2,6 +2,8 @@ module.exports = {
printWidth: 80,
useTabs: true,
tabWidth: 2,
trailingComma: "none",
arrowParens: "avoid",
overrides: [
{
files: "*.json",

View File

@ -104,7 +104,7 @@ class ContextModule extends Module {
// Info from Factory
this.resolveDependencies = resolveDependencies;
/** @type {ContextModuleOptions} */
this.options = ({
this.options = {
resource: resource,
resourceQuery: resourceQuery,
mode: options.mode,
@ -116,7 +116,7 @@ class ContextModule extends Module {
chunkName: options.chunkName,
groupOptions: options.groupOptions,
namespaceObject: options.namespaceObject
});
};
if (options.resolveOptions !== undefined) {
this.resolveOptions = options.resolveOptions;
}

View File

@ -79,8 +79,7 @@ class EvalSourceMapDevToolPlugin {
} else if (m instanceof ConcatenatedModule) {
const concatModule = /** @type {ConcatenatedModule} */ (m);
if (concatModule.rootModule instanceof NormalModule) {
const module =
/** @type {NormalModule} */ (concatModule.rootModule);
const module = /** @type {NormalModule} */ (concatModule.rootModule);
if (!matchModule(module.resource)) {
return source;
}

View File

@ -703,11 +703,7 @@ class Module extends DependenciesBlock {
const sources = this.codeGeneration(sourceContext).sources;
return sourceContext.type
? sources.get(sourceContext.type)
: sources.get(
this.getSourceTypes()
.values()
.next().value
);
: sources.get(this.getSourceTypes().values().next().value);
}
/**

View File

@ -20,10 +20,7 @@ class ModuleDependencyError extends WebpackError {
super(err.message);
this.name = "ModuleDependencyError";
this.details = err.stack
.split("\n")
.slice(1)
.join("\n");
this.details = err.stack.split("\n").slice(1).join("\n");
this.module = module;
this.loc = loc;
this.error = err;

View File

@ -19,10 +19,7 @@ module.exports = class ModuleDependencyWarning extends WebpackError {
super(err.message);
this.name = "ModuleDependencyWarning";
this.details = err.stack
.split("\n")
.slice(1)
.join("\n");
this.details = err.stack.split("\n").slice(1).join("\n");
this.module = module;
this.loc = loc;
this.error = err;

View File

@ -88,10 +88,7 @@ ModuleFilenameHelpers.createFilename = (
shortIdentifier = module.readableIdentifier(requestShortener);
identifier = requestShortener.shorten(module.identifier());
moduleId = chunkGraph.getModuleId(module);
absoluteResourcePath = module
.identifier()
.split("!")
.pop();
absoluteResourcePath = module.identifier().split("!").pop();
hash = getHash(identifier);
}
const resource = shortIdentifier.split("!").pop();

View File

@ -117,9 +117,7 @@ const getNormalizedWebpackOptions = config => {
entry: nestedConfig(config.entry, entry => {
if (typeof entry === "function") {
return () =>
Promise.resolve()
.then(entry)
.then(getNormalizedEntryStatic);
Promise.resolve().then(entry).then(getNormalizedEntryStatic);
}
return getNormalizedEntryStatic(entry);
}),

View File

@ -152,8 +152,7 @@ class JavascriptGenerator extends Generator {
* @returns {void}
*/
sourceDependency(module, dependency, initFragments, source, generateContext) {
const constructor =
/** @type {new (...args: any[]) => Dependency} */ (dependency.constructor);
const constructor = /** @type {new (...args: any[]) => Dependency} */ (dependency.constructor);
const template = generateContext.dependencyTemplates.get(constructor);
if (!template) {
throw new Error(

View File

@ -907,8 +907,7 @@ class ConcatenatedModule extends Module {
})
.map(connection => ({
connection,
sourceOrder:
/** @type {HarmonyImportDependency} */ (connection.dependency)
sourceOrder: /** @type {HarmonyImportDependency} */ (connection.dependency)
.sourceOrder
}));
references.sort(

View File

@ -234,8 +234,7 @@ class InnerGraphPlugin {
parser.hooks.expression
.for(topLevelSymbolTag)
.tap("InnerGraphPlugin", () => {
const topLevelSymbol =
/** @type {TopLevelSymbol} */ (parser.currentTagData);
const topLevelSymbol = /** @type {TopLevelSymbol} */ (parser.currentTagData);
const currentTopLevelSymbol = InnerGraph.getTopLevelSymbol(
parser.state
);

View File

@ -185,7 +185,8 @@ class ModuleConcatenationPlugin {
);
const importingModuleTypes = new Map(
Array.from(importingModules).map(
m => /** @type {[Module, Set<string>]} */ ([
m =>
/** @type {[Module, Set<string>]} */ ([
m,
new Set(
nonHarmonyConnections

View File

@ -1213,8 +1213,9 @@ module.exports = class SplitChunksPlugin {
minSizeValue > maxSizeValue
) {
const keys = chunkConfig && chunkConfig.keys;
const warningKey = `${keys &&
keys.join()} ${minSizeValue} ${maxSizeValue}`;
const warningKey = `${
keys && keys.join()
} ${minSizeValue} ${maxSizeValue}`;
if (!incorrectMinMaxSizeSet.has(warningKey)) {
incorrectMinMaxSizeSet.add(warningKey);
compilation.warnings.push(

View File

@ -435,8 +435,9 @@ const SIMPLE_EXTRACTORS = {
}
let message = undefined;
if (entry.type === LogType.time) {
message = `${entry.args[0]}: ${entry.args[1] * 1000 +
entry.args[2] / 1000000}ms`;
message = `${entry.args[0]}: ${
entry.args[1] * 1000 + entry.args[2] / 1000000
}ms`;
} else if (entry.args && entry.args.length > 0) {
message = util.format(entry.args[0], ...entry.args.slice(1));
}
@ -500,22 +501,22 @@ const SIMPLE_EXTRACTORS = {
compilationAuxiliaryFileToChunks.get(asset.name) || [];
object.chunkNames = uniqueOrderedArray(
chunks,
c => ((c.name ? [c.name] : [])),
c => (c.name ? [c.name] : []),
compareIds
);
object.chunkIdHints = uniqueOrderedArray(
chunks,
c => (Array.from(c.idNameHints)),
c => Array.from(c.idNameHints),
compareIds
);
object.auxiliaryChunkNames = uniqueOrderedArray(
auxiliaryChunks,
c => ((c.name ? [c.name] : [])),
c => (c.name ? [c.name] : []),
compareIds
);
object.auxiliaryChunkIdHints = uniqueOrderedArray(
auxiliaryChunks,
c => (Array.from(c.idNameHints)),
c => Array.from(c.idNameHints),
compareIds
);
object.emitted = compilation.emittedAssets.has(asset.name);
@ -986,25 +987,25 @@ const FILTER = {
}
}
},
"compilation.modules": ({
"compilation.modules": {
excludeModules: EXCLUDE_MODULES_FILTER("module"),
"!orphanModules": (module, { compilation: { chunkGraph } }) => {
if (chunkGraph.getNumberOfModuleChunks(module) === 0) return false;
},
...BASE_MODULES_FILTER
}),
"module.modules": ({
},
"module.modules": {
excludeModules: EXCLUDE_MODULES_FILTER("nested"),
...BASE_MODULES_FILTER
}),
"chunk.modules": ({
},
"chunk.modules": {
excludeModules: EXCLUDE_MODULES_FILTER("chunk"),
...BASE_MODULES_FILTER
}),
"chunk.rootModules": ({
},
"chunk.rootModules": {
excludeModules: EXCLUDE_MODULES_FILTER("root-of-chunk"),
...BASE_MODULES_FILTER
})
}
};
/** @type {Record<string, (module: Module, context: UsualContext, options: UsualOptions, idx: number, i: number) => boolean | undefined>} */

View File

@ -152,12 +152,12 @@ const DEFAULTS = {
warnings: NORMAL_ON,
publicPath: OFF_FOR_TO_STRING,
logging: ({ all }, { forToString }) =>
(forToString && all !== false ? "info" : false),
forToString && all !== false ? "info" : false,
loggingDebug: () => [],
loggingTrace: OFF_FOR_TO_STRING,
excludeModules: () => [],
excludeAssets: () => [],
maxModules: (o, { forToString }) => ((forToString ? 15 : Infinity)),
maxModules: (o, { forToString }) => (forToString ? 15 : Infinity),
modulesSort: () => "depth",
chunkModulesSort: () => "name",
chunkRootModulesSort: () => "name",

View File

@ -43,11 +43,7 @@ const printSizes = (sizes, { formatSize }) => {
}
};
const mapLines = (str, fn) =>
str
.split("\n")
.map(fn)
.join("\n");
const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
/**
* @param {number} n a number
@ -84,10 +80,10 @@ const SIMPLE_PRINTERS = {
"compilation.entrypoints": (entrypoints, context, printer) =>
Array.isArray(entrypoints)
? undefined
: printer.print(context.type, Object.values(entrypoints), ({
: printer.print(context.type, Object.values(entrypoints), {
...context,
chunkGroupKind: "Entrypoint"
})),
}),
"compilation.namedChunkGroups": (namedChunkGroups, context, printer) => {
if (!Array.isArray(namedChunkGroups)) {
const {
@ -100,10 +96,10 @@ const SIMPLE_PRINTERS = {
!Object.prototype.hasOwnProperty.call(entrypoints, group.name)
);
}
return printer.print(context.type, chunkGroups, ({
return printer.print(context.type, chunkGroups, {
...context,
chunkGroupKind: "Chunk Group"
}));
});
}
},
"compilation.assetsByChunkName": () => "",
@ -152,7 +148,7 @@ const SIMPLE_PRINTERS = {
"asset.size": (
size,
{ asset: { isOverSizeLimit }, yellow, green, formatSize }
) => ((isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size))),
) => (isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size)),
"asset.emitted": (emitted, { green, formatFlag }) =>
emitted ? green(formatFlag("emitted")) : undefined,
"asset.comparedForEmit": (comparedForEmit, { yellow, formatFlag }) =>
@ -167,7 +163,7 @@ const SIMPLE_PRINTERS = {
"asset.info.hotModuleReplacement": (
hotModuleReplacement,
{ green, formatFlag }
) => ((hotModuleReplacement ? green(formatFlag("hmr")) : undefined)),
) => (hotModuleReplacement ? green(formatFlag("hmr")) : undefined),
assetChunk: (id, { formatChunkId }) => formatChunkId(id),
@ -350,8 +346,7 @@ const SIMPLE_PRINTERS = {
rendered ? green(formatFlag("rendered")) : undefined,
"chunk.recorded": (recorded, { formatFlag, green }) =>
recorded ? green(formatFlag("recorded")) : undefined,
"chunk.reason": (reason, { yellow }) =>
(reason ? yellow(reason) : undefined),
"chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined),
"chunk.rootModules": (modules, context) => {
let maxModuleId = 0;
for (const module of modules) {
@ -462,7 +457,7 @@ const SIMPLE_PRINTERS = {
loggingGroup: loggingGroup =>
loggingGroup.entries.length === 0 ? "" : undefined,
"loggingGroup.debug": (flag, { red }) => ((flag ? red("DEBUG") : undefined)),
"loggingGroup.debug": (flag, { red }) => (flag ? red("DEBUG") : undefined),
"loggingGroup.name": (name, { bold }) => bold(`LOG from ${name}`),
"loggingGroup.separator!": () => "\n",
"loggingGroup.filteredEntries": filteredEntries =>
@ -830,7 +825,7 @@ const SIMPLE_ELEMENT_JOINERS = {
if (maxModuleId >= 10) prefix += " ";
}
return (
(prefix +
prefix +
joinExplicitNewLine(
items.filter(item => {
switch (item.element) {
@ -846,13 +841,13 @@ const SIMPLE_ELEMENT_JOINERS = {
return true;
}),
indenter
))
)
);
},
chunk: items => {
let hasEntry = false;
return (
("chunk " +
"chunk " +
joinExplicitNewLine(
items.filter(item => {
switch (item.element) {
@ -866,7 +861,7 @@ const SIMPLE_ELEMENT_JOINERS = {
return true;
}),
" "
))
)
);
},
"chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
@ -886,8 +881,8 @@ const SIMPLE_ELEMENT_JOINERS = {
break;
case "resolvedModule":
return (
(moduleReason.module !== moduleReason.resolvedModule &&
item.content)
moduleReason.module !== moduleReason.resolvedModule &&
item.content
);
}
return true;

View File

@ -64,8 +64,7 @@ const validateSchema = (schema, options) => {
}
if (error.keyword === "additionalProperties") {
const params =
/** @type {import("ajv").AdditionalPropertiesParams} */ (error.params);
const params = /** @type {import("ajv").AdditionalPropertiesParams} */ (error.params);
if (
Object.prototype.hasOwnProperty.call(
DID_YOU_MEAN,

View File

@ -68,7 +68,7 @@
"mini-css-extract-plugin": "^0.8.0",
"mini-svg-data-uri": "^1.1.3",
"open-cli": "^5.0.0",
"prettier": "^1.14.3",
"prettier": "2",
"pretty-format": "^25.1.0",
"pug": "^2.0.4",
"pug-loader": "^2.4.0",

View File

@ -96,11 +96,7 @@ function execGetOutput(command, args, description) {
if (exitCode) {
reject(`${description} failed with exit code ${exitCode}`);
} else {
resolve(
Buffer.concat(buffers)
.toString("utf-8")
.trim()
);
resolve(Buffer.concat(buffers).toString("utf-8").trim());
}
});
const buffers = [];

View File

@ -1,3 +1,3 @@
module.exports = {
entry: "./index"
entry: "./index",
};

View File

@ -5313,7 +5313,12 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"
prettier@^1.14.3, prettier@^1.19.1:
prettier@2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.2.tgz#1ba8f3eb92231e769b7fcd7cb73ae1b6b74ade08"
integrity sha512-5xJQIPT8BraI7ZnaDwSbu5zLrB6vvi8hVV58yHQ+QK64qrY40dULy0HSRlQ2/2IdzeBpjhDkqdcFBnFeDEMVdg==
prettier@^1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==