(
root: string,
opts: PrecompilePluginOptions,
{ aliases, problem }: ReadSettings
)
| 145 | |
| 146 | // what `next build`'s config wrapper runs, as Next loads next.config |
| 147 | const readProgram = async ( |
| 148 | root: string, |
| 149 | opts: PrecompilePluginOptions, |
| 150 | { aliases, problem }: ReadSettings |
| 151 | ): Promise<ProgramDone> => { |
| 152 | // find the nearest existing node_modules before creating node_modules/.cache/ark-programs |
| 153 | const modules = nodeModulesOf(root) |
| 154 | const dir = programDirOf(root, opts) |
| 155 | mkdirSync(dir, { recursive: true }) |
| 156 | // another option set's, whose answers a module's cached output may name |
| 157 | for (const name of readdirSync(dirname(dir))) { |
| 158 | if (name !== basename(dir) && !name.startsWith("warned-")) |
| 159 | rmSync(join(dirname(dir), name), { recursive: true, force: true }) |
| 160 | } |
| 161 | const done = |
| 162 | problem ? |
| 163 | refusalOf(problem) |
| 164 | : await readAndWrite(root, opts, dir, treeOf(root), aliases, modules).catch( |
| 165 | (e): ProgramDone => refusalOf(`reading it threw ${String(e)}`) |
| 166 | ) |
| 167 | // its warnings aside, which each build reports anew |
| 168 | writeChanged(doneFileOf(dir), JSON.stringify({ refused: done.refused })) |
| 169 | process.env[readEnv] = dir |
| 170 | return done |
| 171 | } |
| 172 | |
| 173 | interface ReadSettings { |
| 174 | // turbopack.resolveAlias's, for what Turbopack resolves otherwise than Node |
no test coverage detected