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: full ESM config support using Ziti (build #1041) #1048

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sorccu
Copy link
Contributor

@sorccu sorccu commented Mar 25, 2025

This PR is a temporary solution to help build #1041 with secrets enabled.

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.

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 (with versions such as 10.9.1, 4.9.5, or latest) and added jiti with a version constraint of ^2.
packages/cli/package.json
packages/create-cli/package.json
Added jiti to devDependencies (e.g., "2.4.2") and declared it in peerDependencies with a constraint (>=2), including optional metadata.
packages/cli/.../{playwright-config-loader.ts, services/{checkly-config-loader.ts, project-parser.ts, util.ts}}
packages/create-cli/.../{actions/playwright.ts, utils/{directory.ts, fileloader.ts}}
packages/cli/src/services/__tests__/checkly-config-loader.spec.ts
Revised configuration file discovery and loading: expanded supported filename extensions, consolidated file loading functions (renamed loadJsFile to loadFile and added loadTsFileDefault), and updated error messages and handling logic.
packages/create-cli/src/actions/dependencies.ts Modified the dependency update logic to remove ts-node and typescript entries and add jiti in the generated package manifest.
.github/workflows/test.yml Introduced fail-fast: false to the strategy section, allowing all jobs in the matrix to continue running despite individual failures.

📜 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 4426d48 and 207cdd4.

📒 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 (1)
.github/workflows/test.yml (1)

24-26: Ensure Robust Matrix Execution Behavior

The addition of fail-fast: false under the strategy block is correctly implemented. This change ensures that every job in the matrix runs to completion even if one job fails—aligning with the temporary solution described for issue #1041. Please verify that this behavior is the intended outcome for all test runs in the PR context.


🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

Comment on lines +70 to +96
async function loadTsFileDefault (filepath: string): Promise<any> {
const jiti = await getJiti()
if (jiti) {
return jiti.import<any>(filepath, {
default: true,
})
}

// Backward-compatibility for users who installed ts-node.
const tsCompiler = await getTsNodeService()
if (tsCompiler) {
tsCompiler.enabled(true)
let { default: exported } = await require(filepath)
if (exported instanceof Function) {
exported = await exported()
let exported: any
try {
exported = (await require(filepath)).default
} catch (err: any) {
if (err.message && err.message.contains('Unable to compile TypeScript')) {
throw new Error(`You might try installing "jiti" instead of "ts-node" for improved TypeScript support\n${err.stack}`)
}
throw err
}
tsCompiler.enabled(false) // Re-disable the TS compiler
return exported
}

throw new Error('Please install "jiti" to use TypeScript files')
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential runtime error: String.prototype.contains is not standard JavaScript.

In the catch block at line 86, calling err.message.contains() may fail on environments that lack this method. Use the standard includes method instead:

- if (err.message && err.message.contains('Unable to compile TypeScript')) {
+ if (err.message && err.message.includes('Unable to compile TypeScript')) {
📝 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
async function loadTsFileDefault (filepath: string): Promise<any> {
const jiti = await getJiti()
if (jiti) {
return jiti.import<any>(filepath, {
default: true,
})
}
// Backward-compatibility for users who installed ts-node.
const tsCompiler = await getTsNodeService()
if (tsCompiler) {
tsCompiler.enabled(true)
let { default: exported } = await require(filepath)
if (exported instanceof Function) {
exported = await exported()
let exported: any
try {
exported = (await require(filepath)).default
} catch (err: any) {
if (err.message && err.message.contains('Unable to compile TypeScript')) {
throw new Error(`You might try installing "jiti" instead of "ts-node" for improved TypeScript support\n${err.stack}`)
}
throw err
}
tsCompiler.enabled(false) // Re-disable the TS compiler
return exported
}
throw new Error('Please install "jiti" to use TypeScript files')
}
async function loadTsFileDefault (filepath: string): Promise<any> {
const jiti = await getJiti()
if (jiti) {
return jiti.import<any>(filepath, {
default: true,
})
}
// Backward-compatibility for users who installed ts-node.
const tsCompiler = await getTsNodeService()
if (tsCompiler) {
tsCompiler.enabled(true)
let exported: any
try {
exported = (await require(filepath)).default
} catch (err: any) {
if (err.message && err.message.includes('Unable to compile TypeScript')) {
throw new Error(`You might try installing "jiti" instead of "ts-node" for improved TypeScript support\n${err.stack}`)
}
throw err
}
tsCompiler.enabled(false) // Re-disable the TS compiler
return exported
}
throw new Error('Please install "jiti" to use TypeScript files')
}
🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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

🎉 Experimental release successfully published on npm

npm install [email protected]

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