Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including PEX in a vite build results in incorrect build output #130

Open
ryanobjc opened this issue Oct 25, 2023 · 0 comments
Open

Including PEX in a vite build results in incorrect build output #130

ryanobjc opened this issue Oct 25, 2023 · 0 comments

Comments

@ryanobjc
Copy link

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    jsonPathUtils.js has mixed import/require which seems to confuse some js compilers. Specifically vite. When I run my app which includes a library which includes PEX I end up with a require() call in the bundled javascript. When I build the library that includes PEX using esbuild I end up with the correct bundled output.

It seems like vite/rollup.js isn't able to handle the mixed import/require. There is an older bug noting this issue rollup/rollup-plugin-commonjs#273 wherein the rollup authors essentially say "don't do that then please".

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
    This should be able to be fixable via a diff like so:
    @@ -1,10 +1,15 @@
    import { JSONPath as jp } from '@astronautlabs/jsonpath';
    import { PresentationDefinitionV1, PresentationDefinitionV2 } from '@sphereon/pex-models';
    +// eslint-disable-next-line @typescript-eslint/ban-ts-comment
    +// @ts-ignore @eslint-ignore
    +import shim from 'string.prototype.matchall';

import { InputFieldType, IPresentationDefinition, PathComponent } from '../types';

+shim();
+
+
export class JsonPathUtils {

  • static matchAll = require('string.prototype.matchall');
    static REGEX_PATH = /@\w+/g;
    /**

    • @param obj: any object can be found in verifiablePresentation.verifiableCredential[i]
      @@ -114,7 +119,7 @@ export class JsonPathUtils {
      }

    private static modifyPathWithSpecialCharacter(path: string): string {

  • const matches = this.matchAll(path, this.REGEX_PATH);

  • const matches = path.matchAll(this.REGEX_PATH);
    path = this.modifyPathRecursive(matches, path);
    return path;
    }
    @@ -132,7 +137,7 @@ export class JsonPathUtils {
    if (path.substring(atIdx - 2, atIdx) === '..') {
    path = path.substring(0, atIdx - 2) + "..['" + next.value[0] + "']" + path.substring(atIdx + next.value[0].length);
    indexChanged = true;
  •      const matches = this.matchAll(path, this.REGEX_PATH);
    
  •      const matches = path.matchAll(this.REGEX_PATH);
         this.modifyPathRecursive(matches, path);
       } else if (path.charAt(atIdx - 1) === '.') {
         path = path.substring(0, atIdx - 1) + "['" + next.value[0] + "']" + path.substring(atIdx + next.value[0].length);
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant