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

Migrate Build to ESM #291

Merged
merged 6 commits into from
Aug 23, 2024
Merged

Migrate Build to ESM #291

merged 6 commits into from
Aug 23, 2024

Conversation

overheadhunter
Copy link
Member

This PR bumps various build-time dependencies and completes the transitions to ESM.

ES modules is the de-facto standard adopted by all major frameworks and tools in recent years. In order to keep our dependencies up to date, we had to migrate them sooner or later.

This PR also adjusts VSCode settings for it to pick up the new linter and test configurations.

Last but not least, plenty of linter warnings/errors have been fixed, as it seems like the linter has not been run recently.

Copy link

coderabbitai bot commented Aug 22, 2024

Walkthrough

The changes encompass updates to configuration files for ESLint and Mocha, the introduction of a tailored ESLint setup for TypeScript and Vue.js, and various code improvements across multiple components and service files. These enhancements include modifications to type declarations, variable scopes, error handling, and formatting adjustments for better readability. The TypeScript configuration has also been revised to support ECMAScript modules, reflecting a commitment to modern JavaScript practices.

Changes

Files Change Summary
frontend/.vscode/settings.json Updated Mocha and ESLint configuration settings; introduced eslint.useFlatConfig.
frontend/package.json Added "type": "module"; simplified linting script and updated Mocha testing configuration.
frontend/src/common/*.ts Various type safety improvements, variable scope changes, and minor formatting adjustments.
frontend/src/components/*.vue Adjustments to variable declarations, enhancements in formatting, and improved readability.
frontend/test/common/*.spec.ts Updated variable declarations for immutability and clarity; streamlined test setup.
frontend/tsconfig.json Modified to support ECMAScript modules and include test files in compilation.

Sequence Diagram(s)

sequenceDiagram
    participant C as Component
    participant S as Service
    participant T as Test Suite
    participant L as Linter

    C->>L: Request linting
    L->>C: Return linting results

    C->>S: Make API call
    S->>C: Return data

    T->>S: Execute tests
    S->>T: Return test results
Loading

🐰 In the garden where code takes flight,
A rabbit hops with joy, oh what a sight!
With changes made, like springtime bloom,
Type safety shines, dispelling the gloom.
Variables snug, and formats refined,
In the world of code, all's perfectly aligned! 🌼✨


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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2af2800 and 22f82b7.

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (31)
  • frontend/.vscode/settings.json (1 hunks)
  • frontend/eslint.config.js (1 hunks)
  • frontend/package.json (4 hunks)
  • frontend/src/common/auditlog.ts (2 hunks)
  • frontend/src/common/backend.ts (6 hunks)
  • frontend/src/common/crypto.ts (2 hunks)
  • frontend/src/common/jwe.ts (3 hunks)
  • frontend/src/common/jwt.ts (2 hunks)
  • frontend/src/common/updatecheck.ts (1 hunks)
  • frontend/src/common/userdata.ts (2 hunks)
  • frontend/src/common/util.ts (3 hunks)
  • frontend/src/common/wot.ts (2 hunks)
  • frontend/src/components/AdminSettings.vue (2 hunks)
  • frontend/src/components/AuditLogDetailsSignedWotId.vue (1 hunks)
  • frontend/src/components/DeviceList.vue (1 hunks)
  • frontend/src/components/GrantPermissionDialog.vue (2 hunks)
  • frontend/src/components/NavigationBar.vue (3 hunks)
  • frontend/src/components/SignUserKeysDialog.vue (3 hunks)
  • frontend/src/components/TrustDetails.vue (1 hunks)
  • frontend/src/components/UserProfile.vue (1 hunks)
  • frontend/src/components/UserkeyFingerprint.vue (2 hunks)
  • frontend/src/components/VaultDetails.vue (2 hunks)
  • frontend/src/components/VaultList.vue (1 hunks)
  • frontend/src/i18n/index.ts (1 hunks)
  • frontend/src/router/index.ts (2 hunks)
  • frontend/src/shims-vue.d.ts (1 hunks)
  • frontend/test/common/crypto.spec.ts (5 hunks)
  • frontend/test/common/jwe.spec.ts (2 hunks)
  • frontend/test/common/jwt.spec.ts (2 hunks)
  • frontend/test/common/util.spec.ts (1 hunks)
  • frontend/tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (16)
  • frontend/src/common/updatecheck.ts
  • frontend/src/common/userdata.ts
  • frontend/src/common/wot.ts
  • frontend/src/components/AdminSettings.vue
  • frontend/src/components/AuditLogDetailsSignedWotId.vue
  • frontend/src/components/DeviceList.vue
  • frontend/src/components/SignUserKeysDialog.vue
  • frontend/src/components/TrustDetails.vue
  • frontend/src/components/UserProfile.vue
  • frontend/src/components/UserkeyFingerprint.vue
  • frontend/src/components/VaultList.vue
  • frontend/src/i18n/index.ts
  • frontend/src/router/index.ts
  • frontend/src/shims-vue.d.ts
  • frontend/test/common/jwt.spec.ts
  • frontend/test/common/util.spec.ts
Additional context used
Biome
frontend/src/common/util.ts

[error] 47-47: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

Additional comments not posted (39)
frontend/tsconfig.json (2)

17-18: Ensure compatibility with ESM settings.

The addition of "esm": true and "experimentalSpecifierResolution": "node" in the ts-node configuration is crucial for ESM support. Verify that all scripts and modules are compatible with these settings.


20-20: Include test files in TypeScript compilation.

The inclusion of test/**/*.ts in the include array is a positive step towards ensuring that test files are compiled and checked for type safety.

frontend/.vscode/settings.json (2)

23-26: Update Mocha settings for ESM compatibility.

The mochaExplorer.nodeArgv settings enable ES module support and suppress experimental warnings, aligning with the transition to ESM.


30-31: Adopt the new ESLint flat configuration.

The addition of eslint.useFlatConfig: true indicates a shift to the new ESLint configuration format, which is recommended for modern JavaScript projects.

frontend/package.json (4)

2-2: Transition to ECMAScript modules.

The addition of "type": "module" signifies a shift to ESM, affecting how modules are imported and exported. Ensure all files are compatible with this change.


13-13: Simplify ESLint configuration.

The removal of the configuration file reference in the "lint" script suggests reliance on default or new configuration methods, aligning with the move to a flat ESLint configuration.


23-23: Update Mocha loader for ESM.

The change to "loader": "ts-node/esm" in the Mocha configuration supports the use of ES modules in tests, enhancing compatibility with the new module system.


40-50: Update dependencies to latest versions.

The updates to chai, chai-as-promised, eslint, eslint-plugin-vue, and the addition of typescript-eslint reflect a move to modernize the codebase and ensure compatibility with ESM.

frontend/src/common/jwt.ts (2)

21-21: Improved type safety in build method.

Changing the payload parameter to object enhances type safety by ensuring it is always an object.


49-49: Improved type safety in parse method.

Changing the return type to object enhances type safety and aligns with the build method.

frontend/eslint.config.js (1)

1-97: Comprehensive ESLint configuration added.

The new ESLint configuration is well-structured and aligns with TypeScript and Vue.js best practices.

frontend/src/common/util.ts (2)

6-6: Enhanced type safety in transaction method.

Removing the default type of any enforces stricter type requirements, improving type safety.


26-26: Improved type handling in Deferred class.

Changing the reject method's parameter type to unknown promotes better type handling.

frontend/src/common/auditlog.ts (2)

119-119: Enhance type safety with specific function type.

The change from Function to () => void for the debouncedResolvePendingEntities parameter improves type safety by ensuring that only functions with no parameters and no return value are accepted.


136-136: Improve readability with destructuring syntax.

The change from ([_, v]) to ([, v]) in the filter method improves readability by omitting the unused variable name.

frontend/src/components/NavigationBar.vue (4)

71-71: Update icon name for clarity.

The renaming of ArrowRightOnRectangleIcon to ArrowRightStartOnRectangleIcon reflects a change in the icon's designation, improving clarity without altering functionality.


72-72: Add explicit type definition for FunctionalComponent.

The addition of FunctionalComponent in the import statements indicates a shift towards more explicit type definitions, enhancing type safety.


83-83: Introduce ProfileDropdownItem type for clarity.

The new ProfileDropdownItem type enhances type safety and clarity by defining the structure of items in the profile dropdown.


104-104: Update profileDropdown type for improved type safety.

Changing the type of profileDropdown from any[] to ProfileDropdownItem[][] improves type safety and ensures alignment with the newly defined type.

frontend/src/components/GrantPermissionDialog.vue (1)

124-124: Use const for non-reassigned variable.

Changing tokens from let to const clarifies that the variable is not reassigned, preventing potential bugs and improving code clarity.

frontend/test/common/jwe.spec.ts (3)

3-3: LGTM: Use of webcrypto import.

The change to import webcrypto from node:crypto aligns with ESM standards and modern JavaScript practices.


10-10: LGTM: Setting global crypto with webcrypto.

The use of webcrypto to set the global crypto object is appropriate for the test environment.


25-25: LGTM: Use of const for derivedKey.

Changing derivedKey to const enforces immutability, which is a best practice.

frontend/src/common/jwe.ts (3)

84-84: LGTM: Use of generic return type in decryptEcdhEs.

The change to a generic return type Promise<T> enhances type safety by allowing the caller to specify the expected type.


99-99: LGTM: Use of generic return type in decryptPbes2.

The change to a generic return type Promise<T> enhances type safety by allowing the caller to specify the expected type.


113-113: LGTM: Use of generic return type in decrypt.

The change to a generic return type Promise<T> enhances type safety by allowing the caller to specify the expected type.

frontend/src/common/backend.ts (6)

30-30: LGTM: Simplified error handling in axiosAuth interceptor.

The direct throw of UnauthorizedError simplifies the error handling logic.


163-163: LGTM: Use of const for dateString.

Changing dateString to const enforces immutability, which is a best practice.


231-231: LGTM: Updated return type in removeDevice.

The change to Promise<AxiosResponse<unknown>> enhances type safety.


236-236: LGTM: Updated return type in putDevice.

The change to Promise<AxiosResponse<unknown>> enhances type safety.


294-294: LGTM: Use of const for cfg.

Changing cfg to const enforces immutability, which is a best practice.


411-411: LGTM: Updated return type in rethrowAndConvertIfExpected.

The change to never clarifies that the function will always throw an error, enhancing type safety.

frontend/test/common/crypto.spec.ts (4)

4-4: LGTM! Modern import for webcrypto.

The import statement for webcrypto from node:crypto is a modern and cleaner approach.


39-39: LGTM! Simplified setup of global.crypto.

The before hook now directly uses the imported webcrypto, streamlining the setup process.


44-45: LGTM! Use of const for immutable variables.

Changing ecdhP384, ecdsaP384, and recoveryKey to const enhances code safety by indicating immutability.

Also applies to: 65-65


244-244: LGTM! Refined type definition for input.

The type refinement for input to JsonWebKey & Record<string, string> improves type safety and clarity.

frontend/src/common/crypto.ts (1)

6-8: LGTM! Enhanced type safety for UnwrapKeyError.

Changing actualError to unknown improves type safety by requiring explicit handling.

frontend/src/components/VaultDetails.vue (2)

367-367: LGTM! Enhanced type safety for isAuthorityDto.

Changing the parameter type to unknown ensures stricter type safety.


394-394: LGTM! Improved readability in addAuthorityBackend.

The added whitespace around the switch statement enhances readability.

frontend/src/common/util.ts Show resolved Hide resolved
Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

Looks good to me but npm outdated shows still some outdated packages (Keycloak is fixed on the dev branch, so this can be skipped), is there a reason for it?

Package                        Current   Latest  Location                                   Depended by
@rollup/rollup-linux-x64-gnu    4.20.0   4.21.0  node_modules/@rollup/rollup-linux-x64-gnu  frontend
@types/node                    20.14.15  22.5.0  node_modules/@types/node                   frontend
keycloak-js                     25.0.2   25.0.4  node_modules/keycloak-js                   frontend
vite                             5.4.0    5.4.2  node_modules/vite                          frontend
vue-i18n                        9.13.1   9.14.0  node_modules/vue-i18n                      frontend

@overheadhunter
Copy link
Member Author

overheadhunter commented Aug 23, 2024

Looks good to me but npm outdated shows still some outdated packages (Keycloak is fixed on the dev branch, so this can be skipped), is there a reason for it?

Except for node (which I didn't update because I didn't want to touch GitHub Actions as well) and keycloak (which should probably match the kc version we ship) the reason simply is that they all outpaced this PR.

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: 0

Outside diff range, codebase verification and nitpick comments (1)
CHANGELOG.md (1)

Line range hint 17-22: Correct the typographical error in the "Changed" section.

The word "Bumpd" should be corrected to "Bumped."

Apply this diff to correct the typo:

- Bumpd build time dependencies
+ Bumped build time dependencies
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 22f82b7 and 3e464bc.

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • frontend/package.json (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/package.json
Additional comments not posted (3)
CHANGELOG.md (3)

Line range hint 9-12: The "Added" section is clear and concise.

The entries provide a good overview of new features related to user key management and identity verification.


24-24: The "Fixed" section is clear and concise.

The entry provides a concise description of the accessibility improvement.


Line range hint 26-30: The "Security" section is clear and specific.

The entries provide specific details about the vulnerabilities addressed in the update.

@overheadhunter overheadhunter merged commit c3408a4 into develop Aug 23, 2024
4 checks passed
@overheadhunter overheadhunter deleted the feature/esm branch August 23, 2024 09:32
@overheadhunter overheadhunter added this to the 1.4.0 milestone Aug 23, 2024
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