@@ -24,32 +24,25 @@ export function resolve(specifier, context, defaultResolve) {
24
24
return defaultResolve ( specifier , context , defaultResolve ) ;
25
25
}
26
26
27
- export function getFormat ( url , context , defaultGetFormat ) {
28
- // This loader assumes all PGP files are JavaScript ES modules.
27
+ export async function load ( url , context , defaultLoad ) {
29
28
if ( url . endsWith ( '.pgp' ) ) {
30
- return {
31
- format : 'module'
32
- } ;
33
- }
34
-
35
- // Let Node.js handle all other URLs.
36
- return defaultGetFormat ( url , context , defaultGetFormat ) ;
37
- }
29
+ const { source } = await defaultLoad ( url , { format : "module" } )
38
30
39
- export function transformSource ( source , context , defaultTransformSource ) {
40
- if ( context . url . endsWith ( '.pgp' ) ) {
41
31
return fs . readFile ( 'private-key.asc' , 'utf8' )
42
- . then ( privKey => pgp . key . readArmored ( privKey ) )
43
- . then ( priv => privateKeys = priv . keys )
44
- . then ( ( ) => privateKeys [ 0 ] . decrypt ( passwd ) )
45
- . then ( ( ) => pgp . message . readArmored ( source ) )
46
- . then ( cryptMsg => pgp . decrypt ( {
32
+ . then ( privKey => pgp . key . readArmored ( privKey ) )
33
+ . then ( priv => privateKeys = priv . keys )
34
+ . then ( ( ) => privateKeys [ 0 ] . decrypt ( passwd ) )
35
+ . then ( ( ) => pgp . message . readArmored ( source ) )
36
+ . then ( cryptMsg => pgp . decrypt ( {
47
37
message : cryptMsg ,
48
38
privateKeys : privateKeys
49
- } ) )
50
- . then ( decripted => ( { source : decripted . data } ) )
39
+ } ) )
40
+ . then ( decripted => ( {
41
+ format : "module" ,
42
+ source : decripted . data
43
+ } ) )
51
44
}
52
45
53
46
// Let Node.js handle all other URLs.
54
- return defaultTransformSource ( source , context , defaultTransformSource ) ;
47
+ return defaultLoad ( url , context , defaultLoad ) ;
55
48
}
0 commit comments