Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

import fs from 'node:fs/promises'
import path from 'path'

import prettyHrtime from 'pretty-hrtime'
Expand All @@ -18,6 +17,7 @@ import postcssReporter from 'postcss-reporter/lib/formatter.js'
import argv from './lib/args.js'
import createDependencyGraph from './lib/DependencyGraph.js'
import getMapfile from './lib/getMapfile.js'
import outputFile from './lib/outputFile.js'

const reporter = postcssReporter()
const depGraph = createDependencyGraph()
Expand Down Expand Up @@ -288,17 +288,6 @@ function css(css, file) {
.catch((err) => {
throw err
})

async function outputFile(file, string) {
const fileExists = await fs.access(file).then(
() => true,
() => false,
)
const currentValue = fileExists ? await fs.readFile(file, 'utf8') : null
if (currentValue === string) return
await fs.mkdir(path.dirname(file), { recursive: true })
return fs.writeFile(file, string)
}
}

function dependencies(results) {
Expand Down
11 changes: 11 additions & 0 deletions lib/outputFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'node:fs/promises'
import path from 'node:path'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR


export default async function outputFile(file, string) {
try {
const currentValue = await fs.readFile(file, 'utf8')
if (currentValue === string) return
} catch {}
Comment thread
RyanZim marked this conversation as resolved.
await fs.mkdir(path.dirname(file), { recursive: true })
return fs.writeFile(file, string)
}