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

[cli] .ignore file support #4133

Merged
merged 7 commits into from
Sep 30, 2021
Merged

Conversation

Brianzchen
Copy link
Member

@Brianzchen Brianzchen commented Sep 3, 2021

Closes #4127.

This PR supports a new .ignore file that can be added to the root flow-typed dir of a project where your lib defs currently live. ie: ./flow-typed/.ignore

Here you can add lines of exclusions separated by new lines supporting explicit dependencies or scopes
eg the file may look like

@babel
@babel/
@testing-library/react
eslint

Other notes: Tested locally and works pretty well

@Brianzchen
Copy link
Member Author

@AndrewSouthpaw @gantoine

@gantoine gantoine self-assigned this Sep 3, 2021
Copy link
Contributor

@AndrewSouthpaw AndrewSouthpaw left a comment

Choose a reason for hiding this comment

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

Marvelous work! Excited to see this land in the system.

),
).toEqual(false);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Love the tests, great work.

.readFileSync(path.join(cwd, libdefDir, '.ignore'), 'utf-8')
.replace(/"/g, '')
.split('\n');
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we scope the catch to only handle the "couldn't find the file" error and otherwise throw? I'm always leery of just silencing all errors. (JS is much worse about being able to do this, which is a bummer...)

const ignoreDef = cur.trim();
if (ignoreDef === '') return acc;
// if we are looking to ignore a scope dir
if (ignoreDef.charAt(0) === '@' && ignoreDef.indexOf('/') === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean @foo/ would not ignore all subfolders? I think this would surprise some people... maybe we could make that more resilient and add a test for it?

@@ -90,6 +97,18 @@ export function getPackageJsonDependencies(
if (deps[pkgName]) {
console.warn(`Found ${pkgName} listed twice in package.json!`);
}
const pkgIgnored = ignoreDefs.reduce((acc, cur) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could use .some instead of .reduce and it'll both fail early and read more easily.

@Brianzchen
Copy link
Member Author

@AndrewSouthpaw Thanks for suggestions all done!

@gantoine gantoine merged commit f05fc82 into flow-typed:master Sep 30, 2021
@Brianzchen Brianzchen deleted the ignore-file branch September 30, 2021 04:34
@moroine
Copy link
Contributor

moroine commented Oct 4, 2021

Any idea when this will be fixed into a new flow-typed version?

@gantoine
Copy link
Member

gantoine commented Oct 4, 2021

I'll publish a release this weekend.

@gantoine gantoine added the cli Related to CLI tool label Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to CLI tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flow-typed ignore file
4 participants