Skip to content

Commit

Permalink
chore: add types to import functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh3112 committed Jun 4, 2019
1 parent 27c6198 commit 8b88980
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/generators/add-generator.ts
Expand Up @@ -9,7 +9,6 @@ import {
} from "./utils/add/questions";

import {
replaceAt,
traverseAndGetProperties,
webpackDevServerSchema,
webpackSchema
Expand Down Expand Up @@ -112,7 +111,7 @@ export default class AddGenerator extends Generator {
.then((mergeFileAnswer: {
mergeFile: string,
mergeConfigName: string
}) => {
}):void => {
const resolvedPath = resolve(process.cwd(), mergeFileAnswer.mergeFile);
// eslint-disable-next-line
this.configuration.config[action] = [mergeFileAnswer.mergeConfigName, resolvedPath];
Expand Down
6 changes: 3 additions & 3 deletions packages/generators/utils/add/questions/index.ts
Expand Up @@ -16,7 +16,7 @@ import { Question } from "inquirer";
* @param {string} action action for which question has to be prompted
* @returns {Question} Question for given action
*/
export const manualOrListInput: (action: string) => Question = (action: string) => {
export const manualOrListInput = (action: string): Question => {
const actionQuestion = `What do you want to add to ${action}?`;
return Input("actionAnswer", actionQuestion);
};
Expand All @@ -42,9 +42,9 @@ export const topScopeQuestion: Question = Input(
"What do you want to add to topScope?",
);

const mergeFileQuestionsFunction = () => {
const mergeFileQuestionsFunction = (): Question[] => {
const mergePathQuestion = "What is the location of webpack configuration with which you want to merge current configuration?";
const mergePathValidator = (path: string) => {
const mergePathValidator = (path: string): boolean|string => {
const resolvedPath = resolve(process.cwd(), path);
if (existsSync(resolvedPath)) {
if (/\.js$/.test(path)) {
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/ast-utils.ts
Expand Up @@ -7,7 +7,7 @@ function isImportPresent (j: JSCodeshift, ast: Node, path: string): boolean {
throw new Error(`path parameter should be string, recieved ${typeof path}`);
}
let isPresent = false;
ast.find(j.CallExpression).forEach(callExp => {
ast.find(j.CallExpression).forEach((callExp: Node): void => {
if ((callExp.value as Node).callee.name === 'require' && (callExp.value as Node).arguments[0].value === path) {
isPresent = true;
}
Expand Down Expand Up @@ -648,11 +648,11 @@ function parseMerge(j: JSCodeshift, ast: Node, value: string[], action: string):
return false; // TODO: debug later
}

function addMergeImports(configIdentifier: string, configPath: string) {
function addMergeImports(configIdentifier: string, configPath: string): void {
if (typeof configIdentifier !== "string" || typeof configPath !== "string") {
throw new Error(`Both parameters should be string. Recieved ${configIdentifier}, ${configPath}`)
throw new Error(`Both parameters should be string. recieved ${typeof configIdentifier}, ${typeof configPath}`)
}
ast.find(j.Program).forEach(p => {
ast.find(j.Program).forEach((p: Node): void => {
if (!isImportPresent(j, ast, 'webpack-merge')) {
(p.value as Node).body.splice(-1, 0, `const merge = require('webpack-merge')`);
}
Expand Down

0 comments on commit 8b88980

Please sign in to comment.