Skip to content

Commit

Permalink
chore(prettier): ran format
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeveric committed Jul 14, 2024
1 parent 1515f8f commit afffc0d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { cwd } from 'node:process';
/**
* @type {(filenames: string[]) => string[]>}
*/
const relativeFilenames = filenames => {
const relativeFilenames = (filenames) => {
const root = cwd();

return filenames.map(file => relative(root, file));
return filenames.map((file) => relative(root, file));
};

/**
Expand All @@ -16,7 +16,7 @@ const relativeFilenames = filenames => {
export default {
'*.{js,cjs,mjs,ts,cts,mts}': ['eslint --fix', 'prettier --write'],
'*.{json,md}': 'prettier --write',
'*': filenames => {
'*': (filenames) => {
const files = relativeFilenames(filenames);

return [
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function lock(filename: string): Promise<void> {
retries: 100,
retryWait: 100,
},
error => {
(error) => {
if (error) {
reject(error);

Expand All @@ -111,7 +111,7 @@ export function lock(filename: string): Promise<void> {
*/
export function unlock(filename: string): Promise<void> {
return new Promise((resolve, reject) => {
lockfileUnlock(getLockFilename(filename), error => {
lockfileUnlock(getLockFilename(filename), (error) => {
if (error) {
reject(error);

Expand Down
30 changes: 16 additions & 14 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
});

constructor(options: Partial<Options> = {}) {
this.hooks.transform.tap(PLUGIN_NAME, assets => {
this.hooks.transform.tap(PLUGIN_NAME, (assets) => {
const { sortManifest } = this.options;

return sortManifest
Expand Down Expand Up @@ -185,7 +185,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
compiler.hooks.afterEmit.tapPromise(PLUGIN_NAME, this.handleAfterEmit.bind(this));

// The compilation has finished
compiler.hooks.done.tapPromise(PLUGIN_NAME, async stats => await this.hooks.done.promise(this, stats));
compiler.hooks.done.tapPromise(PLUGIN_NAME, async (stats) => await this.hooks.done.promise(this, stats));

// Setup is complete.
this.hooks.apply.call(this);
Expand Down Expand Up @@ -371,10 +371,10 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
*/
public processAssetsByChunkName(assets: StatsCompilation['assetsByChunkName'], hmrFiles: Set<string>): void {
if (assets) {
Object.keys(assets).forEach(chunkName => {
Object.keys(assets).forEach((chunkName) => {
asArray(assets[chunkName])
.filter(filename => !hmrFiles.has(filename)) // Remove hot module replacement files
.forEach(filename => {
.filter((filename) => !hmrFiles.has(filename)) // Remove hot module replacement files
.forEach((filename) => {
this.assetNames.set(chunkName + this.getExtension(filename), filename);
});
});
Expand Down Expand Up @@ -514,7 +514,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
private processStatsAssets(assets: StatsAsset[] | undefined): void {
const { contextRelativeKeys } = this.options;

assets?.forEach(asset => {
assets?.forEach((asset) => {
if (asset.name && asset.info.sourceFilename) {
this.assetNames.set(
contextRelativeKeys
Expand All @@ -535,7 +535,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
} {
const hmrFiles = new Set<string>();

const assets = compilation.getAssets().filter(asset => {
const assets = compilation.getAssets().filter((asset) => {
if (asset.info.hotModuleReplacement) {
hmrFiles.add(asset.name);

Expand Down Expand Up @@ -585,7 +585,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
sourceFilenames.push(name);
}

sourceFilenames.forEach(key => {
sourceFilenames.forEach((key) => {
this.currentAsset = asset;

this.set(key, asset.name);
Expand Down Expand Up @@ -671,7 +671,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
public clear(): void {
// Delete properties instead of setting to {} so that the variable reference
// is maintained incase the `assets` is being shared in multi-compiler mode.
Object.keys(this.assets).forEach(key => {
Object.keys(this.assets).forEach((key) => {
delete this.assets[key];
});
}
Expand All @@ -693,7 +693,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
// Check to see if we let webpack-dev-server handle it.
if (this.inDevServer()) {
const wdsWriteToDisk: ((filePath: string) => boolean) | boolean | undefined = compilation.options.devServer
? compilation.options.devServer.devMiddleware?.writeToDisk ?? compilation.options.devServer.writeToDisk
? (compilation.options.devServer.devMiddleware?.writeToDisk ?? compilation.options.devServer.writeToDisk)
: undefined;

if (wdsWriteToDisk === true) {
Expand Down Expand Up @@ -762,13 +762,15 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {

for (const asset of compilation.getAssets()) {
if (!asset.info[integrityPropertyName]) {
const sriHashes = new Map<string, string | undefined>(integrityHashes.map(algorithm => [algorithm, undefined]));
const sriHashes = new Map<string, string | undefined>(
integrityHashes.map((algorithm) => [algorithm, undefined]),
);

// webpack-subresource-integrity@4+ stores the integrity hash on `asset.info.contenthash`.
if (asset.info.contenthash) {
asArray(asset.info.contenthash)
.filter(contentHash => integrityHashes.some(algorithm => contentHash.startsWith(`${algorithm}-`)))
.forEach(sriHash => sriHashes.set(sriHash.substring(0, sriHash.indexOf('-')), sriHash));
.filter((contentHash) => integrityHashes.some((algorithm) => contentHash.startsWith(`${algorithm}-`)))
.forEach((sriHash) => sriHashes.set(sriHash.substring(0, sriHash.indexOf('-')), sriHash));
}

const assetContent = asset.source.source().toString();
Expand Down Expand Up @@ -840,7 +842,7 @@ export class WebpackAssetsManifest implements WebpackPluginInstance {
return true;
}

if (process.argv.some(arg => arg.includes('webpack-dev-server'))) {
if (process.argv.some((arg) => arg.includes('webpack-dev-server'))) {
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/complex.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import('./hello.js').then(module => console.log(module)).catch(console.error);
import('./hello.js').then((module) => console.log(module)).catch(console.error);
import(/* webpackChunkName: "load-styles" */ './load-styles.mjs')
.then(module => console.log(module))
.then((module) => console.log(module))
.catch(console.error);
import(/* webpackPrefetch: true */ './prefetch.js').then(module => console.log(module)).catch(console.error);
import(/* webpackPreload: true */ './preload.js').then(module => console.log(module)).catch(console.error);
import(/* webpackPrefetch: true */ './prefetch.js').then((module) => console.log(module)).catch(console.error);
import(/* webpackPreload: true */ './preload.js').then((module) => console.log(module)).catch(console.error);

console.log('Complex');
6 changes: 3 additions & 3 deletions test/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('findMapKeysByValue()', function () {

describe('group()', () => {
it('group items from an array based on a callback return value', () => {
const grouped = group(['cat', 'dog', 'dinosaur'], word => word[0]);
const grouped = group(['cat', 'dog', 'dinosaur'], (word) => word[0]);

expect(grouped).toEqual({
c: ['cat'],
Expand All @@ -76,7 +76,7 @@ describe('group()', () => {
});

it('prevent item from being grouped', () => {
const grouped = group(['cat', 'dog', 'dinosaur'], word => (word === 'cat' ? undefined : word[0]));
const grouped = group(['cat', 'dog', 'dinosaur'], (word) => (word === 'cat' ? undefined : word[0]));

expect(grouped).toEqual({
d: ['dog', 'dinosaur'],
Expand All @@ -86,7 +86,7 @@ describe('group()', () => {
it('can modify items with a callback', () => {
const grouped = group(
['cat', 'dog', 'dinosaur'],
word => word[0],
(word) => word[0],
(word, group) => `${word.toUpperCase()}-group-${String(group)}`,
);

Expand Down
4 changes: 2 additions & 2 deletions test/type-predicate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('isKeyValuePair()', () => {
});

describe('isPropertyKey()', () => {
it.each(['string-key', 123, Symbol('symbol-key')])('Returns true for %s', input => {
it.each(['string-key', 123, Symbol('symbol-key')])('Returns true for %s', (input) => {
expect(isPropertyKey(input)).toBeTruthy();
});

it.each([false, null, undefined, {}, []])('Returns false for %s', input => {
it.each([false, null, undefined, {}, []])('Returns false for %s', (input) => {
expect(isPropertyKey(input)).toBeFalsy();
});
});
4 changes: 2 additions & 2 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function makeCompiler(configuration: Configuration): Compiler {
export function makeMultiCompiler(configurations: Configuration[]): MultiCompiler {
const compiler = webpack(
configurations.map(
config =>
(config) =>
({
mode: 'development',
stats: 'errors-only',
Expand Down Expand Up @@ -95,7 +95,7 @@ export function createMulti(

const compiler = comp(
configurations.map(
config =>
(config) =>
({
mode: 'development',
stats: 'errors-only',
Expand Down

0 comments on commit afffc0d

Please sign in to comment.