Skip to content

Commit

Permalink
fix: fix globbing on Windows (#57)
Browse files Browse the repository at this point in the history
* fix: fix globbing on Windows
* use slash helper

Signed-off-by: Chawye Hsu <chawyehsu@hotmail.com>
  • Loading branch information
chawyehsu committed Dec 29, 2021
1 parent d83a6a7 commit 1d71d21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/getPackagePaths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const getManifest = require("./getManifest");
const glob = require("./glob");
const { slash } = require("./utils");
const path = require("path");
const { getPackagesSync } = require("@manypkg/get-packages");

Expand Down Expand Up @@ -29,7 +30,7 @@ function getPackagePaths(cwd, ignorePackages = null) {
}

// remove cwd from results
const packages = workspace.packages.map((p) => path.relative(cwd, p.dir));
const packages = workspace.packages.map((p) => slash(path.relative(cwd, p.dir)));

// If packages to be ignored come from CLI, we need to combine them with the ones from manifest workspaces
if (Array.isArray(ignorePackages)) packages.push(...ignorePackages.map((p) => `!${p}`));
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,22 @@ function getLatestVersion(versions, withPrerelease) {
return versions.filter((version) => withPrerelease || !prerelease(version)).sort(rcompare)[0];
}

// https://github.com/sindresorhus/slash/blob/b5cdd12272f94cfc37c01ac9c2b4e22973e258e5/index.js#L1
function slash(path) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex

if (isExtendedLengthPath || hasNonAscii) {
return path;
}

return path.replace(/\\/g, "/");
}

module.exports = {
tagsToVersions,
getHighestVersion,
getLowestVersion,
getLatestVersion,
slash,
};

0 comments on commit 1d71d21

Please sign in to comment.