Skip to content

Support npm publish using native npm client with .npmrc via --use-npmrc flag #2952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

fluxxBot
Copy link
Collaborator

@fluxxBot fluxxBot commented Apr 13, 2025

  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • The pull request is targeting the dev branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....

This PR introduces a new implementation for the npm publish command that supports both the existing and the updated approach.

  1. A new flag --use-npmrc has been added to opt into the updated publish flow.
  2. When this flag is used, we now rely on the native npm client to perform the publish operation, rather than using rt upload command.
  3. This updated flow respects the user’s local .npmrc configuration, unlike the older approach which depended on jf config.
  4. The older flow was implemented in a single file. To improve maintainability and separation of concerns, the logic is now split across dedicated handlers:
    a. npmPublishHandler: Uses the npm client.
    b. rtPublishHandler: Retains the original behavior using Artifactory upload (rt).
  5. A new interface Publish is introduced in publishHandler, abstracting the logic to switch between the two implementations based on the flag provided.

depends on:

  1. client-go - Added util to create build info from search results jfrog-client-go#1109
  2. cli-core - Added config extractor for new npm publish impl jfrog-cli-core#1374
  3. cli-artifactory - New npm publish impl jfrog-cli-artifactory#63

@fluxxBot fluxxBot added the safe to test Approve running integration tests on a pull request label Apr 13, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Apr 13, 2025
@fluxxBot fluxxBot added feature request New feature or request new feature Automatically generated release notes and removed feature request New feature or request labels Apr 15, 2025
@fluxxBot fluxxBot changed the title New npm publish implementation Support npm publish using native npm client with .npmrc via --use-npmrc flag Apr 15, 2025
@fluxxBot fluxxBot added the safe to test Approve running integration tests on a pull request label Apr 15, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Apr 15, 2025
@fluxxBot fluxxBot requested a review from bhanurp April 15, 2025 06:45
@fluxxBot fluxxBot added the safe to test Approve running integration tests on a pull request label Apr 21, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Apr 21, 2025
Comment on lines +1708 to +1711
useNpmRc: cli.BoolFlag{
Name: useNpmRc,
Usage: "[Default: false] Set to true if you'd like to use the .npmrc file for configurations. Note: This flag would invoke npm native client behind the scenes, has performance implications and does not support deployment view and detailed summary` `",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useNpmRc: cli.BoolFlag{
Name: useNpmRc,
Usage: "[Default: false] Set to true if you'd like to use the .npmrc file for configurations. Note: This flag would invoke npm native client behind the scenes, has performance implications and does not support deployment view and detailed summary` `",
},
useNpmRc: cli.BoolFlag{
Name: useNPMRC,
Usage: "[Default: false] Set to true to use the .npmrc file for publish. Note: This flag would invoke npm native client behind the scenes, has performance implications and does not support deployment view and detailed summary` `",
},

@@ -1797,8 +1800,8 @@ func GetGradleDeployedArtifacts() []string {
}
}

func GetNpmDeployedScopedArtifacts(isNpm7 bool) []string {
path := NpmRepo + "/@jscope/jfrog-cli-tests/-/@jscope/"
func GetNpmDeployedScopedArtifacts(npmRepo string, isNpm7 bool) []string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required?

return
}

func publishUsingNpmrc(configFilePath string, buildNumber string) (npm.NpmPublishCommand, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does sample output looks with --use-npmrc ?

legacyCommand: "rt npm-publish",
repo: repoName,
wd: npmProjectPath,
validationFunc: validateNpmPublish,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateNpmPublish is validating published module using artifact properties but --use-npmrc flag will not fail when it is not able to set properties. Is there any other way to validate the published artifact using --use-npmrc ?

wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
defer clientTestUtils.ChangeDirAndAssert(t, wd)
buildNumber := strconv.Itoa(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
buildNumber := strconv.Itoa(1)
buildNumber := "1"

just wondering why not directly to string?

addNpmScopeRegistryToNpmRc(t, npmProjectPath, packageJsonPath, npmVersion)
}

npmpCmd, err := publishUsingNpmrc(configFilePath, buildNumber)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it npmp ?

result := npmpCmd.Result()
assert.NotNil(t, result)

validateNpmLocalBuildInfo(t, tests.NpmBuildName, buildNumber, moduleName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we creating build info as well with --use-npmrc ?

@@ -285,6 +393,14 @@ func initNpmProjectTest(t *testing.T) (npmProjectPath string) {
return
}

func initNpmPublishRcProjectTest(t *testing.T, projectName string) (npmProjectPath string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func initNpmPublishRcProjectTest(t *testing.T, projectName string) (npmProjectPath string) {
func initNpmPublishviaNPMRCTest(t *testing.T, projectName string) (npmProjectPath string) {

Comment on lines +940 to +941
// we do not support deployment view and detailed summary when using npmrc for publishing since
// TransferDetails is not available to us
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// we do not support deployment view and detailed summary when using npmrc for publishing since
// TransferDetails is not available to us
// Deployment view and Detailed summary is not supported when using npmrc for publishing since transfer details are not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Automatically generated release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants