Skip to content

Commit

Permalink
Add an inline variable for the addon version
Browse files Browse the repository at this point in the history
`__addon_version__` is now a global variable that's usable within an addon which will get replaced at compile-time with the version found in the corresponding manifest file
  • Loading branch information
Lordmau5 committed Oct 27, 2024
1 parent 00af0b1 commit 342f603
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = {
'__webpack_hash__': false,
'__git_commit__': false,
'FrankerFaceZ': false,
'Addon': false
'Addon': false,
'__addon_version__': false,
},
'rules': {
'accessor-pairs': ['error'],
Expand Down
18 changes: 18 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const config = {

module: {
rules: [
// Register method replace to include the addon's name
{
test: /index\.jsx?$/,
exclude: /node_modules/,
Expand All @@ -197,6 +198,23 @@ const config = {
}
}
},
// Inline variable for addon version
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'string-replace-loader',
options: {
search: /__addon_version__/g,
replace(match, offset, string) {
let folder = path.relative(this.rootContext, path.dirname(this.resource));
if ( folder.startsWith('src\\') || folder.startsWith('src/') )
folder = folder.split(path.sep)[1];

const manifest = MANIFESTS[folder];
return JSON.stringify(manifest?.version ?? '0.0.0-unknown');
}
}
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
Expand Down

0 comments on commit 342f603

Please sign in to comment.