wxt 0.19.0 → 0.19.1-alpha2
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/dist/core/builders/vite/index.mjs +1 -4
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +5 -2
- package/dist/core/utils/building/find-entrypoints.mjs +45 -41
- package/dist/core/utils/environments/browser-environment.d.ts +3 -0
- package/dist/core/utils/environments/browser-environment.mjs +19 -0
- package/dist/core/utils/environments/environment.d.ts +8 -0
- package/dist/core/utils/environments/environment.mjs +36 -0
- package/dist/core/utils/environments/extension-environment.d.ts +6 -0
- package/dist/core/utils/environments/extension-environment.mjs +13 -0
- package/dist/core/utils/environments/index.d.ts +2 -0
- package/dist/core/utils/environments/index.mjs +2 -0
- package/dist/version.mjs +1 -1
- package/package.json +1 -1
|
@@ -172,10 +172,7 @@ export async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
172
172
|
baseConfig.optimizeDeps.noDiscovery = true;
|
|
173
173
|
baseConfig.optimizeDeps.include = [];
|
|
174
174
|
const envConfig = {
|
|
175
|
-
plugins: [
|
|
176
|
-
wxtPlugins.extensionApiMock(wxtConfig),
|
|
177
|
-
wxtPlugins.removeEntrypointMainFunction(wxtConfig, path)
|
|
178
|
-
]
|
|
175
|
+
plugins: [wxtPlugins.removeEntrypointMainFunction(wxtConfig, path)]
|
|
179
176
|
};
|
|
180
177
|
const config = vite.mergeConfig(baseConfig, envConfig);
|
|
181
178
|
const server2 = await vite.createServer(config);
|
|
@@ -5,8 +5,11 @@ export function removeEntrypointMainFunction(config, path) {
|
|
|
5
5
|
const absPath = normalizePath(resolve(config.root, path));
|
|
6
6
|
return {
|
|
7
7
|
name: "wxt:remove-entrypoint-main-function",
|
|
8
|
-
transform
|
|
9
|
-
|
|
8
|
+
transform: {
|
|
9
|
+
order: "pre",
|
|
10
|
+
handler(code, id) {
|
|
11
|
+
if (id === absPath) return removeMainFunctionCode(code);
|
|
12
|
+
}
|
|
10
13
|
}
|
|
11
14
|
};
|
|
12
15
|
}
|
|
@@ -12,6 +12,7 @@ import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../utils/constants.mjs";
|
|
|
12
12
|
import { CSS_EXTENSIONS_PATTERN } from "../../utils/paths.mjs";
|
|
13
13
|
import pc from "picocolors";
|
|
14
14
|
import { wxt } from "../../wxt.mjs";
|
|
15
|
+
import { createExtensionEnvironment } from "../environments/index.mjs";
|
|
15
16
|
export async function findEntrypoints() {
|
|
16
17
|
await fs.mkdir(wxt.config.wxtDir, { recursive: true });
|
|
17
18
|
await fs.writeJson(resolve(wxt.config.wxtDir, "tsconfig.json"), {});
|
|
@@ -40,47 +41,50 @@ export async function findEntrypoints() {
|
|
|
40
41
|
preventNoEntrypoints(entrypointInfos);
|
|
41
42
|
preventDuplicateEntrypointNames(entrypointInfos);
|
|
42
43
|
let hasBackground = false;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
44
|
+
const env = createExtensionEnvironment();
|
|
45
|
+
const entrypoints = await env.run(
|
|
46
|
+
() => Promise.all(
|
|
47
|
+
entrypointInfos.map(async (info) => {
|
|
48
|
+
const { type } = info;
|
|
49
|
+
switch (type) {
|
|
50
|
+
case "popup":
|
|
51
|
+
return await getPopupEntrypoint(info);
|
|
52
|
+
case "sidepanel":
|
|
53
|
+
return await getSidepanelEntrypoint(info);
|
|
54
|
+
case "options":
|
|
55
|
+
return await getOptionsEntrypoint(info);
|
|
56
|
+
case "background":
|
|
57
|
+
hasBackground = true;
|
|
58
|
+
return await getBackgroundEntrypoint(info);
|
|
59
|
+
case "content-script":
|
|
60
|
+
return await getContentScriptEntrypoint(info);
|
|
61
|
+
case "unlisted-page":
|
|
62
|
+
return await getUnlistedPageEntrypoint(info);
|
|
63
|
+
case "unlisted-script":
|
|
64
|
+
return await getUnlistedScriptEntrypoint(info);
|
|
65
|
+
case "content-script-style":
|
|
66
|
+
return {
|
|
67
|
+
...info,
|
|
68
|
+
type,
|
|
69
|
+
outputDir: resolve(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
70
|
+
options: {
|
|
71
|
+
include: void 0,
|
|
72
|
+
exclude: void 0
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
default:
|
|
76
|
+
return {
|
|
77
|
+
...info,
|
|
78
|
+
type,
|
|
79
|
+
outputDir: wxt.config.outDir,
|
|
80
|
+
options: {
|
|
81
|
+
include: void 0,
|
|
82
|
+
exclude: void 0
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
)
|
|
84
88
|
);
|
|
85
89
|
if (wxt.config.command === "serve" && !hasBackground) {
|
|
86
90
|
entrypoints.push(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseHTML } from "linkedom";
|
|
2
|
+
import { createEnvironment } from "./environment.mjs";
|
|
3
|
+
export function createBrowserEnvironment() {
|
|
4
|
+
return createEnvironment(getBrowserEnvironmentGlobals);
|
|
5
|
+
}
|
|
6
|
+
export function getBrowserEnvironmentGlobals() {
|
|
7
|
+
const { window, document, global } = parseHTML(`
|
|
8
|
+
<html>
|
|
9
|
+
<head></head>
|
|
10
|
+
<body></body>
|
|
11
|
+
</html>
|
|
12
|
+
`);
|
|
13
|
+
return {
|
|
14
|
+
...global,
|
|
15
|
+
window,
|
|
16
|
+
document,
|
|
17
|
+
self: global
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface Environment {
|
|
2
|
+
setup: () => () => void;
|
|
3
|
+
run: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
4
|
+
}
|
|
5
|
+
export declare function createEnvironment(getGlobals: () => EnvGlobals): Environment;
|
|
6
|
+
export type EnvGlobals = Record<string, any>;
|
|
7
|
+
export declare function getOgGlobals(envGlobals: EnvGlobals): EnvGlobals;
|
|
8
|
+
export declare function applyGlobals(globals: EnvGlobals): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function createEnvironment(getGlobals) {
|
|
2
|
+
const setup = () => {
|
|
3
|
+
const envGlobals = getGlobals();
|
|
4
|
+
const ogGlobals = getOgGlobals(envGlobals);
|
|
5
|
+
applyGlobals(envGlobals);
|
|
6
|
+
return () => {
|
|
7
|
+
applyGlobals(ogGlobals);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const run = async (fn) => {
|
|
11
|
+
const teardown = setup();
|
|
12
|
+
try {
|
|
13
|
+
return await fn();
|
|
14
|
+
} finally {
|
|
15
|
+
teardown();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
setup,
|
|
20
|
+
run
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function getOgGlobals(envGlobals) {
|
|
24
|
+
return Object.keys(envGlobals).reduce((acc, key) => {
|
|
25
|
+
acc[key] = globalThis[key];
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
}
|
|
29
|
+
export function applyGlobals(globals) {
|
|
30
|
+
Object.entries(globals).forEach(([key, envValue]) => {
|
|
31
|
+
try {
|
|
32
|
+
globalThis[key] = envValue;
|
|
33
|
+
} catch (err) {
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Environment } from './environment';
|
|
2
|
+
export declare function createExtensionEnvironment(): Environment;
|
|
3
|
+
export declare function getExtensionEnvironmentGlobals(): {
|
|
4
|
+
chrome: import("@webext-core/fake-browser").FakeBrowser;
|
|
5
|
+
browser: import("@webext-core/fake-browser").FakeBrowser;
|
|
6
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fakeBrowser } from "@webext-core/fake-browser";
|
|
2
|
+
import { getBrowserEnvironmentGlobals } from "./browser-environment.mjs";
|
|
3
|
+
import { createEnvironment } from "./environment.mjs";
|
|
4
|
+
export function createExtensionEnvironment() {
|
|
5
|
+
return createEnvironment(getExtensionEnvironmentGlobals);
|
|
6
|
+
}
|
|
7
|
+
export function getExtensionEnvironmentGlobals() {
|
|
8
|
+
return {
|
|
9
|
+
...getBrowserEnvironmentGlobals(),
|
|
10
|
+
chrome: fakeBrowser,
|
|
11
|
+
browser: fakeBrowser
|
|
12
|
+
};
|
|
13
|
+
}
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.19.
|
|
1
|
+
export const version = "0.19.1-alpha2";
|