Skip to content

Commit 32f1df3

Browse files
committed
v14.2.0
1 parent 1a64c5f commit 32f1df3

File tree

9 files changed

+30961
-62066
lines changed

9 files changed

+30961
-62066
lines changed

.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://github.com/eslint/eslint/blob/master/docs/rules/README.md
22

33
parserOptions:
4-
ecmaVersion: 2017
4+
ecmaVersion: 2018
55

66
env:
77
node: true

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ This repository branch modifies Stylelint and creates a bundle:
66
* To reduce the file size of the standalone version.
77
* It removes excessive code to make it efficient to use with the [Stylus](https://github.com/openstyles/stylus) browser extension.
88
* Using `browserify -r stylelint -o stylelint-bundle.js`:
9-
* Bundle size before build: `3,862 KB`.
10-
* Bundle size after build: `2,577 KB` (`686 KB` minified)
9+
* Bundle size before build: 3.5+ MB.
10+
* Bundle size after build: 1.5 MB (0.5 MB minified)
1111

1212
## Create the bundle
1313

@@ -60,11 +60,9 @@ The resulting bundle:
6060

6161
## For contributors
6262

63-
To update to a new version of Stylelint specify an **exact version** in package.json `dependencies`:
63+
To update to a new version of Stylelint specify its **exact version** in package.json `version`:
6464

6565
```
66-
"dependencies": {
67-
"stylelint": "13.8.0"
68-
},
66+
"version": "14.2.0",
6967
```
7068
Then run the `build` script. In case of failure update the rules in `build/index.js`.

build/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ browserify(null, {
3535
.on('data', ch => chunks.push(ch))
3636
.on('end', () => {
3737
fse.outputFileSync(pkg.main.replace('.min', ''),
38-
`/*!= Stylelint v${pkg.dependencies.stylelint} bundle =*/\n` +
38+
`/*!= Stylelint v${pkg.version} bundle =*/\n` +
3939
`/* See ${pkg.repository.url.replace('.git', '')} */\n` +
4040
`;(()=>{${babel.transformSync(chunks.join(''), BABEL_OPTS).code}})();`);
4141
});

build/index.js

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
22

33
const fs = require('fs');
4-
const fse = require('fs-extra');
54
const childProcess = require('child_process');
65
const pkg = require('../package.json');
76

8-
const version = pkg.dependencies.stylelint.match(/[\d.]+/)[0];
7+
const version = pkg.version.match(/[\d.]+/)[0];
98
const src = 'node_modules/stylelint/';
109

1110
const remove = [
@@ -16,7 +15,6 @@ const remove = [
1615
'lib/rules/property-no-vendor-prefix',
1716
'lib/rules/selector-no-vendor-prefix',
1817
'lib/rules/value-no-vendor-prefix',
19-
'lib/formatters/disableOptionsReportStringFormatter.js',
2018
'lib/formatters/stringFormatter.js',
2119
'lib/formatters/verboseFormatter.js',
2220
];
@@ -40,9 +38,9 @@ const modify = {
4038
'lib/createStylelint.js': file => replaceBlocks(file, [
4139
[
4240
/const getConfigForFile = require.+/,
43-
`const getConfigForFile = ${async stylelint => ({
41+
`const getConfigForFile = async stylelint => ({
4442
config: require('./normalizeAllRuleSettings')(stylelint._options.config),
45-
})};`,
43+
});`,
4644
], [
4745
/const isPathIgnored = require.+/,
4846
'const isPathIgnored = async () => false;',
@@ -52,14 +50,8 @@ const modify = {
5250
]),
5351

5452
'lib/getPostcssResult.js': file => replaceBlocks(file, [
55-
/const fs = require.+/,
56-
[
57-
/const autoSyntax =.+/,
58-
`const autoSyntax = ${config => config.css};`,
59-
], [
60-
/function readFile[\s\S]*?\n}/,
61-
'function readFile(){}',
62-
],
53+
/const { promises: fs } = require.+/,
54+
/getCode = await fs\.readFile.+/,
6355
]),
6456

6557
'lib/standalone.js': file => replaceBlocks(file, [
@@ -72,36 +64,22 @@ const modify = {
7264
'fs',
7365
'globby',
7466
'hash',
75-
'pify',
67+
'normalizePath',
68+
'path',
7669
'pkg',
7770
'writeFileAtomic',
7871
].join('|')}) = require.+`, 'g'),
79-
new RegExp(`${[
80-
'ignoreText = fs\\..+',
81-
'if \\(readError\\.code !==.+',
82-
].join('|')}`, 'g'),
72+
/ignorer = getFileIgnorer.+/,
73+
/let fileList = .+?(?=\n})/s,
8374
[
84-
/(const absoluteIgnoreFilePath = path\.isAbsolute\(ignoreFilePath\)\s*\? ignoreFilePath\s*: path\.resolve\(process.cwd\(\), ignoreFilePath\);)/,
85-
' const absoluteIgnoreFilePath = ignoreFilePath;',
86-
], [
87-
/(const absoluteCodeFilename =\s*codeFilename !== undefined && !path\.isAbsolute\(codeFilename\)\s*\? path\.join\(process\.cwd\(\), codeFilename\)\s*: codeFilename;)/,
88-
' const absoluteCodeFilename = codeFilename;',
89-
], [
90-
/let fileList = files;(\r?\n(?!}).*)+/,
91-
'return ""',
75+
/\bpath\.\w+\([^()]*\)/,
76+
'true',
9277
], [
9378
/&&\s+!filterFilePaths.+/,
9479
'&& false',
95-
], [
96-
/\/\/ Check for file existence\n\s+return new Promise[\s\S]+?(?=\.then\()/,
97-
'return Promise.resolve()',
9880
],
9981
]),
10082

101-
'lib/syntaxes/index.js': file => replaceBlocks(file, [
102-
/('css-in-js'|html|markdown|sass|scss):\s.+/g,
103-
]).replace(/importLazy\(/g, 'require('),
104-
10583
'package.json': file => {
10684
const json = JSON.parse(file);
10785
for (const name of [
@@ -135,14 +113,10 @@ function replaceBlocks(file, blocks) {
135113
return file;
136114
}
137115

138-
fse.removeSync(src);
116+
fs.rmSync(src, {force: true, recursive: true});
139117
childProcess.execSync('npm install --no-save stylelint@' + version, {stdio: 'inherit'});
140-
if (pkg.version !== version) {
141-
pkg.version = version;
142-
fs.writeFileSync('../package.json', JSON.stringify(pkg, null, 2));
143-
}
144118

145-
remove.forEach(name => fse.removeSync(src + name));
119+
remove.forEach(name => fs.rmSync(src + name, {recursive: true}));
146120
Object.entries(modify).forEach(([name, modifier]) => {
147121
fs.writeFileSync(src + name, modifier(fs.readFileSync(src + name, 'utf8')));
148122
});

build/uglify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
22

33
const fs = require('fs');
4-
const fse = require('fs-extra');
54
const UglifyJS = require('uglify-es');
65
const pkg = require('../package.json');
76

87
const OPTS = {
98
compress: {
109
ecma: 7,
10+
passes: 2,
1111
unsafe_arrows: true,
1212
unsafe_methods: true,
1313
},
@@ -19,4 +19,4 @@ const OPTS = {
1919

2020
const srcCode = fs.readFileSync(pkg.main.replace('.min', ''), 'utf8');
2121
const res = UglifyJS.minify(srcCode, OPTS).code;
22-
fse.outputFileSync(pkg.main, res);
22+
fs.writeFileSync(pkg.main, res, 'utf8');

0 commit comments

Comments
 (0)