(inputOpts?: QwikPluginOptions)
| 158 | |
| 159 | /** Note that as a side-effect this updates the internal plugin `opts` */ |
| 160 | const normalizeOptions = (inputOpts?: QwikPluginOptions) => { |
| 161 | const updatedOpts: QwikPluginOptions = Object.assign({}, inputOpts); |
| 162 | |
| 163 | const optimizer = getOptimizer(); |
| 164 | const path = optimizer.sys.path; |
| 165 | |
| 166 | opts.debug = !!updatedOpts.debug; |
| 167 | |
| 168 | if (updatedOpts.assetsDir) { |
| 169 | opts.assetsDir = updatedOpts.assetsDir; |
| 170 | } |
| 171 | |
| 172 | if ( |
| 173 | updatedOpts.target === 'ssr' || |
| 174 | updatedOpts.target === 'client' || |
| 175 | updatedOpts.target === 'lib' || |
| 176 | updatedOpts.target === 'test' |
| 177 | ) { |
| 178 | opts.target = updatedOpts.target; |
| 179 | } else { |
| 180 | opts.target ||= 'client'; |
| 181 | } |
| 182 | |
| 183 | if (opts.target === 'lib') { |
| 184 | opts.buildMode = 'development'; |
| 185 | } else if (updatedOpts.buildMode === 'production' || updatedOpts.buildMode === 'development') { |
| 186 | opts.buildMode = updatedOpts.buildMode; |
| 187 | } else { |
| 188 | opts.buildMode ||= 'development'; |
| 189 | } |
| 190 | |
| 191 | if (updatedOpts.entryStrategy && typeof updatedOpts.entryStrategy === 'object') { |
| 192 | opts.entryStrategy = { ...updatedOpts.entryStrategy }; |
| 193 | } |
| 194 | if (!opts.entryStrategy) { |
| 195 | if (opts.target === 'ssr' || opts.target === 'test') { |
| 196 | opts.entryStrategy = { type: 'hoist' }; |
| 197 | } else if (opts.target === 'lib') { |
| 198 | opts.entryStrategy = { type: 'inline' }; |
| 199 | } else { |
| 200 | if (opts.buildMode === 'production') { |
| 201 | opts.entryStrategy = { type: 'smart' }; |
| 202 | } else { |
| 203 | opts.entryStrategy = { type: 'segment' }; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (typeof updatedOpts.rootDir === 'string') { |
| 209 | opts.rootDir = updatedOpts.rootDir; |
| 210 | } |
| 211 | if (typeof opts.rootDir !== 'string') { |
| 212 | opts.rootDir ||= optimizer.sys.cwd(); |
| 213 | } |
| 214 | opts.rootDir = normalizePath(path.resolve(optimizer.sys.cwd(), opts.rootDir)); |
| 215 | let srcDir = normalizePath(path.resolve(opts.rootDir, SRC_DIR_DEFAULT)); |
| 216 | if (typeof updatedOpts.srcDir === 'string') { |
| 217 | opts.srcDir = normalizePath(path.resolve(opts.rootDir, updatedOpts.srcDir)); |
nothing calls this directly
no test coverage detected