1
1
import propTypes from "prop-types" ;
2
2
import { WeakValidationMap , useEffect , useMemo } from "react" ;
3
-
4
- import {
5
- PyConfigInterpreters ,
6
- PyConfigSplashscreen ,
7
- } from "~root/source/library/components/py-config/py-config.types" ;
8
-
9
3
import type {
10
4
PyConfigFetch ,
5
+ PyConfigFetchItem ,
6
+ PyConfigInterpreters ,
11
7
PyConfigProperties ,
12
8
PyConfigPropertiesBase ,
9
+ PyConfigSplashscreen ,
13
10
PyConfigTag ,
14
11
} from "./py-config.types" ;
15
12
@@ -54,10 +51,6 @@ const PyConfig: PyConfigTag = <T extends object>({
54
51
// eslint-disable-next-line sonarjs/cognitive-complexity
55
52
const config : string = useMemo ( ( ) : string => {
56
53
if ( type === "json" ) {
57
- const transformedFiles : string [ ] = [
58
- ...( fetch ?. files || [ ] ) ,
59
- ...( children ?. fetch ?. files || [ ] ) ,
60
- ] ;
61
54
const transformedPlugins : string [ ] = [
62
55
...( plugins || [ ] ) ,
63
56
...( children ?. plugins || [ ] ) ,
@@ -66,10 +59,16 @@ const PyConfig: PyConfigTag = <T extends object>({
66
59
...( packages || [ ] ) ,
67
60
...( children ?. packages || [ ] ) ,
68
61
] ;
69
- const transformedFetch : PyConfigFetch = {
70
- files : transformedFiles . length ? transformedFiles : undefined ,
71
- ...children ?. fetch ,
72
- } ;
62
+ const transformedFetch : PyConfigFetch = [
63
+ ...( fetch || [ ] ) ,
64
+ ...( children ?. fetch || [ ] ) ,
65
+ ] . map ( ( { files, ...restItem } : PyConfigFetchItem ) : PyConfigFetchItem => {
66
+ const transformedFiles : string [ ] = [ ...( files || [ ] ) ] ;
67
+ return {
68
+ files : transformedFiles . length ? transformedFiles : undefined ,
69
+ ...restItem ,
70
+ } ;
71
+ } ) ;
73
72
const transformedInterpreters : Omit < PyConfigInterpreters , "source" > & {
74
73
src ?: string ;
75
74
} = {
@@ -89,7 +88,7 @@ const PyConfig: PyConfigTag = <T extends object>({
89
88
interpreters : checkForAnyKey ( transformedInterpreters )
90
89
? transformedInterpreters
91
90
: undefined ,
92
- fetch : checkForAnyKey ( transformedFetch ) ? transformedFetch : undefined ,
91
+ fetch : transformedFetch . length ? transformedFetch : undefined ,
93
92
packages : transformedPackages . length ? transformedPackages : undefined ,
94
93
plugins : transformedPlugins . length ? transformedPlugins : undefined ,
95
94
...children ,
@@ -127,10 +126,18 @@ PyConfig.propTypes = {
127
126
name : propTypes . string ,
128
127
language : propTypes . string ,
129
128
} ) ,
130
- fetch : propTypes . shape ( {
131
- files : propTypes . arrayOf ( propTypes . string ) ,
132
- } ) ,
133
- packages : propTypes . arrayOf ( propTypes . string ) ,
129
+ fetch : propTypes . arrayOf (
130
+ propTypes . shape ( {
131
+ files : propTypes . oneOfType ( [
132
+ propTypes . arrayOf ( propTypes . string ) ,
133
+ propTypes . instanceOf ( Set ) ,
134
+ ] ) ,
135
+ } ) ,
136
+ ) ,
137
+ packages : propTypes . oneOfType ( [
138
+ propTypes . arrayOf ( propTypes . string ) ,
139
+ propTypes . instanceOf ( Set ) ,
140
+ ] ) ,
134
141
plugins : propTypes . arrayOf ( propTypes . string ) ,
135
142
} as WeakValidationMap < PyConfigPropertiesBase > ;
136
143
0 commit comments