Skip to content

Commit

Permalink
Rename override-tools to react-native-platform-override (#4993)
Browse files Browse the repository at this point in the history
* Rename override-tools to react-native-windows-override

Fixes #4859

This chnage:
1. Matches better with other packages
2. Allows unambiguously mapping bin name to package name, allowing us to reccomend npx usage instead of Yarn, which has odd cwd behavior.

We also need to update out gitignore file which no longer was allowing checking in VS Code project settings.

* Use public react-native-platform-override instead of react-native-windows-override

* Update descriptions, reduce some hardcoding

* Remove some more duplication

* Missing file

* Remove require-time dependency to be called from the package bin. I.e. allow scripts to still work

* More path hardening

* Simplify logic a bit more

* Fic string
  • Loading branch information
NickGerleman committed May 25, 2020
1 parent 1a96ee7 commit 85b01cb
Show file tree
Hide file tree
Showing 36 changed files with 113 additions and 64 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Expand Up @@ -122,11 +122,17 @@ packages/
#Other files
*.DotSettings
.vs/
.vscode/
*project.lock.json
jsconfig.json
package-lock.json

# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

#JavaScript files
*.jsbundle

Expand Down
@@ -0,0 +1,8 @@
{
"type": "none",
"comment": "Rename override-tools to react-native-platform-override",
"packageName": "@office-iss/react-native-win32",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "none",
"date": "2020-05-25T15:44:40.322Z"
}
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "Rename override-tools to react-native-platform-override",
"packageName": "react-native-platform-override",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-05-25T15:45:02.599Z"
}
@@ -0,0 +1,8 @@
{
"type": "none",
"comment": "Rename override-tools to react-native-platform-override",
"packageName": "react-native-windows",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "none",
"date": "2020-05-25T15:44:45.971Z"
}
27 changes: 0 additions & 27 deletions packages/override-tools/src/ReactVersion.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,24 +1,24 @@
{
"name": "react-native-windows-override-tools",
"name": "react-native-platform-override",
"version": "0.0.1",
"description": "Tooling to manage Javascript file overrides in React Native Windows",
"private": true,
"description": "react-native-platform-override offers CLI tools to manage Javascript overrides in out-of-tree React Native platforms",
"license": "MIT",
"repository": {
"type": "git",
"url": "git@github.com:microsoft/react-native-windows.git",
"directory": "packages/override-tools"
"directory": "packages/react-native-platform-override"
},
"scripts": {
"build": "just-scripts build",
"change": "beachball change",
"clean": "just-scripts clean",
"lint": "just-scripts lint",
"lint:fix": "just-scripts lint:fix",
"test": "just-scripts test",
"watch": "tsc -w"
},
"bin": {
"override": "./bin.js"
"react-native-platform-override": "./bin.js"
},
"dependencies": {
"chalk": "^3.0.0",
Expand Down Expand Up @@ -50,5 +50,10 @@
},
"engines": {
"node": ">=10"
},
"beachball": {
"disallowedChangeTypes": [
"major"
]
}
}
File renamed without changes.
Expand Up @@ -23,10 +23,13 @@ import {
} from './FileRepository';
import OverrideUpgrader, {UpgradeResult} from './OverrideUpgrader';

import {getInstalledRNVersion, getNpmPackage} from './PackageUtils';

import CrossProcessLock from './CrossProcessLock';
import GitReactFileRepository from './GitReactFileRepository';
import OverrideFileRepositoryImpl from './OverrideFileRepositoryImpl';
import {getInstalledRNVersion} from './ReactVersion';

const npmPackage = getNpmPackage();

doMain(() => {
return new Promise((resolve, _) => {
Expand Down Expand Up @@ -97,17 +100,15 @@ doMain(() => {
}),
cmdArgv => manualUpgrade(cmdArgv.manifest, cmdArgv.version),
)
.epilogue(
'This tool allows managing JavaScript overrides for React Native Windows',
)
.epilogue(npmPackage.description)
.option('color', {hidden: true})
.demandCommand()
.recommendCommands()
.strict()
.showHelpOnFail(false)
.wrap(yargs.terminalWidth())
.version(false)
.scriptName('override')
.scriptName(npmPackage.name)
.onFinishCommand(resolve).argv;
});
});
Expand Down Expand Up @@ -329,32 +330,38 @@ function printValidationErrors(errors: Array<ValidationError>) {
});

if (filesMissing.length > 0) {
const errorMessage =
"Found override files that aren't listed in the manifest. Overrides can be added to the manifest by using 'yarn override add <override>' (where override is package relative):";
const errorMessage = `Found override files that aren't listed in the manifest. Overrides can be added to the manifest by using 'npx ${
npmPackage.name
} add <override>':`;
console.error(chalk.red(errorMessage));
filesMissing.forEach(err => console.error(` - ${err.file}`));
console.error();
}

if (overridesMissing.length > 0) {
const errorMessage =
"Found overrides in the manifest that don't exist on disk. Remove existing overrides using 'yarn override remove <override>' (where override is package relative):";
const errorMessage = `Found overrides in the manifest that don't exist on disk. Remove existing overrides using 'npx ${
npmPackage.name
} remove <override>':`;
console.error(chalk.red(errorMessage));
overridesMissing.forEach(err => console.error(` - ${err.file}`));
console.error();
}

if (baseFilesNotFound.length > 0) {
const errorMessage =
"Found overrides whose original files do not exist. Remove existing overrides using 'yarn override remove <override>' (where override is package relative):";
const errorMessage = `Found overrides whose original files do not exist. Remove existing overrides using 'npx ${
npmPackage.name
} remove <override>':`;
console.error(chalk.red(errorMessage));
baseFilesNotFound.forEach(err => console.error(` - ${err.file}`));
console.error();
}

if (outOfDateFiles.length > 0) {
const errorMessage =
"Found overrides whose original files have changed. Upgrade overrides using 'yarn override auto-upgrade <manifest>' and 'yarn override manual-upgrade <manifest>' (where manifest is package relative):";
const errorMessage = `Found overrides whose original files have changed. Upgrade overrides using 'npx ${
npmPackage.name
} auto-upgrade <manifest>' and 'npx ${
npmPackage.name
} manual-upgrade <manifest>':`;
console.error(chalk.red(errorMessage));
outOfDateFiles.forEach(err => console.error(` - ${err.file}`));
console.error();
Expand Down Expand Up @@ -401,7 +408,7 @@ async function readManifestUsingRepos(
throw new Error('Could not parse manifest. Is it valid?');
}

const rnVersion = version || (await getInstalledRNVersion(file));
const rnVersion = version || (await getInstalledRNVersion());
const reactRepo = bindVersion(versionedReactRepo, rnVersion);

return new Manifest(data, ovrRepo, reactRepo);
Expand Down Expand Up @@ -431,7 +438,7 @@ async function spinnerGuard<T>(
* accessing the same local Git repo at the same time.
*/
async function doMain(fn: () => Promise<void>): Promise<void> {
const lock = new CrossProcessLock('react-native-windows-override-cli-lock');
const lock = new CrossProcessLock(`${npmPackage.name}-cli-lock`);

if (!(await lock.tryLock())) {
const spinner = ora(
Expand Down
Expand Up @@ -8,14 +8,6 @@
import * as fs from 'fs';
import * as path from 'path';

/**
* Try to find the path to React Native's package.json
*/
export async function findReactPackage(targetPath: string): Promise<string> {
const relativeRnPackage = 'node_modules\\react-native\\package.json';
return findFileAbove(targetPath, relativeRnPackage);
}

/**
* Search for a manifest above an override file and return its path
*/
Expand Down
Expand Up @@ -12,9 +12,10 @@ import * as simplegit from 'simple-git/promise';

import ActionQueue from './ActionQueue';
import {VersionedReactFileRepository} from './FileRepository';
import {getNpmPackage} from './PackageUtils';

const REACT_NATIVE_GITHUB_URL = 'https://github.com/facebook/react-native.git';
const DEFAULT_DIR = path.join(os.tmpdir(), 'react-native-windows-override-git');
const DEFAULT_DIR = path.join(os.tmpdir(), getNpmPackage().name, 'git');

/**
* Retrives React Native files using the React Native Github repo. Switching
Expand Down
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions packages/react-native-platform-override/src/PackageUtils.ts
@@ -0,0 +1,35 @@
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* @format
*/

import * as path from 'path';

/**
* Try to find the currently installed React Native version by searching for and
* reading it's package.json.
*/
export async function getInstalledRNVersion(): Promise<string> {
const rnPackage = require('react-native/package.json');
const version = rnPackage.version;

if (typeof version !== 'string') {
throw new Error('Unexpected formt of React Native package.json');
}

return version;
}

/**
* Return an object representing the package.json of this package
*/
export function getNpmPackage(): any {
const npmPackageDir = path.join(
path.dirname(require.main.filename),
'package.json',
);

return require(npmPackageDir);
}
Expand Up @@ -16,7 +16,7 @@ import Manifest from '../Manifest';
import OverrideFileRepositoryImpl from '../OverrideFileRepositoryImpl';

import {diff_match_patch} from 'diff-match-patch';
import {getInstalledRNVersion} from '../ReactVersion';
import {getInstalledRNVersion} from '../PackageUtils';

const WIN_PLATFORM_EXT = /\.win32|\.windows|\.windesktop/;
const WHITESPACE_PATTERN = /\s/g;
Expand All @@ -30,7 +30,7 @@ const WHITESPACE_PATTERN = /\s/g;
const spinner = ora();
spinner.start('Creating manifest');

const version = await getInstalledRNVersion(ovrPath);
const version = await getInstalledRNVersion();
const [overrides, reactSources] = await getFileRepos(ovrPath, version);
const manifest: ManifestData.Manifest = {overrides: []};
const overrideFiles = await overrides.listFiles();
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/react-native-win32/package.json
Expand Up @@ -18,7 +18,7 @@
"run-win32-devmain": "rex-win32 --bundle RNTester --component RNTesterApp --basePath ./dist/win32/dev --useDevMain",
"run-win32": "rex-win32 --bundle RNTester --component RNTesterApp --basePath ./dist/win32/dev",
"start": "react-native start",
"validate-overrides": "override validate ./src/overrides.json",
"validate-overrides": "react-native-platform-override validate ./src/overrides.json",
"watch": "tsc -w"
},
"dependencies": {
Expand Down Expand Up @@ -54,7 +54,7 @@
"jscodeshift": "^0.6.2",
"just-scripts": "^0.36.1",
"react": "16.11.0",
"react-native-windows-override-tools": "^0.0.1",
"react-native-platform-override": "^0.0.1",
"react-native": "0.62.2",
"rimraf": "^3.0.0",
"typescript": "^3.8.3"
Expand Down
8 changes: 7 additions & 1 deletion vnext/.gitignore
Expand Up @@ -55,9 +55,15 @@ node_modules
/interface.*
/typings-index.*

# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Visual Studio
.vs/
.vscode/
Generated Files/
/obj/
/AppPackages/
Expand Down
4 changes: 2 additions & 2 deletions vnext/package.json
Expand Up @@ -20,7 +20,7 @@
"lint": "just-scripts lint",
"start": "react-native start",
"watch": "tsc -w",
"validate-overrides": "override validate ./src/overrides.json ./ReactCopies/overrides.json ./DeforkingPatches/overrides.json"
"validate-overrides": "react-native-platform-override validate ./src/overrides.json ./ReactCopies/overrides.json ./DeforkingPatches/overrides.json"
},
"dependencies": {
"@babel/runtime": "^7.8.4",
Expand Down Expand Up @@ -54,7 +54,7 @@
"prettier": "1.17.0",
"react": "16.11.0",
"react-native-windows-codegen": "0.0.5",
"react-native-windows-override-tools": "^0.0.1",
"react-native-platform-override": "^0.0.1",
"react-native": "0.62.2",
"typescript": "^3.8.3"
},
Expand Down

0 comments on commit 85b01cb

Please sign in to comment.