mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Support committing debugger-frontend sync under Git checkouts (#57997)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57997 `scripts/debugger-frontend/sync-and-build` with `--create-diff` only worked under fbsource, making commit creation (in particular the generated changes table) inconvenient outside of Meta. This diff lifts commit creation functionality to both Git and Mercurial (`sl`), and makes writing a local commit the default behaviour. **Changes** - Synced `debugger-frontend` artifacts are now always committed, regardless of version control backend. Internal Mercurial behaviour is forked to a `fbsource-backend.fb.js` script. - `--create-diff` is narrowed to draft Phabricator diff submission (fbsource only). - The script now aborts if there are any working copy changes. Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D116031207 fbshipit-source-id: 8ef3ed465b91d8f71ffa44fd1cba16f28860e3a9
This commit is contained in:
1 parent
3eab03df4c
commit
526016d950
3 files changed
+160
-109
No files matched your search
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*::
|
||||
export type Command = [string, Array<string>];
|
||||
|
||||
export type CommitMessageParts = Readonly<{
|
||||
title: string,
|
||||
summary: string,
|
||||
changelogTable: string,
|
||||
changelogEntry: string,
|
||||
}>;
|
||||
|
||||
// Commands are returned rather than run so that the caller can report them
|
||||
// consistently with the rest of the sync.
|
||||
export type CommitBackend = Readonly<{
|
||||
// Must print nothing when the working directory is clean.
|
||||
status: Command,
|
||||
// Joined with blank lines; empty entries are dropped.
|
||||
messageBlocks: (parts: CommitMessageParts) => ReadonlyArray<string>,
|
||||
commit: (packagePath: string, messageFile: string) => ReadonlyArray<Command>,
|
||||
}>;
|
||||
|
||||
export type ResolveContext = Readonly<{
|
||||
createDiff: boolean,
|
||||
noBuild: boolean,
|
||||
}>;
|
||||
*/
|
||||
|
||||
const GIT /*: CommitBackend */ = {
|
||||
status: ['git', ['status', '--porcelain', '--', '.']],
|
||||
messageBlocks: ({title, summary, changelogTable, changelogEntry}) => [
|
||||
title,
|
||||
summary,
|
||||
changelogTable,
|
||||
`Changelog: ${changelogEntry}`,
|
||||
],
|
||||
commit: (packagePath, messageFile) => [
|
||||
['git', ['add', '-A', '--', packagePath]],
|
||||
['git', ['commit', '-F', messageFile, '--', packagePath]],
|
||||
],
|
||||
};
|
||||
|
||||
function moduleExists(modulePath /*: string */) /*: boolean */ {
|
||||
try {
|
||||
require.resolve(modulePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Resolved before requiring so that a failure to load the module is not
|
||||
// mistaken for its absence in the open source repo. The filename is
|
||||
// deliberately not `commit-backend.fb.js`: Flow and Metro resolve `X.fb.js`
|
||||
// ahead of `X.js`, but Node - which runs this script - does not.
|
||||
const resolveFb /*: ?(context: ResolveContext) => Promise<?CommitBackend> */ =
|
||||
moduleExists('./fbsource-backend.fb.js')
|
||||
? // $FlowFixMe[cannot-resolve-module] - not resolvable in OSS
|
||||
require('./fbsource-backend.fb.js')
|
||||
: null;
|
||||
|
||||
async function resolveCommitBackend(
|
||||
context /*: ResolveContext */,
|
||||
) /*: Promise<CommitBackend> */ {
|
||||
const fbBackend = await resolveFb?.(context);
|
||||
if (fbBackend != null) {
|
||||
return fbBackend;
|
||||
}
|
||||
if (context.createDiff) {
|
||||
throw new Error('--create-diff requires an fbsource checkout');
|
||||
}
|
||||
return GIT;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
resolveCommitBackend,
|
||||
};
|
||||
Reference in new issue
Block a user