diff --git a/packages/utils/src/console/formatMs.ts b/packages/utils/src/console/formatMs.ts index 81e180f13f..e872012b90 100644 --- a/packages/utils/src/console/formatMs.ts +++ b/packages/utils/src/console/formatMs.ts @@ -2,6 +2,5 @@ * Format millisecond */ export const formatMs = (ms: number): string => { - if (ms < 1000) return `${ms}ms` - return `${(ms / 1000).toFixed(2)}s` + return (ms < 1000) ? `${ms}ms` : `${(ms / 1000).toFixed(2)}s`; } diff --git a/packages/utils/src/console/withSpinner.ts b/packages/utils/src/console/withSpinner.ts index fee698e911..f6fd267c57 100644 --- a/packages/utils/src/console/withSpinner.ts +++ b/packages/utils/src/console/withSpinner.ts @@ -7,18 +7,20 @@ export const withSpinner = (msg: string) => async (target: (spinner?: Ora) => Promise): Promise => { if (process.env.DEBUG) { - return target() + return target(); } - const start = Date.now() - const spinner = ora() + const start = Date.now(); + const spinner = ora(); try { - spinner.start(msg) - const result = await target(spinner) - spinner.succeed(`${msg} - done in ${formatMs(Date.now() - start)}`) - return result + spinner.start(msg); + const result = await target(spinner); + const after = Date.now(); + spinner.succeed(`${msg} - done in ${formatMs(after - start)}`); + return result; } catch (e) { - spinner.fail(`${msg} - failed in ${formatMs(Date.now() - start)}`) + const after = Date.now(); + spinner.fail(`${msg} - failed in ${formatMs(after - start)}`); throw e } } diff --git a/packages/utils/src/module/isChildPath.ts b/packages/utils/src/module/isChildPath.ts index a1c57a0f91..ef39e7a516 100644 --- a/packages/utils/src/module/isChildPath.ts +++ b/packages/utils/src/module/isChildPath.ts @@ -5,12 +5,12 @@ import path from 'upath' * they are the same path */ export const isChildPath = (child: string, parent: string): boolean => { - const childPath = path.normalize(child) - const parentPath = path.normalize(parent) + const childPath = path.normalize(child); + const parentPath = path.normalize(parent); // path.win32.isAbsolute could check both win32 and posix absolute path correctly if (!path.win32.isAbsolute(childPath) || !path.win32.isAbsolute(parentPath)) { - return false + return false; } - const relativePath = path.relative(parentPath, childPath) - return relativePath === '' || !relativePath.startsWith('..') + const relativePath = path.relative(parentPath, childPath); + return relativePath === '' || !relativePath.startsWith('..'); } diff --git a/packages/utils/src/ssr/renderHead.ts b/packages/utils/src/ssr/renderHead.ts index 5bebeb46ca..7331c1358d 100644 --- a/packages/utils/src/ssr/renderHead.ts +++ b/packages/utils/src/ssr/renderHead.ts @@ -9,9 +9,11 @@ export const renderHead = ([ attrs, innerHTML = '', ]: HeadConfig): string => { - const openTag = `<${tag}${renderHeadAttrs(attrs)}>` - if (tag === 'link' || tag === 'meta' || tag === 'base') { - return openTag + const openTag = `<${tag}${renderHeadAttrs(attrs)}>`; + const tagsWithNoInnerHtml = ['link', 'meta', 'base']; + + if (tagsWithNoInnerHtml.includes(tag)) { + return openTag; } - return `${openTag}${innerHTML}` + return `${openTag}${innerHTML}`; }