-
Notifications
You must be signed in to change notification settings - Fork 221
Add verification pass for unresolved React components #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,14 @@ import { | |
| shouldWarnForDefaultSupabaseConfig, | ||
| } from '../utils/defaultStorageConfig'; | ||
|
|
||
| const modules = import.meta.glob( | ||
| [ | ||
| '../public/**/*.{mjs,js,mts,ts,jsx,tsx}', | ||
| '!../public/**/*.spec.{mjs,js,mts,ts,jsx,tsx}', | ||
| ], | ||
| { eager: false }, // the parser only checks if the path exists | ||
| ); | ||
|
|
||
| const ajv1 = new Ajv({ allowUnionTypes: true }); | ||
| ajv1.addSchema(globalSchema); | ||
| const globalValidate = ajv1.getSchema<GlobalConfig>('#/definitions/GlobalConfig')!; | ||
|
|
@@ -311,6 +319,29 @@ function verifyStudyConfig(studyConfig: StudyConfig, importedLibrariesData: Reco | |
| }); | ||
| }); | ||
|
|
||
| // Verify that paths to React components exist under the correct base directory | ||
| if (studyConfig.baseComponents != null) { | ||
| for (const key of ['baseComponents', 'components'] as const) { | ||
| for (const [name, component] of Object.entries(studyConfig[key] ?? {})) { | ||
| if ( | ||
| 'path' in component | ||
| && component.path != null | ||
| && component.type === 'react-component' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks the raw component rather than its resolved inherited shape. A child can inherit |
||
| && !(`../public/${component.path}` in modules) | ||
| ) { | ||
| errors.push({ | ||
| message: 'Unresolved path', | ||
| instancePath: `/${key}/${name}/path`, | ||
| params: { | ||
| action: 'Make sure the React component is in `src/public/`, not `public/`', | ||
| }, | ||
| category: 'undefined-component', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { errors, warnings }; | ||
| } | ||
|
|
||
|
|
||
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.
baseComponentsis optional, so this guard skips validation of the requiredcomponentsobject whenever a study does not define any base components. A direct React component with a missing path therefore receives no error. Please remove the outer guard and always iterate both collections usingstudyConfig[key] ?? {}.