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 @eggjs/core next version #21

Merged
merged 4 commits into from
Jun 17, 2024
Merged

feat: support @eggjs/core next version #21

merged 4 commits into from
Jun 17, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jun 17, 2024

BREAKING CHANGE: drop Node.js < 18.19.0 support

eggjs/egg#5257

Summary by CodeRabbit

  • New Features

    • Introduced new utility functions for resolving and importing modules with support for CommonJS and ESM formats.
    • Added new test fixtures for CommonJS and ESM modules to validate module import functionality.
  • Refactor

    • Updated import statements to include file extensions (.js) for consistency and compatibility.
    • Refactored code to use async/await for asynchronous operations.
    • Improved path handling in tests with helper functions.
  • Documentation

    • Updated package.json with new scripts, dependencies, and module management configurations.
  • Chores

    • Enhanced .gitignore to exclude .tshy* files and dist/ directory.
    • Modified GitHub Actions workflows for Node.js and release processes.
  • Tests

    • Added tests for new module import functions.
    • Updated existing tests to reflect new import paths and async changes.
  • Configuration

    • Updated tsconfig.json for stricter TypeScript settings and modern module resolution.

BREAKING CHANGE: drop Node.js < 18.19.0 support

eggjs/egg#5257
@fengmk2 fengmk2 self-assigned this Jun 17, 2024
Copy link

vercel bot commented Jun 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
egg-utils ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 1:35pm

Copy link

coderabbitai bot commented Jun 17, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates focus on improving module management, testing workflows, and modernizing JavaScript features. Key changes include transitioning to ES modules, refining GitHub Actions workflows, updating dependencies, and refactoring import paths for consistency. Additionally, async/await has been introduced to several functions for enhanced readability and performance. The @eggjs/utils package received updates to enhance compatibility and module management.

Changes

Files/Groups Change Summaries
.github/workflows/nodejs.yml, .github/workflows/release.yml Updated GitHub Actions workflows for Node.js and release jobs with new uses values and version changes.
.gitignore Added exclusions for .tshy* files and the dist/ directory.
package.json Updated scripts, dependencies, and module management settings.
src/deprecated.ts, src/framework.ts, src/index.ts Changed to importing modules with .js extensions.
src/import.ts New file introduced functions for resolving and importing modules with ESM and CommonJS support.
src/plugin.ts Refactored to use async/await and modern JavaScript features.
test/... (test files and fixtures) Updated import paths, refactored to use async/await, added new fixture files for module testing.
tsconfig.json Enabled strict type checking settings and updated module resolution to NodeNext.

Sequence Diagram(s)

Import and Module Resolution Flow

sequenceDiagram
    participant Importer
    participant Resolver as importResolve()
    participant ModuleManager as importModule()

    Importer->>Resolver: Request module resolution
    Resolver-->>Importer: Return resolved path
    Importer->>ModuleManager: Import the resolved module
    ModuleManager-->>Importer: Return imported module
Loading

Poem

The code has changed, the scripts are new,
Modules resolved, as ES blue.
With async/await, they run so fast,
Gone are delays, those days have passed.
🎉 A rabbit hops in cheer and glee,
For now the code flows wild and free. 🐇


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

socket-security bot commented Jun 17, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/egg@3.24.1 filesystem, network, unsafe Transitive: environment, eval, shell +289 20.4 MB fengmk2
npm/eslint-config-egg@13.1.0 Transitive: environment, filesystem, shell, unsafe +163 34.4 MB fengmk2
npm/framework-demo@1.0.1 Transitive: environment, eval, filesystem, network, shell, unsafe +316 24.9 MB samaritain89
npm/runscript@1.6.0 environment, shell 0 10.8 kB fengmk2
npm/typescript@5.4.5 None 0 32.4 MB typescript-bot

🚮 Removed packages: npm/eslint-config-egg@12.3.1, npm/npm@9.9.3

View full report↗︎

Copy link

socket-security bot commented Jun 17, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Potential typo squat npm/extend2@1.0.1
Potential typo squat npm/egg-errors@2.3.2

View full report↗︎

Next steps

What is a typosquat?

Package name is similar to other popular packages and may not be the package you want.

Use care when consuming similarly named packages and ensure that you did not intend to consume a different package. Malicious packages often publish using similar names as existing popular packages.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/extend2@1.0.1
  • @SocketSecurity ignore npm/egg-errors@2.3.2

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

Outside diff range and nitpick comments (2)
src/deprecated.ts (1)

Line range hint 27-27: Consider using optional chaining to simplify access to nested properties, enhancing code safety and readability.

-    if (pkg.egg && pkg.egg.framework) {
+    if (pkg.egg?.framework) {
test/plugin.test.ts (1)

Line range hint 21-21: Duplicate afterEach hooks detected. Consider consolidating or removing redundant hooks to enhance clarity and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3ceccab and a6b6dbd.

Files selected for processing (28)
  • .github/workflows/nodejs.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .gitignore (1 hunks)
  • package.json (2 hunks)
  • src/deprecated.ts (1 hunks)
  • src/framework.ts (1 hunks)
  • src/import.ts (1 hunks)
  • src/index.ts (1 hunks)
  • src/plugin.ts (3 hunks)
  • test/fixtures/cjs/es-module-default.js (1 hunks)
  • test/fixtures/cjs/exports.cjs (1 hunks)
  • test/fixtures/cjs/exports.js (1 hunks)
  • test/fixtures/cjs/index.js (1 hunks)
  • test/fixtures/cjs/package.json (1 hunks)
  • test/fixtures/egg-app/get_config.js (1 hunks)
  • test/fixtures/egg-app/get_loadunit.js (1 hunks)
  • test/fixtures/egg-app/get_plugin.js (1 hunks)
  • test/fixtures/egg-app/package.json (1 hunks)
  • test/fixtures/esm/exports.js (1 hunks)
  • test/fixtures/esm/exports.mjs (1 hunks)
  • test/fixtures/esm/index.js (1 hunks)
  • test/fixtures/esm/package.json (1 hunks)
  • test/framework.test.ts (9 hunks)
  • test/getFrameworkOrEggPath.test.ts (1 hunks)
  • test/helper.ts (1 hunks)
  • test/import.test.ts (1 hunks)
  • test/plugin.test.ts (8 hunks)
  • tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (15)
  • .github/workflows/release.yml
  • .gitignore
  • src/framework.ts
  • test/fixtures/cjs/es-module-default.js
  • test/fixtures/cjs/exports.cjs
  • test/fixtures/cjs/exports.js
  • test/fixtures/cjs/index.js
  • test/fixtures/cjs/package.json
  • test/fixtures/egg-app/package.json
  • test/fixtures/esm/exports.js
  • test/fixtures/esm/exports.mjs
  • test/fixtures/esm/index.js
  • test/fixtures/esm/package.json
  • test/helper.ts
  • test/import.test.ts
Additional context used
Biome
src/deprecated.ts

[error] 27-27: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

test/plugin.test.ts

[error] 21-21: Disallow duplicate setup and teardown hooks. (lint/suspicious/noDuplicateTestHooks)

Disallow afterEach duplicacy inside the describe function.

Additional comments not posted (30)
test/fixtures/egg-app/get_plugin.js (1)

1-6: The changes in this script are well-implemented and consistent with the intended functionality.

tsconfig.json (1)

4-9: The updates to the TypeScript configuration align with modern best practices and enhance the project's type safety and compatibility with recent ECMAScript standards.

test/fixtures/egg-app/get_config.js (1)

1-7: The updates in this script are correctly implemented, enhancing the script's utility for debugging and configuration management.

.github/workflows/nodejs.yml (1)

12-16: The changes to the GitHub Actions workflow are well-aligned with the project's updated requirements and best practices for continuous integration.

test/fixtures/egg-app/get_loadunit.js (1)

1-9: This script effectively logs the count of different types of units loaded. Ensure that the process.argv[2] input is properly formatted JSON to avoid runtime errors.

src/index.ts (1)

1-9: The updates to the export statements align with the new ESM format. Ensure that all referenced files correctly implement the exported functionalities.

src/deprecated.ts (1)

3-3: The update to include the .js extension in the import statement is correct and necessary for ESM compatibility.

test/getFrameworkOrEggPath.test.ts (2)

2-3: The updated imports correctly reference the new file locations and utilities, ensuring that the tests have access to necessary functionalities.


5-37: The test cases are well-structured and effectively test various scenarios for the getFrameworkOrEggPath function. The use of getFilepath enhances consistency in path handling.

package.json (7)

4-6: Updated Node.js engine requirement to >=18.19.0 aligns with the new support policy.


13-19: Added several new scripts to enhance the build and test processes.


33-46: Significant updates to dependencies to support new features and ensure compatibility with the latest standards.


48-51: Including dist and src in the files array ensures that only necessary files are packaged, enhancing the cleanliness of the package.


52-52: Switching to ES Modules with type: module is a significant shift that aligns with modern JavaScript practices.


59-73: The exports field configuration supports both CommonJS and ESM, which is crucial for compatibility across different module systems.


74-75: Setting main entry point and types definition for CommonJS explicitly.

src/import.ts (3)

1-3: Imports from Node.js built-in modules to support utility functions.


18-29: importResolve function correctly utilizes custom or native require to resolve module paths, enhancing flexibility in module resolution.


31-82: importModule function supports both CommonJS and ESM, handling different module formats effectively. Good use of async/await for ESM imports.

test/framework.test.ts (3)

5-6: Utilizes helper functions for path handling to maintain consistency and reduce redundancy.


Line range hint 13-109: Updated tests to use the new path handling functions, ensuring that the tests are robust and maintainable.


Line range hint 125-139: Tests for default and monorepo configurations are well-handled, ensuring the framework path is correctly resolved in complex setups.

src/plugin.ts (4)

1-7: Imports and setup for plugin utilities are correctly implemented, ensuring foundational tools are available for plugin handling.


Line range hint 42-65: Functions getPlugins, getLoadUnits, and getConfig are well implemented with async/await, ensuring plugins are loaded and configured asynchronously.


95-120: getLoader function is robust, handling various scenarios with assertions and dynamic path handling, ensuring the loader is correctly set up.


122-161: findEggCore function effectively searches for core dependencies, handling errors and paths intelligently.

test/plugin.test.ts (4)

8-9: Updated import paths to include .js extensions align with the new module system. Ensure all related files are correctly updated to ES modules as well.


12-13: Correct usage of helper functions for path handling, enhancing maintainability and adaptability of the test environment setup.


34-34: Ensure that the expected output in tests (/get all plugins \["onerror",/) matches the actual output from the application, especially after changes in the plugin management.

Also applies to: 48-48, 63-63


66-66: The async functions getPlugins and getLoadUnits are correctly implemented and used. Ensure that they handle errors gracefully and that the tests cover possible edge cases.

Also applies to: 108-108

.expect('code', 0)
.end();
const config = utils.getConfig({
const config = await utils.getConfig({
Copy link

Choose a reason for hiding this comment

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

Ensure the getConfig function correctly fetches configuration from the specified framework path. Consider adding more robust error handling and logging for better diagnostics.

- const config = await utils.getConfig({
+ try {
+   const config = await utils.getConfig({
      baseDir: tmp,
      framework: path.join(tmp, 'node_modules/framework-demo'),
    });
+   assert(config);
+   assert.equal(config.name, 'egg-app');
+ } catch (error) {
+   console.error('Error fetching config:', error);
+   throw error;
+ }
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
const config = await utils.getConfig({
try {
const config = await utils.getConfig({
baseDir: tmp,
framework: path.join(tmp, 'node_modules/framework-demo'),
});
assert(config);
assert.equal(config.name, 'egg-app');
} catch (error) {
console.error('Error fetching config:', error);
throw error;
}

@@ -162,8 +160,7 @@ describe('test/plugin.test.ts', () => {
});
await coffee.fork(bin, [ args ], { cwd: tmp })
.debug()
// .expect('stdout', /get app configs session,security,helper,jsonp,onerror,i18n,watcher,multipart,logrotator,static,view,env,name,keys,proxy,protocolHeaders,ipHeaders,hostHeaders,pkg,baseDir,HOME,rundir,dump,notfound,siteFile,bodyParser,logger,httpclient,coreMiddleware,workerStartTimeout,coreMiddlewares,appMiddlewares,appMiddleware/)
.expect('stdout', /get app configs/)
.expect('stdout', /get app configs \["session"/)
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 search results indicate that references to session are present in the test/plugin.test.ts file, specifically within the test cases. However, there are no references to session in the main codebase, particularly within the getConfig method.

  • Lines 163, 177, and 191 in test/plugin.test.ts contain expectations related to session.

Given this, it appears that the test cases might be outdated or misaligned with the current implementation of getConfig, which does not directly reference session.

Analysis chain

Updated test cases for the getConfig method to ensure they reflect the new configurations and dependencies. Verify that the configurations being tested are up-to-date with the latest application settings.

Also applies to: 177-177, 191-191

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the configurations being tested are up-to-date with the latest application settings.

# Test: Search for the configuration settings in the application code.
rg --type config $'/get app configs \["session"/'

Length of output: 199



Script:

#!/bin/bash
# Search for the `getConfig` method in the codebase.
ast-grep --lang typescript --pattern 'function getConfig($_) { $$$ }'

Length of output: 370



Script:

#!/bin/bash
# Search for references to `session` in the codebase.
rg 'session'

Length of output: 316

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 37 lines in your changes missing coverage. Please review.

Project coverage is 87.65%. Comparing base (f4a47b9) to head (a6b6dbd).
Report is 1 commits behind head on master.

Files Patch % Lines
src/plugin.ts 73.40% 25 Missing ⚠️
src/import.ts 85.36% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
- Coverage   88.85%   87.65%   -1.21%     
==========================================
  Files           5        6       +1     
  Lines         296      413     +117     
  Branches       40       53      +13     
==========================================
+ Hits          263      362      +99     
- Misses         33       51      +18     

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

@fengmk2 fengmk2 merged commit a37968c into master Jun 17, 2024
16 of 19 checks passed
@fengmk2 fengmk2 deleted the esm branch June 17, 2024 13:46
fengmk2 pushed a commit that referenced this pull request Jun 17, 2024
[skip ci]

## [4.0.0](v3.0.1...v4.0.0) (2024-06-17)

### ⚠ BREAKING CHANGES

* drop Node.js < 18.19.0 support

eggjs/egg#5257

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced new utility functions for resolving and importing modules
with support for CommonJS and ESM formats.
- Added new test fixtures for CommonJS and ESM modules to validate
module import functionality.

- **Refactor**
- Updated import statements to include file extensions (`.js`) for
consistency and compatibility.
	- Refactored code to use async/await for asynchronous operations.
	- Improved path handling in tests with helper functions.

- **Documentation**
- Updated `package.json` with new scripts, dependencies, and module
management configurations.

- **Chores**
- Enhanced `.gitignore` to exclude `.tshy*` files and `dist/` directory.
	- Modified GitHub Actions workflows for Node.js and release processes.

- **Tests**
	- Added tests for new module import functions.
	- Updated existing tests to reflect new import paths and async changes.

- **Configuration**
- Updated `tsconfig.json` for stricter TypeScript settings and modern
module resolution.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

### Features

* support @eggjs/core next version ([#21](#21)) ([a37968c](a37968c))
@fengmk2 fengmk2 mentioned this pull request Jun 17, 2024
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant