Skip to content

Commit dc17495

Browse files
[fix] Formatting synchronization has been changed.
1 parent a1a411a commit dc17495

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

cssToHtml.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import fs from 'fs-extra'
22
import path from 'path'
3-
import prettier from "@prettier/sync"
3+
import { createSyncFn } from 'synckit'
44
import { parse } from '@adobe/css-tools'
55
import { createParser } from 'css-selector-parser'
66
import { ElementOfHtml } from './elementOfHtml.js'
77

8+
const syncFormatting = createSyncFn(path.resolve('./formatWorker.js'))
89

910
export class CssToHtml {
1011
static ENCODING = 'utf8'
@@ -113,7 +114,7 @@ export class CssToHtml {
113114
}
114115

115116
if (this.format) {
116-
return prettier.format(newContent, { parser: "html" })
117+
return syncFormatting(newContent)
117118
} else {
118119
return newContent
119120
}

formatWorker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { runAsWorker } from 'synckit'
2+
import * as prettier from "prettier"
3+
4+
runAsWorker(async (newContent) => {
5+
return prettier.format(newContent, { parser: "html" })
6+
})

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
],
2727
"dependencies": {
2828
"@adobe/css-tools": "^4.4.0",
29-
"@prettier/sync": "^0.5.2",
3029
"css-selector-parser": "^3.0.5",
3130
"fs-extra": "^11.2.0",
32-
"prettier": "^3.3.3"
31+
"prettier": "^3.3.3",
32+
"synckit": "^0.9.2"
3333
},
3434
"license": "ISC"
3535
}

0 commit comments

Comments
 (0)