Skip to content

feat(kit,nuxt,schema): support experimental decorators syntax#27672

Merged
danielroe merged 24 commits intomainfrom
feat/decorators
Feb 10, 2025
Merged

feat(kit,nuxt,schema): support experimental decorators syntax#27672
danielroe merged 24 commits intomainfrom
feat/decorators

Conversation

@danielroe
Copy link
Member

@danielroe danielroe commented Jun 17, 2024

🔗 Linked issue

resolves #14126

📚 Description

This PR enables enabling decorator syntax across your entire Nuxt/Nitro app, powered by esbuild. It also allows passing and customising esbuild options across nitro, webpack, and vite build/optimizeDeps configurations via a new top-level esbuild option in your nuxt.config file.

Usage

// nuxt.config.ts
export default defineNuxtConfig({
  experimental: {
    decorators: true,
  },
})
// app.vue
function something (_method: () => unknown) {
  return () => 'decorated'
}

class SomeClass {
  @something
  public someMethod () {
    return 'initial'
  }
}

const value = new SomeClass().someMethod()
// this will return 'decorated'

Background

For a long time, TypeScript has had support for decorators via compilerOptions.experimentalDecorators. This implementation predated the TC39 standardization process. Now, decorators are a Stage 3 Proposal, and supported without special configuration in TS 5.0+ (see microsoft/TypeScript#52582 and https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#decorators).

Caution

Note that there may be changes before this finally lands in the JS standard.

Caution

If you have previously used experimentalDecorators from TypeScript, the implementation and types are different. Please read the proposal before enabling.

TODO:

  • tests
  • update other usages of esbuild

@bolt-new-by-stackblitz
Copy link

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

@darthf1
Copy link

darthf1 commented Jun 17, 2024

Is enabling this setting still necessary when using the stage 3 decorator proposal / decorators since TS 5.0?

https://chatgpt.com/share/e21d39be-259d-4dc2-b426-295b78240e70

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

(adding nitro.experimental.decorators could be also nice for future compat)

@socket-security
Copy link

socket-security bot commented Jul 3, 2024

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

View full report↗︎

@socket-security
Copy link

socket-security bot commented Jul 3, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@darthf1
Copy link

darthf1 commented Aug 8, 2024

Would love seeing this in a new release

@danielroe
Copy link
Member Author

waiting for #30066

@danielroe danielroe modified the milestones: 4.0, 3.16 Jan 14, 2025
@danielroe danielroe marked this pull request as ready for review February 10, 2025 13:02
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Warning

Rate limit exceeded

@danielroe has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 10 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 88cb413 and 1a4c8af.

📒 Files selected for processing (3)
  • packages/schema/src/config/esbuild.ts (1 hunks)
  • packages/schema/src/config/vite.ts (3 hunks)
  • packages/schema/src/config/webpack.ts (1 hunks)

Walkthrough

The changes implement support for experimental decorators across multiple packages and configurations. A new boolean flag is introduced in the template to control TypeScript compiler options related to decorators. Several modules have updated their import and usage of the transform function, shifting the source to internal utility modules to better integrate with esbuild-based transformations. In the configuration schema, a new decorators property is added and esbuild options are dynamically resolved using a merge strategy in Vite and Webpack configurations. A new configuration file centralises esbuild options, while the build configuration now lists esbuild as an external dependency. Additionally, tests and documentation have been updated to reflect and validate the experimental decorators support.


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>, 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. (Beta)
  • @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
Contributor

@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

🧹 Nitpick comments (8)
test/fixtures/basic/server/api/experimental/decorators.ts (1)

2-4: Consider adding type safety to the decorator function.

The decorator function could benefit from stronger typing to ensure type safety at compile time.

-  function something (_method: () => unknown) {
+  function something<T extends () => unknown>(_method: T): T {
-    return () => 'decorated'
+    return (() => 'decorated') as T
   }
test/fixtures/basic/pages/experimental/decorators.vue (2)

15-15: Consider handling fetch errors.

The useFetch call should include error handling for robustness.

-const { data } = await useFetch('/api/experimental/decorators')
+const { data, error } = await useFetch('/api/experimental/decorators')

Then update the template to handle errors:

 <template>
   <div>
-    {{ value }}-{{ data }}
+    <div v-if="error">Error: {{ error.message }}</div>
+    <div v-else>{{ value }}-{{ data }}</div>
   </div>
 </template>

24-26: Consider removing empty style block.

The empty scoped style block can be removed if not needed.

packages/schema/src/config/esbuild.ts (2)

15-27: Consider caching the decorator configuration check.

The useDecorators check might be called frequently during builds. Consider caching the result.

+let cachedDecoratorConfig: boolean | undefined
+
 tsconfigRaw: {
   $resolve: async (val: TransformOptions['tsconfigRaw'], get) => {
-    const useDecorators = await get('experimental').then(r => (r as Record<string, unknown>)?.decorators === true)
+    if (cachedDecoratorConfig === undefined) {
+      cachedDecoratorConfig = await get('experimental').then(r => (r as Record<string, unknown>)?.decorators === true)
+    }
+    const useDecorators = cachedDecoratorConfig
     if (!useDecorators) {
       return val
     }

20-26: Consider adding JSDoc for compiler options.

The compiler options would benefit from documentation explaining their purpose.

 return defu(val, {
   compilerOptions: {
+    // Required for proper decorator metadata handling
     useDefineForClassFields: false,
+    // Disable legacy experimental decorators as we're using the stage 3 proposal
     experimentalDecorators: false,
   },
 } satisfies TransformOptions['tsconfigRaw'])
packages/nuxt/src/core/plugins/prehydrate.ts (1)

5-5: LGTM! Improved code organisation by using local utility functions.

The change consolidates transformation logic into local utilities, making the code more maintainable.

Consider adding JSDoc comments to document the imported utility functions for better code documentation:

+/** Utilities for parsing and transforming code */
 import { parseAndWalk, transform, withLocations } from '../../core/utils/parse'
packages/nuxt/src/pages/route-rules.ts (1)

7-7: LGTM! Consistent use of local utility functions.

The change maintains consistency by using the same local utilities for code transformation.

Consider adding type annotations for better code maintainability:

-import { parseAndWalk, transform } from '../core/utils/parse'
+import type { TransformResult } from '../core/utils/parse'
+import { parseAndWalk, transform } from '../core/utils/parse'
packages/schema/src/config/experimental.ts (1)

94-99: LGTM! Consider enhancing the documentation.

The addition of the decorators property is well-documented. Consider adding more details about:

  • The stage of the TC39 proposal
  • Any limitations or known issues
  • Migration guidance for users
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c952e10 and d80930a.

⛔ Files ignored due to path filters (2)
  • packages/schema/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (16)
  • packages/kit/src/template.ts (2 hunks)
  • packages/nuxt/src/core/plugins/plugin-metadata.ts (1 hunks)
  • packages/nuxt/src/core/plugins/prehydrate.ts (1 hunks)
  • packages/nuxt/src/core/utils/parse.ts (1 hunks)
  • packages/nuxt/src/pages/route-rules.ts (1 hunks)
  • packages/nuxt/src/pages/utils.ts (1 hunks)
  • packages/schema/build.config.ts (1 hunks)
  • packages/schema/src/config/esbuild.ts (1 hunks)
  • packages/schema/src/config/experimental.ts (1 hunks)
  • packages/schema/src/config/index.ts (2 hunks)
  • packages/schema/src/config/vite.ts (3 hunks)
  • packages/schema/src/config/webpack.ts (1 hunks)
  • test/basic.test.ts (1 hunks)
  • test/fixtures/basic/nuxt.config.ts (1 hunks)
  • test/fixtures/basic/pages/experimental/decorators.vue (1 hunks)
  • test/fixtures/basic/server/api/experimental/decorators.ts (1 hunks)
🔇 Additional comments (15)
test/fixtures/basic/server/api/experimental/decorators.ts (1)

7-10: LGTM! Decorator implementation follows the stage 3 proposal.

The decorator syntax and usage align with the stage 3 decorator proposal specifications.

test/fixtures/basic/pages/experimental/decorators.vue (1)

2-4: Consider adding type safety to the decorator function.

Similar to the server-side implementation, the decorator function could benefit from stronger typing.

packages/schema/src/config/index.ts (1)

6-6: LGTM! Clean integration of esbuild configuration.

The import and export of esbuild configuration maintain the existing pattern and alphabetical order.

Also applies to: 30-30

packages/schema/build.config.ts (1)

42-42: LGTM! Addition of esbuild as an external dependency.

The addition of 'esbuild' as an external dependency aligns with the PR's objective of enabling experimental decorators syntax.

packages/schema/src/config/vite.ts (3)

2-2: LGTM! Added defu for options merging.

The addition of defu is appropriate for merging configuration options.


98-100: LGTM! Added esbuild options resolution.

The change allows for flexible configuration of esbuild options while maintaining defaults.

Let's verify the esbuild options schema:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Check if esbuild schema is properly defined
fd --type f --extension ts "esbuild.ts" --exec cat {} \;

Length of output: 2246


Verification Successful: Esbuild Options Schema Defined Correctly

The schema file (esbuild.ts) defines the esbuild options correctly. The async $resolve function for tsconfigRaw properly utilises defu to merge user-specified values with defaults when the experimental decorators are in use. This behaviour aligns with the intended design mentioned in the review comment.

  • The $resolve function in tsconfigRaw correctly conditionally merges configuration based on the experimental setting.
  • Default esbuild options (such as jsxFactory, jsxFragment) are accurately specified.

86-88: LGTM! Added esbuildOptions resolution.

The use of defu for merging esbuild options with defaults is a good practice.

Let's verify that the esbuild options are properly typed:

❌ Verification inconclusive

🏁 Script executed:

#!/bin/bash
# Check if esbuild options type is properly defined
ast-grep --pattern 'interface ViteConfig {
  $$$
  optimizeDeps?: {
    $$$
    esbuildOptions?: {
      $$$
    }
    $$$
  }
  $$$
}'

Length of output: 137


Manual Verification Required: Esbuild Options Typing

The ast-grep search did not return any results indicating an explicit type definition for esbuildOptions within the expected location (i.e. inside the optimizeDeps property of ViteConfig). This could mean that the type is defined elsewhere or that its typing is implicit. Please manually verify that the esbuildOptions property is correctly and intentionally typed.

packages/nuxt/src/core/plugins/plugin-metadata.ts (1)

10-10: LGTM! Import refactoring looks good.

The change to import transform from the local parse utility module aligns with the decorator support implementation.

test/fixtures/basic/nuxt.config.ts (1)

162-162: LGTM! Experimental feature flag added correctly.

The addition of the decorators flag in the experimental section is appropriate, as decorators are currently a stage 3 proposal.

packages/schema/src/config/webpack.ts (1)

161-163: LGTM! Dynamic esbuild configuration looks good.

The change to use dynamic resolution for esbuild loader options allows for proper integration of decorator support.

packages/kit/src/template.ts (2)

183-183: LGTM! Feature flag check implemented correctly.

The boolean flag to check for experimental decorators is well-placed and properly derived from the Nuxt options.


203-216: LGTM! TypeScript configuration for decorators is comprehensive.

The configuration correctly sets up TypeScript for the stage 3 decorators proposal:

  • Disables useDefineForClassFields and experimentalDecorators (as we're using the new syntax)
  • Adds esnext.decorators to the lib array for proper type definitions
packages/nuxt/src/core/utils/parse.ts (1)

3-3: LGTM! Imports are well-organized.

The imports are properly grouped and named.

Also applies to: 6-7

packages/nuxt/src/pages/utils.ts (1)

14-14: LGTM! Import addition is correct.

The transform function is properly imported alongside related functions.

test/basic.test.ts (1)

2784-2790: LGTM! Well-structured test cases for experimental decorators support.

The test cases effectively verify the decorator functionality by checking both server-side rendering and client-side hydration.

Comment on lines +11 to +13
export async function transform<T extends TransformOptions> (input: string | Uint8Array, options?: SameShape<TransformOptions, T>): Promise<TransformResult<T>> {
return await esbuildTransform(input, { ...tryUseNuxt()?.options.esbuild.options, ...options })
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle the case where tryUseNuxt() returns undefined.

The current implementation might cause issues if tryUseNuxt() returns undefined. Consider providing a fallback.

Apply this diff to handle the edge case:

-  return await esbuildTransform(input, { ...tryUseNuxt()?.options.esbuild.options, ...options })
+  const nuxtOptions = tryUseNuxt()?.options.esbuild.options ?? {}
+  return await esbuildTransform(input, { ...nuxtOptions, ...options })
📝 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
export async function transform<T extends TransformOptions> (input: string | Uint8Array, options?: SameShape<TransformOptions, T>): Promise<TransformResult<T>> {
return await esbuildTransform(input, { ...tryUseNuxt()?.options.esbuild.options, ...options })
}
export async function transform<T extends TransformOptions> (input: string | Uint8Array, options?: SameShape<TransformOptions, T>): Promise<TransformResult<T>> {
const nuxtOptions = tryUseNuxt()?.options.esbuild.options ?? {}
return await esbuildTransform(input, { ...nuxtOptions, ...options })
}

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 10, 2025

Open in Stackblitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@27672

nuxt

npm i https://pkg.pr.new/nuxt@27672

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@27672

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@27672

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@27672

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@27672

commit: 1a4c8af

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2025

CodSpeed Performance Report

Merging #27672 will not alter performance

Comparing feat/decorators (1a4c8af) with main (72d524b)

Summary

✅ 9 untouched benchmarks

Copy link
Contributor

@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

🧹 Nitpick comments (2)
docs/2.guide/3.going-further/1.experimental-features.md (2)

478-478: Clarify Redundant Verb Usage

The sentence currently reads "This option enables enabling decorator syntax…". Please remove the duplicate "enables" (e.g. change to "This option enables decorator syntax…") to improve clarity.

🧰 Tools
🪛 LanguageTool

[grammar] ~478-~478: You’ve repeated a verb. Did you mean to only write one of them?
Context: ...-only page. ## decorators This option enables enabling decorator syntax across your entire Nux...

(REPEATED_VERBS)


484-486: Refine Warning Block Punctuation

There are minor punctuation issues in the warning block. Consider reviewing the punctuation (especially around the note in line 485) for improved readability.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~485-~485: Loose punctuation mark.
Context: ... this finally lands in the JS standard. :: #### Usage ```ts twoslash [nuxt.conf...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d80930a and 30f544e.

📒 Files selected for processing (2)
  • docs/2.guide/3.going-further/1.experimental-features.md (1 hunks)
  • packages/kit/src/resolve.test.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/3.going-further/1.experimental-features.md

[grammar] ~478-~478: You’ve repeated a verb. Did you mean to only write one of them?
Context: ...-only page. ## decorators This option enables enabling decorator syntax across your entire Nux...

(REPEATED_VERBS)


[uncategorized] ~483-~483: Loose punctuation mark.
Context: ...xperimentalDecorators` implementation. ::warning Note that there may be changes ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~485-~485: Loose punctuation mark.
Context: ... this finally lands in the JS standard. :: #### Usage ```ts twoslash [nuxt.conf...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)
docs/2.guide/3.going-further/1.experimental-features.md

488-488: Heading levels should only increment by one level at a time
Expected: h3; Actual: h4

(MD001, heading-increment)

🪛 GitHub Actions: autofix.ci
docs/2.guide/3.going-further/1.experimental-features.md

[error] 488-488: Heading levels should only increment by one level at a time [Expected: h3; Actual: h4]

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: codeql (actions)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: code
🔇 Additional comments (2)
docs/2.guide/3.going-further/1.experimental-features.md (2)

476-477: New "decorators" Section Added

The introduction of the "decorators" section is well placed and clearly labelled. It fits with the other experimental features in the document, enhancing clarity for users exploring new options.


490-513: Usage Examples Are Clear and Informative

The provided code examples for enabling decorators in the Nuxt configuration and demonstrating their application in a class (in app.vue) are clear and effectively illustrate the new feature. This will help users understand how to implement the experimental decorators.

@danielroe danielroe changed the title feat(nuxt,schema): allow experimentally enabling decorators syntax feat(kit,nuxt,schema): support experimental decorators syntax Feb 10, 2025
Copy link
Contributor

@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

🧹 Nitpick comments (2)
packages/schema/src/config/esbuild.ts (1)

5-32: Consider adding JSDoc comments for configuration options.

While the code is well-structured, adding JSDoc comments for each configuration option would improve maintainability.

Apply this diff to add documentation:

 export default defineResolvers({
   esbuild: {
+    /**
+     * Shared esbuild options used across Nuxt and passed to other builders.
+     * @property {string} jsxFactory - The factory function used for JSX elements
+     * @property {string} jsxFragment - The component used for JSX fragments
+     * @property {object} tsconfigRaw - TypeScript compiler options
+     */
     options: {
       jsxFactory: 'h',
       jsxFragment: 'Fragment',
docs/2.guide/3.going-further/1.experimental-features.md (1)

478-478: Fix grammatical redundancy.

The phrase "enables enabling" is redundant.

Apply this diff to fix the grammar:

-This option enables enabling decorator syntax across your entire Nuxt/Nitro app, powered by [esbuild](https://github.com/evanw/esbuild/releases/tag/v0.21.3).
+This option enables decorator syntax across your entire Nuxt/Nitro app, powered by [esbuild](https://github.com/evanw/esbuild/releases/tag/v0.21.3).
🧰 Tools
🪛 LanguageTool

[grammar] ~478-~478: You’ve repeated a verb. Did you mean to only write one of them?
Context: ...-only page. ## decorators This option enables enabling decorator syntax across your entire Nux...

(REPEATED_VERBS)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30f544e and 88cb413.

⛔ Files ignored due to path filters (2)
  • packages/schema/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (6)
  • docs/2.guide/3.going-further/1.experimental-features.md (1 hunks)
  • packages/schema/src/config/esbuild.ts (1 hunks)
  • packages/schema/src/config/experimental.ts (1 hunks)
  • packages/schema/src/config/index.ts (2 hunks)
  • packages/schema/src/config/vite.ts (3 hunks)
  • packages/schema/src/config/webpack.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/schema/src/config/experimental.ts
  • packages/schema/src/config/index.ts
  • packages/schema/src/config/webpack.ts
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/3.going-further/1.experimental-features.md

[grammar] ~478-~478: You’ve repeated a verb. Did you mean to only write one of them?
Context: ...-only page. ## decorators This option enables enabling decorator syntax across your entire Nux...

(REPEATED_VERBS)


[uncategorized] ~483-~483: Loose punctuation mark.
Context: ...xperimentalDecorators` implementation. ::warning Note that there may be changes ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~485-~485: Loose punctuation mark.
Context: ... this finally lands in the JS standard. :: ### Usage ```ts twoslash [nuxt.confi...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (4)
packages/schema/src/config/esbuild.ts (1)

1-4: LGTM!

The imports and type usage are correct and well-structured.

packages/schema/src/config/vite.ts (2)

90-92: LGTM!

The esbuildOptions property correctly merges with global esbuild options using defu.


102-104: LGTM!

The esbuild resolver function correctly merges configuration values with global esbuild options.

docs/2.guide/3.going-further/1.experimental-features.md (1)

488-488: Adjust heading level for consistency.

The "Usage" heading increases the heading level by two steps from the preceding "decorators" section.

@danielroe danielroe merged commit 433a7e4 into main Feb 10, 2025
51 checks passed
@danielroe danielroe deleted the feat/decorators branch February 10, 2025 19:16
@github-actions github-actions bot mentioned this pull request Feb 10, 2025
@github-actions github-actions bot mentioned this pull request Feb 11, 2025
@ghost
Copy link

ghost commented Mar 17, 2025

So that at the moment is not usefully? It not work with decorators from other packages like mikro-orm?

@danielroe
Copy link
Member Author

@Maakdev not sure what you mean, but feel free to open an issue with a minimal reproduction if this isn't working for you

@ghost
Copy link

ghost commented Mar 17, 2025

@danielroe i do #31315

i mean

Unable to resolve signature of property decorator when called as an expression.
  No overload matches this call.
    Overload 1 of 3, '(Ctor: VueConstructor<VueBase>): void', gave the following error.
      Argument of type 'undefined' is not assignable to parameter of type 'VueConstructor<VueBase>'.
    Overload 2 of 3, '(target: VueBase, key: string): void', gave the following error.
      Argument of type 'undefined' is not assignable to parameter of type 'VueBase'.
        Type 'undefined' is not assignable to type '{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; ... 11 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: OnCleanup) => any : (ar...'.ts-plugin(1240)

Decorators not work, warnings, not compatible, not work without emitDecoratorMetadata as prior

@ghost
Copy link

ghost commented Mar 17, 2025

@danielroe also fetch not work in prod mode, in dev if i click button http request is made, in prod no errors, no request, nothing.

Button not work.

It's because of use of inversify to inject pinia stores and decorators. But it work in dev mode (with emitDecoratorMetadata not experimental decorators ). And not in prod :(

So big difference between dev and prod

<script lang="ts">
import {
  Component,
  Inject,
  setup,
  Vue,
  type Store
} from '@test'

import { definePageMeta } from '#imports'
import { AdminStore } from '~/store/admin.store'

@Component({
  providers: [
    AdminStore,
  ],
})
export default class IndexPage extends Vue {
  @Inject(AdminStore)
  public adminStore?: Store<AdminStore>
 }

and pinia store is a class

import {
InjectStore,
Pinia,
Store
} from '@test'
@Store()
export class AdminStore extends Pinia {
}

@ghost
Copy link

ghost commented Mar 17, 2025

@ghost
Copy link

ghost commented Mar 17, 2025

if i put in template {{ adminStore }} the page is white and no errors in console in prod.
if i put console.log( adminStore ) in mounted hook no log

only in dev all work

@pi0 @danielroe what is with that framework?

@danielroe
Copy link
Member Author

please comment on an issue rather than a merged pr, and also please avoid directly tagging maintainers 🙏

@nuxt nuxt locked as off-topic and limited conversation to collaborators Mar 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experimental typescript decorator support

3 participants