Skip to content

Commit

Permalink
fix: add explicit error when files is missing from package.json (oc…
Browse files Browse the repository at this point in the history
…lif#1577) (oclif#1578)

* fix: add explicit error when `files` is missing from package.json (oclif#1577)

If `files` is missing from the package.json, `oclif manifest` would throw an unhelpful error

```
TypeError: Cannot read properties of undefined (reading 'find')
```

This makes sure that the user knows how to fix the issue

* chore: compilation error

---------

Co-authored-by: Mathieu Dutour <[email protected]>
  • Loading branch information
mdonnalley and mathieudutour authored Oct 15, 2024
1 parent 000aa0b commit 2ebfb00
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/commands/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ export default class Manifest extends Command {
await plugin.load()
}

if (!Array.isArray(plugin.pjson.files)) {
this.error('The package.json has to contain a "files" array', {
ref: 'https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files',
suggestions: [
'Add a "files" property in the package.json listing the paths to the files that should be included in the published package',
],
})
}

const dotfile = plugin.pjson.files.find((f: string) => f.endsWith('.oclif.manifest.json'))
const file = path.join(plugin.root, `${dotfile ? '.' : ''}oclif.manifest.json`)

Expand Down

0 comments on commit 2ebfb00

Please sign in to comment.