@teambit/formatter 1.0.939 → 1.0.940

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.
@@ -18,9 +18,9 @@ function _legacy() {
18
18
  };
19
19
  return data;
20
20
  }
21
- function _chalk() {
22
- const data = _interopRequireDefault(require("chalk"));
23
- _chalk = function () {
21
+ function _cli() {
22
+ const data = require("@teambit/cli");
23
+ _cli = function () {
24
24
  return data;
25
25
  };
26
26
  return data;
@@ -32,7 +32,6 @@ function _lodash() {
32
32
  };
33
33
  return data;
34
34
  }
35
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
36
35
  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; }
37
36
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
38
37
  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); }
@@ -69,16 +68,16 @@ supports check mode to verify formatting without making changes.`);
69
68
  code,
70
69
  componentsIdsToFormat
71
70
  } = await this.json([pattern], formatterOptions);
72
- const title = _chalk().default.bold(`formatting total of ${_chalk().default.cyan(componentsIdsToFormat.length.toString())} component(s) in workspace '${_chalk().default.cyan(this.componentHost.name)}`);
71
+ const title = (0, _cli().formatTitle)(`formatting total of ${componentsIdsToFormat.length} component(s) in workspace '${this.componentHost.name}'`);
73
72
  const componentsOutputs = this.getAllComponentsResultOutput(data.results, {
74
73
  check: formatterOptions.check
75
74
  });
76
75
  const {
77
76
  seconds
78
77
  } = duration;
79
- const summery = `formatted ${_chalk().default.cyan(componentsIdsToFormat.length.toString())} components in ${_chalk().default.cyan(seconds.toString())}.`;
78
+ const summary = (0, _cli().formatHint)(`formatted ${componentsIdsToFormat.length} components in ${seconds}s.`);
80
79
  return {
81
- data: `${title}\n\n${componentsOutputs}\n\n${summery}`,
80
+ data: (0, _cli().joinSections)([title, componentsOutputs, summary]),
82
81
  code
83
82
  };
84
83
  }
@@ -119,18 +118,15 @@ supports check mode to verify formatting without making changes.`);
119
118
  return allResults.join('\n\n');
120
119
  }
121
120
  getOneComponentResultOutput(componentResult, context) {
122
- const title = _chalk().default.bold.cyan(componentResult.componentId.toString({
121
+ const title = (0, _cli().formatTitle)(componentResult.componentId.toString({
123
122
  ignoreVersion: true
124
123
  }));
125
124
  const filesWithIssues = componentResult.results.filter(fileResult => fileResult.hasIssues);
126
125
  if (!filesWithIssues || !filesWithIssues.length) {
127
- return `${title}\n${_chalk().default.green('no issues found')}`;
126
+ return `${title}\n${(0, _cli().formatSuccessSummary)('no issues found')}`;
128
127
  }
129
- let subTitle = _chalk().default.green('the following files have been re-formatted:');
130
- if (context.check) {
131
- subTitle = _chalk().default.red('issues found in the following files:');
132
- }
133
- const files = filesWithIssues.map(this.getOneComponentFileResultOutput);
128
+ const subTitle = context.check ? `${_cli().errorSymbol} issues found in the following files:` : (0, _cli().formatSuccessSummary)('the following files have been re-formatted:');
129
+ const files = filesWithIssues.map(f => (0, _cli().formatItem)(this.getOneComponentFileResultOutput(f)));
134
130
  return `${title}\n${subTitle}\n${files.join('\n')}`;
135
131
  }
136
132
  getOneComponentFileResultOutput(fileResult) {
@@ -1 +1 @@
1
- {"version":3,"names":["_toolboxTime","data","require","_legacy","_chalk","_interopRequireDefault","_lodash","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","FormatCmd","constructor","formatter","componentHost","workspace","name","description","COMPONENT_PATTERN_HELP","report","pattern","formatterOptions","duration","code","componentsIdsToFormat","json","title","chalk","bold","cyan","length","toString","componentsOutputs","getAllComponentsResultOutput","results","check","seconds","summery","formatterCmdOptions","timer","Timer","create","start","componentsIds","getIdsToFormat","changed","componentsToFormat","getMany","opts","formatterResults","format","jsonFormatterResults","toJsonFormatResults","timerResponse","stop","statusCode","getStatusCode","map","comp","id","hasIssues","some","file","idsByPattern","getNewAndModifiedIds","listIds","componentsResult","context","allResults","getOneComponentResultOutput","join","componentResult","componentId","ignoreVersion","filesWithIssues","filter","fileResult","green","subTitle","red","files","getOneComponentFileResultOutput","filePath","exports","newResults","res","resultsWithoutComponent","result","component","compact","flatten","errors"],"sources":["format.cmd.ts"],"sourcesContent":["import type { TimerResponse } from '@teambit/toolbox.time.timer';\nimport { Timer } from '@teambit/toolbox.time.timer';\nimport { COMPONENT_PATTERN_HELP } from '@teambit/legacy.constants';\nimport type { Command, CommandOptions } from '@teambit/cli';\nimport type { ComponentFactory, ComponentID } from '@teambit/component';\nimport chalk from 'chalk';\nimport type { EnvsExecutionResult } from '@teambit/envs';\nimport type { Workspace } from '@teambit/workspace';\nimport { compact, flatten } from 'lodash';\nimport type { FormatterMain } from './formatter.main.runtime';\nimport type { ComponentFormatResult, FormatResults, FileFormatResult } from './formatter';\nimport type { FormatterOptions } from './formatter-context';\n\nexport type FormatCmdOptions = {\n changed?: boolean;\n json?: boolean;\n check?: boolean;\n};\n\ntype OutputContext = {\n check?: boolean;\n};\n\n/**\n * A type for result with componentId instead of the entire component, as when output to console, we don't want to print all the component\n */\nexport type JsonComponentFormatResult = Omit<ComponentFormatResult, 'component'> & {\n componentId: ComponentID;\n};\n\nexport type JsonFormatDataResults = Omit<FormatResults, 'results'> & { results: JsonComponentFormatResult[] };\n/**\n * A type for result with componentId instead of the entire component, as when output to console, we don't want to print all the component\n */\nexport type JsonFormatResults = {\n duration: TimerResponse;\n data: JsonFormatDataResults;\n code: number;\n componentsIdsToFormat: string[];\n};\n\nexport class FormatCmd implements Command {\n name = 'format [component-pattern]';\n description = 'auto-format component source code';\n extendedDescription = `formats component files using the formatter configured by each component's environment (Prettier, etc.).\nby default formats all components. use --changed to format only new and modified components.\nsupports check mode to verify formatting without making changes.`;\n arguments = [{ name: 'component-pattern', description: COMPONENT_PATTERN_HELP }];\n group = 'testing';\n helpUrl = 'reference/formatting/formatter-overview';\n options = [\n ['c', 'changed', 'format only new and modified components'],\n ['', 'check', 'will output a human-friendly message and a list of unformatted files, if any'],\n ['j', 'json', 'return the format results in json format'],\n ] as CommandOptions;\n\n constructor(\n private formatter: FormatterMain,\n private componentHost: ComponentFactory,\n private workspace: Workspace\n ) {}\n\n async report([pattern]: [string], formatterOptions: FormatCmdOptions) {\n const { duration, data, code, componentsIdsToFormat } = await this.json([pattern], formatterOptions);\n\n const title = chalk.bold(\n `formatting total of ${chalk.cyan(\n componentsIdsToFormat.length.toString()\n )} component(s) in workspace '${chalk.cyan(this.componentHost.name)}`\n );\n\n const componentsOutputs = this.getAllComponentsResultOutput(data.results, { check: formatterOptions.check });\n\n const { seconds } = duration;\n const summery = `formatted ${chalk.cyan(componentsIdsToFormat.length.toString())} components in ${chalk.cyan(\n seconds.toString()\n )}.`;\n\n return {\n data: `${title}\\n\\n${componentsOutputs}\\n\\n${summery}`,\n code,\n };\n }\n\n async json([pattern]: [string], formatterCmdOptions: FormatCmdOptions): Promise<JsonFormatResults> {\n const timer = Timer.create();\n timer.start();\n const componentsIds = await this.getIdsToFormat(pattern, formatterCmdOptions.changed);\n const componentsToFormat = await this.workspace.getMany(componentsIds);\n const opts: FormatterOptions = {};\n const formatterResults = formatterCmdOptions.check\n ? await this.formatter.check(componentsToFormat, opts)\n : await this.formatter.format(componentsToFormat, opts);\n const jsonFormatterResults = toJsonFormatResults(formatterResults);\n const timerResponse = timer.stop();\n const statusCode = this.getStatusCode(jsonFormatterResults, formatterCmdOptions.check);\n\n return {\n duration: timerResponse,\n data: jsonFormatterResults,\n code: statusCode,\n componentsIdsToFormat: componentsToFormat.map((comp) => comp.id.toString()),\n };\n }\n\n private getStatusCode(results: JsonFormatDataResults, check = false): number {\n if (!check) return 0;\n const hasIssues = results.results.some((comp) => comp.results.some((file) => file.hasIssues));\n if (hasIssues) return 1;\n return 0;\n }\n\n private async getIdsToFormat(pattern: string, changed = false): Promise<ComponentID[]> {\n if (pattern) {\n return this.workspace.idsByPattern(pattern);\n }\n if (changed) {\n return this.workspace.getNewAndModifiedIds();\n }\n return this.componentHost.listIds();\n }\n\n private getAllComponentsResultOutput(componentsResult: JsonComponentFormatResult[], context: OutputContext) {\n const allResults = componentsResult.map((comp) => this.getOneComponentResultOutput(comp, context));\n return allResults.join('\\n\\n');\n }\n\n private getOneComponentResultOutput(componentResult: JsonComponentFormatResult, context: OutputContext) {\n const title = chalk.bold.cyan(componentResult.componentId.toString({ ignoreVersion: true }));\n const filesWithIssues = componentResult.results.filter((fileResult) => fileResult.hasIssues);\n if (!filesWithIssues || !filesWithIssues.length) {\n return `${title}\\n${chalk.green('no issues found')}`;\n }\n let subTitle = chalk.green('the following files have been re-formatted:');\n if (context.check) {\n subTitle = chalk.red('issues found in the following files:');\n }\n const files = filesWithIssues.map(this.getOneComponentFileResultOutput);\n return `${title}\\n${subTitle}\\n${files.join('\\n')}`;\n }\n\n private getOneComponentFileResultOutput(fileResult: FileFormatResult) {\n return fileResult.filePath;\n }\n}\n\nfunction toJsonFormatResults(results: EnvsExecutionResult<FormatResults>): JsonFormatDataResults {\n const newResults = results.results.map((res) => {\n const resultsWithoutComponent = res.data?.results.map((result) => {\n return {\n componentId: result.component.id,\n results: result.results,\n };\n });\n return compact(resultsWithoutComponent);\n });\n return {\n results: compact(flatten(newResults)),\n errors: results?.errors,\n };\n}\n"],"mappings":";;;;;;AACA,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;EAAA;EAAA,OAAAA,IAAA;AAA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e,IAAI,CAACA,eAAe,CAAC5C,MAAM,EAAE;MAC/C,OAAO,GAAGJ,KAAK,KAAKC,gBAAK,CAACkD,KAAK,CAAC,iBAAiB,CAAC,EAAE;IACtD;IACA,IAAIC,QAAQ,GAAGnD,gBAAK,CAACkD,KAAK,CAAC,6CAA6C,CAAC;IACzE,IAAIV,OAAO,CAAChC,KAAK,EAAE;MACjB2C,QAAQ,GAAGnD,gBAAK,CAACoD,GAAG,CAAC,sCAAsC,CAAC;IAC9D;IACA,MAAMC,KAAK,GAAGN,eAAe,CAACjB,GAAG,CAAC,IAAI,CAACwB,+BAA+B,CAAC;IACvE,OAAO,GAAGvD,KAAK,KAAKoD,QAAQ,KAAKE,KAAK,CAACV,IAAI,CAAC,IAAI,CAAC,EAAE;EACrD;EAEQW,+BAA+BA,CAACL,UAA4B,EAAE;IACpE,OAAOA,UAAU,CAACM,QAAQ;EAC5B;AACF;AAACC,OAAA,CAAAxE,SAAA,GAAAA,SAAA;AAED,SAASyC,mBAAmBA,CAAClB,OAA2C,EAAyB;EAC/F,MAAMkD,UAAU,GAAGlD,OAAO,CAACA,OAAO,CAACuB,GAAG,CAAE4B,GAAG,IAAK;IAC9C,MAAMC,uBAAuB,GAAGD,GAAG,CAACrG,IAAI,EAAEkD,OAAO,CAACuB,GAAG,CAAE8B,MAAM,IAAK;MAChE,OAAO;QACLf,WAAW,EAAEe,MAAM,CAACC,SAAS,CAAC7B,EAAE;QAChCzB,OAAO,EAAEqD,MAAM,CAACrD;MAClB,CAAC;IACH,CAAC,CAAC;IACF,OAAO,IAAAuD,iBAAO,EAACH,uBAAuB,CAAC;EACzC,CAAC,CAAC;EACF,OAAO;IACLpD,OAAO,EAAE,IAAAuD,iBAAO,EAAC,IAAAC,iBAAO,EAACN,UAAU,CAAC,CAAC;IACrCO,MAAM,EAAEzD,OAAO,EAAEyD;EACnB,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["_toolboxTime","data","require","_legacy","_cli","_lodash","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","FormatCmd","constructor","formatter","componentHost","workspace","name","description","COMPONENT_PATTERN_HELP","report","pattern","formatterOptions","duration","code","componentsIdsToFormat","json","title","formatTitle","length","componentsOutputs","getAllComponentsResultOutput","results","check","seconds","summary","formatHint","joinSections","formatterCmdOptions","timer","Timer","create","start","componentsIds","getIdsToFormat","changed","componentsToFormat","getMany","opts","formatterResults","format","jsonFormatterResults","toJsonFormatResults","timerResponse","stop","statusCode","getStatusCode","map","comp","id","toString","hasIssues","some","file","idsByPattern","getNewAndModifiedIds","listIds","componentsResult","context","allResults","getOneComponentResultOutput","join","componentResult","componentId","ignoreVersion","filesWithIssues","filter","fileResult","formatSuccessSummary","subTitle","errorSymbol","files","f","formatItem","getOneComponentFileResultOutput","filePath","exports","newResults","res","resultsWithoutComponent","result","component","compact","flatten","errors"],"sources":["format.cmd.ts"],"sourcesContent":["import type { TimerResponse } from '@teambit/toolbox.time.timer';\nimport { Timer } from '@teambit/toolbox.time.timer';\nimport { COMPONENT_PATTERN_HELP } from '@teambit/legacy.constants';\nimport type { Command, CommandOptions } from '@teambit/cli';\nimport { formatTitle, formatItem, formatSuccessSummary, formatHint, errorSymbol, joinSections } from '@teambit/cli';\nimport type { ComponentFactory, ComponentID } from '@teambit/component';\nimport type { EnvsExecutionResult } from '@teambit/envs';\nimport type { Workspace } from '@teambit/workspace';\nimport { compact, flatten } from 'lodash';\nimport type { FormatterMain } from './formatter.main.runtime';\nimport type { ComponentFormatResult, FormatResults, FileFormatResult } from './formatter';\nimport type { FormatterOptions } from './formatter-context';\n\nexport type FormatCmdOptions = {\n changed?: boolean;\n json?: boolean;\n check?: boolean;\n};\n\ntype OutputContext = {\n check?: boolean;\n};\n\n/**\n * A type for result with componentId instead of the entire component, as when output to console, we don't want to print all the component\n */\nexport type JsonComponentFormatResult = Omit<ComponentFormatResult, 'component'> & {\n componentId: ComponentID;\n};\n\nexport type JsonFormatDataResults = Omit<FormatResults, 'results'> & { results: JsonComponentFormatResult[] };\n/**\n * A type for result with componentId instead of the entire component, as when output to console, we don't want to print all the component\n */\nexport type JsonFormatResults = {\n duration: TimerResponse;\n data: JsonFormatDataResults;\n code: number;\n componentsIdsToFormat: string[];\n};\n\nexport class FormatCmd implements Command {\n name = 'format [component-pattern]';\n description = 'auto-format component source code';\n extendedDescription = `formats component files using the formatter configured by each component's environment (Prettier, etc.).\nby default formats all components. use --changed to format only new and modified components.\nsupports check mode to verify formatting without making changes.`;\n arguments = [{ name: 'component-pattern', description: COMPONENT_PATTERN_HELP }];\n group = 'testing';\n helpUrl = 'reference/formatting/formatter-overview';\n options = [\n ['c', 'changed', 'format only new and modified components'],\n ['', 'check', 'will output a human-friendly message and a list of unformatted files, if any'],\n ['j', 'json', 'return the format results in json format'],\n ] as CommandOptions;\n\n constructor(\n private formatter: FormatterMain,\n private componentHost: ComponentFactory,\n private workspace: Workspace\n ) {}\n\n async report([pattern]: [string], formatterOptions: FormatCmdOptions) {\n const { duration, data, code, componentsIdsToFormat } = await this.json([pattern], formatterOptions);\n\n const title = formatTitle(\n `formatting total of ${componentsIdsToFormat.length} component(s) in workspace '${this.componentHost.name}'`\n );\n\n const componentsOutputs = this.getAllComponentsResultOutput(data.results, { check: formatterOptions.check });\n\n const { seconds } = duration;\n const summary = formatHint(`formatted ${componentsIdsToFormat.length} components in ${seconds}s.`);\n\n return {\n data: joinSections([title, componentsOutputs, summary]),\n code,\n };\n }\n\n async json([pattern]: [string], formatterCmdOptions: FormatCmdOptions): Promise<JsonFormatResults> {\n const timer = Timer.create();\n timer.start();\n const componentsIds = await this.getIdsToFormat(pattern, formatterCmdOptions.changed);\n const componentsToFormat = await this.workspace.getMany(componentsIds);\n const opts: FormatterOptions = {};\n const formatterResults = formatterCmdOptions.check\n ? await this.formatter.check(componentsToFormat, opts)\n : await this.formatter.format(componentsToFormat, opts);\n const jsonFormatterResults = toJsonFormatResults(formatterResults);\n const timerResponse = timer.stop();\n const statusCode = this.getStatusCode(jsonFormatterResults, formatterCmdOptions.check);\n\n return {\n duration: timerResponse,\n data: jsonFormatterResults,\n code: statusCode,\n componentsIdsToFormat: componentsToFormat.map((comp) => comp.id.toString()),\n };\n }\n\n private getStatusCode(results: JsonFormatDataResults, check = false): number {\n if (!check) return 0;\n const hasIssues = results.results.some((comp) => comp.results.some((file) => file.hasIssues));\n if (hasIssues) return 1;\n return 0;\n }\n\n private async getIdsToFormat(pattern: string, changed = false): Promise<ComponentID[]> {\n if (pattern) {\n return this.workspace.idsByPattern(pattern);\n }\n if (changed) {\n return this.workspace.getNewAndModifiedIds();\n }\n return this.componentHost.listIds();\n }\n\n private getAllComponentsResultOutput(componentsResult: JsonComponentFormatResult[], context: OutputContext) {\n const allResults = componentsResult.map((comp) => this.getOneComponentResultOutput(comp, context));\n return allResults.join('\\n\\n');\n }\n\n private getOneComponentResultOutput(componentResult: JsonComponentFormatResult, context: OutputContext) {\n const title = formatTitle(componentResult.componentId.toString({ ignoreVersion: true }));\n const filesWithIssues = componentResult.results.filter((fileResult) => fileResult.hasIssues);\n if (!filesWithIssues || !filesWithIssues.length) {\n return `${title}\\n${formatSuccessSummary('no issues found')}`;\n }\n const subTitle = context.check\n ? `${errorSymbol} issues found in the following files:`\n : formatSuccessSummary('the following files have been re-formatted:');\n const files = filesWithIssues.map((f) => formatItem(this.getOneComponentFileResultOutput(f)));\n return `${title}\\n${subTitle}\\n${files.join('\\n')}`;\n }\n\n private getOneComponentFileResultOutput(fileResult: FileFormatResult) {\n return fileResult.filePath;\n }\n}\n\nfunction toJsonFormatResults(results: EnvsExecutionResult<FormatResults>): JsonFormatDataResults {\n const newResults = results.results.map((res) => {\n const resultsWithoutComponent = res.data?.results.map((result) => {\n return {\n componentId: result.component.id,\n results: result.results,\n };\n });\n return compact(resultsWithoutComponent);\n });\n return {\n results: compact(flatten(newResults)),\n errors: results?.errors,\n };\n}\n"],"mappings":";;;;;;AACA,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GAAGF,KAAK,KAAK,IAAAmD,2BAAoB,EAAC,iBAAiB,CAAC,EAAE;IAC/D;IACA,MAAMC,QAAQ,GAAGX,OAAO,CAACnC,KAAK,GAC1B,GAAG+C,kBAAW,uCAAuC,GACrD,IAAAF,2BAAoB,EAAC,6CAA6C,CAAC;IACvE,MAAMG,KAAK,GAAGN,eAAe,CAAClB,GAAG,CAAEyB,CAAC,IAAK,IAAAC,iBAAU,EAAC,IAAI,CAACC,+BAA+B,CAACF,CAAC,CAAC,CAAC,CAAC;IAC7F,OAAO,GAAGvD,KAAK,KAAKoD,QAAQ,KAAKE,KAAK,CAACV,IAAI,CAAC,IAAI,CAAC,EAAE;EACrD;EAEQa,+BAA+BA,CAACP,UAA4B,EAAE;IACpE,OAAOA,UAAU,CAACQ,QAAQ;EAC5B;AACF;AAACC,OAAA,CAAA1E,SAAA,GAAAA,SAAA;AAED,SAASwC,mBAAmBA,CAACpB,OAA2C,EAAyB;EAC/F,MAAMuD,UAAU,GAAGvD,OAAO,CAACA,OAAO,CAACyB,GAAG,CAAE+B,GAAG,IAAK;IAC9C,MAAMC,uBAAuB,GAAGD,GAAG,CAACpG,IAAI,EAAE4C,OAAO,CAACyB,GAAG,CAAEiC,MAAM,IAAK;MAChE,OAAO;QACLjB,WAAW,EAAEiB,MAAM,CAACC,SAAS,CAAChC,EAAE;QAChC3B,OAAO,EAAE0D,MAAM,CAAC1D;MAClB,CAAC;IACH,CAAC,CAAC;IACF,OAAO,IAAA4D,iBAAO,EAACH,uBAAuB,CAAC;EACzC,CAAC,CAAC;EACF,OAAO;IACLzD,OAAO,EAAE,IAAA4D,iBAAO,EAAC,IAAAC,iBAAO,EAACN,UAAU,CAAC,CAAC;IACrCO,MAAM,EAAE9D,OAAO,EAAE8D;EACnB,CAAC;AACH","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.defender_formatter@1.0.939/dist/formatter.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.defender_formatter@1.0.939/dist/formatter.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.defender_formatter@1.0.940/dist/formatter.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.defender_formatter@1.0.940/dist/formatter.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "@teambit/formatter",
3
- "version": "1.0.939",
3
+ "version": "1.0.940",
4
4
  "homepage": "https://bit.cloud/teambit/defender/formatter",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.defender",
8
8
  "name": "formatter",
9
- "version": "1.0.939"
9
+ "version": "1.0.940"
10
10
  },
11
11
  "dependencies": {
12
- "chalk": "4.1.2",
13
12
  "lodash": "4.17.21",
14
13
  "graphql-tag": "2.12.1",
14
+ "chalk": "4.1.2",
15
15
  "cli-highlight": "2.1.9",
16
- "@teambit/cli": "0.0.1314",
17
16
  "@teambit/legacy.constants": "0.0.26",
18
17
  "@teambit/toolbox.time.timer": "0.0.13",
19
18
  "@teambit/harmony": "0.4.7",
20
- "@teambit/logger": "0.0.1407",
21
- "@teambit/component": "1.0.939",
22
- "@teambit/envs": "1.0.939",
23
- "@teambit/workspace": "1.0.939",
24
- "@teambit/builder": "1.0.939",
25
- "@teambit/snapping": "1.0.939"
19
+ "@teambit/cli": "0.0.1315",
20
+ "@teambit/component": "1.0.940",
21
+ "@teambit/envs": "1.0.940",
22
+ "@teambit/workspace": "1.0.940",
23
+ "@teambit/builder": "1.0.940",
24
+ "@teambit/logger": "0.0.1408",
25
+ "@teambit/snapping": "1.0.940"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/lodash": "4.14.165",