File tree 2 files changed +22
-4
lines changed
packages/sandpack-core/src/resolver/utils
2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ export function normalizePackageExport(
25
25
26
26
export function extractPathFromExport (
27
27
exportValue : PackageExportType ,
28
- pkgRoot : string
28
+ pkgRoot : string ,
29
+ checkedExportKeys : string [ ] = EXPORTS_KEYS
29
30
) : string | false {
30
31
if ( ! exportValue ) {
31
32
return false ;
@@ -46,13 +47,17 @@ export function extractPathFromExport(
46
47
}
47
48
48
49
if ( typeof exportValue === 'object' ) {
49
- for ( const key of EXPORTS_KEYS ) {
50
+ for ( const key of checkedExportKeys ) {
50
51
const exportFilename = exportValue [ key ] ;
51
52
if ( exportFilename !== undefined ) {
52
53
if ( typeof exportFilename === 'string' ) {
53
54
return normalizePackageExport ( exportFilename , pkgRoot ) ;
54
55
}
55
- return extractPathFromExport ( exportFilename , pkgRoot ) ;
56
+ return extractPathFromExport (
57
+ exportFilename ,
58
+ pkgRoot ,
59
+ checkedExportKeys
60
+ ) ;
56
61
}
57
62
}
58
63
return false ;
Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ const PKG_ALIAS_FIELDS = ['browser', 'alias'];
8
8
9
9
type AliasesDict = { [ key : string ] : string } ;
10
10
11
+ const COMMONJS_EXPORT_KEYS = [ 'browser' , 'development' , 'default' , 'require' ] ;
12
+ function forceCommonJs ( name : string , version : string ) : boolean {
13
+ return name === 'chevrotain' && version . startsWith ( '10.' ) ;
14
+ }
15
+
11
16
export interface ProcessedPackageJSON {
12
17
aliases : AliasesDict ;
13
18
hasExports : boolean ;
@@ -43,7 +48,15 @@ export function processPackageJSON(
43
48
} else if ( typeof content . exports === 'object' ) {
44
49
const exportKeys = Object . keys ( content . exports ) ;
45
50
if ( ! exportKeys [ 0 ] . startsWith ( '.' ) ) {
46
- const resolvedExport = extractPathFromExport ( content . exports , pkgRoot ) ;
51
+ const checkedExportKeys = forceCommonJs ( content . name , content . version )
52
+ ? COMMONJS_EXPORT_KEYS
53
+ : undefined ;
54
+
55
+ const resolvedExport = extractPathFromExport (
56
+ content . exports ,
57
+ pkgRoot ,
58
+ checkedExportKeys
59
+ ) ;
47
60
if ( ! resolvedExport ) {
48
61
throw new Error ( `Could not find a valid export for ${ pkgRoot } ` ) ;
49
62
}
You can’t perform that action at this time.
0 commit comments