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

Windows path separator #69

Merged
merged 2 commits into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Test against these versions of Node.js
environment:
matrix:
# node.js
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "4.0"
- nodejs_version: "0.12"
- nodejs_version: "0.10"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm test

# Don't actually build.
build: off
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var resolveGlob = require('to-absolute-glob');
var globParent = require('glob-parent');
var path = require('path');
var extend = require('extend');
var sepRe = (process.platform === 'win32' ? /[\/\\]/ : /\/+/);
Copy link
Member

Choose a reason for hiding this comment

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

can this be new RegExp(path.sep)?

Copy link
Member Author

Choose a reason for hiding this comment

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

For win32 it's checking for either / or \ and replacing with the path.sep. This is because the user might have passed in / on windows in their glob pattern.


var gs = {
// Creates a stream for a single glob or filter
Expand Down Expand Up @@ -190,7 +191,19 @@ function globIsSingular(glob) {
}

function getBasePath(ourGlob, opt) {
return resolveGlob(globParent(ourGlob) + path.sep, opt);
var basePath;
var parent = globParent(ourGlob);

if (parent === '/' && opt && opt.root) {
basePath = path.join(opt.root);
Copy link
Member

Choose a reason for hiding this comment

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

would this be path.normalize since you aren't joining anything?

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, .normalize would be better. I'll change that.

} else {
basePath = resolveGlob(parent, opt);
}

if (!sepRe.test(basePath.charAt(basePath.length - 1))) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to use charAt than access the last element like an array?

Copy link
Member

Choose a reason for hiding this comment

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

Is testing the last character better than a $ in the RegExp?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is more habit for me with strings since it differentiates them from other arrays. I also read that it was faster in node.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is testing the last character better than a $ in the RegExp?

I think so because I don't think regex will start from the end of a string and test backwards so it'll be testing all the possible combinations leading up to the end. By only testing the last character, it reduces the amount of characters that the regex has to go through.

Copy link
Member

Choose a reason for hiding this comment

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

That's weird that RegExps with the "ends with" character would search the whole string.

Copy link
Member Author

Choose a reason for hiding this comment

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

search the whole string

I thought that too, but this talk is where I learned more about regexp. I'm assuming that it works this way when using $ too because the regexp compiler would need match patterns leading up to the $.

If I find the time, I may put together some benchmarks with these patterns.

basePath += path.sep;
}
return basePath;
}

module.exports = gs;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"index.js"
],
"scripts": {
"lint": "eslint . && jscs *.js test/",
"lint": "eslint . && jscs . test/",
"pretest": "npm run lint",
"test": "mocha",
"coveralls": "istanbul cover _mocha --report lcovonly && istanbul-coveralls"
Expand Down