Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feature: add support for ignoring filepaths via micromatch globs#28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

hydrosquall
Copy link
Contributor

@hydrosquallhydrosquall commentedAug 15, 2021
edited
Loading

Motivation

Changes

  • Addresses + documents the feature requests fromfeature idea: excluded_filenames #21 andexcluded_paths is Sort of Not Working #27 with a newexcluded_globs option. Note that this can technically be used instead ofexcluded_paths, but I didn't want to break anyone's existing workflow by modifying an existing option.
  • Added unit tests to test this change + a github action to run the tests
  • Replaced manual string concatenation withpath.join() so that this will work on Windows

Testing

  • I was leaning on unit tests, I haven't run this set of changes personally (not sure how to test a GH action locally).@swharden's idea to add aCONTRIBUTING.md is a good one for the long term.
  • Wasn't sure if the builtindex.js was supposed to get checked into the repo, or gitignored, but recent PRs seem to be updating it so I left it as-is.

Notes

  • I triedminimatch,micromatch,picomatch, andnanomatch.nanomatch was the only one that worked with the leading./ (minimatch,micromatch), but it was last updated in 2018, isnot as performant, and is not as full featured as micromatch.
  • I think micromatch syntax is probably a safe bet given its widespread usage (webpack, babel, eslint, etc).
  • There's not much incentive to be supportingrelative paths, since repositories shouldn't be ever trying to access parent directories, I think we'd rather use a more popular globbing library than use
  • During the brief period where nanomatch seemed like a good option, I came up with a TS file:Typecript typings micromatch/nanomatch#21 (comment)

swharden reacted with thumbs up emojiswharden reacted with rocket emoji
@hydrosquallhydrosquall changed the titlefeature: add support for ignoring globfeature: add support for ignoring filepaths via globAug 15, 2021
@hydrosquallhydrosquallforce-pushed thecameron.yick/feature/ignore-files-and-folders branch from960f6fd to3c64a7eCompareAugust 15, 2021 00:16
@@ -1,15 +1,18 @@
import fs from "fs";
import * as nodePath from 'path';
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

NamednodePath to avoid colliding with the existing usage ofpath as a variable name.

@@ -18,19 +18,33 @@ Default: diagram.svg

## `excluded_paths`

A list of paths to exclude from the diagram, separated by commas.
A list of paths tofolders toexclude from the diagram, separated by commas.
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Technically this also worked for paths but only if they were immediate children ofroot_dir (this is whypackage.json worked, butsrc/package.json did not. Rather than explain this nuance, I think it'll be simpler to just only use this config for folders, and nudge people towards mostly using globs instead.

},
"dependencies": {
"@actions/core": "^1.4.0",
"@actions/exec": "^1.1.0",
"d3": "^7.0.0",
"esbuild": "^0.12.15",
"husky": "^7.0.1",
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I figured it was probably a typo to have 2 versions of the same library.

@@ -0,0 +1,19 @@
{
"compilerOptions": {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is trimmed down from the defaults provided bytsc --init, and was included for the benefit of the test-runner.

tsconfig.json Outdated

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This was too strict, having all of these on was catching 100s of errors.

@hydrosquallhydrosquall changed the titlefeature: add support for ignoring filepaths via globfeature: add support for ignoring filepaths via micromatch globsAug 15, 2021
@@ -22,14 +22,19 @@ const main = async () => {
core.endGroup()


const rootPath = core.getInput("root_path") || "./";
const rootPath = core.getInput("root_path") || ""; // Micro and minimatch do not support paths starting with ./
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to also remove any leading./ params, to prevent from breaking existing workflows

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I thought about this - what do you think about a choice between

  1. Quitting the script early if the path starts with./ and asking the user to remove it
  2. Quietly removing it if it's detected

I think doing 2 automatically is a smoother migration because it introduces a quiet side effect, but 1 is simpler for us to maintain. Otherwise, people may get confused when seeing some configs start with./ and some without.

@Wattenberger
Copy link
Contributor

this is wonderful@hydrosquall, thanks for digging in here! One question: what's your reasoning behind havingexcluded_pathsandexcluded_globs as separate params? Is it possible to have one combined param?

@hydrosquall
Copy link
ContributorAuthor

this is wonderful@hydrosquall, thanks for digging in here! One question: what's your reasoning behind havingexcluded_pathsandexcluded_globs as separate params? Is it possible to have one combined param?

Hi, thank you! I had a few reasons for going with this

  1. Backwards compatibility- it was safer to add a new param with new behavior than to modify an existing param.
  2. excluded_paths is slightly terser/beginner friendly: to express the current filters asnode_modules, you'd need to writenode_modules/**. It's also slightly more performant to do an excluded_path check (testing set membership vs compiling and running a regular expression), but this is probably a negligible cost for most cases.
  3. excluded_paths matches the behavior of the web app file filters, in case people are copy pasting their exclusion filters from there (as far as I can tell, that's a separate codebase, otherwise I would have updated the matching logic in both spots).

With all of that said, I would be in favor of using the glob param, assuming that

  • it's OK to drop the current param (maybe we leave the old one in as a no-op, and throw an error or warning if people try to set it)
  • our target users are familiar with the idea of whatglobs are
  • having different filtering params than the web app is OK

const children = [];

for (const fileOrFolder of filesOrFolders) {
const fullPath = nodePath.join(rootPath, fileOrFolder);
Copy link
Contributor

Choose a reason for hiding this comment

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

I thinkrootPath needs to bepath, to include the parents recursively?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You're absolutely right, that was a bug :)

@Wattenberger
Copy link
Contributor

I did some testing and made some small tweaks when running into bugs. It works, but ignores folders - I'm thinking because of the comment above.

FYI you can test the Action by pointing it at any repo@branch:
uses: hydrosquall/repo-visualizer@cameron.yick/feature/ignore-files-and-folders
(eg herehttps://github.com/Wattenberger/kumiko/blob/master/.github/workflows/diagram.yml#L14)

@hydrosquall
Copy link
ContributorAuthor

Thanks for fixing the yaml /./ prefix errors - they look good. I made the adjustment to thefullPath calculation, and am optimistic this should fix it since it restores the previous behavior at

constinfo=fs.statSync(path+"/"+file);
.

Also, thanks for the tip about how to test github actions - I will use this to try out dev builds going forward.

@Wattenberger
Copy link
Contributor

Wonderful, all looks great! Thanks!

hydrosquall reacted with hooray emoji

@WattenbergerWattenberger merged commit0cd1a63 intogithubocto:mainAug 17, 2021
@hydrosquallhydrosquall deleted the cameron.yick/feature/ignore-files-and-folders branchAugust 20, 2021 03:33
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@WattenbergerWattenbergerAwaiting requested review from Wattenberger

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@hydrosquall@Wattenberger

[8]ページ先頭

©2009-2025 Movatter.jp