| | |
| | | const RE_URL_GITHUB_EXTREME_SHORT = /^[^/@:.\s][^/@:\s]*\/[^@:\s]*[^/@:\s]#\S+/; |
| | | |
| | | // Short url with specific protocol. eg: github:foo/bar |
| | | const RE_GIT_URL_SHORT = /^(github|gitlab|bitbucket|gist):\/?[^/.]+\/?/i; |
| | | const RE_GIT_URL_SHORT = /^(?:github|gitlab|bitbucket|gist):\/?[^/.]+\/?/i; |
| | | |
| | | // Currently supported protocols |
| | | const RE_PROTOCOL = |
| | | /^((git\+)?(ssh|https?|file)|git|github|gitlab|bitbucket|gist):$/i; |
| | | /^(?:(?:git\+)?(?:ssh|https?|file)|git|github|gitlab|bitbucket|gist):$/i; |
| | | |
| | | // Has custom protocol |
| | | const RE_CUSTOM_PROTOCOL = /^((git\+)?(ssh|https?|file)|git):\/\//i; |
| | | const RE_CUSTOM_PROTOCOL = /^(?:(?:git\+)?(?:ssh|https?|file)|git):\/\//i; |
| | | |
| | | // Valid hash format for npm / yarn ... |
| | | const RE_URL_HASH_VERSION = /#(?:semver:)?(.+)/; |
| | | |
| | | // Simple hostname validate |
| | | const RE_HOSTNAME = /^(?:[^/.]+(\.[^/]+)+|localhost)$/; |
| | | const RE_HOSTNAME = /^(?:[^/.]+(?:\.[^/]+)+|localhost)$/; |
| | | |
| | | // For hostname with colon. eg: ssh://user@github.com:foo/bar |
| | | const RE_HOSTNAME_WITH_COLON = |
| | | /([^/@#:.]+(?:\.[^/@#:.]+)+|localhost):([^#/0-9]+)/; |
| | | |
| | | // Reg for url without protocol |
| | | const RE_NO_PROTOCOL = /^([^/@#:.]+(?:\.[^/@#:.]+)+)/; |
| | | const RE_NO_PROTOCOL = /^[^/@#:.]+(?:\.[^/@#:.]+)+/; |
| | | |
| | | // RegExp for version string |
| | | const VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/; |
| | | const VERSION_PATTERN_REGEXP = /^(?:[\d^=v<>~]|[*xX]$)/; |
| | | |
| | | // Specific protocol for short url without normal hostname |
| | | const PROTOCOLS_FOR_SHORT = [ |
| | |
| | | // thanks to https://github.com/npm/hosted-git-info/blob/latest/git-host-info.js |
| | | const extractCommithashByDomain = { |
| | | /** |
| | | * Returns hash. |
| | | * @param {string} pathname pathname |
| | | * @param {string} hash hash |
| | | * @returns {string | undefined} hash |
| | |
| | | return commithash; |
| | | }, |
| | | /** |
| | | * Returns hash. |
| | | * @param {string} pathname pathname |
| | | * @param {string} hash hash |
| | | * @returns {string | undefined} hash |
| | |
| | | return hash; |
| | | }, |
| | | /** |
| | | * Returns hash. |
| | | * @param {string} pathname pathname |
| | | * @param {string} hash hash |
| | | * @returns {string | undefined} hash |
| | |
| | | return hash; |
| | | }, |
| | | /** |
| | | * Returns hash. |
| | | * @param {string} pathname pathname |
| | | * @param {string} hash hash |
| | | * @returns {string | undefined} hash |
| | |
| | | |
| | | gitUrl = correctUrl(gitUrl); |
| | | |
| | | /** @type {undefined | URL} */ |
| | | let parsed; |
| | | |
| | | try { |
| | | parsed = new URL(gitUrl); |
| | | // eslint-disable-next-line no-empty |
| | |
| | | /** @typedef {{ data: JsonObject, path: string }} DescriptionFile */ |
| | | |
| | | /** |
| | | * Gets description file. |
| | | * @param {InputFileSystem} fs file system |
| | | * @param {string} directory directory to start looking into |
| | | * @param {string[]} descriptionFiles possible description filenames |
| | |
| | | module.exports.getDescriptionFile = getDescriptionFile; |
| | | |
| | | /** |
| | | * Gets required version from description file. |
| | | * @param {JsonObject} data description file data i.e.: package.json |
| | | * @param {string} packageName name of the dependency |
| | | * @returns {string | undefined} normalized version |
| | |
| | | packageName in dependency |
| | | ) { |
| | | return normalizeVersion( |
| | | /** @type {Exclude<JsonPrimitive, null | boolean| number>} */ ( |
| | | /** @type {Exclude<JsonPrimitive, null | boolean | number>} */ ( |
| | | dependency[packageName] |
| | | ) |
| | | ); |
| | |
| | | getRequiredVersionFromDescriptionFile; |
| | | |
| | | /** |
| | | * Checks whether this object is required version. |
| | | * @param {string} str maybe required version |
| | | * @returns {boolean} true, if it looks like a version |
| | | */ |
| | |
| | | module.exports.isRequiredVersion = isRequiredVersion; |
| | | |
| | | /** |
| | | * Normalizes version. |
| | | * @see https://docs.npmjs.com/cli/v7/configuring-npm/package-json#urls-as-dependencies |
| | | * @param {string} versionDesc version to be normalized |
| | | * @returns {string} normalized version |