Skip to content

Commit

Permalink
chore: apply linter
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed Jul 1, 2024
1 parent 9fa82a9 commit d33dd8e
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 278 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import antfu from '@antfu/eslint-config'

export default await antfu({
ignores: ['test/fixtures']
ignores: ['test/fixtures'],
})
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "unplugin-swc",
"type": "module",
"version": "0.0.0",
"packageManager": "pnpm@9.4.0",
"description": "SWC plugin for Vite and Rollup",
"publishConfig": {
"access": "public"
},
"license": "MIT",
"author": "EGOIST <hi@egoist.dev> (https://github.com/egoist)",
"contributors": [
"hannoeru <me@hanlee.co> (https://github.com/hannoeru)"
],
"license": "MIT",
"homepage": "https://github.com/unplugin/unplugin-swc/tree/main/#readme",
"repository": {
"type": "git",
"url": "https://github.com/unplugin/unplugin-swc.git"
},
"bugs": {
"url": "https://github.com/unplugin/unplugin-swc/issues"
},
"homepage": "https://github.com/unplugin/unplugin-swc/tree/main/#readme",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
Expand All @@ -32,12 +32,13 @@
}
}
},
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"test": "npm run build && vitest",
"test": "vitest",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepublishOnly": "npm run build",
Expand All @@ -57,6 +58,7 @@
"@types/node": "^20.14.9",
"defu": "^6.1.4",
"esbuild": "0.20.2",
"eslint": "^9.6.0",
"path-exists": "^5.0.0",
"prettier": "3.2.5",
"rollup": "^4.18.0",
Expand Down
420 changes: 175 additions & 245 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import path from 'path'
import path from 'node:path'
import { createFilter } from '@rollup/pluginutils'
import { transform } from '@swc/core'
import { defu } from 'defu'
// @ts-expect-error missing types
import { loadTsConfig } from 'load-tsconfig'
import { createUnplugin } from 'unplugin'
import { resolveId } from './resolve'
import type { FilterPattern } from '@rollup/pluginutils'
import type { JscConfig, Options as SwcOptions, TransformConfig } from '@swc/core'
import { resolveId } from './resolve'

export type Options = SwcOptions & {
include?: FilterPattern
Expand All @@ -34,7 +34,8 @@ export default createUnplugin<Options | undefined, false>(
resolveId,

async transform(code, id) {
if (!filter(id)) return null
if (!filter(id))
return null

const compilerOptions
= tsconfigFile === false
Expand All @@ -56,7 +57,8 @@ export default createUnplugin<Options | undefined, false>(
if (compilerOptions.jsx) {
if (jsc.parser.syntax === 'typescript') {
jsc.parser.tsx = true
} else {
}
else {
jsc.parser.jsx = true
}
Object.assign<TransformConfig, TransformConfig>(jsc.transform, {
Expand Down
12 changes: 7 additions & 5 deletions src/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import { pathExists } from 'path-exists'

const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.mts', '.jsx', '.js', '.mjs', '.cjs']

const resolveFile = async(resolved: string, index = false) => {
async function resolveFile(resolved: string, index = false) {
for (const ext of RESOLVE_EXTENSIONS) {
const file = index
? path.join(resolved, `index${ext}`)
: `${resolved}${ext}`
if (await pathExists(file)) return file
if (await pathExists(file))
return file
}
}

export const resolveId = async(importee: string, importer?: string) => {
export async function resolveId(importee: string, importer?: string) {
if (importer && importee[0] === '.') {
const absolutePath = path.resolve(
// eslint-disable-next-line node/prefer-global/process
importer ? path.dirname(importer) : process.cwd(),
importee,
)
Expand Down
14 changes: 7 additions & 7 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path'
import path from 'node:path'
import { rollup } from 'rollup'
import { expect, test } from 'vitest'
import swc from '../dist'
import { expect, it } from 'vitest'
import swc from '../src'

const fixture = (...args: string[]) => path.join(__dirname, 'fixtures', ...args)

test('rollup', async() => {
it('rollup', async () => {
const bundle = await rollup({
input: fixture('rollup/index.ts'),
plugins: [
Expand All @@ -32,7 +32,7 @@ test('rollup', async() => {
`)
})

test('read tsconfig', async() => {
it('read tsconfig', async () => {
const bundle = await rollup({
input: fixture('read-tsconfig/index.tsx'),
plugins: [swc.rollup()],
Expand All @@ -53,7 +53,7 @@ test('read tsconfig', async() => {
})).rejects.toThrow('Syntax Error')
})

test('custom swcrc', async() => {
it('custom swcrc', async () => {
const bundle = await rollup({
input: fixture('custom-swcrc/index.tsx'),
plugins: [
Expand All @@ -72,7 +72,7 @@ test('custom swcrc', async() => {
expect(code).toMatch('customPragma')
})

test('minify', async() => {
it('minify', async () => {
const bundle = await rollup({
input: fixture('minify/index.ts'),
plugins: [
Expand Down
12 changes: 6 additions & 6 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node",
"skipLibCheck": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"allowJs": true,
"resolveJsonModule": true
"strict": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"exclude": ["fixtures"]
}
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "Bundler",
"skipLibCheck": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"allowJs": true,
"resolveJsonModule": true
"strict": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src", "*.ts"]
}

0 comments on commit d33dd8e

Please sign in to comment.