@@ -3,7 +3,8 @@ const webpack = require('webpack')
3
3
const CopyWebpackPlugin = require('copy-webpack-plugin')
4
4
const ExtensionReloader = require('webpack-extension-reloader')
5
5
const ZipPlugin = require('zip-webpack-plugin')
6
- const { keyExists, hashKey } = require('./lib/signing-key')
6
+ const { keyExists } = require('./lib/signing-key')
7
+ const manifestTransformer = require('./lib/manifest')
7
8
const defaultOptions = {
8
9
components: {},
9
10
componentOptions: {},
@@ -17,14 +18,6 @@ const performanceAssetFilterList = [
17
18
(file) => !/^icons\//.test(file)
18
19
]
19
20
20
- function getManifestJsonString (pluginOptions, jsonContent) {
21
- if (pluginOptions.manifestTransformer) {
22
- const jsonContentCopy = Object.assign({}, jsonContent)
23
- jsonContent = pluginOptions.manifestTransformer(jsonContentCopy)
24
- }
25
- return JSON.stringify(jsonContent, null, 2)
26
- }
27
-
28
21
module.exports = (api, options) => {
29
22
const appRootPath = api.getCwd()
30
23
const pluginOptions = options.pluginOptions.browserExtension
@@ -68,41 +61,7 @@ module.exports = (api, options) => {
68
61
{
69
62
from: './src/manifest.json',
70
63
to: 'manifest.json',
71
- transform: async (content) => {
72
- const jsonContent = JSON.parse(content)
73
- if (pluginOptions.manifestSync.includes('version')) {
74
- jsonContent.version = packageJson.version
75
- }
76
- if (pluginOptions.manifestSync.includes('description')) {
77
- jsonContent.description = packageJson.description
78
- }
79
-
80
- jsonContent.content_security_policy =
81
- jsonContent.content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
82
-
83
- // If building for production (going to web store) abort early.
84
- // The browser extension store will hash your signing key and apply CSP policies.
85
- if (isProduction) {
86
- jsonContent.content_security_policy = jsonContent.content_security_policy.replace(/'unsafe-eval'/, '')
87
-
88
- return getManifestJsonString(pluginOptions, jsonContent)
89
- }
90
-
91
- if (hasKeyFile) {
92
- try {
93
- jsonContent.key = await hashKey(keyFile)
94
- } catch (error) {
95
- logger.error('Unexpected error hashing keyfile:', error)
96
- }
97
- }
98
- if (!jsonContent.key) {
99
- logger.warn(
100
- 'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
101
- )
102
- }
103
-
104
- return getManifestJsonString(pluginOptions, jsonContent)
105
- }
64
+ transform: manifestTransformer(api, pluginOptions, packageJson)
106
65
}
107
66
]
108
67
])
0 commit comments