Skip to content

Commit

Permalink
Work around rollup ts plugin ES issue
Browse files Browse the repository at this point in the history
This prevents the bahaviour documented in
ezolenko/rollup-plugin-typescript2#170 from
happening. Namely, a _virtual/tslib.js file would be emitted, which
confuses NodeJS because we expect all ES modules to have the .mjs
extension.

The previous syntax feels more elegant though, so I think it should be
re-enabled once the bug is resolved. Also, there's no guarantee that
this issue can alway be worked around so easily. Issue tracking is
available at
ezolenko/rollup-plugin-typescript2#282.
  • Loading branch information
NSeydoux committed Sep 9, 2021
1 parent 0010a72 commit e60ed68
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
46 changes: 34 additions & 12 deletions src/issue/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,41 @@ export default async function issueVerifiableCredential(
internalOptions.fetch = fallbackFetch;
}
// credentialClaims should contain all the claims, but not the context.
const {
"@context": subjectClaimsContext,
...contextlessSubjectClaims
} = subjectClaims;
const {
"@context": credentialClaimsContext,
...contextlessCredentialClaims
} = credentialClaims !== undefined ? credentialClaims : { "@context": [] };
// const {
// "@context": subjectClaimsContext,
// ...contextlessSubjectClaims
// } = subjectClaims;
// The following lines refactor the previous deconstruction in order to work
// around a misalignment between `rollup-plugin-typescript2` and NodeJS.
// Issue tracking: https://github.com/ezolenko/rollup-plugin-typescript2/issues/282
const contextlessSubjectClaims = { ...subjectClaims };
delete contextlessSubjectClaims["@context"];
const subjectClaimsContext = subjectClaims["@context"];

// const {
// "@context": credentialClaimsContext,
// ...contextlessCredentialClaims
// } = credentialClaims !== undefined ? credentialClaims : { "@context": [] };
// The following lines refactor the previous deconstruction in order to work
// around a misalignment between `rollup-plugin-typescript2` and NodeJS.
// Issue tracking: https://github.com/ezolenko/rollup-plugin-typescript2/issues/282
// When we add proper JSONLD parsing support, the following should be replaced.
const {
type: credentialTypeClaims,
...nonTypeCredentialClaims
} = contextlessCredentialClaims;
const contextlessCredentialClaims = { ...credentialClaims };
delete contextlessCredentialClaims["@context"];
const credentialClaimsContext =
credentialClaims !== undefined ? credentialClaims["@context"] : [];

// const {
// type: credentialTypeClaims,
// ...nonTypeCredentialClaims
// } = contextlessCredentialClaims;
// The following lines refactor the previous deconstruction in order to work
// around a misalignment between `rollup-plugin-typescript2` and NodeJS.
// Issue tracking: https://github.com/ezolenko/rollup-plugin-typescript2/issues/282
const nonTypeCredentialClaims = { ...contextlessCredentialClaims };
delete nonTypeCredentialClaims.type;
const credentialTypeClaims = contextlessCredentialClaims.type;

let credentialTypes = [];
if (credentialTypeClaims !== undefined) {
credentialTypes = Array.isArray(credentialTypeClaims)
Expand Down
8 changes: 7 additions & 1 deletion src/lookup/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ export default async function getVerifiableCredentialAllFromShape(
internalOptions.fetch = fallbackFetch;
}
// credentialClaims should contain all the claims, but not the context.
const { "@context": claimsContext, ...credentialClaims } = vcShape;
// const { "@context": claimsContext, ...credentialClaims } = vcShape;
// The following lines refactor the previous deconstruction in order to work
// around a misalignment between `rollup-plugin-typescript2` and NodeJS.
// Issue tracking: https://github.com/ezolenko/rollup-plugin-typescript2/issues/282
const credentialClaims = { ...vcShape };
delete credentialClaims["@context"];
const claimsContext = vcShape["@context"];
const credentialRequestBody = {
// See https://w3c-ccg.github.io/vc-http-api/holder.html
credential: {
Expand Down

0 comments on commit e60ed68

Please sign in to comment.