@teambit/formatter 1.0.106 → 1.0.108

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.
@@ -4,7 +4,7 @@ import { ComponentFactory, ComponentID } from '@teambit/component';
4
4
  import { Workspace } from '@teambit/workspace';
5
5
  import { FormatterMain } from './formatter.main.runtime';
6
6
  import { ComponentFormatResult, FormatResults } from './formatter';
7
- export declare type FormatCmdOptions = {
7
+ export type FormatCmdOptions = {
8
8
  changed?: boolean;
9
9
  json?: boolean;
10
10
  check?: boolean;
@@ -12,16 +12,16 @@ export declare type FormatCmdOptions = {
12
12
  /**
13
13
  * 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
14
14
  */
15
- export declare type JsonComponentFormatResult = Omit<ComponentFormatResult, 'component'> & {
15
+ export type JsonComponentFormatResult = Omit<ComponentFormatResult, 'component'> & {
16
16
  componentId: ComponentID;
17
17
  };
18
- export declare type JsonFormatDataResults = Omit<FormatResults, 'results'> & {
18
+ export type JsonFormatDataResults = Omit<FormatResults, 'results'> & {
19
19
  results: JsonComponentFormatResult[];
20
20
  };
21
21
  /**
22
22
  * 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
23
23
  */
24
- export declare type JsonFormatResults = {
24
+ export type JsonFormatResults = {
25
25
  duration: TimerResponse;
26
26
  data: JsonFormatDataResults;
27
27
  code: number;
@@ -126,8 +126,7 @@ class FormatCmd {
126
126
  exports.FormatCmd = FormatCmd;
127
127
  function toJsonFormatResults(results) {
128
128
  const newResults = results.results.map(res => {
129
- var _res$data;
130
- const resultsWithoutComponent = (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results.map(result => {
129
+ const resultsWithoutComponent = res.data?.results.map(result => {
131
130
  return {
132
131
  componentId: result.component.id,
133
132
  results: result.results
@@ -137,7 +136,7 @@ function toJsonFormatResults(results) {
137
136
  });
138
137
  return {
139
138
  results: (0, _lodash().compact)((0, _lodash().flatten)(newResults)),
140
- errors: results === null || results === void 0 ? void 0 : results.errors
139
+ errors: results?.errors
141
140
  };
142
141
  }
143
142
 
@@ -1 +1 @@
1
- {"version":3,"names":["_timer","data","require","_chalk","_interopRequireDefault","_lodash","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","FormatCmd","constructor","formatter","componentHost","workspace","report","components","formatterOptions","duration","code","componentsIdsToFormat","json","title","chalk","bold","cyan","length","toString","name","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","resolveMultipleComponentIds","getNewAndModifiedIds","listIds","componentsResult","context","allResults","getOneComponentResultOutput","join","componentResult","componentId","ignoreVersion","filesWithIssues","filter","fileResult","green","subTitle","red","files","getOneComponentFileResultOutput","filePath","exports","newResults","res","_res$data","resultsWithoutComponent","result","component","compact","flatten","errors"],"sources":["format.cmd.ts"],"sourcesContent":["import { TimerResponse, Timer } from '@teambit/legacy/dist/toolbox/timer';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { ComponentFactory, ComponentID } from '@teambit/component';\nimport chalk from 'chalk';\nimport { EnvsExecutionResult } from '@teambit/envs';\nimport { Workspace } from '@teambit/workspace';\nimport { compact, flatten } from 'lodash';\nimport { FormatterMain } from './formatter.main.runtime';\nimport { ComponentFormatResult, FormatResults, FileFormatResult } from './formatter';\nimport { 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...]';\n description = 'format components in the development workspace';\n group = 'development';\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([components = []]: [string[]], formatterOptions: FormatCmdOptions) {\n const { duration, data, code, componentsIdsToFormat } = await this.json([components], 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([components = []]: [string[]], formatterCmdOptions: FormatCmdOptions): Promise<JsonFormatResults> {\n const timer = Timer.create();\n timer.start();\n const componentsIds = await this.getIdsToFormat(components, 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(components: string[], changed = false): Promise<ComponentID[]> {\n if (components.length) {\n return this.workspace.resolveMultipleComponentIds(components);\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":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;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{"version":3,"names":["_timer","data","require","_chalk","_interopRequireDefault","_lodash","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","FormatCmd","constructor","formatter","componentHost","workspace","report","components","formatterOptions","duration","code","componentsIdsToFormat","json","title","chalk","bold","cyan","length","toString","name","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","resolveMultipleComponentIds","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 { TimerResponse, Timer } from '@teambit/legacy/dist/toolbox/timer';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { ComponentFactory, ComponentID } from '@teambit/component';\nimport chalk from 'chalk';\nimport { EnvsExecutionResult } from '@teambit/envs';\nimport { Workspace } from '@teambit/workspace';\nimport { compact, flatten } from 'lodash';\nimport { FormatterMain } from './formatter.main.runtime';\nimport { ComponentFormatResult, FormatResults, FileFormatResult } from './formatter';\nimport { 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...]';\n description = 'format components in the development workspace';\n group = 'development';\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([components = []]: [string[]], formatterOptions: FormatCmdOptions) {\n const { duration, data, code, componentsIdsToFormat } = await this.json([components], 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([components = []]: [string[]], formatterCmdOptions: FormatCmdOptions): Promise<JsonFormatResults> {\n const timer = Timer.create();\n timer.start();\n const componentsIds = await this.getIdsToFormat(components, 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(components: string[], changed = false): Promise<ComponentID[]> {\n if (components.length) {\n return this.workspace.resolveMultipleComponentIds(components);\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":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CA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,EAAC;IACtD;IACA,IAAIC,QAAQ,GAAGpD,gBAAK,CAACmD,KAAK,CAAC,6CAA6C,CAAC;IACzE,IAAIV,OAAO,CAAChC,KAAK,EAAE;MACjB2C,QAAQ,GAAGpD,gBAAK,CAACqD,GAAG,CAAC,sCAAsC,CAAC;IAC9D;IACA,MAAMC,KAAK,GAAGN,eAAe,CAACjB,GAAG,CAAC,IAAI,CAACwB,+BAA+B,CAAC;IACvE,OAAQ,GAAExD,KAAM,KAAIqD,QAAS,KAAIE,KAAK,CAACV,IAAI,CAAC,IAAI,CAAE,EAAC;EACrD;EAEQW,+BAA+BA,CAACL,UAA4B,EAAE;IACpE,OAAOA,UAAU,CAACM,QAAQ;EAC5B;AACF;AAACC,OAAA,CAAAtE,SAAA,GAAAA,SAAA;AAED,SAASuC,mBAAmBA,CAAClB,OAA2C,EAAyB;EAC/F,MAAMkD,UAAU,GAAGlD,OAAO,CAACA,OAAO,CAACuB,GAAG,CAAE4B,GAAG,IAAK;IAC9C,MAAMC,uBAAuB,GAAGD,GAAG,CAACpG,IAAI,EAAEiD,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"}
@@ -1,5 +1,5 @@
1
1
  import { ExecutionContext } from '@teambit/envs';
2
- export declare type FormatterOptions = {
2
+ export type FormatterOptions = {
3
3
  check?: boolean;
4
4
  };
5
5
  export interface FormatterContext extends ExecutionContext, FormatterOptions {
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const Logo: () => React.JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const Logo: () => JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { Component } from '@teambit/component';
2
2
  import { FormatterContext } from './formatter-context';
3
- export declare type ComponentFormatResult = {
3
+ export type ComponentFormatResult = {
4
4
  /**
5
5
  * the formatted component.
6
6
  */
@@ -10,7 +10,7 @@ export declare type ComponentFormatResult = {
10
10
  */
11
11
  results: FileFormatResult[];
12
12
  };
13
- export declare type FileFormatResult = {
13
+ export type FileFormatResult = {
14
14
  /**
15
15
  * path of the formatted file.
16
16
  */
@@ -24,7 +24,7 @@ export declare type FileFormatResult = {
24
24
  */
25
25
  newContent?: string;
26
26
  };
27
- export declare type FormatResults = {
27
+ export type FormatResults = {
28
28
  results: ComponentFormatResult[];
29
29
  errors: Error[];
30
30
  };
@@ -7,7 +7,7 @@ import { FormatterService } from './formatter.service';
7
7
  import { FormatTask } from './format.task';
8
8
  import { FormatterOptions } from './formatter-context';
9
9
  import { Formatter } from './formatter';
10
- export declare type FormatterConfig = {};
10
+ export type FormatterConfig = {};
11
11
  export declare class FormatterMain {
12
12
  private envs;
13
13
  private formatterService;
@@ -1,9 +1,9 @@
1
- import React from 'react';
1
+ /// <reference types="react" />
2
2
  import { EnvService, ExecutionContext, EnvDefinition, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';
3
3
  import { Formatter, FormatResults } from './formatter';
4
4
  import { FormatterOptions } from './formatter-context';
5
5
  import { FormatterConfig } from './formatter.main.runtime';
6
- declare type FormatterTransformationMap = ServiceTransformationMap & {
6
+ type FormatterTransformationMap = ServiceTransformationMap & {
7
7
  getFormatter: () => Formatter;
8
8
  };
9
9
  export declare class FormatterService implements EnvService<FormatResults> {
@@ -14,7 +14,7 @@ export declare class FormatterService implements EnvService<FormatResults> {
14
14
  getFormatter(context: ExecutionContext, options: FormatterOptions): Formatter;
15
15
  private optionsWithDefaults;
16
16
  private mergeContext;
17
- render(env: EnvDefinition): React.JSX.Element;
17
+ render(env: EnvDefinition): JSX.Element;
18
18
  transform(env: Env, context: EnvContext): FormatterTransformationMap | undefined;
19
19
  getDescriptor(env: EnvDefinition): {
20
20
  id: any;
@@ -22,6 +22,6 @@ export declare class FormatterService implements EnvService<FormatResults> {
22
22
  config: any;
23
23
  version: any;
24
24
  displayName: any;
25
- } | undefined;
25
+ };
26
26
  }
27
27
  export {};
@@ -64,19 +64,19 @@ class FormatterService {
64
64
  render(env) {
65
65
  const descriptor = this.getDescriptor(env);
66
66
  return /*#__PURE__*/_react().default.createElement(_ink().Text, {
67
- key: descriptor === null || descriptor === void 0 ? void 0 : descriptor.id
67
+ key: descriptor?.id
68
68
  }, /*#__PURE__*/_react().default.createElement(_ink().Text, {
69
69
  color: "cyan"
70
- }, "configured formatter: "), /*#__PURE__*/_react().default.createElement(_ink().Text, null, descriptor === null || descriptor === void 0 ? void 0 : descriptor.id, " (", descriptor === null || descriptor === void 0 ? void 0 : descriptor.displayName, " @ ", descriptor === null || descriptor === void 0 ? void 0 : descriptor.version, ")"), /*#__PURE__*/_react().default.createElement(_ink().Newline, null), /*#__PURE__*/_react().default.createElement(_ink().Text, {
70
+ }, "configured formatter: "), /*#__PURE__*/_react().default.createElement(_ink().Text, null, descriptor?.id, " (", descriptor?.displayName, " @ ", descriptor?.version, ")"), /*#__PURE__*/_react().default.createElement(_ink().Newline, null), /*#__PURE__*/_react().default.createElement(_ink().Text, {
71
71
  color: "cyan"
72
- }, "formatter config:"), /*#__PURE__*/_react().default.createElement(_ink().Newline, null), /*#__PURE__*/_react().default.createElement(_ink().Text, null, (descriptor === null || descriptor === void 0 ? void 0 : descriptor.config) && (0, _cliHighlight().default)(descriptor === null || descriptor === void 0 ? void 0 : descriptor.config, {
72
+ }, "formatter config:"), /*#__PURE__*/_react().default.createElement(_ink().Newline, null), /*#__PURE__*/_react().default.createElement(_ink().Text, null, descriptor?.config && (0, _cliHighlight().default)(descriptor?.config, {
73
73
  language: 'javascript',
74
74
  ignoreIllegals: true
75
75
  })), /*#__PURE__*/_react().default.createElement(_ink().Newline, null));
76
76
  }
77
77
  transform(env, context) {
78
78
  // Old env
79
- if (!(env !== null && env !== void 0 && env.formatter)) return undefined;
79
+ if (!env?.formatter) return undefined;
80
80
  return {
81
81
  getFormatter: () => env.formatter()(context)
82
82
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_lodash","data","require","_react","_interopRequireDefault","_ink","_cliHighlight","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","FormatterService","constructor","formatterConfig","run","context","options","mergedOpts","optionsWithDefaults","formatterContext","mergeContext","formatter","getFormatter","results","check","format","env","defaults","assign","render","descriptor","getDescriptor","createElement","Text","id","color","displayName","version","Newline","config","highlight","language","ignoreIllegals","transform","undefined","icon","displayConfig","exports"],"sources":["formatter.service.tsx"],"sourcesContent":["import { defaults } from 'lodash';\nimport React from 'react';\nimport { EnvService, ExecutionContext, EnvDefinition, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport { Text, Newline } from 'ink';\nimport highlight from 'cli-highlight';\nimport { Formatter, FormatResults } from './formatter';\nimport { FormatterContext, FormatterOptions } from './formatter-context';\nimport { FormatterConfig } from './formatter.main.runtime';\n\ntype FormatterTransformationMap = ServiceTransformationMap & {\n getFormatter: () => Formatter;\n};\nexport class FormatterService implements EnvService<FormatResults> {\n name = 'formatter';\n\n constructor(private formatterConfig: FormatterConfig) {}\n\n async run(context: ExecutionContext, options: FormatterOptions): Promise<FormatResults> {\n const mergedOpts = this.optionsWithDefaults(options);\n const formatterContext: FormatterContext = this.mergeContext(mergedOpts, context);\n const formatter = this.getFormatter(context, options);\n\n const results = options.check ? await formatter.check(formatterContext) : await formatter.format(formatterContext);\n return results;\n }\n\n getFormatter(context: ExecutionContext, options: FormatterOptions): Formatter {\n const mergedOpts = this.optionsWithDefaults(options);\n const formatterContext: FormatterContext = this.mergeContext(mergedOpts, context);\n const formatter: Formatter = context.env.getFormatter(formatterContext);\n\n return formatter;\n }\n\n private optionsWithDefaults(options: FormatterOptions): FormatterOptions {\n return defaults(options, this.formatterConfig);\n }\n\n private mergeContext(options: FormatterOptions, context?: ExecutionContext): FormatterContext {\n const formatterContext: FormatterContext = Object.assign({}, options, context);\n return formatterContext;\n }\n\n render(env: EnvDefinition) {\n const descriptor = this.getDescriptor(env);\n\n return (\n <Text key={descriptor?.id}>\n <Text color=\"cyan\">configured formatter: </Text>\n <Text>\n {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})\n </Text>\n <Newline />\n <Text color=\"cyan\">formatter config:</Text>\n <Newline />\n <Text>\n {descriptor?.config && highlight(descriptor?.config, { language: 'javascript', ignoreIllegals: true })}\n </Text>\n <Newline />\n </Text>\n );\n }\n\n transform(env: Env, context: EnvContext): FormatterTransformationMap | undefined {\n // Old env\n if (!env?.formatter) return undefined;\n return {\n getFormatter: () => env.formatter()(context),\n };\n }\n\n getDescriptor(env: EnvDefinition) {\n if (!env.env.getFormatter) return undefined;\n const mergedOpts = this.optionsWithDefaults({});\n const formatterContext = this.mergeContext(mergedOpts);\n const formatter = env.env.getFormatter(formatterContext);\n\n return {\n id: formatter.id,\n icon: formatter.icon,\n config: formatter.displayConfig ? formatter.displayConfig() : undefined,\n version: formatter.version ? formatter.version() : '?',\n displayName: formatter.displayName ? formatter.displayName : '?',\n };\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA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,GAAG,CAACL,SAAS,CAAC,CAAC,CAACN,OAAO;IAC7C,CAAC;EACH;EAEAgB,aAAaA,CAACL,GAAkB,EAAE;IAChC,IAAI,CAACA,GAAG,CAACA,GAAG,CAACJ,YAAY,EAAE,OAAOsB,SAAS;IAC3C,MAAM3B,UAAU,GAAG,IAAI,CAACC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAMC,gBAAgB,GAAG,IAAI,CAACC,YAAY,CAACH,UAAU,CAAC;IACtD,MAAMI,SAAS,GAAGK,GAAG,CAACA,GAAG,CAACJ,YAAY,CAACH,gBAAgB,CAAC;IAExD,OAAO;MACLe,EAAE,EAAEb,SAAS,CAACa,EAAE;MAChBW,IAAI,EAAExB,SAAS,CAACwB,IAAI;MACpBN,MAAM,EAAElB,SAAS,CAACyB,aAAa,GAAGzB,SAAS,CAACyB,aAAa,CAAC,CAAC,GAAGF,SAAS;MACvEP,OAAO,EAAEhB,SAAS,CAACgB,OAAO,GAAGhB,SAAS,CAACgB,OAAO,CAAC,CAAC,GAAG,GAAG;MACtDD,WAAW,EAAEf,SAAS,CAACe,WAAW,GAAGf,SAAS,CAACe,WAAW,GAAG;IAC/D,CAAC;EACH;AACF;AAACW,OAAA,CAAApC,gBAAA,GAAAA,gBAAA"}
1
+ {"version":3,"names":["_lodash","data","require","_react","_interopRequireDefault","_ink","_cliHighlight","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","FormatterService","constructor","formatterConfig","run","context","options","mergedOpts","optionsWithDefaults","formatterContext","mergeContext","formatter","getFormatter","results","check","format","env","defaults","assign","render","descriptor","getDescriptor","createElement","Text","id","color","displayName","version","Newline","config","highlight","language","ignoreIllegals","transform","undefined","icon","displayConfig","exports"],"sources":["formatter.service.tsx"],"sourcesContent":["import { defaults } from 'lodash';\nimport React from 'react';\nimport { EnvService, ExecutionContext, EnvDefinition, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport { Text, Newline } from 'ink';\nimport highlight from 'cli-highlight';\nimport { Formatter, FormatResults } from './formatter';\nimport { FormatterContext, FormatterOptions } from './formatter-context';\nimport { FormatterConfig } from './formatter.main.runtime';\n\ntype FormatterTransformationMap = ServiceTransformationMap & {\n getFormatter: () => Formatter;\n};\nexport class FormatterService implements EnvService<FormatResults> {\n name = 'formatter';\n\n constructor(private formatterConfig: FormatterConfig) {}\n\n async run(context: ExecutionContext, options: FormatterOptions): Promise<FormatResults> {\n const mergedOpts = this.optionsWithDefaults(options);\n const formatterContext: FormatterContext = this.mergeContext(mergedOpts, context);\n const formatter = this.getFormatter(context, options);\n\n const results = options.check ? await formatter.check(formatterContext) : await formatter.format(formatterContext);\n return results;\n }\n\n getFormatter(context: ExecutionContext, options: FormatterOptions): Formatter {\n const mergedOpts = this.optionsWithDefaults(options);\n const formatterContext: FormatterContext = this.mergeContext(mergedOpts, context);\n const formatter: Formatter = context.env.getFormatter(formatterContext);\n\n return formatter;\n }\n\n private optionsWithDefaults(options: FormatterOptions): FormatterOptions {\n return defaults(options, this.formatterConfig);\n }\n\n private mergeContext(options: FormatterOptions, context?: ExecutionContext): FormatterContext {\n const formatterContext: FormatterContext = Object.assign({}, options, context);\n return formatterContext;\n }\n\n render(env: EnvDefinition) {\n const descriptor = this.getDescriptor(env);\n\n return (\n <Text key={descriptor?.id}>\n <Text color=\"cyan\">configured formatter: </Text>\n <Text>\n {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})\n </Text>\n <Newline />\n <Text color=\"cyan\">formatter config:</Text>\n <Newline />\n <Text>\n {descriptor?.config && highlight(descriptor?.config, { language: 'javascript', ignoreIllegals: true })}\n </Text>\n <Newline />\n </Text>\n );\n }\n\n transform(env: Env, context: EnvContext): FormatterTransformationMap | undefined {\n // Old env\n if (!env?.formatter) return undefined;\n return {\n getFormatter: () => env.formatter()(context),\n };\n }\n\n getDescriptor(env: EnvDefinition) {\n if (!env.env.getFormatter) return undefined;\n const mergedOpts = this.optionsWithDefaults({});\n const formatterContext = this.mergeContext(mergedOpts);\n const formatter = env.env.getFormatter(formatterContext);\n\n return {\n id: formatter.id,\n icon: formatter.icon,\n config: formatter.displayConfig ? formatter.displayConfig() : undefined,\n version: formatter.version ? formatter.version() : '?',\n displayName: formatter.displayName ? formatter.displayName : '?',\n };\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,IAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,cAAA;EAAA,MAAAL,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAI,aAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsC,SAAAG,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAJ,GAAA,IAAAO,MAAA,CAAAC,cAAA,CAAAR,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAX,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAAA,SAAAM,eAAAM,CAAA,QA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ules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_formatter@1.0.106/dist/formatter.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_formatter@1.0.106/dist/formatter.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_formatter@1.0.108/dist/formatter.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_formatter@1.0.108/dist/formatter.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/format.cmd.ts ADDED
@@ -0,0 +1,155 @@
1
+ import { TimerResponse, Timer } from '@teambit/legacy/dist/toolbox/timer';
2
+ import { Command, CommandOptions } from '@teambit/cli';
3
+ import { ComponentFactory, ComponentID } from '@teambit/component';
4
+ import chalk from 'chalk';
5
+ import { EnvsExecutionResult } from '@teambit/envs';
6
+ import { Workspace } from '@teambit/workspace';
7
+ import { compact, flatten } from 'lodash';
8
+ import { FormatterMain } from './formatter.main.runtime';
9
+ import { ComponentFormatResult, FormatResults, FileFormatResult } from './formatter';
10
+ import { FormatterOptions } from './formatter-context';
11
+
12
+ export type FormatCmdOptions = {
13
+ changed?: boolean;
14
+ json?: boolean;
15
+ check?: boolean;
16
+ };
17
+
18
+ type OutputContext = {
19
+ check?: boolean;
20
+ };
21
+
22
+ /**
23
+ * 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
24
+ */
25
+ export type JsonComponentFormatResult = Omit<ComponentFormatResult, 'component'> & {
26
+ componentId: ComponentID;
27
+ };
28
+
29
+ export type JsonFormatDataResults = Omit<FormatResults, 'results'> & { results: JsonComponentFormatResult[] };
30
+ /**
31
+ * 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
32
+ */
33
+ export type JsonFormatResults = {
34
+ duration: TimerResponse;
35
+ data: JsonFormatDataResults;
36
+ code: number;
37
+ componentsIdsToFormat: string[];
38
+ };
39
+
40
+ export class FormatCmd implements Command {
41
+ name = 'format [component...]';
42
+ description = 'format components in the development workspace';
43
+ group = 'development';
44
+ helpUrl = 'reference/formatting/formatter-overview';
45
+ options = [
46
+ ['c', 'changed', 'format only new and modified components'],
47
+ ['', 'check', 'will output a human-friendly message and a list of unformatted files, if any'],
48
+ ['j', 'json', 'return the format results in json format'],
49
+ ] as CommandOptions;
50
+
51
+ constructor(
52
+ private formatter: FormatterMain,
53
+ private componentHost: ComponentFactory,
54
+ private workspace: Workspace
55
+ ) {}
56
+
57
+ async report([components = []]: [string[]], formatterOptions: FormatCmdOptions) {
58
+ const { duration, data, code, componentsIdsToFormat } = await this.json([components], formatterOptions);
59
+
60
+ const title = chalk.bold(
61
+ `formatting total of ${chalk.cyan(
62
+ componentsIdsToFormat.length.toString()
63
+ )} component(s) in workspace '${chalk.cyan(this.componentHost.name)}`
64
+ );
65
+
66
+ const componentsOutputs = this.getAllComponentsResultOutput(data.results, { check: formatterOptions.check });
67
+
68
+ const { seconds } = duration;
69
+ const summery = `formatted ${chalk.cyan(componentsIdsToFormat.length.toString())} components in ${chalk.cyan(
70
+ seconds.toString()
71
+ )}.`;
72
+
73
+ return {
74
+ data: `${title}\n\n${componentsOutputs}\n\n${summery}`,
75
+ code,
76
+ };
77
+ }
78
+
79
+ async json([components = []]: [string[]], formatterCmdOptions: FormatCmdOptions): Promise<JsonFormatResults> {
80
+ const timer = Timer.create();
81
+ timer.start();
82
+ const componentsIds = await this.getIdsToFormat(components, formatterCmdOptions.changed);
83
+ const componentsToFormat = await this.workspace.getMany(componentsIds);
84
+ const opts: FormatterOptions = {};
85
+ const formatterResults = formatterCmdOptions.check
86
+ ? await this.formatter.check(componentsToFormat, opts)
87
+ : await this.formatter.format(componentsToFormat, opts);
88
+ const jsonFormatterResults = toJsonFormatResults(formatterResults);
89
+ const timerResponse = timer.stop();
90
+ const statusCode = this.getStatusCode(jsonFormatterResults, formatterCmdOptions.check);
91
+
92
+ return {
93
+ duration: timerResponse,
94
+ data: jsonFormatterResults,
95
+ code: statusCode,
96
+ componentsIdsToFormat: componentsToFormat.map((comp) => comp.id.toString()),
97
+ };
98
+ }
99
+
100
+ private getStatusCode(results: JsonFormatDataResults, check = false): number {
101
+ if (!check) return 0;
102
+ const hasIssues = results.results.some((comp) => comp.results.some((file) => file.hasIssues));
103
+ if (hasIssues) return 1;
104
+ return 0;
105
+ }
106
+
107
+ private async getIdsToFormat(components: string[], changed = false): Promise<ComponentID[]> {
108
+ if (components.length) {
109
+ return this.workspace.resolveMultipleComponentIds(components);
110
+ }
111
+ if (changed) {
112
+ return this.workspace.getNewAndModifiedIds();
113
+ }
114
+ return this.componentHost.listIds();
115
+ }
116
+
117
+ private getAllComponentsResultOutput(componentsResult: JsonComponentFormatResult[], context: OutputContext) {
118
+ const allResults = componentsResult.map((comp) => this.getOneComponentResultOutput(comp, context));
119
+ return allResults.join('\n\n');
120
+ }
121
+
122
+ private getOneComponentResultOutput(componentResult: JsonComponentFormatResult, context: OutputContext) {
123
+ const title = chalk.bold.cyan(componentResult.componentId.toString({ ignoreVersion: true }));
124
+ const filesWithIssues = componentResult.results.filter((fileResult) => fileResult.hasIssues);
125
+ if (!filesWithIssues || !filesWithIssues.length) {
126
+ return `${title}\n${chalk.green('no issues found')}`;
127
+ }
128
+ let subTitle = chalk.green('the following files have been re-formatted:');
129
+ if (context.check) {
130
+ subTitle = chalk.red('issues found in the following files:');
131
+ }
132
+ const files = filesWithIssues.map(this.getOneComponentFileResultOutput);
133
+ return `${title}\n${subTitle}\n${files.join('\n')}`;
134
+ }
135
+
136
+ private getOneComponentFileResultOutput(fileResult: FileFormatResult) {
137
+ return fileResult.filePath;
138
+ }
139
+ }
140
+
141
+ function toJsonFormatResults(results: EnvsExecutionResult<FormatResults>): JsonFormatDataResults {
142
+ const newResults = results.results.map((res) => {
143
+ const resultsWithoutComponent = res.data?.results.map((result) => {
144
+ return {
145
+ componentId: result.component.id,
146
+ results: result.results,
147
+ };
148
+ });
149
+ return compact(resultsWithoutComponent);
150
+ });
151
+ return {
152
+ results: compact(flatten(newResults)),
153
+ errors: results?.errors,
154
+ };
155
+ }
package/format.task.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { BuildTask, BuiltTaskResult, BuildContext, ComponentResult } from '@teambit/builder';
2
+ import { Formatter } from './formatter';
3
+
4
+ export class FormatTask implements BuildTask {
5
+ constructor(readonly aspectId: string, readonly name = 'format') {}
6
+
7
+ async execute(context: BuildContext): Promise<BuiltTaskResult> {
8
+ const formatter: Formatter = context.env.getFormatter();
9
+ // TODO: add option to select between check and format here
10
+ const results = await formatter.check(context);
11
+ const componentsResults = results.results.map((formatResult): ComponentResult => {
12
+ return {
13
+ component: formatResult.component,
14
+ metadata: {
15
+ results: formatResult.results,
16
+ },
17
+ errors: [],
18
+ };
19
+ });
20
+
21
+ return {
22
+ componentsResults,
23
+ };
24
+ }
25
+ }
@@ -0,0 +1,6 @@
1
+ import { ExecutionContext } from '@teambit/envs';
2
+
3
+ export type FormatterOptions = { check?: boolean };
4
+ export interface FormatterContext extends ExecutionContext, FormatterOptions {}
5
+ // export interface FormatterContext extends ExecutionContext {}
6
+ // export type FormatterContext = ExecutionContext;
@@ -0,0 +1,9 @@
1
+ import { EnvHandler } from '@teambit/envs';
2
+ import { Formatter } from './formatter';
3
+
4
+ export interface FormatterEnv {
5
+ /**
6
+ * return a Formatter instance.
7
+ */
8
+ formatter(): EnvHandler<Formatter>;
9
+ }
@@ -0,0 +1,5 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const FormatterAspect = Aspect.create({
4
+ id: 'teambit.defender/formatter',
5
+ });
@@ -0,0 +1,8 @@
1
+ import gql from 'graphql-tag';
2
+
3
+ export function linterSchema() {
4
+ return {
5
+ typeDefs: gql``,
6
+ resolvers: {},
7
+ };
8
+ }
@@ -0,0 +1,75 @@
1
+ import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
2
+ import { Component, ComponentAspect, ComponentMain } from '@teambit/component';
3
+ import { EnvsAspect, EnvsMain, ExecutionContext } from '@teambit/envs';
4
+ import { LoggerAspect, LoggerMain } from '@teambit/logger';
5
+ import { Workspace, WorkspaceAspect } from '@teambit/workspace';
6
+ import { FormatterAspect } from './formatter.aspect';
7
+ import { FormatterService } from './formatter.service';
8
+ import { FormatTask } from './format.task';
9
+ import { FormatCmd } from './format.cmd';
10
+ import { FormatterOptions } from './formatter-context';
11
+ import { Formatter } from './formatter';
12
+
13
+ export type FormatterConfig = {};
14
+ export class FormatterMain {
15
+ static runtime = MainRuntime;
16
+
17
+ constructor(private envs: EnvsMain, private formatterService: FormatterService) {}
18
+
19
+ /**
20
+ * format an array of components.
21
+ */
22
+ async format(components: Component[], opts: FormatterOptions) {
23
+ const envsRuntime = await this.envs.createEnvironment(components);
24
+ const formatResults = envsRuntime.run(this.formatterService, this.toFormatServiceOptions(opts, false));
25
+ return formatResults;
26
+ }
27
+
28
+ /**
29
+ * check format an array of components.
30
+ */
31
+ async check(components: Component[], opts: FormatterOptions) {
32
+ const envsRuntime = await this.envs.createEnvironment(components);
33
+ const formatResults = envsRuntime.run(this.formatterService, this.toFormatServiceOptions(opts, true));
34
+ return formatResults;
35
+ }
36
+
37
+ getFormatter(context: ExecutionContext, options: FormatterOptions): Formatter {
38
+ return this.formatterService.getFormatter(context, options);
39
+ }
40
+
41
+ private toFormatServiceOptions(opts: FormatterOptions, check = false): FormatterOptions {
42
+ return {
43
+ ...opts,
44
+ check,
45
+ };
46
+ }
47
+
48
+ /**
49
+ * create a format task for build pipelines.
50
+ * @param name name of the task.
51
+ */
52
+ createTask(name?: string): FormatTask {
53
+ return new FormatTask(FormatterAspect.id, name);
54
+ }
55
+
56
+ static dependencies = [EnvsAspect, CLIAspect, ComponentAspect, LoggerAspect, WorkspaceAspect];
57
+
58
+ static defaultConfig: FormatterConfig = {};
59
+
60
+ static async provider(
61
+ [envs, cli, component, loggerAspect, workspace]: [EnvsMain, CLIMain, ComponentMain, LoggerMain, Workspace],
62
+ config: FormatterConfig
63
+ ) {
64
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
65
+ const logger = loggerAspect.createLogger(FormatterAspect.id);
66
+ const formatterService = new FormatterService(config);
67
+ const formatterAspect = new FormatterMain(envs, formatterService);
68
+ envs.registerService(formatterService);
69
+ cli.register(new FormatCmd(formatterAspect, component.getHost(), workspace));
70
+
71
+ return formatterAspect;
72
+ }
73
+ }
74
+
75
+ FormatterAspect.addRuntime(FormatterMain);
package/formatter.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { Component } from '@teambit/component';
2
+ import { FormatterContext } from './formatter-context';
3
+
4
+ export type ComponentFormatResult = {
5
+ /**
6
+ * the formatted component.
7
+ */
8
+ component: Component;
9
+
10
+ /**
11
+ * format results for each file of the component.
12
+ */
13
+ results: FileFormatResult[];
14
+ };
15
+
16
+ export type FileFormatResult = {
17
+ /**
18
+ * path of the formatted file.
19
+ */
20
+ filePath: string;
21
+
22
+ /**
23
+ * Does the file has formatting issues (needs format)
24
+ */
25
+ hasIssues: boolean;
26
+
27
+ /**
28
+ * The new file content after the formatting
29
+ */
30
+ newContent?: string;
31
+ };
32
+
33
+ export type FormatResults = {
34
+ results: ComponentFormatResult[];
35
+ errors: Error[];
36
+ };
37
+
38
+ export interface Formatter {
39
+ id: string;
40
+ format(context: FormatterContext): Promise<FormatResults>;
41
+ formatSnippet(snippet: string, filepath?: string): Promise<string>;
42
+ check(context: FormatterContext): Promise<FormatResults>;
43
+ }
package/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { FormatterAspect } from './formatter.aspect';
2
+
3
+ export { FormatterAspect };
4
+ export type { FormatterMain, FormatterConfig } from './formatter.main.runtime';
5
+ export type { FormatResults, Formatter, FileFormatResult, ComponentFormatResult } from './formatter';
6
+ export type { FormatTask } from './format.task';
7
+ export type { FormatterEnv } from './formatter-env-type';
8
+ export type { FormatterContext, FormatterOptions } from './formatter-context';
9
+ export default FormatterAspect;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/formatter",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
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.106"
9
+ "version": "1.0.108"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -14,30 +14,26 @@
14
14
  "graphql-tag": "2.12.1",
15
15
  "cli-highlight": "2.1.9",
16
16
  "ink": "3.2.0",
17
- "core-js": "^3.0.0",
18
- "@babel/runtime": "7.20.0",
19
17
  "@teambit/harmony": "0.4.6",
20
- "@teambit/cli": "0.0.839",
21
- "@teambit/component": "1.0.106",
22
- "@teambit/envs": "1.0.106",
23
- "@teambit/workspace": "1.0.106",
24
- "@teambit/builder": "1.0.106",
25
- "@teambit/logger": "0.0.932"
18
+ "@teambit/cli": "0.0.840",
19
+ "@teambit/component": "1.0.108",
20
+ "@teambit/envs": "1.0.108",
21
+ "@teambit/workspace": "1.0.108",
22
+ "@teambit/builder": "1.0.108",
23
+ "@teambit/logger": "0.0.933"
26
24
  },
27
25
  "devDependencies": {
28
26
  "@types/lodash": "4.14.165",
29
- "@types/react": "^17.0.8",
30
27
  "@types/mocha": "9.1.0",
31
- "@types/node": "12.20.4",
32
- "@types/react-dom": "^17.0.5",
33
- "@types/jest": "^26.0.0",
34
- "@types/testing-library__jest-dom": "5.9.5",
35
- "@teambit/defender.content.formatter-overview": "1.96.1"
28
+ "@types/jest": "^29.2.2",
29
+ "@types/testing-library__jest-dom": "^5.9.5",
30
+ "@teambit/defender.content.formatter-overview": "1.96.1",
31
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13"
36
32
  },
37
33
  "peerDependencies": {
38
- "@teambit/legacy": "1.0.624",
39
- "react": "^16.8.0 || ^17.0.0",
40
- "react-dom": "^16.8.0 || ^17.0.0"
34
+ "react": "^17.0.0 || ^18.0.0",
35
+ "@types/react": "^18.2.12",
36
+ "@teambit/legacy": "1.0.624"
41
37
  },
42
38
  "license": "Apache-2.0",
43
39
  "optionalDependencies": {},
@@ -51,7 +47,7 @@
51
47
  },
52
48
  "private": false,
53
49
  "engines": {
54
- "node": ">=12.22.0"
50
+ "node": ">=16.0.0"
55
51
  },
56
52
  "repository": {
57
53
  "type": "git",
@@ -60,12 +56,9 @@
60
56
  "keywords": [
61
57
  "bit",
62
58
  "bit-aspect",
59
+ "bit-core-aspect",
63
60
  "components",
64
61
  "collaboration",
65
- "web",
66
- "react",
67
- "react-components",
68
- "angular",
69
- "angular-components"
62
+ "web"
70
63
  ]
71
64
  }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }