Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Improve UX: Support glob patterns in triple-slash comment #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

YiranJing
Copy link

@YiranJing YiranJing commented Dec 3, 2022

Motivation

The dependency-tree's directive can be the whole folder, not just the single file.

To detect the folder dependency, we want the glob patterns can be used in the triple-slash comment like

/// <dependency-tree depends-on="../../../../tools/build/python/lib/logs/**/*" />

The problem

The glob patterns detection isn't supported by default. To use it, users have to explicitly providing ReferenceTransformFn like https://github.com/Canva/canva/pull/325312/commits/0190fcbf2796c6b3bd9984d839683400eeb595f4, which isn't good user experience.

Solution

Add a reference transformer as an automatic glob pattern detection.

@CLAassistant
Copy link

CLAassistant commented Dec 3, 2022

CLA assistant check
All committers have signed the CLA.

Comment on lines +94 to +127
#### Example

```bash
root_dir/
|- index.js
|- dep1.sh
|- util.ts
|- dir1/
|- dep5.py
|- dir2/
|- dep6.md
```

```typescript
// root_dir/util.ts

/// <dependency-tree depends-on="./dep1.sh" />
///<dependency-tree depends-on="./dir1/**/*" />
```

```typescript
// index.js
const dependencyTree = new DependencyTree(['root_dir']);
const result = await dependencyTree.gather();
const dependencies = result.resolved;
//{
// "root_dir/util.ts" => Set {
// "root_dir/dep1.sh",
// "root_dir/dir1/dep5.py",
// "root_dir/dir1/dir2/dep6.md",
// },
//}
```

Copy link
Author

@YiranJing YiranJing Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the readme with a complete example. (make it easier for new users to understand)

Comment on lines -168 to +184
dependencyTree.transformReference(dependsOn, file),
transformReference(dependsOn, file),
Copy link
Author

@YiranJing YiranJing Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will block user provide their own custom transformReference function.

🤔 but I don't think users need an extra transformer for the depend-on=xxx scenario.

@YiranJing YiranJing changed the title Support default glob patterns in triple-slash comment Improve UX: Support default glob patterns in triple-slash comment Dec 3, 2022
@YiranJing YiranJing changed the title Improve UX: Support default glob patterns in triple-slash comment Improve UX: Support glob patterns in triple-slash comment Dec 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants