@teambit/prettier 0.0.673 → 0.0.674
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 -1
- package/dist/prettier.formatter.js +17 -2
- package/dist/prettier.formatter.js.map +1 -1
- package/dist/{preview-1690773444566.js → preview-1690859853833.js} +1 -1
- package/package-tar/teambit-prettier-0.0.674.tgz +0 -0
- package/package.json +5 -5
- package/package-tar/teambit-prettier-0.0.673.tgz +0 -0
|
@@ -17,7 +17,7 @@ export declare class PrettierFormatter implements Formatter {
|
|
|
17
17
|
displayName: string;
|
|
18
18
|
displayConfig(): string;
|
|
19
19
|
format(context: FormatterContext): Promise<FormatResults>;
|
|
20
|
-
formatSnippet(snippet: string): Promise<string>;
|
|
20
|
+
formatSnippet(snippet: string, filePath?: string): Promise<string>;
|
|
21
21
|
check(context: FormatterContext): Promise<FormatResults>;
|
|
22
22
|
private run;
|
|
23
23
|
/**
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
require("core-js/modules/es.array.iterator.js");
|
|
5
5
|
require("core-js/modules/es.promise.js");
|
|
6
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
6
7
|
Object.defineProperty(exports, "__esModule", {
|
|
7
8
|
value: true
|
|
8
9
|
});
|
|
@@ -48,8 +49,22 @@ class PrettierFormatter {
|
|
|
48
49
|
async format(context) {
|
|
49
50
|
return this.run(context);
|
|
50
51
|
}
|
|
51
|
-
async formatSnippet(snippet) {
|
|
52
|
-
|
|
52
|
+
async formatSnippet(snippet, filePath) {
|
|
53
|
+
let parser;
|
|
54
|
+
if (filePath) {
|
|
55
|
+
const ext = filePath.split('.').pop();
|
|
56
|
+
const supportInfo = this.prettierModule.getSupportInfo();
|
|
57
|
+
const language = supportInfo.languages.find(lang => lang.extensions && lang.extensions.includes(`.${ext}`));
|
|
58
|
+
if (language) {
|
|
59
|
+
parser = language.parsers[0];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
parser = parser || 'babel';
|
|
63
|
+
const optsWithFilePath = Object.assign({}, this.options, {
|
|
64
|
+
filepath: filePath,
|
|
65
|
+
parser
|
|
66
|
+
});
|
|
67
|
+
return this.prettierModule.format(snippet, optsWithFilePath);
|
|
53
68
|
}
|
|
54
69
|
async check(context) {
|
|
55
70
|
return this.run(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_prettier","data","_interopRequireDefault","require","_pMapSeries","PrettierFormatter","constructor","logger","options","prettierModule","PrettierLib","_defineProperty2","default","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","
|
|
1
|
+
{"version":3,"names":["_prettier","data","_interopRequireDefault","require","_pMapSeries","PrettierFormatter","constructor","logger","options","prettierModule","PrettierLib","_defineProperty2","default","displayConfig","JSON","stringify","format","context","run","formatSnippet","snippet","filePath","parser","ext","split","pop","supportInfo","getSupportInfo","language","languages","find","lang","extensions","includes","parsers","optsWithFilePath","Object","assign","filepath","check","longProcessLogger","createLongProcessLogger","components","length","resultsP","mapSeries","component","logProgress","id","toString","mergedOpts","getOptions","filesP","filesystem","files","map","file","sourceCode","contents","addFilePathToOpts","checkFormatResults","formatResults","hasIssues","newContent","undefined","Buffer","from","write","relative","Promise","all","results","errors","path","version","exports"],"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 id = 'prettier-formatter';\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, filePath?: string): Promise<string> {\n let parser;\n\n if (filePath) {\n const ext = filePath.split('.').pop();\n const supportInfo = this.prettierModule.getSupportInfo();\n const language = supportInfo.languages.find((lang) => lang.extensions && lang.extensions.includes(`.${ext}`));\n\n if (language) {\n parser = language.parsers[0];\n }\n }\n\n parser = parser || 'babel';\n\n const optsWithFilePath = Object.assign({}, this.options, { filepath: filePath, parser });\n\n return this.prettierModule.format(snippet, optsWithFilePath);\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,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA;;AAEO,MAAMI,iBAAiB,CAAsB;EAClDC,WAAWA,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,IAAAE,gBAAA,GAAAC,OAAA,cAGnB,oBAAoB;IAAA,IAAAD,gBAAA,GAAAC,OAAA,uBACX,UAAU;EAHrB;EAKHC,aAAaA,CAAA,EAAG;IACd,OAAOC,IAAI,CAACC,SAAS,CAAC,IAAI,CAACP,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;EAC9C;EAEA,MAAMQ,MAAMA,CAACC,OAAyB,EAA0B;IAC9D,OAAO,IAAI,CAACC,GAAG,CAACD,OAAO,CAAC;EAC1B;EAEA,MAAME,aAAaA,CAACC,OAAe,EAAEC,QAAiB,EAAmB;IACvE,IAAIC,MAAM;IAEV,IAAID,QAAQ,EAAE;MACZ,MAAME,GAA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yB;IACnG,OAAOT,OAAO;EAChB;EAEQmD,iBAAiBA,CAACnD,OAA8B,EAAEgD,IAAmB,EAAyB;IACpG,OAAOpB,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAE7B,OAAO,EAAE;MAAE8B,QAAQ,EAAEkB,IAAI,CAACiB;IAAK,CAAC,CAAC;EAC5D;EAEAC,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI,CAACjE,cAAc,CAACiE,OAAO;EACpC;AACF;AAACC,OAAA,CAAAtE,iBAAA,GAAAA,iBAAA"}
|
|
@@ -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.674/dist/prettier.composition.js';
|
|
2
2
|
;
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
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.674",
|
|
4
4
|
"homepage": "https://bit.cloud/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.674"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"p-map-series": "2.1.0",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"core-js": "^3.0.0",
|
|
15
15
|
"@babel/runtime": "7.20.0",
|
|
16
16
|
"@teambit/harmony": "0.4.6",
|
|
17
|
-
"@teambit/envs": "0.0.
|
|
18
|
-
"@teambit/formatter": "0.0.
|
|
17
|
+
"@teambit/envs": "0.0.1123",
|
|
18
|
+
"@teambit/formatter": "0.0.674",
|
|
19
19
|
"@teambit/logger": "0.0.845",
|
|
20
20
|
"@teambit/cli": "0.0.752",
|
|
21
21
|
"@teambit/defender.prettier.config-mutator": "0.0.90",
|
|
22
|
-
"@teambit/workspace-config-files": "0.0.
|
|
22
|
+
"@teambit/workspace-config-files": "0.0.103"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/react": "^17.0.8",
|
|
Binary file
|