mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 13:13:37 +08:00
Some packages have vulnerabilities, which can be fixed with "npm audit fix". Unfortunately not all packages can be fixed, as they are transitive dependencies that require major breaking change updates from other packages. Luckily we are not affected by these vulnerabilities in our frontend code. R=aerotwist@chromium.org Bug: none Change-Id: I728411390ebbcb5240045aae5b67b4d8cfc540fb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2949048 Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
var isGlob = require('is-glob');
|
|
var pathPosixDirname = require('path').posix.dirname;
|
|
var isWin32 = require('os').platform() === 'win32';
|
|
|
|
var slash = '/';
|
|
var backslash = /\\/g;
|
|
var enclosure = /[\{\[].*[\}\]]$/;
|
|
var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
|
|
var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
|
|
|
|
/**
|
|
* @param {string} str
|
|
* @param {Object} opts
|
|
* @param {boolean} [opts.flipBackslashes=true]
|
|
* @returns {string}
|
|
*/
|
|
module.exports = function globParent(str, opts) {
|
|
var options = Object.assign({ flipBackslashes: true }, opts);
|
|
|
|
// flip windows path separators
|
|
if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
|
|
str = str.replace(backslash, slash);
|
|
}
|
|
|
|
// special case for strings ending in enclosure containing path separator
|
|
if (enclosure.test(str)) {
|
|
str += slash;
|
|
}
|
|
|
|
// preserves full path in case of trailing path separator
|
|
str += 'a';
|
|
|
|
// remove path parts that are globby
|
|
do {
|
|
str = pathPosixDirname(str);
|
|
} while (isGlob(str) || globby.test(str));
|
|
|
|
// remove escape chars and return result
|
|
return str.replace(escaped, '$1');
|
|
};
|