react-native-platform-override 1.9.21 → 1.9.23
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/lib-commonjs/Api.d.ts +57 -57
- package/lib-commonjs/Api.js +187 -187
- package/lib-commonjs/BatchingQueue.d.ts +15 -15
- package/lib-commonjs/BatchingQueue.js +57 -57
- package/lib-commonjs/Cli.d.ts +7 -7
- package/lib-commonjs/Cli.js +323 -323
- package/lib-commonjs/CrossProcessLock.d.ts +44 -44
- package/lib-commonjs/CrossProcessLock.js +147 -147
- package/lib-commonjs/DiffStrategy.d.ts +24 -24
- package/lib-commonjs/DiffStrategy.js +34 -34
- package/lib-commonjs/FileRepository.d.ts +62 -62
- package/lib-commonjs/FileRepository.js +21 -21
- package/lib-commonjs/FileSearch.d.ts +21 -21
- package/lib-commonjs/FileSearch.js +77 -77
- package/lib-commonjs/FileSystemRepository.d.ts +20 -20
- package/lib-commonjs/FileSystemRepository.js +62 -62
- package/lib-commonjs/GitReactFileRepository.d.ts +56 -56
- package/lib-commonjs/GitReactFileRepository.js +202 -202
- package/lib-commonjs/Hash.d.ts +33 -33
- package/lib-commonjs/Hash.js +81 -81
- package/lib-commonjs/Manifest.d.ts +80 -80
- package/lib-commonjs/Manifest.js +157 -157
- package/lib-commonjs/Override.d.ts +182 -182
- package/lib-commonjs/Override.js +248 -248
- package/lib-commonjs/OverrideFactory.d.ts +33 -33
- package/lib-commonjs/OverrideFactory.js +85 -85
- package/lib-commonjs/OverridePrompt.d.ts +30 -30
- package/lib-commonjs/OverridePrompt.js +130 -130
- package/lib-commonjs/PackageUtils.d.ts +15 -15
- package/lib-commonjs/PackageUtils.js +40 -40
- package/lib-commonjs/PathUtils.d.ts +14 -14
- package/lib-commonjs/PathUtils.js +31 -31
- package/lib-commonjs/Serialized.d.ts +158 -158
- package/lib-commonjs/Serialized.js +145 -145
- package/lib-commonjs/UpgradeStrategy.d.ts +39 -39
- package/lib-commonjs/UpgradeStrategy.js +102 -102
- package/lib-commonjs/ValidationStrategy.d.ts +57 -57
- package/lib-commonjs/ValidationStrategy.js +124 -124
- package/lib-commonjs/refFromVersion.d.ts +10 -10
- package/lib-commonjs/refFromVersion.js +98 -98
- package/lib-commonjs/refFromVersion.js.map +1 -1
- package/lib-commonjs/scripts/generateManifest.d.ts +7 -7
- package/lib-commonjs/scripts/generateManifest.js +196 -196
- package/lib-commonjs/scripts/hashFile.d.ts +7 -7
- package/lib-commonjs/scripts/hashFile.js +17 -17
- package/lib-commonjs/scripts/testLocks.d.ts +1 -1
- package/lib-commonjs/scripts/testLocks.js +29 -29
- package/package.json +10 -10
|
@@ -1,203 +1,203 @@
|
|
|
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;
|
|
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;
|
|
203
203
|
//# sourceMappingURL=GitReactFileRepository.js.map
|
package/lib-commonjs/Hash.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
import FileRepository from './FileRepository';
|
|
9
|
-
export type HashOpts = {
|
|
10
|
-
/**
|
|
11
|
-
* What differences between files should we be insensitive to when generating
|
|
12
|
-
* a hash? Defaults to line-ending insensitivity
|
|
13
|
-
*/
|
|
14
|
-
insensitivity?: 'none' | 'line-ending' | 'whitespace';
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Creates a hash from content, attempting to normalize for line-feeds
|
|
18
|
-
*/
|
|
19
|
-
export declare class Hasher {
|
|
20
|
-
private readonly hash;
|
|
21
|
-
private readonly hashOpts;
|
|
22
|
-
constructor(hashOpts?: HashOpts);
|
|
23
|
-
feedContent(content: string | Buffer): Hasher;
|
|
24
|
-
digest(): string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Convenience helper which hashes a single buffer
|
|
28
|
-
*/
|
|
29
|
-
export declare function hashContent(content: string | Buffer, opts?: HashOpts): string;
|
|
30
|
-
/**
|
|
31
|
-
* Helper to hash a file/directory belonging to a repository
|
|
32
|
-
*/
|
|
33
|
-
export declare function hashFileOrDirectory(name: string, repo: FileRepository, opts?: HashOpts): Promise<string | null>;
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import FileRepository from './FileRepository';
|
|
9
|
+
export type HashOpts = {
|
|
10
|
+
/**
|
|
11
|
+
* What differences between files should we be insensitive to when generating
|
|
12
|
+
* a hash? Defaults to line-ending insensitivity
|
|
13
|
+
*/
|
|
14
|
+
insensitivity?: 'none' | 'line-ending' | 'whitespace';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Creates a hash from content, attempting to normalize for line-feeds
|
|
18
|
+
*/
|
|
19
|
+
export declare class Hasher {
|
|
20
|
+
private readonly hash;
|
|
21
|
+
private readonly hashOpts;
|
|
22
|
+
constructor(hashOpts?: HashOpts);
|
|
23
|
+
feedContent(content: string | Buffer): Hasher;
|
|
24
|
+
digest(): string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convenience helper which hashes a single buffer
|
|
28
|
+
*/
|
|
29
|
+
export declare function hashContent(content: string | Buffer, opts?: HashOpts): string;
|
|
30
|
+
/**
|
|
31
|
+
* Helper to hash a file/directory belonging to a repository
|
|
32
|
+
*/
|
|
33
|
+
export declare function hashFileOrDirectory(name: string, repo: FileRepository, opts?: HashOpts): Promise<string | null>;
|
package/lib-commonjs/Hash.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.hashFileOrDirectory = exports.hashContent = exports.Hasher = void 0;
|
|
13
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
14
|
-
const path_1 = __importDefault(require("path"));
|
|
15
|
-
const PathUtils_1 = require("./PathUtils");
|
|
16
|
-
const isutf8_1 = __importDefault(require("isutf8"));
|
|
17
|
-
/**
|
|
18
|
-
* Normalize content according to insensitivity rules
|
|
19
|
-
*/
|
|
20
|
-
function normalizeContent(content, opts) {
|
|
21
|
-
if (opts.insensitivity === 'none' ||
|
|
22
|
-
(typeof content !== 'string' && !(0, isutf8_1.default)(content))) {
|
|
23
|
-
return content;
|
|
24
|
-
}
|
|
25
|
-
switch (opts.insensitivity || 'line-ending') {
|
|
26
|
-
case 'line-ending':
|
|
27
|
-
// Convert to CRLF for legacy hash stability
|
|
28
|
-
return content.toString('utf8').replace(/(?<!\r)\n/g, '\r\n');
|
|
29
|
-
case 'whitespace':
|
|
30
|
-
return content.toString('utf8').trim().replace(/\s+/g, ' ');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Creates a hash from content, attempting to normalize for line-feeds
|
|
35
|
-
*/
|
|
36
|
-
class Hasher {
|
|
37
|
-
constructor(hashOpts) {
|
|
38
|
-
this.hash = crypto_1.default.createHash('sha1');
|
|
39
|
-
this.hashOpts = hashOpts || {};
|
|
40
|
-
}
|
|
41
|
-
feedContent(content) {
|
|
42
|
-
this.hash.update(normalizeContent(content, this.hashOpts));
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
digest() {
|
|
46
|
-
return this.hash.digest('hex');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.Hasher = Hasher;
|
|
50
|
-
/**
|
|
51
|
-
* Convenience helper which hashes a single buffer
|
|
52
|
-
*/
|
|
53
|
-
function hashContent(content, opts) {
|
|
54
|
-
return new Hasher(opts).feedContent(content).digest();
|
|
55
|
-
}
|
|
56
|
-
exports.hashContent = hashContent;
|
|
57
|
-
/**
|
|
58
|
-
* Helper to hash a file/directory belonging to a repository
|
|
59
|
-
*/
|
|
60
|
-
async function hashFileOrDirectory(name, repo, opts) {
|
|
61
|
-
const type = await repo.stat(name);
|
|
62
|
-
if (type === 'none') {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
if (type === 'file') {
|
|
66
|
-
return hashContent((await repo.readFile(name)), opts);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const hasher = new Hasher(opts);
|
|
70
|
-
const subfiles = await repo.listFiles([`${(0, PathUtils_1.unixPath)(name)}/**`]);
|
|
71
|
-
for (const file of subfiles.sort()) {
|
|
72
|
-
const contents = await repo.readFile(file);
|
|
73
|
-
hasher.feedContent(contents);
|
|
74
|
-
// Incorporate the filename to detect if renames happen
|
|
75
|
-
const platformIndependentPath = (0, PathUtils_1.unixPath)(path_1.default.relative(name, (0, PathUtils_1.normalizePath)(file)));
|
|
76
|
-
hasher.feedContent(platformIndependentPath);
|
|
77
|
-
}
|
|
78
|
-
return hasher.digest();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.hashFileOrDirectory = hashFileOrDirectory;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.hashFileOrDirectory = exports.hashContent = exports.Hasher = void 0;
|
|
13
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const PathUtils_1 = require("./PathUtils");
|
|
16
|
+
const isutf8_1 = __importDefault(require("isutf8"));
|
|
17
|
+
/**
|
|
18
|
+
* Normalize content according to insensitivity rules
|
|
19
|
+
*/
|
|
20
|
+
function normalizeContent(content, opts) {
|
|
21
|
+
if (opts.insensitivity === 'none' ||
|
|
22
|
+
(typeof content !== 'string' && !(0, isutf8_1.default)(content))) {
|
|
23
|
+
return content;
|
|
24
|
+
}
|
|
25
|
+
switch (opts.insensitivity || 'line-ending') {
|
|
26
|
+
case 'line-ending':
|
|
27
|
+
// Convert to CRLF for legacy hash stability
|
|
28
|
+
return content.toString('utf8').replace(/(?<!\r)\n/g, '\r\n');
|
|
29
|
+
case 'whitespace':
|
|
30
|
+
return content.toString('utf8').trim().replace(/\s+/g, ' ');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a hash from content, attempting to normalize for line-feeds
|
|
35
|
+
*/
|
|
36
|
+
class Hasher {
|
|
37
|
+
constructor(hashOpts) {
|
|
38
|
+
this.hash = crypto_1.default.createHash('sha1');
|
|
39
|
+
this.hashOpts = hashOpts || {};
|
|
40
|
+
}
|
|
41
|
+
feedContent(content) {
|
|
42
|
+
this.hash.update(normalizeContent(content, this.hashOpts));
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
digest() {
|
|
46
|
+
return this.hash.digest('hex');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.Hasher = Hasher;
|
|
50
|
+
/**
|
|
51
|
+
* Convenience helper which hashes a single buffer
|
|
52
|
+
*/
|
|
53
|
+
function hashContent(content, opts) {
|
|
54
|
+
return new Hasher(opts).feedContent(content).digest();
|
|
55
|
+
}
|
|
56
|
+
exports.hashContent = hashContent;
|
|
57
|
+
/**
|
|
58
|
+
* Helper to hash a file/directory belonging to a repository
|
|
59
|
+
*/
|
|
60
|
+
async function hashFileOrDirectory(name, repo, opts) {
|
|
61
|
+
const type = await repo.stat(name);
|
|
62
|
+
if (type === 'none') {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (type === 'file') {
|
|
66
|
+
return hashContent((await repo.readFile(name)), opts);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const hasher = new Hasher(opts);
|
|
70
|
+
const subfiles = await repo.listFiles([`${(0, PathUtils_1.unixPath)(name)}/**`]);
|
|
71
|
+
for (const file of subfiles.sort()) {
|
|
72
|
+
const contents = await repo.readFile(file);
|
|
73
|
+
hasher.feedContent(contents);
|
|
74
|
+
// Incorporate the filename to detect if renames happen
|
|
75
|
+
const platformIndependentPath = (0, PathUtils_1.unixPath)(path_1.default.relative(name, (0, PathUtils_1.normalizePath)(file)));
|
|
76
|
+
hasher.feedContent(platformIndependentPath);
|
|
77
|
+
}
|
|
78
|
+
return hasher.digest();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.hashFileOrDirectory = hashFileOrDirectory;
|
|
82
82
|
//# sourceMappingURL=Hash.js.map
|