Skip to content

Commit 943adca

Browse files
committed
fix: @reteps/dockerfmt is ESM only
1 parent 44a00bc commit 943adca

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎packages/sh/src/index.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { formatDockerfileContents } from '@reteps/dockerfmt'
21
import type { Parser, ParserOptions, Plugin, Printer } from 'prettier'
32
import {
43
type File,
@@ -94,6 +93,18 @@ const dockerfileParser: Parser<string> = {
9493
locEnd: node => node.length,
9594
}
9695

96+
let formatDockerfileContents_:
97+
| typeof import('@reteps/dockerfmt').formatDockerfileContents
98+
| undefined
99+
100+
const getFormatDockerfileContents = async () => {
101+
if (!formatDockerfileContents_) {
102+
const dockerfmt = await import('@reteps/dockerfmt')
103+
formatDockerfileContents_ = dockerfmt.formatDockerfileContents
104+
}
105+
return formatDockerfileContents_
106+
}
107+
97108
const dockerPrinter: Printer<string> = {
98109
// @ts-expect-error -- https://github.com/prettier/prettier/issues/15080#issuecomment-1630987744
99110
async print(
@@ -108,6 +119,7 @@ const dockerPrinter: Printer<string> = {
108119
if (!node) {
109120
return ''
110121
}
122+
const formatDockerfileContents = await getFormatDockerfileContents()
111123
return formatDockerfileContents(node, {
112124
indent,
113125
trailingNewline: true,
@@ -204,6 +216,7 @@ const shPrinter: Printer<Node | string> = {
204216
}
205217

206218
try {
219+
const formatDockerfileContents = await getFormatDockerfileContents()
207220
return await formatDockerfileContents(node, {
208221
indent,
209222
trailingNewline: true,

0 commit comments

Comments
 (0)