fix: Proper way of finding npm pack filename output.#3460
fix: Proper way of finding npm pack filename output.#3460ovcharenko wants to merge 1 commit intopre-commit:mainfrom
npm pack filename output.#3460Conversation
|
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.
this is going to make the test prohibitively slow -- can you make a faster example?
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.
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.
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.
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.', | ||
| ) |
| def _make_hello_world(tmp_path, package_json=None): | ||
| package_json = package_json or '''\ |
There was a problem hiding this comment.
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.
can you show the output of this failing before your patch?
That will fix pollution of installation path with TypeScript output: