Skip to content

Commit 1abb2ef

Browse files
authored
Remove unused deps (#441)
* Remove unused deps * Use the plugin that has already been imported rather than dynamically importing it again
1 parent 6443185 commit 1abb2ef

File tree

5 files changed

+14
-49
lines changed

5 files changed

+14
-49
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
5252
"@types/node": "^24.3.0",
5353
"@zackad/prettier-plugin-twig": "^0.16.0",
54-
"ast-types": "^0.14.2",
5554
"clear-module": "^4.1.2",
5655
"cpy-cli": "^6.0.0",
5756
"dedent": "^1.6.0",
@@ -60,7 +59,6 @@
6059
"fast-glob": "^3.3.3",
6160
"import-sort-style-module": "^6.0.0",
6261
"jiti": "^2.6.0",
63-
"jsesc": "^3.1.0",
6462
"license-checker": "^25.0.1",
6563
"line-column": "^1.0.2",
6664
"marko": "^5.37.46",
@@ -77,7 +75,6 @@
7775
"prettier-plugin-sort-imports": "^1.8.8",
7876
"prettier-plugin-svelte": "^3.4.0",
7977
"pug-lexer": "^5.0.1",
80-
"recast": "0.20.5",
8178
"resolve-from": "^5.0.0",
8279
"rimraf": "^6.0.1",
8380
"svelte": "^5.38.2",

pnpm-lock.yaml

Lines changed: 2 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/create-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ function createPrinter({
142142
return printer
143143
}
144144

145-
async function loadPlugins<T>(fns: string[]) {
145+
type PluginLoad = string | Plugin<any>
146+
147+
async function loadPlugins<T>(fns: PluginLoad[]) {
146148
let plugin: Plugin<T> = {
147149
parsers: Object.create(null),
148150
printers: Object.create(null),
@@ -153,7 +155,7 @@ async function loadPlugins<T>(fns: string[]) {
153155

154156
for (let moduleName of fns) {
155157
try {
156-
let loaded = await loadIfExistsESM(moduleName)
158+
let loaded = typeof moduleName === 'string' ? await loadIfExistsESM(moduleName) : moduleName
157159
Object.assign(plugin.parsers!, loaded.parsers ?? {})
158160
Object.assign(plugin.printers!, loaded.printers ?? {})
159161
Object.assign(plugin.options!, loaded.options ?? {})

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ type CssNode = {
10771077
}
10781078

10791079
let css = defineTransform<CssNode>({
1080-
load: ['prettier/plugins/postcss'],
1080+
load: [prettierParserCss],
10811081
compatible: ['prettier-plugin-css-order'],
10821082

10831083
parsers: {
@@ -1106,10 +1106,10 @@ let js = defineTransform<import('@babel/types').Node>({
11061106
],
11071107

11081108
parsers: {
1109-
babel: { load: ['prettier/plugins/babel'] },
1110-
'babel-flow': { load: ['prettier/plugins/babel'] },
1111-
'babel-ts': { load: ['prettier/plugins/babel'] },
1112-
__js_expression: { load: ['prettier/plugins/babel'] },
1109+
babel: { load: [prettierParserBabel] },
1110+
'babel-flow': { load: [prettierParserBabel] },
1111+
'babel-ts': { load: [prettierParserBabel] },
1112+
__js_expression: { load: [prettierParserBabel] },
11131113
typescript: { load: ['prettier/plugins/typescript'] },
11141114
meriyah: { load: ['prettier/plugins/meriyah'] },
11151115
acorn: { load: ['prettier/plugins/acorn'] },

src/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AstPath, ParserOptions } from 'prettier'
1+
import type { AstPath, ParserOptions, Plugin } from 'prettier'
22
import type { TransformerEnv } from './types'
33

44
export function defineTransform<T>(opts: TransformOptions<T>) {
@@ -19,7 +19,7 @@ export interface TransformOptions<T> {
1919
/**
2020
* Load the given plugins for the parsers and printers
2121
*/
22-
load?: string[]
22+
load?: Array<string | Plugin<any>>
2323

2424
/**
2525
* A list of compatible, third-party plugins for this transformation step
@@ -39,7 +39,7 @@ export interface TransformOptions<T> {
3939
/**
4040
* Load the given plugins for the parsers and printers
4141
*/
42-
load?: string[]
42+
load?: Array<string | Plugin<any>>
4343

4444
/**
4545
* Static attributes that are supported by default

0 commit comments

Comments
 (0)