Skip to content

Commit

Permalink
Support running npm install without package.json (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Oct 19, 2023
1 parent 7e2b32d commit 187ca70
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
24 changes: 23 additions & 1 deletion npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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", "[email protected]", "--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)
Expand Down

0 comments on commit 187ca70

Please sign in to comment.