Skip to content

Commit 0903294

Browse files
committed
Refactored the manifest transform function
Uses async/await and utilizes an earlier synchronous fs check
1 parent 09bb924 commit 0903294

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

index.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,42 +96,44 @@ module.exports = (api, options) => {
9696
{
9797
from: './src/manifest.json',
9898
to: 'manifest.json',
99-
transform: (content) => {
100-
return new Promise((resolve, reject) => {
101-
const jsonContent = JSON.parse(content)
102-
if (pluginOptions.manifestSync.includes('version')) {
103-
jsonContent.version = packageJson.version
104-
}
105-
if (pluginOptions.manifestSync.includes('description')) {
106-
jsonContent.description = packageJson.description
107-
}
108-
109-
if (isProduction) {
110-
return resolve(getManifestJsonString(pluginOptions, jsonContent))
111-
}
112-
113-
jsonContent.content_security_policy =
114-
jsonContent.content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
115-
99+
transform: async (content) => {
100+
const jsonContent = JSON.parse(content)
101+
if (pluginOptions.manifestSync.includes('version')) {
102+
jsonContent.version = packageJson.version
103+
}
104+
if (pluginOptions.manifestSync.includes('description')) {
105+
jsonContent.description = packageJson.description
106+
}
107+
108+
if (isProduction) {
109+
return getManifestJsonString(pluginOptions, jsonContent)
110+
}
111+
112+
jsonContent.content_security_policy =
113+
jsonContent.content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
114+
115+
if (hasKeyFile) {
116116
try {
117-
fs.statSync(keyFile)
118-
119-
return exec(`openssl rsa -in ${keyFile} -pubout -outform DER | openssl base64 -A`, (error, stdout) => {
120-
if (error) {
121-
// node couldn't execute the command
122-
reject(error)
123-
}
124-
125-
jsonContent.key = stdout
126-
resolve(getManifestJsonString(pluginOptions, jsonContent))
117+
jsonContent.key = await new Promise((resolve, reject) => {
118+
exec(`openssl rsa -in ${keyFile} -pubout -outform DER | openssl base64 -A`, (error, stdout) => {
119+
if (error) {
120+
// node couldn't execute the command
121+
return reject(error)
122+
}
123+
resolve(stdout)
124+
})
127125
})
128126
} catch (error) {
129-
logger.warn(
130-
'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
131-
)
132-
resolve(getManifestJsonString(pluginOptions, jsonContent))
127+
logger.error('Unexpected error hashing keyfile:', error)
133128
}
134-
})
129+
}
130+
if (!jsonContent.key) {
131+
logger.warn(
132+
'No key.pem file found. This is fine for dev, however you may have problems publishing without one'
133+
)
134+
}
135+
136+
return getManifestJsonString(pluginOptions, jsonContent)
135137
}
136138
}
137139
])

0 commit comments

Comments
 (0)