Skip to content

Commit

Permalink
fix: Namespace blocks within each app/addon/engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Jul 29, 2020
1 parent cebbc59 commit 994239b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/@css-blocks/ember-support/src/BroccoliTreeImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ export function pathToIdent(relativePath: string): string {
export class BroccoliTreeImporter extends BaseImporter {
fallbackImporter: Importer;
input: MergedFileSystem;
namespace: string | null;

constructor(input: MergedFileSystem, fallbackImporter: Importer) {
constructor(input: MergedFileSystem, namespace: string | null, fallbackImporter: Importer) {
super();
this.input = input;
this.fallbackImporter = fallbackImporter;
this.namespace = namespace;
}

identifier(fromIdentifier: string | null, importPath: string, config: Readonly<Configuration>): string {
Expand All @@ -82,8 +84,6 @@ export class BroccoliTreeImporter extends BaseImporter {
let relativePath = identToPath(this.input, identifier);
let contents = this.input.readFileSync(relativePath, "utf8");
let syntax = syntaxFromExtension(path.extname(relativePath));
let defaultName = path.parse(relativePath).name;
defaultName = defaultName.replace(/.block$/, "");
if (this.isCompiledBlockCSS(contents)) {
const segmentedContents = this.segmentizeCompiledBlockCSS(contents);
// Need to determine if the definition URL is an external URL we should
Expand Down Expand Up @@ -123,7 +123,7 @@ export class BroccoliTreeImporter extends BaseImporter {
return {
type: "ImportedFile",
identifier,
defaultName,
defaultName: this.defaultName(identifier, config),
syntax,
contents,
};
Expand All @@ -136,8 +136,11 @@ export class BroccoliTreeImporter extends BaseImporter {
defaultName(identifier: string, configuration: Readonly<Configuration>): string {
if (isBroccoliTreeIdentifier(identifier)) {
let relativePath = identToPath(this.input, identifier);
let defaultName = path.basename(relativePath);
let defaultName = path.parse(relativePath).name;
defaultName = defaultName.replace(/.block$/, "");
if (this.namespace) {
defaultName = `${defaultName}-${this.namespace}`;
}
return defaultName;
} else {
return this.fallbackImporter.defaultName(identifier, configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class CSSBlocksTemplateCompilerPlugin extends TemplateCompilerPlugin {
if (removedFiles.length > 0) {
console.warn(`[WARN] ${removedFiles[0][1]} was just removed and the output directory was not cleaned up.`);
}
let importer = new BroccoliTreeImporter(this.input, this.parserOpts.importer);
let namespace = md5Sum(this.treeName).slice(0, 3);
let importer = new BroccoliTreeImporter(this.input, namespace, this.parserOpts.importer);
let config = resolveConfiguration({importer}, this.parserOpts);
let factory = new BlockFactory(config, postcss);
let fileLocator = new BroccoliFileLocator(this.input);
Expand Down

0 comments on commit 994239b

Please sign in to comment.