Skip to content

Commit

Permalink
chore: supplementary type (umijs#3193)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni authored and ycjcl868 committed Sep 12, 2019
1 parent 3af0fac commit 57ebd18
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/umi-utils/src/chunkName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import winPath from './winPath';

function stripFirstSlash(path: string) {
function stripFirstSlash(path: string): string {
if (path.charAt(0) === '/') {
return path.slice(1);
} else {
Expand All @@ -13,7 +13,7 @@ function stripFirstSlash(path: string) {
* @param cwd
* @param path
*/
export default function chunkName(cwd: string, path: string) {
export default function chunkName(cwd: string, path: string): string {
return stripFirstSlash(winPath(path).replace(winPath(cwd), ''))
.replace(/\//g, '__')
.replace(/^src__/, '')
Expand Down
4 changes: 2 additions & 2 deletions packages/umi-utils/src/compatDirname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import winPath from './winPath';
* @param cwd process cwd
* @param fallback
*/
export default function(path: string, cwd: string, fallback?: any) {
export default function(path: string, cwd: string, fallback?: any): any {
const pkg = findPkg(path, cwd);
if (pkg) return pkg;

Expand All @@ -25,7 +25,7 @@ export default function(path: string, cwd: string, fallback?: any) {
* @param path module name
* @param cwd
*/
function findPkg(path: string, cwd: string) {
function findPkg(path: string, cwd: string): string {
const pkgPath = join(cwd, 'package.json');
const library = path.split('/')[0];
if (existsSync(pkgPath)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-utils/src/deprecate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const hits = new Set<string>();
* @param methodName
* @param args
*/
export default function deprecate(methodName: string, ...args) {
export default function deprecate(methodName: string, ...args): void {
if (hits[methodName]) return;
hits[methodName] = true;
const stream = process.stderr;
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-utils/src/endWithSlash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* Make up the ending slash path ( /abc => /abc/ )
* @param path string
*/
export default function endWithSlash(path: string) {
export default function endWithSlash(path: string): string {
return path.slice(-1) !== '/' ? `${path}/` : path;
}
2 changes: 1 addition & 1 deletion packages/umi-utils/src/findCSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CSS_EXTNAMES = ['.css', '.less', '.scss', '.sass'];
* @param {*} baseDir
* @param {*} fileNameWithoutExtname
*/
export default function(baseDir: string, fileNameWithoutExtname: string) {
export default function(baseDir: string, fileNameWithoutExtname: string): string {
let i = 0;
while (i < CSS_EXTNAMES.length) {
const extname = CSS_EXTNAMES[i];
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-utils/src/findJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const JS_EXTNAMES = ['.js', '.jsx', '.ts', '.tsx'];
* @param baseDir base path
* @param fileNameWithoutExtname file name
*/
export default function(baseDir: string, fileNameWithoutExtname: string) {
export default function(baseDir: string, fileNameWithoutExtname: string): string {
let i = 0;
while (i < JS_EXTNAMES.length) {
const extname = JS_EXTNAMES[i];
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-utils/src/isUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import isUrl from 'is-url';
* Check whether a string is a URL.
* @param path
*/
export default function(path: string) {
export default function(path: string): boolean {
return isUrl(path);
}
19 changes: 18 additions & 1 deletion packages/umi-utils/src/prettierFile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import * as prettier from 'prettier';

type PrettierFormatParser =
| 'babel'
| 'babel-flow'
| 'flow'
| 'typescript'
| 'css'
| 'scss'
| 'less'
| 'json'
| 'json5'
| 'json-stringify'
| 'graphql'
| 'markdown'
| 'mdx'
| 'html'
| 'lwc'
| 'yaml';
/**
* prettier code
* @param fileContent file flow string
* @param parser default typescript
*/
export default function(fileContent: string, parser: string = 'typescript') {
export default function(fileContent: string, parser: PrettierFormatParser = 'typescript'): string {
try {
return prettier.format(fileContent, {
parser,
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-utils/src/winEOL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isWindows = typeof process !== 'undefined' && process.platform === 'win32'
* Convert Windows crlf to lf (\r\n to \n)
* @param content
*/
export default (content: any) => {
export default (content: string | undefined) => {
if (typeof content !== 'string') {
return content;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/umi-utils/src/winPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import slash from 'slash2';
* Convert Windows backslash paths to slash paths
* @param path
*/
export default function(path: string) {
export default function(path: string): string {
return slash(path);
}

0 comments on commit 57ebd18

Please sign in to comment.