Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/pnpmPublic

fix: unsupported env fallbacks in .npmrc when publishing#10255

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
monholm wants to merge1 commit intopnpm:main
base:main
Choose a base branch
Loading
frommonholm:fix/publish-npmrc-env-fallbacks

Conversation

@monholm
Copy link

WIP untilpnpm/components#25 is merged.

As mentioned in the changeset,pnpm publish doesn't work if any of the .npmrc settings that are required to publish, uses an env fallback, since the syntax isn't supported by npm.

Any use of the:-fallback syntax in .npmrc files is now stripped before publishing, using the newstripEnvFallback function from@pnpm/config.env-replace.

I opted to createstripEnvFallback since using the existingenvReplace would place the actual env value in the .npmrc file, which is not desirable for security reasons, even if pnpm attempts to delete the temp npmrc after publishing.

@zkochan
Copy link
Member

could we just stop copying the.npmrc file to the dest folder and pass npm CLI the settings via env variables?

cc@KSXGitHub

@KSXGitHub
Copy link
Contributor

could we just stop copying the.npmrc file to the dest folder and pass npm CLI the settings via env variables?

I'm not sure how it's going to work with keys like//registry.npmjs.org/:_authToken.

"@pnpm/plugin-commands-publishing":patch
---

pnpm uses npm under the hood when publishing, and npm doesn't support the`:-fallback` syntax, resulting in npm not reading any envs specified with a fallback. For example, if the npmrc contains`//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN-fallback}`, all publish commands fails even if the NODE_AUTH_TOKEN env is set. The fallbacks are now stripped before publishing, i.e. the line becomes`//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this misses a: here.

Suggested change
pnpm uses npm under the hood when publishing, and npm doesn't support the`:-fallback` syntax, resulting in npm not reading any envs specified with a fallback. For example, if the npmrc contains`//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN-fallback}`, all publish commands fails even if the NODE_AUTH_TOKEN env is set. The fallbacks are now stripped before publishing, i.e. the line becomes`//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}`.
pnpm uses npm under the hood when publishing, and npm doesn't support the`:-fallback` syntax, resulting in npm not reading any envs specified with a fallback. For example, if the npmrc contains`//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN:-fallback}`, all publish commands fails even if the NODE_AUTH_TOKEN env is set. The fallbacks are now stripped before publishing, i.e. the line becomes`//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Stripping could cause inconsistent behavior betweenpnpm publish and other commands.

I wonder if we can replace the whole${NODE_AUTH_TOKEN:-fallback} with its actual value. What do you think,@zkochan?

Copy link
Author

Choose a reason for hiding this comment

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

This change only strips the fallbacks in the temporary file that is copied to the tmp directory that is used to publish from, not touching the original .npmrc file, so it shouldn't affect any other commands.

As mentioned in the PR description, I'd personally advise against actually placing the secret in the file and writing it to disk. What if therunNpm throws and rimraf isn't called? What if the code is changed later on, without the dev being attentive to the fact that a file which normally doesn't contain sensitive values now does? It seems like a risky approach to me.

Comment on lines +25 to +26
constENV_EXPR=/(?<!\\)(\\*)\$\{([^${}]+)\}/g
constENV_VALUE=/([^:-]+)(:?)-(.+)/
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like complex RegExps. I prefer JavaScript functions that call.startsWith,.endsWith,.includes,.split, etc.

Copy link
Author

Choose a reason for hiding this comment

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

Neither of these are introduced by this PR. As mentioned in the description and in the code comment, I'm considering this PR a WIP untilpnpm/components#25 is either merged, or a different approach is agreed upon. Both of the RegExp's are copied from@pnpm/config.env-replace :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@KSXGitHubKSXGitHubKSXGitHub left review comments

@zkochanzkochanAwaiting requested review from zkochanzkochan is a code owner

Copilot code reviewCopilotAwaiting requested review from CopilotCopilot will automatically review once the pull request is marked ready for review

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@monholm@zkochan@KSXGitHub

[8]ページ先頭

©2009-2025 Movatter.jp