Skip to content

Commit dc9a2e3

Browse files
feat: removed cjs wrapper (#265)
* feat: removed cjs wrapper * fix: exports * docs: formatting * ci: update
1 parent fd8111a commit dc9a2e3

19 files changed

+174
-135
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
strategy:
5353
matrix:
5454
os: [ubuntu-latest, windows-latest, macos-latest]
55-
node-version: [12.x, 14.x, 16.x, 17.x]
55+
node-version: [12.x, 14.x, 16.x]
5656
stylelint-version: [13.x, 14.x]
5757
webpack-version: [latest]
5858

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ type outputReport =
274274
formatter?:
275275
| (
276276
| string
277-
| ((
278-
results: Array<import('stylelint').LintResult>
279-
) => string)
277+
| ((results: Array<import('stylelint').LintResult>) => string)
280278
)
281279
| undefined;
282280
};

declarations/cjs.d.ts

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

package.json

Lines changed: 5 additions & 5 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,7 +39,7 @@
3939
},
4040
"files": [
4141
"dist",
42-
"declarations"
42+
"types"
4343
],
4444
"peerDependencies": {
4545
"stylelint": "^13.0.0 || ^14.0.0",

src/StylelintError.js

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

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

src/cjs.js

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

src/getStylelint.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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

55
// @ts-ignore
6-
import { setup, lintFiles } from './worker';
7-
import { jsonStringifyReplacerSortKeys } from './utils';
8-
import { getStylelintOptions } from './options';
6+
const { setup, lintFiles } = require('./worker');
7+
const { jsonStringifyReplacerSortKeys } = require('./utils');
8+
const { getStylelintOptions } = require('./options');
99

1010
/** @type {{[key: string]: any}} */
1111
const cache = {};
@@ -80,7 +80,7 @@ function loadStylelintThreaded(key, poolSize, options) {
8080
* @param {Options} options
8181
* @returns {Linter}
8282
*/
83-
export default function getStylelint(key, { threads, ...options }) {
83+
function getStylelint(key, { threads, ...options }) {
8484
const max =
8585
typeof threads !== 'number' ? (threads ? cpus().length - 1 : 1) : threads;
8686

@@ -102,3 +102,5 @@ export default function getStylelint(key, { threads, ...options }) {
102102
function getCacheKey(key, options) {
103103
return JSON.stringify({ key, options }, jsonStringifyReplacerSortKeys);
104104
}
105+
106+
module.exports = getStylelint;

src/index.js

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

3-
// @ts-ignore
4-
import globby from 'globby';
3+
const globby = require('globby');
4+
const { isMatch } = require('micromatch');
55

6-
import { isMatch } from 'micromatch';
7-
8-
import { getOptions } from './options';
9-
import linter from './linter';
10-
import { arrify, parseFiles, parseFoldersToGlobs } from './utils';
6+
const { getOptions } = require('./options');
7+
const linter = require('./linter');
8+
const { arrify, parseFiles, parseFoldersToGlobs } = require('./utils');
119

1210
/** @typedef {import('webpack').Compiler} Compiler */
1311
/** @typedef {import('webpack').Module} Module */
@@ -110,6 +108,8 @@ class StylelintWebpackPlugin {
110108
}
111109

112110
compilation.hooks.finishModules.tapPromise(this.key, async () => {
111+
/** @type {string[]} */
112+
// @ts-ignore
113113
const files = (
114114
await Promise.all(
115115
(compiler.modifiedFiles
@@ -119,7 +119,7 @@ class StylelintWebpackPlugin {
119119
!isMatch(file, exclude, { dot: true })
120120
)
121121
: globby.sync(wanted, { dot: true, ignore: exclude })
122-
).map(async (/** @type {string | undefined} */ file) => {
122+
).map(async (file) => {
123123
try {
124124
return (await api.isPathIgnored(file)) ? false : file;
125125
} catch (e) {
@@ -185,4 +185,4 @@ class StylelintWebpackPlugin {
185185
}
186186
}
187187

188-
export default StylelintWebpackPlugin;
188+
module.exports = StylelintWebpackPlugin;

src/linter.js

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

3-
import StylelintError from './StylelintError';
4-
import getStylelint from './getStylelint';
5-
import { arrify } from './utils';
3+
const StylelintError = require('./StylelintError');
4+
const getStylelint = require('./getStylelint');
5+
const { arrify } = require('./utils');
66

77
/** @typedef {import('stylelint')} Stylelint */
88
/** @typedef {import('stylelint').LintResult} LintResult */
@@ -27,7 +27,7 @@ const resultStorage = new WeakMap();
2727
* @param {Compilation} compilation
2828
* @returns {{api: InternalApi, lint: Linter, report: Reporter, threads: number}}
2929
*/
30-
export default function linter(key, options, compilation) {
30+
function linter(key, options, compilation) {
3131
/** @type {Stylelint} */
3232
let stylelint;
3333

@@ -275,3 +275,5 @@ function getResultStorage({ compiler }) {
275275
}
276276
return storage;
277277
}
278+
279+
module.exports = linter;

src/options.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { validate } from 'schema-utils';
1+
const { validate } = require('schema-utils');
22

3-
// @ts-ignore
4-
import schema from './options.json';
3+
const schema = require('./options.json');
54

65
/** @typedef {import("stylelint")} stylelint */
76
/** @typedef {import("stylelint").LinterOptions} StylelintOptions */
@@ -37,7 +36,7 @@ import schema from './options.json';
3736
* @param {Options} pluginOptions
3837
* @returns {Partial<PluginOptions>}
3938
*/
40-
export function getOptions(pluginOptions) {
39+
function getOptions(pluginOptions) {
4140
const options = {
4241
extensions: ['css', 'scss', 'sass'],
4342
emitError: true,
@@ -60,7 +59,7 @@ export function getOptions(pluginOptions) {
6059
* @param {Options} pluginOptions
6160
* @returns {Partial<StylelintOptions>}
6261
*/
63-
export function getStylelintOptions(pluginOptions) {
62+
function getStylelintOptions(pluginOptions) {
6463
const stylelintOptions = { ...pluginOptions };
6564

6665
// Keep the files and formatter option because it is common to both the plugin and Stylelint.
@@ -75,3 +74,8 @@ export function getStylelintOptions(pluginOptions) {
7574

7675
return stylelintOptions;
7776
}
77+
78+
module.exports = {
79+
getOptions,
80+
getStylelintOptions,
81+
};

0 commit comments

Comments
 (0)