Skip to content

Add npm#12

Merged
SpyC0der77 merged 4 commits into
mainfrom
add-npm
Jun 7, 2026
Merged

Add npm#12
SpyC0der77 merged 4 commits into
mainfrom
add-npm

Conversation

@SpyC0der77

@SpyC0der77 SpyC0der77 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • minecraft-script released as an npm package providing mcs/minecraft-script CLI entrypoints
    • npm install now attempts to auto-install the matching Python package
  • Chores

    • .gitignore updated to exclude build/output and local package artifacts
  • Documentation

    • Added configuration docs for changing compile output path; clarified cross‑platform (Windows/macOS/Linux) support

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@SpyC0der77, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 51 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be62b8bb-d62d-49d3-92fd-9fa593019d78

📥 Commits

Reviewing files that changed from the base of the PR and between d193a91 and c30aaf1.

📒 Files selected for processing (1)
  • npm/scripts/postinstall.js
📝 Walkthrough

Walkthrough

This PR adds an npm package wrapper that distributes the minecraft-script Python CLI: a package manifest, a Node.js CLI shim delegating to the Python module, a postinstall script to pip-install the matching Python package, pathlib-based path handling updates in Python code, and .gitignore additions.

Changes

NPM Package Wrapper for Python CLI

Layer / File(s) Summary
Package manifest and configuration
npm/package.json, .gitignore
Defines minecraft-script npm package (v0.2.2) with CLI binaries mcs and minecraft-script pointing to the Node.js shim, a postinstall lifecycle hook, Node ≥18 requirement, publish file whitelist; .gitignore excludes npm build outputs and local tarballs.
CLI shim for Python module delegation
npm/bin/mcs.js
Entry point that constructs arguments for the Python module (-m minecraft_script), tries multiple Python candidates (py, python, python3) synchronously, skips missing executables, and exits with the child process code or prints an error if no Python is found.
Post-install Python dependency management
npm/scripts/postinstall.js
Reads package version and attempts pip install minecraft-script==<version> via candidate Python/pip executables; continues on ENOENT, returns on success, and logs a failure or manual install instructions on error or if no Python is available.
Path handling updates in Python
minecraft_script/config_utils.py, minecraft_script/shell_commands.py
Replaces os.path usage with pathlib.Path: expanduser/resolve for normalization, existence checks via Path methods, derive datapack name from Path.name, and pass resolved path strings into build calls.
Docs
readme.md
Adds config set default_output_path <path> documentation and updates compatibility statement to explicitly list Windows, macOS, and Linux and advises using native platform path separators.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit typed a tiny script,
That hops from npm to Python's crypt,
It tries each py, then python3,
Installs the package, sets files free,
And leaves a path resolved and cryptic-sipped.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Add npm" is vague and does not clearly convey the scope or significance of the changes, which include npm package setup, CLI entrypoints, Node.js integration, and Python installation coordination. Use a more descriptive title such as "Add npm package with CLI entrypoint and postinstall setup" or "Publish minecraft-script as npm package with Node.js CLI wrapper" to clarify the primary objective.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-npm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread npm/package.json Outdated
},
"repository": {
"type": "git",
"url": "git+https://github.com/Bard-Gaming/Minecraft-Script.git",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Repository URL points to Bard-Gaming instead of SpyC0der77

@kilo-code-bot

kilo-code-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file in incremental diff)
  • npm/scripts/postinstall.js - No new issues (unnecessary result.status != null guard removed; functionally equivalent simplification)

Reviewed by step-3.7-flash-20260528 · 185,325 tokens

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="npm/package.json">

<violation number="1" location="npm/package.json:3">
P2: Missing `"os"` field: The readme explicitly states this package does not work on Linux/macOS, but the package.json does not enforce this restriction with `"os": ["win32"]`. Without it, users on unsupported platforms can install the npm package and encounter confusing failures instead of a clear install-time error.</violation>

<violation number="2" location="npm/package.json:23">
P2: The repository, homepage, and bugs URLs all point to `Bard-Gaming/Minecraft-Script`. Verify these point to the correct GitHub owner/organization for this project. If this repository is under a different account (e.g., `SpyC0der77`), these URLs will misdirect users looking for source code, filing issues, etc.</violation>
</file>

<file name="npm/scripts/postinstall.js">

<violation number="1" location="npm/scripts/postinstall.js:25">
P2: The loop exits after the first non-ENOENT failure, so fallback Python commands are never tried.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread npm/scripts/postinstall.js
Comment thread npm/package.json
@@ -0,0 +1,36 @@
{
"name": "minecraft-script",
"version": "0.2.2",

@cubic-dev-ai cubic-dev-ai Bot Jun 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Missing "os" field: The readme explicitly states this package does not work on Linux/macOS, but the package.json does not enforce this restriction with "os": ["win32"]. Without it, users on unsupported platforms can install the npm package and encounter confusing failures instead of a clear install-time error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At npm/package.json, line 3:

<comment>Missing `"os"` field: The readme explicitly states this package does not work on Linux/macOS, but the package.json does not enforce this restriction with `"os": ["win32"]`. Without it, users on unsupported platforms can install the npm package and encounter confusing failures instead of a clear install-time error.</comment>

<file context>
@@ -0,0 +1,36 @@
+{
+  "name": "minecraft-script",
+  "version": "0.2.2",
+  "description": "Compile and debug Minecraft Script (.mcs) files into Minecraft datapacks",
+  "license": "MIT",
</file context>
Fix with cubic

Comment thread npm/package.json Outdated
@SpyC0der77

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
npm/package.json (1)

21-29: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

WARNING: Repository metadata points to Bard-Gaming instead of SpyC0der77

The repository URLs reference https://github.com/Bard-Gaming/Minecraft-Script but the PR is opened from the SpyC0der77 account. Verify that the repository ownership is correct for publishing this npm package.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@npm/package.json` around lines 21 - 29, The package metadata in
npm/package.json currently points to the Bard-Gaming repo; update the
"repository" object (type/url/directory) and the "homepage" and "bugs" fields to
reference the correct GitHub account (SpyC0der77) so URLs reflect the PR owner;
ensure the "repository.url" uses the git+https URL with SpyC0der77, "homepage"
points to the SpyC0der77 repo readme, and "bugs.url" points to the SpyC0der77
issues page to keep package publishing metadata consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@npm/bin/mcs.js`:
- Around line 17-21: The loop currently exits on non-ENOENT spawn errors; change
the logic in npm/bin/mcs.js so that you only call process.exit when the command
actually executed (i.e., when result.status is defined) and not when spawn
produced an error. Concretely, keep checking result.error?.code === "ENOENT" to
continue, but ALSO treat any result.error (non-ENOENT) as a reason to continue
to the next candidate (do not call process.exit there); only invoke
process.exit(result.status ?? 1) when result.status is present (meaning the
spawn succeeded and returned an exit code).

In `@npm/scripts/postinstall.js`:
- Around line 20-33: The postinstall logic currently returns on non-zero pip
exit or spawn errors, preventing trying other candidates; modify the flow around
the result/error handling so that any spawn error (result.error is truthy)
causes the loop to continue (except you may still continue on ENOENT as already
done) and only treat a completed process with result.status !== 0 as the
condition to warn and return. Concretely, in the block using result.error?.code
and result.status, move or add the check so that if result.error exists you
continue to the next candidate (preserving the existing ENOENT special-case),
and only call console.warn and return when result.status is defined and
non-zero.

---

Duplicate comments:
In `@npm/package.json`:
- Around line 21-29: The package metadata in npm/package.json currently points
to the Bard-Gaming repo; update the "repository" object (type/url/directory) and
the "homepage" and "bugs" fields to reference the correct GitHub account
(SpyC0der77) so URLs reflect the PR owner; ensure the "repository.url" uses the
git+https URL with SpyC0der77, "homepage" points to the SpyC0der77 repo readme,
and "bugs.url" points to the SpyC0der77 issues page to keep package publishing
metadata consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f9f93f28-2516-43ae-bbdf-cc85e1f4e119

📥 Commits

Reviewing files that changed from the base of the PR and between d3c028d and ce2b081.

📒 Files selected for processing (4)
  • .gitignore
  • npm/bin/mcs.js
  • npm/package.json
  • npm/scripts/postinstall.js

Comment thread npm/bin/mcs.js Outdated
Comment thread npm/scripts/postinstall.js Outdated
…tilities

- Updated README to clarify that the Python package is compatible with Windows, macOS, and Linux.
- Refactored path handling in `config_utils.py` and `shell_commands.py` to use `pathlib` for improved cross-platform compatibility and readability.
- Adjusted error handling in shell commands to provide clearer messages for file and directory validation.
- Updated npm package repository URLs to reflect the new maintainer.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="npm/scripts/postinstall.js">

<violation number="1" location="npm/scripts/postinstall.js:20">
P2: Non-ENOENT process spawn errors are silently ignored, which can misreport failures as "Python was not found".</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment on lines +20 to +22
if (result.error) {
continue;
}

@cubic-dev-ai cubic-dev-ai Bot Jun 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Non-ENOENT process spawn errors are silently ignored, which can misreport failures as "Python was not found".

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At npm/scripts/postinstall.js, line 20:

<comment>Non-ENOENT process spawn errors are silently ignored, which can misreport failures as "Python was not found".</comment>

<file context>
@@ -17,20 +17,22 @@ const candidates = [
   const result = spawnSync(command, args, { stdio: "inherit" });
 
-  if (result.error?.code === "ENOENT") {
+  if (result.error) {
     continue;
   }
</file context>
Suggested change
if (result.error) {
continue;
}
if (result.error?.code === "ENOENT") {
continue;
}
if (result.error) {
console.warn(
"\n[minecraft-script] Failed to install the Python package via pip.\n" +
"Install it manually with:\n" +
` pip install minecraft-script==${version}\n`
);
return;
}
Fix with cubic

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
npm/scripts/postinstall.js (1)

28-35: ⚡ Quick win

Consider trying all candidates before stopping on non-zero exit.

The script now correctly continues on spawn errors (line 20), but if a candidate runs and exits with a non-zero status, it warns and returns immediately without trying the remaining candidates. While this is appropriate for network errors or missing packages (where all candidates would fail the same way), it may prevent success when pip is unavailable for the first Python but installed for another.

For example, if py -3 -m pip exits 1 because pip isn't installed for that Python, the script stops—even though python -m pip or python3 -m pip might succeed.

♻️ Proposed fix to try all candidates on any failure
  if (result.status === 0) {
    return;
  }
-
-  if (result.status != null) {
-    console.warn(
-      "\n[minecraft-script] Failed to install the Python package via pip.\n" +
-        "Install it manually with:\n" +
-        `  pip install minecraft-script==${version}\n`
-    );
-    return;
-  }
 }
 
+console.warn(
+  "\n[minecraft-script] Failed to install the Python package via pip.\n" +
+    "Install it manually with:\n" +
+    `  pip install minecraft-script==${version}\n`
+);
+return;
+
-console.warn(
-  "\n[minecraft-script] Python was not found, so the PyPI package was not installed.\n" +
-    "Install Python 3 from https://www.python.org/downloads/ and run:\n" +
-    `  pip install minecraft-script==${version}\n`
-);

This moves the pip-failure warning outside the loop so all candidates are tried, merging the two warnings into one. If finer-grained messaging is desired (distinguishing "Python not found" from "pip failed"), you can track whether any candidate actually ran.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@npm/scripts/postinstall.js` around lines 28 - 35, The current loop over
Python candidates returns immediately when a candidate runs but exits with a
non-zero status (the check on result.status), preventing later candidates from
being tried; modify the logic in the code that iterates pythonCandidates so it
does not return on a non-zero exit from a spawned pip process but instead
records that a candidate ran and failed, continues to the next candidate, and
after the loop emits a single consolidated warning if none succeeded (merge the
pip-failure and spawn-failure messages). Specifically, change the early-return
in the block that inspects result.status to continue/collect failure state,
ensure the existing spawn error path still continues, and emit the final warning
once after the loop if no successful install occurred.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@minecraft_script/config_utils.py`:
- Around line 49-54: The README/docs need a short note documenting that
config_path_check() now resolves and persists default_output_path as an absolute
path when update_config() writes to config.json, and that the CLI requires the
target directory to already exist (config_path_check will raise/exit if it
doesn't); also mention that runtime code (sh_compile) still resolves
COMMON_CONFIG["default_output_path"] before use so existing relative values
continue to work until updated.

---

Nitpick comments:
In `@npm/scripts/postinstall.js`:
- Around line 28-35: The current loop over Python candidates returns immediately
when a candidate runs but exits with a non-zero status (the check on
result.status), preventing later candidates from being tried; modify the logic
in the code that iterates pythonCandidates so it does not return on a non-zero
exit from a spawned pip process but instead records that a candidate ran and
failed, continues to the next candidate, and after the loop emits a single
consolidated warning if none succeeded (merge the pip-failure and spawn-failure
messages). Specifically, change the early-return in the block that inspects
result.status to continue/collect failure state, ensure the existing spawn error
path still continues, and emit the final warning once after the loop if no
successful install occurred.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48bc49c2-7d82-41d0-99cf-ab10a2b2f49d

📥 Commits

Reviewing files that changed from the base of the PR and between ce2b081 and b68c43d.

📒 Files selected for processing (6)
  • minecraft_script/config_utils.py
  • minecraft_script/shell_commands.py
  • npm/bin/mcs.js
  • npm/package.json
  • npm/scripts/postinstall.js
  • readme.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • npm/bin/mcs.js
  • npm/package.json

Comment thread minecraft_script/config_utils.py
… error handling

- Added a new section in README to explain how to set the default output path for compilation.
- Updated the post-install script to improve error handling and provide clearer instructions for manual installation of the Python package if automatic installation fails.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
npm/scripts/postinstall.js (1)

32-34: 💤 Low value

Consider simplifying the status check.

At this point in the code, result.error is falsy and result.status !== 0, so result.status is either a non-zero number (pip failed) or null (killed by signal). In both cases, you want to try the next candidate. The explicit != null check works but could be replaced with an unconditional continue for clarity:

 if (result.status === 0) {
   return;
 }

-if (result.status != null) {
-  continue;
-}
+// Process completed with non-zero status or was killed; try next candidate
+continue;

This simplifies the logic and makes the intent clearer. However, the current code is functionally correct, so this is optional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@npm/scripts/postinstall.js` around lines 32 - 34, The conditional check "if
(result.status != null) { continue; }" can be simplified: inside the loop that
evaluates each candidate result, replace that conditional with an unconditional
"continue;" since at this point result.error is falsy and any non-zero status or
null (killed by signal) should both skip to the next candidate; update the loop
body where the "result" variable is used to just "continue;" to make the intent
clearer.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@npm/scripts/postinstall.js`:
- Around line 32-34: The conditional check "if (result.status != null) {
continue; }" can be simplified: inside the loop that evaluates each candidate
result, replace that conditional with an unconditional "continue;" since at this
point result.error is falsy and any non-zero status or null (killed by signal)
should both skip to the next candidate; update the loop body where the "result"
variable is used to just "continue;" to make the intent clearer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 786a4e73-782b-42c6-9f7f-dc7f697a4389

📥 Commits

Reviewing files that changed from the base of the PR and between b68c43d and d193a91.

📒 Files selected for processing (2)
  • npm/scripts/postinstall.js
  • readme.md

- Removed unnecessary status check in the post-install script to simplify command processing.
- Maintained clarity in manual installation instructions for the Python package.
@SpyC0der77 SpyC0der77 merged commit 8f87a10 into main Jun 7, 2026
3 checks passed
@SpyC0der77 SpyC0der77 deleted the add-npm branch June 7, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant