( fileName: string, commandOptions: Record<string, unknown>, watchMode: boolean )
| 49 | }; |
| 50 | |
| 51 | async function getConfigFileExport( |
| 52 | fileName: string, |
| 53 | commandOptions: Record<string, unknown>, |
| 54 | watchMode: boolean |
| 55 | ) { |
| 56 | if (commandOptions.configPlugin || commandOptions.bundleConfigAsCjs) { |
| 57 | try { |
| 58 | return await loadTranspiledConfigFile(fileName, commandOptions); |
| 59 | } catch (error_: any) { |
| 60 | if (error_.message.includes('not defined in ES module scope')) { |
| 61 | return error(logCannotBundleConfigAsEsm(error_)); |
| 62 | } |
| 63 | throw error_; |
| 64 | } |
| 65 | } |
| 66 | let cannotLoadEsm = false; |
| 67 | const handleWarning = (warning: Error): void => { |
| 68 | if ( |
| 69 | warning.message?.includes('To load an ES module') || |
| 70 | warning.message?.includes('Failed to load the ES module') |
| 71 | ) { |
| 72 | cannotLoadEsm = true; |
| 73 | } |
| 74 | }; |
| 75 | process.on('warning', handleWarning); |
| 76 | try { |
| 77 | const fileUrl = pathToFileURL(fileName); |
| 78 | if (watchMode) { |
| 79 | // We are adding the current date to allow reloads in watch mode |
| 80 | fileUrl.search = `?${Date.now()}`; |
| 81 | } |
| 82 | return (await import(fileUrl.href)).default; |
| 83 | } catch (error_: any) { |
| 84 | if (cannotLoadEsm) { |
| 85 | return error(logCannotLoadConfigAsCjs(error_)); |
| 86 | } |
| 87 | if (error_.message.includes('not defined in ES module scope')) { |
| 88 | return error(logCannotLoadConfigAsEsm(error_)); |
| 89 | } |
| 90 | throw error_; |
| 91 | } finally { |
| 92 | process.off('warning', handleWarning); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | function getDefaultFromCjs(namespace: GenericConfigObject): unknown { |
| 97 | return namespace.default || namespace; |
no test coverage detected
searching dependent graphs…