@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.
Files changed (34) hide show
  1. package/dist/bit-id.d.ts +7 -5
  2. package/dist/bit-id.js +344 -291
  3. package/dist/bit-id.js.map +1 -1
  4. package/dist/bit-id.spec.js +349 -224
  5. package/dist/bit-id.spec.js.map +1 -1
  6. package/dist/exceptions/index.js +71 -15
  7. package/dist/exceptions/index.js.map +1 -1
  8. package/dist/exceptions/invalid-bit-id.js +21 -6
  9. package/dist/exceptions/invalid-bit-id.js.map +1 -1
  10. package/dist/exceptions/invalid-id-chunk.js +21 -6
  11. package/dist/exceptions/invalid-id-chunk.js.map +1 -1
  12. package/dist/exceptions/invalid-name.js +21 -6
  13. package/dist/exceptions/invalid-name.js.map +1 -1
  14. package/dist/exceptions/invalid-scope-name-from-remote.js +17 -6
  15. package/dist/exceptions/invalid-scope-name-from-remote.js.map +1 -1
  16. package/dist/exceptions/invalid-scope-name.js +23 -7
  17. package/dist/exceptions/invalid-scope-name.js.map +1 -1
  18. package/dist/index.js +90 -39
  19. package/dist/index.js.map +1 -1
  20. package/dist/utils/is-valid-id-chunk.js +10 -8
  21. package/dist/utils/is-valid-id-chunk.js.map +1 -1
  22. package/dist/utils/is-valid-id-chunk.spec.js +32 -21
  23. package/dist/utils/is-valid-id-chunk.spec.js.map +1 -1
  24. package/dist/utils/is-valid-scope-name.js +8 -5
  25. package/dist/utils/is-valid-scope-name.js.map +1 -1
  26. package/package.json +17 -8
  27. package/tsconfig.json +10 -2
  28. package/.bit-capsule-ready +0 -0
  29. package/bit-id.spec.ts +0 -225
  30. package/bit-id.ts +0 -313
  31. package/dist/tsconfig.json +0 -32
  32. package/index.ts +0 -16
  33. package/package-tar/teambit-legacy-bit-id-1.0.1.tgz +0 -0
  34. /package/dist/{preview-1691932590750.js → preview-1696907926959.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"bit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 {"version":3,"names":["_decamelize","data","_interopRequireDefault","require","path","_interopRequireWildcard","semver","_lodash","_componentVersion","_isValidIdChunk","_isValidScopeName","_exceptions","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_defineProperty","value","_toPropertyKey","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","TypeError","Number","VERSION_DELIMITER","exports","BitId","constructor","scope","box","name","version","InvalidName","freeze","clone","changeScope","newScope","changeVersion","newVersion","isLocal","scopeName","Boolean","getVersion","versionParser","hasVersion","LATEST_VERSION","hasScope","hasSameName","id","hasSameScope","hasSameVersion","toString","ignoreScope","ignoreVersion","componentStr","join","concat","toStringWithoutScope","toStringWithoutVersion","toStringWithoutScopeAndVersion","isEqual","bitId","isEqualWithoutVersion","isEqualWithoutScopeAndVersion","serialize","toFullPath","Error","isVersionSnap","isTag","getVersionPreReleaseData","prerelease","getStringWithoutVersion","splitted","split","startsWith","getVersionOnlyFromString","parse","includes","lastIndexOf","newId","getScopeAndName","isValidIdChunk","isValidScopeName","InvalidScopeName","delimiterIndex","indexOf","InvalidBitId","substring","parseObsolete","idSplit","length","InvalidIdChunk","parseBackwardCompatible","getValidScopeName","suggestedName","toLowerCase","cleanName","map","char","test","nameSplitByDot","head","tail","getValidIdChunk","chunk","replace","decamelize","getValidBitId","isValidVersion","isHash","isValidSemver","valid"],"sources":["bit-id.ts"],"sourcesContent":["import decamelize from 'decamelize';\nimport * as path from 'path';\nimport * as semver from 'semver';\nimport { head, tail } from 'lodash';\nimport { versionParser, isHash, isTag, LATEST_VERSION } from '@teambit/component-version';\nimport isValidIdChunk from './utils/is-valid-id-chunk';\nimport isValidScopeName from './utils/is-valid-scope-name';\nimport { InvalidBitId, InvalidIdChunk, InvalidName, InvalidScopeName } from './exceptions';\n\nexport type BitIdProps = {\n scope?: string | null | undefined;\n box?: string | undefined;\n name: string;\n version?: string | undefined;\n};\n\ntype BitIdSerialized = { scope?: string; name: string; version?: string };\n\nexport type BitIdStr = string;\n\nexport const VERSION_DELIMITER = '@';\n\nexport default class BitId {\n readonly scope: string | null | undefined;\n readonly box: string | undefined;\n readonly name: string;\n readonly version: string | undefined;\n\n constructor({ scope, box, name, version }: BitIdProps) {\n // don't validate the id parts using isValidIdChunk here. we instance this class tons of times\n // and running regex so many times impact the performance\n if (!name) throw new InvalidName(name);\n this.scope = scope || null;\n this.box = undefined;\n this.name = box ? `${box}/${name}` : name;\n this.version = version || undefined;\n Object.freeze(this);\n }\n\n clone(): BitId {\n return new BitId(this);\n }\n\n changeScope(newScope?: string | null | undefined): BitId {\n return new BitId({ scope: newScope, name: this.name, version: this.version });\n }\n\n changeVersion(newVersion: string | undefined): BitId {\n return new BitId({ scope: this.scope, name: this.name, version: newVersion });\n }\n\n isLocal(scopeName?: string): boolean {\n return !this.scope || Boolean(scopeName && scopeName === this.scope);\n }\n\n getVersion() {\n return versionParser(this.version);\n }\n\n hasVersion(): boolean {\n return Boolean(this.version && this.version !== LATEST_VERSION);\n }\n\n hasScope(): boolean {\n return Boolean(this.scope);\n }\n\n hasSameName(id: BitId): boolean {\n return this.name === id.name;\n }\n\n hasSameScope(id: BitId): boolean {\n if (this.hasScope() && id.hasScope()) return this.scope === id.scope;\n if (!this.hasScope() && !id.hasScope()) return true;\n return false; // one has scope but not the other\n }\n\n hasSameVersion(id: BitId): boolean {\n if (this.hasVersion() && id.hasVersion()) return this.version === id.version;\n if (!this.hasVersion() && !id.hasVersion()) return true;\n return false; // one has version but not the other\n }\n\n toString(ignoreScope = false, ignoreVersion = false): BitIdStr {\n const { name, version } = this;\n const scope = this.scope;\n const componentStr = ignoreScope || !scope ? name : [scope, name].join('/');\n // when there is no scope and the version is latest, omit the version.\n if (ignoreVersion || !this.hasVersion()) return componentStr;\n return componentStr.concat(`${VERSION_DELIMITER}${version}`);\n }\n\n toStringWithoutScope(): BitIdStr {\n return this.toString(true);\n }\n\n toStringWithoutVersion(): BitIdStr {\n return this.toString(false, true);\n }\n\n toStringWithoutScopeAndVersion(): BitIdStr {\n return this.toString(true, true);\n }\n\n isEqual(bitId: BitId): boolean {\n return this.hasSameName(bitId) && this.hasSameScope(bitId) && this.hasSameVersion(bitId);\n }\n\n isEqualWithoutVersion(bitId: BitId): boolean {\n return this.hasSameName(bitId) && this.hasSameScope(bitId);\n }\n\n isEqualWithoutScopeAndVersion(bitId: BitId): boolean {\n return this.hasSameName(bitId);\n }\n\n serialize(): BitIdSerialized {\n const obj = { scope: this.scope, name: this.name, version: this.version };\n if (!this.hasVersion()) delete obj.version;\n if (!this.hasScope()) delete obj.scope;\n return obj as BitIdSerialized;\n }\n\n toFullPath(): string {\n if (!this.scope || !this.version) {\n throw new Error('BitId.toFullPath is unable to generate a path without a scope or a version');\n }\n return path.join(this.name, this.scope, this.version);\n }\n\n isVersionSnap() {\n return !isTag(this.version);\n }\n\n /**\n * examples:\n * 1.0.0 => null\n * 1.0.0-dev.1 => ['dev', 1]\n * 1.0.0-dev.1.alpha.2 => ['dev', 1, 'alpha', 2]\n * 1.0.0-0 => [0]\n */\n getVersionPreReleaseData(): null | readonly string[] {\n if (!this.version) return null;\n return semver.prerelease(this.version);\n }\n\n /**\n * Get a string id and return a string without the version part\n * @param {string} id\n * @return {string} id - id without version\n */\n static getStringWithoutVersion(id: string): string {\n const splitted = id.split(VERSION_DELIMITER);\n let res = splitted[0];\n // the delimiter is @. now with the new owner prefix\n // many times the id starts with the @ sign as part of the @owner prefix\n // do not treat this @ at the beginning as the version delimiter\n if (id.startsWith(VERSION_DELIMITER)) {\n res = `${VERSION_DELIMITER}${splitted[1]}`;\n }\n return res;\n }\n\n static getVersionOnlyFromString(id: string): string {\n return id.split(VERSION_DELIMITER)[1];\n }\n\n static parse(id: BitIdStr, hasScope = true, version: string = LATEST_VERSION): BitId {\n if (typeof id !== 'string') {\n throw new TypeError(`BitId.parse expects to get \"id\" as a string, instead, got ${typeof id}`);\n }\n\n if (id.includes(VERSION_DELIMITER) && id.lastIndexOf(VERSION_DELIMITER) > 0) {\n const [newId, newVersion] = id.split(VERSION_DELIMITER);\n id = newId;\n version = newVersion;\n }\n\n const getScopeAndName = () => {\n if (hasScope) {\n return BitId.getScopeAndName(id);\n }\n\n return {\n scope: undefined,\n name: id,\n };\n };\n const { scope, name } = getScopeAndName();\n\n if (!isValidIdChunk(name)) throw new InvalidName(name);\n if (scope && !isValidScopeName(scope)) {\n throw new InvalidScopeName(scope, id);\n }\n\n return new BitId({\n scope,\n name,\n version,\n });\n }\n\n static getScopeAndName(id: string) {\n const delimiterIndex = id.indexOf('/');\n if (delimiterIndex < 0) throw new InvalidBitId(id);\n const scope = id.substring(0, delimiterIndex);\n const name = id.substring(delimiterIndex + 1);\n return {\n scope,\n name,\n };\n }\n\n static parseObsolete(id: BitIdStr, version: string = LATEST_VERSION): BitId {\n if (id.includes(VERSION_DELIMITER)) {\n const [newId, newVersion] = id.split(VERSION_DELIMITER);\n id = newId;\n version = newVersion;\n }\n\n const idSplit = id.split('/');\n if (idSplit.length === 3) {\n const [scope, box, name] = idSplit;\n if (!isValidIdChunk(name, false) || !isValidIdChunk(box, false) || !isValidScopeName(scope)) {\n throw new InvalidIdChunk(`${scope}/${box}/${name}`);\n }\n // $FlowFixMe (in this case the realScopeName is not undefined)\n return new BitId({\n scope,\n box,\n name,\n version,\n });\n }\n\n if (idSplit.length === 2) {\n const [box, name] = idSplit;\n if (!isValidIdChunk(name, false) || !isValidIdChunk(box, false)) {\n throw new InvalidIdChunk(`${box}/${name}`);\n }\n return new BitId({\n box,\n name,\n version,\n });\n }\n\n if (idSplit.length === 1) {\n const [name] = idSplit;\n if (!isValidIdChunk(name)) {\n throw new InvalidIdChunk(name);\n }\n return new BitId({\n name,\n version,\n });\n }\n\n throw new InvalidBitId(id);\n }\n\n /**\n * before version 13.0.3 bitmap and component-dependencies ids were written as strings (e.g. scope/box/name@version)\n * since that version the ids are written as objects ({ scope: scopeName, name: compName, version: 0.0.1 })\n */\n static parseBackwardCompatible(id: string | BitIdProps): BitId {\n return typeof id === 'string' ? BitId.parseObsolete(id) : new BitId(id);\n }\n\n static getValidScopeName(scope: string) {\n const suggestedName = scope.toLowerCase();\n let cleanName = suggestedName\n .split('')\n .map((char) => {\n if (/^[$\\-_!.a-z0-9]+$/.test(char)) return char;\n return '';\n })\n .join('');\n\n // allow only one dot\n const nameSplitByDot = cleanName.split('.');\n if (nameSplitByDot.length > 1) {\n cleanName = `${head(nameSplitByDot)}.${tail(nameSplitByDot).join('')}`;\n }\n\n if (!cleanName) {\n // @todo: change it to BitError\n throw new Error('scope name created by directory name have to contains at least one character or number');\n }\n return cleanName;\n }\n\n static getValidIdChunk(chunk: string): string {\n if (!isValidIdChunk(chunk)) {\n chunk = chunk.replace(/\\./g, ''); // remove \".\"\n chunk = chunk.replace(/ /g, '-'); // replace a space with a dash.\n chunk = decamelize(chunk, '-');\n }\n return chunk;\n }\n\n static getValidBitId(box: string | undefined, name: string): BitId {\n return new BitId({ name: BitId.getValidIdChunk(name), box: box ? BitId.getValidIdChunk(box) : undefined });\n }\n\n static isValidVersion(version: string): boolean {\n // a version can be a tag (semver) or a snap (hash)\n return isTag(version) || isHash(version);\n }\n\n static isValidSemver(version: string): boolean {\n return Boolean(semver.valid(version));\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,OAAA;EAAA,MAAAL,IAAA,GAAAI,uBAAA,CAAAF,OAA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,OAAO+E,aAAaA,CAAC/E,OAAe,EAAW;IAC7C,OAAOU,OAAO,CAAC/D,MAAM,CAAD,CAAC,CAACqI,KAAK,CAAChF,OAAO,CAAC,CAAC;EACvC;AACF;AAACN,OAAA,CAAAlC,OAAA,GAAAmC,KAAA"}
@@ -1,229 +1,354 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const chai_1 = require("chai");
7
- const bit_id_1 = __importDefault(require("./bit-id"));
8
- const exceptions_1 = require("./exceptions");
2
+
3
+ function _chai() {
4
+ const data = require("chai");
5
+ _chai = function () {
6
+ return data;
7
+ };
8
+ return data;
9
+ }
10
+ function _bitId() {
11
+ const data = _interopRequireDefault(require("./bit-id"));
12
+ _bitId = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _exceptions() {
18
+ const data = require("./exceptions");
19
+ _exceptions = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
25
  describe('Bit-id', () => {
10
- // TODO: those tests are now verified by TS compiler, I think we can remove them
11
- it('should be frozen', () => {
12
- const bitId = new bit_id_1.default({ name: 'my-name' });
13
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
14
- (0, chai_1.expect)(() => (bitId.scope = 'name')).to.throw();
15
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
16
- (0, chai_1.expect)(() => (bitId.name = 'name')).to.throw();
17
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
18
- (0, chai_1.expect)(() => (bitId.version = 'name')).to.throw();
19
- });
20
- describe('constructor', () => {
21
- it('should not throw for an invalid scope as it hurts performance (it is done on .parse() instead)', () => {
22
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
23
- const invalidScope = () => new bit_id_1.default({ scope: 123, name: 'my-name' });
24
- (0, chai_1.expect)(invalidScope).to.not.throw(exceptions_1.InvalidScopeName);
25
- });
26
- it('should not throw for an invalid name as it hurts performance (it is done on .parse() instead)', () => {
27
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
28
- const invalidName = () => new bit_id_1.default({ name: ['a', 'b'] });
29
- (0, chai_1.expect)(invalidName).to.not.throw(exceptions_1.InvalidName);
30
- });
31
- it('should accept an empty scope', () => {
32
- const invalidScope = () => new bit_id_1.default({ scope: null, name: 'my-name' });
33
- (0, chai_1.expect)(invalidScope).to.not.throw();
34
- });
35
- it('should not accept an empty name', () => {
36
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
37
- (0, chai_1.expect)(() => new bit_id_1.default({ scope: 'my-scope', name: null })).to.throw(exceptions_1.InvalidName);
38
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
39
- (0, chai_1.expect)(() => new bit_id_1.default({ scope: 'my-scope', name: undefined })).to.throw(exceptions_1.InvalidName);
40
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
41
- (0, chai_1.expect)(() => new bit_id_1.default({ scope: 'my-scope' })).to.throw(exceptions_1.InvalidName);
42
- });
43
- });
44
- describe('changeScope', () => {
45
- it('should return a new BitId with different scope', () => {
46
- const bitId = new bit_id_1.default({ name: 'my-name' });
47
- (0, chai_1.expect)(bitId.changeScope('my-scope')).to.have.property('scope').that.equal('my-scope');
48
- });
49
- it('should accept an empty parameter to remove the scope', () => {
50
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name' });
51
- (0, chai_1.expect)(bitId.changeScope()).to.have.property('scope').that.is.null;
52
- });
53
- });
54
- describe('changeVersion', () => {
55
- it('should return a new BitId with different version', () => {
56
- const bitId = new bit_id_1.default({ name: 'my-name' });
57
- (0, chai_1.expect)(bitId.changeVersion('0.0.1')).to.have.property('version').that.equal('0.0.1');
58
- });
59
- it('should accept an empty parameter to remove the version', () => {
60
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
61
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
62
- (0, chai_1.expect)(bitId.changeVersion()).to.have.property('version').that.is.undefined;
63
- });
64
- });
65
- describe('hasScope', () => {
66
- it('should return false when there is no scope', () => {
67
- const bitId = new bit_id_1.default({ name: 'my-name' });
68
- (0, chai_1.expect)(bitId.hasScope()).to.be.false;
69
- });
70
- it('should return true when there is scope', () => {
71
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name' });
72
- (0, chai_1.expect)(bitId.hasScope()).to.be.true;
73
- });
74
- });
75
- describe('getValidBitId', () => {
76
- it('should convert CSSComp to css-comp', () => {
77
- const bitName = 'CSSComp';
78
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/css-comp');
79
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
80
- });
81
- it('should convert EN-US to en-us', () => {
82
- const bitName = 'EN-US';
83
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/en-us');
84
- });
85
- it('should convert AppBar to app-bar', () => {
86
- const bitName = 'AppBar';
87
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
88
- });
89
- it('should convert app-bar to app-bar', () => {
90
- const bitName = 'app-bar';
91
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
92
- });
93
- it('should convert app-Bar to app-bar', () => {
94
- const bitName = 'app-Bar';
95
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
96
- });
97
- it('should convert App-Bar to app-bar', () => {
98
- const bitName = 'App-Bar';
99
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
100
- });
101
- it('should convert CSScomp to cs-scomp ', () => {
102
- const bitName = 'CSScomp';
103
- (0, chai_1.expect)(bit_id_1.default.getValidBitId('global', bitName).toString()).to.equal('global/cs-scomp');
104
- });
105
- it('should convert CSS@comp/CSScomp to css@comp/cs-scomp ', () => {
106
- const bitName = 'CSScomp';
107
- const global = 'CSS@comp';
108
- (0, chai_1.expect)(bit_id_1.default.getValidBitId(global, bitName).toString()).to.equal('css@comp/cs-scomp');
109
- });
110
- it('should convert CSS!!####@comp/app-Bar to app-Bar', () => {
111
- const bitName = 'app-Bar';
112
- const global = 'CSS!!####@comp';
113
- (0, chai_1.expect)(bit_id_1.default.getValidBitId(global, bitName).toString()).to.equal('css!!####@comp/app-bar');
114
- });
115
- it('should convert app bar to app-bar', () => {
116
- const bitName = 'app bar';
117
- (0, chai_1.expect)(bit_id_1.default.getValidBitId(undefined, bitName).toString()).to.equal('app-bar');
118
- });
119
- });
120
- describe('toString', () => {
121
- it('should not contain the version as latest', () => {
122
- const bitId = bit_id_1.default.parse('bit.envs/mocha/react@latest');
123
- (0, chai_1.expect)(bitId.toString()).to.equal('bit.envs/mocha/react');
124
- });
125
- });
126
- describe('parse', () => {
127
- it('should parse id with scope correctly', () => {
128
- const bitId = bit_id_1.default.parse('scope/my/long/comp/id', true);
129
- (0, chai_1.expect)(bitId.scope).to.equal('scope');
130
- (0, chai_1.expect)(bitId.name).to.equal('my/long/comp/id');
131
- (0, chai_1.expect)(bitId.box).to.be.undefined;
132
- (0, chai_1.expect)(bitId.version).to.equal('latest');
133
- });
134
- it('should parse id without scope correctly', () => {
135
- const bitId = bit_id_1.default.parse('scope/my/long/comp/id', false);
136
- (0, chai_1.expect)(bitId.scope).to.be.null;
137
- (0, chai_1.expect)(bitId.name).to.equal('scope/my/long/comp/id');
138
- (0, chai_1.expect)(bitId.box).to.be.undefined;
139
- (0, chai_1.expect)(bitId.version).to.equal('latest');
140
- });
141
- it('should throw for an invalid id', () => {
142
- const bitId = () => bit_id_1.default.parse('scope/my/long/co*mp/id', false);
143
- (0, chai_1.expect)(bitId).to.throw();
144
- });
145
- });
146
- describe('hasSameScope', () => {
147
- it('should return true when it has the same scope', () => {
148
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name' });
149
- const anotherId = new bit_id_1.default({ scope: 'my-scope', name: 'another-name' });
150
- (0, chai_1.expect)(bitId.hasSameScope(anotherId)).to.be.true;
151
- });
152
- it('should return false when it does not the same scope', () => {
153
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name' });
154
- const anotherId = new bit_id_1.default({ scope: 'another-scope', name: 'my-name' });
155
- (0, chai_1.expect)(bitId.hasSameScope(anotherId)).to.be.false;
156
- });
157
- it('should return true when both scopes are null', () => {
158
- const bitId = new bit_id_1.default({ scope: null, name: 'my-name' });
159
- const anotherId = new bit_id_1.default({ scope: null, name: 'my-name' });
160
- (0, chai_1.expect)(bitId.hasSameScope(anotherId)).to.be.true;
161
- });
162
- it('should return false when one of the scope is null', () => {
163
- const bitId = new bit_id_1.default({ scope: null, name: 'my-name' });
164
- const anotherId = new bit_id_1.default({ scope: 'another-scope', name: 'my-name' });
165
- (0, chai_1.expect)(bitId.hasSameScope(anotherId)).to.be.false;
166
- });
167
- });
168
- describe('isEqual', () => {
169
- it('should return true for an exact match', () => {
170
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
171
- const anotherId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
172
- (0, chai_1.expect)(bitId.isEqual(anotherId)).to.be.true;
173
- });
174
- it('should return false for a version mismatch', () => {
175
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
176
- const anotherId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.2' });
177
- (0, chai_1.expect)(bitId.isEqual(anotherId)).to.be.false;
178
- });
179
- it('should return false for a name mismatch', () => {
180
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
181
- const anotherId = new bit_id_1.default({ scope: 'my-scope', name: 'another-name', version: '0.0.1' });
182
- (0, chai_1.expect)(bitId.isEqual(anotherId)).to.be.false;
183
- });
184
- it('should return false for a scope mismatch', () => {
185
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
186
- const anotherId = new bit_id_1.default({ scope: 'another-scope', name: 'my-name', version: '0.0.1' });
187
- (0, chai_1.expect)(bitId.isEqual(anotherId)).to.be.false;
188
- });
189
- });
190
- describe('serialize', () => {
191
- it('should delete the scope property if not set', () => {
192
- const bitId = new bit_id_1.default({ name: 'my-name', version: '0.0.1' });
193
- (0, chai_1.expect)(bitId.serialize()).to.not.have.property('scope');
194
- });
195
- it('should delete the version property if not set', () => {
196
- const bitId = new bit_id_1.default({ name: 'my-name' });
197
- (0, chai_1.expect)(bitId.serialize()).to.not.have.property('version');
198
- });
199
- it('should include all properties if they are all set', () => {
200
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
201
- (0, chai_1.expect)(bitId.serialize()).to.have.property('name');
202
- (0, chai_1.expect)(bitId.serialize()).to.have.property('scope');
203
- (0, chai_1.expect)(bitId.serialize()).to.have.property('version');
204
- });
205
- it('should not be an instance of BitId', () => {
206
- const bitId = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
207
- (0, chai_1.expect)(bitId.serialize()).to.not.be.an.instanceof(bit_id_1.default);
208
- });
209
- });
210
- describe('parseBackwardCompatible', () => {
211
- it('should parse the new format, which is an object', () => {
212
- const bitIdObj = new bit_id_1.default({ scope: 'my-scope', name: 'my-name', version: '0.0.1' }).serialize();
213
- const bitId = bit_id_1.default.parseBackwardCompatible(bitIdObj);
214
- (0, chai_1.expect)(bitId).to.be.an.instanceof(bit_id_1.default);
215
- (0, chai_1.expect)(bitId.name).to.equal('my-name');
216
- (0, chai_1.expect)(bitId.scope).to.equal('my-scope');
217
- (0, chai_1.expect)(bitId.version).to.equal('0.0.1');
218
- });
219
- it('should parse the old format, which is a string', () => {
220
- const bitIdStr = 'my-scope/my-box/my-name@0.0.1';
221
- const bitId = bit_id_1.default.parseBackwardCompatible(bitIdStr);
222
- (0, chai_1.expect)(bitId).to.be.an.instanceof(bit_id_1.default);
223
- (0, chai_1.expect)(bitId.name).to.equal('my-box/my-name');
224
- (0, chai_1.expect)(bitId.scope).to.equal('my-scope');
225
- (0, chai_1.expect)(bitId.version).to.equal('0.0.1');
226
- });
26
+ // TODO: those tests are now verified by TS compiler, I think we can remove them
27
+ it('should be frozen', () => {
28
+ const bitId = new (_bitId().default)({
29
+ name: 'my-name'
227
30
  });
31
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
32
+ (0, _chai().expect)(() => bitId.scope = 'name').to.throw();
33
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
34
+ (0, _chai().expect)(() => bitId.name = 'name').to.throw();
35
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
36
+ (0, _chai().expect)(() => bitId.version = 'name').to.throw();
37
+ });
38
+ describe('constructor', () => {
39
+ it('should not throw for an invalid scope as it hurts performance (it is done on .parse() instead)', () => {
40
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
41
+ const invalidScope = () => new (_bitId().default)({
42
+ scope: 123,
43
+ name: 'my-name'
44
+ });
45
+ (0, _chai().expect)(invalidScope).to.not.throw(_exceptions().InvalidScopeName);
46
+ });
47
+ it('should not throw for an invalid name as it hurts performance (it is done on .parse() instead)', () => {
48
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
49
+ const invalidName = () => new (_bitId().default)({
50
+ name: ['a', 'b']
51
+ });
52
+ (0, _chai().expect)(invalidName).to.not.throw(_exceptions().InvalidName);
53
+ });
54
+ it('should accept an empty scope', () => {
55
+ const invalidScope = () => new (_bitId().default)({
56
+ scope: null,
57
+ name: 'my-name'
58
+ });
59
+ (0, _chai().expect)(invalidScope).to.not.throw();
60
+ });
61
+ it('should not accept an empty name', () => {
62
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
63
+ (0, _chai().expect)(() => new (_bitId().default)({
64
+ scope: 'my-scope',
65
+ name: null
66
+ })).to.throw(_exceptions().InvalidName);
67
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
68
+ (0, _chai().expect)(() => new (_bitId().default)({
69
+ scope: 'my-scope',
70
+ name: undefined
71
+ })).to.throw(_exceptions().InvalidName);
72
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
73
+ (0, _chai().expect)(() => new (_bitId().default)({
74
+ scope: 'my-scope'
75
+ })).to.throw(_exceptions().InvalidName);
76
+ });
77
+ });
78
+ describe('changeScope', () => {
79
+ it('should return a new BitId with different scope', () => {
80
+ const bitId = new (_bitId().default)({
81
+ name: 'my-name'
82
+ });
83
+ (0, _chai().expect)(bitId.changeScope('my-scope')).to.have.property('scope').that.equal('my-scope');
84
+ });
85
+ it('should accept an empty parameter to remove the scope', () => {
86
+ const bitId = new (_bitId().default)({
87
+ scope: 'my-scope',
88
+ name: 'my-name'
89
+ });
90
+ (0, _chai().expect)(bitId.changeScope()).to.have.property('scope').that.is.null;
91
+ });
92
+ });
93
+ describe('changeVersion', () => {
94
+ it('should return a new BitId with different version', () => {
95
+ const bitId = new (_bitId().default)({
96
+ name: 'my-name'
97
+ });
98
+ (0, _chai().expect)(bitId.changeVersion('0.0.1')).to.have.property('version').that.equal('0.0.1');
99
+ });
100
+ it('should accept an empty parameter to remove the version', () => {
101
+ const bitId = new (_bitId().default)({
102
+ scope: 'my-scope',
103
+ name: 'my-name',
104
+ version: '0.0.1'
105
+ });
106
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
107
+ (0, _chai().expect)(bitId.changeVersion()).to.have.property('version').that.is.undefined;
108
+ });
109
+ });
110
+ describe('hasScope', () => {
111
+ it('should return false when there is no scope', () => {
112
+ const bitId = new (_bitId().default)({
113
+ name: 'my-name'
114
+ });
115
+ (0, _chai().expect)(bitId.hasScope()).to.be.false;
116
+ });
117
+ it('should return true when there is scope', () => {
118
+ const bitId = new (_bitId().default)({
119
+ scope: 'my-scope',
120
+ name: 'my-name'
121
+ });
122
+ (0, _chai().expect)(bitId.hasScope()).to.be.true;
123
+ });
124
+ });
125
+ describe('getValidBitId', () => {
126
+ it('should convert CSSComp to css-comp', () => {
127
+ const bitName = 'CSSComp';
128
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/css-comp');
129
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
130
+ });
131
+
132
+ it('should convert EN-US to en-us', () => {
133
+ const bitName = 'EN-US';
134
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/en-us');
135
+ });
136
+ it('should convert AppBar to app-bar', () => {
137
+ const bitName = 'AppBar';
138
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
139
+ });
140
+ it('should convert app-bar to app-bar', () => {
141
+ const bitName = 'app-bar';
142
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
143
+ });
144
+ it('should convert app-Bar to app-bar', () => {
145
+ const bitName = 'app-Bar';
146
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
147
+ });
148
+ it('should convert App-Bar to app-bar', () => {
149
+ const bitName = 'App-Bar';
150
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
151
+ });
152
+ it('should convert CSScomp to cs-scomp ', () => {
153
+ const bitName = 'CSScomp';
154
+ (0, _chai().expect)(_bitId().default.getValidBitId('global', bitName).toString()).to.equal('global/cs-scomp');
155
+ });
156
+ it('should convert CSS@comp/CSScomp to css@comp/cs-scomp ', () => {
157
+ const bitName = 'CSScomp';
158
+ const global = 'CSS@comp';
159
+ (0, _chai().expect)(_bitId().default.getValidBitId(global, bitName).toString()).to.equal('css@comp/cs-scomp');
160
+ });
161
+ it('should convert CSS!!####@comp/app-Bar to app-Bar', () => {
162
+ const bitName = 'app-Bar';
163
+ const global = 'CSS!!####@comp';
164
+ (0, _chai().expect)(_bitId().default.getValidBitId(global, bitName).toString()).to.equal('css!!####@comp/app-bar');
165
+ });
166
+ it('should convert app bar to app-bar', () => {
167
+ const bitName = 'app bar';
168
+ (0, _chai().expect)(_bitId().default.getValidBitId(undefined, bitName).toString()).to.equal('app-bar');
169
+ });
170
+ });
171
+ describe('toString', () => {
172
+ it('should not contain the version as latest', () => {
173
+ const bitId = _bitId().default.parse('bit.envs/mocha/react@latest');
174
+ (0, _chai().expect)(bitId.toString()).to.equal('bit.envs/mocha/react');
175
+ });
176
+ });
177
+ describe('parse', () => {
178
+ it('should parse id with scope correctly', () => {
179
+ const bitId = _bitId().default.parse('scope/my/long/comp/id', true);
180
+ (0, _chai().expect)(bitId.scope).to.equal('scope');
181
+ (0, _chai().expect)(bitId.name).to.equal('my/long/comp/id');
182
+ (0, _chai().expect)(bitId.box).to.be.undefined;
183
+ (0, _chai().expect)(bitId.version).to.equal('latest');
184
+ });
185
+ it('should parse id without scope correctly', () => {
186
+ const bitId = _bitId().default.parse('scope/my/long/comp/id', false);
187
+ (0, _chai().expect)(bitId.scope).to.be.null;
188
+ (0, _chai().expect)(bitId.name).to.equal('scope/my/long/comp/id');
189
+ (0, _chai().expect)(bitId.box).to.be.undefined;
190
+ (0, _chai().expect)(bitId.version).to.equal('latest');
191
+ });
192
+ it('should throw for an invalid id', () => {
193
+ const bitId = () => _bitId().default.parse('scope/my/long/co*mp/id', false);
194
+ (0, _chai().expect)(bitId).to.throw();
195
+ });
196
+ });
197
+ describe('hasSameScope', () => {
198
+ it('should return true when it has the same scope', () => {
199
+ const bitId = new (_bitId().default)({
200
+ scope: 'my-scope',
201
+ name: 'my-name'
202
+ });
203
+ const anotherId = new (_bitId().default)({
204
+ scope: 'my-scope',
205
+ name: 'another-name'
206
+ });
207
+ (0, _chai().expect)(bitId.hasSameScope(anotherId)).to.be.true;
208
+ });
209
+ it('should return false when it does not the same scope', () => {
210
+ const bitId = new (_bitId().default)({
211
+ scope: 'my-scope',
212
+ name: 'my-name'
213
+ });
214
+ const anotherId = new (_bitId().default)({
215
+ scope: 'another-scope',
216
+ name: 'my-name'
217
+ });
218
+ (0, _chai().expect)(bitId.hasSameScope(anotherId)).to.be.false;
219
+ });
220
+ it('should return true when both scopes are null', () => {
221
+ const bitId = new (_bitId().default)({
222
+ scope: null,
223
+ name: 'my-name'
224
+ });
225
+ const anotherId = new (_bitId().default)({
226
+ scope: null,
227
+ name: 'my-name'
228
+ });
229
+ (0, _chai().expect)(bitId.hasSameScope(anotherId)).to.be.true;
230
+ });
231
+ it('should return false when one of the scope is null', () => {
232
+ const bitId = new (_bitId().default)({
233
+ scope: null,
234
+ name: 'my-name'
235
+ });
236
+ const anotherId = new (_bitId().default)({
237
+ scope: 'another-scope',
238
+ name: 'my-name'
239
+ });
240
+ (0, _chai().expect)(bitId.hasSameScope(anotherId)).to.be.false;
241
+ });
242
+ });
243
+ describe('isEqual', () => {
244
+ it('should return true for an exact match', () => {
245
+ const bitId = new (_bitId().default)({
246
+ scope: 'my-scope',
247
+ name: 'my-name',
248
+ version: '0.0.1'
249
+ });
250
+ const anotherId = new (_bitId().default)({
251
+ scope: 'my-scope',
252
+ name: 'my-name',
253
+ version: '0.0.1'
254
+ });
255
+ (0, _chai().expect)(bitId.isEqual(anotherId)).to.be.true;
256
+ });
257
+ it('should return false for a version mismatch', () => {
258
+ const bitId = new (_bitId().default)({
259
+ scope: 'my-scope',
260
+ name: 'my-name',
261
+ version: '0.0.1'
262
+ });
263
+ const anotherId = new (_bitId().default)({
264
+ scope: 'my-scope',
265
+ name: 'my-name',
266
+ version: '0.0.2'
267
+ });
268
+ (0, _chai().expect)(bitId.isEqual(anotherId)).to.be.false;
269
+ });
270
+ it('should return false for a name mismatch', () => {
271
+ const bitId = new (_bitId().default)({
272
+ scope: 'my-scope',
273
+ name: 'my-name',
274
+ version: '0.0.1'
275
+ });
276
+ const anotherId = new (_bitId().default)({
277
+ scope: 'my-scope',
278
+ name: 'another-name',
279
+ version: '0.0.1'
280
+ });
281
+ (0, _chai().expect)(bitId.isEqual(anotherId)).to.be.false;
282
+ });
283
+ it('should return false for a scope mismatch', () => {
284
+ const bitId = new (_bitId().default)({
285
+ scope: 'my-scope',
286
+ name: 'my-name',
287
+ version: '0.0.1'
288
+ });
289
+ const anotherId = new (_bitId().default)({
290
+ scope: 'another-scope',
291
+ name: 'my-name',
292
+ version: '0.0.1'
293
+ });
294
+ (0, _chai().expect)(bitId.isEqual(anotherId)).to.be.false;
295
+ });
296
+ });
297
+ describe('serialize', () => {
298
+ it('should delete the scope property if not set', () => {
299
+ const bitId = new (_bitId().default)({
300
+ name: 'my-name',
301
+ version: '0.0.1'
302
+ });
303
+ (0, _chai().expect)(bitId.serialize()).to.not.have.property('scope');
304
+ });
305
+ it('should delete the version property if not set', () => {
306
+ const bitId = new (_bitId().default)({
307
+ name: 'my-name'
308
+ });
309
+ (0, _chai().expect)(bitId.serialize()).to.not.have.property('version');
310
+ });
311
+ it('should include all properties if they are all set', () => {
312
+ const bitId = new (_bitId().default)({
313
+ scope: 'my-scope',
314
+ name: 'my-name',
315
+ version: '0.0.1'
316
+ });
317
+ (0, _chai().expect)(bitId.serialize()).to.have.property('name');
318
+ (0, _chai().expect)(bitId.serialize()).to.have.property('scope');
319
+ (0, _chai().expect)(bitId.serialize()).to.have.property('version');
320
+ });
321
+ it('should not be an instance of BitId', () => {
322
+ const bitId = new (_bitId().default)({
323
+ scope: 'my-scope',
324
+ name: 'my-name',
325
+ version: '0.0.1'
326
+ });
327
+ (0, _chai().expect)(bitId.serialize()).to.not.be.an.instanceof(_bitId().default);
328
+ });
329
+ });
330
+ describe('parseBackwardCompatible', () => {
331
+ it('should parse the new format, which is an object', () => {
332
+ const bitIdObj = new (_bitId().default)({
333
+ scope: 'my-scope',
334
+ name: 'my-name',
335
+ version: '0.0.1'
336
+ }).serialize();
337
+ const bitId = _bitId().default.parseBackwardCompatible(bitIdObj);
338
+ (0, _chai().expect)(bitId).to.be.an.instanceof(_bitId().default);
339
+ (0, _chai().expect)(bitId.name).to.equal('my-name');
340
+ (0, _chai().expect)(bitId.scope).to.equal('my-scope');
341
+ (0, _chai().expect)(bitId.version).to.equal('0.0.1');
342
+ });
343
+ it('should parse the old format, which is a string', () => {
344
+ const bitIdStr = 'my-scope/my-box/my-name@0.0.1';
345
+ const bitId = _bitId().default.parseBackwardCompatible(bitIdStr);
346
+ (0, _chai().expect)(bitId).to.be.an.instanceof(_bitId().default);
347
+ (0, _chai().expect)(bitId.name).to.equal('my-box/my-name');
348
+ (0, _chai().expect)(bitId.scope).to.equal('my-scope');
349
+ (0, _chai().expect)(bitId.version).to.equal('0.0.1');
350
+ });
351
+ });
228
352
  });
353
+
229
354
  //# sourceMappingURL=bit-id.spec.js.map