stylelint-webpack-plugin 1.2.3 → 2.2.0

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,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getOptions = getOptions;
7
+ exports.getStylelintOptions = getStylelintOptions;
8
+
9
+ var _schemaUtils = require("schema-utils");
10
+
11
+ var _options = _interopRequireDefault(require("./options.json"));
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ // @ts-ignore
16
+
17
+ /** @typedef {import("stylelint")} stylelint */
18
+
19
+ /** @typedef {import("stylelint").LinterOptions} StylelintOptions */
20
+
21
+ /** @typedef {import("stylelint").FormatterType} FormatterType */
22
+
23
+ /**
24
+ * @typedef {Object} OutputReport
25
+ * @property {string=} filePath
26
+ * @property {FormatterType=} formatter
27
+ */
28
+
29
+ /**
30
+ * @typedef {Object} PluginOptions
31
+ * @property {string} context
32
+ * @property {boolean} emitError
33
+ * @property {boolean} emitWarning
34
+ * @property {string|string[]=} exclude
35
+ * @property {string|string[]} extensions
36
+ * @property {boolean} failOnError
37
+ * @property {boolean} failOnWarning
38
+ * @property {string|string[]} files
39
+ * @property {FormatterType} formatter
40
+ * @property {boolean} lintDirtyModulesOnly
41
+ * @property {boolean} quiet
42
+ * @property {string} stylelintPath
43
+ * @property {OutputReport} outputReport
44
+ * @property {number|boolean=} threads
45
+ */
46
+
47
+ /** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
48
+
49
+ /**
50
+ * @param {Options} pluginOptions
51
+ * @returns {Partial<PluginOptions>}
52
+ */
53
+ function getOptions(pluginOptions) {
54
+ const options = {
55
+ extensions: ['css', 'scss', 'sass'],
56
+ emitError: true,
57
+ emitWarning: true,
58
+ failOnError: true,
59
+ ...pluginOptions,
60
+ ...(pluginOptions.quiet ? {
61
+ emitError: true,
62
+ emitWarning: false
63
+ } : {})
64
+ }; // @ts-ignore
65
+
66
+ (0, _schemaUtils.validate)(_options.default, options, {
67
+ name: 'Stylelint Webpack Plugin',
68
+ baseDataPath: 'options'
69
+ });
70
+ return options;
71
+ }
72
+ /**
73
+ * @param {Options} pluginOptions
74
+ * @returns {Partial<StylelintOptions>}
75
+ */
76
+
77
+
78
+ function getStylelintOptions(pluginOptions) {
79
+ const stylelintOptions = { ...pluginOptions
80
+ }; // Keep the files and formatter option because it is common to both the plugin and Stylelint.
81
+
82
+ const {
83
+ files,
84
+ formatter,
85
+ ...stylelintOnlyOptions
86
+ } = _options.default.properties; // No need to guard the for-in because schema.properties has hardcoded keys.
87
+ // eslint-disable-next-line guard-for-in
88
+
89
+ for (const option in stylelintOnlyOptions) {
90
+ // @ts-ignore
91
+ delete stylelintOptions[option];
92
+ }
93
+
94
+ return stylelintOptions;
95
+ }
package/dist/options.json CHANGED
@@ -7,15 +7,23 @@
7
7
  "type": "string"
8
8
  },
9
9
  "emitError": {
10
- "description": "Will always return errors, if set to `true`.",
10
+ "description": "The errors found will always be emitted, to disable set to `false`.",
11
11
  "type": "boolean"
12
12
  },
13
13
  "emitWarning": {
14
- "description": "Will always return warnings, if set to `true`.",
14
+ "description": "The warnings found will always be emitted, to disable set to `false`.",
15
15
  "type": "boolean"
16
16
  },
17
+ "exclude": {
18
+ "description": "Specify the files and/or directories to exclude. Must be relative to `options.context`.",
19
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
20
+ },
21
+ "extensions": {
22
+ "description": "Specify extensions that should be checked.",
23
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
24
+ },
17
25
  "failOnError": {
18
- "description": "Will cause the module build to fail if there are any errors, if set to `true`.",
26
+ "description": "Will cause the module build to fail if there are any errors, to disable set to `false`.",
19
27
  "type": "boolean"
20
28
  },
21
29
  "failOnWarning": {
@@ -23,7 +31,7 @@
23
31
  "type": "boolean"
24
32
  },
25
33
  "files": {
26
- "description": "Specify the glob pattern for finding files. Must be relative to `options.context`.",
34
+ "description": "Specify directories, files, or globs. Must be relative to `options.context`. Directories are traveresed recursively looking for files matching `options.extensions`. File and glob patterns ignore `options.extensions`.",
27
35
  "anyOf": [{ "type": "string" }, { "type": "array" }]
28
36
  },
29
37
  "formatter": {
@@ -41,6 +49,32 @@
41
49
  "stylelintPath": {
42
50
  "description": "Path to `stylelint` instance that will be used for linting.",
43
51
  "type": "string"
52
+ },
53
+ "outputReport": {
54
+ "description": "Write the output of the errors to a file, for example a `json` file for use for reporting.",
55
+ "anyOf": [
56
+ {
57
+ "type": "boolean"
58
+ },
59
+ {
60
+ "type": "object",
61
+ "additionalProperties": false,
62
+ "properties": {
63
+ "filePath": {
64
+ "description": "The `filePath` is relative to the webpack config: `output.path`.",
65
+ "anyOf": [{ "type": "string" }]
66
+ },
67
+ "formatter": {
68
+ "description": "You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.",
69
+ "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
70
+ }
71
+ }
72
+ }
73
+ ]
74
+ },
75
+ "threads": {
76
+ "description": "Set to true for an auto-selected pool size based on number of cpus. Set to a number greater than 1 to set an explicit pool size. Set to false, 1, or less to disable and only run in main process.",
77
+ "anyOf": [{ "type": "number" }, { "type": "boolean" }]
44
78
  }
45
79
  }
46
80
  }
package/dist/utils.js CHANGED
@@ -4,18 +4,81 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.parseFiles = parseFiles;
7
- exports.replaceBackslashes = replaceBackslashes;
7
+ exports.parseFoldersToGlobs = parseFoldersToGlobs;
8
+ exports.jsonStringifyReplacerSortKeys = void 0;
8
9
 
9
10
  var _path = require("path");
10
11
 
12
+ var _fs = require("fs");
13
+
14
+ var _normalizePath = _interopRequireDefault(require("normalize-path"));
15
+
11
16
  var _arrify = _interopRequireDefault(require("arrify"));
12
17
 
13
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
19
 
20
+ // @ts-ignore
21
+ // @ts-ignore
22
+
23
+ /**
24
+ * @param {string|string[]} files
25
+ * @param {string} context
26
+ * @returns {string[]}
27
+ */
15
28
  function parseFiles(files, context) {
16
- return (0, _arrify.default)(files).map(file => replaceBackslashes((0, _path.join)(context, '/', file)));
29
+ return (0, _arrify.default)(files).map((
30
+ /** @type {string} */
31
+ file) => (0, _normalizePath.default)((0, _path.resolve)(context, file)));
17
32
  }
33
+ /**
34
+ * @param {string|string[]} patterns
35
+ * @param {string|string[]} extensions
36
+ * @returns {string[]}
37
+ */
38
+
39
+
40
+ function parseFoldersToGlobs(patterns, extensions = []) {
41
+ const extensionsList = (0, _arrify.default)(extensions);
42
+ const [prefix, postfix] = extensionsList.length > 1 ? ['{', '}'] : ['', ''];
43
+ const extensionsGlob = extensionsList.map((
44
+ /** @type {string} */
45
+ extension) => extension.replace(/^\./u, '')).join(',');
46
+ return (0, _arrify.default)(patterns).map((
47
+ /** @type {string} */
48
+ pattern) => {
49
+ try {
50
+ // The patterns are absolute because they are prepended with the context.
51
+ const stats = (0, _fs.statSync)(pattern);
52
+ /* istanbul ignore else */
53
+
54
+ if (stats.isDirectory()) {
55
+ return pattern.replace(/[/\\]*?$/u, `/**${extensionsGlob ? `/*.${prefix + extensionsGlob + postfix}` : ''}`);
56
+ }
57
+ } catch (_) {// Return the pattern as is on error.
58
+ }
59
+
60
+ return pattern;
61
+ });
62
+ }
63
+ /**
64
+ *
65
+ * @param {string} _ key, but unused
66
+ * @param {any} value
67
+ */
68
+
69
+
70
+ const jsonStringifyReplacerSortKeys = (_, value) => {
71
+ /**
72
+ * @param {{ [x: string]: any; }} sorted
73
+ * @param {string | number} key
74
+ */
75
+ const insert = (sorted, key) => {
76
+ // eslint-disable-next-line no-param-reassign
77
+ sorted[key] = value[key];
78
+ return sorted;
79
+ };
80
+
81
+ return value instanceof Object && !(value instanceof Array) ? Object.keys(value).sort().reduce(insert, {}) : value;
82
+ };
18
83
 
19
- function replaceBackslashes(str) {
20
- return str.replace(/\\/g, '/');
21
- }
84
+ exports.jsonStringifyReplacerSortKeys = jsonStringifyReplacerSortKeys;
package/dist/worker.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ /** @typedef {import('stylelint')} Stylelint */
4
+
5
+ /** @typedef {import("stylelint").LinterOptions} StylelintOptions */
6
+
7
+ /** @typedef {import('./options').Options} Options */
8
+ Object.assign(module.exports, {
9
+ lintFiles,
10
+ setup
11
+ });
12
+ /** @type {Stylelint} */
13
+
14
+ let stylelint;
15
+ /** @type {Partial<StylelintOptions>} */
16
+
17
+ let linterOptions;
18
+ /**
19
+ * @param {Options} options
20
+ * @param {Partial<StylelintOptions>} stylelintOptions
21
+ */
22
+
23
+ function setup(options, stylelintOptions) {
24
+ stylelint = require(options.stylelintPath || 'stylelint');
25
+ linterOptions = stylelintOptions;
26
+ return stylelint;
27
+ }
28
+ /**
29
+ * @param {string | string[]} files
30
+ */
31
+
32
+
33
+ async function lintFiles(files) {
34
+ const {
35
+ results
36
+ } = await stylelint.lint({ ...linterOptions,
37
+ files
38
+ }); // Reset result to work with worker
39
+
40
+ return results.map(result => {
41
+ return {
42
+ source: result.source,
43
+ errored: result.errored,
44
+ ignored: result.ignored,
45
+ warnings: result.warnings,
46
+ deprecations: result.deprecations,
47
+ invalidOptionWarnings: result.invalidOptionWarnings
48
+ };
49
+ });
50
+ }
package/package.json CHANGED
@@ -1,76 +1,90 @@
1
1
  {
2
2
  "name": "stylelint-webpack-plugin",
3
- "version": "1.2.3",
3
+ "version": "2.2.0",
4
4
  "description": "A Stylelint plugin for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/stylelint-webpack-plugin",
7
- "author": "Javier Sánchez-Marín <javiersanchezmarin@gmail.com>",
7
+ "author": "Ricardo Gobbo de Souza <ricardogobbosouza@yahoo.com.br>",
8
8
  "homepage": "https://github.com/webpack-contrib/stylelint-webpack-plugin",
9
9
  "bugs": "https://github.com/webpack-contrib/stylelint-webpack-plugin/issues",
10
+ "funding": {
11
+ "type": "opencollective",
12
+ "url": "https://opencollective.com/webpack"
13
+ },
10
14
  "main": "dist/cjs.js",
15
+ "types": "declarations/index.d.ts",
11
16
  "engines": {
12
- "node": ">= 8.9.0"
17
+ "node": ">= 10.13.0"
13
18
  },
14
19
  "scripts": {
15
20
  "start": "npm run build -- -w",
21
+ "clean": "del-cli dist declarations",
16
22
  "prebuild": "npm run clean",
17
- "build": "cross-env NODE_ENV=production babel src -d dist --ignore \"src/**/*.test.js\" --copy-files",
18
- "clean": "del-cli dist",
23
+ "build:types": "tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write",
24
+ "build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
25
+ "build": "npm-run-all -p \"build:**\"",
19
26
  "commitlint": "commitlint --from=master",
20
- "lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
21
- "lint:js": "eslint --cache src test",
22
- "lint": "npm-run-all -l -p \"lint:**\"",
23
- "prepare": "npm run build",
24
- "release": "standard-version",
25
27
  "security": "npm audit",
26
- "test:only": "cross-env NODE_ENV=test jest",
27
- "test:watch": "cross-env NODE_ENV=test jest --watch",
28
- "test:coverage": "cross-env NODE_ENV=test jest --collectCoverageFrom=\"src/**/*.js\" --coverage",
28
+ "lint:prettier": "prettier -w --list-different .",
29
+ "lint:js": "eslint --cache .",
30
+ "lint:types": "tsc --pretty --noEmit",
31
+ "lint": "npm-run-all -l -p \"lint:**\"",
32
+ "test:only": "cross-env NODE_ENV=test jest --testTimeout=60000",
33
+ "test:watch": "npm run test:only -- --watch",
34
+ "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
29
35
  "pretest": "npm run lint",
30
- "test": "cross-env NODE_ENV=test npm run test:coverage",
31
- "defaults": "webpack-defaults"
36
+ "test": "npm run test:coverage",
37
+ "prepare": "husky install && npm run build",
38
+ "release": "standard-version"
32
39
  },
33
40
  "files": [
34
- "dist"
41
+ "dist",
42
+ "declarations"
35
43
  ],
36
44
  "peerDependencies": {
37
- "stylelint": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
45
+ "stylelint": "^13.0.0",
38
46
  "webpack": "^4.0.0 || ^5.0.0"
39
47
  },
40
48
  "dependencies": {
49
+ "@types/stylelint": "^13.13.0",
41
50
  "arrify": "^2.0.1",
42
- "micromatch": "^4.0.2",
43
- "schema-utils": "^2.6.1"
51
+ "fast-glob": "^3.2.5",
52
+ "jest-worker": "^27.0.2",
53
+ "micromatch": "^4.0.4",
54
+ "normalize-path": "^3.0.0",
55
+ "schema-utils": "^3.0.0"
44
56
  },
45
57
  "devDependencies": {
46
- "@babel/cli": "^7.7.4",
47
- "@babel/core": "^7.7.4",
48
- "@babel/preset-env": "^7.7.4",
49
- "@commitlint/cli": "^8.2.0",
50
- "@commitlint/config-conventional": "^8.2.0",
51
- "@webpack-contrib/defaults": "^5.1.1",
58
+ "@babel/cli": "^7.14.5",
59
+ "@babel/core": "^7.14.6",
60
+ "@babel/preset-env": "^7.14.5",
61
+ "@commitlint/cli": "^12.1.4",
62
+ "@commitlint/config-conventional": "^12.1.4",
63
+ "@types/fs-extra": "^9.0.11",
64
+ "@types/micromatch": "^4.0.1",
65
+ "@types/normalize-path": "^3.0.0",
66
+ "@types/webpack": "^5.28.0",
52
67
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
53
- "babel-eslint": "^10.0.3",
54
- "babel-jest": "^24.9.0",
55
- "commitlint-azure-pipelines-cli": "^1.0.2",
56
- "cross-env": "^6.0.3",
57
- "del": "^5.1.0",
58
- "del-cli": "^3.0.0",
59
- "eslint": "^6.7.2",
60
- "eslint-config-prettier": "^6.7.0",
61
- "eslint-friendly-formatter": "^4.0.1",
62
- "eslint-plugin-import": "^2.18.2",
63
- "file-loader": "^5.0.2",
64
- "husky": "^3.1.0",
65
- "jest": "^24.9.0",
66
- "jest-junit": "^10.0.0",
67
- "lint-staged": "^9.5.0",
68
- "mkdirp": "^0.5.1",
68
+ "babel-eslint": "^10.1.0",
69
+ "babel-jest": "^27.0.2",
70
+ "chokidar": "^3.5.2",
71
+ "cross-env": "^7.0.3",
72
+ "del": "^6.0.0",
73
+ "del-cli": "^3.0.1",
74
+ "eslint": "^7.28.0",
75
+ "eslint-config-prettier": "^8.3.0",
76
+ "eslint-plugin-import": "^2.23.4",
77
+ "file-loader": "^6.2.0",
78
+ "fs-extra": "^9.1.0",
79
+ "husky": "^6.0.0",
80
+ "jest": "^27.0.4",
81
+ "lint-staged": "^10.5.4",
69
82
  "npm-run-all": "^4.1.5",
70
- "prettier": "^1.19.1",
71
- "standard-version": "^7.0.1",
72
- "stylelint": "^12.0.0",
73
- "webpack": "^4.41.2"
83
+ "prettier": "^2.3.1",
84
+ "standard-version": "^9.3.0",
85
+ "stylelint": "^13.13.1",
86
+ "typescript": "^4.3.2",
87
+ "webpack": "^5.39.0"
74
88
  },
75
89
  "keywords": [
76
90
  "stylelint",
package/CHANGELOG.md DELETED
@@ -1,101 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
-
5
- ### [1.2.3](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.2...v1.2.3) (2020-02-08)
6
-
7
- ### [1.2.2](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.1...v1.2.2) (2020-02-08)
8
-
9
-
10
- ### Bug Fixes
11
-
12
- * replace back slashes on changed files ([#206](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/206)) ([7508028](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/7508028398d366c37d1a14e254baec9dc39b816c))
13
-
14
- ### [1.2.1](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.0...v1.2.1) (2020-01-16)
15
-
16
-
17
- ### Bug Fixes
18
-
19
- * compatibility stylelint v13 ([#204](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/204)) ([483be31](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/483be318450ec9a4f9eeb4bf1b1db203ba0c863d))
20
-
21
- ## [1.2.0](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.1.2...v1.2.0) (2020-01-13)
22
-
23
-
24
- ### Features
25
-
26
- * make possible to define official formatter as string ([#202](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/202)) ([8d6599c](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/8d6599c3f2f0e26d1515b01f6ecbafabeaa68fac))
27
- * support stylelint v13 ([#203](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/203)) ([6fb31a3](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/6fb31a3931cb9d7cb0ce8cc99c9db28f928c82f4))
28
-
29
- ### [1.1.2](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.1.1...v1.1.2) (2019-12-04)
30
-
31
-
32
- ### Bug Fixes
33
-
34
- * support webpack 5 ([#199](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/199)) ([3d9e544](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/3d9e544f31172b7c01f4bd7c7254cfc7e38466c9))
35
-
36
- ### [1.1.1](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.1.0...v1.1.1) (2019-12-01)
37
-
38
-
39
- ### Bug Fixes
40
-
41
- * use hook `afterEmit` and emit error on catch ([17f7421](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/17f7421030e6a5b589b2cab015d9af80b868ca95))
42
-
43
- ## [1.1.0](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.0.4...v1.1.0) (2019-11-18)
44
-
45
-
46
- ### Features
47
-
48
- * support stylelint v12 ([#196](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/196)) ([aacf7ad](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/aacf7ad))
49
-
50
- ### [1.0.4](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.0.3...v1.0.4) (2019-11-13)
51
-
52
-
53
- ### Bug Fixes
54
-
55
- * hooks ([#195](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/195)) ([792fe19](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/792fe19))
56
-
57
- ### [1.0.3](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.0.2...v1.0.3) (2019-10-25)
58
-
59
-
60
- ### Bug Fixes
61
-
62
- * options variable ([#193](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/193)) ([3389aec](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/3389aec))
63
-
64
- ### [1.0.2](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.0.1...v1.0.2) (2019-10-07)
65
-
66
-
67
- ### Bug Fixes
68
-
69
- * convert back-slashes ([#186](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/186)) ([41b0f53](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/41b0f53))
70
-
71
- ### [1.0.1](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.0.0...v1.0.1) (2019-09-30)
72
-
73
-
74
- ### Bug Fixes
75
-
76
- * compiler hooks ([aca2c1d](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/aca2c1d))
77
-
78
- ## 1.0.0 (2019-09-30)
79
-
80
- ### Bug Fixes
81
-
82
- * Handle compilation.fileTimestamps for webpack 4
83
- * DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
84
- * Update option `emitError`
85
- * Update option `failOnError`
86
-
87
- ### Features
88
-
89
- * Modernize project to latest defaults
90
- * Validate options
91
- * Support absolute paths in files array
92
- * New option `stylelintPath`
93
- * New option `emitWarning`
94
- * New option `failOnWarning`
95
- * New option `quiet`
96
-
97
- ### ⚠ BREAKING CHANGES
98
-
99
- * Drop support for Node < 8.9.0
100
- * Minimum supported `webpack` version is 4
101
- * Minimum supported `stylelint` version is 9
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _micromatch = require("micromatch");
9
-
10
- var _linter = _interopRequireDefault(require("./linter"));
11
-
12
- var _utils = require("./utils");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- class LintDirtyModulesPlugin {
17
- constructor(lint, compiler, options) {
18
- this.lint = lint;
19
- this.compiler = compiler;
20
- this.options = options;
21
- this.startTime = Date.now();
22
- this.prevTimestamps = {};
23
- this.isFirstRun = true;
24
- }
25
-
26
- apply(compilation, callback) {
27
- const fileTimestamps = compilation.fileTimestamps || new Map();
28
-
29
- if (this.isFirstRun) {
30
- this.isFirstRun = false;
31
- this.prevTimestamps = fileTimestamps;
32
- callback();
33
- return;
34
- }
35
-
36
- const dirtyOptions = { ...this.options
37
- };
38
- const glob = (0, _utils.replaceBackslashes)(dirtyOptions.files.join('|'));
39
- const changedFiles = this.getChangedFiles(fileTimestamps, glob);
40
- this.prevTimestamps = fileTimestamps;
41
-
42
- if (changedFiles.length) {
43
- dirtyOptions.files = changedFiles;
44
- (0, _linter.default)(this.lint, dirtyOptions, this.compiler, callback);
45
- } else {
46
- callback();
47
- }
48
- }
49
-
50
- getChangedFiles(fileTimestamps, glob) {
51
- const getTimestamps = fileSystemInfoEntry => {
52
- return fileSystemInfoEntry && fileSystemInfoEntry.timestamp ? fileSystemInfoEntry.timestamp : fileSystemInfoEntry;
53
- };
54
-
55
- const hasFileChanged = (filename, fileSystemInfoEntry) => {
56
- const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
57
- const timestamp = getTimestamps(fileSystemInfoEntry);
58
- return (prevTimestamp || this.startTime) < (timestamp || Infinity);
59
- };
60
-
61
- const changedFiles = [];
62
-
63
- for (const [filename, timestamp] of fileTimestamps.entries()) {
64
- if (hasFileChanged(filename, timestamp) && (0, _micromatch.isMatch)(filename, glob)) {
65
- changedFiles.push((0, _utils.replaceBackslashes)(filename));
66
- }
67
- }
68
-
69
- return changedFiles;
70
- }
71
-
72
- }
73
-
74
- exports.default = LintDirtyModulesPlugin;
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = getOptions;
7
-
8
- var _schemaUtils = _interopRequireDefault(require("schema-utils"));
9
-
10
- var _options = _interopRequireDefault(require("./options.json"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function getOptions(pluginOptions) {
15
- const options = {
16
- files: '**/*.s?(c|a)ss',
17
- formatter: 'string',
18
- stylelintPath: 'stylelint',
19
- ...pluginOptions
20
- };
21
- (0, _schemaUtils.default)(_options.default, options, {
22
- name: 'Stylelint Webpack Plugin',
23
- baseDataPath: 'options'
24
- }); // eslint-disable-next-line
25
-
26
- const stylelint = require(options.stylelintPath);
27
-
28
- options.formatter = getFormatter(stylelint, options.formatter);
29
- return options;
30
- }
31
-
32
- function getFormatter({
33
- formatters
34
- }, formatter) {
35
- if (typeof formatter === 'function') {
36
- return formatter;
37
- } // Try to get oficial formatter
38
-
39
-
40
- if (typeof formatter === 'string' && typeof formatters[formatter] === 'function') {
41
- return formatters[formatter];
42
- }
43
-
44
- return formatters.string;
45
- }