-
-
Notifications
You must be signed in to change notification settings - Fork 906
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
base: main
Are you sure you want to change the base?
Conversation
|
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. |
|
pretty sure in json mode it does a better job of obscuring the nonsense |
19d0b42 should do this, right? |
npm pack output.npm pack filename output.
|
@asottile any chance to get this merged any soon? |
tests/languages/node_test.py
Outdated
| "devDependencies": { | ||
| "typescript": "^5.3.0" | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bbabec2 to
928edc0
Compare
|
|
||
|
|
||
| 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())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new code should not end up in utils -- also this is only used in one place
| # https://docs.npmjs.com/cli/v11/using-npm/changelog#1100-pre0-2024-11-26 | ||
| if npm_version >= (11, 0, 0): | ||
| args.append('--ignore-scripts') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems unrelated to your patch / not necessary
| except json.JSONDecodeError as e: | ||
| raise ValueError('Failed to parse npm pack output as JSON.') from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just let it raise no reason to catch and reraise
| 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.', | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just let these raise
| def _make_hello_world(tmp_path, package_json=None): | ||
| package_json = package_json or '''\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you show the output of this failing before your patch?
That will fix pollution of installation path with TypeScript output: