Skip to content

Tighten runtime packaging and version cache behavior - #554

Merged
imjlk merged 2 commits into
mainfrom
codex/issue-550-runtime-packaging-followup
Apr 23, 2026
Merged

Tighten runtime packaging and version cache behavior#554
imjlk merged 2 commits into
mainfrom
codex/issue-550-runtime-packaging-followup

Conversation

@imjlk

@imjlk imjlk commented Apr 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • strip dist-bunli source maps from the published wp-typia tarball while restoring them locally after pack
  • add cache invalidation support to package-versions so long-lived processes recompute when package manifests change
  • lock the new packaging and cache behavior in unit and package-level tests

Testing

  • bun run typecheck
  • bun test tests/unit/package-versions.test.ts
  • cd packages/wp-typia && bun test tests/bunli-prep.test.ts tests/cli-package.test.ts

Closes #550

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced package version caching with automatic recomputation when manifest files change.
    • Improved publishing lifecycle to properly manage source map files during package distribution—source maps are now excluded from published packages but remain available in local builds.
    • Added manual cache invalidation capability for package version information.

@sampo-s-bot

sampo-s-bot Bot commented Apr 23, 2026

Copy link
Copy Markdown

⚠️ No changeset detected

No new .sampo/changesets/*.md files were detected in this PR. To add one:

  • run sampo add
  • follow the prompts to pick the affected packages and describe the change
  • commit the generated file to this pull request, and it will be detected automatically

If this PR isn't supposed to introduce any changes (e.g., documentation updates), you can ignore this message.

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@imjlk has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 40 minutes and 25 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 40 minutes and 25 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54ac9b03-0985-44fb-9128-606d12682cdf

📥 Commits

Reviewing files that changed from the base of the PR and between 05fd5cc and c7de186.

📒 Files selected for processing (4)
  • packages/wp-typia-project-tools/src/runtime/package-versions.ts
  • packages/wp-typia/scripts/publish-runtime-maps.mjs
  • packages/wp-typia/tests/cli-package.test.ts
  • packages/wp-typia/tests/publish-runtime-maps.test.ts
📝 Walkthrough

Walkthrough

This PR implements caching for package version resolution with file-system-based invalidation, and introduces a publish-time backup/restore script that excludes source maps from npm pack tarballs while preserving them in local builds.

Changes

Cohort / File(s) Summary
Package Version Caching
packages/wp-typia-project-tools/src/runtime/package-versions.ts, tests/unit/package-versions.test.ts
Adds file-system-aware caching mechanism for PackageVersions using manifest metadata (mtimeMs, size). Exports invalidatePackageVersionsCache() for manual cache clearing. Tests verify automatic recomputation on workspace manifest changes and manual invalidation.
Runtime Maps Publish Script
packages/wp-typia/scripts/publish-runtime-maps.mjs, packages/wp-typia/tests/bunli-prep.test.ts
New script that backs up *.map files before npm pack (prepare mode) and restores them after (restore mode), with support for skipping restore via environment variable. Tests verify script integration into package.json lifecycle hooks.
Package Configuration
packages/wp-typia/package.json
Updates build scripts: clean removes .pack-backup directory, prepack runs prepare phase, and new postpack hook runs restore phase for source maps.
CLI Package Tests
packages/wp-typia/tests/cli-package.test.ts
Adds assertions verifying that npm pack tarball excludes *.map files while local dist-bunli output includes them.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Skip postpack restore during npm publish #174: Implements matching postpack "skip restore" behavior (WP_TYPIA_SKIP_POSTPACK_RESTORE) in publish-manifest.mjs, directly paralleling the new environment variable support in this PR's publish-runtime-maps.mjs.

Suggested reviewers

  • sampo-s-bot

Poem

🐰 A rabbit prepared, then restored with great care,
Maps backed up safe in the .pack-backup lair,
With caches that learn when the manifest dance,
Runtime behavior gets its second chance! 🗺️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: tightening runtime packaging (source map handling) and version cache behavior (cache invalidation support).
Linked Issues check ✅ Passed The PR directly addresses the coding requirements from issue #550: it removes source maps from published tarball and restores them locally, adds cache invalidation for package-versions, and locks behavior in tests.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objectives: packaging metadata hygiene, published footprint reduction, and long-lived process metadata invalidation support.

✏️ 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 codex/issue-550-runtime-packaging-followup

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05fd5cceed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/wp-typia/scripts/publish-runtime-maps.mjs Outdated
Comment thread packages/wp-typia/scripts/publish-runtime-maps.mjs Outdated

@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: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/wp-typia/tests/cli-package.test.ts (1)

473-479: ⚠️ Potential issue | 🟡 Minor

Make the pack-restore test independent of ambient skip flags.

The new local map assertions depend on postpack restore running, but this spawned npm pack inherits WP_TYPIA_SKIP_POSTPACK_RESTORE=1 if a developer or CI job has it set. Clear it for this command so the test always validates the default restore behavior.

Proposed fix
     const packResult = runCapturedCommand(
       'npm',
       ['pack', '--json', '--pack-destination', packageRoot],
       {
         cwd: packageRoot,
+        env: {
+          ...process.env,
+          WP_TYPIA_SKIP_POSTPACK_RESTORE: '',
+        },
       },
     );

Also applies to: 535-542

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/wp-typia/tests/cli-package.test.ts` around lines 473 - 479, The
test's spawned npm pack inherits the WP_TYPIA_SKIP_POSTPACK_RESTORE env var and
can skip the postpack restore; update the two runCapturedCommand invocations
(the one that produces packResult and the similar call around lines 535-542) to
explicitly clear WP_TYPIA_SKIP_POSTPACK_RESTORE in the env passed to
runCapturedCommand (i.e., construct the command's env from process.env but
delete or unset WP_TYPIA_SKIP_POSTPACK_RESTORE) so the pack process always runs
the default postpack restore during the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/wp-typia-project-tools/src/runtime/package-versions.ts`:
- Around line 115-117: Add an English JSDoc block for the public function
invalidatePackageVersionsCache describing what it does (clears the internal
cachedPackageVersions), when callers should invoke it (e.g., in long‑lived
processes after package manifests or versions have been regenerated or updated),
and any side effects/behavior (synchronous, no return value). Place the JSDoc
directly above the exported function declaration so it documents the public
runtime API.
- Around line 67-83: The cache key produced by resolvePackageManifestLocation
can remain unchanged for rapid rewrites on filesystems with coarse mtimeMs,
causing stale getPackageVersions() results; modify
resolvePackageManifestLocation to include additional fast-changing identifiers
(e.g., stats.ino and stats.ctimeMs) in the cacheKey and, if those fields are not
available or reliable, compute and include a cheap short content fingerprint
(e.g., a truncated hash of fs.readFileSync(packageJsonPath)) as a fallback;
update references to resolvePackageManifestLocation, getPackageVersions, and
invalidatePackageVersionsCache as needed to ensure the cacheKey change is used
for lookups so rapid same-size edits are detected.

In `@packages/wp-typia/scripts/publish-runtime-maps.mjs`:
- Around line 39-45: The build currently treats a missing runtime directory as
fine because collectSourceMapRelativePaths(distRoot) returns [], allowing
preparePublishedRuntimeMaps to succeed; change preparePublishedRuntimeMaps to
explicitly check for the existence of distRoot (the runtime output directory
returned by getPublishRuntimeMapPaths) before proceeding and throw a clear Error
if the directory is missing so prepack fails fast; locate
preparePublishedRuntimeMaps and add a guard using fs.existsSync(distRoot) (or
equivalent) that throws a descriptive error referencing the missing distRoot
when the directory does not exist.
- Around line 77-85: The loop currently skips missing backups silently: in the
for (const relativePath of relativePaths) loop check backupPath existence and if
missing, instead of unconditionally continue, compute destinationPath and if
destinationPath already exists keep idempotency (continue) but if
destinationPath does NOT exist treat this as a genuine missing restore and throw
an error or call process.exit(1) so the script fails non‑zero; update the block
that uses backupPath, destinationPath, fs.existsSync, fs.mkdirSync and
fs.renameSync accordingly and ensure the overall script does not proceed to
delete backupRoot when that error occurs.
- Line 5: The constant DEFAULT_PACKAGE_ROOT currently uses import.meta.dirname
which isn't available on Node 20; replace it by deriving the file path from
import.meta.url: import fileURLToPath from 'url' and compute
DEFAULT_PACKAGE_ROOT with
path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..") (i.e., remove
import.meta.dirname usage, add the fileURLToPath import, and call path.dirname
on the converted file path).

---

Outside diff comments:
In `@packages/wp-typia/tests/cli-package.test.ts`:
- Around line 473-479: The test's spawned npm pack inherits the
WP_TYPIA_SKIP_POSTPACK_RESTORE env var and can skip the postpack restore; update
the two runCapturedCommand invocations (the one that produces packResult and the
similar call around lines 535-542) to explicitly clear
WP_TYPIA_SKIP_POSTPACK_RESTORE in the env passed to runCapturedCommand (i.e.,
construct the command's env from process.env but delete or unset
WP_TYPIA_SKIP_POSTPACK_RESTORE) so the pack process always runs the default
postpack restore during the test.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a0d87d1-27a5-4aaa-9a5a-9228afcc7410

📥 Commits

Reviewing files that changed from the base of the PR and between b54a4a6 and 05fd5cc.

📒 Files selected for processing (6)
  • packages/wp-typia-project-tools/src/runtime/package-versions.ts
  • packages/wp-typia/package.json
  • packages/wp-typia/scripts/publish-runtime-maps.mjs
  • packages/wp-typia/tests/bunli-prep.test.ts
  • packages/wp-typia/tests/cli-package.test.ts
  • tests/unit/package-versions.test.ts

Comment thread packages/wp-typia-project-tools/src/runtime/package-versions.ts
Comment thread packages/wp-typia-project-tools/src/runtime/package-versions.ts
Comment thread packages/wp-typia/scripts/publish-runtime-maps.mjs Outdated
Comment thread packages/wp-typia/scripts/publish-runtime-maps.mjs
Comment thread packages/wp-typia/scripts/publish-runtime-maps.mjs
@imjlk
imjlk merged commit b971dc9 into main Apr 23, 2026
18 checks passed
@imjlk
imjlk deleted the codex/issue-550-runtime-packaging-followup branch April 25, 2026 12:50
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.

Follow-up: audit published runtime footprint, packaging metadata, and long-lived toolchain behavior

1 participant