Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Durand committed Apr 5, 2024
1 parent cade799 commit 340e057
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
19 changes: 10 additions & 9 deletions packages/filter-by-workspace-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function shouldOmitCommit(currentWorkspace: string, commit: IExtendedCommit, log

const wsDir = path.join(currentWorkspace, path.sep)

const atLeastOneFileInCurrentDir = commit.files.find((file) => inFolder(wsDir, file))
const atLeastOneFileInCurrentDir = commit.files.find((file) => inFolder(wsDir, file))

if (!atLeastOneFileInCurrentDir) {
logger.verbose.log(`All files are outside the current workspace directory ('${wsDir}'). Omitting commit '${commit.hash}'.`)
Expand All @@ -21,7 +21,9 @@ function shouldOmitCommit(currentWorkspace: string, commit: IExtendedCommit, log
return true
}

logger.verbose.log(`At least one file is in the current workspace ('${atLeastOneFileInCurrentDir}' in '${wsDir}'). Including commit '${commit.hash}'.`)
logger.verbose.log(
`At least one file is in the current workspace ('${atLeastOneFileInCurrentDir}' in '${wsDir}'). Including commit '${commit.hash}'.`
)
return false
}
}
Expand Down Expand Up @@ -51,16 +53,15 @@ export default class FilterByWorkspacePathPlugin implements IPlugin {
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 resolved= workspaceDeps[Object.keys(workspaceDeps)[0] as any].resolved
// resolved looks like 'file:../../packages/filter-by-workspace-path'
const npm_relative_workspace_path = String(resolved).split(":",2)[1]
currentWorkspace = path.resolve(currentDir,npm_relative_workspace_path)
const resolved = workspaceDeps[Object.keys(workspaceDeps)[0] as any].resolved
// 'resolved' var looks like 'file:../../packages/filter-by-workspace-path'
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const relativeWorkspacePath = String(resolved).split(':', 2)[1]
currentWorkspace = path.resolve(currentDir, relativeWorkspacePath)
}

auto.hooks.onCreateLogParse.tap(this.name, (logParse) => {
logParse.hooks.omitCommit.tap(this.name, (commit) =>
shouldOmitCommit(currentWorkspace, commit, auto.logger) ? true : undefined
)
logParse.hooks.omitCommit.tap(this.name, (commit) => (shouldOmitCommit(currentWorkspace, commit, auto.logger) ? true : undefined))
})

auto.hooks.onCreateRelease.tap(this.name, (release) => {
Expand Down
11 changes: 5 additions & 6 deletions packages/filter-by-workspace-path/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import LogParse from '@auto-it/core/dist/log-parse'
import { makeHooks, makeLogParseHooks, makeReleaseHooks } from '@auto-it/core/dist/utils/make-hooks'
import createLog from '@auto-it/core/dist/utils/logger'
import Release from '@auto-it/core/dist/release'
import FilterByWorkspacePathPlugin from '../src'
import { ProjectFilteringPluginOptions } from '../src'
import FilterByWorkspacePathPlugin, { ProjectFilteringPluginOptions } from '../src'

const setup = (plugin_options: ProjectFilteringPluginOptions) => {
const plugin = new FilterByWorkspacePathPlugin(plugin_options)
const setup = (pluginOptions: ProjectFilteringPluginOptions) => {
const plugin = new FilterByWorkspacePathPlugin(pluginOptions)
const hooks = makeHooks()
const logger = createLog()
const logParseHooks = makeLogParseHooks()
Expand All @@ -26,7 +25,7 @@ const setup = (plugin_options: ProjectFilteringPluginOptions) => {
}

describe('Test plugin omits commits when using NPM', () => {
const hooks = setup({"npm":true})
const hooks = setup({ npm: true })

it('should not filter the commit single file', async () => {
const commit = makeCommitFromMsg('foo', {
Expand Down Expand Up @@ -96,7 +95,7 @@ describe('Test plugin omits commits when using NPM', () => {
})

describe('Test plugin omits commits without NPM', () => {
const hooks = setup({"npm":false})
const hooks = setup({ npm: false })

it('should not filter the commit single file', async () => {
const commit = makeCommitFromMsg('foo', {
Expand Down

0 comments on commit 340e057

Please sign in to comment.