@@ -15,38 +15,14 @@ const indent = x => new Array(x).fill(' ').join('')
15
15
16
16
export default class ImportMap extends Logged {
17
17
18
- static async fromPNPM ( {
19
- cwd = process . cwd ( ) ,
20
- imports = { } ,
21
- scopes = { } ,
22
- pkg = JSON . parse ( runLong ( cwd , 'pnpm' , 'ls' , '--json' , '--depth' , 'Infinity' ) ) [ 0 ] ,
23
- write = false ,
24
- patchMain = ( _ , __ ) => { } ,
25
- patchExports = ( _ , __ ) => { } ,
26
- patchImports = ( _ , __ ) => { } ,
27
- } = { } ) {
28
- const map = new ImportMap ( {
29
- path : resolve ( cwd , 'importmap.json' ) ,
30
- imports,
31
- scopes,
32
- patchMain,
33
- patchExports,
34
- patchImports,
35
- } )
36
- await map . add ( 0 , pkg . name , pkg . version , pkg . dependencies )
37
- if ( write ) {
38
- writeFileSync ( map . path , map . stringified )
39
- }
40
- return map
41
- }
42
-
43
18
constructor ( {
44
19
path = 'importmap.json' ,
45
20
scopes = { } ,
46
21
imports = { } ,
47
22
patchMain = ( _ , __ ) => { } ,
48
23
patchExports = ( _ , __ ) => { } ,
49
24
patchImports = ( _ , __ ) => { } ,
25
+ exportOrder = [ 'browser' , 'import' , 'default' ]
50
26
} = { } ) {
51
27
super ( )
52
28
this . path = path
@@ -55,6 +31,7 @@ export default class ImportMap extends Logged {
55
31
this . patchMain = patchMain
56
32
this . patchExports = patchExports
57
33
this . patchImports = patchImports
34
+ this . exportOrder = exportOrder
58
35
}
59
36
60
37
get stringified ( ) {
@@ -79,6 +56,7 @@ export default class ImportMap extends Logged {
79
56
await this . add ( depth + 2 , name , version , dependencies ?? { } , selfRefs ?? { } )
80
57
}
81
58
}
59
+ return this
82
60
}
83
61
84
62
// Rule 01: Add main entrypoint of package.
@@ -163,3 +141,23 @@ export default class ImportMap extends Logged {
163
141
}
164
142
165
143
}
144
+
145
+ export class PNPMImportMap extends ImportMap {
146
+
147
+ constructor ( {
148
+ write = false ,
149
+ root = process . cwd ( ) ,
150
+ pkg = JSON . parse ( runLong ( root , 'pnpm' , 'ls' , '--json' , '--depth' , 'Infinity' ) ) [ 0 ] ,
151
+ ...options
152
+ } = { } ) {
153
+ super ( { path : resolve ( root , 'importmap.json' ) , ...options } )
154
+ this . ready = this . add ( 0 , pkg . name , pkg . version , pkg . dependencies )
155
+ this . ready . then ( ( ) => {
156
+ if ( write ) {
157
+ this . log ( 'Writing to' , bold ( this . path ) )
158
+ writeFileSync ( this . path , this . stringified )
159
+ }
160
+ } )
161
+ }
162
+
163
+ }
0 commit comments