Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add npm option to allow usage of 'filter-by-workspace-path-plugin' without npm #18

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/filter-by-workspace-path/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To start using this plugin, add it to your `.autorc` config, for example:
```json
{
"plugins": [
"@restfulhead/auto-plugin-filter-by-workspace-path",
["@restfulhead/auto-plugin-filter-by-workspace-path",{"npm":true}],
"npm",
]
}
Expand All @@ -22,6 +22,13 @@ directory, then the changelog will only include pull requests that contain files

However, carefully read the following caveats section.

## Supported Config

| Parameter | Description | Default |
| ----------------------- | ---------------------------------------------------------- | -------- |
| `npm` | Boolean to use NPM workspaces or not. In case you're using auto without NPM, specify `"npm": false`, this way the plugin will filter out changes outside of the current folder `auto` is run from. | `true` |


## Caveats

* Note that this plugin also omits commits that
Expand Down
25 changes: 21 additions & 4 deletions packages/filter-by-workspace-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,33 @@ function shouldOmitCommit(currentDir: string, currentWorkspace: string, commit:
}
}

export interface ProjectFilteringPluginOptions {
/** Path from the repo root to project we are filtering on */
npm: boolean
}

export default class FilterByWorkspacePathPlugin implements IPlugin {
/** The name of the plugin */
name = 'filter-by-workspace-path-plugin'

/** The options of the plugin */
readonly options: ProjectFilteringPluginOptions

/** Initialize the plugin with it's options */
constructor(options: ProjectFilteringPluginOptions = { npm: true }) {
this.options = options
}

apply(auto: Auto): void {
const currentDir = path.resolve('.')
const npmResult = execSync('npm ls --omit=dev --depth 1 -json', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] })
const workspaceDeps: any = JSON.parse(npmResult).dependencies
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const currentWorkspace = workspaceDeps[Object.keys(workspaceDeps)[0] as any].resolved.substring(11)
let currentWorkspace = currentDir

if (this.options.npm) {
const npmResult = execSync('npm ls --omit=dev --depth 1 -json', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] })
const workspaceDeps: any = JSON.parse(npmResult).dependencies
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
currentWorkspace = workspaceDeps[Object.keys(workspaceDeps)[0] as any].resolved.substring(11)
}

auto.hooks.onCreateLogParse.tap(this.name, (logParse) => {
logParse.hooks.omitCommit.tap(this.name, (commit) =>
Expand Down
Loading