Skip to content

Commit 125becf

Browse files
feat: removed cjs wrapper (#152)
* feat: removed cjs wrapper * fix: types
1 parent a33beaa commit 125becf

20 files changed

+3278
-4330
lines changed

declarations/ESLintError.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

declarations/cjs.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

declarations/linter.d.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

package-lock.json

Lines changed: 3081 additions & 4168 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
"type": "opencollective",
1212
"url": "https://opencollective.com/webpack"
1313
},
14-
"main": "dist/cjs.js",
15-
"types": "declarations/index.d.ts",
14+
"main": "dist/index.js",
15+
"types": "types/index.d.ts",
1616
"engines": {
1717
"node": ">= 12.13.0"
1818
},
1919
"scripts": {
2020
"start": "npm run build -- -w",
21-
"clean": "del-cli dist declarations",
21+
"clean": "del-cli dist types",
2222
"prebuild": "npm run clean",
23-
"build:types": "tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write",
23+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
2424
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
2525
"build": "npm-run-all -p \"build:**\"",
2626
"commitlint": "commitlint --from=master",
@@ -39,48 +39,48 @@
3939
},
4040
"files": [
4141
"dist",
42-
"declarations"
42+
"types"
4343
],
4444
"peerDependencies": {
4545
"eslint": "^7.0.0 || ^8.0.0",
4646
"webpack": "^5.0.0"
4747
},
4848
"dependencies": {
49-
"@types/eslint": "^7.28.2 || ^8.2.0",
50-
"jest-worker": "^27.3.1",
51-
"micromatch": "^4.0.4",
49+
"@types/eslint": "^7.29.0 || ^8.4.1",
50+
"jest-worker": "^28.0.2",
51+
"micromatch": "^4.0.5",
5252
"normalize-path": "^3.0.0",
5353
"schema-utils": "^4.0.0"
5454
},
5555
"devDependencies": {
56-
"@babel/cli": "^7.16.0",
57-
"@babel/core": "^7.16.0",
58-
"@babel/preset-env": "^7.16.4",
59-
"@commitlint/cli": "^15.0.0",
60-
"@commitlint/config-conventional": "^15.0.0",
56+
"@babel/cli": "^7.17.10",
57+
"@babel/core": "^7.17.10",
58+
"@babel/preset-env": "^7.17.10",
59+
"@commitlint/cli": "^16.2.4",
60+
"@commitlint/config-conventional": "^16.2.4",
6161
"@types/fs-extra": "^9.0.13",
6262
"@types/micromatch": "^4.0.2",
6363
"@types/normalize-path": "^3.0.0",
6464
"@types/webpack": "^5.28.0",
6565
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
6666
"babel-eslint": "^10.1.0",
67-
"babel-jest": "^27.3.1",
68-
"chokidar": "^3.5.2",
67+
"babel-jest": "^28.0.3",
68+
"chokidar": "^3.5.3",
6969
"cross-env": "^7.0.3",
7070
"del": "^6.0.0",
7171
"del-cli": "^4.0.1",
72-
"eslint": "^8.3.0",
73-
"eslint-config-prettier": "^8.3.0",
74-
"eslint-plugin-import": "^2.25.3",
75-
"fs-extra": "^10.0.0",
72+
"eslint": "^8.14.0",
73+
"eslint-config-prettier": "^8.5.0",
74+
"eslint-plugin-import": "^2.26.0",
75+
"fs-extra": "^10.1.0",
7676
"husky": "^7.0.4",
77-
"jest": "^27.3.1",
78-
"lint-staged": "^12.1.2",
77+
"jest": "^28.0.3",
78+
"lint-staged": "^12.4.1",
7979
"npm-run-all": "^4.1.5",
80-
"prettier": "^2.4.1",
80+
"prettier": "^2.6.2",
8181
"standard-version": "^9.3.2",
82-
"typescript": "^4.5.2",
83-
"webpack": "^5.64.3"
82+
"typescript": "^4.6.4",
83+
"webpack": "^5.72.0"
8484
},
8585
"keywords": [
8686
"eslint",

src/ESLintError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class ESLintError extends Error {
99
}
1010
}
1111

12-
export default ESLintError;
12+
module.exports = ESLintError;

src/cjs.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/getESLint.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { cpus } from 'os';
1+
const { cpus } = require('os');
22

3-
import { Worker as JestWorker } from 'jest-worker';
3+
const { Worker: JestWorker } = require('jest-worker');
44

5-
import { getESLintOptions } from './options';
6-
import { jsonStringifyReplacerSortKeys } from './utils';
5+
const { getESLintOptions } = require('./options');
6+
const { jsonStringifyReplacerSortKeys } = require('./utils');
77

88
/** @type {{[key: string]: any}} */
99
const cache = {};
@@ -14,13 +14,13 @@ const cache = {};
1414
/** @typedef {() => Promise<void>} AsyncTask */
1515
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
1616
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */
17-
/** @typedef {import('jest-worker').Worker & {lintFiles: LintTask}} Worker */
17+
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
1818

1919
/**
2020
* @param {Options} options
2121
* @returns {Linter}
2222
*/
23-
export function loadESLint(options) {
23+
function loadESLint(options) {
2424
const { eslintPath } = options;
2525

2626
const { ESLint } = require(eslintPath || 'eslint');
@@ -51,7 +51,7 @@ export function loadESLint(options) {
5151
* @param {Options} options
5252
* @returns {Linter}
5353
*/
54-
export function loadESLintThreaded(key, poolSize, options) {
54+
function loadESLintThreaded(key, poolSize, options) {
5555
const cacheKey = getCacheKey(key, options);
5656
const { eslintPath = 'eslint' } = options;
5757
const source = require.resolve('./worker');
@@ -90,7 +90,7 @@ export function loadESLintThreaded(key, poolSize, options) {
9090
* @param {Options} options
9191
* @returns {Linter}
9292
*/
93-
export default function getESLint(key, { threads, ...options }) {
93+
function getESLint(key, { threads, ...options }) {
9494
const max =
9595
typeof threads !== 'number'
9696
? threads
@@ -115,3 +115,9 @@ export default function getESLint(key, { threads, ...options }) {
115115
function getCacheKey(key, options) {
116116
return JSON.stringify({ key, options }, jsonStringifyReplacerSortKeys);
117117
}
118+
119+
module.exports = {
120+
loadESLint,
121+
loadESLintThreaded,
122+
getESLint,
123+
};

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { isAbsolute, join } from 'path';
1+
const { isAbsolute, join } = require('path');
22

3-
import { isMatch } from 'micromatch';
3+
const { isMatch } = require('micromatch');
44

5-
import { getOptions } from './options';
6-
import linter from './linter';
7-
import { arrify, parseFiles, parseFoldersToGlobs } from './utils';
5+
const { getOptions } = require('./options');
6+
const linter = require('./linter');
7+
const { arrify, parseFiles, parseFoldersToGlobs } = require('./utils');
88

99
/** @typedef {import('webpack').Compiler} Compiler */
1010
/** @typedef {import('./options').Options} Options */
@@ -175,4 +175,4 @@ class ESLintWebpackPlugin {
175175
}
176176
}
177177

178-
export default ESLintWebpackPlugin;
178+
module.exports = ESLintWebpackPlugin;

src/linter.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { dirname, isAbsolute, join } from 'path';
1+
const { dirname, isAbsolute, join } = require('path');
22

3-
import ESLintError from './ESLintError';
4-
import getESLint from './getESLint';
3+
const ESLintError = require('./ESLintError');
4+
const { getESLint } = require('./getESLint');
55

66
/** @typedef {import('eslint').ESLint} ESLint */
77
/** @typedef {import('eslint').ESLint.Formatter} Formatter */
@@ -25,7 +25,7 @@ const resultStorage = new WeakMap();
2525
* @param {Compilation} compilation
2626
* @returns {{lint: Linter, report: Reporter, threads: number}}
2727
*/
28-
export default function linter(key, options, compilation) {
28+
function linter(key, options, compilation) {
2929
/** @type {ESLint} */
3030
let eslint;
3131

@@ -92,7 +92,7 @@ export default function linter(key, options, compilation) {
9292
}
9393

9494
const formatter = await loadFormatter(eslint, options.formatter);
95-
const { errors, warnings } = formatResults(
95+
const { errors, warnings } = await formatResults(
9696
formatter,
9797
parseResults(options, results)
9898
);
@@ -136,9 +136,9 @@ export default function linter(key, options, compilation) {
136136
return;
137137
}
138138

139-
const content = outputReport.formatter
139+
const content = await (outputReport.formatter
140140
? (await loadFormatter(eslint, outputReport.formatter)).format(results)
141-
: formatter.format(results);
141+
: formatter.format(results));
142142

143143
let { filePath } = outputReport;
144144
if (!isAbsolute(filePath)) {
@@ -153,17 +153,17 @@ export default function linter(key, options, compilation) {
153153
/**
154154
* @param {Formatter} formatter
155155
* @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
156-
* @returns {{errors?: ESLintError, warnings?: ESLintError}}
156+
* @returns {Promise<{errors?: ESLintError, warnings?: ESLintError}>}
157157
*/
158-
function formatResults(formatter, results) {
158+
async function formatResults(formatter, results) {
159159
let errors;
160160
let warnings;
161161
if (results.warnings.length > 0) {
162-
warnings = new ESLintError(formatter.format(results.warnings));
162+
warnings = new ESLintError(await formatter.format(results.warnings));
163163
}
164164

165165
if (results.errors.length > 0) {
166-
errors = new ESLintError(formatter.format(results.errors));
166+
errors = new ESLintError(await formatter.format(results.errors));
167167
}
168168

169169
return {
@@ -314,3 +314,5 @@ function asList(x) {
314314
/* istanbul ignore next */
315315
return Array.isArray(x) ? x : [x];
316316
}
317+
318+
module.exports = linter;

0 commit comments

Comments
 (0)