Skip to content

Conversation

johnnyfekete
Copy link
Contributor

@johnnyfekete johnnyfekete commented Jul 25, 2025

First real contribution here, hope I understood the issue correctly 🙂

Overview

Adds experimental autoIncludeExternalSources option to automatically include external source files in zip archives for monorepo setups.
When enabled, WXT analyzes the build output to find imported files from outside the extension directory and includes them in the sources zip. This eliminates the need for manual configuration when extensions import from parent/sibling packages.

The feature is disabled by default for backward compatibility and marked as experimental.

Manual Testing

  1. Create a shared file outside your extension: ../shared-lib/utils.ts
  2. Import it in your extension: import { util } from '../../../shared-lib/utils';
  3. Enable in config: zip: { autoIncludeExternalSources: true }
  4. Run wxt zip -b firefox
  5. Check sources zip contains the external file's contents

Related Issue

This PR closes #1505

Copy link

netlify bot commented Jul 25, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 0895d28
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/68a4415e91b3350007aecf56
😎 Deploy Preview https://deploy-preview-1826--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

WXT uses the command `npm pack <package-name>` to download the package. That means regardless of your package manager, you need to properly setup a `.npmrc` file. NPM and PNPM both respect `.npmrc` files, but Yarn and Bun have their own ways of authorizing private registries, so you'll need to add a `.npmrc` file.
:::

#### Include External Sources (Experimental)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, if this is the right place to add the documentation 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably fine.

@johnnyfekete johnnyfekete marked this pull request as ready for review July 30, 2025 12:13
Copy link
Member

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the idea, just need to see a better E2E test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't actually test the new behavior. Please actually include a external file in project, then extract and make sure the are included.

Here's an example of how to unzip and check for file existence: https://github.com/johnnyfekete/wxt/blob/d632e5c3cdd96421662b791c6d6008b32dde666e/packages/wxt/e2e/tests/zip.test.ts#L103-L123

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I changed them. It was a lot more complicated than I thought, so maybe you can think of a nicer way to test files that are outside of the project folder, but I'm using the zip test functionalities that you recommended.

WXT uses the command `npm pack <package-name>` to download the package. That means regardless of your package manager, you need to properly setup a `.npmrc` file. NPM and PNPM both respect `.npmrc` files, but Yarn and Bun have their own ways of authorizing private registries, so you'll need to add a `.npmrc` file.
:::

#### Include External Sources (Experimental)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably fine.

@johnnyfekete johnnyfekete requested a review from aklinker1 August 19, 2025 11:13
@st3h3n
Copy link
Contributor

st3h3n commented Aug 22, 2025

This seems to generally work quite well, but I came across a conceptual problem:

Let's say the WXT root is in monorepo/packages/wxt. If you run wxt zip the resulting zip file will include the sources from the other packages in a .. directory. But because of the Zip Slip Vulnerability most zip tools will ignore this directory when unzipping the file.

No problem, just use sourcesRoot: '../', and in order to not include all packages: { excludeSources: '**', includeSources: ['wxt/**'] }. But now the collected external sources will be omitted.

I think excludeSources should either ignore the auto collected sources, or be ignored, or there could be seperate controls for it. While this was also mentioned in this post, I would disagree regarding the includeSources option being ignored, as there are common usecases like includeSources: ['../tsconfig.json', '../package.json', ../assets/**].

@st3h3n
Copy link
Contributor

st3h3n commented Sep 1, 2025

I've had some more time to look into this. I've found some files are missing:

  1. A file which only contains a re-export: export { foo as bar } from 'foobar';
  2. Files that only contain build-time content, so .ts files that only export interfaces or types. I would expect .d.ts to also be affected.
  3. All .html and .less files. The reason for that is me using Angular. But the plugin that makes it Vite compatible uses Vite to resolve those files so a mechanism that hooks into Vite's resolver should still be able to catch these.

I'm a complete noob at Vite, hence why I didn't try to implement this feature myself, but I suspect that the approach of working from the build chunks backwards cannot solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic gathering of used files for zip
3 participants