(filePath)
| 117 | } |
| 118 | |
| 119 | export async function loadJSConfigFile(filePath) { |
| 120 | const resolvedFilePath = path.resolve(filePath); |
| 121 | log.debug( |
| 122 | `Loading JS config file: "${filePath}" ` + |
| 123 | `(resolved to "${resolvedFilePath}")`, |
| 124 | ); |
| 125 | |
| 126 | if (filePath.endsWith('.js')) { |
| 127 | throw new UsageError( |
| 128 | ` Invalid config file "${resolvedFilePath}": the file extension should be` + |
| 129 | '".cjs" or ".mjs". More information at: https://mzl.la/web-ext-config-file', |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | let configObject; |
| 134 | try { |
| 135 | const nonce = `${Date.now()}-${Math.random()}`; |
| 136 | |
| 137 | let configModule; |
| 138 | if (resolvedFilePath.endsWith('package.json')) { |
| 139 | configModule = parseJSON( |
| 140 | await fs.readFile(resolvedFilePath, { encoding: 'utf-8' }), |
| 141 | ); |
| 142 | } else { |
| 143 | configModule = await import(`file://${resolvedFilePath}?nonce=${nonce}`); |
| 144 | } |
| 145 | |
| 146 | if (configModule.default) { |
| 147 | const { default: configDefault, ...esmConfigMod } = configModule; |
| 148 | // ES modules may expose both a default and named exports and so |
| 149 | // we merge the named exports on top of what may have been set in |
| 150 | // the default export. |
| 151 | if (filePath.endsWith('.cjs')) { |
| 152 | // Remove the additional 'module.exports' named export that Node.js >= |
| 153 | // 24 is returning from the dynamic import call (in addition to being |
| 154 | // also set on the default property as in Node.js < 24). |
| 155 | delete esmConfigMod['module.exports']; |
| 156 | } |
| 157 | configObject = { ...configDefault, ...esmConfigMod }; |
| 158 | } else { |
| 159 | configObject = { ...configModule }; |
| 160 | } |
| 161 | } catch (error) { |
| 162 | const configFileError = new UsageError( |
| 163 | `Cannot read config file "${resolvedFilePath}":\n${error}`, |
| 164 | ); |
| 165 | configFileError.cause = error; |
| 166 | throw configFileError; |
| 167 | } |
| 168 | |
| 169 | if (filePath.endsWith('package.json')) { |
| 170 | log.debug('Looking for webExt key inside package.json file'); |
| 171 | configObject = configObject.webExt || {}; |
| 172 | } |
| 173 | |
| 174 | if (Object.keys(configObject).length === 0) { |
| 175 | log.debug( |
| 176 | `Config file ${resolvedFilePath} did not define any options. ` + |
no outgoing calls
no test coverage detected
searching dependent graphs…