Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Filter out all .css, .png and .svg files from showing up in Sources t…
Browse files Browse the repository at this point in the history
…ree (#4145)
  • Loading branch information
danieltucunduva authored and jasonLaster committed Sep 24, 2017
1 parent e3a34d8 commit f390fcc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/utils/sources-tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export {
isDirectory,
createNode,
createParentMap,
getRelativePath
getRelativePath,
isNotJavaScript
} from "./utils";
38 changes: 37 additions & 1 deletion src/utils/sources-tree/tests/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
addToTree,
sortEntireTree,
getURL,
getDirectories
getDirectories,
isNotJavaScript
} from "../index";

describe("sources tree", () => {
Expand Down Expand Up @@ -177,4 +178,39 @@ describe("sources tree", () => {
expect(urlObject.filename).toBe("(index)");
});
});

describe("isNotJavaScript", () => {
it("js file", () => {
expect(
isNotJavaScript({
url: "http://example.com/foo.js"
})
).toBe(false);
});

it("css file", () => {
expect(
isNotJavaScript({
url: "http://example.com/foo.css"
})
).toBe(true);
});

it("svg file", () => {
expect(
isNotJavaScript({
url: "http://example.com/foo.svg"
})
).toBe(true);
});

it("png file", () => {
expect(
isNotJavaScript({
url: "http://example.com/foo.png"
})
).toBe(true);
});
});

});
13 changes: 12 additions & 1 deletion src/utils/sources-tree/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ export function isDirectory(url: Object) {
);
}

export function isNotJavaScript(source: Object): boolean {
const parsedUrl = parse(source.url).pathname
if (!parsedUrl) {
return false;
}
const parsedExtension = parsedUrl.split('.').pop();

return ["css", "svg", "png"].includes(parsedExtension)
}

export function isInvalidUrl(url: Object, source: Object) {
return (
IGNORED_URLS.indexOf(url) != -1 ||
!source.get("url") ||
source.get("loadedState") === "loading" ||
!url.group ||
isPretty(source.toJS())
isPretty(source.toJS()) ||
isNotJavaScript(source.toJS())
);
}

Expand Down

0 comments on commit f390fcc

Please sign in to comment.