mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 15:48:06 -05:00
fix(modules-yaml): don't crash on empty file (#7508)
This commit is contained in:
5
.changeset/nervous-beds-refuse.md
Normal file
5
.changeset/nervous-beds-refuse.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/modules-yaml": patch
|
||||
---
|
||||
|
||||
readModulesYaml should not crash on empty file.
|
||||
@@ -38,6 +38,7 @@ export async function readModulesManifest (modulesDir: string): Promise<Modules
|
||||
let modules!: Modules
|
||||
try {
|
||||
modules = await readYamlFile<Modules>(modulesYamlPath)
|
||||
if (!modules) return modules
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
throw err
|
||||
|
||||
0
pkg-manager/modules-yaml/test/fixtures/empty-modules-yaml/.modules.yaml
vendored
Normal file
0
pkg-manager/modules-yaml/test/fixtures/empty-modules-yaml/.modules.yaml
vendored
Normal file
@@ -113,3 +113,8 @@ test('readModulesManifest() should create a node_modules directory if makeModule
|
||||
await writeModulesManifest(modulesDir, modulesYaml, { makeModulesDir: true })
|
||||
expect(await readModulesManifest(modulesDir)).toEqual(modulesYaml)
|
||||
})
|
||||
|
||||
test('readModulesManifest does not fail on empty file', async () => {
|
||||
const modulesYaml = await readModulesManifest(path.join(__dirname, 'fixtures/empty-modules-yaml'))
|
||||
expect(modulesYaml).toBeUndefined()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user