@teambit/dependencies 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,13 @@
1
1
  import { Command, CommandOptions } from '@teambit/cli';
2
- declare type DependenciesFlags = {
2
+ import { DependenciesMain } from './dependencies.main.runtime';
3
+ declare type GetDependenciesFlags = {
3
4
  tree: boolean;
4
5
  };
5
- export declare class DependenciesGet implements Command {
6
+ export declare type SetDependenciesFlags = {
7
+ dev?: boolean;
8
+ peer?: boolean;
9
+ };
10
+ export declare class DependenciesGetCmd implements Command {
6
11
  name: string;
7
12
  arguments: {
8
13
  name: string;
@@ -12,9 +17,9 @@ export declare class DependenciesGet implements Command {
12
17
  description: string;
13
18
  alias: string;
14
19
  options: CommandOptions;
15
- report([id]: [string], { tree }: DependenciesFlags): Promise<string>;
20
+ report([id]: [string], { tree }: GetDependenciesFlags): Promise<string>;
16
21
  }
17
- export declare class DependenciesDebug implements Command {
22
+ export declare class DependenciesDebugCmd implements Command {
18
23
  name: string;
19
24
  arguments: {
20
25
  name: string;
@@ -26,6 +31,20 @@ export declare class DependenciesDebug implements Command {
26
31
  options: CommandOptions;
27
32
  report([id]: [string]): Promise<string>;
28
33
  }
34
+ export declare class DependenciesSetCmd implements Command {
35
+ private deps;
36
+ name: string;
37
+ arguments: {
38
+ name: string;
39
+ description: string;
40
+ }[];
41
+ group: string;
42
+ description: string;
43
+ alias: string;
44
+ options: CommandOptions;
45
+ constructor(deps: DependenciesMain);
46
+ report([pattern, pkg]: [string, string], setDepsFlags: SetDependenciesFlags): Promise<string>;
47
+ }
29
48
  export declare class DependenciesCmd implements Command {
30
49
  name: string;
31
50
  alias: string;
@@ -9,7 +9,7 @@ require("core-js/modules/es.promise.js");
9
9
  Object.defineProperty(exports, "__esModule", {
10
10
  value: true
11
11
  });
12
- exports.DependenciesGet = exports.DependenciesDebug = exports.DependenciesCmd = void 0;
12
+ exports.DependenciesSetCmd = exports.DependenciesGetCmd = exports.DependenciesDebugCmd = exports.DependenciesCmd = void 0;
13
13
 
14
14
  function _defineProperty2() {
15
15
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -71,8 +71,18 @@ function _idNotFoundInGraph() {
71
71
  return data;
72
72
  }
73
73
 
74
+ function _constants() {
75
+ const data = require("@teambit/legacy/dist/constants");
76
+
77
+ _constants = function () {
78
+ return data;
79
+ };
80
+
81
+ return data;
82
+ }
83
+
74
84
  // eslint-disable-next-line max-classes-per-file
75
- class DependenciesGet {
85
+ class DependenciesGetCmd {
76
86
  constructor() {
77
87
  (0, _defineProperty2().default)(this, "name", 'get <component-name>');
78
88
  (0, _defineProperty2().default)(this, "arguments", [{
@@ -141,9 +151,9 @@ ${scopeTable || '<none>'}`;
141
151
 
142
152
  }
143
153
 
144
- exports.DependenciesGet = DependenciesGet;
154
+ exports.DependenciesGetCmd = DependenciesGetCmd;
145
155
 
146
- class DependenciesDebug {
156
+ class DependenciesDebugCmd {
147
157
  constructor() {
148
158
  (0, _defineProperty2().default)(this, "name", 'debug <component-name>');
149
159
  (0, _defineProperty2().default)(this, "arguments", [{
@@ -163,7 +173,33 @@ class DependenciesDebug {
163
173
 
164
174
  }
165
175
 
166
- exports.DependenciesDebug = DependenciesDebug;
176
+ exports.DependenciesDebugCmd = DependenciesDebugCmd;
177
+
178
+ class DependenciesSetCmd {
179
+ constructor(deps) {
180
+ this.deps = deps;
181
+ (0, _defineProperty2().default)(this, "name", 'set <component-pattern> <package>');
182
+ (0, _defineProperty2().default)(this, "arguments", [{
183
+ name: 'component-pattern',
184
+ description: _constants().COMPONENT_PATTERN_HELP
185
+ }, {
186
+ name: 'package',
187
+ description: 'package name with version, e.g. "lodash@1.0.0"'
188
+ }]);
189
+ (0, _defineProperty2().default)(this, "group", 'info');
190
+ (0, _defineProperty2().default)(this, "description", 'set a dependency to component(s)');
191
+ (0, _defineProperty2().default)(this, "alias", '');
192
+ (0, _defineProperty2().default)(this, "options", [['d', 'dev', 'add to the devDependencies'], ['p', 'peer', 'add to the peerDependencies']]);
193
+ }
194
+
195
+ async report([pattern, pkg], setDepsFlags) {
196
+ const results = await this.deps.setDependency(pattern, pkg, setDepsFlags);
197
+ return _chalk().default.green(`the following component(s) have been successfully updated:\n${results.join('\n')}`);
198
+ }
199
+
200
+ }
201
+
202
+ exports.DependenciesSetCmd = DependenciesSetCmd;
167
203
 
168
204
  class DependenciesCmd {
169
205
  constructor() {
@@ -1 +1 @@
1
- {"version":3,"names":["DependenciesGet","name","description","report","id","tree","results","dependencies","idWithVersion","workspaceGraph","_getIdWithLatestVersion","getGraphAsTree","graph","graphAsTree","getDependenciesAsObjectTree","toString","archy","err","constructor","chalk","red","workspaceTree","scopeTree","scopeGraph","green","getDependenciesInfo","getScopeDependencies","IdNotFoundInGraph","length","toStringWithoutVersion","scopeTable","generateDependenciesInfoTable","workspaceTable","bold","DependenciesDebug","JSON","stringify","undefined","DependenciesCmd","unrecognizedSubcommand"],"sources":["dependencies-cmd.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport archy from 'archy';\nimport {\n dependencies,\n DependenciesResultsDebug,\n DependenciesResults,\n} from '@teambit/legacy/dist/api/consumer/lib/dependencies';\nimport { generateDependenciesInfoTable } from '@teambit/legacy/dist/cli/templates/component-template';\nimport { IdNotFoundInGraph } from '@teambit/legacy/dist/scope/exceptions/id-not-found-in-graph';\nimport DependencyGraph from '@teambit/legacy/dist/scope/graph/scope-graph';\n\ntype DependenciesFlags = {\n tree: boolean;\n};\n\nexport class DependenciesGet implements Command {\n name = 'get <component-name>';\n arguments = [{ name: 'component-name', description: 'component name or component id' }];\n group = 'info';\n description = 'show direct and indirect dependencies of the given component';\n alias = '';\n options = [['t', 'tree', 'EXPERIMENTAL. render dependencies as a tree, similar to \"npm ls\"']] as CommandOptions;\n\n async report([id]: [string], { tree = false }: DependenciesFlags) {\n const results = (await dependencies(id, false)) as DependenciesResults;\n\n if (tree) {\n const idWithVersion = results.workspaceGraph._getIdWithLatestVersion(results.id);\n const getGraphAsTree = (graph: DependencyGraph) => {\n try {\n const graphAsTree = graph.getDependenciesAsObjectTree(idWithVersion.toString());\n return archy(graphAsTree);\n } catch (err: any) {\n if (err.constructor.name === 'RangeError') {\n return `${chalk.red('unable to generate a tree representation, the graph is too big or has cycles')}`;\n }\n throw err;\n }\n };\n const workspaceTree = getGraphAsTree(results.workspaceGraph);\n const scopeTree = getGraphAsTree(results.scopeGraph);\n return `${chalk.green('workspace')}:\\n${workspaceTree}\\n\\n${chalk.green('scope')}:\\n${scopeTree}`;\n }\n const workspaceGraph = results.workspaceGraph.getDependenciesInfo(results.id);\n const getScopeDependencies = () => {\n try {\n return results.scopeGraph.getDependenciesInfo(results.id);\n } catch (err) {\n if (err instanceof IdNotFoundInGraph) return []; // component might be new\n throw err;\n }\n };\n const scopeGraph = getScopeDependencies();\n if (!scopeGraph.length && !workspaceGraph.length) {\n return `no dependencies found for ${results.id.toString()}.\ntry running \"bit cat-component ${results.id.toStringWithoutVersion()}\" to see whether the component/version exists locally`;\n }\n\n const scopeTable = generateDependenciesInfoTable(scopeGraph, results.id);\n const workspaceTable = generateDependenciesInfoTable(workspaceGraph, results.id);\n return `${chalk.bold('Dependencies originated from workspace')}\n${workspaceTable || '<none>'}\n\n${chalk.bold('Dependencies originated from scope')}\n${scopeTable || '<none>'}`;\n }\n}\n\nexport class DependenciesDebug implements Command {\n name = 'debug <component-name>';\n arguments = [{ name: 'component-name', description: 'component name or component id' }];\n group = 'info';\n description = 'show the immediate dependencies and how their versions were determined';\n alias = '';\n options = [] as CommandOptions;\n\n async report([id]: [string]) {\n const results = (await dependencies(id, true)) as DependenciesResultsDebug;\n return JSON.stringify(results, undefined, 4);\n }\n}\n\nexport class DependenciesCmd implements Command {\n name = 'dependencies <sub-command>';\n alias = 'deps';\n description = 'manage dependencies';\n options = [];\n group = 'info';\n commands: Command[] = [];\n\n async report([unrecognizedSubcommand]: [string]) {\n return chalk.red(\n `\"${unrecognizedSubcommand}\" is not a subcommand of \"dependencies\", please run \"bit dependencies --help\" to list the subcommands`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAVA;AAiBO,MAAMA,eAAN,CAAyC;EAAA;IAAA,8CACvC,sBADuC;IAAA,mDAElC,CAAC;MAAEC,IAAI,EAAE,gBAAR;MAA0BC,WAAW,EAAE;IAAvC,CAAD,CAFkC;IAAA,+CAGtC,MAHsC;IAAA,qDAIhC,8DAJgC;IAAA,+CAKtC,EALsC;IAAA,iDAMpC,CAAC,CAAC,GAAD,EAAM,MAAN,EAAc,kEAAd,CAAD,CANoC;EAAA;;EAQlC,MAANC,MAAM,CAAC,CAACC,EAAD,CAAD,EAAiB;IAAEC,IAAI,GAAG;EAAT,CAAjB,EAAsD;IAChE,MAAMC,OAAO,GAAI,MAAM,IAAAC,4BAAA,EAAaH,EAAb,EAAiB,KAAjB,CAAvB;;IAEA,IAAIC,IAAJ,EAAU;MACR,MAAMG,aAAa,GAAGF,OAAO,CAACG,cAAR,CAAuBC,uBAAvB,CAA+CJ,OAAO,CAACF,EAAvD,CAAtB;;MACA,MAAMO,cAAc,GAAIC,KAAD,IAA4B;QACjD,IAAI;UACF,MAAMC,WAAW,GAAGD,KAAK,CAACE,2BAAN,CAAkCN,aAAa,CAACO,QAAd,EAAlC,CAApB;UACA,OAAO,IAAAC,gBAAA,EAAMH,WAAN,CAAP;QACD,CAHD,CAGE,OAAOI,GAAP,EAAiB;UACjB,IAAIA,GAAG,CAACC,WAAJ,CAAgBjB,IAAhB,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gBAAA,CAAMc,IAAN,CAAW,wCAAX,CAAqD;AACnE,EAAED,cAAc,IAAI,QAAS;AAC7B;AACA,EAAEb,gBAAA,CAAMc,IAAN,CAAW,oCAAX,CAAiD;AACnD,EAAEH,UAAU,IAAI,QAAS,EAJrB;EAKD;;AAlD6C;;;;AAqDzC,MAAMI,iBAAN,CAA2C;EAAA;IAAA,8CACzC,wBADyC;IAAA,mDAEpC,CAAC;MAAEjC,IAAI,EAAE,gBAAR;MAA0BC,WAAW,EAAE;IAAvC,CAAD,CAFoC;IAAA,+CAGxC,MAHwC;IAAA,qDAIlC,wEAJkC;IAAA,+CAKxC,EALwC;IAAA,iDAMtC,EANsC;EAAA;;EAQpC,MAANC,MAAM,CAAC,CAACC,EAAD,CAAD,EAAiB;IAC3B,MAAME,OAAO,GAAI,MAAM,IAAAC,4BAAA,EAAaH,EAAb,EAAiB,IAAjB,CAAvB;IACA,OAAO+B,IAAI,CAACC,SAAL,CAAe9B,OAAf,EAAwB+B,SAAxB,EAAmC,CAAnC,CAAP;EACD;;AAX+C;;;;AAc3C,MAAMC,eAAN,CAAyC;EAAA;IAAA,8CACvC,4BADuC;IAAA,+CAEtC,MAFsC;IAAA,qDAGhC,qBAHgC;IAAA,iDAIpC,EAJoC;IAAA,+CAKtC,MALsC;IAAA,kDAMxB,EANwB;EAAA;;EAQlC,MAANnC,MAAM,CAAC,CAACoC,sBAAD,CAAD,EAAqC;IAC/C,OAAOpB,gBAAA,CAAMC,GAAN,CACJ,IAAGmB,sBAAuB,uGADtB,CAAP;EAGD;;AAZ6C"}
1
+ {"version":3,"names":["DependenciesGetCmd","name","description","report","id","tree","results","dependencies","idWithVersion","workspaceGraph","_getIdWithLatestVersion","getGraphAsTree","graph","graphAsTree","getDependenciesAsObjectTree","toString","archy","err","constructor","chalk","red","workspaceTree","scopeTree","scopeGraph","green","getDependenciesInfo","getScopeDependencies","IdNotFoundInGraph","length","toStringWithoutVersion","scopeTable","generateDependenciesInfoTable","workspaceTable","bold","DependenciesDebugCmd","JSON","stringify","undefined","DependenciesSetCmd","deps","COMPONENT_PATTERN_HELP","pattern","pkg","setDepsFlags","setDependency","join","DependenciesCmd","unrecognizedSubcommand"],"sources":["dependencies-cmd.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport archy from 'archy';\nimport {\n dependencies,\n DependenciesResultsDebug,\n DependenciesResults,\n} from '@teambit/legacy/dist/api/consumer/lib/dependencies';\nimport { generateDependenciesInfoTable } from '@teambit/legacy/dist/cli/templates/component-template';\nimport { IdNotFoundInGraph } from '@teambit/legacy/dist/scope/exceptions/id-not-found-in-graph';\nimport DependencyGraph from '@teambit/legacy/dist/scope/graph/scope-graph';\nimport { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';\nimport { DependenciesMain } from './dependencies.main.runtime';\n\ntype GetDependenciesFlags = {\n tree: boolean;\n};\n\nexport type SetDependenciesFlags = {\n dev?: boolean;\n peer?: boolean;\n};\n\nexport class DependenciesGetCmd implements Command {\n name = 'get <component-name>';\n arguments = [{ name: 'component-name', description: 'component name or component id' }];\n group = 'info';\n description = 'show direct and indirect dependencies of the given component';\n alias = '';\n options = [['t', 'tree', 'EXPERIMENTAL. render dependencies as a tree, similar to \"npm ls\"']] as CommandOptions;\n\n async report([id]: [string], { tree = false }: GetDependenciesFlags) {\n const results = (await dependencies(id, false)) as DependenciesResults;\n\n if (tree) {\n const idWithVersion = results.workspaceGraph._getIdWithLatestVersion(results.id);\n const getGraphAsTree = (graph: DependencyGraph) => {\n try {\n const graphAsTree = graph.getDependenciesAsObjectTree(idWithVersion.toString());\n return archy(graphAsTree);\n } catch (err: any) {\n if (err.constructor.name === 'RangeError') {\n return `${chalk.red('unable to generate a tree representation, the graph is too big or has cycles')}`;\n }\n throw err;\n }\n };\n const workspaceTree = getGraphAsTree(results.workspaceGraph);\n const scopeTree = getGraphAsTree(results.scopeGraph);\n return `${chalk.green('workspace')}:\\n${workspaceTree}\\n\\n${chalk.green('scope')}:\\n${scopeTree}`;\n }\n const workspaceGraph = results.workspaceGraph.getDependenciesInfo(results.id);\n const getScopeDependencies = () => {\n try {\n return results.scopeGraph.getDependenciesInfo(results.id);\n } catch (err) {\n if (err instanceof IdNotFoundInGraph) return []; // component might be new\n throw err;\n }\n };\n const scopeGraph = getScopeDependencies();\n if (!scopeGraph.length && !workspaceGraph.length) {\n return `no dependencies found for ${results.id.toString()}.\ntry running \"bit cat-component ${results.id.toStringWithoutVersion()}\" to see whether the component/version exists locally`;\n }\n\n const scopeTable = generateDependenciesInfoTable(scopeGraph, results.id);\n const workspaceTable = generateDependenciesInfoTable(workspaceGraph, results.id);\n return `${chalk.bold('Dependencies originated from workspace')}\n${workspaceTable || '<none>'}\n\n${chalk.bold('Dependencies originated from scope')}\n${scopeTable || '<none>'}`;\n }\n}\n\nexport class DependenciesDebugCmd implements Command {\n name = 'debug <component-name>';\n arguments = [{ name: 'component-name', description: 'component name or component id' }];\n group = 'info';\n description = 'show the immediate dependencies and how their versions were determined';\n alias = '';\n options = [] as CommandOptions;\n\n async report([id]: [string]) {\n const results = (await dependencies(id, true)) as DependenciesResultsDebug;\n return JSON.stringify(results, undefined, 4);\n }\n}\n\nexport class DependenciesSetCmd implements Command {\n name = 'set <component-pattern> <package>';\n arguments = [\n { name: 'component-pattern', description: COMPONENT_PATTERN_HELP },\n { name: 'package', description: 'package name with version, e.g. \"lodash@1.0.0\"' },\n ];\n group = 'info';\n description = 'set a dependency to component(s)';\n alias = '';\n options = [\n ['d', 'dev', 'add to the devDependencies'],\n ['p', 'peer', 'add to the peerDependencies'],\n ] as CommandOptions;\n\n constructor(private deps: DependenciesMain) {}\n\n async report([pattern, pkg]: [string, string], setDepsFlags: SetDependenciesFlags) {\n const results = await this.deps.setDependency(pattern, pkg, setDepsFlags);\n return chalk.green(`the following component(s) have been successfully updated:\\n${results.join('\\n')}`);\n }\n}\n\nexport class DependenciesCmd implements Command {\n name = 'dependencies <sub-command>';\n alias = 'deps';\n description = 'manage dependencies';\n options = [];\n group = 'info';\n commands: Command[] = [];\n\n async report([unrecognizedSubcommand]: [string]) {\n return chalk.red(\n `\"${unrecognizedSubcommand}\" is not a subcommand of \"dependencies\", please run \"bit dependencies --help\" to list the subcommands`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAZA;AAwBO,MAAMA,kBAAN,CAA4C;EAAA;IAAA,8CAC1C,sBAD0C;IAAA,mDAErC,CAAC;MAAEC,IAAI,EAAE,gBAAR;MAA0BC,WAAW,EAAE;IAAvC,CAAD,CAFqC;IAAA,+CAGzC,MAHyC;IAAA,qDAInC,8DAJmC;IAAA,+CAKzC,EALyC;IAAA,iDAMvC,CAAC,CAAC,GAAD,EAAM,MAAN,EAAc,kEAAd,CAAD,CANuC;EAAA;;EAQrC,MAANC,MAAM,CAAC,CAACC,EAAD,CAAD,EAAiB;IAAEC,IAAI,GAAG;EAAT,CAAjB,EAAyD;IACnE,MAAMC,OAAO,GAAI,MAAM,IAAAC,4BAAA,EAAaH,EAAb,EAAiB,KAAjB,CAAvB;;IAEA,IAAIC,IAAJ,EAAU;MACR,MAAMG,aAAa,GAAGF,OAAO,CAACG,cAAR,CAAuBC,uBAAvB,CAA+CJ,OAAO,CAACF,EAAvD,CAAtB;;MACA,MAAMO,cAAc,GAAIC,KAAD,IAA4B;QACjD,IAAI;UACF,MAAMC,WAAW,GAAGD,KAAK,CAACE,2BAAN,CAAkCN,aAAa,CAACO,QAAd,EAAlC,CAApB;UACA,O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d,CAFQ,CAKkC;EAAE;;EAElC,MAANC,MAAM,CAAC,CAACsC,OAAD,EAAUC,GAAV,CAAD,EAAmCC,YAAnC,EAAuE;IACjF,MAAMrC,OAAO,GAAG,MAAM,KAAKiC,IAAL,CAAUK,aAAV,CAAwBH,OAAxB,EAAiCC,GAAjC,EAAsCC,YAAtC,CAAtB;IACA,OAAOxB,gBAAA,CAAMK,KAAN,CAAa,+DAA8DlB,OAAO,CAACuC,IAAR,CAAa,IAAb,CAAmB,EAA9F,CAAP;EACD;;AAnBgD;;;;AAsB5C,MAAMC,eAAN,CAAyC;EAAA;IAAA,8CACvC,4BADuC;IAAA,+CAEtC,MAFsC;IAAA,qDAGhC,qBAHgC;IAAA,iDAIpC,EAJoC;IAAA,+CAKtC,MALsC;IAAA,kDAMxB,EANwB;EAAA;;EAQlC,MAAN3C,MAAM,CAAC,CAAC4C,sBAAD,CAAD,EAAqC;IAC/C,OAAO5B,gBAAA,CAAMC,GAAN,CACJ,IAAG2B,sBAAuB,uGADtB,CAAP;EAGD;;AAZ6C"}
@@ -1,8 +1,13 @@
1
1
  import { CLIMain } from '@teambit/cli';
2
+ import { Workspace } from '@teambit/workspace';
3
+ import { SetDependenciesFlags } from './dependencies-cmd';
2
4
  export declare class DependenciesMain {
5
+ private workspace;
6
+ constructor(workspace: Workspace);
7
+ setDependency(componentPattern: string, pkg: string, options: SetDependenciesFlags): Promise<string[]>;
3
8
  static slots: never[];
4
9
  static dependencies: import("@teambit/harmony").Aspect[];
5
10
  static runtime: import("@teambit/harmony").RuntimeDefinition;
6
- static provider([cli]: [CLIMain]): Promise<DependenciesMain>;
11
+ static provider([cli, workspace]: [CLIMain, Workspace]): Promise<DependenciesMain>;
7
12
  }
8
13
  export default DependenciesMain;
@@ -6,6 +6,8 @@ require("core-js/modules/es.array.iterator.js");
6
6
 
7
7
  require("core-js/modules/es.promise.js");
8
8
 
9
+ require("core-js/modules/es.regexp.exec.js");
10
+
9
11
  Object.defineProperty(exports, "__esModule", {
10
12
  value: true
11
13
  });
@@ -31,6 +33,26 @@ function _cli() {
31
33
  return data;
32
34
  }
33
35
 
36
+ function _dependencyResolver() {
37
+ const data = require("@teambit/dependency-resolver");
38
+
39
+ _dependencyResolver = function () {
40
+ return data;
41
+ };
42
+
43
+ return data;
44
+ }
45
+
46
+ function _workspace() {
47
+ const data = _interopRequireDefault(require("@teambit/workspace"));
48
+
49
+ _workspace = function () {
50
+ return data;
51
+ };
52
+
53
+ return data;
54
+ }
55
+
34
56
  function _dependenciesCmd() {
35
57
  const data = require("./dependencies-cmd");
36
58
 
@@ -52,18 +74,52 @@ function _dependencies() {
52
74
  }
53
75
 
54
76
  class DependenciesMain {
55
- static async provider([cli]) {
77
+ constructor(workspace) {
78
+ this.workspace = workspace;
79
+ }
80
+
81
+ async setDependency(componentPattern, pkg, options) {
82
+ const compIds = await this.workspace.idsByPattern(componentPattern);
83
+
84
+ const getDepField = () => {
85
+ if (options.dev) return 'devDependencies';
86
+ if (options.peer) return 'peerDependencies';
87
+ return 'dependencies';
88
+ };
89
+
90
+ const packageSplit = pkg.split('@');
91
+
92
+ if (packageSplit.length !== 2) {
93
+ throw new Error(`invalid package "${pkg}" syntax, expected "package@version"`);
94
+ }
95
+
96
+ const config = {
97
+ policy: {
98
+ [getDepField()]: {
99
+ [packageSplit[0]]: packageSplit[1]
100
+ }
101
+ }
102
+ };
103
+ await Promise.all(compIds.map(async compId => {
104
+ await this.workspace.addSpecificComponentConfig(compId, _dependencyResolver().DependencyResolverAspect.id, config, true);
105
+ }));
106
+ await this.workspace.bitMap.write();
107
+ return compIds.map(compId => compId.toStringWithoutVersion());
108
+ }
109
+
110
+ static async provider([cli, workspace]) {
111
+ const depsMain = new DependenciesMain(workspace);
56
112
  const depsCmd = new (_dependenciesCmd().DependenciesCmd)();
57
- depsCmd.commands = [new (_dependenciesCmd().DependenciesGet)(), new (_dependenciesCmd().DependenciesDebug)()];
113
+ depsCmd.commands = [new (_dependenciesCmd().DependenciesGetCmd)(), new (_dependenciesCmd().DependenciesDebugCmd)(), new (_dependenciesCmd().DependenciesSetCmd)(depsMain)];
58
114
  cli.register(depsCmd);
59
- return new DependenciesMain();
115
+ return depsMain;
60
116
  }
61
117
 
62
118
  }
63
119
 
64
120
  exports.DependenciesMain = DependenciesMain;
65
121
  (0, _defineProperty2().default)(DependenciesMain, "slots", []);
66
- (0, _defineProperty2().default)(DependenciesMain, "dependencies", [_cli().CLIAspect]);
122
+ (0, _defineProperty2().default)(DependenciesMain, "dependencies", [_cli().CLIAspect, _workspace().default]);
67
123
  (0, _defineProperty2().default)(DependenciesMain, "runtime", _cli().MainRuntime);
68
124
 
69
125
  _dependencies().DependenciesAspect.addRuntime(DependenciesMain);
@@ -1 +1 @@
1
- {"version":3,"names":["DependenciesMain","provider","cli","depsCmd","DependenciesCmd","commands","DependenciesGet","DependenciesDebug","register","CLIAspect","MainRuntime","DependenciesAspect","addRuntime"],"sources":["dependencies.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { DependenciesCmd, DependenciesDebug, DependenciesGet } from './dependencies-cmd';\nimport { DependenciesAspect } from './dependencies.aspect';\n\nexport class DependenciesMain {\n static slots = [];\n static dependencies = [CLIAspect];\n\n static runtime = MainRuntime;\n\n static async provider([cli]: [CLIMain]) {\n const depsCmd = new DependenciesCmd();\n depsCmd.commands = [new DependenciesGet(), new DependenciesDebug()];\n cli.register(depsCmd);\n return new DependenciesMain();\n }\n}\n\nDependenciesAspect.addRuntime(DependenciesMain);\n\nexport default DependenciesMain;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,gBAAN,CAAuB;EAMP,aAARC,QAAQ,CAAC,CAACC,GAAD,CAAD,EAAmB;IACtC,MAAMC,OAAO,GAAG,KAAIC,kCAAJ,GAAhB;IACAD,OAAO,CAACE,QAAR,GAAmB,CAAC,KAAIC,kCAAJ,GAAD,EAAwB,KAAIC,oCAAJ,GAAxB,CAAnB;IACAL,GAAG,CAACM,QAAJ,CAAaL,OAAb;IACA,OAAO,IAAIH,gBAAJ,EAAP;EACD;;AAX2B;;;gCAAjBA,gB,WACI,E;gCADJA,gB,kBAEW,CAACS,gBAAD,C;gCAFXT,gB,aAIMU,kB;;AAUnBC,kCAAA,CAAmBC,UAAnB,CAA8BZ,gBAA9B;;eAEeA,gB"}
1
+ {"version":3,"names":["DependenciesMain","constructor","workspace","setDependency","componentPattern","pkg","options","compIds","idsByPattern","getDepField","dev","peer","packageSplit","split","length","Error","config","policy","Promise","all","map","compId","addSpecificComponentConfig","DependencyResolverAspect","id","bitMap","write","toStringWithoutVersion","provider","cli","depsMain","depsCmd","DependenciesCmd","commands","DependenciesGetCmd","DependenciesDebugCmd","DependenciesSetCmd","register","CLIAspect","WorkspaceAspect","MainRuntime","DependenciesAspect","addRuntime"],"sources":["dependencies.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { DependencyResolverAspect } from '@teambit/dependency-resolver';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport {\n DependenciesCmd,\n DependenciesDebugCmd,\n DependenciesGetCmd,\n DependenciesSetCmd,\n SetDependenciesFlags,\n} from './dependencies-cmd';\nimport { DependenciesAspect } from './dependencies.aspect';\n\nexport class DependenciesMain {\n constructor(private workspace: Workspace) {}\n\n async setDependency(componentPattern: string, pkg: string, options: SetDependenciesFlags): Promise<string[]> {\n const compIds = await this.workspace.idsByPattern(componentPattern);\n const getDepField = () => {\n if (options.dev) return 'devDependencies';\n if (options.peer) return 'peerDependencies';\n return 'dependencies';\n };\n const packageSplit = pkg.split('@');\n if (packageSplit.length !== 2) {\n throw new Error(`invalid package \"${pkg}\" syntax, expected \"package@version\"`);\n }\n const config = {\n policy: {\n [getDepField()]: {\n [packageSplit[0]]: packageSplit[1],\n },\n },\n };\n await Promise.all(\n compIds.map(async (compId) => {\n await this.workspace.addSpecificComponentConfig(compId, DependencyResolverAspect.id, config, true);\n })\n );\n\n await this.workspace.bitMap.write();\n\n return compIds.map((compId) => compId.toStringWithoutVersion());\n }\n\n static slots = [];\n static dependencies = [CLIAspect, WorkspaceAspect];\n\n static runtime = MainRuntime;\n\n static async provider([cli, workspace]: [CLIMain, Workspace]) {\n const depsMain = new DependenciesMain(workspace);\n const depsCmd = new DependenciesCmd();\n depsCmd.commands = [new DependenciesGetCmd(), new DependenciesDebugCmd(), new DependenciesSetCmd(depsMain)];\n cli.register(depsCmd);\n\n return depsMain;\n }\n}\n\nDependenciesAspect.addRuntime(DependenciesMain);\n\nexport default DependenciesMain;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,gBAAN,CAAuB;EAC5BC,WAAW,CAASC,SAAT,EAA+B;IAAA,KAAtBA,SAAsB,GAAtBA,SAAsB;EAAE;;EAEzB,MAAbC,aAAa,CAACC,gBAAD,EAA2BC,GAA3B,EAAwCC,OAAxC,EAA0F;IAC3G,MAAMC,OAAO,GAAG,MAAM,KAAKL,SAAL,CAAeM,YAAf,CAA4BJ,gBAA5B,CAAtB;;IACA,MAAMK,WAAW,GAAG,MAAM;MACxB,IAAIH,OAAO,CAACI,GAAZ,EAAiB,OAAO,iBAAP;MACjB,IAAIJ,OAAO,CAACK,IAAZ,EAAkB,OAAO,kBAAP;MAClB,OAAO,cAAP;IACD,CAJD;;IAKA,MAAMC,YAAY,GAAGP,GAAG,CA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A8B1C,gBAA9B;;eAEeA,gB"}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/dependencies",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
+ "homepage": "https://bit.dev/teambit/dependencies/dependencies",
4
5
  "main": "dist/index.js",
5
6
  "componentId": {
6
7
  "scope": "teambit.dependencies",
7
8
  "name": "dependencies",
8
- "version": "0.0.1"
9
+ "version": "0.0.2"
9
10
  },
10
11
  "dependencies": {
11
12
  "archy": "1.0.0",
@@ -13,7 +14,9 @@
13
14
  "@babel/runtime": "7.12.18",
14
15
  "core-js": "^3.0.0",
15
16
  "@teambit/harmony": "0.3.3",
16
- "@teambit/cli": "0.0.539"
17
+ "@teambit/cli": "0.0.540",
18
+ "@teambit/dependency-resolver": "0.0.809",
19
+ "@teambit/workspace": "0.0.809"
17
20
  },
18
21
  "devDependencies": {
19
22
  "@types/mocha": "9.1.0",
@@ -24,7 +27,7 @@
24
27
  "@types/node": "12.20.4"
25
28
  },
26
29
  "peerDependencies": {
27
- "@teambit/legacy": "1.0.322",
30
+ "@teambit/legacy": "1.0.323",
28
31
  "react-dom": "^16.8.0 || ^17.0.0",
29
32
  "react": "^16.8.0 || ^17.0.0"
30
33
  },