Skip to content

Commit

Permalink
chore: upgrate eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Oct 19, 2023
1 parent 7db5d17 commit 369dc21
Show file tree
Hide file tree
Showing 13 changed files with 1,267 additions and 312 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.experimental.useFlatConfig": true
}
2 changes: 1 addition & 1 deletion __tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test('aws s3', async (t) => {
const r = await readAll(path.join(dist, id))
const compressed = len(r.filter((s) => s.endsWith('.gz')))
t.is(compressed, 0)
// eslint-disable-next-line padded-blocks
const css = r.filter(v => v.endsWith('.css'))[0]
const bf = zlib.unzipSync(fs.readFileSync(css))
t.is(bf.toString(), '.pr{padding-right:30px}.pl{padding-left:30px}.mt{margin-top:30px}\n')
Expand Down
4 changes: 1 addition & 3 deletions e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TestOptions {
compressOption?: Parameters<typeof compression>[number]
}

function createGetter<T>(obj: T, key: string, getter: ()=> unknown) {
function createGetter<T>(obj: T, key: string, getter: () => unknown) {
Object.defineProperty(obj, key, {
get: getter
})
Expand Down Expand Up @@ -72,8 +72,6 @@ async function createChromeBrowser(server: Server) {
return { page }
}



async function expectTestCase(taskName: string, page: Awaited<Page>) {
const expect1 = new Promise((resolve) => {
page.on('console', (message) => resolve(message.text()))
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { nonzzz } = require('eslint-config-kagura')

module.exports = nonzzz({ ts: true }, { ignores: ['dist', 'node_modules'] })
1 change: 0 additions & 1 deletion example/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function createServer() {
})
})


server.listen(0, () => {
const { port } = server.address()
console.log(`server run on http://localhost:${port}`)
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@
"@esbuild-kit/cjs-loader": "^2.4.2",
"@nolyfill/es-aggregate-error": "^1.0.21",
"@types/node": "^17.0.14",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"ava": "^5.2.0",
"c8": "^7.13.0",
"eslint": "^8.40.0",
"eslint-config-kagura": "^1.2.0",
"eslint-plugin-import": "npm:[email protected]",
"eslint-config-kagura": "^2.0.0",
"playwright": "^1.32.3",
"sirv": "^2.0.3",
"tsup": "^7.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function compression<T extends UserCompressionOptions, A extends Algorithm>(opts

const zlib: {
algorithm: AlgorithmFunction<T>
filename: string | ((id: string)=> string)
filename: string | ((id: string) => string)
options: UserCompressionOptions
} = Object.create(null)

Expand Down Expand Up @@ -158,7 +158,7 @@ function compression<T extends UserCompressionOptions, A extends Algorithm>(opts
if (!filter(importer)) return
if (importer in bundles) {
const bundle = bundles[importer]
const chunk = bundle.type === 'asset' ? bundle.source : bundle.code
const chunk = bundle.type === 'asset' ? bundle.source : bundle.code
if (len(chunk) < threshold) return
const { dests, files } = makeOutputs(normalizedOutputs, importer)
stores.set(importer, {
Expand Down
21 changes: 9 additions & 12 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export type CompressionOptions<T> = InferDefault<T>

export type Pretty<T> = {
[key in keyof T]:
T[key] extends (...args: any[])=> any
? (...args: Parameters<T[key]>)=> ReturnType<T[key]>
: T[key] & NonNullable<unknown>
T[key] extends (...args: any[]) => any
? (...args: Parameters<T[key]>) => ReturnType<T[key]>
: T[key] & NonNullable<unknown>
} & NonNullable<unknown>

interface BaseCompressionPluginOptions {
include?: FilterPattern
exclude?: FilterPattern
threshold?: number
filename?: string | ((id: string)=> string)
filename?: string | ((id: string) => string)
deleteOriginalAssets?: boolean
skipIfLargerOrEqual?: boolean
}
Expand All @@ -34,14 +34,13 @@ interface AlgorithmToZlib {
}

export type AlgorithmFunction<T extends UserCompressionOptions> =
(buf: Buffer, options: T)=> Promise<Buffer>
(buf: Buffer, options: T) => Promise<Buffer>


type InternalCompressionPluginOptionsFunction<T> = {
type InternalCompressionPluginOptionsFunction<T> = {
algorithm?: AlgorithmFunction<T>
compressionOptions: T
}
type InternalWithoutCompressionPluginOptionsFunction = {
type InternalWithoutCompressionPluginOptionsFunction = {
algorithm?: AlgorithmFunction<undefined>
}
type InternalCompressionPluginOptionsAlgorithm<A extends Algorithm> = {
Expand All @@ -50,11 +49,11 @@ type InternalCompressionPluginOptionsAlgorithm<A extends Algorithm> = {
}

export type ViteCompressionPluginConfigFunction<T extends UserCompressionOptions> = BaseCompressionPluginOptions &
InternalCompressionPluginOptionsFunction<T>
InternalCompressionPluginOptionsFunction<T>
export type ViteWithoutCompressionPluginConfigFunction = Pretty<BaseCompressionPluginOptions &
InternalWithoutCompressionPluginOptionsFunction>
export type ViteCompressionPluginConfigAlgorithm<A extends Algorithm> = BaseCompressionPluginOptions &
InternalCompressionPluginOptionsAlgorithm<A>
InternalCompressionPluginOptionsAlgorithm<A>
export type ViteCompressionPluginConfig<T, A extends Algorithm> =
| ViteCompressionPluginConfigFunction<T>
| ViteCompressionPluginConfigAlgorithm<A>
Expand All @@ -74,5 +73,3 @@ interface DyanmiCompressMetaInfo extends BaseCompressMetaInfo {
}

export type CompressMetaInfo = NormalCompressMetaInfo | DyanmiCompressMetaInfo


2 changes: 1 addition & 1 deletion src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { len } from './utils'

class Queue {
maxConcurrent: number
queue: Array<()=> Promise<void>>
queue: Array<() => Promise<void>>
running: number
errors: Array<Error>
constructor(maxConcurrent: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function len<T extends ArrayLike<unknown>>(source: T) {
// [path][base].ext
// [path] is replaced with the directories to the original asset, included trailing
// [base] is replaced with the base ([name] + [ext]) of the original asset (image.png)
export function replaceFileName(staticPath: string, rule: string | ((id: string)=> string)) {
export function replaceFileName(staticPath: string, rule: string | ((id: string) => string)) {
const template = typeof rule === 'function' ? rule(staticPath) : rule
const { dir, base } = path.parse(staticPath)
const p = dir ? dir + '/' : ''
Expand Down
Loading

0 comments on commit 369dc21

Please sign in to comment.