react-native-platform-override 0.4.7 → 0.80.5

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.
Files changed (73) hide show
  1. package/bin.js +1 -2
  2. package/lib-commonjs/Api.d.ts +57 -56
  3. package/lib-commonjs/Api.js +187 -167
  4. package/lib-commonjs/Api.js.map +1 -1
  5. package/lib-commonjs/BatchingQueue.d.ts +15 -15
  6. package/lib-commonjs/BatchingQueue.js +57 -57
  7. package/lib-commonjs/BatchingQueue.js.map +1 -1
  8. package/lib-commonjs/Cli.d.ts +7 -7
  9. package/lib-commonjs/Cli.js +323 -291
  10. package/lib-commonjs/Cli.js.map +1 -1
  11. package/lib-commonjs/CrossProcessLock.d.ts +44 -44
  12. package/lib-commonjs/CrossProcessLock.js +147 -144
  13. package/lib-commonjs/CrossProcessLock.js.map +1 -1
  14. package/lib-commonjs/DiffStrategy.d.ts +24 -24
  15. package/lib-commonjs/DiffStrategy.js +34 -34
  16. package/lib-commonjs/DiffStrategy.js.map +1 -1
  17. package/lib-commonjs/FileRepository.d.ts +63 -62
  18. package/lib-commonjs/FileRepository.js +21 -21
  19. package/lib-commonjs/FileRepository.js.map +1 -1
  20. package/lib-commonjs/FileSearch.d.ts +21 -21
  21. package/lib-commonjs/FileSearch.js +77 -91
  22. package/lib-commonjs/FileSearch.js.map +1 -1
  23. package/lib-commonjs/FileSystemRepository.d.ts +21 -20
  24. package/lib-commonjs/FileSystemRepository.js +62 -59
  25. package/lib-commonjs/FileSystemRepository.js.map +1 -1
  26. package/lib-commonjs/GitReactFileRepository.d.ts +57 -58
  27. package/lib-commonjs/GitReactFileRepository.js +202 -208
  28. package/lib-commonjs/GitReactFileRepository.js.map +1 -1
  29. package/lib-commonjs/Hash.d.ts +34 -33
  30. package/lib-commonjs/Hash.js +81 -81
  31. package/lib-commonjs/Hash.js.map +1 -1
  32. package/lib-commonjs/Manifest.d.ts +80 -80
  33. package/lib-commonjs/Manifest.js +157 -154
  34. package/lib-commonjs/Manifest.js.map +1 -1
  35. package/lib-commonjs/Override.d.ts +182 -182
  36. package/lib-commonjs/Override.js +248 -245
  37. package/lib-commonjs/Override.js.map +1 -1
  38. package/lib-commonjs/OverrideFactory.d.ts +33 -33
  39. package/lib-commonjs/OverrideFactory.js +85 -70
  40. package/lib-commonjs/OverrideFactory.js.map +1 -1
  41. package/lib-commonjs/OverridePrompt.d.ts +30 -30
  42. package/lib-commonjs/OverridePrompt.js +130 -104
  43. package/lib-commonjs/OverridePrompt.js.map +1 -1
  44. package/lib-commonjs/PackageUtils.d.ts +15 -15
  45. package/lib-commonjs/PackageUtils.js +40 -38
  46. package/lib-commonjs/PackageUtils.js.map +1 -1
  47. package/lib-commonjs/PathUtils.d.ts +14 -14
  48. package/lib-commonjs/PathUtils.js +31 -28
  49. package/lib-commonjs/PathUtils.js.map +1 -1
  50. package/lib-commonjs/Serialized.d.ts +158 -158
  51. package/lib-commonjs/Serialized.js +145 -119
  52. package/lib-commonjs/Serialized.js.map +1 -1
  53. package/lib-commonjs/UpgradeStrategy.d.ts +39 -39
  54. package/lib-commonjs/UpgradeStrategy.js +102 -99
  55. package/lib-commonjs/UpgradeStrategy.js.map +1 -1
  56. package/lib-commonjs/ValidationStrategy.d.ts +57 -57
  57. package/lib-commonjs/ValidationStrategy.js +124 -124
  58. package/lib-commonjs/ValidationStrategy.js.map +1 -1
  59. package/lib-commonjs/refFromVersion.d.ts +10 -0
  60. package/lib-commonjs/refFromVersion.js +99 -0
  61. package/lib-commonjs/refFromVersion.js.map +1 -0
  62. package/lib-commonjs/scripts/generateManifest.d.ts +7 -7
  63. package/lib-commonjs/scripts/generateManifest.js +196 -170
  64. package/lib-commonjs/scripts/generateManifest.js.map +1 -1
  65. package/lib-commonjs/scripts/hashFile.d.ts +7 -7
  66. package/lib-commonjs/scripts/hashFile.js +17 -14
  67. package/lib-commonjs/scripts/hashFile.js.map +1 -1
  68. package/lib-commonjs/scripts/testLocks.d.ts +1 -1
  69. package/lib-commonjs/scripts/testLocks.js +29 -26
  70. package/lib-commonjs/scripts/testLocks.js.map +1 -1
  71. package/package.json +53 -43
  72. package/CHANGELOG.json +0 -554
  73. package/CHANGELOG.md +0 -238
package/bin.js CHANGED
@@ -7,6 +7,5 @@
7
7
  * @format
8
8
  */
9
9
 
10
- // Yarn will fail to link workspace binaries if they haven't been built yet. Add
11
- // a simple JS file to forward to the CLI which is built after install.
10
+ require('source-map-support').install();
12
11
  require('./lib-commonjs/Cli');
@@ -1,56 +1,57 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- *
5
- * @format
6
- */
7
- import OverrideFactory from './OverrideFactory';
8
- import Override from './Override';
9
- import { UpgradeResult } from './UpgradeStrategy';
10
- import { ValidationError } from './ValidationStrategy';
11
- export * from './OverrideFactory';
12
- export * from './Override';
13
- export { UpgradeResult, ValidationError };
14
- /**
15
- * Check that the given manifest correctly describe overrides and that all
16
- * overrides are up to date
17
- */
18
- export declare function validateManifest(manifestPath: string, opts?: {
19
- reactNativeVersion?: string;
20
- }): Promise<ValidationError[]>;
21
- /**
22
- * Return whether the override exists in the manifest
23
- */
24
- export declare function hasOverride(overrideName: string, manifestPath: string): Promise<boolean>;
25
- /**
26
- * Removes an override from the manifest if it exists.
27
- * @returns whether the override was removed
28
- */
29
- export declare function removeOverride(overrideName: string, manifestPath: string): Promise<boolean>;
30
- /**
31
- * Returns a factory to create overrides which may be added to the manifest
32
- */
33
- export declare function getOverrideFactory(manifestPath: string, opts?: {
34
- reactNativeVersion?: string;
35
- }): Promise<OverrideFactory>;
36
- /**
37
- * Adds an override to the manifest
38
- */
39
- export declare function addOverride(override: Override, manifestPath: string): Promise<void>;
40
- /**
41
- * Ouputs a patch-style diff of an override compared to its original source
42
- */
43
- export declare function diffOverride(overrideName: string, manifestPath: string): Promise<string>;
44
- /**
45
- * Receives notifications on progress during overide upgrades
46
- */
47
- export declare type UpgradeProgressListener = (currentOverride: number, totalOverrides: number) => void;
48
- /**
49
- * Attempts to automatically merge changes from the current version into
50
- * out-of-date overrides.
51
- */
52
- export declare function upgradeOverrides(manifestPath: string, opts: {
53
- allowConflicts: boolean;
54
- reactNativeVersion?: string;
55
- progressListener?: UpgradeProgressListener;
56
- }): Promise<UpgradeResult[]>;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ import OverrideFactory from './OverrideFactory';
8
+ import Override from './Override';
9
+ import { UpgradeResult } from './UpgradeStrategy';
10
+ import { ValidationError } from './ValidationStrategy';
11
+ export * from './OverrideFactory';
12
+ export * from './Override';
13
+ export * from './refFromVersion';
14
+ export { UpgradeResult, ValidationError };
15
+ /**
16
+ * Check that the given manifest correctly describe overrides and that all
17
+ * overrides are up to date
18
+ */
19
+ export declare function validateManifest(manifestPath: string, opts?: {
20
+ reactNativeVersion?: string;
21
+ }): Promise<ValidationError[]>;
22
+ /**
23
+ * Return whether the override exists in the manifest
24
+ */
25
+ export declare function hasOverride(overrideName: string, manifestPath: string): Promise<boolean>;
26
+ /**
27
+ * Removes an override from the manifest if it exists.
28
+ * @returns whether the override was removed
29
+ */
30
+ export declare function removeOverride(overrideName: string, manifestPath: string): Promise<boolean>;
31
+ /**
32
+ * Returns a factory to create overrides which may be added to the manifest
33
+ */
34
+ export declare function getOverrideFactory(manifestPath: string, opts?: {
35
+ reactNativeVersion?: string;
36
+ }): Promise<OverrideFactory>;
37
+ /**
38
+ * Adds an override to the manifest
39
+ */
40
+ export declare function addOverride(override: Override, manifestPath: string): Promise<void>;
41
+ /**
42
+ * Outputs a patch-style diff of an override compared to its original source
43
+ */
44
+ export declare function diffOverride(overrideName: string, manifestPath: string): Promise<string>;
45
+ /**
46
+ * Receives notifications on progress during override upgrades
47
+ */
48
+ export type UpgradeProgressListener = (currentOverride: number, totalOverrides: number) => void;
49
+ /**
50
+ * Attempts to automatically merge changes from the current version into
51
+ * out-of-date overrides.
52
+ */
53
+ export declare function upgradeOverrides(manifestPath: string, opts: {
54
+ allowConflicts: boolean;
55
+ reactNativeVersion?: string;
56
+ progressListener?: UpgradeProgressListener;
57
+ }): Promise<UpgradeResult[]>;
@@ -1,168 +1,188 @@
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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.upgradeOverrides = exports.diffOverride = exports.addOverride = exports.getOverrideFactory = exports.removeOverride = exports.hasOverride = exports.validateManifest = void 0;
20
- // Typings for "async" confuse this rule
21
- /* eslint-disable @typescript-eslint/no-misused-promises */
22
- const Serialized = require("./Serialized");
23
- const _ = require("lodash");
24
- const fs = require("fs");
25
- const path = require("path");
26
- const OverrideFactory_1 = require("./OverrideFactory");
27
- const FileRepository_1 = require("./FileRepository");
28
- const async_1 = require("async");
29
- const FileSystemRepository_1 = require("./FileSystemRepository");
30
- const GitReactFileRepository_1 = require("./GitReactFileRepository");
31
- const Manifest_1 = require("./Manifest");
32
- const PackageUtils_1 = require("./PackageUtils");
33
- // Re-export types used in the public API so external packages don't have to
34
- // reach into our guts to import them.
35
- __exportStar(require("./OverrideFactory"), exports);
36
- __exportStar(require("./Override"), exports);
37
- const MAX_CONCURRENT_TASKS = 30;
38
- /**
39
- * Check that the given manifest correctly describe overrides and that all
40
- * overrides are up to date
41
- */
42
- async function validateManifest(manifestPath, opts) {
43
- const { manifest, overrideRepo, reactRepo } = await createManifestContext(manifestPath, opts);
44
- return await manifest.validate(overrideRepo, reactRepo);
45
- }
46
- exports.validateManifest = validateManifest;
47
- /**
48
- * Return whether the override exists in the manifest
49
- */
50
- async function hasOverride(overrideName, manifestPath) {
51
- const { manifest } = await createManifestContext(manifestPath);
52
- return manifest.hasOverride(overrideName);
53
- }
54
- exports.hasOverride = hasOverride;
55
- /**
56
- * Removes an override from the manifest if it exists.
57
- * @returns whether the override was removed
58
- */
59
- async function removeOverride(overrideName, manifestPath) {
60
- const { manifest } = await createManifestContext(manifestPath);
61
- const removed = manifest.removeOverride(overrideName);
62
- if (removed) {
63
- await Serialized.writeManifestToFile(manifest.serialize(), manifestPath);
64
- }
65
- return removed;
66
- }
67
- exports.removeOverride = removeOverride;
68
- /**
69
- * Returns a factory to create overrides which may be added to the manifest
70
- */
71
- async function getOverrideFactory(manifestPath, opts) {
72
- return (await createManifestContext(manifestPath, opts)).overrideFactory;
73
- }
74
- exports.getOverrideFactory = getOverrideFactory;
75
- /**
76
- * Adds an override to the manifest
77
- */
78
- async function addOverride(override, manifestPath) {
79
- const { manifest } = await createManifestContext(manifestPath);
80
- manifest.addOverride(override);
81
- await Serialized.writeManifestToFile(manifest.serialize(), manifestPath);
82
- }
83
- exports.addOverride = addOverride;
84
- /**
85
- * Ouputs a patch-style diff of an override compared to its original source
86
- */
87
- async function diffOverride(overrideName, manifestPath) {
88
- const ctx = await createManifestContext(manifestPath);
89
- const override = ctx.manifest.findOverride(overrideName);
90
- if (!override) {
91
- throw new Error(`Could not find override with name "${overrideName}"`);
92
- }
93
- return override.diffStrategy().diff(ctx.gitReactRepo, ctx.overrideRepo);
94
- }
95
- exports.diffOverride = diffOverride;
96
- /**
97
- * Attempts to automatically merge changes from the current version into
98
- * out-of-date overrides.
99
- */
100
- async function upgradeOverrides(manifestPath, opts) {
101
- const ctx = await createManifestContext(manifestPath, opts);
102
- const validationErrors = await ctx.manifest.validate(ctx.overrideRepo, ctx.reactRepo);
103
- const outOfDateOverrides = validationErrors
104
- .filter(err => err.type === 'outOfDate')
105
- .map(err => ctx.manifest.findOverride(err.overrideName));
106
- // Perform upgrades concurrently so we can take advantage of
107
- // GitReactFileRepository optimizations when multiple requests are queued at
108
- // once.
109
- let i = 0;
110
- const upgradeResults = await async_1.mapLimit(outOfDateOverrides, MAX_CONCURRENT_TASKS, async (override) => {
111
- const upgradeResult = await override
112
- .upgradeStrategy()
113
- .upgrade(ctx.gitReactRepo, ctx.overrideRepo, ctx.reactNativeVersion, opts.allowConflicts);
114
- if (opts.progressListener) {
115
- opts.progressListener(++i, outOfDateOverrides.length);
116
- }
117
- return upgradeResult;
118
- });
119
- // Regenerate overrides that are already up to date to update the baseVersion
120
- // to current. This helps to minimize the numbers of versions we have to
121
- // check out for future upgrades.
122
- const upToDateOverrides = [
123
- ..._.difference(ctx.manifest.listOverrides(), validationErrors.map(err => ctx.manifest.findOverride(err.overrideName))).map(ovr => ovr.name()),
124
- ...upgradeResults
125
- .filter(res => res.filesWritten)
126
- .map(res => res.overrideName),
127
- ];
128
- await async_1.eachLimit(upToDateOverrides, MAX_CONCURRENT_TASKS, async (name) => {
129
- await ctx.manifest.markUpToDate(name, ctx.overrideFactory);
130
- });
131
- ctx.manifest.setBaseVersion(ctx.reactNativeVersion);
132
- await Serialized.writeManifestToFile(ctx.manifest.serialize(), manifestPath);
133
- return upgradeResults.sort((a, b) => a.overrideName.localeCompare(b.overrideName, 'en'));
134
- }
135
- exports.upgradeOverrides = upgradeOverrides;
136
- /**
137
- * Throw if a file doesn't exist, printing an error message on the way
138
- */
139
- async function checkFileExists(friendlyName, filePath) {
140
- try {
141
- await fs.promises.access(filePath);
142
- }
143
- catch (ex) {
144
- throw new Error(`Could not find ${friendlyName} at path '${filePath}'`);
145
- }
146
- }
147
- /**
148
- * Sets up state for a manifest describing overrides at a specified RN version
149
- */
150
- async function createManifestContext(manifestPath, opts) {
151
- await checkFileExists('manifest', manifestPath);
152
- const reactNativeVersion = (opts === null || opts === void 0 ? void 0 : opts.reactNativeVersion) || (await PackageUtils_1.getInstalledRNVersion());
153
- const overrideDir = path.dirname(manifestPath);
154
- const overrideRepo = new FileSystemRepository_1.default(overrideDir);
155
- const gitReactRepo = await GitReactFileRepository_1.default.createAndInit();
156
- const reactRepo = FileRepository_1.bindVersion(gitReactRepo, reactNativeVersion);
157
- const overrideFactory = new OverrideFactory_1.OverrideFactoryImpl(reactRepo, overrideRepo);
158
- const manifest = Manifest_1.default.fromSerialized(await Serialized.readManifestFromFile(manifestPath));
159
- return {
160
- overrideRepo,
161
- reactRepo,
162
- gitReactRepo,
163
- overrideFactory,
164
- manifest,
165
- reactNativeVersion,
166
- };
167
- }
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
32
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.upgradeOverrides = exports.diffOverride = exports.addOverride = exports.getOverrideFactory = exports.removeOverride = exports.hasOverride = exports.validateManifest = void 0;
39
+ // Typings for "async" confuse this rule
40
+ /* eslint-disable @typescript-eslint/no-misused-promises */
41
+ const Serialized = __importStar(require("./Serialized"));
42
+ const lodash_1 = __importDefault(require("lodash"));
43
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
44
+ const path_1 = __importDefault(require("path"));
45
+ const OverrideFactory_1 = require("./OverrideFactory");
46
+ const FileRepository_1 = require("./FileRepository");
47
+ const async_1 = require("async");
48
+ const FileSystemRepository_1 = __importDefault(require("./FileSystemRepository"));
49
+ const GitReactFileRepository_1 = __importDefault(require("./GitReactFileRepository"));
50
+ const Manifest_1 = __importDefault(require("./Manifest"));
51
+ const PackageUtils_1 = require("./PackageUtils");
52
+ // Re-export types used in the public API so external packages don't have to
53
+ // reach into our guts to import them.
54
+ __exportStar(require("./OverrideFactory"), exports);
55
+ __exportStar(require("./Override"), exports);
56
+ __exportStar(require("./refFromVersion"), exports);
57
+ const MAX_CONCURRENT_TASKS = 30;
58
+ /**
59
+ * Check that the given manifest correctly describe overrides and that all
60
+ * overrides are up to date
61
+ */
62
+ async function validateManifest(manifestPath, opts) {
63
+ const { manifest, overrideRepo, reactRepo } = await createManifestContext(manifestPath, opts);
64
+ return await manifest.validate(overrideRepo, reactRepo);
65
+ }
66
+ exports.validateManifest = validateManifest;
67
+ /**
68
+ * Return whether the override exists in the manifest
69
+ */
70
+ async function hasOverride(overrideName, manifestPath) {
71
+ const { manifest } = await createManifestContext(manifestPath);
72
+ return manifest.hasOverride(overrideName);
73
+ }
74
+ exports.hasOverride = hasOverride;
75
+ /**
76
+ * Removes an override from the manifest if it exists.
77
+ * @returns whether the override was removed
78
+ */
79
+ async function removeOverride(overrideName, manifestPath) {
80
+ const { manifest } = await createManifestContext(manifestPath);
81
+ const removed = manifest.removeOverride(overrideName);
82
+ if (removed) {
83
+ await Serialized.writeManifestToFile(manifest.serialize(), manifestPath);
84
+ }
85
+ return removed;
86
+ }
87
+ exports.removeOverride = removeOverride;
88
+ /**
89
+ * Returns a factory to create overrides which may be added to the manifest
90
+ */
91
+ async function getOverrideFactory(manifestPath, opts) {
92
+ return (await createManifestContext(manifestPath, opts)).overrideFactory;
93
+ }
94
+ exports.getOverrideFactory = getOverrideFactory;
95
+ /**
96
+ * Adds an override to the manifest
97
+ */
98
+ async function addOverride(override, manifestPath) {
99
+ const { manifest } = await createManifestContext(manifestPath);
100
+ manifest.addOverride(override);
101
+ await Serialized.writeManifestToFile(manifest.serialize(), manifestPath);
102
+ }
103
+ exports.addOverride = addOverride;
104
+ /**
105
+ * Outputs a patch-style diff of an override compared to its original source
106
+ */
107
+ async function diffOverride(overrideName, manifestPath) {
108
+ const ctx = await createManifestContext(manifestPath);
109
+ const override = ctx.manifest.findOverride(overrideName);
110
+ if (!override) {
111
+ throw new Error(`Could not find override with name "${overrideName}"`);
112
+ }
113
+ return override.diffStrategy().diff(ctx.gitReactRepo, ctx.overrideRepo);
114
+ }
115
+ exports.diffOverride = diffOverride;
116
+ /**
117
+ * Attempts to automatically merge changes from the current version into
118
+ * out-of-date overrides.
119
+ */
120
+ async function upgradeOverrides(manifestPath, opts) {
121
+ const ctx = await createManifestContext(manifestPath, opts);
122
+ const validationErrors = await ctx.manifest.validate(ctx.overrideRepo, ctx.reactRepo);
123
+ const outOfDateOverrides = validationErrors
124
+ .filter(err => err.type === 'outOfDate')
125
+ .map(err => ctx.manifest.findOverride(err.overrideName));
126
+ // Perform upgrades concurrently so we can take advantage of
127
+ // GitReactFileRepository optimizations when multiple requests are queued at
128
+ // once.
129
+ let i = 0;
130
+ const upgradeResults = await (0, async_1.mapLimit)(outOfDateOverrides, MAX_CONCURRENT_TASKS, async (override) => {
131
+ const upgradeResult = await override
132
+ .upgradeStrategy()
133
+ .upgrade(ctx.gitReactRepo, ctx.overrideRepo, ctx.reactNativeVersion, opts.allowConflicts);
134
+ if (opts.progressListener) {
135
+ opts.progressListener(++i, outOfDateOverrides.length);
136
+ }
137
+ return upgradeResult;
138
+ });
139
+ // Regenerate overrides that are already up to date to update the baseVersion
140
+ // to current. This helps to minimize the numbers of versions we have to
141
+ // check out for future upgrades.
142
+ const upToDateOverrides = [
143
+ ...lodash_1.default.difference(ctx.manifest.listOverrides(), validationErrors.map(err => ctx.manifest.findOverride(err.overrideName))).map(ovr => ovr.name()),
144
+ ...upgradeResults
145
+ .filter(res => res.filesWritten)
146
+ .map(res => res.overrideName),
147
+ ];
148
+ await (0, async_1.eachLimit)(upToDateOverrides, MAX_CONCURRENT_TASKS, async (name) => {
149
+ await ctx.manifest.markUpToDate(name, ctx.overrideFactory);
150
+ });
151
+ ctx.manifest.setBaseVersion(ctx.reactNativeVersion);
152
+ await Serialized.writeManifestToFile(ctx.manifest.serialize(), manifestPath);
153
+ return upgradeResults.sort((a, b) => a.overrideName.localeCompare(b.overrideName, 'en'));
154
+ }
155
+ exports.upgradeOverrides = upgradeOverrides;
156
+ /**
157
+ * Throw if a file doesn't exist, printing an error message on the way
158
+ */
159
+ async function checkFileExists(friendlyName, filePath) {
160
+ try {
161
+ await fs_1.default.access(filePath);
162
+ }
163
+ catch (ex) {
164
+ throw new Error(`Could not find ${friendlyName} at path '${filePath}'`);
165
+ }
166
+ }
167
+ /**
168
+ * Sets up state for a manifest describing overrides at a specified RN version
169
+ */
170
+ async function createManifestContext(manifestPath, opts) {
171
+ await checkFileExists('manifest', manifestPath);
172
+ const reactNativeVersion = (opts === null || opts === void 0 ? void 0 : opts.reactNativeVersion) || (await (0, PackageUtils_1.getInstalledRNVersion)());
173
+ const overrideDir = path_1.default.dirname(manifestPath);
174
+ const overrideRepo = new FileSystemRepository_1.default(overrideDir);
175
+ const gitReactRepo = await GitReactFileRepository_1.default.createAndInit();
176
+ const reactRepo = (0, FileRepository_1.bindVersion)(gitReactRepo, reactNativeVersion);
177
+ const overrideFactory = new OverrideFactory_1.OverrideFactoryImpl(reactRepo, overrideRepo);
178
+ const manifest = Manifest_1.default.fromSerialized(await Serialized.readManifestFromFile(manifestPath));
179
+ return {
180
+ overrideRepo,
181
+ reactRepo,
182
+ gitReactRepo,
183
+ overrideFactory,
184
+ manifest,
185
+ reactNativeVersion,
186
+ };
187
+ }
168
188
  //# sourceMappingURL=Api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Api.js","sourceRoot":"","sources":["../src/Api.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;AAEH,wCAAwC;AACxC,2DAA2D;AAE3D,2CAA2C;AAC3C,4BAA4B;AAC5B,yBAAyB;AACzB,6BAA6B;AAE7B,uDAAuE;AACvE,qDAI0B;AAC1B,iCAA0C;AAC1C,iEAA0D;AAC1D,qEAA8D;AAC9D,yCAAkC;AAIlC,iDAAqD;AAErD,4EAA4E;AAC5E,sCAAsC;AACtC,oDAAkC;AAClC,6CAA2B;AAG3B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;;GAGG;AACI,KAAK,UAAU,gBAAgB,CACpC,YAAoB,EACpB,IAEC;IAED,MAAM,EAAC,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAC,GAAG,MAAM,qBAAqB,CACrE,YAAY,EACZ,IAAI,CACL,CAAC;IACF,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC;AAXD,4CAWC;AAED;;GAEG;AACI,KAAK,UAAU,WAAW,CAC/B,YAAoB,EACpB,YAAoB;IAEpB,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAC7D,OAAO,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAND,kCAMC;AAED;;;GAGG;AACI,KAAK,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) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\n// Typings for \"async\" confuse this rule\n/* eslint-disable @typescript-eslint/no-misused-promises */\n\nimport * as Serialized from './Serialized';\nimport _ from 'lodash';\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\n\nimport OverrideFactory, {OverrideFactoryImpl} from './OverrideFactory';\nimport {\n ReactFileRepository,\n WritableFileRepository,\n bindVersion,\n} from './FileRepository';\nimport {eachLimit, mapLimit} from 'async';\nimport FileSystemRepository from './FileSystemRepository';\nimport GitReactFileRepository from './GitReactFileRepository';\nimport Manifest from './Manifest';\nimport Override from './Override';\nimport {UpgradeResult} from './UpgradeStrategy';\nimport {ValidationError} from './ValidationStrategy';\nimport {getInstalledRNVersion} from './PackageUtils';\n\n// Re-export types used in the public API so external packages don't have to\n// reach into our guts to import them.\nexport * from './OverrideFactory';\nexport * from './Override';\nexport * from './refFromVersion';\nexport {UpgradeResult, ValidationError};\n\nconst MAX_CONCURRENT_TASKS = 30;\n\n/**\n * Check that the given manifest correctly describe overrides and that all\n * overrides are up to date\n */\nexport async function validateManifest(\n manifestPath: string,\n opts?: {\n reactNativeVersion?: string;\n },\n): Promise<ValidationError[]> {\n const {manifest, overrideRepo, reactRepo} = await createManifestContext(\n manifestPath,\n opts,\n );\n return await manifest.validate(overrideRepo, reactRepo);\n}\n\n/**\n * Return whether the override exists in the manifest\n */\nexport async function hasOverride(\n overrideName: string,\n manifestPath: string,\n): Promise<boolean> {\n const {manifest} = await createManifestContext(manifestPath);\n return manifest.hasOverride(overrideName);\n}\n\n/**\n * Removes an override from the manifest if it exists.\n * @returns whether the override was removed\n */\nexport async function removeOverride(\n overrideName: string,\n manifestPath: string,\n): Promise<boolean> {\n const {manifest} = await createManifestContext(manifestPath);\n const removed = manifest.removeOverride(overrideName);\n if (removed) {\n await Serialized.writeManifestToFile(manifest.serialize(), manifestPath);\n }\n\n return removed;\n}\n\n/**\n * Returns a factory to create overrides which may be added to the manifest\n */\nexport async function getOverrideFactory(\n manifestPath: string,\n opts?: {\n reactNativeVersion?: string;\n },\n): Promise<OverrideFactory> {\n return (await createManifestContext(manifestPath, opts)).overrideFactory;\n}\n\n/**\n * Adds an override to the manifest\n */\nexport async function addOverride(\n override: Override,\n manifestPath: string,\n): Promise<void> {\n const {manifest} = await createManifestContext(manifestPath);\n manifest.addOverride(override);\n await Serialized.writeManifestToFile(manifest.serialize(), manifestPath);\n}\n\n/**\n * Outputs a patch-style diff of an override compared to its original source\n */\nexport async function diffOverride(\n overrideName: string,\n manifestPath: string,\n): Promise<string> {\n const ctx = await createManifestContext(manifestPath);\n\n const override = ctx.manifest.findOverride(overrideName);\n if (!override) {\n throw new Error(`Could not find override with name \"${overrideName}\"`);\n }\n\n return override.diffStrategy().diff(ctx.gitReactRepo, ctx.overrideRepo);\n}\n\n/**\n * Receives notifications on progress during override upgrades\n */\nexport type UpgradeProgressListener = (\n currentOverride: number,\n totalOverrides: number,\n) => void;\n\n/**\n * Attempts to automatically merge changes from the current version into\n * out-of-date overrides.\n */\nexport async function upgradeOverrides(\n manifestPath: string,\n opts: {\n allowConflicts: boolean;\n reactNativeVersion?: string;\n progressListener?: UpgradeProgressListener;\n },\n): Promise<UpgradeResult[]> {\n const ctx = await createManifestContext(manifestPath, opts);\n\n const validationErrors = await ctx.manifest.validate(\n ctx.overrideRepo,\n ctx.reactRepo,\n );\n\n const outOfDateOverrides = validationErrors\n .filter(err => err.type === 'outOfDate')\n .map(err => ctx.manifest.findOverride(err.overrideName)!);\n\n // Perform upgrades concurrently so we can take advantage of\n // GitReactFileRepository optimizations when multiple requests are queued at\n // once.\n let i = 0;\n const upgradeResults = await mapLimit<Override, UpgradeResult>(\n outOfDateOverrides,\n MAX_CONCURRENT_TASKS,\n async (override: any) => {\n const upgradeResult = await override\n .upgradeStrategy()\n .upgrade(\n ctx.gitReactRepo,\n ctx.overrideRepo,\n ctx.reactNativeVersion,\n opts.allowConflicts,\n );\n\n if (opts.progressListener) {\n opts.progressListener(++i, outOfDateOverrides.length);\n }\n\n return upgradeResult;\n },\n );\n\n // Regenerate overrides that are already up to date to update the baseVersion\n // to current. This helps to minimize the numbers of versions we have to\n // check out for future upgrades.\n const upToDateOverrides = [\n ..._.difference(\n ctx.manifest.listOverrides(),\n validationErrors.map(err => ctx.manifest.findOverride(err.overrideName)!),\n ).map(ovr => ovr.name()),\n\n ...upgradeResults\n .filter(res => res.filesWritten)\n .map(res => res.overrideName),\n ];\n\n await eachLimit(upToDateOverrides, MAX_CONCURRENT_TASKS, async name => {\n await ctx.manifest.markUpToDate(name, ctx.overrideFactory);\n });\n\n ctx.manifest.setBaseVersion(ctx.reactNativeVersion);\n await Serialized.writeManifestToFile(ctx.manifest.serialize(), manifestPath);\n\n return upgradeResults.sort((a, b) =>\n a.overrideName.localeCompare(b.overrideName, 'en'),\n );\n}\n\n/**\n * Throw if a file doesn't exist, printing an error message on the way\n */\nasync function checkFileExists(friendlyName: string, filePath: string) {\n try {\n await fs.access(filePath);\n } catch (ex) {\n throw new Error(`Could not find ${friendlyName} at path '${filePath}'`);\n }\n}\n\n/**\n * Context describing state centered around a single manifest\n */\ninterface ManifestContext {\n overrideRepo: WritableFileRepository;\n reactRepo: ReactFileRepository;\n gitReactRepo: GitReactFileRepository;\n overrideFactory: OverrideFactory;\n manifest: Manifest;\n reactNativeVersion: string;\n}\n\n/**\n * Sets up state for a manifest describing overrides at a specified RN version\n */\nasync function createManifestContext(\n manifestPath: string,\n opts?: {\n reactNativeVersion?: string;\n },\n): Promise<ManifestContext> {\n await checkFileExists('manifest', manifestPath);\n const reactNativeVersion =\n opts?.reactNativeVersion || (await getInstalledRNVersion());\n\n const overrideDir = path.dirname(manifestPath);\n const overrideRepo = new FileSystemRepository(overrideDir);\n\n const gitReactRepo = await GitReactFileRepository.createAndInit();\n const reactRepo = bindVersion(gitReactRepo, reactNativeVersion);\n\n const overrideFactory = new OverrideFactoryImpl(reactRepo, overrideRepo);\n const manifest = Manifest.fromSerialized(\n await Serialized.readManifestFromFile(manifestPath),\n );\n\n return {\n overrideRepo,\n reactRepo,\n gitReactRepo,\n overrideFactory,\n manifest,\n reactNativeVersion,\n };\n}\n"]}
@@ -1,15 +1,15 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- *
5
- * @format
6
- */
7
- /**
8
- * Executes actions, attempting to group by a given key
9
- */
10
- export default class BatchingQueue<TKey> {
11
- private readonly keyedQueues;
12
- private currentKey?;
13
- enqueue<T>(key: TKey, action: () => Promise<T>): Promise<T>;
14
- private pumpQueue;
15
- }
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ /**
8
+ * Executes actions, attempting to group by a given key
9
+ */
10
+ export default class BatchingQueue<TKey> {
11
+ private readonly keyedQueues;
12
+ private currentKey?;
13
+ enqueue<T>(key: TKey, action: () => Promise<T>): Promise<T>;
14
+ private pumpQueue;
15
+ }