Skip to content

Commit

Permalink
style: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Sep 20, 2023
1 parent 55cba73 commit c3671c8
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": true,
"semi": false
}
}
2 changes: 1 addition & 1 deletion example/foo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default class Foo {
render() {
return <div className="hehe">hello there!!!</div>
}
}
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export default ({

const extensions: string[] = Object.keys(loaders)
const INCLUDE_REGEXP = new RegExp(
`\\.(${extensions.map((ext) => ext.slice(1)).join('|')})$`
`\\.(${extensions.map((ext) => ext.slice(1)).join('|')})$`,
)
const EXCLUDE_REGEXP = /node_modules/

const filter = createFilter(
include || INCLUDE_REGEXP,
exclude || EXCLUDE_REGEXP
exclude || EXCLUDE_REGEXP,
)

const resolveFile = (resolved: string, index: boolean = false) => {
Expand Down Expand Up @@ -128,7 +128,7 @@ export default ({
if (importer && id[0] === '.') {
const resolved = resolve(
importer ? dirname(importer) : process.cwd(),
id
id,
)

let file = resolveFile(resolved)
Expand Down
4 changes: 2 additions & 2 deletions src/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { transform, TransformOptions, Format } from 'esbuild'
import { warn } from './warn'

const getEsbuildFormat = (
rollupFormat: InternalModuleFormat
rollupFormat: InternalModuleFormat,
): Format | undefined => {
if (rollupFormat === 'es') {
return 'esm'
Expand All @@ -20,7 +20,7 @@ export type Options = Omit<TransformOptions, 'sourcemap'> & {
export const getRenderChunk = ({
sourceMap = true,
...options
}: Options): Plugin["renderChunk"] =>
}: Options): Plugin['renderChunk'] =>
async function (code, _, rollupOptions) {
if (
options.minify ||
Expand Down
4 changes: 2 additions & 2 deletions src/optimizer/optmize-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type OptimizeDepsResult = {
const slash = (p: string) => p.replace(/\\/g, '/')

export const optimizeDeps = async (
options: OptimizeDepsOptions
options: OptimizeDepsOptions,
): Promise<OptimizeDepsResult> => {
const cacheDir = path.join(options.cwd, 'node_modules/.optimize_deps')
await fs.promises.mkdir(cacheDir, { recursive: true })
Expand Down Expand Up @@ -82,7 +82,7 @@ export const optimizeDeps = async (
: `module.exports = require('${slash(absolute)}')`,
resolveDir,
}
}
},
)
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const jsxValueMap: Record<any, Pick<TransformOptions, 'jsx' | 'jsxDev'>> = {

export const getOptions = async (
cwd: string,
tsconfig?: string
tsconfig?: string,
): Promise<
Pick<
TransformOptions,
Expand Down
24 changes: 12 additions & 12 deletions src/warn.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { PluginContext } from 'rollup'
import {
formatMessages,
Message,
} from 'esbuild'
import { formatMessages, Message } from 'esbuild'

export const warn = async (pluginContext: PluginContext, messages: Message[]) => {
if (messages.length > 0) {
const warnings = await formatMessages(messages, {
kind: 'warning',
color: true,
})
warnings.forEach((warning) => pluginContext.warn(warning))
}
export const warn = async (
pluginContext: PluginContext,
messages: Message[],
) => {
if (messages.length > 0) {
const warnings = await formatMessages(messages, {
kind: 'warning',
color: true,
})
warnings.forEach((warning) => pluginContext.warn(warning))
}
}
18 changes: 10 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { vi, expect, beforeEach, describe, test } from 'vitest'
const mockEsbuildTransform = vi.fn()

vi.mock('esbuild', async (): Promise<typeof import('esbuild')> => {
const originalModule = await vi.importActual<typeof import('esbuild')>(
'esbuild'
)
const originalModule =
await vi.importActual<typeof import('esbuild')>('esbuild')
return {
...originalModule,
transform: (...args) => {
Expand All @@ -30,7 +29,10 @@ const realFs = (folderName: string, files: Record<string, string>) => {
}

const getTestName = () =>
((expect.getState().currentTestName as string) || '').split(' > ').slice(1).join(' ')
((expect.getState().currentTestName as string) || '')
.split(' > ')
.slice(1)
.join(' ')

const build = async ({
input = './fixture/index.js',
Expand All @@ -49,7 +51,7 @@ const build = async ({
} = {}) => {
const build = await rollup({
input: [...(Array.isArray(input) ? input : [input])].map((v) =>
path.resolve(dir, v)
path.resolve(dir, v),
),
plugins: rollupPlugins,
external,
Expand Down Expand Up @@ -508,7 +510,7 @@ describe('esbuild plugin', () => {
expect.any(String),
expect.objectContaining({
sourcemap: true,
})
}),
)

// sourceMap: false
Expand All @@ -524,7 +526,7 @@ describe('esbuild plugin', () => {
expect.any(String),
expect.objectContaining({
sourcemap: false,
})
}),
)

// sourceMap: true
Expand All @@ -540,7 +542,7 @@ describe('esbuild plugin', () => {
expect.any(String),
expect.objectContaining({
sourcemap: true,
})
}),
)
})
})
Expand Down
14 changes: 7 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
Expand All @@ -23,7 +23,7 @@
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
Expand All @@ -46,7 +46,7 @@
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

Expand All @@ -61,7 +61,7 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src/**/*"]
}

0 comments on commit c3671c8

Please sign in to comment.