mhassan1 / yarn-plugin-licenses

Yarn Berry plugin that adds `yarn licenses` commands
39 stars 11 forks source link

License file for only the current workspace #62

Closed jonathanj closed 3 months ago

jonathanj commented 3 months ago

I'm not sure if I'm doing something wrong, but I would expect that running yarn licenses generate-disclaimer within a specific workspace would generate only the licenses applicable to that workspace.

However, I'm seeing dependencies that exist in other (unrelated) workspaces within the project.

# Check current workspace
$ cat package.json | jq '.name'
"@org/app-name"

# Confirm that a given dependency is not used within the current workspace
$ yarn why @castleio/react-native-castle | grep '@org/app-name'

# Generate licenses for the current workspace, expecting to find no results
$ yarn licenses generate-disclaimer --production | grep '@castleio/react-native-castle'
The following software may be included in this product: @castleio/react-native-castle. A copy of the source code may be downloaded from https://github.com/castle/castle-react-native. This software contains the following license and notice below:

The relevant part of my .yarnrc.yml:

  - checksum: 55d54388ad171beb0a12e808e375d3c5f8632556a2eed7d03b38b8304514b07831ef7a9f9e78410287313940d107ea4634cfa2933e08459a165c432cea55bdba
    path: .yarn/plugins/@yarnpkg/plugin-licenses.cjs
    spec: "https://raw.githubusercontent.com/mhassan1/yarn-plugin-licenses/v0.13.1/bundles/@yarnpkg/plugin-licenses.js"

If what I'm asking for is new behaviour, would you consider a PR that adds support for this, maybe via a --include a,b,c type option (to follow yarn workspaces foreach --include)?

mhassan1 commented 3 months ago

You should be able to achieve per-workspace output by first executing yarn workspaces focus .... Let me know if that works.

Maybe we could add support for a --focus ... flag that acts like yarn workspaces focus .... One potential downside I see is that focus will include workspaces that are dependencies of the focused workspace, which may not be desired.

mhassan1 commented 3 months ago

@jonathanj I've put up a PR for a new --focus flag. Can you try it out?

yarn plugin import https://raw.githubusercontent.com/mhassan1/yarn-plugin-licenses/focus/bundles/@yarnpkg/plugin-licenses.js
yarn licenses list --focus <workspace-a> --focus <workspace-b>
mhassan1 commented 3 months ago

@jonathanj ☝️ Any thoughts?

jonathanj commented 3 months ago

@mhassan1 Sorry for the late reply. I needed this for work and ended up forking the project and implementing --include with minimatch (like Yarn does), as well as a --json flag to output an array of license objects.

I tried out your focus flag and it works well, thank you! I'm sure anyone with a monorepo would find this useful, as I have.

Unrelated to this issue, I'm still dependent on my --json output (it just outputs JSON, not NDJSON), is there some interest in adding this to the plugin?

mhassan1 commented 3 months ago

@jonathanj Thanks! I'll release that PR.

Please create a new issue for the JSON request.