Skip to content

Commit

Permalink
Fix npm publish with provided tarball (#2502)
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea authored Mar 27, 2024
1 parent 9bd2ed7 commit 26ead66
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240321095315-72b008905aa2
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240327081155-4a0e1442bf74

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240320102352-af2f392bb490

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ github.com/jfrog/gofrog v1.6.3 h1:F7He0+75HcgCe6SGTSHLFCBDxiE2Ja0tekvvcktW6wc=
github.com/jfrog/gofrog v1.6.3/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg=
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.31.1-0.20240321095315-72b008905aa2 h1:wJ9Tn8D+koRVNuVdX5f0+FBxuEmVuY6hgCQZsCIWV0U=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240321095315-72b008905aa2/go.mod h1:XZP7fmNBBoieQTUE2p2mvA8h/CFO5z4PE7KW1s2cdNk=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240327081155-4a0e1442bf74 h1:8hyoBxxXywmAzLXGMmmjFxXmp//KMBQgDITbqAN16LE=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240327081155-4a0e1442bf74/go.mod h1:XZP7fmNBBoieQTUE2p2mvA8h/CFO5z4PE7KW1s2cdNk=
github.com/jfrog/jfrog-cli-security v1.0.5-0.20240321101458-c86ea9b28dfd h1:yr3nfponKdXZ2hSBE9CT9EaVCUUpHDJQC5hPgsLqQSg=
github.com/jfrog/jfrog-cli-security v1.0.5-0.20240321101458-c86ea9b28dfd/go.mod h1:P3r0ebMCrBiLBXdwq2j4eVqySEWd4NzDleUkvP22V5I=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240320102352-af2f392bb490 h1:oGgwRJatirSNZyqO3e4FtHCe5W30VNgULCW/GYhHdao=
Expand Down
73 changes: 59 additions & 14 deletions npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,20 +549,7 @@ func TestNpmPublishWithWorkspaces(t *testing.T) {
err = commands.Exec(npmpCmd)
assert.NoError(t, err)

result := npmpCmd.Result()
assert.NotNil(t, result)
reader := result.Reader()
readerGetErrorAndAssert(t, reader)
defer readerCloseAndAssert(t, reader)
// Read result
var files []clientutils.FileTransferDetails
for transferDetails := new(clientutils.FileTransferDetails); reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) {
files = append(files, *transferDetails)
}
if files == nil {
assert.NotNil(t, files)
return
}
files := assertNpmPublishResultFiles(t, npmpCmd)

expectedTars := []string{"nested1", "nested2"}
for index, tar := range expectedTars {
Expand All @@ -577,6 +564,51 @@ func TestNpmPublishWithWorkspaces(t *testing.T) {
}
}

// Test npm publish command with provided tarball
func TestNpmPackProvidedTarball(t *testing.T) {
// Check npm version
npmVersion, _, err := buildutils.GetNpmVersionAndExecPath(log.Logger)
if err != nil {
assert.NoError(t, err)
return
}
// In npm under v7 skip test
if npmVersion.Compare(minimumWorkspacesNpmVersion) > 0 {
log.Info("Test skipped as this function in not supported in npm version " + npmVersion.GetVersion())
return
}

// Prepare test
initNpmTest(t)
defer cleanNpmTest(t)
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
testFolder := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "npm", "npmprovidedtarball")
err = biutils.CopyDir(testFolder, tempDirPath, false, []string{})
assert.NoError(t, err)

// CD inside the copied project and create npm config
wd, err := os.Getwd()
assert.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, tempDirPath)
defer chdirCallback()
err = createConfigFileForTest([]string{tempDirPath}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, false)
assert.NoError(t, err)

// Init npm project & npmp command for testing
configFilePath := filepath.Join(tempDirPath, ".jfrog", "projects", "npm.yaml")
args := []string{"jfrog-cli-tests-v1.0.0.tgz", "--detailed-summary=true", "--workspaces", "--verbose"}
npmpCmd := npm.NewNpmPublishCommand()
npmpCmd.SetConfigFilePath(configFilePath).SetArgs(args)
npmpCmd.SetNpmArgs(args)
assert.NoError(t, npmpCmd.Init())
err = commands.Exec(npmpCmd)
assert.NoError(t, err)

// Check result
assertNpmPublishResultFiles(t, npmpCmd)
}

func TestYarn(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)
Expand Down Expand Up @@ -679,3 +711,16 @@ func runGenericNpm(t *testing.T, args ...string) {
jfCli := coretests.NewJfrogCli(execMain, "jf", "")
assert.NoError(t, jfCli.WithoutCredentials().Exec(args...))
}

func assertNpmPublishResultFiles(t *testing.T, npmpCmd *npm.NpmPublishCommand) (files []clientutils.FileTransferDetails) {
result := npmpCmd.Result()
assert.NotNil(t, result)
reader := result.Reader()
readerGetErrorAndAssert(t, reader)
defer readerCloseAndAssert(t, reader)
for transferDetails := new(clientutils.FileTransferDetails); reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) {
files = append(files, *transferDetails)
}
assert.NotNil(t, files)
return files
}
Binary file not shown.

0 comments on commit 26ead66

Please sign in to comment.