stylelint-webpack-plugin 2.1.0 → 2.2.2

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.
@@ -1,118 +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
- /** @typedef {import('webpack').Compiler} Compiler */
17
-
18
- /** @typedef {import('./getOptions').Options} Options */
19
-
20
- /** @typedef {import('./linter').Lint} Lint */
21
-
22
- /** @typedef {import('./linter').LinterCallback} LinterCallback */
23
-
24
- /** @typedef {Partial<{timestamp:number} | number>} FileSystemInfoEntry */
25
- class LintDirtyModulesPlugin {
26
- /**
27
- * @param {Lint} lint
28
- * @param {Compiler} compiler
29
- * @param {Options} options
30
- */
31
- constructor(lint, compiler, options) {
32
- this.lint = lint;
33
- this.compiler = compiler;
34
- this.options = options;
35
- this.startTime = Date.now();
36
- this.prevTimestamps = new Map();
37
- this.isFirstRun = true;
38
- }
39
- /**
40
- * @param {Compiler} compilation
41
- * @param {LinterCallback} callback
42
- * @returns {void}
43
- */
44
-
45
-
46
- apply(compilation, callback) {
47
- const fileTimestamps = compilation.fileTimestamps || new Map();
48
-
49
- if (this.isFirstRun) {
50
- this.isFirstRun = false;
51
- this.prevTimestamps = fileTimestamps;
52
- callback();
53
- return;
54
- }
55
-
56
- const dirtyOptions = { ...this.options
57
- }; // @ts-ignore
58
-
59
- const glob = (0, _utils.replaceBackslashes)(dirtyOptions.files.join('|'));
60
- const changedFiles = this.getChangedFiles(fileTimestamps, glob);
61
- this.prevTimestamps = fileTimestamps;
62
-
63
- if (changedFiles.length) {
64
- dirtyOptions.files = changedFiles;
65
- (0, _linter.default)(this.lint, dirtyOptions, this.compiler, callback);
66
- } else {
67
- callback();
68
- }
69
- }
70
- /**
71
- * @param {Map<string, number>} fileTimestamps
72
- * @param {string | ReadonlyArray<string>} glob
73
- * @returns {Array<string>}
74
- */
75
-
76
-
77
- getChangedFiles(fileTimestamps, glob) {
78
- /**
79
- * @param {FileSystemInfoEntry} fileSystemInfoEntry
80
- * @returns {Partial<number>}
81
- */
82
- const getTimestamps = fileSystemInfoEntry => {
83
- // @ts-ignore
84
- if (fileSystemInfoEntry && fileSystemInfoEntry.timestamp) {
85
- // @ts-ignore
86
- return fileSystemInfoEntry.timestamp;
87
- } // @ts-ignore
88
-
89
-
90
- return fileSystemInfoEntry;
91
- };
92
- /**
93
- * @param {string} filename
94
- * @param {FileSystemInfoEntry} fileSystemInfoEntry
95
- * @returns {boolean}
96
- */
97
-
98
-
99
- const hasFileChanged = (filename, fileSystemInfoEntry) => {
100
- const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
101
- const timestamp = getTimestamps(fileSystemInfoEntry);
102
- return (prevTimestamp || this.startTime) < (timestamp || Infinity);
103
- };
104
-
105
- const changedFiles = [];
106
-
107
- for (const [filename, timestamp] of fileTimestamps.entries()) {
108
- if (hasFileChanged(filename, timestamp) && (0, _micromatch.isMatch)(filename, glob)) {
109
- changedFiles.push((0, _utils.replaceBackslashes)(filename));
110
- }
111
- }
112
-
113
- return changedFiles;
114
- }
115
-
116
- }
117
-
118
- exports.default = LintDirtyModulesPlugin;
@@ -1,74 +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
- /** @typedef {import("stylelint")} stylelint */
15
-
16
- /**
17
- * @typedef {Object} Options
18
- * @property {string=} context
19
- * @property {boolean=} emitError
20
- * @property {boolean=} emitWarning
21
- * @property {boolean=} failOnError
22
- * @property {boolean=} failOnWarning
23
- * @property {Array<string> | string} files
24
- * @property {Function | string} formatter
25
- * @property {boolean=} lintDirtyModulesOnly
26
- * @property {boolean=} quiet
27
- * @property {string} stylelintPath
28
- */
29
-
30
- /**
31
- * @param {Partial<Options>} pluginOptions
32
- * @returns {Options}
33
- */
34
- function getOptions(pluginOptions) {
35
- const options = {
36
- files: '**/*.s?(c|a)ss',
37
- formatter: 'string',
38
- stylelintPath: 'stylelint',
39
- ...pluginOptions
40
- }; // @ts-ignore
41
-
42
- (0, _schemaUtils.default)(_options.default, options, {
43
- name: 'Stylelint Webpack Plugin',
44
- baseDataPath: 'options'
45
- }); // eslint-disable-next-line
46
-
47
- const stylelint = require(options.stylelintPath);
48
-
49
- options.formatter = getFormatter(stylelint, options.formatter);
50
- return options;
51
- }
52
- /**
53
- * @param {stylelint} stylelint
54
- * @param {Function | string} formatter
55
- * @returns {Function}
56
- */
57
-
58
-
59
- function getFormatter({
60
- formatters
61
- }, formatter) {
62
- if (typeof formatter === 'function') {
63
- return formatter;
64
- } // Try to get oficial formatter
65
-
66
-
67
- if (typeof formatter === 'string' && // @ts-ignore
68
- typeof formatters[formatter] === 'function') {
69
- // @ts-ignore
70
- return formatters[formatter];
71
- }
72
-
73
- return formatters.string;
74
- }