Skip to content

Commit

Permalink
feat: ✨ use --filter + to filter for cwd's dependencies (#155)
Browse files Browse the repository at this point in the history
* feat: ✨ use --filter + to filter for cwd's dependencies

* fix: πŸ› better error message for --filter +

* fix: πŸ› dont read package file when filtering on cwd. Check package dirs instead

Co-authored-by: Folke Lemaitre <[email protected]>
  • Loading branch information
remorses and folke authored Jan 11, 2021
1 parent cfa0281 commit 4aa061a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import globrex from "globrex"
import { existsSync } from "fs"
import path from "path"
import { getPackage, findPackages, PackageJsonWithRoot } from "./package"
import { findPackages, getPackage, PackageJsonWithRoot } from "./package"
import { providers, WorkspaceProviderType } from "./workspace.providers"
import { existsSync } from "fs"

const defaultOptions = {
cwd: process.cwd(),
Expand Down Expand Up @@ -122,13 +122,27 @@ export class Workspace {

if (filter) {
const withDeps = filter.startsWith("+")
if (withDeps) filter = filter.slice(1)
let useCwd = false
if (withDeps) {
if (filter === "+" || filter === "+.") {
if (!existsSync(path.resolve(".", "package.json"))) {
throw new Error(
`'--filter +' requires a ./package.json file in the current working directory`
)
}
useCwd = true
} else {
filter = filter.slice(1)
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
const regex: RegExp = globrex(filter, { filepath: true, extended: true })
.regex
const names = new Set<string>()
ret.forEach((p) => {
if (
(useCwd && p.root == process.cwd()) ||
regex.test(p.name || "") ||
regex.test(path.relative(this.root, p.root).replace(/\\/gu, "/"))
) {
Expand Down

0 comments on commit 4aa061a

Please sign in to comment.