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 2 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
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
1 change: 1 addition & 0 deletions packages/cli/src/tools/__tests__/packageManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import execa from 'execa';
// $FlowFixMe - converted to TS
import * as yarn from '../yarn';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import * as PackageManager from '../packageManager';

const PACKAGES = ['react', 'react-native'];
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,15 @@
// @flow
thymikee marked this conversation as resolved.
Show resolved Hide resolved
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 +28,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 +62,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);
}