Skip to content

feat(config): Add outDirTemplate for customizing output directory structure - #1074

Merged
aklinker1 merged 5 commits into
wxt-dev:mainfrom
Timeraa:feat-outdirtemplate
Oct 18, 2024
Merged

aklinker1 merged 5 commits into
wxt-dev:mainfrom
Timeraa:feat-outdirtemplate

Conversation

@Timeraa

@Timeraa Timeraa commented Oct 17, 2024

Copy link
Copy Markdown
Member

Closes #1069

This pull request introduces a new feature to allow customization of the output directory structure using a template string. The main changes include adding a new configuration option, updating the build logic to respect this new option, and adding tests to ensure the feature works as expected.

New Feature: Customizable Output Directory Structure

  • packages/wxt/src/types.ts: Added a new configuration option outDirTemplate to the InlineConfig interface, allowing users to define a template string for the output directory. This template can include variables such as {{browser}}, {{manifestVersion}}, {{mode}}, {{modeSuffix}}, and {{command}}.

  • packages/wxt/src/core/resolve-config.ts: Updated the resolveConfig function to process the outDirTemplate configuration option. The function now replaces the template variables with their actual values to determine the output directory path.

Tests

  • packages/wxt/e2e/tests/user-config.test.ts: Added a new test case to verify that the outDirTemplate configuration is respected during the build process. The test checks that the output directory matches the expected structure based on the template.

@Timeraa
Timeraa marked this pull request as ready for review October 17, 2024 14:26
@netlify

netlify Bot commented Oct 17, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 617c23c
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/67127c83bc56d70008e9cfef
😎 Deploy Preview https://deploy-preview-1074--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 site configuration.

@Timeraa Timeraa changed the title feat(#1069): add outDirTemplate feat(config): add outDirTemplate Oct 17, 2024
@pkg-pr-new

pkg-pr-new Bot commented Oct 18, 2024 •

Copy link
Copy Markdown

Open in Stackblitz

@wxt-dev/i18n

pnpm add https://pkg.pr.new/@wxt-dev/i18n@1074

@wxt-dev/module-react

pnpm add https://pkg.pr.new/@wxt-dev/module-react@1074

@wxt-dev/module-solid

pnpm add https://pkg.pr.new/@wxt-dev/module-solid@1074

@wxt-dev/module-svelte

pnpm add https://pkg.pr.new/@wxt-dev/module-svelte@1074

@wxt-dev/module-vue

pnpm add https://pkg.pr.new/@wxt-dev/module-vue@1074

wxt

pnpm add https://pkg.pr.new/wxt@1074

@wxt-dev/auto-icons

pnpm add https://pkg.pr.new/@wxt-dev/auto-icons@1074

commit: 617c23c

@codecov

codecov Bot commented Oct 18, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.13%. Comparing base (a0b63e7) to head (617c23c).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1074      +/-   ##
==========================================
- Coverage   82.16%   82.13%   -0.04%     
==========================================
  Files         127      127              
  Lines        6634     6645      +11     
  Branches     1102     1109       +7     
==========================================
+ Hits         5451     5458       +7     
- Misses       1169     1173       +4     
  Partials       14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aklinker1 aklinker1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, looks good. Thank you for adding tests :)

Comment thread packages/wxt/src/types.ts Resolved
Comment thread packages/wxt/src/core/resolve-config.ts Resolved
@aklinker1 aklinker1 changed the title feat(config): add outDirTemplate feat(config): Add outDirTemplate for customizing output directory structure Oct 18, 2024
@aklinker1

Copy link
Copy Markdown
Member

Waiting for @avi12 to try this out before merging

@avi12

avi12 commented Oct 18, 2024 •

Copy link
Copy Markdown
Contributor

That's odd, even though the dev server has seemingly detected a change in the content script, it didn't load the updated content script
e.g. say the content script is

// yttm-tracker.content.ts
export default defineContentScript({
  matches: ["https://www.youtube.com/*"],
  main() {
    console.log("init yttm-tracker 1");
  }
});

then the CS reloads, logs "init yttm-tracker 1"
Next, I change it to

// yttm-tracker.content.ts
export default defineContentScript({
  matches: ["https://www.youtube.com/*"],
  main() {
    console.log("init yttm-tracker 2");
  }
});

the dev server will detect the change but after a web page reload, it will still log "init yttm-tracker 1"

@aklinker1

aklinker1 commented Oct 18, 2024 •

Copy link
Copy Markdown
Member

@avi12 Hmm, very weird. I can reproduce your problem, and I'm also running into another issue:

Details
$ pnpm wxt

WXT 0.19.11                                                                                             1:07:58 PM
ℹ Example module with options: { a: 'a', c: 'c' }                                                      1:07:58 PM
ℹ [i18n] Default locale: en                                                                            1:07:58 PM
✔ Started dev server @ http://localhost:3000                                                           1:07:58 PM
ℹ Pre-rendering chrome-mv3 for development with Vite 5.4.8                                             1:07:58 PM
⠹ [2/11] example-2Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

More info: https://sass-lang.com/d/legacy-js-api

✔ Built extension in 1.558 s                                                                           1:08:00 PM
  ├─ .output/chrome-mv3-dev/manifest.json                       1.61 kB
  ├─ .output/chrome-mv3-dev/example.html                        540 B
  ├─ .output/chrome-mv3-dev/iframe-src.html                     594 B
  ├─ .output/chrome-mv3-dev/options.html                        687 B
  ├─ .output/chrome-mv3-dev/popup.html                          558 B
  ├─ .output/chrome-mv3-dev/sandbox.html                        540 B
  ├─ .output/chrome-mv3-dev/sidepanel.html                      477 B
  ├─ .output/chrome-mv3-dev/background.js                       110.51 kB
  ├─ .output/chrome-mv3-dev/chunks/reload-html-BxzUToPe.js      8.17 kB
  ├─ .output/chrome-mv3-dev/chunks/reload-html-BxzUToPe.js      8.17 kB
  ├─ .output/chrome-mv3-dev/content-scripts/example-tsx.js      3.25 MB
  ├─ .output/chrome-mv3-dev/content-scripts/iframe.js           41.42 kB
  ├─ .output/chrome-mv3-dev/content-scripts/location-change.js  28.03 kB
  ├─ .output/chrome-mv3-dev/content-scripts/main-world.js       2.05 kB
  ├─ .output/chrome-mv3-dev/content-scripts/ui.js               57.91 kB
  ├─ .output/chrome-mv3-dev/unlisted.js                         1.9 kB
  ├─ .output/chrome-mv3-dev/content-scripts/injected.css        24 B
  ├─ .output/chrome-mv3-dev/content-scripts/ui.css              150 B
  ├─ .output/chrome-mv3-dev/_locales/en/messages.json           714 B
  ├─ .output/chrome-mv3-dev/icons/128.png                       1.55 kB
  ├─ .output/chrome-mv3-dev/icons/16.png                        568 B
  ├─ .output/chrome-mv3-dev/icons/32.png                        1.24 kB
  └─ .output/chrome-mv3-dev/icons/48.png                        1.99 kB
Σ Total size: 3.52 MB
✖ Command failed after 27.3 s                                                                          1:08:25 PM

 ERROR  connect ECONNREFUSED 127.0.0.1:61862                                                            1:08:25 PM

  at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)

The server just quits on me after 30 seconds lol

@aklinker1

Copy link
Copy Markdown
Member

OK, that happens even without setting the outDirTemplate variable, so unrelated.

@avi12

avi12 commented Oct 18, 2024 •

Copy link
Copy Markdown
Contributor

Weird, just tried rerunning the dev server as wxt --mode dev and then as wxt and the problem seemingly got solved

@aklinker1

Copy link
Copy Markdown
Member

I noticed content scripts didn't reload correctly when using --user-data-dir chrome flag. It worked when I removed that.

@aklinker1

aklinker1 commented Oct 18, 2024 •

Copy link
Copy Markdown
Member

OK, so I had to 100% quit out of Chrome when using --user-data-dir, otherwise web-ext didn't update the installed extension to .output/chrome-mv3-dev, it kept using .output/chrome-mv3, hence the old code. You can see where an extension is installed from locally at the bottom of the extension's details page at chrome://extensions. After quitting out of Chrome, it worked. Uninstalling and then re-running the dev command also worked.

@aklinker1

Copy link
Copy Markdown
Member

My dev server also stopped crashing once the browser was pointing at the latest folder. Seems to be a bug in web-ext or chrome.

@avi12

avi12 commented Oct 18, 2024

Copy link
Copy Markdown
Contributor

It's worth reporting the bug to web-ext then

@aklinker1

Copy link
Copy Markdown
Member

Could be fixed already, might just need to update my fork. Will look into this, but I don't think it's a blocker for this PR. Gonna merge it.

@avi12

avi12 commented Oct 18, 2024

Copy link
Copy Markdown
Contributor

I have a question: If I put wxt --mode dev --mode test, which mode will be set?

@aklinker1

Copy link
Copy Markdown
Member

I have a question: If I put wxt --mode dev --mode test, which mode will be set?

No clue, not sure how CAC handles that. Just add a log printing import.meta.env.MODE at the beginning of your background or something.

@aklinker1
aklinker1 merged commit d09cf6d into wxt-dev:main Oct 18, 2024
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.

outDirTemplate for customizing output directory

3 participants