mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
chore: fix some lint errors
This commit is contained in:
parent
11f57e2dd6
commit
b3fab602a1
@ -51,6 +51,7 @@
|
||||
"@babel/core": "^7.13.15",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@swc/core": "^1.2.112",
|
||||
"@types/babel__core": "^7.1.16",
|
||||
"@types/buble": "^0.19.2",
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/flat": "^5.0.2",
|
||||
|
||||
31
pnpm-lock.yaml
generated
31
pnpm-lock.yaml
generated
@ -4,6 +4,7 @@ specifiers:
|
||||
'@babel/core': ^7.13.15
|
||||
'@rollup/plugin-json': ^4.1.0
|
||||
'@swc/core': ^1.2.112
|
||||
'@types/babel__core': ^7.1.16
|
||||
'@types/buble': ^0.19.2
|
||||
'@types/debug': ^4.1.5
|
||||
'@types/flat': ^5.0.2
|
||||
@ -62,6 +63,7 @@ devDependencies:
|
||||
'@babel/core': 7.16.0
|
||||
'@rollup/plugin-json': 4.1.0_rollup@2.60.1
|
||||
'@swc/core': 1.2.112
|
||||
'@types/babel__core': 7.1.16
|
||||
'@types/buble': 0.19.2
|
||||
'@types/debug': 4.1.7
|
||||
'@types/flat': 5.0.2
|
||||
@ -480,6 +482,35 @@ packages:
|
||||
'@swc/core-win32-x64-msvc': 1.2.112
|
||||
dev: true
|
||||
|
||||
/@types/babel__core/7.1.16:
|
||||
resolution: {integrity: sha512-EAEHtisTMM+KaKwfWdC3oyllIqswlznXCIVCt7/oRNrh+DhgT4UEBNC/jlADNjvw7UnfbcdkGQcPVZ1xYiLcrQ==}
|
||||
dependencies:
|
||||
'@babel/parser': 7.16.4
|
||||
'@babel/types': 7.16.0
|
||||
'@types/babel__generator': 7.6.3
|
||||
'@types/babel__template': 7.4.1
|
||||
'@types/babel__traverse': 7.14.2
|
||||
dev: true
|
||||
|
||||
/@types/babel__generator/7.6.3:
|
||||
resolution: {integrity: sha512-/GWCmzJWqV7diQW54smJZzWbSFf4QYtF71WCKhcx6Ru/tFyQIY2eiiITcCAeuPbNSvT9YCGkVMqqvSk2Z0mXiA==}
|
||||
dependencies:
|
||||
'@babel/types': 7.16.0
|
||||
dev: true
|
||||
|
||||
/@types/babel__template/7.4.1:
|
||||
resolution: {integrity: sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==}
|
||||
dependencies:
|
||||
'@babel/parser': 7.16.4
|
||||
'@babel/types': 7.16.0
|
||||
dev: true
|
||||
|
||||
/@types/babel__traverse/7.14.2:
|
||||
resolution: {integrity: sha512-K2waXdXBi2302XUdcHcR1jCeU0LL4TD9HRs/gk0N2Xvrht+G/BfJa4QObBQZfhMdxiCpV3COl5Nfq4uKTeTnJA==}
|
||||
dependencies:
|
||||
'@babel/types': 7.16.0
|
||||
dev: true
|
||||
|
||||
/@types/buble/0.19.2:
|
||||
resolution: {integrity: sha512-uUD8zIfXMKThmFkahTXDGI3CthFH1kMg2dOm3KLi4GlC5cbARA64bEcUMbbWdWdE73eoc/iBB9PiTMqH0dNS2Q==}
|
||||
dependencies:
|
||||
|
||||
@ -117,7 +117,7 @@ export async function main(options: Options = {}) {
|
||||
options.inject = inject
|
||||
}
|
||||
if (flags.define) {
|
||||
const define: any = flat(flags.define)
|
||||
const define: Record<string, string> = flat(flags.define)
|
||||
options.define = define
|
||||
}
|
||||
if (flags.loader) {
|
||||
|
||||
@ -13,7 +13,7 @@ export const externalPlugin = ({
|
||||
external?: (string | RegExp)[]
|
||||
noExternal?: (string | RegExp)[]
|
||||
skipNodeModulesBundle?: boolean
|
||||
tsconfigResolvePaths?: Record<string, any>
|
||||
tsconfigResolvePaths?: Record<string, string[]>
|
||||
}): Plugin => {
|
||||
return {
|
||||
name: `external`,
|
||||
|
||||
@ -26,7 +26,7 @@ const getOutputExtensionMap = (
|
||||
format: Format
|
||||
) => {
|
||||
const isModule = pkgTypeField === 'module'
|
||||
const map: any = {}
|
||||
const map: Record<string, string> = {}
|
||||
if (isModule && format === 'cjs') {
|
||||
map['.js'] = '.cjs'
|
||||
}
|
||||
@ -172,7 +172,9 @@ export async function runEsbuild(
|
||||
},
|
||||
inject: [
|
||||
format === 'cjs' ? path.join(__dirname, '../assets/cjs_shims.js') : '',
|
||||
format === 'esm' && platform === 'node' ? path.join(__dirname, '../assets/esm_shims.js') : '',
|
||||
format === 'esm' && platform === 'node'
|
||||
? path.join(__dirname, '../assets/esm_shims.js')
|
||||
: '',
|
||||
...(options.inject || []),
|
||||
].filter(Boolean),
|
||||
outdir:
|
||||
@ -262,10 +264,17 @@ export async function runEsbuild(
|
||||
spreadRest: true,
|
||||
},
|
||||
}).code
|
||||
} catch (error: any) {
|
||||
throw new PrettyError(
|
||||
`Error compiling to es5 target:\n${error.snippet}`
|
||||
)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw new PrettyError(
|
||||
`Error compiling to es5 target:\n${
|
||||
// @ts-expect-error not sure how to type error.snippet
|
||||
error.snippet || error.message
|
||||
}`
|
||||
)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
// Workaround to enable code splitting for cjs format
|
||||
|
||||
@ -37,11 +37,12 @@ export const sveltePlugin = ({
|
||||
}
|
||||
|
||||
// This converts a message in Svelte's format to esbuild's format
|
||||
let convertMessage = ({ message, start, end }: any) => {
|
||||
const convertMessage = ({ message, start, end }: any) => {
|
||||
let location
|
||||
if (start && end) {
|
||||
let lineText = source.split(/\r\n|\r|\n/g)[start.line - 1]
|
||||
let lineEnd = start.line === end.line ? end.column : lineText.length
|
||||
const lineText = source.split(/\r\n|\r|\n/g)[start.line - 1]
|
||||
const lineEnd =
|
||||
start.line === end.line ? end.column : lineText.length
|
||||
location = {
|
||||
file: filename,
|
||||
line: start.line,
|
||||
@ -54,8 +55,8 @@ export const sveltePlugin = ({
|
||||
}
|
||||
|
||||
// Load the file from the file system
|
||||
let source = await fs.promises.readFile(args.path, 'utf8')
|
||||
let filename = path.relative(process.cwd(), args.path)
|
||||
const source = await fs.promises.readFile(args.path, 'utf8')
|
||||
const filename = path.relative(process.cwd(), args.path)
|
||||
|
||||
// Convert Svelte syntax to JavaScript
|
||||
try {
|
||||
|
||||
@ -9,7 +9,7 @@ export const swcPlugin = (): Plugin => {
|
||||
return {
|
||||
name: 'swc',
|
||||
|
||||
async setup(build) {
|
||||
setup(build) {
|
||||
const swc: typeof import('@swc/core') = localRequire('@swc/core')
|
||||
|
||||
if (!swc) {
|
||||
|
||||
@ -24,7 +24,7 @@ export type NormalizedOptions = Omit<
|
||||
'dts'
|
||||
> & {
|
||||
dts?: DtsConfig
|
||||
tsconfigResolvePaths: Record<string, any>
|
||||
tsconfigResolvePaths: Record<string, string[]>
|
||||
tsconfigDecoratorMetadata?: boolean
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ export async function build(_options: Options) {
|
||||
/** Files imported by the entry */
|
||||
const buildDependencies: Set<string> = new Set()
|
||||
|
||||
async function killPreviousProcess() {
|
||||
const killPreviousProcess = async () => {
|
||||
if (existingOnSuccess) {
|
||||
await killProcess({
|
||||
pid: existingOnSuccess.pid,
|
||||
@ -244,7 +244,7 @@ export async function build(_options: Options) {
|
||||
ignorePermissionErrors: true,
|
||||
ignored,
|
||||
})
|
||||
watcher.on('all', async (type, file) => {
|
||||
watcher.on('all', (type, file) => {
|
||||
file = slash(file)
|
||||
if (!buildDependencies.has(file)) return
|
||||
|
||||
|
||||
18
src/load.ts
18
src/load.ts
@ -9,18 +9,22 @@ const joycon = new JoyCon()
|
||||
const loadJson = async (filepath: string) => {
|
||||
try {
|
||||
return jsoncParse(await fs.promises.readFile(filepath, 'utf8'))
|
||||
} catch (error: any) {
|
||||
throw new Error(
|
||||
`Failed to parse ${path.relative(process.cwd(), filepath)}: ${
|
||||
error.message
|
||||
}`
|
||||
)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw new Error(
|
||||
`Failed to parse ${path.relative(process.cwd(), filepath)}: ${
|
||||
error.message
|
||||
}`
|
||||
)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const jsonLoader = {
|
||||
test: /\.json$/,
|
||||
async load(filepath: string) {
|
||||
load(filepath: string) {
|
||||
return loadJson(filepath)
|
||||
},
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ async function watchRollup(options: {
|
||||
...options.inputConfig,
|
||||
plugins: options.inputConfig.plugins,
|
||||
output: options.outputConfig,
|
||||
}).on('event', async (event) => {
|
||||
}).on('event', (event) => {
|
||||
if (event.code === 'START') {
|
||||
logger.info('dts', 'Build start')
|
||||
} else if (event.code === 'BUNDLE_END') {
|
||||
|
||||
@ -13,7 +13,7 @@ const resolveModule = (
|
||||
): Promise<string | null> =>
|
||||
new Promise((resolve, reject) => {
|
||||
_resolve(id, opts, (err, res) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error error code is not typed
|
||||
if (err?.code === 'MODULE_NOT_FOUND') return resolve(null)
|
||||
if (err) return reject(err)
|
||||
resolve(res || null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user