1
1
import * as config from "@css-blocks/config" ;
2
- import { AnalysisOptions , Block , BlockCompiler , BlockFactory , Configuration , NodeJsImporter , Options as ParserOptions , OutputMode , resolveConfiguration } from "@css-blocks/core" ;
2
+ import { AnalysisOptions , Block , BlockCompiler , BlockDefinitionCompiler , BlockFactory , Configuration , INLINE_DEFINITION_FILE , NodeJsImporter , Options as ParserOptions , OutputMode , resolveConfiguration } from "@css-blocks/core" ;
3
3
import type { ASTPlugin , ASTPluginEnvironment } from "@glimmer/syntax" ;
4
4
import { ObjectDictionary } from "@opticss/util" ;
5
5
import BroccoliDebug = require( "broccoli-debug" ) ;
@@ -112,17 +112,23 @@ class CSSBlocksTemplateCompilerPlugin extends TemplateCompilerPlugin {
112
112
}
113
113
}
114
114
let compiler = new BlockCompiler ( postcss , this . parserOpts ) ;
115
+ compiler . setDefinitionCompiler ( new BlockDefinitionCompiler ( postcss , ( _b , p ) => { return p . replace ( ".block.css" , ".css" ) ; } , this . parserOpts ) ) ;
115
116
for ( let block of blocks ) {
116
117
let outputPath = getOutputPath ( block ) ;
118
+ // Skip processing if we don't get an output path. This happens for files that
119
+ // get referenced in @block from node_modules.
120
+ if ( outputPath === null ) {
121
+ continue ;
122
+ }
117
123
blockOutputPaths . set ( block , outputPath ) ;
118
124
if ( ! block . stylesheet ) {
119
125
throw new Error ( "[internal error] block stylesheet expected." ) ;
120
126
}
121
- // TODO generate definition file too1
122
- let compiledAST = compiler . compile ( block , block . stylesheet , this . analyzingRewriter . reservedClassNames ( ) ) ;
127
+ // TODO - allow for inline definitions or files, by user option
128
+ let { css : compiledAST } = compiler . compileWithDefinition ( block , block . stylesheet , this . analyzingRewriter . reservedClassNames ( ) , INLINE_DEFINITION_FILE ) ;
123
129
// TODO disable source maps in production?
124
130
let result = compiledAST . toResult ( { to : outputPath , map : { inline : true } } ) ;
125
- this . output . writeFileSync ( outputPath , wrapCSSWithDelimiterComments ( block . guid , result . css ) , "utf8" ) ;
131
+ this . output . writeFileSync ( outputPath , result . css , "utf8" ) ;
126
132
}
127
133
for ( let analysis of analyses ) {
128
134
let analysisOutputPath = analysisPath ( analysis . template . relativePath ) ;
@@ -136,23 +142,18 @@ class CSSBlocksTemplateCompilerPlugin extends TemplateCompilerPlugin {
136
142
}
137
143
}
138
144
139
- // This is a placeholder, eventually the block compiler should add this.
140
- function wrapCSSWithDelimiterComments ( guid : string , css : string ) {
141
- return `/*#css-blocks ${ guid } */\n${ css } \n/*#css-blocks end*/\n` ;
142
- }
143
-
144
145
function analysisPath ( templatePath : string ) : string {
145
146
let analysisPath = path . parse ( templatePath ) ;
146
147
delete analysisPath . base ;
147
148
analysisPath . ext = ".block-analysis.json" ;
148
149
return path . format ( analysisPath ) ;
149
150
}
150
151
151
- function getOutputPath ( block : Block ) : string {
152
+ function getOutputPath ( block : Block ) : string | null {
152
153
if ( isBroccoliTreeIdentifier ( block . identifier ) ) {
153
154
return identToPath ( block . identifier ) . replace ( ".block" , "" ) ;
154
155
} else {
155
- throw new Error ( "Implement me!" ) ;
156
+ return null ;
156
157
}
157
158
}
158
159
0 commit comments