Skip to content

Commit

Permalink
style: format code, upgrade prettier to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jul 16, 2024
1 parent 5f0aa07 commit 533876c
Show file tree
Hide file tree
Showing 30 changed files with 211 additions and 208 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"fs-extra": "10.0.0",
"postcss": "8.4.12",
"postcss-simple-vars": "6.0.3",
"prettier": "2.5.1",
"prettier": "3.3.3",
"resolve": "1.20.0",
"rollup-plugin-dts": "6.1.0",
"sass": "1.62.1",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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

22 changes: 11 additions & 11 deletions src/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const logger = createLogger()
function rollupDtsFile(
inputFilePath: string,
outputFilePath: string,
tsconfigFilePath: string
tsconfigFilePath: string,
) {
let cwd = process.cwd()
let packageJsonFullPath = path.join(cwd, 'package.json')
Expand Down Expand Up @@ -59,7 +59,7 @@ function rollupDtsFile(
const imported = getApiExtractor()
if (!imported) {
throw new Error(
`@microsoft/api-extractor is not installed. Please install it first.`
`@microsoft/api-extractor is not installed. Please install it first.`,
)
}
const { ExtractorConfig, Extractor } = imported
Expand All @@ -77,15 +77,15 @@ function rollupDtsFile(

if (!extractorResult.succeeded) {
throw new Error(
`API Extractor completed with ${extractorResult.errorCount} errors and ${extractorResult.warningCount} warnings when processing ${inputFilePath}`
`API Extractor completed with ${extractorResult.errorCount} errors and ${extractorResult.warningCount} warnings when processing ${inputFilePath}`,
)
}
}

async function rollupDtsFiles(
options: NormalizedOptions,
exports: ExportDeclaration[],
format: Format
format: Format,
) {
let declarationDir = ensureTempDeclarationDir()
let outDir = options.outDir || 'dist'
Expand All @@ -94,7 +94,7 @@ async function rollupDtsFiles(

let dtsInputFilePath = path.join(
declarationDir,
'_tsup-dts-aggregation' + dtsExtension
'_tsup-dts-aggregation' + dtsExtension,
)
// @microsoft/api-extractor doesn't support `.d.mts` and `.d.cts` file as a
// entrypoint yet. So we replace the extension here as a temporary workaround.
Expand All @@ -109,29 +109,29 @@ async function rollupDtsFiles(

writeFileSync(
dtsInputFilePath,
formatAggregationExports(exports, declarationDir)
formatAggregationExports(exports, declarationDir),
)

rollupDtsFile(
dtsInputFilePath,
dtsOutputFilePath,
options.tsconfig || 'tsconfig.json'
options.tsconfig || 'tsconfig.json',
)

for (let [out, sourceFileName] of Object.entries(
options.experimentalDts!.entry
options.experimentalDts!.entry,
)) {
sourceFileName = toAbsolutePath(sourceFileName)
const outFileName = path.join(outDir, out + dtsExtension)

// Find all declarations that are exported from the current source file
const currentExports = exports.filter(
(declaration) => declaration.sourceFileName === sourceFileName
(declaration) => declaration.sourceFileName === sourceFileName,
)

writeFileSync(
outFileName,
formatDistributionExports(currentExports, outFileName, dtsOutputFilePath)
formatDistributionExports(currentExports, outFileName, dtsOutputFilePath),
)
}
}
Expand All @@ -144,7 +144,7 @@ function cleanDtsFiles(options: NormalizedOptions) {

export async function runDtsRollup(
options: NormalizedOptions,
exports?: ExportDeclaration[]
exports?: ExportDeclaration[],
) {
try {
const start = Date.now()
Expand Down
22 changes: 11 additions & 11 deletions src/cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,44 @@ export async function main(options: Options = {}) {
.option('--minify-syntax', 'Minify syntax')
.option(
'--keep-names',
'Keep original function and class names in minified code'
'Keep original function and class names in minified code',
)
.option('--target <target>', 'Bundle target, "es20XX" or "esnext"', {
default: 'es2017',
})
.option(
'--legacy-output',
'Output different formats to different folder instead of using different extensions'
'Output different formats to different folder instead of using different extensions',
)
.option('--dts [entry]', 'Generate declaration file')
.option('--dts-resolve', 'Resolve externals types used for d.ts files')
.option('--dts-only', 'Emit declaration files only')
.option(
'--experimental-dts [entry]',
'Generate declaration file (experimental)'
'Generate declaration file (experimental)',
)
.option(
'--sourcemap [inline]',
'Generate external sourcemap, or inline source: --sourcemap inline'
'Generate external sourcemap, or inline source: --sourcemap inline',
)
.option(
'--watch [path]',
'Watch mode, if path is not specified, it watches the current folder ".". Repeat "--watch" for more than one path'
'Watch mode, if path is not specified, it watches the current folder ".". Repeat "--watch" for more than one path',
)
.option('--ignore-watch <path>', 'Ignore custom paths in watch mode')
.option(
'--onSuccess <command>',
'Execute command after successful build, specially useful for watch mode'
'Execute command after successful build, specially useful for watch mode',
)
.option('--env.* <value>', 'Define compile-time env variables')
.option(
'--inject <file>',
'Replace a global variable with an import from another file'
'Replace a global variable with an import from another file',
)
.option('--define.* <value>', 'Define compile-time constants')
.option(
'--external <name>',
'Mark specific packages / package.json (dependencies and peerDependencies) as external'
'Mark specific packages / package.json (dependencies and peerDependencies) as external',
)
.option('--global-name <name>', 'Global variable name for iife format')
.option('--jsxFactory <jsxFactory>', 'Name of JSX factory function', {
Expand All @@ -77,7 +77,7 @@ export async function main(options: Options = {}) {
.option('--clean', 'Clean output directory')
.option(
'--silent',
'Suppress non-error logs (excluding "onSuccess" process output)'
'Suppress non-error logs (excluding "onSuccess" process output)',
)
.option('--pure <express>', 'Mark specific expressions as pure')
.option('--metafile', 'Emit esbuild metafile (a JSON file)')
Expand All @@ -92,12 +92,12 @@ export async function main(options: Options = {}) {
.option('--inject-style', 'Inject style tag to document head')
.option(
'--treeshake [strategy]',
'Using Rollup for treeshaking instead, "recommended" or "smallest" or "safest"'
'Using Rollup for treeshaking instead, "recommended" or "smallest" or "safest"',
)
.option('--publicDir [dir]', 'Copy public directory to output directory')
.option(
'--killSignal <signal>',
'Signal to kill child process, "SIGTERM" or "SIGKILL"'
'Signal to kill child process, "SIGTERM" or "SIGKILL"',
)
.option('--cjsInterop', 'Enable cjs interop')
.action(async (files: string[], flags) => {
Expand Down
6 changes: 3 additions & 3 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export function handleError(error: any) {
console.error(
colors.bold(
colors.red(
`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`
)
)
`Error parsing: ${error.loc.file}:${error.loc.line}:${error.loc.column}`,
),
),
)
}
if (error.frame) {
Expand Down
2 changes: 1 addition & 1 deletion src/esbuild/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const externalPlugin = ({
setup(build) {
if (skipNodeModulesBundle) {
const resolvePatterns = tsconfigPathsToRegExp(
tsconfigResolvePaths || {}
tsconfigResolvePaths || {},
)
build.onResolve({ filter: /.*/ }, (args) => {
// Resolve `paths` from tsconfig
Expand Down
12 changes: 6 additions & 6 deletions src/esbuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { OutExtensionFactory } from '../options'
const getOutputExtensionMap = (
options: NormalizedOptions,
format: Format,
pkgType: string | undefined
pkgType: string | undefined,
) => {
const outExtension: OutExtensionFactory =
options.outExtension || defaultOutExtension
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function runEsbuild(
buildDependencies: Set<string>
logger: Logger
pluginContainer: PluginContainer
}
},
) {
const pkg = await loadPkg(process.cwd())
const deps = await getProductionDeps(process.cwd())
Expand Down Expand Up @@ -103,8 +103,8 @@ export async function runEsbuild(
format === 'iife'
? false
: typeof options.splitting === 'boolean'
? options.splitting
: format === 'esm'
? options.splitting
: format === 'esm'

const platform = options.platform || 'node'
const loader = options.loader || {}
Expand Down Expand Up @@ -251,7 +251,7 @@ export async function runEsbuild(
const messages = result.warnings.filter((warning) => {
if (
warning.text.includes(
`This call to "require" will not be bundled because`
`This call to "require" will not be bundled because`,
) ||
warning.text.includes(`Indirect calls to "require" will not be bundled`)
)
Expand Down Expand Up @@ -290,7 +290,7 @@ export async function runEsbuild(
await fs.promises.writeFile(
outPath,
JSON.stringify(result.metafile),
'utf8'
'utf8',
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/esbuild/native-node-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const nativeNodeModulesPlugin = (): Plugin => {
(args) => ({
path: args.path,
namespace: 'file',
})
}),
)

// Tell esbuild's default loading behavior to use the "file" loader for
Expand Down
2 changes: 1 addition & 1 deletion src/esbuild/node-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const nodeProtocolPlugin = (): Plugin => {
({ path }) => ({
path: path.slice(nodeProtocol.length),
external: true,
})
}),
)
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/esbuild/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const postcssPlugin = ({
`,
loader: 'js',
}
}
},
)

build.onLoad({ filter: /\.css$/ }, async (args) => {
Expand Down Expand Up @@ -126,7 +126,7 @@ export const postcssPlugin = ({
typeof inject === 'function'
? inject(JSON.stringify(contents), args.path)
: `import styleInject from '#style-inject';styleInject(${JSON.stringify(
contents
contents,
)})`

return {
Expand Down
4 changes: 2 additions & 2 deletions src/esbuild/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const sveltePlugin = ({
return {
path: path.relative(
process.cwd(),
path.join(args.resolveDir, args.path)
path.join(args.resolveDir, args.path),
),
namespace: 'svelte-css',
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export const sveltePlugin = ({
},
{
filename: args.path,
}
},
)
const result = svelte.compile(preprocess.code, {
filename,
Expand Down
4 changes: 2 additions & 2 deletions src/esbuild/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const swcPlugin = ({ logger }: { logger: Logger }): Plugin => {
if (!swc) {
logger.warn(
build.initialOptions.format!,
`You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin`
`You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin`,
)
return
}
Expand Down Expand Up @@ -58,7 +58,7 @@ export const swcPlugin = ({ logger }: { logger: Logger }): Plugin => {
: source
})
code += `//# sourceMappingURL=data:application/json;base64,${Buffer.from(
JSON.stringify(map)
JSON.stringify(map),
).toString('base64')}`
}
return {
Expand Down
Loading

0 comments on commit 533876c

Please sign in to comment.