Skip to content

Commit ab9cc5a

Browse files
Fix folder index path
1 parent 0e83ea4 commit ab9cc5a

5 files changed

Lines changed: 34 additions & 33 deletions

File tree

example-project/src/utils/register-service-worker.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,17 @@ const isLocalhost = Boolean(
1919
);
2020

2121
export default function register() {
22-
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
23-
// The URL constructor is available in all browsers that support SW.
24-
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
25-
if (publicUrl.origin !== window.location.origin) {
26-
// Our service worker won't work if PUBLIC_URL is on a different origin
27-
// from what our page is served on. This might happen if a CDN is used to
28-
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
29-
return;
30-
}
31-
32-
window.addEventListener('load', () => {
33-
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
22+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
23+
if (publicUrl.origin !== window.location.origin) return;
3424

35-
if (!isLocalhost) {
36-
// Is not local host. Just register service worker
37-
registerValidSW(swUrl);
38-
} else {
39-
// This is running on localhost. Lets check if a service worker still exists or not.
40-
checkValidServiceWorker(swUrl);
41-
}
42-
});
43-
}
25+
window.addEventListener('load', () => {
26+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
27+
if (!isLocalhost) {
28+
registerValidSW(swUrl);
29+
} else {
30+
checkValidServiceWorker(swUrl);
31+
}
32+
});
4433
}
4534

4635
function registerValidSW(swUrl) {

src/public/dist/bundle.js

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/dist/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/js/components/sideBar/component/DependenciesTab/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import './index.scss';
1515
const Panel = Collapse.Panel;
1616

1717
const DependenciesTab = props => {
18-
const { selectedNode, filesMap, selectedDependencyEdgeNodes } = props;
18+
const { selectedNode, filesMap, foldersMap, selectedDependencyEdgeNodes } = props;
1919

2020
const importedDependencies = filterImportedDependencies(
2121
selectedNode.importedDependencies,
@@ -35,7 +35,7 @@ const DependenciesTab = props => {
3535
</Panel>
3636
{importedDependencies.map((file, i) => {
3737
const filePath = convertRelativeToAbsolutePath(selectedNode.path, file.sourceFile);
38-
const fileNode = findFileNode(filePath, filesMap);
38+
const fileNode = findFileNode(filePath, filesMap, foldersMap);
3939

4040
if (!fileNode) {
4141
return null;
@@ -69,12 +69,13 @@ const DependenciesTab = props => {
6969
};
7070

7171
const mapStateToProps = state => {
72-
const { selectedNode, selectedDependencyEdgeNodes, filesMap } = state.dataBus;
72+
const { selectedNode, selectedDependencyEdgeNodes, filesMap, foldersMap } = state.dataBus;
7373

7474
return {
7575
selectedNode,
7676
selectedDependencyEdgeNodes,
77-
filesMap
77+
filesMap,
78+
foldersMap
7879
};
7980
};
8081

src/public/js/components/sideBar/component/shared/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export const filterImportedDependencies = (
2121
});
2222
};
2323

24-
export const findFileNode = (path, filesMap) => {
24+
export const findFileNode = (path, filesMap, foldersMap) => {
25+
if (foldersMap[path]) {
26+
path += '/index';
27+
}
28+
2529
if (filesMap[path]) {
2630
return filesMap[path];
2731
}
@@ -51,7 +55,7 @@ export const extractExportsForImports = (fileCode, specifiers, path) => {
5155
if (isDefaultImported && node.type === 'ExportDefaultDeclaration') {
5256
exports.push(node);
5357
} else if (node.type === 'ExportNamedDeclaration') {
54-
const declaration = node.declaration.declarations.find(d =>
58+
const declaration = node.declaration && node.declaration.declarations.find(d =>
5559
namedImportsNames.includes(d.id.name)
5660
);
5761
if (declaration) {

0 commit comments

Comments
 (0)