Skip to content

Commit

Permalink
refactor: lint
Browse files Browse the repository at this point in the history
eslint --fix by @sxzz/eslint-config

- add `node:` protocol
- sort imports
- ...
  • Loading branch information
sxzz committed Jul 17, 2024
1 parent 881b4b8 commit e8c6079
Show file tree
Hide file tree
Showing 44 changed files with 247 additions and 298 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

release:
runs-on: ubuntu-latest
needs: ['test']
needs: [test]
if: "!contains(github.event.head_commit.message, 'skip-release') && !contains(github.event.head_commit.message, 'skip-ci') && github.event_name != 'pull_request'"
permissions:
contents: write
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Fix
on:
push:
branches-ignore:
- 'main'
- 'dev'
- main
- dev

jobs:
format:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
playground
.idea
.DS_Store
.eslintcache
2 changes: 1 addition & 1 deletion assets/cjs_shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const getImportMetaUrl = () =>
typeof document === 'undefined'
? new URL('file:' + __filename).href
? new URL(`file:${__filename}`).href
: (document.currentScript && document.currentScript.src) ||
new URL('main.js', document.baseURI).href

Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { html } from 'docup'

export default () => {
let isPreview = location.hostname !== 'tsup.egoist.dev'
const isPreview = location.hostname !== 'tsup.egoist.dev'

if (!isPreview) return null

Expand Down Expand Up @@ -409,7 +409,7 @@ You can return a cleanup function in `onSuccess`:
import { defineConfig } from 'tsup'

export default defineConfig({
async onSuccess() {
onSuccess() {
const server = http.createServer((req, res) => {
res.end('Hello World!')
})
Expand Down
66 changes: 33 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"name": "tsup",
"version": "0.0.0-semantic-release",
"packageManager": "[email protected]",
"description": "Bundle your TypeScript library with no config, powered by esbuild",
"main": "dist/index.js",
"bin": {
"tsup": "dist/cli-default.js",
"tsup-node": "dist/cli-node.js"
"license": "MIT",
"homepage": "https://tsup.egoist.dev/",
"repository": {
"url": "https://github.com/egoist/tsup.git"
},
"types": "dist/index.d.ts",
"author": "EGOIST",
"files": [
"/dist",
"/assets",
"/dist",
"/schema.json"
],
"author": "EGOIST",
"license": "MIT",
"homepage": "https://tsup.egoist.dev/",
"repository": {
"url": "https://github.com/egoist/tsup.git"
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"tsup": "dist/cli-default.js",
"tsup-node": "dist/cli-node.js"
},
"scripts": {
"dev": "npm run build-fast -- --watch",
Expand All @@ -28,6 +29,26 @@
"test-only": "vitest run",
"build-fast": "npm run build -- --no-dts"
},
"peerDependencies": {
"@microsoft/api-extractor": "^7.36.0",
"@swc/core": "^1",
"postcss": "^8.4.12",
"typescript": ">=4.5.0"
},
"peerDependenciesMeta": {
"@microsoft/api-extractor": {
"optional": true
},
"@swc/core": {
"optional": true
},
"postcss": {
"optional": true
},
"typescript": {
"optional": true
}
},
"dependencies": {
"bundle-require": "^5.0.0",
"cac": "^6.7.14",
Expand Down Expand Up @@ -72,28 +93,7 @@
"vitest": "2.0.3",
"wait-for-expect": "3.0.2"
},
"peerDependencies": {
"@microsoft/api-extractor": "^7.36.0",
"@swc/core": "^1",
"postcss": "^8.4.12",
"typescript": ">=4.5.0"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
},
"postcss": {
"optional": true
},
"@swc/core": {
"optional": true
},
"@microsoft/api-extractor": {
"optional": true
}
},
"engines": {
"node": ">=18"
},
"packageManager": "[email protected]"
}
}
18 changes: 13 additions & 5 deletions pnpm-lock.yaml

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

36 changes: 18 additions & 18 deletions src/api-extractor.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import type {
ExtractorResult,
IConfigFile,
IExtractorConfigPrepareOptions,
} from '@microsoft/api-extractor'
import path from 'path'
import path from 'node:path'
import { handleError } from './errors'
import {
type ExportDeclaration,
formatAggregationExports,
formatDistributionExports,
type ExportDeclaration,
} from './exports'
import { loadPkg } from './load'
import { createLogger } from './log'
import type { Format, NormalizedOptions } from './options'
import {
defaultOutExtension,
ensureTempDeclarationDir,
Expand All @@ -21,6 +15,12 @@ import {
toAbsolutePath,
writeFileSync,
} from './utils'
import type { Format, NormalizedOptions } from './options'
import type {
ExtractorResult,
IConfigFile,
IExtractorConfigPrepareOptions,
} from '@microsoft/api-extractor'

const logger = createLogger()

Expand All @@ -29,9 +29,9 @@ function rollupDtsFile(
outputFilePath: string,
tsconfigFilePath: string,
) {
let cwd = process.cwd()
let packageJsonFullPath = path.join(cwd, 'package.json')
let configObject: IConfigFile = {
const cwd = process.cwd()
const packageJsonFullPath = path.join(cwd, 'package.json')
const configObject: IConfigFile = {
mainEntryPointFilePath: inputFilePath,
apiReport: {
enabled: false,
Expand All @@ -46,7 +46,7 @@ function rollupDtsFile(
},
tsdocMetadata: { enabled: false },
compiler: {
tsconfigFilePath: tsconfigFilePath,
tsconfigFilePath,
},
projectFolder: cwd,
}
Expand Down Expand Up @@ -87,14 +87,14 @@ async function rollupDtsFiles(
exports: ExportDeclaration[],
format: Format,
) {
let declarationDir = ensureTempDeclarationDir()
let outDir = options.outDir || 'dist'
let pkg = await loadPkg(process.cwd())
let dtsExtension = defaultOutExtension({ format, pkgType: pkg.type }).dts
const declarationDir = ensureTempDeclarationDir()
const outDir = options.outDir || 'dist'
const pkg = await loadPkg(process.cwd())
const dtsExtension = defaultOutExtension({ format, pkgType: pkg.type }).dts

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 @@ -105,7 +105,7 @@ async function rollupDtsFiles(
.replace(/\.d\.mts$/, '.dmts.d.ts')
.replace(/\.d\.cts$/, '.dcts.d.ts')

let dtsOutputFilePath = path.join(outDir, '_tsup-dts-rollup' + dtsExtension)
const dtsOutputFilePath = path.join(outDir, `_tsup-dts-rollup${dtsExtension}`)

writeFileSync(
dtsInputFilePath,
Expand Down
9 changes: 4 additions & 5 deletions src/cli-main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cac } from 'cac'
import { flatten } from 'flat'
import type { Format, Options } from '.'
import { version } from '../package.json'
import { slash } from './utils'
import type { Format, Options } from '.'

function ensureArray(input: string): string[] {
return Array.isArray(input) ? input : input.split(',')
Expand Down Expand Up @@ -117,10 +117,9 @@ export async function main(options: Options = {}) {
options.external = external
}
if (flags.target) {
options.target =
flags.target.indexOf(',') >= 0
? flags.target.split(',')
: flags.target
options.target = flags.target.includes(',')
? flags.target.split(',')
: flags.target
}
if (flags.dts || flags.dtsResolve || flags.dtsOnly) {
options.dts = {}
Expand Down
10 changes: 4 additions & 6 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isMainThread, parentPort } from 'worker_threads'
import { isMainThread, parentPort } from 'node:worker_threads'
import * as colors from 'colorette'

export class PrettyError extends Error {
Expand Down Expand Up @@ -26,12 +26,10 @@ export function handleError(error: any) {
if (error.frame) {
console.error(colors.red(error.message))
console.error(colors.dim(error.frame))
} else if (error instanceof PrettyError) {
console.error(colors.red(error.message))
} else {
if (error instanceof PrettyError) {
console.error(colors.red(error.message))
} else {
console.error(colors.red(error.stack))
}
console.error(colors.red(error.stack))
}
process.exitCode = 1
if (!isMainThread && parentPort) {
Expand Down
4 changes: 2 additions & 2 deletions src/esbuild/external.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { match, tsconfigPathsToRegExp } from 'bundle-require'
import type { Plugin } from 'esbuild'
import { tsconfigPathsToRegExp, match } from 'bundle-require'

// Must not start with "/" or "./" or "../" or "C:\" or be the exact strings ".." or "."
const NON_NODE_MODULE_RE = /^[A-Z]:[\\\/]|^\.{0,2}[\/]|^\.{1,2}$/
const NON_NODE_MODULE_RE = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/

export const externalPlugin = ({
external,
Expand Down
18 changes: 9 additions & 9 deletions src/esbuild/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import {
build as esbuild,
type BuildResult,
formatMessages,
type Plugin as EsbuildPlugin,
build as esbuild,
formatMessages,
} from 'esbuild'
import type { NormalizedOptions, Format } from '..'
import consola from 'consola'
import { getProductionDeps, loadPkg } from '../load'
import { type Logger, getSilent } from '../log'
import { defaultOutExtension, truthy } from '../utils'
import { nodeProtocolPlugin } from './node-protocol'
import { externalPlugin } from './external'
import { postcssPlugin } from './postcss'
import { sveltePlugin } from './svelte'
import consola from 'consola'
import { defaultOutExtension, truthy } from '../utils'
import { swcPlugin } from './swc'
import { nativeNodeModulesPlugin } from './native-node-module'
import { PluginContainer } from '../plugin'
import type { PluginContainer } from '../plugin'
import type { Format, NormalizedOptions } from '..'
import type { OutExtensionFactory } from '../options'

const getOutputExtensionMap = (
Expand Down Expand Up @@ -47,7 +47,7 @@ const generateExternal = async (external: (string | RegExp)[]) => {
continue
}

let pkgPath: string = path.isAbsolute(item)
const pkgPath: string = path.isAbsolute(item)
? path.dirname(item)
: path.dirname(path.resolve(process.cwd(), item))

Expand Down
Loading

0 comments on commit e8c6079

Please sign in to comment.