react-native-platform-override 0.4.7 → 0.81.0-preview.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +1 -2
- package/lib-commonjs/Api.d.ts +57 -56
- package/lib-commonjs/Api.js +187 -167
- package/lib-commonjs/Api.js.map +1 -1
- package/lib-commonjs/BatchingQueue.d.ts +15 -15
- package/lib-commonjs/BatchingQueue.js +57 -57
- package/lib-commonjs/BatchingQueue.js.map +1 -1
- package/lib-commonjs/Cli.d.ts +7 -7
- package/lib-commonjs/Cli.js +323 -291
- package/lib-commonjs/Cli.js.map +1 -1
- package/lib-commonjs/CrossProcessLock.d.ts +44 -44
- package/lib-commonjs/CrossProcessLock.js +147 -144
- package/lib-commonjs/CrossProcessLock.js.map +1 -1
- package/lib-commonjs/DiffStrategy.d.ts +24 -24
- package/lib-commonjs/DiffStrategy.js +34 -34
- package/lib-commonjs/DiffStrategy.js.map +1 -1
- package/lib-commonjs/FileRepository.d.ts +63 -62
- package/lib-commonjs/FileRepository.js +21 -21
- package/lib-commonjs/FileRepository.js.map +1 -1
- package/lib-commonjs/FileSearch.d.ts +21 -21
- package/lib-commonjs/FileSearch.js +77 -91
- package/lib-commonjs/FileSearch.js.map +1 -1
- package/lib-commonjs/FileSystemRepository.d.ts +21 -20
- package/lib-commonjs/FileSystemRepository.js +62 -59
- package/lib-commonjs/FileSystemRepository.js.map +1 -1
- package/lib-commonjs/GitReactFileRepository.d.ts +57 -58
- package/lib-commonjs/GitReactFileRepository.js +202 -208
- package/lib-commonjs/GitReactFileRepository.js.map +1 -1
- package/lib-commonjs/Hash.d.ts +34 -33
- package/lib-commonjs/Hash.js +81 -81
- package/lib-commonjs/Hash.js.map +1 -1
- package/lib-commonjs/Manifest.d.ts +80 -80
- package/lib-commonjs/Manifest.js +157 -154
- package/lib-commonjs/Manifest.js.map +1 -1
- package/lib-commonjs/Override.d.ts +182 -182
- package/lib-commonjs/Override.js +248 -245
- package/lib-commonjs/Override.js.map +1 -1
- package/lib-commonjs/OverrideFactory.d.ts +33 -33
- package/lib-commonjs/OverrideFactory.js +85 -70
- package/lib-commonjs/OverrideFactory.js.map +1 -1
- package/lib-commonjs/OverridePrompt.d.ts +30 -30
- package/lib-commonjs/OverridePrompt.js +130 -104
- package/lib-commonjs/OverridePrompt.js.map +1 -1
- package/lib-commonjs/PackageUtils.d.ts +15 -15
- package/lib-commonjs/PackageUtils.js +40 -38
- package/lib-commonjs/PackageUtils.js.map +1 -1
- package/lib-commonjs/PathUtils.d.ts +14 -14
- package/lib-commonjs/PathUtils.js +31 -28
- package/lib-commonjs/PathUtils.js.map +1 -1
- package/lib-commonjs/Serialized.d.ts +158 -158
- package/lib-commonjs/Serialized.js +145 -119
- package/lib-commonjs/Serialized.js.map +1 -1
- package/lib-commonjs/UpgradeStrategy.d.ts +39 -39
- package/lib-commonjs/UpgradeStrategy.js +102 -99
- package/lib-commonjs/UpgradeStrategy.js.map +1 -1
- package/lib-commonjs/ValidationStrategy.d.ts +57 -57
- package/lib-commonjs/ValidationStrategy.js +124 -124
- package/lib-commonjs/ValidationStrategy.js.map +1 -1
- package/lib-commonjs/refFromVersion.d.ts +10 -0
- package/lib-commonjs/refFromVersion.js +99 -0
- package/lib-commonjs/refFromVersion.js.map +1 -0
- package/lib-commonjs/scripts/generateManifest.d.ts +7 -7
- package/lib-commonjs/scripts/generateManifest.js +196 -170
- package/lib-commonjs/scripts/generateManifest.js.map +1 -1
- package/lib-commonjs/scripts/hashFile.d.ts +7 -7
- package/lib-commonjs/scripts/hashFile.js +17 -14
- package/lib-commonjs/scripts/hashFile.js.map +1 -1
- package/lib-commonjs/scripts/testLocks.d.ts +1 -1
- package/lib-commonjs/scripts/testLocks.js +29 -26
- package/lib-commonjs/scripts/testLocks.js.map +1 -1
- package/package.json +53 -43
- package/CHANGELOG.json +0 -554
- package/CHANGELOG.md +0 -238
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private readonly
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
private
|
|
52
|
-
private
|
|
53
|
-
private
|
|
54
|
-
private
|
|
55
|
-
private
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
import { VersionedReactFileRepository } from './FileRepository';
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves React Native files using the React Native Github repo. Switching
|
|
12
|
+
* between getting file contents of different versions may be slow.
|
|
13
|
+
*/
|
|
14
|
+
export default class GitReactFileRepository implements VersionedReactFileRepository {
|
|
15
|
+
private readonly fileRepo;
|
|
16
|
+
private readonly gitClient;
|
|
17
|
+
private checkedOutVersion?;
|
|
18
|
+
private static githubToken?;
|
|
19
|
+
private readonly batchingQueue;
|
|
20
|
+
private constructor();
|
|
21
|
+
/**
|
|
22
|
+
* Asynchronously initialize the scratch repository, creating a new Git repo is needed
|
|
23
|
+
* @param gitDirectory optional repo directory
|
|
24
|
+
*/
|
|
25
|
+
static createAndInit(gitDirectory?: string): Promise<GitReactFileRepository>;
|
|
26
|
+
/**
|
|
27
|
+
* Set a GitHub API token for all instances of GitReactFileRepository to use
|
|
28
|
+
* when making requests.
|
|
29
|
+
* @param token a GitHub PAT
|
|
30
|
+
*/
|
|
31
|
+
static setGithubToken(token: string): void;
|
|
32
|
+
listFiles(globs: string[] | undefined, reactNativeVersion: string): Promise<string[]>;
|
|
33
|
+
readFile(filename: string, reactNativeVersion: string): Promise<Buffer | null>;
|
|
34
|
+
stat(filename: string, reactNativeVersion: string): Promise<'file' | 'directory' | 'none'>;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a Git-style patch to transform the given file into the given
|
|
37
|
+
* content.
|
|
38
|
+
*/
|
|
39
|
+
generatePatch(filename: string, reactNativeVersion: string, newContent: Buffer): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Apply a patch to the given file, returning the merged result, which may
|
|
42
|
+
* include conflict markers. The underlying file is not mutated.
|
|
43
|
+
*
|
|
44
|
+
* Git is unable to generate a representation with conflict markers in the
|
|
45
|
+
* event of binary merge conflicts. In this case a null Buffer is returned.
|
|
46
|
+
*/
|
|
47
|
+
getPatchedFile(filename: string, reactNativeVersion: string, patchContent: string): Promise<{
|
|
48
|
+
patchedFile: Buffer | null;
|
|
49
|
+
hasConflicts: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
private usingVersion;
|
|
52
|
+
private checkoutVersion;
|
|
53
|
+
private tryCheckoutLocal;
|
|
54
|
+
private fetchAndCheckout;
|
|
55
|
+
private static defaultGitDirectory;
|
|
56
|
+
private ensureFile;
|
|
57
|
+
}
|
|
@@ -1,209 +1,203 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
Object.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
await
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
async
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
else if (stat === 'directory') {
|
|
204
|
-
throw new Error(`"${filename}" refers to a directory`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
exports.default = GitReactFileRepository;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
36
|
+
const os_1 = __importDefault(require("os"));
|
|
37
|
+
const path_1 = __importDefault(require("path"));
|
|
38
|
+
const simple_git_1 = __importStar(require("simple-git"));
|
|
39
|
+
const BatchingQueue_1 = __importDefault(require("./BatchingQueue"));
|
|
40
|
+
const FileSystemRepository_1 = __importDefault(require("./FileSystemRepository"));
|
|
41
|
+
const PackageUtils_1 = require("./PackageUtils");
|
|
42
|
+
const refFromVersion_1 = require("./refFromVersion");
|
|
43
|
+
const RN_GITHUB_URL = 'https://github.com/facebook/react-native.git';
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves React Native files using the React Native Github repo. Switching
|
|
46
|
+
* between getting file contents of different versions may be slow.
|
|
47
|
+
*/
|
|
48
|
+
class GitReactFileRepository {
|
|
49
|
+
constructor(gitDirectory, gitClient) {
|
|
50
|
+
this.batchingQueue = new BatchingQueue_1.default();
|
|
51
|
+
this.fileRepo = new FileSystemRepository_1.default(gitDirectory);
|
|
52
|
+
this.gitClient = gitClient;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Asynchronously initialize the scratch repository, creating a new Git repo is needed
|
|
56
|
+
* @param gitDirectory optional repo directory
|
|
57
|
+
*/
|
|
58
|
+
static async createAndInit(gitDirectory) {
|
|
59
|
+
const dir = gitDirectory || (await this.defaultGitDirectory());
|
|
60
|
+
await fs_1.default.mkdir(dir, { recursive: true });
|
|
61
|
+
const gitClient = (0, simple_git_1.default)(dir);
|
|
62
|
+
if (!(await gitClient.checkIsRepo())) {
|
|
63
|
+
await gitClient.init();
|
|
64
|
+
await gitClient.addConfig('core.autocrlf', 'input');
|
|
65
|
+
await gitClient.addConfig('core.filemode', 'false');
|
|
66
|
+
await gitClient.addConfig('core.ignorecase', 'true');
|
|
67
|
+
}
|
|
68
|
+
return new GitReactFileRepository(dir, gitClient);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set a GitHub API token for all instances of GitReactFileRepository to use
|
|
72
|
+
* when making requests.
|
|
73
|
+
* @param token a GitHub PAT
|
|
74
|
+
*/
|
|
75
|
+
static setGithubToken(token) {
|
|
76
|
+
GitReactFileRepository.githubToken = token;
|
|
77
|
+
}
|
|
78
|
+
async listFiles(globs, reactNativeVersion) {
|
|
79
|
+
return this.usingVersion(reactNativeVersion, () => this.fileRepo.listFiles(globs));
|
|
80
|
+
}
|
|
81
|
+
async readFile(filename, reactNativeVersion) {
|
|
82
|
+
return this.usingVersion(reactNativeVersion, () => this.fileRepo.readFile(filename));
|
|
83
|
+
}
|
|
84
|
+
async stat(filename, reactNativeVersion) {
|
|
85
|
+
return this.usingVersion(reactNativeVersion, () => this.fileRepo.stat(filename));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Generate a Git-style patch to transform the given file into the given
|
|
89
|
+
* content.
|
|
90
|
+
*/
|
|
91
|
+
async generatePatch(filename, reactNativeVersion, newContent) {
|
|
92
|
+
return this.usingVersion(reactNativeVersion, async () => {
|
|
93
|
+
await this.ensureFile(filename);
|
|
94
|
+
try {
|
|
95
|
+
await this.fileRepo.writeFile(filename, newContent);
|
|
96
|
+
const patch = await this.gitClient.diff([
|
|
97
|
+
'--patch',
|
|
98
|
+
'--ignore-space-at-eol',
|
|
99
|
+
'--binary',
|
|
100
|
+
'--',
|
|
101
|
+
filename,
|
|
102
|
+
]);
|
|
103
|
+
return patch;
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await this.gitClient.reset(simple_git_1.ResetMode.HARD);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Apply a patch to the given file, returning the merged result, which may
|
|
112
|
+
* include conflict markers. The underlying file is not mutated.
|
|
113
|
+
*
|
|
114
|
+
* Git is unable to generate a representation with conflict markers in the
|
|
115
|
+
* event of binary merge conflicts. In this case a null Buffer is returned.
|
|
116
|
+
*/
|
|
117
|
+
async getPatchedFile(filename, reactNativeVersion, patchContent) {
|
|
118
|
+
return this.usingVersion(reactNativeVersion, async () => {
|
|
119
|
+
await this.ensureFile(filename);
|
|
120
|
+
try {
|
|
121
|
+
await this.fileRepo.writeFile('rnwgit.patch', patchContent);
|
|
122
|
+
let hasConflicts = false;
|
|
123
|
+
let binaryConflicts = false;
|
|
124
|
+
try {
|
|
125
|
+
await this.gitClient.raw([
|
|
126
|
+
'apply',
|
|
127
|
+
'--3way',
|
|
128
|
+
'--whitespace=nowarn',
|
|
129
|
+
'rnwgit.patch',
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
catch (ex) {
|
|
133
|
+
// Hack alert: simple-git doesn't populate exception information from
|
|
134
|
+
// conflicts when we're using raw commands (which we need to since it
|
|
135
|
+
// doesn't support apply). Try to detect if Git gave us a bad exit code
|
|
136
|
+
// because of merge conflicts, which we explicitly want to allow.
|
|
137
|
+
if (!ex.message.includes('with conflicts')) {
|
|
138
|
+
throw ex;
|
|
139
|
+
}
|
|
140
|
+
hasConflicts = true;
|
|
141
|
+
binaryConflicts = ex.message.includes('Cannot merge binary files');
|
|
142
|
+
}
|
|
143
|
+
const patchedFile = binaryConflicts
|
|
144
|
+
? null
|
|
145
|
+
: await this.fileRepo.readFile(filename);
|
|
146
|
+
return { patchedFile, hasConflicts };
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
await this.gitClient.reset(simple_git_1.ResetMode.HARD);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async usingVersion(reactNativeVersion, fn) {
|
|
154
|
+
return await this.batchingQueue.enqueue(reactNativeVersion, async () => {
|
|
155
|
+
await this.checkoutVersion(reactNativeVersion);
|
|
156
|
+
return await fn();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async checkoutVersion(reactNativeVersion) {
|
|
160
|
+
if (reactNativeVersion !== this.checkedOutVersion) {
|
|
161
|
+
if (!(await this.tryCheckoutLocal(reactNativeVersion))) {
|
|
162
|
+
await this.fetchAndCheckout(reactNativeVersion);
|
|
163
|
+
}
|
|
164
|
+
this.checkedOutVersion = reactNativeVersion;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async tryCheckoutLocal(reactNativeVersion) {
|
|
168
|
+
try {
|
|
169
|
+
await this.gitClient.checkout([reactNativeVersion, '--force']);
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
catch (_a) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async fetchAndCheckout(reactNativeVersion) {
|
|
177
|
+
const githubToken = GitReactFileRepository.githubToken ||
|
|
178
|
+
process.env.PLATFORM_OVERRIDE_GITHUB_TOKEN;
|
|
179
|
+
const gitRef = await (0, refFromVersion_1.fetchFullRef)(reactNativeVersion, { githubToken });
|
|
180
|
+
try {
|
|
181
|
+
await this.gitClient.fetch([RN_GITHUB_URL, gitRef, '--depth=1']);
|
|
182
|
+
await this.gitClient.checkout(['-b', reactNativeVersion, 'FETCH_HEAD']);
|
|
183
|
+
}
|
|
184
|
+
catch (ex) {
|
|
185
|
+
throw new Error(`Failed to fetch '${gitRef}'. Does it exist? (${ex.message})`);
|
|
186
|
+
}
|
|
187
|
+
await this.gitClient.checkout([reactNativeVersion, '--force']);
|
|
188
|
+
}
|
|
189
|
+
static async defaultGitDirectory() {
|
|
190
|
+
return path_1.default.join(os_1.default.tmpdir(), (await (0, PackageUtils_1.getNpmPackage)()).name, 'git');
|
|
191
|
+
}
|
|
192
|
+
async ensureFile(filename) {
|
|
193
|
+
const stat = await this.fileRepo.stat(filename);
|
|
194
|
+
if (stat === 'none') {
|
|
195
|
+
throw new Error(`Cannot find file "${filename}" in react-native@${this.checkedOutVersion}`);
|
|
196
|
+
}
|
|
197
|
+
else if (stat === 'directory') {
|
|
198
|
+
throw new Error(`"${filename}" refers to a directory`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.default = GitReactFileRepository;
|
|
209
203
|
//# sourceMappingURL=GitReactFileRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitReactFileRepository.js","sourceRoot":"","sources":["../src/GitReactFileRepository.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,yBAAyB;AACzB,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AACjC,gDAAgD;AAEhD,mDAA4C;AAC5C,iEAA0D;AAE1D,2CAA+B;AAC/B,iDAA6C;AAE7C,MAAM,kBAAkB,GACtB,4DAA4D,CAAC;AAC/D,MAAM,aAAa,GAAG,8CAA8C,CAAC;AAErE;;;GAGG;AACH,MAAqB,sBAAsB;IAYzC,YAAoB,YAAoB,EAAE,SAA8B;QACtE,IAAI,CAAC,aAAa,GAAG,IAAI,uBAAa,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,8BAAoB,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,aAAa,CACxB,YAAqB;QAErB,MAAM,GAAG,GAAG,YAAY,IAAI,CAAC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC/D,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;QAEhD,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QACjC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvB,IAAI,CAAC,CAAC,MAAM,SAAS,CAAC,WAAW,EAAE,CAAC,EAAE;YACpC,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;YACvB,MAAM,SAAS,CAAC,SAAS,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACpD,MAAM,SAAS,CAAC,SAA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AAC;QAChD,IAAI,IAAI,KAAK,MAAM,EAAE;YACnB,MAAM,IAAI,KAAK,CACb,qBAAqB,QAAQ,qBAAqB,IAAI,CAAC,iBAAiB,EAAE,CAC3E,CAAC;SACH;aAAM,IAAI,IAAI,KAAK,WAAW,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,IAAI,QAAQ,yBAAyB,CAAC,CAAC;SACxD;IACH,CAAC;CACF;AA/ND,yCA+NC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport fs from '@react-native-windows/fs';\nimport os from 'os';\nimport path from 'path';\nimport simplegit, {SimpleGit, ResetMode} from 'simple-git';\n\nimport BatchingQueue from './BatchingQueue';\nimport FileSystemRepository from './FileSystemRepository';\nimport {VersionedReactFileRepository} from './FileRepository';\nimport {getNpmPackage} from './PackageUtils';\nimport {fetchFullRef} from './refFromVersion';\n\nconst RN_GITHUB_URL = 'https://github.com/facebook/react-native.git';\n\n/**\n * Retrieves React Native files using the React Native Github repo. Switching\n * between getting file contents of different versions may be slow.\n */\nexport default class GitReactFileRepository\n implements VersionedReactFileRepository\n{\n private readonly fileRepo: FileSystemRepository;\n private readonly gitClient: SimpleGit;\n private checkedOutVersion?: string;\n private static githubToken?: string;\n\n // We need to ensure it is impossible to check out a new React Native\n // version while an operation hasn't yet finished. We queue each operation to\n // ensure they are performed atomically.\n private readonly batchingQueue: BatchingQueue<string>;\n\n private constructor(gitDirectory: string, gitClient: SimpleGit) {\n this.batchingQueue = new BatchingQueue();\n this.fileRepo = new FileSystemRepository(gitDirectory);\n this.gitClient = gitClient;\n }\n\n /**\n * Asynchronously initialize the scratch repository, creating a new Git repo is needed\n * @param gitDirectory optional repo directory\n */\n static async createAndInit(\n gitDirectory?: string,\n ): Promise<GitReactFileRepository> {\n const dir = gitDirectory || (await this.defaultGitDirectory());\n await fs.mkdir(dir, {recursive: true});\n\n const gitClient = simplegit(dir);\n\n if (!(await gitClient.checkIsRepo())) {\n await gitClient.init();\n await gitClient.addConfig('core.autocrlf', 'input');\n await gitClient.addConfig('core.filemode', 'false');\n await gitClient.addConfig('core.ignorecase', 'true');\n }\n\n return new GitReactFileRepository(dir, gitClient);\n }\n\n /**\n * Set a GitHub API token for all instances of GitReactFileRepository to use\n * when making requests.\n * @param token a GitHub PAT\n */\n static setGithubToken(token: string) {\n GitReactFileRepository.githubToken = token;\n }\n\n async listFiles(\n globs: string[] | undefined,\n reactNativeVersion: string,\n ): Promise<string[]> {\n return this.usingVersion(reactNativeVersion, () =>\n this.fileRepo.listFiles(globs),\n );\n }\n\n async readFile(\n filename: string,\n reactNativeVersion: string,\n ): Promise<Buffer | null> {\n return this.usingVersion(reactNativeVersion, () =>\n this.fileRepo.readFile(filename),\n );\n }\n\n async stat(\n filename: string,\n reactNativeVersion: string,\n ): Promise<'file' | 'directory' | 'none'> {\n return this.usingVersion(reactNativeVersion, () =>\n this.fileRepo.stat(filename),\n );\n }\n\n /**\n * Generate a Git-style patch to transform the given file into the given\n * content.\n */\n async generatePatch(\n filename: string,\n reactNativeVersion: string,\n newContent: Buffer,\n ): Promise<string> {\n return this.usingVersion(reactNativeVersion, async () => {\n await this.ensureFile(filename);\n\n try {\n await this.fileRepo.writeFile(filename, newContent);\n const patch = await this.gitClient.diff([\n '--patch',\n '--ignore-space-at-eol',\n '--binary',\n '--',\n filename,\n ]);\n\n return patch;\n } finally {\n await this.gitClient.reset(ResetMode.HARD);\n }\n });\n }\n\n /**\n * Apply a patch to the given file, returning the merged result, which may\n * include conflict markers. The underlying file is not mutated.\n *\n * Git is unable to generate a representation with conflict markers in the\n * event of binary merge conflicts. In this case a null Buffer is returned.\n */\n async getPatchedFile(\n filename: string,\n reactNativeVersion: string,\n patchContent: string,\n ): Promise<{patchedFile: Buffer | null; hasConflicts: boolean}> {\n return this.usingVersion(reactNativeVersion, async () => {\n await this.ensureFile(filename);\n\n try {\n await this.fileRepo.writeFile('rnwgit.patch', patchContent);\n\n let hasConflicts = false;\n let binaryConflicts = false;\n\n try {\n await this.gitClient.raw([\n 'apply',\n '--3way',\n '--whitespace=nowarn',\n 'rnwgit.patch',\n ]);\n } catch (ex) {\n // Hack alert: simple-git doesn't populate exception information from\n // conflicts when we're using raw commands (which we need to since it\n // doesn't support apply). Try to detect if Git gave us a bad exit code\n // because of merge conflicts, which we explicitly want to allow.\n if (!(ex as Error).message.includes('with conflicts')) {\n throw ex;\n }\n\n hasConflicts = true;\n binaryConflicts = (ex as Error).message.includes(\n 'Cannot merge binary files',\n );\n }\n\n const patchedFile = binaryConflicts\n ? null\n : await this.fileRepo.readFile(filename);\n\n return {patchedFile, hasConflicts};\n } finally {\n await this.gitClient.reset(ResetMode.HARD);\n }\n });\n }\n\n private async usingVersion<T>(\n reactNativeVersion: string,\n fn: () => Promise<T>,\n ): Promise<T> {\n return await this.batchingQueue.enqueue(reactNativeVersion, async () => {\n await this.checkoutVersion(reactNativeVersion);\n return await fn();\n });\n }\n\n private async checkoutVersion(reactNativeVersion: string) {\n if (reactNativeVersion !== this.checkedOutVersion) {\n if (!(await this.tryCheckoutLocal(reactNativeVersion))) {\n await this.fetchAndCheckout(reactNativeVersion);\n }\n\n this.checkedOutVersion = reactNativeVersion;\n }\n }\n\n private async tryCheckoutLocal(reactNativeVersion: string): Promise<boolean> {\n try {\n await this.gitClient.checkout([reactNativeVersion, '--force']);\n return true;\n } catch {\n return false;\n }\n }\n\n private async fetchAndCheckout(reactNativeVersion: string) {\n const githubToken =\n GitReactFileRepository.githubToken ||\n process.env.PLATFORM_OVERRIDE_GITHUB_TOKEN;\n const gitRef = await fetchFullRef(reactNativeVersion, {githubToken});\n\n try {\n await this.gitClient.fetch([RN_GITHUB_URL, gitRef, '--depth=1']);\n await this.gitClient.checkout(['-b', reactNativeVersion, 'FETCH_HEAD']);\n } catch (ex) {\n throw new Error(\n `Failed to fetch '${gitRef}'. Does it exist? (${\n (ex as Error).message\n })`,\n );\n }\n\n await this.gitClient.checkout([reactNativeVersion, '--force']);\n }\n\n private static async defaultGitDirectory(): Promise<string> {\n return path.join(os.tmpdir(), (await getNpmPackage()).name, 'git');\n }\n\n private async ensureFile(filename: string): Promise<void> {\n const stat = await this.fileRepo.stat(filename);\n if (stat === 'none') {\n throw new Error(\n `Cannot find file \"${filename}\" in react-native@${this.checkedOutVersion}`,\n );\n } else if (stat === 'directory') {\n throw new Error(`\"${filename}\" refers to a directory`);\n }\n }\n}\n"]}
|