Skip to content

Commit ea27173

Browse files
committed
fix: Cache invalidation when block files change.
1 parent c3aec23 commit ea27173

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

packages/@css-blocks/ember/src/CSSBlocksTemplateCompilerPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class CSSBlocksTemplateCompilerPlugin extends TemplateCompilerPlugin {
128128
let factory = new BlockFactory(config, postcss);
129129
let fileLocator = new BroccoliFileLocator(this.input);
130130
this.debug(`Looking for templates using css blocks.`);
131-
this.analyzingRewriter = new AnalyzingRewriteManager(factory, fileLocator, this.cssBlocksOptions.analysisOpts || {}, this.parserOpts);
131+
this.analyzingRewriter = new AnalyzingRewriteManager(factory, fileLocator, this.cssBlocksOptions.analysisOpts || {}, config);
132132
// The astPluginBuilder interface isn't async so we have to first load all
133133
// the blocks and associate them to their corresponding templates.
134134
await this.analyzingRewriter.discoverTemplatesWithBlocks();

packages/@css-blocks/ember/src/TemplateAnalyzingRewriter.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from "@glimmer/syntax";
2323
import { assertNever } from "@opticss/util";
2424
import * as debugGenerator from "debug";
25+
import * as path from "path";
2526

2627
const enum StyleCondition {
2728
STATIC = 1,
@@ -100,21 +101,30 @@ export class TemplateAnalyzingRewriter implements ASTPluginWithDeps {
100101
get name(): string { return this.block ? "css-blocks-glimmer-rewriter" : "css-blocks-noop"; }
101102

102103
/**
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.
104106
* @returns Files this template file depends on.
105107
*/
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);
108110
if (!this.block) return [];
109111

110112
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()]) {
113115
// 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+
116118
this.debug("block file path is", blockFile);
117119
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+
}
118128
deps.add(blockFile);
119129
}
120130
// These dependencies happen when additional files get involved via preprocessors.

packages/@css-blocks/ember/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ const EMBER_ADDON: AddonImplementation<CSSBlocksAddon> = {
112112
name: "css-blocks-htmlbars",
113113
// TODO: parallel babel stuff
114114
plugin: this.astPluginBuilder.bind(this),
115-
// This is turned off to work around a bug in broccoli-persistent-filter.
116-
dependencyInvalidation: false,
115+
dependencyInvalidation: true,
117116
cacheKey: () => this.optionsForCacheInvalidation(),
118117
baseDir: () => __dirname,
119118
});

private-packages/fixtures-ember-v2/ember-app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"build": "yarn pretest && ember build",
1515
"build:debug": "yarn pretest && node --inspect-brk ./node_modules/.bin/ember build",
1616
"start": "yarn pretest && ember serve",
17+
"start:debug": "yarn pretest && node --inspect-brk ./node_modules/.bin/ember serve",
1718
"pretest": "cd ../../../packages/@css-blocks/ember && yarn compile && cd ../ember-app && yarn compile",
1819
"test": "ember test",
1920
"clean:debug": "rm -rf DEBUG"

0 commit comments

Comments
 (0)