Skip to content

feat: full ESM config support using Jiti (build #1041) #1048

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

Merged
merged 7 commits into from
Apr 15, 2025

Conversation

sorccu
Copy link
Member

@sorccu sorccu commented Mar 25, 2025

This PR merges #1041.

Temporarily disables testing on Windows due to (presumably) ts-jest and jiti fighting over the module cache. A different test setup is needed to make this work.

Copy link

coderabbitai bot commented Mar 25, 2025

"""

Walkthrough

This pull request updates dependency management and refines configuration file loading across several projects. In multiple package manifests, TypeScript-related dependencies (ts-node and typescript) have been removed and replaced with the jiti runtime. In parallel, several configuration and file-loading routines have been refactored to support additional file extensions (such as .mts, .cts, and .cjs), consolidate duplicate logic (e.g., renaming loadJsFile to loadFile and introducing loadTsFileDefault), and improve error reporting and TypeScript support by preferring jiti with fallback to ts-node. The GitHub Actions workflow was also updated to disable fail-fast behavior on matrix jobs.

Changes

File(s) Change Summary
examples/advanced-project/package.json
examples/boilerplate-project/package.json
packages/create-cli/e2e/__tests__/fixtures/initiated-project/package.json
packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json
packages/create-cli/src/utils/__tests__/fixtures/checkly-project/package.json
Removed development dependencies ts-node and typescript (versions including 10.9.1, 4.9.5, or latest) and added jiti with version constraint ^2.
packages/cli/package.json
packages/create-cli/package.json
Added jiti to devDependencies (e.g., "^2.4.2") and declared it as a peer dependency with version >=2, marked optional in peerDependenciesMeta. Also added cross-env to devDependencies in packages/create-cli/package.json for environment variable handling in test scripts.
packages/cli/src/playwright/playwright-config-loader.ts
packages/cli/src/services/checkly-config-loader.ts
packages/cli/src/services/project-parser.ts
packages/cli/src/services/util.ts
packages/cli/src/services/__tests__/checkly-config-loader.spec.ts
packages/create-cli/src/actions/playwright.ts
packages/create-cli/src/utils/directory.ts
packages/create-cli/src/utils/fileloader.ts
Expanded supported configuration file extensions to include .mts, .cts, .cjs alongside existing .ts, .js, .mjs. Consolidated file loading logic by replacing separate loadJsFile and loadTsFile with a unified loadFile function and introduced loadTsFileDefault that prefers jiti with fallback to ts-node. Updated error messages and added existence and extension validation checks. Removed redundant internal functions and improved dynamic import handling.
packages/create-cli/src/actions/dependencies.ts Updated addDevDependecies function to remove ts-node and typescript entries and add jiti in the generated package manifest.
.github/workflows/test.yml Added fail-fast: false to the strategy section of the test job to allow all matrix jobs to run even if some fail, and reduced the test matrix to only ubuntu-latest.

Suggested reviewers

  • umutuzgur
    """

📜 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 59ffdd0 and 54ea062.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test - ubuntu-latest
🔇 Additional comments (2)
.github/workflows/test.yml (2)

25-25: Good use of fail-fast: false for matrix jobs.

This ensures all test jobs run to completion, providing better visibility into failures across the matrix.


27-27: Matrix simplification to ubuntu-latest is clear and consistent.

Focusing on a single OS streamlines CI and matches the project's updated dependency/runtime strategy.


🪧 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.
  • @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.

@sorccu sorccu changed the title feat: full ESM config support using Ziti (temporary build) feat: full ESM config support using Ziti (build #1041) Mar 25, 2025
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: 1

🧹 Nitpick comments (4)
examples/boilerplate-project/package.json (1)

2-2: Typo in package name

There's a typo in the package name: "boilerlate-project" should be "boilerplate-project".

-  "name": "boilerlate-project",
+  "name": "boilerplate-project",
packages/cli/src/playwright/playwright-config-loader.ts (1)

15-16: Consider logging if no config file was found.

While returning undefined clearly indicates that a config file was not found, providing a small log or debug message here could be beneficial to inform users why the config is missing. This is just a minor improvement for debugging.

Also applies to: 19-20, 22-22

packages/cli/src/services/checkly-config-loader.ts (1)

112-114: Early file existence check is convenient.

Skipping non-existent files before attempting to load them prevents unnecessary errors. Consider logging or warning if multiple config files could be found concurrently, to guide users on potential configuration conflicts.

packages/create-cli/src/utils/fileloader.ts (1)

36-37: Use optional chaining for safer property access.

As hinted by static analysis, consider using err.message?.includes('Unable to compile TypeScript') to avoid potential runtime errors when err.message is undefined.

-      if (err.message && err.message.contains('Unable to compile TypeScript')) {
+      if (err.message?.includes('Unable to compile TypeScript')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1418114 and 4426d48.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (16)
  • examples/advanced-project/package.json (1 hunks)
  • examples/boilerplate-project/package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/playwright/playwright-config-loader.ts (1 hunks)
  • packages/cli/src/services/__tests__/checkly-config-loader.spec.ts (1 hunks)
  • packages/cli/src/services/checkly-config-loader.ts (3 hunks)
  • packages/cli/src/services/project-parser.ts (2 hunks)
  • packages/cli/src/services/util.ts (3 hunks)
  • packages/create-cli/e2e/__tests__/fixtures/initiated-project/package.json (1 hunks)
  • packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json (1 hunks)
  • packages/create-cli/package.json (1 hunks)
  • packages/create-cli/src/actions/dependencies.ts (1 hunks)
  • packages/create-cli/src/actions/playwright.ts (1 hunks)
  • packages/create-cli/src/utils/__tests__/fixtures/checkly-project/package.json (1 hunks)
  • packages/create-cli/src/utils/directory.ts (1 hunks)
  • packages/create-cli/src/utils/fileloader.ts (3 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/create-cli/src/utils/fileloader.ts (1)
packages/cli/src/services/util.ts (1)
  • loadFile (53-68)
packages/cli/src/services/util.ts (1)
packages/create-cli/src/utils/fileloader.ts (1)
  • loadFile (3-18)
🪛 Biome (1.9.4)
packages/create-cli/src/utils/fileloader.ts

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/cli/src/services/util.ts

[error] 86-86: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test - windows-latest
  • GitHub Check: test - ubuntu-latest
🔇 Additional comments (30)
examples/advanced-project/package.json (1)

14-14: Good dependency update to support ESM modules

Replacing TypeScript tools (ts-node and typescript) with jiti is a good approach for enabling better ESM module support. Jiti acts as a runtime that can handle both TypeScript and ESM modules, which aligns well with the PR's goal of providing full ESM config support.

examples/boilerplate-project/package.json (1)

14-14: Good dependency update to support ESM modules

The addition of jiti as a replacement for ts-node and typescript follows the same pattern as other package.json files in this PR. This change will enable better ESM module support across example projects.

packages/cli/src/services/__tests__/checkly-config-loader.spec.ts (1)

26-26: Good expansion of supported config file extensions

The error message now includes additional file extensions (.mts, .cts, .cjs) that are now supported. This properly reflects the expanded config file format capabilities and is an important part of providing full ESM support. The .mts extension in particular is crucial for TypeScript ESM modules.

packages/create-cli/e2e/__tests__/fixtures/initiated-project/package.json (1)

13-13: Good dependency update for test fixtures

Replacing ts-node and typescript with jiti in test fixtures ensures that the test environment mirrors the expected real-world project structure. This change maintains consistency with the other package.json updates in this PR and properly tests the new dependency arrangement for ESM support.

packages/create-cli/src/actions/dependencies.ts (1)

15-18: LGTM: Dependency update aligns with project-wide changes

The change from TypeScript-related tools (ts-node, typescript) to using jiti is consistent with the broader project strategy. The version constraint ^2 follows semantic versioning standards.

packages/create-cli/src/utils/__tests__/fixtures/checkly-project/package.json (1)

12-15: LGTM: Test fixture updated to match new dependency strategy

The fixture now correctly reflects the project's move from TypeScript-specific dependencies to using jiti as a runtime loader, maintaining consistency with the changes in the main code.

packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json (1)

11-14: LGTM: Playwright test fixture updated correctly

This change properly aligns the Playwright project test fixture with the project's new dependency approach, consistently using jiti ^2 instead of TypeScript-specific dependencies.

packages/create-cli/src/actions/playwright.ts (1)

47-55: LGTM: Enhanced configuration file support

Good enhancement to support additional module system file extensions. The function now properly handles .mts, .cts, and .cjs configuration files, increasing flexibility for users with different module preferences.

packages/create-cli/src/utils/directory.ts (1)

27-35: Improved error handling and file extension support

This change enhances the loadPlaywrightConfig function with proper existence checks and expanded file extension support. The regex /\.[mc]?(js|ts)$/ now handles ESM and CommonJS variants, supporting .js, .ts, .mjs, .cjs, .mts, and .cts files.

packages/create-cli/package.json (2)

83-83: LGTM - Adding jiti as a dev dependency

Adding jiti aligns with the PR's goals to support ESM configs.


89-96: Good approach making jiti an optional peer dependency

Making jiti an optional peer dependency with >=2 version constraint provides flexibility while ensuring compatibility when it's present.

packages/cli/package.json (2)

116-116: LGTM - Adding jiti as a dev dependency

Adding jiti aligns with the PR's goals to support ESM configs.


124-131: Good approach making jiti an optional peer dependency

Making jiti an optional peer dependency with >=2 version constraint provides flexibility while ensuring compatibility when it's present.

packages/cli/src/services/project-parser.ts (2)

3-3: LGTM - Updated import to use consolidated file loader

Importing the unified loadFile function instead of separate loaders simplifies the code.


88-93: Improved code with unified file loading approach

The updated implementation:

  1. Simplifies logic by using a single regex for all supported file types
  2. Uses a unified loadFile function instead of separate functions for JS and TS
  3. Adds support for additional file extensions (.mjs, .cjs, .mts, .cts)

This change improves maintainability while expanding format support.

packages/cli/src/playwright/playwright-config-loader.ts (2)

2-3: Good import consolidation.

Consolidating filesystem and utility imports at the top helps keep the code more organized.


6-13: Support for multiple config file extensions is a robust addition.

Including .mts, .cts, .mjs, and .cjs offers extra flexibility for Playwright configuration.

packages/cli/src/services/checkly-config-loader.ts (3)

3-3: Centralized file loading is a good refactor.

Using loadFile from ./util ensures consistent file-loading logic across the codebase and removes duplicated code.


80-88: Expanding configuration file extensions increases compatibility.

Adding .mts, .cts, and .cjs provides more ways for users to structure their Checkly config.


107-107: Defaults maintain clarity and ease-of-use.

Introducing new default filenames in the loadChecklyConfig parameters is straightforward and meshes well with the broader multi-extension support.

packages/create-cli/src/utils/fileloader.ts (6)

3-11: Refined file loading logic enhances modularity.

Using a single loadFile function that dynamically branches for TS or JS simplifies future maintenance and reduces duplicated code.


20-26: loadTsFileDefault is a clean abstraction.

Centralizing the TypeScript-specific loading path via jiti or fallback options is a great approach to handle different TS setups.


28-40: Fallback to ts-node ensures backward compatibility.

This logic rightly handles scenarios where jiti is not installed, using ts-node as a graceful fallback.

🧰 Tools
🪛 Biome (1.9.4)

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


48-53: Type alias for Jiti usage is well structured.

Storing the Jiti type here is clear for future reference if more Jiti-based functionality is added.


55-67: getJiti on demand is performance-friendly.

Lazily importing and caching Jiti avoids overhead for users who are not using TypeScript. This design is sensible.


71-90: getTsNodeService gracefully accommodates TS projects without jiti.

The fallback logic is robust, and the code re-enables then disables the TS compiler as needed, minimizing side effects.

packages/cli/src/services/util.ts (4)

53-61: Streamlined file loader logic.

This updated loadFile function neatly distinguishes between TypeScript and other file extensions, and the fallback to call the default export if it's a function is well-handled. No issues detected here.


98-103: Advanced TypeScript pattern for Jiti type.

Using a dynamically inferred return type here is acceptable given the complexity of the jiti import. This helps avoid direct type imports that cause issues in certain test environments.


105-118: Robust lazy loading of the jiti module.

This approach avoids introducing an explicit dependency for all users, and the error handling for missing jiti is well-managed.


120-141: Selective ts-node dynamic import for backward compatibility.

This gated logic effectively avoids forcing ts-node on all users. The error handling for the module not found scenario is correct and returns undefined gracefully.

@sorccu sorccu added the build Issue regarding building and packaging label Mar 25, 2025

This comment has been minimized.

@sorccu sorccu changed the title feat: full ESM config support using Ziti (build #1041) feat: full ESM config support using Jiti (build #1041) Apr 3, 2025
@sorccu sorccu force-pushed the henrist/support-esm branch from 207cdd4 to 314a3b8 Compare April 14, 2025 15:31
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: 1

♻️ Duplicate comments (1)
packages/cli/src/services/util.ts (1)

71-97: Use includes instead of non-standard contains.

This is a repeat of a past comment. String.prototype.contains is not supported in many environments. Switch to message.includes(...) for reliability.

-      if (err.message && err.message.contains('Unable to compile TypeScript')) {
+      if (err.message && err.message.includes('Unable to compile TypeScript')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 87-87: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🧹 Nitpick comments (8)
packages/create-cli/src/utils/fileloader.ts (4)

3-11: Improve cross-platform consistency for imports.

Currently, the code directly calls import(filepath). In other files, pathToPosix(filepath) is used to normalize paths across platforms. Consider aligning this approach here to avoid potential path separator issues on Windows.

-      exported = (await import(filepath)).default
+      exported = (await import(pathToPosix(filepath))).default

20-26: Add tests to ensure fallback logic is functioning correctly.

The introduction of loadTsFileDefault is a good step toward handling TypeScript files. However, consider adding unit tests that confirm Jiti-based loading works as intended and properly falls back to ts-node if Jiti is not found.


55-68: Ensure caching logic is robust.

getJiti() caches the imported Jiti instance in a module-level variable. Ensure that the rest of the codebase never inadvertently re-initializes or overrides this variable. Also confirm that partial module reloads won't cause any unexpected re-import logic.


71-91: Check fallback synergy with custom TS config.

When using ts-node fallback, any custom TypeScript configurations (tsconfig.json) might not be fully respected unless explicitly passed in. Consider clarifying or documenting how overrides are handled, if at all.

packages/cli/src/playwright/playwright-config-loader.ts (1)

2-22: Consider returning null or throwing if no config is found.

Returning undefined at line 22 can be slightly ambiguous. Consider returning null or throwing an explicit error to better indicate a missing config. This can help prevent silent failures when no config file exists.

packages/cli/src/services/util.ts (3)

54-69: Ensure consistent import normalization.

This loading logic mirrors other files. If there's any Windows path normalization concern, consider using pathToPosix(filepath) consistently to reduce unexpected path separator issues.


106-119: Validate fallback logic for Jiti import errors.

If the user has installed an incompatible Jiti version, the code rethrows the error, which is good. Consider adding an additional message or logs to highlight potential version mismatches.


122-141: Check ts-node usage for advanced TS features.

tsNodeService is re-enabled and disabled around the load, which is a neat approach. However, be mindful that more advanced TS features (like project references) may require an extended configuration.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 207cdd4 and 314a3b8.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (17)
  • .github/workflows/test.yml (1 hunks)
  • examples/advanced-project/package.json (1 hunks)
  • examples/boilerplate-project/package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/playwright/playwright-config-loader.ts (1 hunks)
  • packages/cli/src/services/__tests__/checkly-config-loader.spec.ts (1 hunks)
  • packages/cli/src/services/checkly-config-loader.ts (3 hunks)
  • packages/cli/src/services/project-parser.ts (2 hunks)
  • packages/cli/src/services/util.ts (3 hunks)
  • packages/create-cli/e2e/__tests__/fixtures/initiated-project/package.json (1 hunks)
  • packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json (1 hunks)
  • packages/create-cli/package.json (1 hunks)
  • packages/create-cli/src/actions/dependencies.ts (1 hunks)
  • packages/create-cli/src/actions/playwright.ts (1 hunks)
  • packages/create-cli/src/utils/__tests__/fixtures/checkly-project/package.json (1 hunks)
  • packages/create-cli/src/utils/directory.ts (1 hunks)
  • packages/create-cli/src/utils/fileloader.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (13)
  • .github/workflows/test.yml
  • packages/create-cli/src/actions/dependencies.ts
  • packages/cli/src/services/tests/checkly-config-loader.spec.ts
  • packages/create-cli/src/utils/directory.ts
  • packages/create-cli/e2e/tests/fixtures/playwright-project/package.json
  • examples/advanced-project/package.json
  • packages/create-cli/e2e/tests/fixtures/initiated-project/package.json
  • packages/create-cli/package.json
  • examples/boilerplate-project/package.json
  • packages/create-cli/src/utils/tests/fixtures/checkly-project/package.json
  • packages/cli/package.json
  • packages/create-cli/src/actions/playwright.ts
  • packages/cli/src/services/project-parser.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/cli/src/playwright/playwright-config-loader.ts (3)
packages/create-cli/src/utils/directory.ts (1)
  • loadPlaywrightConfig (26-36)
packages/cli/src/services/util.ts (1)
  • loadFile (54-69)
packages/create-cli/src/utils/fileloader.ts (1)
  • loadFile (3-18)
packages/cli/src/services/util.ts (1)
packages/create-cli/src/utils/fileloader.ts (1)
  • loadFile (3-18)
packages/create-cli/src/utils/fileloader.ts (1)
packages/cli/src/services/util.ts (1)
  • loadFile (54-69)
🪛 Biome (1.9.4)
packages/cli/src/services/util.ts

[error] 87-87: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/create-cli/src/utils/fileloader.ts

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test - windows-latest
  • GitHub Check: test - ubuntu-latest
🔇 Additional comments (4)
packages/create-cli/src/utils/fileloader.ts (1)

48-53: No immediate concerns.

Defining the Jiti type inline is acceptable. Just ensure that if further expansions are needed, it might be clearer to place it in a dedicated .d.ts file.

packages/cli/src/services/util.ts (1)

99-105: Jiti type definition looks fine.

No issues noted with the approach. It's a succinct way to handle dynamic import types.

packages/cli/src/services/checkly-config-loader.ts (2)

3-3: Expanded list of supported config extensions is helpful.

Adding .mts, .cts, and .cjs broadens compatibility for ESM configs. The approach here is consistent with the rest of the PR, so no major concerns.

Also applies to: 81-88


107-107: Validate partial configuration loading.

When a config file is found and loaded, ensure that partial or incomplete user-defined fields throw the desired errors. The rest of the logic correctly handles missing required fields. Looks good overall.

Would you like a script to search for references to loadChecklyConfig to ensure partial config usage is tested properly?

Also applies to: 112-114

@sorccu sorccu force-pushed the henrist/support-esm branch from 314a3b8 to e88b6c6 Compare April 14, 2025 20:42
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

🧹 Nitpick comments (2)
packages/create-cli/src/utils/fileloader.ts (1)

37-37: Prefer optional chaining to check for the error message.

Using optional chaining can simplify the null check logic and improve readability:

- if (err.message && err.message.includes('Unable to compile TypeScript')) {
+ if (err.message?.includes('Unable to compile TypeScript')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/cli/src/services/util.ts (1)

88-88: Use optional chaining for safer error message checks.

Replacing the && condition with the optional chain can streamline this check:

- if (err.message && err.message.includes('Unable to compile TypeScript')) {
+ if (err.message?.includes('Unable to compile TypeScript')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 88-88: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 314a3b8 and 9cb7744.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (17)
  • .github/workflows/test.yml (1 hunks)
  • examples/advanced-project/package.json (1 hunks)
  • examples/boilerplate-project/package.json (1 hunks)
  • packages/cli/package.json (2 hunks)
  • packages/cli/src/playwright/playwright-config-loader.ts (1 hunks)
  • packages/cli/src/services/__tests__/checkly-config-loader.spec.ts (1 hunks)
  • packages/cli/src/services/checkly-config-loader.ts (3 hunks)
  • packages/cli/src/services/project-parser.ts (2 hunks)
  • packages/cli/src/services/util.ts (3 hunks)
  • packages/create-cli/e2e/__tests__/fixtures/initiated-project/package.json (1 hunks)
  • packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json (1 hunks)
  • packages/create-cli/package.json (1 hunks)
  • packages/create-cli/src/actions/dependencies.ts (1 hunks)
  • packages/create-cli/src/actions/playwright.ts (1 hunks)
  • packages/create-cli/src/utils/__tests__/fixtures/checkly-project/package.json (1 hunks)
  • packages/create-cli/src/utils/directory.ts (1 hunks)
  • packages/create-cli/src/utils/fileloader.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (15)
  • packages/create-cli/src/actions/dependencies.ts
  • examples/advanced-project/package.json
  • .github/workflows/test.yml
  • packages/create-cli/src/actions/playwright.ts
  • packages/cli/src/playwright/playwright-config-loader.ts
  • packages/cli/src/services/tests/checkly-config-loader.spec.ts
  • packages/create-cli/e2e/tests/fixtures/playwright-project/package.json
  • packages/create-cli/package.json
  • packages/cli/src/services/project-parser.ts
  • packages/create-cli/e2e/tests/fixtures/initiated-project/package.json
  • packages/cli/package.json
  • packages/create-cli/src/utils/directory.ts
  • packages/cli/src/services/checkly-config-loader.ts
  • packages/create-cli/src/utils/tests/fixtures/checkly-project/package.json
  • examples/boilerplate-project/package.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/cli/src/services/util.ts (1)
packages/create-cli/src/utils/fileloader.ts (1)
  • loadFile (4-19)
🪛 Biome (1.9.4)
packages/create-cli/src/utils/fileloader.ts

[error] 37-37: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/cli/src/services/util.ts

[error] 88-88: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (2)
packages/create-cli/src/utils/fileloader.ts (1)

4-19: Unified file loading approach looks good.

This refactor consolidates JavaScript and TypeScript loading into a single function, improving maintainability and reducing code duplication. Nicely done!

packages/cli/src/services/util.ts (1)

55-66: Consistent loader pattern is well-structured.

Loading .ts or .mts files via loadTsFileDefault and .js files via native import is a neat solution for unified file handling.

@sorccu sorccu added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels Apr 15, 2025
Copy link

🎉 Experimental release successfully published on npm

npm install [email protected]

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: 0

🧹 Nitpick comments (5)
packages/create-cli/src/utils/fileloader.ts (3)

10-10: Consider normalizing file paths for Windows compatibility

Unlike the similar function in packages/cli/src/services/util.ts which uses pathToPosix(filepath), this implementation might have issues on Windows systems when using direct file paths with backslashes.

- exported = (await import(filepath)).default
+ exported = (await import(filepath.replace(/\\/g, '/'))).default

37-37: Use optional chaining for cleaner code

The current error message check can be simplified using optional chaining.

- if (err.message && err.message.includes('Unable to compile TypeScript')) {
+ if (err.message?.includes('Unable to compile TypeScript')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


4-19: Consider DRYing up code across packages

This loadFile function is similar to the one in packages/cli/src/services/util.ts. Consider extracting these utilities to a shared package to avoid duplication and ensure consistent behavior.

Also applies to: 55-70

packages/cli/src/services/util.ts (2)

55-63: Consider returning a more precise type than any.

Relying on any can make it harder to detect type errors at compile-time. If feasible, consider using a more specific type or a generic parameter for improved type safety.


72-99: Use optional chaining for concise error checks.

At line 89, replace the err.message && err.message.includes(...) check with optional chaining for brevity:

- if (err.message && err.message.includes('Unable to compile TypeScript')) {
+ if (err.message?.includes('Unable to compile TypeScript')) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 88-88: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cb7744 and 59ffdd0.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • packages/cli/package.json (3 hunks)
  • packages/cli/src/services/util.ts (3 hunks)
  • packages/create-cli/package.json (2 hunks)
  • packages/create-cli/src/utils/fileloader.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/cli/package.json
  • packages/create-cli/package.json
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/cli/src/services/util.ts (1)
packages/create-cli/src/utils/fileloader.ts (1)
  • loadFile (4-19)
packages/create-cli/src/utils/fileloader.ts (1)
packages/cli/src/services/util.ts (1)
  • loadFile (55-70)
🪛 Biome (1.9.4)
packages/cli/src/services/util.ts

[error] 88-88: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/create-cli/src/utils/fileloader.ts

[error] 37-37: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
packages/create-cli/src/utils/fileloader.ts (4)

4-19: LGTM: File loading functionality has been generalized

The renamed function now properly handles both JavaScript and TypeScript files, with a clear separation of concerns. The regex pattern /\.[mc]?ts$/ appropriately matches all TypeScript file extensions (.ts, .mts, .cts).


21-48: LGTM: Robust TypeScript file loading with progressive enhancement

Well-structured approach that prioritizes jiti while maintaining backward compatibility with ts-node. The error messages are informative and guide users toward the recommended approach.

🧰 Tools
🪛 Biome (1.9.4)

[error] 37-37: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


41-43: LGTM: Proper compiler state management

Excellent use of the finally block to ensure the TypeScript compiler is disabled even when errors occur. This addresses the previous review comment and prevents potential side effects.


50-70: LGTM: Clean implementation of dynamic Jiti loading

The dynamic import approach with caching is a good strategy to avoid requiring dependencies that users might not have installed. The type definition is also well handled.

packages/cli/src/services/util.ts (2)

101-119: Dynamic import for jiti looks good.

The lazy, cached approach for loading jiti is well-structured. No further issues noted here.


125-143: Fallback logic for ts-node is well-handled.

Your usage of a cached service and a return to disabled state after errors avoids resources remaining enabled. Looks good.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 15, 2025
@sorccu sorccu merged commit a859644 into main Apr 15, 2025
3 checks passed
@sorccu sorccu deleted the henrist/support-esm branch April 15, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issue regarding building and packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants