@teambit/snapping 1.0.486 → 1.0.488
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/artifacts/__bit_junit.xml +13 -9
- package/artifacts/schema.json +1491 -1431
- package/dist/flattened-edges.d.ts +2 -2
- package/dist/flattened-edges.js.map +1 -1
- package/dist/generate-comp-from-scope.js +16 -31
- package/dist/generate-comp-from-scope.js.map +1 -1
- package/dist/get-flattened-dependencies.d.ts +32 -0
- package/dist/get-flattened-dependencies.js +190 -0
- package/dist/get-flattened-dependencies.js.map +1 -0
- package/dist/message-per-component.d.ts +17 -0
- package/dist/message-per-component.js +204 -0
- package/dist/message-per-component.js.map +1 -0
- package/dist/message-per-component.spec.d.ts +1 -0
- package/dist/message-per-component.spec.js +63 -0
- package/dist/message-per-component.spec.js.map +1 -0
- package/dist/reset-cmd.js +5 -5
- package/dist/reset-cmd.js.map +1 -1
- package/dist/reset-component.d.ts +3 -3
- package/dist/reset-component.js +8 -9
- package/dist/reset-component.js.map +1 -1
- package/dist/snap-cmd.js +7 -7
- package/dist/snap-cmd.js.map +1 -1
- package/dist/snapping.main.runtime.d.ts +4 -8
- package/dist/snapping.main.runtime.js +50 -64
- package/dist/snapping.main.runtime.js.map +1 -1
- package/dist/snapping.spec.js +5 -5
- package/dist/snapping.spec.js.map +1 -1
- package/dist/tag-cmd.js +6 -6
- package/dist/tag-cmd.js.map +1 -1
- package/dist/tag-model-component.d.ts +3 -4
- package/dist/tag-model-component.js +26 -40
- package/dist/tag-model-component.js.map +1 -1
- package/package.json +48 -36
- /package/dist/{preview-1733541556857.js → preview-1733830651067.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Graph } from '@teambit/graph.cleargraph';
|
|
2
2
|
import { DepEdgeType } from '@teambit/graph';
|
|
3
3
|
import { ScopeMain } from '@teambit/scope';
|
|
4
|
-
import ConsumerComponent from '@teambit/legacy
|
|
5
|
-
import { Lane } from '@teambit/
|
|
4
|
+
import { ConsumerComponent } from '@teambit/legacy.consumer-component';
|
|
5
|
+
import { Lane } from '@teambit/scope.objects';
|
|
6
6
|
import { ComponentID } from '@teambit/component-id';
|
|
7
7
|
import { Logger } from '@teambit/logger';
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_graph","data","require","_componentId","_toolboxPromise","_bitError","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","FlattenedEdgesGetter","constructor","scope","consumerComponents","logger","lane","Graph","buildGraph","debug","buildTheFirstLevel","populateMissingFromGraph","missingFromGraph","length","graph","addPreviousGraphs","importMissingAndAddToGraph","addComponentsWithMissingFlattenedEdges","populateFlattenedAndEdgesForComp","component","graphFromIds","successorsSubgraph","id","toString","edgesFromGraph","edges","map","edge","source","ComponentID","fromString","sourceId","target","targetId","type","attr","flattenedFromGraphIncludeItself","nodes","node","flattenedFromGraph","filter","isEqual","forEach","dep","throwWhenDepNotIncluded","flattenedDependencies","ComponentIdList","fromArray","flattenedEdges","idsWithoutGraphList","legacyScope","scopeImporter","importWithoutDeps","cache","componentsAndVersions","getComponentsAndVersions","missingEdges","Promise","all","version","versionStr","getFlattenedEdges","objects","push","toComponentId","changeVersion","addFlattenedEdgesToGraph","flattenedDeps","pMapPool","comp","previousVersion","previouslyUsedVersion","modelComponent","getModelComponent","undefined","loadVersion","concurrency","flattenedDepsUniq","uniqFromArray","flat","has","warn","join","missingEdgesList","results","importMany","ids","preferDependencyGraph","allFlattened","result","allFlattenedUniq","compId","setNode","Node","addEdges","dependencies","devDependencies","extensionDependencies","setEdge","Edge","allIds","currentlySnappedIds","filteredIds","label","get","exports","componentId","dependencyId","hasScope","hasVersion","BitError"],"sources":["flattened-edges.ts"],"sourcesContent":["import { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport { DepEdgeType } from '@teambit/graph';\nimport { ScopeMain } from '@teambit/scope';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { Lane } from '@teambit/legacy/dist/scope/models';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport { DepEdge } from '@teambit/legacy/dist/scope/models/version';\nimport { Logger } from '@teambit/logger';\nimport { pMapPool } from '@teambit/toolbox.promise.map-pool';\nimport { BitError } from '@teambit/bit-error';\n\n/**\n * the goal of this class is to determine the graph dependencies of a given set of components with minimal effort.\n * it takes advantage of the fact that we save the dependency graph in the `Version` object and tries to reuse it.\n *\n * to optimize it as much as possible, we do it in 4 steps. each step we check whether the graph has missing ids,\n * and if so, continue to the next step.\n *\n * * * First step * * *\n * we have two groups in this graph.\n * 1. components that are now versioned (this.consumerComponents). they have the new version (which is not in the scope yet).\n * 2. component that are not part of the current snap/tag.\n * it's not possible that this group has new components that never been into the scope, otherwise the tag/snap is failing.\n * so we know we can always find the version-object of these components in the scope or import them.\n *\n * given the above. we can simply get the first level of dependencies of the first group.\n * start the graph by adding them all as nodes and edges.\n *\n * this dependencies array may contain components from the first group. we can filter them out. (we don't care about\n * them, they're part of the graph already)\n * we're left with the dependencies that are part of the second group. there are the `missingFromGraph`.\n *\n * * * Second step * * *\n * instead of import these components, we can more efficiently get their previous version from the scope.\n * it must be already in the scope because these are the components we load in the first place.\n * chances are that 99% of the dependencies of the current components objects are identical to the previous version.\n * by adding the flattenedEdges of the previous versions we can probably finish the graph without importing a single\n * component. It's ok that this graph of previous versions has ids that are not relevant to this graph. for example, if\n * we now tag bar@0.0.2, this graph will have bar@0.0.1 although it's not relevant. it's ok, because finally we don't\n * use this graph as a whole. we only pick a component and get its sub-graph, so all irrelevant ids are ignored.\n *\n * * * Third step * * *\n * in case the graph above wasn't enough. we can import the missing components and get their flattenedEdges.\n * all components that were snapped/tagged since around 0.0.8000 have the flattenedEdges saved in the version.\n * older components don't have them and that's why the last step is needed.\n *\n * * * Fourth step * * *\n * this is the worst scenario. we have some old dependencies without flattenedEdges, we have to import them with\n * all their flattened dependencies.\n * once we have all these objects we can iterate them and add them to the graph.\n */\nexport class FlattenedEdgesGetter {\n private graph = new Graph<ComponentID, DepEdgeType>();\n private missingFromGraph: ComponentID[] = [];\n constructor(\n private scope: ScopeMain,\n private consumerComponents: ConsumerComponent[],\n private logger: Logger,\n private lane?: Lane\n ) {}\n\n async buildGraph() {\n this.logger.debug('FlattenedEdgesGetter, start');\n this.buildTheFirstLevel();\n this.populateMissingFromGraph();\n if (!this.missingFromGraph.length) {\n return this.graph;\n }\n this.logger.debug(\n `FlattenedEdgesGetter, total ${this.missingFromGraph.length} components missing from graph, trying to find them in previous versions`\n );\n await this.addPreviousGraphs();\n if (!this.missingFromGraph.length) {\n this.logger.debug(`FlattenedEdgesGetter, all missing ids were found in previous versions`);\n return this.graph;\n }\n this.logger.debug(\n `FlattenedEdgesGetter, total ${this.missingFromGraph.length} components missing from graph, trying to import them and load their flattenedEdges`\n );\n await this.importMissingAndAddToGraph();\n if (!this.missingFromGraph.length) {\n this.logger.debug(`FlattenedEdgesGetter, successfully found flattened edges for all components without graph`);\n return this.graph;\n }\n this.logger.debug(\n `FlattenedEdgesGetter, total ${this.missingFromGraph.length} components without graph and their version-objects has no flattened edges, no choice but to import all their flattened deps`\n );\n await this.addComponentsWithMissingFlattenedEdges();\n return this.graph;\n }\n\n populateFlattenedAndEdgesForComp(component: ConsumerComponent) {\n const graphFromIds = this.graph.successorsSubgraph(component.id.toString());\n const edgesFromGraph = graphFromIds.edges.map((edge) => {\n return {\n source: ComponentID.fromString(edge.sourceId),\n target: ComponentID.fromString(edge.targetId),\n type: edge.attr as DepEdgeType,\n };\n });\n\n const flattenedFromGraphIncludeItself = graphFromIds.nodes.map((node) => node.attr);\n const flattenedFromGraph = flattenedFromGraphIncludeItself.filter((id) => !id.isEqual(component.id));\n flattenedFromGraph.forEach((dep) => throwWhenDepNotIncluded(component.id, dep));\n\n component.flattenedDependencies = ComponentIdList.fromArray(flattenedFromGraph);\n component.flattenedEdges = edgesFromGraph;\n }\n\n private async importMissingAndAddToGraph() {\n const idsWithoutGraphList = ComponentIdList.fromArray(this.missingFromGraph);\n await this.scope.legacyScope.scopeImporter.importWithoutDeps(idsWithoutGraphList, {\n cache: true,\n lane: this.lane,\n });\n const componentsAndVersions = await this.scope.legacyScope.getComponentsAndVersions(idsWithoutGraphList);\n const missingEdges: ComponentID[] = [];\n await Promise.all(\n componentsAndVersions.map(async ({ component, version, versionStr }) => {\n const flattenedEdges = await version.getFlattenedEdges(this.scope.legacyScope.objects);\n if (!flattenedEdges.length && version.flattenedDependencies.length) {\n missingEdges.push(component.toComponentId().changeVersion(versionStr));\n }\n this.addFlattenedEdgesToGraph(flattenedEdges);\n })\n );\n this.missingFromGraph = missingEdges;\n }\n\n private async addPreviousGraphs() {\n const flattenedDeps: ComponentID[][] = [];\n await pMapPool(\n this.consumerComponents,\n async (comp) => {\n const previousVersion = comp.previouslyUsedVersion;\n if (!previousVersion) return;\n const modelComponent =\n comp.modelComponent || (await this.scope.legacyScope.getModelComponent(comp.id.changeVersion(undefined)));\n const version = await modelComponent.loadVersion(previousVersion, this.scope.legacyScope.objects, true);\n const flattenedEdges = await version.getFlattenedEdges(this.scope.legacyScope.objects);\n if (flattenedEdges.length) flattenedDeps.push(version.flattenedDependencies);\n this.addFlattenedEdgesToGraph(flattenedEdges);\n },\n { concurrency: 50 }\n );\n\n const flattenedDepsUniq = ComponentIdList.uniqFromArray(flattenedDeps.flat());\n this.missingFromGraph = this.missingFromGraph.filter((id) => !flattenedDepsUniq.has(id));\n }\n\n private async addComponentsWithMissingFlattenedEdges() {\n const missingEdges = this.missingFromGraph;\n this.logger.warn(`FlattenedEdgesGetter, found ${missingEdges.length} components with missing flattened edges:\n${missingEdges.map((e) => e.toString()).join('\\n')}`);\n const missingEdgesList = ComponentIdList.fromArray(missingEdges);\n const results = await this.scope.legacyScope.scopeImporter.importMany({\n ids: missingEdgesList,\n cache: true,\n lane: this.lane,\n preferDependencyGraph: false, // we know it does not have a dependency graph\n });\n const allFlattened = results.map((result) => result.version.flattenedDependencies);\n allFlattened.push(missingEdgesList);\n const allFlattenedUniq = ComponentIdList.uniqFromArray(allFlattened.flat());\n const componentsAndVersions = await this.scope.legacyScope.getComponentsAndVersions(\n ComponentIdList.fromArray(allFlattenedUniq)\n );\n componentsAndVersions.forEach(({ component, version, versionStr }) => {\n const compId = component.toComponentId().changeVersion(versionStr);\n this.graph.setNode(new Node(compId.toString(), compId));\n this.addEdges(compId, version.dependencies, 'prod');\n this.addEdges(compId, version.devDependencies, 'dev');\n this.addEdges(compId, version.extensionDependencies, 'ext');\n });\n }\n\n private addFlattenedEdgesToGraph(flattenedEdges: DepEdge[]) {\n flattenedEdges.forEach(({ source, target, type }) => {\n this.graph.setNode(new Node(source.toString(), source));\n this.graph.setNode(new Node(target.toString(), target));\n this.graph.setEdge(new Edge(source.toString(), target.toString(), type));\n });\n }\n\n private populateMissingFromGraph() {\n const allIds = this.graph.nodes.map((node) => node.attr);\n const currentlySnappedIds = ComponentIdList.fromArray(this.consumerComponents.map((comp) => comp.id));\n const filteredIds = allIds.filter((id) => !currentlySnappedIds.has(id));\n this.missingFromGraph = filteredIds;\n }\n\n private buildTheFirstLevel() {\n this.consumerComponents.forEach((comp) => {\n const id = comp.id;\n this.graph.setNode(new Node(id.toString(), id));\n this.addEdges(comp.id, comp.dependencies, 'prod');\n this.addEdges(comp.id, comp.devDependencies, 'dev');\n this.addEdges(comp.id, comp.extensionDependencies, 'ext');\n });\n }\n\n private addEdges(compId: ComponentID, dependencies: ConsumerComponent['dependencies'], label: DepEdgeType) {\n dependencies.get().forEach((dep) => {\n this.graph.setNode(new Node(dep.id.toString(), dep.id));\n this.graph.setEdge(new Edge(compId.toString(), dep.id.toString(), label));\n });\n }\n}\n\nfunction throwWhenDepNotIncluded(componentId: ComponentID, dependencyId: ComponentID) {\n if (!dependencyId.hasScope() && !dependencyId.hasVersion()) {\n throw new BitError(`fatal: \"${componentId.toString()}\" has a dependency \"${dependencyId.toString()}\".\nth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graph","data","require","_componentId","_toolboxPromise","_bitError","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","FlattenedEdgesGetter","constructor","scope","consumerComponents","logger","lane","Graph","buildGraph","debug","buildTheFirstLevel","populateMissingFromGraph","missingFromGraph","length","graph","addPreviousGraphs","importMissingAndAddToGraph","addComponentsWithMissingFlattenedEdges","populateFlattenedAndEdgesForComp","component","graphFromIds","successorsSubgraph","id","toString","edgesFromGraph","edges","map","edge","source","ComponentID","fromString","sourceId","target","targetId","type","attr","flattenedFromGraphIncludeItself","nodes","node","flattenedFromGraph","filter","isEqual","forEach","dep","throwWhenDepNotIncluded","flattenedDependencies","ComponentIdList","fromArray","flattenedEdges","idsWithoutGraphList","legacyScope","scopeImporter","importWithoutDeps","cache","componentsAndVersions","getComponentsAndVersions","missingEdges","Promise","all","version","versionStr","getFlattenedEdges","objects","push","toComponentId","changeVersion","addFlattenedEdgesToGraph","flattenedDeps","pMapPool","comp","previousVersion","previouslyUsedVersion","modelComponent","getModelComponent","undefined","loadVersion","concurrency","flattenedDepsUniq","uniqFromArray","flat","has","warn","join","missingEdgesList","results","importMany","ids","preferDependencyGraph","allFlattened","result","allFlattenedUniq","compId","setNode","Node","addEdges","dependencies","devDependencies","extensionDependencies","setEdge","Edge","allIds","currentlySnappedIds","filteredIds","label","get","exports","componentId","dependencyId","hasScope","hasVersion","BitError"],"sources":["flattened-edges.ts"],"sourcesContent":["import { Graph, Node, Edge } from '@teambit/graph.cleargraph';\nimport { DepEdgeType } from '@teambit/graph';\nimport { ScopeMain } from '@teambit/scope';\nimport { ConsumerComponent } from '@teambit/legacy.consumer-component';\nimport { DepEdge, Lane } from '@teambit/scope.objects';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport { Logger } from '@teambit/logger';\nimport { pMapPool } from '@teambit/toolbox.promise.map-pool';\nimport { BitError } from '@teambit/bit-error';\n\n/**\n * the goal of this class is to determine the graph dependencies of a given set of components with minimal effort.\n * it takes advantage of the fact that we save the dependency graph in the `Version` object and tries to reuse it.\n *\n * to optimize it as much as possible, we do it in 4 steps. each step we check whether the graph has missing ids,\n * and if so, continue to the next step.\n *\n * * * First step * * *\n * we have two groups in this graph.\n * 1. components that are now versioned (this.consumerComponents). they have the new version (which is not in the scope yet).\n * 2. component that are not part of the current snap/tag.\n * it's not possible that this group has new components that never been into the scope, otherwise the tag/snap is failing.\n * so we know we can always find the version-object of these components in the scope or import them.\n *\n * given the above. we can simply get the first level of dependencies of the first group.\n * start the graph by adding them all as nodes and edges.\n *\n * this dependencies array may contain components from the first group. we can filter them out. (we don't care about\n * them, they're part of the graph already)\n * we're left with the dependencies that are part of the second group. there are the `missingFromGraph`.\n *\n * * * Second step * * *\n * instead of import these components, we can more efficiently get their previous version from the scope.\n * it must be already in the scope because these are the components we load in the first place.\n * chances are that 99% of the dependencies of the current components objects are identical to the previous version.\n * by adding the flattenedEdges of the previous versions we can probably finish the graph without importing a single\n * component. It's ok that this graph of previous versions has ids that are not relevant to this graph. for example, if\n * we now tag bar@0.0.2, this graph will have bar@0.0.1 although it's not relevant. it's ok, because finally we don't\n * use this graph as a whole. we only pick a component and get its sub-graph, so all irrelevant ids are ignored.\n *\n * * * Third step * * *\n * in case the graph above wasn't enough. we can import the missing components and get their flattenedEdges.\n * all components that were snapped/tagged since around 0.0.8000 have the flattenedEdges saved in the version.\n * older components don't have them and that's why the last step is needed.\n *\n * * * Fourth step * * *\n * this is the worst scenario. we have some old dependencies without flattenedEdges, we have to import them with\n * all their flattened dependencies.\n * once we have all these objects we can iterate them and add them to the graph.\n */\nexport class FlattenedEdgesGetter {\n private graph = new Graph<ComponentID, DepEdgeType>();\n private missingFromGraph: ComponentID[] = [];\n constructor(\n private scope: ScopeMain,\n private consumerComponents: ConsumerComponent[],\n private logger: Logger,\n private lane?: Lane\n ) {}\n\n async buildGraph() {\n this.logger.debug('FlattenedEdgesGetter, start');\n this.buildTheFirstLevel();\n this.populateMissingFromGraph();\n if (!this.missingFromGraph.length) {\n return this.graph;\n }\n this.logger.debug(\n `FlattenedEdgesGetter, total ${this.missingFromGraph.length} components missing from graph, trying to find them in previous versions`\n );\n await this.addPreviousGraphs();\n if (!this.missingFromGraph.length) {\n this.logger.debug(`FlattenedEdgesGetter, all missing ids were found in previous versions`);\n return this.graph;\n }\n this.logger.debug(\n `FlattenedEdgesGetter, total ${this.missingFromGraph.length} components missing from graph, trying to import them and load their flattenedEdges`\n );\n await this.importMissingAndAddToGraph();\n if (!this.missingFromGraph.length) {\n this.logger.debug(`FlattenedEdgesGetter, successfully found flattened edges for all components without graph`);\n return this.graph;\n }\n this.logger.debug(\n `FlattenedEdgesGetter, total ${this.missingFromGraph.length} components without graph and their version-objects has no flattened edges, no choice but to import all their flattened deps`\n );\n await this.addComponentsWithMissingFlattenedEdges();\n return this.graph;\n }\n\n populateFlattenedAndEdgesForComp(component: ConsumerComponent) {\n const graphFromIds = this.graph.successorsSubgraph(component.id.toString());\n const edgesFromGraph = graphFromIds.edges.map((edge) => {\n return {\n source: ComponentID.fromString(edge.sourceId),\n target: ComponentID.fromString(edge.targetId),\n type: edge.attr as DepEdgeType,\n };\n });\n\n const flattenedFromGraphIncludeItself = graphFromIds.nodes.map((node) => node.attr);\n const flattenedFromGraph = flattenedFromGraphIncludeItself.filter((id) => !id.isEqual(component.id));\n flattenedFromGraph.forEach((dep) => throwWhenDepNotIncluded(component.id, dep));\n\n component.flattenedDependencies = ComponentIdList.fromArray(flattenedFromGraph);\n component.flattenedEdges = edgesFromGraph;\n }\n\n private async importMissingAndAddToGraph() {\n const idsWithoutGraphList = ComponentIdList.fromArray(this.missingFromGraph);\n await this.scope.legacyScope.scopeImporter.importWithoutDeps(idsWithoutGraphList, {\n cache: true,\n lane: this.lane,\n });\n const componentsAndVersions = await this.scope.legacyScope.getComponentsAndVersions(idsWithoutGraphList);\n const missingEdges: ComponentID[] = [];\n await Promise.all(\n componentsAndVersions.map(async ({ component, version, versionStr }) => {\n const flattenedEdges = await version.getFlattenedEdges(this.scope.legacyScope.objects);\n if (!flattenedEdges.length && version.flattenedDependencies.length) {\n missingEdges.push(component.toComponentId().changeVersion(versionStr));\n }\n this.addFlattenedEdgesToGraph(flattenedEdges);\n })\n );\n this.missingFromGraph = missingEdges;\n }\n\n private async addPreviousGraphs() {\n const flattenedDeps: ComponentID[][] = [];\n await pMapPool(\n this.consumerComponents,\n async (comp) => {\n const previousVersion = comp.previouslyUsedVersion;\n if (!previousVersion) return;\n const modelComponent =\n comp.modelComponent || (await this.scope.legacyScope.getModelComponent(comp.id.changeVersion(undefined)));\n const version = await modelComponent.loadVersion(previousVersion, this.scope.legacyScope.objects, true);\n const flattenedEdges = await version.getFlattenedEdges(this.scope.legacyScope.objects);\n if (flattenedEdges.length) flattenedDeps.push(version.flattenedDependencies);\n this.addFlattenedEdgesToGraph(flattenedEdges);\n },\n { concurrency: 50 }\n );\n\n const flattenedDepsUniq = ComponentIdList.uniqFromArray(flattenedDeps.flat());\n this.missingFromGraph = this.missingFromGraph.filter((id) => !flattenedDepsUniq.has(id));\n }\n\n private async addComponentsWithMissingFlattenedEdges() {\n const missingEdges = this.missingFromGraph;\n this.logger.warn(`FlattenedEdgesGetter, found ${missingEdges.length} components with missing flattened edges:\n${missingEdges.map((e) => e.toString()).join('\\n')}`);\n const missingEdgesList = ComponentIdList.fromArray(missingEdges);\n const results = await this.scope.legacyScope.scopeImporter.importMany({\n ids: missingEdgesList,\n cache: true,\n lane: this.lane,\n preferDependencyGraph: false, // we know it does not have a dependency graph\n });\n const allFlattened = results.map((result) => result.version.flattenedDependencies);\n allFlattened.push(missingEdgesList);\n const allFlattenedUniq = ComponentIdList.uniqFromArray(allFlattened.flat());\n const componentsAndVersions = await this.scope.legacyScope.getComponentsAndVersions(\n ComponentIdList.fromArray(allFlattenedUniq)\n );\n componentsAndVersions.forEach(({ component, version, versionStr }) => {\n const compId = component.toComponentId().changeVersion(versionStr);\n this.graph.setNode(new Node(compId.toString(), compId));\n this.addEdges(compId, version.dependencies, 'prod');\n this.addEdges(compId, version.devDependencies, 'dev');\n this.addEdges(compId, version.extensionDependencies, 'ext');\n });\n }\n\n private addFlattenedEdgesToGraph(flattenedEdges: DepEdge[]) {\n flattenedEdges.forEach(({ source, target, type }) => {\n this.graph.setNode(new Node(source.toString(), source));\n this.graph.setNode(new Node(target.toString(), target));\n this.graph.setEdge(new Edge(source.toString(), target.toString(), type));\n });\n }\n\n private populateMissingFromGraph() {\n const allIds = this.graph.nodes.map((node) => node.attr);\n const currentlySnappedIds = ComponentIdList.fromArray(this.consumerComponents.map((comp) => comp.id));\n const filteredIds = allIds.filter((id) => !currentlySnappedIds.has(id));\n this.missingFromGraph = filteredIds;\n }\n\n private buildTheFirstLevel() {\n this.consumerComponents.forEach((comp) => {\n const id = comp.id;\n this.graph.setNode(new Node(id.toString(), id));\n this.addEdges(comp.id, comp.dependencies, 'prod');\n this.addEdges(comp.id, comp.devDependencies, 'dev');\n this.addEdges(comp.id, comp.extensionDependencies, 'ext');\n });\n }\n\n private addEdges(compId: ComponentID, dependencies: ConsumerComponent['dependencies'], label: DepEdgeType) {\n dependencies.get().forEach((dep) => {\n this.graph.setNode(new Node(dep.id.toString(), dep.id));\n this.graph.setEdge(new Edge(compId.toString(), dep.id.toString(), label));\n });\n }\n}\n\nfunction throwWhenDepNotIncluded(componentId: ComponentID, dependencyId: ComponentID) {\n if (!dependencyId.hasScope() && !dependencyId.hasVersion()) {\n throw new BitError(`fatal: \"${componentId.toString()}\" has a dependency \"${dependencyId.toString()}\".\nthis dependency was not included in the tag command.`);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAE,aAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,YAAA,YAAAA,CAAA;I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,CAACzB,IAAI,CAAC/C,EAAE,EAAE+C,IAAI,CAAC4B,qBAAqB,EAAE,KAAK,CAAC;IAC3D,CAAC,CAAC;EACJ;EAEQH,QAAQA,CAACH,MAAmB,EAAEI,YAA+C,EAAEQ,KAAkB,EAAE;IACzGR,YAAY,CAACS,GAAG,CAAC,CAAC,CAAC9D,OAAO,CAAEC,GAAG,IAAK;MAClC,IAAI,CAAC7B,KAAK,CAAC8E,OAAO,CAAC,KAAIC,aAAI,EAAClD,GAAG,CAACrB,EAAE,CAACC,QAAQ,CAAC,CAAC,EAAEoB,GAAG,CAACrB,EAAE,CAAC,CAAC;MACvD,IAAI,CAACR,KAAK,CAACoF,OAAO,CAAC,KAAIC,aAAI,EAACR,MAAM,CAACpE,QAAQ,CAAC,CAAC,EAAEoB,GAAG,CAACrB,EAAE,CAACC,QAAQ,CAAC,CAAC,EAAEgF,KAAK,CAAC,CAAC;IAC3E,CAAC,CAAC;EACJ;AACF;AAACE,OAAA,CAAAxG,oBAAA,GAAAA,oBAAA;AAED,SAAS2C,uBAAuBA,CAAC8D,WAAwB,EAAEC,YAAyB,EAAE;EACpF,IAAI,CAACA,YAAY,CAACC,QAAQ,CAAC,CAAC,IAAI,CAACD,YAAY,CAACE,UAAU,CAAC,CAAC,EAAE;IAC1D,MAAM,KAAIC,oBAAQ,EAAC,WAAWJ,WAAW,CAACnF,QAAQ,CAAC,CAAC,uBAAuBoF,YAAY,CAACpF,QAAQ,CAAC,CAAC;AACtG,qDAAqD,CAAC;EACpD;AACF","ignoreList":[]}
|
|
@@ -12,49 +12,34 @@ function _componentId() {
|
|
|
12
12
|
};
|
|
13
13
|
return data;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const data =
|
|
17
|
-
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
function _dependencies() {
|
|
23
|
-
const data = require("@teambit/legacy/dist/consumer/component/dependencies");
|
|
24
|
-
_dependencies = function () {
|
|
15
|
+
function _legacy() {
|
|
16
|
+
const data = require("@teambit/legacy.consumer-component");
|
|
17
|
+
_legacy = function () {
|
|
25
18
|
return data;
|
|
26
19
|
};
|
|
27
20
|
return data;
|
|
28
21
|
}
|
|
29
|
-
function
|
|
22
|
+
function _component() {
|
|
30
23
|
const data = require("@teambit/component.sources");
|
|
31
|
-
|
|
24
|
+
_component = function () {
|
|
32
25
|
return data;
|
|
33
26
|
};
|
|
34
27
|
return data;
|
|
35
28
|
}
|
|
36
|
-
function
|
|
37
|
-
const data =
|
|
38
|
-
|
|
29
|
+
function _legacy2() {
|
|
30
|
+
const data = require("@teambit/legacy.consumer-config");
|
|
31
|
+
_legacy2 = function () {
|
|
39
32
|
return data;
|
|
40
33
|
};
|
|
41
34
|
return data;
|
|
42
35
|
}
|
|
43
|
-
function
|
|
36
|
+
function _legacy3() {
|
|
44
37
|
const data = require("@teambit/legacy.extension-data");
|
|
45
|
-
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
function _componentSchema() {
|
|
51
|
-
const data = require("@teambit/legacy/dist/consumer/component/component-schema");
|
|
52
|
-
_componentSchema = function () {
|
|
38
|
+
_legacy3 = function () {
|
|
53
39
|
return data;
|
|
54
40
|
};
|
|
55
41
|
return data;
|
|
56
42
|
}
|
|
57
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
58
43
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
59
44
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
60
45
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -72,7 +57,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
72
57
|
async function generateCompFromScope(scope, compData, snapping) {
|
|
73
58
|
if (!compData.files) throw new Error('generateComp: files are missing');
|
|
74
59
|
const files = compData.files.map(file => {
|
|
75
|
-
return new (
|
|
60
|
+
return new (_component().SourceFile)({
|
|
76
61
|
base: '.',
|
|
77
62
|
path: file.path,
|
|
78
63
|
contents: Buffer.from(file.content),
|
|
@@ -80,14 +65,14 @@ async function generateCompFromScope(scope, compData, snapping) {
|
|
|
80
65
|
});
|
|
81
66
|
});
|
|
82
67
|
const id = compData.componentId;
|
|
83
|
-
const extensions =
|
|
84
|
-
const consumerComponent = new (
|
|
68
|
+
const extensions = _legacy3().ExtensionDataList.fromConfigObject(compData.aspects || {});
|
|
69
|
+
const consumerComponent = new (_legacy().ConsumerComponent)({
|
|
85
70
|
mainFile: compData.mainFile || 'index.ts',
|
|
86
71
|
name: compData.componentId.fullName,
|
|
87
72
|
scope: compData.componentId.scope,
|
|
88
73
|
files,
|
|
89
|
-
schema:
|
|
90
|
-
overrides: await
|
|
74
|
+
schema: _legacy().CURRENT_SCHEMA,
|
|
75
|
+
overrides: await _legacy2().ComponentOverrides.loadNewFromScope(id, files, extensions),
|
|
91
76
|
defaultScope: compData.componentId.scope,
|
|
92
77
|
extensions,
|
|
93
78
|
// the dummy data here are not important. this Version object will be discarded later.
|
|
@@ -124,7 +109,7 @@ async function addDeps(component, snapData, scope, deps, depsResolver, snapping)
|
|
|
124
109
|
const comp = comps.find(c => c.id.isEqualWithoutVersion(depId));
|
|
125
110
|
if (!comp) throw new Error(`unable to find the specified dependency ${depId.toString()} in the scope`);
|
|
126
111
|
const pkgName = depsResolver.getPackageName(comp);
|
|
127
|
-
return new (
|
|
112
|
+
return new (_legacy().Dependency)(comp.id, [], pkgName);
|
|
128
113
|
};
|
|
129
114
|
const compDeps = compIdsDataParsed.filter(c => c.type === 'runtime').map(dep => toDependency(dep.id));
|
|
130
115
|
const compDevDeps = compIdsDataParsed.filter(c => c.type === 'dev').map(dep => toDependency(dep.id));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_componentId","data","require","_component","_interopRequireDefault","_dependencies","_component2","_componentOverrides","_legacy","_componentSchema","e","__esModule","default","ownKeys","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","generateCompFromScope","scope","compData","snapping","files","Error","map","file","SourceFile","base","path","contents","Buffer","from","content","test","id","componentId","extensions","ExtensionDataList","fromConfigObject","aspects","consumerComponent","ConsumerComponent","mainFile","name","fullName","schema","CURRENT_SCHEMA","overrides","ComponentOverrides","loadNewFromScope","defaultScope","log","message","date","Date","now","toString","username","email","_addFlattenedDependenciesToComponents","version","filesBitObject","legacyScope","sources","consumerComponentToVersion","modelComponent","findOrAddComponent","hash","objects","writeObjectsToTheFS","f","component","getManyByLegacy","addDeps","snapData","deps","depsResolver","newDeps","newDependencies","updateDeps","dependencies","compIdsData","dep","isComponent","compIdsDataParsed","ComponentID","fromString","compIds","changeVersion","comps","getMany","toDependency","depId","comp","find","c","isEqualWithoutVersion","pkgName","getPackageName","Dependency","compDeps","type","compDevDeps","compPeerDeps","packageDeps","toPackageObj","pkgs","reduce","acc","curr","getPkgObj","manipulateCurrentPkgs","removeDependencies","pkg","found","d","startsWith","replace","manipulateCurrentDeps","currentCompDeps","afterRemoval","includes","toStringWithoutVersion","state","_consumer","dependenciesData","allDependencies","get","devDependencies","peerDependencies","allPackagesDependencies","packageDependencies","devPackageDependencies","peerPackageDependencies","loadDependenciesFromScope","UpdateDepsAspectsSaveIntoDepsResolver"],"sources":["generate-comp-from-scope.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component-id';\nimport ConsumerComponent from '@teambit/legacy/dist/consumer/component';\nimport { Dependency } from '@teambit/legacy/dist/consumer/component/dependencies';\nimport { SourceFile } from '@teambit/component.sources';\nimport { ScopeMain } from '@teambit/scope';\nimport ComponentOverrides from '@teambit/legacy/dist/consumer/config/component-overrides';\nimport { ExtensionDataList } from '@teambit/legacy.extension-data';\nimport { Component } from '@teambit/component';\nimport { CURRENT_SCHEMA } from '@teambit/legacy/dist/consumer/component/component-schema';\nimport { DependenciesMain } from '@teambit/dependencies';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { FileData } from './snap-from-scope.cmd';\nimport { SnappingMain, SnapDataParsed } from './snapping.main.runtime';\n\nexport type CompData = {\n componentId: ComponentID;\n dependencies: string[];\n aspects: Record<string, any> | undefined;\n message: string | undefined;\n files: FileData[] | undefined;\n mainFile?: string;\n};\n\n/**\n * normally new components are created from a workspace. the files are in the filesystem and the ConsumerComponent\n * object is created from the files.\n * here, we need to create the ConsumerComponent object \"on the fly\". we don't have workspace, only scope. the files\n * are in-memory (we got them from snap-from-scope command).\n * the way how it is done is by creating a minimal ConsumerComponent object, then convert `Version` object from it,\n * write the version and files into the scope as objects, so then it's possible to load Component object using the\n * ConsumerComponent.\n */\nexport async function generateCompFromScope(\n scope: ScopeMain,\n compData: CompData,\n snapping: SnappingMain\n): Promise<Component> {\n if (!compData.files) throw new Error('generateComp: files are missing');\n const files = compData.files.map((file) => {\n return new SourceFile({ base: '.', path: file.path, contents: Buffer.from(file.content), test: false });\n });\n const id = compData.componentId;\n const extensions = ExtensionDataList.fromConfigObject(compData.aspects || {});\n\n const consumerComponent = new ConsumerComponent({\n mainFile: compData.mainFile || 'index.ts',\n name: compData.componentId.fullName,\n scope: compData.componentId.scope,\n files,\n schema: CURRENT_SCHEMA,\n overrides: await ComponentOverrides.loadNewFromScope(id, files, extensions),\n defaultScope: compData.componentId.scope,\n extensions,\n // the dummy data here are not important. this Version object will be discarded later.\n log: {\n message: compData.message || '',\n date: Date.now().toString(),\n username: '',\n email: '',\n },\n });\n // this is needed, otherwise in case of updating envs/aspects, the version-validator throws\n // an error saying \"the extension ${extensionId.toString()} is missing from the flattenedDependencies\"\n await snapping._addFlattenedDependenciesToComponents([consumerComponent]);\n\n const { version, files: filesBitObject } =\n await scope.legacyScope.sources.consumerComponentToVersion(consumerComponent);\n const modelComponent = scope.legacyScope.sources.findOrAddComponent(consumerComponent);\n consumerComponent.version = version.hash().toString();\n await scope.legacyScope.objects.writeObjectsToTheFS([version, modelComponent, ...filesBitObject.map((f) => f.file)]);\n const component = await scope.getManyByLegacy([consumerComponent]);\n\n return component[0];\n}\n\nexport async function addDeps(\n component: Component,\n snapData: SnapDataParsed,\n scope: ScopeMain,\n deps: DependenciesMain,\n depsResolver: DependencyResolverMain,\n snapping: SnappingMain\n) {\n const newDeps = snapData.newDependencies || [];\n const updateDeps = snapData.dependencies || [];\n const compIdsData = newDeps.filter((dep) => dep.isComponent);\n const compIdsDataParsed = compIdsData.map((data) => ({\n ...data,\n id: ComponentID.fromString(data.id),\n }));\n const compIds = compIdsDataParsed.map((dep) => (dep.version ? dep.id.changeVersion(dep.version) : dep.id));\n const comps = await scope.getMany(compIds);\n const toDependency = (depId: ComponentID) => {\n const comp = comps.find((c) => c.id.isEqualWithoutVersion(depId));\n if (!comp) throw new Error(`unable to find the specified dependency ${depId.toString()} in the scope`);\n const pkgName = depsResolver.getPackageName(comp);\n return new Dependency(comp.id, [], pkgName);\n };\n const compDeps = compIdsDataParsed.filter((c) => c.type === 'runtime').map((dep) => toDependency(dep.id));\n const compDevDeps = compIdsDataParsed.filter((c) => c.type === 'dev').map((dep) => toDependency(dep.id));\n const compPeerDeps = compIdsDataParsed.filter((c) => c.type === 'peer').map((dep) => toDependency(dep.id));\n const packageDeps = newDeps.filter((dep) => !dep.isComponent);\n const toPackageObj = (pkgs: Array<{ id: string; version?: string }>) => {\n return pkgs.reduce((acc, curr) => {\n if (!curr.version) throw new Error(`please specify a version for the package dependency: \"${curr.id}\"`);\n acc[curr.id] = curr.version;\n return acc;\n }, {});\n };\n const getPkgObj = (type: 'runtime' | 'dev' | 'peer') => {\n return toPackageObj(packageDeps.filter((dep) => dep.type === type));\n };\n const manipulateCurrentPkgs = (pkgs: Record<string, string>) => {\n snapData.removeDependencies?.forEach((pkg) => {\n delete pkgs[pkg];\n });\n Object.keys(pkgs).forEach((pkg) => {\n const found = updateDeps.find((d) => d.startsWith(`${pkg}@`));\n if (found) {\n pkgs[pkg] = found.replace(`${pkg}@`, '');\n }\n });\n return pkgs;\n };\n const manipulateCurrentDeps = (currentCompDeps: Dependency[]) => {\n const afterRemoval = currentCompDeps.filter(\n (dep) => !snapData.removeDependencies?.includes(dep.id.toStringWithoutVersion())\n );\n afterRemoval.forEach((dep) => {\n const found = updateDeps.find((d) => d.startsWith(`${dep.id.toStringWithoutVersion()}@`));\n if (found) {\n dep.id = dep.id.changeVersion(found.replace(`${dep.id.toStringWithoutVersion()}@`, ''));\n }\n });\n return afterRemoval;\n };\n\n const consumerComponent = component.state._consumer as ConsumerComponent;\n\n const dependenciesData = {\n allDependencies: {\n dependencies: [...compDeps, ...manipulateCurrentDeps(consumerComponent.dependencies.get())],\n devDependencies: [...compDevDeps, ...manipulateCurrentDeps(consumerComponent.devDependencies.get())],\n peerDependencies: [...compPeerDeps, ...manipulateCurrentDeps(consumerComponent.peerDependencies.get())],\n },\n allPackagesDependencies: {\n packageDependencies: { ...manipulateCurrentPkgs(consumerComponent.packageDependencies), ...getPkgObj('runtime') },\n devPackageDependencies: {\n ...manipulateCurrentPkgs(consumerComponent.devPackageDependencies),\n ...getPkgObj('dev'),\n },\n peerPackageDependencies: {\n ...manipulateCurrentPkgs(consumerComponent.peerPackageDependencies),\n ...getPkgObj('peer'),\n },\n },\n };\n\n // add the dependencies to the legacy ConsumerComponent object\n // it takes care of both: given dependencies (from the cli) and the overrides, which are coming from the env.\n await deps.loadDependenciesFromScope(consumerComponent, dependenciesData);\n\n await snapping.UpdateDepsAspectsSaveIntoDepsResolver(component, updateDeps);\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,aAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,YAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,WAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,cAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,aAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAM,oBAAA;EAAA,MAAAN,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAK,mBAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,OAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAQ,iBAAA;EAAA,MAAAR,IAAA,GAAAC,OAAA;EAAAO,gBAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0F,SAAAG,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GA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legacy","_component","_legacy2","_legacy3","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","generateCompFromScope","scope","compData","snapping","files","Error","map","file","SourceFile","base","path","contents","Buffer","from","content","test","id","componentId","extensions","ExtensionDataList","fromConfigObject","aspects","consumerComponent","ConsumerComponent","mainFile","name","fullName","schema","CURRENT_SCHEMA","overrides","ComponentOverrides","loadNewFromScope","defaultScope","log","message","date","Date","now","toString","username","email","_addFlattenedDependenciesToComponents","version","filesBitObject","legacyScope","sources","consumerComponentToVersion","modelComponent","findOrAddComponent","hash","objects","writeObjectsToTheFS","f","component","getManyByLegacy","addDeps","snapData","deps","depsResolver","newDeps","newDependencies","updateDeps","dependencies","compIdsData","dep","isComponent","compIdsDataParsed","ComponentID","fromString","compIds","changeVersion","comps","getMany","toDependency","depId","comp","find","c","isEqualWithoutVersion","pkgName","getPackageName","Dependency","compDeps","type","compDevDeps","compPeerDeps","packageDeps","toPackageObj","pkgs","reduce","acc","curr","getPkgObj","manipulateCurrentPkgs","removeDependencies","pkg","found","d","startsWith","replace","manipulateCurrentDeps","currentCompDeps","afterRemoval","includes","toStringWithoutVersion","state","_consumer","dependenciesData","allDependencies","get","devDependencies","peerDependencies","allPackagesDependencies","packageDependencies","devPackageDependencies","peerPackageDependencies","loadDependenciesFromScope","UpdateDepsAspectsSaveIntoDepsResolver"],"sources":["generate-comp-from-scope.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component-id';\nimport { Dependency, ConsumerComponent, CURRENT_SCHEMA } from '@teambit/legacy.consumer-component';\nimport { SourceFile } from '@teambit/component.sources';\nimport { ScopeMain } from '@teambit/scope';\nimport { ComponentOverrides } from '@teambit/legacy.consumer-config';\nimport { ExtensionDataList } from '@teambit/legacy.extension-data';\nimport { Component } from '@teambit/component';\nimport { DependenciesMain } from '@teambit/dependencies';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { FileData } from './snap-from-scope.cmd';\nimport { SnappingMain, SnapDataParsed } from './snapping.main.runtime';\n\nexport type CompData = {\n componentId: ComponentID;\n dependencies: string[];\n aspects: Record<string, any> | undefined;\n message: string | undefined;\n files: FileData[] | undefined;\n mainFile?: string;\n};\n\n/**\n * normally new components are created from a workspace. the files are in the filesystem and the ConsumerComponent\n * object is created from the files.\n * here, we need to create the ConsumerComponent object \"on the fly\". we don't have workspace, only scope. the files\n * are in-memory (we got them from snap-from-scope command).\n * the way how it is done is by creating a minimal ConsumerComponent object, then convert `Version` object from it,\n * write the version and files into the scope as objects, so then it's possible to load Component object using the\n * ConsumerComponent.\n */\nexport async function generateCompFromScope(\n scope: ScopeMain,\n compData: CompData,\n snapping: SnappingMain\n): Promise<Component> {\n if (!compData.files) throw new Error('generateComp: files are missing');\n const files = compData.files.map((file) => {\n return new SourceFile({ base: '.', path: file.path, contents: Buffer.from(file.content), test: false });\n });\n const id = compData.componentId;\n const extensions = ExtensionDataList.fromConfigObject(compData.aspects || {});\n\n const consumerComponent = new ConsumerComponent({\n mainFile: compData.mainFile || 'index.ts',\n name: compData.componentId.fullName,\n scope: compData.componentId.scope,\n files,\n schema: CURRENT_SCHEMA,\n overrides: await ComponentOverrides.loadNewFromScope(id, files, extensions),\n defaultScope: compData.componentId.scope,\n extensions,\n // the dummy data here are not important. this Version object will be discarded later.\n log: {\n message: compData.message || '',\n date: Date.now().toString(),\n username: '',\n email: '',\n },\n });\n // this is needed, otherwise in case of updating envs/aspects, the version-validator throws\n // an error saying \"the extension ${extensionId.toString()} is missing from the flattenedDependencies\"\n await snapping._addFlattenedDependenciesToComponents([consumerComponent]);\n\n const { version, files: filesBitObject } =\n await scope.legacyScope.sources.consumerComponentToVersion(consumerComponent);\n const modelComponent = scope.legacyScope.sources.findOrAddComponent(consumerComponent);\n consumerComponent.version = version.hash().toString();\n await scope.legacyScope.objects.writeObjectsToTheFS([version, modelComponent, ...filesBitObject.map((f) => f.file)]);\n const component = await scope.getManyByLegacy([consumerComponent]);\n\n return component[0];\n}\n\nexport async function addDeps(\n component: Component,\n snapData: SnapDataParsed,\n scope: ScopeMain,\n deps: DependenciesMain,\n depsResolver: DependencyResolverMain,\n snapping: SnappingMain\n) {\n const newDeps = snapData.newDependencies || [];\n const updateDeps = snapData.dependencies || [];\n const compIdsData = newDeps.filter((dep) => dep.isComponent);\n const compIdsDataParsed = compIdsData.map((data) => ({\n ...data,\n id: ComponentID.fromString(data.id),\n }));\n const compIds = compIdsDataParsed.map((dep) => (dep.version ? dep.id.changeVersion(dep.version) : dep.id));\n const comps = await scope.getMany(compIds);\n const toDependency = (depId: ComponentID) => {\n const comp = comps.find((c) => c.id.isEqualWithoutVersion(depId));\n if (!comp) throw new Error(`unable to find the specified dependency ${depId.toString()} in the scope`);\n const pkgName = depsResolver.getPackageName(comp);\n return new Dependency(comp.id, [], pkgName);\n };\n const compDeps = compIdsDataParsed.filter((c) => c.type === 'runtime').map((dep) => toDependency(dep.id));\n const compDevDeps = compIdsDataParsed.filter((c) => c.type === 'dev').map((dep) => toDependency(dep.id));\n const compPeerDeps = compIdsDataParsed.filter((c) => c.type === 'peer').map((dep) => toDependency(dep.id));\n const packageDeps = newDeps.filter((dep) => !dep.isComponent);\n const toPackageObj = (pkgs: Array<{ id: string; version?: string }>) => {\n return pkgs.reduce((acc, curr) => {\n if (!curr.version) throw new Error(`please specify a version for the package dependency: \"${curr.id}\"`);\n acc[curr.id] = curr.version;\n return acc;\n }, {});\n };\n const getPkgObj = (type: 'runtime' | 'dev' | 'peer') => {\n return toPackageObj(packageDeps.filter((dep) => dep.type === type));\n };\n const manipulateCurrentPkgs = (pkgs: Record<string, string>) => {\n snapData.removeDependencies?.forEach((pkg) => {\n delete pkgs[pkg];\n });\n Object.keys(pkgs).forEach((pkg) => {\n const found = updateDeps.find((d) => d.startsWith(`${pkg}@`));\n if (found) {\n pkgs[pkg] = found.replace(`${pkg}@`, '');\n }\n });\n return pkgs;\n };\n const manipulateCurrentDeps = (currentCompDeps: Dependency[]) => {\n const afterRemoval = currentCompDeps.filter(\n (dep) => !snapData.removeDependencies?.includes(dep.id.toStringWithoutVersion())\n );\n afterRemoval.forEach((dep) => {\n const found = updateDeps.find((d) => d.startsWith(`${dep.id.toStringWithoutVersion()}@`));\n if (found) {\n dep.id = dep.id.changeVersion(found.replace(`${dep.id.toStringWithoutVersion()}@`, ''));\n }\n });\n return afterRemoval;\n };\n\n const consumerComponent = component.state._consumer as ConsumerComponent;\n\n const dependenciesData = {\n allDependencies: {\n dependencies: [...compDeps, ...manipulateCurrentDeps(consumerComponent.dependencies.get())],\n devDependencies: [...compDevDeps, ...manipulateCurrentDeps(consumerComponent.devDependencies.get())],\n peerDependencies: [...compPeerDeps, ...manipulateCurrentDeps(consumerComponent.peerDependencies.get())],\n },\n allPackagesDependencies: {\n packageDependencies: { ...manipulateCurrentPkgs(consumerComponent.packageDependencies), ...getPkgObj('runtime') },\n devPackageDependencies: {\n ...manipulateCurrentPkgs(consumerComponent.devPackageDependencies),\n ...getPkgObj('dev'),\n },\n peerPackageDependencies: {\n ...manipulateCurrentPkgs(consumerComponent.peerPackageDependencies),\n ...getPkgObj('peer'),\n },\n },\n };\n\n // add the dependencies to the legacy ConsumerComponent object\n // it takes care of both: given dependencies (from the cli) and the overrides, which are coming from the env.\n await deps.loadDependenciesFromScope(consumerComponent, dependenciesData);\n\n await snapping.UpdateDepsAspectsSaveIntoDepsResolver(component, updateDeps);\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,aAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,YAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;E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AC,KAAK,CAAC,CACpB;MACDuB,uBAAuB,EAAAvI,aAAA,CAAAA,aAAA,KAClBiH,qBAAqB,CAACvE,iBAAiB,CAAC6F,uBAAuB,CAAC,GAChEvB,SAAS,CAAC,MAAM,CAAC;IAExB;EACF,CAAC;;EAED;EACA;EACA,MAAMnC,IAAI,CAAC2D,yBAAyB,CAAC9F,iBAAiB,EAAEqF,gBAAgB,CAAC;EAEzE,MAAMxG,QAAQ,CAACkH,qCAAqC,CAAChE,SAAS,EAAEQ,UAAU,CAAC;AAC7E","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Scope } from '@teambit/legacy.scope';
|
|
2
|
+
import { ConsumerComponent as Component } from '@teambit/legacy.consumer-component';
|
|
3
|
+
import { Lane } from '@teambit/scope.objects';
|
|
4
|
+
export declare class FlattenedDependenciesGetter {
|
|
5
|
+
private scope;
|
|
6
|
+
private components;
|
|
7
|
+
private lane?;
|
|
8
|
+
private dependenciesGraph;
|
|
9
|
+
private versionDependencies;
|
|
10
|
+
private cache;
|
|
11
|
+
constructor(scope: Scope, components: Component[], lane?: Lane | undefined);
|
|
12
|
+
/**
|
|
13
|
+
* to get the flattened dependencies of a component, we iterate over the direct dependencies and
|
|
14
|
+
* figure out what should be the flattened of each one of the dependencies.
|
|
15
|
+
* a dependency can be one of the two scenarios and should be handled accordingly.
|
|
16
|
+
* 1. a dependency can be tagged/snapped along with the current component.
|
|
17
|
+
* 2. a dependency can be a component that was already tagged before.
|
|
18
|
+
* there is no option #3 of a component that exists on the workspace but wasn't tagged and is not
|
|
19
|
+
* part of the current tag. In such case, we throw an error, see throwWhenDepNotIncluded below.
|
|
20
|
+
*
|
|
21
|
+
* the flattened dependencies process handles the two cases above differently.
|
|
22
|
+
* 1. first, it builds a graph with all current components, this way it's easier to get the
|
|
23
|
+
* flattened dependencies by graph algorithm. (without graph, it becomes difficult when there are
|
|
24
|
+
* circular dependencies).
|
|
25
|
+
* 2. for other components, it loads them from the model and gets the flattened from the objects.
|
|
26
|
+
*/
|
|
27
|
+
populateFlattenedDependencies(): Promise<void>;
|
|
28
|
+
private importExternalDependenciesInBulk;
|
|
29
|
+
private getFlattened;
|
|
30
|
+
private getFlattenedFromCurrentComponents;
|
|
31
|
+
private getFlattenedFromVersion;
|
|
32
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FlattenedDependenciesGetter = void 0;
|
|
7
|
+
function _graphlib() {
|
|
8
|
+
const data = _interopRequireWildcard(require("graphlib"));
|
|
9
|
+
_graphlib = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _pMapSeries() {
|
|
15
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
16
|
+
_pMapSeries = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _bitError() {
|
|
22
|
+
const data = require("@teambit/bit-error");
|
|
23
|
+
_bitError = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _componentId() {
|
|
29
|
+
const data = require("@teambit/component-id");
|
|
30
|
+
_componentId = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _legacy() {
|
|
36
|
+
const data = require("@teambit/legacy.logger");
|
|
37
|
+
_legacy = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _lodash() {
|
|
43
|
+
const data = require("lodash");
|
|
44
|
+
_lodash = function () {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
50
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
51
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
52
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
53
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
54
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
55
|
+
class FlattenedDependenciesGetter {
|
|
56
|
+
constructor(scope, components, lane) {
|
|
57
|
+
this.scope = scope;
|
|
58
|
+
this.components = components;
|
|
59
|
+
this.lane = lane;
|
|
60
|
+
_defineProperty(this, "dependenciesGraph", void 0);
|
|
61
|
+
_defineProperty(this, "versionDependencies", void 0);
|
|
62
|
+
_defineProperty(this, "cache", {});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* to get the flattened dependencies of a component, we iterate over the direct dependencies and
|
|
67
|
+
* figure out what should be the flattened of each one of the dependencies.
|
|
68
|
+
* a dependency can be one of the two scenarios and should be handled accordingly.
|
|
69
|
+
* 1. a dependency can be tagged/snapped along with the current component.
|
|
70
|
+
* 2. a dependency can be a component that was already tagged before.
|
|
71
|
+
* there is no option #3 of a component that exists on the workspace but wasn't tagged and is not
|
|
72
|
+
* part of the current tag. In such case, we throw an error, see throwWhenDepNotIncluded below.
|
|
73
|
+
*
|
|
74
|
+
* the flattened dependencies process handles the two cases above differently.
|
|
75
|
+
* 1. first, it builds a graph with all current components, this way it's easier to get the
|
|
76
|
+
* flattened dependencies by graph algorithm. (without graph, it becomes difficult when there are
|
|
77
|
+
* circular dependencies).
|
|
78
|
+
* 2. for other components, it loads them from the model and gets the flattened from the objects.
|
|
79
|
+
*/
|
|
80
|
+
async populateFlattenedDependencies() {
|
|
81
|
+
_legacy().logger.debug(`populateFlattenedDependencies starts with ${this.components.length} components`);
|
|
82
|
+
this.dependenciesGraph = buildComponentsGraphCombined(this.components);
|
|
83
|
+
// console.log("this.dependenciesGraph", this.dependenciesGraph.toString())
|
|
84
|
+
await this.importExternalDependenciesInBulk();
|
|
85
|
+
await (0, _pMapSeries().default)(this.components, async component => {
|
|
86
|
+
component.flattenedDependencies = await this.getFlattened(component.componentId);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async importExternalDependenciesInBulk() {
|
|
90
|
+
const allDependencies = this.components.map(component => {
|
|
91
|
+
return getEdges(this.dependenciesGraph, component.id.toString());
|
|
92
|
+
});
|
|
93
|
+
const idsStr = (0, _lodash().compact)((0, _lodash().uniq)(allDependencies.flat()));
|
|
94
|
+
const bitIds = idsStr.map(idStr => this.dependenciesGraph.node(idStr)).filter(bitId => !this.components.find(c => c.id.isEqual(bitId)));
|
|
95
|
+
const scopeComponentsImporter = this.scope.scopeImporter;
|
|
96
|
+
this.versionDependencies = await scopeComponentsImporter.importMany({
|
|
97
|
+
ids: _componentId().ComponentIdList.fromArray(bitIds),
|
|
98
|
+
preferDependencyGraph: false,
|
|
99
|
+
cache: true,
|
|
100
|
+
throwForDependencyNotFound: true,
|
|
101
|
+
lane: this.lane,
|
|
102
|
+
reason: 'for fetching all dependencies'
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async getFlattened(bitId) {
|
|
106
|
+
const dependencies = this.getFlattenedFromCurrentComponents(bitId);
|
|
107
|
+
dependencies.forEach(dep => throwWhenDepNotIncluded(bitId, dep));
|
|
108
|
+
const dependenciesDeps = await (0, _pMapSeries().default)(dependencies, dep => this.getFlattenedFromVersion(dep, bitId));
|
|
109
|
+
const dependenciesDepsFlattened = dependenciesDeps.flat();
|
|
110
|
+
// this dependenciesDepsFlattened can be huge, don't use spread operator (...) here. otherwise, it throws
|
|
111
|
+
// `Maximum call stack size exceeded`. it's important to first make them uniq
|
|
112
|
+
// (from a real example, before uniq: 133,068. after uniq: 2,126)
|
|
113
|
+
const dependenciesDepsUniq = _componentId().ComponentIdList.uniqFromArray(dependenciesDepsFlattened);
|
|
114
|
+
dependencies.push(...dependenciesDepsUniq);
|
|
115
|
+
return _componentId().ComponentIdList.uniqFromArray(dependencies);
|
|
116
|
+
}
|
|
117
|
+
getFlattenedFromCurrentComponents(bitId) {
|
|
118
|
+
const allDeps = getEdges(this.dependenciesGraph, bitId.toString()) || [];
|
|
119
|
+
const dependencies = allDeps.map(idStr => this.dependenciesGraph.node(idStr));
|
|
120
|
+
return dependencies;
|
|
121
|
+
}
|
|
122
|
+
async getFlattenedFromVersion(id, dependentId) {
|
|
123
|
+
if (!this.cache[id.toString()]) {
|
|
124
|
+
const versionDeps = this.versionDependencies.find(({
|
|
125
|
+
component
|
|
126
|
+
}) => component.toComponentId().isEqual(id));
|
|
127
|
+
if (versionDeps) {
|
|
128
|
+
const dependencies = await versionDeps.component.flattenedDependencies(this.scope.objects);
|
|
129
|
+
this.cache[id.toString()] = dependencies;
|
|
130
|
+
} else {
|
|
131
|
+
const existing = this.components.find(c => c.id.isEqual(id));
|
|
132
|
+
if (existing) {
|
|
133
|
+
this.cache[id.toString()] = new (_componentId().ComponentIdList)();
|
|
134
|
+
} else {
|
|
135
|
+
if (!id.hasVersion()) {
|
|
136
|
+
throw new Error(`error found while getting the dependencies of "${dependentId.toString()}". A dependency "${id.toString()}" doesn't have a version
|
|
137
|
+
if this is an external env/extension/aspect configured in workspace.jsonc, make sure it is set with a version`);
|
|
138
|
+
}
|
|
139
|
+
const fromModel = await this.scope.getVersionInstance(id);
|
|
140
|
+
this.cache[id.toString()] = fromModel.flattenedDependencies;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return this.cache[id.toString()];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.FlattenedDependenciesGetter = FlattenedDependenciesGetter;
|
|
148
|
+
function throwWhenDepNotIncluded(componentId, dependencyId) {
|
|
149
|
+
if (!dependencyId.hasScope() && !dependencyId.hasVersion()) {
|
|
150
|
+
throw new (_bitError().BitError)(`fatal: "${componentId.toString()}" has a dependency "${dependencyId.toString()}".
|
|
151
|
+
this dependency was not included in the tag command.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* get all successors edges recursively (flatten)
|
|
157
|
+
*/
|
|
158
|
+
function getEdges(graph, id) {
|
|
159
|
+
if (!graph.hasNode(id)) return null;
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
const edges = _graphlib().default.alg.preorder(graph, id);
|
|
162
|
+
return (0, _lodash().tail)(edges); // the first item is the component itself
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* one graph of the given components. it doesn't fetch/load anything. it builds the graph with the
|
|
167
|
+
* given data. the node is a ComponentID and the edge has the label of the dependency type. it can be
|
|
168
|
+
* either "dependencies" or "devDependencies".
|
|
169
|
+
*/
|
|
170
|
+
function buildComponentsGraphCombined(components) {
|
|
171
|
+
const graph = new (_graphlib().Graph)();
|
|
172
|
+
components.forEach(component => {
|
|
173
|
+
_setGraphEdges(component.id, component.dependencies, graph);
|
|
174
|
+
_setGraphEdges(component.id, component.devDependencies, graph, 'devDependencies');
|
|
175
|
+
_setGraphEdges(component.id, component.extensionDependencies, graph, 'devDependencies');
|
|
176
|
+
});
|
|
177
|
+
return graph;
|
|
178
|
+
}
|
|
179
|
+
function _setGraphEdges(bitId, dependencies, graph, label = 'dependencies') {
|
|
180
|
+
const id = bitId.toString();
|
|
181
|
+
dependencies.get().forEach(dependency => {
|
|
182
|
+
const depId = dependency.id.toString();
|
|
183
|
+
// save the full ComponentID of a string id to be able to retrieve it later with no confusion
|
|
184
|
+
if (!graph.hasNode(id)) graph.setNode(id, bitId);
|
|
185
|
+
if (!graph.hasNode(depId)) graph.setNode(depId, dependency.id);
|
|
186
|
+
graph.setEdge(id, depId, label);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
//# sourceMappingURL=get-flattened-dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_graphlib","data","_interopRequireWildcard","require","_pMapSeries","_interopRequireDefault","_bitError","_componentId","_legacy","_lodash","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_defineProperty","_toPropertyKey","value","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","FlattenedDependenciesGetter","constructor","scope","components","lane","populateFlattenedDependencies","logger","debug","length","dependenciesGraph","buildComponentsGraphCombined","importExternalDependenciesInBulk","mapSeries","component","flattenedDependencies","getFlattened","componentId","allDependencies","map","getEdges","id","toString","idsStr","compact","uniq","flat","bitIds","idStr","node","filter","bitId","find","c","isEqual","scopeComponentsImporter","scopeImporter","versionDependencies","importMany","ids","ComponentIdList","fromArray","preferDependencyGraph","cache","throwForDependencyNotFound","reason","dependencies","getFlattenedFromCurrentComponents","forEach","dep","throwWhenDepNotIncluded","dependenciesDeps","getFlattenedFromVersion","dependenciesDepsFlattened","dependenciesDepsUniq","uniqFromArray","push","allDeps","dependentId","versionDeps","toComponentId","objects","existing","hasVersion","Error","fromModel","getVersionInstance","exports","dependencyId","hasScope","BitError","graph","hasNode","edges","graphlib","alg","preorder","tail","GraphLib","_setGraphEdges","devDependencies","extensionDependencies","label","dependency","depId","setNode","setEdge"],"sources":["get-flattened-dependencies.ts"],"sourcesContent":["import graphlib, { Graph as GraphLib } from 'graphlib';\nimport mapSeries from 'p-map-series';\nimport { BitError } from '@teambit/bit-error';\nimport { ComponentID, ComponentIdList } from '@teambit/component-id';\nimport { BitIdStr } from '@teambit/legacy-bit-id';\nimport { VersionDependencies, Scope } from '@teambit/legacy.scope';\nimport { ConsumerComponent as Component, Dependencies } from '@teambit/legacy.consumer-component';\nimport { logger } from '@teambit/legacy.logger';\nimport { Lane } from '@teambit/scope.objects';\nimport { compact, tail, uniq } from 'lodash';\n\nexport class FlattenedDependenciesGetter {\n private dependenciesGraph: GraphLib;\n private versionDependencies: VersionDependencies[];\n private cache: { [idStr: string]: ComponentIdList } = {};\n constructor(\n private scope: Scope,\n private components: Component[],\n private lane?: Lane\n ) {}\n\n /**\n * to get the flattened dependencies of a component, we iterate over the direct dependencies and\n * figure out what should be the flattened of each one of the dependencies.\n * a dependency can be one of the two scenarios and should be handled accordingly.\n * 1. a dependency can be tagged/snapped along with the current component.\n * 2. a dependency can be a component that was already tagged before.\n * there is no option #3 of a component that exists on the workspace but wasn't tagged and is not\n * part of the current tag. In such case, we throw an error, see throwWhenDepNotIncluded below.\n *\n * the flattened dependencies process handles the two cases above differently.\n * 1. first, it builds a graph with all current components, this way it's easier to get the\n * flattened dependencies by graph algorithm. (without graph, it becomes difficult when there are\n * circular dependencies).\n * 2. for other components, it loads them from the model and gets the flattened from the objects.\n */\n async populateFlattenedDependencies() {\n logger.debug(`populateFlattenedDependencies starts with ${this.components.length} components`);\n this.dependenciesGraph = buildComponentsGraphCombined(this.components);\n // console.log(\"this.dependenciesGraph\", this.dependenciesGraph.toString())\n await this.importExternalDependenciesInBulk();\n await mapSeries(this.components, async (component) => {\n component.flattenedDependencies = await this.getFlattened(component.componentId);\n });\n }\n\n private async importExternalDependenciesInBulk() {\n const allDependencies = this.components.map((component) => {\n return getEdges(this.dependenciesGraph, component.id.toString());\n });\n const idsStr: string[] = compact(uniq(allDependencies.flat()));\n const bitIds = idsStr\n .map((idStr) => this.dependenciesGraph.node(idStr))\n .filter((bitId) => !this.components.find((c) => c.id.isEqual(bitId)));\n const scopeComponentsImporter = this.scope.scopeImporter;\n this.versionDependencies = await scopeComponentsImporter.importMany({\n ids: ComponentIdList.fromArray(bitIds),\n preferDependencyGraph: false,\n cache: true,\n throwForDependencyNotFound: true,\n lane: this.lane,\n reason: 'for fetching all dependencies',\n });\n }\n\n private async getFlattened(bitId: ComponentID): Promise<ComponentIdList> {\n const dependencies = this.getFlattenedFromCurrentComponents(bitId);\n dependencies.forEach((dep) => throwWhenDepNotIncluded(bitId, dep));\n const dependenciesDeps = await mapSeries(dependencies, (dep) => this.getFlattenedFromVersion(dep, bitId));\n const dependenciesDepsFlattened = dependenciesDeps.flat();\n // this dependenciesDepsFlattened can be huge, don't use spread operator (...) here. otherwise, it throws\n // `Maximum call stack size exceeded`. it's important to first make them uniq\n // (from a real example, before uniq: 133,068. after uniq: 2,126)\n const dependenciesDepsUniq = ComponentIdList.uniqFromArray(dependenciesDepsFlattened);\n dependencies.push(...dependenciesDepsUniq);\n return ComponentIdList.uniqFromArray(dependencies);\n }\n\n private getFlattenedFromCurrentComponents(bitId: ComponentID): ComponentID[] {\n const allDeps = getEdges(this.dependenciesGraph, bitId.toString()) || [];\n const dependencies = allDeps.map((idStr) => this.dependenciesGraph.node(idStr));\n return dependencies;\n }\n\n private async getFlattenedFromVersion(id: ComponentID, dependentId: ComponentID): Promise<ComponentIdList> {\n if (!this.cache[id.toString()]) {\n const versionDeps = this.versionDependencies.find(({ component }) => component.toComponentId().isEqual(id));\n if (versionDeps) {\n const dependencies = await versionDeps.component.flattenedDependencies(this.scope.objects);\n this.cache[id.toString()] = dependencies;\n } else {\n const existing = this.components.find((c) => c.id.isEqual(id));\n if (existing) {\n this.cache[id.toString()] = new ComponentIdList();\n } else {\n if (!id.hasVersion()) {\n throw new Error(`error found while getting the dependencies of \"${dependentId.toString()}\". A dependency \"${id.toString()}\" doesn't have a version\nif this is an external env/extension/aspect configured in workspace.jsonc, make sure it is set with a version`);\n }\n const fromModel = await this.scope.getVersionInstance(id);\n this.cache[id.toString()] = fromModel.flattenedDependencies;\n }\n }\n }\n return this.cache[id.toString()];\n }\n}\n\nfunction throwWhenDepNotIncluded(componentId: ComponentID, dependencyId: ComponentID) {\n if (!dependencyId.hasScope() && !dependencyId.hasVersion()) {\n throw new BitError(`fatal: \"${componentId.toString()}\" has a dependency \"${dependencyId.toString()}\".\nthis dependency was not included in the tag command.`);\n }\n}\n\n/**\n * get all successors edges recursively (flatten)\n */\nfunction getEdges(graph: GraphLib, id: BitIdStr): BitIdStr[] | null {\n if (!graph.hasNode(id)) return null;\n // @ts-ignore\n const edges = graphlib.alg.preorder(graph, id);\n return tail(edges); // the first item is the component itself\n}\n\n/**\n * one graph of the given components. it doesn't fetch/load anything. it builds the graph with the\n * given data. the node is a ComponentID and the edge has the label of the dependency type. it can be\n * either \"dependencies\" or \"devDependencies\".\n */\nfunction buildComponentsGraphCombined(components: Component[]): GraphLib {\n const graph = new GraphLib();\n components.forEach((component) => {\n _setGraphEdges(component.id, component.dependencies, graph);\n _setGraphEdges(component.id, component.devDependencies, graph, 'devDependencies');\n _setGraphEdges(component.id, component.extensionDependencies, graph, 'devDependencies');\n });\n return graph;\n}\n\nfunction _setGraphEdges(bitId: ComponentID, dependencies: Dependencies, graph: GraphLib, label = 'dependencies') {\n const id = bitId.toString();\n dependencies.get().forEach((dependency) => {\n const depId = dependency.id.toString();\n // save the full ComponentID of a string id to be able to retrieve it later with no confusion\n if (!graph.hasNode(id)) graph.setNode(id, bitId);\n if (!graph.hasNode(depId)) graph.setNode(depId, dependency.id);\n graph.setEdge(id, dep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SAAS9D,4BAA4BA,CAACP,UAAuB,EAAY;EACvE,MAAMmE,KAAK,GAAG,KAAIO,iBAAQ,EAAC,CAAC;EAC5B1E,UAAU,CAAC4C,OAAO,CAAElC,SAAS,IAAK;IAChCiE,cAAc,CAACjE,SAAS,CAACO,EAAE,EAAEP,SAAS,CAACgC,YAAY,EAAEyB,KAAK,CAAC;IAC3DQ,cAAc,CAACjE,SAAS,CAACO,EAAE,EAAEP,SAAS,CAACkE,eAAe,EAAET,KAAK,EAAE,iBAAiB,CAAC;IACjFQ,cAAc,CAACjE,SAAS,CAACO,EAAE,EAAEP,SAAS,CAACmE,qBAAqB,EAAEV,KAAK,EAAE,iBAAiB,CAAC;EACzF,CAAC,CAAC;EACF,OAAOA,KAAK;AACd;AAEA,SAASQ,cAAcA,CAAChD,KAAkB,EAAEe,YAA0B,EAAEyB,KAAe,EAAEW,KAAK,GAAG,cAAc,EAAE;EAC/G,MAAM7D,EAAE,GAAGU,KAAK,CAACT,QAAQ,CAAC,CAAC;EAC3BwB,YAAY,CAACrE,GAAG,CAAC,CAAC,CAACuE,OAAO,CAAEmC,UAAU,IAAK;IACzC,MAAMC,KAAK,GAAGD,UAAU,CAAC9D,EAAE,CAACC,QAAQ,CAAC,CAAC;IACtC;IACA,IAAI,CAACiD,KAAK,CAACC,OAAO,CAACnD,EAAE,CAAC,EAAEkD,KAAK,CAACc,OAAO,CAAChE,EAAE,EAAEU,KAAK,CAAC;IAChD,IAAI,CAACwC,KAAK,CAACC,OAAO,CAACY,KAAK,CAAC,EAAEb,KAAK,CAACc,OAAO,CAACD,KAAK,EAAED,UAAU,CAAC9D,EAAE,CAAC;IAC9DkD,KAAK,CAACe,OAAO,CAACjE,EAAE,EAAE+D,KAAK,EAAEF,KAAK,CAAC;EACjC,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentID, ComponentIdList } from '@teambit/component-id';
|
|
2
|
+
import { Tmp } from '@teambit/legacy.scope';
|
|
3
|
+
export type MessagePerComponent = {
|
|
4
|
+
id: ComponentID;
|
|
5
|
+
msg: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class MessagePerComponentFetcher {
|
|
8
|
+
private idsToTagObject;
|
|
9
|
+
private idsToAutoTagObject;
|
|
10
|
+
constructor(idsToTag: ComponentIdList, idsToAutoTag: ComponentIdList);
|
|
11
|
+
getMessagesFromEditor(tmp: Tmp, editor: string | boolean): Promise<MessagePerComponent[]>;
|
|
12
|
+
getTemplate(): string;
|
|
13
|
+
parseFileWithMessages(messagesFileContent: string): MessagePerComponent[];
|
|
14
|
+
private openEditor;
|
|
15
|
+
private getIdsToTagStr;
|
|
16
|
+
private getIdsToAutoTagStr;
|
|
17
|
+
}
|