wxt 0.19.7 → 0.19.9
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/chrome.d.ts +4 -8
- package/dist/core/builders/vite/index.mjs +5 -4
- package/dist/core/create-server.mjs +1 -1
- package/dist/core/initialize.mjs +34 -19
- package/dist/core/utils/building/generate-wxt-dir.mjs +0 -1
- package/dist/core/utils/building/rebuild.mjs +4 -10
- package/dist/core/utils/building/resolve-config.mjs +1 -1
- package/dist/core/utils/entrypoints.mjs +1 -1
- package/dist/core/utils/environments/environment.mjs +1 -1
- package/dist/core/utils/eslint.mjs +1 -1
- package/dist/core/utils/manifest.mjs +4 -4
- package/dist/core/utils/package.mjs +2 -1
- package/dist/core/utils/strings.d.ts +4 -0
- package/dist/core/utils/strings.mjs +7 -1
- package/dist/core/utils/testing/fake-objects.d.ts +779 -19
- package/dist/core/utils/testing/fake-objects.mjs +1 -0
- package/dist/core/utils/transform.mjs +1 -3
- package/dist/core/wxt.mjs +1 -0
- package/dist/core/zip.mjs +2 -4
- package/dist/modules.d.ts +9 -5
- package/dist/types.d.ts +35 -2
- package/dist/version.mjs +1 -1
- package/package.json +8 -9
package/dist/browser/chrome.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module wxt/browser/chrome
|
|
3
|
-
*/
|
|
4
|
-
import type { WxtRuntime, WxtI18n } from './index';
|
|
5
1
|
/**
|
|
6
2
|
* EXPERIMENTAL
|
|
7
3
|
*
|
|
@@ -9,9 +5,9 @@ import type { WxtRuntime, WxtI18n } from './index';
|
|
|
9
5
|
*
|
|
10
6
|
* @module wxt/browser/chrome
|
|
11
7
|
*/
|
|
12
|
-
|
|
13
|
-
export type WxtBrowser = Omit<
|
|
14
|
-
runtime: WxtRuntime & Omit<
|
|
15
|
-
i18n: WxtI18n & Omit<
|
|
8
|
+
import type { WxtRuntime, WxtI18n } from './index';
|
|
9
|
+
export type WxtBrowser = Omit<typeof chrome, 'runtime' | 'i18n'> & {
|
|
10
|
+
runtime: WxtRuntime & Omit<(typeof chrome)['runtime'], 'getURL'>;
|
|
11
|
+
i18n: WxtI18n & Omit<(typeof chrome)['i18n'], 'getMessage'>;
|
|
16
12
|
};
|
|
17
13
|
export declare const browser: WxtBrowser;
|
|
@@ -28,6 +28,10 @@ export async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
28
28
|
if (config.build.sourcemap == null && wxtConfig.command === "serve") {
|
|
29
29
|
config.build.sourcemap = "inline";
|
|
30
30
|
}
|
|
31
|
+
config.server ??= {};
|
|
32
|
+
config.server.watch = {
|
|
33
|
+
ignored: [`${wxtConfig.outBaseDir}/**`, `${wxtConfig.wxtDir}/**`]
|
|
34
|
+
};
|
|
31
35
|
config.plugins ??= [];
|
|
32
36
|
config.plugins.push(
|
|
33
37
|
wxtPlugins.download(wxtConfig),
|
|
@@ -227,10 +231,7 @@ export async function createViteBuilder(wxtConfig, hooks, server) {
|
|
|
227
231
|
port: info.port,
|
|
228
232
|
strictPort: true,
|
|
229
233
|
host: info.hostname,
|
|
230
|
-
origin: info.origin
|
|
231
|
-
watch: {
|
|
232
|
-
ignored: [`${wxtConfig.outBaseDir}/**`, `${wxtConfig.wxtDir}/**`]
|
|
233
|
-
}
|
|
234
|
+
origin: info.origin
|
|
234
235
|
}
|
|
235
236
|
};
|
|
236
237
|
const baseConfig = await getBaseConfig();
|
package/dist/core/initialize.mjs
CHANGED
|
@@ -73,32 +73,46 @@ export async function initialize(options) {
|
|
|
73
73
|
console.log();
|
|
74
74
|
}
|
|
75
75
|
async function listTemplates() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
const templates = await listTemplatesUngh().catch((err) => {
|
|
77
|
+
consola.debug("Failed to load templates via ungh:", err);
|
|
78
|
+
return listTemplatesGithub();
|
|
79
|
+
});
|
|
80
|
+
return templates.sort((l, r) => {
|
|
81
|
+
const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
|
|
82
|
+
const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
|
|
83
|
+
const diff = lWeight - rWeight;
|
|
84
|
+
if (diff !== 0) return diff;
|
|
85
|
+
return l.name.localeCompare(r.name);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function listTemplatesUngh() {
|
|
89
|
+
const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
|
|
90
|
+
if (res.status !== 200)
|
|
91
|
+
throw Error(
|
|
92
|
+
`Request failed with status ${res.status} ${res.statusText}: ${await res.text()}`
|
|
93
|
+
);
|
|
94
|
+
const data = await res.json();
|
|
95
|
+
return data.files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({ name, path: `templates/${name}` }));
|
|
96
|
+
}
|
|
97
|
+
async function listTemplatesGithub() {
|
|
98
|
+
const res = await fetch(
|
|
99
|
+
`https://api.github.com/repos/${REPO}/contents/templates`,
|
|
100
|
+
{ headers: { Accept: "application/vnd.github+json" } }
|
|
101
|
+
);
|
|
102
|
+
if (res.status !== 200)
|
|
103
|
+
throw Error(
|
|
104
|
+
`Request failed with status ${res.status} ${res.statusText}: ${await res.text()}`
|
|
105
|
+
);
|
|
106
|
+
return await res.json();
|
|
92
107
|
}
|
|
93
108
|
async function cloneProject({
|
|
94
109
|
directory,
|
|
95
|
-
template
|
|
96
|
-
packageManager
|
|
110
|
+
template
|
|
97
111
|
}) {
|
|
98
112
|
const { default: ora } = await import("ora");
|
|
99
113
|
const spinner = ora("Downloading template").start();
|
|
100
114
|
try {
|
|
101
|
-
await downloadTemplate(`gh
|
|
115
|
+
await downloadTemplate(`gh:${REPO}/${template.path}`, {
|
|
102
116
|
dir: directory,
|
|
103
117
|
force: true
|
|
104
118
|
});
|
|
@@ -126,3 +140,4 @@ const TEMPLATE_SORT_WEIGHT = {
|
|
|
126
140
|
vue: 1,
|
|
127
141
|
react: 2
|
|
128
142
|
};
|
|
143
|
+
const REPO = "wxt-dev/wxt";
|
|
@@ -15,24 +15,18 @@ export async function rebuild(allEntrypoints, entrypointGroups, existingOutput =
|
|
|
15
15
|
const newOutput = await buildEntrypoints(entrypointGroups, spinner);
|
|
16
16
|
const mergedOutput = {
|
|
17
17
|
steps: [...existingOutput.steps, ...newOutput.steps],
|
|
18
|
-
|
|
18
|
+
// Do not merge existing because all publicAssets copied everytime
|
|
19
|
+
publicAssets: newOutput.publicAssets
|
|
19
20
|
};
|
|
20
21
|
const { manifest: newManifest, warnings: manifestWarnings } = await generateManifest(allEntrypoints, mergedOutput);
|
|
21
22
|
const finalOutput = {
|
|
22
23
|
manifest: newManifest,
|
|
23
|
-
...
|
|
24
|
+
...mergedOutput
|
|
24
25
|
};
|
|
25
26
|
await writeManifest(newManifest, finalOutput);
|
|
26
27
|
spinner.clear().stop();
|
|
27
28
|
return {
|
|
28
|
-
output:
|
|
29
|
-
manifest: newManifest,
|
|
30
|
-
steps: [...existingOutput.steps, ...finalOutput.steps],
|
|
31
|
-
publicAssets: [
|
|
32
|
-
...existingOutput.publicAssets,
|
|
33
|
-
...finalOutput.publicAssets
|
|
34
|
-
]
|
|
35
|
-
},
|
|
29
|
+
output: finalOutput,
|
|
36
30
|
manifest: newManifest,
|
|
37
31
|
warnings: manifestWarnings
|
|
38
32
|
};
|
|
@@ -46,7 +46,7 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
46
46
|
if (await isDirMissing(entrypointsDir)) {
|
|
47
47
|
logMissingDir(logger, "Entrypoints", entrypointsDir);
|
|
48
48
|
}
|
|
49
|
-
const filterEntrypoints =
|
|
49
|
+
const filterEntrypoints = mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
|
|
50
50
|
const publicDir = path.resolve(srcDir, mergedConfig.publicDir ?? "public");
|
|
51
51
|
const typesDir = path.resolve(wxtDir, "types");
|
|
52
52
|
const outBaseDir = path.resolve(root, mergedConfig.outDir ?? ".output");
|
|
@@ -2,7 +2,7 @@ import path, { relative, resolve } from "node:path";
|
|
|
2
2
|
import { normalizePath } from "./paths.mjs";
|
|
3
3
|
export function getEntrypointName(entrypointsDir, inputPath) {
|
|
4
4
|
const relativePath = path.relative(entrypointsDir, inputPath);
|
|
5
|
-
const name = relativePath.split(/[
|
|
5
|
+
const name = relativePath.split(/[./\\]/, 2)[0];
|
|
6
6
|
return name;
|
|
7
7
|
}
|
|
8
8
|
export function getEntrypointOutputFile(entrypoint, ext) {
|
|
@@ -190,14 +190,14 @@ function addEntrypoints(manifest, entrypoints, buildOutput) {
|
|
|
190
190
|
options2.browser_style = popup.options.browserStyle;
|
|
191
191
|
if (manifest.manifest_version === 3) {
|
|
192
192
|
manifest.action = {
|
|
193
|
-
...manifest.action
|
|
193
|
+
...manifest.action,
|
|
194
194
|
...options2,
|
|
195
195
|
default_popup
|
|
196
196
|
};
|
|
197
197
|
} else {
|
|
198
198
|
const key = popup.options.mv2Key ?? "browser_action";
|
|
199
199
|
manifest[key] = {
|
|
200
|
-
...manifest[key]
|
|
200
|
+
...manifest[key],
|
|
201
201
|
...options2,
|
|
202
202
|
default_popup
|
|
203
203
|
};
|
|
@@ -325,9 +325,9 @@ function discoverIcons(buildOutput) {
|
|
|
325
325
|
// icon@16h.png
|
|
326
326
|
/^icon@([0-9]+)\.png$/,
|
|
327
327
|
// icon@16.png
|
|
328
|
-
/^icons?[
|
|
328
|
+
/^icons?[/\\]([0-9]+)\.png$/,
|
|
329
329
|
// icon/16.png | icons/16.png
|
|
330
|
-
/^icons?[
|
|
330
|
+
/^icons?[/\\]([0-9]+)x[0-9]+\.png$/
|
|
331
331
|
// icon/16x16.png | icons/16x16.png
|
|
332
332
|
];
|
|
333
333
|
buildOutput.publicAssets.forEach((asset) => {
|
|
@@ -7,7 +7,8 @@ export async function getPackageJson() {
|
|
|
7
7
|
return await fs.readJson(file);
|
|
8
8
|
} catch (err) {
|
|
9
9
|
wxt.logger.debug(
|
|
10
|
-
`Failed to read package.json at: ${file}. Returning undefined
|
|
10
|
+
`Failed to read package.json at: ${file}. Returning undefined.`,
|
|
11
|
+
err
|
|
11
12
|
);
|
|
12
13
|
return {};
|
|
13
14
|
}
|
|
@@ -3,6 +3,10 @@ export declare function kebabCaseAlphanumeric(str: string): string;
|
|
|
3
3
|
* Return a safe variable name for a given string.
|
|
4
4
|
*/
|
|
5
5
|
export declare function safeVarName(str: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Converts a string to a valid filename (NOT path), stripping out invalid characters.
|
|
8
|
+
*/
|
|
9
|
+
export declare function safeFilename(str: string): string;
|
|
6
10
|
/**
|
|
7
11
|
* Removes import statements from the top of a file. Keeps import.meta and inline, async `import()`
|
|
8
12
|
* calls.
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { camelCase } from "scule";
|
|
1
2
|
export function kebabCaseAlphanumeric(str) {
|
|
2
3
|
return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
|
|
3
4
|
}
|
|
4
5
|
export function safeVarName(str) {
|
|
5
|
-
|
|
6
|
+
const name = camelCase(kebabCaseAlphanumeric(str));
|
|
7
|
+
if (name.match(/^[a-z]/)) return name;
|
|
8
|
+
return "_" + name;
|
|
9
|
+
}
|
|
10
|
+
export function safeFilename(str) {
|
|
11
|
+
return kebabCaseAlphanumeric(str);
|
|
6
12
|
}
|
|
7
13
|
export function removeImportStatements(text) {
|
|
8
14
|
return text.replace(
|