8000 fix: `.cts` should never be treated as esm by JounQin · Pull Request #226 · un-ts/synckit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: .cts should never be treated as esm #226

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 3 commits into from
Apr 4, 2025
Merged

fix: .cts should never be treated as esm #226

merged 3 commits into from
Apr 4, 2025

Conversation

JounQin
Copy link
Member
@JounQin JounQin commented Apr 4, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced file handling to ensure specific file types are processed correctly, leading to more reliable application behavior.
  • Documentation
    • Updated and standardized external links in project documentation for improved clarity and consistency.
  • Chores
    • Refined automation workflows with clearer step names and standardized branch references, streamlining build and testing processes.

@JounQin JounQin requested a review from Copilot April 4, 2025 06:24
Copy link
changeset-bot bot commented Apr 4, 2025

🦋 Changeset detected

Latest commit: 50dfdaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
synckit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor
coderabbitai bot commented Apr 4, 2025

Walkthrough

This pull request introduces several modifications. It patches the synckit package to ensure .cts files are not treated as ESM. In addition, several GitHub Actions workflow files have been updated by removing an unused environment variable, adding descriptive step names, updating branch references, and specifying a commit hash for an action. The README has been adjusted to standardize link label capitalizations, and the logic in the TypeScript runner helper now directly checks file extensions to set ESM flags more precisely.

Changes

File(s) Change Summary
.changeset/grumpy-socks-raise.md Patch update for synckit ensuring that .cts files are no longer treated as ECMAScript modules.
.github/workflows/ci.yml, .github/workflows/pkg-pr-new.yml, .github/workflows/size-limit.yml ci.yml: Removed EFF_NO_LINK_RULES from Lint step.
pkg-pr-new.yml: Added the "Publish" step name.
size-limit.yml: Changed branch references from master/v3.x to main, removed permissions, renamed steps ("Checkout Repo", "Check Size Limit"), and updated the action version to a commit hash.
README.md Updated link formatting: changed [1stg.me] to [1stG.me], [jounqin] to [JounQin], and [mit] to [MIT].
src/helpers.ts Modified the setupTsRunner function to determine ESM flags by directly checking the file extension variable. The conditions now specifically exclude .cts for TypeScript and .cjs for JavaScript from ESM usage.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant setupTsRunner
    Caller->>setupTsRunner: call setupTsRunner(file, ext)
    Note right of setupTsRunner: Evaluate file extension
    alt ext == ".mjs"
        setupTsRunner->>setupTsRunner: Set jsUseEsm = true
    else ext == ".cjs"
        setupTsRunner->>setupTsRunner: Set jsUseEsm = false
    end
    alt ext == ".mts" and ext != ".cts"
        setupTsRunner->>setupTsRunner: Set tsUseEsm = true
    else ext == ".cts"
        setupTsRunner->>setupTsRunner: Set tsUseEsm = false
    end
    setupTsRunner-->>Caller: Return configuration
Loading

Possibly related PRs

Poem

I'm a rabbit in a code-filled glen,
Hopping over bugs again and again.
.cts files now skip the ESM dance,
Clear workflows that make our code advance.
With hops and bytes, I cheer the change—
A joyful journey in our coding range! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/helpers.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


📜 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 fc65ea8 and 50dfdaa.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • .changeset/grumpy-socks-raise.md (1 hunks)
  • .github/workflows/ci.yml (0 hunks)
  • .github/workflows/pkg-pr-new.yml (1 hunks)
  • .github/workflows/size-limit.yml (3 hunks)
  • README.md (1 hunks)
  • src/helpers.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/ci.yml
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Lint and Test with Node.js 23 on macos-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 23 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18.18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 23 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18.18 on windows-latest
🔇 Additional comments (9)
README.md (1)

250-252: Standardize Link Label Capitalization
The updated link labels now read [1stG.me], [JounQin], and [MIT] to conform with a consistent naming convention across the documentation. This minor change improves readability and consistency without affecting functionality.

.github/workflows/pkg-pr-new.yml (1)

30-31: Step Name Addition Improves Clarity.
Introducing the explicit step name "Publish" for the command yarn dlx pkg-pr-new publish --compact enhances the readability and maintainability of the workflow.

.github/workflows/size-limit.yml (3)

6-6: Update Branch Filter to Main.
Changing the branch filter from legacy names (like master or v3.x) to main aligns the workflow configuration with current repository conventions.


16-17: Explicit Naming for Checkout Step.
The addition of the step name "Checkout Repo" clarifies the action's purpose, aiding maintainers and easing troubleshooting efforts.


28-29: Locking Action Version with Commit Hash Increases Stability.
Referencing the size-limit-action via a commit hash (94bc357df29c36c8f8d50ea497c3e225c3c95d1d) ensures that the workflow uses a well-defined snapshot of the action. Remember to update the hash as needed to incorporate upstream improvements.

src/helpers.ts (3)

116-117: ESM detection now directly checks file extensions

The code now checks the ext variable directly for determining ESM usage, which is clearer and more maintainable than checking if the workerPath ends with these extensions.

Consider adding a descriptive comment explaining the ESM detection logic as suggested in a previous review:

+// Determine ESM usage based on file extension
+// .mjs/.mts files are always ESM
+// .cts files are always CJS
+// other .ts files check package.json type
 let jsUseEsm = ext === '.mjs'
 let tsUseEsm = ext === '.mts'

120-125: Added explicit check to prevent .cts files from being treated as ESM

This change correctly ensures that .cts files are always treated as CommonJS modules, regardless of the package.json "type" field, which aligns with TypeScript's module resolution rules.


284-289: Added explicit check to prevent .cjs files from being treated as ESM

Similar to the TypeScript change, this ensures JavaScript files with the .cjs extension are always treated as CommonJS modules, maintaining consistency with Node.js module resolution standards.

.changeset/grumpy-socks-raise.md (1)

1-5: Appropriate patch version changeset for the fix

The changeset correctly identifies this as a patch-level change and provides a clear description of the fix. The message accurately reflects the code changes that ensure .cts files are never treated as ESM.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

Copy link
codesandbox-ci bot commented Apr 4, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (5)

src/helpers.ts:120

  • Ensure that 'ext' is properly initialized from 'workerPath' before this check, as an undefined or unexpected value could lead to incorrect module type resolution for TypeScript files.
if (!tsUseEsm && ext !== '.cts') {

README.md:251

  • [nitpick] The updated capitalization for 'JounQin' improves consistency; please verify that this change aligns with all related documentation references.
+[JounQin]: https://github.com/JounQin

.github/workflows/size-limit.yml:6

  • Confirm that restricting the branch filter to 'main' is intentional and that it doesn't inadvertently exclude other active branches.
+      - main

.github/workflows/pkg-pr-new.yml:30

  • [nitpick] The explicit naming for the publish step enhances clarity; ensure that similar workflow steps follow consistent naming conventions.
+      - name: Publish

.github/workflows/ci.yml:65

  • Removing the EFF_NO_LINK_RULES environment variable might affect linting behavior; please confirm that this change is fully intentional and tested.
             PARSER_NO_WATCH: true

Copy link
Contributor
github-actions bot commented Apr 4, 2025

📊 Package size report   -0.08%↓

File Before After
lib/helpers.js 17.3 kB -0.13%↓17.3 kB
lib/helpers.js.map 15.3 kB -0.19%↓15.3 kB
lib/index.cjs 24.3 kB -0.09%↓24.3 kB
Total (Includes all files) 96.1 kB -0.08%↓96.1 kB
Tarball size 23.1 kB -0.03%↓23.1 kB
Unchanged files
File Size
index.d.cts 60 B
lib/common.d.ts 329 B
lib/common.js 987 B
lib/common.js.map 1.2 kB
lib/constants.d.ts 1.8 kB
lib/constants.js 2.4 kB
lib/constants.js.map 2.3 kB
lib/helpers.d.ts 1.5 kB
lib/index.d.ts 424 B
lib/index.js 2.6 kB
lib/index.js.map 2.5 kB
lib/types.d.ts 1.4 kB
lib/types.js 44 B
lib/types.js.map 102 B
LICENSE 1.1 kB
package.json 4.3 kB
README.md 15.9 kB

🤖 This report was automatically generated by pkg-size-action

@JounQin
Copy link
Member Author
JounQin commented Apr 4, 2025

@codecov-ai-reviewer review

Copy link
codecov-ai bot commented Apr 4, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Copy link
Contributor
github-actions bot commented Apr 4, 2025

size-limit report 📦

Path Size
lib/index.js 912 B (0%)

Copy link
pkg-pr-new bot commented Apr 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/synckit@226

commit: 50dfdaa

Copy link
pkg-pr-new bot commented Apr 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/synckit@226

commit: 43c7a6c

Copy link
codecov bot commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.80%. Comparing base (fc65ea8) to head (50dfdaa).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #226   +/-   ##
=======================================
  Coverage   95.80%   95.80%           
=======================================
  Files           4        4           
  Lines         334      334           
  Branches      156      155    -1     
=======================================
  Hits          320      320           
  Misses         14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Report too large to display inline

View full report↗︎

Copy link
sonarqubecloud bot commented Apr 4, 2025

@JounQin JounQin merged commit 133408d into main Apr 4, 2025
45 checks passed
@JounQin JounQin deleted the fix/cts branch April 4, 2025 06:42
@JounQin JounQin mentioned this pull request Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0