Skip to content

Commit

Permalink
fix: Expand glob patterns in workspace.members (#626)
Browse files Browse the repository at this point in the history
* fix: Expand glob patterns in workspace.members

* log

* onlyDirectories

* comapre with toml path

* test deep: 1

* i hate glob patterns

* rm testfile

* remove log

* Update fix-member-globs.md [skip ci]
  • Loading branch information
FabianLars committed Nov 28, 2023
1 parent b41e1f2 commit b87a544
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-member-globs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
action: 'patch'
---

The action now correctly handles glob patterns in the workspace.members config (example: `members = ["bin/*"]`).
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/external-modules.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare module 'glob-gitignore';
//declare module 'glob-gitignore';
declare module 'lodash.merge';
20 changes: 15 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,25 @@ export function getTauriDir(root: string): string | null {

export function getWorkspaceDir(dir: string): string | null {
const rootPath = dir;

while (dir.length && dir[dir.length - 1] !== sep) {
const manifestPath = join(dir, 'Cargo.toml');
if (existsSync(manifestPath)) {
const toml = parseToml(readFileSync(manifestPath).toString());
// @ts-expect-error
const toml = parseToml(readFileSync(manifestPath).toString()) as {
workspace?: { members?: string[]; exclude?: string[] };
};
if (toml.workspace?.members) {
// @ts-expect-error
const members: string[] = toml.workspace.members;
if (members.some((m) => resolve(dir, m) === rootPath)) {
const ignore = ['**/target', '**/node_modules'];
if (toml.workspace.exclude) ignore.push(...toml.workspace.exclude);

const memberPaths = globbySync(toml.workspace.members, {
cwd: dir,
ignore,
expandDirectories: false,
onlyFiles: false,
});

if (memberPaths.some((m) => resolve(dir, m) === rootPath)) {
return dir;
}
}
Expand Down

0 comments on commit b87a544

Please sign in to comment.