wxt 0.18.15 → 0.19.0
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/bin/wxt.mjs +1 -1
- package/dist/browser/chrome.d.ts +17 -0
- package/dist/browser/chrome.mjs +7 -0
- package/dist/browser/index.d.ts +18 -0
- package/dist/browser/index.mjs +2 -0
- package/dist/builtin-modules/index.d.ts +2 -0
- package/dist/builtin-modules/index.mjs +2 -0
- package/dist/builtin-modules/unimport.d.ts +8 -0
- package/dist/builtin-modules/unimport.mjs +99 -0
- package/dist/cli/cli-utils.d.ts +25 -0
- package/dist/cli/cli-utils.mjs +58 -0
- package/dist/cli/commands.d.ts +2 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.mjs +11 -0
- package/dist/client/app-config.d.ts +2 -0
- package/dist/client/app-config.mjs +4 -0
- package/dist/client/content-scripts/content-script-context.d.ts +114 -0
- package/dist/client/content-scripts/content-script-context.mjs +169 -0
- package/dist/client/content-scripts/custom-events.d.ts +10 -0
- package/dist/client/content-scripts/custom-events.mjs +13 -0
- package/dist/client/content-scripts/index.d.ts +2 -0
- package/dist/client/content-scripts/index.mjs +2 -0
- package/dist/client/content-scripts/location-watcher.d.ts +12 -0
- package/dist/client/content-scripts/location-watcher.mjs +22 -0
- package/dist/client/content-scripts/ui/index.d.ts +23 -0
- package/dist/client/content-scripts/ui/index.mjs +188 -0
- package/dist/{client.d.ts → client/content-scripts/ui/types.d.ts} +17 -45
- package/dist/client/content-scripts/ui/types.mjs +0 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.mjs +2 -0
- package/dist/core/build.d.ts +15 -0
- package/dist/core/build.mjs +6 -0
- package/dist/core/builders/vite/index.d.ts +3 -0
- package/dist/core/builders/vite/index.mjs +285 -0
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +7 -0
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +15 -0
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +13 -0
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +22 -0
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +14 -0
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +13 -0
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +7 -0
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +140 -0
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +6 -0
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -0
- package/dist/core/builders/vite/plugins/download.d.ts +10 -0
- package/dist/core/builders/vite/plugins/download.mjs +14 -0
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +6 -0
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +16 -0
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +11 -0
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +26 -0
- package/dist/core/builders/vite/plugins/globals.d.ts +3 -0
- package/dist/core/builders/vite/plugins/globals.mjs +15 -0
- package/dist/core/builders/vite/plugins/index.d.ts +17 -0
- package/dist/core/builders/vite/plugins/index.mjs +17 -0
- package/dist/core/builders/vite/plugins/multipageMove.d.ts +20 -0
- package/dist/core/builders/vite/plugins/multipageMove.mjs +59 -0
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +6 -0
- package/dist/core/builders/vite/plugins/noopBackground.mjs +17 -0
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +6 -0
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +12 -0
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +6 -0
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -0
- package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +10 -0
- package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +15 -0
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +6 -0
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +30 -0
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +3 -0
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +12 -0
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +6 -0
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +56 -0
- package/dist/core/clean.d.ts +21 -0
- package/dist/core/clean.mjs +38 -0
- package/dist/core/create-server.d.ts +11 -0
- package/dist/core/create-server.mjs +206 -0
- package/dist/core/define-config.d.ts +2 -0
- package/dist/core/define-config.mjs +3 -0
- package/dist/core/define-runner-config.d.ts +2 -0
- package/dist/core/define-runner-config.mjs +3 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.mjs +8 -0
- package/dist/core/initialize.d.ts +5 -0
- package/dist/core/initialize.mjs +128 -0
- package/dist/core/package-managers/bun.d.ts +2 -0
- package/dist/core/package-managers/bun.mjs +19 -0
- package/dist/core/package-managers/index.d.ts +2 -0
- package/dist/core/package-managers/index.mjs +65 -0
- package/dist/core/package-managers/npm.d.ts +17 -0
- package/dist/core/package-managers/npm.mjs +58 -0
- package/dist/core/package-managers/pnpm.d.ts +2 -0
- package/dist/core/package-managers/pnpm.mjs +21 -0
- package/dist/core/package-managers/types.d.ts +2 -0
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +2 -0
- package/dist/core/package-managers/yarn.mjs +31 -0
- package/dist/core/prepare.d.ts +2 -0
- package/dist/core/prepare.mjs +8 -0
- package/dist/core/runners/index.d.ts +2 -0
- package/dist/core/runners/index.mjs +12 -0
- package/dist/core/runners/manual.d.ts +5 -0
- package/dist/core/runners/manual.mjs +16 -0
- package/dist/core/runners/safari.d.ts +5 -0
- package/dist/core/runners/safari.mjs +16 -0
- package/dist/core/runners/web-ext.d.ts +5 -0
- package/dist/core/runners/web-ext.mjs +78 -0
- package/dist/core/runners/wsl.d.ts +5 -0
- package/dist/core/runners/wsl.mjs +16 -0
- package/dist/core/utils/arrays.d.ts +13 -0
- package/dist/{chunk-BERPNPEZ.js → core/utils/arrays.mjs} +6 -10
- package/dist/core/utils/building/build-entrypoints.d.ts +3 -0
- package/dist/core/utils/building/build-entrypoints.mjs +47 -0
- package/dist/core/utils/building/detect-dev-changes.d.ts +57 -0
- package/dist/core/utils/building/detect-dev-changes.mjs +93 -0
- package/dist/core/utils/building/find-entrypoints.d.ts +5 -0
- package/dist/core/utils/building/find-entrypoints.mjs +385 -0
- package/dist/core/utils/building/generate-wxt-dir.d.ts +5 -0
- package/dist/core/utils/building/generate-wxt-dir.mjs +192 -0
- package/dist/core/utils/building/group-entrypoints.d.ts +8 -0
- package/dist/core/utils/building/group-entrypoints.mjs +37 -0
- package/dist/core/utils/building/import-entrypoint.d.ts +16 -0
- package/dist/core/utils/building/import-entrypoint.mjs +97 -0
- package/dist/core/utils/building/index.d.ts +9 -0
- package/dist/core/utils/building/index.mjs +9 -0
- package/dist/core/utils/building/internal-build.d.ts +12 -0
- package/dist/core/utils/building/internal-build.mjs +112 -0
- package/dist/core/utils/building/rebuild.d.ts +23 -0
- package/dist/core/utils/building/rebuild.mjs +39 -0
- package/dist/core/utils/building/resolve-config.d.ts +11 -0
- package/dist/core/utils/building/resolve-config.mjs +364 -0
- package/dist/core/utils/cache.d.ts +8 -0
- package/dist/core/utils/cache.mjs +21 -0
- package/dist/core/utils/cli.d.ts +3 -0
- package/dist/core/utils/cli.mjs +26 -0
- package/dist/core/utils/constants.d.ts +5 -0
- package/dist/core/utils/constants.mjs +1 -0
- package/dist/core/utils/content-scripts.d.ts +11 -0
- package/dist/core/utils/content-scripts.mjs +60 -0
- package/dist/core/utils/content-security-policy.d.ts +14 -0
- package/dist/core/utils/content-security-policy.mjs +39 -0
- package/dist/core/utils/entrypoints.d.ts +25 -0
- package/dist/core/utils/entrypoints.mjs +31 -0
- package/dist/core/utils/eslint.d.ts +1 -0
- package/dist/core/utils/eslint.mjs +11 -0
- package/dist/core/utils/fs.d.ts +13 -0
- package/dist/core/utils/fs.mjs +15 -0
- package/dist/core/utils/globals.d.ts +11 -0
- package/dist/core/utils/globals.mjs +53 -0
- package/dist/core/utils/i18n.d.ts +11 -0
- package/dist/core/utils/i18n.mjs +35 -0
- package/dist/core/utils/log/index.d.ts +4 -0
- package/dist/core/utils/log/index.mjs +4 -0
- package/dist/core/utils/log/printBuildSummary.d.ts +2 -0
- package/dist/core/utils/log/printBuildSummary.mjs +32 -0
- package/dist/core/utils/log/printFileList.d.ts +1 -0
- package/dist/core/utils/log/printFileList.mjs +42 -0
- package/dist/core/utils/log/printHeader.d.ts +1 -0
- package/dist/core/utils/log/printHeader.mjs +7 -0
- package/dist/core/utils/log/printTable.d.ts +1 -0
- package/dist/core/utils/log/printTable.mjs +22 -0
- package/dist/core/utils/manifest.d.ts +44 -0
- package/dist/core/utils/manifest.mjs +512 -0
- package/dist/core/utils/network.d.ts +7 -0
- package/dist/core/utils/network.mjs +38 -0
- package/dist/core/utils/package.d.ts +6 -0
- package/dist/core/utils/package.mjs +14 -0
- package/dist/core/utils/paths.d.ts +11 -0
- package/dist/core/utils/paths.mjs +10 -0
- package/dist/core/utils/strings.d.ts +14 -0
- package/dist/core/utils/strings.mjs +18 -0
- package/dist/core/utils/testing/fake-objects.d.ts +4556 -0
- package/dist/core/utils/testing/fake-objects.mjs +322 -0
- package/dist/core/utils/time.d.ts +9 -0
- package/dist/core/utils/time.mjs +17 -0
- package/dist/core/utils/transform.d.ts +9 -0
- package/dist/core/utils/transform.mjs +17 -0
- package/dist/core/utils/types.d.ts +10 -0
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +15 -0
- package/dist/core/utils/validation.mjs +55 -0
- package/dist/core/utils/virtual-modules.d.ts +22 -0
- package/dist/core/utils/virtual-modules.mjs +14 -0
- package/dist/core/utils/wsl.d.ts +4 -0
- package/dist/core/utils/wsl.mjs +4 -0
- package/dist/core/wxt.d.ts +19 -0
- package/dist/core/wxt.mjs +41 -0
- package/dist/core/zip.d.ts +7 -0
- package/dist/core/zip.mjs +137 -0
- package/dist/index.d.ts +4 -79
- package/dist/index.mjs +3 -0
- package/dist/modules.d.ts +10 -20
- package/dist/{chunk-6XSIWUWF.js → modules.mjs} +7 -16
- package/dist/sandbox/define-app-config.d.ts +19 -0
- package/dist/sandbox/define-app-config.mjs +3 -0
- package/dist/sandbox/define-background.d.ts +3 -0
- package/dist/sandbox/define-background.mjs +4 -0
- package/dist/sandbox/define-content-script.d.ts +2 -0
- package/dist/sandbox/define-content-script.mjs +3 -0
- package/dist/sandbox/define-unlisted-script.d.ts +3 -0
- package/dist/sandbox/define-unlisted-script.mjs +4 -0
- package/dist/sandbox/define-wxt-plugin.d.ts +2 -0
- package/dist/sandbox/define-wxt-plugin.mjs +3 -0
- package/dist/sandbox/dev-server-websocket.d.ts +21 -0
- package/dist/sandbox/dev-server-websocket.mjs +37 -0
- package/dist/sandbox/index.d.ts +11 -0
- package/dist/sandbox/index.mjs +6 -0
- package/dist/sandbox/utils/logger.d.ts +9 -0
- package/dist/sandbox/utils/logger.mjs +15 -0
- package/dist/storage.d.ts +39 -16
- package/dist/{storage.js → storage.mjs} +30 -41
- package/dist/testing/fake-browser.d.ts +1 -0
- package/dist/testing/fake-browser.mjs +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.mjs +2 -0
- package/dist/{testing.d.ts → testing/wxt-vitest-plugin.d.ts} +3 -15
- package/dist/testing/wxt-vitest-plugin.mjs +26 -0
- package/dist/{index-nWRfwAJi.d.cts → types.d.ts} +150 -264
- package/dist/types.mjs +0 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.mjs +1 -0
- package/dist/virtual/{background-entrypoint.js → background-entrypoint.mjs} +31 -40
- package/dist/virtual/{content-script-isolated-world-entrypoint.js → content-script-isolated-world-entrypoint.mjs} +9 -13
- package/dist/virtual/{content-script-main-world-entrypoint.js → content-script-main-world-entrypoint.mjs} +9 -14
- package/dist/virtual/mock-browser.mjs +6 -0
- package/dist/virtual/{reload-html.js → reload-html.mjs} +8 -9
- package/dist/virtual/{unlisted-script-entrypoint.js → unlisted-script-entrypoint.mjs} +8 -12
- package/package.json +47 -57
- package/dist/browser.d.ts +0 -18
- package/dist/browser.js +0 -6
- package/dist/chunk-BM6QYGAW.js +0 -1063
- package/dist/chunk-FNTE2L27.js +0 -7
- package/dist/chunk-FP7RYLVL.js +0 -3617
- package/dist/chunk-KPD5J7PZ.js +0 -1065
- package/dist/chunk-QGM4M3NI.js +0 -37
- package/dist/chunk-SGKCDMVR.js +0 -38
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -4438
- package/dist/client.js +0 -424
- package/dist/define-app-config-bg54F_lV.d.ts +0 -294
- package/dist/execa-4UBDUBJZ.js +0 -7244
- package/dist/execa-QLUM2B3W.js +0 -7245
- package/dist/index-nWRfwAJi.d.ts +0 -1401
- package/dist/index.cjs +0 -14473
- package/dist/index.d.cts +0 -81
- package/dist/index.js +0 -696
- package/dist/modules.cjs +0 -96
- package/dist/modules.d.cts +0 -119
- package/dist/modules.js +0 -17
- package/dist/prompt-25QIVJDC.js +0 -755
- package/dist/prompt-7BMKNSWS.js +0 -754
- package/dist/sandbox.d.ts +0 -16
- package/dist/sandbox.js +0 -36
- package/dist/storage.cjs +0 -439
- package/dist/storage.d.cts +0 -200
- package/dist/testing.cjs +0 -2815
- package/dist/testing.d.cts +0 -30
- package/dist/testing.js +0 -40
- package/dist/virtual/mock-browser.js +0 -6
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BuildOutput, BuildStepOutput, EntrypointGroup } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Compare the changed files vs the build output and determine what kind of reload needs to happen:
|
|
4
|
+
*
|
|
5
|
+
* - Do nothing
|
|
6
|
+
* - CSS or JS file associated with an HTML page is changed - this is handled automatically by the
|
|
7
|
+
* dev server
|
|
8
|
+
* - Change isn't used by any of the entrypoints
|
|
9
|
+
* - Reload Content script
|
|
10
|
+
* - CSS or JS file associated with a content script
|
|
11
|
+
* - Background script will be told to reload the content script
|
|
12
|
+
* - Reload HTML file
|
|
13
|
+
* - HTML file itself is saved - HMR doesn't handle this because the HTML pages are pre-rendered
|
|
14
|
+
* - Chrome is OK reloading the page when the HTML file is changed without reloading the whole
|
|
15
|
+
* extension. Not sure about firefox, this might need to change to an extension reload
|
|
16
|
+
* - Reload extension
|
|
17
|
+
* - Background script is changed
|
|
18
|
+
* - Manifest is different
|
|
19
|
+
* - Restart browser
|
|
20
|
+
* - Config file changed (wxt.config.ts, .env, web-ext.config.ts, etc)
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectDevChanges(changedFiles: string[], currentOutput: BuildOutput): DevModeChange;
|
|
23
|
+
/**
|
|
24
|
+
* Contains information about what files changed, what needs rebuilt, and the type of reload that is
|
|
25
|
+
* required.
|
|
26
|
+
*/
|
|
27
|
+
export type DevModeChange = NoChange | HtmlReload | ExtensionReload | ContentScriptReload | FullRestart | BrowserRestart;
|
|
28
|
+
interface NoChange {
|
|
29
|
+
type: 'no-change';
|
|
30
|
+
}
|
|
31
|
+
interface RebuildChange {
|
|
32
|
+
/**
|
|
33
|
+
* The list of entrypoints that need rebuilt.
|
|
34
|
+
*/
|
|
35
|
+
rebuildGroups: EntrypointGroup[];
|
|
36
|
+
/**
|
|
37
|
+
* The previous output stripped of any files are going to change.
|
|
38
|
+
*/
|
|
39
|
+
cachedOutput: BuildOutput;
|
|
40
|
+
}
|
|
41
|
+
interface FullRestart {
|
|
42
|
+
type: 'full-restart';
|
|
43
|
+
}
|
|
44
|
+
interface BrowserRestart {
|
|
45
|
+
type: 'browser-restart';
|
|
46
|
+
}
|
|
47
|
+
interface HtmlReload extends RebuildChange {
|
|
48
|
+
type: 'html-reload';
|
|
49
|
+
}
|
|
50
|
+
interface ExtensionReload extends RebuildChange {
|
|
51
|
+
type: 'extension-reload';
|
|
52
|
+
}
|
|
53
|
+
interface ContentScriptReload extends RebuildChange {
|
|
54
|
+
type: 'content-script-reload';
|
|
55
|
+
changedSteps: BuildStepOutput[];
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { every, some } from "../../utils/arrays.mjs";
|
|
2
|
+
import { normalizePath } from "../../utils/paths.mjs";
|
|
3
|
+
import { wxt } from "../../wxt.mjs";
|
|
4
|
+
export function detectDevChanges(changedFiles, currentOutput) {
|
|
5
|
+
const isConfigChange = some(
|
|
6
|
+
changedFiles,
|
|
7
|
+
(file) => file === wxt.config.userConfigMetadata.configFile
|
|
8
|
+
);
|
|
9
|
+
if (isConfigChange) return { type: "full-restart" };
|
|
10
|
+
const isRunnerChange = some(
|
|
11
|
+
changedFiles,
|
|
12
|
+
(file) => file === wxt.config.runnerConfig.configFile
|
|
13
|
+
);
|
|
14
|
+
if (isRunnerChange) return { type: "browser-restart" };
|
|
15
|
+
const changedSteps = new Set(
|
|
16
|
+
changedFiles.flatMap(
|
|
17
|
+
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
if (changedSteps.size === 0) {
|
|
21
|
+
const hasPublicChange = some(
|
|
22
|
+
changedFiles,
|
|
23
|
+
(file) => file.startsWith(wxt.config.publicDir)
|
|
24
|
+
);
|
|
25
|
+
if (hasPublicChange) {
|
|
26
|
+
return {
|
|
27
|
+
type: "extension-reload",
|
|
28
|
+
rebuildGroups: [],
|
|
29
|
+
cachedOutput: currentOutput
|
|
30
|
+
};
|
|
31
|
+
} else {
|
|
32
|
+
return { type: "no-change" };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const unchangedOutput = {
|
|
36
|
+
manifest: currentOutput.manifest,
|
|
37
|
+
steps: [],
|
|
38
|
+
publicAssets: [...currentOutput.publicAssets]
|
|
39
|
+
};
|
|
40
|
+
const changedOutput = {
|
|
41
|
+
manifest: currentOutput.manifest,
|
|
42
|
+
steps: [],
|
|
43
|
+
publicAssets: []
|
|
44
|
+
};
|
|
45
|
+
for (const step of currentOutput.steps) {
|
|
46
|
+
if (changedSteps.has(step)) {
|
|
47
|
+
changedOutput.steps.push(step);
|
|
48
|
+
} else {
|
|
49
|
+
unchangedOutput.steps.push(step);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
53
|
+
if (isOnlyHtmlChanges) {
|
|
54
|
+
return {
|
|
55
|
+
type: "html-reload",
|
|
56
|
+
cachedOutput: unchangedOutput,
|
|
57
|
+
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const isOnlyContentScripts = changedOutput.steps.length > 0 && every(
|
|
61
|
+
changedOutput.steps.flatMap((step) => step.entrypoints),
|
|
62
|
+
(entry) => entry.type === "content-script"
|
|
63
|
+
);
|
|
64
|
+
if (isOnlyContentScripts) {
|
|
65
|
+
return {
|
|
66
|
+
type: "content-script-reload",
|
|
67
|
+
cachedOutput: unchangedOutput,
|
|
68
|
+
changedSteps: changedOutput.steps,
|
|
69
|
+
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
type: "extension-reload",
|
|
74
|
+
cachedOutput: unchangedOutput,
|
|
75
|
+
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function findEffectedSteps(changedFile, currentOutput) {
|
|
79
|
+
const changes = [];
|
|
80
|
+
const changedPath = normalizePath(changedFile);
|
|
81
|
+
const isChunkEffected = (chunk) => (
|
|
82
|
+
// If it's an HTML file with the same path, is is effected because HTML files need to be re-rendered
|
|
83
|
+
// - fileName is normalized, relative bundle path, "<entrypoint-name>.html"
|
|
84
|
+
chunk.type === "asset" && changedPath.replace("/index.html", ".html").endsWith(chunk.fileName) || // If it's a chunk that depends on the changed file, it is effected
|
|
85
|
+
// - moduleIds are absolute, normalized paths
|
|
86
|
+
chunk.type === "chunk" && chunk.moduleIds.includes(changedPath)
|
|
87
|
+
);
|
|
88
|
+
for (const step of currentOutput.steps) {
|
|
89
|
+
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
90
|
+
if (effectedChunk) changes.push(step);
|
|
91
|
+
}
|
|
92
|
+
return changes;
|
|
93
|
+
}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { relative, resolve } from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { minimatch } from "minimatch";
|
|
4
|
+
import { parseHTML } from "linkedom";
|
|
5
|
+
import JSON5 from "json5";
|
|
6
|
+
import glob from "fast-glob";
|
|
7
|
+
import {
|
|
8
|
+
getEntrypointName,
|
|
9
|
+
resolvePerBrowserOptions
|
|
10
|
+
} from "../../utils/entrypoints.mjs";
|
|
11
|
+
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../utils/constants.mjs";
|
|
12
|
+
import { CSS_EXTENSIONS_PATTERN } from "../../utils/paths.mjs";
|
|
13
|
+
import pc from "picocolors";
|
|
14
|
+
import { wxt } from "../../wxt.mjs";
|
|
15
|
+
export async function findEntrypoints() {
|
|
16
|
+
await fs.mkdir(wxt.config.wxtDir, { recursive: true });
|
|
17
|
+
await fs.writeJson(resolve(wxt.config.wxtDir, "tsconfig.json"), {});
|
|
18
|
+
const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
|
|
19
|
+
cwd: wxt.config.entrypointsDir
|
|
20
|
+
});
|
|
21
|
+
relativePaths.sort();
|
|
22
|
+
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
23
|
+
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
24
|
+
const inputPath = resolve(wxt.config.entrypointsDir, relativePath);
|
|
25
|
+
const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
|
|
26
|
+
const matchingGlob = pathGlobs.find(
|
|
27
|
+
(glob2) => minimatch(relativePath, glob2)
|
|
28
|
+
);
|
|
29
|
+
if (matchingGlob) {
|
|
30
|
+
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
|
|
31
|
+
results.push({
|
|
32
|
+
name,
|
|
33
|
+
inputPath,
|
|
34
|
+
type,
|
|
35
|
+
skipped: wxt.config.filterEntrypoints != null && !wxt.config.filterEntrypoints.has(name)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return results;
|
|
39
|
+
}, []);
|
|
40
|
+
preventNoEntrypoints(entrypointInfos);
|
|
41
|
+
preventDuplicateEntrypointNames(entrypointInfos);
|
|
42
|
+
let hasBackground = false;
|
|
43
|
+
const entrypoints = await Promise.all(
|
|
44
|
+
entrypointInfos.map(async (info) => {
|
|
45
|
+
const { type } = info;
|
|
46
|
+
switch (type) {
|
|
47
|
+
case "popup":
|
|
48
|
+
return await getPopupEntrypoint(info);
|
|
49
|
+
case "sidepanel":
|
|
50
|
+
return await getSidepanelEntrypoint(info);
|
|
51
|
+
case "options":
|
|
52
|
+
return await getOptionsEntrypoint(info);
|
|
53
|
+
case "background":
|
|
54
|
+
hasBackground = true;
|
|
55
|
+
return await getBackgroundEntrypoint(info);
|
|
56
|
+
case "content-script":
|
|
57
|
+
return await getContentScriptEntrypoint(info);
|
|
58
|
+
case "unlisted-page":
|
|
59
|
+
return await getUnlistedPageEntrypoint(info);
|
|
60
|
+
case "unlisted-script":
|
|
61
|
+
return await getUnlistedScriptEntrypoint(info);
|
|
62
|
+
case "content-script-style":
|
|
63
|
+
return {
|
|
64
|
+
...info,
|
|
65
|
+
type,
|
|
66
|
+
outputDir: resolve(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
67
|
+
options: {
|
|
68
|
+
include: void 0,
|
|
69
|
+
exclude: void 0
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
default:
|
|
73
|
+
return {
|
|
74
|
+
...info,
|
|
75
|
+
type,
|
|
76
|
+
outputDir: wxt.config.outDir,
|
|
77
|
+
options: {
|
|
78
|
+
include: void 0,
|
|
79
|
+
exclude: void 0
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
if (wxt.config.command === "serve" && !hasBackground) {
|
|
86
|
+
entrypoints.push(
|
|
87
|
+
await getBackgroundEntrypoint({
|
|
88
|
+
inputPath: VIRTUAL_NOOP_BACKGROUND_MODULE_ID,
|
|
89
|
+
name: "background",
|
|
90
|
+
type: "background",
|
|
91
|
+
skipped: false
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
wxt.logger.debug("All entrypoints:", entrypoints);
|
|
96
|
+
const skippedEntrypointNames = entrypointInfos.filter((item) => item.skipped).map((item) => item.name);
|
|
97
|
+
if (skippedEntrypointNames.length) {
|
|
98
|
+
wxt.logger.warn(
|
|
99
|
+
`Filter excluded the following entrypoints:
|
|
100
|
+
${skippedEntrypointNames.map((item) => `${pc.dim("-")} ${pc.cyan(item)}`).join("\n")}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const targetEntrypoints = entrypoints.filter((entry) => {
|
|
104
|
+
const { include, exclude } = entry.options;
|
|
105
|
+
if (include?.length && exclude?.length) {
|
|
106
|
+
wxt.logger.warn(
|
|
107
|
+
`The ${entry.name} entrypoint lists both include and exclude, but only one can be used per entrypoint. Entrypoint ignored.`
|
|
108
|
+
);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (exclude?.length && !include?.length) {
|
|
112
|
+
return !exclude.includes(wxt.config.browser);
|
|
113
|
+
}
|
|
114
|
+
if (include?.length && !exclude?.length) {
|
|
115
|
+
return include.includes(wxt.config.browser);
|
|
116
|
+
}
|
|
117
|
+
if (skippedEntrypointNames.includes(entry.name)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
wxt.logger.debug(`${wxt.config.browser} entrypoints:`, targetEntrypoints);
|
|
123
|
+
await wxt.hooks.callHook("entrypoints:resolved", wxt, targetEntrypoints);
|
|
124
|
+
return targetEntrypoints;
|
|
125
|
+
}
|
|
126
|
+
function preventDuplicateEntrypointNames(files) {
|
|
127
|
+
const namesToPaths = files.reduce(
|
|
128
|
+
(map, { name, inputPath }) => {
|
|
129
|
+
map[name] ??= [];
|
|
130
|
+
map[name].push(inputPath);
|
|
131
|
+
return map;
|
|
132
|
+
},
|
|
133
|
+
{}
|
|
134
|
+
);
|
|
135
|
+
const errorLines = Object.entries(namesToPaths).reduce(
|
|
136
|
+
(lines, [name, absolutePaths]) => {
|
|
137
|
+
if (absolutePaths.length > 1) {
|
|
138
|
+
lines.push(`- ${name}`);
|
|
139
|
+
absolutePaths.forEach((absolutePath) => {
|
|
140
|
+
lines.push(` - ${relative(wxt.config.root, absolutePath)}`);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return lines;
|
|
144
|
+
},
|
|
145
|
+
[]
|
|
146
|
+
);
|
|
147
|
+
if (errorLines.length > 0) {
|
|
148
|
+
const errorContent = errorLines.join("\n");
|
|
149
|
+
throw Error(
|
|
150
|
+
`Multiple entrypoints with the same name detected, only one entrypoint for each name is allowed.
|
|
151
|
+
|
|
152
|
+
${errorContent}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function preventNoEntrypoints(files) {
|
|
157
|
+
if (files.length === 0) {
|
|
158
|
+
throw Error(`No entrypoints found in ${wxt.config.entrypointsDir}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function getPopupEntrypoint(info) {
|
|
162
|
+
const options = await getHtmlEntrypointOptions(
|
|
163
|
+
info,
|
|
164
|
+
{
|
|
165
|
+
browserStyle: "browse_style",
|
|
166
|
+
exclude: "exclude",
|
|
167
|
+
include: "include",
|
|
168
|
+
defaultIcon: "default_icon",
|
|
169
|
+
defaultTitle: "default_title",
|
|
170
|
+
mv2Key: "type"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
defaultTitle: (document) => document.querySelector("title")?.textContent || void 0
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
defaultTitle: (content) => content,
|
|
177
|
+
mv2Key: (content) => content === "page_action" ? "page_action" : "browser_action"
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
return {
|
|
181
|
+
type: "popup",
|
|
182
|
+
name: "popup",
|
|
183
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
184
|
+
inputPath: info.inputPath,
|
|
185
|
+
outputDir: wxt.config.outDir,
|
|
186
|
+
skipped: info.skipped
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
async function getOptionsEntrypoint(info) {
|
|
190
|
+
const options = await getHtmlEntrypointOptions(
|
|
191
|
+
info,
|
|
192
|
+
{
|
|
193
|
+
browserStyle: "browse_style",
|
|
194
|
+
chromeStyle: "chrome_style",
|
|
195
|
+
exclude: "exclude",
|
|
196
|
+
include: "include",
|
|
197
|
+
openInTab: "open_in_tab"
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
return {
|
|
201
|
+
type: "options",
|
|
202
|
+
name: "options",
|
|
203
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
204
|
+
inputPath: info.inputPath,
|
|
205
|
+
outputDir: wxt.config.outDir,
|
|
206
|
+
skipped: info.skipped
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
async function getUnlistedPageEntrypoint(info) {
|
|
210
|
+
const options = await getHtmlEntrypointOptions(info, {
|
|
211
|
+
exclude: "exclude",
|
|
212
|
+
include: "include"
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
type: "unlisted-page",
|
|
216
|
+
name: info.name,
|
|
217
|
+
inputPath: info.inputPath,
|
|
218
|
+
outputDir: wxt.config.outDir,
|
|
219
|
+
options,
|
|
220
|
+
skipped: info.skipped
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
async function getUnlistedScriptEntrypoint({
|
|
224
|
+
inputPath,
|
|
225
|
+
name,
|
|
226
|
+
skipped
|
|
227
|
+
}) {
|
|
228
|
+
const defaultExport = await wxt.builder.importEntrypoint(inputPath);
|
|
229
|
+
if (defaultExport == null) {
|
|
230
|
+
throw Error(
|
|
231
|
+
`${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
const { main: _, ...options } = defaultExport;
|
|
235
|
+
return {
|
|
236
|
+
type: "unlisted-script",
|
|
237
|
+
name,
|
|
238
|
+
inputPath,
|
|
239
|
+
outputDir: wxt.config.outDir,
|
|
240
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
241
|
+
skipped
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
async function getBackgroundEntrypoint({
|
|
245
|
+
inputPath,
|
|
246
|
+
name,
|
|
247
|
+
skipped
|
|
248
|
+
}) {
|
|
249
|
+
let options = {};
|
|
250
|
+
if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
251
|
+
const defaultExport = await wxt.builder.importEntrypoint(inputPath);
|
|
252
|
+
if (defaultExport == null) {
|
|
253
|
+
throw Error(
|
|
254
|
+
`${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
const { main: _, ...moduleOptions } = defaultExport;
|
|
258
|
+
options = moduleOptions;
|
|
259
|
+
}
|
|
260
|
+
if (wxt.config.manifestVersion !== 3) {
|
|
261
|
+
delete options.type;
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
type: "background",
|
|
265
|
+
name,
|
|
266
|
+
inputPath,
|
|
267
|
+
outputDir: wxt.config.outDir,
|
|
268
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
269
|
+
skipped
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
async function getContentScriptEntrypoint({
|
|
273
|
+
inputPath,
|
|
274
|
+
name,
|
|
275
|
+
skipped
|
|
276
|
+
}) {
|
|
277
|
+
const defaultExport = await wxt.builder.importEntrypoint(inputPath);
|
|
278
|
+
if (defaultExport == null) {
|
|
279
|
+
throw Error(
|
|
280
|
+
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
const { main: _, ...options } = defaultExport;
|
|
284
|
+
if (options == null) {
|
|
285
|
+
throw Error(
|
|
286
|
+
`${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
type: "content-script",
|
|
291
|
+
name,
|
|
292
|
+
inputPath,
|
|
293
|
+
outputDir: resolve(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
294
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
295
|
+
skipped
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
async function getSidepanelEntrypoint(info) {
|
|
299
|
+
const options = await getHtmlEntrypointOptions(
|
|
300
|
+
info,
|
|
301
|
+
{
|
|
302
|
+
browserStyle: "browse_style",
|
|
303
|
+
exclude: "exclude",
|
|
304
|
+
include: "include",
|
|
305
|
+
defaultIcon: "default_icon",
|
|
306
|
+
defaultTitle: "default_title",
|
|
307
|
+
openAtInstall: "open_at_install"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
defaultTitle: (document) => document.querySelector("title")?.textContent || void 0
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
defaultTitle: (content) => content
|
|
314
|
+
}
|
|
315
|
+
);
|
|
316
|
+
return {
|
|
317
|
+
type: "sidepanel",
|
|
318
|
+
name: info.name,
|
|
319
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser),
|
|
320
|
+
inputPath: info.inputPath,
|
|
321
|
+
outputDir: wxt.config.outDir,
|
|
322
|
+
skipped: info.skipped
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
|
|
326
|
+
const content = await fs.readFile(info.inputPath, "utf-8");
|
|
327
|
+
const { document } = parseHTML(content);
|
|
328
|
+
const options = {};
|
|
329
|
+
const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
|
|
330
|
+
Object.entries(keyMap).forEach(([_key, manifestKey]) => {
|
|
331
|
+
const key = _key;
|
|
332
|
+
const content2 = queries?.[key] ? queries[key](document, manifestKey) : defaultQuery(manifestKey);
|
|
333
|
+
if (content2) {
|
|
334
|
+
try {
|
|
335
|
+
options[key] = (parsers?.[key] ?? JSON5.parse)(content2);
|
|
336
|
+
} catch (err) {
|
|
337
|
+
wxt.logger.fatal(
|
|
338
|
+
`Failed to parse meta tag content. Usually this means you have invalid JSON5 content (content=${content2})`,
|
|
339
|
+
err
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
return options;
|
|
345
|
+
}
|
|
346
|
+
const PATH_GLOB_TO_TYPE_MAP = {
|
|
347
|
+
"sandbox.html": "sandbox",
|
|
348
|
+
"sandbox/index.html": "sandbox",
|
|
349
|
+
"*.sandbox.html": "sandbox",
|
|
350
|
+
"*.sandbox/index.html": "sandbox",
|
|
351
|
+
"bookmarks.html": "bookmarks",
|
|
352
|
+
"bookmarks/index.html": "bookmarks",
|
|
353
|
+
"history.html": "history",
|
|
354
|
+
"history/index.html": "history",
|
|
355
|
+
"newtab.html": "newtab",
|
|
356
|
+
"newtab/index.html": "newtab",
|
|
357
|
+
"sidepanel.html": "sidepanel",
|
|
358
|
+
"sidepanel/index.html": "sidepanel",
|
|
359
|
+
"*.sidepanel.html": "sidepanel",
|
|
360
|
+
"*.sidepanel/index.html": "sidepanel",
|
|
361
|
+
"devtools.html": "devtools",
|
|
362
|
+
"devtools/index.html": "devtools",
|
|
363
|
+
"background.[jt]s": "background",
|
|
364
|
+
"background/index.[jt]s": "background",
|
|
365
|
+
[VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
|
|
366
|
+
"content.[jt]s?(x)": "content-script",
|
|
367
|
+
"content/index.[jt]s?(x)": "content-script",
|
|
368
|
+
"*.content.[jt]s?(x)": "content-script",
|
|
369
|
+
"*.content/index.[jt]s?(x)": "content-script",
|
|
370
|
+
[`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
371
|
+
[`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
372
|
+
[`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
373
|
+
[`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
374
|
+
"popup.html": "popup",
|
|
375
|
+
"popup/index.html": "popup",
|
|
376
|
+
"options.html": "options",
|
|
377
|
+
"options/index.html": "options",
|
|
378
|
+
"*.html": "unlisted-page",
|
|
379
|
+
"*/index.html": "unlisted-page",
|
|
380
|
+
"*.[jt]s?(x)": "unlisted-script",
|
|
381
|
+
"*/index.[jt]s?(x)": "unlisted-script",
|
|
382
|
+
[`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
383
|
+
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
384
|
+
};
|
|
385
|
+
const CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|