@@ -17,70 +17,100 @@ const imports: Record<string, any> = {};
1717imports [ "#src/third_party/jpgjs/jpg.js" ] = "./src/third_party/jpgjs/jpg.js" ;
1818imports [ "#src/*.js" ] = "./src/*.ts" ;
1919imports [ "#src/*" ] = "./src/*" ;
20+ imports [ "#tests/fixtures/msw" ] = {
21+ node : "./tests/fixtures/msw_node.ts" ,
22+ default : "./tests/fixtures/msw_browser.ts" ,
23+ } ;
24+ imports [ "#tests/fixtures/gl" ] = {
25+ node : "./tests/fixtures/gl_node.ts" ,
26+ default : "./tests/fixtures/gl_browser.ts" ,
27+ } ;
28+ imports [ "#tests/*.js" ] = "./tests/*.ts" ;
2029imports [ "#testdata/*" ] = "./testdata/*" ;
2130
22- const datasourceDir = path . resolve ( rootDir , "src" , "datasource" ) ;
23- const layerDir = path . resolve ( rootDir , "src" , "layer" ) ;
24-
25- const datasources = (
26- await fs . promises . readdir ( datasourceDir , { withFileTypes : true } )
27- )
28- . filter ( ( e ) => e . isDirectory ( ) )
29- . map ( ( e ) => e . name ) ;
30-
31- const layers = ( await fs . promises . readdir ( layerDir , { withFileTypes : true } ) )
32- . filter ( ( e ) => e . isDirectory ( ) )
33- . map ( ( e ) => e . name ) ;
34-
35- const datasourceKeys = {
36- backend : "backend" ,
37- async_computation : "async_computation" ,
38- register_default : "frontend" ,
39- register_credentials_provider : "frontend" ,
40- } as const ;
31+ async function listSubdirs ( dir : string ) : Promise < string [ ] > {
32+ return ( await fs . promises . readdir ( dir , { withFileTypes : true } ) )
33+ . filter ( ( e ) => e . isDirectory ( ) )
34+ . map ( ( e ) => e . name ) ;
35+ }
4136
42- const datasourceModules = Object . fromEntries (
43- Object . values ( datasourceKeys ) . map ( ( key ) => [ key , new Array < string > ( ) ] ) ,
44- ) ;
37+ async function writeModule ( modulePath : string , imports : string [ ] ) {
38+ await fs . promises . writeFile (
39+ modulePath ,
40+ "// DO NOT EDIT: Generated by config/update_conditions.ts\n" +
41+ imports . map ( ( name ) => `import ${ JSON . stringify ( name ) } ;\n` ) . join ( "" ) ,
42+ { encoding : "utf-8" } ,
43+ ) ;
44+ }
4545
46- for ( const datasource of datasources ) {
47- for ( const [ filePrefix , moduleKind ] of Object . entries ( datasourceKeys ) ) {
48- const sourcePrefix = `./src/datasource/${ datasource } /${ filePrefix } ` ;
49- if (
50- await fs . promises
51- . stat ( path . resolve ( rootDir , `${ sourcePrefix } .ts` ) )
52- . catch ( ( ) => undefined )
53- ) {
54- const source = sourcePrefix + JS_EXT ;
55- const conditions : Record < string , string > = { } ;
56- if ( datasource === "python" ) {
57- conditions [ "neuroglancer/python" ] = source ;
58- conditions . default = NOOP ;
59- } else {
60- if ( filePrefix === "register_credentials_provider" ) {
61- conditions [ "neuroglancer/python" ] = NOOP ;
46+ async function handleDrivers (
47+ kind : string ,
48+ moduleMap : Record < string , string [ ] > ,
49+ ) {
50+ const driverDir = path . resolve ( rootDir , "src" , kind ) ;
51+ const drivers = await listSubdirs ( driverDir ) ;
52+ const modules : Record < string , string [ ] > = { } ;
53+ for ( const driver of drivers ) {
54+ for ( const [ filePrefix , moduleKinds ] of Object . entries ( moduleMap ) ) {
55+ const sourcePrefix = `./src/${ kind } /${ driver } /${ filePrefix } ` ;
56+ if (
57+ await fs . promises
58+ . stat ( path . resolve ( rootDir , `${ sourcePrefix } .ts` ) )
59+ . catch ( ( ) => undefined )
60+ ) {
61+ const source = sourcePrefix + JS_EXT ;
62+ const conditions : Record < string , string > = { } ;
63+ if ( driver === "python" ) {
64+ conditions [ "neuroglancer/python" ] = source ;
65+ conditions . default = NOOP ;
66+ } else {
67+ if ( filePrefix === "register_credentials_provider" ) {
68+ conditions [ "neuroglancer/python" ] = NOOP ;
69+ }
70+ conditions [ `neuroglancer/${ kind } /${ driver } :enabled` ] = source ;
71+ conditions [ `neuroglancer/${ kind } :none_by_default` ] = NOOP ;
72+ conditions [ `neuroglancer/${ kind } /${ driver } :disabled` ] = NOOP ;
73+ conditions . default = source ;
74+ }
75+ let moduleId = `#${ kind } /${ driver } ` ;
76+ if ( filePrefix !== "index" ) {
77+ moduleId += `/${ filePrefix } ` ;
78+ }
79+ imports [ moduleId ] = conditions ;
80+ for ( const moduleKind of moduleKinds ) {
81+ if ( modules [ moduleKind ] === undefined ) {
82+ modules [ moduleKind ] = [ ] ;
83+ }
84+ modules [ moduleKind ] . push ( moduleId ) ;
6285 }
63- conditions [ `neuroglancer/datasource/${ datasource } :enabled` ] = source ;
64- conditions [ "neuroglancer/datasource:none_by_default" ] = NOOP ;
65- conditions [ `neuroglancer/datasource/${ datasource } :disabled` ] = source ;
66- conditions . default = source ;
6786 }
68- const moduleId = `#datasource/${ datasource } /${ filePrefix } ` ;
69- imports [ moduleId ] = conditions ;
70- datasourceModules [ moduleKind ] . push ( moduleId ) ;
7187 }
7288 }
89+ for ( const [ moduleKind , moduleIds ] of Object . entries ( modules ) ) {
90+ await writeModule (
91+ path . resolve ( driverDir , `enabled_${ moduleKind } _modules.ts` ) ,
92+ moduleIds ,
93+ ) ;
94+ }
7395}
7496
75- for ( const layer of layers ) {
76- const source = `./src/layer/${ layer } /index` + JS_EXT ;
77- imports [ `#layer/${ layer } ` ] = {
78- [ `neuroglancer/layer/${ layer } :enabled` ] : source ,
79- "neuroglancer/layer:none_by_default" : NOOP ,
80- [ `neuroglancer/layer/${ layer } :enabled` ] : source ,
81- default : source ,
82- } ;
83- }
97+ await handleDrivers ( "datasource" , {
98+ backend : [ "backend" ] ,
99+ async_computation : [ "async_computation" ] ,
100+ register_default : [ "frontend" ] ,
101+ register_credentials_provider : [ "frontend" ] ,
102+ } ) ;
103+
104+ await handleDrivers ( "kvstore" , {
105+ register : [ "frontend" , "backend" ] ,
106+ register_frontend : [ "frontend" ] ,
107+ register_backend : [ "backend" ] ,
108+ register_credentials_provider : [ "frontend" ] ,
109+ } ) ;
110+
111+ await handleDrivers ( "layer" , {
112+ index : [ "frontend" ] ,
113+ } ) ;
84114
85115// main entrypoint.
86116imports [ "#main" ] = {
@@ -94,32 +124,6 @@ imports["#python_integration_build"] = {
94124 default : NOOP ,
95125} ;
96126
97- async function writeModule ( modulePath : string , imports : string [ ] ) {
98- await fs . promises . writeFile (
99- modulePath ,
100- "// DO NOT EDIT: Generated by config/update_conditions.ts\n" +
101- imports . map ( ( name ) => `import ${ JSON . stringify ( name ) } ;\n` ) . join ( "" ) ,
102- { encoding : "utf-8" } ,
103- ) ;
104- }
105-
106- for ( const [ moduleKind , moduleIds ] of Object . entries ( datasourceModules ) ) {
107- await writeModule (
108- path . resolve (
109- rootDir ,
110- "src" ,
111- "datasource" ,
112- `enabled_${ moduleKind } _modules.ts` ,
113- ) ,
114- moduleIds ,
115- ) ;
116- }
117-
118- await writeModule (
119- path . resolve ( rootDir , "src" , "layer" , "enabled_frontend_modules.ts" ) ,
120- layers . map ( ( name ) => `#layer/${ name } ` ) ,
121- ) ;
122-
123127packageJson . imports = imports ;
124128
125129packageJson . exports = {
0 commit comments