Skip to content

Commit 53c8c49

Browse files
committed
Add manifest transformer option
1 parent 1bfc292 commit 53c8c49

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
@@ -124,6 +124,22 @@ module.exports = {
124124

125125
Currently, the only supported keys are `version` and `description`.
126126

127+
- **manifestTransformer**
128+
- Type: `Function`
129+
130+
Function to modify the manifest JSON outputted by this plugin.
131+
132+
An example use case is adding or removing permissions depending on which browser is being targeted.
133+
134+
```js
135+
manifestTransformer: (manifest) => {
136+
if (process.env.BROWSER === 'chrome') {
137+
manifest.permissions.push('pageCapture');
138+
}
139+
return manifest;
140+
}
141+
```
142+
127143
- **modesToZip**
128144
- Type: `Array<string>`
129145
- 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 ? Object.assign(defaultOptions, options.pluginOptions.browserExtension) : defaultOptions
@@ -91,7 +100,7 @@ module.exports = (api, options) => {
91100
}
92101

93102
if (isProduction) {
94-
return resolve(JSON.stringify(jsonContent, null, 2))
103+
return resolve(getManifestJsonString(pluginOptions, jsonContent))
95104
}
96105

97106
jsonContent.content_security_policy = jsonContent.content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
@@ -106,11 +115,11 @@ module.exports = (api, options) => {
106115
}
107116

108117
jsonContent.key = stdout
109-
resolve(JSON.stringify(jsonContent, null, 2))
118+
resolve(getManifestJsonString(pluginOptions, jsonContent))
110119
})
111120
} catch (error) {
112121
logger.warn('No key.pem file found. This is fine for dev, however you may have problems publishing without one')
113-
resolve(JSON.stringify(jsonContent, null, 2))
122+
resolve(getManifestJsonString(pluginOptions, jsonContent))
114123
}
115124
})
116125
}

0 commit comments

Comments
 (0)