1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.normalizePackageName = normalizePackageName;
|
7 | exports.getShorthandName = getShorthandName;
|
8 | exports.getNamespaceFromTerm = getNamespaceFromTerm;
|
9 |
|
10 | const NAMESPACE_REGEX = /^@.*\//iu;
|
11 |
|
12 | const prefix = 'commitlint-plugin';
|
13 |
|
14 |
|
15 | function convertPathToPosix(filepath) {
|
16 | const normalizedFilepath = path.normalize(filepath);
|
17 | const posixFilepath = normalizedFilepath.replace(/\\/gu, '/');
|
18 |
|
19 | return posixFilepath;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function normalizePackageName(name) {
|
29 | let normalizedName = name;
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 | if (normalizedName.indexOf('\\') > -1) {
|
37 | normalizedName = convertPathToPosix(normalizedName);
|
38 | }
|
39 |
|
40 | if (normalizedName.charAt(0) === '@') {
|
41 | |
42 |
|
43 |
|
44 |
|
45 | const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, 'u'),
|
46 | scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, 'u');
|
47 |
|
48 | if (scopedPackageShortcutRegex.test(normalizedName)) {
|
49 | normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
|
50 | } else if (!scopedPackageNameRegex.test(normalizedName.split('/')[1])) {
|
51 | |
52 |
|
53 |
|
54 |
|
55 | normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`);
|
56 | }
|
57 | } else if (normalizedName.indexOf(`${prefix}-`) !== 0) {
|
58 | normalizedName = `${prefix}-${normalizedName}`;
|
59 | }
|
60 |
|
61 | return normalizedName;
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function getShorthandName(fullname) {
|
70 | if (fullname[0] === '@') {
|
71 | let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, 'u').exec(fullname);
|
72 |
|
73 | if (matchResult) {
|
74 | return matchResult[1];
|
75 | }
|
76 |
|
77 | matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, 'u').exec(fullname);
|
78 | if (matchResult) {
|
79 | return `${matchResult[1]}/${matchResult[2]}`;
|
80 | }
|
81 | } else if (fullname.startsWith(`${prefix}-`)) {
|
82 | return fullname.slice(prefix.length + 1);
|
83 | }
|
84 |
|
85 | return fullname;
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | function getNamespaceFromTerm(term) {
|
94 | const match = term.match(NAMESPACE_REGEX);
|
95 |
|
96 | return match ? match[0] : '';
|
97 | }
|
98 |
|
\ | No newline at end of file |