Skip to content

Commit

Permalink
fix verify imports for named imports
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Sep 29, 2022
1 parent 32d516c commit 2534286
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
30 changes: 23 additions & 7 deletions lib/TemplateImportProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,30 @@ export default class TemplateImportProcessor extends BroccoliFilter {
processString(contents, relativePath) {
importProcessor.options = Object.assign({}, this.options);
const [res, imports] = importProcessor.processAst(contents, relativePath);
this.options.imports.from[relativePath] = [];
imports.components.forEach((comp) => {
this.options.imports.components.add(comp);
this.options.imports.from[relativePath].push(comp);
this.options.imports.from[relativePath] = new Set();
Object.values(imports.info.components).forEach((comp) => {
let path = comp.path;
if (comp.imp.shouldLookInFile) {
path = comp.imp.importPath.split('/').slice(0, -1).join('/')
}
this.options.imports.components.add(path);
this.options.imports.from[relativePath].add(path);
});
imports.others.forEach((comp) => {
this.options.imports.others.add(comp);
this.options.imports.from[relativePath].push(comp);
Object.values(imports.info.helpers).forEach((comp) => {
let path = comp.resolvedPath;
if (comp.imp.shouldLookInFile) {
path = comp.imp.importPath.split('/').slice(0, -1).join('/')
}
this.options.imports.components.add(path);
this.options.imports.from[relativePath].add(path);
});
Object.values(imports.info.modifiers).forEach((comp) => {
let path = comp.resolvedPath;
if (comp.imp.shouldLookInFile) {
path = comp.imp.importPath.split('/').slice(0, -1).join('/')
}
this.options.imports.components.add(path);
this.options.imports.from[relativePath].add(path);
});
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/VerifyImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class VerifyImports extends BroccoliFilter {
failOnMissingImport: boolean
};
imports: {
from: Record<string, string[]>
from: Record<string, Set<string>>
};
files: Set<any>;

Expand All @@ -27,7 +27,7 @@ class VerifyImports extends BroccoliFilter {
const r = await super.build(...args);
const imports = this.imports;
Object.entries(imports.from).forEach(([from, imps]) => {
const notFound = imps.filter((i) => !this.files.has(i) && !this.files.has(i + '.js') && !this.files.has(i+'/index') && !this.files.has(i+'/index.js'));
const notFound = [...imps.values()].filter((i) => !this.files.has(i) && !this.files.has(i + '.js') && !this.files.has(i+'/index') && !this.files.has(i+'/index.js'));
if (notFound.length) {
if (this.options.failOnMissingImport) {
throw new Error(from + ':imports not found -> ' + notFound)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-hbs-imports",
"version": "0.5.18",
"version": "0.5.19",
"repository": {
"type": "git",
"url": "https://github.com/patricklx/ember-hbs-imports"
Expand Down

0 comments on commit 2534286

Please sign in to comment.