@teambit/eslint 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/eslint-preview"]=t():e["teambit.defender/eslint-preview"]=t()}(self,(()=>(()=>{"use strict";var e={66918:(e,t,o)=>{var r={id:"teambit.defender/eslint@1.0.110",homepage:"https://bit.cloud/teambit/defender/eslint",exported:!0};function n(){const e=i(o(87363));return n=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,n.__bit_component=r,i.__bit_component=r;const p=()=>n().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},n().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/brands/logo-eslint.svg"}));p.__bit_component=r,t.Logo=p},87363:e=>{e.exports=React}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.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:()=>l,compositions_metadata:()=>u,overview:()=>f});var e={};o.r(e),o.d(e,{default:()=>c});var t=o(66918);o(87363);const n=MdxJsReact,i=TeambitMdxUiMdxScopeContext;var p=["components"];function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},s.apply(this,arguments)}var a={},d="wrapper";function c(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,r,n=function(e,t){if(null==e)return{};var o,r,n={},i=Object.keys(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||(n[o]=e[o]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}(e,p);return(0,n.mdx)(d,s({},a,o,{components:t,mdxType:"MDXLayout"}),(0,n.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}c.isMDXComponent=!0;const l=[t],f=[e],u={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),r})()));
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.108/dist/eslint.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.108/dist/eslint.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.110/dist/eslint.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_eslint@1.0.110/dist/eslint.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/eslint",
3
- "version": "1.0.108",
3
+ "version": "1.0.110",
4
4
  "homepage": "https://bit.cloud/teambit/defender/eslint",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.defender",
8
8
  "name": "eslint",
9
- "version": "1.0.108"
9
+ "version": "1.0.110"
10
10
  },
11
11
  "dependencies": {
12
12
  "eslint": "7.32.0",
@@ -16,12 +16,12 @@
16
16
  "p-map-series": "2.1.0",
17
17
  "@babel/runtime": "7.23.2",
18
18
  "@teambit/harmony": "0.4.6",
19
- "@teambit/component": "1.0.108",
20
- "@teambit/linter": "1.0.108",
21
- "@teambit/logger": "0.0.933",
22
- "@teambit/cli": "0.0.840",
19
+ "@teambit/component": "1.0.110",
20
+ "@teambit/linter": "1.0.110",
21
+ "@teambit/logger": "0.0.935",
22
+ "@teambit/cli": "0.0.842",
23
23
  "@teambit/defender.eslint.config-mutator": "0.0.96",
24
- "@teambit/workspace-config-files": "1.0.108"
24
+ "@teambit/workspace-config-files": "1.0.110"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/eslint": "7.28.0",
@@ -30,7 +30,7 @@
30
30
  "@types/object-hash": "1.3.4",
31
31
  "@types/jest": "^29.2.2",
32
32
  "@types/testing-library__jest-dom": "^5.9.5",
33
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
33
+ "@teambit/harmony.envs.core-aspect-env": "0.0.15"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": "^17.0.0 || ^18.0.0",
@@ -40,11 +40,15 @@
40
40
  "optionalDependencies": {},
41
41
  "peerDependenciesMeta": {},
42
42
  "exports": {
43
- "node": {
44
- "require": "./dist/index.js",
45
- "import": "./dist/esm.mjs"
43
+ ".": {
44
+ "node": {
45
+ "require": "./dist/index.js",
46
+ "import": "./dist/esm.mjs"
47
+ },
48
+ "default": "./dist/index.js"
46
49
  },
47
- "default": "./dist/index.js"
50
+ "./dist/*": "./dist/*",
51
+ "./artifacts/*": "./artifacts/*"
48
52
  },
49
53
  "private": false,
50
54
  "engines": {
package/eslint.aspect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const ESLintAspect = Aspect.create({
4
- id: 'teambit.defender/eslint',
5
- });
package/eslint.linter.ts DELETED
@@ -1,258 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import { flatten, compact } from 'lodash';
4
- import { Linter, LinterContext, LintResults, ComponentLintResult } from '@teambit/linter';
5
- import { ESLint as ESLintLib } from 'eslint';
6
- import mapSeries from 'p-map-series';
7
- import objectHash from 'object-hash';
8
- import { ComponentMap } from '@teambit/component';
9
- import { Logger } from '@teambit/logger';
10
- import { ESLintOptions } from './eslint.main.runtime';
11
-
12
- export class ESLintLinter implements Linter {
13
- constructor(
14
- private logger: Logger,
15
-
16
- private options: ESLintOptions,
17
-
18
- /**
19
- * reference to the eslint module.
20
- */
21
- private ESLint?: any
22
- ) {}
23
-
24
- id = 'eslint-linter';
25
- displayName = 'ESlint';
26
-
27
- displayConfig() {
28
- return JSON.stringify(this.options, null, 2);
29
- }
30
-
31
- async lint(context: LinterContext): Promise<LintResults> {
32
- const longProcessLogger = this.logger.createLongProcessLogger('linting components', context.components.length);
33
- const eslint = this.createEslint(this.options.config, this.ESLint);
34
- if (this.options.tsConfig && context.rootDir) {
35
- const tsConfigPath = this.createTempTsConfigFile(
36
- context.rootDir,
37
- context.componentsDirMap,
38
- context.envRuntime.id,
39
- this.options.tsConfig
40
- );
41
- if (this.options?.config?.overrideConfig?.parserOptions) {
42
- this.options.config.overrideConfig.parserOptions.project = tsConfigPath;
43
- }
44
- }
45
- const resultsP = mapSeries(context.components, async (component) => {
46
- longProcessLogger.logProgress(
47
- `component: ${component.id.toString()}, # of files: ${component.filesystem.files.length}`
48
- );
49
- const filesP = component.filesystem.files.map(async (file) => {
50
- // TODO: now that we moved to lint files, maybe it's not required anymore
51
- // The eslint api will not ignore extensions by default when using lintText, so we do it manually
52
- if (!this.options.extensions?.includes(file.extname)) return undefined;
53
- return file.path;
54
- });
55
-
56
- const files = compact(await Promise.all(filesP));
57
- const lintResults = await eslint.lintFiles(files);
58
-
59
- if (eslint && this.options.config.fix && lintResults) {
60
- await ESLintLib.outputFixes(lintResults);
61
- }
62
-
63
- const results: ESLintLib.LintResult[] = compact(flatten(lintResults));
64
- const formatter = await eslint.loadFormatter(this.options.formatter || 'stylish');
65
- const output = formatter.format(results);
66
- const {
67
- totalErrorCount,
68
- totalFatalErrorCount,
69
- totalFixableErrorCount,
70
- totalFixableWarningCount,
71
- totalWarningCount,
72
- componentsResults,
73
- } = this.computeComponentResultsWithTotals(results);
74
-
75
- return {
76
- component,
77
- output,
78
- totalErrorCount,
79
- totalFatalErrorCount,
80
- totalFixableErrorCount,
81
- totalFixableWarningCount,
82
- totalWarningCount,
83
- results: componentsResults,
84
- };
85
- });
86
-
87
- const results = (await resultsP) as any as ComponentLintResult[];
88
- const {
89
- totalErrorCount,
90
- totalFatalErrorCount,
91
- totalFixableErrorCount,
92
- totalFixableWarningCount,
93
- totalWarningCount,
94
- totalComponentsWithErrorCount,
95
- totalComponentsWithFatalErrorCount,
96
- totalComponentsWithFixableErrorCount,
97
- totalComponentsWithFixableWarningCount,
98
- totalComponentsWithWarningCount,
99
- } = this.computeManyComponentsTotals(results);
100
-
101
- return {
102
- totalErrorCount,
103
- totalFatalErrorCount,
104
- totalFixableErrorCount,
105
- totalFixableWarningCount,
106
- totalWarningCount,
107
- totalComponentsWithErrorCount,
108
- totalComponentsWithFatalErrorCount,
109
- totalComponentsWithFixableErrorCount,
110
- totalComponentsWithFixableWarningCount,
111
- totalComponentsWithWarningCount,
112
- results,
113
- errors: [],
114
- };
115
- }
116
-
117
- private createTempTsConfigFile(
118
- rootDir: string,
119
- componentDirMap: ComponentMap<string>,
120
- envId: string,
121
- tsConfig: Record<string, any>
122
- ): string {
123
- const newTsConfig = {
124
- ...tsConfig,
125
- };
126
- const compDirs: string[] = componentDirMap.toArray().map(([, compDir]) => compDir);
127
- if (tsConfig.include) {
128
- newTsConfig.include = flatten(
129
- tsConfig.include.map((includedPath) => {
130
- return compDirs.map((compDir) => `../../${compDir}/${includedPath}`);
131
- })
132
- );
133
- }
134
- if (tsConfig.exclude) {
135
- newTsConfig.exclude = flatten(
136
- tsConfig.exclude.map((excludedPath) => {
137
- return compDirs.map((compDir) => `../../${compDir}/${excludedPath}`);
138
- })
139
- );
140
- }
141
- const cacheDir = getCacheDir(rootDir);
142
- const hash = objectHash(newTsConfig);
143
- // We save the tsconfig with hash here to avoid creating unnecessary tsconfig files
144
- // this is very important as eslint will be able to cache the tsconfig file and will not need to create another program
145
- // this affects performance dramatically
146
- const tempTsConfigPath = path.join(cacheDir, `bit.tsconfig.eslint.${hash}.json`);
147
- if (!fs.existsSync(tempTsConfigPath)) {
148
- fs.outputJSONSync(tempTsConfigPath, newTsConfig, { spaces: 2 });
149
- }
150
- return tempTsConfigPath;
151
- }
152
-
153
- private computeComponentResultsWithTotals(results: ESLintLib.LintResult[]) {
154
- let totalErrorCount = 0;
155
- let totalFatalErrorCount = 0;
156
- let totalFixableErrorCount = 0;
157
- let totalFixableWarningCount = 0;
158
- let totalWarningCount = 0;
159
- const componentsResults = results.map((result) => {
160
- totalErrorCount += result.errorCount ?? 0;
161
- // @ts-ignore - missing from the @types/eslint lib
162
- totalFatalErrorCount += result.fatalErrorCount ?? 0;
163
- totalFixableErrorCount += result.fixableErrorCount ?? 0;
164
- totalFixableWarningCount += result.fixableWarningCount ?? 0;
165
- totalWarningCount += result.warningCount ?? 0;
166
- return {
167
- filePath: result.filePath,
168
- errorCount: result.errorCount,
169
- // @ts-ignore - missing from the @types/eslint lib
170
- fatalErrorCount: result.fatalErrorCount,
171
- fixableErrorCount: result.fixableErrorCount,
172
- fixableWarningCount: result.fixableWarningCount,
173
- warningCount: result.warningCount,
174
- messages: result.messages,
175
- raw: result,
176
- };
177
- });
178
- return {
179
- totalErrorCount,
180
- totalFatalErrorCount,
181
- totalFixableErrorCount,
182
- totalFixableWarningCount,
183
- totalWarningCount,
184
- componentsResults,
185
- };
186
- }
187
-
188
- private computeManyComponentsTotals(componentsResults: ComponentLintResult[]) {
189
- let totalErrorCount = 0;
190
- let totalFatalErrorCount = 0;
191
- let totalFixableErrorCount = 0;
192
- let totalFixableWarningCount = 0;
193
- let totalWarningCount = 0;
194
- let totalComponentsWithErrorCount = 0;
195
- let totalComponentsWithFatalErrorCount = 0;
196
- let totalComponentsWithFixableErrorCount = 0;
197
- let totalComponentsWithFixableWarningCount = 0;
198
- let totalComponentsWithWarningCount = 0;
199
-
200
- componentsResults.forEach((result) => {
201
- if (result.totalErrorCount) {
202
- totalErrorCount += result.totalErrorCount;
203
- totalComponentsWithErrorCount += 1;
204
- }
205
- // @ts-ignore - missing from the @types/eslint lib
206
- if (result.totalFatalErrorCount) {
207
- totalFatalErrorCount += result.totalFatalErrorCount;
208
- totalComponentsWithFatalErrorCount += 1;
209
- }
210
- if (result.totalFixableErrorCount) {
211
- totalFixableErrorCount += result.totalFixableErrorCount;
212
- totalComponentsWithFixableErrorCount += 1;
213
- }
214
- if (result.totalFixableWarningCount) {
215
- totalFixableWarningCount += result.totalFixableWarningCount;
216
- totalComponentsWithFixableWarningCount += 1;
217
- }
218
- if (result.totalWarningCount) {
219
- totalWarningCount += result.totalWarningCount;
220
- totalComponentsWithWarningCount += 1;
221
- }
222
- });
223
- return {
224
- totalErrorCount,
225
- totalFatalErrorCount,
226
- totalFixableErrorCount,
227
- totalFixableWarningCount,
228
- totalWarningCount,
229
- componentsResults,
230
- totalComponentsWithErrorCount,
231
- totalComponentsWithFatalErrorCount,
232
- totalComponentsWithFixableErrorCount,
233
- totalComponentsWithFixableWarningCount,
234
- totalComponentsWithWarningCount,
235
- };
236
- }
237
-
238
- /**
239
- * Create the eslint instance by options that was already merged with context
240
- * @param options
241
- * @param ESLintModule
242
- * @returns
243
- */
244
- private createEslint(options: ESLintLib.Options, ESLintModule?: any): ESLintLib {
245
- // eslint-disable-next-line no-new
246
- if (ESLintModule) new ESLintModule.ESLint(options);
247
- return new ESLintLib(options);
248
- }
249
-
250
- version() {
251
- if (this.ESLint) return this.ESLint.version;
252
- return ESLintLib.version;
253
- }
254
- }
255
-
256
- function getCacheDir(rootDir): string {
257
- return path.join(rootDir, 'node_modules', '.cache');
258
- }
@@ -1,112 +0,0 @@
1
- import { MainRuntime } from '@teambit/cli';
2
- // import { Linter as ESLinter, ESLint as ESLintLib } from 'eslint';
3
- import { ESLint as ESLintLib } from 'eslint';
4
- import { Linter, LinterContext, LinterMain } from '@teambit/linter';
5
- import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
6
- import { EslintConfigMutator } from '@teambit/defender.eslint.config-mutator';
7
- import { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';
8
- import { ESLintAspect } from './eslint.aspect';
9
- import { ESLintLinter } from './eslint.linter';
10
-
11
- export type ESLintOptions = {
12
- /**
13
- * linter config for eslint.
14
- */
15
- // config: ESLinter.Config;
16
- config: ESLintLib.Options;
17
-
18
- /**
19
- * specify to path to resolve eslint plugins from.
20
- */
21
- pluginPath?: string;
22
-
23
- /**
24
- * decide the formatter for the CLI output.
25
- */
26
- formatter?: string;
27
-
28
- /**
29
- * file types to lint.
30
- */
31
- extensions?: string[];
32
-
33
- // TODO: improve type
34
- /**
35
- * typescript config for eslint.
36
- * If you pass this, bit will auto generate a temp config file in `node_modules/.cache` and pass it to eslint.
37
- * In case you have include/exclude props in the tsconfig, they will be changed to handle the fact that they are inside the node_modules/.cache folder.
38
- * a `../../` will be added to the beginning of the path.
39
- */
40
- tsConfig?: Record<string, any>;
41
- };
42
-
43
- export type EslintConfigTransformContext = {
44
- fix: boolean;
45
- };
46
-
47
- export type EslintConfigTransformer = (
48
- config: EslintConfigMutator,
49
- context: EslintConfigTransformContext
50
- ) => EslintConfigMutator;
51
-
52
- export class ESLintMain {
53
- constructor(private logger: Logger) {}
54
-
55
- /**
56
- * create a eslint linter instance.
57
- * @param options eslint options.
58
- * @param ESLintModule reference to an `eslint` module.
59
- */
60
- createLinter(
61
- context: LinterContext,
62
- options: ESLintOptions,
63
- transformers: EslintConfigTransformer[] = [],
64
- ESLintModule?: any
65
- ): Linter {
66
- const mergedOptions = getOptions(options, context);
67
- const configMutator = new EslintConfigMutator(mergedOptions);
68
- const transformerContext: EslintConfigTransformContext = { fix: !!context.fix };
69
- const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
70
-
71
- return new ESLintLinter(this.logger, afterMutation.raw, ESLintModule);
72
- }
73
-
74
- static runtime = MainRuntime;
75
-
76
- static dependencies = [LoggerAspect];
77
-
78
- static async provider([loggerExt]: [LoggerMain, WorkspaceConfigFilesMain, LinterMain]): Promise<ESLintMain> {
79
- const logger = loggerExt.createLogger(ESLintAspect.id);
80
- return new ESLintMain(logger);
81
- }
82
- }
83
-
84
- ESLintAspect.addRuntime(ESLintMain);
85
-
86
- /**
87
- * get options for eslint.
88
- */
89
- function getOptions(options: ESLintOptions, context: LinterContext): ESLintOptions {
90
- const mergedConfig: ESLintLib.Options = {
91
- // @ts-ignore - this is a bug in the @types/eslint types
92
- overrideConfig: options.config,
93
- extensions: context.extensionFormats,
94
- useEslintrc: false,
95
- cwd: options.pluginPath,
96
- fix: !!context.fix,
97
- fixTypes: context.fixTypes,
98
- };
99
- return Object.assign({}, options, { config: mergedConfig, extensions: context.extensionFormats });
100
- }
101
-
102
- export function runTransformersWithContext(
103
- config: EslintConfigMutator,
104
- transformers: EslintConfigTransformer[] = [],
105
- context: EslintConfigTransformContext
106
- ): EslintConfigMutator {
107
- if (!Array.isArray(transformers)) return config;
108
- const newConfig = transformers.reduce((acc, transformer) => {
109
- return transformer(acc, context);
110
- }, config);
111
- return newConfig;
112
- }
package/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import { ESLintAspect } from './eslint.aspect';
2
-
3
- export { ESLintAspect };
4
- export type {
5
- ESLintMain,
6
- ESLintOptions,
7
- EslintConfigTransformContext,
8
- EslintConfigTransformer,
9
- } from './eslint.main.runtime';
10
- export default ESLintAspect;