Skip to content

Organizing zod-plugin directories#2921

Merged
RobinTail merged 6 commits intomasterfrom
org-plugin
Sep 19, 2025
Merged

Organizing zod-plugin directories#2921
RobinTail merged 6 commits intomasterfrom
org-plugin

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Sep 6, 2025

Summary by CodeRabbit

  • Chores

    • Switch build/type entry points to source files and align package metadata resolution with project layout.
    • Broaden lint ignore patterns to cover generated/dist and coverage output.
  • Tests

    • Point test setup and test imports to source entry points for consistency.
    • Expand test discovery to include nested test files.
  • Refactor

    • Standardized internal module resolution across the codebase.

No user-facing behavior changes.

@RobinTail RobinTail added refactoring The better way to achieve the same result CI/CD labels Sep 6, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 6, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Retargets zod-plugin sources and tests to src/, updates ESLint ignore/test globs to recursive patterns, adjusts tsdown entry paths, changes test and setup imports to ../src or ./src/*, and updates a package.json import in zod-plugin/src/runtime.ts to ../package.json. No public API changes.

Changes

Cohort / File(s) Summary
Lint config
eslint.config.js
Replaced explicit ignore and test file lists with recursive globs (**/dist/, **/coverage/, compat-test/sample.ts, **/tests/*.ts, **/vitest.setup.ts, **/*.spec.ts); added pluginDir constant and an ESLint block targeting zod-plugin/src/*.ts with rules using pluginDir.
Bundler / build config
zod-plugin/tsdown.config.ts
Updated entry paths to source files: src/index.ts and src/augmentation.ts (previously root-level entries); other config flags unchanged.
Runtime package import
zod-plugin/src/runtime.ts
Changed import of name from ./package.json to ../package.json.
Vitest setup
zod-plugin/vitest.setup.ts
Switched import from ./runtime to ./src/runtime.
Tests retargeted to src
zod-plugin/tests/*
zod-plugin/tests/brand.spec.ts, zod-plugin/tests/index.spec.ts, zod-plugin/tests/packer.spec.ts, zod-plugin/tests/runtime.spec.ts
Test imports updated from local sibling modules (e.g., ./brand, ./packer, ./index) to package source under ../src (e.g., ../src, ../src/brand, ../src/packer); test logic unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

A rabbit hops where code paths cleave,
Src-bound trails the devs conceive.
Globs unfurl and tests take flight,
Parent package beams with light.
I pack the changes — soft goodnight 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Organizing zod-plugin directories" accurately and concisely describes the main intent of the changeset: many imports and config entrypoints were updated to point at src/ (tests, vitest setup, tsdown config), the runtime package.json import was redirected, and eslint globs were broadened — all indicating a directory reorganization rather than functional/API changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a127b8 and 150e9bc.

📒 Files selected for processing (1)
  • eslint.config.js (4 hunks)

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.

@coveralls-official
Copy link
Copy Markdown

coveralls-official Bot commented Sep 6, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling 150e9bc on org-plugin
into 93a4759 on master.

@RobinTail RobinTail marked this pull request as ready for review September 11, 2025 17:46
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
eslint.config.js (2)

242-248: Add vitest setup file to the tests group for consistent lint rules.

Including zod-plugin/vitest.setup.ts under the tests/all config keeps rule relaxations consistent with express-zod-api’s setup file.

   files: [
     "express-zod-api/tests/*.ts",
     "express-zod-api/vitest.setup.ts",
     "migration/*.spec.ts",
+    "zod-plugin/vitest.setup.ts",
     "zod-plugin/tests/*.ts",
   ],

177-185: Optional: mirror ignore patterns for zod-plugin.

Consider adding coverage output and aligning the trailing slash for consistency.

  • Add: "zod-plugin/coverage/"
  • Change: "zod-plugin/dist" → "zod-plugin/dist/"
zod-plugin/vitest.setup.ts (1)

1-1: Setup now initializes runtime from src — good.

Ensure this file is included by the workspace’s vitest config (it appears to be). Also consider linting it via eslint tests group (see config suggestion).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee3cf1b and a90fa55.

📒 Files selected for processing (8)
  • eslint.config.js (1 hunks)
  • zod-plugin/src/runtime.ts (1 hunks)
  • zod-plugin/tests/brand.spec.ts (1 hunks)
  • zod-plugin/tests/index.spec.ts (1 hunks)
  • zod-plugin/tests/packer.spec.ts (1 hunks)
  • zod-plugin/tests/runtime.spec.ts (1 hunks)
  • zod-plugin/tsdown.config.ts (1 hunks)
  • zod-plugin/vitest.setup.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:11:20.768Z
Learning: In the express-zod-api repository, RobinTail follows a release workflow where package.json version is only updated on the master branch after merging all planned release changes. Changelog entries may show future version numbers while package.json remains at the previous version during feature development, and this is intentional workflow, not a version inconsistency that needs to be flagged.
📚 Learning: 2025-08-01T09:48:13.742Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-01T09:48:13.742Z
Learning: In express-zod-api, when migrating from Zod v3 to v4, the correct approach for internal type imports is to change from `import type { $ZodType } from "zod/v4/core"` to `import { z } from "zod"` and then use `z.core.$ZodType`. The zod/v4/core module is reexported as z.core by the main zod package, making this a valid and working approach.

Applied to files:

  • zod-plugin/tests/packer.spec.ts
  • zod-plugin/vitest.setup.ts
  • zod-plugin/tests/brand.spec.ts
  • zod-plugin/src/runtime.ts
  • zod-plugin/tests/index.spec.ts
📚 Learning: 2025-05-27T19:35:57.357Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/tests/buffer-schema.spec.ts:32-37
Timestamp: 2025-05-27T19:35:57.357Z
Learning: In the express-zod-api project, tests are run from the `express-zod-api` workspace directory, and the project uses an ESM-first environment without `__dirname`. Relative paths like `../logo.svg` in test files correctly resolve to the repository root due to this test execution context.

Applied to files:

  • zod-plugin/tests/packer.spec.ts
  • zod-plugin/tests/runtime.spec.ts
  • eslint.config.js
  • zod-plugin/tests/brand.spec.ts
  • zod-plugin/tests/index.spec.ts
📚 Learning: 2025-08-08T16:45:20.527Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-08T16:45:20.527Z
Learning: express-zod-api/zod-plugin: The ZodType.prototype.brand getter returns setBrand.bind(this) each time (no memoization). setBrand must always call pack() and include { brand: undefined } when unbranding so that pack → .check() runs and prior brand is overwritten; do not suggest removing the explicit undefined entry.

Applied to files:

  • zod-plugin/tests/packer.spec.ts
  • zod-plugin/tests/runtime.spec.ts
  • zod-plugin/tests/brand.spec.ts
  • zod-plugin/src/runtime.ts
📚 Learning: 2025-08-08T11:59:04.814Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2878
File: zod-plugin/runtime.ts:39-42
Timestamp: 2025-08-08T11:59:04.814Z
Learning: express-zod-api/zod-plugin/runtime.ts (TypeScript): Do not memoize the ZodType.prototype.brand getter. The current design returning setBrand.bind(this) on each access is intentional/preferred; avoid redefining "brand" as a data property per instance.

Applied to files:

  • zod-plugin/tests/runtime.spec.ts
  • zod-plugin/tests/brand.spec.ts
  • zod-plugin/src/runtime.ts
📚 Learning: 2025-08-08T16:45:20.527Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-08T16:45:20.527Z
Learning: express-zod-api/zod-plugin: The brand setter must be immutable and always invoke pack→.check() via the getter-bound setBrand. Including brandProperty with an explicit undefined enables unbranding and should not be optimized away.

Applied to files:

  • zod-plugin/tests/runtime.spec.ts
  • zod-plugin/tests/brand.spec.ts
  • zod-plugin/src/runtime.ts
📚 Learning: 2025-08-08T16:45:20.527Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-08T16:45:20.527Z
Learning: express-zod-api zod-plugin: The brand setter must stay immutable and always invoke pack→.check() (onattach). Including brandProperty with an explicit undefined enables “unbranding” (overwriting a previous brand) and should not be optimized away.

Applied to files:

  • zod-plugin/tests/runtime.spec.ts
  • zod-plugin/tests/brand.spec.ts
  • zod-plugin/src/runtime.ts
📚 Learning: 2025-08-08T16:45:20.527Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-08T16:45:20.527Z
Learning: In express-zod-api zod-plugin, the brand setter must be immutable and always call `.check()` (packer’s onattach). Therefore, writing an explicit undefined entry in the bag for brand is intentional and should not be suggested for removal.

Applied to files:

  • zod-plugin/tests/runtime.spec.ts
  • zod-plugin/tests/brand.spec.ts
📚 Learning: 2025-06-02T21:08:56.475Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:08:56.475Z
Learning: The `cjs-test` directory in the express-zod-api repository is a test workspace and should be excluded when checking for main project version consistency with changelog entries.

Applied to files:

  • eslint.config.js
  • zod-plugin/tests/index.spec.ts
📚 Learning: 2025-05-27T19:27:13.492Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/tests/form-schema.spec.ts:31-31
Timestamp: 2025-05-27T19:27:13.492Z
Learning: Zod version 3.25.0 and later expose the Zod v4 API through the special import paths "zod/v4" and "zod/v4/core", allowing v4 features like .loose() to be used even when the package.json dependency shows a 3.x version.

Applied to files:

  • zod-plugin/src/runtime.ts
🔇 Additional comments (6)
zod-plugin/tests/runtime.spec.ts (1)

3-3: Path update to ../src looks good.

Importing getBrand from the entrypoint under src aligns with the new layout.

zod-plugin/tests/index.spec.ts (1)

2-2: Entrypoint import redirected to ../src — OK.

Test assertions validate exported surface; no further changes needed.

zod-plugin/tsdown.config.ts (1)

5-5: DTS augmentation import verified — build OK, attw clean.

tsdown emitted dist/augmentation.d.ts and dist/index.{js,d.ts}; the dts banner import (import './augmentation.js') is intentional for DTS-only augmentation and did not trigger attw.

zod-plugin/tests/packer.spec.ts (1)

2-2: OK to source pack/unpack from ../src.

Tests still cover merge semantics and parse behavior; looks consistent.

zod-plugin/tests/brand.spec.ts (1)

2-3: Direct imports from ../src/ are appropriate.*

Spy on pack remains valid; unbranding and bag access cases are covered.

zod-plugin/src/runtime.ts (1)

2-2: JSON import path updated — resolveJsonModule enabled; verify bundler inlines JSON for ESM consumers.

  • zod-plugin/tsconfig.json: resolveJsonModule = true.
  • zod-plugin/package.json: "type": "module", build = "tsdown" — no bundler config found to confirm JSON is inlined; ensure tsdown/your build emits a dist that does not require raw JSON imports at runtime (or emits JSON import assertions).
  • zod-plugin/src/runtime.ts imports ../package.json and sets pluginFlag = Symbol.for(name) (zod-plugin/src/runtime.ts:20) — confirm this stable key is intended.

Copy link
Copy Markdown
Owner Author

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

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

🏁 ready

@RobinTail RobinTail merged commit 5d28e89 into master Sep 19, 2025
12 checks passed
@RobinTail RobinTail deleted the org-plugin branch September 19, 2025 09:36
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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)
eslint.config.js (1)

178-179: Make ignore globs recurse to ensure contents are excluded

Use **/dist/** and **/coverage/** so all files under those dirs are ignored reliably across tools.

-    ignores: ["**/dist/", "**/coverage/", "compat-test/sample.ts"],
+    ignores: ["**/dist/**", "**/coverage/**", "compat-test/sample.ts"],
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f80d610 and 7a127b8.

📒 Files selected for processing (1)
  • eslint.config.js (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:11:20.768Z
Learning: In the express-zod-api repository, RobinTail follows a release workflow where package.json version is only updated on the master branch after merging all planned release changes. Changelog entries may show future version numbers while package.json remains at the previous version during feature development, and this is intentional workflow, not a version inconsistency that needs to be flagged.
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-08-01T09:48:13.742Z
Learning: In express-zod-api, when migrating from Zod v3 to v4, the correct approach for internal type imports is to change from `import type { $ZodType } from "zod/v4/core"` to `import { z } from "zod"` and then use `z.core.$ZodType`. The zod/v4/core module is reexported as z.core by the main zod package, making this a valid and working approach.
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/tests/buffer-schema.spec.ts:32-37
Timestamp: 2025-05-27T19:35:57.357Z
Learning: In the express-zod-api project, tests are run from the `express-zod-api` workspace directory, and the project uses an ESM-first environment without `__dirname`. Relative paths like `../logo.svg` in test files correctly resolve to the repository root due to this test execution context.
📚 Learning: 2025-06-02T21:08:56.475Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:08:56.475Z
Learning: The `cjs-test` directory in the express-zod-api repository is a test workspace and should be excluded when checking for main project version consistency with changelog entries.

Applied to files:

  • eslint.config.js
📚 Learning: 2025-05-27T19:35:57.357Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/tests/buffer-schema.spec.ts:32-37
Timestamp: 2025-05-27T19:35:57.357Z
Learning: In the express-zod-api project, tests are run from the `express-zod-api` workspace directory, and the project uses an ESM-first environment without `__dirname`. Relative paths like `../logo.svg` in test files correctly resolve to the repository root due to this test execution context.

Applied to files:

  • eslint.config.js

Comment thread eslint.config.js
Comment on lines +237 to 238
files: ["**/tests/*.ts", "**/vitest.setup.ts", "**/*.spec.ts"],
rules: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

🧩 Analysis chain

Broaden test globs to cover nested tests and .test.ts files

Current pattern misses nested files under tests/** and any *.test.ts. Safer to include both.

-    files: ["**/tests/*.ts", "**/vitest.setup.ts", "**/*.spec.ts"],
+    files: ["**/tests/**/*.ts", "**/vitest.setup.ts", "**/*.spec.ts", "**/*.test.ts"],

Run to check if any .test.ts exist or nested tests would be missed:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "Possible misses with current config:"
echo "Count of **/*.test.ts:"
rg --files -g '**/*.test.ts' -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/coverage/**' | wc -l
echo "Example nested tests under **/tests/**:"
rg --files -g '**/tests/**/*.ts' -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/coverage/**' | head -n 20

Length of output: 61


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Checking for .test.ts files:"
rg --files -g '**/*.test.ts' -g '!**/{node_modules,dist,coverage}/**' || true

echo "Checking for nested tests under tests/**:"
rg --files -g '**/tests/**/*.ts' -g '!**/{node_modules,dist,coverage}/**' || true

Length of output: 2128


Broaden test globs in eslint.config.js to include nested tests and .test.ts

Current "/tests/*.ts" misses nested files under tests/ (rg found many); add "/tests//.ts" and "**/.test.ts".

File: eslint.config.js (lines 237-238)

-    files: ["**/tests/*.ts", "**/vitest.setup.ts", "**/*.spec.ts"],
+    files: ["**/tests/**/*.ts", "**/vitest.setup.ts", "**/*.spec.ts", "**/*.test.ts"],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
files: ["**/tests/*.ts", "**/vitest.setup.ts", "**/*.spec.ts"],
rules: {
files: ["**/tests/**/*.ts", "**/vitest.setup.ts", "**/*.spec.ts", "**/*.test.ts"],
rules: {
🤖 Prompt for AI Agents
In eslint.config.js around lines 237 to 238, the test file globs are too narrow
("**/tests/*.ts") and miss nested test files and files using the .test.ts
convention; update the files array to include "**/tests/**/*.ts" to capture
nested tests and add a pattern like "**/*.test.ts" so .test.ts files are linted
as well, keeping existing patterns intact and ensuring no duplicates.

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

Labels

CI/CD refactoring The better way to achieve the same result

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant