wxt 0.19.29 → 0.20.0-beta2
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/browser.d.ts +30 -0
- package/dist/browser.mjs +3 -0
- package/dist/builtin-modules/unimport.mjs +29 -10
- package/dist/cli/index.mjs +0 -1
- package/dist/core/builders/vite/index.mjs +17 -37
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +1 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +2 -4
- package/dist/core/builders/vite/plugins/index.d.ts +0 -1
- package/dist/core/builders/vite/plugins/index.mjs +0 -1
- package/dist/core/builders/vite/plugins/noopBackground.mjs +1 -1
- package/dist/core/define-web-ext-config.d.ts +9 -0
- package/dist/core/define-web-ext-config.mjs +10 -0
- package/dist/core/generate-wxt-dir.mjs +3 -6
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.mjs +1 -1
- package/dist/core/resolve-config.mjs +142 -49
- package/dist/core/utils/building/index.d.ts +0 -1
- package/dist/core/utils/building/index.mjs +0 -1
- package/dist/core/utils/building/rebuild.d.ts +2 -2
- package/dist/core/utils/content-scripts.d.ts +4 -3
- package/dist/core/utils/content-scripts.mjs +2 -0
- package/dist/core/utils/manifest.d.ts +4 -8
- package/dist/core/utils/manifest.mjs +4 -7
- package/dist/core/utils/strings.d.ts +0 -4
- package/dist/core/utils/strings.mjs +0 -6
- package/dist/core/utils/testing/fake-objects.d.ts +3376 -1013
- package/dist/core/utils/testing/fake-objects.mjs +19 -22
- package/dist/core/utils/transform.d.ts +1 -1
- package/dist/core/utils/types.d.ts +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/modules.d.ts +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/wxt-vitest-plugin.mjs +1 -3
- package/dist/types.d.ts +42 -76
- package/dist/utils/app-config.d.ts +2 -0
- package/dist/{client/content-scripts → utils}/content-script-context.d.ts +4 -3
- package/dist/{client/content-scripts → utils}/content-script-context.mjs +5 -3
- package/dist/utils/content-script-ui/iframe.d.ts +32 -0
- package/dist/utils/content-script-ui/iframe.mjs +30 -0
- package/dist/utils/content-script-ui/integrated.d.ts +34 -0
- package/dist/utils/content-script-ui/integrated.mjs +32 -0
- package/dist/utils/content-script-ui/shadow-root.d.ts +76 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +73 -0
- package/dist/utils/content-script-ui/shared.d.ts +5 -0
- package/dist/{client/content-scripts/ui/index.mjs → utils/content-script-ui/shared.mjs} +5 -138
- package/dist/{client/content-scripts/ui → utils/content-script-ui}/types.d.ts +1 -96
- package/dist/{sandbox → utils}/define-app-config.d.ts +3 -2
- package/dist/{sandbox → utils}/define-background.d.ts +1 -0
- package/dist/{sandbox → utils}/define-content-script.d.ts +1 -0
- package/dist/{sandbox → utils}/define-unlisted-script.d.ts +1 -0
- package/dist/{sandbox → utils}/define-wxt-plugin.d.ts +1 -0
- package/dist/{sandbox → utils/internal}/dev-server-websocket.mjs +1 -1
- package/dist/{client/content-scripts → utils/internal}/location-watcher.d.ts +1 -1
- package/dist/utils/match-patterns.d.ts +5 -0
- package/dist/utils/match-patterns.mjs +1 -0
- package/dist/utils/storage.d.ts +5 -0
- package/dist/version.mjs +1 -1
- package/dist/virtual/background-entrypoint.mjs +1 -1
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +1 -1
- package/package.json +109 -76
- package/dist/browser/chrome.d.ts +0 -13
- package/dist/browser/chrome.mjs +0 -7
- package/dist/browser/index.d.ts +0 -26
- package/dist/browser/index.mjs +0 -2
- package/dist/client/app-config.d.ts +0 -2
- package/dist/client/content-scripts/index.d.ts +0 -2
- package/dist/client/content-scripts/index.mjs +0 -2
- package/dist/client/content-scripts/ui/index.d.ts +0 -23
- package/dist/client/index.d.ts +0 -8
- package/dist/client/index.mjs +0 -3
- package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +0 -10
- package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +0 -15
- package/dist/core/define-runner-config.d.ts +0 -2
- package/dist/core/define-runner-config.mjs +0 -3
- package/dist/core/utils/building/import-entrypoint.d.ts +0 -16
- package/dist/core/utils/building/import-entrypoint.mjs +0 -99
- package/dist/sandbox/index.d.ts +0 -11
- package/dist/sandbox/index.mjs +0 -6
- package/dist/storage.d.ts +0 -4
- /package/dist/{client → utils}/app-config.mjs +0 -0
- /package/dist/{client/content-scripts/ui → utils/content-script-ui}/types.mjs +0 -0
- /package/dist/{sandbox → utils}/define-app-config.mjs +0 -0
- /package/dist/{sandbox → utils}/define-background.mjs +0 -0
- /package/dist/{sandbox → utils}/define-content-script.mjs +0 -0
- /package/dist/{sandbox → utils}/define-unlisted-script.mjs +0 -0
- /package/dist/{sandbox → utils}/define-wxt-plugin.mjs +0 -0
- /package/dist/{client → utils}/inject-script.d.ts +0 -0
- /package/dist/{client → utils}/inject-script.mjs +0 -0
- /package/dist/{client/content-scripts → utils/internal}/custom-events.d.ts +0 -0
- /package/dist/{client/content-scripts → utils/internal}/custom-events.mjs +0 -0
- /package/dist/{sandbox → utils/internal}/dev-server-websocket.d.ts +0 -0
- /package/dist/{client/content-scripts → utils/internal}/location-watcher.mjs +0 -0
- /package/dist/{sandbox/utils → utils/internal}/logger.d.ts +0 -0
- /package/dist/{sandbox/utils → utils/internal}/logger.mjs +0 -0
- /package/dist/{storage.mjs → utils/storage.mjs} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains the `browser` export which you should use to access the extension APIs in your project:
|
|
3
|
+
* ```ts
|
|
4
|
+
* import { browser } from 'wxt/browser';
|
|
5
|
+
*
|
|
6
|
+
* browser.runtime.onInstalled.addListener(() => {
|
|
7
|
+
* // ...
|
|
8
|
+
* })
|
|
9
|
+
* ```
|
|
10
|
+
* @module wxt/browser
|
|
11
|
+
*/
|
|
12
|
+
import { browser as _browser, type Browser } from '@wxt-dev/browser';
|
|
13
|
+
/**
|
|
14
|
+
* This interface is empty because it is generated per-project when running `wxt prepare`. See:
|
|
15
|
+
* - `.wxt/types/paths.d.ts`
|
|
16
|
+
*/
|
|
17
|
+
export interface WxtRuntime {
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* This interface is empty because it is generated per-project when running `wxt prepare`. See:
|
|
21
|
+
* - `.wxt/types/i18n.d.ts`
|
|
22
|
+
*/
|
|
23
|
+
export interface WxtI18n {
|
|
24
|
+
}
|
|
25
|
+
export type WxtBrowser = Omit<typeof _browser, 'runtime' | 'i18n'> & {
|
|
26
|
+
runtime: WxtRuntime & Omit<(typeof _browser)['runtime'], 'getURL'>;
|
|
27
|
+
i18n: WxtI18n & Omit<(typeof _browser)['i18n'], 'getMessage'>;
|
|
28
|
+
};
|
|
29
|
+
export declare const browser: WxtBrowser;
|
|
30
|
+
export { Browser };
|
package/dist/browser.mjs
ADDED
|
@@ -1,41 +1,45 @@
|
|
|
1
1
|
import { addViteConfig, defineWxtModule } from "../modules.mjs";
|
|
2
|
-
import { createUnimport } from "unimport";
|
|
2
|
+
import { createUnimport, toExports } from "unimport";
|
|
3
3
|
import UnimportPlugin from "unimport/unplugin";
|
|
4
4
|
export default defineWxtModule({
|
|
5
5
|
name: "wxt:built-in:unimport",
|
|
6
6
|
setup(wxt) {
|
|
7
|
-
const options = wxt.config.imports;
|
|
8
|
-
if (options === false) return;
|
|
9
7
|
let unimport;
|
|
8
|
+
const isEnabled = () => !wxt.config.imports.disabled;
|
|
10
9
|
wxt.hooks.hook("config:resolved", () => {
|
|
11
10
|
const addModuleImports = (module) => {
|
|
12
11
|
if (!module.imports) return;
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
wxt.config.imports.imports ??= [];
|
|
13
|
+
wxt.config.imports.imports.push(...module.imports);
|
|
15
14
|
};
|
|
16
15
|
wxt.config.builtinModules.forEach(addModuleImports);
|
|
17
16
|
wxt.config.userModules.forEach(addModuleImports);
|
|
18
17
|
});
|
|
19
18
|
wxt.hooks.afterEach((event) => {
|
|
20
19
|
if (event.name === "config:resolved") {
|
|
21
|
-
unimport = createUnimport(
|
|
20
|
+
unimport = createUnimport(wxt.config.imports);
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
wxt.hooks.hook("prepare:types", async (_, entries) => {
|
|
25
24
|
await unimport.init();
|
|
25
|
+
entries.push(await getImportsModuleEntry(wxt, unimport));
|
|
26
|
+
if (!isEnabled()) return;
|
|
26
27
|
entries.push(await getImportsDeclarationEntry(unimport));
|
|
27
|
-
if (
|
|
28
|
+
if (wxt.config.imports.eslintrc.enabled === false) return;
|
|
28
29
|
entries.push(
|
|
29
|
-
await getEslintConfigEntry(
|
|
30
|
+
await getEslintConfigEntry(
|
|
31
|
+
unimport,
|
|
32
|
+
wxt.config.imports.eslintrc.enabled,
|
|
33
|
+
wxt.config.imports
|
|
34
|
+
)
|
|
30
35
|
);
|
|
31
36
|
});
|
|
32
37
|
addViteConfig(wxt, () => ({
|
|
33
|
-
plugins: [UnimportPlugin.vite(
|
|
38
|
+
plugins: [UnimportPlugin.vite(wxt.config.imports)]
|
|
34
39
|
}));
|
|
35
40
|
}
|
|
36
41
|
});
|
|
37
42
|
async function getImportsDeclarationEntry(unimport) {
|
|
38
|
-
await unimport.init();
|
|
39
43
|
return {
|
|
40
44
|
path: "types/imports.d.ts",
|
|
41
45
|
text: [
|
|
@@ -46,6 +50,21 @@ async function getImportsDeclarationEntry(unimport) {
|
|
|
46
50
|
tsReference: true
|
|
47
51
|
};
|
|
48
52
|
}
|
|
53
|
+
async function getImportsModuleEntry(wxt, unimport) {
|
|
54
|
+
const imports = await unimport.getImports();
|
|
55
|
+
return {
|
|
56
|
+
path: "types/imports-module.d.ts",
|
|
57
|
+
text: [
|
|
58
|
+
"// Generated by wxt",
|
|
59
|
+
"// Types for the #import virtual module",
|
|
60
|
+
"declare module '#imports' {",
|
|
61
|
+
` ${toExports(imports, wxt.config.wxtDir, true).replaceAll("\n", "\n ")}`,
|
|
62
|
+
"}",
|
|
63
|
+
""
|
|
64
|
+
].join("\n"),
|
|
65
|
+
tsReference: true
|
|
66
|
+
};
|
|
67
|
+
}
|
|
49
68
|
async function getEslintConfigEntry(unimport, version, options) {
|
|
50
69
|
const globals = (await unimport.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().reduce((globals2, name) => {
|
|
51
70
|
globals2[name] = options.eslintrc.globalsPropValue;
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import cli from "./commands.mjs";
|
|
2
2
|
import { version } from "../version.mjs";
|
|
3
3
|
import { isAliasedCommand } from "./cli-utils.mjs";
|
|
4
|
-
process.env.VITE_CJS_IGNORE_WARNING = "true";
|
|
5
4
|
cli.parse(process.argv, { run: false });
|
|
6
5
|
if (!isAliasedCommand(cli.matchedCommand)) {
|
|
7
6
|
cli.help();
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
} from "../../utils/entrypoints.mjs";
|
|
6
6
|
import { toArray } from "../../utils/arrays.mjs";
|
|
7
7
|
import { safeVarName } from "../../utils/strings.mjs";
|
|
8
|
-
import { importEntrypointFile } from "../../utils/building/index.mjs";
|
|
9
8
|
import { ViteNodeServer } from "vite-node/server";
|
|
10
9
|
import { ViteNodeRunner } from "vite-node/client";
|
|
11
10
|
import { installSourcemapsSupport } from "vite-node/source-map";
|
|
@@ -47,7 +46,6 @@ export async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
47
46
|
wxtPlugins.tsconfigPaths(wxtConfig),
|
|
48
47
|
wxtPlugins.noopBackground(),
|
|
49
48
|
wxtPlugins.globals(wxtConfig),
|
|
50
|
-
wxtPlugins.resolveExtensionApi(wxtConfig),
|
|
51
49
|
wxtPlugins.defineImportMeta(),
|
|
52
50
|
wxtPlugins.wxtPluginLoader(wxtConfig),
|
|
53
51
|
wxtPlugins.resolveAppConfig(wxtConfig)
|
|
@@ -216,44 +214,26 @@ export async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
216
214
|
version: vite.version,
|
|
217
215
|
async importEntrypoint(path) {
|
|
218
216
|
const env = createExtensionEnvironment();
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
case "vite-node": {
|
|
225
|
-
const { runner, server } = await createViteNodeImporter([path]);
|
|
226
|
-
const res = await env.run(() => runner.executeFile(path));
|
|
227
|
-
await server.close();
|
|
228
|
-
requireDefaultExport(path, res);
|
|
229
|
-
return res.default;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
217
|
+
const { runner, server } = await createViteNodeImporter([path]);
|
|
218
|
+
const res = await env.run(() => runner.executeFile(path));
|
|
219
|
+
await server.close();
|
|
220
|
+
requireDefaultExport(path, res);
|
|
221
|
+
return res.default;
|
|
232
222
|
},
|
|
233
223
|
async importEntrypoints(paths) {
|
|
234
224
|
const env = createExtensionEnvironment();
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const mod = await runner.executeFile(path);
|
|
248
|
-
requireDefaultExport(path, mod);
|
|
249
|
-
return mod.default;
|
|
250
|
-
})
|
|
251
|
-
)
|
|
252
|
-
);
|
|
253
|
-
await server.close();
|
|
254
|
-
return res;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
225
|
+
const { runner, server } = await createViteNodeImporter(paths);
|
|
226
|
+
const res = await env.run(
|
|
227
|
+
() => Promise.all(
|
|
228
|
+
paths.map(async (path) => {
|
|
229
|
+
const mod = await runner.executeFile(path);
|
|
230
|
+
requireDefaultExport(path, mod);
|
|
231
|
+
return mod.default;
|
|
232
|
+
})
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
await server.close();
|
|
236
|
+
return res;
|
|
257
237
|
},
|
|
258
238
|
async build(group) {
|
|
259
239
|
let entryConfig;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
2
|
import { ResolvedConfig } from '../../../../types';
|
|
3
3
|
/**
|
|
4
|
-
* Mock `
|
|
5
|
-
* all dependencies that import them and adding a custom alias so that Vite
|
|
6
|
-
* resolves to a mocked version of the module.
|
|
7
|
-
*
|
|
8
|
-
* TODO: Detect non-wxt dependencies (like `@webext-core/*`) that import `webextension-polyfill` via
|
|
9
|
-
* `npm list` and inline them automatically.
|
|
4
|
+
* Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake version of the extension APIs
|
|
10
5
|
*/
|
|
11
6
|
export declare function extensionApiMock(config: ResolvedConfig): vite.PluginOption;
|
|
@@ -15,14 +15,12 @@ export function extensionApiMock(config) {
|
|
|
15
15
|
},
|
|
16
16
|
resolve: {
|
|
17
17
|
alias: [
|
|
18
|
-
{ find: "webextension-polyfill", replacement },
|
|
19
18
|
// wxt/browser, wxt/browser/...
|
|
20
|
-
{ find:
|
|
19
|
+
{ find: "wxt/browser", replacement }
|
|
21
20
|
]
|
|
22
21
|
},
|
|
23
22
|
ssr: {
|
|
24
|
-
// Inline all WXT modules
|
|
25
|
-
// be resolved
|
|
23
|
+
// Inline all WXT modules subdependencies can be mocked
|
|
26
24
|
noExternal: ["wxt"]
|
|
27
25
|
}
|
|
28
26
|
};
|
|
@@ -9,7 +9,6 @@ export * from './cssEntrypoints';
|
|
|
9
9
|
export * from './bundleAnalysis';
|
|
10
10
|
export * from './globals';
|
|
11
11
|
export * from './extensionApiMock';
|
|
12
|
-
export * from './resolveExtensionApi';
|
|
13
12
|
export * from './entrypointGroupGlobals';
|
|
14
13
|
export * from './defineImportMeta';
|
|
15
14
|
export * from './removeEntrypointMainFunction';
|
|
@@ -9,7 +9,6 @@ export * from "./cssEntrypoints.mjs";
|
|
|
9
9
|
export * from "./bundleAnalysis.mjs";
|
|
10
10
|
export * from "./globals.mjs";
|
|
11
11
|
export * from "./extensionApiMock.mjs";
|
|
12
|
-
export * from "./resolveExtensionApi.mjs";
|
|
13
12
|
export * from "./entrypointGroupGlobals.mjs";
|
|
14
13
|
export * from "./defineImportMeta.mjs";
|
|
15
14
|
export * from "./removeEntrypointMainFunction.mjs";
|
|
@@ -9,7 +9,7 @@ export function noopBackground() {
|
|
|
9
9
|
},
|
|
10
10
|
load(id) {
|
|
11
11
|
if (id === resolvedVirtualModuleId) {
|
|
12
|
-
return `import { defineBackground } from 'wxt/
|
|
12
|
+
return `import { defineBackground } from 'wxt/utils/define-background';
|
|
13
13
|
export default defineBackground(() => void 0)`;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebExtConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use `defineWebExtConfig` instead. Same function, different name.
|
|
4
|
+
*/
|
|
5
|
+
export declare function defineRunnerConfig(config: WebExtConfig): WebExtConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the browser during development.
|
|
8
|
+
*/
|
|
9
|
+
export declare function defineWebExtConfig(config: WebExtConfig): WebExtConfig;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import consola from "consola";
|
|
2
|
+
export function defineRunnerConfig(config) {
|
|
3
|
+
consola.warn(
|
|
4
|
+
"`defineRunnerConfig` is deprecated, use `defineWebExtConfig` instead. See https://wxt.dev/guide/resources/upgrading.html#v0-19-0-rarr-v0-20-0"
|
|
5
|
+
);
|
|
6
|
+
return defineWebExtConfig(config);
|
|
7
|
+
}
|
|
8
|
+
export function defineWebExtConfig(config) {
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
@@ -19,9 +19,6 @@ export async function generateWxtDir(entrypoints) {
|
|
|
19
19
|
entries.push(await getPathsDeclarationEntry(entrypoints));
|
|
20
20
|
entries.push(await getI18nDeclarationEntry());
|
|
21
21
|
entries.push(await getGlobalsDeclarationEntry());
|
|
22
|
-
if (wxt.config.extensionApi === "chrome") {
|
|
23
|
-
entries.push({ module: "@types/chrome" });
|
|
24
|
-
}
|
|
25
22
|
entries.push(await getTsConfigEntry());
|
|
26
23
|
await wxt.hooks.callHook("prepare:types", wxt, entries);
|
|
27
24
|
entries.push(getMainDeclarationEntry(entries));
|
|
@@ -180,10 +177,10 @@ async function getTsConfigEntry() {
|
|
|
180
177
|
const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
181
178
|
const aliasPath = getTsconfigPath(absolutePath);
|
|
182
179
|
return [
|
|
183
|
-
`
|
|
184
|
-
`
|
|
180
|
+
`"${alias}": ["${aliasPath}"]`,
|
|
181
|
+
`"${alias}/*": ["${aliasPath}/*"]`
|
|
185
182
|
];
|
|
186
|
-
}).join(",\n");
|
|
183
|
+
}).map((line) => ` ${line}`).join(",\n");
|
|
187
184
|
const text = `{
|
|
188
185
|
"compilerOptions": {
|
|
189
186
|
"target": "ESNext",
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './build';
|
|
2
2
|
export * from './clean';
|
|
3
3
|
export * from './define-config';
|
|
4
|
-
export * from './define-
|
|
4
|
+
export * from './define-web-ext-config';
|
|
5
5
|
export * from './create-server';
|
|
6
6
|
export * from './initialize';
|
|
7
7
|
export * from './prepare';
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./build.mjs";
|
|
2
2
|
export * from "./clean.mjs";
|
|
3
3
|
export * from "./define-config.mjs";
|
|
4
|
-
export * from "./define-
|
|
4
|
+
export * from "./define-web-ext-config.mjs";
|
|
5
5
|
export * from "./create-server.mjs";
|
|
6
6
|
export * from "./initialize.mjs";
|
|
7
7
|
export * from "./prepare.mjs";
|
|
@@ -48,28 +48,34 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
48
48
|
srcDir,
|
|
49
49
|
mergedConfig.entrypointsDir ?? "entrypoints"
|
|
50
50
|
);
|
|
51
|
-
const modulesDir = path.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
|
|
52
51
|
if (await isDirMissing(entrypointsDir)) {
|
|
53
52
|
logMissingDir(logger, "Entrypoints", entrypointsDir);
|
|
54
53
|
}
|
|
54
|
+
const modulesDir = path.resolve(root, mergedConfig.modulesDir ?? "modules");
|
|
55
55
|
const filterEntrypoints = mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
|
|
56
|
-
const publicDir = path.resolve(
|
|
56
|
+
const publicDir = path.resolve(root, mergedConfig.publicDir ?? "public");
|
|
57
57
|
const typesDir = path.resolve(wxtDir, "types");
|
|
58
58
|
const outBaseDir = path.resolve(root, mergedConfig.outDir ?? ".output");
|
|
59
59
|
const modeSuffixes = {
|
|
60
60
|
production: "",
|
|
61
61
|
development: "-dev"
|
|
62
62
|
};
|
|
63
|
-
const
|
|
63
|
+
const modeSuffix = modeSuffixes[mode] ?? `-${mode}`;
|
|
64
|
+
const outDirTemplate = (mergedConfig.outDirTemplate ?? `${browser}-mv${manifestVersion}${modeSuffix}`).replaceAll("{{browser}}", browser).replaceAll("{{manifestVersion}}", manifestVersion.toString()).replaceAll("{{modeSuffix}}", modeSuffix).replaceAll("{{mode}}", mode).replaceAll("{{command}}", command);
|
|
64
65
|
const outDir = path.resolve(outBaseDir, outDirTemplate);
|
|
65
66
|
const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
|
|
67
|
+
if (inlineConfig.runner != null || userConfig.runner != null) {
|
|
68
|
+
logger.warn(
|
|
69
|
+
"`InlineConfig#runner` is deprecated, use `InlineConfig#webExt` instead. See https://wxt.dev/guide/resources/upgrading.html#v0-19-0-rarr-v0-20-0"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
66
72
|
const runnerConfig = await loadConfig({
|
|
67
73
|
name: "web-ext",
|
|
68
74
|
cwd: root,
|
|
69
75
|
globalRc: true,
|
|
70
76
|
rcFile: ".webextrc",
|
|
71
|
-
overrides: inlineConfig.runner,
|
|
72
|
-
defaults: userConfig.runner
|
|
77
|
+
overrides: inlineConfig.webExt ?? inlineConfig.runner,
|
|
78
|
+
defaults: userConfig.webExt ?? userConfig.runner
|
|
73
79
|
});
|
|
74
80
|
const alias = Object.fromEntries(
|
|
75
81
|
Object.entries({
|
|
@@ -113,7 +119,6 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
113
119
|
},
|
|
114
120
|
{}
|
|
115
121
|
);
|
|
116
|
-
const extensionApi = mergedConfig.extensionApi ?? "webextension-polyfill";
|
|
117
122
|
return {
|
|
118
123
|
browser,
|
|
119
124
|
command,
|
|
@@ -123,13 +128,7 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
123
128
|
filterEntrypoints,
|
|
124
129
|
env,
|
|
125
130
|
fsCache: createFsCache(wxtDir),
|
|
126
|
-
imports: await getUnimportOptions(
|
|
127
|
-
wxtDir,
|
|
128
|
-
srcDir,
|
|
129
|
-
logger,
|
|
130
|
-
extensionApi,
|
|
131
|
-
mergedConfig
|
|
132
|
-
),
|
|
131
|
+
imports: await getUnimportOptions(wxtDir, srcDir, logger, mergedConfig),
|
|
133
132
|
logger,
|
|
134
133
|
manifest: await resolveManifestConfig(env, mergedConfig.manifest),
|
|
135
134
|
manifestVersion,
|
|
@@ -144,12 +143,9 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
144
143
|
typesDir,
|
|
145
144
|
wxtDir,
|
|
146
145
|
zip: resolveZipConfig(root, browser, outBaseDir, mergedConfig),
|
|
147
|
-
transformManifest: mergedConfig.transformManifest,
|
|
148
146
|
analysis: resolveAnalysisConfig(root, mergedConfig),
|
|
149
147
|
userConfigMetadata: userConfigMetadata ?? {},
|
|
150
148
|
alias,
|
|
151
|
-
extensionApi,
|
|
152
|
-
entrypointLoader: mergedConfig.entrypointLoader ?? "vite-node",
|
|
153
149
|
experimental: defu(mergedConfig.experimental, {}),
|
|
154
150
|
dev: {
|
|
155
151
|
server: devServerConfig,
|
|
@@ -173,10 +169,6 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
|
|
|
173
169
|
const inline = await resolveManifestConfig(env, inlineConfig.manifest);
|
|
174
170
|
return defu(inline, user);
|
|
175
171
|
};
|
|
176
|
-
const transformManifest = (manifest2) => {
|
|
177
|
-
userConfig.transformManifest?.(manifest2);
|
|
178
|
-
inlineConfig.transformManifest?.(manifest2);
|
|
179
|
-
};
|
|
180
172
|
const merged = defu(inlineConfig, userConfig);
|
|
181
173
|
const builderConfig = await mergeBuilderConfig(
|
|
182
174
|
merged.logger ?? consola,
|
|
@@ -186,7 +178,6 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
|
|
|
186
178
|
return {
|
|
187
179
|
...merged,
|
|
188
180
|
// Custom merge values
|
|
189
|
-
transformManifest,
|
|
190
181
|
imports,
|
|
191
182
|
manifest,
|
|
192
183
|
...builderConfig
|
|
@@ -239,34 +230,136 @@ function resolveAnalysisConfig(root, mergedConfig) {
|
|
|
239
230
|
keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
|
|
240
231
|
};
|
|
241
232
|
}
|
|
242
|
-
async function getUnimportOptions(wxtDir, srcDir, logger,
|
|
243
|
-
|
|
233
|
+
async function getUnimportOptions(wxtDir, srcDir, logger, config) {
|
|
234
|
+
const disabled = config.imports === false;
|
|
235
|
+
const eslintrc = await getUnimportEslintOptions(wxtDir, config.imports);
|
|
236
|
+
const invalidExports = ["options"];
|
|
237
|
+
const defineImportsAndTypes = (imports, typeImports) => [
|
|
238
|
+
...imports,
|
|
239
|
+
...typeImports.map((name) => ({ name, type: true }))
|
|
240
|
+
];
|
|
244
241
|
const defaultOptions = {
|
|
245
|
-
|
|
246
|
-
imports: [
|
|
247
|
-
{ name: "defineConfig", from: "wxt" },
|
|
248
|
-
{ name: "fakeBrowser", from: "wxt/testing" }
|
|
249
|
-
],
|
|
242
|
+
imports: [{ name: "fakeBrowser", from: "wxt/testing" }],
|
|
250
243
|
presets: [
|
|
251
244
|
{
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
245
|
+
from: "wxt/browser",
|
|
246
|
+
imports: defineImportsAndTypes(["browser"], ["Browser"])
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
from: "wxt/utils/storage",
|
|
250
|
+
imports: defineImportsAndTypes(
|
|
251
|
+
["storage"],
|
|
252
|
+
[
|
|
253
|
+
"StorageArea",
|
|
254
|
+
"WxtStorage",
|
|
255
|
+
"WxtStorageItem",
|
|
256
|
+
"StorageArea",
|
|
257
|
+
"StorageItemKey",
|
|
258
|
+
"StorageAreaChanges",
|
|
259
|
+
"MigrationError"
|
|
260
|
+
]
|
|
261
|
+
)
|
|
257
262
|
},
|
|
258
263
|
{
|
|
259
|
-
|
|
264
|
+
from: "wxt/utils/app-config",
|
|
265
|
+
imports: defineImportsAndTypes(["useAppConfig"], [])
|
|
260
266
|
},
|
|
261
|
-
{
|
|
262
|
-
|
|
267
|
+
{
|
|
268
|
+
from: "wxt/utils/content-script-context",
|
|
269
|
+
imports: defineImportsAndTypes(
|
|
270
|
+
["ContentScriptContext"],
|
|
271
|
+
["WxtWindowEventMap"]
|
|
272
|
+
)
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
from: "wxt/utils/content-script-ui/iframe",
|
|
276
|
+
imports: defineImportsAndTypes(
|
|
277
|
+
["createIframeUi"],
|
|
278
|
+
["IframeContentScriptUi", "IframeContentScriptUiOptions"]
|
|
279
|
+
),
|
|
280
|
+
ignore: invalidExports
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
from: "wxt/utils/content-script-ui/integrated",
|
|
284
|
+
imports: defineImportsAndTypes(
|
|
285
|
+
["createIntegratedUi"],
|
|
286
|
+
["IntegratedContentScriptUi", "IntegratedContentScriptUiOptions"]
|
|
287
|
+
),
|
|
288
|
+
ignore: invalidExports
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
from: "wxt/utils/content-script-ui/shadow-root",
|
|
292
|
+
imports: defineImportsAndTypes(
|
|
293
|
+
["createShadowRootUi"],
|
|
294
|
+
["ShadowRootContentScriptUi", "ShadowRootContentScriptUiOptions"]
|
|
295
|
+
),
|
|
296
|
+
ignore: invalidExports
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
from: "wxt/utils/content-script-ui/types",
|
|
300
|
+
imports: defineImportsAndTypes(
|
|
301
|
+
[],
|
|
302
|
+
[
|
|
303
|
+
"ContentScriptUi",
|
|
304
|
+
"ContentScriptUiOptions",
|
|
305
|
+
"ContentScriptOverlayAlignment",
|
|
306
|
+
"ContentScriptAppendMode",
|
|
307
|
+
"ContentScriptInlinePositioningOptions",
|
|
308
|
+
"ContentScriptOverlayPositioningOptions",
|
|
309
|
+
"ContentScriptModalPositioningOptions",
|
|
310
|
+
"ContentScriptPositioningOptions",
|
|
311
|
+
"ContentScriptAnchoredOptions",
|
|
312
|
+
"AutoMountOptions",
|
|
313
|
+
"StopAutoMount",
|
|
314
|
+
"AutoMount"
|
|
315
|
+
]
|
|
316
|
+
)
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
from: "wxt/utils/define-app-config",
|
|
320
|
+
imports: defineImportsAndTypes(["defineAppConfig"], ["WxtAppConfig"])
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
from: "wxt/utils/define-background",
|
|
324
|
+
imports: defineImportsAndTypes(["defineBackground"], [])
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
from: "wxt/utils/define-content-script",
|
|
328
|
+
imports: defineImportsAndTypes(["defineContentScript"], [])
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
from: "wxt/utils/define-unlisted-script",
|
|
332
|
+
imports: defineImportsAndTypes(["defineUnlistedScript"], [])
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
from: "wxt/utils/define-wxt-plugin",
|
|
336
|
+
imports: defineImportsAndTypes(["defineWxtPlugin"], [])
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
from: "wxt/utils/inject-script",
|
|
340
|
+
imports: defineImportsAndTypes(
|
|
341
|
+
["injectScript"],
|
|
342
|
+
["ScriptPublicPath", "InjectScriptOptions"]
|
|
343
|
+
),
|
|
344
|
+
ignore: invalidExports
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
from: "wxt/utils/match-patterns",
|
|
348
|
+
imports: defineImportsAndTypes(
|
|
349
|
+
["InvalidMatchPattern", "MatchPattern"],
|
|
350
|
+
[]
|
|
351
|
+
)
|
|
352
|
+
}
|
|
263
353
|
],
|
|
354
|
+
virtualImports: ["#imports"],
|
|
355
|
+
debugLog: logger.debug,
|
|
264
356
|
warn: logger.warn,
|
|
265
|
-
dirs: ["components", "composables", "hooks", "utils"],
|
|
266
357
|
dirsScanOptions: {
|
|
267
358
|
cwd: srcDir
|
|
268
359
|
},
|
|
269
|
-
eslintrc
|
|
360
|
+
eslintrc,
|
|
361
|
+
dirs: disabled ? [] : ["components", "composables", "hooks", "utils"],
|
|
362
|
+
disabled
|
|
270
363
|
};
|
|
271
364
|
return defu(
|
|
272
365
|
config.imports ?? {},
|
|
@@ -274,28 +367,28 @@ async function getUnimportOptions(wxtDir, srcDir, logger, extensionApi, config)
|
|
|
274
367
|
);
|
|
275
368
|
}
|
|
276
369
|
async function getUnimportEslintOptions(wxtDir, options) {
|
|
277
|
-
const
|
|
278
|
-
let
|
|
279
|
-
switch (
|
|
370
|
+
const inlineEnabled = options === false ? false : options?.eslintrc?.enabled ?? "auto";
|
|
371
|
+
let enabled;
|
|
372
|
+
switch (inlineEnabled) {
|
|
280
373
|
case "auto":
|
|
281
374
|
const version = await getEslintVersion();
|
|
282
375
|
let major = parseInt(version[0]);
|
|
283
|
-
if (isNaN(major))
|
|
284
|
-
if (major <= 8)
|
|
285
|
-
else if (major >= 9)
|
|
286
|
-
else
|
|
376
|
+
if (isNaN(major)) enabled = false;
|
|
377
|
+
if (major <= 8) enabled = 8;
|
|
378
|
+
else if (major >= 9) enabled = 9;
|
|
379
|
+
else enabled = false;
|
|
287
380
|
break;
|
|
288
381
|
case true:
|
|
289
|
-
|
|
382
|
+
enabled = 8;
|
|
290
383
|
break;
|
|
291
384
|
default:
|
|
292
|
-
|
|
385
|
+
enabled = inlineEnabled;
|
|
293
386
|
}
|
|
294
387
|
return {
|
|
295
|
-
enabled
|
|
388
|
+
enabled,
|
|
296
389
|
filePath: path.resolve(
|
|
297
390
|
wxtDir,
|
|
298
|
-
|
|
391
|
+
enabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"
|
|
299
392
|
),
|
|
300
393
|
globalsPropValue: true
|
|
301
394
|
};
|
|
@@ -2,6 +2,5 @@ export * from "./build-entrypoints.mjs";
|
|
|
2
2
|
export * from "./detect-dev-changes.mjs";
|
|
3
3
|
export * from "./find-entrypoints.mjs";
|
|
4
4
|
export * from "./group-entrypoints.mjs";
|
|
5
|
-
export * from "./import-entrypoint.mjs";
|
|
6
5
|
export * from "./internal-build.mjs";
|
|
7
6
|
export * from "./rebuild.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Manifest } from 'wxt/browser';
|
|
2
1
|
import { BuildOutput, Entrypoint, EntrypointGroup } from '../../../types';
|
|
2
|
+
import type { Browser } from '@wxt-dev/browser';
|
|
3
3
|
/**
|
|
4
4
|
* Given a configuration, list of entrypoints, and an existing, partial output, build the
|
|
5
5
|
* entrypoints and merge the new output with the existing output.
|
|
@@ -18,6 +18,6 @@ import { BuildOutput, Entrypoint, EntrypointGroup } from '../../../types';
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function rebuild(allEntrypoints: Entrypoint[], entrypointGroups: EntrypointGroup[], existingOutput?: Omit<BuildOutput, 'manifest'>): Promise<{
|
|
20
20
|
output: BuildOutput;
|
|
21
|
-
manifest: Manifest
|
|
21
|
+
manifest: Browser.runtime.Manifest;
|
|
22
22
|
warnings: any[][];
|
|
23
23
|
}>;
|