@@ -22,6 +22,7 @@ import {
22
22
} from "@glimmer/syntax" ;
23
23
import { assertNever } from "@opticss/util" ;
24
24
import * as debugGenerator from "debug" ;
25
+ import * as path from "path" ;
25
26
26
27
const enum StyleCondition {
27
28
STATIC = 1 ,
@@ -100,21 +101,30 @@ export class TemplateAnalyzingRewriter implements ASTPluginWithDeps {
100
101
get name ( ) : string { return this . block ? "css-blocks-glimmer-rewriter" : "css-blocks-noop" ; }
101
102
102
103
/**
103
- * @param _relativePath Unused in this implementation.
104
+ * @param relativePath the relative path to the template starting at the root
105
+ * of the input tree.
104
106
* @returns Files this template file depends on.
105
107
*/
106
- dependencies ( _relativePath : string ) : Array < string > {
107
- this . debug ( "Getting dependencies for" , _relativePath ) ;
108
+ dependencies ( relativePath : string ) : Array < string > {
109
+ this . debug ( "Getting dependencies for" , relativePath ) ;
108
110
if ( ! this . block ) return [ ] ;
109
111
110
112
let deps : Set < string > = new Set ( ) ;
111
- // let importer = this.cssBlocksOpts.importer;
112
- for ( let block of this . block . transitiveBlockDependencies ( ) ) {
113
+ let importer = this . cssBlocksOpts . importer ;
114
+ for ( let block of [ this . block , ... this . block . transitiveBlockDependencies ( ) ] ) {
113
115
// TODO: Figure out why the importer is returning null here.
114
- // let blockFile = importer.filesystemPath(block.identifier, this.cssBlocksOpts);
115
- let blockFile = block . identifier ;
116
+ let blockFile = importer . filesystemPath ( block . identifier , this . cssBlocksOpts ) ;
117
+
116
118
this . debug ( "block file path is" , blockFile ) ;
117
119
if ( blockFile ) {
120
+ if ( ! path . isAbsolute ( blockFile ) ) {
121
+ // this isn't actually relative to the rootDir but it doesn't matter
122
+ // because the shared root directory will be removed by the relative
123
+ // path calculation.
124
+ let templatePath = path . dirname ( path . resolve ( this . cssBlocksOpts . rootDir , relativePath ) ) ;
125
+ let blockPath = path . resolve ( this . cssBlocksOpts . rootDir , blockFile ) ;
126
+ blockFile = path . relative ( templatePath , blockPath ) ;
127
+ }
118
128
deps . add ( blockFile ) ;
119
129
}
120
130
// These dependencies happen when additional files get involved via preprocessors.
0 commit comments