@teambit/workspace 0.0.693 → 0.0.696
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/component-tree.widget.tsx +1 -1
- package/dist/bit-map.d.ts +1 -0
- package/dist/bit-map.js +35 -0
- package/dist/bit-map.js.map +1 -1
- package/dist/component-tree.widget.js +1 -1
- package/dist/component-tree.widget.js.map +1 -1
- package/dist/envs-subcommands/envs-replace.cmd.js +1 -1
- package/dist/envs-subcommands/envs-replace.cmd.js.map +1 -1
- package/dist/workspace.d.ts +8 -1
- package/dist/workspace.js +56 -6
- package/dist/workspace.js.map +1 -1
- package/envs-subcommands/envs-replace.cmd.ts +1 -1
- package/package-tar/teambit-workspace-0.0.696.tgz +0 -0
- package/package.json +36 -36
- package/{preview-1648524148272.js → preview-1648783740851.js} +2 -2
- package/package-tar/teambit-workspace-0.0.693.tgz +0 -0
|
@@ -13,7 +13,7 @@ export class ComponentTreeWidget implements ComponentTreeNode {
|
|
|
13
13
|
|
|
14
14
|
const isInCurrentLane = useMemo(() => {
|
|
15
15
|
return workspaceComponent?.id && lanes?.isInCurrentLane(workspaceComponent.id);
|
|
16
|
-
}, [lanes?.
|
|
16
|
+
}, [lanes?.viewedLane, workspaceComponent?.id]);
|
|
17
17
|
|
|
18
18
|
if (!workspaceComponent) return null;
|
|
19
19
|
|
package/dist/bit-map.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare class BitMap {
|
|
|
28
28
|
* get the data saved in the .bitmap file for this component-id.
|
|
29
29
|
*/
|
|
30
30
|
getBitmapEntry(id: ComponentID, { ignoreVersion, ignoreScopeAndVersion }?: GetBitMapComponentOptions): ComponentMap;
|
|
31
|
+
getAspectIdFromConfig(componentId: ComponentID, aspectId: ComponentID, ignoreAspectVersion?: boolean): string | undefined;
|
|
31
32
|
/**
|
|
32
33
|
* components that were not tagged yet are safe to rename them from the .bitmap file.
|
|
33
34
|
*/
|
package/dist/bit-map.js
CHANGED
|
@@ -27,6 +27,16 @@ function _config() {
|
|
|
27
27
|
return data;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
function _bitError() {
|
|
31
|
+
const data = require("@teambit/bit-error");
|
|
32
|
+
|
|
33
|
+
_bitError = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
/**
|
|
31
41
|
* consider extracting to a new component.
|
|
32
42
|
* (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)
|
|
@@ -124,6 +134,31 @@ class BitMap {
|
|
|
124
134
|
ignoreScopeAndVersion
|
|
125
135
|
});
|
|
126
136
|
}
|
|
137
|
+
|
|
138
|
+
getAspectIdFromConfig(componentId, aspectId, ignoreAspectVersion = false) {
|
|
139
|
+
const bitMapEntry = this.getBitmapEntry(componentId);
|
|
140
|
+
const config = bitMapEntry.config;
|
|
141
|
+
|
|
142
|
+
if (!config) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (config[aspectId.toString()]) {
|
|
147
|
+
return aspectId.toString();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!ignoreAspectVersion) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const allVersions = Object.keys(config).filter(id => id.startsWith(`${aspectId.toStringWithoutVersion()}@`));
|
|
155
|
+
|
|
156
|
+
if (allVersions.length > 1) {
|
|
157
|
+
throw new (_bitError().BitError)(`error: the same aspect ${aspectId.toStringWithoutVersion} configured multiple times for "${componentId.toString()}"\n${allVersions.join('\n')}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return allVersions.length === 1 ? allVersions[0] : undefined;
|
|
161
|
+
}
|
|
127
162
|
/**
|
|
128
163
|
* components that were not tagged yet are safe to rename them from the .bitmap file.
|
|
129
164
|
*/
|
package/dist/bit-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["bit-map.ts"],"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","write","writeBitMap","ignoreVersion","getComponent","_legacy","renameNewComponent","sourceId","targetId","hasVersion","
|
|
1
|
+
{"version":3,"sources":["bit-map.ts"],"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","write","writeBitMap","ignoreVersion","getComponent","_legacy","getAspectIdFromConfig","componentId","ignoreAspectVersion","undefined","toString","allVersions","Object","keys","filter","startsWith","toStringWithoutVersion","length","BitError","join","renameNewComponent","sourceId","targetId","hasVersion","removeComponent","setComponent"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;AAClBC,EAAAA,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;AAAA,SAAxDD,YAAwD,GAAxDA,YAAwD;AAAA,SAApBC,QAAoB,GAApBA,QAAoB;AAAE;AAE9E;AACF;AACA;AACA;AACA;;;AACEC,EAAAA,kBAAkB,CAACC,EAAD,EAAkBC,QAAlB,EAAoCC,MAA2B,GAAG,EAAlE,EAA+E;AAC/F,QAAI,CAACD,QAAD,IAAa,OAAOA,QAAP,KAAoB,QAArC,EAA+C,MAAM,IAAIE,KAAJ,CAAW,qCAAoCF,QAAS,EAAxD,CAAN;AAC/C,UAAMG,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V,EAAiC;AAC/B,aAAOtB,QAAQ,CAACsB,QAAT,EAAP;AACD;;AACD,QAAI,CAACF,mBAAL,EAA0B;AACxB,aAAOC,SAAP;AACD;;AACD,UAAME,WAAW,GAAGC,MAAM,CAACC,IAAP,CAAYxB,MAAZ,EAAoByB,MAApB,CAA4B3B,EAAD,IAAQA,EAAE,CAAC4B,UAAH,CAAe,GAAE3B,QAAQ,CAAC4B,sBAAT,EAAkC,GAAnD,CAAnC,CAApB;;AACA,QAAIL,WAAW,CAACM,MAAZ,GAAqB,CAAzB,EAA4B;AAC1B,YAAM,KAAIC,oBAAJ,EACH,0BACC9B,QAAQ,CAAC4B,sBACV,mCAAkCT,WAAW,CAACG,QAAZ,EAAuB,MAAKC,WAAW,CAACQ,IAAZ,CAAiB,IAAjB,CAAuB,EAHlF,CAAN;AAKD;;AACD,WAAOR,WAAW,CAACM,MAAZ,KAAuB,CAAvB,GAA2BN,WAAW,CAAC,CAAD,CAAtC,GAA4CF,SAAnD;AACD;AAED;AACF;AACA;;;AACEW,EAAAA,kBAAkB,CAACC,QAAD,EAAwBC,QAAxB,EAA+C;AAC/D,UAAM/B,WAAW,GAAG,KAAKC,cAAL,CAAoB6B,QAApB,CAApB;;AACA,QAAI9B,WAAW,CAACJ,EAAZ,CAAeoC,UAAf,EAAJ,EAAiC;AAC/B,YAAM,IAAIjC,KAAJ,CAAW,kDAAiDC,WAAW,CAACJ,EAAZ,CAAeuB,QAAf,EAA0B,EAAtF,CAAN;AACD;;AACD,SAAK1B,YAAL,CAAkBwC,eAAlB,CAAkCjC,WAAW,CAACJ,EAA9C;AACAI,IAAAA,WAAW,CAACJ,EAAZ,GAAiBmC,QAAQ,CAACjB,OAA1B;AACA,SAAKrB,YAAL,CAAkByC,YAAlB,CAA+BlC,WAAW,CAACJ,EAA3C,EAA+CI,WAA/C;AACD;;AAhHiB","sourcesContent":["import { isEqual } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\nimport { BitError } from '@teambit/bit-error';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n addComponentConfig(id: ComponentID, aspectId: string, config: Record<string, any> = {}): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n if (!config) {\n delete bitMapEntry.config[aspectId];\n } else {\n bitMapEntry.config[aspectId] = config;\n }\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (currentConfig) {\n delete bitMapEntry.config[aspectId];\n } else {\n if (!markWithMinusIfNotExist) {\n return false; // no changes\n }\n bitMapEntry.config[aspectId] = REMOVE_EXTENSION_SPECIAL_SIGN;\n }\n\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeEntireConfig(id: ComponentID): boolean {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (!bitMapEntry.config) return false;\n delete bitMapEntry.config;\n this.legacyBitMap.markAsChanged();\n return true;\n }\n\n setEntireConfig(id: ComponentID, config: Record<string, any>) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.config = config;\n this.legacyBitMap.markAsChanged();\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n getAspectIdFromConfig(\n componentId: ComponentID,\n aspectId: ComponentID,\n ignoreAspectVersion = false\n ): string | undefined {\n const bitMapEntry = this.getBitmapEntry(componentId);\n const config = bitMapEntry.config;\n if (!config) {\n return undefined;\n }\n if (config[aspectId.toString()]) {\n return aspectId.toString();\n }\n if (!ignoreAspectVersion) {\n return undefined;\n }\n const allVersions = Object.keys(config).filter((id) => id.startsWith(`${aspectId.toStringWithoutVersion()}@`));\n if (allVersions.length > 1) {\n throw new BitError(\n `error: the same aspect ${\n aspectId.toStringWithoutVersion\n } configured multiple times for \"${componentId.toString()}\"\\n${allVersions.join('\\n')}`\n );\n }\n return allVersions.length === 1 ? allVersions[0] : undefined;\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n}\n"]}
|
|
@@ -71,7 +71,7 @@ class ComponentTreeWidget {
|
|
|
71
71
|
const lanes = (0, _lanesUi().useLanesContext)();
|
|
72
72
|
const isInCurrentLane = (0, _react().useMemo)(() => {
|
|
73
73
|
return (workspaceComponent === null || workspaceComponent === void 0 ? void 0 : workspaceComponent.id) && (lanes === null || lanes === void 0 ? void 0 : lanes.isInCurrentLane(workspaceComponent.id));
|
|
74
|
-
}, [lanes === null || lanes === void 0 ? void 0 : lanes.
|
|
74
|
+
}, [lanes === null || lanes === void 0 ? void 0 : lanes.viewedLane, workspaceComponent === null || workspaceComponent === void 0 ? void 0 : workspaceComponent.id]);
|
|
75
75
|
if (!workspaceComponent) return null;
|
|
76
76
|
return /*#__PURE__*/_react().default.createElement(_componentUi().ComponentStatusResolver, {
|
|
77
77
|
status: workspaceComponent.status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component-tree.widget.tsx"],"names":["ComponentTreeWidget","component","workspace","WorkspaceContext","workspaceComponent","getComponent","id","lanes","isInCurrentLane","
|
|
1
|
+
{"version":3,"sources":["component-tree.widget.tsx"],"names":["ComponentTreeWidget","component","workspace","WorkspaceContext","workspaceComponent","getComponent","id","lanes","isInCurrentLane","viewedLane","status","issuesCount"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEO,MAAMA,mBAAN,CAAuD;AAAA;AAAA,oDACnD,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAA2C;AAClD,YAAMC,SAAS,GAAG,yBAAWC,oCAAX,CAAlB;AACA,YAAMC,kBAAkB,GAAGF,SAAS,CAACG,YAAV,CAAuBJ,SAAS,CAACK,EAAjC,CAA3B;AACA,YAAMC,KAAK,GAAG,iCAAd;AAEA,YAAMC,eAAe,GAAG,sBAAQ,MAAM;AACpC,eAAO,CAAAJ,kBAAkB,SAAlB,IAAAA,kBAAkB,WAAlB,YAAAA,kBAAkB,CAAEE,EAApB,MAA0BC,KAA1B,aAA0BA,KAA1B,uBAA0BA,KAAK,CAAEC,eAAP,CAAuBJ,kBAAkB,CAACE,EAA1C,CAA1B,CAAP;AACD,OAFuB,EAErB,CAACC,KAAD,aAACA,KAAD,uBAACA,KAAK,CAAEE,UAAR,EAAoBL,kBAApB,aAAoBA,kBAApB,uBAAoBA,kBAAkB,CAAEE,EAAxC,CAFqB,CAAxB;AAIA,UAAI,CAACF,kBAAL,EAAyB,OAAO,IAAP;AAEzB,0BACE,+BAAC,sCAAD;AACE,QAAA,MAAM,EAAEA,kBAAkB,CAACM,MAD7B;AAEE,QAAA,WAAW,EAAEN,kBAAkB,CAACO,WAFlC;AAGE,QAAA,eAAe,EAAEH;AAHnB,QADF;AAOD,KAnB2D;AAAA;;AAAA","sourcesContent":["import { ComponentTreeNode, ComponentTreeNodeProps } from '@teambit/component-tree';\nimport { ComponentStatusResolver } from '@teambit/component.ui.component-status-resolver';\nimport React, { useContext, useMemo } from 'react';\n\nimport { useLanesContext } from '@teambit/lanes.ui.lanes';\nimport { WorkspaceContext } from './ui/workspace/workspace-context';\n\nexport class ComponentTreeWidget implements ComponentTreeNode {\n widget = ({ component }: ComponentTreeNodeProps) => {\n const workspace = useContext(WorkspaceContext);\n const workspaceComponent = workspace.getComponent(component.id);\n const lanes = useLanesContext();\n\n const isInCurrentLane = useMemo(() => {\n return workspaceComponent?.id && lanes?.isInCurrentLane(workspaceComponent.id);\n }, [lanes?.viewedLane, workspaceComponent?.id]);\n\n if (!workspaceComponent) return null;\n\n return (\n <ComponentStatusResolver\n status={workspaceComponent.status}\n issuesCount={workspaceComponent.issuesCount}\n isInCurrentLane={isInCurrentLane}\n />\n );\n };\n}\n"]}
|
|
@@ -42,7 +42,7 @@ class EnvsReplaceCmd {
|
|
|
42
42
|
|
|
43
43
|
async report([oldEnv, env]) {
|
|
44
44
|
const envId = await this.workspace.resolveComponentId(env);
|
|
45
|
-
const components = await this.workspace.getComponentsUsingEnv(oldEnv, true);
|
|
45
|
+
const components = await this.workspace.getComponentsUsingEnv(oldEnv, true, true);
|
|
46
46
|
const componentIds = components.map(comp => comp.id);
|
|
47
47
|
await this.workspace.setEnvToComponents(envId, componentIds);
|
|
48
48
|
return `added ${_chalk().default.bold(envId.toString())} env to the following component(s):
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["envs-replace.cmd.ts"],"names":["EnvsReplaceCmd","constructor","workspace","report","oldEnv","env","envId","resolveComponentId","components","getComponentsUsingEnv","componentIds","map","comp","id","setEnvToComponents","chalk","bold","toString","compId","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;AAM7CC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDALnC,6BAKmC;AAAA,yDAJ5B,+EAI4B;AAAA,qDAHhC,EAGgC;AAAA,mDAFlC,aAEkC;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,MAAD,EAASC,GAAT,CAAD,EAAkC;AAC5C,UAAMC,KAAK,GAAG,MAAM,KAAKJ,SAAL,CAAeK,kBAAf,CAAkCF,GAAlC,CAApB;AACA,UAAMG,UAAU,GAAG,MAAM,KAAKN,SAAL,CAAeO,qBAAf,CAAqCL,MAArC,EAA6C,IAA7C,CAAzB;AACA,UAAMM,YAAY,GAAGF,UAAU,CAACG,GAAX,CAAgBC,IAAD,IAAUA,IAAI,CAACC,EAA9B,CAArB;AACA,UAAM,KAAKX,SAAL,CAAeY,kBAAf,CAAkCR,KAAlC,EAAyCI,YAAzC,CAAN;AACA,WAAQ,SAAQK,iBAAMC,IAAN,CAAWV,KAAK,CAACW,QAAN,EAAX,CAA6B;AACjD,EAAEP,YAAY,CAACC,GAAb,CAAkBO,MAAD,IAAYA,MAAM,CAACD,QAAP,EAA7B,EAAgDE,IAAhD,CAAqD,IAArD,CAA2D,EADzD;AAED;;AAf4C","sourcesContent":["import { Command } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from '../workspace';\n\nexport class EnvsReplaceCmd implements Command {\n name = 'replace <old-env> <new-env>';\n description = 'replace an existing env with another env for all components using the old env';\n options = [];\n group = 'development';\n\n constructor(private workspace: Workspace) {}\n\n async report([oldEnv, env]: [string, string]) {\n const envId = await this.workspace.resolveComponentId(env);\n const components = await this.workspace.getComponentsUsingEnv(oldEnv, true);\n const componentIds = components.map((comp) => comp.id);\n await this.workspace.setEnvToComponents(envId, componentIds);\n return `added ${chalk.bold(envId.toString())} env to the following component(s):\n${componentIds.map((compId) => compId.toString()).join('\\n')}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["envs-replace.cmd.ts"],"names":["EnvsReplaceCmd","constructor","workspace","report","oldEnv","env","envId","resolveComponentId","components","getComponentsUsingEnv","componentIds","map","comp","id","setEnvToComponents","chalk","bold","toString","compId","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;AAM7CC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDALnC,6BAKmC;AAAA,yDAJ5B,+EAI4B;AAAA,qDAHhC,EAGgC;AAAA,mDAFlC,aAEkC;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,MAAD,EAASC,GAAT,CAAD,EAAkC;AAC5C,UAAMC,KAAK,GAAG,MAAM,KAAKJ,SAAL,CAAeK,kBAAf,CAAkCF,GAAlC,CAApB;AACA,UAAMG,UAAU,GAAG,MAAM,KAAKN,SAAL,CAAeO,qBAAf,CAAqCL,MAArC,EAA6C,IAA7C,EAAmD,IAAnD,CAAzB;AACA,UAAMM,YAAY,GAAGF,UAAU,CAACG,GAAX,CAAgBC,IAAD,IAAUA,IAAI,CAACC,EAA9B,CAArB;AACA,UAAM,KAAKX,SAAL,CAAeY,kBAAf,CAAkCR,KAAlC,EAAyCI,YAAzC,CAAN;AACA,WAAQ,SAAQK,iBAAMC,IAAN,CAAWV,KAAK,CAACW,QAAN,EAAX,CAA6B;AACjD,EAAEP,YAAY,CAACC,GAAb,CAAkBO,MAAD,IAAYA,MAAM,CAACD,QAAP,EAA7B,EAAgDE,IAAhD,CAAqD,IAArD,CAA2D,EADzD;AAED;;AAf4C","sourcesContent":["import { Command } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from '../workspace';\n\nexport class EnvsReplaceCmd implements Command {\n name = 'replace <old-env> <new-env>';\n description = 'replace an existing env with another env for all components using the old env';\n options = [];\n group = 'development';\n\n constructor(private workspace: Workspace) {}\n\n async report([oldEnv, env]: [string, string]) {\n const envId = await this.workspace.resolveComponentId(env);\n const components = await this.workspace.getComponentsUsingEnv(oldEnv, true, true);\n const componentIds = components.map((comp) => comp.id);\n await this.workspace.setEnvToComponents(envId, componentIds);\n return `added ${chalk.bold(envId.toString())} env to the following component(s):\n${componentIds.map((compId) => compId.toString()).join('\\n')}`;\n }\n}\n"]}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -298,7 +298,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
298
298
|
* some commands such as build/test needs to run also on the dependents.
|
|
299
299
|
*/
|
|
300
300
|
getComponentsByUserInput(all?: boolean, pattern?: string, includeDependents?: boolean): Promise<Component[]>;
|
|
301
|
-
getComponentsUsingEnv(env: string, throwIfNotFound?: boolean): Promise<Component[]>;
|
|
301
|
+
getComponentsUsingEnv(env: string, ignoreVersion?: boolean, throwIfNotFound?: boolean): Promise<Component[]>;
|
|
302
302
|
getMany(ids: Array<ComponentID>, forCapsule?: boolean): Promise<Component[]>;
|
|
303
303
|
getManyByLegacy(components: ConsumerComponent[]): Promise<Component[]>;
|
|
304
304
|
/**
|
|
@@ -387,6 +387,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
387
387
|
triggerOnPreWatch(componentIds: ComponentID[], watchOpts: WatchOptions): Promise<void>;
|
|
388
388
|
addSpecificComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any>): Promise<void>;
|
|
389
389
|
removeSpecificComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): Promise<void>;
|
|
390
|
+
getAspectIdFromConfig(componentId: ComponentID, aspectIdStr: string, ignoreAspectVersion?: boolean): Promise<string | undefined>;
|
|
390
391
|
getSpecificComponentConfig(id: ComponentID, aspectId: string): Promise<any>;
|
|
391
392
|
/**
|
|
392
393
|
* This will mutate the entries with extensionId prop to have resolved legacy id
|
|
@@ -511,6 +512,12 @@ export declare class Workspace implements ComponentFactory {
|
|
|
511
512
|
* overrides in workspace.jsonc.
|
|
512
513
|
*/
|
|
513
514
|
setEnvToComponents(envId: ComponentID, componentIds: ComponentID[]): Promise<void>;
|
|
515
|
+
/**
|
|
516
|
+
* helpful when a user provides an env-string to be set and this env has no version.
|
|
517
|
+
* in the workspace config, a custom-env needs to be set with a version unless it's part of the workspace.
|
|
518
|
+
* (inside envs/envs it's set without a version).
|
|
519
|
+
*/
|
|
520
|
+
resolveEnvIdWithPotentialVersionForConfig(envId: ComponentID): Promise<string>;
|
|
514
521
|
/**
|
|
515
522
|
* remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
|
|
516
523
|
*/
|
package/dist/workspace.js
CHANGED
|
@@ -1183,10 +1183,15 @@ class Workspace {
|
|
|
1183
1183
|
return newAndModified;
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
|
-
async getComponentsUsingEnv(env, throwIfNotFound = false) {
|
|
1186
|
+
async getComponentsUsingEnv(env, ignoreVersion = true, throwIfNotFound = false) {
|
|
1187
1187
|
const allComps = await this.list();
|
|
1188
1188
|
const allEnvs = await this.envs.createEnvironment(allComps);
|
|
1189
|
-
const foundEnv = allEnvs.runtimeEnvs.find(runtimeEnv =>
|
|
1189
|
+
const foundEnv = allEnvs.runtimeEnvs.find(runtimeEnv => {
|
|
1190
|
+
if (runtimeEnv.id === env) return true;
|
|
1191
|
+
if (!ignoreVersion) return false;
|
|
1192
|
+
const envWithoutVersion = runtimeEnv.id.split('@')[0];
|
|
1193
|
+
return env === envWithoutVersion;
|
|
1194
|
+
});
|
|
1190
1195
|
|
|
1191
1196
|
if (!foundEnv && throwIfNotFound) {
|
|
1192
1197
|
const availableEnvs = allEnvs.runtimeEnvs.map(runtimeEnv => runtimeEnv.id);
|
|
@@ -1636,6 +1641,18 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1636
1641
|
}
|
|
1637
1642
|
}
|
|
1638
1643
|
|
|
1644
|
+
async getAspectIdFromConfig(componentId, aspectIdStr, ignoreAspectVersion = false) {
|
|
1645
|
+
const aspectId = await this.resolveComponentId(aspectIdStr);
|
|
1646
|
+
const componentConfigFile = await this.componentConfigFile(componentId);
|
|
1647
|
+
|
|
1648
|
+
if (componentConfigFile) {
|
|
1649
|
+
const aspectEntry = componentConfigFile.aspects.find(aspectId, ignoreAspectVersion);
|
|
1650
|
+
return aspectEntry === null || aspectEntry === void 0 ? void 0 : aspectEntry.id.toString();
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
return this.bitMap.getAspectIdFromConfig(componentId, aspectId, ignoreAspectVersion);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1639
1656
|
async getSpecificComponentConfig(id, aspectId) {
|
|
1640
1657
|
var _this$bitMap$getBitma;
|
|
1641
1658
|
|
|
@@ -2560,18 +2577,50 @@ your workspace.jsonc has this component-id set. you might want to remove/change
|
|
|
2560
2577
|
|
|
2561
2578
|
|
|
2562
2579
|
async setEnvToComponents(envId, componentIds) {
|
|
2563
|
-
const
|
|
2564
|
-
const existsOnWorkspace = await this.hasId(envId);
|
|
2580
|
+
const envStrWithPossiblyVersion = await this.resolveEnvIdWithPotentialVersionForConfig(envId);
|
|
2565
2581
|
const envIdStrNoVersion = envId.toStringWithoutVersion();
|
|
2566
2582
|
await this.unsetEnvFromComponents(componentIds);
|
|
2567
2583
|
await Promise.all(componentIds.map(async componentId => {
|
|
2568
|
-
await this.addSpecificComponentConfig(componentId,
|
|
2584
|
+
await this.addSpecificComponentConfig(componentId, envStrWithPossiblyVersion);
|
|
2569
2585
|
await this.addSpecificComponentConfig(componentId, _envs().EnvsAspect.id, {
|
|
2570
2586
|
env: envIdStrNoVersion
|
|
2571
2587
|
});
|
|
2572
2588
|
}));
|
|
2573
2589
|
await this.bitMap.write();
|
|
2574
2590
|
}
|
|
2591
|
+
/**
|
|
2592
|
+
* helpful when a user provides an env-string to be set and this env has no version.
|
|
2593
|
+
* in the workspace config, a custom-env needs to be set with a version unless it's part of the workspace.
|
|
2594
|
+
* (inside envs/envs it's set without a version).
|
|
2595
|
+
*/
|
|
2596
|
+
|
|
2597
|
+
|
|
2598
|
+
async resolveEnvIdWithPotentialVersionForConfig(envId) {
|
|
2599
|
+
var _found$extensionId;
|
|
2600
|
+
|
|
2601
|
+
const isCore = this.aspectLoader.isCoreAspect(envId.toStringWithoutVersion());
|
|
2602
|
+
const existsOnWorkspace = await this.hasId(envId);
|
|
2603
|
+
|
|
2604
|
+
if (isCore || existsOnWorkspace) {
|
|
2605
|
+
// the env needs to be without version
|
|
2606
|
+
return envId.toStringWithoutVersion();
|
|
2607
|
+
} // the env must include a version
|
|
2608
|
+
|
|
2609
|
+
|
|
2610
|
+
if (envId.hasVersion()) {
|
|
2611
|
+
return envId.toString();
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
const extensions = this.harmony.get('teambit.harmony/config').extensions;
|
|
2615
|
+
const found = extensions === null || extensions === void 0 ? void 0 : extensions.findExtension(envId.toString(), true);
|
|
2616
|
+
|
|
2617
|
+
if (found && (_found$extensionId = found.extensionId) !== null && _found$extensionId !== void 0 && _found$extensionId.version) {
|
|
2618
|
+
return found.extensionId.toString();
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
const comps = await this.importAndGetMany([envId]);
|
|
2622
|
+
return comps[0].id.toString();
|
|
2623
|
+
}
|
|
2575
2624
|
/**
|
|
2576
2625
|
* remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
|
|
2577
2626
|
*/
|
|
@@ -2589,7 +2638,8 @@ your workspace.jsonc has this component-id set. you might want to remove/change
|
|
|
2589
2638
|
return;
|
|
2590
2639
|
}
|
|
2591
2640
|
|
|
2592
|
-
await this.
|
|
2641
|
+
const currentEnvWithPotentialVersion = await this.getAspectIdFromConfig(id, currentEnv, true);
|
|
2642
|
+
await this.removeSpecificComponentConfig(id, currentEnvWithPotentialVersion || currentEnv, false);
|
|
2593
2643
|
await this.removeSpecificComponentConfig(id, _envs().EnvsAspect.id, false);
|
|
2594
2644
|
changed.push(id);
|
|
2595
2645
|
}));
|