Skip to content

Commit cbd9036

Browse files
committed
Merge branch 'fix-pgp-loader' into github-actions
2 parents 206cb78 + 308e7c1 commit cbd9036

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

pgp-loader/loader.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,25 @@ export function resolve(specifier, context, defaultResolve) {
2424
return defaultResolve(specifier, context, defaultResolve);
2525
}
2626

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) {
2928
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" })
3830

39-
export function transformSource(source, context, defaultTransformSource) {
40-
if (context.url.endsWith('.pgp')) {
4131
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({
4737
message: cryptMsg,
4838
privateKeys: privateKeys
49-
}))
50-
.then(decripted => ({source: decripted.data}) )
39+
}))
40+
.then(decripted => ({
41+
format: "module",
42+
source: decripted.data
43+
}))
5144
}
5245

5346
// Let Node.js handle all other URLs.
54-
return defaultTransformSource(source, context, defaultTransformSource);
47+
return defaultLoad(url, context, defaultLoad);
5548
}

0 commit comments

Comments
 (0)