Skip to content

Commit 4b18c3d

Browse files
committed
chore: remove unused dead code
Prune stale helpers and internal-only exports found by deslop, and align package metadata with actual build/runtime usage.
1 parent 0be2a87 commit 4b18c3d

37 files changed

Lines changed: 1990 additions & 4600 deletions

packages/extension/src/utils/helpers.ts

Lines changed: 47 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export const isIframe = window !== window.top;
2-
export const isPopup = window.opener !== null;
1+
const isIframe = window !== window.top;
2+
const isPopup = window.opener !== null;
33
export const canLoadReactScan = !isIframe && !isPopup;
44

5-
export const IS_CLIENT = typeof window !== 'undefined';
5+
const IS_CLIENT = typeof window !== "undefined";
66

77
export const isInternalUrl = (url: string): boolean => {
88
if (!url) return false;
99

10-
const allowedProtocols = ['http:', 'https:', 'file:'];
10+
const allowedProtocols = ["http:", "https:", "file:"];
1111
return !allowedProtocols.includes(new URL(url).protocol);
1212
};
1313

@@ -26,26 +26,42 @@ const ReactDetection = {
2626
limits: {
2727
MAX_DEPTH: 10,
2828
MAX_ELEMENTS: 30,
29-
ELEMENTS_PER_LEVEL: 5
29+
ELEMENTS_PER_LEVEL: 5,
3030
},
3131
nonVisualTags: new Set([
3232
// Document level
33-
'HTML', 'HEAD', 'META', 'TITLE', 'BASE',
33+
"HTML",
34+
"HEAD",
35+
"META",
36+
"TITLE",
37+
"BASE",
3438
// Scripts and styles
35-
'SCRIPT', 'STYLE', 'LINK', 'NOSCRIPT',
39+
"SCRIPT",
40+
"STYLE",
41+
"LINK",
42+
"NOSCRIPT",
3643
// Media and embeds
37-
'SOURCE', 'TRACK', 'EMBED', 'OBJECT', 'PARAM',
44+
"SOURCE",
45+
"TRACK",
46+
"EMBED",
47+
"OBJECT",
48+
"PARAM",
3849
// Special elements
39-
'TEMPLATE', 'PORTAL', 'SLOT',
50+
"TEMPLATE",
51+
"PORTAL",
52+
"SLOT",
4053
// Others
41-
'AREA', 'XML', 'DOCTYPE', 'COMMENT'
54+
"AREA",
55+
"XML",
56+
"DOCTYPE",
57+
"COMMENT",
4258
]),
4359
reactMarkers: {
44-
root: '_reactRootContainer',
45-
fiber: '__reactFiber',
46-
instance: '__reactInternalInstance$',
47-
container: '__reactContainer$'
48-
}
60+
root: "_reactRootContainer",
61+
fiber: "__reactFiber",
62+
instance: "__reactInternalInstance$",
63+
container: "__reactContainer$",
64+
},
4965
} as const;
5066

5167
const childrenCache = new WeakMap<Element, Element[]>();
@@ -81,8 +97,8 @@ export const hasReactFiber = (): boolean => {
8197
const rootContainer = elementWithRoot._reactRootContainer;
8298

8399
const hasLegacyRoot = rootContainer?._internalRoot?.current?.child != null;
84-
const hasContainerRoot = Object.keys(elementWithRoot).some(key =>
85-
key.startsWith(ReactDetection.reactMarkers.container)
100+
const hasContainerRoot = Object.keys(elementWithRoot).some((key) =>
101+
key.startsWith(ReactDetection.reactMarkers.container),
86102
);
87103

88104
return hasLegacyRoot || hasContainerRoot;
@@ -133,59 +149,6 @@ export const saveLocalStorage = <T>(storageKey: string, state: T): void => {
133149
} catch {}
134150
};
135151

136-
export const removeLocalStorage = (storageKey: string): void => {
137-
if (!IS_CLIENT) return;
138-
139-
try {
140-
window.localStorage.removeItem(storageKey);
141-
} catch {}
142-
};
143-
144-
export const debounce = <T extends (enabled: boolean | null) => Promise<void>>(
145-
fn: T,
146-
wait: number,
147-
options: { leading?: boolean; trailing?: boolean } = {},
148-
) => {
149-
let timeoutId: number | undefined;
150-
let lastArg: boolean | null | undefined;
151-
let isLeadingInvoked = false;
152-
153-
const debounced = (enabled: boolean | null) => {
154-
lastArg = enabled;
155-
156-
if (options.leading && !isLeadingInvoked) {
157-
isLeadingInvoked = true;
158-
fn(enabled);
159-
return;
160-
}
161-
162-
if (timeoutId !== undefined) {
163-
clearTimeout(timeoutId);
164-
}
165-
166-
if (options.trailing !== false) {
167-
timeoutId = setTimeout(() => {
168-
isLeadingInvoked = false;
169-
timeoutId = undefined;
170-
if (lastArg !== undefined) {
171-
fn(lastArg);
172-
}
173-
}, wait);
174-
}
175-
};
176-
177-
debounced.cancel = () => {
178-
if (timeoutId !== undefined) {
179-
clearTimeout(timeoutId);
180-
timeoutId = undefined;
181-
isLeadingInvoked = false;
182-
lastArg = undefined;
183-
}
184-
};
185-
186-
return debounced;
187-
};
188-
189152
type EventCallback<T = unknown> = (data: T) => void;
190153
const eventBus = new Map<string, Set<EventCallback>>();
191154

@@ -220,14 +183,16 @@ export const sleep = (ms: number): Promise<void> => {
220183
return new Promise((resolve) => setTimeout(resolve, ms));
221184
};
222185

223-
export const storageGetItem = async <T>(
224-
storageKey: string,
225-
key: string,
226-
): Promise<T | null> => {
186+
const isStorageRecord = (value: unknown): value is Record<string, unknown> =>
187+
typeof value === "object" && value !== null;
188+
189+
export const storageGetItem = async <T>(storageKey: string, key: string): Promise<T | null> => {
227190
try {
228191
const result = await chrome.storage.local.get(storageKey);
229192
const data = result[storageKey];
230-
return data?.[key] ?? null;
193+
if (!isStorageRecord(data)) return null;
194+
const value = data[key];
195+
return value === undefined ? null : (value as T);
231196
} catch {
232197
return null;
233198
}
@@ -240,9 +205,11 @@ export const storageSetItem = async <T>(
240205
): Promise<void> => {
241206
try {
242207
const result = await chrome.storage.local.get(storageKey);
243-
const data = result[storageKey] || {};
244-
data[key] = value;
245-
await chrome.storage.local.set({ [storageKey]: data });
246-
} catch {
247-
}
208+
const data = result[storageKey];
209+
const updatedData = {
210+
...(isStorageRecord(data) ? data : {}),
211+
[key]: value,
212+
};
213+
await chrome.storage.local.set({ [storageKey]: updatedData });
214+
} catch {}
248215
};

packages/scan/package.json

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,66 @@
33
"version": "0.5.7",
44
"description": "Scan your React app for renders",
55
"keywords": [
6+
"performance",
67
"react",
7-
"react-scan",
88
"react scan",
9-
"render",
10-
"performance"
9+
"react-scan",
10+
"render"
1111
],
1212
"homepage": "https://react-scan.million.dev",
1313
"bugs": {
1414
"url": "https://github.com/aidenybai/react-scan/issues"
1515
},
16-
"repository": {
17-
"type": "git",
18-
"url": "git+https://github.com/aidenybai/react-scan.git"
19-
},
2016
"license": "MIT",
2117
"author": {
2218
"name": "Aiden Bai",
2319
"email": "aiden@million.dev",
2420
"url": "https://million.dev"
2521
},
26-
"scripts": {
27-
"build": "pnpm build:css && NODE_ENV=production tsup",
28-
"build:copy": "pnpm build && cat dist/auto.global.js | pbcopy",
29-
"build:css": "postcss ./src/web/assets/css/styles.tailwind.css -o ./src/web/assets/css/styles.css",
30-
"dev:css": "postcss ./src/web/assets/css/styles.tailwind.css -o ./src/web/assets/css/styles.css --watch",
31-
"dev:tsup": "NODE_ENV=development tsup --watch",
32-
"dev": "pnpm run --parallel \"/^dev:(css|tsup)/\"",
33-
"pack": "npm version patch && pnpm build && npm pack",
34-
"pack:bump": "node scripts/bump-version.mjs && pnpm run pack && echo $(pwd)/react-scan-$(node -p \"require('./package.json').version\").tgz | pbcopy",
35-
"publint": "publint",
36-
"test": "vp test run",
37-
"test:watch": "vp test",
38-
"lint": "vp lint",
39-
"format": "vp fmt",
40-
"typecheck": "tsc --noEmit"
22+
"repository": {
23+
"type": "git",
24+
"url": "git+https://github.com/aidenybai/react-scan.git"
25+
},
26+
"bin": "bin/cli.js",
27+
"files": [
28+
"dist",
29+
"bin",
30+
"package.json",
31+
"README.md",
32+
"LICENSE",
33+
"auto.d.ts"
34+
],
35+
"main": "dist/index.js",
36+
"module": "dist/index.mjs",
37+
"browser": "dist/auto.global.js",
38+
"types": "dist/index.d.ts",
39+
"typesVersions": {
40+
"*": {
41+
"react-component-name/vite": [
42+
"./dist/react-component-name/vite.d.ts"
43+
],
44+
"react-component-name/webpack": [
45+
"./dist/react-component-name/webpack.d.ts"
46+
],
47+
"react-component-name/esbuild": [
48+
"./dist/react-component-name/esbuild.d.ts"
49+
],
50+
"react-component-name/rspack": [
51+
"./dist/react-component-name/rspack.d.ts"
52+
],
53+
"react-component-name/rolldown": [
54+
"./dist/react-component-name/rolldown.d.ts"
55+
],
56+
"react-component-name/rollup": [
57+
"./dist/react-component-name/rollup.d.ts"
58+
],
59+
"react-component-name/astro": [
60+
"./dist/react-component-name/astro.d.ts"
61+
],
62+
"react-component-name/loader": [
63+
"./dist/react-component-name/loader.d.ts"
64+
]
65+
}
4166
},
4267
"exports": {
4368
"./package.json": "./package.json",
@@ -164,47 +189,25 @@
164189
"require": "./dist/react-component-name/loader.js"
165190
}
166191
},
167-
"main": "dist/index.js",
168-
"module": "dist/index.mjs",
169-
"browser": "dist/auto.global.js",
170-
"types": "dist/index.d.ts",
171-
"typesVersions": {
172-
"*": {
173-
"react-component-name/vite": [
174-
"./dist/react-component-name/vite.d.ts"
175-
],
176-
"react-component-name/webpack": [
177-
"./dist/react-component-name/webpack.d.ts"
178-
],
179-
"react-component-name/esbuild": [
180-
"./dist/react-component-name/esbuild.d.ts"
181-
],
182-
"react-component-name/rspack": [
183-
"./dist/react-component-name/rspack.d.ts"
184-
],
185-
"react-component-name/rolldown": [
186-
"./dist/react-component-name/rolldown.d.ts"
187-
],
188-
"react-component-name/rollup": [
189-
"./dist/react-component-name/rollup.d.ts"
190-
],
191-
"react-component-name/astro": [
192-
"./dist/react-component-name/astro.d.ts"
193-
],
194-
"react-component-name/loader": [
195-
"./dist/react-component-name/loader.d.ts"
196-
]
197-
}
192+
"publishConfig": {
193+
"access": "public"
194+
},
195+
"scripts": {
196+
"build": "pnpm build:css && NODE_ENV=production tsup",
197+
"build:copy": "pnpm build && cat dist/auto.global.js | pbcopy",
198+
"build:css": "postcss ./src/web/assets/css/styles.tailwind.css -o ./src/web/assets/css/styles.css",
199+
"dev:css": "postcss ./src/web/assets/css/styles.tailwind.css -o ./src/web/assets/css/styles.css --watch",
200+
"dev:tsup": "NODE_ENV=development tsup --watch",
201+
"dev": "pnpm run --parallel \"/^dev:(css|tsup)/\"",
202+
"pack": "npm version patch && pnpm build && npm pack",
203+
"pack:bump": "node scripts/bump-version.mjs && pnpm run pack && echo $(pwd)/react-scan-$(node -p \"require('./package.json').version\").tgz | pbcopy",
204+
"publint": "publint",
205+
"test": "vp test run",
206+
"test:watch": "vp test",
207+
"lint": "vp lint",
208+
"format": "vp fmt",
209+
"typecheck": "tsc --noEmit"
198210
},
199-
"bin": "bin/cli.js",
200-
"files": [
201-
"dist",
202-
"bin",
203-
"package.json",
204-
"README.md",
205-
"LICENSE",
206-
"auto.d.ts"
207-
],
208211
"dependencies": {
209212
"@babel/core": "^7.29.0",
210213
"@babel/types": "^7.29.0",
@@ -215,7 +218,6 @@
215218
"picocolors": "^1.1.1",
216219
"preact": "^10.29.1",
217220
"prompts": "^2.4.2",
218-
"react-doctor": "latest",
219221
"react-grab": "latest"
220222
},
221223
"devDependencies": {
@@ -253,8 +255,5 @@
253255
},
254256
"optionalDependencies": {
255257
"unplugin": "^3.0.0"
256-
},
257-
"publishConfig": {
258-
"access": "public"
259258
}
260259
}

0 commit comments

Comments
 (0)