FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: replace fs-extra with native Node.js fs by roli-lpci · Pull Request #510 · postcss/postcss-cli · GitHub

Repository navigation

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

Filter by extension

Filter by extension .js  (11) .json  (1) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 7 additions & 3 deletions index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

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

import prettyHrtime from 'pretty-hrtime'
Expand Down Expand Up @@ -286,10 +286,14 @@ function css(css, file) {
})

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

Expand Down
1 change: 0 additions & 1 deletion package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"dependencies": {
"chokidar": "^3.3.0",
"dependency-graph": "^1.0.0",
"fs-extra": "^11.0.0",
"picocolors": "^1.0.0",
"postcss-load-config": "^5.0.0",
"postcss-reporter": "^7.0.0",
Expand Down
16 changes: 13 additions & 3 deletions test/ext.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'

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

import cli from './helpers/cli.js'
Expand All @@ -20,7 +20,12 @@ test('--ext works', async (t) => {
])
t.falsy(error, stderr)

t.truthy(await fs.pathExists(path.join(dir, 'a.css')))
t.truthy(
await fs.access(path.join(dir, 'a.css')).then(
() => true,
() => false,
),
)
})

test('--ext works with no leading dot', async (t) => {
Expand All @@ -37,5 +42,10 @@ test('--ext works with no leading dot', async (t) => {
])
t.falsy(error, stderr)

t.truthy(await fs.pathExists(path.join(dir, 'a.css')))
t.truthy(
await fs.access(path.join(dir, 'a.css')).then(
() => true,
() => false,
),
)
})
8 changes: 5 additions & 3 deletions test/helpers/clean.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'fs-extra'
import fs from 'node:fs/promises'

Promise.all([
fs.emptyDir('./test/fixtures/.tmp/'),
fs.remove('./coverage'),
fs
.rm('./test/fixtures/.tmp/', { recursive: true, force: true })
.then(() => fs.mkdir('./test/fixtures/.tmp/', { recursive: true })),
fs.rm('./coverage', { recursive: true, force: true }),
]).catch((err) => {
console.error(err)
process.exit(1)
Expand Down
24 changes: 15 additions & 9 deletions test/helpers/env.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import fs from 'fs-extra'
import fs from 'node:fs/promises'
import path from 'path'
import { glob } from 'tinyglobby'

import tmp from './tmp.js'

export default function (config, fixtures = '**/*', extension = 'cjs') {
export default async function (config, fixtures = '**/*', extension = 'cjs') {
const dir = tmp()

return Promise.all([
glob(fixtures, { cwd: 'test/fixtures' }).then((list) => {
return list.map((item) => {
return fs.copy(path.join('test/fixtures', item), path.join(dir, item))
})
await fs.mkdir(dir, { recursive: true })

const list = await glob(fixtures, { cwd: 'test/fixtures' })

await Promise.all([
...list.map(async (item) => {
const dest = path.join(dir, item)
await fs.mkdir(path.dirname(dest), { recursive: true })
await fs.copyFile(path.join('test/fixtures', item), dest)
}),
fs.outputFile(path.join(dir, `postcss.config.${extension}`), config),
]).then(() => dir)
fs.writeFile(path.join(dir, `postcss.config.${extension}`), config),
])

return dir
}
2 changes: 1 addition & 1 deletion test/helpers/read.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs-extra'
import fs from 'node:fs/promises'

export default function (path) {
return fs.readFile(path, 'utf8').then(
Expand Down
9 changes: 7 additions & 2 deletions test/map.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava'
import fs from 'fs-extra'
import fs from 'node:fs/promises'

import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
Expand Down Expand Up @@ -35,7 +35,12 @@ test('--map generates external sourcemaps', async (t) => {

t.falsy(error, stderr)

t.truthy(await fs.pathExists(output.replace('.css', '.css.map')))
t.truthy(
await fs.access(output.replace('.css', '.css.map')).then(
() => true,
() => false,
),
)
})

test('--no-map disables internal sourcemaps', async (t) => {
Expand Down
7 changes: 4 additions & 3 deletions test/replace.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'

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

import cli from './helpers/cli.js'
Expand All @@ -12,9 +12,10 @@ test('--replace works', async (t) => {

const output = path.join(dir, 'output.css')

await fs.mkdir(dir, { recursive: true })
await Promise.all([
fs.copy('test/fixtures/import.css', output),
fs.copy('test/fixtures/a.css', path.join(dir, 'a.css')),
fs.copyFile('test/fixtures/import.css', output),
fs.copyFile('test/fixtures/a.css', path.join(dir, 'a.css')),
])

const { error, stderr } = await cli([
Expand Down
4 changes: 2 additions & 2 deletions test/stdin.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'

import fs from 'fs-extra'
import { createReadStream } from 'node:fs'
import path from 'path'
import { exec } from 'child_process'

Expand All @@ -24,5 +24,5 @@ test.cb('reads from stdin', (t) => {
},
)

fs.createReadStream('test/fixtures/a.css').pipe(cp.stdin)
createReadStream('test/fixtures/a.css').pipe(cp.stdin)
})
4 changes: 2 additions & 2 deletions test/stdout.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'

import fs from 'fs-extra'
import { createReadStream } from 'node:fs'
import path from 'path'
import { exec } from 'child_process'

Expand All @@ -23,5 +23,5 @@ test.cb('writes to stdout', (t) => {
},
)

fs.createReadStream('./test/fixtures/a.sss').pipe(cp.stdin)
createReadStream('./test/fixtures/a.sss').pipe(cp.stdin)
})
2 changes: 1 addition & 1 deletion test/unchanged.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs-extra'
import fs from 'node:fs/promises'
import test from 'ava'

import cli from './helpers/cli.js'
Expand Down
2 changes: 1 addition & 1 deletion test/watch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'

import fs from 'fs-extra'
import fs from 'node:fs/promises'
import path from 'path'
import { exec, spawn } from 'child_process'
import chokidar from 'chokidar'
Expand Down

Back | FazBrowse Home | New Git URL