1
1
'use strict' ;
2
2
3
3
const fs = require ( 'fs' ) ;
4
- const fse = require ( 'fs-extra' ) ;
5
4
const childProcess = require ( 'child_process' ) ;
6
5
const pkg = require ( '../package.json' ) ;
7
6
8
- const version = pkg . dependencies . stylelint . match ( / [ \d . ] + / ) [ 0 ] ;
7
+ const version = pkg . version . match ( / [ \d . ] + / ) [ 0 ] ;
9
8
const src = 'node_modules/stylelint/' ;
10
9
11
10
const remove = [
@@ -16,7 +15,6 @@ const remove = [
16
15
'lib/rules/property-no-vendor-prefix' ,
17
16
'lib/rules/selector-no-vendor-prefix' ,
18
17
'lib/rules/value-no-vendor-prefix' ,
19
- 'lib/formatters/disableOptionsReportStringFormatter.js' ,
20
18
'lib/formatters/stringFormatter.js' ,
21
19
'lib/formatters/verboseFormatter.js' ,
22
20
] ;
@@ -40,9 +38,9 @@ const modify = {
40
38
'lib/createStylelint.js' : file => replaceBlocks ( file , [
41
39
[
42
40
/ c o n s t g e t C o n f i g F o r F i l e = r e q u i r e .+ / ,
43
- `const getConfigForFile = ${ async stylelint => ( {
41
+ `const getConfigForFile = async stylelint => ({
44
42
config: require('./normalizeAllRuleSettings')(stylelint._options.config),
45
- } ) } ;`,
43
+ });` ,
46
44
] , [
47
45
/ c o n s t i s P a t h I g n o r e d = r e q u i r e .+ / ,
48
46
'const isPathIgnored = async () => false;' ,
@@ -52,14 +50,8 @@ const modify = {
52
50
] ) ,
53
51
54
52
'lib/getPostcssResult.js' : file => replaceBlocks ( file , [
55
- / c o n s t f s = r e q u i r e .+ / ,
56
- [
57
- / c o n s t a u t o S y n t a x = .+ / ,
58
- `const autoSyntax = ${ config => config . css } ;` ,
59
- ] , [
60
- / f u n c t i o n r e a d F i l e [ \s \S ] * ?\n } / ,
61
- 'function readFile(){}' ,
62
- ] ,
53
+ / c o n s t { p r o m i s e s : f s } = r e q u i r e .+ / ,
54
+ / g e t C o d e = a w a i t f s \. r e a d F i l e .+ / ,
63
55
] ) ,
64
56
65
57
'lib/standalone.js' : file => replaceBlocks ( file , [
@@ -72,36 +64,22 @@ const modify = {
72
64
'fs' ,
73
65
'globby' ,
74
66
'hash' ,
75
- 'pify' ,
67
+ 'normalizePath' ,
68
+ 'path' ,
76
69
'pkg' ,
77
70
'writeFileAtomic' ,
78
71
] . join ( '|' ) } ) = require.+`, 'g' ) ,
79
- new RegExp ( `${ [
80
- 'ignoreText = fs\\..+' ,
81
- 'if \\(readError\\.code !==.+' ,
82
- ] . join ( '|' ) } `, 'g' ) ,
72
+ / i g n o r e r = g e t F i l e I g n o r e r .+ / ,
73
+ / l e t f i l e L i s t = .+ ?(? = \n } ) / s,
83
74
[
84
- / ( c o n s t a b s o l u t e I g n o r e F i l e P a t h = p a t h \. i s A b s o l u t e \( i g n o r e F i l e P a t h \) \s * \? i g n o r e F i l e P a t h \s * : p a t h \. r e s o l v e \( p r o c e s s .c w d \( \) , i g n o r e F i l e P a t h \) ; ) / ,
85
- ' const absoluteIgnoreFilePath = ignoreFilePath;' ,
86
- ] , [
87
- / ( c o n s t a b s o l u t e C o d e F i l e n a m e = \s * c o d e F i l e n a m e ! = = u n d e f i n e d & & ! p a t h \. i s A b s o l u t e \( c o d e F i l e n a m e \) \s * \? p a t h \. j o i n \( p r o c e s s \. c w d \( \) , c o d e F i l e n a m e \) \s * : c o d e F i l e n a m e ; ) / ,
88
- ' const absoluteCodeFilename = codeFilename;' ,
89
- ] , [
90
- / l e t f i l e L i s t = f i l e s ; ( \r ? \n (? ! } ) .* ) + / ,
91
- 'return ""' ,
75
+ / \b p a t h \. \w + \( [ ^ ( ) ] * \) / ,
76
+ 'true' ,
92
77
] , [
93
78
/ & & \s + ! f i l t e r F i l e P a t h s .+ / ,
94
79
'&& false' ,
95
- ] , [
96
- / \/ \/ C h e c k f o r f i l e e x i s t e n c e \n \s + r e t u r n n e w P r o m i s e [ \s \S ] + ?(? = \. t h e n \( ) / ,
97
- 'return Promise.resolve()' ,
98
80
] ,
99
81
] ) ,
100
82
101
- 'lib/syntaxes/index.js' : file => replaceBlocks ( file , [
102
- / ( ' c s s - i n - j s ' | h t m l | m a r k d o w n | s a s s | s c s s ) : \s .+ / g,
103
- ] ) . replace ( / i m p o r t L a z y \( / g, 'require(' ) ,
104
-
105
83
'package.json' : file => {
106
84
const json = JSON . parse ( file ) ;
107
85
for ( const name of [
@@ -135,14 +113,10 @@ function replaceBlocks(file, blocks) {
135
113
return file ;
136
114
}
137
115
138
- fse . removeSync ( src ) ;
116
+ fs . rmSync ( src , { force : true , recursive : true } ) ;
139
117
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
- }
144
118
145
- remove . forEach ( name => fse . removeSync ( src + name ) ) ;
119
+ remove . forEach ( name => fs . rmSync ( src + name , { recursive : true } ) ) ;
146
120
Object . entries ( modify ) . forEach ( ( [ name , modifier ] ) => {
147
121
fs . writeFileSync ( src + name , modifier ( fs . readFileSync ( src + name , 'utf8' ) ) ) ;
148
122
} ) ;
0 commit comments