Skip to content

fix publish scope rewrite for dist output#40

Open
qingliaowu wants to merge 1 commit into
salesforce:mainfrom
qingliaowu:fix-publish-dist-scope
Open

fix publish scope rewrite for dist output#40
qingliaowu wants to merge 1 commit into
salesforce:mainfrom
qingliaowu:fix-publish-dist-scope

Conversation

@qingliaowu
Copy link
Copy Markdown

@qingliaowu qingliaowu commented May 16, 2026

Summary

This fixes #35

Fixes the release-time scope rewrite so published packages do not keep @agentscript/* imports in their compiled dist files.

The publish script already rewrites package metadata from @agentscript/* to @sf-agentscript/*, but the compiled JS and type declaration files are produced before that rewrite happens. As a result, the published package can install dependencies under @sf-agentscript/* while the runtime code still imports @agentscript/*.

This PR extends the publish step to also rewrite built output files before publishing.

What Changed

  • Rewrites @agentscript/* to @sf-agentscript/* inside package dist folders
  • Covers JS, CJS, MJS, declaration files, and source maps
  • Keeps the internal source code unchanged
  • Adds a patch Changeset so affected public packages are republished with corrected output

Why This Fix

This keeps the existing development workflow intact while making the npm-published artifacts match the published package scope.

That means installed packages should resolve imports like:

@sf-agentscript/parser






## What

Fixes release-time scope rewriting so published packages do not keep `@agentscript/*` imports in compiled `dist` files.

## Why

The publish script already rewrites package metadata from `@agentscript/*` to `@sf-agentscript/*`, but compiled output is built before that rewrite. This means npm installs dependencies under `@sf-agentscript/*` while runtime JS can still import `@agentscript/*`, causing module resolution failures.

Fixes #35.

## How

Extended `scripts/publish.mjs` to rewrite built package outputs under each package’s `dist` directory before publishing.

The rewrite covers publish artifacts where package specifiers can appear:

- `.js`
- `.mjs`
- `.cjs`
- `.d.ts`
- `.d.mts`
- `.d.cts`
- `.map`

The source packages still use the internal `@agentscript/*` scope during development; only publish-time artifacts are rewritten.

Added a patch Changeset so affected public packages are republished with corrected `dist` output.

## Test Plan

- [x] Existing tests pass (`pnpm test`)
- [x] New/updated tests cover the change
- [x] Linting and type checks pass (`pnpm lint && pnpm typecheck`)
- [x] `node --check scripts/publish.mjs`
- [x] Smoke-tested `rewriteDistFiles` against nested `.js`, `.d.ts`, and `.map` files
- [x] `pnpm dlx prettier@3.8.1 --check scripts/publish.mjs .changeset/fix-publish-dist-scope.md`

## Checklist

- [x] My code follows the project's coding style
- [x] I have reviewed my own diff
- [x] I have added/updated documentation as needed
- [x] This change does not introduce new warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: dist/ JS retains @agentscript/* imports after scope rewrite, breaking installed package

1 participant