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

Adding .gitignore support in project-archiver #463

Merged
merged 5 commits into from
Jun 28, 2020
Merged

Adding .gitignore support in project-archiver #463

merged 5 commits into from
Jun 28, 2020

Conversation

aalykiot
Copy link
Member

@aalykiot aalykiot commented Jun 22, 2020

This PR adds .gitignore file support in nodeshift's project archiver. #460

Two new NPM packages have been used:

  • parse-gitignore: transforms .gitignore's contents into a javascript array.
  • minimatch: performs some filename checks according to given rules (same module NPM uses internally for the same job)

Maybe we can work out some custom implementation for the .gitignore parser if we want to reduce the amount of 3rd party modules that we use.

.dockerignore support should be 2-3 extra lines of code since the core implementation is done.

@lholmquist @helio-frota I'm just pinging you here cause I can't add any reviewers for this PR

If you guys think everything is OK I'll continue with the .dockerignore support and tests.

@lholmquist
Copy link
Member

@alexalikiotis I think this looks good so far. Looks like the parse-gitignore has no dependencies, so that is good.

I would go for it for adding the tests

];
// Parse ignore files
const gitignoreRules = await helpers.parseIgnoreFile(`${config.projectLocation}/.gitignore`);
exclusionRules.push.apply(exclusionRules, gitignoreRules);
Copy link
Member

Choose a reason for hiding this comment

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

you can also merge arrays like this too: const merged = [...array1, ...array2];

I wouldn't change this now, since there are other places in this file that do the same thing you are doing. I think when i first created nodeshift, that syntax wasn't available yet. I can add another issue for use to look at using spread to merge things

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I used this method so I'll be consistent with the rest of the file.

const file = await readfile(path);
return parse(file);
} catch (e) {
return [];
Copy link
Member

Choose a reason for hiding this comment

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

Not following why this needs to return an empty array in case of error, other than that seems good.

Copy link
Member

Choose a reason for hiding this comment

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

i don't think we can assume that a user is using git, so if they are not, we don't want to just fail, and the empty array plays into the "array merge" in the project-archiver

Copy link
Member

Choose a reason for hiding this comment

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

thanks for the information 👍

@aalykiot
Copy link
Member Author

@lholmquist I've done some small updates and wrote some tests. I think the PR it's good to go!

lholmquist
lholmquist previously approved these changes Jun 26, 2020
Copy link
Member

@lholmquist lholmquist left a comment

Choose a reason for hiding this comment

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

@alexalikiotis nice job.

The only thing is that the exclusion rules could have multiple of the same value, but i don't think that is really to much of a big deal.

@lholmquist lholmquist self-requested a review June 26, 2020 13:50
@lholmquist lholmquist dismissed their stale review June 26, 2020 13:51

Just noticed something that i think we need to address

Copy link
Member

@lholmquist lholmquist left a comment

Choose a reason for hiding this comment

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

It looks like right now, it will always do the gitignore and dockerignore even if a users uses the files property in the package.json.

I think with that case(using the file props), then we should skip looking at the ignore files since they are explicitly saying they want only these files

@aalykiot
Copy link
Member Author

aalykiot commented Jun 26, 2020

@lholmquist are you sure ?? Cause the project-archiver checks (line 32) if the files property is specified. Only if it's not, continues to the default, gitignore, and dockerignore rules.

@aalykiot
Copy link
Member Author

aalykiot commented Jun 26, 2020

The only thing is that the exclusion rules could have multiple of the same value, but i don't think that is really to much of a big deal.

I'll try to fix that before we merge it.

@lholmquist
Copy link
Member

@lholmquist are you sure ?? Cause the project-archiver checks (line 32) if the files property is specified. Only if it's not, continues to the default, gitignore, and dockerignore rules.

nvm, i was looking at it in the github preview, so that part wasn't expanded 🤦

Copy link
Member

@lholmquist lholmquist left a comment

Choose a reason for hiding this comment

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

LGTM

@lholmquist lholmquist merged commit 3f7d48d into nodeshift:master Jun 28, 2020
@aalykiot aalykiot deleted the project-archiver branch June 29, 2020 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants