Skip to content

Commit f3386ac

Browse files
committed
fix: Discover new glimmer components when they are added while watching.
Also verify that files can be removed without causing any issues.
1 parent d3397cd commit f3386ac

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

packages/@css-blocks/broccoli/test/Analyze.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,51 @@ describe("Broccoli Analyze Plugin Test", function () {
148148
await output.build();
149149
assert.equal(transport["css"], "Transport Not Modified On NO-OP");
150150
assert.deepEqual(output.changes(), {});
151+
152+
// Adding a template & block is safe
153+
input.write({
154+
src: {
155+
ui: {
156+
components: {
157+
[entryComponentName]: {
158+
"template.hbs": `<div><h1>Welcome to Glimmer!</h1><AnotherComponent /></div>`,
159+
},
160+
AnotherComponent: {
161+
"template.hbs": `<div block:scope><h1 block:class="bar">Another Component</h1></div>`,
162+
"stylesheet.css": `:scope { border: 1px solid black; } .bar { border-left: 0px; }`,
163+
},
164+
},
165+
},
166+
},
167+
});
168+
await output.build();
169+
assert.equal(transport["css"],
170+
`.a { color: red; }\n` +
171+
`.b { border: 1px solid black; } .c { border-left: 0px; }`,
172+
"Addition of new component compiles it.");
173+
assert.deepEqual(output.changes(), {
174+
"src/ui/components/Chrisrng/template.hbs": "change",
175+
"src/ui/components/AnotherComponent/": "mkdir",
176+
"src/ui/components/AnotherComponent/template.hbs": "create",
177+
});
178+
179+
// Removing a template is safe
180+
input.write({
181+
src: {
182+
ui: {
183+
components: {
184+
AnotherComponent: {
185+
"template.hbs": null,
186+
"stylesheet.css": null,
187+
},
188+
},
189+
},
190+
},
191+
});
192+
await output.build();
193+
assert.deepEqual(output.changes(),
194+
{ "src/ui/components/AnotherComponent/template.hbs": "unlink" },
195+
"output directory is cleaned up.");
151196
});
152197
});
153198
});

packages/@css-blocks/glimmer/src/Analyzer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class GlimmerAnalyzer extends Analyzer<TEMPLATE_TYPE> {
2424
blockFactory: BlockFactory;
2525
resolver: Resolver;
2626
debug: debugGenerator.IDebugger;
27+
private moduleConfig: ResolverConfiguration | undefined;
2728

2829
constructor(
2930
blockFactory: BlockFactory,
@@ -32,11 +33,13 @@ export class GlimmerAnalyzer extends Analyzer<TEMPLATE_TYPE> {
3233
) {
3334
super(blockFactory, analysisOpts);
3435
this.blockFactory = blockFactory;
36+
this.moduleConfig = moduleConfig;
3537
this.resolver = new Resolver(blockFactory.configuration, moduleConfig);
3638
this.debug = debugGenerator("css-blocks:glimmer:analyzer");
3739
}
3840

3941
reset() {
42+
this.resolver = new Resolver(this.blockFactory.configuration, this.moduleConfig);
4043
super.reset();
4144
this.blockFactory.reset();
4245
}
@@ -86,7 +89,7 @@ export class GlimmerAnalyzer extends Analyzer<TEMPLATE_TYPE> {
8689
}
8790
return await this.blockFactory.getBlockFromPath(blockFile.path);
8891
} catch (e) {
89-
console.error(e);
92+
this.debug(e);
9093
this.debug(`Analyzing ${componentName}. No block for component. Returning empty analysis.`);
9194
return undefined;
9295
}

packages/@css-blocks/glimmer/src/Resolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ export class Resolver {
146146
recursiveDependenciesForTemplate(base: string, identifier: string): string[] {
147147
let depAnalyzer = this.dependencyAnalyzerFor(base);
148148
if (!depAnalyzer) { return [identifier]; }
149-
return depAnalyzer.recursiveDependenciesForTemplate(identifier).components;
149+
let results = depAnalyzer.recursiveDependenciesForTemplate(identifier).components;
150+
DEBUG("Recursively discovered components: %s", results);
151+
return results;
150152
}
151153

152154
/**

0 commit comments

Comments
 (0)