Skip to content

Commit 8d81908

Browse files
committed
Move outputFile to lib/
1 parent aa84980 commit 8d81908

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

index.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
import fs from 'node:fs/promises'
43
import path from 'path'
54

65
import prettyHrtime from 'pretty-hrtime'
@@ -18,6 +17,7 @@ import postcssReporter from 'postcss-reporter/lib/formatter.js'
1817
import argv from './lib/args.js'
1918
import createDependencyGraph from './lib/DependencyGraph.js'
2019
import getMapfile from './lib/getMapfile.js'
20+
import outputFile from './lib/outputFile.js'
2121

2222
const reporter = postcssReporter()
2323
const depGraph = createDependencyGraph()
@@ -288,17 +288,6 @@ function css(css, file) {
288288
.catch((err) => {
289289
throw err
290290
})
291-
292-
async function outputFile(file, string) {
293-
const fileExists = await fs.access(file).then(
294-
() => true,
295-
() => false,
296-
)
297-
const currentValue = fileExists ? await fs.readFile(file, 'utf8') : null
298-
if (currentValue === string) return
299-
await fs.mkdir(path.dirname(file), { recursive: true })
300-
return fs.writeFile(file, string)
301-
}
302291
}
303292

304293
function dependencies(results) {

lib/outputFile.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
4+
export default async function outputFile(file, string) {
5+
try {
6+
const currentValue = await fs.readFile(file, 'utf8')
7+
if (currentValue === string) return
8+
} catch {}
9+
await fs.mkdir(path.dirname(file), { recursive: true })
10+
return fs.writeFile(file, string)
11+
}

0 commit comments

Comments
 (0)