From 1e15c16cdc11b210baf0561d5e18cdbcdb82e15a Mon Sep 17 00:00:00 2001 From: Nuruddin Ashr Date: Thu, 17 May 2018 10:37:00 +0700 Subject: [PATCH 1/3] Disallow internal package on root --- src/goPackages.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/goPackages.ts b/src/goPackages.ts index b71ce8463..f2bac3e84 100644 --- a/src/goPackages.ts +++ b/src/goPackages.ts @@ -278,9 +278,13 @@ export function getNonVendorPackages(folderPath: string): Promise { // see: https://golang.org/s/go14internal function isAllowToImportPackage(toDirPath: string, currentWorkspace: string, pkgPath: string) { let internalPkgFound = pkgPath.match(/\/internal\/|\/internal$/); + if (internalPkgFound) { + internalPkgFound = pkgPath.match(/^internal\b/); + } + if (internalPkgFound) { let rootProjectForInternalPkg = path.join(currentWorkspace, pkgPath.substr(0, internalPkgFound.index)); - return toDirPath.startsWith(rootProjectForInternalPkg + path.sep) || toDirPath === rootProjectForInternalPkg; + return (rootProjectForInternalPkg !== currentWorkspace && toDirPath.startsWith(rootProjectForInternalPkg + path.sep)) || toDirPath === rootProjectForInternalPkg; } return true; } From eb13c4db8117da43b211ea3061c5f146d232b274 Mon Sep 17 00:00:00 2001 From: Nuruddin Ashr Date: Mon, 4 Jun 2018 11:11:21 +0700 Subject: [PATCH 2/3] Fix the regex for detecting internal package --- src/goPackages.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/goPackages.ts b/src/goPackages.ts index f2bac3e84..bf87cc71c 100644 --- a/src/goPackages.ts +++ b/src/goPackages.ts @@ -277,11 +277,7 @@ export function getNonVendorPackages(folderPath: string): Promise { // see: https://golang.org/doc/go1.4#internalpackages // see: https://golang.org/s/go14internal function isAllowToImportPackage(toDirPath: string, currentWorkspace: string, pkgPath: string) { - let internalPkgFound = pkgPath.match(/\/internal\/|\/internal$/); - if (internalPkgFound) { - internalPkgFound = pkgPath.match(/^internal\b/); - } - + let internalPkgFound = pkgPath.match(/(^|\/)internal(\/|$)/); if (internalPkgFound) { let rootProjectForInternalPkg = path.join(currentWorkspace, pkgPath.substr(0, internalPkgFound.index)); return (rootProjectForInternalPkg !== currentWorkspace && toDirPath.startsWith(rootProjectForInternalPkg + path.sep)) || toDirPath === rootProjectForInternalPkg; From 3b7b1c727384faa2cb115db6ac3df508d3c87d07 Mon Sep 17 00:00:00 2001 From: Nuruddin Ashr Date: Mon, 4 Jun 2018 14:56:06 +0700 Subject: [PATCH 3/3] Disallow to use internal package located on root --- src/goPackages.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/goPackages.ts b/src/goPackages.ts index bf87cc71c..1e8264ebc 100644 --- a/src/goPackages.ts +++ b/src/goPackages.ts @@ -277,10 +277,14 @@ export function getNonVendorPackages(folderPath: string): Promise { // see: https://golang.org/doc/go1.4#internalpackages // see: https://golang.org/s/go14internal function isAllowToImportPackage(toDirPath: string, currentWorkspace: string, pkgPath: string) { - let internalPkgFound = pkgPath.match(/(^|\/)internal(\/|$)/); + if (pkgPath.startsWith('internal/')) { + return false; + } + + let internalPkgFound = pkgPath.match(/\/internal\/|\/internal$/); if (internalPkgFound) { let rootProjectForInternalPkg = path.join(currentWorkspace, pkgPath.substr(0, internalPkgFound.index)); - return (rootProjectForInternalPkg !== currentWorkspace && toDirPath.startsWith(rootProjectForInternalPkg + path.sep)) || toDirPath === rootProjectForInternalPkg; + return toDirPath.startsWith(rootProjectForInternalPkg + path.sep) || toDirPath === rootProjectForInternalPkg; } return true; }