Skip to content

Commit

Permalink
Update unified, vfile, @types/unist, utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 15, 2023
1 parent 7413acd commit 42f0823
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 155 deletions.
4 changes: 1 addition & 3 deletions lib/file-pipeline/copy.js
Expand Up @@ -46,9 +46,7 @@ export function copy(context, file, next) {
// but we should keep the basename of the given file.
fs.stat(path.dirname(outpath), (error) => {
if (error) {
next(
new Error('Cannot read parent directory. Error:\n' + error.message)
)
next(new Error('Cannot read parent directory', {cause: error}))
} else {
done(false)
}
Expand Down
14 changes: 9 additions & 5 deletions lib/finder.js
Expand Up @@ -245,11 +245,15 @@ function search(input, options, next) {
}

if (error && error.code === 'ENOENT') {
try {
file.fail(
error.syscall === 'stat' ? 'No such file or directory' : error
)
} catch {}
if (error.syscall === 'stat') {
try {
file.fail('No such file or directory', {cause: error})
} catch {}
} else {
try {
file.fail(error)
} catch {}
}
}

one(null, [file])
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -353,7 +353,7 @@ export function engine(options, callback) {
* @param {Context | undefined} [context]
*/
function next(error, context) {
const stats = statistics((context || {}).files)
const stats = statistics((context || {}).files || [])
const failed = Boolean(
settings.frail ? stats.fatal || stats.warn : stats.fatal
)
Expand Down
23 changes: 12 additions & 11 deletions package.json
Expand Up @@ -33,7 +33,7 @@
"@types/debug": "^4.0.0",
"@types/is-empty": "^1.0.0",
"@types/node": "^20.0.0",
"@types/unist": "^2.0.0",
"@types/unist": "^3.0.0",
"concat-stream": "^2.0.0",
"debug": "^4.0.0",
"fault": "^2.0.0",
Expand All @@ -44,12 +44,12 @@
"is-plain-obj": "^4.0.0",
"load-plugin": "^5.0.0",
"parse-json": "^7.0.0",
"to-vfile": "^7.0.0",
"to-vfile": "^8.0.0",
"trough": "^2.0.0",
"unist-util-inspect": "^7.0.0",
"vfile-message": "^3.0.0",
"vfile-reporter": "^7.0.0",
"vfile-statistics": "^2.0.0",
"unist-util-inspect": "^8.0.0",
"vfile-message": "^4.0.0",
"vfile-reporter": "^8.0.0",
"vfile-statistics": "^3.0.0",
"yaml": "^2.0.0"
},
"devDependencies": {
Expand All @@ -63,10 +63,10 @@
"strip-ansi": "^7.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unified": "^10.0.0",
"vfile": "^5.0.0",
"vfile-reporter-json": "^3.0.0",
"vfile-reporter-pretty": "^6.0.0",
"unified": "^11.0.0",
"vfile": "^6.0.0",
"vfile-reporter-json": "^4.0.0",
"vfile-reporter-pretty": "^7.0.0",
"xo": "^0.56.0"
},
"scripts": {
Expand Down Expand Up @@ -105,7 +105,8 @@
"complexity": "off",
"unicorn/no-this-assignment": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-event-target": "off"
"unicorn/prefer-event-target": "off",
"unicorn/prefer-string-replace-all": "off"
},
"overrides": [
{
Expand Down
13 changes: 7 additions & 6 deletions test/color.js
@@ -1,12 +1,10 @@
import assert from 'node:assert/strict'
import process from 'node:process'
import test from 'node:test'
import {engine} from '../index.js'
import {noop} from './util/noop-processor.js'
import {cleanError} from './util/clean-error.js'
import {spy} from './util/spy.js'

const cross = process.platform === 'win32' ? '×' : '✖'

const fixtures = new URL('fixtures/', import.meta.url)

test('color', async () => {
Expand All @@ -22,16 +20,19 @@ test('color', async () => {
color: true
},
(error, code) => {
const actual = cleanError(stderr())
const expected = [
'\u001B[4m\u001B[31mreadme.md\u001B[39m\u001B[24m',
' 1:1 \u001B[31merror\u001B[39m No such file or directory',
' \u001B[31merror\u001B[39m \u001B[1mNo such file or directory\u001B[22m',
' \u001B[1m[cause]\u001B[22m:',
' Error: ENOENT:…',
'',
'\u001B[31m' + cross + '\u001B[39m 1 error',
'\u001B[31m\u001B[39m 1 error',
''
].join('\n')

assert.deepEqual(
[error, code, stderr()],
[error, code, actual],
[null, 1, expected],
'should support color'
)
Expand Down
26 changes: 13 additions & 13 deletions test/configuration-plugins.js
Expand Up @@ -2,6 +2,7 @@ import assert from 'node:assert/strict'
import {sep} from 'node:path'
import test from 'node:test'
import {engine} from '../index.js'
import {cleanError} from './util/clean-error.js'
import {noop} from './util/noop-processor.js'
import {spy} from './util/spy.js'

Expand Down Expand Up @@ -104,11 +105,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 4).join('\n')
const actual = cleanError(stderr(), 4)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `package.json`',
' error Error: Cannot parse file `package.json`',
'Cannot import `test.js`',
'Error: Boom!'
].join('\n')
Expand Down Expand Up @@ -136,11 +137,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 4).join('\n')
const actual = cleanError(stderr(), 4)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `package.json`',
' error Error: Cannot parse file `package.json`',
'Cannot import `test.js`',
'Error: Expected a plugin or preset exported as the default export'
].join('\n')
Expand Down Expand Up @@ -169,11 +170,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const actual = cleanError(stderr(), 2)

const expected = [
'one.txt',
' 1:1 error Error: Could not find module `missing`'
' error Error: Could not find module `missing`'
].join('\n')

assert.deepEqual(
Expand All @@ -200,11 +201,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 3).join('\n')
const actual = cleanError(stderr(), 3)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `package.json`',
' error Error: Cannot parse file `package.json`',
'Error: Expected preset or plugin, not false, at `test.js`'
].join('\n')

Expand Down Expand Up @@ -232,12 +233,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const actual = cleanError(stderr(), 2)

const expected = [
'one.txt',
' 1:1 error Error: Missing `required`'
].join('\n')
const expected = ['one.txt', ' error Error: Missing `required`'].join(
'\n'
)

assert.deepEqual(
[error, code, actual],
Expand Down
9 changes: 5 additions & 4 deletions test/configuration-presets.js
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {engine} from '../index.js'
import {cleanError} from './util/clean-error.js'
import {noop} from './util/noop-processor.js'
import {spy} from './util/spy.js'

Expand All @@ -21,11 +22,11 @@ test('configuration-presets', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 3).join('\n')
const actual = cleanError(stderr(), 3)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `.foorc`',
' error Error: Cannot parse file `.foorc`',
'Expected a list or object of plugins, not `./preset`'
].join('\n')

Expand Down Expand Up @@ -90,11 +91,11 @@ test('configuration-presets', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const actual = cleanError(stderr(), 2)

const expected = [
'one.txt',
' 1:1 error Error: Could not find module `./plugin.js`'
' error Error: Could not find module `./plugin.js`'
].join('\n')

assert.deepEqual(
Expand Down
38 changes: 21 additions & 17 deletions test/configuration.js
Expand Up @@ -2,6 +2,7 @@ import assert from 'node:assert/strict'
import {sep} from 'node:path'
import test from 'node:test'
import {engine} from '../index.js'
import {cleanError} from './util/clean-error.js'
import {noop} from './util/noop-processor.js'
import {spy} from './util/spy.js'

Expand All @@ -21,11 +22,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')

const actual = cleanError(stderr(), 3)
const expected = [
'one.txt',
' 1:1 error Error: Cannot read given file `.foorc`'
' error Error: Cannot read given file `.foorc`',
'Error: ENOENT:…'
].join('\n')

assert.deepEqual(
Expand All @@ -51,13 +52,12 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const expected = [
'one.txt',
' 1:1 error Error: Cannot parse given file `.foorc`'
' error Error: Cannot parse given file `.foorc`'
].join('\n')
assert.deepEqual(
[error, code, actual],
[error, code, cleanError(stderr(), 2)],
[null, 1, expected],
'should fail fatally when custom rc files are empty'
)
Expand All @@ -80,12 +80,13 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 3).join('\n')
const actual = cleanError(stderr(), 4)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse given file `.foorc.js`',
'Error: Expected preset, not `false`'
' error Error: Cannot parse given file `.foorc.js`',
'Error: Expected preset, not `false`',
' at merge (configuration.js:1:1)'
].join('\n')

assert.deepEqual(
Expand All @@ -112,11 +113,13 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const actual = cleanError(stderr(), 4)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `.foorc.js`'
' error Error: Cannot parse file `.foorc.js`',
'Cannot import `.foorc.js`',
'Error: Broken config'
].join('\n')

assert.deepEqual(
Expand Down Expand Up @@ -263,11 +266,12 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const actual = cleanError(stderr(), 3)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `.foorc.yaml`'
' error Error: Cannot parse file `.foorc.yaml`',
'Unexpected scalar at node end at line 2, column 1:'
].join('\n')

assert.deepEqual(
Expand Down Expand Up @@ -340,11 +344,11 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')
const actual = cleanError(stderr(), 2)

const expected = [
'one.txt',
' 1:1 error Error: Cannot parse file `package.json`'
' error Error: Cannot parse file `package.json`'
].join('\n')

assert.deepEqual(
Expand Down Expand Up @@ -502,10 +506,10 @@ test('configuration', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 4).join('\n')
const actual = cleanError(stderr(), 4)
const expected = [
'packages' + sep + 'deep' + sep + 'one.txt',
' 1:1 error Error: Cannot parse file `package.json`',
' error Error: Cannot parse file `package.json`',
'Cannot import `plugin.js`',
'Error: Boom!'
].join('\n')
Expand Down
8 changes: 4 additions & 4 deletions test/ignore.js
Expand Up @@ -4,6 +4,7 @@ import {fileURLToPath} from 'node:url'
import {join, sep, relative} from 'node:path'
import test from 'node:test'
import {engine} from '../index.js'
import {cleanError} from './util/clean-error.js'
import {noop} from './util/noop-processor.js'
import {spy} from './util/spy.js'

Expand All @@ -25,15 +26,14 @@ test('ignore', async () => {
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 2).join('\n')

const expected = [
'one.txt',
' 1:1 error Error: Cannot read given file `.missing-ignore`'
' error Error: Cannot read given file `.missing-ignore`',
'Error: ENOENT:…'
].join('\n')

assert.deepEqual(
[error, code, actual],
[error, code, cleanError(stderr(), 3)],
[null, 1, expected],
'should fail fatally when given ignores are not found'
)
Expand Down

0 comments on commit 42f0823

Please sign in to comment.