@@ -3,7 +3,8 @@ const webpack = require('webpack')
33const CopyWebpackPlugin = require ( 'copy-webpack-plugin' )
44const ExtensionReloader = require ( 'webpack-extension-reloader' )
55const 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' )
78const defaultOptions = {
89 components : { } ,
910 componentOptions : { } ,
@@ -17,14 +18,6 @@ const performanceAssetFilterList = [
1718 ( file ) => ! / ^ i c o n s \/ / . test ( file )
1819]
1920
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-
2821module . exports = ( api , options ) => {
2922 const appRootPath = api . getCwd ( )
3023 const pluginOptions = options . pluginOptions . browserExtension
@@ -68,41 +61,7 @@ module.exports = (api, options) => {
6861 {
6962 from : './src/manifest.json' ,
7063 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 ( / ' u n s a f e - e v a l ' / , '' )
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 )
10665 }
10766 ]
10867 ] )
0 commit comments