Skip to content

#2006 Support manifest.json w/o Webpack Encore #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import fr.adrienbrault.idea.symfony2plugin.Settings;
import fr.adrienbrault.idea.symfony2plugin.templating.webpack.SymfonyWebpackUtil;
import fr.adrienbrault.idea.symfony2plugin.util.ProjectUtil;
Expand Down Expand Up @@ -62,7 +64,8 @@ private static Collection<VirtualFile> getProjectAssetRoot(@NotNull Project proj
public Collection<AssetFile> getAssetFiles(@NotNull Project project) {
Collection<AssetFile> files = new ArrayList<>();

for (VirtualFile webDirectory : getProjectAssetRoot(project)) {
Collection<VirtualFile> projectAssetRoots = getProjectAssetRoot(project);
for (VirtualFile webDirectory : projectAssetRoots) {
VfsUtil.visitChildrenRecursively(webDirectory, new VirtualFileVisitor<VirtualFile>() {
@Override
public boolean visitFile(@NotNull VirtualFile virtualFile) {
Expand All @@ -72,14 +75,13 @@ public boolean visitFile(@NotNull VirtualFile virtualFile) {
return super.visitFile(virtualFile);
}
});
}

VirtualFile fileByRelativePath = webDirectory.findFileByRelativePath("build/manifest.json");
if (fileByRelativePath != null) {
SymfonyWebpackUtil.visitManifestJsonEntries(
fileByRelativePath,
pair -> files.add(AssetFile.createVirtualManifestEntry(fileByRelativePath, pair.getFirst()))
);
}
for (VirtualFile projectManifestJsonFile : getProjectManifestJsonFiles(project, projectAssetRoots)) {
SymfonyWebpackUtil.visitManifestJsonEntries(
projectManifestJsonFile,
pair -> files.add(AssetFile.createVirtualManifestEntry(projectManifestJsonFile, pair.getFirst()))
);
}

if(!this.includeBundleDir) {
Expand Down Expand Up @@ -155,7 +157,8 @@ public Collection<VirtualFile> resolveAssetFile(@NotNull Project project, @NotNu

Collection<VirtualFile> files = new HashSet<>();

for (VirtualFile webDirectory : getProjectAssetRoot(project)) {
Collection<VirtualFile> projectAssetRoots = getProjectAssetRoot(project);
for (VirtualFile webDirectory : projectAssetRoots) {
Matcher matcher = Pattern.compile("^(.*[/\\\\])\\*([.\\w+]*)$").matcher(assetName);
if (!matcher.find()) {
VirtualFile assetFile = VfsUtil.findRelativeFile(webDirectory, assetName.split("/"));
Expand All @@ -167,18 +170,17 @@ public Collection<VirtualFile> resolveAssetFile(@NotNull Project project, @NotNu
// "/*.js"
files.addAll(collectWildcardDirectories(matcher, webDirectory));
}
}

VirtualFile fileByRelativePath = webDirectory.findFileByRelativePath("build/manifest.json");
if (fileByRelativePath != null) {
SymfonyWebpackUtil.visitManifestJsonEntries(
fileByRelativePath,
pair -> {
if (filename.equalsIgnoreCase(pair.getFirst())) {
files.add(fileByRelativePath);
}
for (VirtualFile projectManifestJsonFile : getProjectManifestJsonFiles(project, projectAssetRoots)) {
SymfonyWebpackUtil.visitManifestJsonEntries(
projectManifestJsonFile,
pair -> {
if (filename.equalsIgnoreCase(pair.getFirst())) {
files.add(projectManifestJsonFile);
}
);
}
}
);
}

return files;
Expand Down Expand Up @@ -223,4 +225,21 @@ private boolean isValidFile(@NotNull VirtualFile virtualFile) {
String extension = virtualFile.getExtension();
return extension != null && this.filterExtension.contains(extension);
}

@NotNull
private Collection<VirtualFile> getProjectManifestJsonFiles(@NotNull Project project, @NotNull Collection<VirtualFile> webDirectories) {
HashSet<VirtualFile> manifestFiles = new HashSet<>(
FilenameIndex.getVirtualFilesByName("manifest.json", GlobalSearchScope.allScope(project))
);

// for files which are ignored by indexing, resolve based on project web folder
for (VirtualFile webDirectory : webDirectories) {
VirtualFile fileByRelativePath = webDirectory.findFileByRelativePath("build/manifest.json");
if (fileByRelativePath != null) {
manifestFiles.add(fileByRelativePath);
}
}

return manifestFiles;
}
}