1
- import { exitFail , exitPass } from './lib/exit'
2
- import { readOrWriteFile , safelyReadFile , writeFile } from './lib/utils'
3
- import * as log from './lib/log '
4
- import getErrorMessage from './lib/get-error-message '
5
- import getOptions from './lib/get-options '
1
+ import * as exit from './lib/exit.js '
2
+ import { readOrWriteFile , safelyReadFile , writeFile } from './lib/utils.js '
3
+ import { getErrorMessage } from './lib/get-error-message.js '
4
+ import { getOptions } from './lib/get-options.js '
5
+ import * as log from './lib/log.js '
6
6
import path from 'path'
7
7
8
- async function postcss8 ( plugins ) {
8
+ const postcss8 = async ( plugins ) => {
9
9
const pkg = await import ( 'postcss/package.json' )
10
+
10
11
if ( pkg . version [ 0 ] === '8' ) {
11
12
const m = await import ( 'postcss' )
12
13
return m . default ( plugins )
@@ -15,9 +16,7 @@ async function postcss8(plugins) {
15
16
}
16
17
}
17
18
18
- function isPostcss8Plugin ( plugin ) {
19
- return typeof plugin === 'function' && Object ( plugin ) . postcss === true
20
- }
19
+ const isPostcss8Plugin = ( plugin ) => typeof plugin === 'function' && Object ( plugin ) . postcss === true
21
20
22
21
getOptions ( ) . then (
23
22
async options => {
@@ -39,9 +38,11 @@ getOptions().then(
39
38
const pluginOptions = test . options
40
39
41
40
let rawPlugin = test . plugin || options . plugin
41
+
42
42
if ( rawPlugin . default ) {
43
43
rawPlugin = rawPlugin . default
44
44
}
45
+
45
46
const plugin = isPostcss8Plugin ( rawPlugin )
46
47
? rawPlugin ( pluginOptions )
47
48
: typeof Object ( rawPlugin ) . process === 'function'
@@ -63,12 +64,15 @@ getOptions().then(
63
64
const sourceCSS = await readOrWriteFile ( sourcePath , expectCSS )
64
65
65
66
let result
67
+
66
68
if ( isPostcss8Plugin ( rawPlugin ) ) {
67
69
const postcss = await postcss8 ( [ plugin ] )
70
+
68
71
result = await postcss . process ( sourceCSS , processOptions )
69
72
} else {
70
73
result = await plugin . process ( sourceCSS , processOptions , pluginOptions )
71
74
}
75
+
72
76
const resultCSS = result . css
73
77
74
78
if ( options . fix ) {
@@ -168,6 +172,5 @@ getOptions().then(
168
172
throw hadError
169
173
}
170
174
}
171
- ) . then ( exitPass , exitFail )
172
-
175
+ ) . then ( exit . pass , exit . fail )
173
176
0 commit comments