wxt-turbo 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Steve Zhu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # wxt-turbo
2
+
3
+ WXT module for Turborepo integration.
4
+
5
+ This module intelligently bundles only the extension workspace and its dependent workspaces when creating source zips, excluding unrelated packages from your monorepo.
6
+
7
+ ## Installation
8
+
9
+ ```shell
10
+ pnpm install -D wxt-turbo
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Add the module to your `wxt.config.ts`:
16
+
17
+ ```typescript
18
+ import { defineConfig } from 'wxt';
19
+
20
+ export default defineConfig({
21
+ modules: ['wxt-turbo'],
22
+ turbo: {
23
+ packageName: 'your-extension-package-name',
24
+ copyFiles: [{ from: 'FIREFOX_README.md', to: 'README.md' }, 'LICENSE'],
25
+ cleanup: true, // default: true
26
+ },
27
+ });
28
+ ```
29
+
30
+ ## Features
31
+
32
+ - **Turborepo Pruning**: Automatically prunes your monorepo when running `wxt zip` to include only the necessary sources for the extension.
33
+ - **Extra Files**: Copy extra files (like READMEs or legal docs) into the sources zip during the build process.
34
+
35
+ ## License
36
+
37
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,102 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let node_fs_promises = require("node:fs/promises");
29
+ let node_path = require("node:path");
30
+ let is_path_inside = require("is-path-inside");
31
+ is_path_inside = __toESM(is_path_inside);
32
+ let tinyexec = require("tinyexec");
33
+ let wxt_modules = require("wxt/modules");
34
+
35
+ //#region src/index.ts
36
+ const LOGGER_PREFIX = "`[wxt-turbo]`";
37
+ var src_default = (0, wxt_modules.defineWxtModule)({
38
+ name: "wxt-turbo",
39
+ configKey: "turbo",
40
+ async setup(wxt, options) {
41
+ const packageName = options?.packageName;
42
+ if (!packageName) throw new Error("packageName is required");
43
+ try {
44
+ if ((await (0, tinyexec.x)("turbo", ["--version"])).exitCode !== 0) throw new Error(`${LOGGER_PREFIX} Command failed: \`turbo --version\``);
45
+ wxt.logger.info(LOGGER_PREFIX, "Turborepo detected.");
46
+ } catch (error) {
47
+ if (error instanceof Error && "code" in error && typeof error.code === "string" && error.code === "ENOENT") {
48
+ wxt.logger.warn(LOGGER_PREFIX, "Turborepo is not installed");
49
+ return;
50
+ }
51
+ throw error;
52
+ }
53
+ wxt.hook("config:resolved", (wxt) => {
54
+ if (wxt.config.zip.sourcesRoot === wxt.config.root) wxt.config.zip.sourcesRoot = (0, node_path.join)(wxt.config.outBaseDir, `${(0, node_path.basename)(wxt.config.outDir)}-sources`);
55
+ });
56
+ wxt.hook("zip:sources:start", async (wxt) => {
57
+ await clearZipSourcesRoot(wxt);
58
+ const { sourcesRoot } = wxt.config.zip;
59
+ const absoluteSourcesRoot = (0, node_path.resolve)(wxt.config.root, sourcesRoot);
60
+ const proc = (0, tinyexec.x)("turbo", [
61
+ "prune",
62
+ packageName,
63
+ "--out-dir",
64
+ absoluteSourcesRoot
65
+ ]);
66
+ proc.process?.stdout?.on("data", (data) => {
67
+ wxt.logger.debug(LOGGER_PREFIX, data.toString().trimEnd());
68
+ });
69
+ const res = await proc;
70
+ if (res.exitCode !== 0) throw new Error(res.stderr);
71
+ if (options.copyFiles) for (const fileInfo of options.copyFiles) {
72
+ const { absoluteFromPath, absoluteToPath } = ((fileInfo) => {
73
+ if (typeof fileInfo === "string") return {
74
+ absoluteFromPath: (0, node_path.resolve)(wxt.config.root, fileInfo),
75
+ absoluteToPath: (0, node_path.resolve)(absoluteSourcesRoot, (0, node_path.basename)(fileInfo))
76
+ };
77
+ return {
78
+ absoluteFromPath: (0, node_path.resolve)(wxt.config.root, fileInfo.from),
79
+ absoluteToPath: (0, node_path.resolve)(absoluteSourcesRoot, fileInfo.to)
80
+ };
81
+ })(fileInfo);
82
+ await (0, node_fs_promises.copyFile)(absoluteFromPath, absoluteToPath, node_fs_promises.constants.COPYFILE_EXCL);
83
+ }
84
+ });
85
+ wxt.hook("zip:sources:done", async (wxt) => {
86
+ if (options.cleanup ?? true) await clearZipSourcesRoot(wxt);
87
+ });
88
+ }
89
+ });
90
+ async function clearZipSourcesRoot(wxt) {
91
+ const { sourcesRoot } = wxt.config.zip;
92
+ const absoluteSourcesRoot = (0, node_path.resolve)(wxt.config.root, sourcesRoot);
93
+ if (!(0, is_path_inside.default)(absoluteSourcesRoot, wxt.config.outBaseDir)) throw new Error(`${LOGGER_PREFIX} Sources root config must be in .output/ directory. Received: ${absoluteSourcesRoot}`);
94
+ await (0, node_fs_promises.rm)(absoluteSourcesRoot, {
95
+ recursive: true,
96
+ force: true
97
+ });
98
+ }
99
+
100
+ //#endregion
101
+ module.exports = src_default;
102
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["fsConstants"],"sources":["../src/index.ts"],"sourcesContent":["import { constants as fsConstants, copyFile, rm } from 'node:fs/promises';\nimport { basename, join, resolve } from 'node:path';\n\nimport isPathInside from 'is-path-inside';\nimport { x } from 'tinyexec';\nimport type { Wxt } from 'wxt';\nimport { defineWxtModule } from 'wxt/modules';\n\nexport interface CopyFileConfig {\n /**\n * Source path relative to the project root or absolute path.\n */\n from: string;\n /**\n * Destination path relative to the sources zip root or absolute path.\n */\n to: string;\n}\n\nexport interface TurboModuleOptions {\n /**\n * The package name of the project to generate sources for. This needs to match the package name in the `package.json` of the project.\n */\n packageName: string;\n /**\n * Optional list of files to copy into the sources zip.\n *\n * If a string is provided, it will be copied to the zip sources at the root path.\n *\n * @example\n * [{ from: 'README.md', to: 'README.md' }, 'README.md']\n */\n copyFiles?: (CopyFileConfig | string)[];\n /**\n * Whether to clear the zip sources root directory after the zip file is created.\n *\n * @default true\n */\n cleanup?: boolean;\n}\n\ndeclare module 'wxt' {\n export interface InlineConfig {\n turbo: TurboModuleOptions;\n }\n}\n\nconst LOGGER_PREFIX = '`[wxt-turbo]`';\n\nexport default defineWxtModule<TurboModuleOptions>({\n name: 'wxt-turbo',\n configKey: 'turbo',\n async setup(wxt, options) {\n const packageName = options?.packageName;\n if (!packageName) {\n throw new Error('packageName is required');\n }\n\n // check whether turborepo is installed\n try {\n if ((await x('turbo', ['--version'])).exitCode !== 0) {\n throw new Error(`${LOGGER_PREFIX} Command failed: \\`turbo --version\\``);\n }\n wxt.logger.info(LOGGER_PREFIX, 'Turborepo detected.');\n } catch (error) {\n // https://github.com/nodejs/node/issues/46869\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof error.code === 'string' &&\n error.code === 'ENOENT'\n ) {\n wxt.logger.warn(LOGGER_PREFIX, 'Turborepo is not installed');\n return;\n }\n throw error;\n }\n\n wxt.hook('config:resolved', (wxt) => {\n if (wxt.config.zip.sourcesRoot === wxt.config.root) {\n wxt.config.zip.sourcesRoot = join(\n wxt.config.outBaseDir,\n `${basename(wxt.config.outDir)}-sources`,\n );\n }\n });\n\n wxt.hook('zip:sources:start', async (wxt) => {\n await clearZipSourcesRoot(wxt);\n\n const { sourcesRoot } = wxt.config.zip;\n const absoluteSourcesRoot = resolve(wxt.config.root, sourcesRoot);\n const proc = x('turbo', [\n 'prune',\n packageName,\n '--out-dir',\n absoluteSourcesRoot,\n ]);\n proc.process?.stdout?.on('data', (data: Buffer) => {\n wxt.logger.debug(LOGGER_PREFIX, data.toString().trimEnd());\n });\n const res = await proc;\n if (res.exitCode !== 0) {\n throw new Error(res.stderr);\n }\n\n if (options.copyFiles) {\n for (const fileInfo of options.copyFiles) {\n const { absoluteFromPath, absoluteToPath } = ((\n fileInfo: CopyFileConfig | string,\n ) => {\n if (typeof fileInfo === 'string') {\n return {\n absoluteFromPath: resolve(wxt.config.root, fileInfo),\n absoluteToPath: resolve(\n absoluteSourcesRoot,\n basename(fileInfo),\n ),\n };\n }\n return {\n absoluteFromPath: resolve(wxt.config.root, fileInfo.from),\n absoluteToPath: resolve(absoluteSourcesRoot, fileInfo.to),\n };\n })(fileInfo);\n await copyFile(\n absoluteFromPath,\n absoluteToPath,\n // fail if destination file already exists\n fsConstants.COPYFILE_EXCL,\n );\n }\n }\n });\n\n wxt.hook('zip:sources:done', async (wxt) => {\n if (options.cleanup ?? true) {\n await clearZipSourcesRoot(wxt);\n }\n });\n },\n});\n\nasync function clearZipSourcesRoot(wxt: Wxt) {\n const { sourcesRoot } = wxt.config.zip;\n\n // Safety check: ensure sources root is under .output/\n const absoluteSourcesRoot = resolve(wxt.config.root, sourcesRoot);\n if (!isPathInside(absoluteSourcesRoot, wxt.config.outBaseDir)) {\n throw new Error(\n `${LOGGER_PREFIX} Sources root config must be in .output/ directory. Received: ${absoluteSourcesRoot}`,\n );\n }\n\n await rm(absoluteSourcesRoot, { recursive: true, force: true });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,gBAAgB;AAEtB,mDAAmD;CACjD,MAAM;CACN,WAAW;CACX,MAAM,MAAM,KAAK,SAAS;EACxB,MAAM,cAAc,SAAS;AAC7B,MAAI,CAAC,YACH,OAAM,IAAI,MAAM,0BAA0B;AAI5C,MAAI;AACF,QAAK,sBAAQ,SAAS,CAAC,YAAY,CAAC,EAAE,aAAa,EACjD,OAAM,IAAI,MAAM,GAAG,cAAc,sCAAsC;AAEzE,OAAI,OAAO,KAAK,eAAe,sBAAsB;WAC9C,OAAO;AAEd,OACE,iBAAiB,SACjB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,MAAM,SAAS,UACf;AACA,QAAI,OAAO,KAAK,eAAe,6BAA6B;AAC5D;;AAEF,SAAM;;AAGR,MAAI,KAAK,oBAAoB,QAAQ;AACnC,OAAI,IAAI,OAAO,IAAI,gBAAgB,IAAI,OAAO,KAC5C,KAAI,OAAO,IAAI,kCACb,IAAI,OAAO,YACX,2BAA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src/index.d.ts
4
+ interface CopyFileConfig {
5
+ /**
6
+ * Source path relative to the project root or absolute path.
7
+ */
8
+ from: string;
9
+ /**
10
+ * Destination path relative to the sources zip root or absolute path.
11
+ */
12
+ to: string;
13
+ }
14
+ interface TurboModuleOptions {
15
+ /**
16
+ * The package name of the project to generate sources for. This needs to match the package name in the `package.json` of the project.
17
+ */
18
+ packageName: string;
19
+ /**
20
+ * Optional list of files to copy into the sources zip.
21
+ *
22
+ * If a string is provided, it will be copied to the zip sources at the root path.
23
+ *
24
+ * @example
25
+ * [{ from: 'README.md', to: 'README.md' }, 'README.md']
26
+ */
27
+ copyFiles?: (CopyFileConfig | string)[];
28
+ /**
29
+ * Whether to clear the zip sources root directory after the zip file is created.
30
+ *
31
+ * @default true
32
+ */
33
+ cleanup?: boolean;
34
+ }
35
+ declare module 'wxt' {
36
+ interface InlineConfig {
37
+ turbo: TurboModuleOptions;
38
+ }
39
+ }
40
+ declare const _default: wxt.WxtModule<TurboModuleOptions>;
41
+ //#endregion
42
+ export { CopyFileConfig, TurboModuleOptions, _default as default };
43
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,43 @@
1
+ import * as wxt from "wxt";
2
+
3
+ //#region src/index.d.ts
4
+ interface CopyFileConfig {
5
+ /**
6
+ * Source path relative to the project root or absolute path.
7
+ */
8
+ from: string;
9
+ /**
10
+ * Destination path relative to the sources zip root or absolute path.
11
+ */
12
+ to: string;
13
+ }
14
+ interface TurboModuleOptions {
15
+ /**
16
+ * The package name of the project to generate sources for. This needs to match the package name in the `package.json` of the project.
17
+ */
18
+ packageName: string;
19
+ /**
20
+ * Optional list of files to copy into the sources zip.
21
+ *
22
+ * If a string is provided, it will be copied to the zip sources at the root path.
23
+ *
24
+ * @example
25
+ * [{ from: 'README.md', to: 'README.md' }, 'README.md']
26
+ */
27
+ copyFiles?: (CopyFileConfig | string)[];
28
+ /**
29
+ * Whether to clear the zip sources root directory after the zip file is created.
30
+ *
31
+ * @default true
32
+ */
33
+ cleanup?: boolean;
34
+ }
35
+ declare module 'wxt' {
36
+ interface InlineConfig {
37
+ turbo: TurboModuleOptions;
38
+ }
39
+ }
40
+ declare const _default: wxt.WxtModule<TurboModuleOptions>;
41
+ //#endregion
42
+ export { CopyFileConfig, TurboModuleOptions, _default as default };
43
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,74 @@
1
+ import { constants, copyFile, rm } from "node:fs/promises";
2
+ import { basename, join, resolve } from "node:path";
3
+ import isPathInside from "is-path-inside";
4
+ import { x } from "tinyexec";
5
+ import { defineWxtModule } from "wxt/modules";
6
+
7
+ //#region src/index.ts
8
+ const LOGGER_PREFIX = "`[wxt-turbo]`";
9
+ var src_default = defineWxtModule({
10
+ name: "wxt-turbo",
11
+ configKey: "turbo",
12
+ async setup(wxt, options) {
13
+ const packageName = options?.packageName;
14
+ if (!packageName) throw new Error("packageName is required");
15
+ try {
16
+ if ((await x("turbo", ["--version"])).exitCode !== 0) throw new Error(`${LOGGER_PREFIX} Command failed: \`turbo --version\``);
17
+ wxt.logger.info(LOGGER_PREFIX, "Turborepo detected.");
18
+ } catch (error) {
19
+ if (error instanceof Error && "code" in error && typeof error.code === "string" && error.code === "ENOENT") {
20
+ wxt.logger.warn(LOGGER_PREFIX, "Turborepo is not installed");
21
+ return;
22
+ }
23
+ throw error;
24
+ }
25
+ wxt.hook("config:resolved", (wxt) => {
26
+ if (wxt.config.zip.sourcesRoot === wxt.config.root) wxt.config.zip.sourcesRoot = join(wxt.config.outBaseDir, `${basename(wxt.config.outDir)}-sources`);
27
+ });
28
+ wxt.hook("zip:sources:start", async (wxt) => {
29
+ await clearZipSourcesRoot(wxt);
30
+ const { sourcesRoot } = wxt.config.zip;
31
+ const absoluteSourcesRoot = resolve(wxt.config.root, sourcesRoot);
32
+ const proc = x("turbo", [
33
+ "prune",
34
+ packageName,
35
+ "--out-dir",
36
+ absoluteSourcesRoot
37
+ ]);
38
+ proc.process?.stdout?.on("data", (data) => {
39
+ wxt.logger.debug(LOGGER_PREFIX, data.toString().trimEnd());
40
+ });
41
+ const res = await proc;
42
+ if (res.exitCode !== 0) throw new Error(res.stderr);
43
+ if (options.copyFiles) for (const fileInfo of options.copyFiles) {
44
+ const { absoluteFromPath, absoluteToPath } = ((fileInfo) => {
45
+ if (typeof fileInfo === "string") return {
46
+ absoluteFromPath: resolve(wxt.config.root, fileInfo),
47
+ absoluteToPath: resolve(absoluteSourcesRoot, basename(fileInfo))
48
+ };
49
+ return {
50
+ absoluteFromPath: resolve(wxt.config.root, fileInfo.from),
51
+ absoluteToPath: resolve(absoluteSourcesRoot, fileInfo.to)
52
+ };
53
+ })(fileInfo);
54
+ await copyFile(absoluteFromPath, absoluteToPath, constants.COPYFILE_EXCL);
55
+ }
56
+ });
57
+ wxt.hook("zip:sources:done", async (wxt) => {
58
+ if (options.cleanup ?? true) await clearZipSourcesRoot(wxt);
59
+ });
60
+ }
61
+ });
62
+ async function clearZipSourcesRoot(wxt) {
63
+ const { sourcesRoot } = wxt.config.zip;
64
+ const absoluteSourcesRoot = resolve(wxt.config.root, sourcesRoot);
65
+ if (!isPathInside(absoluteSourcesRoot, wxt.config.outBaseDir)) throw new Error(`${LOGGER_PREFIX} Sources root config must be in .output/ directory. Received: ${absoluteSourcesRoot}`);
66
+ await rm(absoluteSourcesRoot, {
67
+ recursive: true,
68
+ force: true
69
+ });
70
+ }
71
+
72
+ //#endregion
73
+ export { src_default as default };
74
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["fsConstants"],"sources":["../src/index.ts"],"sourcesContent":["import { constants as fsConstants, copyFile, rm } from 'node:fs/promises';\nimport { basename, join, resolve } from 'node:path';\n\nimport isPathInside from 'is-path-inside';\nimport { x } from 'tinyexec';\nimport type { Wxt } from 'wxt';\nimport { defineWxtModule } from 'wxt/modules';\n\nexport interface CopyFileConfig {\n /**\n * Source path relative to the project root or absolute path.\n */\n from: string;\n /**\n * Destination path relative to the sources zip root or absolute path.\n */\n to: string;\n}\n\nexport interface TurboModuleOptions {\n /**\n * The package name of the project to generate sources for. This needs to match the package name in the `package.json` of the project.\n */\n packageName: string;\n /**\n * Optional list of files to copy into the sources zip.\n *\n * If a string is provided, it will be copied to the zip sources at the root path.\n *\n * @example\n * [{ from: 'README.md', to: 'README.md' }, 'README.md']\n */\n copyFiles?: (CopyFileConfig | string)[];\n /**\n * Whether to clear the zip sources root directory after the zip file is created.\n *\n * @default true\n */\n cleanup?: boolean;\n}\n\ndeclare module 'wxt' {\n export interface InlineConfig {\n turbo: TurboModuleOptions;\n }\n}\n\nconst LOGGER_PREFIX = '`[wxt-turbo]`';\n\nexport default defineWxtModule<TurboModuleOptions>({\n name: 'wxt-turbo',\n configKey: 'turbo',\n async setup(wxt, options) {\n const packageName = options?.packageName;\n if (!packageName) {\n throw new Error('packageName is required');\n }\n\n // check whether turborepo is installed\n try {\n if ((await x('turbo', ['--version'])).exitCode !== 0) {\n throw new Error(`${LOGGER_PREFIX} Command failed: \\`turbo --version\\``);\n }\n wxt.logger.info(LOGGER_PREFIX, 'Turborepo detected.');\n } catch (error) {\n // https://github.com/nodejs/node/issues/46869\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof error.code === 'string' &&\n error.code === 'ENOENT'\n ) {\n wxt.logger.warn(LOGGER_PREFIX, 'Turborepo is not installed');\n return;\n }\n throw error;\n }\n\n wxt.hook('config:resolved', (wxt) => {\n if (wxt.config.zip.sourcesRoot === wxt.config.root) {\n wxt.config.zip.sourcesRoot = join(\n wxt.config.outBaseDir,\n `${basename(wxt.config.outDir)}-sources`,\n );\n }\n });\n\n wxt.hook('zip:sources:start', async (wxt) => {\n await clearZipSourcesRoot(wxt);\n\n const { sourcesRoot } = wxt.config.zip;\n const absoluteSourcesRoot = resolve(wxt.config.root, sourcesRoot);\n const proc = x('turbo', [\n 'prune',\n packageName,\n '--out-dir',\n absoluteSourcesRoot,\n ]);\n proc.process?.stdout?.on('data', (data: Buffer) => {\n wxt.logger.debug(LOGGER_PREFIX, data.toString().trimEnd());\n });\n const res = await proc;\n if (res.exitCode !== 0) {\n throw new Error(res.stderr);\n }\n\n if (options.copyFiles) {\n for (const fileInfo of options.copyFiles) {\n const { absoluteFromPath, absoluteToPath } = ((\n fileInfo: CopyFileConfig | string,\n ) => {\n if (typeof fileInfo === 'string') {\n return {\n absoluteFromPath: resolve(wxt.config.root, fileInfo),\n absoluteToPath: resolve(\n absoluteSourcesRoot,\n basename(fileInfo),\n ),\n };\n }\n return {\n absoluteFromPath: resolve(wxt.config.root, fileInfo.from),\n absoluteToPath: resolve(absoluteSourcesRoot, fileInfo.to),\n };\n })(fileInfo);\n await copyFile(\n absoluteFromPath,\n absoluteToPath,\n // fail if destination file already exists\n fsConstants.COPYFILE_EXCL,\n );\n }\n }\n });\n\n wxt.hook('zip:sources:done', async (wxt) => {\n if (options.cleanup ?? true) {\n await clearZipSourcesRoot(wxt);\n }\n });\n },\n});\n\nasync function clearZipSourcesRoot(wxt: Wxt) {\n const { sourcesRoot } = wxt.config.zip;\n\n // Safety check: ensure sources root is under .output/\n const absoluteSourcesRoot = resolve(wxt.config.root, sourcesRoot);\n if (!isPathInside(absoluteSourcesRoot, wxt.config.outBaseDir)) {\n throw new Error(\n `${LOGGER_PREFIX} Sources root config must be in .output/ directory. Received: ${absoluteSourcesRoot}`,\n );\n }\n\n await rm(absoluteSourcesRoot, { recursive: true, force: true });\n}\n"],"mappings":";;;;;;;AA+CA,MAAM,gBAAgB;AAEtB,kBAAe,gBAAoC;CACjD,MAAM;CACN,WAAW;CACX,MAAM,MAAM,KAAK,SAAS;EACxB,MAAM,cAAc,SAAS;AAC7B,MAAI,CAAC,YACH,OAAM,IAAI,MAAM,0BAA0B;AAI5C,MAAI;AACF,QAAK,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC,EAAE,aAAa,EACjD,OAAM,IAAI,MAAM,GAAG,cAAc,sCAAsC;AAEzE,OAAI,OAAO,KAAK,eAAe,sBAA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AoB,IAAI;IAEhC;;CAEL,CAAC;AAEF,eAAe,oBAAoB,KAAU;CAC3C,MAAM,EAAE,gBAAgB,IAAI,OAAO;CAGnC,MAAM,sBAAsB,QAAQ,IAAI,OAAO,MAAM,YAAY;AACjE,KAAI,CAAC,aAAa,qBAAqB,IAAI,OAAO,WAAW,CAC3D,OAAM,IAAI,MACR,GAAG,cAAc,gEAAgE,sBAClF;AAGH,OAAM,GAAG,qBAAqB;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "wxt-turbo",
3
+ "version": "0.1.0",
4
+ "description": "WXT module for Turborepo integration",
5
+ "keywords": [
6
+ "wxt",
7
+ "wxt-module",
8
+ "turborepo",
9
+ "turbo"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/stevezhu/wxt-turbo.git"
14
+ },
15
+ "license": "MIT",
16
+ "author": "Steve Zhu <4130171+stevezhu@users.noreply.github.com>",
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.mts",
21
+ "require": "./dist/index.cjs",
22
+ "import": "./dist/index.mjs"
23
+ }
24
+ },
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.mts",
28
+ "files": [
29
+ "dist/*"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "format": "prettier -w . && eslint . --fix",
34
+ "lint": "prettier -c . && eslint .",
35
+ "test": "tsc --noEmit"
36
+ },
37
+ "dependencies": {
38
+ "is-path-inside": "^4.0.0",
39
+ "tinyexec": "^1.0.2"
40
+ },
41
+ "devDependencies": {
42
+ "@stzhu/eslint-config": "^0.9.0",
43
+ "@stzhu/tsconfig": "^0.1.1",
44
+ "@types/node": "^25.0.3",
45
+ "eslint": "^9.39.2",
46
+ "prettier": "^3.8.1",
47
+ "prettier-plugin-packagejson": "^3.0.0",
48
+ "tsdown": "^0.20.3",
49
+ "typescript": "^5.9.3"
50
+ },
51
+ "peerDependencies": {
52
+ "wxt": "^0.20.0"
53
+ },
54
+ "packageManager": "pnpm@10.28.2",
55
+ "engines": {
56
+ "node": ">=20"
57
+ }
58
+ }