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: support to use import.meta.url on commonjs #1

Merged
merged 1 commit into from
Jul 7, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jul 7, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new GitHub Actions workflow to publish on any commit or pull request.
    • Added a function to handle import.meta.url in CommonJS modules.
  • Improvements

    • Updated Node.js versions in workflows to include v22.
    • Enhanced package.json with updated paths for imports, exports, and types.
    • Improved file system operations and path handling within the project.
    • Updated TypeScript configurations for better code consistency and module handling.
  • Bug Fixes

    • Addressed a SyntaxError related to import.meta.url in CommonJS modules.
  • Documentation

    • Updated README with new instructions for auto-setting package.json.
  • Tests

    • Expanded test scenarios with additional asynchronous calls and configurations.

Copy link

coderabbitai bot commented Jul 7, 2024

Walkthrough

This update encompasses several changes to the project’s configuration and functionality. The Node.js version in the workflow is updated, new workflows are added for publishing commits, and the release process is streamlined by removing a test parameter. The package.json and TypeScript configurations are revised to align import paths and enhance compatibility. Additionally, the project addresses import.meta.url syntax issues in CommonJS modules and bolsters file system operations, with corresponding adjustments to the test suite.

Changes

Files Change Summary
.github/workflows/nodejs.yml Updated Node.js versions to include version 22.
.github/workflows/pkg.pr.new.yml Introduced a new workflow for publishing on any commit.
.github/workflows/release.yml Removed the checkTest parameter from the job configuration.
README.md Documented new auto-setting package.json features and provided a workaround for import.meta.url in CommonJS.
package.json Updated paths for imports/require and revised "main", "types", and "module" attributes.
src/index.ts Added file system operations, path handling, and a function to replace import.meta.url occurrences.
test/fixtures/demo/src/index.ts Introduced a function getDirname() to handle directory name retrieval.
test/fixtures/demo/src/tsconfig.json Updated TypeScript compiler options.
test/index.test.ts Enhanced test suite with additional asynchronous calls and configurations.

Poem

🎉 In code we trust, so bold and new,
Paths aligned, with clearer view.
Node's updated, tests refined,
Bugs addressed, solutions signed.
Commit and publish, workflows flow,
With every change, our project grows.
🚀👾 Keep coding on, let progress show!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

pkg-pr-new bot commented Jul 7, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: 6039a60

tshy-after

npm i https://pkg.pr.new/node-modules/tshy-after@1


templates

@fengmk2 fengmk2 self-assigned this Jul 7, 2024
@fengmk2 fengmk2 added the bug Something isn't working label Jul 7, 2024
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: 3

Outside diff range and nitpick comments (2)
test/index.test.ts (2)

23-26: Consider removing .debug() in production tests.

The .debug() call is useful for debugging but should be removed in production tests to reduce noise.

-      .debug()

31-37: Consider removing .debug() in production tests.

The .debug() call is useful for debugging but should be removed in production tests to reduce noise.

-      .debug()
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0d739a5 and 6039a60.

Files selected for processing (10)
  • .github/workflows/nodejs.yml (1 hunks)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • README.md (1 hunks)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
  • test/fixtures/demo/src/index.ts (1 hunks)
  • test/fixtures/demo/src/tsconfig.json (1 hunks)
  • test/fixtures/demo/tsconfig.json (1 hunks)
  • test/index.test.ts (1 hunks)
Files skipped from review due to trivial changes (4)
  • .github/workflows/nodejs.yml
  • .github/workflows/pkg.pr.new.yml
  • test/fixtures/demo/src/tsconfig.json
  • test/fixtures/demo/tsconfig.json
Additional comments not posted (4)
.github/workflows/release.yml (1)

Line range hint 1-11:
LGTM!

The GitHub Actions workflow for releasing the project appears to be correct and complete.

test/fixtures/demo/src/index.ts (1)

1-10: LGTM!

The getDirname function and necessary imports appear to be correct and complete.

README.md (1)

8-30: LGTM!

The documentation updates are clear and correct. The example provided is consistent with the implementation in test/fixtures/demo/src/index.ts.

src/index.ts (1)

3-31: LGTM!

The replaceImportMetaUrl function and necessary imports appear to be correct and complete. The use of synchronous file system operations is acceptable in this context.

Comment on lines +57 to +59
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js"
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Paths in package.json are incorrect or the build process is failing.

The specified files in the main, types, and module fields do not exist. This could be due to incorrect paths or an issue with the build process. Please verify the build process and ensure the paths are correct.

  • ./dist/commonjs/index.js
  • ./dist/commonjs/index.d.ts
  • ./dist/esm/index.js
Analysis chain

Verify the updated paths.

Ensure that the updated paths for main, types, and module are correct and align with the project structure.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the updated paths in package.json.

# Test: Check if the main file exists. Expect: File should exist.
test -f ./dist/commonjs/index.js && echo "Main file exists" || echo "Main file missing"

# Test: Check if the types file exists. Expect: File should exist.
test -f ./dist/commonjs/index.d.ts && echo "Types file exists" || echo "Types file missing"

# Test: Check if the module file exists. Expect: File should exist.
test -f ./dist/esm/index.js && echo "Module file exists" || echo "Module file missing"

Length of output: 242

Comment on lines +46 to 48
"source": "./src/index.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The types file ./dist/esm/index.d.ts is missing.

Please ensure that the build process correctly generates the index.d.ts file in the ./dist/esm/ directory. Verify the build scripts and configurations related to type generation.

  • Check the build scripts in package.json or related configuration files.
  • Ensure the index.d.ts file is correctly generated and placed in the ./dist/esm/ directory.
Analysis chain

Verify the new import paths.

Ensure that the new import paths for source and types are correct and align with the project structure.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new import paths in package.json.

# Test: Check if the source file exists. Expect: File should exist.
test -f ./src/index.ts && echo "Source file exists" || echo "Source file missing"

# Test: Check if the types file exists. Expect: File should exist.
test -f ./dist/esm/index.d.ts && echo "Types file exists" || echo "Types file missing"

Length of output: 150

Comment on lines +51 to 53
"source": "./src/index.ts",
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Missing Type Declaration File

The index.d.ts file is missing because the main tsconfig.json does not have the necessary declaration and outDir settings. These settings are required to generate type declaration files.

  • File: tsconfig.json
    • Add "declaration": true and "outDir": "./dist/commonjs" to the compilerOptions.

Please update the tsconfig.json to include these settings to ensure type declaration files are generated correctly.

Analysis chain

Verify the new require paths.

Ensure that the new require paths for source and types are correct and align with the project structure.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new require paths in package.json.

# Test: Check if the source file exists. Expect: File should exist.
test -f ./src/index.ts && echo "Source file exists" || echo "Source file missing"

# Test: Check if the types file exists. Expect: File should exist.
test -f ./dist/commonjs/index.d.ts && echo "Types file exists" || echo "Types file missing"

Length of output: 155


Script:

#!/bin/bash
# Description: Investigate the missing types file.

# Search for the index.d.ts file in the repository to see if it exists elsewhere.
fd -e d.ts index

# Check for relevant build configurations in the project.
fd -e json -e js -e tsconfig -e babelrc

Length of output: 205


Script:

#!/bin/bash
# Description: Display the contents of tsconfig.json to understand the configuration for type declaration files.

# Display the contents of tsconfig.json
cat tsconfig.json

Length of output: 396


Script:

#!/bin/bash
# Description: Search for other tsconfig.json files and check for declaration and outDir settings.

# Search for other tsconfig.json files in the repository.
fd -e json tsconfig

# Check for declaration and outDir settings in all tsconfig.json files.
fd -e json tsconfig | xargs -I {} sh -c 'echo "File: {}"; cat {} | jq ".compilerOptions.declaration, .compilerOptions.outDir"'

Length of output: 368

@fengmk2 fengmk2 merged commit 155cb48 into master Jul 7, 2024
10 checks passed
@fengmk2 fengmk2 deleted the import.meta.url branch July 7, 2024 05:48
fengmk2 pushed a commit that referenced this pull request Jul 7, 2024
[skip ci]

## [1.1.0](v1.0.0...v1.1.0) (2024-07-07)

### Features

* support to use import.meta.url on commonjs ([#1](#1)) ([155cb48](155cb48))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant