@teambit/workspace 0.0.837 → 0.0.845
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-map.js +13 -3
- package/dist/bit-map.js.map +1 -1
- package/dist/ui/workspace/use-workspace.js +3 -0
- package/dist/ui/workspace/use-workspace.js.map +1 -1
- package/dist/workspace.js +20 -6
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.ui.runtime.d.ts +2 -1
- package/dist/workspace.ui.runtime.js +27 -6
- package/dist/workspace.ui.runtime.js.map +1 -1
- package/package-tar/teambit-workspace-0.0.845.tgz +0 -0
- package/package.json +39 -39
- package/{preview-1662069881993.js → preview-1662521943539.js} +2 -2
- package/ui/workspace/use-workspace.ts +3 -0
- package/workspace.ui.runtime.tsx +16 -6
- package/package-tar/teambit-workspace-0.0.837.tgz +0 -0
package/dist/bit-map.js
CHANGED
|
@@ -202,9 +202,19 @@ class BitMap {
|
|
|
202
202
|
throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
if (sourceId.isEqual(targetId)) {
|
|
206
|
+
throw new Error(`source-id and target-id are equal: "${sourceId.toString()}"`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (sourceId.fullName !== targetId.fullName) {
|
|
210
|
+
this.legacyBitMap.removeComponent(bitMapEntry.id);
|
|
211
|
+
bitMapEntry.id = targetId._legacy;
|
|
212
|
+
this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (sourceId.scope !== targetId.scope) {
|
|
216
|
+
this.setDefaultScope(targetId, targetId.scope);
|
|
217
|
+
}
|
|
208
218
|
}
|
|
209
219
|
|
|
210
220
|
removeComponent(id) {
|
package/dist/bit-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","shouldMergeConfig","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","isEqual","getNewConfig","merge","newConfig","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","removeDefaultScope","defaultScope","setDefaultScope","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","getExportedLaneId","isLaneExported","laneId","hasChanged"],"sources":["bit-map.ts"],"sourcesContent":["import { isEqual, merge } 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';\nimport { LaneId } from '@teambit/lane-id';\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(\n id: ComponentID,\n aspectId: string,\n config: Record<string, any> = {},\n shouldMergeConfig = false\n ): 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 const getNewConfig = () => {\n if (!config) return null;\n if (!shouldMergeConfig) return config;\n // should merge\n if (!currentConfig) return config;\n if (currentConfig === '-') return config;\n // lodash merge performs a deep merge. (the native concatenation don't)\n return merge(currentConfig, config);\n };\n const newConfig = getNewConfig();\n if (newConfig) {\n bitMapEntry.config[aspectId] = newConfig;\n } else {\n delete bitMapEntry.config[aspectId];\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 removeDefaultScope(id: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (bitMapEntry.defaultScope) {\n delete bitMapEntry.defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n }\n\n setDefaultScope(id: ComponentID, defaultScope: string) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.defaultScope = defaultScope;\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 removeComponent(id: ComponentID) {\n this.legacyBitMap.removeComponent(id._legacy);\n }\n\n /**\n * this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be\n * empty.\n */\n getExportedLaneId(): LaneId | undefined {\n return this.legacyBitMap.isLaneExported ? this.legacyBitMap.laneId : undefined;\n }\n\n /**\n * whether .bitmap file has changed in-memory\n */\n hasChan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,CAA+BzC,WAAW,CAACL,EAA3C,EAA+CK,WAA/C;EACD;;EAEDwC,eAAe,CAAC7C,EAAD,EAAkB;IAC/B,KAAKH,YAAL,CAAkBgD,eAAlB,CAAkC7C,EAAE,CAAC0B,OAArC;EACD;EAED;AACF;AACA;AACA;;;EACEqB,iBAAiB,GAAuB;IACtC,OAAO,KAAKlD,YAAL,CAAkBmD,cAAlB,GAAmC,KAAKnD,YAAL,CAAkBoD,MAArD,GAA8DnB,SAArE;EACD;EAED;AACF;AACA;;;EACEoB,UAAU,GAAY;IACpB,OAAO,KAAKrD,YAAL,CAAkBqD,UAAzB;EACD;;AAhKiB"}
|
|
1
|
+
{"version":3,"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","shouldMergeConfig","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","isEqual","getNewConfig","merge","newConfig","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","removeDefaultScope","defaultScope","setDefaultScope","write","writeBitMap","ignoreVersion","getComponent","_legacy","getAspectIdFromConfig","componentId","ignoreAspectVersion","undefined","toString","allVersions","Object","keys","filter","startsWith","toStringWithoutVersion","length","BitError","join","renameNewComponent","sourceId","targetId","hasVersion","fullName","removeComponent","setComponent","scope","getExportedLaneId","isLaneExported","laneId","hasChanged"],"sources":["bit-map.ts"],"sourcesContent":["import { isEqual, merge } 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';\nimport { LaneId } from '@teambit/lane-id';\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(\n id: ComponentID,\n aspectId: string,\n config: Record<string, any> = {},\n shouldMergeConfig = false\n ): 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 const getNewConfig = () => {\n if (!config) return null;\n if (!shouldMergeConfig) return config;\n // should merge\n if (!currentConfig) return config;\n if (currentConfig === '-') return config;\n // lodash merge performs a deep merge. (the native concatenation don't)\n return merge(currentConfig, config);\n };\n const newConfig = getNewConfig();\n if (newConfig) {\n bitMapEntry.config[aspectId] = newConfig;\n } else {\n delete bitMapEntry.config[aspectId];\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 removeDefaultScope(id: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (bitMapEntry.defaultScope) {\n delete bitMapEntry.defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n }\n\n setDefaultScope(id: ComponentID, defaultScope: string) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.defaultScope = defaultScope;\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 if (sourceId.isEqual(targetId)) {\n throw new Error(`source-id and target-id are equal: \"${sourceId.toString()}\"`);\n }\n if (sourceId.fullName !== targetId.fullName) {\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n if (sourceId.scope !== targetId.scope) {\n this.setDefaultScope(targetId, targetId.scope);\n }\n }\n\n removeComponent(id: ComponentID) {\n this.legacyBitMap.removeComponent(id._legacy);\n }\n\n /**\n * this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be\n * empty.\n */\n getExportedLaneId(): LaneId | undefined {\n return this.legacyBitMap.isLaneExported ? this.legacyBitMap.laneId : undefined;\n }\n\n /**\n * whether .bitmap file has changed in-memory\n */\n hasChanged(): boolean {\n return this.legacyBitMap.hasChanged;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;EAClBC,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;IAAA,KAAxDD,YAAwD,GAAxDA,YAAwD;IAAA,KAApBC,QAAoB,GAApBA,QAAoB;EAAE;EAE9E;AACF;AACA;AACA;AACA;;;EACEC,kBAAkB,CAChBC,EADgB,EAEhBC,QAFgB,EAGhBC,MAA2B,GAAG,EAHd,EAIhBC,iBAAiB,GAAG,KAJJ,EAKP;IACT,IAAI,CAACF,QAAD,IAAa,OAAOA,QAAP,KAAoB,QAArC,EAA+C,MAAM,IAAIG,KAAJ,CAAW,qCAAoCH,QAAS,EAAxD,CAAN;IAC/C,MAAMI,WAAW,GA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D,MAArD,GAA8DrB,SAArE;EACD;EAED;AACF;AACA;;;EACEsB,UAAU,GAAY;IACpB,OAAO,KAAKvD,YAAL,CAAkBuD,UAAzB;EACD;;AAxKiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["wcComponentFields","gql","WORKSPACE","COMPONENT_SUBSCRIPTION_ADDED","COMPONENT_SUBSCRIPTION_CHANGED","COMPONENT_SUBSCRIPTION_REMOVED","useWorkspace","options","useDataQuery","data","subscribeToMore","rest","optionsRef","useLatest","useEffect","unSubCompAddition","document","updateQuery","prev","subscriptionData","update","addedComponent","componentAdded","component","componentExists","workspace","components","find","ComponentID","isEqualObj","id","ignoreVersion","setTimeout","current","onComponentAdded","ComponentModel","from","unSubCompChange","updatedComponent","componentChanged","onComponentUpdated","map","name","unSubCompRemoved","idsToRemove","componentRemoved","componentIds","length","onComponentRemoved","fromObject","filter","every","useMemo","Workspace","undefined"],"sources":["use-workspace.ts"],"sourcesContent":["import { useEffect, useMemo } from 'react';\nimport { ComponentModel } from '@teambit/component';\nimport useLatest from '@react-hook/latest';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { gql } from '@apollo/client';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\n\nimport { Workspace } from './workspace-model';\n\ntype UseWorkspaceOptions = {\n onComponentAdded?: (component: ComponentModel[]) => void;\n onComponentUpdated?: (component: ComponentModel[]) => void;\n onComponentRemoved?: (compId: ComponentID[]) => void;\n};\ntype RawComponent = { id: ComponentIdObj };\n\nconst wcComponentFields = gql`\n fragment wcComponentFields on Component {\n id {\n name\n version\n scope\n }\n compositions {\n identifier\n }\n description\n issuesCount\n status {\n isOutdated\n isNew\n isInScope\n isStaged\n modifyInfo {\n hasModifiedFiles\n hasModifiedDependencies\n }\n isDeleted\n }\n deprecation {\n isDeprecate\n newId\n }\n server {\n env\n url\n }\n env {\n id\n icon\n }\n }\n`;\n\nconst WORKSPACE = gql`\n query workspace {\n workspace {\n name\n path\n icon\n components {\n ...wcComponentFields\n }\n }\n }\n ${wcComponentFields}\n`;\n\nconst COMPONENT_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded {\n componentAdded {\n component {\n ...wcComponentFields\n }\n }\n }\n ${wcComponentFields}\n`;\n\nconst COMPONENT_SUBSCRIPTION_CHANGED = gql`\n subscription OnComponentChanged {\n componentChanged {\n component {\n ...wcComponentFields\n }\n }\n }\n ${wcComponentFields}\n`;\n\nconst COMPONENT_SUBSCRIPTION_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n name\n version\n scope\n }\n }\n }\n`;\n\nexport function useWorkspace(options: UseWorkspaceOptions = {}) {\n const { data, subscribeToMore, ...rest } = useDataQuery(WORKSPACE);\n const optionsRef = useLatest(options);\n\n useEffect(() => {\n const unSubCompAddition = subscribeToMore({\n document: COMPONENT_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const update = subscriptionData.data;\n const addedComponent = update?.componentAdded?.component;\n if (!addedComponent) return prev;\n\n const componentExists = prev.workspace.components.find((component: any) =>\n ComponentID.isEqualObj(component.id, addedComponent.id, { ignoreVersion: true })\n );\n if (componentExists) return prev;\n\n // side effect - trigger observers\n setTimeout(() => optionsRef.current.onComponentAdded?.([ComponentModel.from(addedComponent)]));\n\n return {\n ...prev,\n workspace: {\n ...prev.workspace,\n components: [...prev.workspace.components, addedComponent],\n },\n };\n },\n });\n\n const unSubCompChange = subscribeToMore({\n document: COMPONENT_SUBSCRIPTION_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n const update = subscriptionData.data;\n if (!update) return prev;\n\n const updatedComponent = update.componentChanged.component;\n // side effect - trigger observers\n setTimeout(() => optionsRef.current.onComponentUpdated?.([ComponentModel.from(updatedComponent)]));\n\n return {\n ...prev,\n workspace: {\n ...prev.workspace,\n components: prev.workspace.components.map((component) =>\n component.id.name === updatedComponent.id.name ? updatedComponent : component\n ),\n },\n };\n },\n });\n\n const unSubCompRemoved = subscribeToMore({\n document: COMPONENT_SUBSCRIPTION_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n const idsToRemove: ComponentIdObj[] | undefined = subscriptionData.data?.componentRemoved?.componentIds;\n if (!idsToRemove || idsToRemove.length === 0) return prev;\n\n // side effect - trigger observers\n setTimeout(() => optionsRef.current.onComponentRemoved?.(idsToRemove.map((id) => ComponentID.fromObject(id))));\n\n return {\n ...prev,\n workspace: {\n ...prev.workspace,\n components: prev.workspace.components.filter((component: RawComponent) =>\n idsToRemove.every((id) => !ComponentID.isEqualObj(id, component.id))\n ),\n },\n };\n },\n });\n\n // TODO - sub to component removal\n\n return () => {\n unSubCompAddition();\n unSubCompChange();\n unSubCompRemoved();\n };\n }, [optionsRef]);\n\n const workspace = useMemo(() => {\n return data?.workspace ? Workspace.from(data?.workspace) : undefined;\n }, [data?.workspace]);\n\n return {\n workspace,\n subscribeToMore,\n ...rest,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AASA,MAAMA,iBAAiB,GAAG,IAAAC,aAAA,CAAI;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,
|
|
1
|
+
{"version":3,"names":["wcComponentFields","gql","WORKSPACE","COMPONENT_SUBSCRIPTION_ADDED","COMPONENT_SUBSCRIPTION_CHANGED","COMPONENT_SUBSCRIPTION_REMOVED","useWorkspace","options","useDataQuery","data","subscribeToMore","rest","optionsRef","useLatest","useEffect","unSubCompAddition","document","updateQuery","prev","subscriptionData","update","addedComponent","componentAdded","component","componentExists","workspace","components","find","ComponentID","isEqualObj","id","ignoreVersion","setTimeout","current","onComponentAdded","ComponentModel","from","unSubCompChange","updatedComponent","componentChanged","onComponentUpdated","map","name","unSubCompRemoved","idsToRemove","componentRemoved","componentIds","length","onComponentRemoved","fromObject","filter","every","useMemo","Workspace","undefined"],"sources":["use-workspace.ts"],"sourcesContent":["import { useEffect, useMemo } from 'react';\nimport { ComponentModel } from '@teambit/component';\nimport useLatest from '@react-hook/latest';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { gql } from '@apollo/client';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\n\nimport { Workspace } from './workspace-model';\n\ntype UseWorkspaceOptions = {\n onComponentAdded?: (component: ComponentModel[]) => void;\n onComponentUpdated?: (component: ComponentModel[]) => void;\n onComponentRemoved?: (compId: ComponentID[]) => void;\n};\ntype RawComponent = { id: ComponentIdObj };\n\nconst wcComponentFields = gql`\n fragment wcComponentFields on Component {\n id {\n name\n version\n scope\n }\n compositions {\n identifier\n }\n description\n issuesCount\n status {\n isOutdated\n isNew\n isInScope\n isStaged\n modifyInfo {\n hasModifiedFiles\n hasModifiedDependencies\n }\n isDeleted\n }\n preview {\n isScaling\n }\n deprecation {\n isDeprecate\n newId\n }\n server {\n env\n url\n }\n env {\n id\n icon\n }\n }\n`;\n\nconst WORKSPACE = gql`\n query workspace {\n workspace {\n name\n path\n icon\n components {\n ...wcComponentFields\n }\n }\n }\n ${wcComponentFields}\n`;\n\nconst COMPONENT_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded {\n componentAdded {\n component {\n ...wcComponentFields\n }\n }\n }\n ${wcComponentFields}\n`;\n\nconst COMPONENT_SUBSCRIPTION_CHANGED = gql`\n subscription OnComponentChanged {\n componentChanged {\n component {\n ...wcComponentFields\n }\n }\n }\n ${wcComponentFields}\n`;\n\nconst COMPONENT_SUBSCRIPTION_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n name\n version\n scope\n }\n }\n }\n`;\n\nexport function useWorkspace(options: UseWorkspaceOptions = {}) {\n const { data, subscribeToMore, ...rest } = useDataQuery(WORKSPACE);\n const optionsRef = useLatest(options);\n\n useEffect(() => {\n const unSubCompAddition = subscribeToMore({\n document: COMPONENT_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const update = subscriptionData.data;\n const addedComponent = update?.componentAdded?.component;\n if (!addedComponent) return prev;\n\n const componentExists = prev.workspace.components.find((component: any) =>\n ComponentID.isEqualObj(component.id, addedComponent.id, { ignoreVersion: true })\n );\n if (componentExists) return prev;\n\n // side effect - trigger observers\n setTimeout(() => optionsRef.current.onComponentAdded?.([ComponentModel.from(addedComponent)]));\n\n return {\n ...prev,\n workspace: {\n ...prev.workspace,\n components: [...prev.workspace.components, addedComponent],\n },\n };\n },\n });\n\n const unSubCompChange = subscribeToMore({\n document: COMPONENT_SUBSCRIPTION_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n const update = subscriptionData.data;\n if (!update) return prev;\n\n const updatedComponent = update.componentChanged.component;\n // side effect - trigger observers\n setTimeout(() => optionsRef.current.onComponentUpdated?.([ComponentModel.from(updatedComponent)]));\n\n return {\n ...prev,\n workspace: {\n ...prev.workspace,\n components: prev.workspace.components.map((component) =>\n component.id.name === updatedComponent.id.name ? updatedComponent : component\n ),\n },\n };\n },\n });\n\n const unSubCompRemoved = subscribeToMore({\n document: COMPONENT_SUBSCRIPTION_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n const idsToRemove: ComponentIdObj[] | undefined = subscriptionData.data?.componentRemoved?.componentIds;\n if (!idsToRemove || idsToRemove.length === 0) return prev;\n\n // side effect - trigger observers\n setTimeout(() => optionsRef.current.onComponentRemoved?.(idsToRemove.map((id) => ComponentID.fromObject(id))));\n\n return {\n ...prev,\n workspace: {\n ...prev.workspace,\n components: prev.workspace.components.filter((component: RawComponent) =>\n idsToRemove.every((id) => !ComponentID.isEqualObj(id, component.id))\n ),\n },\n };\n },\n });\n\n // TODO - sub to component removal\n\n return () => {\n unSubCompAddition();\n unSubCompChange();\n unSubCompRemoved();\n };\n }, [optionsRef]);\n\n const workspace = useMemo(() => {\n return data?.workspace ? Workspace.from(data?.workspace) : undefined;\n }, [data?.workspace]);\n\n return {\n workspace,\n subscribeToMore,\n ...rest,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AASA,MAAMA,iBAAiB,GAAG,IAAAC,aAAA,CAAI;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAvCA;AAyCA,MAAMC,SAAS,GAAG,IAAAD,aAAA,CAAI;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,CAZA;AAcA,MAAMG,4BAA4B,GAAG,IAAAF,aAAA,CAAI;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAk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sImporter() {
|
|
|
359
359
|
return data;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
+
function _exceptions3() {
|
|
363
|
+
const data = require("@teambit/legacy/dist/consumer/bit-map/exceptions");
|
|
364
|
+
|
|
365
|
+
_exceptions3 = function () {
|
|
366
|
+
return data;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
return data;
|
|
370
|
+
}
|
|
371
|
+
|
|
362
372
|
function _loader() {
|
|
363
373
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
|
|
364
374
|
|
|
@@ -399,10 +409,10 @@ function _componentConfigFile() {
|
|
|
399
409
|
return data;
|
|
400
410
|
}
|
|
401
411
|
|
|
402
|
-
function
|
|
412
|
+
function _exceptions4() {
|
|
403
413
|
const data = require("./exceptions");
|
|
404
414
|
|
|
405
|
-
|
|
415
|
+
_exceptions4 = function () {
|
|
406
416
|
return data;
|
|
407
417
|
};
|
|
408
418
|
|
|
@@ -1100,7 +1110,7 @@ class Workspace {
|
|
|
1100
1110
|
// if it's not a pattern but just id, resolve it without multimatch to support specifying id without scope-name
|
|
1101
1111
|
const id = await this.resolveComponentId(pattern);
|
|
1102
1112
|
if (this.exists(id)) return [id];
|
|
1103
|
-
if (throwForNoMatch) throw new (
|
|
1113
|
+
if (throwForNoMatch) throw new (_exceptions3().MissingBitMapComponent)(pattern);
|
|
1104
1114
|
return [];
|
|
1105
1115
|
}
|
|
1106
1116
|
|
|
@@ -1939,9 +1949,13 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1939
1949
|
|
|
1940
1950
|
const scopeIdsGrouped = await this.scope.groupAspectIdsByEnvOfTheList(scopeIds);
|
|
1941
1951
|
const scopeEnvsManifestsIds = scopeIdsGrouped.envs && scopeIdsGrouped.envs.length ? await this.scope.loadAspects(scopeIdsGrouped.envs, throwOnError, 'workspace.loadAspects loading scope aspects') : [];
|
|
1942
|
-
const
|
|
1952
|
+
const {
|
|
1953
|
+
manifests: scopeOtherManifests
|
|
1954
|
+
} = scopeIdsGrouped.other && scopeIdsGrouped.other.length ? await this.scope.getManifestsGraphRecursively(scopeIdsGrouped.other, (0, _lodash().compact)(workspaceManifestsIds), throwOnError, {
|
|
1943
1955
|
packageManagerConfigRootDir: this.path
|
|
1944
|
-
}) :
|
|
1956
|
+
}) : {
|
|
1957
|
+
manifests: []
|
|
1958
|
+
};
|
|
1945
1959
|
const scopeOtherManifestsIds = (0, _lodash().compact)(scopeOtherManifests.map(m => m.id));
|
|
1946
1960
|
await this.aspectLoader.loadExtensionsByManifests([...scopeOtherManifests, ...workspaceManifests], throwOnError); // Try require components for potential plugins
|
|
1947
1961
|
|
|
@@ -2221,7 +2235,7 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
2221
2235
|
|
|
2222
2236
|
async _addPackages(packages, options) {
|
|
2223
2237
|
if (!(options !== null && options !== void 0 && options.variants) && (options === null || options === void 0 ? void 0 : options.lifecycleType) === 'dev') {
|
|
2224
|
-
throw new (
|
|
2238
|
+
throw new (_exceptions4().DependencyTypeNotSupportedInPolicy)(options === null || options === void 0 ? void 0 : options.lifecycleType);
|
|
2225
2239
|
}
|
|
2226
2240
|
|
|
2227
2241
|
this.logger.debug(`installing the following packages: ${packages.join()}`);
|