Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching directory in files array does not include its contents #83

Closed
aomarks opened this issue Apr 6, 2022 · 0 comments · Fixed by #106
Closed

Matching directory in files array does not include its contents #83

aomarks opened this issue Apr 6, 2022 · 0 comments · Fixed by #106
Assignees

Comments

@aomarks
Copy link
Member

aomarks commented Apr 6, 2022

When using output, matching a directory implicitly includes all of the contents of that directory (though see #77 for a caveat with how that is currently broken with ! negations). That's because when we clean and cache, we use recursive operations like fs.rm and fs.cp.

However, with files, which is used for generating the cache key, we don't use recursive operations. We just read and hash the files that directly matched the glob.

files should be consistent with output. Matching a directory should implicitly match all of its contents. This is also consistent with the how the package.json files array, and .gitignore files work.

@aomarks aomarks self-assigned this Apr 12, 2022
aomarks added a commit that referenced this issue Apr 18, 2022
### Before

Before this PR, if the input `files` array matched a directory, we would **not** implicitly include all recursive children of that directory, even though we **would** effectively do that for `output` files.

In this example, `files` would not match anything, but `output` would match all recursive children of `lib/`. That meant if you change a file inside `src/`, the script would still be considered fresh.

{
  "ts": {
    "command": "tsc",
    "files": [
      "src"
    ],
    "output": [
      "lib"
    ]
  }
}

### After

After this PR, the `files` and `output` arrays behave the same. So, in the above example, `files` will now match all recursive children of `src/`.

### Explanation

The reason for the difference was that, while the globbing logic we did for `files` and `output` was more-or-less the same, the difference is in what we do with the results.

When we generate a script's state, we take each matched file, and hash it. If the file was not explicitly listed in the glob output, we would never see it.

When we clean or cache, however, we use recursive `fs.rm` and `fs.cp` operations, so it didn't matter that the glob results didn't explicitly list all recursive contents.

We now have an `expandDirectories` option, which modifies the given glob patterns to automatically include the recursive contents of every matching directory. We do this simply by adding a copy of each pattern with a `/**` suffix.

Fixes #83

### Also

- Factored the `glob` function out of `Executor` and into its own module, for organization and easier testing.

- Added checks for empty and blank strings in `Analyzer`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant