wxt 0.2.4 → 0.2.5
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/cli.cjs +65 -16
- package/dist/index.cjs +61 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +61 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -223,7 +223,7 @@ function getUnimportOptions(config) {
|
|
|
223
223
|
],
|
|
224
224
|
presets: [{ package: "wxt/client" }],
|
|
225
225
|
warn: config.logger.warn,
|
|
226
|
-
dirs: ["components", "composables", "hooks", "utils"]
|
|
226
|
+
dirs: ["./components/*", "./composables/*", "./hooks/*", "./utils/*"]
|
|
227
227
|
};
|
|
228
228
|
return mergeConfig(
|
|
229
229
|
defaultOptions,
|
|
@@ -297,6 +297,26 @@ function tsconfigPaths(config) {
|
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
// src/core/vite-plugins/noopBackground.ts
|
|
301
|
+
function noopBackground() {
|
|
302
|
+
const virtualModuleId = VIRTUAL_NOOP_BACKGROUND_MODULE_ID;
|
|
303
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
304
|
+
return {
|
|
305
|
+
name: "wxt:noop-background",
|
|
306
|
+
resolveId(id) {
|
|
307
|
+
if (id === virtualModuleId)
|
|
308
|
+
return resolvedVirtualModuleId;
|
|
309
|
+
},
|
|
310
|
+
load(id) {
|
|
311
|
+
if (id === resolvedVirtualModuleId) {
|
|
312
|
+
return `import { defineBackground } from 'wxt/client';
|
|
313
|
+
export default defineBackground(() => void 0)`;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
|
|
319
|
+
|
|
300
320
|
// src/core/utils/createFsCache.ts
|
|
301
321
|
import fs3, { ensureDir as ensureDir2 } from "fs-extra";
|
|
302
322
|
import { dirname as dirname3, resolve as resolve5 } from "path";
|
|
@@ -470,6 +490,7 @@ async function getInternalConfig(config, command) {
|
|
|
470
490
|
);
|
|
471
491
|
finalConfig.vite.plugins.push(devServerGlobals(finalConfig));
|
|
472
492
|
finalConfig.vite.plugins.push(tsconfigPaths(finalConfig));
|
|
493
|
+
finalConfig.vite.plugins.push(noopBackground());
|
|
473
494
|
finalConfig.vite.define ??= {};
|
|
474
495
|
getGlobals(finalConfig).forEach((global) => {
|
|
475
496
|
finalConfig.vite.define[global.name] = JSON.stringify(global.value);
|
|
@@ -724,6 +745,16 @@ import { createUnimport as createUnimport2 } from "unimport";
|
|
|
724
745
|
import fs6 from "fs-extra";
|
|
725
746
|
import { resolve as resolve8 } from "path";
|
|
726
747
|
import transform from "jiti/dist/babel";
|
|
748
|
+
|
|
749
|
+
// src/core/utils/strings.ts
|
|
750
|
+
function removeImportStatements(text) {
|
|
751
|
+
return text.replace(
|
|
752
|
+
/(import\s?[{\w][\s\S]*?from\s?["'][\s\S]*?["'];?|import\s?["'][\s\S]*?["'];?)/gm,
|
|
753
|
+
""
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/core/utils/importTsFile.ts
|
|
727
758
|
async function importTsFile(path5, config) {
|
|
728
759
|
config.logger.debug("Loading file metadata:", path5);
|
|
729
760
|
const unimport2 = createUnimport2({
|
|
@@ -734,7 +765,7 @@ async function importTsFile(path5, config) {
|
|
|
734
765
|
});
|
|
735
766
|
await unimport2.init();
|
|
736
767
|
const text = await fs6.readFile(path5, "utf-8");
|
|
737
|
-
const textNoImports = text
|
|
768
|
+
const textNoImports = removeImportStatements(text);
|
|
738
769
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
739
770
|
config.logger.debug(
|
|
740
771
|
["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
@@ -774,6 +805,7 @@ async function findEntrypoints(config) {
|
|
|
774
805
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
775
806
|
const existingNames = {};
|
|
776
807
|
const entrypoints = [];
|
|
808
|
+
let hasBackground = false;
|
|
777
809
|
await Promise.all(
|
|
778
810
|
relativePaths.map(async (relativePath) => {
|
|
779
811
|
const path5 = resolve9(config.entrypointsDir, relativePath);
|
|
@@ -803,6 +835,7 @@ ${JSON.stringify(
|
|
|
803
835
|
break;
|
|
804
836
|
case "background":
|
|
805
837
|
entrypoint = await getBackgroundEntrypoint(config, path5);
|
|
838
|
+
hasBackground = true;
|
|
806
839
|
break;
|
|
807
840
|
case "content-script":
|
|
808
841
|
entrypoint = await getContentScriptEntrypoint(
|
|
@@ -832,6 +865,11 @@ ${JSON.stringify(
|
|
|
832
865
|
existingNames[entrypoint.name] = entrypoint;
|
|
833
866
|
})
|
|
834
867
|
);
|
|
868
|
+
if (config.command === "serve" && !hasBackground) {
|
|
869
|
+
entrypoints.push(
|
|
870
|
+
await getBackgroundEntrypoint(config, VIRTUAL_NOOP_BACKGROUND_MODULE_ID)
|
|
871
|
+
);
|
|
872
|
+
}
|
|
835
873
|
return entrypoints;
|
|
836
874
|
}
|
|
837
875
|
async function getPopupEntrypoint(config, path5) {
|
|
@@ -889,9 +927,17 @@ async function getOptionsEntrypoint(config, path5) {
|
|
|
889
927
|
};
|
|
890
928
|
}
|
|
891
929
|
async function getBackgroundEntrypoint(config, path5) {
|
|
892
|
-
|
|
893
|
-
if (
|
|
894
|
-
|
|
930
|
+
let options = {};
|
|
931
|
+
if (path5 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
|
|
932
|
+
const defaultExport = await importTsFile(
|
|
933
|
+
path5,
|
|
934
|
+
config
|
|
935
|
+
);
|
|
936
|
+
if (defaultExport == null) {
|
|
937
|
+
throw Error("Background script does not have a default export");
|
|
938
|
+
}
|
|
939
|
+
const { main: _, ...moduleOptions } = defaultExport;
|
|
940
|
+
options = moduleOptions;
|
|
895
941
|
}
|
|
896
942
|
return {
|
|
897
943
|
type: "background",
|
|
@@ -935,6 +981,7 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
935
981
|
"devtools.html": "devtools",
|
|
936
982
|
"devtools/index.html": "devtools",
|
|
937
983
|
"background.ts": "background",
|
|
984
|
+
[VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
|
|
938
985
|
"content.ts?(x)": "content-script",
|
|
939
986
|
"content/index.ts?(x)": "content-script",
|
|
940
987
|
"*.content.ts?(x)": "content-script",
|
|
@@ -1615,7 +1662,7 @@ async function buildInternal(config) {
|
|
|
1615
1662
|
await fs12.ensureDir(config.outDir);
|
|
1616
1663
|
const entrypoints = await findEntrypoints(config);
|
|
1617
1664
|
const groups = groupEntrypoints(entrypoints);
|
|
1618
|
-
const { output } = await rebuild(config, groups);
|
|
1665
|
+
const { output } = await rebuild(config, groups, void 0);
|
|
1619
1666
|
config.logger.success(
|
|
1620
1667
|
`Built extension in ${formatDuration(Date.now() - startTime)}`
|
|
1621
1668
|
);
|
|
@@ -1627,7 +1674,11 @@ async function rebuild(config, entrypointGroups, existingOutput = {
|
|
|
1627
1674
|
publicAssets: []
|
|
1628
1675
|
}) {
|
|
1629
1676
|
const allEntrypoints = await findEntrypoints(config);
|
|
1630
|
-
await generateTypesDir(allEntrypoints, config)
|
|
1677
|
+
await generateTypesDir(allEntrypoints, config).catch((err) => {
|
|
1678
|
+
config.logger.warn("Failed to update .wxt directory:", err);
|
|
1679
|
+
if (config.command === "build")
|
|
1680
|
+
throw err;
|
|
1681
|
+
});
|
|
1631
1682
|
const newOutput = await buildEntrypoints(entrypointGroups, config);
|
|
1632
1683
|
const mergedOutput = {
|
|
1633
1684
|
steps: [...existingOutput.steps, ...newOutput.steps],
|
|
@@ -1803,7 +1854,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1803
1854
|
}
|
|
1804
1855
|
|
|
1805
1856
|
// package.json
|
|
1806
|
-
var version2 = "0.2.
|
|
1857
|
+
var version2 = "0.2.5";
|
|
1807
1858
|
|
|
1808
1859
|
// src/core/utils/defineConfig.ts
|
|
1809
1860
|
function defineConfig(config) {
|
|
@@ -1843,6 +1894,8 @@ async function createServer2(config) {
|
|
|
1843
1894
|
changeQueue.push([event, path5]);
|
|
1844
1895
|
await fileChangedMutex.runExclusive(async () => {
|
|
1845
1896
|
const fileChanges = changeQueue.splice(0, changeQueue.length);
|
|
1897
|
+
if (fileChanges.length === 0)
|
|
1898
|
+
return;
|
|
1846
1899
|
const changes = detectDevChanges(fileChanges, server.currentOutput);
|
|
1847
1900
|
if (changes.type === "no-change")
|
|
1848
1901
|
return;
|