diff --git a/packages/filter-by-workspace-path/README.md b/packages/filter-by-workspace-path/README.md index 230d55c..c485ee6 100644 --- a/packages/filter-by-workspace-path/README.md +++ b/packages/filter-by-workspace-path/README.md @@ -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", ] } @@ -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 diff --git a/packages/filter-by-workspace-path/src/index.ts b/packages/filter-by-workspace-path/src/index.ts index a6a6fd0..3ad8dd7 100644 --- a/packages/filter-by-workspace-path/src/index.ts +++ b/packages/filter-by-workspace-path/src/index.ts @@ -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) =>