Skip to content

Commit

Permalink
feat: biome
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Jan 14, 2024
1 parent 1028e89 commit ea5f6c4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/cli/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default defineConfig({
'process.env.NODE_DEBUG': 'undefined',
},
// minify: true,
external: [
'@biomejs/js-api',
],
noExternal: [
'jscodeshift',
'ast-types',
Expand Down
2 changes: 2 additions & 0 deletions packages/unminify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@biomejs/js-api": "^0.3.0-nightly.efc084c",
"@biomejs/wasm-nodejs": "^1.5.1",
"@types/jscodeshift": "^0.11.11",
"@types/prettier": "^2.7.3",
"@types/yargs": "^17.0.32",
Expand Down
45 changes: 45 additions & 0 deletions packages/unminify/src/transformations/biome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Biome, Distribution } from '@biomejs/js-api'
import { createStringTransformationRule } from '@wakaru/shared/rule'

type FormatConfiguration = Parameters<Biome['applyConfiguration']>[0]

let biome: Biome | null = null

const formatConfig: FormatConfiguration = {
formatter: {
enabled: true,
indentStyle: 'space',
indentWidth: 2,
lineWidth: 80,
},
javascript: {
formatter: {
quoteStyle: 'double',
jsxQuoteStyle: 'double',
// trailing_comma: 'all',
trailingComma: 'es5',
semicolons: 'always',
arrowParentheses: 'always',
bracketSameLine: false,
bracketSpacing: true,
enabled: true,
},
},
}

/**
* @url https://github.com/biomejs/biome
*/
export default createStringTransformationRule({
name: 'prettier',
transform: async (code) => {
if (!biome) {
biome = await Biome.create({
distribution: Distribution.NODE,
})
biome.applyConfiguration(formatConfig)
}

return biome.formatContent(code, { filePath: 'example.js' }).content
},
})
7 changes: 5 additions & 2 deletions packages/unminify/src/transformations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import biome from './biome'
import lebab from './lebab'
import moduleMapping from './module-mapping'
import prettier from './prettier'

Check failure on line 4 in packages/unminify/src/transformations/index.ts

View workflow job for this annotation

GitHub Actions / check

'prettier' is defined but never used

Check failure on line 4 in packages/unminify/src/transformations/index.ts

View workflow job for this annotation

GitHub Actions / check

'prettier' is defined but never used
Expand Down Expand Up @@ -38,7 +39,8 @@ import type { TransformationRule } from '@wakaru/shared/rule'

export const transformationRules: TransformationRule[] = [
// first stage - basically prettify the code
prettier.withId('prettier'),
// prettier.withId('prettier'),
biome,
moduleMapping,
unCurlyBraces, // add curly braces so that other transformations can works easier, but generally this is not required
unSequenceExpression, // curly braces can bring out return sequence expression, so it runs before this
Expand Down Expand Up @@ -84,5 +86,6 @@ export const transformationRules: TransformationRule[] = [
unAsyncAwait,

// last stage - prettify the code again after we finish all the transformations
prettier.withId('prettier-1'),
// prettier.withId('prettier-1'),
biome,
]
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit ea5f6c4

Please sign in to comment.