Skip to content
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

fix crash when project contains a package.json with "type: "module" #862

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ Thumbs.db
**/__pycache__
/.venv/

# js files copied into the basedpyright pypi package
# files from the npm package copied into the basedpyright pypi package
basedpyright/*.js
basedpyright/package.json

# typeshed stubs with docstrings
docstubs
7 changes: 5 additions & 2 deletions pdm_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from json import loads
from pathlib import Path
from shutil import copyfile, copytree
from shutil import copy, copyfile, copytree
from typing import TYPE_CHECKING, TypedDict, cast

from nodejs_wheel.executable import npm
Expand Down Expand Up @@ -34,7 +34,8 @@ def pdm_build_update_files(self, context: Context, files: dict[str, Path]):
npm_package_dir = Path("packages/pyright")
pypi_package_dir = Path("basedpyright")
dist_dir = Path("dist")
npm_script_paths = cast(PackageJson, loads((npm_package_dir / "package.json").read_text()))[
package_json = "package.json"
npm_script_paths = cast(PackageJson, loads((npm_package_dir / package_json).read_text()))[
"bin"
].values()
generate_docstubs()
Expand All @@ -43,10 +44,12 @@ def pdm_build_update_files(self, context: Context, files: dict[str, Path]):
run_npm("run", "build:cli:dev")

if context.target == "editable":
copy(npm_package_dir / package_json, pypi_package_dir)
copytree(npm_package_dir / dist_dir, pypi_package_dir / dist_dir, dirs_exist_ok=True)
for script_path in npm_script_paths:
_ = copyfile(npm_package_dir / script_path, pypi_package_dir / script_path)
else:
files[str(pypi_package_dir / package_json)] = npm_package_dir / package_json
for file in (npm_package_dir / dist_dir).rglob("**/*"):
if file.is_file():
files[str(pypi_package_dir / file.relative_to(npm_package_dir))] = file
Expand Down
Loading