MCPcopy Create free account
hub / github.com/arktypeio/arktype / readProgram

Function readProgram

ark/aot/nextProgram.ts:147–171  ·  view source on GitHub ↗
(
	root: string,
	opts: PrecompilePluginOptions,
	{ aliases, problem }: ReadSettings
)

Source from the content-addressed store, hash-verified

145
146// what `next build`'s config wrapper runs, as Next loads next.config
147const 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
173interface ReadSettings {
174 // turbopack.resolveAlias's, for what Turbopack resolves otherwise than Node

Callers 1

readProjectWithFunction · 0.85

Calls 9

nodeModulesOfFunction · 0.85
programDirOfFunction · 0.85
joinFunction · 0.85
readAndWriteFunction · 0.85
treeOfFunction · 0.85
StringInterface · 0.85
writeChangedFunction · 0.85
doneFileOfFunction · 0.85
refusalOfFunction · 0.70

Tested by

no test coverage detected