Skip to content

fix(plugins): load imported ESM packages with CommonJS wrappers - #540

Merged
vastsa merged 2 commits into
vastsa:mainfrom
Blue-Berrys:fix/issue-506-esm-wrapper
Sep 18, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
Blue-Berrys:fix/issue-506-esm-wrapper

Conversation

@Blue-Berrys

@Blue-Berrys Blue-Berrys commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

An imported Pi package with "type": "module" currently makes the generated CommonJS main.js wrapper fail with module is not defined in ES module scope. Generate main.cjs and point the manifest at it so the wrapper loads without changing the package's module semantics.

Fixes #506.

Regression coverage loads ESM, CommonJS and untyped packages through the real plugin-host child process, checks the skill/extension catalog and preserved package files, and verifies that re-importing creates a working new copy without rewriting an older import. Existing broken copies are not migrated automatically; remove the failed import and import its source again. The paired English/Chinese specs document this boundary.

Validation on macOS arm64 / Node 25.5.0, in a dedicated worktree:

  • Candidate 4964d0245956f1f5098d95f78980dc01820d8ee3, based on cdc63d06b53eeaa5683ae3f7be804e86181eeda3.
  • pnpm build:js passed after merging current main into the published branch without rewriting history.
  • 36 related importer/skill tests passed, including 7 real plugin-host cases. Independent review reran those 7 cases successfully.
  • Typecheck and lint passed during initial validation; pnpm docs:check passed again on the latest candidate (460 pages).
  • Reproduced the original ESM failure before the fix.

Windows, the native picker, external npm installation and arbitrary third-party extension/model execution were not tested.

Include the current plugin runtime and SDK baseline before rerunning
the imported-package wrapper integration tests. Preserve the published
branch history so the candidate can be pushed without rewriting commits.
@vastsa
vastsa merged commit 3ff6ed4 into vastsa:main Sep 18, 2026
3 of 4 checks passed
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.

[Bug] Imported Pi packages with type: module fail because generated main.js is CommonJS

2 participants