Files
react-native/packages/helloworld/lib/filesystem.js
T
Blake Friedman fedb1452a2 cli helper methods (#44463)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44463

Helper methods to help the cli grab system state, devices and run react-native/core-cli-utils tasks using Listr.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D57067037

fbshipit-source-id: 28cb4239f3a93558b88417f366a2146f696cc411
2024-05-13 14:06:33 -07:00

50 lines
1.2 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
* @oncall react_native
*/
import {execSync, spawn} from 'child_process';
import debug from 'debug';
const logWatchman = debug('helloworld:cli:watchman');
export async function pauseWatchman(command: () => Promise<mixed | void>) {
let p: ReturnType<typeof spawn> | null = null;
try {
const raw: string = execSync('watchman watch-project .', {
cwd: process.cwd(),
}).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');
}
}
}