@teambit/prettier 0.0.445 → 0.0.446
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prettier.formatter.d.ts +1 -0
- package/dist/prettier.formatter.js +3 -0
- package/dist/prettier.formatter.js.map +1 -1
- package/dist/prettier.main.runtime.d.ts +2 -2
- package/dist/prettier.main.runtime.js +2 -2
- package/dist/prettier.main.runtime.js.map +1 -1
- package/package-tar/teambit-prettier-0.0.446.tgz +0 -0
- package/package.json +4 -3
- package/{preview-1667878820252.js → preview-1667965305919.js} +1 -1
- package/package-tar/teambit-prettier-0.0.445.tgz +0 -0
|
@@ -16,6 +16,7 @@ export declare class PrettierFormatter implements Formatter {
|
|
|
16
16
|
displayName: string;
|
|
17
17
|
displayConfig(): string;
|
|
18
18
|
format(context: FormatterContext): Promise<FormatResults>;
|
|
19
|
+
formatSnippet(snippet: string): Promise<string>;
|
|
19
20
|
check(context: FormatterContext): Promise<FormatResults>;
|
|
20
21
|
private run;
|
|
21
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PrettierFormatter","constructor","logger","options","prettierModule","PrettierLib","displayConfig","JSON","stringify","format","context","run","check","longProcessLogger","createLongProcessLogger","components","length","resultsP","mapSeries","component","logProgress","id","toString","mergedOpts","getOptions","filesP","filesystem","files","map","file","sourceCode","contents","optsWithFilePath","addFilePathToOpts","checkFormatResults","formatResults","hasIssues","newContent","undefined","Buffer","from","write","filePath","relative","Promise","all","results","errors","Object","assign","filepath","path","version"],"sources":["prettier.formatter.ts"],"sourcesContent":["import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport {\n Formatter,\n FormatterContext,\n FormatResults,\n FileFormatResult,\n ComponentFormatResult,\n} from '@teambit/formatter';\nimport PrettierLib, { Options as PrettierModuleOptions } from 'prettier';\nimport mapSeries from 'p-map-series';\nimport { Logger } from '@teambit/logger';\n// import { PrettierOptions } from './prettier.main.runtime';\n\nexport class PrettierFormatter implements Formatter {\n constructor(\n private logger: Logger,\n\n private options: PrettierModuleOptions,\n\n /**\n * reference to the prettier module.\n */\n private prettierModule = PrettierLib\n ) {}\n\n displayName = 'Prettier';\n\n displayConfig() {\n return JSON.stringify(this.options, null, 2);\n }\n\n async format(context: FormatterContext): Promise<FormatResults> {\n return this.run(context);\n }\n async check(context: FormatterContext): Promise<FormatResults> {\n return this.run(context);\n }\n\n private async run(context: FormatterContext): Promise<FormatResults> {\n const check = !!context.check;\n const longProcessLogger = this.logger.createLongProcessLogger('formatting components', context.components.length);\n const resultsP = mapSeries(context.components, async (component): Promise<ComponentFormatResult> => {\n longProcessLogger.logProgress(component.id.toString());\n const mergedOpts = this.getOptions(this.options, context);\n const filesP = component.filesystem.files.map(async (file): Promise<FileFormatResult> => {\n const sourceCode = file.contents.toString('utf8');\n const optsWithFilePath = this.addFilePathToOpts(mergedOpts, file);\n const checkFormatResults = await this.prettierModule.check(sourceCode, optsWithFilePath);\n const formatResults = await this.prettierModule.format(sourceCode, optsWithFilePath);\n\n const hasIssues = !checkFormatResults;\n const newContent = typeof formatResults === 'string' && hasIssues ? formatResults : undefined;\n\n if (!check && newContent) {\n file.contents = Buffer.from(newContent);\n await file.write(undefined, true);\n }\n\n return {\n filePath: file.relative,\n hasIssues,\n newContent,\n };\n });\n\n const files = await Promise.all(filesP);\n\n return {\n component,\n results: files,\n };\n });\n\n const results = await resultsP;\n\n return {\n results,\n errors: [],\n };\n }\n\n /**\n * get options for eslint.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n private getOptions(options: PrettierModuleOptions, context: FormatterContext): PrettierModuleOptions {\n return options;\n }\n\n private addFilePathToOpts(options: PrettierModuleOptions, file: AbstractVinyl): PrettierModuleOptions {\n return Object.assign({}, options, { filepath: file.path });\n }\n\n version() {\n return this.prettierModule.version;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;
|
|
1
|
+
{"version":3,"names":["PrettierFormatter","constructor","logger","options","prettierModule","PrettierLib","displayConfig","JSON","stringify","format","context","run","formatSnippet","snippet","check","longProcessLogger","createLongProcessLogger","components","length","resultsP","mapSeries","component","logProgress","id","toString","mergedOpts","getOptions","filesP","filesystem","files","map","file","sourceCode","contents","optsWithFilePath","addFilePathToOpts","checkFormatResults","formatResults","hasIssues","newContent","undefined","Buffer","from","write","filePath","relative","Promise","all","results","errors","Object","assign","filepath","path","version"],"sources":["prettier.formatter.ts"],"sourcesContent":["import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport {\n Formatter,\n FormatterContext,\n FormatResults,\n FileFormatResult,\n ComponentFormatResult,\n} from '@teambit/formatter';\nimport PrettierLib, { Options as PrettierModuleOptions } from 'prettier';\nimport mapSeries from 'p-map-series';\nimport { Logger } from '@teambit/logger';\nimport { ExecutionContext } from '@teambit/envs';\n// import { PrettierOptions } from './prettier.main.runtime';\n\nexport class PrettierFormatter implements Formatter {\n constructor(\n private logger: Logger,\n\n private options: PrettierModuleOptions,\n\n /**\n * reference to the prettier module.\n */\n private prettierModule = PrettierLib\n ) {}\n\n displayName = 'Prettier';\n\n displayConfig() {\n return JSON.stringify(this.options, null, 2);\n }\n\n async format(context: FormatterContext): Promise<FormatResults> {\n return this.run(context);\n }\n\n async formatSnippet(snippet: string): Promise<string> {\n return this.prettierModule.format(snippet, this.options);\n }\n\n async check(context: FormatterContext): Promise<FormatResults> {\n return this.run(context);\n }\n\n private async run(context: FormatterContext & ExecutionContext): Promise<FormatResults> {\n const check = !!context.check;\n const longProcessLogger = this.logger.createLongProcessLogger('formatting components', context.components.length);\n const resultsP = mapSeries(context.components, async (component): Promise<ComponentFormatResult> => {\n longProcessLogger.logProgress(component.id.toString());\n const mergedOpts = this.getOptions(this.options, context);\n const filesP = component.filesystem.files.map(async (file): Promise<FileFormatResult> => {\n const sourceCode = file.contents.toString('utf8');\n const optsWithFilePath = this.addFilePathToOpts(mergedOpts, file);\n const checkFormatResults = await this.prettierModule.check(sourceCode, optsWithFilePath);\n const formatResults = await this.prettierModule.format(sourceCode, optsWithFilePath);\n\n const hasIssues = !checkFormatResults;\n const newContent = typeof formatResults === 'string' && hasIssues ? formatResults : undefined;\n\n if (!check && newContent) {\n file.contents = Buffer.from(newContent);\n await file.write(undefined, true);\n }\n\n return {\n filePath: file.relative,\n hasIssues,\n newContent,\n };\n });\n\n const files = await Promise.all(filesP);\n\n return {\n component,\n results: files,\n };\n });\n\n const results = await resultsP;\n\n return {\n results,\n errors: [],\n };\n }\n\n /**\n * get options for eslint.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n private getOptions(options: PrettierModuleOptions, context: FormatterContext): PrettierModuleOptions {\n return options;\n }\n\n private addFilePathToOpts(options: PrettierModuleOptions, file: AbstractVinyl): PrettierModuleOptions {\n return Object.assign({}, options, { filepath: file.path });\n }\n\n version() {\n return this.prettierModule.version;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;;AAEO,MAAMA,iBAAiB,CAAsB;EAClDC,WAAW,CACDC,MAAc,EAEdC,OAA8B;EAEtC;AACJ;AACA;EACYC,cAAc,GAAGC,mBAAW,EACpC;IAAA,KARQH,MAAc,GAAdA,MAAc;IAAA,KAEdC,OAA8B,GAA9BA,OAA8B;IAAA,KAK9BC,cAAc,GAAdA,cAAc;IAAA,qDAGV,UAAU;EAFrB;EAIHE,aAAa,GAAG;IACd,OAAOC,IAAI,CAACC,SAAS,CAAC,IAAI,CAACL,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;EAC9C;EAEA,MAAMM,MAAM,CAACC,OAAyB,EAA0B;IAC9D,OAAO,IAAI,CAACC,GAAG,CAACD,OAAO,CAAC;EAC1B;EAEA,MAAME,aAAa,CAACC,OAAe,EAAmB;I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GG,SAAS;QAE7F,IAAI,CAAC1B,KAAK,IAAIyB,UAAU,EAAE;UACxBR,IAAI,CAACE,QAAQ,GAAGQ,MAAM,CAACC,IAAI,CAACH,UAAU,CAAC;UACvC,MAAMR,IAAI,CAACY,KAAK,CAACH,SAAS,EAAE,IAAI,CAAC;QACnC;QAEA,OAAO;UACLI,QAAQ,EAAEb,IAAI,CAACc,QAAQ;UACvBP,SAAS;UACTC;QACF,CAAC;MACH,CAAC,CAAC;MAEF,MAAMV,KAAK,GAAG,MAAMiB,OAAO,CAACC,GAAG,CAACpB,MAAM,CAAC;MAEvC,OAAO;QACLN,SAAS;QACT2B,OAAO,EAAEnB;MACX,CAAC;IACH,CAAC,CAAC;IAEF,MAAMmB,OAAO,GAAG,MAAM7B,QAAQ;IAE9B,OAAO;MACL6B,OAAO;MACPC,MAAM,EAAE;IACV,CAAC;EACH;;EAEA;AACF;AACA;EACE;EACQvB,UAAU,CAACvB,OAA8B,EAAEO,OAAyB,EAAyB;IACnG,OAAOP,OAAO;EAChB;EAEQgC,iBAAiB,CAAChC,OAA8B,EAAE4B,IAAmB,EAAyB;IACpG,OAAOmB,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEhD,OAAO,EAAE;MAAEiD,QAAQ,EAAErB,IAAI,CAACsB;IAAK,CAAC,CAAC;EAC5D;EAEAC,OAAO,GAAG;IACR,OAAO,IAAI,CAAClD,cAAc,CAACkD,OAAO;EACpC;AACF;AAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Options as PrettierModuleOptions } from 'prettier';
|
|
2
|
-
import { Formatter,
|
|
2
|
+
import { Formatter, FormatterOptions } from '@teambit/formatter';
|
|
3
3
|
import { Logger, LoggerMain } from '@teambit/logger';
|
|
4
4
|
import { PrettierConfigMutator } from '@teambit/defender.prettier.config-mutator';
|
|
5
5
|
export declare type PrettierOptions = {
|
|
@@ -20,7 +20,7 @@ export declare class PrettierMain {
|
|
|
20
20
|
* @param options prettier options.
|
|
21
21
|
* @param PrettierModule reference to an `prettier` module.
|
|
22
22
|
*/
|
|
23
|
-
createFormatter(
|
|
23
|
+
createFormatter(formatterOptions: FormatterOptions | undefined, options: PrettierOptions, transformers?: PrettierConfigTransformer[], PrettierModule?: any): Formatter;
|
|
24
24
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
25
25
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
26
26
|
static provider([loggerExt]: [LoggerMain]): Promise<PrettierMain>;
|
|
@@ -59,10 +59,10 @@ class PrettierMain {
|
|
|
59
59
|
* @param options prettier options.
|
|
60
60
|
* @param PrettierModule reference to an `prettier` module.
|
|
61
61
|
*/
|
|
62
|
-
createFormatter(
|
|
62
|
+
createFormatter(formatterOptions = {}, options, transformers = [], PrettierModule) {
|
|
63
63
|
const configMutator = new (_defenderPrettier().PrettierConfigMutator)(options.config);
|
|
64
64
|
const transformerContext = {
|
|
65
|
-
check: !!
|
|
65
|
+
check: !!formatterOptions.check
|
|
66
66
|
};
|
|
67
67
|
const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
|
|
68
68
|
return new (_prettier2().PrettierFormatter)(this.logger, afterMutation.raw, PrettierModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PrettierMain","constructor","logger","createFormatter","
|
|
1
|
+
{"version":3,"names":["PrettierMain","constructor","logger","createFormatter","formatterOptions","options","transformers","PrettierModule","configMutator","PrettierConfigMutator","config","transformerContext","check","afterMutation","runTransformersWithContext","clone","PrettierFormatter","raw","provider","loggerExt","createLogger","PrettierAspect","id","MainRuntime","LoggerAspect","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["prettier.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { Options as PrettierModuleOptions } from 'prettier';\nimport { Formatter, FormatterOptions } from '@teambit/formatter';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { PrettierConfigMutator } from '@teambit/defender.prettier.config-mutator';\nimport { PrettierAspect } from './prettier.aspect';\nimport { PrettierFormatter } from './prettier.formatter';\n\nexport type PrettierOptions = {\n /**\n * formatter config for prettier.\n */\n config: PrettierModuleOptions;\n};\n\nexport type PrettierConfigTransformContext = {\n check: boolean;\n};\n\nexport type PrettierConfigTransformer = (\n config: PrettierConfigMutator,\n context: PrettierConfigTransformContext\n) => PrettierConfigMutator;\n\nexport class PrettierMain {\n constructor(private logger: Logger) {}\n /**\n * create a prettier formatter instance.\n * @param options prettier options.\n * @param PrettierModule reference to an `prettier` module.\n */\n createFormatter(\n formatterOptions: FormatterOptions = {},\n options: PrettierOptions,\n transformers: PrettierConfigTransformer[] = [],\n PrettierModule?: any\n ): Formatter {\n const configMutator = new PrettierConfigMutator(options.config);\n const transformerContext: PrettierConfigTransformContext = { check: !!formatterOptions.check };\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new PrettierFormatter(this.logger, afterMutation.raw, PrettierModule);\n }\n\n static runtime = MainRuntime;\n\n static dependencies = [LoggerAspect];\n\n static async provider([loggerExt]: [LoggerMain]): Promise<PrettierMain> {\n const logger = loggerExt.createLogger(PrettierAspect.id);\n return new PrettierMain(logger);\n }\n}\n\nPrettierAspect.addRuntime(PrettierMain);\n\nexport function runTransformersWithContext(\n config: PrettierConfigMutator,\n transformers: PrettierConfigTransformer[] = [],\n context: PrettierConfigTransformContext\n): PrettierConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;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;AAkBO,MAAMA,YA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AAC;EACV,OAAOmB,SAAS;AAClB"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/prettier",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.446",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/defender/prettier",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.defender",
|
|
8
8
|
"name": "prettier",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.446"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"p-map-series": "2.1.0",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"@babel/runtime": "7.20.0",
|
|
15
15
|
"core-js": "^3.0.0",
|
|
16
16
|
"@teambit/harmony": "0.3.3",
|
|
17
|
-
"@teambit/
|
|
17
|
+
"@teambit/envs": "0.0.895",
|
|
18
|
+
"@teambit/formatter": "0.0.446",
|
|
18
19
|
"@teambit/logger": "0.0.692",
|
|
19
20
|
"@teambit/cli": "0.0.599",
|
|
20
21
|
"@teambit/defender.prettier.config-mutator": "0.0.90"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_prettier@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_prettier@0.0.446/dist/prettier.composition.js';
|
|
2
2
|
;
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
Binary file
|