Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#683] Convert commands/packageManager.ts to TS #692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import commands from './commands';
import init from './commands/init/initCompat';
import assertRequiredOptions from './tools/assertRequiredOptions';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import {setProjectDir} from './tools/packageManager';
import pkgJson from '../package.json';
import loadConfig from './tools/config';
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import bundle from './bundle/bundle';
// @ts-ignore - JS file
import ramBundle from './bundle/ramBundle';
// @ts-ignore - JS file
import link from './link/link'; // eslint-disable-line
import link from './link/link'; // eslint-disable-line import/namespace, import/default
// @ts-ignore - JS file
import unlink from './link/unlink'; // eslint-disable-line
import unlink from './link/unlink'; // eslint-disable-line import/namespace, import/default
// @ts-ignore - JS file
import install from './install/install'; // eslint-disable-line
import install from './install/install'; // eslint-disable-line import/namespace, import/default
// @ts-ignore - JS file
import uninstall from './install/uninstall'; // eslint-disable-line
import uninstall from './install/uninstall'; // eslint-disable-line import/namespace, import/default
import upgrade from './upgrade/upgrade';
import info from './info/info';
// @ts-ignore - JS file
import config from './config/config'; // eslint-disable-line
import config from './config/config'; // eslint-disable-line import/namespace, import/default
// @ts-ignore - JS file
import init from './init';
// @ts-ignore - JS file
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/__tests__/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
jest.mock('execa', () => jest.fn());
import execa from 'execa';
import path from 'path';
// $FlowFixMe - converted to TS
import * as PackageManger from '../../../tools/packageManager';
import {
installTemplatePackage,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
executePostInitScript,
} from './template';
import {changePlaceholderInTemplate} from './editTemplate';
// $FlowFixMe - converted to TS
import * as PackageManager from '../../tools/packageManager';
// $FlowFixMe - converted to TS
import installPods from '../../tools/installPods';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import execa from 'execa';
import path from 'path';
// $FlowFixMe - converted to TS
import * as PackageManager from '../../tools/packageManager';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/install/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import type {ConfigT} from 'types';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import * as PackageManager from '../../tools/packageManager';
import link from '../link/link';
import loadConfig from '../../tools/config';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/install/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import type {ConfigT} from 'types';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import * as PackageManager from '../../tools/packageManager';
import unlink from '../link/unlink';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import snapshotDiff from 'snapshot-diff';
import stripAnsi from 'strip-ansi';
import upgrade from '../upgrade';
import {fetch, logger} from '@react-native-community/cli-tools';
import loadConfig from '../../../tools/config'; // eslint-disable-line
import loadConfig from '../../../tools/config'; // eslint-disable-line import/namespace, import/default
import merge from '../../../tools/merge';

jest.mock('https');
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/commands/upgrade/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import semver from 'semver';
import execa from 'execa';
import {Config} from '@react-native-community/cli-types';
import {logger, CLIError, fetch} from '@react-native-community/cli-tools';
// @ts-ignore JS file
import * as PackageManager from '../../tools/packageManager'; // eslint-disable-line import/namespace
// @ts-ignore JS file
import * as PackageManager from '../../tools/packageManager';
import installPods from '../../tools/installPods';

// https://react-native-community.github.io/upgrade-helper/?from=0.59.10&to=0.60.0-rc.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @flow
jest.mock('execa', () => jest.fn());
import execa from 'execa';
// $FlowFixMe - converted to TS
import * as yarn from '../yarn';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../packageManager';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/config/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ test('should not add default React Native config when one present', () => {
});

// @todo: figure out why this test is so flaky
// eslint-disable-next-line jest/no-disabled-tests
test.skip('should skip packages that have invalid configuration', () => {
writeFiles(DIR, {
'node_modules/react-native/package.json': '{}',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/generator/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import fs from 'fs';
import path from 'path';
import copyProjectTemplateAndReplace from './copyProjectTemplateAndReplace';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import * as PackageManager from '../packageManager';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// @flow
import execa from 'execa';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import {getYarnVersionIfAvailable, isProjectUsingYarn} from './yarn';

type Options = {|
preferYarn?: boolean,
silent?: boolean,
cwd?: string,
|};
type Options = {
preferYarn?: boolean;
silent?: boolean;
cwd?: string;
};

let projectDir;
let projectDir: string;

const packageManagers = {
yarn: {
Expand All @@ -29,8 +27,8 @@ const packageManagers = {

function configurePackageManager(
packageNames: Array<string>,
options?: Options,
action: 'install' | 'installDev' | 'installAll' | 'uninstall',
options?: Options,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Esemesek you ok with that? Makes sense imho

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. It makes a lot of sense.

) {
const pm = shouldUseYarn(options) ? 'yarn' : 'npm';
const [executable, ...flags] = packageManagers[pm][action];
Expand Down Expand Up @@ -63,17 +61,17 @@ export function setProjectDir(dir: string) {
}

export function install(packageNames: Array<string>, options?: Options) {
return configurePackageManager(packageNames, options, 'install');
return configurePackageManager(packageNames, 'install', options);
}

export function installDev(packageNames: Array<string>, options?: Options) {
return configurePackageManager(packageNames, options, 'installDev');
return configurePackageManager(packageNames, 'installDev', options);
}

export function uninstall(packageNames: Array<string>, options?: Options) {
return configurePackageManager(packageNames, options, 'uninstall');
return configurePackageManager(packageNames, 'uninstall', options);
}

export function installAll(options?: Options) {
return configurePackageManager([], options, 'installAll');
return configurePackageManager([], 'installAll', options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ project(':test').projectDir = new File(rootProject.projectDir, '../node_modules/
// Simulate Windows environment on POSIX filesystem
// TODO: scope this test to Windows-only once we setup CI on Windows
// as changing path to be windows-specific breaks global path mock
// eslint-disable-next-line jest/no-disabled-tests
it.skip('includes project with correct path on Windows', () => {
jest.resetModules();
jest.doMock('path', () => {
Expand Down