@teambit/legacy-bit-id 1.0.4 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bit-id.spec.ts +225 -0
- package/bit-id.ts +314 -0
- package/bit-ids.spec.ts +96 -0
- package/bit-ids.ts +195 -0
- package/dist/bit-id.js +290 -344
- package/dist/bit-id.js.map +1 -1
- package/dist/bit-id.spec.js +224 -349
- package/dist/bit-id.spec.js.map +1 -1
- package/dist/bit-ids.d.ts +52 -0
- package/dist/bit-ids.js +174 -0
- package/dist/bit-ids.js.map +1 -0
- package/dist/bit-ids.spec.d.ts +1 -0
- package/dist/bit-ids.spec.js +92 -0
- package/dist/bit-ids.spec.js.map +1 -0
- package/dist/exceptions/index.js +15 -71
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/invalid-bit-id.js +6 -21
- package/dist/exceptions/invalid-bit-id.js.map +1 -1
- package/dist/exceptions/invalid-id-chunk.js +6 -21
- package/dist/exceptions/invalid-id-chunk.js.map +1 -1
- package/dist/exceptions/invalid-name.js +6 -21
- package/dist/exceptions/invalid-name.js.map +1 -1
- package/dist/exceptions/invalid-scope-name-from-remote.js +7 -18
- package/dist/exceptions/invalid-scope-name-from-remote.js.map +1 -1
- package/dist/exceptions/invalid-scope-name.js +7 -23
- package/dist/exceptions/invalid-scope-name.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +41 -90
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.json +32 -0
- package/dist/utils/is-valid-id-chunk.js +8 -10
- package/dist/utils/is-valid-id-chunk.js.map +1 -1
- package/dist/utils/is-valid-id-chunk.spec.js +21 -32
- package/dist/utils/is-valid-id-chunk.spec.js.map +1 -1
- package/dist/utils/is-valid-scope-name.js +5 -8
- package/dist/utils/is-valid-scope-name.js.map +1 -1
- package/index.ts +18 -0
- package/package.json +5 -13
- package/tsconfig.json +2 -10
- /package/dist/{preview-1698204020177.js → preview-1706301986259.js} +0 -0
package/dist/bit-id.js
CHANGED
|
@@ -1,350 +1,296 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
5
17
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
function _lodash() {
|
|
29
|
-
const data = require("lodash");
|
|
30
|
-
_lodash = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
function _componentVersion() {
|
|
36
|
-
const data = require("@teambit/component-version");
|
|
37
|
-
_componentVersion = function () {
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
|
-
function _isValidIdChunk() {
|
|
43
|
-
const data = _interopRequireDefault(require("./utils/is-valid-id-chunk"));
|
|
44
|
-
_isValidIdChunk = function () {
|
|
45
|
-
return data;
|
|
46
|
-
};
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
function _isValidScopeName() {
|
|
50
|
-
const data = _interopRequireDefault(require("./utils/is-valid-scope-name"));
|
|
51
|
-
_isValidScopeName = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
function _exceptions() {
|
|
57
|
-
const data = require("./exceptions");
|
|
58
|
-
_exceptions = function () {
|
|
59
|
-
return data;
|
|
60
|
-
};
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
64
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
65
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
66
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
67
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
68
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
69
|
-
const VERSION_DELIMITER = '@';
|
|
70
|
-
exports.VERSION_DELIMITER = VERSION_DELIMITER;
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.VERSION_DELIMITER = void 0;
|
|
30
|
+
const decamelize_1 = __importDefault(require("decamelize"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const semver = __importStar(require("semver"));
|
|
33
|
+
const lodash_1 = require("lodash");
|
|
34
|
+
const component_version_1 = require("@teambit/component-version");
|
|
35
|
+
const is_valid_id_chunk_1 = __importDefault(require("./utils/is-valid-id-chunk"));
|
|
36
|
+
const is_valid_scope_name_1 = __importDefault(require("./utils/is-valid-scope-name"));
|
|
37
|
+
const exceptions_1 = require("./exceptions");
|
|
38
|
+
exports.VERSION_DELIMITER = '@';
|
|
71
39
|
class BitId {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
static getValidIdChunk(chunk) {
|
|
327
|
-
if (!(0, _isValidIdChunk().default)(chunk)) {
|
|
328
|
-
chunk = chunk.replace(/\./g, ''); // remove "."
|
|
329
|
-
chunk = chunk.replace(/ /g, '-'); // replace a space with a dash.
|
|
330
|
-
chunk = (0, _decamelize().default)(chunk, '-');
|
|
331
|
-
}
|
|
332
|
-
return chunk;
|
|
333
|
-
}
|
|
334
|
-
static getValidBitId(box, name) {
|
|
335
|
-
return new BitId({
|
|
336
|
-
name: BitId.getValidIdChunk(name),
|
|
337
|
-
box: box ? BitId.getValidIdChunk(box) : undefined
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
static isValidVersion(version) {
|
|
341
|
-
// a version can be a tag (semver) or a snap (hash)
|
|
342
|
-
return (0, _componentVersion().isTag)(version) || (0, _componentVersion().isHash)(version);
|
|
343
|
-
}
|
|
344
|
-
static isValidSemver(version) {
|
|
345
|
-
return Boolean(semver().valid(version));
|
|
346
|
-
}
|
|
40
|
+
constructor({ scope, box, name, version }) {
|
|
41
|
+
// don't validate the id parts using isValidIdChunk here. we instance this class tons of times
|
|
42
|
+
// and running regex so many times impact the performance
|
|
43
|
+
if (!name)
|
|
44
|
+
throw new exceptions_1.InvalidName(name);
|
|
45
|
+
this.scope = scope || null;
|
|
46
|
+
this.box = undefined;
|
|
47
|
+
this.name = box ? `${box}/${name}` : name;
|
|
48
|
+
this.version = version || undefined;
|
|
49
|
+
Object.freeze(this);
|
|
50
|
+
}
|
|
51
|
+
clone() {
|
|
52
|
+
return new BitId(this);
|
|
53
|
+
}
|
|
54
|
+
changeScope(newScope) {
|
|
55
|
+
return new BitId({ scope: newScope, name: this.name, version: this.version });
|
|
56
|
+
}
|
|
57
|
+
changeVersion(newVersion) {
|
|
58
|
+
return new BitId({ scope: this.scope, name: this.name, version: newVersion });
|
|
59
|
+
}
|
|
60
|
+
isLocal(scopeName) {
|
|
61
|
+
return !this.scope || Boolean(scopeName && scopeName === this.scope);
|
|
62
|
+
}
|
|
63
|
+
getVersion() {
|
|
64
|
+
return (0, component_version_1.versionParser)(this.version);
|
|
65
|
+
}
|
|
66
|
+
hasVersion() {
|
|
67
|
+
return Boolean(this.version && this.version !== component_version_1.LATEST_VERSION);
|
|
68
|
+
}
|
|
69
|
+
hasScope() {
|
|
70
|
+
return Boolean(this.scope);
|
|
71
|
+
}
|
|
72
|
+
hasSameName(id) {
|
|
73
|
+
return this.name === id.name;
|
|
74
|
+
}
|
|
75
|
+
hasSameScope(id) {
|
|
76
|
+
if (this.hasScope() && id.hasScope())
|
|
77
|
+
return this.scope === id.scope;
|
|
78
|
+
if (!this.hasScope() && !id.hasScope())
|
|
79
|
+
return true;
|
|
80
|
+
return false; // one has scope but not the other
|
|
81
|
+
}
|
|
82
|
+
hasSameVersion(id) {
|
|
83
|
+
if (this.hasVersion() && id.hasVersion())
|
|
84
|
+
return this.version === id.version;
|
|
85
|
+
if (!this.hasVersion() && !id.hasVersion())
|
|
86
|
+
return true;
|
|
87
|
+
return false; // one has version but not the other
|
|
88
|
+
}
|
|
89
|
+
toString(ignoreScope = false, ignoreVersion = false) {
|
|
90
|
+
const { name, version } = this;
|
|
91
|
+
const scope = this.scope;
|
|
92
|
+
const componentStr = ignoreScope || !scope ? name : [scope, name].join('/');
|
|
93
|
+
// when there is no scope and the version is latest, omit the version.
|
|
94
|
+
if (ignoreVersion || !this.hasVersion())
|
|
95
|
+
return componentStr;
|
|
96
|
+
return componentStr.concat(`${exports.VERSION_DELIMITER}${version}`);
|
|
97
|
+
}
|
|
98
|
+
toStringWithoutScope() {
|
|
99
|
+
return this.toString(true);
|
|
100
|
+
}
|
|
101
|
+
toStringWithoutVersion() {
|
|
102
|
+
return this.toString(false, true);
|
|
103
|
+
}
|
|
104
|
+
toStringWithoutScopeAndVersion() {
|
|
105
|
+
return this.toString(true, true);
|
|
106
|
+
}
|
|
107
|
+
isEqual(bitId) {
|
|
108
|
+
return this.hasSameName(bitId) && this.hasSameScope(bitId) && this.hasSameVersion(bitId);
|
|
109
|
+
}
|
|
110
|
+
isEqualWithoutVersion(bitId) {
|
|
111
|
+
return this.hasSameName(bitId) && this.hasSameScope(bitId);
|
|
112
|
+
}
|
|
113
|
+
isEqualWithoutScopeAndVersion(bitId) {
|
|
114
|
+
return this.hasSameName(bitId);
|
|
115
|
+
}
|
|
116
|
+
serialize() {
|
|
117
|
+
const obj = { scope: this.scope, name: this.name, version: this.version };
|
|
118
|
+
if (!this.hasVersion())
|
|
119
|
+
delete obj.version;
|
|
120
|
+
if (!this.hasScope())
|
|
121
|
+
delete obj.scope;
|
|
122
|
+
return obj;
|
|
123
|
+
}
|
|
124
|
+
toFullPath() {
|
|
125
|
+
if (!this.scope || !this.version) {
|
|
126
|
+
throw new Error('BitId.toFullPath is unable to generate a path without a scope or a version');
|
|
127
|
+
}
|
|
128
|
+
return path.join(this.name, this.scope, this.version);
|
|
129
|
+
}
|
|
130
|
+
isVersionSnap() {
|
|
131
|
+
return !(0, component_version_1.isTag)(this.version);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* examples:
|
|
135
|
+
* 1.0.0 => null
|
|
136
|
+
* 1.0.0-dev.1 => ['dev', 1]
|
|
137
|
+
* 1.0.0-dev.1.alpha.2 => ['dev', 1, 'alpha', 2]
|
|
138
|
+
* 1.0.0-0 => [0]
|
|
139
|
+
*/
|
|
140
|
+
getVersionPreReleaseData() {
|
|
141
|
+
if (!this.version)
|
|
142
|
+
return null;
|
|
143
|
+
return semver.prerelease(this.version);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get a string id and return a string without the version part
|
|
147
|
+
* @param {string} id
|
|
148
|
+
* @return {string} id - id without version
|
|
149
|
+
*/
|
|
150
|
+
static getStringWithoutVersion(id) {
|
|
151
|
+
const splitted = id.split(exports.VERSION_DELIMITER);
|
|
152
|
+
let res = splitted[0];
|
|
153
|
+
// the delimiter is @. now with the new owner prefix
|
|
154
|
+
// many times the id starts with the @ sign as part of the @owner prefix
|
|
155
|
+
// do not treat this @ at the beginning as the version delimiter
|
|
156
|
+
if (id.startsWith(exports.VERSION_DELIMITER)) {
|
|
157
|
+
res = `${exports.VERSION_DELIMITER}${splitted[1]}`;
|
|
158
|
+
}
|
|
159
|
+
return res;
|
|
160
|
+
}
|
|
161
|
+
static getVersionOnlyFromString(id) {
|
|
162
|
+
return id.split(exports.VERSION_DELIMITER)[1];
|
|
163
|
+
}
|
|
164
|
+
static parse(id, hasScope = true, version = component_version_1.LATEST_VERSION) {
|
|
165
|
+
if (typeof id !== 'string') {
|
|
166
|
+
throw new TypeError(`BitId.parse expects to get "id" as a string, instead, got ${typeof id}`);
|
|
167
|
+
}
|
|
168
|
+
if (id.includes(exports.VERSION_DELIMITER) && id.lastIndexOf(exports.VERSION_DELIMITER) > 0) {
|
|
169
|
+
const [newId, newVersion] = id.split(exports.VERSION_DELIMITER);
|
|
170
|
+
id = newId;
|
|
171
|
+
version = newVersion;
|
|
172
|
+
}
|
|
173
|
+
const getScopeAndName = () => {
|
|
174
|
+
if (hasScope) {
|
|
175
|
+
return BitId.getScopeAndName(id);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
scope: undefined,
|
|
179
|
+
name: id,
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
const { scope, name } = getScopeAndName();
|
|
183
|
+
if (!(0, is_valid_id_chunk_1.default)(name))
|
|
184
|
+
throw new exceptions_1.InvalidName(name);
|
|
185
|
+
if (scope && !(0, is_valid_scope_name_1.default)(scope)) {
|
|
186
|
+
throw new exceptions_1.InvalidScopeName(scope, id);
|
|
187
|
+
}
|
|
188
|
+
return new BitId({
|
|
189
|
+
scope,
|
|
190
|
+
name,
|
|
191
|
+
version,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
static getScopeAndName(id) {
|
|
195
|
+
const delimiterIndex = id.indexOf('/');
|
|
196
|
+
if (delimiterIndex < 0)
|
|
197
|
+
throw new exceptions_1.InvalidBitId(id);
|
|
198
|
+
const scope = id.substring(0, delimiterIndex);
|
|
199
|
+
const name = id.substring(delimiterIndex + 1);
|
|
200
|
+
return {
|
|
201
|
+
scope,
|
|
202
|
+
name,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
static parseObsolete(id, version = component_version_1.LATEST_VERSION) {
|
|
206
|
+
if (id.includes(exports.VERSION_DELIMITER)) {
|
|
207
|
+
const [newId, newVersion] = id.split(exports.VERSION_DELIMITER);
|
|
208
|
+
id = newId;
|
|
209
|
+
version = newVersion;
|
|
210
|
+
}
|
|
211
|
+
const idSplit = id.split('/');
|
|
212
|
+
if (idSplit.length === 3) {
|
|
213
|
+
const [scope, box, name] = idSplit;
|
|
214
|
+
if (!(0, is_valid_id_chunk_1.default)(name, false) || !(0, is_valid_id_chunk_1.default)(box, false) || !(0, is_valid_scope_name_1.default)(scope)) {
|
|
215
|
+
throw new exceptions_1.InvalidIdChunk(`${scope}/${box}/${name}`);
|
|
216
|
+
}
|
|
217
|
+
// $FlowFixMe (in this case the realScopeName is not undefined)
|
|
218
|
+
return new BitId({
|
|
219
|
+
scope,
|
|
220
|
+
box,
|
|
221
|
+
name,
|
|
222
|
+
version,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (idSplit.length === 2) {
|
|
226
|
+
const [box, name] = idSplit;
|
|
227
|
+
if (!(0, is_valid_id_chunk_1.default)(name, false) || !(0, is_valid_id_chunk_1.default)(box, false)) {
|
|
228
|
+
throw new exceptions_1.InvalidIdChunk(`${box}/${name}`);
|
|
229
|
+
}
|
|
230
|
+
return new BitId({
|
|
231
|
+
box,
|
|
232
|
+
name,
|
|
233
|
+
version,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (idSplit.length === 1) {
|
|
237
|
+
const [name] = idSplit;
|
|
238
|
+
if (!(0, is_valid_id_chunk_1.default)(name)) {
|
|
239
|
+
throw new exceptions_1.InvalidIdChunk(name);
|
|
240
|
+
}
|
|
241
|
+
return new BitId({
|
|
242
|
+
name,
|
|
243
|
+
version,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
throw new exceptions_1.InvalidBitId(id);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* before version 13.0.3 bitmap and component-dependencies ids were written as strings (e.g. scope/box/name@version)
|
|
250
|
+
* since that version the ids are written as objects ({ scope: scopeName, name: compName, version: 0.0.1 })
|
|
251
|
+
*/
|
|
252
|
+
static parseBackwardCompatible(id) {
|
|
253
|
+
return typeof id === 'string' ? BitId.parseObsolete(id) : new BitId(id);
|
|
254
|
+
}
|
|
255
|
+
static getValidScopeName(scope) {
|
|
256
|
+
const suggestedName = scope.toLowerCase();
|
|
257
|
+
let cleanName = suggestedName
|
|
258
|
+
.split('')
|
|
259
|
+
.map((char) => {
|
|
260
|
+
if (/^[$\-_!.a-z0-9]+$/.test(char))
|
|
261
|
+
return char;
|
|
262
|
+
return '';
|
|
263
|
+
})
|
|
264
|
+
.join('');
|
|
265
|
+
// allow only one dot
|
|
266
|
+
const nameSplitByDot = cleanName.split('.');
|
|
267
|
+
if (nameSplitByDot.length > 1) {
|
|
268
|
+
cleanName = `${(0, lodash_1.head)(nameSplitByDot)}.${(0, lodash_1.tail)(nameSplitByDot).join('')}`;
|
|
269
|
+
}
|
|
270
|
+
if (!cleanName) {
|
|
271
|
+
// @todo: change it to BitError
|
|
272
|
+
throw new Error('scope name created by directory name have to contains at least one character or number');
|
|
273
|
+
}
|
|
274
|
+
return cleanName;
|
|
275
|
+
}
|
|
276
|
+
static getValidIdChunk(chunk) {
|
|
277
|
+
if (!(0, is_valid_id_chunk_1.default)(chunk)) {
|
|
278
|
+
chunk = chunk.replace(/\./g, ''); // remove "."
|
|
279
|
+
chunk = chunk.replace(/ /g, '-'); // replace a space with a dash.
|
|
280
|
+
chunk = (0, decamelize_1.default)(chunk, '-');
|
|
281
|
+
}
|
|
282
|
+
return chunk;
|
|
283
|
+
}
|
|
284
|
+
static getValidBitId(box, name) {
|
|
285
|
+
return new BitId({ name: BitId.getValidIdChunk(name), box: box ? BitId.getValidIdChunk(box) : undefined });
|
|
286
|
+
}
|
|
287
|
+
static isValidVersion(version) {
|
|
288
|
+
// a version can be a tag (semver) or a snap (hash)
|
|
289
|
+
return (0, component_version_1.isTag)(version) || (0, component_version_1.isHash)(version);
|
|
290
|
+
}
|
|
291
|
+
static isValidSemver(version) {
|
|
292
|
+
return Boolean(semver.valid(version));
|
|
293
|
+
}
|
|
347
294
|
}
|
|
348
295
|
exports.default = BitId;
|
|
349
|
-
|
|
350
296
|
//# sourceMappingURL=bit-id.js.map
|