1
1
import { postcss } from "opticss" ;
2
2
3
- import { BlockCompiler } from "./BlockCompiler" ;
4
- import { BlockFactory } from "./BlockParser" ;
5
- import { Options , ResolvedConfiguration , resolveConfiguration } from "./configuration" ;
6
- import * as errors from "./errors" ;
3
+ import { BlockCompiler } from "../../src/BlockCompiler" ;
4
+ import { BlockFactory } from "../../src/BlockParser" ;
5
+ import { Configuration , OutputMode } from "../../src/configuration" ;
6
+ import { Options , ResolvedConfiguration , resolveConfiguration } from "../../src/configuration" ;
7
+ import * as errors from "../../src/errors" ;
7
8
8
9
/**
9
10
* CSS Blocks PostCSS plugin.
10
11
*/
11
- export class Plugin {
12
+ class Plugin {
12
13
private config : ResolvedConfiguration ;
13
14
private postcss : typeof postcss ;
14
15
@@ -22,7 +23,7 @@ export class Plugin {
22
23
}
23
24
24
25
/**
25
- * Main processing entrypoint for PostCSS Plugin
26
+ * Main processing entry point for PostCSS Plugin
26
27
* @param root PostCSS AST
27
28
* @param result Provides the result of the PostCSS transformations
28
29
*/
@@ -48,3 +49,31 @@ export class Plugin {
48
49
}
49
50
50
51
}
52
+
53
+ // This is ugly but it's the only thing I have been able to make work.
54
+ // I welcome a patch that cleans this up.
55
+
56
+ type temp = {
57
+ ( postcssImpl : typeof postcss ) : ( config ?: Partial < Readonly < Configuration > > ) => postcss . Plugin < Partial < Readonly < Configuration > > > ;
58
+ OutputMode : typeof OutputMode ;
59
+ CssBlockError : typeof errors . CssBlockError ;
60
+ InvalidBlockSyntax : typeof errors . InvalidBlockSyntax ;
61
+ MissingSourcePath : typeof errors . MissingSourcePath ;
62
+ } ;
63
+
64
+ function makeApi ( ) : temp {
65
+ let cssBlocks : temp ;
66
+ cssBlocks = < temp > function ( postcssImpl : typeof postcss ) {
67
+ return ( config ?: Partial < Readonly < Configuration > > ) => {
68
+ let plugin = new Plugin ( postcssImpl , config ) ;
69
+ return plugin . process . bind ( plugin ) ;
70
+ } ;
71
+ } ;
72
+ cssBlocks . OutputMode = OutputMode ;
73
+ cssBlocks . CssBlockError = errors . CssBlockError ;
74
+ cssBlocks . InvalidBlockSyntax = errors . InvalidBlockSyntax ;
75
+ cssBlocks . MissingSourcePath = errors . MissingSourcePath ;
76
+ return cssBlocks ;
77
+ }
78
+
79
+ export = makeApi ( ) ;
0 commit comments