@@ -11,8 +11,10 @@ import type { SourceFileManager } from './typescript/SourceFileManager.js';
11
11
import { createHosts } from './typescript/create-hosts.js' ;
12
12
import { _getImportsAndExports } from './typescript/get-imports-and-exports.js' ;
13
13
import type { ResolveModuleNames } from './typescript/resolve-module-names.js' ;
14
+ import { isJSON } from './typescript/visitors/helpers.js' ;
14
15
import { timerify } from './util/Performance.js' ;
15
16
import { compact } from './util/array.js' ;
17
+ import { createExport , createFileNode } from './util/dependency-graph.js' ;
16
18
import { getPackageNameFromModuleSpecifier , isStartsLikePackageName , sanitizeSpecifier } from './util/modules.js' ;
17
19
import { dirname , extname , isInNodeModules , join } from './util/path.js' ;
18
20
import type { ToSourceFilePath } from './util/to-source-path.js' ;
@@ -244,6 +246,14 @@ export class ProjectPrincipal {
244
246
245
247
const skipExports = this . skipExportsAnalysis . has ( filePath ) ;
246
248
249
+ if ( isJSON ( sourceFile ) ) {
250
+ // Exception to allow .json files to be imported + compiled conditionally
251
+ const fileNode = createFileNode ( ) ;
252
+ if ( / ^ \s * [ [ { ] / . test ( sourceFile . text ) ) return fileNode ;
253
+ fileNode . exports . set ( 'default' , createExport ( { identifier : 'default' } ) ) ;
254
+ return fileNode ;
255
+ }
256
+
247
257
const resolve = ( specifier : string ) => this . backend . resolveModuleNames ( [ specifier ] , sourceFile . fileName ) [ 0 ] ;
248
258
249
259
const { imports, ...rest } = _getImportsAndExports ( sourceFile , resolve , typeChecker , { ...options , skipExports } ) ;
0 commit comments