8000 fix: Proper way of finding `npm pack` `filename` output. by ovcharenko · Pull Request #3460 · pre-commit/pre-commit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Proper way of finding npm pack filename output. #3460

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 2 commits into
base: main
Choose a base branch
from

Conversation

ovcharenko
Copy link

That will fix pollution of installation path with TypeScript output:

E           pre_commit.util.CalledProcessError: command: ('/private/var/folders/sd/qk6llt717b99lp1wgtym5qwm0000gn/T/pytest-of-local.user/pytest-16/test_node_typescript_hook_syst0/node_env-system/bin/node', '/opt/homebrew/bin/npm', 'install', '-g', '/private/var/folders/sd/qk6llt717b99lp1wgtym5qwm0000gn/T/pytest-of-local.user/pytest-16/test_node_typescript_hook_syst0/> t@0.0.1 prepare\n> tsc\n\nt-0.0.1.tgz')
E           return code: 254
E           stdout: (none)
E           stderr:
E               npm warn tarball tarball data for file:/private/var/folders/sd/qk6llt717b99lp1wgtym5qwm0000gn/T/pytest-of-local.user/pytest-16/test_node_typescript_hook_syst0/> t@0.0.1 prepare> tsct-0.0.1.tgz (null) seems to be corrupted. Trying again.
E               npm warn tarball tarball data for file:/private/var/folders/sd/qk6llt717b99lp1wgtym5qwm0000gn/T/pytest-of-local.user/pytest-16/test_node_typescript_hook_syst0/> t@0.0.1 prepare> tsct-0.0.1.tgz (null) seems to be corrupted. Trying again.
E               npm error code ENOENT
E               npm error syscall open
E               npm error path /private/var/folders/sd/qk6llt717b99lp1wgtym5qwm0000gn/T/pytest-of-local.user/pytest-16/test_node_typescript_hook_syst0/> t@0.0.1 prepare> tsct-0.0.1.tgz
E               npm error errno -2
E               npm error enoent ENOENT: no such file or directory, open '/private/var/folders/sd/qk6llt717b99lp1wgtym5qwm0000gn/T/pytest-of-local.user/pytest-16/test_node_typescript_hook_syst0/> t@0.0.1 prepare> tsct-0.0.1.tgz'
E               npm error enoent This is related to npm not being able to find a file.
E               npm error enoent
E               npm error A complete log of this run can be found in: /Users/local.user/.npm/_logs/2025-05-09T10_21_58_861Z-debug-0.log

@asottile
Copy link
Member
asottile commented May 9, 2025

the other branch which tried to solve this is here and my recommendation: #3259 (comment)

@ovcharenko
Copy link
Author

the other branch which tried to solve this is here and my recommendation: #3259 (comment)

That doesn't help much IMHO, because the JSON is part of other noisy output. So instead of one-line fix you will have to find JSON object and handle all error parsing.

@asottile
Copy link
Member
asottile commented May 9, 2025

pretty sure in json mode it does a better job of obscuring the nonsense

@ovcharenko
Copy link
Author

pretty sure in json mode it does a better job of obscuring the nonsense

19d0b42 should do this, right?

@ovcharenko ovcharenko changed the title fix: Process only the last line of npm pack output. fix: Proper way of finding npm pack filename output. May 9, 2025
@ovcharenko
Copy link
Author

@asottile any chance to get this merged any soon?

Comment on lines +141 to +143
"devDependencies": {
"typescript": "^5.3.0"
}
Copy link
Member

Choose a reason for hiding this comment

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

this is going to make the test prohibitively slow -- can you make a faster example?

pkg = prefix.path(pkg.strip())
_, pkg, _ = cmd_output('npm', 'pack', '--json', cwd=prefix.prefix_dir)
pkg_json = json.loads(pkg)
pkg = prefix.path(pkg_json[0].get('filename'))
Copy link
Member

Choose a reason for hiding this comment

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

.get will "silently" fail when the key is missing -- use brackets to access keys in a dictionary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0