Files
Alex Hunt 89300acb9c Migrate Node.js builtin imports to node: scheme (#57611)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57611

Directly follows D112733139 (Metro).

**Motivation**

- New Node builtins are *only* available under the prefix (e.g. `node:sqlite`), as this allows Node to introduce them without ecosystem-breaking changes, so this is the direction of travel and the only choice that'll allow consistency.
- Encouraging them and grouping them separately makes it easier to reason about a module's 3rd party dependencies.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D112803684

fbshipit-source-id: 40668d746a7151b3aa4800ff8af997902a18d198
2026-07-21 09:01:41 -07:00

64 lines
1.5 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
import debug from 'debug';
import {execSync, spawn} from 'node:child_process';
import {existsSync} from 'node:fs';
import path from 'node:path';
const logWatchman = debug('helloworld:cli:watchman');
export async function pauseWatchman(command: () => Promise<unknown | void>) {
let p: ReturnType<typeof spawn> | null = null;
try {
const raw: string = execSync('watchman watch-project .', {
cwd: process.cwd(),
stdio: 'pipe',
}).toString();
const {watch} = JSON.parse(raw);
p = spawn('watchman', [
'--no-pretty',
'--persistent',
'state-enter',
watch,
'yarn-install',
]);
logWatchman(`[PID:${p.pid}] started`);
} catch (e) {
logWatchman(
`Unable to pause watchman: ${e.message}, running command anyway`,
);
} finally {
try {
// Always run our user, if watchman has problems or doesn't exist proceed.
await command();
} finally {
if (p?.killed || p?.exitCode != null) {
return;
}
logWatchman(`[PID:${p?.pid ?? '????'}] killing with SIGTERM`);
p?.kill('SIGTERM');
}
}
}
export function getExistingPath(
folder: string,
paths: ReadonlyArray<string>,
): string | null {
for (const p of paths) {
if (existsSync(path.join(folder, p))) {
return p;
}
}
return null;
}