UNPKG

5.38 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/utils/pluginNaming.js"],"names":["normalizePackageName","getShorthandName","getNamespaceFromTerm","NAMESPACE_REGEX","prefix","convertPathToPosix","filepath","normalizedFilepath","path","normalize","posixFilepath","replace","name","normalizedName","indexOf","charAt","scopedPackageShortcutRegex","RegExp","scopedPackageNameRegex","test","split","fullname","matchResult","exec","startsWith","slice","length","term","match"],"mappings":";;;;;QAmBgBA,oB,GAAAA,oB;QAkDAC,gB,GAAAA,gB;QAwBAC,oB,GAAAA,oB;AA7FhB;AACA,MAAMC,kBAAkB,UAAxB;AACA;AACA,MAAMC,SAAS,mBAAf;;AAEA;AACA,SAASC,kBAAT,CAA4BC,QAA5B,EAAsC;AACrC,OAAMC,qBAAqBC,KAAKC,SAAL,CAAeH,QAAf,CAA3B;AACA,OAAMI,gBAAgBH,mBAAmBI,OAAnB,CAA2B,MAA3B,EAAmC,GAAnC,CAAtB;;AAEA,QAAOD,aAAP;AACA;;AAED;;;;;;AAMO,SAASV,oBAAT,CAA8BY,IAA9B,EAAoC;AAC1C,KAAIC,iBAAiBD,IAArB;;AAEA;;;;;AAKA,KAAIC,eAAeC,OAAf,CAAuB,IAAvB,IAA+B,CAAC,CAApC,EAAuC;AACtCD,mBAAiBR,mBAAmBQ,cAAnB,CAAjB;AACA;;AAED,KAAIA,eAAeE,MAAf,CAAsB,CAAtB,MAA6B,GAAjC,EAAsC;AACrC;;;;AAIA,QAAMC,6BAA6B,IAAIC,MAAJ,CAChC,mBAAkBb,MAAO,OADO,EAEjC,GAFiC,CAAnC;AAAA,QAICc,yBAAyB,IAAID,MAAJ,CAAY,IAAGb,MAAO,OAAtB,EAA8B,GAA9B,CAJ1B;;AAMA,MAAIY,2BAA2BG,IAA3B,CAAgCN,cAAhC,CAAJ,EAAqD;AACpDA,oBAAiBA,eAAeF,OAAf,CAChBK,0BADgB,EAEf,MAAKZ,MAAO,EAFG,CAAjB;AAIA,GALD,MAKO,IAAI,CA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in system\nconst NAMESPACE_REGEX = /^@.*\\//iu;\n// In eslint this is a parameter - we don't need to support the extra options\nconst prefix = 'commitlint-plugin';\n\n// Replace Windows with posix style paths\nfunction convertPathToPosix(filepath) {\n\tconst normalizedFilepath = path.normalize(filepath);\n\tconst posixFilepath = normalizedFilepath.replace(/\\\\/gu, '/');\n\n\treturn posixFilepath;\n}\n\n/**\n * Brings package name to correct format based on prefix\n * @param {string} name The name of the package.\n * @returns {string} Normalized name of the package\n * @private\n */\nexport function normalizePackageName(name) {\n\tlet normalizedName = name;\n\n\t/**\n\t * On Windows, name can come in with Windows slashes instead of Unix slashes.\n\t * Normalize to Unix first to avoid errors later on.\n\t * https://github.com/eslint/eslint/issues/5644\n\t */\n\tif (normalizedName.indexOf('\\\\') > -1) {\n\t\tnormalizedName = convertPathToPosix(normalizedName);\n\t}\n\n\tif (normalizedName.charAt(0) === '@') {\n\t\t/**\n\t\t * it's a scoped package\n\t\t * package name is the prefix, or just a username\n\t\t */\n\t\tconst scopedPackageShortcutRegex = new RegExp(\n\t\t\t\t`^(@[^/]+)(?:/(?:${prefix})?)?$`,\n\t\t\t\t'u'\n\t\t\t),\n\t\t\tscopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, 'u');\n\n\t\tif (scopedPackageShortcutRegex.test(normalizedName)) {\n\t\t\tnormalizedName = normalizedName.replace(\n\t\t\t\tscopedPackageShortcutRegex,\n\t\t\t\t`$1/${prefix}`\n\t\t\t);\n\t\t} else if (!scopedPackageNameRegex.test(normalizedName.split('/')[1])) {\n\t\t\t/**\n\t\t\t * for scoped packages, insert the prefix after the first / unless\n\t\t\t * the path is already @scope/eslint or @scope/eslint-xxx-yyy\n\t\t\t */\n\t\t\tnormalizedName = normalizedName.replace(\n\t\t\t\t/^@([^/]+)\\/(.*)$/u,\n\t\t\t\t`@$1/${prefix}-$2`\n\t\t\t);\n\t\t}\n\t} else if (normalizedName.indexOf(`${prefix}-`) !== 0) {\n\t\tnormalizedName = `${prefix}-${normalizedName}`;\n\t}\n\n\treturn normalizedName;\n}\n\n/**\n * Removes the prefix from a fullname.\n * @param {string} fullname The term which may have the prefix.\n * @returns {string} The term without prefix.\n */\nexport function getShorthandName(fullname) {\n\tif (fullname[0] === '@') {\n\t\tlet matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, 'u').exec(fullname);\n\n\t\tif (matchResult) {\n\t\t\treturn matchResult[1];\n\t\t}\n\n\t\tmatchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, 'u').exec(fullname);\n\t\tif (matchResult) {\n\t\t\treturn `${matchResult[1]}/${matchResult[2]}`;\n\t\t}\n\t} else if (fullname.startsWith(`${prefix}-`)) {\n\t\treturn fullname.slice(prefix.length + 1);\n\t}\n\n\treturn fullname;\n}\n\n/**\n * Gets the scope (namespace) of a term.\n * @param {string} term The term which may have the namespace.\n * @returns {string} The namepace of the term if it has one.\n */\nexport function getNamespaceFromTerm(term) {\n\tconst match = term.match(NAMESPACE_REGEX);\n\n\treturn match ? match[0] : '';\n}\n"]}
\No newline at end of file