react/scripts/merge-fork/replace-fork.js
Andrew Clark 453df3ff72
Autofix imports when running replace-fork (#20251)
* Pass extra CLI args through to ESLint

These now work:

```
yarn run lint --fix
yarn run linc --fix
```

* Autofix imports when running replace-fork

We have a custom ESLint rule that can autofix cross-fork imports.

Usually, after running the `replace-fork` script, you need to run
`yarn lint --fix` to fix the imports.

This combines the two steps into one.
2020-11-13 11:01:25 -08:00

49 lines
1020 B
JavaScript

'use strict';
/* eslint-disable no-for-of-loops/no-for-of-loops */
// Copies the contents of the new fork into the old fork
const {promisify} = require('util');
const glob = promisify(require('glob'));
const {spawnSync} = require('child_process');
const fs = require('fs');
const stat = promisify(fs.stat);
const copyFile = promisify(fs.copyFile);
async function main() {
const oldFilenames = await glob('packages/react-reconciler/**/*.old.js');
await Promise.all(oldFilenames.map(unforkFile));
// Use ESLint to autofix imports
spawnSync('yarn', ['linc', '--fix']);
}
async function unforkFile(oldFilename) {
let oldStats;
try {
oldStats = await stat(oldFilename);
} catch {
return;
}
if (!oldStats.isFile()) {
return;
}
const newFilename = oldFilename.replace(/\.old.js$/, '.new.js');
let newStats;
try {
newStats = await stat(newFilename);
} catch {
return;
}
if (!newStats.isFile()) {
return;
}
await copyFile(newFilename, oldFilename);
}
main();