( dir: string, options?: ReadConfigOptions )
| 134 | }; |
| 135 | |
| 136 | export async function readConfig( |
| 137 | dir: string, |
| 138 | options?: ReadConfigOptions |
| 139 | ): Promise<ReadConfigResult> { |
| 140 | const absoluteDir = path.resolve(process.cwd(), dir); |
| 141 | |
| 142 | const configPath = await getConfigPath(dir, options?.configFile); |
| 143 | |
| 144 | if (!configPath) { |
| 145 | if (options?.projectRef) { |
| 146 | const rawConfig = await normalizeConfig({ project: options.projectRef }); |
| 147 | const config = Config.parse(rawConfig); |
| 148 | |
| 149 | return { |
| 150 | status: "in-memory", |
| 151 | config: await resolveConfig(absoluteDir, config), |
| 152 | }; |
| 153 | } else { |
| 154 | throw new Error(`Config file not found in ${absoluteDir} or any parent directory.`); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | const tempDir = await createTempDir(); |
| 159 | |
| 160 | const builtConfigFilePath = join(tempDir, "config.js"); |
| 161 | const builtConfigFileHref = pathToFileURL(builtConfigFilePath).href; |
| 162 | |
| 163 | logger.debug("Building config file", { |
| 164 | configPath, |
| 165 | builtConfigFileHref, |
| 166 | builtConfigFilePath, |
| 167 | }); |
| 168 | |
| 169 | // We need to build the path to the config file, and then import it? |
| 170 | await build({ |
| 171 | entryPoints: [configPath], |
| 172 | bundle: true, |
| 173 | metafile: true, |
| 174 | minify: false, |
| 175 | write: true, |
| 176 | format: "cjs", |
| 177 | platform: "node", |
| 178 | target: ["es2018", "node18"], |
| 179 | outfile: builtConfigFilePath, |
| 180 | logLevel: "silent", |
| 181 | plugins: [ |
| 182 | esbuildDecorators({ |
| 183 | cwd: absoluteDir, |
| 184 | tsx: false, |
| 185 | force: false, |
| 186 | }), |
| 187 | { |
| 188 | name: "native-node-modules", |
| 189 | setup(build) { |
| 190 | const opts = build.initialOptions; |
| 191 | opts.loader = opts.loader || {}; |
| 192 | opts.loader[".node"] = "copy"; |
| 193 | }, |
no test coverage detected
searching dependent graphs…