-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
base: main
Are you sure you want to change the base?
Conversation
…te and sourcesTemplate
✅ Deploy Preview for creative-fairy-df92c4 ready!
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
wxt/packages/wxt/src/core/utils/manifest.ts
Lines 115 to 119 in 14d4aa2
manifest.version_name = | |
// Firefox doesn't support version_name | |
wxt.config.browser === 'firefox' || versionName === version | |
? undefined | |
: versionName; |
There was a problem hiding this comment.
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:
- We call
getPackageJson
in the line above your change. Call it once and extract it into a variable. - Update the JSDoc:
Lines 143 to 156 in f5619f6
/** * 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;
Lines 167 to 180 in f5619f6
/** * 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;
There was a problem hiding this comment.
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 usemanifest.version
{{versionName}}
--> usemanifest.version_name
if available or fallback tomanifest.version
(current behaviour of{{version}}
){{packageVersion}}
--> always usepackage.version
The behaviour of {{version}}
would change but this feels more consistent.
What do you say?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
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.:
With this PR and when using {{packageVersion}} instead of {{version}}, the version in the file names is the same:
Manual Testing
Change your package version to 1.0.0-beta.1 .
Set a custom artifactTemplate and sourcesTemplate in your wxt.config.ts:
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.