Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jan 16, 2024
1 parent e3dfa16 commit 70de1c6
Show file tree
Hide file tree
Showing 21 changed files with 560 additions and 540 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ type minimizer =
| {
[key: string]: any;
}
| undefined
| undefined,
) => Promise<{
filename: string;
data: Buffer;
Expand All @@ -733,7 +733,7 @@ type minimizer =
pathData: {
filename?: string | undefined;
},
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string)
| undefined;
}
Expand All @@ -750,7 +750,7 @@ type minimizer =
| {
[key: string]: any;
}
| undefined
| undefined,
) => Promise<{
filename: string;
data: Buffer;
Expand All @@ -773,7 +773,7 @@ type minimizer =
pathData: {
filename?: string | undefined;
},
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string)
| undefined;
}>;
Expand Down Expand Up @@ -1008,7 +1008,7 @@ type implementation = (
errors: Array<Error>;
info: import("webpack").AssetInfo;
},
options?: BasicTransformerOptions<T>
options?: BasicTransformerOptions<T>,
) => Promise<{
filename: string;
data: Buffer;
Expand Down Expand Up @@ -1147,7 +1147,7 @@ type filename =
pathData: {
filename?: string | undefined;
},
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string)
| undefined;
```
Expand Down Expand Up @@ -1235,7 +1235,7 @@ type generator = Array<{
| {
[key: string]: any;
}
| undefined
| undefined,
) => Promise<{
filename: string;
data: Buffer;
Expand All @@ -1258,7 +1258,7 @@ type generator = Array<{
pathData: {
filename?: string | undefined;
},
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string)
| undefined;
preset?: string | undefined;
Expand Down Expand Up @@ -1654,7 +1654,7 @@ type implementation = (
| {
[key: string]: any;
}
| undefined
| undefined,
) => Promise<{
filename: string;
data: Buffer;
Expand Down Expand Up @@ -1800,7 +1800,7 @@ type filename =
| string
| ((
pathData: PathData,
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string);
```
Expand Down Expand Up @@ -2071,7 +2071,7 @@ type minimizer =
| {
[key: string]: any;
}
| undefined
| undefined,
) => Promise<{
filename: string;
data: Buffer;
Expand All @@ -2094,7 +2094,7 @@ type minimizer =
pathData: {
filename?: string | undefined;
},
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string)
| undefined;
}
Expand All @@ -2111,7 +2111,7 @@ type minimizer =
| {
[key: string]: any;
}
| undefined
| undefined,
) => Promise<{
filename: string;
data: Buffer;
Expand All @@ -2134,7 +2134,7 @@ type minimizer =
pathData: {
filename?: string | undefined;
},
assetInfo?: import("webpack").AssetInfo | undefined
assetInfo?: import("webpack").AssetInfo | undefined,
) => string)
| undefined;
}>;
Expand Down
37 changes: 19 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ImageMinimizerPlugin {

if (!minimizer && !generator) {
throw new Error(
"Not configured 'minimizer' or 'generator' options, please setup them"
"Not configured 'minimizer' or 'generator' options, please setup them",
);
}

Expand Down Expand Up @@ -259,7 +259,7 @@ class ImageMinimizerPlugin {
if (
!compiler.webpack.ModuleFilenameHelpers.matchObject(
this.options,
name
name,
)
) {
return false;
Expand Down Expand Up @@ -301,30 +301,30 @@ class ImageMinimizerPlugin {
if (generators.length > 0) {
tasks.push(
...(await Promise.all(
generators.map((generator) => getFromCache(generator))
))
generators.map((generator) => getFromCache(generator)),
)),
);
}

if (minimizers.length > 0) {
tasks.push(
await getFromCache(
/** @type {Minimizer<T>[]} */
(minimizers)
)
(minimizers),
),
);
}

return tasks;
})
}),
)
).flat();

// In some cases cpus() returns undefined
// https://github.com/nodejs/node/issues/19022
const limit = Math.max(
1,
this.options.concurrency ?? os.cpus()?.length ?? 1
this.options.concurrency ?? os.cpus()?.length ?? 1,
);
const { RawSource } = compiler.webpack.sources;

Expand Down Expand Up @@ -380,13 +380,13 @@ class ImageMinimizerPlugin {
compilation.updateAsset(
output.filename,
/** @type {Source} */ (output.source),
output.info
output.info,
);
} else {
compilation.emitAsset(
output.filename,
/** @type {Source} */ (output.source),
output.info
output.info,
);

if (this.options.deleteOriginalAssets) {
Expand Down Expand Up @@ -475,7 +475,7 @@ class ImageMinimizerPlugin {

compilation.updateAsset(file, asset.source, newInfo);
}
}
},
);

// Collect asset modules and update info for asset modules
Expand All @@ -490,7 +490,7 @@ class ImageMinimizerPlugin {
}

return filename;
}
},
);
});

Expand All @@ -503,7 +503,8 @@ class ImageMinimizerPlugin {

if (Array.isArray(generatorForLoader)) {
const importGenerators = generatorForLoader.filter(
(item) => typeof item.type === "undefined" || item.type === "import"
(item) =>
typeof item.type === "undefined" || item.type === "import",
);

generatorForLoader =
Expand Down Expand Up @@ -566,7 +567,7 @@ class ImageMinimizerPlugin {
},
async (assets) => {
await this.optimize(compiler, compilation, assets);
}
},
);

compilation.hooks.statsPrinter.tap(pluginName, (stats) => {
Expand All @@ -577,9 +578,9 @@ class ImageMinimizerPlugin {
(minimized, { green, formatFlag }) =>
minimized
? /** @type {Function} */ (green)(
/** @type {Function} */ (formatFlag)("minimized")
/** @type {Function} */ (formatFlag)("minimized"),
)
: ""
: "",
);

stats.hooks.print
Expand All @@ -589,9 +590,9 @@ class ImageMinimizerPlugin {
(generated, { green, formatFlag }) =>
generated
? /** @type {Function} */ (green)(
/** @type {Function} */ (formatFlag)("generated")
/** @type {Function} */ (formatFlag)("generated"),
)
: ""
: "",
);
});
});
Expand Down
22 changes: 11 additions & 11 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ async function loader(content) {
if (!minimizer && !generator) {
callback(
new Error(
"Not configured 'minimizer' or 'generator' options, please setup them"
)
"Not configured 'minimizer' or 'generator' options, please setup them",
),
);

return;
Expand All @@ -128,8 +128,8 @@ async function loader(content) {
if (!generator) {
callback(
new Error(
"Please specify the 'generator' option to use 'as' query param for generation purposes."
)
"Please specify the 'generator' option to use 'as' query param for generation purposes.",
),
);

return;
Expand All @@ -140,8 +140,8 @@ async function loader(content) {
if (presets.length > 1) {
callback(
new Error(
"Found several identical preset names, the 'preset' option should be unique"
)
"Found several identical preset names, the 'preset' option should be unique",
),
);

return;
Expand All @@ -150,8 +150,8 @@ async function loader(content) {
if (presets.length === 0) {
callback(
new Error(
`Can't find '${presetName}' preset in the 'generator' option`
)
`Can't find '${presetName}' preset in the 'generator' option`,
),
);

return;
Expand All @@ -178,7 +178,7 @@ async function loader(content) {
[transformer] = processSizeQuery(
[transformer],
widthQuery,
heightQuery
heightQuery,
);
}
}
Expand Down Expand Up @@ -222,15 +222,15 @@ async function loader(content) {
// Change content of the data URI after minimizer
if (this._module?.resourceResolveData?.encodedContent) {
const isBase64 = /^base64$/i.test(
this._module.resourceResolveData.encoding
this._module.resourceResolveData.encoding,
);

this._module.resourceResolveData.encodedContent = isBase64
? output.data.toString("base64")
: encodeURIComponent(output.data.toString("utf-8")).replace(
/[!'()*]/g,
(character) =>
`%${/** @type {number} */ (character.codePointAt(0)).toString(16)}`
`%${/** @type {number} */ (character.codePointAt(0)).toString(16)}`,
);
} else {
let query = this.resourceQuery;
Expand Down
Loading

0 comments on commit 70de1c6

Please sign in to comment.