Skip to content

Commit

Permalink
feat(utils): add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Jul 14, 2018
1 parent 95796c3 commit 47702cb
Show file tree
Hide file tree
Showing 60 changed files with 1,574 additions and 1,428 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"@commitlint/prompt-cli": "^7.0.0",
"@commitlint/travis-cli": "^7.0.0",
"@types/node": "^10.5.1",
"@types/jest": "^23.1.1",
"bundlesize": "^0.17.0",
"codecov": "^3.0.2",
"commitizen": "^2.10.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/generators/add-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as autoComplete from "inquirer-autocomplete-prompt";
import * as path from "path";
import webpackDevServerSchema from "webpack-dev-server/lib/optionsSchema.json";

import * as npmExists from "@webpack-cli/utils/npm-exists";
import npmExists from "@webpack-cli/utils/npm-exists";
import { getPackageManager } from "@webpack-cli/utils/package-manager";
import * as PROP_TYPES from "@webpack-cli/utils/prop-types";
import PROP_TYPES from "@webpack-cli/utils/prop-types";
import {
AutoComplete,
Confirm,
Expand Down
122 changes: 0 additions & 122 deletions packages/generators/remove-generator.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/generators/remove-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import Generator = require("yeoman-generator");

import * as PROP_TYPES from "@webpack-cli/utils/prop-types";
import PROP_TYPES from "@webpack-cli/utils/prop-types";
import { List } from "@webpack-cli/webpack-scaffold";
import { IWebpackOptions } from "./types";

Expand Down
8 changes: 4 additions & 4 deletions packages/init/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as defaultGenerator from "@webpack-cli/generators/init-generator";
import * as modifyConfigHelper from "@webpack-cli/utils/modify-config-helper";
import * as npmPackagesExists from "@webpack-cli/utils/npm-packages-exists";
import defaultGenerator from "@webpack-cli/generators/init-generator";
import modifyConfigHelper from "@webpack-cli/utils/modify-config-helper";
import npmPackagesExists from "@webpack-cli/utils/npm-packages-exists";

/**
*
Expand All @@ -13,7 +13,7 @@ import * as npmPackagesExists from "@webpack-cli/utils/npm-packages-exists";
* followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator
*/

export default function initializeInquirer(...args: string[]): Function {
export default function initializeInquirer(...args: string[]): Function | void {
const packages: string[] = args.slice(3);

if (packages.length === 0) {
Expand Down
9 changes: 5 additions & 4 deletions packages/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import * as j from "jscodeshift";
import pEachSeries = require("p-each-series");
import * as path from "path";

import * as propTypes from "@webpack-cli/utils/prop-types";
import * as astTransform from "@webpack-cli/utils/recursive-parser";
import * as runPrettier from "@webpack-cli/utils/run-prettier";
import propTypes from "@webpack-cli/utils/prop-types";
import astTransform from "@webpack-cli/utils/recursive-parser";
import runPrettier from "@webpack-cli/utils/run-prettier";

import { INode } from "@webpack-cli/utils/types/NodePath";
import { IError } from "./types";
import { IConfiguration, IWebpackProperties } from "./types/Transform";

Expand Down Expand Up @@ -53,7 +54,7 @@ export default function runTransform(webpackProperties: IWebpackProperties, acti
);
const transformAction: string | null = action || null;

return pEachSeries(transformations, (f: string): Promise<string[]> => {
return pEachSeries(transformations, (f: string): boolean | INode => {
return astTransform(j, ast, config.webpackOptions[f], transformAction, f);
})
.then((_?: any) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/bannerPlugin/bannerPlugin.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "bannerPlugin", "bannerPlugin-0");
defineTest(__dirname, "bannerPlugin", "bannerPlugin-1");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "extractTextPlugin");
2 changes: 1 addition & 1 deletion packages/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pLazy = require("p-lazy");
import * as path from "path";
import { validate, WebpackOptionsValidationError } from "webpack";

import * as runPrettier from "@webpack-cli/utils/run-prettier";
import runPrettier from "@webpack-cli/utils/run-prettier";

import { transformations } from "./migrate";
import { IJSCodeshift, INode } from "./types/NodePath";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "loaderOptionsPlugin", "loaderOptionsPlugin-0");
defineTest(__dirname, "loaderOptionsPlugin", "loaderOptionsPlugin-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ILoaderOptions {
*
*/

export default function(j: IJSCodeshift, ast: INode): void {
export default function(j: IJSCodeshift, ast: INode): INode {
const loaderOptions: ILoaderOptions = {};

// If there is debug: true, set debug: true in the plugin
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/loaders/loaders.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "loaders", "loaders-0");
defineTest(__dirname, "loaders", "loaders-1");
Expand Down
8 changes: 4 additions & 4 deletions packages/migrate/loaders/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default function(j: IJSCodeshift, ast: INode): INode {
* @returns {Node} ast - jscodeshift ast
*/

const prepostLoaders = (_?: void): void =>
const prepostLoaders = (_?: void): INode =>
ast
.find(j.ObjectExpression)
.filter((p: INode): boolean => utils.findObjWithOneOfKeys(p, ["preLoaders", "postLoaders"]))
Expand All @@ -221,7 +221,7 @@ export default function(j: IJSCodeshift, ast: INode): INode {
* @returns {Node} ast - jscodeshift ast
*/

const loadersToRules = (_?: void): void =>
const loadersToRules = (_?: void): INode =>
ast
.find(j.Identifier)
.filter(checkForLoader)
Expand Down Expand Up @@ -308,7 +308,7 @@ export default function(j: IJSCodeshift, ast: INode): INode {
* @returns {Node} ast - jscodeshift ast
*/

const addLoaderSuffix = (_?: void): void =>
const addLoaderSuffix = (_?: void): INode =>
ast.find(j.ObjectExpression).forEach((path: INode): void => {
path.value.properties.forEach((prop: INode): void => {
if (
Expand Down Expand Up @@ -360,7 +360,7 @@ export default function(j: IJSCodeshift, ast: INode): INode {
* @returns {Node} ast - jscodeshift ast
*/

const moveOptionsToUse = (_?: void): void =>
const moveOptionsToUse = (_?: void): INode =>
ast
.find(j.ObjectExpression)
.filter((p: INode): boolean => utils.findObjWithOneOfKeys(p, ["use"]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(
__dirname,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "namedModulesPlugin", "namedModulesPlugin-0");
defineTest(__dirname, "namedModulesPlugin", "namedModulesPlugin-1");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-0");
defineTest(__dirname, "noEmitOnErrorsPlugin", "noEmitOnErrorsPlugin-1");
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/outputPath/outputPath.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "outputPath", "outputPath-0");
defineTest(__dirname, "outputPath", "outputPath-1");
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/outputPath/outputPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function(j: IJSCodeshift, ast: INode): INode | void {
.replaceWith((p: INode): INode => replaceWithPath(j, p, finalPathName));

if (!isPathPresent) {
const pathRequire: INode[] = utils.getRequire(j, "path", "path");
const pathRequire: INode = utils.getRequire(j, "path", "path");
return ast
.find(j.Program)
.replaceWith((p: INode): INode =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "removeDeprecatedPlugins", "removeDeprecatedPlugins-0");
defineTest(__dirname, "removeDeprecatedPlugins", "removeDeprecatedPlugins-1");
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/removeJsonLoader/removeJsonLoader.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "removeJsonLoader", "removeJsonLoader-0");
defineTest(__dirname, "removeJsonLoader", "removeJsonLoader-1");
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/resolve/resolve.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";

const defineTest = require("@webpack-cli/utils/defineTest");
const defineTest = require("@webpack-cli/utils/defineTest").default;

defineTest(__dirname, "resolve");
2 changes: 1 addition & 1 deletion packages/migrate/resolve/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IJSCodeshift, INode } from "../types/NodePath";
* @returns {Node} ast - jscodeshift ast
*/

export default function transformer(j: IJSCodeshift, ast: INode): INode[] | void {
export default function transformer(j: IJSCodeshift, ast: INode): INode {

const getRootVal = (p: INode): INode => {
return p.node.value.properties.filter((prop: INode): boolean => prop.key.name === "root")[0];
Expand Down
Loading

0 comments on commit 47702cb

Please sign in to comment.