Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')!;
Expand Down Expand Up @@ -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'
&& !(`../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 };
}

Expand Down