FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Proper way of finding `npm pack` `filename` output. by ovcharenko · Pull Request #3460 · pre-commit/pre-commit · GitHub

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

Closed
ovcharenko wants to merge 1 commit into
pre-commit:mainfrom
ovcharenko:main
Closed

fix: Proper way of finding npm pack filename output.#3460
ovcharenko wants to merge 1 commit into
pre-commit:mainfrom
ovcharenko:main

Conversation

Copy link
Copy Markdown

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 commented May 9, 2025

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
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 commented May 9, 2025

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Author

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

19d0b42 should do this, right?

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

Copy link
Copy Markdown
Author

@asottile any chance to get this merged any soon?

Comment thread tests/languages/node_test.py Outdated
Comment on lines +141 to +143
"devDependencies": {
"typescript": "^5.3.0"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@asottile I took an example from #3259 instead. Will that work?

Comment thread pre_commit/languages/node.py Outdated
Comment thread pre_commit/util.py
Comment on lines +241 to +250


def get_npm_version() -> tuple[int, ...]:
_, out, _ = cmd_output('npm', '--version')
version_match = re.match(r'^(\d+)\.(\d+)\.(\d+)', out)

if version_match is None:
return 0, 0, 0
else:
return tuple(map(int, version_match.groups()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

new code should not end up in utils -- also this is only used in one place

Comment on lines +106 to +108
# https://docs.npmjs.com/cli/v11/using-npm/changelog#1100-pre0-2024-11-26
if npm_version >= (11, 0, 0):
args.append('--ignore-scripts')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this seems unrelated to your patch / not necessary

Comment on lines +113 to +114
except json.JSONDecodeError as e:
raise ValueError('Failed to parse npm pack output as JSON.') from e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

just let it raise no reason to catch and reraise

Comment on lines +116 to +127
if not pkg_json:
raise ValueError('JSON array from npm pack is empty.')

if not isinstance(pkg_json, list):
raise ValueError('Expected npm pack output to be a JSON array.')

filename = pkg_json[0].get('filename')
if filename is None:
raise KeyError(
"Key 'filename' not found in the first element "
'of the JSON array.',
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would just let these raise

Comment on lines +116 to +117
def _make_hello_world(tmp_path, package_json=None):
package_json = package_json or '''\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

rather than changing this function -- call it and then write a package.json in the specific test below

assert ret == (0, b'Hello World\n')


def test_node_with_prepare_script(tmp_path):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

can you show the output of this failing before your patch?

Copy link
Copy Markdown
Member

via #3719

asottile closed this Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL