Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(custom-routing): Refactor internally to use new template #182

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

Fryuni
Copy link
Owner

@Fryuni Fryuni commented Dec 10, 2024

Summary by CodeRabbit

  • New Features

    • Introduced custom routing integration for Astro with options for standard and strict routing behaviors.
    • Added configuration for the tsup bundler to streamline the build process.
  • Bug Fixes

    • Removed outdated ESLint and .gitignore configurations, allowing default behaviors to take effect.
  • Documentation

    • Updated package.json to reflect new scripts and dependency management.
  • Chores

    • Adjusted .npmignore to include the src directory for npm packaging.

@Fryuni Fryuni requested a review from BryceRussell December 10, 2024 01:02
@Fryuni Fryuni self-assigned this Dec 10, 2024
Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
inox-tools ✅ Ready (Inspect) Visit Preview Dec 10, 2024 1:12am

Copy link

coderabbitai bot commented Dec 10, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve the removal of several files related to the custom routing package, including ESLint configuration, .gitignore, and the main routing functionality. A new index.ts file introduces custom routing capabilities for Astro, along with a new tsup.config.ts for bundling configuration. The package.json file has been updated to reflect new export formats, scripts, and dependencies. The modifications indicate a shift towards a more structured and modular approach in the package's configuration and functionality.

Changes

File Path Change Summary
packages/custom-routing/.eslintrc.cjs Removed ESLint configuration file; default linting rules will now apply.
packages/custom-routing/gitignore Removed .gitignore file; patterns for ignoring files will no longer be applied.
packages/custom-routing/index.ts Removed custom routing functionality; functions customRouting and strictCustomRouting were deleted.
packages/custom-routing/npmignore Modified .npmignore to include the src directory in the ignore list for npm packaging.
packages/custom-routing/package.json Updated exports, modified files, added dev script, replaced build and test scripts, added new dev dependencies.
packages/custom-routing/src/index.ts Added new custom routing functionality with customRouting and strictCustomRouting functions.
packages/custom-routing/tsup.config.ts Introduced tsup configuration for building the TypeScript project with specific settings.

Suggested labels

pkg/modular-station, pkg/astro-tests, pkg/inline-mod, workspace

🐇 "In the garden where code does play,
Custom routes hop and dance all day.
With scripts and configs all in tune,
The project blooms like a bright spring moon.
So let’s cheer for changes, both big and small,
For in this code, we’ll rise and not fall!" 🌷


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b10541f and a2f30d6.

📒 Files selected for processing (1)
  • packages/custom-routing/package.json (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

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

🧹 Outside diff range and nitpick comments (6)
packages/custom-routing/tsup.config.ts (2)

4-9: Add error handling for package.json parsing

The current implementation might throw uncaught exceptions if the package.json file is missing or malformed. Consider adding proper error handling and type safety.

-const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
+interface PackageJson {
+  dependencies?: Record<string, string>;
+  peerDependencies?: Record<string, string>;
+  devDependencies?: Record<string, string>;
+}
+
+let packageJson: PackageJson;
+try {
+  packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
+} catch (error) {
+  console.error('Failed to parse package.json:', error);
+  packageJson = {};
+}

11-28: Configuration looks good with some suggestions

The bundler configuration is well-structured for a library package. A few suggestions for consideration:

  1. The format could include 'cjs' if CommonJS support is needed
  2. Consider enabling shims: true for better compatibility if browser usage is intended
  3. The chunk naming strategy might generate long filenames
 export default defineConfig({
   entry: ['src/index.ts'],
-  format: ['esm'],
+  format: ['esm', 'cjs'],
   target: 'node18',
   bundle: true,
   dts: true,
   sourcemap: true,
   clean: true,
   splitting: true,
   minify: false,
   external: dependencies,
   noExternal: devDependencies,
   treeshake: 'smallest',
   tsconfig: 'tsconfig.json',
+  shims: true,
   esbuildOptions: (options) => {
-    options.chunkNames = 'chunks/[name]-[hash]';
+    options.chunkNames = '[name]-[hash]';
   },
 });
packages/custom-routing/src/index.ts (2)

5-6: Offer to assist with adding support for inline API routes

The TODO comment indicates a pending feature to support inline API routes once Astro core accepts virtual modules as injected routes. I can help implement this feature or open a GitHub issue to track it if you'd like.


33-34: Fix grammatical error in the error message

The error message contains a grammatical error. Please change 'Either use disable strict mode of custom routing or remove any file-based routes.' to 'Either disable strict mode of custom routing or remove any file-based routes.'

Apply this diff to correct the error message:

- 'Either use disable strict mode of custom routing or remove any file-based routes.'
+ 'Either disable strict mode of custom routing or remove any file-based routes.'
packages/custom-routing/package.json (2)

28-28: Use prepublishOnly instead of prepublish

It's recommended to use prepublishOnly instead of prepublish to avoid unexpected script executions during package installation.

Apply this diff:

-    "prepublish": "pnpm run build",
+    "prepublishOnly": "pnpm run build",

23-23: Consider excluding src from the package distribution

Including the src directory in the files array will include source files in the published package, potentially increasing package size. If this is unintended, consider removing src from files.

Apply this diff to exclude src from the package files:

   "files": [
     "README.md",
     "dist",
-    "src"
   ],
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 59025b5 and b10541f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • packages/custom-routing/.eslintrc.cjs (0 hunks)
  • packages/custom-routing/gitignore (0 hunks)
  • packages/custom-routing/index.ts (0 hunks)
  • packages/custom-routing/npmignore (1 hunks)
  • packages/custom-routing/package.json (1 hunks)
  • packages/custom-routing/src/index.ts (1 hunks)
  • packages/custom-routing/tsup.config.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/custom-routing/gitignore
  • packages/custom-routing/.eslintrc.cjs
  • packages/custom-routing/index.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/custom-routing/npmignore
🔇 Additional comments (5)
packages/custom-routing/tsup.config.ts (1)

14-14: Verify Node.js version compatibility

The configuration targets Node.js 18. Please ensure this aligns with the project's minimum supported Node.js version.

✅ Verification successful

Let me try a different approach to check the Node.js requirements.


Let me try one more approach to check the Node.js requirements by looking at the package manager configuration and dependencies.


Node.js 18 target is appropriate

The target of node18 in the tsup configuration is appropriate based on the project's dependencies and requirements:

  • The project uses modern dependencies like Vite 6, TypeScript 5.7, and Astro 5
  • @types/node is at version 22.x in the catalog
  • The build tooling (tsup 8.3.5) and test framework (Vitest 2.x) all support Node.js 18

These dependencies indicate the project is using current Node.js features, making Node.js 18 a suitable minimum target that balances modern features with broad compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Node.js version requirements across the project

# Check for Node.js version specifications in package.json files
echo "Checking Node.js version requirements in package.json files:"
fd package.json --exec jq -r '.engines.node // empty'

# Check for .nvmrc or .node-version files
echo -e "\nChecking for Node.js version files:"
fd -e nvmrc -e node-version --exec cat

Length of output: 428


Script:

#!/bin/bash
# Description: Check Node.js version requirements with a more robust approach

# Check root package.json
echo "Root package.json engines field:"
cat package.json | grep -A 5 '"engines"' || true

# Check custom-routing package.json
echo -e "\nCustom routing package.json engines field:"
cat packages/custom-routing/package.json | grep -A 5 '"engines"' || true

# Look for any Node version references in README
echo -e "\nNode.js version mentions in README:"
rg -i "node(\s+)?(\d+)" README.md || true

# Check for any other version requirements in workspace files
echo -e "\nChecking other workspace package.json files:"
find . -name "package.json" -type f -exec sh -c 'echo "=== $1 ==="; cat "$1" | grep -A 5 "engines"' sh {} \;

Length of output: 2509


Script:

#!/bin/bash
# Check for Node.js version requirements in package manager files
echo "Checking pnpm-workspace.yaml:"
cat pnpm-workspace.yaml || true

echo -e "\nChecking .npmrc:"
cat .npmrc || true

echo -e "\nChecking dependencies in custom-routing package.json:"
cat packages/custom-routing/package.json | jq '.dependencies, .devDependencies, .peerDependencies' || true

echo -e "\nChecking dependencies in root package.json:"
cat package.json | jq '.dependencies, .devDependencies' || true

Length of output: 2040

packages/custom-routing/src/index.ts (3)

14-42: customRoutingInner function is well-implemented

The function correctly constructs the AstroIntegration object with appropriate hooks, including conditional logic based on the strict option.


44-49: customRouting function correctly initializes the integration

The function correctly initializes customRoutingInner with strict: false.


51-56: strictCustomRouting function correctly initializes the integration in strict mode

The function correctly initializes customRoutingInner with strict: true.

packages/custom-routing/package.json (1)

15-18: exports field is correctly configured

The exports field is appropriately set to provide type definitions and the default export.

packages/custom-routing/package.json Outdated Show resolved Hide resolved
packages/custom-routing/package.json Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Luiz Ferraz <[email protected]>
@Fryuni Fryuni merged commit 9256372 into main Dec 10, 2024
20 of 21 checks passed
@Fryuni Fryuni deleted the feat/update-custom-routing-to-new-format branch December 10, 2024 01:13
@coderabbitai coderabbitai bot mentioned this pull request Dec 10, 2024
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.

1 participant