forked from facebook/lexical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverride-react.js
55 lines (52 loc) · 1.45 KB
/
override-react.js
1
2
3
4
5
6
7
8
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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// @ts-check
'use strict';
const glob = require('glob');
const fs = require('fs-extra');
const argv = require('minimist')(process.argv.slice(2));
const {exec} = require('child-process-promise');
async function main() {
const {version} = argv;
if (!version) {
throw new Error('USAGE: node ./scripts/override-react --version=beta');
}
const packages = ['react', 'react-dom'];
[
'package.json',
...glob.sync('./packages/*/package.json', {windowsPathsNoEscape: true}),
].forEach((fn) => {
const json = fs.readJsonSync(fn);
const isRoot = fn === 'package.json';
let didUpdate = isRoot;
if (isRoot) {
json.overrides ||= {};
Object.assign(
json.overrides,
Object.fromEntries(packages.map((pkg) => [pkg, '$' + pkg])),
);
} else if (json.dependencies) {
for (const k of packages) {
if (json.dependencies[k]) {
json.dependencies[k] = '*';
didUpdate = true;
}
}
}
if (didUpdate) {
fs.writeJsonSync(fn, json, {spaces: 2});
}
});
const cmd = `npm i ${packages.map((pkg) => `${pkg}@${version}`).join(' ')}`;
console.log(cmd);
await exec(cmd);
await exec(
`git checkout package-lock.json package.json packages/*/package.json`,
);
}
main();