@teambit/prettier 1.0.107 → 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.
- package/dist/prettier.composition.d.ts +2 -2
- package/dist/prettier.main.runtime.d.ts +5 -5
- package/dist/{preview-1703590665075.js → preview-1703647408454.js} +1 -1
- package/index.ts +10 -0
- package/package.json +16 -23
- package/prettier.aspect.ts +5 -0
- package/prettier.formatter.ts +120 -0
- package/prettier.main.runtime.ts +67 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const Logo: () =>
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Logo: () => JSX.Element;
|
|
@@ -3,16 +3,16 @@ import { Formatter, FormatterMain, FormatterOptions } from '@teambit/formatter';
|
|
|
3
3
|
import { Logger, LoggerMain } from '@teambit/logger';
|
|
4
4
|
import { PrettierConfigMutator } from '@teambit/defender.prettier.config-mutator';
|
|
5
5
|
import { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';
|
|
6
|
-
export
|
|
6
|
+
export type PrettierOptions = {
|
|
7
7
|
/**
|
|
8
8
|
* formatter config for prettier.
|
|
9
9
|
*/
|
|
10
10
|
config: PrettierModuleOptions;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type PrettierConfigTransformContext = {
|
|
13
13
|
check: boolean;
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type PrettierConfigTransformer = (config: PrettierConfigMutator, context: PrettierConfigTransformContext) => PrettierConfigMutator;
|
|
16
16
|
export declare class PrettierMain {
|
|
17
17
|
private logger;
|
|
18
18
|
constructor(logger: Logger);
|
|
@@ -21,9 +21,9 @@ export declare class PrettierMain {
|
|
|
21
21
|
* @param options prettier options.
|
|
22
22
|
* @param PrettierModule reference to an `prettier` module.
|
|
23
23
|
*/
|
|
24
|
-
createFormatter(formatterOptions: FormatterOptions
|
|
24
|
+
createFormatter(formatterOptions: FormatterOptions, options: PrettierOptions, transformers?: PrettierConfigTransformer[], PrettierModule?: any): Formatter;
|
|
25
25
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
26
26
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
27
27
|
static provider([loggerExt]: [LoggerMain, FormatterMain, WorkspaceConfigFilesMain]): Promise<PrettierMain>;
|
|
28
28
|
}
|
|
29
|
-
export declare function runTransformersWithContext(config: PrettierConfigMutator, transformers: PrettierConfigTransformer[]
|
|
29
|
+
export declare function runTransformersWithContext(config: PrettierConfigMutator, transformers: PrettierConfigTransformer[], context: PrettierConfigTransformContext): PrettierConfigMutator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_prettier@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_prettier@1.0.108/dist/prettier.composition.js';
|
|
2
2
|
;
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
package/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/prettier",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.108",
|
|
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.
|
|
9
|
+
"version": "1.0.108"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"p-map-series": "2.1.0",
|
|
13
13
|
"prettier": "2.3.2",
|
|
14
|
-
"core-js": "^3.0.0",
|
|
15
|
-
"@babel/runtime": "7.20.0",
|
|
16
14
|
"@teambit/harmony": "0.4.6",
|
|
17
|
-
"@teambit/envs": "1.0.
|
|
18
|
-
"@teambit/formatter": "1.0.
|
|
19
|
-
"@teambit/logger": "0.0.
|
|
20
|
-
"@teambit/cli": "0.0.
|
|
15
|
+
"@teambit/envs": "1.0.108",
|
|
16
|
+
"@teambit/formatter": "1.0.108",
|
|
17
|
+
"@teambit/logger": "0.0.933",
|
|
18
|
+
"@teambit/cli": "0.0.840",
|
|
21
19
|
"@teambit/defender.prettier.config-mutator": "0.0.94",
|
|
22
|
-
"@teambit/workspace-config-files": "1.0.
|
|
20
|
+
"@teambit/workspace-config-files": "1.0.108"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
25
|
-
"@types/react": "^17.0.8",
|
|
26
23
|
"@types/prettier": "2.3.2",
|
|
27
24
|
"@types/mocha": "9.1.0",
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
30
|
-
"@
|
|
31
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
|
25
|
+
"@types/jest": "^29.2.2",
|
|
26
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
27
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
|
32
28
|
},
|
|
33
29
|
"peerDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"react": "^
|
|
36
|
-
"
|
|
30
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
31
|
+
"@types/react": "^18.2.12",
|
|
32
|
+
"@teambit/legacy": "1.0.624"
|
|
37
33
|
},
|
|
38
34
|
"license": "Apache-2.0",
|
|
39
35
|
"optionalDependencies": {},
|
|
@@ -47,7 +43,7 @@
|
|
|
47
43
|
},
|
|
48
44
|
"private": false,
|
|
49
45
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
46
|
+
"node": ">=16.0.0"
|
|
51
47
|
},
|
|
52
48
|
"repository": {
|
|
53
49
|
"type": "git",
|
|
@@ -56,12 +52,9 @@
|
|
|
56
52
|
"keywords": [
|
|
57
53
|
"bit",
|
|
58
54
|
"bit-aspect",
|
|
55
|
+
"bit-core-aspect",
|
|
59
56
|
"components",
|
|
60
57
|
"collaboration",
|
|
61
|
-
"web"
|
|
62
|
-
"react",
|
|
63
|
-
"react-components",
|
|
64
|
-
"angular",
|
|
65
|
-
"angular-components"
|
|
58
|
+
"web"
|
|
66
59
|
]
|
|
67
60
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"lib": [
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
4
|
+
"esnext",
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.Iterable"
|
|
9
7
|
],
|
|
10
|
-
"target": "
|
|
11
|
-
"module": "
|
|
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
|
-
"
|
|
14
|
+
"skipLibCheck": true,
|
|
20
15
|
"moduleResolution": "node",
|
|
21
16
|
"esModuleInterop": true,
|
|
22
|
-
"rootDir": ".",
|
|
23
17
|
"resolveJsonModule": true,
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"
|
|
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<
|
|
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
|
+
}
|