-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: support define page #145
Conversation
WalkthroughThe update entails enhancements in ESLint integration, Vue.js project page management, and development workflow optimizations. It introduces new features for defining and parsing pages, improves ESLint settings in VS Code, and streamlines interactions with Vue Single File Components (SFCs). Utility functions are introduced, and the playground showcases enhanced capabilities, emphasizing code quality and developer efficiency. Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
package.json
is excluded by:!**/*.json
packages/core/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (10)
- .vscode/settings.json (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (8 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/i18n.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review due to trivial changes (1)
- packages/playground/src/uni-pages.d.ts
Additional comments: 18
packages/playground/src/pages/i18n.vue (1)
- 5-11: The usage of
definePage
within the<script setup>
block correctly implements the new feature. This change aligns with the PR's objective to support thedefinePage
macro, allowing for a more structured and declarative way to define page options. Ensure that the%app.name%
placeholder is properly resolved in the context of your application.packages/core/src/constant.ts (1)
- 8-8: The addition of the
DEFINE_PAGE
constant is correct and aligns with the PR's objective to support thedefinePage
macro. This constant will likely be used throughout the framework to reference the macro by name, ensuring consistency.packages/core/client.d.ts (1)
- 9-11: The declaration of the
definePage
function within theglobalThis
module is correctly implemented, allowing it to be recognized globally. This aligns with the PR's objective to introduce thedefinePage
macro. Ensure that theDefinePageOptions
type accurately reflects the options that can be passed todefinePage
..vscode/settings.json (1)
- 2-42: The ESLint configuration adjustments, including enabling flat config support, disabling the default formatter in favor of ESLint, configuring editor settings for ESLint auto-fix, customizing ESLint rules severity, and enabling ESLint validation for various languages, are correctly implemented. These changes enhance the development experience by ensuring code quality and consistency. Ensure that these settings align with your project's coding standards and ESLint rules.
packages/core/src/utils.ts (2)
- 2-2: Changing the import statement for
ModuleNode
andViteDevServer
from 'vite' to use type syntax is a good practice, as it clarifies that these imports are only used for type information and not included in the JavaScript output.- 54-56: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [36-60]
The removal of unused functions (
getRouteSfcBlock
anduseCachedPages
) and their internal logic is a positive change, as it helps to keep the codebase clean and maintainable. Ensure that these functions are indeed not used anywhere in the project to avoid breaking changes.packages/core/src/types.ts (2)
- 15-16: The addition of the
RouteBlockLang
type with specific string literals is a good practice, as it restricts the values to a predefined set, enhancing type safety and readability.- 146-152: The introduction of the
DefinePageOptions
interface with a deprecatedpath
property is correctly implemented. However, ensure that the deprecation of thepath
property is clearly communicated to developers, possibly through documentation, to avoid confusion.packages/core/src/index.ts (1)
- 83-115: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-149]
The modifications in
index.ts
, including importing necessary functions from@vue/compiler-sfc
, adding new constants, and adjusting thetransform
function to handle parsing of Vue single-file components (SFC), finding macros, and route blocks, are correctly implemented. These changes align with the PR's objective to support thedefinePage
macro and enhance code transformation and parsing capabilities. Ensure that thetransform
function's logic correctly handles all edge cases and that the error messages are clear and informative for developers.packages/core/src/page.ts (2)
- 16-60: The introduction of the
Page
class, which centralizes the reading and parsing of page options from various file formats, is correctly implemented. This class enhances the maintainability and modularity of the codebase by encapsulating page-related logic. Ensure that the error handling in thereadOptions
method is robust and provides clear error messages to developers.- 63-149: The functions
readPageOptionsFromFile
,readPageOptionsFromMacro
, andreadPageOptionsFromBlock
are well-implemented, providing a structured approach to parsing page options based on the file content and the specified route block language. Ensure that the parsing logic correctly handles all supported formats and that the error messages are informative.packages/core/src/context.ts (7)
- 22-22: The import of the
Page
class aligns with the PR's objective to support thedefinePage
macro by introducing a centralized way to manage page metadata and options. This change is crucial for the refactoring efforts to work withPage
instances.- 44-45: The introduction of
pages
andsubPages
as class properties is a significant change. It shifts the data structure from using paths to usingPage
instances, which likely enhances the flexibility and capabilities of page management within the framework. However, ensure that all references to these properties throughout the codebase have been updated accordingly.Verification successful
The examination of the context around
subPagesPath
indeclaration.ts
indicates that it is used to generate paths for subpages, derived fromctx.subPageMetaData
. This usage does not directly reference the newsubPages
property but seems to align with the intent of managing page paths within the framework. There's no evidence from the provided context that references to the old structure were not updated correctly. Therefore, based on the information available, it appears that the concern raised in the original review comment has been addressed as far as can be determined.* 83-83: The refactoring of the `scanPages` method to work with `Page` instances instead of paths is a key part of integrating the `definePage` macro. This change should streamline the page initialization process. However, it's important to ensure that the `Page` class's constructor and methods are designed to handle all necessary page-related functionalities efficiently.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that all references to `pages` and `subPages` are correctly updated. rg --type ts "pagesPath|subPagesPath"Length of output: 301
Script:
#!/bin/bash # Examine the context around the usage of `subPagesPath` in declaration.ts to understand its relation to the new `subPages` property. rg --type ts -C 5 "subPagesPath" packages/core/src/declaration.tsLength of output: 714
Verification successful
The Page class's constructor and methods, including
getOptions
,hasChanged
, andreadOptions
, are designed to efficiently and comprehensively handle page-related functionalities. The constructor initializes the context and file path, while the methods manage the reading, caching, and change detection of page options. This setup should support the integration of thedefinePage
macro effectively by streamlining the page initialization process.* 87-97: The `scanSubPages` method has been updated to also work with `Page` instances, similar to the `scanPages` method. This consistency in handling both pages and sub-pages using the same data structure is beneficial. Ensure that the logic for handling sub-pages is thoroughly tested, especially in scenarios involving nested sub-pages or complex directory structures. * 181-182: The `parsePages` method's update to work with `Page` instances and potentially custom page metadata is a critical part of the new page handling logic. It's important to ensure that this method accurately merges generated and custom page metadata, especially when overrides are provided. Consider adding tests to verify the correctness of the merged metadata under various scenarios. * 250-262: The `getPageByPath` method has been updated to retrieve `Page` instances by their absolute path. This method is crucial for efficiently finding pages, especially during the update process. Ensure that this method is optimized for performance, considering the potential size of the `pages` and `subPages` collections. * 266-267: The logic within `updatePagesJSON` to skip updates if a page has not changed is a good optimization. However, ensure that the `hasChanged` method of the `Page` class is robust and accurately detects changes to avoid unnecessary updates or missing necessary ones.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the efficiency and completeness of the Page class's constructor and methods. ast-grep --lang typescript --pattern $'class Page { $$$ constructor($_, $_) { $$$ } $$$ }'Length of output: 2632
Verification successful
The
hasChanged
method in thePage
class is designed to be robust, leveraging thereadOptions
method to accurately detect changes by comparing the serialized current options with a previously stored version. This approach, combined with exception handling in thereadOptions
method, ensures a reliable mechanism for detecting changes in page options. Therefore, the optimization to skip updates if a page has not changed, as implemented, appears to be well-founded.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the robustness of the Page class's hasChanged method. ast-grep --lang typescript --pattern $'class Page { $$$ hasChanged() { $$$ } $$$ }'Length of output: 2625
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/core/client.d.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/client.d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- README.md (1 hunks)
- packages/core/src/page.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/src/page.ts
Additional comments: 2
README.md (2)
- 57-73: The documentation for the
definePage
macro is clear and provides useful examples. However, it might be beneficial for readers if a brief explanation of the benefits or specific use cases of usingdefinePage
over traditional methods is included.- 75-75: The documentation for using SFC custom blocks for route data is comprehensive and informative. It might be helpful to include a note about any potential limitations or considerations when opting for this method to define routing data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/core/src/page.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/src/page.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/core/src/page.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/src/page.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (7)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (4)
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/playground/src/uni-pages.d.ts
Additional comments: 5
packages/core/src/context.ts (5)
- 21-21: The addition of the
Page
import aligns with the PR's objectives and supports the new page management approach.- 43-45: The introduction of
pages
andsubPages
as class properties is a significant and positive change, facilitating the new approach to page management using thePage
class.- 79-82: Refactoring the page initialization and scanning logic to work with
Page
instances instead ofPagePath
is a significant improvement, enhancing the module's functionality and maintainability.- 180-180: The method
parsePages
has been updated to work withPage
instances, which is a crucial change for integrating thedefinePage
macro. This update enhances the flexibility and accuracy of page parsing.- 249-261: The method
getPageByPath
has been updated to retrieve pages by path usingPage
instances. This change improves the accuracy and efficiency of page retrieval.
<script lang="ts" setup> | ||
definePage({ | ||
style:{ | ||
navigationBarTitleText: 'hello world' | ||
}, | ||
middlewares: [ | ||
'auth' | ||
] | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div>test</div> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of the definePage
macro in a Vue component using an object configuration looks good. Ensure that there is sufficient documentation and tests covering the definePage
macro to facilitate its adoption and ensure its reliability.
Would you like assistance in creating documentation or tests for the definePage
macro?
<script lang="ts" setup> | ||
definePage(()=>{ | ||
|
||
const hello = 'hello' | ||
|
||
const world = 'world' | ||
|
||
return { | ||
style:{ | ||
navigationBarTitleText: [hello, world].join(' ') | ||
}, | ||
middlewares: [ | ||
'auth' | ||
] | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div>test</div> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of the definePage
macro in a Vue component using a function configuration looks good. Ensure that there is sufficient documentation and tests covering the definePage
macro to facilitate its adoption and ensure its reliability.
Would you like assistance in creating documentation or tests for the definePage
macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/core/src/page.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/src/page.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (4)
- README.md (1 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (3)
- README.md
- packages/core/src/page.ts
- packages/playground/src/uni-pages.d.ts
definePage(async ()=>{ | ||
|
||
const randomTxt = await new Promise(resolve=> { | ||
const txt = Math.random().toString(36).slice(-8) | ||
resolve(txt) | ||
}); | ||
|
||
return { | ||
style:{ | ||
navigationBarTitleText: randomTxt | ||
}, | ||
middlewares: [ | ||
'auth' | ||
] | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of definePage
with an async function is a powerful feature, allowing for dynamic page configuration. However, consider the following points for improvement:
- Error Handling: The async function lacks error handling. Wrapping the promise in a try-catch block would ensure that any errors during the promise resolution are caught and handled appropriately.
- Code Clarity: While the current implementation is concise, adding a brief comment explaining the purpose of generating a random string for
navigationBarTitleText
could improve code readability and maintainability. - Middleware Documentation: If
middlewares
like 'auth' have specific requirements or behaviors, documenting them near their usage can help future developers understand their purpose and how to use them effectively.
definePage(async ()=>{
+ // Generate a random string to dynamically set the navigation bar title
+ try {
const randomTxt = await new Promise(resolve=> {
const txt = Math.random().toString(36).slice(-8)
resolve(txt)
});
+ } catch (error) {
+ console.error("Failed to generate random text for navigation bar title", error);
+ // Handle error appropriately
+ }
return {
style:{
navigationBarTitleText: randomTxt
},
+ // 'auth' middleware ensures that the user is authenticated before accessing this page
middlewares: [
'auth'
]
}
})
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.
definePage(async ()=>{ | |
const randomTxt = await new Promise(resolve=> { | |
const txt = Math.random().toString(36).slice(-8) | |
resolve(txt) | |
}); | |
return { | |
style:{ | |
navigationBarTitleText: randomTxt | |
}, | |
middlewares: [ | |
'auth' | |
] | |
} | |
}) | |
definePage(async ()=>{ | |
// Generate a random string to dynamically set the navigation bar title | |
try { | |
const randomTxt = await new Promise(resolve=> { | |
const txt = Math.random().toString(36).slice(-8) | |
resolve(txt) | |
}); | |
} catch (error) { | |
console.error("Failed to generate random text for navigation bar title", error); | |
// Handle error appropriately | |
} | |
return { | |
style:{ | |
navigationBarTitleText: randomTxt | |
}, | |
// 'auth' middleware ensures that the user is authenticated before accessing this page | |
middlewares: [ | |
'auth' | |
] | |
} | |
}) |
0aaac11
to
0d0b0b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
package.json
is excluded by:!**/*.json
packages/core/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (13)
- README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/i18n.vue (1 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (11)
- README.md
- packages/core/client.d.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/playground/src/pages/i18n.vue
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/uni-pages.d.ts
Additional comments: 5
packages/core/src/utils.ts (1)
- 2-2: The change to use type imports for
ModuleNode
andViteDevServer
is a good practice in TypeScript, as it clarifies that these imports are only used for type information. This can help with build optimization and clarity in the codebase.packages/core/src/context.ts (4)
- 21-21: The changes in import statements, including the removal of old page management imports and the addition of the
Page
import, reflect a significant shift towards a more object-oriented approach in managing pages. This aligns well with the introduction of thedefinePage
macro and should enhance modularity and maintainability.- 43-44: The modifications to the
PageContext
class, including the use ofPage
instances for managing pages and subpages, represent a significant improvement in the architecture. This approach allows for better encapsulation of page-related logic and data, enhancing the flexibility and maintainability of the codebase.- 180-180: The updates to methods for parsing and managing pages, including changes to work with
Page
instances, significantly improve the page management workflow. These changes enhance the clarity and efficiency of page parsing and retrieval, aligning well with the new object-oriented approach.- 82-82: The refactoring of page initialization and scanning logic to accommodate the new
Page
class represents a significant improvement in the codebase. This change simplifies the page management process, making the code cleaner, more maintainable, and easier to extend.
0d0b0b1
to
2ec3799
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
packages/core/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (12)
- README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (11)
- README.md
- packages/core/client.d.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/core/src/utils.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/uni-pages.d.ts
Additional comments: 7
packages/core/src/context.ts (7)
- 21-21: The import of the
Page
class is correctly added to support the newdefinePage
macro feature. Ensure that thePage
class is implemented as expected and integrates well with the existing codebase.- 43-44: The declarations of
pages
andsubPages
as class properties are appropriate for managing instances ofPage
. This change aligns with the objective of refactoring page initialization and scanning logic to work withPage
instances.- 82-82: The refactoring of the
scanPages
method to work withPage
instances instead ofPagePath
is a significant improvement. It simplifies the handling of pages by directly associating them with their respectivePage
objects. However, ensure that thegetPagePaths
function is correctly updated to support this change.- 86-96: The
scanSubPages
method has been correctly refactored to work withPage
instances, similar to thescanPages
method. This consistency in handling both pages and subpages asPage
instances is beneficial for maintainability and clarity.- 180-180: The
parsePages
method's refactoring to work withPage
instances and its integration with type enhancements (e.g.,PageMetaDatum
) is a positive change. It improves the clarity and type safety of the page parsing logic. Ensure that thePage
class'sgetOptions
method is implemented correctly and returns the expected data structure.- 249-261: The
getPageByPath
method has been updated to retrieve pages by their absolute path, considering both main pages and subpages. This method is crucial for the dynamic update of pages JSON. Ensure that thePage
class'sfile
property correctly stores theabsolutePath
and is accessible as shown.- 265-266: The logic within
updatePagesJSON
for checking if a page has changed before proceeding with the update is a good performance optimization. However, ensure that thePage
class'shasChanged
method is implemented correctly and efficiently determines if a page's content has changed.
2ec3799
to
9acad28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
packages/core/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (12)
- README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (11)
- README.md
- packages/core/client.d.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/core/src/utils.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/uni-pages.d.ts
Additional comments: 7
packages/core/src/context.ts (7)
- 21-21: The import of the
Page
class is correctly added to support the newdefinePage
functionality. Ensure that thePage
class is implemented as expected and integrates well with the existing codebase.- 43-44: The introduction of
pages
andsubPages
as class properties to store instances ofPage
is a significant change. This approach aligns with the objective of supporting thedefinePage
macro by enabling more structured management of page definitions.- 82-82: Refactoring the
scanPages
method to work withPage
instances instead ofPagePath
is a crucial change. It's important to ensure that thePage
constructor is called with the correct arguments and that thePage
instances are correctly managed within thePageContext
.- 96-96: Similarly, the
scanSubPages
method has been refactored to createPage
instances for subpages. This consistency in handling pages and subpages asPage
instances is beneficial for maintainability and future enhancements.- 180-180: The
parsePages
method has been updated to work withPage
instances. It's crucial to verify thatpage.getOptions()
correctly retrieves the options for each page and that the method correctly handles the merging of page metadata.- 249-261: The
getPageByPath
method has been updated to retrievePage
instances by their absolute path. This change is essential for maintaining the integrity of page management. Ensure that the comparison ofabsolutePath
is accurate and that the method correctly handles both main pages and subpages.- 265-266: The
updatePagesJSON
method now includes logic to check if a page has changed before proceeding with the update. This optimization can help reduce unnecessary updates. However, it's important to ensure that thehasChanged
method of thePage
class accurately detects changes.
218af7d
to
0d7e869
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
packages/core/package.json
is excluded by:!**/*.json
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (18)
- README.md (1 hunks)
- packages/core/README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/child-process.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/import-module.vue (1 hunks)
- packages/playground/src/pages/macros/import.vue (1 hunks)
- packages/playground/src/pages/macros/nested-function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/pages/macros/utils.ts (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (11)
- README.md
- packages/core/client.d.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/core/src/utils.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/uni-pages.d.ts
Additional comments: 5
packages/playground/src/pages/macros/import-module.vue (1)
- 1-15: The usage of
definePage
and the import ofversion
fromvite
are correctly implemented.packages/playground/src/pages/macros/nested-function.vue (1)
- 1-24: The usage of
definePage
with a nested functiongetTitle
is correctly implemented and serves as a good example of incorporating more complex logic withindefinePage
.packages/core/README.md (2)
- 47-69: The documentation for the
definePage
macro provides clear and accurate examples of how to define page options using both object and function arguments.- 44-74: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [71-100]
The documentation for adding route meta directly to routes using a custom
<route>
block in SFCs is clear and informative, covering the supported parsers and how to specify a parser.packages/core/src/context.ts (1)
- 76-99: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [21-261]
The refactoring in
context.ts
introduces a more object-oriented approach to handling pages and sub-pages, improving maintainability and modularity. The changes appear to be correctly implemented.Please verify the performance impact of these changes, especially in projects with a large number of pages.
import type { SpawnOptionsWithoutStdio } from 'node:child_process' | ||
import { spawn } from 'node:child_process' | ||
import process from 'node:process' | ||
|
||
export function runProcess(command: string, args: string[] = [], options?: SpawnOptionsWithoutStdio) { | ||
return new Promise<string>((resolve, reject) => { | ||
const child = spawn(command, args, { | ||
env: { | ||
...process.env, | ||
}, | ||
...options, | ||
}) | ||
const output = [] as string[] | ||
child.stdout.on('data', chunk => output.push(chunk)) | ||
child.on('close', () => resolve(output.join('').trim())) | ||
child.on('error', error => reject(error)) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The runProcess
function correctly spawns a child process and handles success cases. However, it currently does not handle stderr
output from the child process, which could lead to missed error messages. Consider adding a listener for stderr
similar to stdout
.
+ child.stderr.on('data', chunk => output.push(chunk))
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.
import type { SpawnOptionsWithoutStdio } from 'node:child_process' | |
import { spawn } from 'node:child_process' | |
import process from 'node:process' | |
export function runProcess(command: string, args: string[] = [], options?: SpawnOptionsWithoutStdio) { | |
return new Promise<string>((resolve, reject) => { | |
const child = spawn(command, args, { | |
env: { | |
...process.env, | |
}, | |
...options, | |
}) | |
const output = [] as string[] | |
child.stdout.on('data', chunk => output.push(chunk)) | |
child.on('close', () => resolve(output.join('').trim())) | |
child.on('error', error => reject(error)) | |
}) | |
} | |
import type { SpawnOptionsWithoutStdio } from 'node:child_process' | |
import { spawn } from 'node:child_process' | |
import process from 'node:process' | |
export function runProcess(command: string, args: string[] = [], options?: SpawnOptionsWithoutStdio) { | |
return new Promise<string>((resolve, reject) => { | |
const child = spawn(command, args, { | |
env: { | |
...process.env, | |
}, | |
...options, | |
}) | |
const output = [] as string[] | |
child.stdout.on('data', chunk => output.push(chunk)) | |
child.stderr.on('data', chunk => output.push(chunk)) | |
child.on('close', () => resolve(output.join('').trim())) | |
child.on('error', error => reject(error)) | |
}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/core/client.d.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/client.d.ts
f540677
to
109d430
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
packages/core/package.json
is excluded by:!**/*.json
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (17)
- README.md (1 hunks)
- packages/core/README.md (1 hunks)
- packages/core/src/child-process.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/import-module.vue (1 hunks)
- packages/playground/src/pages/macros/import.vue (1 hunks)
- packages/playground/src/pages/macros/nested-function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/pages/macros/utils.ts (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (15)
- README.md
- packages/core/README.md
- packages/core/src/child-process.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/import-module.vue
- packages/playground/src/pages/macros/import.vue
- packages/playground/src/pages/macros/nested-function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/pages/macros/utils.ts
- packages/playground/src/uni-pages.d.ts
Additional comments: 6
packages/core/src/utils.ts (2)
- 2-2: The import statement for
ModuleNode
andViteDevServer
has been updated to use type syntax, which is a good practice for TypeScript to ensure these imports are used for type information only and not included in the JavaScript output.- 60-75: The
parseSFC
function is a new addition that utilizes@vue/compiler-sfc
for parsing Vue Single File Components (SFCs). It's important to handle errors gracefully, and the catch block does this by throwing a new error with a helpful message. However, consider adding more specific error handling or logging for different types of errors that could occur during parsing.Consider enhancing error handling in the
parseSFC
function to provide more specific feedback for different error scenarios, which could aid in debugging.packages/core/src/context.ts (4)
- 21-21: The import of the
Page
class is a key addition, indicating a shift towards using this class for page management. This aligns with the PR's objective of enhancing page definition capabilities.- 43-45: The introduction of
pages
andsubPages
as class properties to store instances of thePage
class is a significant change. It's crucial to ensure that all methods interacting with these properties are updated accordingly.- 82-82: The
scanPages
method has been refactored to createPage
instances for each path. This is a crucial part of integrating thePage
class into the system. Ensure that thePage
constructor and its methods are thoroughly tested to handle various page definitions correctly.- 180-180: The
parsePages
method has been updated to work withPage
instances. This method is central to processing page definitions and generating metadata. It's important to verify that thegetOptions
method of thePage
class correctly handles different page configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
packages/core/package.json
is excluded by:!**/*.json
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (17)
- README.md (1 hunks)
- packages/core/README.md (1 hunks)
- packages/core/src/child-process.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (4 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/import-module.vue (1 hunks)
- packages/playground/src/pages/macros/import.vue (1 hunks)
- packages/playground/src/pages/macros/nested-function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/pages/macros/utils.ts (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (16)
- README.md
- packages/core/README.md
- packages/core/src/child-process.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/core/src/utils.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/import-module.vue
- packages/playground/src/pages/macros/import.vue
- packages/playground/src/pages/macros/nested-function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/pages/macros/utils.ts
- packages/playground/src/uni-pages.d.ts
Additional comments: 7
packages/core/src/context.ts (7)
- 21-21: The import of the
Page
class is correctly added to support the new functionality introduced by thedefinePage
macro. This aligns with the PR objectives.- 43-44: The declarations of
pages
andsubPages
as class properties are correctly refactored to use instances of thePage
class instead ofPagePath
. This change is necessary for the enhanced page handling logic.- 82-82: The refactoring of the
scanPages
method to initializePage
instances for each path is correctly implemented. This change is crucial for the new page handling logic that leverages thePage
class.- 92-92: Similarly, the
scanSubPages
method is correctly refactored to createPage
instances for subpages. This ensures consistency in handling both main pages and subpages.- 180-180: The
parsePages
method's refactoring to work withPage
instances instead ofPagePath
is correctly done. This method now correctly awaits the resolution ofpage.getOptions()
for each page, which is essential for asynchronous page option retrieval.- 249-261: The
getPageByPath
method is updated to retrievePage
instances by their absolute path. This update is necessary for the new page handling logic and correctly implemented.- 265-266: The
updatePagesJSON
method's logic to check if a page has changed before updating the pages JSON is correctly implemented. This optimization prevents unnecessary updates, aligning with best practices for performance.
22995a9
to
e532f7f
Compare
e532f7f
to
ee67edd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
packages/core/package.json
is excluded by:!**/*.json
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (19)
- README.md (1 hunks)
- packages/core/README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/child-process.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (2 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/import-module.vue (1 hunks)
- packages/playground/src/pages/macros/import.vue (1 hunks)
- packages/playground/src/pages/macros/nested-function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/pages/macros/remove-console.vue (1 hunks)
- packages/playground/src/pages/macros/utils.ts (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (17)
- README.md
- packages/core/README.md
- packages/core/client.d.ts
- packages/core/src/child-process.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/core/src/utils.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/import-module.vue
- packages/playground/src/pages/macros/import.vue
- packages/playground/src/pages/macros/nested-function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/pages/macros/utils.ts
- packages/playground/src/uni-pages.d.ts
Additional comments: 9
packages/playground/src/pages/macros/remove-console.vue (2)
- 3-3: The comment indicates that the console log statement should be removed. If this is for demonstration purposes related to the
definePage
macro's ability to handle or remove console logs, please ensure this is clearly documented to avoid confusion.- 12-14: The template block is straightforward and serves its purpose as a placeholder for page content.
packages/core/src/context.ts (7)
- 21-21: The addition of the
Page
import aligns with the PR's objectives to enhance the development experience by usingPage
instances for better handling of page functionalities.- 43-44: The declaration of
pages
andsubPages
as arrays ofPage
instances supports the new approach of handling pages as objects, facilitating more sophisticated operations on pages.- 79-82: The refactoring of the
scanPages
method to directly createPage
instances simplifies the process and aligns with the object-oriented approach of handling pages.- 86-96: The refactoring of the
scanSubPages
method to work withPage
instances instead of paths simplifies the handling of sub-pages and enhances the object-oriented design.- 180-180: The update to the
parsePages
method to work withPage
instances instead of paths is a necessary change that improves the flexibility and robustness of page handling.- 220-220: The
mergePageMetaData
method's update to work withPage
instances supports the new approach and enhances the process of merging page metadata.- 249-249: The
getPageByPath
method's update to retrievePage
instances by path aligns with the new approach of handling pages as objects, improving the overall design.
ee67edd
to
54d9c8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
packages/core/package.json
is excluded by:!**/*.json
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (19)
- README.md (1 hunks)
- packages/core/README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/child-process.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (7 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (3 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/import-module.vue (1 hunks)
- packages/playground/src/pages/macros/import.vue (1 hunks)
- packages/playground/src/pages/macros/nested-function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/pages/macros/remove-console.vue (1 hunks)
- packages/playground/src/pages/macros/utils.ts (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (17)
- README.md
- packages/core/README.md
- packages/core/client.d.ts
- packages/core/src/child-process.ts
- packages/core/src/constant.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/import-module.vue
- packages/playground/src/pages/macros/import.vue
- packages/playground/src/pages/macros/nested-function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/pages/macros/remove-console.vue
- packages/playground/src/pages/macros/utils.ts
- packages/playground/src/uni-pages.d.ts
Additional comments: 7
packages/core/src/utils.ts (2)
- 2-2: The change to use type imports for
ModuleNode
andViteDevServer
from 'vite' is a good practice for TypeScript, as it ensures these imports are used only for type checking and do not contribute to the runtime bundle size.- 61-76: The addition of the
parseSFC
function is a significant enhancement. It encapsulates the parsing logic for Single File Components (SFCs) using@vue/compiler-sfc
, with error handling that throws a more informative error if the parsing fails. This function improves maintainability by centralizing SFC parsing logic and error handling. However, consider adding more specific error handling or logging to provide clearer insights into parsing failures.Consider enhancing error handling within the
parseSFC
function to log specific parsing errors or to categorize errors based on their nature. This could help developers diagnose issues more effectively.packages/core/src/context.ts (5)
- 21-21: The import of the
Page
class aligns with the PR's objective to introduce a more structured approach to page management. This change suggests a shift towards object-oriented management of pages, which can enhance code readability and maintainability.- 43-45: The introduction of
pages
andsubPages
as class properties, with their types being arrays ofPage
instances or records ofPage
arrays, respectively, is a significant improvement. It indicates a move towards a more structured and scalable way of handling pages and subpages within the project. This change should facilitate easier manipulation and querying of page data throughout the application.- 82-82: The refactoring to initialize
Page
instances directly within thescanPages
method simplifies the process of page scanning and instantiation. This approach encapsulates the creation and initialization of pages within a single, cohesive operation, improving code clarity and maintainability.- 180-181: The
parsePages
method's asynchronous nature and its use ofPromise.all
to concurrently process page options is an efficient way to handle potentially time-consuming operations. This method demonstrates good use of asynchronous programming patterns to improve performance.- 249-261: The
getPageByPath
method provides a clear and concise way to retrieve a page by its absolute path, searching through both main pages and subpages. This utility method enhances code reusability and simplifies the logic for finding pages, contributing to better code organization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (2)
- packages/playground/src/pages/macros/yaml.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/playground/src/uni-pages.d.ts
Additional comments: 3
packages/playground/src/pages/macros/yaml.vue (3)
- 5-11: The usage of
definePage
here demonstrates its capability to support functions, aligning with the PR objectives. Ensure thatdefinePage
operates in a separate scope from the page script as intended.- 3-3: The import of
yamlParser
is correctly implemented. Given the PR's enhancements onimport
support, ensure that this import does not introduce any unintended side effects or scope issues within thedefinePage
macro.- 18-20: The template is simple and effective for demonstrating the component's functionality in the playground. Good to go!
cb7ec63
to
db9b6b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
packages/core/package.json
is excluded by:!**/*.json
packages/playground/package.json
is excluded by:!**/*.json
pnpm-lock.yaml
is excluded by:!**/*.yaml
Files selected for processing (20)
- README.md (1 hunks)
- packages/core/README.md (1 hunks)
- packages/core/client.d.ts (1 hunks)
- packages/core/src/child-process.ts (1 hunks)
- packages/core/src/constant.ts (1 hunks)
- packages/core/src/context.ts (9 hunks)
- packages/core/src/index.ts (3 hunks)
- packages/core/src/page.ts (1 hunks)
- packages/core/src/types.ts (3 hunks)
- packages/core/src/utils.ts (3 hunks)
- packages/playground/src/pages/macros/async-function.vue (1 hunks)
- packages/playground/src/pages/macros/function.vue (1 hunks)
- packages/playground/src/pages/macros/import-module.vue (1 hunks)
- packages/playground/src/pages/macros/import.vue (1 hunks)
- packages/playground/src/pages/macros/nested-function.vue (1 hunks)
- packages/playground/src/pages/macros/object.vue (1 hunks)
- packages/playground/src/pages/macros/remove-console.vue (1 hunks)
- packages/playground/src/pages/macros/utils.ts (1 hunks)
- packages/playground/src/pages/macros/yaml.vue (1 hunks)
- packages/playground/src/uni-pages.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (19)
- README.md
- packages/core/README.md
- packages/core/client.d.ts
- packages/core/src/child-process.ts
- packages/core/src/constant.ts
- packages/core/src/context.ts
- packages/core/src/index.ts
- packages/core/src/page.ts
- packages/core/src/types.ts
- packages/playground/src/pages/macros/async-function.vue
- packages/playground/src/pages/macros/function.vue
- packages/playground/src/pages/macros/import-module.vue
- packages/playground/src/pages/macros/import.vue
- packages/playground/src/pages/macros/nested-function.vue
- packages/playground/src/pages/macros/object.vue
- packages/playground/src/pages/macros/remove-console.vue
- packages/playground/src/pages/macros/utils.ts
- packages/playground/src/pages/macros/yaml.vue
- packages/playground/src/uni-pages.d.ts
Additional comments: 1
packages/core/src/utils.ts (1)
- 2-2: The change to use type imports for
ModuleNode
andViteDevServer
from 'vite' is a good practice for TypeScript, as it clarifies that these imports are only used for type information and can be stripped away during compilation.
export async function parseSFC(code: string, options?: SFCParseOptions): Promise<SFCDescriptor> { | ||
try { | ||
return ( | ||
VueParser(code, { | ||
pad: 'space', | ||
...options, | ||
}).descriptor | ||
// for @vue/compiler-sfc ^2.7 | ||
|| (VueParser as any)({ | ||
source: code, | ||
...options, | ||
}) | ||
) | ||
} | ||
|
||
async function hasChanged(filePath: string, routeBlock?: SFCBlock) { | ||
if (!routeBlock) | ||
routeBlock = await getRouteSfcBlock(normalizePath(filePath)) | ||
|
||
return !pages.has(filePath) || JSON.stringify(parseData(routeBlock)) !== pages.get(filePath) | ||
} | ||
|
||
return { | ||
setCache, | ||
hasChanged, | ||
catch (error) { | ||
throw new Error(`[vite-plugin-uni-pages] Vue3's "@vue/compiler-sfc" is required. \nOriginal error: \n${error}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parseSFC
function is a valuable addition for handling SFC parsing with proper error handling. However, when re-throwing the error, consider preserving the original error stack for easier debugging.
- throw new Error(`[vite-plugin-uni-pages] Vue3's "@vue/compiler-sfc" is required. \nOriginal error: \n${error}`)
+ const newError = new Error(`[vite-plugin-uni-pages] Vue3's "@vue/compiler-sfc" is required. \nOriginal error: \n${error}`);
+ newError.stack = error.stack;
+ throw newError;
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.
export async function parseSFC(code: string, options?: SFCParseOptions): Promise<SFCDescriptor> { | |
try { | |
return ( | |
VueParser(code, { | |
pad: 'space', | |
...options, | |
}).descriptor | |
// for @vue/compiler-sfc ^2.7 | |
|| (VueParser as any)({ | |
source: code, | |
...options, | |
}) | |
) | |
} | |
async function hasChanged(filePath: string, routeBlock?: SFCBlock) { | |
if (!routeBlock) | |
routeBlock = await getRouteSfcBlock(normalizePath(filePath)) | |
return !pages.has(filePath) || JSON.stringify(parseData(routeBlock)) !== pages.get(filePath) | |
} | |
return { | |
setCache, | |
hasChanged, | |
catch (error) { | |
throw new Error(`[vite-plugin-uni-pages] Vue3's "@vue/compiler-sfc" is required. \nOriginal error: \n${error}`) | |
export async function parseSFC(code: string, options?: SFCParseOptions): Promise<SFCDescriptor> { | |
try { | |
return ( | |
VueParser(code, { | |
pad: 'space', | |
...options, | |
}).descriptor | |
// for @vue/compiler-sfc ^2.7 | |
|| (VueParser as any)({ | |
source: code, | |
...options, | |
}) | |
) | |
} | |
catch (error) { | |
const newError = new Error(`[vite-plugin-uni-pages] Vue3's "@vue/compiler-sfc" is required. \nOriginal error: \n${error}`); | |
newError.stack = error.stack; | |
throw newError; |
Sorry,最近大家可能都比较忙,可能没有时间看,如果非必要请不要 @,感谢。 如果比较着急,可以看自己发个包用一下。 我看你的文件改动比较大,如果不冲突最好把重构和新功能分开 pr。 |
我最近没有用uniapp的需求。如果有其他人需要这个功能再考虑另发包。
改动的细分很难界定,曾经试过在其他库提几个文件的修改,因为代码样式、实现方式等,来来回回改近十个commit,拖了十多天才通过第一个PR,后续PR都一直等第一个PR合并才能继续。。。 另,正如我之前所说,我写这个PR,仅仅是为爱发电,如果你觉得改动太多,不好梳理,或者你们按照需求去拆分commit?对于commit的owner是否我,都没问题。 此 PR 暂关闭,分支在此仓库下,你们自行决定怎么处理吧? |
个人感觉definePage比其他几种方式更优雅 希望早日能实现合并 |
支持
definePage
宏 related #134playground
下的示例import
使用注意:
import
仅支持从js
或ts
导入,不支持从vue
文件里导入import
导入暂不支持别名路径definePage
和页面script不在同一个作用域,无法使用页面变量。实现原理:
使用
@vue/compiler-sfc
和@babel/types
获取宏代码节点vite-plugin-uni-pages/packages/core/src/page.ts
Lines 86 to 88 in 218af7d
使用
@babel/generator
还原为 JS codevite-plugin-uni-pages/packages/core/src/page.ts
Lines 99 to 101 in 218af7d
创建子进程,并调用
tsx
运行生成的 script,得到结果。vite-plugin-uni-pages/packages/core/src/page.ts
Lines 201 to 212 in 0d7e869
Summary by CodeRabbit
New Features
definePage
function for more flexible page definitions.Refactor
Page
instances, improving the handling of page options.Bug Fixes
Chores
child-process.ts
file for running child processes, facilitating external command execution.Documentation