Skip to content

feat: add {{packageVersion}} as template variable #1604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Tensai75
Copy link
Contributor

Overview

This PR adds {{packageVersion}} as an additional template variable to artifactTemplate and sourcesTemplate.
Currently only {{version}} can be used. However, when building for Firefox, a package version such as 1.0.0-beta.1 is reduced to 1.0.0 because Firefox does not allow suffixes in the version in the manifest file. Therefore, the version numbers in the file names of the zip files for Firefox differ from the version number in the file name for Chrome, e.g.:

myextension-1.0.0-beta.1-chrome.zip
myextension-1.0.0-firefox.zip
myextension-1.0.0-sources.zip

With this PR and when using {{packageVersion}} instead of {{version}}, the version in the file names is the same:

myextension-1.0.0-beta.1-chrome.zip
myextension-1.0.0-beta.1-firefox.zip
myextension-1.0.0-beta.1-sources.zip

Manual Testing

Change your package version to 1.0.0-beta.1 .
Set a custom artifactTemplate and sourcesTemplate in your wxt.config.ts:

artifactTemplate: "{{name}}-{{packageVersion}}-{{browser}}.zip",
sourcesTemplate: "{{name}}-{{packageVersion}}-sources.zip" ,

Run wxt zip -b firefox.
The resulting zip files should contain the package version 1.0.0-beta.1 in the file name.

Related Issue

N/A
I think this PR might be beneficial for people like me who want to see the package version number in the filename.

Copy link

netlify bot commented Apr 22, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 4da8ae9
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/6809d85c20fb2f00086da8c1
😎 Deploy Preview https://deploy-preview-1604--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.

@@ -39,6 +40,7 @@ export async function zip(config?: InlineConfig): Promise<string[]> {
'{{version}}',
output.manifest.version_name ?? output.manifest.version,
Copy link
Collaborator

@aklinker1 aklinker1 Apr 23, 2025

Choose a reason for hiding this comment

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

As you can see here, the {{version}} template variable will already use the manifest.version_name if it exists... And as long as you haven't manually set the manifest's version property, it will be automatically pulled from the package.json:

https://wxt.dev/guide/essentials/config/manifest.html#version-and-version-name

Copy link
Contributor Author

@Tensai75 Tensai75 Apr 23, 2025

Choose a reason for hiding this comment

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

No, it doesn't.
I use custom artifactTemplate and sourcesTemplate:

zip: {
    excludeSources: ['icons/**', 'screenshots/**', '*.yml'],
    artifactTemplate: '{{name}}-v{{version}}-{{browser}}.zip',
    sourcesTemplate: '{{name}}-v{{version}}-sources.zip',
  },

Package version is 1.0.0-beta.1 and I don't set the manifest's version property manually. But the resulting zip files are named:

myextension-v1.0.0-beta.1-chrome.zip
myextension-v1.0.0-firefox.zip
myextension-v1.0.0-sources.zip

-beta.1 is not included in the firefox and sources zip!

EDIT: this is probably because Firefox does not support version_name and hence when building/zipping for Firefox, version_name is not used?

EDIT2: Yep, I was right:

manifest.version_name =
// Firefox doesn't support version_name
wxt.config.browser === 'firefox' || versionName === version
? undefined
: versionName;

Copy link
Collaborator

@aklinker1 aklinker1 Apr 24, 2025

Choose a reason for hiding this comment

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

Hmm, I understand the problem now, yeah, I'm OK with this change.

Two changes then based on your PR:

  1. We call getPackageJson in the line above your change. Call it once and extract it into a variable.
  2. Update the JSDoc:
    /**
    * Configure the filename output when zipping files.
    *
    * Available template variables:
    *
    * - <span v-pre>`{{name}}`</span> - The project's name converted to kebab-case
    * - <span v-pre>`{{version}}`</span> - The version_name or version from the manifest
    * - <span v-pre>`{{browser}}`</span> - The target browser from the `--browser` CLI flag
    * - <span v-pre>`{{mode}}`</span> - The current mode
    * - <span v-pre>`{{manifestVersion}}`</span> - Either "2" or "3"
    *
    * @default "{{name}}-{{version}}-{{browser}}.zip"
    */
    artifactTemplate?: string;

    /**
    * Configure the filename output when zipping files.
    *
    * Available template variables:
    *
    * - <span v-pre>`{{name}}`</span> - The project's name converted to kebab-case
    * - <span v-pre>`{{version}}`</span> - The version_name or version from the manifest
    * - <span v-pre>`{{browser}}`</span> - The target browser from the `--browser` CLI flag
    * - <span v-pre>`{{mode}}`</span> - The current mode
    * - <span v-pre>`{{manifestVersion}}`</span> - Either "2" or "3"
    *
    * @default "{{name}}-{{version}}-sources.zip"
    */
    sourcesTemplate?: string;

Copy link
Contributor Author

@Tensai75 Tensai75 Apr 24, 2025

Choose a reason for hiding this comment

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

If you are OK with a breaking change, maybe it would be more consistent to to have 3 template variables for the version:

  • {{version}} --> strictly use manifest.version
  • {{versionName}} --> use manifest.version_name if available or fallback to manifest.version (current behaviour of {{version}})
  • {{packageVersion}} --> always use package.version

The behaviour of {{version}} would change but this feels more consistent.

What do you say?

Copy link
Collaborator

@aklinker1 aklinker1 Apr 24, 2025

Choose a reason for hiding this comment

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

Eventually that's probably a good idea. If you want this PR merged soon, make the breaking change in the breaking change in a second PR and I'll add it to the next major release whenever that happens.

If it's not urgent, you are welcome to update this PR with that change!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the PR according to your suggestions. I hope it is OK.
I will create a separate PR for the breaking change later.

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.

2 participants