Skip to content

Commit 1d71d21

Browse files
authored
fix: fix globbing on Windows (#57)
* fix: fix globbing on Windows * use slash helper Signed-off-by: Chawye Hsu <[email protected]>
1 parent d83a6a7 commit 1d71d21

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/getPackagePaths.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const getManifest = require("./getManifest");
22
const glob = require("./glob");
3+
const { slash } = require("./utils");
34
const path = require("path");
45
const { getPackagesSync } = require("@manypkg/get-packages");
56

@@ -29,7 +30,7 @@ function getPackagePaths(cwd, ignorePackages = null) {
2930
}
3031

3132
// remove cwd from results
32-
const packages = workspace.packages.map((p) => path.relative(cwd, p.dir));
33+
const packages = workspace.packages.map((p) => slash(path.relative(cwd, p.dir)));
3334

3435
// If packages to be ignored come from CLI, we need to combine them with the ones from manifest workspaces
3536
if (Array.isArray(ignorePackages)) packages.push(...ignorePackages.map((p) => `!${p}`));

lib/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,22 @@ function getLatestVersion(versions, withPrerelease) {
5252
return versions.filter((version) => withPrerelease || !prerelease(version)).sort(rcompare)[0];
5353
}
5454

55+
// https://github.com/sindresorhus/slash/blob/b5cdd12272f94cfc37c01ac9c2b4e22973e258e5/index.js#L1
56+
function slash(path) {
57+
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
58+
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex
59+
60+
if (isExtendedLengthPath || hasNonAscii) {
61+
return path;
62+
}
63+
64+
return path.replace(/\\/g, "/");
65+
}
66+
5567
module.exports = {
5668
tagsToVersions,
5769
getHighestVersion,
5870
getLowestVersion,
5971
getLatestVersion,
72+
slash,
6073
};

0 commit comments

Comments
 (0)