Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .eslintignore

This file was deleted.

16 changes: 0 additions & 16 deletions .eslintrc.json

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ jobs:
- name: Download deps
uses: bahmutov/npm-install@v1

- name: Build sources
run: npm run build

- name: Run lint
run: npm run lint
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ yarn add -D webpack-bundle-analyzer
<h2 align="center">Usage (as a plugin)</h2>

```js
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");

module.exports = {
plugins: [new BundleAnalyzerPlugin()],
Expand All @@ -48,6 +47,7 @@ And it also shows their gzipped, Brotli, or Zstandard sizes!

<h2 align="center">Options (for plugin)</h2>

<!-- eslint-skip -->
```js
new BundleAnalyzerPlugin(options?: object)
```
Expand Down
3 changes: 1 addition & 2 deletions client/components/CheckboxList.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import PureComponent from "../lib/PureComponent.jsx";
import CheckboxListItem from "./CheckboxListItem.jsx";

import * as styles from "./CheckboxList.css";
import CheckboxListItem from "./CheckboxListItem.jsx";

const ALL_ITEM = Symbol("ALL_ITEM");

Expand Down
3 changes: 1 addition & 2 deletions client/components/CheckboxListItem.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component } from "preact";

import Checkbox from "./Checkbox.jsx";
import CheckboxList from "./CheckboxList.jsx";

import * as styles from "./CheckboxList.css";
import CheckboxList from "./CheckboxList.jsx";

export default class CheckboxListItem extends Component {
render() {
Expand Down
3 changes: 1 addition & 2 deletions client/components/ContextMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import cls from "classnames";
import PureComponent from "../lib/PureComponent.jsx";
import { store } from "../store.js";
import { elementIsOutside } from "../utils.js";
import ContextMenuItem from "./ContextMenuItem.jsx";

import * as styles from "./ContextMenu.css";
import ContextMenuItem from "./ContextMenuItem.jsx";

export default class ContextMenu extends PureComponent {
componentDidMount() {
Expand Down
5 changes: 1 addition & 4 deletions client/components/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ export default class Dropdown extends PureComponent {
if (el && event && !el.contains(event.target)) {
this.setState({ showOptions: false });
// If the query is not in the options, reset the selection
if (
this.state.query &&
!this.props.options.some((option) => option === this.state.query)
) {
if (this.state.query && !this.props.options.includes(this.state.query)) {
this.setState({ query: "" });
this.props.onSelectionChange(undefined);
}
Expand Down
4 changes: 2 additions & 2 deletions client/components/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import iconPin from "../assets/icon-pin.svg";
import iconSun from "../assets/icon-sun.svg";
import PureComponent from "../lib/PureComponent.jsx";

import * as s from "./Icon.css";
import * as styles from "./Icon.css";

const ICONS = {
"arrow-right": {
Expand All @@ -28,7 +28,7 @@ const ICONS = {

export default class Icon extends PureComponent {
render({ className }) {
return <i className={cls(s.icon, className)} style={this.style} />;
return <i className={cls(styles.icon, className)} style={this.style} />;
}

get style() {
Expand Down
8 changes: 7 additions & 1 deletion client/components/ModuleItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export default class ModuleItem extends PureComponent {
onMouseLeave={this.handleMouseLeave}
>
<span dangerouslySetInnerHTML={{ __html: this.titleHtml }} />
{showSize && [" (", <strong>{filesize(module[showSize])}</strong>, ")"]}
{showSize && (
<>
{" ("}
<strong>{filesize(module[showSize])}</strong>
{")"}
</>
)}
</div>
);
}
Expand Down
35 changes: 20 additions & 15 deletions client/components/ModulesTreemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@ import CheckboxList from "./CheckboxList.jsx";
import ContextMenu from "./ContextMenu.jsx";
import Dropdown from "./Dropdown.jsx";
import ModulesList from "./ModulesList.jsx";
import * as styles from "./ModulesTreemap.css";
import Search from "./Search.jsx";
import Sidebar from "./Sidebar.jsx";
import Switcher from "./Switcher.jsx";
import Tooltip from "./Tooltip.jsx";
import Treemap from "./Treemap.jsx";

import * as styles from "./ModulesTreemap.css";

function getSizeSwitchItems() {
const items = [
{ label: "Stat", prop: "statSize" },
{ label: "Parsed", prop: "parsedSize" },
];

if (window.compressionAlgorithm === "gzip") {
if (globalThis.compressionAlgorithm === "gzip") {
items.push({ label: "Gzipped", prop: "gzipSize" });
}

if (window.compressionAlgorithm === "brotli") {
if (globalThis.compressionAlgorithm === "brotli") {
items.push({ label: "Brotli", prop: "brotliSize" });
}

if (window.compressionAlgorithm === "zstd") {
if (globalThis.compressionAlgorithm === "zstd") {
items.push({ label: "Zstandard", prop: "zstdSize" });
}

Expand Down Expand Up @@ -205,7 +204,11 @@ class ModulesTreemap extends Component {
const label = isAllItem ? "All" : item.label;
const size = isAllItem ? store.totalChunksSize : item[store.activeSize];

return [`${label} (`, <strong>{filesize(size)}</strong>, ")"];
return (
<>
{label} (<strong>{filesize(size)}</strong>)
</>
);
};

get sizeSwitchItems() {
Expand Down Expand Up @@ -244,14 +247,16 @@ class ModulesTreemap extends Component {
}

if (store.hasFoundModules) {
return [
<div className={styles.foundModulesInfoItem}>
Count: <strong>{store.foundModules.length}</strong>
</div>,
<div className={styles.foundModulesInfoItem}>
Total size: <strong>{filesize(store.foundModulesSize)}</strong>
</div>,
];
return (
<>
<div className={styles.foundModulesInfoItem}>
Count: <strong>{store.foundModules.length}</strong>
</div>
<div className={styles.foundModulesInfoItem}>
Total size: <strong>{filesize(store.foundModulesSize)}</strong>
</div>
</>
);
}

return `Nothing found${store.allChunksSelected ? "" : " in selected chunks"}`;
Expand Down Expand Up @@ -379,7 +384,7 @@ class ModulesTreemap extends Component {
{this.renderModuleSize(module, "stat")}
{!module.inaccurateSizes && this.renderModuleSize(module, "parsed")}
{!module.inaccurateSizes &&
this.renderModuleSize(module, window.compressionAlgorithm)}
this.renderModuleSize(module, globalThis.compressionAlgorithm)}
{module.path && (
<div>
Path: <strong>{module.path}</strong>
Expand Down
5 changes: 2 additions & 3 deletions client/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Component } from "preact";

import Button from "./Button.jsx";
import Icon from "./Icon.jsx";
import ThemeToggle from "./ThemeToggle.jsx";

import * as styles from "./Sidebar.css";
import ThemeToggle from "./ThemeToggle.jsx";

const toggleTime = parseInt(styles.toggleTime, 10);
const toggleTime = Number.parseInt(styles.toggleTime, 10);

export default class Sidebar extends Component {
static defaultProps = {
Expand Down
3 changes: 1 addition & 2 deletions client/components/Switcher.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import PureComponent from "../lib/PureComponent.jsx";
import SwitcherItem from "./SwitcherItem.jsx";

import * as styles from "./Switcher.css";
import SwitcherItem from "./SwitcherItem.jsx";

export default class Switcher extends PureComponent {
render() {
Expand Down
30 changes: 15 additions & 15 deletions client/components/Treemap.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import FoamTree from "@carrotsearch/foamtree";
import { Component } from "preact";

function preventDefault(event) {
event.preventDefault();
}

function hashCode(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
hash = (hash << 5) - hash + code;
hash &= hash;
}
return hash;
}

export default class Treemap extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -75,7 +89,7 @@ export default class Treemap extends Component {
const chunkName = component.getChunkNamePart(root.label);
const hash = /[^0-9]/u.test(chunkName)
? hashCode(chunkName)
: (Number.parseInt(chunkName) / 1000) * 360;
: (Number.parseInt(chunkName, 10) / 1000) * 360;
variables.groupColor = {
model: "hsla",
h: Math.round(Math.abs(hash) % 360),
Expand Down Expand Up @@ -246,17 +260,3 @@ export default class Treemap extends Component {
);
}
}

function preventDefault(event) {
event.preventDefault();
}

function hashCode(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
hash = (hash << 5) - hash + code;
hash &= hash;
}
return hash;
}
12 changes: 6 additions & 6 deletions client/lib/PureComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Component } from "preact";

export default class PureComponent extends Component {
shouldComponentUpdate(nextProps, nextState) {
return !isEqual(nextProps, this.props) || !isEqual(this.state, nextState);
}
}

function isEqual(obj1, obj2) {
if (obj1 === obj2) return true;
const keys = Object.keys(obj1);
Expand All @@ -16,3 +10,9 @@ function isEqual(obj1, obj2) {
}
return true;
}

export default class PureComponent extends Component {
shouldComponentUpdate(nextProps, nextState) {
return !isEqual(nextProps, this.props) || !isEqual(this.state, nextState);
}
}
8 changes: 5 additions & 3 deletions client/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ const KEY_PREFIX = "wba";
export default {
getItem(key) {
try {
return JSON.parse(window.localStorage.getItem(`${KEY_PREFIX}.${key}`));
return JSON.parse(
globalThis.localStorage.getItem(`${KEY_PREFIX}.${key}`),
);
} catch {
return null;
}
},

setItem(key, value) {
try {
window.localStorage.setItem(
globalThis.localStorage.setItem(
`${KEY_PREFIX}.${key}`,
JSON.stringify(value),
);
Expand All @@ -22,7 +24,7 @@ export default {

removeItem(key) {
try {
window.localStorage.removeItem(`${KEY_PREFIX}.${key}`);
globalThis.localStorage.removeItem(`${KEY_PREFIX}.${key}`);
} catch {
/* ignored */
}
Expand Down
16 changes: 8 additions & 8 deletions client/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computed, makeObservable, observable } from "mobx";
import localStorage from "./localStorage";
import { isChunkParsed, walkModules } from "./utils";
import localStorage from "./localStorage.js";
import { isChunkParsed, walkModules } from "./utils.js";

export class Store {
cid = 0;
Expand All @@ -27,7 +27,7 @@ export class Store {
localStorage.getItem("showConcatenatedModulesContent") === true;

darkMode = (() => {
const systemPrefersDark = window.matchMedia(
const systemPrefersDark = globalThis.matchMedia(
"(prefers-color-scheme: dark)",
).matches;

Expand Down Expand Up @@ -127,7 +127,7 @@ export class Store {
}

get isSearching() {
return !!this.searchQueryRegexp;
return Boolean(this.searchQueryRegexp);
}

get foundModulesByChunk() {
Expand Down Expand Up @@ -184,12 +184,12 @@ export class Store {
};
})
.filter((result) => result.modules.length > 0)
.sort((c1, c2) => c1.modules.length - c2.modules.length);
.toSorted((c1, c2) => c1.modules.length - c2.modules.length);
}

get foundModules() {
return this.foundModulesByChunk.reduce(
(arr, chunk) => arr.concat(chunk.modules),
(arr, chunk) => [...arr, ...chunk.modules],
[],
);
}
Expand Down Expand Up @@ -253,9 +253,9 @@ export class Store {

updateTheme() {
if (this.darkMode) {
document.documentElement.setAttribute("data-theme", "dark");
document.documentElement.dataset.theme = "dark";
} else {
document.documentElement.removeAttribute("data-theme");
delete document.documentElement.dataset.theme;
}
}
}
Expand Down
Loading
Loading