Skip to content

Commit 1ccd8bf

Browse files
feat: removed cjs wrapper (#281)
1 parent 9e14831 commit 1ccd8bf

17 files changed

+166
-133
lines changed

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": ">= 10.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 = {};
@@ -78,7 +78,7 @@ function loadStylelintThreaded(key, poolSize, options) {
7878
* @param {Options} options
7979
* @returns {Linter}
8080
*/
81-
export default function getStylelint(key, { threads, ...options }) {
81+
function getStylelint(key, { threads, ...options }) {
8282
const max =
8383
typeof threads !== 'number' ? (threads ? cpus().length - 1 : 1) : threads;
8484

@@ -100,3 +100,5 @@ export default function getStylelint(key, { threads, ...options }) {
100100
function getCacheKey(key, options) {
101101
return JSON.stringify({ key, options }, jsonStringifyReplacerSortKeys);
102102
}
103+
104+
module.exports = getStylelint;

src/index.js

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

3-
// @ts-ignore
4-
import arrify from 'arrify';
5-
// @ts-ignore
6-
import globby from 'globby';
7-
import { isMatch } from 'micromatch';
3+
const arrify = require('arrify');
4+
const globby = require('globby');
5+
const { isMatch } = require('micromatch');
86

9-
import { getOptions } from './options';
10-
import linter from './linter';
11-
import { parseFiles, parseFoldersToGlobs } from './utils';
7+
const { getOptions } = require('./options');
8+
const linter = require('./linter');
9+
const { parseFiles, parseFoldersToGlobs } = require('./utils');
1210

1311
/** @typedef {import('webpack').Compiler} Compiler */
1412
/** @typedef {import('webpack').Module} Module */
@@ -244,4 +242,4 @@ class StylelintWebpackPlugin {
244242
}
245243
}
246244

247-
export default StylelintWebpackPlugin;
245+
module.exports = StylelintWebpackPlugin;

src/linter.js

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

3-
// @ts-ignore
4-
import arrify from 'arrify';
3+
const arrify = require('arrify');
54

6-
import StylelintError from './StylelintError';
7-
import getStylelint from './getStylelint';
5+
const StylelintError = require('./StylelintError');
6+
const getStylelint = require('./getStylelint');
87

98
/** @typedef {import('stylelint')} Stylelint */
109
/** @typedef {import('stylelint').LintResult} LintResult */
@@ -28,7 +27,7 @@ const resultStorage = new WeakMap();
2827
* @param {Compilation} compilation
2928
* @returns {{lint: Linter, report: Reporter, threads: number}}
3029
*/
31-
export default function linter(key, options, compilation) {
30+
function linter(key, options, compilation) {
3231
/** @type {Stylelint} */
3332
let stylelint;
3433

@@ -270,3 +269,5 @@ function getResultStorage({ compiler }) {
270269
}
271270
return storage;
272271
}
272+
273+
module.exports = linter;

src/options.js

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

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

66
/** @typedef {import("stylelint")} stylelint */
77
/** @typedef {import("stylelint").LinterOptions} StylelintOptions */
@@ -37,7 +37,7 @@ import schema from './options.json';
3737
* @param {Options} pluginOptions
3838
* @returns {Partial<PluginOptions>}
3939
*/
40-
export function getOptions(pluginOptions) {
40+
function getOptions(pluginOptions) {
4141
const options = {
4242
extensions: ['css', 'scss', 'sass'],
4343
emitError: true,
@@ -60,7 +60,7 @@ export function getOptions(pluginOptions) {
6060
* @param {Options} pluginOptions
6161
* @returns {Partial<StylelintOptions>}
6262
*/
63-
export function getStylelintOptions(pluginOptions) {
63+
function getStylelintOptions(pluginOptions) {
6464
const stylelintOptions = { ...pluginOptions };
6565

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

7676
return stylelintOptions;
7777
}
78+
79+
module.exports = {
80+
getOptions,
81+
getStylelintOptions,
82+
};

src/utils.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import { resolve } from 'path';
2-
import { statSync } from 'fs';
1+
const { resolve } = require('path');
2+
const { statSync } = require('fs');
33

4-
// @ts-ignore
5-
import normalizePath from 'normalize-path';
6-
// @ts-ignore
7-
import arrify from 'arrify';
4+
const normalizePath = require('normalize-path');
5+
const arrify = require('arrify');
86

97
/**
108
* @param {string|(string|undefined)[]} files
119
* @param {string} context
1210
* @returns {string[]}
1311
*/
14-
export function parseFiles(files, context) {
12+
function parseFiles(files, context) {
1513
return arrify(files)
16-
.filter((/** @type {string} */ file) => typeof file === 'string')
17-
.map((/** @type {string} */ file) => normalizePath(resolve(context, file)));
14+
.filter((file) => typeof file === 'string')
15+
.map((file) => normalizePath(resolve(context, file || '')));
1816
}
1917

2018
/**
2119
* @param {string|string[]} patterns
2220
* @param {string|string[]} extensions
2321
* @returns {string[]}
2422
*/
25-
export function parseFoldersToGlobs(patterns, extensions = []) {
23+
function parseFoldersToGlobs(patterns, extensions = []) {
2624
const extensionsList = arrify(extensions);
2725
const [prefix, postfix] = extensionsList.length > 1 ? ['{', '}'] : ['', ''];
2826
const extensionsGlob = extensionsList
@@ -54,7 +52,7 @@ export function parseFoldersToGlobs(patterns, extensions = []) {
5452
* @param {string} _ key, but unused
5553
* @param {any} value
5654
*/
57-
export const jsonStringifyReplacerSortKeys = (_, value) => {
55+
const jsonStringifyReplacerSortKeys = (_, value) => {
5856
/**
5957
* @param {{ [x: string]: any; }} sorted
6058
* @param {string | number} key
@@ -69,3 +67,9 @@ export const jsonStringifyReplacerSortKeys = (_, value) => {
6967
? Object.keys(value).sort().reduce(insert, {})
7068
: value;
7169
};
70+
71+
module.exports = {
72+
parseFiles,
73+
parseFoldersToGlobs,
74+
jsonStringifyReplacerSortKeys,
75+
};

test/cjs.test.js

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

0 commit comments

Comments
 (0)