@teambit/legacy-bit-id 1.0.1 → 1.0.2
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/dist/bit-id.d.ts +7 -5
- package/dist/bit-id.js +344 -291
- package/dist/bit-id.js.map +1 -1
- package/dist/bit-id.spec.js +349 -224
- package/dist/bit-id.spec.js.map +1 -1
- package/dist/exceptions/index.js +71 -15
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/invalid-bit-id.js +21 -6
- package/dist/exceptions/invalid-bit-id.js.map +1 -1
- package/dist/exceptions/invalid-id-chunk.js +21 -6
- package/dist/exceptions/invalid-id-chunk.js.map +1 -1
- package/dist/exceptions/invalid-name.js +21 -6
- package/dist/exceptions/invalid-name.js.map +1 -1
- package/dist/exceptions/invalid-scope-name-from-remote.js +17 -6
- package/dist/exceptions/invalid-scope-name-from-remote.js.map +1 -1
- package/dist/exceptions/invalid-scope-name.js +23 -7
- package/dist/exceptions/invalid-scope-name.js.map +1 -1
- package/dist/index.js +90 -39
- package/dist/index.js.map +1 -1
- package/dist/utils/is-valid-id-chunk.js +10 -8
- package/dist/utils/is-valid-id-chunk.js.map +1 -1
- package/dist/utils/is-valid-id-chunk.spec.js +32 -21
- package/dist/utils/is-valid-id-chunk.spec.js.map +1 -1
- package/dist/utils/is-valid-scope-name.js +8 -5
- package/dist/utils/is-valid-scope-name.js.map +1 -1
- package/package.json +17 -8
- package/tsconfig.json +10 -2
- package/.bit-capsule-ready +0 -0
- package/bit-id.spec.ts +0 -225
- package/bit-id.ts +0 -313
- package/dist/tsconfig.json +0 -32
- package/index.ts +0 -16
- package/package-tar/teambit-legacy-bit-id-1.0.1.tgz +0 -0
- /package/dist/{preview-1691932590750.js → preview-1696907926959.js} +0 -0
package/bit-id.ts
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import decamelize from 'decamelize';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as semver from 'semver';
|
|
4
|
-
import { head, tail } from 'lodash';
|
|
5
|
-
import { versionParser, isHash, LATEST_VERSION } from '@teambit/component-version';
|
|
6
|
-
import isValidIdChunk from './utils/is-valid-id-chunk';
|
|
7
|
-
import isValidScopeName from './utils/is-valid-scope-name';
|
|
8
|
-
import { InvalidBitId, InvalidIdChunk, InvalidName, InvalidScopeName } from './exceptions';
|
|
9
|
-
|
|
10
|
-
export type BitIdProps = {
|
|
11
|
-
scope?: string | null | undefined;
|
|
12
|
-
box?: string | undefined;
|
|
13
|
-
name: string;
|
|
14
|
-
version?: string | undefined;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type BitIdStr = string;
|
|
18
|
-
|
|
19
|
-
export const VERSION_DELIMITER = '@';
|
|
20
|
-
|
|
21
|
-
export default class BitId {
|
|
22
|
-
readonly scope: string | null | undefined;
|
|
23
|
-
readonly box: string | undefined;
|
|
24
|
-
readonly name: string;
|
|
25
|
-
readonly version: string | undefined;
|
|
26
|
-
|
|
27
|
-
constructor({ scope, box, name, version }: BitIdProps) {
|
|
28
|
-
// don't validate the id parts using isValidIdChunk here. we instance this class tons of times
|
|
29
|
-
// and running regex so many times impact the performance
|
|
30
|
-
if (!name) throw new InvalidName(name);
|
|
31
|
-
this.scope = scope || null;
|
|
32
|
-
this.box = undefined;
|
|
33
|
-
this.name = box ? `${box}/${name}` : name;
|
|
34
|
-
this.version = version || undefined;
|
|
35
|
-
Object.freeze(this);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
clone(): BitId {
|
|
39
|
-
return new BitId(this);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
changeScope(newScope?: string | null | undefined): BitId {
|
|
43
|
-
return new BitId({ scope: newScope, name: this.name, version: this.version });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
changeVersion(newVersion: string | undefined): BitId {
|
|
47
|
-
return new BitId({ scope: this.scope, name: this.name, version: newVersion });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
isLocal(scopeName?: string): boolean {
|
|
51
|
-
return !this.scope || Boolean(scopeName && scopeName === this.scope);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getVersion() {
|
|
55
|
-
return versionParser(this.version);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
hasVersion(): boolean {
|
|
59
|
-
return Boolean(this.version && this.version !== LATEST_VERSION);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
hasScope(): boolean {
|
|
63
|
-
return Boolean(this.scope);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
hasSameName(id: BitId): boolean {
|
|
67
|
-
return this.name === id.name;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
hasSameScope(id: BitId): boolean {
|
|
71
|
-
if (this.hasScope() && id.hasScope()) return this.scope === id.scope;
|
|
72
|
-
if (!this.hasScope() && !id.hasScope()) return true;
|
|
73
|
-
return false; // one has scope but not the other
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
hasSameVersion(id: BitId): boolean {
|
|
77
|
-
if (this.hasVersion() && id.hasVersion()) return this.version === id.version;
|
|
78
|
-
if (!this.hasVersion() && !id.hasVersion()) return true;
|
|
79
|
-
return false; // one has version but not the other
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
toString(ignoreScope = false, ignoreVersion = false): BitIdStr {
|
|
83
|
-
const { name, version } = this;
|
|
84
|
-
const scope = this.scope;
|
|
85
|
-
const componentStr = ignoreScope || !scope ? name : [scope, name].join('/');
|
|
86
|
-
// when there is no scope and the version is latest, omit the version.
|
|
87
|
-
if (ignoreVersion || !this.hasVersion()) return componentStr;
|
|
88
|
-
// $FlowFixMe version here is a string because this.hasVersion() is true
|
|
89
|
-
return componentStr.concat(`${VERSION_DELIMITER}${version}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
toStringWithoutScope(): BitIdStr {
|
|
93
|
-
return this.toString(true);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
toStringWithoutVersion(): BitIdStr {
|
|
97
|
-
return this.toString(false, true);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
toStringWithoutScopeAndVersion(): BitIdStr {
|
|
101
|
-
return this.toString(true, true);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
isEqual(bitId: BitId): boolean {
|
|
105
|
-
return this.hasSameName(bitId) && this.hasSameScope(bitId) && this.hasSameVersion(bitId);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
isEqualWithoutVersion(bitId: BitId): boolean {
|
|
109
|
-
return this.hasSameName(bitId) && this.hasSameScope(bitId);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
isEqualWithoutScopeAndVersion(bitId: BitId): boolean {
|
|
113
|
-
return this.hasSameName(bitId);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
serialize() {
|
|
117
|
-
const obj = { scope: this.scope, name: this.name, version: this.version };
|
|
118
|
-
if (!this.hasVersion()) delete obj.version;
|
|
119
|
-
if (!this.hasScope()) delete obj.scope;
|
|
120
|
-
return obj;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
toFullPath(): string {
|
|
124
|
-
if (!this.scope || !this.version) {
|
|
125
|
-
throw new Error('BitId.toFullPath is unable to generate a path without a scope or a version');
|
|
126
|
-
}
|
|
127
|
-
return path.join(this.name, this.scope, this.version);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
isVersionSnap() {
|
|
131
|
-
return isHash(this.version);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* examples:
|
|
136
|
-
* 1.0.0 => null
|
|
137
|
-
* 1.0.0-dev.1 => ['dev', 1]
|
|
138
|
-
* 1.0.0-dev.1.alpha.2 => ['dev', 1, 'alpha', 2]
|
|
139
|
-
* 1.0.0-0 => [0]
|
|
140
|
-
*/
|
|
141
|
-
getVersionPreReleaseData(): null | readonly string[] {
|
|
142
|
-
if (!this.version) return null;
|
|
143
|
-
return semver.prerelease(this.version);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Get a string id and return a string without the version part
|
|
148
|
-
* @param {string} id
|
|
149
|
-
* @return {string} id - id without version
|
|
150
|
-
*/
|
|
151
|
-
static getStringWithoutVersion(id: string): string {
|
|
152
|
-
const splitted = id.split(VERSION_DELIMITER);
|
|
153
|
-
let res = splitted[0];
|
|
154
|
-
// the delimiter is @. now with the new owner prefix
|
|
155
|
-
// many times the id starts with the @ sign as part of the @owner prefix
|
|
156
|
-
// do not treat this @ at the beginning as the version delimiter
|
|
157
|
-
if (id.startsWith(VERSION_DELIMITER)) {
|
|
158
|
-
res = `${VERSION_DELIMITER}${splitted[1]}`;
|
|
159
|
-
}
|
|
160
|
-
return res;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
static getVersionOnlyFromString(id: string): string {
|
|
164
|
-
return id.split(VERSION_DELIMITER)[1];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
static parse(id: BitIdStr, hasScope = true, version: string = LATEST_VERSION): BitId {
|
|
168
|
-
if (typeof id !== 'string') {
|
|
169
|
-
throw new TypeError(`BitId.parse expects to get "id" as a string, instead, got ${typeof id}`);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (id.includes(VERSION_DELIMITER) && id.lastIndexOf(VERSION_DELIMITER) > 0) {
|
|
173
|
-
const [newId, newVersion] = id.split(VERSION_DELIMITER);
|
|
174
|
-
id = newId;
|
|
175
|
-
version = newVersion;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const getScopeAndName = () => {
|
|
179
|
-
if (hasScope) {
|
|
180
|
-
return BitId.getScopeAndName(id);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
scope: undefined,
|
|
185
|
-
name: id,
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
const { scope, name } = getScopeAndName();
|
|
189
|
-
|
|
190
|
-
if (!isValidIdChunk(name)) throw new InvalidName(name);
|
|
191
|
-
if (scope && !isValidScopeName(scope)) {
|
|
192
|
-
throw new InvalidScopeName(scope, id);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return new BitId({
|
|
196
|
-
scope,
|
|
197
|
-
name,
|
|
198
|
-
version,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
static getScopeAndName(id: string) {
|
|
203
|
-
const delimiterIndex = id.indexOf('/');
|
|
204
|
-
if (delimiterIndex < 0) throw new InvalidBitId(id);
|
|
205
|
-
const scope = id.substring(0, delimiterIndex);
|
|
206
|
-
const name = id.substring(delimiterIndex + 1);
|
|
207
|
-
return {
|
|
208
|
-
scope,
|
|
209
|
-
name,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
static parseObsolete(id: BitIdStr, version: string = LATEST_VERSION): BitId {
|
|
214
|
-
if (id.includes(VERSION_DELIMITER)) {
|
|
215
|
-
const [newId, newVersion] = id.split(VERSION_DELIMITER);
|
|
216
|
-
id = newId;
|
|
217
|
-
version = newVersion;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const idSplit = id.split('/');
|
|
221
|
-
if (idSplit.length === 3) {
|
|
222
|
-
const [scope, box, name] = idSplit;
|
|
223
|
-
if (!isValidIdChunk(name, false) || !isValidIdChunk(box, false) || !isValidScopeName(scope)) {
|
|
224
|
-
throw new InvalidIdChunk(`${scope}/${box}/${name}`);
|
|
225
|
-
}
|
|
226
|
-
// $FlowFixMe (in this case the realScopeName is not undefined)
|
|
227
|
-
return new BitId({
|
|
228
|
-
scope,
|
|
229
|
-
box,
|
|
230
|
-
name,
|
|
231
|
-
version,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (idSplit.length === 2) {
|
|
236
|
-
const [box, name] = idSplit;
|
|
237
|
-
if (!isValidIdChunk(name, false) || !isValidIdChunk(box, false)) {
|
|
238
|
-
throw new InvalidIdChunk(`${box}/${name}`);
|
|
239
|
-
}
|
|
240
|
-
return new BitId({
|
|
241
|
-
box,
|
|
242
|
-
name,
|
|
243
|
-
version,
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (idSplit.length === 1) {
|
|
248
|
-
const [name] = idSplit;
|
|
249
|
-
if (!isValidIdChunk(name)) {
|
|
250
|
-
throw new InvalidIdChunk(name);
|
|
251
|
-
}
|
|
252
|
-
return new BitId({
|
|
253
|
-
name,
|
|
254
|
-
version,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
throw new InvalidBitId(id);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* before version 13.0.3 bitmap and component-dependencies ids were written as strings (e.g. scope/box/name@version)
|
|
263
|
-
* since that version the ids are written as objects ({ scope: scopeName, name: compName, version: 0.0.1 })
|
|
264
|
-
*/
|
|
265
|
-
static parseBackwardCompatible(id: string | BitIdProps): BitId {
|
|
266
|
-
return typeof id === 'string' ? BitId.parseObsolete(id) : new BitId(id);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
static getValidScopeName(scope: string) {
|
|
270
|
-
const suggestedName = scope.toLowerCase();
|
|
271
|
-
let cleanName = suggestedName
|
|
272
|
-
.split('')
|
|
273
|
-
.map((char) => {
|
|
274
|
-
if (/^[$\-_!.a-z0-9]+$/.test(char)) return char;
|
|
275
|
-
return '';
|
|
276
|
-
})
|
|
277
|
-
.join('');
|
|
278
|
-
|
|
279
|
-
// allow only one dot
|
|
280
|
-
const nameSplitByDot = cleanName.split('.');
|
|
281
|
-
if (nameSplitByDot.length > 1) {
|
|
282
|
-
cleanName = `${head(nameSplitByDot)}.${tail(nameSplitByDot).join('')}`;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (!cleanName) {
|
|
286
|
-
// @todo: change it to BitError
|
|
287
|
-
throw new Error('scope name created by directory name have to contains at least one character or number');
|
|
288
|
-
}
|
|
289
|
-
return cleanName;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
static getValidIdChunk(chunk: string): string {
|
|
293
|
-
if (!isValidIdChunk(chunk)) {
|
|
294
|
-
chunk = chunk.replace(/\./g, ''); // remove "."
|
|
295
|
-
chunk = chunk.replace(/ /g, '-'); // replace a space with a dash.
|
|
296
|
-
chunk = decamelize(chunk, '-');
|
|
297
|
-
}
|
|
298
|
-
return chunk;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
static getValidBitId(box: string | undefined, name: string): BitId {
|
|
302
|
-
return new BitId({ name: BitId.getValidIdChunk(name), box: box ? BitId.getValidIdChunk(box) : undefined });
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
static isValidVersion(version: string): boolean {
|
|
306
|
-
// a version can be a tag (semver) or a snap (hash)
|
|
307
|
-
return BitId.isValidSemver(version) || isHash(version);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
static isValidSemver(version: string): boolean {
|
|
311
|
-
return Boolean(semver.valid(version));
|
|
312
|
-
}
|
|
313
|
-
}
|
package/dist/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": [
|
|
4
|
-
"es2019",
|
|
5
|
-
"DOM",
|
|
6
|
-
"ES6",
|
|
7
|
-
"DOM.Iterable"
|
|
8
|
-
],
|
|
9
|
-
"target": "es2015",
|
|
10
|
-
"module": "CommonJS",
|
|
11
|
-
"jsx": "react",
|
|
12
|
-
"allowJs": true,
|
|
13
|
-
"composite": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"outDir": "dist",
|
|
19
|
-
"moduleResolution": "node",
|
|
20
|
-
"esModuleInterop": true,
|
|
21
|
-
"rootDir": ".",
|
|
22
|
-
"resolveJsonModule": true
|
|
23
|
-
},
|
|
24
|
-
"exclude": [
|
|
25
|
-
"dist",
|
|
26
|
-
"package.json"
|
|
27
|
-
],
|
|
28
|
-
"include": [
|
|
29
|
-
"**/*",
|
|
30
|
-
"**/*.json"
|
|
31
|
-
]
|
|
32
|
-
}
|
package/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import BitId, { BitIdProps, VERSION_DELIMITER, BitIdStr } from './bit-id';
|
|
2
|
-
import { InvalidName, InvalidScopeName, InvalidScopeNameFromRemote } from './exceptions';
|
|
3
|
-
import isValidScopeName from './utils/is-valid-scope-name';
|
|
4
|
-
import isValidIdChunk from './utils/is-valid-id-chunk';
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
BitId,
|
|
8
|
-
BitIdProps,
|
|
9
|
-
BitIdStr,
|
|
10
|
-
VERSION_DELIMITER,
|
|
11
|
-
isValidScopeName,
|
|
12
|
-
isValidIdChunk,
|
|
13
|
-
InvalidName,
|
|
14
|
-
InvalidScopeName,
|
|
15
|
-
InvalidScopeNameFromRemote,
|
|
16
|
-
};
|
|
Binary file
|
|
File without changes
|