wxt 0.19.1-alpha3 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/core/utils/testing/fake-objects.d.ts +764 -764
- package/dist/core/utils/transform.d.ts +2 -1
- package/dist/core/utils/transform.mjs +68 -9
- package/dist/core/wxt.mjs +1 -0
- package/dist/version.mjs +1 -1
- package/package.json +9 -9
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Removes any code used at runtime related to an entrypoint's main function.
|
|
3
3
|
* 1. Removes or clears out `main` function from returned object
|
|
4
|
-
* 2. Removes unused
|
|
4
|
+
* 2. Removes any unused functions/variables outside the definition that aren't being called/used
|
|
5
|
+
* 3. Removes unused imports
|
|
5
6
|
* 3. Removes value-less, side-effect only imports (like `import "./styles.css"` or `import "webextension-polyfill"`)
|
|
6
7
|
*/
|
|
7
8
|
export declare function removeMainFunctionCode(code: string): {
|
|
@@ -2,7 +2,15 @@ import { parseModule } from "magicast";
|
|
|
2
2
|
export function removeMainFunctionCode(code) {
|
|
3
3
|
const mod = parseModule(code);
|
|
4
4
|
emptyMainFunction(mod);
|
|
5
|
-
|
|
5
|
+
let removedCount = 0;
|
|
6
|
+
let depth = 0;
|
|
7
|
+
const maxDepth = 10;
|
|
8
|
+
do {
|
|
9
|
+
removedCount = 0;
|
|
10
|
+
removedCount += removeUnusedTopLevelVariables(mod);
|
|
11
|
+
removedCount += removeUnusedTopLevelFunctions(mod);
|
|
12
|
+
removedCount += removeUnusedImports(mod);
|
|
13
|
+
} while (removedCount > 0 && depth++ <= maxDepth);
|
|
6
14
|
removeSideEffectImports(mod);
|
|
7
15
|
return mod.generate();
|
|
8
16
|
}
|
|
@@ -17,26 +25,77 @@ function emptyMainFunction(mod) {
|
|
|
17
25
|
}
|
|
18
26
|
}
|
|
19
27
|
}
|
|
28
|
+
function removeUnusedTopLevelVariables(mod) {
|
|
29
|
+
const simpleAst = getSimpleAstJson(mod.$ast);
|
|
30
|
+
const usedMap = findUsedIdentifiers(simpleAst);
|
|
31
|
+
let deletedCount = 0;
|
|
32
|
+
const ast = mod.$ast;
|
|
33
|
+
for (let i = ast.body.length - 1; i >= 0; i--) {
|
|
34
|
+
if (ast.body[i].type === "VariableDeclaration") {
|
|
35
|
+
for (let j = ast.body[i].declarations.length - 1; j >= 0; j--) {
|
|
36
|
+
if (!usedMap.get(ast.body[i].declarations[j].id.name)) {
|
|
37
|
+
ast.body[i].declarations.splice(j, 1);
|
|
38
|
+
deletedCount++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (ast.body[i].declarations.length === 0) {
|
|
42
|
+
ast.body.splice(i, 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return deletedCount;
|
|
47
|
+
}
|
|
48
|
+
function removeUnusedTopLevelFunctions(mod) {
|
|
49
|
+
const simpleAst = getSimpleAstJson(mod.$ast);
|
|
50
|
+
const usedMap = findUsedIdentifiers(simpleAst);
|
|
51
|
+
let deletedCount = 0;
|
|
52
|
+
const ast = mod.$ast;
|
|
53
|
+
for (let i = ast.body.length - 1; i >= 0; i--) {
|
|
54
|
+
if (ast.body[i].type === "FunctionDeclaration" && !usedMap.get(ast.body[i].id.name)) {
|
|
55
|
+
ast.body.splice(i, 1);
|
|
56
|
+
deletedCount++;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return deletedCount;
|
|
60
|
+
}
|
|
20
61
|
function removeUnusedImports(mod) {
|
|
62
|
+
const simpleAst = getSimpleAstJson(mod.$ast);
|
|
63
|
+
const usedMap = findUsedIdentifiers(simpleAst);
|
|
21
64
|
const importSymbols = Object.keys(mod.imports);
|
|
22
|
-
|
|
23
|
-
|
|
65
|
+
let deletedCount = 0;
|
|
66
|
+
importSymbols.forEach((name) => {
|
|
67
|
+
if (usedMap.get(name)) return;
|
|
68
|
+
delete mod.imports[name];
|
|
69
|
+
deletedCount++;
|
|
70
|
+
});
|
|
71
|
+
return deletedCount;
|
|
72
|
+
}
|
|
73
|
+
function findUsedIdentifiers(simpleAst) {
|
|
74
|
+
const usedMap = /* @__PURE__ */ new Map();
|
|
75
|
+
const queue = [simpleAst];
|
|
24
76
|
for (const item of queue) {
|
|
25
77
|
if (!item) {
|
|
26
|
-
continue;
|
|
27
78
|
} else if (Array.isArray(item)) {
|
|
28
79
|
queue.push(...item);
|
|
29
80
|
} else if (item.type === "ImportDeclaration") {
|
|
30
81
|
continue;
|
|
31
82
|
} else if (item.type === "Identifier") {
|
|
32
|
-
|
|
83
|
+
usedMap.set(item.name, true);
|
|
33
84
|
} else if (typeof item === "object") {
|
|
34
|
-
|
|
85
|
+
const filterFns = {
|
|
86
|
+
// Ignore the function declaration's name
|
|
87
|
+
FunctionDeclaration: ([key]) => key !== "id",
|
|
88
|
+
// Ignore object property names
|
|
89
|
+
ObjectProperty: ([key]) => key !== "key",
|
|
90
|
+
// Ignore variable declaration's name
|
|
91
|
+
VariableDeclarator: ([key]) => key !== "id"
|
|
92
|
+
};
|
|
93
|
+
queue.push(
|
|
94
|
+
Object.entries(item).filter(filterFns[item.type] ?? (() => true)).map(([_, value]) => value)
|
|
95
|
+
);
|
|
35
96
|
}
|
|
36
97
|
}
|
|
37
|
-
|
|
38
|
-
if (!used) delete mod.imports[name];
|
|
39
|
-
}
|
|
98
|
+
return usedMap;
|
|
40
99
|
}
|
|
41
100
|
function deleteImportAst(mod, shouldDelete) {
|
|
42
101
|
const importIndexesToDelete = [];
|
package/dist/core/wxt.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { createViteBuilder } from "./builders/vite/index.mjs";
|
|
|
5
5
|
import { builtinModules } from "../builtin-modules/index.mjs";
|
|
6
6
|
export let wxt;
|
|
7
7
|
export async function registerWxt(command, inlineConfig = {}, getServer) {
|
|
8
|
+
process.env.NODE_ENV ??= command === "serve" ? "development" : "production";
|
|
8
9
|
const hooks = createHooks();
|
|
9
10
|
const config = await resolveConfig(inlineConfig, command);
|
|
10
11
|
const server = await getServer?.(config);
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.19.
|
|
1
|
+
export const version = "0.19.2";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.2",
|
|
5
5
|
"description": "Next gen framework for developing web extensions",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -105,20 +105,20 @@
|
|
|
105
105
|
"picocolors": "^1.0.1",
|
|
106
106
|
"prompts": "^2.4.2",
|
|
107
107
|
"publish-browser-extension": "^2.1.3",
|
|
108
|
-
"unimport": "^3.9.
|
|
109
|
-
"vite": "^5.3.
|
|
110
|
-
"vite-node": "^2.0.
|
|
108
|
+
"unimport": "^3.9.1",
|
|
109
|
+
"vite": "^5.3.5",
|
|
110
|
+
"vite-node": "^2.0.4",
|
|
111
111
|
"web-ext-run": "^0.2.1",
|
|
112
112
|
"webextension-polyfill": "^0.12.0"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@aklinker1/check": "^1.3.1",
|
|
116
116
|
"@faker-js/faker": "^8.4.1",
|
|
117
|
-
"@types/chrome": "^0.0.
|
|
117
|
+
"@types/chrome": "^0.0.269",
|
|
118
118
|
"@types/fs-extra": "^11.0.4",
|
|
119
119
|
"@types/lodash.merge": "^4.6.9",
|
|
120
120
|
"@types/natural-compare": "^1.4.3",
|
|
121
|
-
"@types/node": "^20.14.
|
|
121
|
+
"@types/node": "^20.14.12",
|
|
122
122
|
"@types/normalize-path": "^3.0.2",
|
|
123
123
|
"@types/prompts": "^2.4.9",
|
|
124
124
|
"execa": "^9.3.0",
|
|
@@ -128,9 +128,9 @@
|
|
|
128
128
|
"p-map": "^7.0.2",
|
|
129
129
|
"publint": "^0.2.9",
|
|
130
130
|
"tsx": "4.15.7",
|
|
131
|
-
"typescript": "^5.5.
|
|
131
|
+
"typescript": "^5.5.4",
|
|
132
132
|
"unbuild": "^2.0.0",
|
|
133
|
-
"vitest": "^2.0.
|
|
133
|
+
"vitest": "^2.0.4",
|
|
134
134
|
"vitest-plugin-random-seed": "^1.1.0"
|
|
135
135
|
},
|
|
136
136
|
"peerDependencies": {
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"scripts": {
|
|
145
145
|
"wxt": "tsx src/cli/index.ts",
|
|
146
146
|
"build": "buildc -- unbuild",
|
|
147
|
-
"check": "
|
|
147
|
+
"check": "pnpm build && run-s -c check:*",
|
|
148
148
|
"check:default": "check",
|
|
149
149
|
"check:tsc-virtual": "tsc --noEmit -p src/virtual",
|
|
150
150
|
"test": "buildc --deps-only -- vitest",
|