Skip to content

Commit eda02c8

Browse files
pvinisdratwas
authored andcommitted
chore: change upgrade to use new diff files approach (react-native-community#348)
* use diff files and dont rely on gh * lint * update snapshots * update link to diff table
1 parent 5b08c58 commit eda02c8

File tree

2 files changed

+70
-66
lines changed

2 files changed

+70
-66
lines changed

packages/cli/src/commands/upgrade/__tests__/upgrade.test.js

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ test('fetches empty patch and installs deps', async () => {
159159
(fetch: any).mockImplementation(() => Promise.resolve(''));
160160
await upgrade.func([newVersion], ctx, opts);
161161
expect(flushOutput()).toMatchInlineSnapshot(`
162-
"info Fetching diff between v0.57.8 and v0.58.4...
163-
info Diff has no changes to apply, proceeding further
164-
info Installing \\"[email protected]\\" and its peer dependencies...
165-
$ execa npm info [email protected] peerDependencies --json
166-
167-
$ execa git add package.json
168-
$ execa git add yarn.lock
169-
$ execa git add package-lock.json
170-
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
171-
`);
162+
"info Fetching diff between v0.57.8 and v0.58.4...
163+
info Diff has no changes to apply, proceeding further
164+
info Installing \\"[email protected]\\" and its peer dependencies...
165+
$ execa npm info [email protected] peerDependencies --json
166+
167+
$ execa git add package.json
168+
$ execa git add yarn.lock
169+
$ execa git add package-lock.json
170+
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
171+
`);
172172
}, 60000);
173173

174174
test('fetches regular patch, adds remote, applies patch, installs deps, removes remote,', async () => {
@@ -184,24 +184,24 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes
184184
opts,
185185
);
186186
expect(flushOutput()).toMatchInlineSnapshot(`
187-
"info Fetching diff between v0.57.8 and v0.58.4...
188-
[fs] write tmp-upgrade-rn.patch
189-
$ execa git rev-parse --show-prefix
190-
$ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory=
191-
info Applying diff...
192-
$ execa git apply tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory=
193-
[fs] unlink tmp-upgrade-rn.patch
194-
$ execa git status -s
195-
info Installing \\"[email protected]\\" and its peer dependencies...
196-
$ execa npm info [email protected] peerDependencies --json
197-
198-
$ execa git add package.json
199-
$ execa git add yarn.lock
200-
$ execa git add package-lock.json
201-
info Running \\"git status\\" to check what changed...
202-
$ execa git status
203-
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
204-
`);
187+
"info Fetching diff between v0.57.8 and v0.58.4...
188+
[fs] write tmp-upgrade-rn.patch
189+
$ execa git rev-parse --show-prefix
190+
$ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory=
191+
info Applying diff...
192+
$ execa git apply tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory=
193+
[fs] unlink tmp-upgrade-rn.patch
194+
$ execa git status -s
195+
info Installing \\"[email protected]\\" and its peer dependencies...
196+
$ execa npm info [email protected] peerDependencies --json
197+
198+
$ execa git add package.json
199+
$ execa git add yarn.lock
200+
$ execa git add package-lock.json
201+
info Running \\"git status\\" to check what changed...
202+
$ execa git status
203+
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
204+
`);
205205
expect(
206206
snapshotDiff(samplePatch, fs.writeFileSync.mock.calls[0][1], {
207207
contextLines: 1,
@@ -216,24 +216,24 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes
216216
const config = {...ctx, root: '/project/root/NestedApp'};
217217
await upgrade.func([newVersion], config, opts);
218218
expect(flushOutput()).toMatchInlineSnapshot(`
219-
"info Fetching diff between v0.57.8 and v0.58.4...
220-
[fs] write tmp-upgrade-rn.patch
221-
$ execa git rev-parse --show-prefix
222-
$ execa git apply --check tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/
223-
info Applying diff...
224-
$ execa git apply tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/
225-
[fs] unlink tmp-upgrade-rn.patch
226-
$ execa git status -s
227-
info Installing \\"[email protected]\\" and its peer dependencies...
228-
$ execa npm info [email protected] peerDependencies --json
229-
230-
$ execa git add package.json
231-
$ execa git add yarn.lock
232-
$ execa git add package-lock.json
233-
info Running \\"git status\\" to check what changed...
234-
$ execa git status
235-
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
236-
`);
219+
"info Fetching diff between v0.57.8 and v0.58.4...
220+
[fs] write tmp-upgrade-rn.patch
221+
$ execa git rev-parse --show-prefix
222+
$ execa git apply --check tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/
223+
info Applying diff...
224+
$ execa git apply tmp-upgrade-rn.patch --exclude=NestedApp/package.json -p2 --3way --directory=NestedApp/
225+
[fs] unlink tmp-upgrade-rn.patch
226+
$ execa git status -s
227+
info Installing \\"[email protected]\\" and its peer dependencies...
228+
$ execa npm info [email protected] peerDependencies --json
229+
230+
$ execa git add package.json
231+
$ execa git add yarn.lock
232+
$ execa git add package-lock.json
233+
info Running \\"git status\\" to check what changed...
234+
$ execa git status
235+
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
236+
`);
237237
}, 60000);
238238
test('cleans up if patching fails,', async () => {
239239
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));
@@ -263,22 +263,22 @@ test('cleans up if patching fails,', async () => {
263263
);
264264
}
265265
expect(flushOutput()).toMatchInlineSnapshot(`
266-
"info Fetching diff between v0.57.8 and v0.58.4...
267-
[fs] write tmp-upgrade-rn.patch
268-
$ execa git rev-parse --show-prefix
269-
$ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory=
270-
info Applying diff (excluding: package.json, .flowconfig)...
271-
$ execa git apply tmp-upgrade-rn.patch --exclude=package.json --exclude=.flowconfig -p2 --3way --directory=
272-
error: .flowconfig: does not exist in index
273-
error Automatically applying diff failed
274-
[fs] unlink tmp-upgrade-rn.patch
275-
$ execa git status -s
276-
error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading
277-
info You may find these resources helpful:
278-
• Release notes: https://github.com/facebook/react-native/releases/tag/v0.58.4
279-
• Comparison between versions: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.58.4
280-
• Git diff: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.58.4.diff"
281-
`);
266+
"info Fetching diff between v0.57.8 and v0.58.4...
267+
[fs] write tmp-upgrade-rn.patch
268+
$ execa git rev-parse --show-prefix
269+
$ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way --directory=
270+
info Applying diff (excluding: package.json, .flowconfig)...
271+
$ execa git apply tmp-upgrade-rn.patch --exclude=package.json --exclude=.flowconfig -p2 --3way --directory=
272+
error: .flowconfig: does not exist in index
273+
error Automatically applying diff failed
274+
[fs] unlink tmp-upgrade-rn.patch
275+
$ execa git status -s
276+
error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading
277+
info You may find these resources helpful:
278+
• Release notes: https://github.com/facebook/react-native/releases/tag/v0.58.4
279+
• Comparison between versions: https://github.com/react-native-community/rn-diff-purge/compare/release/0.57.8..release/0.58.4
280+
• Git diff: https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs/0.57.8..0.58.4.diff"
281+
`);
282282
}, 60000);
283283
test('works with --name-ios and --name-android', async () => {
284284
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));

packages/cli/src/commands/upgrade/upgrade.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type FlagsT = {
1616

1717
const rnDiffPurgeUrl =
1818
'https://github.com/react-native-community/rn-diff-purge';
19+
const rnDiffPurgeRawDiffsUrl =
20+
'https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs';
1921

2022
const getLatestRNVersion = async (): Promise<string> => {
2123
logger.info('No version passed. Fetching latest...');
@@ -45,14 +47,16 @@ const getPatch = async (currentVersion, newVersion, config) => {
4547

4648
try {
4749
patch = await fetch(
48-
`${rnDiffPurgeUrl}/compare/version/${currentVersion}...version/${newVersion}.diff`,
50+
`${rnDiffPurgeRawDiffsUrl}/${currentVersion}..${newVersion}.diff`,
4951
);
5052
} catch (error) {
5153
logger.error(
5254
`Failed to fetch diff for react-native@${newVersion}. Maybe it's not released yet?`,
5355
);
5456
logger.info(
55-
'For available releases to diff see: https://github.com/react-native-community/rn-diff-purge#version-changes',
57+
`For available releases to diff see: ${chalk.underline.dim(
58+
'https://github.com/react-native-community/rn-diff-purge#diff-table-full-table-here',
59+
)}`,
5660
);
5761
return null;
5862
}
@@ -297,10 +301,10 @@ async function upgrade(argv: Array<string>, ctx: ConfigT, args: FlagsT) {
297301
`https://github.com/facebook/react-native/releases/tag/v${newVersion}`,
298302
)}
299303
• Comparison between versions: ${chalk.underline.dim(
300-
`${rnDiffPurgeUrl}/compare/version/${currentVersion}..version/${newVersion}`,
304+
`${rnDiffPurgeUrl}/compare/release/${currentVersion}..release/${newVersion}`,
301305
)}
302306
• Git diff: ${chalk.underline.dim(
303-
`${rnDiffPurgeUrl}/compare/version/${currentVersion}..version/${newVersion}.diff`,
307+
`${rnDiffPurgeRawDiffsUrl}/${currentVersion}..${newVersion}.diff`,
304308
)}`);
305309

306310
throw new Error(

0 commit comments

Comments
 (0)