wxt 0.16.6 → 0.16.7
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/{chunk-7UFBHZ5F.js → chunk-KKL6XTRP.js} +94 -64
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +95 -65
- package/dist/{index-avHSnR0o.d.cts → index-sl22zA2Z.d.cts} +41 -3
- package/dist/{index-avHSnR0o.d.ts → index-sl22zA2Z.d.ts} +41 -3
- package/dist/index.cjs +114 -84
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/testing.cjs +75 -59
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.16.
|
|
2
|
+
var version = "0.16.7";
|
|
3
3
|
|
|
4
4
|
// src/core/utils/fs.ts
|
|
5
5
|
import fs from "fs-extra";
|
|
@@ -573,29 +573,6 @@ import { createUnimport } from "unimport";
|
|
|
573
573
|
import fs4 from "fs-extra";
|
|
574
574
|
import { relative as relative3, resolve as resolve4 } from "path";
|
|
575
575
|
|
|
576
|
-
// src/core/utils/unimport.ts
|
|
577
|
-
import { defu } from "defu";
|
|
578
|
-
function getUnimportOptions(config) {
|
|
579
|
-
if (config.imports === false)
|
|
580
|
-
return false;
|
|
581
|
-
const defaultOptions = {
|
|
582
|
-
debugLog: config.logger.debug,
|
|
583
|
-
imports: [
|
|
584
|
-
{ name: "defineConfig", from: "wxt" },
|
|
585
|
-
{ name: "fakeBrowser", from: "wxt/testing" }
|
|
586
|
-
],
|
|
587
|
-
presets: [
|
|
588
|
-
{ package: "wxt/client" },
|
|
589
|
-
{ package: "wxt/browser" },
|
|
590
|
-
{ package: "wxt/sandbox" },
|
|
591
|
-
{ package: "wxt/storage" }
|
|
592
|
-
],
|
|
593
|
-
warn: config.logger.warn,
|
|
594
|
-
dirs: ["components", "composables", "hooks", "utils"]
|
|
595
|
-
};
|
|
596
|
-
return defu(config.imports, defaultOptions);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
576
|
// src/core/utils/globals.ts
|
|
600
577
|
function getGlobals(config) {
|
|
601
578
|
return [
|
|
@@ -695,9 +672,12 @@ function parseI18nMessages(messagesJson) {
|
|
|
695
672
|
async function generateTypesDir(entrypoints) {
|
|
696
673
|
await fs4.ensureDir(wxt.config.typesDir);
|
|
697
674
|
const references = [];
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
references.push(await writeImportsDeclarationFile(
|
|
675
|
+
if (wxt.config.imports !== false) {
|
|
676
|
+
const unimport2 = createUnimport(wxt.config.imports);
|
|
677
|
+
references.push(await writeImportsDeclarationFile(unimport2));
|
|
678
|
+
if (wxt.config.imports.eslintrc.enabled) {
|
|
679
|
+
await writeImportsEslintFile(unimport2, wxt.config.imports);
|
|
680
|
+
}
|
|
701
681
|
}
|
|
702
682
|
references.push(await writePathsDeclarationFile(entrypoints));
|
|
703
683
|
references.push(await writeI18nDeclarationFile());
|
|
@@ -705,9 +685,8 @@ async function generateTypesDir(entrypoints) {
|
|
|
705
685
|
const mainReference = await writeMainDeclarationFile(references);
|
|
706
686
|
await writeTsConfigFile(mainReference);
|
|
707
687
|
}
|
|
708
|
-
async function writeImportsDeclarationFile(
|
|
688
|
+
async function writeImportsDeclarationFile(unimport2) {
|
|
709
689
|
const filePath = resolve4(wxt.config.typesDir, "imports.d.ts");
|
|
710
|
-
const unimport2 = createUnimport(unimportOptions);
|
|
711
690
|
await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
|
|
712
691
|
await writeFileIfDifferent(
|
|
713
692
|
filePath,
|
|
@@ -717,6 +696,14 @@ async function writeImportsDeclarationFile(unimportOptions) {
|
|
|
717
696
|
);
|
|
718
697
|
return filePath;
|
|
719
698
|
}
|
|
699
|
+
async function writeImportsEslintFile(unimport2, options) {
|
|
700
|
+
const globals2 = {};
|
|
701
|
+
const eslintrc = { globals: globals2 };
|
|
702
|
+
(await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
|
|
703
|
+
eslintrc.globals[name] = options.eslintrc.globalsPropValue;
|
|
704
|
+
});
|
|
705
|
+
await fs4.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
|
|
706
|
+
}
|
|
720
707
|
async function writePathsDeclarationFile(entrypoints) {
|
|
721
708
|
const filePath = resolve4(wxt.config.typesDir, "paths.d.ts");
|
|
722
709
|
const unions = entrypoints.map(
|
|
@@ -1206,7 +1193,7 @@ var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
1206
1193
|
".svelte"
|
|
1207
1194
|
]);
|
|
1208
1195
|
function unimport(config) {
|
|
1209
|
-
const options =
|
|
1196
|
+
const options = config.imports;
|
|
1210
1197
|
if (options === false)
|
|
1211
1198
|
return [];
|
|
1212
1199
|
const unimport2 = createUnimport2(options);
|
|
@@ -1644,7 +1631,27 @@ function getRollupEntry(entrypoint) {
|
|
|
1644
1631
|
}
|
|
1645
1632
|
|
|
1646
1633
|
// src/core/utils/building/resolve-config.ts
|
|
1647
|
-
import
|
|
1634
|
+
import defu from "defu";
|
|
1635
|
+
|
|
1636
|
+
// src/core/utils/package.ts
|
|
1637
|
+
import { resolve as resolve9 } from "node:path";
|
|
1638
|
+
import fs8 from "fs-extra";
|
|
1639
|
+
async function getPackageJson() {
|
|
1640
|
+
const file = resolve9(wxt.config.root, "package.json");
|
|
1641
|
+
try {
|
|
1642
|
+
return await fs8.readJson(file);
|
|
1643
|
+
} catch (err) {
|
|
1644
|
+
wxt.logger.debug(
|
|
1645
|
+
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
1646
|
+
);
|
|
1647
|
+
return {};
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
function isModuleInstalled(name) {
|
|
1651
|
+
return import(name).then(() => true).catch(() => false);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// src/core/utils/building/resolve-config.ts
|
|
1648
1655
|
async function resolveConfig(inlineConfig, command, server) {
|
|
1649
1656
|
let userConfig = {};
|
|
1650
1657
|
let userConfigMetadata;
|
|
@@ -1715,7 +1722,7 @@ async function resolveConfig(inlineConfig, command, server) {
|
|
|
1715
1722
|
filterEntrypoints,
|
|
1716
1723
|
env,
|
|
1717
1724
|
fsCache: createFsCache(wxtDir),
|
|
1718
|
-
imports:
|
|
1725
|
+
imports: await getUnimportOptions(wxtDir, logger, mergedConfig),
|
|
1719
1726
|
logger,
|
|
1720
1727
|
manifest: await resolveManifestConfig(env, mergedConfig.manifest),
|
|
1721
1728
|
manifestVersion,
|
|
@@ -1772,22 +1779,22 @@ function mergeInlineConfig(inlineConfig, userConfig) {
|
|
|
1772
1779
|
} else if (userConfig.imports == null && inlineConfig.imports == null) {
|
|
1773
1780
|
imports = void 0;
|
|
1774
1781
|
} else {
|
|
1775
|
-
imports =
|
|
1782
|
+
imports = defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
|
|
1776
1783
|
}
|
|
1777
1784
|
const manifest = async (env) => {
|
|
1778
1785
|
const user = await resolveManifestConfig(env, userConfig.manifest);
|
|
1779
1786
|
const inline = await resolveManifestConfig(env, inlineConfig.manifest);
|
|
1780
|
-
return
|
|
1787
|
+
return defu(inline, user);
|
|
1781
1788
|
};
|
|
1782
|
-
const runner =
|
|
1789
|
+
const runner = defu(
|
|
1783
1790
|
inlineConfig.runner ?? {},
|
|
1784
1791
|
userConfig.runner ?? {}
|
|
1785
1792
|
);
|
|
1786
|
-
const zip =
|
|
1793
|
+
const zip = defu(
|
|
1787
1794
|
inlineConfig.zip ?? {},
|
|
1788
1795
|
userConfig.zip ?? {}
|
|
1789
1796
|
);
|
|
1790
|
-
const hooks =
|
|
1797
|
+
const hooks = defu(
|
|
1791
1798
|
inlineConfig.hooks ?? {},
|
|
1792
1799
|
userConfig.hooks ?? {}
|
|
1793
1800
|
);
|
|
@@ -1851,6 +1858,44 @@ function resolveInternalZipConfig(root, mergedConfig) {
|
|
|
1851
1858
|
]
|
|
1852
1859
|
};
|
|
1853
1860
|
}
|
|
1861
|
+
async function getUnimportOptions(wxtDir, logger, config) {
|
|
1862
|
+
if (config.imports === false)
|
|
1863
|
+
return false;
|
|
1864
|
+
const enabledConfig = config.imports?.eslintrc?.enabled;
|
|
1865
|
+
let enabled;
|
|
1866
|
+
switch (enabledConfig) {
|
|
1867
|
+
case void 0:
|
|
1868
|
+
case "auto":
|
|
1869
|
+
enabled = await isModuleInstalled("eslint");
|
|
1870
|
+
break;
|
|
1871
|
+
default:
|
|
1872
|
+
enabled = enabledConfig;
|
|
1873
|
+
}
|
|
1874
|
+
const defaultOptions = {
|
|
1875
|
+
debugLog: logger.debug,
|
|
1876
|
+
imports: [
|
|
1877
|
+
{ name: "defineConfig", from: "wxt" },
|
|
1878
|
+
{ name: "fakeBrowser", from: "wxt/testing" }
|
|
1879
|
+
],
|
|
1880
|
+
presets: [
|
|
1881
|
+
{ package: "wxt/client" },
|
|
1882
|
+
{ package: "wxt/browser" },
|
|
1883
|
+
{ package: "wxt/sandbox" },
|
|
1884
|
+
{ package: "wxt/storage" }
|
|
1885
|
+
],
|
|
1886
|
+
warn: logger.warn,
|
|
1887
|
+
dirs: ["components", "composables", "hooks", "utils"],
|
|
1888
|
+
eslintrc: {
|
|
1889
|
+
enabled,
|
|
1890
|
+
filePath: path5.resolve(wxtDir, "eslintrc-auto-import.json"),
|
|
1891
|
+
globalsPropValue: true
|
|
1892
|
+
}
|
|
1893
|
+
};
|
|
1894
|
+
return defu(
|
|
1895
|
+
config.imports ?? {},
|
|
1896
|
+
defaultOptions
|
|
1897
|
+
);
|
|
1898
|
+
}
|
|
1854
1899
|
|
|
1855
1900
|
// src/core/utils/building/group-entrypoints.ts
|
|
1856
1901
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1894,8 +1939,8 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
|
|
|
1894
1939
|
// src/core/utils/building/import-entrypoint.ts
|
|
1895
1940
|
import createJITI from "jiti";
|
|
1896
1941
|
import { createUnimport as createUnimport3 } from "unimport";
|
|
1897
|
-
import
|
|
1898
|
-
import { relative as relative5, resolve as
|
|
1942
|
+
import fs9 from "fs-extra";
|
|
1943
|
+
import { relative as relative5, resolve as resolve10 } from "node:path";
|
|
1899
1944
|
|
|
1900
1945
|
// src/core/utils/strings.ts
|
|
1901
1946
|
function kebabCaseAlphanumeric(str) {
|
|
@@ -1921,12 +1966,12 @@ async function importEntrypointFile(path7) {
|
|
|
1921
1966
|
wxt.logger.debug("Loading file metadata:", path7);
|
|
1922
1967
|
const normalPath = normalizePath(path7);
|
|
1923
1968
|
const unimport2 = createUnimport3({
|
|
1924
|
-
...
|
|
1969
|
+
...wxt.config.imports,
|
|
1925
1970
|
// Only allow specific imports, not all from the project
|
|
1926
1971
|
dirs: []
|
|
1927
1972
|
});
|
|
1928
1973
|
await unimport2.init();
|
|
1929
|
-
const text = await
|
|
1974
|
+
const text = await fs9.readFile(path7, "utf-8");
|
|
1930
1975
|
const textNoImports = removeProjectImportStatements(text);
|
|
1931
1976
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
1932
1977
|
wxt.logger.debug(
|
|
@@ -1939,7 +1984,7 @@ async function importEntrypointFile(path7) {
|
|
|
1939
1984
|
debug: wxt.config.debug,
|
|
1940
1985
|
esmResolve: true,
|
|
1941
1986
|
alias: {
|
|
1942
|
-
"webextension-polyfill":
|
|
1987
|
+
"webextension-polyfill": resolve10(
|
|
1943
1988
|
wxt.config.root,
|
|
1944
1989
|
"node_modules/wxt/dist/virtual/mock-browser.js"
|
|
1945
1990
|
)
|
|
@@ -1999,12 +2044,12 @@ import pc5 from "picocolors";
|
|
|
1999
2044
|
import fs12 from "fs-extra";
|
|
2000
2045
|
|
|
2001
2046
|
// src/core/utils/log/printBuildSummary.ts
|
|
2002
|
-
import { resolve as
|
|
2047
|
+
import { resolve as resolve11 } from "path";
|
|
2003
2048
|
|
|
2004
2049
|
// src/core/utils/log/printFileList.ts
|
|
2005
2050
|
import path6 from "node:path";
|
|
2006
2051
|
import pc3 from "picocolors";
|
|
2007
|
-
import
|
|
2052
|
+
import fs10 from "fs-extra";
|
|
2008
2053
|
import { filesize } from "filesize";
|
|
2009
2054
|
|
|
2010
2055
|
// src/core/utils/log/printTable.ts
|
|
@@ -2045,7 +2090,7 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
2045
2090
|
];
|
|
2046
2091
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
2047
2092
|
const color = getChunkColor(file);
|
|
2048
|
-
const stats = await
|
|
2093
|
+
const stats = await fs10.lstat(file);
|
|
2049
2094
|
totalSize += stats.size;
|
|
2050
2095
|
const size = String(filesize(stats.size));
|
|
2051
2096
|
return [
|
|
@@ -2087,7 +2132,7 @@ async function printBuildSummary(log, header, output) {
|
|
|
2087
2132
|
return l.fileName.localeCompare(r.fileName);
|
|
2088
2133
|
});
|
|
2089
2134
|
const files = chunks.map(
|
|
2090
|
-
(chunk) =>
|
|
2135
|
+
(chunk) => resolve11(wxt.config.outDir, chunk.fileName)
|
|
2091
2136
|
);
|
|
2092
2137
|
await printFileList(log, header, wxt.config.outDir, files);
|
|
2093
2138
|
}
|
|
@@ -2217,23 +2262,8 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
2217
2262
|
};
|
|
2218
2263
|
}
|
|
2219
2264
|
|
|
2220
|
-
// src/core/utils/package.ts
|
|
2221
|
-
import { resolve as resolve11 } from "node:path";
|
|
2222
|
-
import fs10 from "fs-extra";
|
|
2223
|
-
async function getPackageJson() {
|
|
2224
|
-
const file = resolve11(wxt.config.root, "package.json");
|
|
2225
|
-
try {
|
|
2226
|
-
return await fs10.readJson(file);
|
|
2227
|
-
} catch (err) {
|
|
2228
|
-
wxt.logger.debug(
|
|
2229
|
-
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
2230
|
-
);
|
|
2231
|
-
return {};
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
|
|
2235
2265
|
// src/core/utils/manifest.ts
|
|
2236
|
-
import
|
|
2266
|
+
import defu2 from "defu";
|
|
2237
2267
|
async function writeManifest(manifest, output) {
|
|
2238
2268
|
const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
2239
2269
|
await fs11.ensureDir(wxt.config.outDir);
|
|
@@ -2263,7 +2293,7 @@ async function generateManifest(entrypoints, buildOutput) {
|
|
|
2263
2293
|
icons: discoverIcons(buildOutput)
|
|
2264
2294
|
};
|
|
2265
2295
|
const userManifest = wxt.config.manifest;
|
|
2266
|
-
let manifest =
|
|
2296
|
+
let manifest = defu2(
|
|
2267
2297
|
userManifest,
|
|
2268
2298
|
baseManifest
|
|
2269
2299
|
);
|
|
@@ -2923,11 +2953,11 @@ export {
|
|
|
2923
2953
|
tsconfigPaths,
|
|
2924
2954
|
globals,
|
|
2925
2955
|
webextensionPolyfillMock,
|
|
2956
|
+
getPackageJson,
|
|
2926
2957
|
resolveConfig,
|
|
2927
2958
|
kebabCaseAlphanumeric,
|
|
2928
2959
|
printFileList,
|
|
2929
2960
|
version,
|
|
2930
|
-
getPackageJson,
|
|
2931
2961
|
getContentScriptCssFiles,
|
|
2932
2962
|
getContentScriptsCssMap,
|
|
2933
2963
|
rebuild,
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
CHANGED
|
@@ -596,29 +596,6 @@ import { createUnimport } from "unimport";
|
|
|
596
596
|
import fs4 from "fs-extra";
|
|
597
597
|
import { relative as relative3, resolve as resolve4 } from "path";
|
|
598
598
|
|
|
599
|
-
// src/core/utils/unimport.ts
|
|
600
|
-
import { defu } from "defu";
|
|
601
|
-
function getUnimportOptions(config) {
|
|
602
|
-
if (config.imports === false)
|
|
603
|
-
return false;
|
|
604
|
-
const defaultOptions = {
|
|
605
|
-
debugLog: config.logger.debug,
|
|
606
|
-
imports: [
|
|
607
|
-
{ name: "defineConfig", from: "wxt" },
|
|
608
|
-
{ name: "fakeBrowser", from: "wxt/testing" }
|
|
609
|
-
],
|
|
610
|
-
presets: [
|
|
611
|
-
{ package: "wxt/client" },
|
|
612
|
-
{ package: "wxt/browser" },
|
|
613
|
-
{ package: "wxt/sandbox" },
|
|
614
|
-
{ package: "wxt/storage" }
|
|
615
|
-
],
|
|
616
|
-
warn: config.logger.warn,
|
|
617
|
-
dirs: ["components", "composables", "hooks", "utils"]
|
|
618
|
-
};
|
|
619
|
-
return defu(config.imports, defaultOptions);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
599
|
// src/core/utils/globals.ts
|
|
623
600
|
function getGlobals(config) {
|
|
624
601
|
return [
|
|
@@ -718,9 +695,12 @@ function parseI18nMessages(messagesJson) {
|
|
|
718
695
|
async function generateTypesDir(entrypoints) {
|
|
719
696
|
await fs4.ensureDir(wxt.config.typesDir);
|
|
720
697
|
const references = [];
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
references.push(await writeImportsDeclarationFile(
|
|
698
|
+
if (wxt.config.imports !== false) {
|
|
699
|
+
const unimport2 = createUnimport(wxt.config.imports);
|
|
700
|
+
references.push(await writeImportsDeclarationFile(unimport2));
|
|
701
|
+
if (wxt.config.imports.eslintrc.enabled) {
|
|
702
|
+
await writeImportsEslintFile(unimport2, wxt.config.imports);
|
|
703
|
+
}
|
|
724
704
|
}
|
|
725
705
|
references.push(await writePathsDeclarationFile(entrypoints));
|
|
726
706
|
references.push(await writeI18nDeclarationFile());
|
|
@@ -728,9 +708,8 @@ async function generateTypesDir(entrypoints) {
|
|
|
728
708
|
const mainReference = await writeMainDeclarationFile(references);
|
|
729
709
|
await writeTsConfigFile(mainReference);
|
|
730
710
|
}
|
|
731
|
-
async function writeImportsDeclarationFile(
|
|
711
|
+
async function writeImportsDeclarationFile(unimport2) {
|
|
732
712
|
const filePath = resolve4(wxt.config.typesDir, "imports.d.ts");
|
|
733
|
-
const unimport2 = createUnimport(unimportOptions);
|
|
734
713
|
await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
|
|
735
714
|
await writeFileIfDifferent(
|
|
736
715
|
filePath,
|
|
@@ -740,6 +719,14 @@ async function writeImportsDeclarationFile(unimportOptions) {
|
|
|
740
719
|
);
|
|
741
720
|
return filePath;
|
|
742
721
|
}
|
|
722
|
+
async function writeImportsEslintFile(unimport2, options) {
|
|
723
|
+
const globals2 = {};
|
|
724
|
+
const eslintrc = { globals: globals2 };
|
|
725
|
+
(await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
|
|
726
|
+
eslintrc.globals[name] = options.eslintrc.globalsPropValue;
|
|
727
|
+
});
|
|
728
|
+
await fs4.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
|
|
729
|
+
}
|
|
743
730
|
async function writePathsDeclarationFile(entrypoints) {
|
|
744
731
|
const filePath = resolve4(wxt.config.typesDir, "paths.d.ts");
|
|
745
732
|
const unions = entrypoints.map(
|
|
@@ -1229,7 +1216,7 @@ var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
1229
1216
|
".svelte"
|
|
1230
1217
|
]);
|
|
1231
1218
|
function unimport(config) {
|
|
1232
|
-
const options =
|
|
1219
|
+
const options = config.imports;
|
|
1233
1220
|
if (options === false)
|
|
1234
1221
|
return [];
|
|
1235
1222
|
const unimport2 = createUnimport2(options);
|
|
@@ -1642,7 +1629,27 @@ function getRollupEntry(entrypoint) {
|
|
|
1642
1629
|
}
|
|
1643
1630
|
|
|
1644
1631
|
// src/core/utils/building/resolve-config.ts
|
|
1645
|
-
import
|
|
1632
|
+
import defu from "defu";
|
|
1633
|
+
|
|
1634
|
+
// src/core/utils/package.ts
|
|
1635
|
+
import { resolve as resolve9 } from "node:path";
|
|
1636
|
+
import fs8 from "fs-extra";
|
|
1637
|
+
async function getPackageJson() {
|
|
1638
|
+
const file = resolve9(wxt.config.root, "package.json");
|
|
1639
|
+
try {
|
|
1640
|
+
return await fs8.readJson(file);
|
|
1641
|
+
} catch (err) {
|
|
1642
|
+
wxt.logger.debug(
|
|
1643
|
+
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
1644
|
+
);
|
|
1645
|
+
return {};
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
function isModuleInstalled(name) {
|
|
1649
|
+
return import(name).then(() => true).catch(() => false);
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
// src/core/utils/building/resolve-config.ts
|
|
1646
1653
|
async function resolveConfig(inlineConfig, command, server) {
|
|
1647
1654
|
let userConfig = {};
|
|
1648
1655
|
let userConfigMetadata;
|
|
@@ -1713,7 +1720,7 @@ async function resolveConfig(inlineConfig, command, server) {
|
|
|
1713
1720
|
filterEntrypoints,
|
|
1714
1721
|
env,
|
|
1715
1722
|
fsCache: createFsCache(wxtDir),
|
|
1716
|
-
imports:
|
|
1723
|
+
imports: await getUnimportOptions(wxtDir, logger, mergedConfig),
|
|
1717
1724
|
logger,
|
|
1718
1725
|
manifest: await resolveManifestConfig(env, mergedConfig.manifest),
|
|
1719
1726
|
manifestVersion,
|
|
@@ -1770,22 +1777,22 @@ function mergeInlineConfig(inlineConfig, userConfig) {
|
|
|
1770
1777
|
} else if (userConfig.imports == null && inlineConfig.imports == null) {
|
|
1771
1778
|
imports = void 0;
|
|
1772
1779
|
} else {
|
|
1773
|
-
imports =
|
|
1780
|
+
imports = defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
|
|
1774
1781
|
}
|
|
1775
1782
|
const manifest = async (env) => {
|
|
1776
1783
|
const user = await resolveManifestConfig(env, userConfig.manifest);
|
|
1777
1784
|
const inline = await resolveManifestConfig(env, inlineConfig.manifest);
|
|
1778
|
-
return
|
|
1785
|
+
return defu(inline, user);
|
|
1779
1786
|
};
|
|
1780
|
-
const runner =
|
|
1787
|
+
const runner = defu(
|
|
1781
1788
|
inlineConfig.runner ?? {},
|
|
1782
1789
|
userConfig.runner ?? {}
|
|
1783
1790
|
);
|
|
1784
|
-
const zip2 =
|
|
1791
|
+
const zip2 = defu(
|
|
1785
1792
|
inlineConfig.zip ?? {},
|
|
1786
1793
|
userConfig.zip ?? {}
|
|
1787
1794
|
);
|
|
1788
|
-
const hooks =
|
|
1795
|
+
const hooks = defu(
|
|
1789
1796
|
inlineConfig.hooks ?? {},
|
|
1790
1797
|
userConfig.hooks ?? {}
|
|
1791
1798
|
);
|
|
@@ -1849,6 +1856,44 @@ function resolveInternalZipConfig(root, mergedConfig) {
|
|
|
1849
1856
|
]
|
|
1850
1857
|
};
|
|
1851
1858
|
}
|
|
1859
|
+
async function getUnimportOptions(wxtDir, logger, config) {
|
|
1860
|
+
if (config.imports === false)
|
|
1861
|
+
return false;
|
|
1862
|
+
const enabledConfig = config.imports?.eslintrc?.enabled;
|
|
1863
|
+
let enabled;
|
|
1864
|
+
switch (enabledConfig) {
|
|
1865
|
+
case void 0:
|
|
1866
|
+
case "auto":
|
|
1867
|
+
enabled = await isModuleInstalled("eslint");
|
|
1868
|
+
break;
|
|
1869
|
+
default:
|
|
1870
|
+
enabled = enabledConfig;
|
|
1871
|
+
}
|
|
1872
|
+
const defaultOptions = {
|
|
1873
|
+
debugLog: logger.debug,
|
|
1874
|
+
imports: [
|
|
1875
|
+
{ name: "defineConfig", from: "wxt" },
|
|
1876
|
+
{ name: "fakeBrowser", from: "wxt/testing" }
|
|
1877
|
+
],
|
|
1878
|
+
presets: [
|
|
1879
|
+
{ package: "wxt/client" },
|
|
1880
|
+
{ package: "wxt/browser" },
|
|
1881
|
+
{ package: "wxt/sandbox" },
|
|
1882
|
+
{ package: "wxt/storage" }
|
|
1883
|
+
],
|
|
1884
|
+
warn: logger.warn,
|
|
1885
|
+
dirs: ["components", "composables", "hooks", "utils"],
|
|
1886
|
+
eslintrc: {
|
|
1887
|
+
enabled,
|
|
1888
|
+
filePath: path4.resolve(wxtDir, "eslintrc-auto-import.json"),
|
|
1889
|
+
globalsPropValue: true
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
return defu(
|
|
1893
|
+
config.imports ?? {},
|
|
1894
|
+
defaultOptions
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1852
1897
|
|
|
1853
1898
|
// src/core/utils/building/group-entrypoints.ts
|
|
1854
1899
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1892,8 +1937,8 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
|
|
|
1892
1937
|
// src/core/utils/building/import-entrypoint.ts
|
|
1893
1938
|
import createJITI from "jiti";
|
|
1894
1939
|
import { createUnimport as createUnimport3 } from "unimport";
|
|
1895
|
-
import
|
|
1896
|
-
import { relative as relative5, resolve as
|
|
1940
|
+
import fs9 from "fs-extra";
|
|
1941
|
+
import { relative as relative5, resolve as resolve10 } from "node:path";
|
|
1897
1942
|
|
|
1898
1943
|
// src/core/utils/strings.ts
|
|
1899
1944
|
function kebabCaseAlphanumeric(str) {
|
|
@@ -1919,12 +1964,12 @@ async function importEntrypointFile(path8) {
|
|
|
1919
1964
|
wxt.logger.debug("Loading file metadata:", path8);
|
|
1920
1965
|
const normalPath = normalizePath(path8);
|
|
1921
1966
|
const unimport2 = createUnimport3({
|
|
1922
|
-
...
|
|
1967
|
+
...wxt.config.imports,
|
|
1923
1968
|
// Only allow specific imports, not all from the project
|
|
1924
1969
|
dirs: []
|
|
1925
1970
|
});
|
|
1926
1971
|
await unimport2.init();
|
|
1927
|
-
const text = await
|
|
1972
|
+
const text = await fs9.readFile(path8, "utf-8");
|
|
1928
1973
|
const textNoImports = removeProjectImportStatements(text);
|
|
1929
1974
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
1930
1975
|
wxt.logger.debug(
|
|
@@ -1937,7 +1982,7 @@ async function importEntrypointFile(path8) {
|
|
|
1937
1982
|
debug: wxt.config.debug,
|
|
1938
1983
|
esmResolve: true,
|
|
1939
1984
|
alias: {
|
|
1940
|
-
"webextension-polyfill":
|
|
1985
|
+
"webextension-polyfill": resolve10(
|
|
1941
1986
|
wxt.config.root,
|
|
1942
1987
|
"node_modules/wxt/dist/virtual/mock-browser.js"
|
|
1943
1988
|
)
|
|
@@ -1997,12 +2042,12 @@ import pc5 from "picocolors";
|
|
|
1997
2042
|
import fs12 from "fs-extra";
|
|
1998
2043
|
|
|
1999
2044
|
// src/core/utils/log/printBuildSummary.ts
|
|
2000
|
-
import { resolve as
|
|
2045
|
+
import { resolve as resolve11 } from "path";
|
|
2001
2046
|
|
|
2002
2047
|
// src/core/utils/log/printFileList.ts
|
|
2003
2048
|
import path5 from "node:path";
|
|
2004
2049
|
import pc3 from "picocolors";
|
|
2005
|
-
import
|
|
2050
|
+
import fs10 from "fs-extra";
|
|
2006
2051
|
import { filesize } from "filesize";
|
|
2007
2052
|
|
|
2008
2053
|
// src/core/utils/log/printTable.ts
|
|
@@ -2043,7 +2088,7 @@ async function printFileList(log, header, baseDir, files) {
|
|
|
2043
2088
|
];
|
|
2044
2089
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
2045
2090
|
const color = getChunkColor(file);
|
|
2046
|
-
const stats = await
|
|
2091
|
+
const stats = await fs10.lstat(file);
|
|
2047
2092
|
totalSize += stats.size;
|
|
2048
2093
|
const size = String(filesize(stats.size));
|
|
2049
2094
|
return [
|
|
@@ -2085,7 +2130,7 @@ async function printBuildSummary(log, header, output) {
|
|
|
2085
2130
|
return l.fileName.localeCompare(r.fileName);
|
|
2086
2131
|
});
|
|
2087
2132
|
const files = chunks.map(
|
|
2088
|
-
(chunk) =>
|
|
2133
|
+
(chunk) => resolve11(wxt.config.outDir, chunk.fileName)
|
|
2089
2134
|
);
|
|
2090
2135
|
await printFileList(log, header, wxt.config.outDir, files);
|
|
2091
2136
|
}
|
|
@@ -2107,7 +2152,7 @@ function getChunkSortWeight(filename) {
|
|
|
2107
2152
|
import pc4 from "picocolors";
|
|
2108
2153
|
|
|
2109
2154
|
// package.json
|
|
2110
|
-
var version = "0.16.
|
|
2155
|
+
var version = "0.16.7";
|
|
2111
2156
|
|
|
2112
2157
|
// src/core/utils/log/printHeader.ts
|
|
2113
2158
|
import { consola as consola2 } from "consola";
|
|
@@ -2224,23 +2269,8 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
2224
2269
|
};
|
|
2225
2270
|
}
|
|
2226
2271
|
|
|
2227
|
-
// src/core/utils/package.ts
|
|
2228
|
-
import { resolve as resolve11 } from "node:path";
|
|
2229
|
-
import fs10 from "fs-extra";
|
|
2230
|
-
async function getPackageJson() {
|
|
2231
|
-
const file = resolve11(wxt.config.root, "package.json");
|
|
2232
|
-
try {
|
|
2233
|
-
return await fs10.readJson(file);
|
|
2234
|
-
} catch (err) {
|
|
2235
|
-
wxt.logger.debug(
|
|
2236
|
-
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
2237
|
-
);
|
|
2238
|
-
return {};
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
|
|
2242
2272
|
// src/core/utils/manifest.ts
|
|
2243
|
-
import
|
|
2273
|
+
import defu2 from "defu";
|
|
2244
2274
|
async function writeManifest(manifest, output) {
|
|
2245
2275
|
const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
2246
2276
|
await fs11.ensureDir(wxt.config.outDir);
|
|
@@ -2270,7 +2300,7 @@ async function generateManifest(entrypoints, buildOutput) {
|
|
|
2270
2300
|
icons: discoverIcons(buildOutput)
|
|
2271
2301
|
};
|
|
2272
2302
|
const userManifest = wxt.config.manifest;
|
|
2273
|
-
let manifest =
|
|
2303
|
+
let manifest = defu2(
|
|
2274
2304
|
userManifest,
|
|
2275
2305
|
baseManifest
|
|
2276
2306
|
);
|
|
@@ -2955,7 +2985,7 @@ function createWslRunner() {
|
|
|
2955
2985
|
}
|
|
2956
2986
|
|
|
2957
2987
|
// src/core/runners/web-ext.ts
|
|
2958
|
-
import
|
|
2988
|
+
import defu3 from "defu";
|
|
2959
2989
|
function createWebExtRunner() {
|
|
2960
2990
|
let runner;
|
|
2961
2991
|
return {
|
|
@@ -2986,7 +3016,7 @@ function createWebExtRunner() {
|
|
|
2986
3016
|
} : {
|
|
2987
3017
|
chromiumBinary: wxtUserConfig?.binaries?.[wxt.config.browser],
|
|
2988
3018
|
chromiumProfile: wxtUserConfig?.chromiumProfile,
|
|
2989
|
-
chromiumPref:
|
|
3019
|
+
chromiumPref: defu3(
|
|
2990
3020
|
wxtUserConfig?.chromiumPref,
|
|
2991
3021
|
DEFAULT_CHROMIUM_PREFS
|
|
2992
3022
|
),
|
|
@@ -172,7 +172,7 @@ interface InlineConfig {
|
|
|
172
172
|
* })
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
|
-
imports?:
|
|
175
|
+
imports?: WxtUnimportOptions | false;
|
|
176
176
|
/**
|
|
177
177
|
* Explicitly set a browser to build for. This will override the default browser for each command,
|
|
178
178
|
* and can be overridden by the command line `--browser` option.
|
|
@@ -899,7 +899,7 @@ interface ResolvedConfig {
|
|
|
899
899
|
manifestVersion: TargetManifestVersion;
|
|
900
900
|
env: ConfigEnv;
|
|
901
901
|
logger: Logger;
|
|
902
|
-
imports: false |
|
|
902
|
+
imports: false | WxtResolvedUnimportOptions;
|
|
903
903
|
manifest: UserManifest;
|
|
904
904
|
fsCache: FsCache;
|
|
905
905
|
server?: WxtDevServer;
|
|
@@ -947,5 +947,43 @@ interface ExtensionRunner {
|
|
|
947
947
|
closeBrowser(): Promise<void>;
|
|
948
948
|
}
|
|
949
949
|
type VirtualEntrypointType = 'content-script-main-world' | 'content-script-isolated-world' | 'background' | 'unlisted-script';
|
|
950
|
+
type EslintGlobalsPropValue = boolean | 'readonly' | 'readable' | 'writable' | 'writeable';
|
|
951
|
+
interface Eslintrc {
|
|
952
|
+
/**
|
|
953
|
+
* When true, generates a file that can be used by ESLint to know which variables are valid globals.
|
|
954
|
+
*
|
|
955
|
+
* - `'auto'`: Check if eslint is installed, and if it is, generate the helper file
|
|
956
|
+
* - `true`: Generate the helper file
|
|
957
|
+
* - `false`: Don't generate the file
|
|
958
|
+
*
|
|
959
|
+
* @default 'auto'
|
|
960
|
+
*/
|
|
961
|
+
enabled?: boolean | 'auto';
|
|
962
|
+
/**
|
|
963
|
+
* File path to save the generated eslint config.
|
|
964
|
+
*
|
|
965
|
+
* @default './.wxt/eslintrc-auto-import.json'
|
|
966
|
+
*/
|
|
967
|
+
filePath?: string;
|
|
968
|
+
/**
|
|
969
|
+
* @default true
|
|
970
|
+
*/
|
|
971
|
+
globalsPropValue?: EslintGlobalsPropValue;
|
|
972
|
+
}
|
|
973
|
+
interface ResolvedEslintrc {
|
|
974
|
+
enabled: boolean;
|
|
975
|
+
/** Absolute path */
|
|
976
|
+
filePath: string;
|
|
977
|
+
globalsPropValue: EslintGlobalsPropValue;
|
|
978
|
+
}
|
|
979
|
+
type WxtUnimportOptions = Partial<UnimportOptions> & {
|
|
980
|
+
/**
|
|
981
|
+
* When eslint is installed,
|
|
982
|
+
*/
|
|
983
|
+
eslintrc?: Eslintrc;
|
|
984
|
+
};
|
|
985
|
+
type WxtResolvedUnimportOptions = Partial<UnimportOptions> & {
|
|
986
|
+
eslintrc: ResolvedEslintrc;
|
|
987
|
+
};
|
|
950
988
|
|
|
951
|
-
export type { Wxt as A, BuildOutput as B, ContentScriptEntrypoint as C, ExtensionRunner as D, ExtensionRunnerConfig as E, FsCache as F, GenericEntrypoint as G, HookResult as H, InlineConfig as I, Logger as L, OutputFile as O, PopupEntrypoint as P, ResolvedConfig as R, ServerInfo as S, TargetBrowser as T, UserConfig as U, VirtualEntrypointType as V, WxtDevServer as W, WxtViteConfig as a, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BaseEntrypoint as g, BackgroundEntrypoint as h, OptionsEntrypoint as i, Entrypoint as j, EntrypointGroup as k, OnContentScriptStopped as l, ContentScriptDefinition as m, ContentScriptIsolatedWorldDefinition as n, ContentScriptMainWorldDefinition as o, ContentScriptBaseDefinition as p, BackgroundDefinition as q, UnlistedScriptDefinition as r, PerBrowserOption as s, ExcludableEntrypoint as t, UserManifest as u, UserManifestFn as v, ConfigEnv as w, WxtBuilder as x, WxtBuilderServer as y, WxtHooks as z };
|
|
989
|
+
export type { Wxt as A, BuildOutput as B, ContentScriptEntrypoint as C, ExtensionRunner as D, ExtensionRunnerConfig as E, FsCache as F, GenericEntrypoint as G, HookResult as H, InlineConfig as I, EslintGlobalsPropValue as J, Eslintrc as K, Logger as L, ResolvedEslintrc as M, WxtUnimportOptions as N, OutputFile as O, PopupEntrypoint as P, WxtResolvedUnimportOptions as Q, ResolvedConfig as R, ServerInfo as S, TargetBrowser as T, UserConfig as U, VirtualEntrypointType as V, WxtDevServer as W, WxtViteConfig as a, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BaseEntrypoint as g, BackgroundEntrypoint as h, OptionsEntrypoint as i, Entrypoint as j, EntrypointGroup as k, OnContentScriptStopped as l, ContentScriptDefinition as m, ContentScriptIsolatedWorldDefinition as n, ContentScriptMainWorldDefinition as o, ContentScriptBaseDefinition as p, BackgroundDefinition as q, UnlistedScriptDefinition as r, PerBrowserOption as s, ExcludableEntrypoint as t, UserManifest as u, UserManifestFn as v, ConfigEnv as w, WxtBuilder as x, WxtBuilderServer as y, WxtHooks as z };
|