From 187ca705de0f0c82803941142c93c55950931948 Mon Sep 17 00:00:00 2001 From: Yahav Itzhak Date: Thu, 19 Oct 2023 12:17:34 +0300 Subject: [PATCH] Support running npm install without package.json (#2269) --- go.mod | 4 ++-- go.sum | 8 ++++---- npm_test.go | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index a58d31876..8472c070a 100644 --- a/go.mod +++ b/go.mod @@ -129,9 +129,9 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230928084830-478bd49f5d3e +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231019085746-e1b192457664 -// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20231019090648-a85aaa5fe352 // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.6-0.20230418122323-2bf299dd6d27 diff --git a/go.sum b/go.sum index f61b07559..e67ab5486 100644 --- a/go.sum +++ b/go.sum @@ -237,14 +237,14 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedib0t/go-pretty/v6 v6.4.8 h1:HiNzyMSEpsBaduKhmK+CwcpulEeBrTmxutz4oX/oWkg= github.com/jedib0t/go-pretty/v6 v6.4.8/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs= -github.com/jfrog/build-info-go v1.9.13 h1:OeoGzPVK/O4TOUYk35uL4bXg/hleyqMrjGjjmyLOYrg= -github.com/jfrog/build-info-go v1.9.13/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg= +github.com/jfrog/build-info-go v1.8.9-0.20231019085746-e1b192457664 h1:6DIV7SpTEBD3xmOuUy9MoOaOw4bFhX0F3FgSyTTtgYQ= +github.com/jfrog/build-info-go v1.8.9-0.20231019085746-e1b192457664/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg= github.com/jfrog/gofrog v1.3.1 h1:QqAwQXCVReT724uga1AYqG/ZyrNQ6f+iTxmzkb+YFQk= github.com/jfrog/gofrog v1.3.1/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0= github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY= github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= -github.com/jfrog/jfrog-cli-core/v2 v2.45.3 h1:Umh+TvSJCaxBC/nV5pHGq80pGNdldwqFLeX8vqxgvsQ= -github.com/jfrog/jfrog-cli-core/v2 v2.45.3/go.mod h1:Gkua13G8aYPmv7cZgGhAwcyjqejvxwK5q8pEutvL0TI= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20231019090648-a85aaa5fe352 h1:DgOvo6c/hWRqbqEnuIHaJRD49dXpe6FPNB3aiBfhU9Q= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20231019090648-a85aaa5fe352/go.mod h1:mI6Ein5JpHSHJw8Mx1cYUYW3zUz80chnLJQsnRglS5U= github.com/jfrog/jfrog-client-go v1.34.3 h1:kDfw3FUQQvOsTKFqonIgLlziez6CSX80xCYZIH9YYcg= github.com/jfrog/jfrog-client-go v1.34.3/go.mod h1:fuxhYzWEkA16+ZV5cP/BJUGjA3SXVKbBoDmb8ZS6J4g= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= diff --git a/npm_test.go b/npm_test.go index 1a5e4a683..5222e4e03 100644 --- a/npm_test.go +++ b/npm_test.go @@ -135,7 +135,7 @@ func testNpm(t *testing.T, isLegacy bool) { } func readModuleId(t *testing.T, wd string, npmVersion *version.Version) string { - packageInfo, err := buildutils.ReadPackageInfoFromPackageJson(filepath.Dir(wd), npmVersion) + packageInfo, err := buildutils.ReadPackageInfoFromPackageJsonIfExists(filepath.Dir(wd), npmVersion) assert.NoError(t, err) return packageInfo.BuildInfoModuleId() } @@ -165,6 +165,28 @@ func validateNpmLocalBuildInfo(t *testing.T, buildName, buildNumber, moduleName } } +func TestNpmWithoutPackageJson(t *testing.T) { + initNpmTest(t) + defer cleanNpmTest(t) + + // Create temp dir that does not contain an npm project + tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) + defer createTempDirCallback() + wd, err := os.Getwd() + assert.NoError(t, err, "Failed to get current dir") + chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, tempDirPath) + defer chdirCallback() + + // Run config to allow resolution from Artifactory + err = createConfigFileForTest([]string{tempDirPath}, tests.NpmRemoteRepo, "", t, utils.Npm, false) + assert.NoError(t, err) + + // Run npm install and make sure that package.json and package-lock.json were created + runJfrogCli(t, "npm", "i", "json@9.0.6", "--save-exact") + assert.FileExists(t, filepath.Join(tempDirPath, "package.json")) + assert.FileExists(t, filepath.Join(tempDirPath, "package-lock.json")) +} + func TestNpmConditionalUpload(t *testing.T) { initNpmTest(t) defer cleanNpmTest(t)