From 5d94608ee6a8a92e25608fe8c8a83e35d4c54ed4 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Mon, 4 Mar 2019 10:51:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20submodules=20starts=20with=20?= =?UTF-8?q?=E2=80=9C.=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/driver/core/FileExplorer.ts | 50 ++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/driver/core/FileExplorer.ts b/src/driver/core/FileExplorer.ts index 5ba2b21..b4d3858 100644 --- a/src/driver/core/FileExplorer.ts +++ b/src/driver/core/FileExplorer.ts @@ -66,30 +66,48 @@ function transformModuleGitURL(node: TreeNode, URL: string) { function transformModuleHTTPURL(node: TreeNode, URL: string) { return URL.replace(/\.git/, `/tree/${node.sha}`) } + +type Parsed = { + [key: string]: ParsedModule | Parsed +} + +type ParsedModule = { + path: string + url: string +} + function resolveGitModules(root: TreeNode, blobData: BlobData) { if (blobData) { if (blobData.encoding === 'base64' && blobData.content && Array.isArray(root.contents)) { const content = atob(blobData.content) - const parsed = ini.parse(content) - Object.values(parsed).forEach((value: { url: string; path: string }) => { - const { url, path } = value - const node = findNode(root, path.split('/')) - if (node) { - if (githubSubModuleURLRegex.HTTP.test(url)) { - node.url = transformModuleHTTPURL(node, url) - } else if (githubSubModuleURLRegex.git.test(url)) { - node.url = transformModuleGitURL(node, url) - } else { - node.accessDenied = true - } - } else { - raiseError(Error(`Sub-module node ${path} not found`)) - } - }) + const parsed: Parsed = ini.parse(content) + handleParsed(root, parsed) } } } +function handleParsed(root: TreeNode, parsed: Parsed) { + Object.values(parsed).forEach(value => { + const { url, path } = value + if (typeof url === 'string' && typeof path === 'string') { + const node = findNode(root, path.split('/')) + if (node) { + if (githubSubModuleURLRegex.HTTP.test(url)) { + node.url = transformModuleHTTPURL(node, url) + } else if (githubSubModuleURLRegex.git.test(url)) { + node.url = transformModuleGitURL(node, url) + } else { + node.accessDenied = true + } + } else { + raiseError(Error(`Sub-module node ${path} not found`)) + } + } else { + handleParsed(root, value as Parsed) + } + }) +} + const setUpTree: MethodCreator = dispatch => () => dispatch.get(async (_, { treeData, metaData, compressSingletonFolder, accessToken }) => { if (!treeData) return