From 26ead666053bca1922b449c645ff106bfc9cec1d Mon Sep 17 00:00:00 2001 From: Eyal Delarea Date: Wed, 27 Mar 2024 12:44:17 +0200 Subject: [PATCH] Fix npm publish with provided tarball (#2502) --- go.mod | 2 +- go.sum | 4 +- npm_test.go | 73 ++++++++++++++---- .../jfrog-cli-tests-v1.0.0.tgz | Bin 0 -> 302 bytes 4 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 testdata/npm/npmprovidedtarball/jfrog-cli-tests-v1.0.0.tgz diff --git a/go.mod b/go.mod index 73709a648..e3d33f203 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6ce7a5a25..2e36c0c0e 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/npm_test.go b/npm_test.go index d040e3eee..ba9a72a0a 100644 --- a/npm_test.go +++ b/npm_test.go @@ -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 { @@ -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) @@ -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 +} diff --git a/testdata/npm/npmprovidedtarball/jfrog-cli-tests-v1.0.0.tgz b/testdata/npm/npmprovidedtarball/jfrog-cli-tests-v1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..ac4e38b7e9aa067be1ff2b1862f33fbe42397780 GIT binary patch literal 302 zcmV+}0nz>+iwFP!00002|Ls#fPs1<}&75Cx^3aI}r;s4J0s}K6Ww4xU>o&0?+YOOW z|2yZnlnxy$RHVGYm)v{rJ|w#paw}GN+s2q}oYBdJ!8v~@3OJV!C`t~=9i4ezmi!(P z`Y4JS#pDmLb6!{)0S7;z=|1_u>rcK`?g0H!L7 A8vp