Skip to content

Commit

Permalink
Fix bug where monorepo packages were not configured
Browse files Browse the repository at this point in the history
This fixes a bug, where deep `package.json`s without config,
which were previously ignored and higher `package.json`s used,
were instead seen as an unconfigured project.

This bug was introduced in 9.1.0.

Related-to: GH-64.
Related-to: 7f91757.
  • Loading branch information
wooorm committed Jun 25, 2022
1 parent 6c10502 commit 1c11663
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/find-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {wrap} from 'trough'
const debug = createDebug('unified-engine:find-up')

/**
* @template Value
* @template {object & {filePath?: string}} Value
*/
export class FindUp {
/**
Expand Down Expand Up @@ -193,9 +193,11 @@ export class FindUp {
error.message
)
)
} else {
} else if (result && result.filePath) {
debug('Read file `%s`', fp)
found(null, result)
} else {
next()
}
})(buf, fp)
}
Expand Down
30 changes: 29 additions & 1 deletion test/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {spy} from './util/spy.js'
const fixtures = new URL('fixtures/', import.meta.url)

test('configuration', (t) => {
t.plan(15)
t.plan(16)

t.test('should fail fatally when custom rc files are missing', (t) => {
const stderr = spy()
Expand Down Expand Up @@ -483,4 +483,32 @@ test('configuration', (t) => {
}
)
})

t.test('should ignore unconfigured `packages.json`', (t) => {
const stderr = spy()

t.plan(1)

engine(
{
processor: noop(),
cwd: new URL('config-monorepo-package/', fixtures),
streamError: stderr.stream,
files: ['.'],
packageField: 'fooConfig',
extensions: ['txt']
},
(error, code) => {
const actual = stderr().split('\n').slice(0, 4).join('\n')
const expected = [
'packages' + sep + 'deep' + sep + 'one.txt',
' 1:1 error Error: Cannot parse file `package.json`',
'Cannot import `plugin.js`',
'Error: Boom!'
].join('\n')

t.deepEqual([error, code, actual], [null, 1, expected], 'should report')
}
)
})
})
8 changes: 8 additions & 0 deletions test/fixtures/config-monorepo-package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "module",
"fooConfig": {
"plugins": [
"./plugin.js"
]
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "module",
"#": "this `package.json` does not have a config field"
}
1 change: 1 addition & 0 deletions test/fixtures/config-monorepo-package/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('Boom!')

0 comments on commit 1c11663

Please sign in to comment.