Skip to content

Commit 2e1bbce

Browse files
authored
Merge pull request #29 from siphomateke/add-manifest-transformer
Add a new plugin option to modify the outputted manifest
2 parents 2f6e5e0 + ac550db commit 2e1bbce

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ module.exports = {
134134

135135
Currently, the only supported keys are `version` and `description`.
136136

137+
- **manifestTransformer**
138+
- Type: `Function`
139+
140+
Function to modify the manifest JSON outputted by this plugin.
141+
142+
An example use case is adding or removing permissions depending on which browser is being targeted.
143+
144+
```js
145+
manifestTransformer: (manifest) => {
146+
if (process.env.BROWSER === 'chrome') {
147+
manifest.permissions.push('pageCapture');
148+
}
149+
return manifest;
150+
}
151+
```
152+
137153
- **modesToZip**
138154
- Type: `Array<string>`
139155
- Default: `['production']`

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ const defaultOptions = {
99
components: {},
1010
componentOptions: {},
1111
manifestSync: ['version'],
12-
modesToZip: ['production']
12+
modesToZip: ['production'],
13+
manifestTransformer: null
1314
}
1415
const performanceAssetFilterList = [
1516
(file) => !/\.map$/.test(file),
1617
(file) => !file.endsWith('.zip'),
1718
(file) => !/^icons\//.test(file)
1819
]
1920

21+
function getManifestJsonString(pluginOptions, jsonContent) {
22+
if (pluginOptions.manifestTransformer) {
23+
const jsonContentCopy = Object.assign({}, jsonContent);
24+
jsonContent = pluginOptions.manifestTransformer(jsonContentCopy)
25+
}
26+
return JSON.stringify(jsonContent, null, 2)
27+
}
28+
2029
module.exports = (api, options) => {
2130
const appRootPath = api.getCwd()
2231
const pluginOptions = options.pluginOptions.browserExtension
@@ -97,7 +106,7 @@ module.exports = (api, options) => {
97106
}
98107

99108
if (isProduction) {
100-
return resolve(JSON.stringify(jsonContent, null, 2))
109+
return resolve(getManifestJsonString(pluginOptions, jsonContent))
101110
}
102111

103112
jsonContent.content_security_policy =
@@ -113,13 +122,13 @@ module.exports = (api, options) => {
113122
}
114123

115124
jsonContent.key = stdout
116-
resolve(JSON.stringify(jsonContent, null, 2))
125+
resolve(getManifestJsonString(pluginOptions, jsonContent))
117126
})
118127
} catch (error) {
119128
logger.warn(
120129
'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
121130
)
122-
resolve(JSON.stringify(jsonContent, null, 2))
131+
resolve(getManifestJsonString(pluginOptions, jsonContent))
123132
}
124133
})
125134
}

0 commit comments

Comments
 (0)