From 8d819086d9251aa302aa70fbbc3b49bb2bfb54eb Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Thu, 27 Aug 2026 10:35:07 -0400 Subject: [PATCH] Move outputFile to lib/ --- index.js | 13 +------------ lib/outputFile.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 lib/outputFile.js diff --git a/index.js b/index.js index 2c86221..8d36dfb 100755 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ #!/usr/bin/env node -import fs from 'node:fs/promises' import path from 'path' import prettyHrtime from 'pretty-hrtime' @@ -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() @@ -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) { diff --git a/lib/outputFile.js b/lib/outputFile.js new file mode 100644 index 0000000..f0c05af --- /dev/null +++ b/lib/outputFile.js @@ -0,0 +1,11 @@ +import fs from 'node:fs/promises' +import path from 'node:path' + +export default async function outputFile(file, string) { + try { + const currentValue = await fs.readFile(file, 'utf8') + if (currentValue === string) return + } catch {} + await fs.mkdir(path.dirname(file), { recursive: true }) + return fs.writeFile(file, string) +}