MCPcopy
hub / github.com/facebook/react / main

Function main

compiler/packages/snap/src/runner.ts:166–237  ·  view source on GitHub ↗
(opts: RunnerOptions)

Source from the content-addressed store, hash-verified

164 * Runs the compiler in watch or single-execution mode
165 */
166export async function main(opts: RunnerOptions): Promise<void> {
167 const worker: Worker & typeof runnerWorker = new Worker(WORKER_PATH, {
168 enableWorkerThreads: opts.workerThreads,
169 numWorkers: NUM_WORKERS,
170 }) as any;
171 worker.getStderr().pipe(process.stderr);
172 worker.getStdout().pipe(process.stdout);
173
174 if (opts.watch) {
175 makeWatchRunner(state => onChange(worker, state), opts.filter);
176 if (opts.filter) {
177 /**
178 * Warm up wormers when in watch mode. Loading the Forget babel plugin
179 * and all of its transitive dependencies takes 1-3s (per worker) on a M1.
180 * As jest-worker dispatches tasks using a round-robin strategy, we can
181 * avoid an additional 1-3s wait on the first num_workers runs by warming
182 * up workers eagerly.
183 */
184 for (let i = 0; i < NUM_WORKERS - 1; i++) {
185 worker.transformFixture(
186 {
187 fixturePath: 'tmp',
188 snapshotPath: './tmp.expect.md',
189 inputPath: './tmp.js',
190 input: `
191 function Foo(props) {
192 return identity(props);
193 }
194 `,
195 snapshot: null,
196 },
197 0,
198 false,
199 false,
200 );
201 }
202 }
203 } else {
204 // Non-watch mode. For simplicity we re-use the same watchSrc() function.
205 // After the first build completes run tests and exit
206 const tsWatch: ts.WatchOfConfigFile<ts.SemanticDiagnosticsBuilderProgram> =
207 watchSrc(
208 () => {},
209 async (isTypecheckSuccess: boolean) => {
210 let isSuccess = false;
211 if (!isTypecheckSuccess) {
212 console.error(
213 'Found typescript errors in Forget source code, skipping test fixtures.',
214 );
215 } else {
216 try {
217 execSync('yarn build', {cwd: PROJECT_ROOT});
218 console.log('Built compiler successfully with tsup');
219 const testFilter = opts.filter ? await readTestFilter() : null;
220 const results = await runFixtures(worker, testFilter, 0);
221 if (opts.update) {
222 update(results);
223 isSuccess = true;

Callers 1

runner.tsFile · 0.70

Calls 10

makeWatchRunnerFunction · 0.90
watchSrcFunction · 0.90
readTestFilterFunction · 0.90
updateFunction · 0.90
reportFunction · 0.90
runFixturesFunction · 0.85
exitMethod · 0.80
onChangeFunction · 0.70
errorMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected