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

fix: run tests on windows #127

Merged
merged 5 commits into from
Nov 24, 2020

Conversation

achingbrain
Copy link
Contributor

There are two things that break this module on windows:

  1. Quoting globbed strings to stop unix shells doing path expansion
    results in the quotes being passed through to globby which breaks
  2. Normalising the paths replaces backlashes with forward slashes on
    Windows. Because the code passes them to globby twice, the second
    time round nothing is matched because it doesn't understand forward
    slashes as path separators

So in this PR

  1. Strip any leading and trailing quotes from strings
  2. Do the path normalisation to dedupe globby's output but return the
    original strings instead

@achingbrain
Copy link
Contributor Author

achingbrain commented Nov 13, 2020

Not sure why GH actions hasn't run CI for this, but hey look, it ran in my fork: https://github.com/achingbrain/dependency-check/actions/runs/362928866

There are two things that break this module on windows:

1. Quoting globbed strings to stop unix shells doing path expansion
  results in the quotes being passed through to globby which breaks
2. Normalising the paths replaces backlashes with forward slashes on
  Windows. Because the code passes them to globby twice, the second
  time round nothing is matched because it doesn't understand forward
  slashes as path separators

So in this PR

1. Strip any leading and trailing quotes from strings
2. Do the path.resolve dance to dedupe globby's output but return the
  original strings instead of the resolved strings
@voxpelli voxpelli self-requested a review November 24, 2020 10:18
Copy link
Collaborator

@voxpelli voxpelli left a comment

Choose a reason for hiding this comment

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

Thanks for this! Awesome that you took time to get this set up correctly for windows 🙏

Added some helpful comments, I hope you don't mind, not meant to criticize you in any way.

cli.js Outdated Show resolved Hide resolved
index.js Outdated
Comment on lines 37 to 45
const paths = Object.values(resolvedEntries.reduce((result, entry) => {
// Globby yields unix-style paths.
const normalized = path.resolve(entry)

if (!result[normalized]) {
result[normalized] = true
result[normalized] = entry
}

return result
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes the normalized variable rather redundant, no? So we could just skip this entire reduce and just return resolvedEntries straight up?

Makes me wonder why its originally been added there at all 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I read it, the reason you resolve the path is to make all the requires absolute and then use the result hash to dedupe them?

Copy link
Collaborator

@voxpelli voxpelli Nov 24, 2020

Choose a reason for hiding this comment

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

That's true, good catch.

Because the code passes them to globby twice, the second time round nothing is matched because it doesn't understand forward slashes as path separators

I'm thinking that we maybe instead should ensure that whatever globby is given is always using the right slashes? Adding a entry.replace('\', '/') to

async function resolveGlobbedPath (entries, cwd) {
if (typeof entries === 'string') entries = [entries]
debug('globby resolving', entries)
const resolvedEntries = await globby(entries, {
cwd,
absolute: true,
expandDirectories: false
})
What do you think? Then we will keep the OS-type path separators in the result of the method, which should be preferable considering the other file interactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to work with replacing the slashes before passing the entries to globby, I've updated the PR.

Copy link
Collaborator

@voxpelli voxpelli left a comment

Choose a reason for hiding this comment

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

Splendid!

@voxpelli voxpelli merged commit 717c1a7 into dependency-check-team:master Nov 24, 2020
@achingbrain achingbrain deleted the fix/run-on-windows branch November 24, 2020 12:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants