@teambit/prettier 1.0.108 → 1.0.110

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.
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.defender/prettier-preview"]=t():e["teambit.defender/prettier-preview"]=t()}(self,(()=>(()=>{"use strict";var e={10133:(e,t,o)=>{var r={id:"teambit.defender/prettier@1.0.110",homepage:"https://bit.cloud/teambit/defender/prettier",exported:!0};function i(){const e=n(o(87363));return i=function(){return e},e}function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,i.__bit_component=r,n.__bit_component=r;const d=()=>i().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},i().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/brands/logo-prettier.svg"}));d.__bit_component=r,t.Logo=d},87363:e=>{e.exports=React}},t={};function o(r){var i=t[r];if(void 0!==i)return i.exports;var n=t[r]={exports:{}};return e[r](n,n.exports,o),n.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{compositions:()=>e,compositions_metadata:()=>i,overview:()=>t});const e=[o(10133)],t=[],i={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),r})()));
@@ -1,4 +1,4 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_prettier@1.0.108/dist/prettier.composition.js';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_prettier@1.0.110/dist/prettier.composition.js';
2
2
  ;
3
3
 
4
4
  export const compositions = [compositions_0];
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
1
  {
2
2
  "name": "@teambit/prettier",
3
- "version": "1.0.108",
3
+ "version": "1.0.110",
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": "1.0.108"
9
+ "version": "1.0.110"
10
10
  },
11
11
  "dependencies": {
12
12
  "p-map-series": "2.1.0",
13
13
  "prettier": "2.3.2",
14
14
  "@teambit/harmony": "0.4.6",
15
- "@teambit/envs": "1.0.108",
16
- "@teambit/formatter": "1.0.108",
17
- "@teambit/logger": "0.0.933",
18
- "@teambit/cli": "0.0.840",
15
+ "@teambit/envs": "1.0.110",
16
+ "@teambit/formatter": "1.0.110",
17
+ "@teambit/logger": "0.0.935",
18
+ "@teambit/cli": "0.0.842",
19
19
  "@teambit/defender.prettier.config-mutator": "0.0.94",
20
- "@teambit/workspace-config-files": "1.0.108"
20
+ "@teambit/workspace-config-files": "1.0.110"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/prettier": "2.3.2",
24
24
  "@types/mocha": "9.1.0",
25
25
  "@types/jest": "^29.2.2",
26
26
  "@types/testing-library__jest-dom": "^5.9.5",
27
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
27
+ "@teambit/harmony.envs.core-aspect-env": "0.0.15"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "^17.0.0 || ^18.0.0",
@@ -35,11 +35,15 @@
35
35
  "optionalDependencies": {},
36
36
  "peerDependenciesMeta": {},
37
37
  "exports": {
38
- "node": {
39
- "require": "./dist/index.js",
40
- "import": "./dist/esm.mjs"
38
+ ".": {
39
+ "node": {
40
+ "require": "./dist/index.js",
41
+ "import": "./dist/esm.mjs"
42
+ },
43
+ "default": "./dist/index.js"
41
44
  },
42
- "default": "./dist/index.js"
45
+ "./dist/*": "./dist/*",
46
+ "./artifacts/*": "./artifacts/*"
43
47
  },
44
48
  "private": false,
45
49
  "engines": {
package/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import { PrettierAspect } from './prettier.aspect';
2
-
3
- export { PrettierAspect };
4
- export type {
5
- PrettierMain,
6
- PrettierOptions,
7
- PrettierConfigTransformer,
8
- PrettierConfigTransformContext,
9
- } from './prettier.main.runtime';
10
- export default PrettierAspect;
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const PrettierAspect = Aspect.create({
4
- id: 'teambit.defender/prettier',
5
- });
@@ -1,120 +0,0 @@
1
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
2
- import {
3
- Formatter,
4
- FormatterContext,
5
- FormatResults,
6
- FileFormatResult,
7
- ComponentFormatResult,
8
- } from '@teambit/formatter';
9
- import PrettierLib, { Options as PrettierModuleOptions } from 'prettier';
10
- import mapSeries from 'p-map-series';
11
- import { Logger } from '@teambit/logger';
12
- import { ExecutionContext } from '@teambit/envs';
13
- // import { PrettierOptions } from './prettier.main.runtime';
14
-
15
- export class PrettierFormatter implements Formatter {
16
- constructor(
17
- private logger: Logger,
18
-
19
- private options: PrettierModuleOptions,
20
-
21
- /**
22
- * reference to the prettier module.
23
- */
24
- private prettierModule = PrettierLib
25
- ) {}
26
-
27
- id = 'prettier-formatter';
28
- displayName = 'Prettier';
29
-
30
- displayConfig() {
31
- return JSON.stringify(this.options, null, 2);
32
- }
33
-
34
- async format(context: FormatterContext): Promise<FormatResults> {
35
- return this.run(context);
36
- }
37
-
38
- async formatSnippet(snippet: string, filePath?: string): Promise<string> {
39
- let parser;
40
-
41
- if (filePath) {
42
- const ext = filePath.split('.').pop();
43
- const supportInfo = this.prettierModule.getSupportInfo();
44
- const language = supportInfo.languages.find((lang) => lang.extensions && lang.extensions.includes(`.${ext}`));
45
-
46
- if (language) {
47
- parser = language.parsers[0];
48
- }
49
- }
50
-
51
- parser = parser || 'babel';
52
-
53
- const optsWithFilePath = Object.assign({}, this.options, { filepath: filePath, parser });
54
-
55
- return this.prettierModule.format(snippet, optsWithFilePath);
56
- }
57
-
58
- async check(context: FormatterContext): Promise<FormatResults> {
59
- return this.run(context);
60
- }
61
-
62
- private async run(context: FormatterContext & ExecutionContext): Promise<FormatResults> {
63
- const check = !!context.check;
64
- const longProcessLogger = this.logger.createLongProcessLogger('formatting components', context.components.length);
65
- const resultsP = mapSeries(context.components, async (component): Promise<ComponentFormatResult> => {
66
- longProcessLogger.logProgress(component.id.toString());
67
- const mergedOpts = this.getOptions(this.options, context);
68
- const filesP = component.filesystem.files.map(async (file): Promise<FileFormatResult> => {
69
- const sourceCode = file.contents.toString('utf8');
70
- const optsWithFilePath = this.addFilePathToOpts(mergedOpts, file);
71
- const checkFormatResults = await this.prettierModule.check(sourceCode, optsWithFilePath);
72
- const formatResults = await this.prettierModule.format(sourceCode, optsWithFilePath);
73
-
74
- const hasIssues = !checkFormatResults;
75
- const newContent = typeof formatResults === 'string' && hasIssues ? formatResults : undefined;
76
-
77
- if (!check && newContent) {
78
- file.contents = Buffer.from(newContent);
79
- await file.write(undefined, true);
80
- }
81
-
82
- return {
83
- filePath: file.relative,
84
- hasIssues,
85
- newContent,
86
- };
87
- });
88
-
89
- const files = await Promise.all(filesP);
90
-
91
- return {
92
- component,
93
- results: files,
94
- };
95
- });
96
-
97
- const results = await resultsP;
98
-
99
- return {
100
- results,
101
- errors: [],
102
- };
103
- }
104
-
105
- /**
106
- * get options for eslint.
107
- */
108
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
109
- private getOptions(options: PrettierModuleOptions, context: FormatterContext): PrettierModuleOptions {
110
- return options;
111
- }
112
-
113
- private addFilePathToOpts(options: PrettierModuleOptions, file: AbstractVinyl): PrettierModuleOptions {
114
- return Object.assign({}, options, { filepath: file.path });
115
- }
116
-
117
- version() {
118
- return this.prettierModule.version;
119
- }
120
- }
@@ -1,67 +0,0 @@
1
- import { MainRuntime } from '@teambit/cli';
2
- import { Options as PrettierModuleOptions } from 'prettier';
3
- import { Formatter, FormatterMain, FormatterOptions } from '@teambit/formatter';
4
- import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
5
- import { PrettierConfigMutator } from '@teambit/defender.prettier.config-mutator';
6
- import { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';
7
- import { PrettierAspect } from './prettier.aspect';
8
- import { PrettierFormatter } from './prettier.formatter';
9
-
10
- export type PrettierOptions = {
11
- /**
12
- * formatter config for prettier.
13
- */
14
- config: PrettierModuleOptions;
15
- };
16
-
17
- export type PrettierConfigTransformContext = {
18
- check: boolean;
19
- };
20
-
21
- export type PrettierConfigTransformer = (
22
- config: PrettierConfigMutator,
23
- context: PrettierConfigTransformContext
24
- ) => PrettierConfigMutator;
25
-
26
- export class PrettierMain {
27
- constructor(private logger: Logger) {}
28
- /**
29
- * create a prettier formatter instance.
30
- * @param options prettier options.
31
- * @param PrettierModule reference to an `prettier` module.
32
- */
33
- createFormatter(
34
- formatterOptions: FormatterOptions = {},
35
- options: PrettierOptions,
36
- transformers: PrettierConfigTransformer[] = [],
37
- PrettierModule?: any
38
- ): Formatter {
39
- const configMutator = new PrettierConfigMutator(options.config);
40
- const transformerContext: PrettierConfigTransformContext = { check: !!formatterOptions.check };
41
- const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
42
- return new PrettierFormatter(this.logger, afterMutation.raw, PrettierModule);
43
- }
44
-
45
- static runtime = MainRuntime;
46
-
47
- static dependencies = [LoggerAspect];
48
-
49
- static async provider([loggerExt]: [LoggerMain, FormatterMain, WorkspaceConfigFilesMain]): Promise<PrettierMain> {
50
- const logger = loggerExt.createLogger(PrettierAspect.id);
51
- return new PrettierMain(logger);
52
- }
53
- }
54
-
55
- PrettierAspect.addRuntime(PrettierMain);
56
-
57
- export function runTransformersWithContext(
58
- config: PrettierConfigMutator,
59
- transformers: PrettierConfigTransformer[] = [],
60
- context: PrettierConfigTransformContext
61
- ): PrettierConfigMutator {
62
- if (!Array.isArray(transformers)) return config;
63
- const newConfig = transformers.reduce((acc, transformer) => {
64
- return transformer(acc, context);
65
- }, config);
66
- return newConfig;
67
- }