Skip to content

chore: remove unnecessary tslib by targeting ES2021#12

Merged
JounQin merged 2 commits intomainfrom
chore/cleanup
Apr 20, 2025
Merged

chore: remove unnecessary tslib by targeting ES2021#12
JounQin merged 2 commits intomainfrom
chore/cleanup

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Apr 20, 2025

Summary by CodeRabbit

  • Chores

    • Removed the dependency on tslib and updated build configuration to target ES2021.
    • Updated TypeScript and ESLint configurations for improved compatibility and code style.
    • Eliminated tslib from the package manifest and related build files.
  • Style

    • Modernized code by updating import styles for Node.js modules and simplifying error handling and null checks.
    • Improved code clarity and conciseness throughout the project.
  • Documentation

    • Added a changeset file documenting the patch-level update.

@JounQin JounQin requested a review from Copilot April 20, 2025 13:22
@changeset-bot
Copy link

changeset-bot bot commented Apr 20, 2025

🦋 Changeset detected

Latest commit: a66982b

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

This PR includes changesets to release 1 package
Name Type
napi-postinstall 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

@coderabbitai
Copy link

coderabbitai bot commented Apr 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update removes the project's dependency on tslib by switching TypeScript's compilation target to ES2021 and updating all module imports to use direct or namespace imports for Node.js core modules. The package manifest, TypeScript configuration, and related code are revised to eliminate tslib usage. Async functions are rewritten to use native async/await syntax, and optional chaining and nullish coalescing are used for cleaner code. No exported APIs or public entity signatures are altered, except for the internal conversion of async function implementations.

Changes

File(s) Change Summary
.changeset/fast-crabs-pull.md Added a changeset documenting the removal of tslib dependency and the switch to ES2021 target.
package.json Removed the tslib dependency from the dependencies section.
tsconfig.json Set "target": "ES2021", and explicitly set "allowSyntheticDefaultImports" and "esModuleInterop" to false.
eslint.config.mjs Disabled the unicorn/import-style rule.
lib/constants.js, lib/helpers.js, lib/index.js, lib/target.js Replaced tslib-wrapped imports with direct require calls; updated code to use optional chaining and nullish coalescing; converted generator-based async functions to native async/await syntax in relevant files.
src/constants.ts, src/helpers.ts, src/index.ts Changed default and named imports of Node.js core modules to namespace imports (e.g., import * as fs from 'node:fs'). Updated type annotations accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant checkAndPreparePackage
    participant fs
    participant path
    participant npm
    participant https

    User->>checkAndPreparePackage: Call with package info
    checkAndPreparePackage->>fs: Check for native binary
    alt Binary exists
        checkAndPreparePackage-->>User: Success
    else Binary missing
        checkAndPreparePackage->>npm: Try install via npm
        alt npm install succeeds
            checkAndPreparePackage-->>User: Success
        else npm install fails
            checkAndPreparePackage->>https: Download binary directly
            alt Download succeeds
                checkAndPreparePackage-->>User: Success
            else Download fails
                checkAndPreparePackage-->>User: Error
            end
        end
    end
Loading

Possibly related issues

Possibly related PRs

Poem

A hop and a skip, no tslib in sight,
ES2021 now powers our flight.
Imports are cleaner, async is neat,
Rabbits rejoice—this change is a treat!
With code now more simple, and bugs kept at bay,
We leap into progress, the bunny way.
🐇✨

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.

eslint.config.mjs

Oops! Something went wrong! :(

ESLint: 9.25.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.mjs
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)

lib/helpers.js

Oops! Something went wrong! :(

ESLint: 9.25.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.mjs
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)

lib/constants.js

Oops! Something went wrong! :(

ESLint: 9.25.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.mjs
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)

  • 5 others

📜 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 63eaac2 and a66982b.

⛔ Files ignored due to path filters (5)
  • lib/constants.js.map is excluded by !**/*.map
  • lib/helpers.js.map is excluded by !**/*.map
  • lib/index.js.map is excluded by !**/*.map
  • lib/target.js.map is excluded by !**/*.map
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (11)
  • .changeset/fast-crabs-pull.md (1 hunks)
  • eslint.config.mjs (1 hunks)
  • lib/constants.js (1 hunks)
  • lib/helpers.js (5 hunks)
  • lib/index.js (3 hunks)
  • lib/target.js (1 hunks)
  • package.json (0 hunks)
  • src/constants.ts (1 hunks)
  • src/helpers.ts (2 hunks)
  • src/index.ts (1 hunks)
  • tsconfig.json (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

Copy link

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.

Pull Request Overview

This PR removes the unnecessary dependency on tslib by targeting ES2021 and updates the import style accordingly. Key changes include:

  • Converting default imports for Node built-ins in TypeScript files to namespace imports.
  • Removing tslib usage in JavaScript files and updating helper functions to use modern syntax.
  • Disabling an ESLint unicorn rule to match the team’s style preferences.

Reviewed Changes

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

Show a summary per file
File Description
src/index.ts Updated import statements for Node modules.
src/helpers.ts Changed import syntax and updated Typescript types.
src/constants.ts Adjusted import style for Node modules.
lib/target.js Replaced older nullish patterns with the nullish coalescing operator.
lib/index.js Removed tslib usage and refactored async functions and error messages.
lib/helpers.js Updated Node module imports and modernized error handling syntax.
lib/constants.js Revised import flow using the new require syntax.
eslint.config.mjs Disabled a unicorn rule to ensure consistent import styles.
Files not reviewed (1)
  • package.json: Language not supported

@JounQin JounQin merged commit 5b8ff18 into main Apr 20, 2025
26 checks passed
@JounQin JounQin deleted the chore/cleanup branch April 20, 2025 13:22
@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 20, 2025

Open in StackBlitz

npm i https://pkg.pr.new/napi-postinstall@12

commit: a66982b

@github-actions
Copy link
Contributor

📊 Package size report   No changes

File Before After
Total (Includes all files) 42.7 kB 42.7 kB
Tarball size 12.4 kB 12.4 kB
Unchanged files
File Size
lib/cli.d.ts 31 B
lib/cli.js 289 B
lib/cli.js.map 282 B
lib/constants.d.ts 168 B
lib/constants.js 486 B
lib/constants.js.map 306 B
lib/helpers.d.ts 685 B
lib/helpers.js 7.1 kB
lib/helpers.js.map 6.2 kB
lib/index.d.ts 249 B
lib/index.js 6.3 kB
lib/index.js.map 5.8 kB
lib/target.d.ts 348 B
lib/target.js 1.4 kB
lib/target.js.map 1.4 kB
lib/types.d.ts 541 B
lib/types.js 110 B
lib/types.js.map 102 B
LICENSE 1.1 kB
package.json 3.5 kB
README.md 6.3 kB

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

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
lib/index.js 2.04 KB (0%)

@codecov
Copy link

codecov bot commented Apr 20, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 39.56%. Comparing base (63eaac2) to head (a66982b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/helpers.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #12   +/-   ##
=======================================
  Coverage   39.56%   39.56%           
=======================================
  Files           6        6           
  Lines         460      460           
  Branches       53       53           
=======================================
  Hits          182      182           
  Misses        278      278           

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

@github-actions
Copy link
Contributor

Deploy preview for napi-postinstall ready!

✅ Preview
https://napi-postinstall-6zzwpylja-1stg.vercel.app

Built with commit a66982b.
This pull request is being automatically deployed with vercel-action

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.

2 participants