@teambit/workspace 0.0.556 → 0.0.557

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.
@@ -188,7 +188,10 @@ class GraphFromFsBuilder {
188
188
  const allDeps = components.map(c => this.getAllDepsUnfiltered(c)).flat();
189
189
  const allDepsWithScope = allDeps.filter(dep => dep.hasScope());
190
190
  const scopeComponentsImporter = new (_scopeComponentsImporter().default)(this.consumer.scope);
191
- await scopeComponentsImporter.importMany(_bitIds().default.uniqFromArray(allDepsWithScope), undefined, this.shouldThrowOnMissingDep);
191
+ await scopeComponentsImporter.importMany({
192
+ ids: _bitIds().default.uniqFromArray(allDepsWithScope),
193
+ throwForDependencyNotFound: this.shouldThrowOnMissingDep
194
+ });
192
195
  }
193
196
 
194
197
  async processOneComponent(component) {
@@ -1 +1 @@
1
- {"version":3,"sources":["build-graph-from-fs.ts"],"names":["GraphFromFsBuilder","constructor","workspace","logger","ignoreIds","BitIds","shouldLoadItsDeps","LegacyGraph","consumer","buildGraph","ids","debug","length","start","Date","now","components","loadManyComponents","processManyComponents","graph","getAllDepsUnfiltered","component","getAllDependenciesIds","difference","getAllDepsFiltered","depsWithoutIgnore","shouldLoadFunc","deps","depId","shouldLoad","push","fromArray","depth","importObjects","allDependencies","processOneComponent","allDependenciesFlattened","allDeps","map","c","flat","allDepsWithScope","filter","dep","hasScope","scopeComponentsImporter","ScopeComponentsImporter","scope","importMany","uniqFromArray","undefined","shouldThrowOnMissingDep","idStr","id","toString","completed","includes","allIds","Object","entries","depsIdsGroupedByType","forEach","depType","depsIds","has","hasNode","Error","setEdge","componentsIds","dependenciesOf","comp","fromGraph","node","loadComponent","setNode","err","ComponentNotFound","BitError","error","componentId","componentMap","bitMap","getComponentIfExist","isOnWorkspace","Boolean","loadComponentForCapsule","componentFromModel","loadComponentFromModel","clone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAA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IG,aAAJ,EAAmB;AACjB,aAAO,KAAK3E,QAAL,CAAc6E,uBAAd,CAAsCN,WAAtC,CAAP;AACD,KALiE,CAMlE;AACA;;;AACA,UAAMO,kBAAkB,GAAG,MAAM,KAAK9E,QAAL,CAAc+E,sBAAd,CAAqCR,WAArC,CAAjC;AACA,WAAOO,kBAAkB,CAACE,KAAnB,EAAP;AACD;;AA9I6B","sourcesContent":["import mapSeries from 'p-map-series';\nimport { flatten } from 'lodash';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport BitIds from '@teambit/legacy/dist/bit-id/bit-ids';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';\nimport ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';\nimport compact from 'lodash.compact';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport { ComponentNotFound } from '@teambit/scope';\nimport { BitError } from '@teambit/bit-error';\nimport { Workspace } from './workspace';\n\nexport type ShouldIgnoreFunc = (bitId: BitId) => Promise<boolean>;\n\nexport class GraphFromFsBuilder {\n private graph = new LegacyGraph();\n private completed: string[] = [];\n private depth = 1;\n private shouldThrowOnMissingDep = true;\n private consumer: Consumer;\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private ignoreIds = new BitIds(),\n private shouldLoadItsDeps?: ShouldIgnoreFunc\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n /**\n * create a graph with all dependencies and flattened dependencies of the given components.\n * the nodes are components and the edges has a label of the dependency type.\n *\n * the way how it is done is iterations by depths. each depth we gather all the dependencies of\n * that depths, make sure all objects exist and then check their dependencies for the next depth.\n * once there is no dependency left, we're on the last depth level and the graph is ready.\n *\n * for example, imagine the following graph:\n * A1 -> A2 -> A3\n * B1 -> B2 -> B3\n * C1 -> C2 -> C3\n *\n * where the buildGraph is given [A1, B1, C1].\n * first, it saves all these components as nodes in the graph. then, it finds the dependencies of\n * the next level, in this case they're [A2, B2, C2]. it runs `importMany` in case some objects\n * are missing. then, it loads them all (some from FS, some from the model) and sets the edges\n * between the component and the dependencies.\n * once done, it finds all their dependencies, which are [A3, B3, C3] and repeat the process\n * above. since there are no more dependencies, the graph is completed.\n * in this case, the total depth levels are 3.\n *\n * even with a huge project, there are not many depth levels. by iterating through depth levels\n * we keep performance sane as the importMany doesn't run multiple time and therefore the round\n * trips to the remotes are minimal.\n *\n * normally, one importMany of the seeders is enough as importMany knows to fetch all flattened.\n * however, since this buildGraph is performed on the workspace, a dependency may be new or\n * modified and as such, we don't know its flattened yet.\n */\n async buildGraph(ids: BitId[]): Promise<LegacyGraph> {\n this.logger.debug(`GraphFromFsBuilder, buildGraph with ${ids.length} seeders`);\n const start = Date.now();\n const components = await this.loadManyComponents(ids, '<none>');\n await this.processManyComponents(components);\n this.logger.debug(\n `GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`\n );\n return this.graph;\n }\n\n private getAllDepsUnfiltered(component: Component) {\n return component.getAllDependenciesIds().difference(this.ignoreIds);\n }\n\n private async getAllDepsFiltered(component: Component): Promise<BitIds> {\n const depsWithoutIgnore = this.getAllDepsUnfiltered(component);\n const shouldLoadFunc = this.shouldLoadItsDeps;\n if (!shouldLoadFunc) return depsWithoutIgnore;\n const deps = await mapSeries(depsWithoutIgnore, async (depId) => {\n const shouldLoad = await shouldLoadFunc(depId);\n if (!shouldLoad) this.ignoreIds.push(depId);\n return shouldLoad ? depId : null;\n });\n return BitIds.fromArray(compact(deps));\n }\n\n private async processManyComponents(components: Component[]) {\n this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);\n this.depth += 1;\n await this.importObjects(components);\n const allDependencies = await mapSeries(components, (component) => this.processOneComponent(component));\n const allDependenciesFlattened = flatten(allDependencies);\n if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);\n }\n\n private async importObjects(components: Component[]) {\n const allDeps = components.map((c) => this.getAllDepsUnfiltered(c)).flat();\n const allDepsWithScope = allDeps.filter((dep) => dep.hasScope());\n const scopeComponentsImporter = new ScopeComponentsImporter(this.consumer.scope);\n await scopeComponentsImporter.importMany(\n BitIds.uniqFromArray(allDepsWithScope),\n undefined,\n this.shouldThrowOnMissingDep\n );\n }\n\n private async processOneComponent(component: Component) {\n const idStr = component.id.toString();\n if (this.completed.includes(idStr)) return [];\n const allIds = await this.getAllDepsFiltered(component);\n\n const allDependencies = await this.loadManyComponents(allIds, idStr);\n Object.entries(component.depsIdsGroupedByType).forEach(([depType, depsIds]) => {\n depsIds.forEach((depId) => {\n if (this.ignoreIds.has(depId)) return;\n if (!this.graph.hasNode(depId.toString())) {\n throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);\n }\n this.graph.setEdge(idStr, depId.toString(), depType);\n });\n });\n this.completed.push(idStr);\n return allDependencies;\n }\n\n private async loadManyComponents(componentsIds: BitId[], dependenciesOf: string): Promise<Component[]> {\n const components = await mapSeries(componentsIds, async (comp: BitId) => {\n const idStr = comp.toString();\n const fromGraph = this.graph.node(idStr);\n if (fromGraph) return fromGraph;\n try {\n const component = await this.loadComponent(comp);\n this.graph.setNode(idStr, component);\n return component;\n } catch (err: any) {\n if (err instanceof ComponentNotFound) {\n throw new BitError(\n `error: component \"${idStr}\" was not found.\\nthis component is a dependency of \"${dependenciesOf}\" and is needed as part of the graph generation`\n );\n }\n this.logger.error(`failed loading dependencies of ${dependenciesOf}`);\n throw err;\n }\n });\n return components;\n }\n private async loadComponent(componentId: BitId): Promise<Component> {\n const componentMap = this.consumer.bitMap.getComponentIfExist(componentId);\n const isOnWorkspace = Boolean(componentMap);\n if (isOnWorkspace) {\n return this.consumer.loadComponentForCapsule(componentId);\n }\n // a dependency might have been installed as a package in the workspace, and as such doesn't\n // have a componentMap.\n const componentFromModel = await this.consumer.loadComponentFromModel(componentId);\n return componentFromModel.clone();\n }\n}\n"]}
1
+ {"version":3,"sources":["build-graph-from-fs.ts"],"names":["GraphFromFsBuilder","constructor","workspace","logger","ignoreIds","BitIds","shouldLoadItsDeps","LegacyGraph","consumer","buildGraph","ids","debug","length","start","Date","now","components","loadManyComponents","processManyComponents","graph","getAllDepsUnfiltered","component","getAllDependenciesIds","difference","getAllDepsFiltered","depsWithoutIgnore","shouldLoadFunc","deps","depId","shouldLoad","push","fromArray","depth","importObjects","allDependencies","processOneComponent","allDependenciesFlattened","allDeps","map","c","flat","allDepsWithScope","filter","dep","hasScope","scopeComponentsImporter","ScopeComponentsImporter","scope","importMany","uniqFromArray","throwForDependencyNotFound","shouldThrowOnMissingDep","idStr","id","toString","completed","includes","allIds","Object","entries","depsIdsGroupedByType","forEach","depType","depsIds","has","hasNode","Error","setEdge","componentsIds","dependenciesOf","comp","fromGraph","node","loadComponent","setNode","err","ComponentNotFound","BitError","error","componentId","componentMap","bitMap","getComponentIfExist","isOnWorkspace","Boolean","loadComponentForCapsule","componentFromModel","loadComponentFromModel","clone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAKO,MAAMA,kBAAN,CAAyB;AAM9BC,EAAAA,WAAW,CACDC,SADC,EAEDC,MAFC,EAGDC,SAAS,GAAG,KAAIC,iBAAJ,GAHX,EAIDC,iBAJC,EAKT;AAAA,SAJQJ,SAIR,GAJQA,SAIR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SAFQC,SAER,GAFQA,SAER;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AgBpB,KAAhB,CAAlB;AACA,UAAImB,SAAJ,EAAe,OAAOA,SAAP;;AACf,UAAI;AACF,cAAMlD,SAAS,GAAG,MAAM,KAAKoD,aAAL,CAAmBH,IAAnB,CAAxB;AACA,aAAKnD,KAAL,CAAWuD,OAAX,CAAmBtB,KAAnB,EAA0B/B,SAA1B;AACA,eAAOA,SAAP;AACD,OAJD,CAIE,OAAOsD,GAAP,EAAiB;AACjB,YAAIA,GAAG,YAAYC,0BAAnB,EAAsC;AACpC,gBAAM,KAAIC,oBAAJ,EACH,qBAAoBzB,KAAM,wDAAuDiB,cAAe,iDAD7F,CAAN;AAGD;;AACD,aAAKlE,MAAL,CAAY2E,KAAZ,CAAmB,kCAAiCT,cAAe,EAAnE;AACA,cAAMM,GAAN;AACD;AACF,KAjBwB,CAAzB;AAkBA,WAAO3D,UAAP;AACD;;AAC0B,QAAbyD,aAAa,CAACM,WAAD,EAAyC;AAClE,UAAMC,YAAY,GAAG,KAAKxE,QAAL,CAAcyE,MAAd,CAAqBC,mBAArB,CAAyCH,WAAzC,CAArB;AACA,UAAMI,aAAa,GAAGC,OAAO,CAACJ,YAAD,CAA7B;;AACA,QAAIG,aAAJ,EAAmB;AACjB,aAAO,KAAK3E,QAAL,CAAc6E,uBAAd,CAAsCN,WAAtC,CAAP;AACD,KALiE,CAMlE;AACA;;;AACA,UAAMO,kBAAkB,GAAG,MAAM,KAAK9E,QAAL,CAAc+E,sBAAd,CAAqCR,WAArC,CAAjC;AACA,WAAOO,kBAAkB,CAACE,KAAnB,EAAP;AACD;;AA7I6B","sourcesContent":["import mapSeries from 'p-map-series';\nimport { flatten } from 'lodash';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport BitIds from '@teambit/legacy/dist/bit-id/bit-ids';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';\nimport ScopeComponentsImporter from '@teambit/legacy/dist/scope/component-ops/scope-components-importer';\nimport compact from 'lodash.compact';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport { Logger } from '@teambit/logger';\nimport { ComponentNotFound } from '@teambit/scope';\nimport { BitError } from '@teambit/bit-error';\nimport { Workspace } from './workspace';\n\nexport type ShouldIgnoreFunc = (bitId: BitId) => Promise<boolean>;\n\nexport class GraphFromFsBuilder {\n private graph = new LegacyGraph();\n private completed: string[] = [];\n private depth = 1;\n private shouldThrowOnMissingDep = true;\n private consumer: Consumer;\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private ignoreIds = new BitIds(),\n private shouldLoadItsDeps?: ShouldIgnoreFunc\n ) {\n this.consumer = this.workspace.consumer;\n }\n\n /**\n * create a graph with all dependencies and flattened dependencies of the given components.\n * the nodes are components and the edges has a label of the dependency type.\n *\n * the way how it is done is iterations by depths. each depth we gather all the dependencies of\n * that depths, make sure all objects exist and then check their dependencies for the next depth.\n * once there is no dependency left, we're on the last depth level and the graph is ready.\n *\n * for example, imagine the following graph:\n * A1 -> A2 -> A3\n * B1 -> B2 -> B3\n * C1 -> C2 -> C3\n *\n * where the buildGraph is given [A1, B1, C1].\n * first, it saves all these components as nodes in the graph. then, it finds the dependencies of\n * the next level, in this case they're [A2, B2, C2]. it runs `importMany` in case some objects\n * are missing. then, it loads them all (some from FS, some from the model) and sets the edges\n * between the component and the dependencies.\n * once done, it finds all their dependencies, which are [A3, B3, C3] and repeat the process\n * above. since there are no more dependencies, the graph is completed.\n * in this case, the total depth levels are 3.\n *\n * even with a huge project, there are not many depth levels. by iterating through depth levels\n * we keep performance sane as the importMany doesn't run multiple time and therefore the round\n * trips to the remotes are minimal.\n *\n * normally, one importMany of the seeders is enough as importMany knows to fetch all flattened.\n * however, since this buildGraph is performed on the workspace, a dependency may be new or\n * modified and as such, we don't know its flattened yet.\n */\n async buildGraph(ids: BitId[]): Promise<LegacyGraph> {\n this.logger.debug(`GraphFromFsBuilder, buildGraph with ${ids.length} seeders`);\n const start = Date.now();\n const components = await this.loadManyComponents(ids, '<none>');\n await this.processManyComponents(components);\n this.logger.debug(\n `GraphFromFsBuilder, buildGraph with ${ids.length} seeders completed (${(Date.now() - start) / 1000} sec)`\n );\n return this.graph;\n }\n\n private getAllDepsUnfiltered(component: Component) {\n return component.getAllDependenciesIds().difference(this.ignoreIds);\n }\n\n private async getAllDepsFiltered(component: Component): Promise<BitIds> {\n const depsWithoutIgnore = this.getAllDepsUnfiltered(component);\n const shouldLoadFunc = this.shouldLoadItsDeps;\n if (!shouldLoadFunc) return depsWithoutIgnore;\n const deps = await mapSeries(depsWithoutIgnore, async (depId) => {\n const shouldLoad = await shouldLoadFunc(depId);\n if (!shouldLoad) this.ignoreIds.push(depId);\n return shouldLoad ? depId : null;\n });\n return BitIds.fromArray(compact(deps));\n }\n\n private async processManyComponents(components: Component[]) {\n this.logger.debug(`GraphFromFsBuilder.processManyComponents depth ${this.depth}, ${components.length} components`);\n this.depth += 1;\n await this.importObjects(components);\n const allDependencies = await mapSeries(components, (component) => this.processOneComponent(component));\n const allDependenciesFlattened = flatten(allDependencies);\n if (allDependenciesFlattened.length) await this.processManyComponents(allDependenciesFlattened);\n }\n\n private async importObjects(components: Component[]) {\n const allDeps = components.map((c) => this.getAllDepsUnfiltered(c)).flat();\n const allDepsWithScope = allDeps.filter((dep) => dep.hasScope());\n const scopeComponentsImporter = new ScopeComponentsImporter(this.consumer.scope);\n await scopeComponentsImporter.importMany({\n ids: BitIds.uniqFromArray(allDepsWithScope),\n throwForDependencyNotFound: this.shouldThrowOnMissingDep,\n });\n }\n\n private async processOneComponent(component: Component) {\n const idStr = component.id.toString();\n if (this.completed.includes(idStr)) return [];\n const allIds = await this.getAllDepsFiltered(component);\n\n const allDependencies = await this.loadManyComponents(allIds, idStr);\n Object.entries(component.depsIdsGroupedByType).forEach(([depType, depsIds]) => {\n depsIds.forEach((depId) => {\n if (this.ignoreIds.has(depId)) return;\n if (!this.graph.hasNode(depId.toString())) {\n throw new Error(`buildOneComponent: missing node of ${depId.toString()}`);\n }\n this.graph.setEdge(idStr, depId.toString(), depType);\n });\n });\n this.completed.push(idStr);\n return allDependencies;\n }\n\n private async loadManyComponents(componentsIds: BitId[], dependenciesOf: string): Promise<Component[]> {\n const components = await mapSeries(componentsIds, async (comp: BitId) => {\n const idStr = comp.toString();\n const fromGraph = this.graph.node(idStr);\n if (fromGraph) return fromGraph;\n try {\n const component = await this.loadComponent(comp);\n this.graph.setNode(idStr, component);\n return component;\n } catch (err: any) {\n if (err instanceof ComponentNotFound) {\n throw new BitError(\n `error: component \"${idStr}\" was not found.\\nthis component is a dependency of \"${dependenciesOf}\" and is needed as part of the graph generation`\n );\n }\n this.logger.error(`failed loading dependencies of ${dependenciesOf}`);\n throw err;\n }\n });\n return components;\n }\n private async loadComponent(componentId: BitId): Promise<Component> {\n const componentMap = this.consumer.bitMap.getComponentIfExist(componentId);\n const isOnWorkspace = Boolean(componentMap);\n if (isOnWorkspace) {\n return this.consumer.loadComponentForCapsule(componentId);\n }\n // a dependency might have been installed as a package in the workspace, and as such doesn't\n // have a componentMap.\n const componentFromModel = await this.consumer.loadComponentFromModel(componentId);\n return componentFromModel.clone();\n }\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/workspace",
3
- "version": "0.0.556",
3
+ "version": "0.0.557",
4
4
  "homepage": "https://bit.dev/teambit/workspace/workspace",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.workspace",
8
8
  "name": "workspace",
9
- "version": "0.0.556"
9
+ "version": "0.0.557"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash.compact": "3.0.1",
@@ -34,55 +34,55 @@
34
34
  "@teambit/base-ui.surfaces.split-pane.hover-splitter": "1.0.0",
35
35
  "@teambit/base-ui.surfaces.split-pane.split-pane": "1.0.0",
36
36
  "@teambit/base-ui.graph.tree.recursive-tree": "1.0.0",
37
- "@teambit/bit-error": "0.0.373",
38
- "@teambit/legacy-bit-id": "0.0.376",
39
- "@teambit/logger": "0.0.472",
40
- "@teambit/scope": "0.0.556",
41
- "@teambit/cli": "0.0.387",
42
- "@teambit/isolator": "0.0.556",
43
- "@teambit/component-tree": "0.0.373",
44
- "@teambit/component.ui.component-status-resolver": "0.0.468",
45
- "@teambit/harmony.modules.resolved-component": "0.0.462",
46
- "@teambit/dependency-resolver": "0.0.556",
47
- "@teambit/compiler": "0.0.556",
48
- "@teambit/component": "0.0.556",
49
- "@teambit/graphql": "0.0.556",
50
- "@teambit/aspect-loader": "0.0.556",
51
- "@teambit/bundler": "0.0.556",
52
- "@teambit/envs": "0.0.556",
53
- "@teambit/pubsub": "0.0.556",
54
- "@teambit/ui": "0.0.556",
55
- "@teambit/variants": "0.0.474",
56
- "@teambit/component-issues": "0.0.22",
57
- "@teambit/config": "0.0.398",
58
- "@teambit/harmony.modules.requireable-component": "0.0.462",
59
- "@teambit/importer": "0.0.14",
60
- "@teambit/workspace.modules.match-pattern": "0.0.466",
61
- "@teambit/command-bar": "0.0.556",
37
+ "@teambit/bit-error": "0.0.374",
38
+ "@teambit/legacy-bit-id": "0.0.377",
39
+ "@teambit/logger": "0.0.473",
40
+ "@teambit/scope": "0.0.557",
41
+ "@teambit/cli": "0.0.388",
42
+ "@teambit/isolator": "0.0.557",
43
+ "@teambit/component-tree": "0.0.374",
44
+ "@teambit/component.ui.component-status-resolver": "0.0.469",
45
+ "@teambit/harmony.modules.resolved-component": "0.0.463",
46
+ "@teambit/dependency-resolver": "0.0.557",
47
+ "@teambit/compiler": "0.0.557",
48
+ "@teambit/component": "0.0.557",
49
+ "@teambit/graphql": "0.0.557",
50
+ "@teambit/aspect-loader": "0.0.557",
51
+ "@teambit/bundler": "0.0.557",
52
+ "@teambit/envs": "0.0.557",
53
+ "@teambit/pubsub": "0.0.557",
54
+ "@teambit/ui": "0.0.557",
55
+ "@teambit/variants": "0.0.475",
56
+ "@teambit/component-issues": "0.0.23",
57
+ "@teambit/config": "0.0.399",
58
+ "@teambit/harmony.modules.requireable-component": "0.0.463",
59
+ "@teambit/importer": "0.0.15",
60
+ "@teambit/workspace.modules.match-pattern": "0.0.467",
61
+ "@teambit/command-bar": "0.0.557",
62
62
  "@teambit/design.ui.surfaces.menu.link-item": "0.0.374",
63
- "@teambit/graph": "0.0.556",
64
- "@teambit/react-router": "0.0.556",
65
- "@teambit/sidebar": "0.0.556",
66
- "@teambit/ui-foundation.ui.main-dropdown": "0.0.464",
67
- "@teambit/ui-foundation.ui.menu": "0.0.464",
68
- "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.466",
69
- "@teambit/toolbox.time.time-format": "0.0.461",
70
- "@teambit/component-id": "0.0.377",
71
- "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.465",
72
- "@teambit/deprecation": "0.0.556",
73
- "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.464",
74
- "@teambit/ui-foundation.ui.buttons.collapser": "0.0.169",
75
- "@teambit/ui-foundation.ui.corner": "0.0.471",
76
- "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.465",
77
- "@teambit/ui-foundation.ui.top-bar": "0.0.466",
63
+ "@teambit/graph": "0.0.557",
64
+ "@teambit/react-router": "0.0.557",
65
+ "@teambit/sidebar": "0.0.557",
66
+ "@teambit/ui-foundation.ui.main-dropdown": "0.0.465",
67
+ "@teambit/ui-foundation.ui.menu": "0.0.465",
68
+ "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.467",
69
+ "@teambit/toolbox.time.time-format": "0.0.462",
70
+ "@teambit/component-id": "0.0.378",
71
+ "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.466",
72
+ "@teambit/deprecation": "0.0.557",
73
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.465",
74
+ "@teambit/ui-foundation.ui.buttons.collapser": "0.0.170",
75
+ "@teambit/ui-foundation.ui.corner": "0.0.472",
76
+ "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.466",
77
+ "@teambit/ui-foundation.ui.top-bar": "0.0.467",
78
78
  "@teambit/design.ui.styles.ellipsis": "0.0.346",
79
79
  "@teambit/design.ui.styles.muted-italic": "0.0.35",
80
- "@teambit/ui-foundation.ui.full-loader": "0.0.464",
81
- "@teambit/ui-foundation.ui.side-bar": "0.0.470",
82
- "@teambit/ui-foundation.ui.tree.drawer": "0.0.464",
83
- "@teambit/explorer.ui.gallery.component-grid": "0.0.464",
84
- "@teambit/workspace.ui.empty-workspace": "0.0.466",
85
- "@teambit/workspace.ui.workspace-component-card": "0.0.467"
80
+ "@teambit/ui-foundation.ui.full-loader": "0.0.465",
81
+ "@teambit/ui-foundation.ui.side-bar": "0.0.471",
82
+ "@teambit/ui-foundation.ui.tree.drawer": "0.0.465",
83
+ "@teambit/explorer.ui.gallery.component-grid": "0.0.465",
84
+ "@teambit/workspace.ui.empty-workspace": "0.0.467",
85
+ "@teambit/workspace.ui.workspace-component-card": "0.0.468"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/lodash.compact": "3.0.6",
@@ -102,7 +102,7 @@
102
102
  },
103
103
  "peerDependencies": {
104
104
  "@apollo/client": "^3.0.0",
105
- "@teambit/legacy": "1.0.173",
105
+ "@teambit/legacy": "1.0.174",
106
106
  "react-dom": "^16.8.0 || ^17.0.0",
107
107
  "react": "^16.8.0 || ^17.0.0"
108
108
  },
@@ -130,7 +130,7 @@
130
130
  "react": "-"
131
131
  },
132
132
  "peerDependencies": {
133
- "@teambit/legacy": "1.0.173",
133
+ "@teambit/legacy": "1.0.174",
134
134
  "react-dom": "^16.8.0 || ^17.0.0",
135
135
  "react": "^16.8.0 || ^17.0.0"
136
136
  }
@@ -140,7 +140,9 @@
140
140
  "dist",
141
141
  "!dist/tsconfig.tsbuildinfo",
142
142
  "README.md",
143
- "README.mdx"
143
+ "README.mdx",
144
+ "*.js",
145
+ "*.json"
144
146
  ],
145
147
  "private": false,
146
148
  "engines": {
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "es2019",
5
+ "DOM",
6
+ "ES6",
7
+ "DOM.Iterable",
8
+ "ScriptHost"
9
+ ],
10
+ "target": "es2015",
11
+ "module": "commonjs",
12
+ "jsx": "react",
13
+ "declaration": true,
14
+ "sourceMap": true,
15
+ "skipLibCheck": true,
16
+ "moduleResolution": "node",
17
+ "esModuleInterop": true,
18
+ "composite": true,
19
+ "emitDeclarationOnly": true,
20
+ "outDir": "dist",
21
+ "experimentalDecorators": true,
22
+ "emitDecoratorMetadata": true,
23
+ "allowSyntheticDefaultImports": true,
24
+ "strictPropertyInitialization": false,
25
+ "strict": true,
26
+ "noImplicitAny": false,
27
+ "rootDir": ".",
28
+ "preserveConstEnums": true,
29
+ "resolveJsonModule": true
30
+ },
31
+ "exclude": [
32
+ "dist"
33
+ ]
34
+ }